]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the ".integrity_check" command to tserver.
authordan <dan@noemail.net>
Tue, 18 Dec 2018 16:24:21 +0000 (16:24 +0000)
committerdan <dan@noemail.net>
Tue, 18 Dec 2018 16:24:21 +0000 (16:24 +0000)
FossilOrigin-Name: fa46fa3bfcd4b6d1d219db4179ce69d0edb0786a521acaa034fdb74b312274ff

manifest
manifest.uuid
tool/tserver.c
tool/tserver_test.tcl

index 1ed1e81b4b6db347fe31b867178b66758db7cfeb..36dd0b926f7ae3a76ef232dec1872daabb2e7553 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\swal2\srelated\stests\sto\sthis\sbranch.
-D 2018-12-17T18:26:48.041
+C Add\sthe\s".integrity_check"\scommand\sto\stserver.
+D 2018-12-18T16:24:21.581
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in 68d0ba0f0b533d5bc84c78c13a6ce84ee81183a67014caa47a969e67f028fa1c
@@ -1779,8 +1779,8 @@ F tool/srcck1.c 371de5363b70154012955544f86fdee8f6e5326f
 F tool/stack_usage.tcl f8e71b92cdb099a147dad572375595eae55eca43
 F tool/symbols-mingw.sh 4dbcea7e74768305384c9fd2ed2b41bbf9f0414d
 F tool/symbols.sh c5a617b8c61a0926747a56c65f5671ef8ac0e148
-F tool/tserver.c 46ef565f79b326a86b696ae255548cf841fafae10dda7b6a2027b323f4ee6dac
-F tool/tserver_test.tcl 777e1e4f26c1bf47fecdb61ce46e1db36c209a81956ccfd9e2d957377b54974f
+F tool/tserver.c 434336a4566415b6917d1b9cf1834cbb3a5b03756c6ad83bbe68f135f64c68e5
+F tool/tserver_test.tcl 54f4e543cbef41bf4b061e1774fa2af6c7ed89e5982316a3c10080fac6203b56
 F tool/varint.c 5d94cb5003db9dbbcbcc5df08d66f16071aee003
 F tool/vdbe-compress.tcl 5926c71f9c12d2ab73ef35c29376e756eb68361c
 F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f
@@ -1808,7 +1808,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 85f49f0d7344611ac4157421273660c648f73ca62afa4faa8707475f21c67f7a
-R 65f394733f0ba62dea4c1755dadbd201
+P 5645822039b9f36aeb986645106cac2d95b09964689deb767cadaa6ea1d1867f
+R c457a89f51ce15a2bf7d5fa21f5a871c
 U dan
-Z 04eed859c773bffbf8a57cb8193cc4eb
+Z 2113a4a090e26cc6c885bd681bc557d4
index d9d3e057b4ac8d46a84beb47701b02cf30c3c7e1..99ddef66b5c499b660aa64a753e6312722b1ad40 100644 (file)
@@ -1 +1 @@
-5645822039b9f36aeb986645106cac2d95b09964689deb767cadaa6ea1d1867f
\ No newline at end of file
+fa46fa3bfcd4b6d1d219db4179ce69d0edb0786a521acaa034fdb74b312274ff
\ No newline at end of file
index c2dc35b4f8bf8b447e878069127d4d19b58cfd99..6916a5781edf527fd7706865175ca5a03a31cbb6 100644 (file)
@@ -35,6 +35,8 @@
 **   .mutex_commit            Add a "COMMIT" protected by a g.commit_mutex
 **                            to the current SQL.
 **   .stop                    Stop the tserver process - exit(0).
+**   .checkpoint N
+**   .integrity_check
 **
 ** Example input:
 **
@@ -87,9 +89,12 @@ static struct TserverGlobal g = {0};
 typedef struct ClientSql ClientSql;
 struct ClientSql {
   sqlite3_stmt *pStmt;
-  int bMutex;
+  int flags;
 };
 
