Skip to content

[Bug] Fix for stored fields force merge regression #14512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ protected StoredFieldsReader() {}
public StoredFieldsReader getMergeInstance() {
return this;
}

/**
* Optional: reset or close merge resources used in the reader
*
* <p>The default implementation is empty
*/
public void finishMerge() throws IOException {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,16 @@ public int merge(MergeState mergeState) throws IOException {
docCount++;
}
finish(docCount);
finishMerge(mergeState);
return docCount;
}

private void finishMerge(MergeState mergeState) throws IOException {
for (int i = 0; i < mergeState.storedFieldsReaders.length; i++) {
mergeState.storedFieldsReaders[i].finishMerge();
}
}

/**
* A visitor that adds every field it sees.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import java.io.EOFException;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.StoredFieldsReader;
Expand Down Expand Up @@ -104,6 +105,13 @@ private Lucene90CompressingStoredFieldsReader(
this.version = reader.version;
this.fieldInfos = reader.fieldInfos;
this.fieldsStream = reader.fieldsStream.clone();
if (merging) {
try {
this.fieldsStream.updateReadAdvice(ReadAdvice.SEQUENTIAL);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
this.indexReader = reader.indexReader.clone();
this.maxPointer = reader.maxPointer;
this.chunkSize = reader.chunkSize;
Expand Down Expand Up @@ -257,6 +265,11 @@ public void close() throws IOException {
}
}

@Override
public void finishMerge() throws IOException {
this.fieldsStream.updateReadAdvice(ReadAdvice.RANDOM);
}

private static void readField(DataInput in, StoredFieldVisitor visitor, FieldInfo info, int bits)
throws IOException {
switch (bits & TYPE_MASK) {
Expand Down