]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a new test script to exercise the deadlock avoidance code in the
authordrh <drh@noemail.net>
Mon, 14 Jul 2008 19:39:16 +0000 (19:39 +0000)
committerdrh <drh@noemail.net>
Mon, 14 Jul 2008 19:39:16 +0000 (19:39 +0000)
btree mutex logic. (CVS 5412)

FossilOrigin-Name: 7d5e1c4375599a913d23e5954fa63c10ac9d7688

manifest
manifest.uuid
src/btmutex.c
test/permutations.test
test/shared4.test [new file with mode: 0644]

index 597d836f8910aceb3a8e7f7304954203c7ebbacd..a9d6cde1b163c22e870268908897d6f95d40573d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\stypo\sin\sthe\sdocumentation.\s\sTicket\s#3219.\s(CVS\s5411)
-D 2008-07-14T18:38:17
+C Add\sa\snew\stest\sscript\sto\sexercise\sthe\sdeadlock\savoidance\scode\sin\sthe\nbtree\smutex\slogic.\s(CVS\s5412)
+D 2008-07-14T19:39:17
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in a03f7cb4f7ad50bc53a788c6c544430e81f95de4
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -95,7 +95,7 @@ F src/analyze.c 9ee63497ee720728abe630d169ab91323ac7519c
 F src/attach.c b18ba42c77f7d3941f5d23d2ca20fa1d841a4e91
 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
 F src/bitvec.c 95c86bd18d8fedf0533f5af196192546e10a7e7d
-F src/btmutex.c 483ced3c52205b04b97df69161fadbf87f4f1ea2
+F src/btmutex.c 709cad2cdca0afd013f0f612363810e53f59ec53
 F src/btree.c cda41ffc78e53cd29e53eab47d174d3e6afd680d
 F src/btree.h 03256ed7ee42b5ecacbe887070b0f8249e7d069d
 F src/btreeInt.h a6a5ffab12fa2c15392b85242cd5568371949046
@@ -430,7 +430,7 @@ F test/pager2.test c025f91b75fe65e85febda64d9416428b8a5cab5
 F test/pager3.test 2323bf27fd5bd887b580247e5bce500ceee994b4
 F test/pageropt.test 6df72c441db0a037b7ec6990d16311c24fbea77b
 F test/pagesize.test e0a8b3fe80f8b8e808d94a00734c7a18c76c407e
-F test/permutations.test bf962d39b77fd87555455d16bb1208d32a732c6d
+F test/permutations.test ed3b4721caf1d538778f9f155fd8133216e48212
 F test/pragma.test 2c675ed9a288094ed62bf55b35fbc749e25670fb
 F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47
 F test/printf.test 262a5acd3158f788e9bdf7f18d718f3af32ff6ef
@@ -461,6 +461,7 @@ F test/server1.test f5b790d4c0498179151ca8a7715a65a7802c859c
 F test/shared.test b9f3bbd3ba727c5f1f8c815b7d0199262aacf214
 F test/shared2.test 0ee9de8964d70e451936a48c41cb161d9134ccf4
 F test/shared3.test 987316be601e2349e6a340a6d5f8ed981e507931
+F test/shared4.test ea035211a4444205537c542d9a24015aea9f0c8d
 F test/shared_err.test 776ab7196ecda8b07a075e115b0725806991e151
 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
 F test/sidedelete.test 736ac1da08b3b1aa62df97fef2fcdb1b660111b9
@@ -605,7 +606,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P c060a9a6beca455bdceee9ce6ca71a7262f98a5f
-R f1cf792514fd75a27596e2a43ce502f1
+P 3dc72a46171020c62e6028d113b0e0f5ab05d159
+R 6d734a63548e6f48975b58c9676b7c06
 U drh
-Z c55669db705c2547daf67dc6154f8afd
+Z 77913ffe58a126c4bbfbbf4bc5ff271d
index 3c192ed4ae0a73f3abbf5988745ac991f598bbe9..10b2aeac8584868d6d2a3859f815294ea33273f7 100644 (file)
@@ -1 +1 @@
-3dc72a46171020c62e6028d113b0e0f5ab05d159
\ No newline at end of file
+7d5e1c4375599a913d23e5954fa63c10ac9d7688
\ No newline at end of file
index 58a1b56aeae1a87f1c4a85a355a6cd550326f11d..bf6361706adea5061b39223c3afbf0a41cc7e7e0 100644 (file)
@@ -10,7 +10,7 @@
 **
 *************************************************************************
 **
-** $Id: btmutex.c,v 1.9 2008/01/23 12:52:41 drh Exp $
+** $Id: btmutex.c,v 1.10 2008/07/14 19:39:17 drh Exp $
 **
 ** This file contains code used to implement mutexes on Btree objects.
 ** This code really belongs in btree.c.  But btree.c is getting too
