Use vector in UncollapsedRangeDelMap (#4487)

Summary:
Using `./range_del_aggregator_bench --use_collapsed=false
--num_range_tombstones=5000 --num_runs=1000`, here are the results before and
after this change:

Before:
```
=========================
Results:
=========================
AddTombstones:           1822.61 us
ShouldDelete (first):    94.5286 us
```

After:
```
=========================
Results:
=========================
AddTombstones:           199.26 us
ShouldDelete (first):    38.9344 us
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4487

Differential Revision: D10347288

Pulled By: abhimadan

fbshipit-source-id: d44efe3a166d583acfdc3ec1199e0892f34dbfb7
This commit is contained in:
Abhishek Madan 2018-10-11 15:27:29 -07:00 committed by Facebook Github Bot
parent 46dd8b1e13
commit 7dd1641048

View File

@ -37,8 +37,7 @@ struct ParsedInternalKeyComparator {
// An UncollapsedRangeDelMap is quick to create but slow to answer ShouldDelete // An UncollapsedRangeDelMap is quick to create but slow to answer ShouldDelete
// queries. // queries.
class UncollapsedRangeDelMap : public RangeDelMap { class UncollapsedRangeDelMap : public RangeDelMap {
typedef std::multiset<TruncatedRangeTombstone, TombstoneStartKeyComparator> typedef std::vector<TruncatedRangeTombstone> Rep;
Rep;
class Iterator : public RangeDelIterator { class Iterator : public RangeDelIterator {
const Rep& rep_; const Rep& rep_;
@ -70,7 +69,7 @@ class UncollapsedRangeDelMap : public RangeDelMap {
public: public:
explicit UncollapsedRangeDelMap(const InternalKeyComparator* icmp) explicit UncollapsedRangeDelMap(const InternalKeyComparator* icmp)
: rep_(TombstoneStartKeyComparator(icmp)), icmp_(icmp) {} : icmp_(icmp) {}
bool ShouldDelete(const ParsedInternalKey& parsed, bool ShouldDelete(const ParsedInternalKey& parsed,
RangeDelPositioningMode mode) override { RangeDelPositioningMode mode) override {
@ -78,7 +77,7 @@ class UncollapsedRangeDelMap : public RangeDelMap {
assert(mode == RangeDelPositioningMode::kFullScan); assert(mode == RangeDelPositioningMode::kFullScan);
for (const auto& tombstone : rep_) { for (const auto& tombstone : rep_) {
if (icmp_->Compare(parsed, tombstone.start_key_) < 0) { if (icmp_->Compare(parsed, tombstone.start_key_) < 0) {
break; continue;
} }
if (parsed.sequence < tombstone.seq_ && if (parsed.sequence < tombstone.seq_ &&
icmp_->Compare(parsed, tombstone.end_key_) < 0) { icmp_->Compare(parsed, tombstone.end_key_) < 0) {
@ -101,7 +100,7 @@ class UncollapsedRangeDelMap : public RangeDelMap {
} }
void AddTombstone(TruncatedRangeTombstone tombstone) override { void AddTombstone(TruncatedRangeTombstone tombstone) override {
rep_.emplace(tombstone); rep_.emplace_back(tombstone);
} }
size_t Size() const override { return rep_.size(); } size_t Size() const override { return rep_.size(); }
@ -109,6 +108,7 @@ class UncollapsedRangeDelMap : public RangeDelMap {
void InvalidatePosition() override {} // no-op void InvalidatePosition() override {} // no-op
std::unique_ptr<RangeDelIterator> NewIterator() override { std::unique_ptr<RangeDelIterator> NewIterator() override {
std::sort(rep_.begin(), rep_.end(), TombstoneStartKeyComparator(icmp_));
return std::unique_ptr<RangeDelIterator>(new Iterator(this->rep_)); return std::unique_ptr<RangeDelIterator>(new Iterator(this->rep_));
} }
}; };