From 67189465869a24b226e0c9f923f5ad5381a46f5d Mon Sep 17 00:00:00 2001 From: Changyu Bi Date: Thu, 12 Sep 2024 11:21:36 -0700 Subject: [PATCH 1/3] fix --- db/compaction/compaction.cc | 2 +- db/compaction/compaction.h | 8 ++++---- db/compaction/compaction_picker.cc | 3 ++- db/compaction/compaction_picker.h | 2 +- db/db_impl/db_impl_compaction_flush.cc | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/db/compaction/compaction.cc b/db/compaction/compaction.cc index 1c014663cbe..53895fa7c46 100644 --- a/db/compaction/compaction.cc +++ b/db/compaction/compaction.cc @@ -735,7 +735,7 @@ uint64_t Compaction::CalculateTotalInputSize() const { return size; } -void Compaction::ReleaseCompactionFiles(Status status) { +void Compaction::ReleaseCompactionFiles(const Status& status) { MarkFilesBeingCompacted(false); cfd_->compaction_picker()->ReleaseCompactionFiles(this, status); } diff --git a/db/compaction/compaction.h b/db/compaction/compaction.h index 22157eb2c36..ad2ce2172f7 100644 --- a/db/compaction/compaction.h +++ b/db/compaction/compaction.h @@ -230,7 +230,7 @@ class Compaction { // Delete this compaction from the list of running compactions. // // Requirement: DB mutex held - void ReleaseCompactionFiles(Status status); + void ReleaseCompactionFiles(const Status& status); // Returns the summary of the compaction in "output" with maximum "len" // in bytes. The caller is responsible for the memory management of @@ -435,13 +435,13 @@ class Compaction { const int start_level, const int output_level); + // mark (or clear) all files that are being compacted + void MarkFilesBeingCompacted(bool mark_as_compacted); + private: Status InitInputTableProperties(); - // mark (or clear) all files that are being compacted - void MarkFilesBeingCompacted(bool mark_as_compacted); - // get the smallest and largest key present in files to be compacted static void GetBoundaryKeys(VersionStorageInfo* vstorage, const std::vector& inputs, diff --git a/db/compaction/compaction_picker.cc b/db/compaction/compaction_picker.cc index e049d95b24e..cc47060b5f3 100644 --- a/db/compaction/compaction_picker.cc +++ b/db/compaction/compaction_picker.cc @@ -133,7 +133,8 @@ CompactionPicker::CompactionPicker(const ImmutableOptions& ioptions, CompactionPicker::~CompactionPicker() = default; // Delete this compaction from the list of running compactions. -void CompactionPicker::ReleaseCompactionFiles(Compaction* c, Status status) { +void CompactionPicker::ReleaseCompactionFiles(Compaction* c, + const Status& status) { UnregisterCompaction(c); if (!status.ok()) { c->ResetNextCompactionIndex(); diff --git a/db/compaction/compaction_picker.h b/db/compaction/compaction_picker.h index 88915d45946..087595a8a68 100644 --- a/db/compaction/compaction_picker.h +++ b/db/compaction/compaction_picker.h @@ -104,7 +104,7 @@ class CompactionPicker { // Free up the files that participated in a compaction // // Requirement: DB mutex held - void ReleaseCompactionFiles(Compaction* c, Status status); + void ReleaseCompactionFiles(Compaction* c, const Status& status); // Returns true if any one of the specified files are being compacted bool AreFilesInCompaction(const std::vector& files); diff --git a/db/db_impl/db_impl_compaction_flush.cc b/db/db_impl/db_impl_compaction_flush.cc index 14dd02b57f8..3fb8af44774 100644 --- a/db/db_impl/db_impl_compaction_flush.cc +++ b/db/db_impl/db_impl_compaction_flush.cc @@ -1880,7 +1880,7 @@ Status DBImpl::ReFitLevel(ColumnFamilyData* cfd, int level, int target_level) { Status status = versions_->LogAndApply(cfd, mutable_cf_options, read_options, write_options, &edit, &mutex_, directories_.GetDbDir()); - + c->MarkFilesBeingCompacted(false); cfd->compaction_picker()->UnregisterCompaction(c.get()); c.reset(); From fe58a323b27b7bd123556e04323e1fec688423e1 Mon Sep 17 00:00:00 2001 From: Changyu Bi Date: Thu, 12 Sep 2024 11:32:35 -0700 Subject: [PATCH 2/3] add change log --- unreleased_history/bug_fixes/bug-refit-level.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 unreleased_history/bug_fixes/bug-refit-level.md diff --git a/unreleased_history/bug_fixes/bug-refit-level.md b/unreleased_history/bug_fixes/bug-refit-level.md new file mode 100644 index 00000000000..f41e699e6a1 --- /dev/null +++ b/unreleased_history/bug_fixes/bug-refit-level.md @@ -0,0 +1 @@ +* Fix a bug in CompactRange() where result files may not be compacted in any future compaction. This can only happen when users configure CompactRangeOptions::change_level to true and the change level step of manual compaction fails (#13009). \ No newline at end of file From c612386dab77c443c9c0ce233f8dbe578dc2adde Mon Sep 17 00:00:00 2001 From: Changyu Bi Date: Thu, 12 Sep 2024 12:51:21 -0700 Subject: [PATCH 3/3] small refactor --- db/compaction/compaction.cc | 7 +++---- db/compaction/compaction.h | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/db/compaction/compaction.cc b/db/compaction/compaction.cc index 53895fa7c46..fc76f93f1c5 100644 --- a/db/compaction/compaction.cc +++ b/db/compaction/compaction.cc @@ -686,12 +686,11 @@ bool Compaction::KeyRangeNotExistsBeyondOutputLevel( }; // Mark (or clear) each file that is being compacted -void Compaction::MarkFilesBeingCompacted(bool mark_as_compacted) { +void Compaction::MarkFilesBeingCompacted(bool being_compacted) const { for (size_t i = 0; i < num_input_levels(); i++) { for (size_t j = 0; j < inputs_[i].size(); j++) { - assert(mark_as_compacted ? !inputs_[i][j]->being_compacted - : inputs_[i][j]->being_compacted); - inputs_[i][j]->being_compacted = mark_as_compacted; + assert(being_compacted != inputs_[i][j]->being_compacted); + inputs_[i][j]->being_compacted = being_compacted; } } } diff --git a/db/compaction/compaction.h b/db/compaction/compaction.h index ad2ce2172f7..633e68a9eac 100644 --- a/db/compaction/compaction.h +++ b/db/compaction/compaction.h @@ -436,7 +436,7 @@ class Compaction { const int output_level); // mark (or clear) all files that are being compacted - void MarkFilesBeingCompacted(bool mark_as_compacted); + void MarkFilesBeingCompacted(bool being_compacted) const; private: