Apache Solr open-source search software
LUCENE-3293: Use IOContext.READONCE in VarGapTermsIndexReader to load FST
Simon Willnauer7dcaddec96b6
diff --git a/lucene/src/java/org/apache/lucene/index/SegmentReader.java b/lucene/src/java/org/apache/lucene/index/SegmentReader.javaindex e9a584bbb61..e0af45626b3 100644--- a/lucene/src/java/org/apache/lucene/index/SegmentReader.java+++ b/lucene/src/java/org/apache/lucene/index/SegmentReader.java@@ -90,7 +90,6 @@ public class SegmentReader extends IndexReader implements Cloneable {* @throws IOException if there is a low-level IO error*/public static SegmentReader get(boolean readOnly, SegmentInfo si, int termInfosIndexDivisor, IOContext context) throws CorruptIndexException, IOException {- // TODO should we check if readOnly and context combination makes sense like asserting that if read only we don't get a default?return get(readOnly, si.dir, si, true, termInfosIndexDivisor, context);}@@ -116,7 +115,7 @@ public class SegmentReader extends IndexReader implements Cloneable {if (doOpenStores) {instance.core.openDocStores(si);}- instance.loadLiveDocs();+ instance.loadLiveDocs(context);instance.openNorms(instance.core.cfsDir, context);success = true;} finally {@@ -158,10 +157,10 @@ public class SegmentReader extends IndexReader implements Cloneable {return true;}- private void loadLiveDocs() throws IOException {+ private void loadLiveDocs(IOContext context) throws IOException {// NOTE: the bitvector is stored using the regular directory, not cfsif (hasDeletions(si)) {- liveDocs = new BitVector(directory(), si.getDelFileName(), IOContext.DEFAULT);+ liveDocs = new BitVector(directory(), si.getDelFileName(), new IOContext(context, true));if (liveDocs.getVersion() < BitVector.VERSION_DGAPS_CLEARED) {liveDocs.invertAll();}@@ -274,7 +273,7 @@ public class SegmentReader extends IndexReader implements Cloneable {if (!deletionsUpToDate) {// load deleted docsassert clone.liveDocs == null;- clone.loadLiveDocs();+ clone.loadLiveDocs(IOContext.READ);} else if (liveDocs != null) {liveDocsRef.incrementAndGet();clone.liveDocs = liveDocs;diff --git a/lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexReader.java b/lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexReader.javaindex 14281a4923e..bbc064d7476 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexReader.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/VariableGapTermsIndexReader.java@@ -32,7 +32,6 @@ import org.apache.lucene.index.SegmentInfo;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;-import org.apache.lucene.store.IOContext.Context;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.CodecUtil;import org.apache.lucene.util.fst.Builder;@@ -61,8 +60,7 @@ public class VariableGapTermsIndexReader extends TermsIndexReaderBase {final String segment;public VariableGapTermsIndexReader(Directory dir, FieldInfos fieldInfos, String segment, int indexDivisor, int codecId, IOContext context)throws IOException {-- in = dir.openInput(IndexFileNames.segmentFileName(segment, codecId, VariableGapTermsIndexWriter.TERMS_INDEX_EXTENSION), context);+ in = dir.openInput(IndexFileNames.segmentFileName(segment, codecId, VariableGapTermsIndexWriter.TERMS_INDEX_EXTENSION), new IOContext(context, true));this.segment = segment;boolean success = false;diff --git a/lucene/src/java/org/apache/lucene/store/IOContext.java b/lucene/src/java/org/apache/lucene/store/IOContext.javaindex 04a8964429a..992ff8c2fa0 100644--- a/lucene/src/java/org/apache/lucene/store/IOContext.java+++ b/lucene/src/java/org/apache/lucene/store/IOContext.java@@ -76,7 +76,7 @@ public class IOContext {public IOContext(MergeInfo mergeInfo) {this(Context.MERGE, mergeInfo);}-+private IOContext(Context context, MergeInfo mergeInfo) {assert context != Context.MERGE || mergeInfo != null : "MergeInfo must not be null if context is MERGE";assert context != Context.FLUSH : "Use IOContext(FlushInfo) to create a FLUSH IOContext";@@ -85,6 +85,18 @@ public class IOContext {this.mergeInfo = mergeInfo;this.flushInfo = null;}++ /**+ * This constructor is used to initialize a {@link IOContext} instance with a new value for the readOnce variable.+ * @param ctxt {@link IOContext} object whose information is used to create the new instance except the readOnce variable.+ * @param readOnce The new {@link IOContext} object will use this value for readOnce.+ */+ public IOContext(IOContext ctxt, boolean readOnce) {+ this.context = ctxt.context;+ this.mergeInfo = ctxt.mergeInfo;+ this.flushInfo = ctxt.flushInfo;+ this.readOnce = readOnce;+ }@Overridepublic int hashCode() {