venti: add -s flag to disable redundant SHA1 in mirrorarenas

This commit is contained in:
Russ Cox 2007-08-23 11:01:20 -04:00
parent 2c0dfd420a
commit 92baf59b69

View file

@ -22,13 +22,14 @@ Part *src;
Part *dst; Part *dst;
int force; int force;
int verbose; int verbose;
int dosha1 = 1;
char *status; char *status;
uvlong astart, aend; uvlong astart, aend;
void void
usage(void) usage(void)
{ {
fprint(2, "usage: mirrorarenas [-v] src dst [ranges]\n"); fprint(2, "usage: mirrorarenas [-sv] src dst [ranges]\n");
threadexitsall("usage"); threadexitsall("usage");
} }
@ -240,7 +241,7 @@ void
mirror(Arena *sa, Arena *da) mirror(Arena *sa, Arena *da)
{ {
vlong v, si, di, end; vlong v, si, di, end;
int clumpmax, blocksize; int clumpmax, blocksize, sealed;
static uchar buf[MaxIoSize]; static uchar buf[MaxIoSize];
ArenaHead h; ArenaHead h;
DigestState xds, *ds; DigestState xds, *ds;
@ -305,7 +306,8 @@ mirror(Arena *sa, Arena *da)
shaoff = 0; shaoff = 0;
ds = nil; ds = nil;
if(sa->diskstats.sealed && scorecmp(sa->score, zeroscore) != 0){ sealed = sa->diskstats.sealed && scorecmp(sa->score, zeroscore) != 0;
if(sealed && dosha1){
/* start sha1 state with header */ /* start sha1 state with header */
memset(&xds, 0, sizeof xds); memset(&xds, 0, sizeof xds);
ds = &xds; ds = &xds;
@ -362,7 +364,7 @@ mirror(Arena *sa, Arena *da)
if(ewritepart(dst, end, buf, blocksize) < 0) if(ewritepart(dst, end, buf, blocksize) < 0)
return; return;
if(ds){ if(sealed){
/* /*
* ... but on the final pass, copy the encoding * ... but on the final pass, copy the encoding
* of the tail information from the source * of the tail information from the source
@ -375,20 +377,27 @@ mirror(Arena *sa, Arena *da)
if(asha1(dst, shaoff, end, ds) < 0 if(asha1(dst, shaoff, end, ds) < 0
|| copy(end, end+blocksize-VtScoreSize, "tail", ds) < 0) || copy(end, end+blocksize-VtScoreSize, "tail", ds) < 0)
return; return;
memset(buf, 0, VtScoreSize); if(dosha1){
sha1(buf, VtScoreSize, da->score, ds); memset(buf, 0, VtScoreSize);
if(scorecmp(sa->score, da->score) == 0){ sha1(buf, VtScoreSize, da->score, ds);
if(verbose) if(scorecmp(sa->score, da->score) == 0){
chat("%T %s: %V sealed mirrored\n", sa->name, sa->score); if(verbose)
if(ewritepart(dst, end+blocksize-VtScoreSize, da->score, VtScoreSize) < 0) chat("%T %s: %V sealed mirrored\n", sa->name, sa->score);
return; if(ewritepart(dst, end+blocksize-VtScoreSize, da->score, VtScoreSize) < 0)
return;
}else{
chat("%T %s: sealing dst: score mismatch: %V vs %V\n", sa->name, sa->score, da->score);
memset(&xds, 0, sizeof xds);
asha1(dst, base-blocksize, end+blocksize-VtScoreSize, &xds);
sha1(buf, VtScoreSize, 0, &xds);
chat("%T reseal: %V\n", da->score);
status = "errors";
}
}else{ }else{
chat("%T %s: sealing dst: score mismatch: %V vs %V\n", sa->name, sa->score, da->score); if(verbose)
memset(&xds, 0, sizeof xds); chat("%T %s: %V mirrored\n", sa->name, sa->score);
asha1(dst, base-blocksize, end+blocksize-VtScoreSize, &xds); if(ewritepart(dst, end+blocksize-VtScoreSize, sa->score, VtScoreSize) < 0)
sha1(buf, VtScoreSize, 0, &xds); return;
chat("%T reseal: %V\n", da->score);
status = "errors";
} }
}else{ }else{
chat("%T %s: %,lld used mirrored\n", chat("%T %s: %,lld used mirrored\n",
@ -462,6 +471,9 @@ threadmain(int argc, char **argv)
case 'v': case 'v':
verbose++; verbose++;
break; break;
case 's':
dosha1 = 0;
break;
default: default:
usage(); usage();
}ARGEND }ARGEND