Skip to content

Commit 740b849

Browse files
author
Ibrahim Jarif
authored
Ensure rewrite in vlog is within transactional limits (#911)
* Ensure rewrite in vlog is within transactional limits With this commit the temporary list of entries built during value log iteration is committed before it overflows transactional limits (maxBatchSize and maxBatchCount). Fixes #907
1 parent 329b682 commit 740b849

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

value.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,19 @@ func (vlog *valueLog) rewrite(f *logFile, tr trace.Trace) error {
397397
}
398398

399399
ne.Value = append([]byte{}, e.Value...)
400-
wb = append(wb, ne)
401-
size += int64(e.estimateSize(vlog.opt.ValueThreshold))
402-
if size >= 64*mi {
400+
es := int64(ne.estimateSize(vlog.opt.ValueThreshold))
401+
// Ensure length and size of wb is within transaction limits.
402+
if int64(len(wb)+1) > vlog.opt.maxBatchCount ||
403+
size+es > vlog.opt.maxBatchSize {
403404
tr.LazyPrintf("request has %d entries, size %d", len(wb), size)
404405
if err := vlog.db.batchSet(wb); err != nil {
405406
return err
406407
}
407408
size = 0
408409
wb = wb[:0]
409410
}
411+
wb = append(wb, ne)
412+
size += es
410413
} else {
411414
vlog.db.opt.Warningf("This entry should have been caught. %+v\n", e)
412415
}

0 commit comments

Comments
 (0)