Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return Aborted when no valid input files are found for a CompactFile call #12633

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions db/compaction/compaction_picker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ Status CompactionPicker::SanitizeCompactionInputFilesForAllLevels(
std::string smallestkey;
std::string largestkey;
// a flag for initializing smallest and largest key
bool is_first = false;
bool valid_input_files_found = false;
const int kNotFound = -1;

// For each level, it does the following things:
Expand All @@ -946,10 +946,10 @@ Status CompactionPicker::SanitizeCompactionInputFilesForAllLevels(
}
first_included = std::min(first_included, static_cast<int>(f));
last_included = std::max(last_included, static_cast<int>(f));
if (is_first == false) {
if (!valid_input_files_found) {
smallestkey = current_files[f].smallestkey;
largestkey = current_files[f].largestkey;
is_first = true;
valid_input_files_found = true;
}
}
if (last_included == kNotFound) {
Expand Down Expand Up @@ -1040,6 +1040,11 @@ Status CompactionPicker::SanitizeCompactionInputFilesForAllLevels(
}
}
}

if (!valid_input_files_found) {
Copy link
Member

@cbi42 cbi42 May 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does checking is_first works here? Or rename is_first to valid_input_files_found for better naming.

return Status::Aborted(
"There are no valid input files found for the specified files.");
}
if (RangeOverlapWithCompaction(smallestkey, largestkey, output_level)) {
return Status::Aborted(
"A running compaction is writing to the same output level in an "
Expand Down
16 changes: 11 additions & 5 deletions db/db_with_timestamp_basic_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,17 @@ TEST_F(DBBasicTestWithTimestamp, CompactRangeWithSpecifiedRange) {
ASSERT_OK(db_->Put(write_opts, "foo2", ts, "bar"));
ASSERT_OK(Flush());

std::string start_str = "foo";
std::string end_str = "foo2";
Slice start(start_str), end(end_str);
ASSERT_OK(db_->CompactRange(CompactRangeOptions(), &start, &end));

port::Thread compact_range([&]() {
std::string start_str = "foo";
std::string end_str = "foo2";
Slice start(start_str), end(end_str);
ASSERT_OK(db_->CompactRange(CompactRangeOptions(), &start, &end));
});
// Compact random(non-existing) file receive a proper status.
ASSERT_TRUE(db_->CompactFiles(CompactionOptions(), db_->DefaultColumnFamily(),
{"002349.sst"}, 1)
.IsAborted());
compact_range.join();
Close();
}

Expand Down
Loading