Diff
Not logged in

Differences From:

File src/verify.c part of check-in [edbb332d54] - The xfer mechanism has been completely reworked to better support delta compression and to require fewer round-trips. The wire protocol is roughly the same but is different enough that you will need to recompile before sync will work. by drh on 2007-08-10 02:59:52. [view]

To:

File src/verify.c part of check-in [d5e7891b07] - Add a more advanced commit-hook mechanism that allows us to specify multiple procedures in a particular order prior to commit. Continuing work toward getting tickets going. by drh on 2007-11-18 20:48:07. Also file src/verify.c part of check-in [d0305b305a] - Merged mainline into my branch to get the newest application. by aku on 2007-12-05 08:07:46. [view]

@@ -21,9 +21,15 @@
 **
 *******************************************************************************
 **
 ** This file contains code used to help verify the integrity of the
-** the repository
+** the repository.
+**
+** This file primarily implements the verify_before_commit() interface.
+** Any function can call verify_before_commit() with a record id (RID)
+** as an argument.  Then before the next change to the database commits,
+** this routine will reach in and check that the record can be extracted
+** correctly from the BLOB table.
 */
 #include "config.h"
 #include "verify.h"
 #include <assert.h>
@@ -57,19 +63,27 @@
   blob_reset(&uuid);
 }
 
 /*
-**
+** The following bag holds the rid for every record that needs
+** to be verified.
+*/
+static Bag toVerify;
+static int inFinalVerify = 0;
+
+/*
+** This routine is called just prior to each commit operation.
 */
-static int verify_at_commit(void *notUsed){
-  Stmt q;
-  db_prepare(&q, "SELECT rid FROM toverify");
-  while( db_step(&q)==SQLITE_ROW ){
-    int rid = db_column_int(&q, 0);
+static int verify_at_commit(void){
+  int rid;
+  inFinalVerify = 1;
+  rid = bag_first(&toVerify);
+  while( rid>0 ){
     verify_rid(rid);
+    rid = bag_next(&toVerify, rid);
   }
-  db_finalize(&q);
-  db_multi_exec("DELETE FROM toverify");
+  bag_clear(&toVerify);
+  inFinalVerify = 0;
   return 0;
 }
 
 /*
@@ -81,18 +95,14 @@
 */
 void verify_before_commit(int rid){
   static int isInit = 0;
   if( !isInit ){
-    db_multi_exec(
-       "CREATE TEMP TABLE toverify(rid INTEGER PRIMARY KEY);"
-    );
-    sqlite3_commit_hook(g.db, verify_at_commit, 0);
+    db_commit_hook(verify_at_commit, 1000);
     isInit = 1;
   }
+  assert( !inFinalVerify );
   if( rid>0 ){
-    db_multi_exec(
-      "INSERT OR IGNORE INTO toverify VALUES(%d)", rid
-    );
+    bag_insert(&toVerify, rid);
   }
 }
 
 /*
@@ -101,12 +111,17 @@
 ** Verify all records in the repository.
 */
 void verify_all_cmd(void){
   Stmt q;
+  int cnt = 0;
   db_must_be_within_tree();
   db_prepare(&q, "SELECT rid FROM blob");
   while( db_step(&q)==SQLITE_ROW ){
     int rid = db_column_int(&q, 0);
-    verify_rid(rid);
+    verify_before_commit(rid);
+    cnt++;
+    assert( bag_count(&toVerify)==cnt );
   }
   db_finalize(&q);
+  verify_at_commit();
+  assert( bag_count(&toVerify)==0 );
 }