]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Test that if a corrupt wal-index header is encountered when attempting to commit...
authordan <dan@noemail.net>
Tue, 25 Aug 2015 16:01:04 +0000 (16:01 +0000)
committerdan <dan@noemail.net>
Tue, 25 Aug 2015 16:01:04 +0000 (16:01 +0000)
FossilOrigin-Name: c746e0bd20cb136eed2b691f326657d266e2f1ed

manifest
manifest.uuid
test/concurrent2.test
test/wal2.test
test/wal_common.tcl

index b28ae7786e338640c896a01a51a5f1dbdfde2c4a..57a2877c15794ef03ed56da09a8e95dc48893377 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\ssegfault\sthat\scould\soccur\sfollowing\san\sOOM\scondition\sin\sthe\sconcurrent\stransaction\scode.
-D 2015-08-25T14:37:39.823
+C Test\sthat\sif\sa\scorrupt\swal-index\sheader\sis\sencountered\swhen\sattempting\sto\scommit\sa\sconcurrent\stransaction,\sSQLITE_BUSY_SNAPSHOT\sis\sreturned\sto\sthe\scaller.
+D 2015-08-25T16:01:04.106
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in e2218eb228374422969de7b1680eda6864affcef
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -525,7 +525,7 @@ F test/colmeta.test 2c765ea61ee37bc43bbe6d6047f89004e6508eb1
 F test/colname.test 08948a4809d22817e0e5de89c7c0a8bd90cb551b
 F test/concfault.test 500f17c3fcfe7705114422bcc6ddd3c740001a43
 F test/concurrent.test 26c2d49abbf4847ceed9bf8cf7fbe9a2a4ffc70c
-F test/concurrent2.test 21a15630192ba92287070a1a58a6e497d393c55d
+F test/concurrent2.test 4b9d1cc7126bb83bb08aca0e7fa10e0eab54b0c7
 F test/concurrent3.test 7dcf81372c06cbac58e7e630aebf7292945947bb
 F test/conflict.test 841bcf7cabbfca39c577eb8411ea8601843b46a8
 F test/conflict2.test 0d3af4fb534fa1bd020c79960bb56e4d52655f09
@@ -1262,7 +1262,7 @@ F test/vtab_alter.test 9e374885248f69e251bdaacf480b04a197f125e5
 F test/vtab_err.test 0d4d8eb4def1d053ac7c5050df3024fd47a3fbd8
 F test/vtab_shared.test ea8778d5b0df200adef2ca7c00c3c37d4375f772
 F test/wal.test dbfc482e10c7263298833bb1fc60b3ac9d6340a1
-F test/wal2.test 1f841d2048080d32f552942e333fd99ce541dada
+F test/wal2.test dc801f6d3f8f39d1534ffbd15a715b0b287508db
 F test/wal3.test 2b5445e5da44780b9b44712f5a38523f7aeb0941
 F test/wal4.test 4744e155cd6299c6bd99d3eab1c82f77db9cdb3c
 F test/wal5.test 88b5d9a6a3d1532497ee9f4296f010d66f07e33c
@@ -1271,7 +1271,7 @@ F test/wal64k.test 163655ecd2cb8afef4737cac2a40fdd2eeaf20b8
 F test/wal7.test 2ae8f427d240099cc4b2dfef63cff44e2a68a1bd
 F test/wal8.test 75c42e1bc4545c277fed212f8fc9b7723cd02216
 F test/wal9.test 378e76a9ad09cd9bee06c172ad3547b0129a6750
-F test/wal_common.tcl a98f17fba96206122eff624db0ab13ec377be4fe
+F test/wal_common.tcl 37902864b63794e9bf59393b8887e21a9cbd4db8
 F test/walbak.test b9f68e39646375c2b877be906babcc15d38b4877
 F test/walbig.test f437473a16cfb314867c6b5d1dbcd519e73e3434
 F test/walblock.test be48f3a75eff0b4456209f26b3ce186c2015497d
@@ -1382,7 +1382,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 3e7d6dd62dfa63d7def00bd00ac055a606a0c80d
-R 7e8bf99bd9ee49e1baaabce6c0c30e59
+P 231b5880228cf01efe3981bc8be3150d79b422e5
+R f2d97f3b3defb10cf5a80dc03134f727
 U dan
-Z 16262c3600df8d68cd85cb26ef84be69
+Z ef5936cdf16a4565acadeed2265c73bc
index 9e2c009bc9ee7a26d89bb1420a997c1f60bcf975..203a63006aad36c7805aff722326a623a607462f 100644 (file)
@@ -1 +1 @@
-231b5880228cf01efe3981bc8be3150d79b422e5
\ No newline at end of file
+c746e0bd20cb136eed2b691f326657d266e2f1ed
\ No newline at end of file
index d058733e485a7a99f068f52eaa5bf20fa089aa23..f254e6d2aa91679e4a2db0f8fb0142fa61eebfd2 100644 (file)
@@ -9,10 +9,13 @@
 #
 #***********************************************************************
 #
+# Miscellaneous tests for transactions started with BEGIN CONCURRENT. 
+#
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
 source $testdir/lock_common.tcl
