2 * Rebuild the Venti index from scratch.
10 * Write a single bucket. Could profit from a big buffer here
11 * so that we can absorb sporadic runs of blocks into one write,
12 * avoiding disk seeks.
15 writebucket(Index *ix, u32int buck, IBucket *ib, ZBlock *b)
19 is = ix->sects[indexsect0(ix, buck)];
20 if(buck < is->start || buck >= is->stop){
21 seterr(EAdmin, "cannot find index section for bucket %lud\n", (ulong)buck);
31 packibucket(ib, b->data, is->bucketmagic);
32 return writepart(is->part, is->blockbase + ((u64int)buck << is->blocklog), b->data, is->blocksize);
36 buildindex(Index *ix, Part *part, u64int off, u64int clumps, int zero)
46 //ZZZ make buffer size configurable
47 b = alloczblock(ix->blocksize, 0, ix->blocksize);
48 z = alloczblock(ix->blocksize, 1, ix->blocksize);
49 ies = initiestream(part, off, clumps, 64*1024);
50 if(b == nil || z == nil || ies == nil){
57 memset(&ib, 0, sizeof ib);
58 ib.data = b->data + IBucketSize;
59 zib.data = z->data + IBucketSize;
63 buck = buildbucket(ix, ies, &ib, ix->blocksize-IBucketSize);
66 for(; next != buck; next++){
67 if(next == ix->buckets){
69 fprint(2, "bucket out of range\n");
74 if(writebucket(ix, next, &zib, z) < 0){
75 fprint(2, "can't write zero bucket to buck=%d: %r", next);
80 if(buck >= ix->buckets){
83 fprint(2, "bucket out of range\n");
87 if(writebucket(ix, buck, &ib, b) < 0){
88 fprint(2, "bad bucket found=%lld: %r\n", found);
92 if(++nbuck%10000 == 0)
93 fprint(2, "\t%,d buckets written...\n", nbuck);
96 fprint(2, "wrote index with %lld entries\n", found);
106 fprint(2, "usage: buildindex [-Z] [-B blockcachesize] config tmppart\n");
113 threadmain(int argc, char *argv[])
125 bcmem = unittoull(ARGF());
138 if(initventi(argv[0], &conf) < 0)
139 sysfatal("can't init venti: %r");
141 if(bcmem < maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16))
142 bcmem = maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16);
143 if(0) fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
146 fprint(2, "building a new index %s using %s for temporary storage\n", mainindex->name, argv[1]);
148 part = initpart(argv[1], ORDWR|ODIRECT);
150 sysfatal("can't initialize temporary partition: %r");
152 clumps = sortrawientries(mainindex, part, &base, mainindex->bloom);
154 sysfatal("can't build sorted index: %r");
155 fprint(2, "found and sorted index entries for clumps=%lld at %lld\n", clumps, base);
157 if(buildindex(mainindex, part, base, clumps, zero) < 0)
158 sysfatal("can't build new index: %r");
161 writebloom(mainindex->bloom);