From f678b69ccf4f44c06eb1b605a6fa8016b76c08dc Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Sun, 4 Dec 2011 23:52:51 +0000 Subject: [PATCH] LUCENE-3606: Remove IR.openIfChanged(readOnly) and corresponding impls git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene3606@1210283 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/DirectoryReader.java | 50 +++++++------------ .../org/apache/lucene/index/IndexReader.java | 24 --------- .../apache/lucene/index/SegmentReader.java | 9 +--- 3 files changed, 20 insertions(+), 63 deletions(-) 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 readOnly; 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())