in server/src/main/java/org/apache/cassandra/sidecar/tasks/CdcRawDirectorySpaceCleaner.java [302:333]
private void cleanupOrphanedIdxFiles(File cdcDir) throws IOException
{
final File[] indexFiles =
cdcDir.listFiles(f -> f.isFile() && CdcUtil.isValidIdxFile(f.getName()));
if (indexFiles == null || indexFiles.length == 0)
return; // exit early when finding no index files
final File[] cdcSegments =
cdcDir.listFiles(f -> f.isFile() && CdcUtil.isLogFile(f.getName()));
Set<String> cdcFileNames = Set.of();
if (cdcSegments != null)
{
cdcFileNames = new HashSet<>(cdcSegments.length);
for (File f : cdcSegments)
{
cdcFileNames.add(f.getName());
}
}
// now, delete all old index files that have no corresponding log files.
for (File idxFile : indexFiles)
{
final String cdcFileName = CdcUtil.idxToLogFileName(idxFile.getName());
if (!cdcFileNames.contains(cdcFileName))
{ // found an orphaned index file
LOGGER.warn("Orphaned Cdc idx file found with no corresponding Cdc segment path={}",
idxFile.toPath());
cdcMetrics.orphanedIdx.metric.update(1L);
Files.deleteIfExists(idxFile.toPath());
}
}
}