From 75344120711f164d19ae02a8e87f0ebaf69ae2b4 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Sat, 5 Jan 2019 16:28:46 +0200 Subject: [PATCH] table_helper: de-inline insert() and setup_keyspace() After previous patches de-templated these functions, we can de-inline them. This helps reduce compile time and prepares to reduce header dependencies. --- table_helper.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ table_helper.hh | 42 ++---------------------------------------- 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/table_helper.cc b/table_helper.cc index e162d39b01..b62af747c2 100644 --- a/table_helper.cc +++ b/table_helper.cc @@ -81,3 +81,45 @@ future<> table_helper::cache_table_info(service::query_state& qs) { } }); } + +future<> table_helper::insert(service::query_state& qs, noncopyable_function opt_maker) { + return cache_table_info(qs).then([this, &qs, opt_maker = std::move(opt_maker)] () mutable { + return do_with(opt_maker(), [this, &qs] (auto& opts) { + return _insert_stmt->execute(service::get_storage_proxy().local(), qs, opts); + }); + }).discard_result(); +} + +future<> table_helper::setup_keyspace(const sstring& keyspace_name, sstring replication_factor, service::query_state& qs, std::vector tables) { + if (engine().cpu_id() == 0) { + size_t n = tables.size(); + for (size_t i = 0; i < n; ++i) { + if (tables[i]->_keyspace != keyspace_name) { + throw std::invalid_argument("setup_keyspace called with table_helper for different keyspace"); + } + } + return seastar::async([&keyspace_name, replication_factor, &qs, tables] { + auto& db = cql3::get_local_query_processor().db(); + + // Create a keyspace + if (!db.has_keyspace(keyspace_name)) { + std::map opts; + opts["replication_factor"] = replication_factor; + auto ksm = keyspace_metadata::new_keyspace(keyspace_name, "org.apache.cassandra.locator.SimpleStrategy", std::move(opts), true); + // We use min_timestamp so that default keyspace metadata will loose with any manual adjustments. See issue #2129. + service::get_local_migration_manager().announce_new_keyspace(ksm, api::min_timestamp, false).get(); + } + + qs.get_client_state().set_keyspace(cql3::get_local_query_processor().db(), keyspace_name); + + + // Create tables + size_t n = tables.size(); + for (size_t i = 0; i < n; ++i) { + tables[i]->setup_table().get(); + } + }); + } else { + return make_ready_future<>(); + } +} diff --git a/table_helper.hh b/table_helper.hh index 7b05e6a7a7..2c51053cb0 100644 --- a/table_helper.hh +++ b/table_helper.hh @@ -95,47 +95,9 @@ public: })); } - future<> insert(service::query_state& qs, noncopyable_function opt_maker) { - return cache_table_info(qs).then([this, &qs, opt_maker = std::move(opt_maker)] () mutable { - return do_with(opt_maker(), [this, &qs] (auto& opts) { - return _insert_stmt->execute(service::get_storage_proxy().local(), qs, opts); - }); - }).discard_result(); - } + future<> insert(service::query_state& qs, noncopyable_function opt_maker); - static inline future<> setup_keyspace(const sstring& keyspace_name, sstring replication_factor, service::query_state& qs, std::vector tables) { - if (engine().cpu_id() == 0) { - size_t n = tables.size(); - for (size_t i = 0; i < n; ++i) { - if (tables[i]->_keyspace != keyspace_name) { - throw std::invalid_argument("setup_keyspace called with table_helper for different keyspace"); - } - } - return seastar::async([&keyspace_name, replication_factor, &qs, tables] { - auto& db = cql3::get_local_query_processor().db(); - - // Create a keyspace - if (!db.has_keyspace(keyspace_name)) { - std::map opts; - opts["replication_factor"] = replication_factor; - auto ksm = keyspace_metadata::new_keyspace(keyspace_name, "org.apache.cassandra.locator.SimpleStrategy", std::move(opts), true); - // We use min_timestamp so that default keyspace metadata will loose with any manual adjustments. See issue #2129. - service::get_local_migration_manager().announce_new_keyspace(ksm, api::min_timestamp, false).get(); - } - - qs.get_client_state().set_keyspace(cql3::get_local_query_processor().db(), keyspace_name); - - - // Create tables - size_t n = tables.size(); - for (size_t i = 0; i < n; ++i) { - tables[i]->setup_table().get(); - } - }); - } else { - return make_ready_future<>(); - } - } + static future<> setup_keyspace(const sstring& keyspace_name, sstring replication_factor, service::query_state& qs, std::vector tables); /** * Makes a monotonically increasing value in 100ns ("nanos") based on the given time