From ec911925250e051db625919e7c15fb01083fa9bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Sielu=C5=BCycki?= Date: Wed, 9 Feb 2022 12:11:53 +0100 Subject: [PATCH 1/2] compaction: Convert table::compact_sstables to coroutines. --- replica/table.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/replica/table.cc b/replica/table.cc index 55b5484efe..81d5151698 100644 --- a/replica/table.cc +++ b/replica/table.cc @@ -987,7 +987,7 @@ future<> table::compact_sstables(sstables::compaction_descriptor descriptor, sstables::compaction_data& cdata) { if (!descriptor.sstables.size()) { // if there is nothing to compact, just return. - return make_ready_future<>(); + co_return; } descriptor.creator = [this] (shard_id dummy) { @@ -1005,13 +1005,13 @@ table::compact_sstables(sstables::compaction_descriptor descriptor, sstables::co auto compaction_type = descriptor.options.type(); auto start_size = boost::accumulate(descriptor.sstables | boost::adaptors::transformed(std::mem_fn(&sstables::sstable::data_size)), uint64_t(0)); - return sstables::compact_sstables(std::move(descriptor), cdata, as_table_state()).then([this, &cdata, compaction_type, start_size] (sstables::compaction_result res) { + sstables::compaction_result res = co_await sstables::compact_sstables(std::move(descriptor), cdata, as_table_state()); if (compaction_type != sstables::compaction_type::Compaction) { - return make_ready_future<>(); + co_return; } // skip update if running without a query context, for example, when running a test case. if (!db::qctx) { - return make_ready_future<>(); + co_return; } auto ended_at = std::chrono::duration_cast(res.ended_at.time_since_epoch()).count(); @@ -1019,9 +1019,8 @@ table::compact_sstables(sstables::compaction_descriptor descriptor, sstables::co // shows how many sstables each row is merged from. This information // cannot be accessed until we make combined_reader more generic, // for example, by adding a reducer method. - return db::system_keyspace::update_compaction_history(cdata.compaction_uuid, _schema->ks_name(), _schema->cf_name(), ended_at, + co_return co_await db::system_keyspace::update_compaction_history(cdata.compaction_uuid, _schema->ks_name(), _schema->cf_name(), ended_at, start_size, res.end_size, std::unordered_map{}); - }); } future<> From ee386213c247af932ec51ea5536c81c5fcc016dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Sielu=C5=BCycki?= Date: Wed, 9 Feb 2022 12:12:27 +0100 Subject: [PATCH 2/2] compaction: Fix indentation in table::compact_sstables. --- replica/table.cc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/replica/table.cc b/replica/table.cc index 81d5151698..643141a0ff 100644 --- a/replica/table.cc +++ b/replica/table.cc @@ -1006,21 +1006,21 @@ table::compact_sstables(sstables::compaction_descriptor descriptor, sstables::co auto start_size = boost::accumulate(descriptor.sstables | boost::adaptors::transformed(std::mem_fn(&sstables::sstable::data_size)), uint64_t(0)); sstables::compaction_result res = co_await sstables::compact_sstables(std::move(descriptor), cdata, as_table_state()); - if (compaction_type != sstables::compaction_type::Compaction) { - co_return; - } - // skip update if running without a query context, for example, when running a test case. - if (!db::qctx) { - co_return; - } - auto ended_at = std::chrono::duration_cast(res.ended_at.time_since_epoch()).count(); + if (compaction_type != sstables::compaction_type::Compaction) { + co_return; + } + // skip update if running without a query context, for example, when running a test case. + if (!db::qctx) { + co_return; + } + auto ended_at = std::chrono::duration_cast(res.ended_at.time_since_epoch()).count(); - // FIXME: add support to merged_rows. merged_rows is a histogram that - // shows how many sstables each row is merged from. This information - // cannot be accessed until we make combined_reader more generic, - // for example, by adding a reducer method. - co_return co_await db::system_keyspace::update_compaction_history(cdata.compaction_uuid, _schema->ks_name(), _schema->cf_name(), ended_at, - start_size, res.end_size, std::unordered_map{}); + // FIXME: add support to merged_rows. merged_rows is a histogram that + // shows how many sstables each row is merged from. This information + // cannot be accessed until we make combined_reader more generic, + // for example, by adding a reducer method. + co_return co_await db::system_keyspace::update_compaction_history(cdata.compaction_uuid, _schema->ks_name(), _schema->cf_name(), ended_at, + start_size, res.end_size, std::unordered_map{}); } future<>