From 4d0b42f29195e210148f467a5be69b81f6bea8d9 Mon Sep 17 00:00:00 2001 From: Wang Haitao Date: Wed, 4 May 2022 11:12:31 +0800 Subject: [PATCH 1/3] Add checking a status in BlobGCJob::InstallOutputBlobFiles Signed-off-by: Wang Haitao --- src/blob_gc_job.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/blob_gc_job.cc b/src/blob_gc_job.cc index 5624f061e..8533096b8 100644 --- a/src/blob_gc_job.cc +++ b/src/blob_gc_job.cc @@ -415,6 +415,9 @@ Status BlobGCJob::InstallOutputBlobFiles() { for (auto& builder : blob_file_builders_) { BlobFileBuilder::OutContexts contexts; s = builder.second->Finish(&contexts); + if (!s.ok()) { + break; + } BatchWriteNewIndices(contexts, &s); if (!s.ok()) { break; From 187a55ba9b72426c1635a4846087e6bfb8c8c2b8 Mon Sep 17 00:00:00 2001 From: Wang Haitao Date: Wed, 4 May 2022 11:17:23 +0800 Subject: [PATCH 2/3] Rewritte the BatchWriteNewIndices to have the same interface Signed-off-by: Wang Haitao --- src/blob_gc_job.cc | 21 ++++++++++----------- src/blob_gc_job.h | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/blob_gc_job.cc b/src/blob_gc_job.cc index 8533096b8..eb4aaa247 100644 --- a/src/blob_gc_job.cc +++ b/src/blob_gc_job.cc @@ -246,7 +246,7 @@ Status BlobGCJob::DoRunGC() { BlobFileBuilder::OutContexts contexts; blob_file_builder->Add(blob_record, std::move(ctx), &contexts); - BatchWriteNewIndices(contexts, &s); + s = BatchWriteNewIndices(contexts); if (!s.ok()) { break; @@ -269,11 +269,10 @@ Status BlobGCJob::DoRunGC() { return s; } -void BlobGCJob::BatchWriteNewIndices(BlobFileBuilder::OutContexts& contexts, - Status* s) { +Status BlobGCJob::BatchWriteNewIndices(const BlobFileBuilder::OutContexts& contexts) { auto* cfh = blob_gc_->column_family_handle(); - for (const std::unique_ptr& ctx : - contexts) { + Status s; + for (const auto& ctx : contexts) { MergeBlobIndex merge_blob_index; merge_blob_index.file_number = ctx->new_blob_index.file_number; merge_blob_index.source_file_number = ctx->original_blob_index.file_number; @@ -285,8 +284,7 @@ void BlobGCJob::BatchWriteNewIndices(BlobFileBuilder::OutContexts& contexts, BlobIndex original_index = ctx->original_blob_index; ParsedInternalKey ikey; if (!ParseInternalKey(ctx->key, &ikey)) { - *s = Status::Corruption(Slice()); - return; + return Status::Corruption(Slice());; } if (!gc_merge_rewrite_) { merge_blob_index.EncodeToBase(&index_entry); @@ -297,18 +295,19 @@ void BlobGCJob::BatchWriteNewIndices(BlobFileBuilder::OutContexts& contexts, rewrite_batches_.emplace_back( std::make_pair(WriteBatch(), std::move(callback))); auto& wb = rewrite_batches_.back().first; - *s = WriteBatchInternal::PutBlobIndex(&wb, cfh->GetID(), ikey.user_key, + s = WriteBatchInternal::PutBlobIndex(&wb, cfh->GetID(), ikey.user_key, index_entry); } else { merge_blob_index.EncodeTo(&index_entry); rewrite_batches_without_callback_.emplace_back( std::make_pair(WriteBatch(), original_index.blob_handle.size)); auto& wb = rewrite_batches_without_callback_.back().first; - *s = WriteBatchInternal::Merge(&wb, cfh->GetID(), ikey.user_key, + s = WriteBatchInternal::Merge(&wb, cfh->GetID(), ikey.user_key, index_entry); } - if (!s->ok()) break; + if (!s.ok()) break; } + return s; } Status BlobGCJob::BuildIterator( @@ -418,7 +417,7 @@ Status BlobGCJob::InstallOutputBlobFiles() { if (!s.ok()) { break; } - BatchWriteNewIndices(contexts, &s); + s = BatchWriteNewIndices(contexts); if (!s.ok()) { break; } diff --git a/src/blob_gc_job.h b/src/blob_gc_job.h index 4e0bcc8ab..4f54da6dc 100644 --- a/src/blob_gc_job.h +++ b/src/blob_gc_job.h @@ -90,7 +90,7 @@ class BlobGCJob { uint64_t io_bytes_written_ = 0; Status DoRunGC(); - void BatchWriteNewIndices(BlobFileBuilder::OutContexts &contexts, Status *s); + Status BatchWriteNewIndices(const BlobFileBuilder::OutContexts& contexts); Status BuildIterator(std::unique_ptr *result); Status DiscardEntry(const Slice &key, const BlobIndex &blob_index, bool *discardable); From 8740cfac2b726f176a5171a1b1da5be3e966b9f7 Mon Sep 17 00:00:00 2001 From: Wang Haitao Date: Wed, 4 May 2022 11:22:51 +0800 Subject: [PATCH 3/3] Avoid unnecessary MergeBlobIndex when gc_merge_rewrite = false Signed-off-by: Wang Haitao --- src/blob_gc_job.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/blob_gc_job.cc b/src/blob_gc_job.cc index eb4aaa247..b6add7bc3 100644 --- a/src/blob_gc_job.cc +++ b/src/blob_gc_job.cc @@ -273,13 +273,6 @@ Status BlobGCJob::BatchWriteNewIndices(const BlobFileBuilder::OutContexts& conte auto* cfh = blob_gc_->column_family_handle(); Status s; for (const auto& ctx : contexts) { - MergeBlobIndex merge_blob_index; - merge_blob_index.file_number = ctx->new_blob_index.file_number; - merge_blob_index.source_file_number = ctx->original_blob_index.file_number; - merge_blob_index.source_file_offset = - ctx->original_blob_index.blob_handle.offset; - merge_blob_index.blob_handle = ctx->new_blob_index.blob_handle; - std::string index_entry; BlobIndex original_index = ctx->original_blob_index; ParsedInternalKey ikey; @@ -287,7 +280,8 @@ Status BlobGCJob::BatchWriteNewIndices(const BlobFileBuilder::OutContexts& conte return Status::Corruption(Slice());; } if (!gc_merge_rewrite_) { - merge_blob_index.EncodeToBase(&index_entry); + const BlobIndex &index = ctx->new_blob_index; + index.EncodeTo(&index_entry); // Store WriteBatch for rewriting new Key-Index pairs to LSM GarbageCollectionWriteCallback callback(cfh, ikey.user_key.ToString(), std::move(original_index)); @@ -298,6 +292,13 @@ Status BlobGCJob::BatchWriteNewIndices(const BlobFileBuilder::OutContexts& conte s = WriteBatchInternal::PutBlobIndex(&wb, cfh->GetID(), ikey.user_key, index_entry); } else { + MergeBlobIndex merge_blob_index; + merge_blob_index.file_number = ctx->new_blob_index.file_number; + merge_blob_index.source_file_number = + ctx->original_blob_index.file_number; + merge_blob_index.source_file_offset = + ctx->original_blob_index.blob_handle.offset; + merge_blob_index.blob_handle = ctx->new_blob_index.blob_handle; merge_blob_index.EncodeTo(&index_entry); rewrite_batches_without_callback_.emplace_back( std::make_pair(WriteBatch(), original_index.blob_handle.size));