Check-in [ce1c1a2907]
Not logged in
Overview

SHA1 Hash:ce1c1a2907e9aa10c0426a1a9bb148e43242ae89
Date: 2007-09-21 18:33:13
User: drh
Comment:Add the --randomize parameter to the rebuild command. Used for testing.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/construct.c from [10bb790daf] to [238e2858a9].

@@ -154,15 +154,15 @@
 
   printf("imported:   %d %s\n", fileCnt, fileCnt == 1 ?
 	 "file" : "files");
 
   /* Finalize the repository, rebuild the derived tables */
-  errCnt = rebuild_db ();
+  errCnt = rebuild_db(0);
 
   if( errCnt ){
     printf("%d %s. Rolling back changes.\n", errCnt, errCnt == 1 ?
 	   "error" : "errors");
     db_end_transaction(1);
   }else{
     db_end_transaction(0);
   }
 }

Modified src/rebuild.c from [45c4994360] to [6a267b5a25].

@@ -31,13 +31,17 @@
 ** Core function to rebuild the infomration in the derived tables of a
 ** 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;
 
   db_multi_exec(
@@ -56,11 +60,14 @@
 
   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 ){
       Blob content;
@@ -83,22 +90,24 @@
 ** records.  Run this command after updating the fossil
 ** 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);
   }else{
     db_end_transaction(0);
   }
 }