]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Shift the meaning of aReadMark[] back so that +1 offset from mxFrame is
authordrh <drh@noemail.net>
Wed, 9 Jun 2010 14:45:12 +0000 (14:45 +0000)
committerdrh <drh@noemail.net>
Wed, 9 Jun 2010 14:45:12 +0000 (14:45 +0000)
removed.  Add the new READMARK_NOT_USED value (0xffffffff) instead of
zero to signal an aReadMark[] that is not in use.

FossilOrigin-Name: c576827d55c156572b76cf7063e9f253ca6e7403

manifest
manifest.uuid
src/wal.c
test/wal2.test

index ca62da1acd1e9e542f8bda0611de2b18bd63a94b..18998b1d22f760032d6b7dc2219eb85f4fab5208 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,8 @@
-C Simpler\sfix\sfor\sthe\srace\scondition\salso\sfixed\sby\s[7c102c7b5f]
-D 2010-06-09T11:28:44
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+C Shift\sthe\smeaning\sof\saReadMark[]\sback\sso\sthat\s+1\soffset\sfrom\smxFrame\sis\nremoved.\s\sAdd\sthe\snew\sREADMARK_NOT_USED\svalue\s(0xffffffff)\sinstead\sof\nzero\sto\ssignal\san\saReadMark[]\sthat\sis\snot\sin\suse.
+D 2010-06-09T14:45:13
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -224,7 +227,7 @@ F src/vdbeblob.c 5327132a42a91e8b7acfb60b9d2c3b1c5c863e0e
 F src/vdbemem.c 2a82f455f6ca6f78b59fb312f96054c04ae0ead1
 F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2
 F src/vtab.c a0f8a40274e4261696ef57aa806de2776ab72cda
-F src/wal.c 70edade3677e36afbe8075d4304cca767848ef6c
+F src/wal.c 25ce19c8e175baf0c7d303243d38c0b2d4b1ba30
 F src/wal.h 4ace25262452d17e7d3ec970c89ee17794004008
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
 F src/where.c 75fee9e255b62f773fcadd1d1f25b6f63ac7a356
@@ -762,7 +765,7 @@ F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5
 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
 F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d
 F test/wal.test 0a599c3c4812ed92bc7ad9efcc2c4007fe4cc99a
-F test/wal2.test f70bbe268891a70cc40dce659efe617e548c7491
+F test/wal2.test 854a2b409450f1cb756c2bbd1e87e30740094357
 F test/wal3.test ae876ff988af5b2b34d27474e0dd1a8c84e9bbcb
 F test/wal_common.tcl 3e953ae60919281688ea73e4d0aa0e1bc94becd9
 F test/walbak.test e7650a26eb4b8abeca9b145b1af1e63026dde432
