Fossil SCM

Add --vacuum, --wal, and --pagesize options to the "rebuild" command.

drh 2011-02-25 14:49 trunk
Commit e166ea6aebffd12f904e3ab97fd896f580a218ed
1 file changed +32
--- src/rebuild.c
+++ src/rebuild.c
@@ -355,22 +355,40 @@
355355
**
356356
** --noverify Skip the verification of changes to the BLOB table
357357
** --force Force the rebuild to complete even if errors are seen
358358
** --randomize Scan artifacts in a random order
359359
** --cluster Compute clusters for unclustered artifacts
360
+** --pagesize N Set the database pagesize to N. (512..65536 and power of 2)
361
+** --wal Set Write-Ahead-Log journalling mode on the database
362
+** --vacuum Run VACUUM on the database after rebuilding
360363
*/
361364
void rebuild_database(void){
362365
int forceFlag;
363366
int randomizeFlag;
364367
int errCnt;
365368
int omitVerify;
366369
int doClustering;
370
+ const char *zPagesize;
371
+ int newPagesize = 0;
372
+ int activateWal;
373
+ int runVacuum;
367374
368375
omitVerify = find_option("noverify",0,0)!=0;
369376
forceFlag = find_option("force","f",0)!=0;
370377
randomizeFlag = find_option("randomize", 0, 0)!=0;
371378
doClustering = find_option("cluster", 0, 0)!=0;
379
+ runVacuum = find_option("vacuum",0,0)!=0;
380
+ zPagesize = find_option("pagesize",0,1);
381
+ if( zPagesize ){
382
+ newPagesize = atoi(zPagesize);
383
+ if( newPagesize<512 || newPagesize>65536
384
+ || (newPagesize&(newPagesize-1))!=0
385
+ ){
386
+ fossil_fatal("page size must be a power of two between 512 and 65536");
387
+ }
388
+ }
389
+ activateWal = find_option("wal",0,0)!=0;
372390
if( g.argc==3 ){
373391
db_open_repository(g.argv[2]);
374392
}else{
375393
db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
376394
if( g.argc!=2 ){
@@ -392,10 +410,24 @@
392410
errCnt);
393411
db_end_transaction(1);
394412
}else{
395413
if( omitVerify ) verify_cancel();
396414
db_end_transaction(0);
415
+ db_close(0);
416
+ db_open_repository(g.zRepositoryName);
417
+ if( newPagesize ){
418
+ db_multi_exec("PRAGMA page_size=%d", newPagesize);
419
+ runVacuum = 1;
420
+ }
421
+ if( runVacuum ){
422
+ printf("Vacuuming the database... "); fflush(stdout);
423
+ db_multi_exec("VACUUM");
424
+ printf("done\n");
425
+ }
426
+ if( activateWal ){
427
+ db_multi_exec("PRAGMA journal_mode=WAL;");
428
+ }
397429
}
398430
}
399431
400432
/*
401433
** COMMAND: test-detach ?REPOSITORY?
402434
--- src/rebuild.c
+++ src/rebuild.c
@@ -355,22 +355,40 @@
355 **
356 ** --noverify Skip the verification of changes to the BLOB table
357 ** --force Force the rebuild to complete even if errors are seen
358 ** --randomize Scan artifacts in a random order
359 ** --cluster Compute clusters for unclustered artifacts
 
 
 
360 */
361 void rebuild_database(void){
362 int forceFlag;
363 int randomizeFlag;
364 int errCnt;
365 int omitVerify;
366 int doClustering;
 
 
 
 
367
368 omitVerify = find_option("noverify",0,0)!=0;
369 forceFlag = find_option("force","f",0)!=0;
370 randomizeFlag = find_option("randomize", 0, 0)!=0;
371 doClustering = find_option("cluster", 0, 0)!=0;
 
 
 
 
 
 
 
 
 
 
 
372 if( g.argc==3 ){
373 db_open_repository(g.argv[2]);
374 }else{
375 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
376 if( g.argc!=2 ){
@@ -392,10 +410,24 @@
392 errCnt);
393 db_end_transaction(1);
394 }else{
395 if( omitVerify ) verify_cancel();
396 db_end_transaction(0);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
397 }
398 }
399
400 /*
401 ** COMMAND: test-detach ?REPOSITORY?
402
--- src/rebuild.c
+++ src/rebuild.c
@@ -355,22 +355,40 @@
355 **
356 ** --noverify Skip the verification of changes to the BLOB table
357 ** --force Force the rebuild to complete even if errors are seen
358 ** --randomize Scan artifacts in a random order
359 ** --cluster Compute clusters for unclustered artifacts
360 ** --pagesize N Set the database pagesize to N. (512..65536 and power of 2)
361 ** --wal Set Write-Ahead-Log journalling mode on the database
362 ** --vacuum Run VACUUM on the database after rebuilding
363 */
364 void rebuild_database(void){
365 int forceFlag;
366 int randomizeFlag;
367 int errCnt;
368 int omitVerify;
369 int doClustering;
370 const char *zPagesize;
371 int newPagesize = 0;
372 int activateWal;
373 int runVacuum;
374
375 omitVerify = find_option("noverify",0,0)!=0;
376 forceFlag = find_option("force","f",0)!=0;
377 randomizeFlag = find_option("randomize", 0, 0)!=0;
378 doClustering = find_option("cluster", 0, 0)!=0;
379 runVacuum = find_option("vacuum",0,0)!=0;
380 zPagesize = find_option("pagesize",0,1);
381 if( zPagesize ){
382 newPagesize = atoi(zPagesize);
383 if( newPagesize<512 || newPagesize>65536
384 || (newPagesize&(newPagesize-1))!=0
385 ){
386 fossil_fatal("page size must be a power of two between 512 and 65536");
387 }
388 }
389 activateWal = find_option("wal",0,0)!=0;
390 if( g.argc==3 ){
391 db_open_repository(g.argv[2]);
392 }else{
393 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
394 if( g.argc!=2 ){
@@ -392,10 +410,24 @@
410 errCnt);
411 db_end_transaction(1);
412 }else{
413 if( omitVerify ) verify_cancel();
414 db_end_transaction(0);
415 db_close(0);
416 db_open_repository(g.zRepositoryName);
417 if( newPagesize ){
418 db_multi_exec("PRAGMA page_size=%d", newPagesize);
419 runVacuum = 1;
420 }
421 if( runVacuum ){
422 printf("Vacuuming the database... "); fflush(stdout);
423 db_multi_exec("VACUUM");
424 printf("done\n");
425 }
426 if( activateWal ){
427 db_multi_exec("PRAGMA journal_mode=WAL;");
428 }
429 }
430 }
431
432 /*
433 ** COMMAND: test-detach ?REPOSITORY?
434

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button