6 writebucket(Index *ix, u32int buck, IBucket *ib, ZBlock *b)
10 is = findisect(ix, buck);
12 seterr(EAdmin, "bad math in writebucket");
15 if(buck < is->start || buck >= is->stop)
16 seterr(EAdmin, "index write out of bounds: %d not in [%d,%d)\n",
17 buck, is->start, is->stop);
22 packibucket(ib, b->data);
23 return writepart(is->part, is->blockbase + ((u64int)buck << is->blocklog), b->data, is->blocksize);
27 buildindex(Index *ix, Part *part, u64int off, u64int clumps, int zero)
36 //ZZZ make buffer size configurable
37 b = alloczblock(ix->blocksize, 0);
38 z = alloczblock(ix->blocksize, 1);
39 ies = initiestream(part, off, clumps, 64*1024);
40 if(b == nil || z == nil || ies == nil){
47 ib.data = b->data + IBucketSize;
48 zib.data = z->data + IBucketSize;
52 buck = buildbucket(ix, ies, &ib);
55 for(; next != buck; next++){
56 if(next == ix->buckets){
58 fprint(2, "bucket out of range\n");
63 if(writebucket(ix, next, &zib, z) < 0){
64 fprint(2, "can't write zero bucket to buck=%d: %r", next);
69 if(buck >= ix->buckets){
72 fprint(2, "bucket out of range\n");
76 if(writebucket(ix, buck, &ib, b) < 0){
77 fprint(2, "bad bucket found=%lld: %r\n", found);
83 fprint(2, "constructed index with %lld entries\n", found);
93 fprint(2, "usage: buildindex [-Z] [-B blockcachesize] config tmppart\n");
98 threadmain(int argc, char *argv[])
109 bcmem = unittoull(ARGF());
122 if(initventi(argv[0]) < 0)
123 sysfatal("can't init venti: %r");
125 if(bcmem < maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16))
126 bcmem = maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16);
127 fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
130 fprint(2, "building a new index %s using %s for temporary storage\n", mainindex->name, argv[1]);
132 part = initpart(argv[1], 1);
134 sysfatal("can't initialize temporary partition: %r");
136 clumps = sortrawientries(mainindex, part, &base);
138 sysfatal("can't build sorted index: %r");
139 fprint(2, "found and sorted index entries for clumps=%lld at %lld\n", clumps, base);
141 if(buildindex(mainindex, part, base, clumps, zero) < 0)
142 sysfatal("can't build new index: %r");