@@ -817,7 +820,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P b072e9f69ad5ec68b8ec4c716556070001f885e0
-R 9421e982987c37bd229515e5e78a5b85
-U dan
-Z 5d192ec04bfd1c32160d5fae6852d7c2
+P 3c2de820034e01c2e939bd90a05a58159f60df50
+R 91636215da20a362ea2e64fc78c9decc
+U drh
+Z 48ecf6d24ad1746c8fc1cd67f013e730
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.6 (GNU/Linux)
+
+iD8DBQFMD6j8oxKgR168RlERAhEQAJ9R5n1TsaleiaYrC7/BGXipfEEX+wCeIl+J
+u01EHGRvmB2pUOkEor+I24I=
+=iubS
+-----END PGP SIGNATURE-----
index da39512fc5f08a08af75fff5496b1c72fd1ca0f0..d0ba69d25d6edad1ec233e2db331e4c1db40d725 100644 (file)
@@ -1 +1 @@
-3c2de820034e01c2e939bd90a05a58159f60df50
\ No newline at end of file
+c576827d55c156572b76cf7063e9f253ca6e7403
\ No newline at end of file
index 1a457f23ac46024540fa6f61abdb480c624eee1e..1b90d384f43b3892a6e4f5b01e69792ff5612de8 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -285,9 +285,12 @@ struct WalIndexHdr {
 **
 ** There is one entry in aReadMark[] for each reader lock.  If a reader
 ** holds read-lock K, then the value in aReadMark[K] is no greater than
-** the mxFrame for that reader.  aReadMark[0] is a special case.  It
-** always holds zero.  Readers holding WAL_READ_LOCK(0) always ignore 
-** the entire WAL and read all content directly from the database.
+** the mxFrame for that reader.  The value READMARK_NOT_USED (0xffffffff)
+** for any aReadMark[] means that entry is unused.  aReadMark[0] is 
+** a special case; its value is never used and it exists as a place-holder
+** to avoid having to offset aReadMark[] indexs by one.  Readers holding
+** WAL_READ_LOCK(0) always ignore the entire WAL and read all content
+** directly from the database.
 **
 ** The value of aReadMark[K] may only be changed by a thread that
 ** is holding an exclusive lock on WAL_READ_LOCK(K).  Thus, the value of
@@ -320,6 +323,7 @@ struct WalCkptInfo {
   u32 nBackfill;                  /* Number of WAL frames backfilled into DB */
   u32 aReadMark[WAL_NREADER];     /* Reader marks */
 };
+#define READMARK_NOT_USED  0xffffffff
 
 
 /* A block of WALINDEX_LOCK_RESERVED bytes beginning at
@@ -1076,15 +1080,20 @@ finished:
     rc = walIndexRemap(pWal, walMappingSize(1));
   }
   if( rc==SQLITE_OK ){
+    volatile WalCkptInfo *pInfo;
+    int i;
     pWal->hdr.aFrameCksum[0] = aFrameCksum[0];
     pWal->hdr.aFrameCksum[1] = aFrameCksum[1];
     walIndexWriteHdr(pWal);
 
-    /* Zero the checkpoint-header. This is safe because this thread is 
+    /* Reset the checkpoint-header. This is safe because this thread is 
     ** currently holding locks that exclude all other readers, writers and
     ** checkpointers.
     */
-    memset((void *)walCkptInfo(pWal), 0, sizeof(WalCkptInfo));
+    pInfo = walCkptInfo(pWal);
+    pInfo->nBackfill = 0;
+    pInfo->aReadMark[0] = 0;
+    for(i=1; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED;
   }
 
 recovery_error:
@@ -1426,14 +1435,14 @@ static int walCheckpoint(
   assert( pInfo==walCkptInfo(pWal) );
   for(i=1; i<WAL_NREADER; i++){
     u32 y = pInfo->aReadMark[i];
-    if( y>0 && mxSafeFrame>=y ){
+    if( mxSafeFrame>=y ){
       assert( y<=pWal->hdr.mxFrame );
       rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
       if( rc==SQLITE_OK ){
-        pInfo->aReadMark[i] = 0;
+        pInfo->aReadMark[i] = READMARK_NOT_USED;
         walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
       }else if( rc==SQLITE_BUSY ){
-        mxSafeFrame = y-1;
+        mxSafeFrame = y;
       }else{
         goto walcheckpoint_out;
       }
@@ -1780,7 +1789,8 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){
   mxI = 0;
   for(i=1; i<WAL_NREADER; i++){
     u32 thisMark = pInfo->aReadMark[i];
-    if( mxReadMark<thisMark && thisMark<=(pWal->hdr.mxFrame+1) ){
+    if( mxReadMark<=thisMark && thisMark<=pWal->hdr.mxFrame ){
+      assert( thisMark!=READMARK_NOT_USED );
       mxReadMark = thisMark;
       mxI = i;
     }
@@ -1792,7 +1802,7 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){
     */
     rc = walLockExclusive(pWal, WAL_READ_LOCK(1), 1);
     if( rc==SQLITE_OK ){
-      pInfo->aReadMark[1] = pWal->hdr.mxFrame+1;
+      pInfo->aReadMark[1] = pWal->hdr.mxFrame;
       walUnlockExclusive(pWal, WAL_READ_LOCK(1), 1);
       rc = WAL_RETRY;
     }else if( rc==SQLITE_BUSY ){
@@ -1804,7 +1814,7 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){
       for(i=1; i<WAL_NREADER; i++){
         rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1);
         if( rc==SQLITE_OK ){
-          mxReadMark = pInfo->aReadMark[i] = pWal->hdr.mxFrame+1;
+          mxReadMark = pInfo->aReadMark[i] = pWal->hdr.mxFrame;
           mxI = i;
           walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1);
           break;
@@ -1845,7 +1855,7 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){
       walUnlockShared(pWal, WAL_READ_LOCK(mxI));
       return WAL_RETRY;
     }else{
-      assert( mxReadMark<=(pWal->hdr.mxFrame+1) );
+      assert( mxReadMark<=pWal->hdr.mxFrame );
       pWal->readLock = mxI;
     }
   }
index 595779049a58d6bada93c6cf330ad0c456335474..c3f98a4b24e291ae941f1ebbcdb7f7f47bd0cbd8 100644 (file)
@@ -167,6 +167,7 @@ file delete -force test.db test.db-wal test.db-journal
 set WRITER [list 0 1 lock exclusive]
 set LOCKS  [list \
   {0 1 lock exclusive} {0 1 unlock exclusive} \
+  {4 1 lock exclusive} {4 1 unlock exclusive} \
   {4 1 lock shared}    {4 1 unlock shared}    \
 ]
 do_test wal2-2.0 {