From 4fe6fea75842d2fce054fa87f6574c30bac963d0 Mon Sep 17 00:00:00 2001 From: "Raphael S. Carvalho" Date: Thu, 30 Nov 2017 04:37:52 -0200 Subject: [PATCH] dtcs: make code to extract non expired tables faster since it's O(n) and not O(n log n). change also needed for change in interface of function to retrieve fully expired tables, or sort lambda would need to be parametrized. Signed-off-by: Raphael S. Carvalho --- sstables/date_tiered_compaction_strategy.hh | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/sstables/date_tiered_compaction_strategy.hh b/sstables/date_tiered_compaction_strategy.hh index 64543ac161..f857758275 100644 --- a/sstables/date_tiered_compaction_strategy.hh +++ b/sstables/date_tiered_compaction_strategy.hh @@ -144,22 +144,13 @@ public: // Find fully expired SSTables. Those will be included no matter what. auto expired = get_fully_expired_sstables(cf, uncompacting, gc_before.time_since_epoch().count()); - auto sort_ssts = [] (std::vector& sstables) { - std::sort(sstables.begin(), sstables.end(), [] (const auto& x, const auto& y) { - return x->generation() < y->generation(); - }); - }; - sort_ssts(uncompacting); - sort_ssts(expired); + if (!expired.empty()) { + auto expired_as_set = boost::copy_range>(expired); + auto is_expired = [&] (const sstables::shared_sstable& s) { return expired_as_set.find(s) != expired_as_set.end(); }; + uncompacting.erase(boost::remove_if(uncompacting, is_expired), uncompacting.end()); + } - std::vector non_expired_set; - // Set non_expired_set with the elements that are in uncompacting, but not in the expired. - std::set_difference(uncompacting.begin(), uncompacting.end(), expired.begin(), expired.end(), - std::inserter(non_expired_set, non_expired_set.begin()), [] (const auto& x, const auto& y) { - return x->generation() < y->generation(); - }); - - auto compaction_candidates = get_next_non_expired_sstables(cf, non_expired_set, gc_before); + auto compaction_candidates = get_next_non_expired_sstables(cf, uncompacting, gc_before); if (!expired.empty()) { compaction_candidates.insert(compaction_candidates.end(), expired.begin(), expired.end()); }