From 9211df2cdffb77d3ce79d9bfa63ae2dd2bf2997f Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 23 Jan 2020 13:42:10 +0300 Subject: [PATCH] snapshot: Make check_snapshot_not_exist a method Sanitation. It now can access the this->_db pointer. Signed-off-by: Pavel Emelyanov --- db/snapshot-ctl.cc | 12 ++++++------ db/snapshot-ctl.hh | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/db/snapshot-ctl.cc b/db/snapshot-ctl.cc index 6901ea0454..60d6446f33 100644 --- a/db/snapshot-ctl.cc +++ b/db/snapshot-ctl.cc @@ -43,10 +43,10 @@ namespace db { -future<> check_snapshot_not_exist(database& db, sstring ks_name, sstring name) { - auto& ks = db.find_keyspace(ks_name); - return parallel_for_each(ks.metadata()->cf_meta_data(), [&db, ks_name = std::move(ks_name), name = std::move(name)] (auto& pair) { - auto& cf = db.find_column_family(pair.second); +future<> snapshot_ctl::check_snapshot_not_exist(sstring ks_name, sstring name) { + auto& ks = _db.local().find_keyspace(ks_name); + return parallel_for_each(ks.metadata()->cf_meta_data(), [this, ks_name = std::move(ks_name), name = std::move(name)] (auto& pair) { + auto& cf = _db.local().find_column_family(pair.second); return cf.snapshot_exists(name).then([ks_name = std::move(ks_name), name] (bool exists) { if (exists) { throw std::runtime_error(format("Keyspace {}: snapshot {} already exists.", ks_name, name)); @@ -84,7 +84,7 @@ future<> snapshot_ctl::take_snapshot(sstring tag, std::vector keyspace_ return run_snapshot_modify_operation([tag = std::move(tag), keyspace_names = std::move(keyspace_names), this] { return parallel_for_each(keyspace_names, [tag, this] (auto& ks_name) { - return check_snapshot_not_exist(_db.local(), ks_name, tag); + return check_snapshot_not_exist(ks_name, tag); }).then([this, tag, keyspace_names] { return _db.invoke_on_all([tag = std::move(tag), keyspace_names] (database& db) { return parallel_for_each(keyspace_names, [&db, tag = std::move(tag)] (auto& ks_name) { @@ -111,7 +111,7 @@ future<> snapshot_ctl::take_column_family_snapshot(sstring ks_name, std::vector< } return run_snapshot_modify_operation([this, ks_name = std::move(ks_name), tables = std::move(tables), tag = std::move(tag)] { - return check_snapshot_not_exist(_db.local(), ks_name, tag).then([this, ks_name, tables = std::move(tables), tag] { + return check_snapshot_not_exist(ks_name, tag).then([this, ks_name, tables = std::move(tables), tag] { return do_with(std::vector(std::move(tables)),[this, ks_name, tag](const std::vector& tables) { return do_for_each(tables, [ks_name, tag, this] (const sstring& table_name) { if (table_name.find(".") != sstring::npos) { diff --git a/db/snapshot-ctl.hh b/db/snapshot-ctl.hh index 3ee56348d5..85e260096e 100644 --- a/db/snapshot-ctl.hh +++ b/db/snapshot-ctl.hh @@ -112,6 +112,8 @@ private: seastar::rwlock _lock; seastar::gate _ops; + future<> check_snapshot_not_exist(sstring ks_name, sstring name); + template std::result_of_t run_snapshot_modify_operation(Func&&);