mikemccand commented on code in PR #12126: URL: https://github.com/apache/lucene/pull/12126#discussion_r1128355632
########## lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java: ########## @@ -154,7 +151,7 @@ public IndexFileDeleter( || fileName.startsWith(IndexFileNames.PENDING_SEGMENTS))) { // Add this file to refCounts with initial count 0: - getRefCount(fileName); + fileDeleter.getRefCount(fileName); Review Comment: Kinda weird that a method starting with `get` has this set-like side effect, sigh. ########## lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java: ########## @@ -610,76 +601,34 @@ public void checkpoint(SegmentInfos segmentInfos, boolean isCommit) throws IOExc } } + private void logInfo(FileDeleter.MsgType msgType, String msg) { + if (msgType == FileDeleter.MsgType.REF && VERBOSE_REF_COUNTS == false) { Review Comment: Probably you could have just moved the `VERBOSE_REF_COUNTS` down into `FileDeleter`, but since this is a rote refactor it's good to separate / do that later. ########## lucene/core/src/java/org/apache/lucene/util/FileDeleter.java: ########## @@ -0,0 +1,274 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.util; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.NoSuchFileException; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.function.BiConsumer; +import org.apache.lucene.index.IndexFileNames; +import org.apache.lucene.store.Directory; + +/** + * This class provides ability to track the reference counts of a set of index files and delete them + * when their counts decreased to 0. + * + * <p>This class is NOT thread-safe, the user should make sure the thread-safety themselves + */ Review Comment: Can you add `@lucene.internal` javadocs tag? Users should not rely on the future stability of this API? ########## lucene/CHANGES.txt: ########## @@ -112,7 +112,8 @@ New Features Improvements --------------------- -(No changes) +* GITHUB#12126: Refactor part of IndexFileDeleter and ReplicaFileDeleter into a public common utility class + FileDeleter. (Patrick Zhai)s Review Comment: Is that trailing `s` by accident? ########## lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java: ########## @@ -154,7 +151,7 @@ public IndexFileDeleter( || fileName.startsWith(IndexFileNames.PENDING_SEGMENTS))) { // Add this file to refCounts with initial count 0: - getRefCount(fileName); + fileDeleter.getRefCount(fileName); Review Comment: We can maybe later / separately improve the naming, or add a dedicated `initRefCount(fileName)` method or so. ########## lucene/core/src/java/org/apache/lucene/util/FileDeleter.java: ########## @@ -0,0 +1,274 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.util; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.NoSuchFileException; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.function.BiConsumer; +import org.apache.lucene.index.IndexFileNames; +import org.apache.lucene.store.Directory; + +/** + * This class provides ability to track the reference counts of a set of index files and delete them + * when their counts decreased to 0. + * + * <p>This class is NOT thread-safe, the user should make sure the thread-safety themselves + */ +public class FileDeleter { Review Comment: Maybe `final`? This is such a crazy expert class -- it should be used only, but not extended? -- 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