@@ -226,11 +226,11 @@ int sqlite3BtreeHoldsAllMutexes(sqlite3 *db){
 #endif /* NDEBUG */
 
 /*
-** Potentially dd a new Btree pointer to a BtreeMutexArray.
-** Really only add the Btree if it can possibly be shared with
+** Add a new Btree pointer to a BtreeMutexArray. 
+** if the pointer can possibly be shared with
 ** another database connection.
 **
-** The Btrees are kept in sorted order by pBtree->pBt.  That
+** The pointers are kept in sorted order by pBtree->pBt.  That
 ** way when we go to enter all the mutexes, we can enter them
 ** in order without every having to backup and retry and without
 ** worrying about deadlock.
index b03c1e0ff0ab76d379a157997b11903ec6d05d8e..cf3a1ff7be92d165e638766121216291d2b23566 100644 (file)
@@ -9,7 +9,7 @@
 #
 #***********************************************************************
 #
-# $Id: permutations.test,v 1.11 2008/07/10 18:13:43 drh Exp $
+# $Id: permutations.test,v 1.12 2008/07/14 19:39:17 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -119,7 +119,6 @@ proc run_tests {name args} {
   }
   if {$::testmode ne "" && [lsearch $::testmode $name]<0} return
 
-
   uplevel $options(-initialize)
   set ::permutations_presql $options(-presql)
 
diff --git a/test/shared4.test b/test/shared4.test
new file mode 100644 (file)
index 0000000..c01bd26
--- /dev/null
@@ -0,0 +1,237 @@
+# 2008 July 14
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# Test the btree mutex protocol for shared cache mode.
+#
+# $Id: shared4.test,v 1.1 2008/07/14 19:39:17 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+db close
+puts hello
+
+# This script is only valid if we are running shared-cache mode in a
+# threadsafe-capable database engine.
+#
+ifcapable !shared_cache {
+  finish_test
+  return
+}
+set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
+
+# Prepare multiple databases in shared cache mode.
+#
+do_test shared4-1.1 {
+  file delete -force test1.db test1.db-journal
+  file delete -force test2.db test2.db-journal
+  file delete -force test3.db test3.db-journal
+  file delete -force test4.db test4.db-journal
+  sqlite3 db1 test1.db
+  sqlite3 db2 test2.db
+  sqlite3 db3 test3.db
+  sqlite3 db4 test4.db
+  db1 eval {
+    CREATE TABLE t1(a);
+    INSERT INTO t1 VALUES(111);
+  }
+  db2 eval {
+    CREATE TABLE t2(b);
+    INSERT INTO t2 VALUES(222);
+  }
+  db3 eval {
+    CREATE TABLE t3(c);
+    INSERT INTO t3 VALUES(333);
+  }
+  db4 eval {
+    CREATE TABLE t4(d);
+    INSERT INTO t4 VALUES(444);
+  }
+  db1 eval {
+    ATTACH DATABASE 'test2.db' AS two;
+    ATTACH DATABASE 'test3.db' AS three;
+    ATTACH DATABASE 'test4.db' AS four;
+  }
+  db2 eval {
+    ATTACH DATABASE 'test4.db' AS four;
+    ATTACH DATABASE 'test3.db' AS three;
+    ATTACH DATABASE 'test1.db' AS one;
+  }
+  db3 eval {
+    ATTACH DATABASE 'test1.db' AS one;
+    ATTACH DATABASE 'test2.db' AS two;
+    ATTACH DATABASE 'test4.db' AS four;
+  }
+  db4 eval {
+    ATTACH DATABASE 'test3.db' AS three;
+    ATTACH DATABASE 'test2.db' AS two;
+    ATTACH DATABASE 'test1.db' AS one;
+  }
+  db1 eval {
+     SELECT a FROM t1 UNION ALL
+     SELECT b FROM t2 UNION ALL
+     SELECT c FROM t3 UNION ALL
+     SELECT d FROM t4;
+  }
+} {111 222 333 444}
+do_test shared4-1.2 {
+  db2 eval {
+     SELECT a FROM t1 UNION ALL
+     SELECT b FROM t2 UNION ALL
+     SELECT d FROM t4 UNION ALL
+     SELECT c FROM t3;
+  }
+} {111 222 444 333}
+do_test shared4-1.3 {
+  db3 eval {
+     SELECT a FROM t1 UNION ALL
+     SELECT c FROM t3 UNION ALL
+     SELECT b FROM t2 UNION ALL
+     SELECT d FROM t4;
+  }
+} {111 333 222 444}
+do_test shared4-1.4 {
+  db4 eval {
+     SELECT a FROM t1 UNION ALL
+     SELECT c FROM t3 UNION ALL
+     SELECT d FROM t4 UNION ALL
+     SELECT b FROM t2;
+  }
+} {111 333 444 222}
+do_test shared4-1.5 {
+  db3 eval {
+     SELECT a FROM t1 UNION ALL
+     SELECT d FROM t4 UNION ALL
+     SELECT b FROM t2 UNION ALL
+     SELECT c FROM t3;
+  }
+} {111 444 222 333}
+do_test shared4-1.6 {
+  db4 eval {
+     SELECT a FROM t1 UNION ALL
+     SELECT d FROM t4 UNION ALL
+     SELECT c FROM t3 UNION ALL
+     SELECT b FROM t2;
+  }
+} {111 444 333 222}
+do_test shared4-1.7 {
+  db1 eval {
+     SELECT b FROM t2 UNION ALL
+     SELECT a FROM t1 UNION ALL
+     SELECT c FROM t3 UNION ALL
+     SELECT d FROM t4;
+  }
+} {222 111 333 444}
+do_test shared4-1.8 {
+  db2 eval {
+     SELECT b FROM t2 UNION ALL
+     SELECT a FROM t1 UNION ALL
+     SELECT d FROM t4 UNION ALL
+     SELECT c FROM t3;
+  }
+} {222 111 444 333}
+do_test shared4-1.9 {
+  db3 eval {
+     SELECT b FROM t2 UNION ALL
+     SELECT c FROM t3 UNION ALL
+     SELECT a FROM t1 UNION ALL
+     SELECT d FROM t4;
+  }
+} {222 333 111 444}
+do_test shared4-1.10 {
+  db4 eval {
+     SELECT b FROM t2 UNION ALL
+     SELECT c FROM t3 UNION ALL
+     SELECT d FROM t4 UNION ALL
+     SELECT a FROM t1;
+  }
+} {222 333 444 111}
+do_test shared4-1.11 {
+  db1 eval {
+     SELECT c FROM t3 UNION ALL
+     SELECT a FROM t1 UNION ALL
+     SELECT b FROM t2 UNION ALL
+     SELECT d FROM t4;
+  }
+} {333 111 222 444}
+do_test shared4-1.12 {
+  db2 eval {
+     SELECT c FROM t3 UNION ALL
+     SELECT a FROM t1 UNION ALL
+     SELECT d FROM t4 UNION ALL
+     SELECT b FROM t2;
+  }
+} {333 111 444 222}
+
+do_test shared4-2.1 {
+  db1 eval {
+    UPDATE t1 SET a=a+1000;
+    UPDATE t2 SET b=b+2000;
+    UPDATE t3 SET c=c+3000;
+    UPDATE t4 SET d=d+4000;
+  }
+  db2 eval {
+    UPDATE t1 SET a=a+10000;
+    UPDATE t2 SET b=b+20000;
+    UPDATE t3 SET c=c+30000;
+    UPDATE t4 SET d=d+40000;
+  }
+  db3 eval {
+    UPDATE t1 SET a=a+100000;
+    UPDATE t2 SET b=b+200000;
+    UPDATE t3 SET c=c+300000;
+    UPDATE t4 SET d=d+400000;
+  }
+  db4 eval {
+    UPDATE t1 SET a=a+1000000;
+    UPDATE t2 SET b=b+2000000;
+    UPDATE t3 SET c=c+3000000;
+    UPDATE t4 SET d=d+4000000;
+  }
+  db1 eval {
+     SELECT a FROM t1 UNION ALL
+     SELECT b FROM t2 UNION ALL
+     SELECT c FROM t3 UNION ALL
+     SELECT d FROM t4;
+  }
+} {1111111 2222222 3333333 4444444}
+do_test shared4-2.2 {
+  db2 eval {
+     SELECT a FROM t1 UNION ALL
+     SELECT b FROM t2 UNION ALL
+     SELECT d FROM t4 UNION ALL
+     SELECT c FROM t3;
+  }
+} {1111111 2222222 4444444 3333333}
+do_test shared4-2.3 {
+  db3 eval {
+     SELECT a FROM t1 UNION ALL
+     SELECT c FROM t3 UNION ALL
+     SELECT b FROM t2 UNION ALL
+     SELECT d FROM t4;
+  }
+} {1111111 3333333 2222222 4444444}
+do_test shared4-2.4 {
+  db4 eval {
+     SELECT a FROM t1 UNION ALL
+     SELECT c FROM t3 UNION ALL
+     SELECT d FROM t4 UNION ALL
+     SELECT b FROM t2;
+  }
+} {1111111 3333333 4444444 2222222}
+
+
+db1 close
+db2 close
+db3 close
+db4 close
+
+sqlite3_enable_shared_cache $::enable_shared_cache
+finish_test