yifan-c commented on a change in pull request #1311:
URL: https://github.com/apache/cassandra/pull/1311#discussion_r759899607



##########
File path: 
src/java/org/apache/cassandra/db/commitlog/CommitLogSegmentManagerCDC.java
##########
@@ -78,11 +81,45 @@ public void discard(CommitLogSegment segment, boolean 
delete)
                 FileUtils.deleteWithConfirm(cdcLink);
 
             File cdcIndexFile = segment.getCDCIndexFile();
-            if (cdcIndexFile.exists())
-                FileUtils.deleteWithConfirm(cdcIndexFile);
+            deleteCDCFiles(cdcLink, cdcIndexFile);
         }
     }
 
+    /**
+     * Delete the oldest CDC commit log segment to free up space.
+     * @return total deleted file size in bytes
+     */
+    public long deleteOldestCommitLogSegment()
+    {
+        File cdcDir = new File(DatabaseDescriptor.getCDCLogLocation());
+        Preconditions.checkState(cdcDir.isDirectory(), "The CDC directory does 
not exist.");
+        File[] files = cdcDir.tryList(f -> 
CommitLogDescriptor.isValid(f.name()));
+        Preconditions.checkState(files != null && files.length > 0, "There 
should be at least 1 CDC commit log segment.");
+        List<File> sorted = Arrays.stream(files)
+                                  
.sorted(Comparator.comparingLong(File::lastModified))
+                                  .collect(Collectors.toList());
+        File oldestCdcFile = sorted.get(0);
+        File cdcIndexFile = 
CommitLogDescriptor.inferCdcIndexFile(oldestCdcFile);
+        return deleteCDCFiles(oldestCdcFile, cdcIndexFile);
+    }
+
+    private long deleteCDCFiles(File cdcFile, File cdcIndexFile)
+    {
+        long total = 0;
+        if (cdcFile.exists())
+        {
+            total += cdcFile.length();
+            FileUtils.deleteWithConfirm(cdcFile);

Review comment:
       👍 Now that there is a `File` wrapper class, 
`org.apache.cassandra.io.util.File`, instead of `java.io.File`. I think the 
intent of the deprecation is to call `delete` on the file wrapper directly.  




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