+source $testdir/wal_common.tcl
 set ::testprefix concurrent2
 
 ifcapable !concurrent {
@@ -296,5 +299,43 @@ do_multiclient_test tn {
   do_test 6.$tn.5 { sql3 { PRAGMA integrity_check } } {ok}
   do_test 6.$tn.5 { sql3 { SELECT count(*) from t1 } } {3}
 }
+
+#-------------------------------------------------------------------------
+# Test that if a corrupt wal-index-header is encountered when attempting
+# to commit a CONCURRENT transaction, the transaction is not committed
+# (or rolled back) and that SQLITE_BUSY_SNAPSHOT is returned to the user.
+#
+catch { db close }
+forcedelete test.db
+testvfs tvfs
+sqlite3 db test.db -vfs tvfs
+do_execsql_test 7.1 {
+  PRAGMA journal_mode = wal;
+  BEGIN;
+    CREATE TABLE t1(a, b, PRIMARY KEY(a));
+    INSERT INTO t1 VALUES(1, 2);
+    INSERT INTO t1 VALUES(3, 4);
+  COMMIT;
+  BEGIN CONCURRENT;
+    INSERT INTO t1 VALUES(5, 6);
+    INSERT INTO t1 VALUES(7, 8);
+    SELECT * FROM t1;
+} {wal 1 2 3 4 5 6 7 8}
+
+# Corrupt the wal-index header
+incr_tvfs_hdr test.db 11 1
+
+do_catchsql_test 7.2.1 { COMMIT } {1 {database is locked}}
+do_test 7.2.2 { sqlite3_extended_errcode db } SQLITE_BUSY_SNAPSHOT
+
+do_execsql_test 7.3.1 {
+  SELECT * FROM t1;
+  ROLLBACK;
+} {1 2 3 4 5 6 7 8}
+do_execsql_test 7.3.2 {
+  SELECT * FROM t1;
+} {1 2 3 4}
+
+
 finish_test
 
index 9d45444d6a4b5d0d3afaae0f8adc4683686b43b1..ad2147c2bc9913f981a779d681ee77eb9306d64b 100644 (file)
@@ -35,43 +35,6 @@ proc cond_incr_sync_count {adj} {
   }
 }
 
-proc set_tvfs_hdr {file args} {
-
-  # Set $nHdr to the number of bytes in the wal-index header:
-  set nHdr 48
-  set nInt [expr {$nHdr/4}]
-
-  if {[llength $args]>2} {
-    error {wrong # args: should be "set_tvfs_hdr fileName ?val1? ?val2?"}
-  }
-
-  set blob [tvfs shm $file]
-  if {$::tcl_platform(byteOrder)=="bigEndian"} {set fmt I} {set fmt i}
-
-  if {[llength $args]} {
-    set ia [lindex $args 0]
-    set ib $ia
-    if {[llength $args]==2} {
-      set ib [lindex $args 1]
-    }
-    binary scan $blob a[expr $nHdr*2]a* dummy tail
-    set blob [binary format ${fmt}${nInt}${fmt}${nInt}a* $ia $ib $tail]
-    tvfs shm $file $blob
-  }
-
-  binary scan $blob ${fmt}${nInt} ints
-  return $ints
-}
-
-proc incr_tvfs_hdr {file idx incrval} {
-  set ints [set_tvfs_hdr $file]
-  set v [lindex $ints $idx]
-  incr v $incrval
-  lset ints $idx $v
-  set_tvfs_hdr $file $ints
-}
-
-
 #-------------------------------------------------------------------------
 # Test case wal2-1.*:
 #
index 917ad598f6307567d79c63f58b431e817acb8f61..e39bffdc26e3432a41693f1103367f12cb9c89ec 100644 (file)
@@ -90,4 +90,44 @@ proc wal_fix_walindex_cksum {hdrvar} {
   lset hdr 11 $c2
 }
 
+# This command assumes that $file is the name of a database file opened
+# in wal mode using a [testvfs] VFS. It returns a list of the 12 32-bit
+# integers that make up the wal-index-header for the named file.
+#
+proc set_tvfs_hdr {file args} {
+
+  # Set $nHdr to the number of bytes in the wal-index header:
+  set nHdr 48
+  set nInt [expr {$nHdr/4}]
+
+  if {[llength $args]>2} {
+    error {wrong # args: should be "set_tvfs_hdr fileName ?val1? ?val2?"}
+  }
+
+  set blob [tvfs shm $file]
+  if {$::tcl_platform(byteOrder)=="bigEndian"} {set fmt I} {set fmt i}
+
+  if {[llength $args]} {
+    set ia [lindex $args 0]
+    set ib $ia
+    if {[llength $args]==2} {
+      set ib [lindex $args 1]
+    }
+    binary scan $blob a[expr $nHdr*2]a* dummy tail
+    set blob [binary format ${fmt}${nInt}${fmt}${nInt}a* $ia $ib $tail]
+    tvfs shm $file $blob
+  }
+
+  binary scan $blob ${fmt}${nInt} ints
+  return $ints
+}
+
+proc incr_tvfs_hdr {file idx incrval} {
+  set ints [set_tvfs_hdr $file]
+  set v [lindex $ints $idx]
+  incr v $incrval
+  lset ints $idx $v
+  set_tvfs_hdr $file $ints
+}
+