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() {