Skip to content

Commit

Permalink
Clear snapshots via SnapshotManager
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloricardomg committed Nov 6, 2021
1 parent 1fb024e commit 2b1ec31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/java/org/apache/cassandra/service/StorageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4000,23 +4000,8 @@ private Keyspace getValidKeyspace(String keyspaceName)
*/
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).tryListNames())
{
// 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);
Set<String> keyspaces = new HashSet<>(Arrays.asList(keyspaceNames));
snapshotManager.clearSnapshots(s -> tag == null || s.getTag().equals(tag) && (keyspaces.isEmpty() || keyspaces.contains(s.getKeyspace())));

if (logger.isDebugEnabled())
logger.debug("Cleared out snapshot directories");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,9 @@ private static Set<TableSnapshot> loadSnapshotsFromDataDirectories()
throw new RuntimeException("Error while loading snapshots from data directories.", e);
}
}

public void clearSnapshots(Predicate<TableSnapshot> predicate)
{
getSnapshots(predicate).forEach(this::clearSnapshot);
}
}

0 comments on commit 2b1ec31

Please sign in to comment.