Skip to content

Commit

Permalink
Make MultiCFIter not valid for only one CF
Browse files Browse the repository at this point in the history
  • Loading branch information
jaykorean committed Feb 28, 2024
1 parent 15ba79f commit 1d33aa5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions db/db_impl/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3724,9 +3724,9 @@ ArenaWrappedDBIter* DBImpl::NewIteratorImpl(
std::unique_ptr<MultiCfIterator> DBImpl::NewMultiCfIterator(
const ReadOptions& _read_options,
const std::vector<ColumnFamilyHandle*>& column_families) {
if (column_families.size() == 0) {
if (column_families.size() < 2) {
return std::make_unique<EmptyMultiCfIterator>(
Status::InvalidArgument("No column families were provided"));
Status::InvalidArgument("Less than 2 CFs were provided"));
}
const Comparator* first_comparator = column_families[0]->GetComparator();
for (size_t i = 1; i < column_families.size(); ++i) {
Expand Down
4 changes: 1 addition & 3 deletions db/multi_cf_iterator_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class MultiCfIteratorImpl : public MultiCfIterator {
column_families[i], std::unique_ptr<Iterator>(child_iterators[i]));
}
}
~MultiCfIteratorImpl() override {
status_.PermitUncheckedError();
}
~MultiCfIteratorImpl() override { status_.PermitUncheckedError(); }

// No copy allowed
MultiCfIteratorImpl(const MultiCfIteratorImpl&) = delete;
Expand Down
19 changes: 19 additions & 0 deletions db/multi_cf_iterator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ class MultiCfIteratorTest : public DBTestBase {
}
};

TEST_F(MultiCfIteratorTest, InvalidArguments) {
Options options = GetDefaultOptions();
{
CreateAndReopenWithCF({"cf_1", "cf_2", "cf_3"}, options);

// Invalid - No CF is provided
std::unique_ptr<MultiCfIterator> iter_with_no_cf =
db_->NewMultiCfIterator(ReadOptions(), {});
ASSERT_NOK(iter_with_no_cf->status());
ASSERT_TRUE(iter_with_no_cf->status().IsInvalidArgument());

// Invalid - Only one CF is provided
std::unique_ptr<MultiCfIterator> iter_with_one_cf =
db_->NewMultiCfIterator(ReadOptions(), {handles_[0]});
ASSERT_NOK(iter_with_one_cf->status());
ASSERT_TRUE(iter_with_one_cf->status().IsInvalidArgument());
}
}

TEST_F(MultiCfIteratorTest, SimpleValues) {
Options options = GetDefaultOptions();
{
Expand Down

0 comments on commit 1d33aa5

Please sign in to comment.