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

Avoid double-compacting data in bottom level in manual compactions #5138

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
forward CompactRangeOptions when possible
  • Loading branch information
miasantreble committed Apr 15, 2019
commit c2eeaa59493afe0b833d9bb2e6c4f79d57a26a1c
8 changes: 3 additions & 5 deletions db/column_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -989,16 +989,14 @@ const int ColumnFamilyData::kCompactToBaseLevel = -2;

Compaction* ColumnFamilyData::CompactRange(
const MutableCFOptions& mutable_cf_options, int input_level,
int output_level, uint32_t output_path_id, uint32_t max_subcompactions,
BottommostLevelCompaction bottommost_level_compaction,
int output_level, const CompactRangeOptions& compact_range_options,
const InternalKey* begin, const InternalKey* end,
InternalKey** compaction_end, bool* conflict,
uint64_t max_file_num_to_ignore) {
auto* result = compaction_picker_->CompactRange(
GetName(), mutable_cf_options, current_->storage_info(), input_level,
output_level, output_path_id, max_subcompactions,
bottommost_level_compaction, begin, end,
compaction_end, conflict, max_file_num_to_ignore);
output_level, compact_range_options, begin, end, compaction_end, conflict,
max_file_num_to_ignore);
if (result != nullptr) {
result->SetInputVersion(current_);
}
Expand Down
3 changes: 1 addition & 2 deletions db/column_family.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ class ColumnFamilyData {
// REQUIRES: DB mutex held
Compaction* CompactRange(const MutableCFOptions& mutable_cf_options,
int input_level, int output_level,
uint32_t output_path_id, uint32_t max_subcompactions,
BottommostLevelCompaction bottommost_level_compaction,
const CompactRangeOptions& compact_range_options,
const InternalKey* begin, const InternalKey* end,
InternalKey** compaction_end, bool* manual_conflict,
uint64_t max_file_num_to_ignore);
Expand Down
27 changes: 15 additions & 12 deletions db/compaction_picker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,8 @@ void CompactionPicker::GetGrandparents(
Compaction* CompactionPicker::CompactRange(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, int input_level, int output_level,
uint32_t output_path_id, uint32_t max_subcompactions,
BottommostLevelCompaction bottommost_level_compaction,
const InternalKey* begin, const InternalKey* end,
InternalKey** compaction_end, bool* manual_conflict,
const CompactRangeOptions& compact_range_options, const InternalKey* begin,
const InternalKey* end, InternalKey** compaction_end, bool* manual_conflict,
uint64_t max_file_num_to_ignore) {
// CompactionPickerFIFO has its own implementation of compact range
assert(ioptions_.compaction_style != kCompactionStyleFIFO);
Expand Down Expand Up @@ -611,11 +609,13 @@ Compaction* CompactionPicker::CompactRange(
output_level,
MaxFileSizeForLevel(mutable_cf_options, output_level,
ioptions_.compaction_style),
/* max_compaction_bytes */ LLONG_MAX, output_path_id,
/* max_compaction_bytes */ LLONG_MAX,
compact_range_options.target_path_id,
GetCompressionType(ioptions_, vstorage, mutable_cf_options,
output_level, 1),
GetCompressionOptions(ioptions_, vstorage, output_level),
max_subcompactions, /* grandparents */ {}, /* is manual */ true);
compact_range_options.max_subcompactions, /* grandparents */ {},
/* is manual */ true);
RegisterCompaction(c);
return c;
}
Expand Down Expand Up @@ -660,11 +660,13 @@ Compaction* CompactionPicker::CompactRange(
}
}
}
assert(output_path_id < static_cast<uint32_t>(ioptions_.cf_paths.size()));
assert(compact_range_options.target_path_id <
static_cast<uint32_t>(ioptions_.cf_paths.size()));

