From: dan Date: Mon, 31 May 2010 11:16:30 +0000 (+0000) Subject: Fix some asserts and other things in the new WAL branch. X-Git-Tag: version-3.7.2~328^2~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d54ff60bf41cbff978764073b4244c3d289c4d6a;p=thirdparty%2Fsqlite.git Fix some asserts and other things in the new WAL branch. FossilOrigin-Name: 181ceb32ead7f540a7c6437f53a5b0f3e78162db --- diff --git a/manifest b/manifest index 6065559281..fade5ab5ae 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,5 @@ ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -C WAL\sruns\sbut\squickly\sdeadlocks. -D 2010-05-31T01:41:16 +C Fix\ssome\sasserts\sand\sother\sthings\sin\sthe\snew\sWAL\sbranch. +D 2010-05-31T11:16:31 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -227,7 +224,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 016ea4ed0323907bc8139622c9dae5ab75ec364c +F src/wal.c 23b3733a0be297d74c4c123fd0672a9c97727386 F src/wal.h 1c1c9feb629b7f4afcbe0b47f80f47c5551d3a02 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f F src/where.c 75fee9e255b62f773fcadd1d1f25b6f63ac7a356 @@ -769,7 +766,7 @@ F test/wal2.test c58bb5b2fac48b8393909038ced730df5ad973b0 F test/walbak.test e7650a26eb4b8abeca9b145b1af1e63026dde432 F test/walcksum.test 4efa8fb88c32bed8288ea4385a9cc113a5c8f0bf F test/walcrash.test f6d5fb2bb108876f04848720a488065d9deef69f -F test/walcrash2.test 14585ad1a2c85da2de721caa3b4deeea55213008 +F test/walcrash2.test f37c99f729a30c6916849a4b1d3a161f2c4fb000 F test/walfault.test f71d4c9a13d4e27086aef55f1e0e94734ffa2f6a F test/walhook.test 67e675127f4acb72f061a12667ce6e5460b06b78 F test/walmode.test 6ca9d710cc9f6545b913abcded6d6b0b15641048 @@ -818,14 +815,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P ef3ba7a17ff90674d702e5694b9e792851ab6998 -R 651c029120b6d93a925820592e49e0df -U drh -Z fe262abca6c7606bad6380cede9b085d ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.6 (GNU/Linux) - -iD8DBQFMAxPBoxKgR168RlERAvPlAJ9ajxNPryXB6MLg8ylPwxiINjVplACfZFw5 -H866uySmTIu3rUiQvqGaMCI= -=yN+5 ------END PGP SIGNATURE----- +P ace58acbf1fad13d2be96cafebc3a22875098d03 +R ff9d1967b732326f3bce0ee3d72a6c66 +U dan +Z afad2ce8da9a593f49e5e1a5ca3459df diff --git a/manifest.uuid b/manifest.uuid index a7687e5183..0c7c8c289a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ace58acbf1fad13d2be96cafebc3a22875098d03 \ No newline at end of file +181ceb32ead7f540a7c6437f53a5b0f3e78162db \ No newline at end of file diff --git a/src/wal.c b/src/wal.c index 0d1d0e42b4..9436916927 100644 --- a/src/wal.c +++ b/src/wal.c @@ -1232,7 +1232,7 @@ static int walIteratorInit(Wal *pWal, WalIterator **pp){ ** running (or, indeed, while the WalIterator object exists). Hence, ** we can cast off the volatile qualifacation from shared memory */ - assert( pWal->ckptLock ); + assert( pWal->ckptLock || pWal->exclusiveMode ); aData = (u32*)pWal->pWiData; /* Allocate space for the WalIterator object */ @@ -1345,20 +1345,20 @@ static int walCheckpoint( ** overwrite database pages that are in use by active readers and thus ** cannot be backfilled from the WAL. */ - mxSafeFrame = 0; + mxSafeFrame = pWal->hdr.mxFrame; pHdr = (volatile WalIndexHdr*)pWal->pWiData; pInfo = (volatile WalCkptInfo*)&pHdr[2]; assert( pInfo==walCkptInfo(pWal) ); for(i=1; iaReadMark[i]; - if( y>0 && (mxSafeFrame==0 || mxSafeFrame0 && (mxSafeFrame==0 || mxSafeFrame>=y) ){ if( yhdr.mxFrame && (rc = walLockExclusive(pWal, WAL_READ_LOCK(i), 1))==SQLITE_OK ){ pInfo->aReadMark[i] = 0; walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1); }else{ - mxSafeFrame = y; + mxSafeFrame = y-1; } } } @@ -1545,7 +1545,7 @@ static int walIndexReadHdr(Wal *pWal, int *pChanged){ /* If the first attempt failed, it might have been due to a race ** with a writer. So get a WRITE lock and try again. */ - assert( pWal->writeLock==0 ); + assert( badHdr==0 || pWal->writeLock==0 ); if( badHdr ){ rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1); if( rc==SQLITE_OK ){ @@ -1687,16 +1687,16 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal){ */ rc = walLockExclusive(pWal, WAL_READ_LOCK(1), 1); if( rc==SQLITE_OK ){ - pInfo->aReadMark[1] = pWal->hdr.mxFrame; + pInfo->aReadMark[1] = pWal->hdr.mxFrame+1; walUnlockExclusive(pWal, WAL_READ_LOCK(1), 1); } return WAL_RETRY; }else{ if( mxReadMark < pWal->hdr.mxFrame ){ - for(i=0; iaReadMark[i] = pWal->hdr.mxFrame; + pInfo->aReadMark[i] = pWal->hdr.mxFrame+1; mxReadMark = pWal->hdr.mxFrame; mxI = i; walUnlockExclusive(pWal, WAL_READ_LOCK(i), 1); @@ -1953,22 +1953,25 @@ int sqlite3WalBeginWriteTransaction(Wal *pWal){ } pInfo = walCkptInfo(pWal); - if( pWal->readLock==0 && pInfo->nBackfill==pWal->hdr.mxFrame ){ - rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); - if( rc==SQLITE_OK ){ - /* If all readers are using WAL_READ_LOCK(0) (in other words if no - ** readers are currently using the WAL) */ - pWal->nCkpt++; - pWal->hdr.mxFrame = 0; - sqlite3Put4byte((u8*)pWal->hdr.aSalt, - 1 + sqlite3Get4byte((u8*)pWal->hdr.aSalt)); - sqlite3_randomness(4, &pWal->hdr.aSalt[1]); - walIndexWriteHdr(pWal); - pInfo->nBackfill = 0; - memset(&pInfo->aReadMark[1], 0, sizeof(pInfo->aReadMark)-sizeof(u32)); - rc = sqlite3OsTruncate(pWal->pDbFd, - ((i64)pWal->hdr.nPage*(i64)pWal->szPage)); - walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); + if( pWal->readLock==0 ){ + assert( pInfo->nBackfill==pWal->hdr.mxFrame ); + if( pInfo->nBackfill>0 ){ + rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); + if( rc==SQLITE_OK ){ + /* If all readers are using WAL_READ_LOCK(0) (in other words if no + ** readers are currently using the WAL) */ + pWal->nCkpt++; + pWal->hdr.mxFrame = 0; + sqlite3Put4byte((u8*)pWal->hdr.aSalt, + 1 + sqlite3Get4byte((u8*)pWal->hdr.aSalt)); + sqlite3_randomness(4, &pWal->hdr.aSalt[1]); + walIndexWriteHdr(pWal); + pInfo->nBackfill = 0; + memset(&pInfo->aReadMark[1], 0, sizeof(pInfo->aReadMark)-sizeof(u32)); + rc = sqlite3OsTruncate(pWal->pDbFd, + ((i64)pWal->hdr.nPage*(i64)pWal->szPage)); + walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1); + } } walUnlockShared(pWal, WAL_READ_LOCK(0)); pWal->readLock = -1; @@ -1977,6 +1980,7 @@ int sqlite3WalBeginWriteTransaction(Wal *pWal){ rc = walTryBeginRead(pWal, ¬Used, 1); }while( rc==WAL_RETRY ); } + walIndexUnmap(pWal); return rc; } @@ -1986,6 +1990,7 @@ int sqlite3WalBeginWriteTransaction(Wal *pWal){ */ int sqlite3WalEndWriteTransaction(Wal *pWal){ walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); + pWal->writeLock = 0; return SQLITE_OK; } @@ -2211,6 +2216,7 @@ int sqlite3WalCheckpoint( int isChanged = 0; /* True if a new wal-index header is loaded */ assert( pWal->pWiData==0 ); + assert( pWal->ckptLock==0 ); rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); if( rc ){ @@ -2219,6 +2225,7 @@ int sqlite3WalCheckpoint( ** also be SQLITE_IOERR. */ return rc; } + pWal->ckptLock = 1; /* Copy data from the log to the database file. */ rc = walIndexReadHdr(pWal, &isChanged); @@ -2238,6 +2245,7 @@ int sqlite3WalCheckpoint( /* Release the locks. */ walIndexUnmap(pWal); walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1); + pWal->ckptLock = 0; return rc; } diff --git a/test/walcrash2.test b/test/walcrash2.test index 417fe144d7..b8d7e76ab3 100644 --- a/test/walcrash2.test +++ b/test/walcrash2.test @@ -91,8 +91,20 @@ for {set nEntry 8} {$nEntry < 8192} {incr nEntry 8} { file size test.db-wal } [wal_file_size 16 1024] } +sqlite3 db2 test.db +breakpoint + db2 eval { + PRAGMA cache_size = 15; + BEGIN; + INSERT INTO t1 VALUES(randomblob(900)); -- 1 row, 1 page + INSERT INTO t1 SELECT * FROM t1; -- 2 rows, 3 pages + INSERT INTO t1 SELECT * FROM t1; -- 4 rows, 5 pages + INSERT INTO t1 SELECT * FROM t1; -- 8 rows, 9 pages + INSERT INTO t1 SELECT * FROM t1; -- 16 rows, 17 pages + INSERT INTO t1 SELECT * FROM t1 LIMIT 3; -- 20 rows, 20 pages + } + do_test walcrash2-1.3 { - sqlite3 db2 test.db execsql { SELECT count(*) FROM t1 } db2 } {0} catch { db2 close }