mikemccand commented on code in PR #11815:
URL: https://github.com/apache/lucene/pull/11815#discussion_r1001630980


##########
lucene/misc/src/java/org/apache/lucene/misc/index/IndexRearranger.java:
##########
@@ -139,6 +203,47 @@ private static void addOneSegment(
     writer.addIndexes(readers);
   }
 
+  private static void applyDeletes(
+      IndexWriter writer, IndexReader reader, DocumentSelector selector)
+      throws ExecutionException, InterruptedException {
+    if (selector == null) {
+      // There are no deletes to be applied
+      return;
+    }
+
+    ExecutorService executor =
+        Executors.newFixedThreadPool(
+            Math.min(Runtime.getRuntime().availableProcessors(), 
reader.leaves().size()),
+            new NamedThreadFactory("rearranger"));
+    ArrayList<Future<Void>> futures = new ArrayList<>();
+
+    for (LeafReaderContext context : reader.leaves()) {
+      Callable<Void> applyDeletesToSegment =
+          () -> {
+            applyDeletesToOneSegment(writer, (CodecReader) context.reader(), 
selector);
+            return null;
+          };
+      futures.add(executor.submit(applyDeletesToSegment));
+    }
+
+    for (Future<Void> future : futures) {
+      future.get();
+    }
+    executor.shutdown();
+  }
+
+  private static void applyDeletesToOneSegment(
+      IndexWriter writer, CodecReader segmentReader, DocumentSelector 
selector) throws IOException {
+    Bits deletedDocs = selector.getFilteredDocs(segmentReader);
+    for (int i = 0; i < segmentReader.maxDoc(); ++i) {
+      if (deletedDocs.get(i)) {
+        if (writer.tryDeleteDocument(segmentReader, i) == -1) {
+          throw new IllegalStateException("tryDeleteDocument failed and 
there's no plan B");

Review Comment:
   LOL.
   
   Fortunately, as `tryDeleteDocument` is currently implemented today, it 
should never fail, since you have disabled merging in this writer.



##########
lucene/misc/src/java/org/apache/lucene/misc/index/IndexRearranger.java:
##########
@@ -139,6 +203,47 @@ private static void addOneSegment(
     writer.addIndexes(readers);
   }
 
+  private static void applyDeletes(
+      IndexWriter writer, IndexReader reader, DocumentSelector selector)
+      throws ExecutionException, InterruptedException {
+    if (selector == null) {
+      // There are no deletes to be applied
+      return;
+    }
+
+    ExecutorService executor =
+        Executors.newFixedThreadPool(
+            Math.min(Runtime.getRuntime().availableProcessors(), 
reader.leaves().size()),
+            new NamedThreadFactory("rearranger"));
+    ArrayList<Future<Void>> futures = new ArrayList<>();
+
+    for (LeafReaderContext context : reader.leaves()) {
+      Callable<Void> applyDeletesToSegment =
+          () -> {
+            applyDeletesToOneSegment(writer, (CodecReader) context.reader(), 
selector);
+            return null;
+          };
+      futures.add(executor.submit(applyDeletesToSegment));
+    }
+
+    for (Future<Void> future : futures) {
+      future.get();
+    }
+    executor.shutdown();
+  }
+
+  private static void applyDeletesToOneSegment(
+      IndexWriter writer, CodecReader segmentReader, DocumentSelector 
selector) throws IOException {
+    Bits deletedDocs = selector.getFilteredDocs(segmentReader);
+    for (int i = 0; i < segmentReader.maxDoc(); ++i) {

Review Comment:
   Could we rename `i` to `docid`?



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

Reply via email to