// for BOTTOM LEVEL compaction only, use max_file_num_to_ignore to filter out files
// that are created during the current compaction.
if (bottommost_level_compaction == BottommostLevelCompaction::kForceOptimized &&
// for BOTTOM LEVEL compaction only, use max_file_num_to_ignore to filter out
// files that are created during the current compaction.
if (compact_range_options.bottommost_level_compaction ==
BottommostLevelCompaction::kForceOptimized &&
max_file_num_to_ignore != port::kMaxUint64) {
assert(input_level == output_level);
// inputs_shrunk holds a continuous subset of input files which were all
Expand Down Expand Up @@ -760,11 +762,12 @@ Compaction* CompactionPicker::CompactRange(
MaxFileSizeForLevel(mutable_cf_options, output_level,
ioptions_.compaction_style, vstorage->base_level(),
ioptions_.level_compaction_dynamic_level_bytes),
mutable_cf_options.max_compaction_bytes, output_path_id,
mutable_cf_options.max_compaction_bytes,
compact_range_options.target_path_id,
GetCompressionType(ioptions_, vstorage, mutable_cf_options, output_level,
vstorage->base_level()),
GetCompressionOptions(ioptions_, vstorage, output_level),
max_subcompactions, std::move(grandparents),
compact_range_options.max_subcompactions, std::move(grandparents),
/* is manual compaction */ true);

TEST_SYNC_POINT_CALLBACK("CompactionPicker::CompactRange:Return", compaction);
Expand Down
7 changes: 2 additions & 5 deletions db/compaction_picker.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ class CompactionPicker {
virtual Compaction* CompactRange(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, int input_level, int output_level,
uint32_t output_path_id, uint32_t max_subcompactions,
BottommostLevelCompaction bottommost_level_compaction,
const CompactRangeOptions& compact_range_options,
const InternalKey* begin, const InternalKey* end,
InternalKey** compaction_end, bool* manual_conflict,
uint64_t max_file_num_to_ignore);
Expand Down Expand Up @@ -257,9 +256,7 @@ class NullCompactionPicker : public CompactionPicker {
const MutableCFOptions& /*mutable_cf_options*/,
VersionStorageInfo* /*vstorage*/,
int /*input_level*/, int /*output_level*/,
uint32_t /*output_path_id*/,
uint32_t /*max_subcompactions*/,
BottommostLevelCompaction /*bottommost_level_compaction*/,
const CompactRangeOptions& /*compact_range_options*/,
const InternalKey* /*begin*/,
const InternalKey* /*end*/,
InternalKey** /*compaction_end*/,
Expand Down
3 changes: 1 addition & 2 deletions db/compaction_picker_fifo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,7 @@ Compaction* FIFOCompactionPicker::PickCompaction(
Compaction* FIFOCompactionPicker::CompactRange(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, int input_level, int output_level,
uint32_t /*output_path_id*/, uint32_t /*max_subcompactions*/,
BottommostLevelCompaction /*bottommost_level_compaction*/,
const CompactRangeOptions& /*compact_range_options*/,
const InternalKey* /*begin*/, const InternalKey* /*end*/,
InternalKey** compaction_end, bool* /*manual_conflict*/,
uint64_t /*max_file_num_to_ignore*/) {
Expand Down
3 changes: 1 addition & 2 deletions db/compaction_picker_fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class FIFOCompactionPicker : public CompactionPicker {
virtual Compaction* CompactRange(
const std::string& cf_name, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, int input_level, int output_level,
uint32_t output_path_id, uint32_t max_subcompactions,
BottommostLevelCompaction bottommost_level_compaction,
const CompactRangeOptions& compact_range_options,
const InternalKey* begin, const InternalKey* end,
InternalKey** compaction_end, bool* manual_conflict,
uint64_t max_file_num_to_ignore) override;
Expand Down
9 changes: 6 additions & 3 deletions db/db_compaction_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ TEST_P(DBCompactionTestWithParam, CompactionsPreserveDeletes) {
CompactRangeOptions cro;
cro.change_level = true;
cro.target_level = 2;
cro.bottommost_level_compaction = BottommostLevelCompaction::kForceOptimized;
cro.bottommost_level_compaction =
BottommostLevelCompaction::kForceOptimized;

dbfull()->TEST_WaitForFlushMemTable();
dbfull()->CompactRange(cro, nullptr, nullptr);
Expand Down Expand Up @@ -4446,7 +4447,8 @@ TEST_F(DBCompactionTest, ManualCompactionBottomLevelOptimized) {
Random rnd(301);
for (auto i = 0; i < 8; ++i) {
for (auto j = 0; j < 10; ++j) {
ASSERT_OK(Put("foo" + std::to_string(i*10+j), RandomString(&rnd, 1024)));
ASSERT_OK(
Put("foo" + std::to_string(i * 10 + j), RandomString(&rnd, 1024)));
}
Flush();
}
Expand All @@ -4455,7 +4457,8 @@ TEST_F(DBCompactionTest, ManualCompactionBottomLevelOptimized) {

for (auto i = 0; i < 8; ++i) {
for (auto j = 0; j < 10; ++j) {
ASSERT_OK(Put("bar" + std::to_string(i*10+j), RandomString(&rnd, 1024)));
ASSERT_OK(
Put("bar" + std::to_string(i * 10 + j), RandomString(&rnd, 1024)));
}
Flush();
}
Expand Down
10 changes: 4 additions & 6 deletions db/db_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,10 @@ class DBImpl : public DB {
// compacted SST files. Setting max_file_num_to_ignore to kMaxUint64 will
// disable the filtering
Status RunManualCompaction(ColumnFamilyData* cfd, int input_level,
int output_level, uint32_t output_path_id,
uint32_t max_subcompactions,
BottommostLevelCompaction bottommost_level_compaction,
const Slice* begin,
const Slice* end, bool exclusive,
bool disallow_trivial_move,
int output_level,
const CompactRangeOptions& compact_range_options,
const Slice* begin, const Slice* end,
bool exclusive, bool disallow_trivial_move,
uint64_t max_file_num_to_ignore);

// Return an internal iterator over the current state of the database.
Expand Down
41 changes: 17 additions & 24 deletions db/db_impl_compaction_flush.cc
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,8 @@ Status DBImpl::CompactRange(const CompactRangeOptions& options,
}

int max_level_with_files = 0;
// max_file_num_to_ignore can be used to filter out newly created SST files, useful
// for bottom level compaction in a manual compaction
// max_file_num_to_ignore can be used to filter out newly created SST files,
// useful for bottom level compaction in a manual compaction
uint64_t max_file_num_to_ignore = port::kMaxUint64;
uint64_t next_file_number = port::kMaxUint64;
{
Expand All @@ -711,10 +711,8 @@ Status DBImpl::CompactRange(const CompactRangeOptions& options,
final_output_level--;
}
s = RunManualCompaction(cfd, ColumnFamilyData::kCompactAllLevels,
final_output_level, options.target_path_id,
options.max_subcompactions,
options.bottommost_level_compaction, begin, end,
exclusive, false, max_file_num_to_ignore);
final_output_level, options, begin, end, exclusive,
false, max_file_num_to_ignore);
} else {
for (int level = 0; level <= max_level_with_files; level++) {
int output_level;
Expand All @@ -739,9 +737,9 @@ Status DBImpl::CompactRange(const CompactRangeOptions& options,
continue;
}
output_level = level;
// update max_file_num_to_ignore only for bottom level compaction because
// data in newly compacted files in middle levels may still need to
// be pushed down
// update max_file_num_to_ignore only for bottom level compaction
// because data in newly compacted files in middle levels may still need
// to be pushed down
max_file_num_to_ignore = next_file_number;
} else {
output_level = level + 1;
Expand All @@ -751,9 +749,7 @@ Status DBImpl::CompactRange(const CompactRangeOptions& options,
output_level = ColumnFamilyData::kCompactToBaseLevel;
}
}
s = RunManualCompaction(cfd, level, output_level, options.target_path_id,
options.max_subcompactions,
options.bottommost_level_compaction, begin, end,
s = RunManualCompaction(cfd, level, output_level, options, begin, end,
exclusive, false, max_file_num_to_ignore);
if (!s.ok()) {
break;
Expand Down Expand Up @@ -1337,13 +1333,11 @@ Status DBImpl::Flush(const FlushOptions& flush_options,
return s;
}

Status DBImpl::RunManualCompaction(ColumnFamilyData* cfd, int input_level,
int output_level, uint32_t output_path_id,
uint32_t max_subcompactions,
BottommostLevelCompaction bottommost_level_compaction,
const Slice* begin, const Slice* end,
bool exclusive, bool disallow_trivial_move,
uint64_t max_file_num_to_ignore) {
Status DBImpl::RunManualCompaction(
ColumnFamilyData* cfd, int input_level, int output_level,
const CompactRangeOptions& compact_range_options, const Slice* begin,
const Slice* end, bool exclusive, bool disallow_trivial_move,
uint64_t max_file_num_to_ignore) {
assert(input_level == ColumnFamilyData::kCompactAllLevels ||
input_level >= 0);

Expand All @@ -1356,7 +1350,7 @@ Status DBImpl::RunManualCompaction(ColumnFamilyData* cfd, int input_level,
manual.cfd = cfd;
manual.input_level = input_level;
manual.output_level = output_level;
manual.output_path_id = output_path_id;
manual.output_path_id = compact_range_options.target_path_id;
manual.done = false;
manual.in_progress = false;
manual.incomplete = false;
Expand Down Expand Up @@ -1431,10 +1425,9 @@ Status DBImpl::RunManualCompaction(ColumnFamilyData* cfd, int input_level,
(((manual.manual_end = &manual.tmp_storage1) != nullptr) &&
((compaction = manual.cfd->CompactRange(
*manual.cfd->GetLatestMutableCFOptions(), manual.input_level,
manual.output_level, manual.output_path_id, max_subcompactions,
bottommost_level_compaction,
manual.begin, manual.end, &manual.manual_end,
&manual_conflict, max_file_num_to_ignore)) == nullptr &&
manual.output_level, compact_range_options, manual.begin,
manual.end, &manual.manual_end, &manual_conflict,
max_file_num_to_ignore)) == nullptr &&
manual_conflict))) {
// exclusive manual compactions should not see a conflict during
// CompactRange
Expand Down
7 changes: 2 additions & 5 deletions db/db_impl_debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ Status DBImpl::TEST_CompactRange(int level, const Slice* begin,
cfd->ioptions()->compaction_style == kCompactionStyleFIFO)
? level
: level + 1;
return RunManualCompaction(cfd, level, output_level, 0 /*output_path_id*/,
0 /*max_subcompactions*/,
BottommostLevelCompaction::kIfHaveCompactionFilter,
begin, end, true,
disallow_trivial_move,
return RunManualCompaction(cfd, level, output_level, CompactRangeOptions(),
begin, end, true, disallow_trivial_move,
port::kMaxUint64 /*max_file_num_to_ignore*/);
}

Expand Down
7 changes: 3 additions & 4 deletions db/db_range_del_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,9 @@ TEST_F(DBRangeDelTest, ValidUniversalSubcompactionBoundaries) {
ASSERT_OK(dbfull()->RunManualCompaction(
reinterpret_cast<ColumnFamilyHandleImpl*>(db_->DefaultColumnFamily())
->cfd(),
1 /* input_level */, 2 /* output_level */, 0 /* output_path_id */,
0 /* max_subcompactions */,
BottommostLevelCompaction::kIfHaveCompactionFilter, nullptr /* begin */,
nullptr /* end */, true /* exclusive */, true /* disallow_trivial_move */,
1 /* input_level */, 2 /* output_level */, CompactRangeOptions(),
nullptr /* begin */, nullptr /* end */, true /* exclusive */,
true /* disallow_trivial_move */,
port::kMaxUint64 /* max_file_num_to_ignore */));
}
#endif // ROCKSDB_LITE
Expand Down
3 changes: 2 additions & 1 deletion tools/db_bench_tool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6070,7 +6070,8 @@ void VerifyDBFromDB(std::string& truth_db_name) {
void Compact(ThreadState* thread) {
DB* db = SelectDB(thread);
CompactRangeOptions cro;
cro.bottommost_level_compaction = BottommostLevelCompaction::kForceOptimized;
cro.bottommost_level_compaction =
BottommostLevelCompaction::kForceOptimized;
db->CompactRange(cro, nullptr, nullptr);
}

Expand Down