From d0cbcce4a25a0d28ac4407e275e9db7e8bb8b3f7 Mon Sep 17 00:00:00 2001 From: Vlad Zolotarov Date: Sun, 3 Jan 2016 13:30:46 +0200 Subject: [PATCH 1/3] service::storage_service: remove not used variable ('deleted_keyspaces') Signed-off-by: Vlad Zolotarov --- service/storage_service.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/service/storage_service.cc b/service/storage_service.cc index ad8f04a068..8ff0a923c3 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -1413,8 +1413,7 @@ future<> storage_service::clear_snapshot(sstring tag, std::vector keysp } } - auto deleted_keyspaces = make_lw_shared>(); - return parallel_for_each(keyspaces, [this, tag, deleted_keyspaces] (auto& ks) { + return parallel_for_each(keyspaces, [this, tag] (auto& ks) { return parallel_for_each(ks.get().metadata()->cf_meta_data(), [this, tag] (auto& pair) { auto& cf = _db.local().find_column_family(pair.second); return cf.clear_snapshot(tag); From d5920705b820c265aef904682d08351a03dad754 Mon Sep 17 00:00:00 2001 From: Vlad Zolotarov Date: Sun, 3 Jan 2016 13:48:58 +0200 Subject: [PATCH 2/3] service::storage_service: move clear_snapshot() code to 'database' class service::storage_service::clear_snapshot() was built around _db.local() calls so it makes more sense to move its code into the 'database' class instead of calling _db.local().bla_bla() all the time. Signed-off-by: Vlad Zolotarov --- database.cc | 23 +++++++++++++++++++++++ database.hh | 1 + service/storage_service.cc | 20 +------------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/database.cc b/database.cc index 94306526b3..5857b08a30 100644 --- a/database.cc +++ b/database.cc @@ -1798,6 +1798,29 @@ const sstring& database::get_snitch_name() const { return _cfg->endpoint_snitch(); } +// For the filesystem operations, this code will assume that all keyspaces are visible in all shards +// (as we have been doing for a lot of the other operations, like the snapshot itself). +future<> database::clear_snapshot(sstring tag, std::vector keyspace_names) { + std::vector> keyspaces; + + for (auto& ksname: keyspace_names) { + try { + keyspaces.push_back(std::reference_wrapper(find_keyspace(ksname))); + } catch (no_such_keyspace& e) { + return make_exception_future(std::current_exception()); + } + } + + return parallel_for_each(keyspaces, [this, tag] (auto& ks) { + return parallel_for_each(ks.get().metadata()->cf_meta_data(), [this, tag] (auto& pair) { + auto& cf = this->find_column_family(pair.second); + return cf.clear_snapshot(tag); + }).then_wrapped([] (future<> f) { + dblog.debug("Cleared out snapshot directories"); + }); + }); +} + future<> update_schema_version_and_announce(distributed& proxy) { return db::schema_tables::calculate_schema_digest(proxy).then([&proxy] (utils::UUID uuid) { diff --git a/database.hh b/database.hh index b2cd279892..fb6889f5d1 100644 --- a/database.hh +++ b/database.hh @@ -621,6 +621,7 @@ public: future<> apply(const frozen_mutation&); keyspace::config make_keyspace_config(const keyspace_metadata& ksm); const sstring& get_snitch_name() const; + future<> clear_snapshot(sstring tag, std::vector keyspace_names); friend std::ostream& operator<<(std::ostream& out, const database& db); const std::unordered_map& get_keyspaces() const { diff --git a/service/storage_service.cc b/service/storage_service.cc index 8ff0a923c3..bb5db35af9 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -1401,26 +1401,8 @@ future<> storage_service::take_column_family_snapshot(sstring ks_name, sstring c }); } -// For the filesystem operations, this code will assume that all keyspaces are visible in all shards -// (as we have been doing for a lot of the other operations, like the snapshot itself). future<> storage_service::clear_snapshot(sstring tag, std::vector keyspace_names) { - std::vector> keyspaces; - for (auto& ksname: keyspace_names) { - try { - keyspaces.push_back(std::reference_wrapper(_db.local().find_keyspace(ksname))); - } catch (no_such_keyspace& e) { - return make_exception_future(std::current_exception()); - } - } - - return parallel_for_each(keyspaces, [this, tag] (auto& ks) { - return parallel_for_each(ks.get().metadata()->cf_meta_data(), [this, tag] (auto& pair) { - auto& cf = _db.local().find_column_family(pair.second); - return cf.clear_snapshot(tag); - }).then_wrapped([] (future<> f) { - logger.debug("Cleared out snapshot directories"); - }); - }); + return _db.local().clear_snapshot(tag, keyspace_names); } future>> From 7bb2b2408b6fe49b32c2bf18114a1c95dc16442e Mon Sep 17 00:00:00 2001 From: Vlad Zolotarov Date: Sun, 3 Jan 2016 14:18:47 +0200 Subject: [PATCH 3/3] database::clear_snapshot(): added support for deleting all snapshots When 'nodetool clearsnapshot' is given no parameters it should remove all existing snapshots. Fixes issue #639 Signed-off-by: Vlad Zolotarov --- database.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/database.cc b/database.cc index 5857b08a30..62f56da326 100644 --- a/database.cc +++ b/database.cc @@ -1803,11 +1803,18 @@ const sstring& database::get_snitch_name() const { future<> database::clear_snapshot(sstring tag, std::vector keyspace_names) { std::vector> keyspaces; - for (auto& ksname: keyspace_names) { - try { - keyspaces.push_back(std::reference_wrapper(find_keyspace(ksname))); - } catch (no_such_keyspace& e) { - return make_exception_future(std::current_exception()); + if (keyspace_names.empty()) { + // if keyspace names are not given - apply to all existing local keyspaces + for (auto& ks: _keyspaces) { + keyspaces.push_back(std::reference_wrapper(ks.second)); + } + } else { + for (auto& ksname: keyspace_names) { + try { + keyspaces.push_back(std::reference_wrapper(find_keyspace(ksname))); + } catch (no_such_keyspace& e) { + return make_exception_future(std::current_exception()); + } } }