From 21f84d77fc972dd9e5f7b6efbb825bc12db657b5 Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Mon, 12 Oct 2015 15:31:18 +0200 Subject: [PATCH] storage_service: delete a snapshot This patch provides an storage service api to delete an snapshot. Because all keyspaces and CFs are visible in all shards. This will allow us to fetch the list of keyspaces in the present shard and issue the filesystem operations in that same shard. That simplifies the code tremendously, and because there are not any operations we need to do previous to the fs ones (like in the case of create snapshot), we need no synchronization. Even easier. Signed-off-by: Glauber Costa --- service/storage_service.cc | 23 +++++++++++++++++++++++ service/storage_service.hh | 26 +++----------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/service/storage_service.cc b/service/storage_service.cc index f4c5249a60..239ecdaee7 100644 --- a/service/storage_service.cc +++ b/service/storage_service.cc @@ -1317,6 +1317,29 @@ 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()); + } + } + + auto deleted_keyspaces = make_lw_shared>(); + return parallel_for_each(keyspaces, [this, tag, deleted_keyspaces] (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); + }); + }); + logger.debug("Cleared out snapshot directories"); +} + + future<> storage_service::start_rpc_server() { fail(unimplemented::cause::STORAGE_SERVICE); #if 0 diff --git a/service/storage_service.hh b/service/storage_service.hh index f02343b282..fe45104836 100644 --- a/service/storage_service.hh +++ b/service/storage_service.hh @@ -1125,34 +1125,14 @@ public: } return Keyspace.open(keyspaceName); } +#endif /** * Remove the snapshot with the given name from the given keyspaces. * If no tag is specified we will remove all snapshots. */ - public void clearSnapshot(String tag, String... keyspaceNames) throws IOException - { - if(tag == null) - tag = ""; - - Set keyspaces = new HashSet<>(); - for (String dataDir : DatabaseDescriptor.getAllDataFileLocations()) - { - for(String keyspaceDir : new File(dataDir).list()) - { - // Only add a ks if it has been specified as a param, assuming params were actually provided. - if (keyspaceNames.length > 0 && !Arrays.asList(keyspaceNames).contains(keyspaceDir)) - continue; - keyspaces.add(keyspaceDir); - } - } - - for (String keyspace : keyspaces) - Keyspace.clearSnapshot(tag, keyspace); - - if (logger.isDebugEnabled()) - logger.debug("Cleared out snapshot directories"); - } + future<> clear_snapshot(sstring tag, std::vector keyspace_names); +#if 0 public Map getSnapshotDetails() {