plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

syncindex.c (1275B)


      1 #include "stdinc.h"
      2 #include "dat.h"
      3 #include "fns.h"
      4 
      5 static	int	verbose;
      6 void
      7 usage(void)
      8 {
      9 	fprint(2, "usage: syncindex [-v] [-B blockcachesize] config\n");
     10 	threadexitsall("usage");
     11 }
     12 
     13 Config conf;
     14 
     15 void
     16 threadmain(int argc, char *argv[])
     17 {
     18 	u32int bcmem, icmem;
     19 
     20 	bcmem = 0;
     21 	icmem = 0;
     22 	ARGBEGIN{
     23 	case 'B':
     24 		bcmem = unittoull(EARGF(usage()));
     25 		break;
     26 	case 'I':
     27 		icmem = unittoull(EARGF(usage()));
     28 		break;
     29 	case 'v':
     30 		verbose++;
     31 		break;
     32 	default:
     33 		usage();
     34 		break;
     35 	}ARGEND
     36 
     37 	if(argc != 1)
     38 		usage();
     39 
     40 	ventifmtinstall();
     41 	if(initventi(argv[0], &conf) < 0)
     42 		sysfatal("can't init venti: %r");
     43 	if(mainindex->bloom && loadbloom(mainindex->bloom) < 0)
     44 		sysfatal("can't load bloom filter: %r");
     45 
     46 	if(bcmem < maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16))
     47 		bcmem = maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16);
     48 	if(0) fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
     49 	initdcache(bcmem);
     50 	initlumpcache(1*1024*1024, 1024/8);
     51 	initicache(icmem);
     52 	initicachewrite();
     53 	if(mainindex->bloom)
     54 		startbloomproc(mainindex->bloom);
     55 
     56 	if(verbose)
     57 		printindex(2, mainindex);
     58 	if(syncindex(mainindex) < 0)
     59 		sysfatal("failed to sync index=%s: %r", mainindex->name);
     60 	flushicache();
     61 	flushdcache();
     62 
     63 	threadexitsall(0);
     64 }