From 3cac5dc9bc97a0dfe83d3f78d21f573b27f3831a Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 4 Jun 2010 18:37:59 +0000 Subject: [PATCH] Clarify an assert in sqlite3WalExclusiveMode(). FossilOrigin-Name: 255850699ddbf4aad8cc3223aefbada35daa0703 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/wal.c | 14 ++++++++++---- test/wal2.test | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index f00c8d6c4f..89cefd2d55 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\san\sunnecessary\sbranch\sfrom\swal.c. -D 2010-06-04T17:16:53 +C Clarify\san\sassert\sin\ssqlite3WalExclusiveMode(). +D 2010-06-04T18:38:00 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in a5cad1f8f3e021356bfcc6c77dc16f6f1952bbc3 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -224,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 ea912c55b33ae62ae375efb80ca7ae6ef919943c +F src/wal.c e237581eeb99a9c766419e824c766ac67f37adb9 F src/wal.h 4ace25262452d17e7d3ec970c89ee17794004008 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f F src/where.c 75fee9e255b62f773fcadd1d1f25b6f63ac7a356 @@ -762,7 +762,7 @@ F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8 F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d F test/wal.test bfec61450b47cdf09f7d2269f9e9967683b8b0fc -F test/wal2.test c90d20363f17373cbf5bdfcee3571b43e8fa597b +F test/wal2.test 743d9b86041e57ba986dd7e3891c67725f9e2b2b F test/wal3.test 08626ca06bc87f34179258515c2d674b56b7e150 F test/wal_common.tcl 3e953ae60919281688ea73e4d0aa0e1bc94becd9 F test/walbak.test e7650a26eb4b8abeca9b145b1af1e63026dde432 @@ -817,7 +817,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P ca327e32cfe1633f2c9d3f058e411f108aaa2b3c -R 02edcf55cffb3be8e9337fa14f5f9042 +P 8e54786c9a0c5c399f228f56c73271f84d75694b +R 723b0db73791affd894a1e0706a506aa U dan -Z 3024f5e351971331772efea8971b5efc +Z 1b6d1f85256b6057d423f1cf677d1ba1 diff --git a/manifest.uuid b/manifest.uuid index 2642c19a09..cdec3e7710 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8e54786c9a0c5c399f228f56c73271f84d75694b \ No newline at end of file +255850699ddbf4aad8cc3223aefbada35daa0703 \ No newline at end of file diff --git a/src/wal.c b/src/wal.c index 69c5757412..6633784b62 100644 --- a/src/wal.c +++ b/src/wal.c @@ -2448,14 +2448,20 @@ int sqlite3WalCallback(Wal *pWal){ int sqlite3WalExclusiveMode(Wal *pWal, int op){ int rc; assert( pWal->writeLock==0 ); - /* pWal->readLock is usually set, but might be -1 if there was a prior OOM */ + + /* pWal->readLock is usually set, but might be -1 if there was a + ** prior error while attempting to acquire are read-lock. This cannot + ** happen if the connection is actually in exclusive mode (as no xShmLock + ** locks are taken in this case). Nor should the pager attempt to + ** upgrade to exclusive-mode following such an error. + */ assert( pWal->readLock>=0 || pWal->lockError ); + assert( pWal->readLock>=0 || (op<=0 && pWal->exclusiveMode==0) ); + if( op==0 ){ if( pWal->exclusiveMode ){ pWal->exclusiveMode = 0; - if( pWal->readLock>=0 - && walLockShared(pWal, WAL_READ_LOCK(pWal->readLock))!=SQLITE_OK - ){ + if( walLockShared(pWal, WAL_READ_LOCK(pWal->readLock))!=SQLITE_OK ){ pWal->exclusiveMode = 1; } rc = pWal->exclusiveMode==0; diff --git a/test/wal2.test b/test/wal2.test index b2ab654e74..c6cbe394c2 100644 --- a/test/wal2.test +++ b/test/wal2.test @@ -421,6 +421,12 @@ tvfs delete # wal2-6.4.*: Check that xShmLock calls are omitted in exclusive locking # mode. # +# wal2-6.5.*: +# +# wal2-6.6.*: Check that if the xShmLock() to reaquire a WAL read-lock when +# exiting exclusive mode fails (i.e. SQLITE_IOERR), then the +# connection silently remains in exclusive mode. +# do_test wal2-6.1.1 { file delete -force test.db test.db-wal test.db-journal sqlite3 db test.db @@ -718,6 +724,50 @@ do_test wal2-6.5.3 { } {} db close +proc lock_control {method filename handle spec} { + foreach {start n op type} $spec break + if {$op == "lock"} { return SQLITE_IOERR } + return SQLITE_OK +} +do_test wal2-6.6.1 { + testvfs T + T script lock_control + T filter {} + sqlite3 db test.db -vfs T + execsql { PRAGMA locking_mode = exclusive } + execsql { INSERT INTO t2 VALUES('V', 'VI') } +} {} +do_test wal2-6.6.2 { + execsql { PRAGMA locking_mode = normal } + T filter xShmLock + execsql { INSERT INTO t2 VALUES('VII', 'VIII') } +} {} +do_test wal2-6.6.3 { + # At this point the connection should still be in exclusive-mode, even + # though it tried to exit exclusive-mode when committing the INSERT + # statement above. To exit exclusive mode, SQLite has to take a read-lock + # on the WAL file using xShmLock(). Since that call failed, it remains + # in exclusive mode. + # + sqlite3 db2 test.db -vfs T + catchsql { SELECT * FROM t2 } db2 +} {1 {database is locked}} +do_test wal2-6.6.2 { + db2 close + T filter {} + execsql { INSERT INTO t2 VALUES('IX', 'X') } +} {} +do_test wal2-6.6.3 { + # This time, we have successfully exited exclusive mode. So the second + # connection can read the database. + sqlite3 db2 test.db -vfs T + catchsql { SELECT * FROM t2 } db2 +} {0 {I II III IV V VI VII VIII IX X}} + +db close +db2 close +T delete + #------------------------------------------------------------------------- # Test a theory about the checksum algorithm. Theory was false and this # test did not provoke a bug.