Index: src/java/org/apache/lucene/index/IndexWriter.java
===================================================================
--- src/java/org/apache/lucene/index/IndexWriter.java (revision 793769)
+++ src/java/org/apache/lucene/index/IndexWriter.java (working copy)
@@ -493,14 +493,14 @@
}
// used only by asserts
- synchronized boolean infoIsLive(SegmentInfo info) {
+ public synchronized boolean infoIsLive(SegmentInfo info) {
int idx = segmentInfos.indexOf(info);
assert idx != -1;
assert segmentInfos.get(idx) == info;
return true;
}
- synchronized SegmentInfo mapToLive(SegmentInfo info) {
+ public synchronized SegmentInfo mapToLive(SegmentInfo info) {
int idx = segmentInfos.indexOf(info);
if (idx != -1) {
info = (SegmentInfo) segmentInfos.get(idx);
@@ -508,12 +508,24 @@
return info;
}
- synchronized void release(SegmentReader sr) throws IOException {
+ /**
+ * Release the segment reader (i.e. decRef it and close if there
+ * are no more references.
+ * @param sr
+ * @throws IOException
+ */
+ public synchronized void release(SegmentReader sr) throws IOException {
release(sr, false);
}
+
+ /**
+ * Release the segment reader (i.e. decRef it and close if there
+ * are no more references.
+ * @param sr
+ * @throws IOException
+ */
+ public synchronized void release(SegmentReader sr, boolean drop) throws IOException {
- synchronized void release(SegmentReader sr, boolean drop) throws IOException {
-
final boolean pooled = readerMap.containsKey(sr.getSegmentInfo());
assert !pooled | readerMap.get(sr.getSegmentInfo()) == sr;
@@ -552,7 +564,7 @@
/** Remove all our references to readers, and commits
* any pending changes. */
- public synchronized void close() throws IOException {
+ synchronized void close() throws IOException {
Iterator iter = readerMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry ent = (Map.Entry) iter.next();
@@ -582,7 +594,11 @@
}
}
- public synchronized void commit() throws IOException {
+ /**
+ * Commit all segment reader in the pool.
+ * @throws IOException
+ */
+ synchronized void commit() throws IOException {
Iterator iter = readerMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry ent = (Map.Entry) iter.next();
@@ -604,9 +620,11 @@
}
}
- // Returns a ref to a clone. NOTE: this clone is not
- // enrolled in the pool, so you should simply close()
- // it when you're done (ie, do not call release()).
+ /**
+ * Returns a ref to a clone. NOTE: this clone is not
+ * enrolled in the pool, so you should simply close()
+ * it when you're done (ie, do not call release()).
+ */
public synchronized SegmentReader getReadOnlyClone(SegmentInfo info, boolean doOpenStores, int termInfosIndexDivisor) throws IOException {
SegmentReader sr = get(info, doOpenStores, BufferedIndexInput.BUFFER_SIZE, termInfosIndexDivisor);
try {
@@ -616,11 +634,30 @@
}
}
- // Returns a ref
+ /**
+ * Obtain a SegmentReader from the readerPool. The reader
+ * must be returned by calling {@link #release(SegmentReader)}
+ * @see #release(SegmentReader)
+ * @param info
+ * @param doOpenStores
+ * @return
+ * @throws IOException
+ */
public synchronized SegmentReader get(SegmentInfo info, boolean doOpenStores) throws IOException {
return get(info, doOpenStores, BufferedIndexInput.BUFFER_SIZE, IndexReader.DEFAULT_TERMS_INDEX_DIVISOR);
}
-
+ /**
+ * Obtain a SegmentReader from the readerPool. The reader
+ * must be returned by calling {@link #release(SegmentReader)}
+ *
+ * @see #release(SegmentReader)
+ * @param info
+ * @param doOpenStores
+ * @param readBufferSize
+ * @param termsIndexDivisor
+ * @return
+ * @throws IOException
+ */
public synchronized SegmentReader get(SegmentInfo info, boolean doOpenStores, int readBufferSize, int termsIndexDivisor) throws IOException {
if (poolReaders) {
@@ -664,6 +701,28 @@
}
}
+ /**
+ * If the given segmentInfo has deletions or it's
+ * corresponding segmentReader does, this method returns true.
+ *
+ * If the segmentReader is null, segmentInfo.hasDeletions is returned
+ * otherwise the method returns reader.hasDeletions.
+ *
+ * @param info The segmentInfo used to lookup the corresponding reader in the pool
+ */
+ public boolean hasDeletions(SegmentInfo info) throws IOException {
+ SegmentReader reader = readerPool.getIfExists(info);
+ try {
+ if (reader != null) {
+ return reader.hasDeletions();
+ } else {
+ return info.hasDeletions();
+ }
+ } finally {
+ if (reader != null) readerPool.release(reader);
+ }
+ }
+
synchronized void acquireWrite() {
assert writeThread != Thread.currentThread();
while(writeThread != null || readCount > 0)
Index: src/java/org/apache/lucene/index/LogMergePolicy.java
===================================================================
--- src/java/org/apache/lucene/index/LogMergePolicy.java (revision 793769)
+++ src/java/org/apache/lucene/index/LogMergePolicy.java (working copy)
@@ -303,16 +303,8 @@
int firstSegmentWithDeletions = -1;
for(int i=0;i
NOTE: This API is new and still experimental + * (subject to change suddenly in the next release)
+ */ +public final class SegmentInfos extends Vector { /** The file format version, a negative number. */ /* Works since counter, the old 1st entry, is always >= 0 */ @@ -767,7 +774,7 @@ version = other.version; } - public final void rollbackCommit(Directory dir) throws IOException { + final void rollbackCommit(Directory dir) throws IOException { if (pendingSegnOutput != null) { try { pendingSegnOutput.close(); @@ -796,7 +803,7 @@ * end, so that it is not visible to readers. Once this * is called you must call {@link #finishCommit} to complete * the commit or {@link #rollbackCommit} to abort it. */ - public final void prepareCommit(Directory dir) throws IOException { + final void prepareCommit(Directory dir) throws IOException { if (pendingSegnOutput != null) throw new IllegalStateException("prepareCommit was already called"); write(dir); @@ -822,7 +829,7 @@ return files; } - public final void finishCommit(Directory dir) throws IOException { + final void finishCommit(Directory dir) throws IOException { if (pendingSegnOutput == null) throw new IllegalStateException("prepareCommit was not called"); boolean success = false; @@ -882,7 +889,7 @@ /** Writes & syncs to the Directory dir, taking care to * remove the segments file on exception */ - public final void commit(Directory dir) throws IOException { + final void commit(Directory dir) throws IOException { prepareCommit(dir); finishCommit(dir); } @@ -906,7 +913,7 @@ return userData; } - public void setUserData(Map data) { + void setUserData(Map data) { if (data == null) { userData = Collections.EMPTY_MAP; } else { Index: src/java/org/apache/lucene/index/SegmentReader.java =================================================================== --- src/java/org/apache/lucene/index/SegmentReader.java (revision 793769) +++ src/java/org/apache/lucene/index/SegmentReader.java (working copy) @@ -39,7 +39,11 @@ import org.apache.lucene.util.CloseableThreadLocal; /** @version $Id */ -class SegmentReader extends IndexReader implements Cloneable { +/** + *NOTE: This API is new and still experimental + * (subject to change suddenly in the next release)
+ */ +public class SegmentReader extends IndexReader implements Cloneable { protected boolean readOnly; private SegmentInfo si;