From 80460f66fc376d578aa21050cd2b7ca544efdbd6 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 28 Oct 2021 13:34:22 +0300 Subject: [PATCH] table: Rewrap table::apply() The main motivation is to have future returning apply (to be used by next patches). As a side effect -- indentation fix and private dirty_memory_region_group() method. Signed-off-by: Pavel Emelyanov --- database.cc | 16 ++++++---------- database.hh | 20 ++++++++++++++------ table.cc | 18 ++++++++++++------ 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/database.cc b/database.cc index b84dbc6a0e..6a01626d5f 100644 --- a/database.cc +++ b/database.cc @@ -1786,19 +1786,15 @@ future<> database::apply_in_memory(const frozen_mutation& m, schema_ptr m_schema data_listeners().on_write(m_schema, m); - return with_gate(cf.async_gate(), [this, &m, m_schema = std::move(m_schema), h = std::move(h), &cf, timeout] () mutable -> future<> { - return cf.dirty_memory_region_group().run_when_memory_available([this, &m, m_schema = std::move(m_schema), h = std::move(h), &cf]() mutable { - cf.apply(m, m_schema, std::move(h)); - }, timeout); - }); + return with_gate(cf.async_gate(), [this, &m, m_schema = std::move(m_schema), h = std::move(h), &cf, timeout] () mutable -> future<> { + return cf.apply(m, std::move(m_schema), std::move(h), timeout); + }); } future<> database::apply_in_memory(const mutation& m, column_family& cf, db::rp_handle&& h, db::timeout_clock::time_point timeout) { - return with_gate(cf.async_gate(), [this, &m, h = std::move(h), &cf, timeout]() mutable -> future<> { - return cf.dirty_memory_region_group().run_when_memory_available([this, &m, &cf, h = std::move(h)] () mutable { - cf.apply(m, std::move(h)); - }, timeout); - }); + return with_gate(cf.async_gate(), [this, &m, h = std::move(h), &cf, timeout]() mutable -> future<> { + return cf.apply(m, std::move(h), timeout); + }); } future database::apply_counter_update(schema_ptr s, const frozen_mutation& m, db::timeout_clock::time_point timeout, tracing::trace_state_ptr trace_state) { diff --git a/database.hh b/database.hh index 2039f7f7a7..04fe0fd4f2 100644 --- a/database.hh +++ b/database.hh @@ -612,15 +612,16 @@ private: partition_presence_checker make_partition_presence_checker(lw_shared_ptr); std::chrono::steady_clock::time_point _sstable_writes_disabled_at; void do_trigger_compaction(); -public: - sstring dir() const { - return _config.datadir; - } logalloc::region_group& dirty_memory_region_group() const { return _config.dirty_memory_manager->region_group(); } +public: + sstring dir() const { + return _config.datadir; + } + seastar::gate& async_gate() { return _async_gate; } uint64_t failed_counter_applies_to_memtable() const { @@ -745,8 +746,15 @@ public: future find_row(schema_ptr, reader_permit permit, const dht::decorated_key& partition_key, clustering_key clustering_key) const; // Applies given mutation to this column family // The mutation is always upgraded to current schema. - void apply(const frozen_mutation& m, const schema_ptr& m_schema, db::rp_handle&& = {}); - void apply(const mutation& m, db::rp_handle&& = {}); + void apply(const frozen_mutation& m, const schema_ptr& m_schema, db::rp_handle&& h = {}) { + do_apply(std::move(h), m, m_schema); + } + void apply(const mutation& m, db::rp_handle&& h = {}) { + do_apply(std::move(h), m); + } + + future<> apply(const frozen_mutation& m, schema_ptr m_schema, db::rp_handle&& h, db::timeout_clock::time_point tmo); + future<> apply(const mutation& m, db::rp_handle&& h, db::timeout_clock::time_point tmo); // Returns at most "cmd.limit" rows // The saved_querier parameter is an input-output parameter which contains diff --git a/table.cc b/table.cc index 479fa77504..18d25749c0 100644 --- a/table.cc +++ b/table.cc @@ -1905,16 +1905,22 @@ void table::do_apply(db::rp_handle&& h, Args&&... args) { } } -void -table::apply(const mutation& m, db::rp_handle&& h) { - do_apply(std::move(h), m); +future<> table::apply(const mutation& m, db::rp_handle&& h, db::timeout_clock::time_point timeout) { + return dirty_memory_region_group().run_when_memory_available([this, &m, h = std::move(h)] () mutable { + do_apply(std::move(h), m); + }, timeout); } -void -table::apply(const frozen_mutation& m, const schema_ptr& m_schema, db::rp_handle&& h) { - do_apply(std::move(h), m, m_schema); +template void table::do_apply(db::rp_handle&&, const mutation&); + +future<> table::apply(const frozen_mutation& m, schema_ptr m_schema, db::rp_handle&& h, db::timeout_clock::time_point timeout) { + return dirty_memory_region_group().run_when_memory_available([this, &m, m_schema = std::move(m_schema), h = std::move(h)]() mutable { + do_apply(std::move(h), m, m_schema); + }, timeout); } +template void table::do_apply(db::rp_handle&&, const frozen_mutation&, const schema_ptr&); + future<> write_memtable_to_sstable(flat_mutation_reader reader, memtable& mt, sstables::shared_sstable sst,