Diff
Not logged in

Differences From:

File src/rebuild.c part of check-in [e1c1877c99] - Sync using clusters appears to work. More testing is needed before we go live. by drh on 2007-09-08 16:01:28. Also file src/rebuild.c part of check-in [bbcb6326c9] - Pulled in the navbar and timeline changes. by aku on 2007-09-17 00:58:51. [view]

To:

File src/rebuild.c part of check-in [ce1c1a2907] - Add the --randomize parameter to the rebuild command. Used for testing. by drh on 2007-09-21 18:33:13. [view]

@@ -32,11 +32,15 @@
 ** fossil repository from the blobs. This function is shared between
 ** 'rebuild_database' ('rebuild') and 'reconstruct_cmd'
 ** ('reconstruct'), both of which have to regenerate this information
 ** from scratch.
+**
+** If the randomize parameter is true, then the BLOBs are deliberately
+** extracted in a random order.  This feature is used to test the
+** ability of fossil to accept records in any order and still
+** construct a sane repository.
 */
-
-int rebuild_db(void){
+int rebuild_db(int randomize){
   Stmt s;
   int errCnt = 0;
   char *zTable;
 
@@ -57,9 +61,12 @@
   db_multi_exec("INSERT INTO unclustered SELECT rid FROM blob");
   db_multi_exec(
     "DELETE FROM config WHERE name IN ('remote-code', 'remote-maxid')"
   );
-  db_prepare(&s, "SELECT rid, size FROM blob");
+  db_prepare(&s,
+     "SELECT rid, size FROM blob %s",
+     randomize ? "ORDER BY random()" : ""
+  );
   while( db_step(&s)==SQLITE_ROW ){
     int rid = db_column_int(&s, 0);
     int size = db_column_int(&s, 1);
     if( size>=0 ){
@@ -84,17 +91,19 @@
 ** executable in a way that changes the database schema.
 */
 void rebuild_database(void){
   int forceFlag;
+  int randomizeFlag;
   int errCnt;
 
   forceFlag = find_option("force","f",0)!=0;
+  randomizeFlag = find_option("randomize", 0, 0)!=0;
   if( g.argc!=3 ){
     usage("REPOSITORY-FILENAME");
   }
   db_open_repository(g.argv[2]);
   db_begin_transaction();
-  errCnt = rebuild_db();
+  errCnt = rebuild_db(randomizeFlag);
   if( errCnt && !forceFlag ){
     printf("%d errors. Rolling back changes. Use --force to force a commit.\n",
             errCnt);
     db_end_transaction(1);