diff --git a/db/range_del_aggregator.cc b/db/range_del_aggregator.cc index fdd847a7a..10d22fbb6 100644 --- a/db/range_del_aggregator.cc +++ b/db/range_del_aggregator.cc @@ -536,4 +536,11 @@ bool RangeDelAggregator::IsEmpty() { return true; } +bool RangeDelAggregator::AddFile(uint64_t file_number) { + if (added_files_ == nullptr) { + added_files_.reset(new std::set()); + } + return added_files_->emplace(file_number).second; +} + } // namespace rocksdb diff --git a/db/range_del_aggregator.h b/db/range_del_aggregator.h index f050e8917..1c1402d29 100644 --- a/db/range_del_aggregator.h +++ b/db/range_del_aggregator.h @@ -6,6 +6,7 @@ #pragma once #include +#include #include #include @@ -140,6 +141,7 @@ class RangeDelAggregator { CompactionIterationStats* range_del_out_stats = nullptr, bool bottommost_level = false); bool IsEmpty(); + bool AddFile(uint64_t file_number); private: // Maps tombstone user start key -> tombstone object @@ -180,6 +182,10 @@ class RangeDelAggregator { const InternalKeyComparator& icmp_; // collapse range deletions so they're binary searchable const bool collapse_deletions_; + + // Record files whose tombstones have been added, to avoid duplicate adding. + // Same as rep_, we initializes it lazily. + std::unique_ptr> added_files_; }; } // namespace rocksdb diff --git a/db/table_cache.cc b/db/table_cache.cc index a4f2b2ceb..a3c02fa8b 100644 --- a/db/table_cache.cc +++ b/db/table_cache.cc @@ -247,13 +247,15 @@ InternalIterator* TableCache::NewIterator( } } if (s.ok() && range_del_agg != nullptr && !options.ignore_range_deletions) { - std::unique_ptr range_del_iter( - table_reader->NewRangeTombstoneIterator(options)); - if (range_del_iter != nullptr) { - s = range_del_iter->status(); - } - if (s.ok()) { - s = range_del_agg->AddTombstones(std::move(range_del_iter)); + if (range_del_agg->AddFile(fd.GetNumber())) { + std::unique_ptr range_del_iter( + table_reader->NewRangeTombstoneIterator(options)); + if (range_del_iter != nullptr) { + s = range_del_iter->status(); + } + if (s.ok()) { + s = range_del_agg->AddTombstones(std::move(range_del_iter)); + } } }