From 27445141b27b1eaffff8bff6a9b0ba525eda7fbe Mon Sep 17 00:00:00 2001 From: Kezhu Wang Date: Tue, 10 May 2016 00:46:11 +0800 Subject: [PATCH] Reset grandparents overlapped bytes after current output has been finished due to file size limitation If current ouput is finished due to file size limitation, possibilities exist that we hit grandparents overlapped bytes limitation after writing fewer entries. So we need to restart grandparents overlapped bytes if we start building a new output for reasons other than overlapped bytes with grandparents. This commit adds code to restart grandparents overlapped counting after current output has been successfully finished due to file size limitation. I think the best place to restart grandparents overlapped counting should be DBImpl::OpenCompactionOutputFile, thus we don't need to remember to do this every time after we stop or start a output. --- db/db_impl.cc | 1 + db/version_set.h | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/db/db_impl.cc b/db/db_impl.cc index 82be594..93ab0ef 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -992,6 +992,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) { if (!status.ok()) { break; } + compact->compaction->RestartOverlappedBytes(); } } diff --git a/db/version_set.h b/db/version_set.h index 69f3d70..9737c7d 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -353,6 +353,10 @@ class Compaction { // before processing "internal_key". bool ShouldStopBefore(const Slice& internal_key); + // Reset overlapped bytes with grandparents. Should be called if we start + // building a new output for other reasons(eg. file size limitation). + void RestartOverlappedBytes() { overlapped_bytes_ = 0; } + // Release the input version for the compaction, once the compaction // is successful. void ReleaseInputs();