Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-3606: Remove IR.openIfChanged(readOnly) and corresponding impls

Uwe Schindlerf678b69ccf4f
diff --git a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
index 252dd36e035..55be2c7030d 100644
--- a/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
+++ b/lucene/src/java/org/apache/lucene/index/DirectoryReader.java
@@ -305,7 +305,7 @@ class DirectoryReader extends IndexReader implements Cloneable {
@Override
public final synchronized Object clone() {
try {
- DirectoryReader newReader = doOpenIfChanged((SegmentInfos) segmentInfos.clone(), true, true);
+ DirectoryReader newReader = doOpenIfChanged((SegmentInfos) segmentInfos.clone(), true);
newReader.writer = writer;
newReader.hasDeletions = hasDeletions;
assert newReader.readerFinishedListeners != null;
@@ -317,31 +317,34 @@ class DirectoryReader extends IndexReader implements Cloneable {
@Override
protected final IndexReader doOpenIfChanged() throws CorruptIndexException, IOException {
- return doOpenIfChanged(true, null);
- }
-
- @Override
- protected final IndexReader doOpenIfChanged(boolean openReadOnly) throws CorruptIndexException, IOException {
- return doOpenIfChanged(openReadOnly, null);
+ return doOpenIfChanged(null);
}
@Override
protected final IndexReader doOpenIfChanged(final IndexCommit commit) throws CorruptIndexException, IOException {
- return doOpenIfChanged(true, commit);
+ ensureOpen();
+
+ // If we were obtained by writer.getReader(), re-ask the
+ // writer to get a new reader.
+ if (writer != null) {
+ return doOpenFromWriter(commit);
+ } else {
+ return doOpenNoWriter(commit);
+ }
}
@Override
protected final IndexReader doOpenIfChanged(IndexWriter writer, boolean applyAllDeletes) throws CorruptIndexException, IOException {
+ ensureOpen();
if (writer == this.writer && applyAllDeletes == this.applyAllDeletes) {
- return doOpenIfChanged();
- } else {
+ return doOpenFromWriter(null);
+ } else {
+ // fail by calling supers impl throwing UOE
return super.doOpenIfChanged(writer, applyAllDeletes);
}
}
- private final IndexReader doOpenFromWriter(boolean openReadOnly, IndexCommit commit) throws CorruptIndexException, IOException {
- assert openReadOnly;
-
+ private final IndexReader doOpenFromWriter(IndexCommit commit) throws CorruptIndexException, IOException {
if (commit != null) {
throw new IllegalArgumentException("a reader obtained from IndexWriter.getReader() cannot currently accept a commit");
}
@@ -362,21 +365,7 @@ class DirectoryReader extends IndexReader implements Cloneable {
return reader;
}
- private IndexReader doOpenIfChanged(final boolean openReadOnly, IndexCommit commit) throws CorruptIndexException, IOException {
- ensureOpen();
-
- assert openReadOnly;
-
- // If we were obtained by writer.getReader(), re-ask the
- // writer to get a new reader.
- if (writer != null) {
- return doOpenFromWriter(openReadOnly, commit);
- } else {
- return doOpenNoWriter(openReadOnly, commit);
- }
- }
-
- private synchronized IndexReader doOpenNoWriter(final boolean openReadOnly, IndexCommit commit) throws CorruptIndexException, IOException {
+ private synchronized IndexReader doOpenNoWriter(IndexCommit commit) throws CorruptIndexException, IOException {
if (commit == null) {
if (isCurrent()) {
@@ -396,13 +385,12 @@ class DirectoryReader extends IndexReader implements Cloneable {
protected Object doBody(String segmentFileName) throws CorruptIndexException, IOException {
final SegmentInfos infos = new SegmentInfos();
infos.read(directory, segmentFileName);
- return doOpenIfChanged(infos, false, openReadOnly);
+ return doOpenIfChanged(infos, false);
}
}.run(commit);
}
- private synchronized DirectoryReader doOpenIfChanged(SegmentInfos infos, boolean doClone, boolean openReadOnly) throws CorruptIndexException, IOException {
- assert openReadOnly;
+ private synchronized DirectoryReader doOpenIfChanged(SegmentInfos infos, boolean doClone) throws CorruptIndexException, IOException {
return new DirectoryReader(directory, infos, subReaders, doClone, termInfosIndexDivisor, readerFinishedListeners);
}
diff --git a/lucene/src/java/org/apache/lucene/index/IndexReader.java b/lucene/src/java/org/apache/lucene/index/IndexReader.java
index cff2ea6fff3..6639f889564 100644
--- a/lucene/src/java/org/apache/lucene/index/IndexReader.java
+++ b/lucene/src/java/org/apache/lucene/index/IndexReader.java
@@ -496,20 +496,6 @@ public abstract class IndexReader implements Cloneable,Closeable {
return newReader;
}
- /**
- * If the index has changed since the provided reader was
- * opened, open and return a new reader, with the
- * specified <code>readOnly</code>; else, return
- * null.
- *
- * @see #openIfChanged(IndexReader)
- */
- public static IndexReader openIfChanged(IndexReader oldReader, boolean readOnly) throws IOException {
- final IndexReader newReader = oldReader.doOpenIfChanged(readOnly);
- assert newReader != oldReader;
- return newReader;
- }
-
/**
* If the IndexCommit differs from what the
* provided reader is searching, or the provided reader is
@@ -602,16 +588,6 @@ public abstract class IndexReader implements Cloneable,Closeable {
throw new UnsupportedOperationException("This reader does not support reopen().");
}
- /**
- * If the index has changed since it was opened, open and return a new reader;
- * else, return {@code null}.
- *
- * @see #openIfChanged(IndexReader, boolean)
- */
- protected IndexReader doOpenIfChanged(boolean openReadOnly) throws CorruptIndexException, IOException {
- throw new UnsupportedOperationException("This reader does not support reopen().");
- }
-
/**
* If the index has changed since it was opened, open and return a new reader;
* else, return {@code null}.
diff --git a/lucene/src/java/org/apache/lucene/index/SegmentReader.java b/lucene/src/java/org/apache/lucene/index/SegmentReader.java
index a9efc38ce46..aa9f0bc75cb 100644
--- a/lucene/src/java/org/apache/lucene/index/SegmentReader.java
+++ b/lucene/src/java/org/apache/lucene/index/SegmentReader.java
@@ -193,17 +193,10 @@ public class SegmentReader extends IndexReader implements Cloneable {
}
@Override
- protected synchronized IndexReader doOpenIfChanged()
- throws CorruptIndexException, IOException {
+ protected synchronized IndexReader doOpenIfChanged() throws CorruptIndexException, IOException {
return reopenSegment(si, false, readOnly);
}
- @Override
- protected synchronized IndexReader doOpenIfChanged(boolean openReadOnly)
- throws CorruptIndexException, IOException {
- return reopenSegment(si, false, openReadOnly);
- }
-
synchronized SegmentReader reopenSegment(SegmentInfo si, boolean doClone, boolean openReadOnly) throws CorruptIndexException, IOException {
ensureOpen();
boolean deletionsUpToDate = (this.si.hasDeletions() == si.hasDeletions())