Skip to content

Commit b2ad4ae

Browse files
author
Duc Hieu Pham
committed
Avoid expanding input set in remote compaction
Summary: As titled. Test Plan: Bake in master for now. I'll try to write unit test in different diffs. Reviewers: dhruba Reviewed By: dhruba Differential Revision: https://rockset.phacility.com/D6102
1 parent d0f9b5c commit b2ad4ae

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

db/db_impl/db_impl_remote_compaction.cc

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,35 @@ Status DBImpl::doCompact(const CompactionOptions& compact_options,
4848
ColumnFamilyMetaData cf_meta;
4949
version->GetColumnFamilyMetaData(&cf_meta);
5050

51-
// For unit tests, the PluggableService redirects to the compaction
52-
// to the same test database.
53-
Status s = cfd->compaction_picker()->SanitizeCompactionInputFiles(
54-
&input_set, cf_meta, output_level);
55-
if (!s.ok()) {
56-
return s;
51+
if (output_level >= static_cast<int>(cf_meta.levels.size())) {
52+
return Status::InvalidArgument(
53+
"Output level for column family " + cf_meta.name +
54+
" must between [0, " +
55+
ToString(cf_meta.levels[cf_meta.levels.size() - 1].level) + "].");
56+
}
57+
58+
auto max_output_level = cfd->compaction_picker()->MaxOutputLevel();
59+
if (output_level > max_output_level) {
60+
return Status::InvalidArgument(
61+
"Exceed the maximum output level defined by "
62+
"the current compaction algorithm --- " +
63+
ToString(max_output_level));
64+
}
65+
66+
if (output_level < 0) {
67+
return Status::InvalidArgument("Output level cannot be negative.");
68+
}
69+
70+
if (input_set.empty()) {
71+
return Status::InvalidArgument(
72+
"A compaction must contain at least one file.");
5773
}
5874

5975
// Validate that these files actually belong to this database. We do
6076
// not explicitly need to state the level where these files reside
6177
// because the DB should auto find the level of the specified file#.
6278
std::vector<CompactionInputFiles> input_files;
63-
s = cfd->compaction_picker()->GetCompactionInputsFromFileNumbers(
79+
Status s = cfd->compaction_picker()->GetCompactionInputsFromFileNumbers(
6480
&input_files, &input_set, version->storage_info(), compact_options);
6581
if (!s.ok()) {
6682
return s;

0 commit comments

Comments
 (0)