From 49896e5f765a608e9c7e3e1b141f67f6a52a5b19 Mon Sep 17 00:00:00 2001 From: Wang Haitao Date: Thu, 21 Apr 2022 17:32:53 +0800 Subject: [PATCH] fix file_size always = 0 bug Signed-off-by: Wang Haitao --- src/blob_file_builder.h | 3 +++ src/blob_gc_job.cc | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/blob_file_builder.h b/src/blob_file_builder.h index 183c6ad13..f63980542 100644 --- a/src/blob_file_builder.h +++ b/src/blob_file_builder.h @@ -108,6 +108,9 @@ class BlobFileBuilder { const std::string& GetLargestKey() { return largest_key_; } uint64_t live_data_size() const { return live_data_size_; } + bool IsFileSizeReachLimit() const { + return file_->GetFileSize() >= cf_options_.blob_file_target_size; + } private: BuilderState builder_state_; diff --git a/src/blob_gc_job.cc b/src/blob_gc_job.cc index 5624f061e..e246a42d1 100644 --- a/src/blob_gc_job.cc +++ b/src/blob_gc_job.cc @@ -164,8 +164,6 @@ Status BlobGCJob::DoRunGC() { // uint64_t total_entry_num = 0; // uint64_t total_entry_size = 0; - uint64_t file_size = 0; - std::string last_key; bool last_key_valid = false; gc_iter->SeekToFirst(); @@ -203,9 +201,8 @@ Status BlobGCJob::DoRunGC() { // Rewrite entry to new blob file if ((!blob_file_handle && !blob_file_builder) || - file_size >= blob_gc_->titan_cf_options().blob_file_target_size) { - if (file_size >= blob_gc_->titan_cf_options().blob_file_target_size) { - assert(blob_file_builder); + (blob_file_builder && blob_file_builder->IsFileSizeReachLimit())) { + if (blob_file_builder && blob_file_builder->IsFileSizeReachLimit()) { assert(blob_file_handle); assert(blob_file_builder->status().ok()); blob_file_builders_.emplace_back(std::make_pair( @@ -222,7 +219,6 @@ Status BlobGCJob::DoRunGC() { blob_file_builder = std::unique_ptr( new BlobFileBuilder(db_options_, blob_gc_->titan_cf_options(), blob_file_handle->GetFile())); - file_size = 0; } assert(blob_file_handle); assert(blob_file_builder);