pauloricardomg commented on code in PR #1828:
URL: https://github.com/apache/cassandra/pull/1828#discussion_r973710877


##########
src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java:
##########
@@ -43,34 +46,60 @@ public class ClearSnapshot extends NodeToolCmd
     @Option(title = "clear_all_snapshots", name = "--all", description = 
"Removes all snapshots")
     private boolean clearAllSnapshots = false;
 
+    @Option(title = "older_than", name = "--older-than", description = "Clear 
snapshots older than specified time period.")
+    private String olderThan;
+
+    @Option(title = "older_than_timestamp", name = "--older-than-timestamp", 
description = "Clear snapshots older than specified timestamp.")
+    private Long olderThanTimestamp;

Review Comment:
   Why is this a long and not a isodate (`2022-09-18T12:09:54+0000`) ?



##########
test/unit/org/apache/cassandra/tools/nodetool/ClearSnapshotTest.java:
##########
@@ -19,21 +19,40 @@
 package org.apache.cassandra.tools.nodetool;
 
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.time.Instant;
 import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Pattern;
 import javax.management.openmbean.TabularData;
 
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.db.Keyspace;
+import org.apache.cassandra.io.util.File;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.service.snapshot.SnapshotManifest;
 import org.apache.cassandra.tools.NodeProbe;
 import org.apache.cassandra.tools.ToolRunner;
 
+import static java.lang.String.format;
+import static java.time.temporal.ChronoUnit.HOURS;
+import static java.time.temporal.ChronoUnit.MINUTES;
+import static java.util.Collections.emptyMap;
+import static org.apache.cassandra.tools.ToolRunner.invokeNodetool;
+import static org.apache.cassandra.utils.Clock.Global.currentTimeMillis;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
 
 public class ClearSnapshotTest extends CQLTester

Review Comment:
   Can you add a test that it's not possible to use `--older-than` or 
`--older-than-timestamp` unless `--all` is specified?



##########
src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java:
##########
@@ -43,34 +46,60 @@ public class ClearSnapshot extends NodeToolCmd
     @Option(title = "clear_all_snapshots", name = "--all", description = 
"Removes all snapshots")
     private boolean clearAllSnapshots = false;
 
+    @Option(title = "older_than", name = "--older-than", description = "Clear 
snapshots older than specified time period.")
+    private String olderThan;
+
+    @Option(title = "older_than_timestamp", name = "--older-than-timestamp", 
description = "Clear snapshots older than specified timestamp.")
+    private Long olderThanTimestamp;
+
     @Override
     public void execute(NodeProbe probe)
     {
-        if(snapshotName.isEmpty() && !clearAllSnapshots)
+        if (snapshotName.isEmpty() && !clearAllSnapshots)
             throw new RuntimeException("Specify snapshot name or --all");
 
-        if(!snapshotName.isEmpty() && clearAllSnapshots)
+        if (!snapshotName.isEmpty() && clearAllSnapshots)

Review Comment:
   I think it doesn't make sense to use `--older-than` or 
`--older-than-timestamp` unless `-all` is also specified. Should we error out 
if  `--older-than` or `--older-than-timestamp` is specified without `--all` ?



##########
src/java/org/apache/cassandra/service/StorageService.java:
##########
@@ -4207,8 +4215,25 @@ public void clearSnapshot(String tag, String... 
keyspaceNames)
             }
         }
 
+        Object olderThan = options.get("older_than");

Review Comment:
   I was wondering if we need to support both options in the server or just 
`clearOlderThanTimestamp`, since we can easily construct that in nodetool from 
`olderThan` and not need to parse it in the server. On the other hand, if 
people access via JMX directly they might lose this functionality. WDYT?



##########
test/unit/org/apache/cassandra/tools/nodetool/ClearSnapshotTest.java:
##########
@@ -52,60 +71,142 @@ public static void teardown() throws IOException
     @Test
     public void testClearSnapshot_NoArgs()
     {
-        ToolRunner.ToolResult tool = 
ToolRunner.invokeNodetool("clearsnapshot");
+        ToolRunner.ToolResult tool = invokeNodetool("clearsnapshot");
         assertThat(tool.getExitCode()).isEqualTo(2);
         assertThat(tool.getCleanedStderr()).contains("Specify snapshot name or 
--all");
         
-        tool = ToolRunner.invokeNodetool("clearsnapshot", "--all");
+        tool = invokeNodetool("clearsnapshot", "--all");
         tool.assertOnCleanExit();
     }
 
     @Test
     public void testClearSnapshot_AllAndName()
     {
-        ToolRunner.ToolResult tool = 
ToolRunner.invokeNodetool("clearsnapshot", "-t", "some-name", "--all");
+        ToolRunner.ToolResult tool = invokeNodetool("clearsnapshot", "-t", 
"some-name", "--all");
         assertThat(tool.getExitCode()).isEqualTo(2);
         assertThat(tool.getCleanedStderr()).contains("Specify only one of 
snapshot name or --all");
     }
 
     @Test
     public void testClearSnapshot_RemoveByName()
     {
-        ToolRunner.ToolResult tool = 
ToolRunner.invokeNodetool("snapshot","-t","some-name");
+        ToolRunner.ToolResult tool = 
invokeNodetool("snapshot","-t","some-name");
         tool.assertOnCleanExit();
         assertThat(tool.getStdout()).isNotEmpty();
         
-        Map<String, TabularData> snapshots_before = probe.getSnapshotDetails();
+        Map<String, TabularData> snapshots_before = 
probe.getSnapshotDetails(emptyMap());
         assertThat(snapshots_before).containsKey("some-name");
 
-        tool = ToolRunner.invokeNodetool("clearsnapshot","-t","some-name");
+        tool = invokeNodetool("clearsnapshot","-t","some-name");
         tool.assertOnCleanExit();
         assertThat(tool.getStdout()).isNotEmpty();
         
-        Map<String, TabularData> snapshots_after = probe.getSnapshotDetails();
+        Map<String, TabularData> snapshots_after = 
probe.getSnapshotDetails(emptyMap());
         assertThat(snapshots_after).doesNotContainKey("some-name");
     }
 
     @Test
     public void testClearSnapshot_RemoveMultiple()
     {
-        ToolRunner.ToolResult tool = 
ToolRunner.invokeNodetool("snapshot","-t","some-name");
+        ToolRunner.ToolResult tool = 
invokeNodetool("snapshot","-t","some-name");
         tool.assertOnCleanExit();
         assertThat(tool.getStdout()).isNotEmpty();
 
-        tool = ToolRunner.invokeNodetool("snapshot","-t","some-other-name");
+        tool = invokeNodetool("snapshot","-t","some-other-name");
         tool.assertOnCleanExit();
         assertThat(tool.getStdout()).isNotEmpty();
 
-        Map<String, TabularData> snapshots_before = probe.getSnapshotDetails();
+        Map<String, TabularData> snapshots_before = 
probe.getSnapshotDetails(emptyMap());
         assertThat(snapshots_before).hasSize(2);
 
-        tool = ToolRunner.invokeNodetool("clearsnapshot","--all");
+        tool = invokeNodetool("clearsnapshot","--all");
         tool.assertOnCleanExit();
         assertThat(tool.getStdout()).isNotEmpty();
         
-        Map<String, TabularData> snapshots_after = probe.getSnapshotDetails();
+        Map<String, TabularData> snapshots_after = 
probe.getSnapshotDetails(emptyMap());
         assertThat(snapshots_after).isEmpty();
     }
+
+    @Test
+    public void testClearSnapshotWithOlderThanFlag() throws Throwable

Review Comment:
   Are we testing `olderThanTimestamp` ?



##########
src/java/org/apache/cassandra/service/snapshot/TableSnapshot.java:
##########
@@ -325,7 +325,7 @@ static File getLiveFileFromSnapshotFile(Path 
snapshotFilePath)
         return new File(liveDir.toString(), 
snapshotFilePath.getFileName().toString());
     }
 
-    public static Predicate<TableSnapshot> shouldClearSnapshot(String tag)
+    public static Predicate<TableSnapshot> shouldClearSnapshot(String tag, 
long olderThanTimestamp)

Review Comment:
   Should we add a specific unit test for this method in addition to the 
nodetool tests? I think this method is critical enough that deserves a specific 
unit test to ensure it's doing the right thing (and it will stay that way).



-- 
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]

Reply via email to