From 969cacba2d9bd7153df7bee837c492ba9c868b5d Mon Sep 17 00:00:00 2001 From: Ibrahim Jarif Date: Tue, 9 Jun 2020 19:46:16 +0530 Subject: [PATCH] GC: Consider size of value while rewriting (#1357) The existing code doesn't consider the size of the value while calculating the size of the entry batch in rewrite method. This PR fixes it. Fixes #1292 (cherry picked from commit 14386ac9b764cb6655cb0da7c848e244369a2a27) --- value.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/value.go b/value.go index e2dcc2e39..1c7b749c2 100644 --- a/value.go +++ b/value.go @@ -411,6 +411,11 @@ func (vlog *valueLog) rewrite(f *logFile, tr trace.Trace) error { ne.Value = append([]byte{}, e.Value...) es := int64(ne.estimateSize(vlog.opt.ValueThreshold)) + // Consider size of value as well while considering the total size + // of the batch. There have been reports of high memory usage in + // rewrite because we don't consider the value size. See #1292. + es += int64(len(e.Value)) + // Ensure length and size of wb is within transaction limits. if int64(len(wb)+1) >= vlog.opt.maxBatchCount || size+es >= vlog.opt.maxBatchSize {