You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "sukiand (via GitHub)" <gi...@apache.org> on 2023/02/13 21:37:42 UTC

[GitHub] [lucene] sukiand commented on a diff in pull request #12126: Refactor part of IndexFileDeleter and ReplicaFileDeleter into a common utility class

sukiand commented on code in PR #12126:
URL: https://github.com/apache/lucene/pull/12126#discussion_r1105037958


##########
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:
   we get toDelete from `fileDeleter` as well. should this part of code be encaptulated into `fileDeleter` as a whole. like call fileDeleter.clean() or sth.



-- 
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-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org