Blob


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