]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add further test cases for the logic in sqlite3WalBeginReadTransaction().
authordan <dan@noemail.net>
Sat, 5 Jun 2010 19:18:59 +0000 (19:18 +0000)
committerdan <dan@noemail.net>
Sat, 5 Jun 2010 19:18:59 +0000 (19:18 +0000)
FossilOrigin-Name: a49713db39d0d6940b368206d4e669aa69aa1fe5

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

index b77b7279562f375ac0427a0dc046c54b509d420f..bc0be6d2d4ccd4a180b59e29956eea273e8d5cd6 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Clarify\sthe\spurpose\sof\sa\stest\sfor\sa\srace-condition\sin\swalIndexReadHdr().
-D 2010-06-05T18:34:26
+C Add\sfurther\stest\scases\sfor\sthe\slogic\sin\ssqlite3WalBeginReadTransaction().
+D 2010-06-05T19:18:59
 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 a97ac7ee623fd92140bb0b37bc210b9cccb283f5
+F src/wal.c d1a6aa3f29c7f4e7ab474264978b7c1030363cb9
 F src/wal.h 4ace25262452d17e7d3ec970c89ee17794004008
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
 F src/where.c 75fee9e255b62f773fcadd1d1f25b6f63ac7a356
@@ -763,7 +763,7 @@ F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
 F test/vtab_shared.test 0eff9ce4f19facbe0a3e693f6c14b80711a4222d
 F test/wal.test bfec61450b47cdf09f7d2269f9e9967683b8b0fc
 F test/wal2.test 743d9b86041e57ba986dd7e3891c67725f9e2b2b
-F test/wal3.test 1c5e9535e0e307f837e059ec45842e7101796a96
+F test/wal3.test b82ac8268bac644d1d928d25316e5e7696ec47bf
 F test/wal_common.tcl 3e953ae60919281688ea73e4d0aa0e1bc94becd9
 F test/walbak.test e7650a26eb4b8abeca9b145b1af1e63026dde432
 F test/walcksum.test 4efa8fb88c32bed8288ea4385a9cc113a5c8f0bf
@@ -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 394204735a842b04b677cca20485b1578e475d4c
-R 27fd1a32d66f249d5fa488d9e53b7946
+P c041c6a9786bc9ebb82527f7a2c96d255aec927f
+R b34f0ea46ed4ddc81ab394ae4b47f8c2
 U dan
