From ba417b593fdf40a9c700b9d12f2d4bf0dec0fe8e Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Thu, 29 Jul 2021 08:28:39 -0400 Subject: [PATCH] LUCENE-10032: Remove leafDocMaps from MergeState (#222) These maps are no longer useful after LUCENE-8505. --- .../org/apache/lucene/index/IndexWriter.java | 13 +++--- .../org/apache/lucene/index/MergeState.java | 42 ++++--------------- 2 files changed, 12 insertions(+), 43 deletions(-) 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 05198829dd8..580ea73a0a5 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -4138,7 +4138,6 @@ public class IndexWriter assert rld != null : "seg=" + info.info.name; MergeState.DocMap segDocMap = mergeState.docMaps[i]; - MergeState.DocMap segLeafDocMap = mergeState.leafDocMaps[i]; carryOverHardDeletes( mergedDeletesAndUpdates, @@ -4146,8 +4145,7 @@ public class IndexWriter mergeState.liveDocs[i], merge.getMergeReader().get(i).hardLiveDocs, rld.getHardLiveDocs(), - segDocMap, - segLeafDocMap); + segDocMap); // Now carry over all doc values updates that were resolved while we were merging, remapping // the docIDs to the newly merged docIDs. @@ -4200,7 +4198,7 @@ public class IndexWriter DocValuesFieldUpdates.Iterator it = updates.iterator(); int doc; while ((doc = it.nextDoc()) != NO_MORE_DOCS) { - int mappedDoc = segDocMap.get(segLeafDocMap.get(doc)); + int mappedDoc = segDocMap.get(doc); if (mappedDoc != -1) { if (it.hasValue()) { // not deleted @@ -4250,8 +4248,7 @@ public class IndexWriter Bits mergeLiveDocs, // the liveDocs used to build the segDocMaps Bits prevHardLiveDocs, // the hard deletes when the merge reader was pulled Bits currentHardLiveDocs, // the current hard deletes - MergeState.DocMap segDocMap, - MergeState.DocMap segLeafDocMap) + MergeState.DocMap segDocMap) throws IOException { assert mergeLiveDocs == null || mergeLiveDocs.length() == maxDoc; @@ -4293,7 +4290,7 @@ public class IndexWriter assert currentHardLiveDocs.get(j) == false; } else if (carryOverDelete.test(j)) { // the document was deleted while we were merging: - mergedReadersAndUpdates.delete(segDocMap.get(segLeafDocMap.get(j))); + mergedReadersAndUpdates.delete(segDocMap.get(j)); } } } @@ -4303,7 +4300,7 @@ public class IndexWriter // does: for (int j = 0; j < maxDoc; j++) { if (carryOverDelete.test(j)) { - mergedReadersAndUpdates.delete(segDocMap.get(segLeafDocMap.get(j))); + mergedReadersAndUpdates.delete(segDocMap.get(j)); } } } 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 93d3a2847aa..6bc7e76440a 100644 --- a/lucene/core/src/java/org/apache/lucene/index/MergeState.java +++ b/lucene/core/src/java/org/apache/lucene/index/MergeState.java @@ -19,7 +19,6 @@ package org.apache.lucene.index; import static org.apache.lucene.index.IndexWriter.isCongruentSort; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import java.util.Locale; import org.apache.lucene.codecs.DocValuesProducer; @@ -45,10 +44,6 @@ public class MergeState { /** Maps document IDs from old segments to document IDs in the new segment */ public final DocMap[] docMaps; - // Only used by IW when it must remap deletes that arrived against the merging segments while a - // merge was running: - final DocMap[] leafDocMaps; - /** {@link SegmentInfo} of the newly merged segment. */ public final SegmentInfo segmentInfo; @@ -92,15 +87,11 @@ public class MergeState { public boolean needsIndexSort; /** Sole constructor. */ - MergeState(List originalReaders, SegmentInfo segmentInfo, InfoStream infoStream) + MergeState(List readers, SegmentInfo segmentInfo, InfoStream infoStream) throws IOException { - + verifyIndexSort(readers, segmentInfo); this.infoStream = infoStream; - - final Sort indexSort = segmentInfo.getIndexSort(); - int numReaders = originalReaders.size(); - leafDocMaps = new DocMap[numReaders]; - List readers = maybeSortReaders(originalReaders, segmentInfo); + int numReaders = readers.size(); maxDocs = new int[numReaders]; fieldsProducers = new FieldsProducer[numReaders]; @@ -158,7 +149,7 @@ public class MergeState { segmentInfo.setMaxDoc(numDocs); this.segmentInfo = segmentInfo; - this.docMaps = buildDocMaps(readers, indexSort); + this.docMaps = buildDocMaps(readers, segmentInfo.getIndexSort()); } // Remap docIDs around deletions @@ -226,28 +217,12 @@ public class MergeState { } } - private List maybeSortReaders( - List originalReaders, SegmentInfo segmentInfo) throws IOException { - - // Default to identity: - for (int i = 0; i < originalReaders.size(); i++) { - leafDocMaps[i] = - new DocMap() { - @Override - public int get(int docID) { - return docID; - } - }; - } - + private static void verifyIndexSort(List readers, SegmentInfo segmentInfo) { Sort indexSort = segmentInfo.getIndexSort(); if (indexSort == null) { - return originalReaders; + return; } - - List readers = new ArrayList<>(originalReaders.size()); - - for (CodecReader leaf : originalReaders) { + for (CodecReader leaf : readers) { Sort segmentSort = leaf.getMetaData().getSort(); if (segmentSort == null || isCongruentSort(indexSort, segmentSort) == false) { throw new IllegalArgumentException( @@ -256,10 +231,7 @@ public class MergeState { + " but to-be-merged segment has sort=" + (segmentSort == null ? "null" : segmentSort)); } - readers.add(leaf); } - - return readers; } /** A map of doc IDs. */