]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add test cases for the instrumentation on this branch. Fix some OOM handling transaction-pages
authordan <dan@noemail.net>
Thu, 19 Jan 2017 11:52:13 +0000 (11:52 +0000)
committerdan <dan@noemail.net>
Thu, 19 Jan 2017 11:52:13 +0000 (11:52 +0000)
issues in the same.

FossilOrigin-Name: 50ca94b919ccb462f523513fd7fe99957f0b9204

manifest
manifest.uuid
src/btree.c
test/tpages.test

index 0920577db278871c1a926ddb257d1256cf6ab15e..84bcc03f27d6cc8ecd41e89d97562f4153c86ca6 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\stemporary\scode\sto\srecord\sand\sreport\son\sthe\sset\sof\sb-tree\spages\sread\sand\nwritten\sby\sthe\scurrent\stransaction.\sThis\sis\slikely\sstill\sbuggy.
-D 2017-01-18T20:14:50.383
+C Add\stest\scases\sfor\sthe\sinstrumentation\son\sthis\sbranch.\sFix\ssome\sOOM\shandling\nissues\sin\sthe\ssame.
+D 2017-01-19T11:52:13.715
 F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
@@ -333,7 +333,7 @@ F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792
 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b
 F src/bitvec.c 263395e75ac122a7138f0797172868be700cf22a
 F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca
-F src/btree.c b0b714e311138e5f543d167b48415bf4ab6f2529
+F src/btree.c 9e3d38d2d93384c6d8b765b39c0c80b6a8a6dacd
 F src/btree.h a25d8121baf921ed56cdf5bb65a37233b4fa059a
 F src/btreeInt.h d528379e5da9aa33ef046e3c210a5d82acd2740b
 F src/build.c 9e799f1edd910dfa8a0bc29bd390d35d310596af
@@ -1318,7 +1318,7 @@ F test/tkt3992.test f3e7d548ac26f763b47bc0f750da3d03c81071da
 F test/tkt3997.test a335fa41ca3985660a139df7b734a26ef53284bd
 F test/tkt4018.test 18dbc6617f7a4b90e938d1bd6d26ad18daafaf08
 F test/tokenize.test ce430a7aed48fc98301611429595883fdfcab5d7
-F test/tpages.test abcb738d7a61a62ee60b00ac37eeb987f4919062
+F test/tpages.test 20b7cae49b46fae6aacdd14a44f531a5a1fab33f
 F test/tpch01.test 04adbf8d8300fa60a222f28d901abd76e7be6dd4
 F test/trace.test 6f676313e3ebd2a50585036d2f212a3319dd5836
 F test/trace2.test f5cb67ad3bc09e0c58e8cca78dfd0b5639259983
@@ -1548,10 +1548,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 681d96eb822e606da53700867191d4738bda20c8
-R d3876579ed9b8addfbb830510866c4e1
-T *branch * transaction-pages
-T *sym-transaction-pages *
-T -sym-trunk *
+P 2a8f6c890cfa5f61b491ddf8f560b6ba8c6cdc32
+R ae523458281bb3a9a28803814e720ed6
 U dan
-Z 49b44b310f5c3b7319ea5dbf5a0bd059
+Z 5b5cdeb9ebac248f4328063c950d744e
index 41195ecdea192f9c2375c83391a6783e9824e30c..ed5577773e6e92209b7a97ee7bffae4a44edecaa 100644 (file)
@@ -1 +1 @@
-2a8f6c890cfa5f61b491ddf8f560b6ba8c6cdc32
\ No newline at end of file
+50ca94b919ccb462f523513fd7fe99957f0b9204
\ No newline at end of file
index 8142d41433a06aa1a3d978cb271ed30aa281588c..3261795b8ffccef1d73a3170973649384c21d946 100644 (file)
@@ -3119,6 +3119,27 @@ int sqlite3BtreeNewDb(Btree *p){
   return rc;
 }
 
+#ifdef SQLITE_ENABLE_TRANSACTION_PAGES
+/*
+** If the b-tree is not currently in a write transaction, free the various
+** resources allocated for the sqlite3_transaction_pages() functionality.
+*/
+static void freeTransactionPagesBitvec(BtShared *pBt){
+  if( pBt->inTransaction!=TRANS_WRITE ){
+    sqlite3BitvecDestroy(pBt->pBtRead);
+    sqlite3BitvecDestroy(pBt->pBtWrite);
+    sqlite3BitvecDestroy(pBt->pBtAlloc);
+    pBt->pBtAlloc = pBt->pBtRead = pBt->pBtWrite = 0;
+    sqlite3_free(pBt->aiRead);
+    sqlite3_free(pBt->aiWrite);
+    pBt->aiRead = pBt->aiWrite = 0;
+    pBt->nRead = pBt->nWrite = 0;
+  }
+}
+#else
+# define freeTransactionPagesBitvec(x) 
+#endif
+
 /*
 ** Attempt to start a new transaction. A write-transaction
 ** is started if the second argument is nonzero, otherwise a read-
@@ -3204,6 +3225,20 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag){
   }
 #endif
 
+#ifdef SQLITE_ENABLE_TRANSACTION_PAGES
+  if( wrflag ){
+    assert( pBt->pBtRead==0 && pBt->pBtWrite==0 && pBt->pBtAlloc==0 );
+    assert( rc==SQLITE_OK );
+    pBt->pBtRead = sqlite3BitvecCreate(pBt->nPage);
+    pBt->pBtWrite = sqlite3BitvecCreate(pBt->nPage);
+    pBt->pBtAlloc = sqlite3BitvecCreate(pBt->nPage);
+    if( pBt->pBtRead==0 || pBt->pBtWrite==0 || pBt->pBtAlloc==0 ){
+      rc = SQLITE_NOMEM;
+      goto trans_begun;
+    }
+  }
+#endif
+
   /* Any read-only or read-write transaction implies a read-lock on 
   ** page 1. So if some other shared-cache client already has a write-lock 
   ** on page 1, the transaction cannot be opened. */
