From: drh Date: Tue, 9 Oct 2001 12:39:24 +0000 (+0000) Subject: More changes prior to release 2.0.2. Mostly comment changes. But there X-Git-Tag: version-3.6.10~5761 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ff0839c0b6ff689830ef011bd3a66579cbd4f7be;p=thirdparty%2Fsqlite.git More changes prior to release 2.0.2. Mostly comment changes. But there was also a minor change to temptable.test so that it would work under Windows. (CVS 282) FossilOrigin-Name: 864349de6fba5b38a3fbf7ab502922937b1b61e5 --- diff --git a/manifest b/manifest index 6dd01e1543..665381f70b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Version\s2.0.2\s(CVS\s281) -D 2001-10-09T04:21:51 +C More\schanges\sprior\sto\srelease\s2.0.2.\s\sMostly\scomment\schanges.\s\sBut\sthere\nwas\salso\sa\sminor\schange\sto\stemptable.test\sso\sthat\sit\swould\swork\sunder\nWindows.\s(CVS\s282) +D 2001-10-09T12:39:24 F Makefile.in 98d4627cb364537e4c3a29ee806171f3abf5211a F Makefile.template 1e54087c0390c4ce0bb5be43e14ba028283751e6 F README 93d2977cc5c6595c448de16bdefc312b9d401533 @@ -29,7 +29,7 @@ F src/hash.h a5f5b3ce2d086a172c5879b0b06a27a82eac9fac F src/insert.c a48ba850461b203fb8dbc7add83fc6b6a9cf47f3 F src/main.c 87b2fca50cbe8b400e1443b2c73693e18d9911cb F src/md5.c 52f677bfc590e09f71d07d7e327bd59da738d07c -F src/os.c 64d0015bfc9edcb6380ce6fc75b31c73490f4c7b +F src/os.c a83f4cb85e4d3b98c1659a799f9e318fcaf1c76c F src/os.h bed702c9e3b768bc3cb1b12c90b83d099c1546be F src/pager.c 3445bd7c18cbfdffd8d6d1077f0b2bdf788da4fe F src/pager.h a0d4c5ae271914aa07b62aee0707997d6932b6ca @@ -83,7 +83,7 @@ F test/subselect.test 335d3dad8d585726c447dfee8d9c4f7383c76b78 F test/table.test 3ef4254d62ece31a3872ab11cdaec846f6fa8fd1 F test/tableapi.test 162840153191a91a7dce6395f2334f9aef713b37 F test/tclsqlite.test a57bb478d7e9f0b2c927f92e161f391e2896631a -F test/temptable.test 9576d30a6809a3233310163fee9ae8d4b9d27f54 +F test/temptable.test 37acd9e39781c2ff7cff2ba741b6b27ce020a44a F test/tester.tcl c7ddeebc14cc841abb37134cd5d40c1e3ad367c1 F test/trans.test 855337b8a178c73c433fcf8ee88e4b2f5efff0d9 F test/unique.test ef1f67607a7109e9c0842cd8557550fb121d7ec6 @@ -101,7 +101,7 @@ F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf F www/arch.png 82ef36db1143828a7abc88b1e308a5f55d4336f4 F www/arch.tcl 03b521d252575f93b9c52f7c8b0007011512fcfb F www/c_interface.tcl 8e8d9e66e8467c5751116c3427296bde77f474a6 -F www/changes.tcl 6c25c0098cddde028e04d8ce7b59f58359a0fa1f +F www/changes.tcl 2b416b49a136312678317f509821cf9359e421b5 F www/crosscompile.tcl c99efacb3aefaa550c6e80d91b240f55eb9fd33e F www/download.tcl 3e51c9ff1326b0a182846134987301310dff7d60 F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c @@ -113,7 +113,7 @@ F www/speed.tcl ab7d6d3bc898472bd94320a5d3c63de928d4804b F www/sqlite.tcl 6a21242a272e9c0939a04419a51c3d50cae33e3e F www/tclsqlite.tcl 13d50723f583888fc80ae1a38247c0ab415066fa F www/vdbe.tcl bb7d620995f0a987293e9d4fb6185a3b077e9b44 -P 484b82d8a1c84f3d9725a509de93276b9fa9b294 -R e0211f7ef81f1015b59b3a33ae8ec9df +P 765359c77ebae22e42b78636e70a57b010aaa18e +R 00a3f33de80cb8fb5006abe2246012c5 U drh -Z 085c67f80b7bd57b2ee9d6e92b91d085 +Z 8201536b58eae125c25ac9ac5ab95d7d diff --git a/manifest.uuid b/manifest.uuid index f4a69a4eed..a8c89fe78a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -765359c77ebae22e42b78636e70a57b010aaa18e \ No newline at end of file +864349de6fba5b38a3fbf7ab502922937b1b61e5 \ No newline at end of file diff --git a/src/os.c b/src/os.c index edb4f6eee9..3aaf8fae7e 100644 --- a/src/os.c +++ b/src/os.c @@ -39,6 +39,58 @@ #if OS_UNIX +/* +** Here is the dirt on POSIX advisory locks: ANSI STD 1003.1 (1996) +** section 6.5.2.2 lines 483 through 490 specify that when a process +** sets or clears a lock, that operation overrides any prior locks set +** by the same process. It does not explicitly say so, but this implies +** that it overrides locks set by the same process using a different +** file descriptor. Consider this test case: +** +** int fd1 = open("./file1", O_RDWR|O_CREAT, 0644); +** int fd2 = open("./file2", O_RDWR|O_CREAT, 0644); +** +** Suppose ./file1 and ./file2 are really be the same file (because +** one is a hard or symbolic link to the other) then if you set +** an exclusive lock on fd1, then try to get an exclusive lock +** on fd2, it works. I would have expected the second lock to +** fail since there was already a lock on the file due to fd1. +** But not so. Since both locks came from the same process, the +** second overrides the first, even though they were on different +** file descriptors opened on different file names. +** +** Bummer. If you ask me, this is broken. Badly broken. It means +** that we cannot use POSIX locks to synchronize file access among +** competing threads of the same process. POSIX locks will work fine +** to synchronize access for threads in separate processes, but not +** threads within the same process. +** +** To work around the problem, SQLite has to manage file locks internally +** on its own. Whenever a new database is opened, we have to find the +** specific inode of the database file (the inode is determined by the +** st_dev and st_ino fields of the stat structure the stat() fills in) +** and check for locks already existing on that inode. When locks are +** created or removed, we have to look at our own internal record of the +** locks to see if another thread has previously set a lock on that same +** inode. +** +** The OsFile structure for POSIX is no longer just an integer file +** descriptor. It is now a structure that holds the integer file +** descriptor and a pointer to a structure that describes the internal +** locks on the corresponding inode. There is one locking structure +** per inode, so if the same inode is opened twice, both OsFile structures +** point to the same locking structure. The locking structure keeps +** a reference count (so we will know when to delete it) and a "cnt" +** field that tells us its internal lock status. cnt==0 means the +** file is unlocked. cnt==-1 means the file has an exclusive lock. +** cnt>0 means there are cnt shared locks on the file. +** +** Any attempt to lock or unlock a file first checks the locking +** structure. The fcntl() system call is only invoked to set a +** POSIX lock if the internal lock structure transitions between +** a locked and an unlocked state. +*/ + /* ** An instance of the following structure serves as the key used ** to locate a particular lockInfo structure given its inode. @@ -50,8 +102,9 @@ struct inodeKey { /* ** An instance of the following structure is allocated for each inode. -** A single inode can have multiple file descriptors, so each OsFile structure -** contains a pointer to an instance of this object. +** A single inode can have multiple file descriptors, so each OsFile +** structure contains a pointer to an instance of this object and this +** object keeps a count of the number of OsFiles pointing to it. */ struct lockInfo { struct inodeKey key; /* The lookup key */ @@ -67,7 +120,8 @@ static Hash lockHash = { SQLITE_HASH_BINARY, 0, 0, 0, 0, 0 }; /* ** Given a file descriptor, locate a lockInfo structure that describes -** that file descriptor. Create a new one if necessary. +** that file descriptor. Create a new one if necessary. NULL might +** be returned if malloc() fails. */ static struct lockInfo *findLockInfo(int fd){ int rc; @@ -81,6 +135,7 @@ static struct lockInfo *findLockInfo(int fd){ pInfo = (struct lockInfo*)sqliteHashFind(&lockHash, &key, sizeof(key)); if( pInfo==0 ){ pInfo = sqliteMalloc( sizeof(*pInfo) ); + if( pInfo==0 ) return 0; pInfo->key = key; pInfo->nRef = 1; pInfo->cnt = 0; @@ -101,7 +156,7 @@ static void releaseLockInfo(struct lockInfo *pInfo){ sqliteFree(pInfo); } } -#endif +#endif /** POSIX advisory lock work-around **/ /* diff --git a/test/temptable.test b/test/temptable.test index c52f5e8376..efc815a134 100644 --- a/test/temptable.test +++ b/test/temptable.test @@ -12,7 +12,7 @@ # # This file implements tests for temporary tables and indices. # -# $Id: temptable.test,v 1.2 2001/10/09 04:19:47 drh Exp $ +# $Id: temptable.test,v 1.3 2001/10/09 12:39:24 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -225,4 +225,6 @@ do_test temptable-5.9 { execsql {SELECT y FROM t2 WHERE x=9} } {8} +db2 close + finish_test diff --git a/www/changes.tcl b/www/changes.tcl index 93ba31a202..ac06b1bf9e 100644 --- a/www/changes.tcl +++ b/www/changes.tcl @@ -18,7 +18,7 @@ proc chng {date desc} { } chng {2001 Oct 9 (2.0.2)} { -
  • Fix a bugs in the locking protocol.
  • +
  • Fix two bugs in the locking protocol. (One was masking the other.)
  • Removed some unused "#include " that were causing problems for VC++.
  • Fixed sqlite.h so that it is usable from C++