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 <glommer@scylladb.com>
This commit is contained in:
Glauber Costa
2015-10-12 15:31:18 +02:00
parent 2f2a4e83e0
commit 21f84d77fc
2 changed files with 26 additions and 23 deletions

View File

@@ -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<sstring> keyspace_names) {
std::vector<std::reference_wrapper<keyspace>> keyspaces;
for (auto& ksname: keyspace_names) {
try {
keyspaces.push_back(std::reference_wrapper<keyspace>(_db.local().find_keyspace(ksname)));
} catch (no_such_keyspace& e) {
return make_exception_future(std::current_exception());
}
}
auto deleted_keyspaces = make_lw_shared<std::vector<sstring>>();
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

View File

@@ -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<String> 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<sstring> keyspace_names);
#if 0
public Map<String, TabularData> getSnapshotDetails()
{