diff --git a/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldMergeState.java b/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldMergeState.java index 15e65091aed..824fe951b5a 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldMergeState.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldMergeState.java @@ -69,7 +69,8 @@ final class PerFieldMergeState { in.maxDocs, in.infoStream, in.intraMergeTaskExecutor, - in.needsIndexSort); + in.needsIndexSort, + in.mergeProgress); } private static class FilterFieldInfos extends FieldInfos { diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java index def9ef06fce..e7f99df5668 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -3453,7 +3453,8 @@ public class IndexWriter trackingDir, globalFieldNumberMap, context, - intraMergeExecutor); + intraMergeExecutor, + merge.getMergeProgress()); if (!merger.shouldMerge()) { return; @@ -5254,7 +5255,8 @@ public class IndexWriter dirWrapper, globalFieldNumberMap, context, - intraMergeExecutor); + intraMergeExecutor, + merge.getMergeProgress()); merge.info.setSoftDelCount(Math.toIntExact(softDeleteCount.get())); merge.checkAborted(); diff --git a/lucene/core/src/java/org/apache/lucene/index/MergeState.java b/lucene/core/src/java/org/apache/lucene/index/MergeState.java index 838699215f0..66aab07fe23 100644 --- a/lucene/core/src/java/org/apache/lucene/index/MergeState.java +++ b/lucene/core/src/java/org/apache/lucene/index/MergeState.java @@ -91,17 +91,22 @@ public class MergeState { /** Indicates if the index needs to be sorted * */ public boolean needsIndexSort; + /** Progress and state for an executing merge. */ + public final MergePolicy.OneMergeProgress mergeProgress; + /** Sole constructor. */ MergeState( List readers, SegmentInfo segmentInfo, InfoStream infoStream, - Executor intraMergeTaskExecutor) + Executor intraMergeTaskExecutor, + MergePolicy.OneMergeProgress mergeProgress) throws IOException { verifyIndexSort(readers, segmentInfo); this.infoStream = infoStream; int numReaders = readers.size(); this.intraMergeTaskExecutor = intraMergeTaskExecutor; + this.mergeProgress = mergeProgress; maxDocs = new int[numReaders]; fieldsProducers = new FieldsProducer[numReaders]; @@ -284,7 +289,8 @@ public class MergeState { int[] maxDocs, InfoStream infoStream, Executor intraMergeTaskExecutor, - boolean needsIndexSort) { + boolean needsIndexSort, + MergePolicy.OneMergeProgress mergeProgress) { this.docMaps = docMaps; this.segmentInfo = segmentInfo; this.mergeFieldInfos = mergeFieldInfos; @@ -301,5 +307,6 @@ public class MergeState { this.infoStream = infoStream; this.intraMergeTaskExecutor = intraMergeTaskExecutor; this.needsIndexSort = needsIndexSort; + this.mergeProgress = mergeProgress; } } diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java b/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java index 5e336c7fef0..7b3c8651d22 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java +++ b/lucene/core/src/java/org/apache/lucene/index/SegmentMerger.java @@ -59,13 +59,15 @@ final class SegmentMerger { Directory dir, FieldInfos.FieldNumbers fieldNumbers, IOContext context, - Executor intraMergeTaskExecutor) + Executor intraMergeTaskExecutor, + MergePolicy.OneMergeProgress mergeProgress) throws IOException { if (context.context() != IOContext.Context.MERGE) { throw new IllegalArgumentException( "IOContext.context should be MERGE; got: " + context.context()); } - mergeState = new MergeState(readers, segmentInfo, infoStream, intraMergeTaskExecutor); + mergeState = + new MergeState(readers, segmentInfo, infoStream, intraMergeTaskExecutor, mergeProgress); mergeStateCreationThread = Thread.currentThread(); directory = dir; this.codec = segmentInfo.getCodec(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDoc.java b/lucene/core/src/test/org/apache/lucene/index/TestDoc.java index 0cdd645e7e0..da7e8572ce7 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDoc.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDoc.java @@ -230,7 +230,6 @@ public class TestDoc extends LuceneTestCase { StringHelper.randomId(), new HashMap<>(), null); - SegmentMerger merger = new SegmentMerger( Arrays.asList(r1, r2), @@ -239,8 +238,8 @@ public class TestDoc extends LuceneTestCase { trackingDir, new FieldInfos.FieldNumbers(null, null), context, - new SameThreadExecutorService()); - + new SameThreadExecutorService(), + new MergePolicy.OneMergeProgress()); merger.merge(); r1.close(); r2.close(); diff --git a/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java b/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java index d3f7ec8a803..0d27ca7bbdb 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestSegmentMerger.java @@ -107,7 +107,8 @@ public class TestSegmentMerger extends LuceneTestCase { mergedDir, new FieldInfos.FieldNumbers(null, null), newIOContext(random(), new IOContext(new MergeInfo(-1, -1, false, -1))), - new SameThreadExecutorService()); + new SameThreadExecutorService(), + new MergePolicy.OneMergeProgress()); MergeState mergeState = merger.merge(); int docsMerged = mergeState.segmentInfo.maxDoc(); assertTrue(docsMerged == 2);