vigyasharma commented on a change in pull request #633:
URL: https://github.com/apache/lucene/pull/633#discussion_r822184400



##########
File path: lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
##########
@@ -3121,147 +3125,265 @@ private void validateMergeReader(CodecReader leaf) {
    */
   public long addIndexes(CodecReader... readers) throws IOException {
     ensureOpen();
-
-    // long so we can detect int overflow:
-    long numDocs = 0;
     long seqNo;
-    try {
-      if (infoStream.isEnabled("IW")) {
-        infoStream.message("IW", "flush at addIndexes(CodecReader...)");
-      }
-      flush(false, true);
+    long numDocs = 0;
+    final int mergeTimeoutInSeconds = 600;
 
-      String mergedName = newSegmentName();
-      int numSoftDeleted = 0;
-      for (CodecReader leaf : readers) {
-        numDocs += leaf.numDocs();
+    try {
+      // Best effort up front validations
+      for (CodecReader leaf: readers) {
         validateMergeReader(leaf);
-        if (softDeletesEnabled) {
-          Bits liveDocs = leaf.getLiveDocs();
-          numSoftDeleted +=
-              PendingSoftDeletes.countSoftDeletes(
-                  DocValuesFieldExistsQuery.getDocValuesDocIdSetIterator(
-                      config.getSoftDeletesField(), leaf),
-                  liveDocs);
+        for (FieldInfo fi: leaf.getFieldInfos()) {
+          globalFieldNumberMap.verifyFieldInfo(fi);
         }
+        numDocs += leaf.numDocs();
       }
-
-      // Best-effort up front check:
       testReserveDocs(numDocs);
 
-      final IOContext context =
-          new IOContext(
-              new MergeInfo(Math.toIntExact(numDocs), -1, false, 
UNBOUNDED_MAX_MERGE_SEGMENTS));
+      synchronized (this) {
+        ensureOpen();
+        if (merges.areEnabled() == false) {
+          throw new UnsupportedOperationException("Merges are disabled on 
current writer. " +
+            "Cannot execute addIndexes(CodecReaders...) API");
+        }
+      }
+
+      MergePolicy mergePolicy = config.getMergePolicy();
+      MergePolicy.MergeSpecification spec = 
mergePolicy.findMerges(Arrays.asList(readers));

Review comment:
       We allow for cascading to proceed in background by calling a 
`maybeMerge()` at the end of `addIndexes()`.
   
   For `addIndexes(CodecReader...)`, we can only add segments to IW after the 
readers have gone through `SegmentMerger.merge()`. Until then, we don't have 
any segments to add, (unlike the `addIndexes(Directory...)` variant, where we 
already have segments provided in the input). So we wait for the first round of 
merges to complete, by blocking the API on the merges defined in the MergeSpec.
   
   Once these merges complete, we add segments to IW's SegmentInfos, and invoke 
a maybeMerge(), which will cascade any merges on top of these segments in




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