-Z ac39f481b39b4a8a76aecf6dead9965f
+Z b9b05ea832538d97e39aa0947439a601
index c58bba614c0fe38bdaf63156c246245f5432daf1..786185fab68242d71498cddc2e608409d1dfd17f 100644 (file)
@@ -1 +1 @@
-c041c6a9786bc9ebb82527f7a2c96d255aec927f
\ No newline at end of file
+a49713db39d0d6940b368206d4e669aa69aa1fe5
\ No newline at end of file
index 45a2d75e725079636b9cd297dcf3f84946cac29a..22a0688ae608613664571dcb750b01d7f29a3bc7 100644 (file)
--- a/src/wal.c
+++ b/src/wal.c
@@ -1747,7 +1747,7 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){
     rc = walLockShared(pWal, WAL_READ_LOCK(0));
     sqlite3OsShmBarrier(pWal->pDbFd);
     if( rc==SQLITE_OK ){
-      if( memcmp(pHdr, &pWal->hdr, sizeof(WalIndexHdr)) ){
+      if( memcmp((void *)pHdr, &pWal->hdr, sizeof(WalIndexHdr)) ){
         /* It is not safe to allow the reader to continue here if frames
         ** may have been appended to the log before READ_LOCK(0) was obtained.
         ** When holding READ_LOCK(0), the reader ignores the entire log file,
@@ -1832,15 +1832,15 @@ static int walTryBeginRead(Wal *pWal, int *pChanged, int useWal, int cnt){
     ** pWal->hdr.mxFrame risks reading a corrupted snapshot. So, retry
     ** instead.
     **
-    ** This does not guarantee that the copy wal-index header is up to
-    ** date before proceeding. This would not be possible without somehow
-    ** blocking writers. It only guarantees that a damaging checkpoint or 
+    ** This does not guarantee that the copy of the wal-index header is up to
+    ** date before proceeding. That would not be possible without somehow
+    ** blocking writers. It only guarantees that a dangerous checkpoint or 
     ** log-wrap (either of which would require an exclusive lock on
     ** WAL_READ_LOCK(mxI)) has not occurred since the snapshot was valid.
     */
     sqlite3OsShmBarrier(pWal->pDbFd);
     if( pInfo->aReadMark[mxI]!=mxReadMark
-     || memcmp(pHdr, &pWal->hdr, sizeof(WalIndexHdr))
+     || memcmp((void *)pHdr, &pWal->hdr, sizeof(WalIndexHdr))
     ){
       walUnlockShared(pWal, WAL_READ_LOCK(mxI));
       return WAL_RETRY;
index 430855d91367e6a67f440105caffebf5360308d7..746175d391debfea891304b0b7b822e2ff9af328 100644 (file)
@@ -420,8 +420,8 @@ T delete
 #-------------------------------------------------------------------------
 # When opening a read-transaction on a database, if the entire log has
 # already been copied to the database file, the reader grabs a special
-# kind of read lock (on aReadMark[0]). This test case tests the outcome
-# of the following:
+# kind of read lock (on aReadMark[0]). This set of test cases tests the 
+# outcome of the following:
 #
 #   + The reader discovering that between the time when it determined 
 #     that the log had been completely backfilled and the lock is obtained
@@ -563,6 +563,77 @@ db2 close
 db close
 T delete
 
+#-------------------------------------------------------------------------
+# When opening a read-transaction on a database, if the entire log has
+# not yet been copied to the database file, the reader grabs a read
+# lock on aReadMark[x], where x>0. The following test cases experiment
+# with the outcome of the following:
+#
+#   + The reader discovering that between the time when it read the
+#     wal-index header and the lock was obtained that a writer has 
+#     written to the log. In this case the reader should re-read the 
+#     wal-index header and lock a snapshot corresponding to the new 
+#     header.
+#
+#   + The value in the aReadMark[x] slot has been modified since it was
+#     read.
+#
+catch {db close}
+testvfs T -default 1
+do_test wal3-7.1.1 {
+  file delete -force test.db test.db-journal test.db wal
+  sqlite3 db test.db
+  execsql {
+    PRAGMA journal_mode = WAL;
+    CREATE TABLE blue(red PRIMARY KEY, green);
+  }
+} {wal}
+
+T script method_callback
+T filter xOpen
+proc method_callback {method args} {
+  if {$method == "xOpen"} { return "reader" }
+}
+do_test wal3-7.1.2 {
+  sqlite3 db2 test.db
+  execsql { SELECT * FROM blue } db2
+} {}
+
+T filter xShmLock
+set ::locks [list]
+proc method_callback {method file handle spec} {
+  if {$handle != "reader" } { return }
+  if {$method == "xShmLock"} {
+    catch { execsql { INSERT INTO blue VALUES(1, 2) } }
+    catch { execsql { INSERT INTO blue VALUES(3, 4) } }
+  }
+  lappend ::locks $spec
+}
+do_test wal3-7.1.3 {
+  execsql { SELECT * FROM blue } db2
+} {1 2 3 4}
+do_test wal3-7.1.4 {
+  set ::locks
+} {{4 1 lock shared} {4 1 unlock shared} {5 1 lock shared} {5 1 unlock shared}}
+
+set ::locks [list]
+proc method_callback {method file handle spec} {
+  if {$handle != "reader" } { return }
+  if {$method == "xShmLock"} {
+    catch { execsql { INSERT INTO blue VALUES(5, 6) } }
+  }
+  lappend ::locks $spec
+}
+do_test wal3-7.2.1 {
+  execsql { SELECT * FROM blue } db2
+} {1 2 3 4 5 6}
+do_test wal3-7.2.2 {
+  set ::locks
+} {{5 1 lock shared} {5 1 unlock shared} {4 1 lock shared} {4 1 unlock shared}}
+
+db close
+db2 close
+T delete
 
 finish_test