+#define TSERVER_CLIENTSQL_MUTEX     0x0001
+#define TSERVER_CLIENTSQL_INTEGRITY 0x0002
+
 typedef struct ClientCtx ClientCtx;
 struct ClientCtx {
   sqlite3 *db;                    /* Database handle for this client */
@@ -248,18 +253,27 @@ static int handle_run_command(ClientCtx *p){
     for(i=0; i<p->nPrepare && rc==SQLITE_OK; i++){
       sqlite3_stmt *pStmt = p->aPrepare[i].pStmt;
 
-      /* If the bMutex flag is set, grab g.commit_mutex before executing
+      /* If the MUTEX flag is set, grab g.commit_mutex before executing
       ** the SQL statement (which is always "COMMIT" in this case). */
-      if( p->aPrepare[i].bMutex ){
+      if( p->aPrepare[i].flags & TSERVER_CLIENTSQL_MUTEX ){
         sqlite3_mutex_enter(g.commit_mutex);
       }
 
       /* Execute the statement */
+      if( p->aPrepare[i].flags & TSERVER_CLIENTSQL_INTEGRITY ){
+        sqlite3_step(pStmt);
+        if( sqlite3_stricmp("ok", sqlite3_column_text(pStmt, 0)) ){
+          send_message(p, "error - integrity_check failed: %s\n", 
+              sqlite3_column_text(pStmt, 0)
+          );
+        }
+        sqlite3_reset(pStmt);
+      }
       while( sqlite3_step(pStmt)==SQLITE_ROW );
       rc = sqlite3_reset(pStmt);
 
       /* Relinquish the g.commit_mutex mutex if required. */
-      if( p->aPrepare[i].bMutex ){
+      if( p->aPrepare[i].flags & TSERVER_CLIENTSQL_MUTEX ){
         sqlite3_mutex_leave(g.commit_mutex);
       }
 
@@ -315,6 +329,7 @@ static int handle_run_command(ClientCtx *p){
 
     if( rc==SQLITE_OK && p->bClientCkptRequired ){
       rc = sqlite3_wal_checkpoint(p->db, "main");
+      if( rc==SQLITE_BUSY ) rc = SQLITE_OK;
       assert( rc==SQLITE_OK );
       p->bClientCkptRequired = 0;
     }
@@ -363,7 +378,7 @@ static int handle_dot_command(ClientCtx *p, const char *zCmd, int nCmd){
   }
 
   else if( n>=1 && n<=4 && 0==strncmp(z, "quit", n) ){
-    rc = 1;
+    rc = -1;
   }
 
   else if( n>=2 && n<=7 && 0==strncmp(z, "repeats", n) ){
@@ -389,7 +404,7 @@ static int handle_dot_command(ClientCtx *p, const char *zCmd, int nCmd){
   else if( n>=1 && n<=12 && 0==strncmp(z, "mutex_commit", n) ){
     rc = handle_some_sql(p, "COMMIT;", 7);
     if( rc==SQLITE_OK ){
-      p->aPrepare[p->nPrepare-1].bMutex = 1;
+      p->aPrepare[p->nPrepare-1].flags |= TSERVER_CLIENTSQL_MUTEX;
     }
   }
 
@@ -405,11 +420,18 @@ static int handle_dot_command(ClientCtx *p, const char *zCmd, int nCmd){
     exit(0);
   }
 
+  else if( n>=2 && n<=15 && 0==strncmp(z, "integrity_check", n) ){
+    rc = handle_some_sql(p, "PRAGMA integrity_check;", 23);
+    if( rc==SQLITE_OK ){
+      p->aPrepare[p->nPrepare-1].flags |= TSERVER_CLIENTSQL_INTEGRITY;
+    }
+  }
+
   else{
     send_message(p, 
         "unrecognized dot command: %.*s\n"
         "should be \"list\", \"run\", \"repeats\", \"mutex_commit\", "
-        "\"checkpoint\" or \"seconds\"\n", n, z
+        "\"checkpoint\", \"integrity_check\" or \"seconds\"\n", n, z
     );
     rc = 1;
   }
@@ -506,7 +528,7 @@ static void *handle_client(void *pArg){
     }while( rc==SQLITE_OK && nConsume>0 );
   }
 
-  fprintf(stdout, "Client %d disconnects\n", ctx.fd);
+  fprintf(stdout, "Client %d disconnects (rc=%d)\n", ctx.fd, rc);
   fflush(stdout);
   close(ctx.fd);
   clear_sql(&ctx);
index 39dec56b3c718887f0687ca0de5e619a79828d93..3ef1a905983aa163ba85f05f53146e690fa6f84e 100644 (file)
@@ -8,14 +8,15 @@
 package require sqlite3
 
 # Default values for command line switches:
-set O(-database) ""
-set O(-rows)     [expr 5000000]
-set O(-mode)     wal2
-set O(-tserver)  "./tserver"
-set O(-seconds)  20
-set O(-writers)  1
-set O(-readers)  0
-set O(-verbose)  0
+set O(-database)  ""
+set O(-rows)      [expr 5000000]
+set O(-mode)      wal2
+set O(-tserver)   "./tserver"
+set O(-seconds)   20
+set O(-writers)   1
+set O(-readers)   0
+set O(-integrity) 0
+set O(-verbose)   0
 
 
 proc error_out {err} {
@@ -34,6 +35,7 @@ proc usage {} {
   puts stderr "  -seconds <time to run for in seconds> (default: 20)"
   puts stderr "  -writers <number of writer clients>   (default: 1)"
   puts stderr "  -readers <number of reader clients>   (default: 0)"
+  puts stderr "  -integrity <number of IC clients>     (default: 0)"
   puts stderr "  -verbose 0|1                          (default: 0)"
   exit -1
 }
@@ -248,6 +250,14 @@ proc script_reader {} {
   }]
 }
 
+proc script_integrity {} {
+  global O
+
+  return {
+    .integrity_check
+  }
+}
+
 
 create_test_database
 tserver_start
@@ -258,10 +268,14 @@ for {set i 0} {$i < $O(-writers)} {incr i} {
 for {set i 0} {$i < $O(-readers)} {incr i} {
   client_launch r.$i [script_reader]
 }
+for {set i 0} {$i < $O(-integrity)} {incr i} {
+  client_launch i.$i [script_integrity]
+}
 client_wait
 
 set name(w) "Writers"
 set name(r) "Readers"
+set name(i) "Integrity"
 foreach r $::client_output {
   array set a $r
   set type [string range $a(name) 0 0]