smiklosovic commented on code in PR #3374:
URL: https://github.com/apache/cassandra/pull/3374#discussion_r1686197352
##########
src/java/org/apache/cassandra/service/StorageService.java:
##########
@@ -2969,77 +2958,49 @@ private Keyspace getValidKeyspace(String keyspaceName)
* 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)
+ public void clearSnapshot(String tag, String... keyspaceNames) throws
IOException
{
clearSnapshot(Collections.emptyMap(), tag, keyspaceNames);
}
public void clearSnapshot(Map<String, Object> options, String tag,
String... keyspaceNames)
{
- if (tag == null)
- tag = "";
-
if (options == null)
options = Collections.emptyMap();
- 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);
- }
- }
+ Set<String> keyspaces = new HashSet<>(Arrays.asList(keyspaceNames));
+ long maxCreatedAt = getMaxSnapshotCreatedAt(options);
+
+ SnapshotManager.instance.clearSnapshots(tag, keyspaces, maxCreatedAt);
+ if (logger.isDebugEnabled())
+ logger.debug("Cleared out snapshot directories");
+ }
+
+ private static long getMaxSnapshotCreatedAt(Map<String, Object> options)
+ {
Object olderThan = options.get("older_than");
Object olderThanTimestamp = options.get("older_than_timestamp");
- final long clearOlderThanTimestamp;
+ long maxCreatedAt = Clock.Global.currentTimeMillis();
Review Comment:
So ... this is all fine. Because if you check how it was in TableSnapshot
(1), then we are filtering on time only when it is bigger than 0.
Now the logic is that we put there the current time, indeed, but we do this:
Instant createdAt = ts.getCreatedAt();
if (createdAt != null)
byTimestamp =
createdAt.isBefore(Instant.ofEpochMilli(olderThanTimestamp));
But here, byTimestamp will be `true`, because, presumably, `createdAt` will
be always before the current time. We cant create a snapshot in the future so
byTimestamp would be evaluated to false. So logically the behaviour is same.
(1)
https://github.com/apache/cassandra/blob/trunk/src/java/org/apache/cassandra/service/snapshot/TableSnapshot.java#L341-L346
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]