Unit test for custom comparator RangeDelAggregator (#4388)

Summary:
Add a unit test for range collapsing when non-default comparator is used. This exposes the bug fixed in #4386.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4388

Differential Revision: D9918252

Pulled By: ajkr

fbshipit-source-id: 99501b96b251eab41791a7e33b27055ee36c5c39
main
Andrew Kryczka 6 years ago committed by Facebook Github Bot
parent 27221b0cc2
commit 990b52e95b
  1. 2
      db/range_del_aggregator.cc
  2. 21
      db/range_del_aggregator_test.cc

@ -173,7 +173,7 @@ class CollapsedRangeDelMap : public RangeDelMap {
const Comparator* ucmp_; const Comparator* ucmp_;
public: public:
CollapsedRangeDelMap(const Comparator* ucmp) explicit CollapsedRangeDelMap(const Comparator* ucmp)
: rep_(stl_wrappers::LessOfComparator(ucmp)), : rep_(stl_wrappers::LessOfComparator(ucmp)),
ucmp_(ucmp) { ucmp_(ucmp) {
InvalidatePosition(); InvalidatePosition();

@ -27,7 +27,7 @@ enum Direction {
kReverse, kReverse,
}; };
static auto icmp = InternalKeyComparator(BytewiseComparator()); static auto bytewise_icmp = InternalKeyComparator(BytewiseComparator());
void AddTombstones(RangeDelAggregator* range_del_agg, void AddTombstones(RangeDelAggregator* range_del_agg,
const std::vector<RangeTombstone>& range_dels, const std::vector<RangeTombstone>& range_dels,
@ -66,8 +66,8 @@ void VerifyRangeDels(
const std::vector<RangeTombstone>& range_dels_in, const std::vector<RangeTombstone>& range_dels_in,
const std::vector<ExpectedPoint>& expected_points, const std::vector<ExpectedPoint>& expected_points,
const std::vector<RangeTombstone>& expected_collapsed_range_dels, const std::vector<RangeTombstone>& expected_collapsed_range_dels,
const InternalKey* smallest = nullptr, const InternalKey* smallest = nullptr, const InternalKey* largest = nullptr,
const InternalKey* largest = nullptr) { const InternalKeyComparator& icmp = bytewise_icmp) {
// Test same result regardless of which order the range deletions are added // Test same result regardless of which order the range deletions are added
// and regardless of collapsed mode. // and regardless of collapsed mode.
for (bool collapsed : {false, true}) { for (bool collapsed : {false, true}) {
@ -164,6 +164,14 @@ TEST_F(RangeDelAggregatorTest, OverlapAboveMiddle) {
{{"a", "b", 5}, {"b", "c", 10}, {"c", "d", 5}}); {{"a", "b", 5}, {"b", "c", 10}, {"c", "d", 5}});
} }
TEST_F(RangeDelAggregatorTest, OverlapAboveMiddleReverse) {
VerifyRangeDels({{"d", "a", 5}, {"c", "b", 10}},
{{"z", 0}, {"d", 5}, {"c", 10}, {"b", 5}, {"a", 0}},
{{"d", "c", 5}, {"c", "b", 10}, {"b", "a", 5}},
nullptr /* smallest */, nullptr /* largest */,
InternalKeyComparator(ReverseBytewiseComparator()));
}
TEST_F(RangeDelAggregatorTest, OverlapFully) { TEST_F(RangeDelAggregatorTest, OverlapFully) {
VerifyRangeDels({{"a", "d", 10}, {"b", "c", 5}}, VerifyRangeDels({{"a", "d", 10}, {"b", "c", 5}},
{{" ", 0}, {"a", 10}, {"d", 0}}, {{"a", "d", 10}}); {{" ", 0}, {"a", 10}, {"d", 0}}, {{"a", "d", 10}});
@ -235,14 +243,14 @@ TEST_F(RangeDelAggregatorTest, AlternateMultipleAboveBelow) {
TEST_F(RangeDelAggregatorTest, MergingIteratorAllEmptyStripes) { TEST_F(RangeDelAggregatorTest, MergingIteratorAllEmptyStripes) {
for (bool collapsed : {true, false}) { for (bool collapsed : {true, false}) {
RangeDelAggregator range_del_agg(icmp, {1, 2}, collapsed); RangeDelAggregator range_del_agg(bytewise_icmp, {1, 2}, collapsed);
VerifyRangeDelIter(range_del_agg.NewIterator().get(), {}); VerifyRangeDelIter(range_del_agg.NewIterator().get(), {});
} }
} }
TEST_F(RangeDelAggregatorTest, MergingIteratorOverlappingStripes) { TEST_F(RangeDelAggregatorTest, MergingIteratorOverlappingStripes) {
for (bool collapsed : {true, false}) { for (bool collapsed : {true, false}) {
RangeDelAggregator range_del_agg(icmp, {5, 15, 25, 35}, collapsed); RangeDelAggregator range_del_agg(bytewise_icmp, {5, 15, 25, 35}, collapsed);
AddTombstones( AddTombstones(
&range_del_agg, &range_del_agg,
{{"d", "e", 10}, {"aa", "b", 20}, {"c", "d", 30}, {"a", "b", 10}}); {{"d", "e", 10}, {"aa", "b", 20}, {"c", "d", 30}, {"a", "b", 10}});
@ -253,7 +261,8 @@ TEST_F(RangeDelAggregatorTest, MergingIteratorOverlappingStripes) {
} }
TEST_F(RangeDelAggregatorTest, MergingIteratorSeek) { TEST_F(RangeDelAggregatorTest, MergingIteratorSeek) {
RangeDelAggregator range_del_agg(icmp, {5, 15}, true /* collapsed */); RangeDelAggregator range_del_agg(bytewise_icmp, {5, 15},
true /* collapsed */);
AddTombstones(&range_del_agg, {{"a", "c", 10}, AddTombstones(&range_del_agg, {{"a", "c", 10},
{"b", "c", 11}, {"b", "c", 11},
{"f", "g", 10}, {"f", "g", 10},

Loading…
Cancel
Save