zhaih commented on code in PR #12126: URL: https://github.com/apache/lucene/pull/12126#discussion_r1105331268
########## lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java: ########## @@ -225,24 +222,18 @@ public IndexFileDeleter( // Now delete anything with ref count at 0. These are // presumably abandoned files eg due to crash of // IndexWriter. - Set<String> toDelete = new HashSet<>(); - for (Map.Entry<String, RefCount> entry : refCounts.entrySet()) { - RefCount rc = entry.getValue(); - final String fileName = entry.getKey(); - if (0 == rc.count) { - // A segments_N file should never have ref count 0 on init: - if (fileName.startsWith(IndexFileNames.SEGMENTS)) { - throw new IllegalStateException( - "file \"" + fileName + "\" has refCount=0, which should never happen on init"); - } - if (infoStream.isEnabled("IFD")) { - infoStream.message("IFD", "init: removing unreferenced file \"" + fileName + "\""); - } - toDelete.add(fileName); + Set<String> toDelete = fileDeleter.getUnrefedFiles(); + for (String fileName : toDelete) { + if (fileName.startsWith(IndexFileNames.SEGMENTS)) { + throw new IllegalStateException( + "file \"" + fileName + "\" has refCount=0, which should never happen on init"); + } + if (infoStream.isEnabled("IFD")) { + infoStream.message("IFD", "init: removing unreferenced file \"" + fileName + "\""); } } - deleteFiles(toDelete); + fileDeleter.deleteFilesIfNoRef(toDelete); Review Comment: Yeah I was struggling with this as well. The reason I put it like this is that I feel like the `IllegalStateException` here is quite important so I don't want to throw it away, but if I put it into say `fileDeleter.clean()`, then it does not always make sense too. -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org