@@ -3279,22 +3314,6 @@ int sqlite3BtreeBeginTrans(Btree *p, int wrflag){
     }
   }
 
-#ifdef SQLITE_ENABLE_TRANSACTION_PAGES
-  if( rc==SQLITE_OK && wrflag ){
-    assert( pBt->pBtRead==0 && pBt->pBtWrite==0 );
-    pBt->pBtRead = sqlite3BitvecCreate(pBt->nPage);
-    pBt->pBtWrite = sqlite3BitvecCreate(pBt->nPage);
-    pBt->pBtAlloc = sqlite3BitvecCreate(pBt->nPage);
-    if( pBt->pBtRead==0 || pBt->pBtWrite==0 || pBt->pBtAlloc==0 ){
-      rc = SQLITE_NOMEM;
-      sqlite3BitvecDestroy(pBt->pBtRead);
-      sqlite3BitvecDestroy(pBt->pBtWrite);
-      sqlite3BitvecDestroy(pBt->pBtAlloc);
-      pBt->pBtAlloc = pBt->pBtRead = pBt->pBtWrite = 0;
-    }
-  }
-#endif
-
 trans_begun:
   if( rc==SQLITE_OK && wrflag ){
     /* This call makes sure that the pager has the correct number of
@@ -3304,6 +3323,7 @@ trans_begun:
     rc = sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint);
   }
 
+  freeTransactionPagesBitvec(pBt);
   btreeIntegrity(p);
   sqlite3BtreeLeave(p);
   return rc;
@@ -3818,19 +3838,7 @@ static void btreeEndTransaction(Btree *p){
     unlockBtreeIfUnused(pBt);
   }
 
-#ifdef SQLITE_ENABLE_TRANSACTION_PAGES
-  if( pBt->inTransaction!=TRANS_WRITE ){
-    sqlite3BitvecDestroy(pBt->pBtRead);
-    sqlite3BitvecDestroy(pBt->pBtWrite);
-    sqlite3BitvecDestroy(pBt->pBtAlloc);
-    pBt->pBtAlloc = pBt->pBtRead = pBt->pBtWrite = 0;
-    sqlite3_free(pBt->aiRead);
-    sqlite3_free(pBt->aiWrite);
-    pBt->aiRead = pBt->aiWrite = 0;
-    pBt->nRead = pBt->nWrite = 0;
-  }
-#endif
-
+  freeTransactionPagesBitvec(pBt);
   btreeIntegrity(p);
 }
 
index e6fd8c8d19cae8bb6fc2f48ceb7b127700365891..7b03e15a2c90b79f902979245e52d8644fead027 100644 (file)
@@ -44,7 +44,6 @@ foreach {n1 n2} {
    6000 1000
    7000 1000
 } {
-
   set n1 [expr $n1]
   set n2 [expr $n2]
 
@@ -79,7 +78,67 @@ foreach {n1 n2} {
   execsql cOMMIT
 }
 
+#-------------------------------------------------------------------------
+#
+proc do_transaction_pages_test {tn sql pages} {
+  uplevel [list execsql $sql]
+  uplevel [list \
+    do_test $tn {sqlite3_transaction_pages db main} [list {*}$pages]
+  ]
+}
+reset_db
+do_transaction_pages_test 2.0 {
+  PRAGMA auto_vacuum = 0;
+  PRAGMA page_size = 1024;
+  CREATE TABLE t1(x);
+  BEGIN;
+    INSERT INTO t1 VALUES(randomblob(1500));
+} {2 2}
+
+do_transaction_pages_test 2.1 {
+  COMMIT;
+  BEGIN;
+    DELETE FROM t1;
+} {2 2}
+
+reset_db
+do_execsql_test 2.2 {
+  PRAGMA auto_vacuum = 0;
+  PRAGMA page_size = 1024;
+  CREATE TABLE t1(x);
+  INSERT INTO t1 VALUES(randomblob(900));
+  INSERT INTO t1 VALUES(randomblob(900));
+  CREATE TABLE t2(y);
+}  
 
+do_transaction_pages_test 2.3 {
+  BEGIN;
+    UPDATE t1 SET x=randomblob(899);
+} {{2 3 4} {3 4}}
 
+do_transaction_pages_test 2.4 {
+    DELETE FROM t1;
+  COMMIT;
+} {{} {}}
+
+do_transaction_pages_test 2.5 {
+  BEGIN;
+    INSERT INTO t2 VALUES(randomblob(900));
+    INSERT INTO t2 VALUES(randomblob(900));
+} {5 5}
+
+do_transaction_pages_test 2.6 {
+  COMMIT;
+  BEGIN;
+    INSERT INTO t1 VALUES(randomblob(900));
+} {2 2}
+
+do_transaction_pages_test 2.7 {
+    INSERT INTO t1 VALUES(randomblob(900));
+    INSERT INTO t1 VALUES(randomblob(900));
+    INSERT INTO t1 VALUES(randomblob(900));
+    INSERT INTO t1 VALUES(randomblob(900));
+} {2 2}
 
 finish_test
+