6 checkbucket(Index *ix, u32int buck, IBucket *ib)
14 is = findisect(ix, buck);
16 seterr(EAdmin, "bad math in checkbuckets");
20 eb = getdblock(is->part, is->blockbase + ((u64int)buck << is->blocklog), 1);
23 unpackibucket(&eib, eb->data);
27 for(i = 0; i < ib->n; i++){
29 c = ientrycmp(&ib->data[i * IEntrySize], &eib.data[ei * IEntrySize]);
31 unpackientry(&ie, &ib->data[i * IEntrySize]);
32 unpackientry(&eie, &eib.data[ei * IEntrySize]);
33 if(iaddrcmp(&ie.ia, &eie.ia) != 0){
34 fprint(2, "bad entry in index for score=%V\n", &ib->data[i * IEntrySize]);
35 fprint(2, "\taddr=%lld type=%d size=%d blocks=%d\n",
36 ie.ia.addr, ie.ia.type, ie.ia.size, ie.ia.blocks);
37 fprint(2, "\taddr=%lld type=%d size=%d blocks=%d\n",
38 eie.ia.addr, eie.ia.type, eie.ia.size, eie.ia.blocks);
46 fprint(2, "spurious entry in index for score=%V type=%d\n",
47 &eib.data[ei * IEntrySize], eib.data[ei * IEntrySize + IEntryTypeOff]);
51 fprint(2, "missing entry in index for score=%V type=%d\n",
52 &ib->data[i * IEntrySize], ib->data[i * IEntrySize + IEntryTypeOff]);
56 for(; ei < eib.n; ei++){
57 if(1) fprint(2, "spurious entry in index for score=%V; found %d entries expected %d\n",
58 &eib.data[ei * IEntrySize], eib.n, ib->n);
67 checkindex(Index *ix, Part *part, u64int off, u64int clumps, int zero)
76 //ZZZ make buffer size configurable
77 b = alloczblock(ix->blocksize, 0);
78 z = alloczblock(ix->blocksize, 1);
79 ies = initiestream(part, off, clumps, 64*1024);
80 if(b == nil || z == nil || ies == nil){
92 buck = buildbucket(ix, ies, &ib);
95 for(; next != buck; next++){
96 if(next == ix->buckets){
98 fprint(2, "bucket out of range\n");
101 bok = checkbucket(ix, next, &zib);
103 fprint(2, "bad bucket=%d found: %r\n", next);
108 if(buck >= ix->buckets){
111 fprint(2, "bucket out of range\n");
115 bok = checkbucket(ix, buck, &ib);
117 fprint(2, "bad bucket found=%lld: %r\n", found);
123 fprint(2, "found %lld entries in sorted list\n", found);
133 fprint(2, "usage: checkindex [-f] [-B blockcachesize] config tmp\n");
138 threadmain(int argc, char *argv[])
150 bcmem = unittoull(ARGF());
169 if(initventi(argv[0]) < 0)
170 sysfatal("can't init venti: %r");
172 if(bcmem < maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16))
173 bcmem = maxblocksize * (mainindex->narenas + mainindex->nsects * 4 + 16);
174 fprint(2, "initialize %d bytes of disk block cache\n", bcmem);
177 part = initpart(argv[1], 1);
179 sysfatal("can't initialize temporary partition: %r");
181 clumps = sortrawientries(mainindex, part, &base);
183 sysfatal("can't build sorted index: %r");
184 fprint(2, "found and sorted index entries for clumps=%lld at %lld\n", clumps, base);
185 checkindex(mainindex, part, base, clumps, !skipz);