From ebbc7aa43ea9eac24813a2f96c2936ab47fe1ea6 Mon Sep 17 00:00:00 2001 From: "Raphael S. Carvalho" Date: Thu, 9 Jul 2015 15:49:53 -0300 Subject: [PATCH] database: add compact_sstables to column_family compact_all_sstables is about selecting all available sstables for compaction and executing a compaction code on them. This compaction code was moved to a more generic function called compact_sstables, which will compact a list of given sstables. Signed-off-by: Raphael S. Carvalho --- database.cc | 23 +++++++++++++++-------- database.hh | 2 ++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/database.cc b/database.cc index 0df884a82c..4c4a31cd31 100644 --- a/database.cc +++ b/database.cc @@ -455,15 +455,10 @@ column_family::stop() { }); } -// FIXME: this is just an example, should be changed to something more general -// Note: We assume that the column_family does not get destroyed during compaction. future<> -column_family::compact_all_sstables() { - auto sstables_to_compact = - make_lw_shared>(); - for (auto&& entry : *_sstables) { - sstables_to_compact->push_back(entry.second); - } +column_family::compact_sstables(std::vector sstables) { + auto sstables_to_compact = make_lw_shared>(std::move(sstables)); + auto new_tables = make_lw_shared>>(); auto create_sstable = [this, new_tables] { @@ -505,6 +500,18 @@ column_family::compact_all_sstables() { }); } +// FIXME: this is just an example, should be changed to something more general +// Note: We assume that the column_family does not get destroyed during compaction. +future<> +column_family::compact_all_sstables() { + std::vector sstables; + sstables.reserve(_sstables->size()); + for (auto&& entry : *_sstables) { + sstables.push_back(entry.second); + } + return compact_sstables(std::move(sstables)); +} + void column_family::start_compaction() { set_compaction_strategy(sstables::compaction_strategy_type::null); diff --git a/database.hh b/database.hh index 426e699b11..16cccf2f33 100644 --- a/database.hh +++ b/database.hh @@ -158,6 +158,8 @@ public: // It doesn't flush the current memtable first. It's just a ad-hoc method, // not a real compaction policy. future<> compact_all_sstables(); + // Compact all sstables provided in the vector. + future<> compact_sstables(std::vector> sstables); size_t sstables_count();