LUCENE-3471: don't close ES until after writer; add try/finally/success logic during warming so we close newly reopened but-not-swapped reader; move IS's locking on merging results out of for loop

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1176478 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2011-09-27 17:19:11 +00:00
parent dc4450207f
commit 09c2d563f1
4 changed files with 49 additions and 24 deletions

View File

@ -309,17 +309,28 @@ public class NRTManager implements Closeable {
final IndexSearcher startSearcher = noDeletesSearchingGen.get() > searchingGen.get() ? noDeletesCurrentSearcher : currentSearcher; final IndexSearcher startSearcher = noDeletesSearchingGen.get() > searchingGen.get() ? noDeletesCurrentSearcher : currentSearcher;
final IndexReader nextReader = startSearcher.getIndexReader().reopen(writer, applyDeletes); final IndexReader nextReader = startSearcher.getIndexReader().reopen(writer, applyDeletes);
if (nextReader != startSearcher.getIndexReader()) {
final IndexSearcher nextSearcher = new IndexSearcher(nextReader, es); final IndexSearcher nextSearcher = new IndexSearcher(nextReader, es);
if (warmer != null) { if (warmer != null) {
boolean success = false;
try {
warmer.warm(nextSearcher); warmer.warm(nextSearcher);
success = true;
} finally {
if (!success) {
nextReader.decRef();
}
}
} }
// Transfer reference to swapSearcher: // Transfer reference to swapSearcher:
swapSearcher(nextSearcher, swapSearcher(nextSearcher,
newSearcherGen, newSearcherGen,
applyDeletes); applyDeletes);
return true; return true;
} else {
return false;
}
} }
// Steals a reference from newSearcher: // Steals a reference from newSearcher:

View File

@ -142,7 +142,15 @@ public class SearcherManager implements Closeable {
if (newReader != currentSearcher.getIndexReader()) { if (newReader != currentSearcher.getIndexReader()) {
IndexSearcher newSearcher = new IndexSearcher(newReader, es); IndexSearcher newSearcher = new IndexSearcher(newReader, es);
if (warmer != null) { if (warmer != null) {
boolean success = false;
try {
warmer.warm(newSearcher); warmer.warm(newSearcher);
success = true;
} finally {
if (!success) {
newReader.decRef();
}
}
} }
swapSearcher(newSearcher); swapSearcher(newSearcher);
return true; return true;

View File

@ -752,17 +752,18 @@ public class IndexSearcher implements Closeable {
public TopDocs call() throws IOException { public TopDocs call() throws IOException {
final TopDocs docs = searcher.search (slice.leaves, weight, filter, after, nDocs); final TopDocs docs = searcher.search (slice.leaves, weight, filter, after, nDocs);
final ScoreDoc[] scoreDocs = docs.scoreDocs; final ScoreDoc[] scoreDocs = docs.scoreDocs;
lock.lock();
try {
for (int j = 0; j < scoreDocs.length; j++) { // merge scoreDocs into hq for (int j = 0; j < scoreDocs.length; j++) { // merge scoreDocs into hq
final ScoreDoc scoreDoc = scoreDocs[j]; final ScoreDoc scoreDoc = scoreDocs[j];
//it would be so nice if we had a thread-safe insert //it would be so nice if we had a thread-safe insert
lock.lock(); if (scoreDoc == hq.insertWithOverflow(scoreDoc)) {
try {
if (scoreDoc == hq.insertWithOverflow(scoreDoc))
break; break;
}
}
} finally { } finally {
lock.unlock(); lock.unlock();
} }
}
return docs; return docs;
} }
} }

View File

@ -616,17 +616,22 @@ public abstract class ThreadedIndexingAndSearchingTestCase extends LuceneTestCas
assertEquals("index=" + writer.segString() + " addCount=" + addCount + " delCount=" + delCount, addCount.get() - delCount.get(), s.getIndexReader().numDocs()); assertEquals("index=" + writer.segString() + " addCount=" + addCount + " delCount=" + delCount, addCount.get() - delCount.get(), s.getIndexReader().numDocs());
releaseSearcher(s); releaseSearcher(s);
if (es != null) {
es.shutdown();
es.awaitTermination(1, TimeUnit.SECONDS);
}
writer.commit(); writer.commit();
assertEquals("index=" + writer.segString() + " addCount=" + addCount + " delCount=" + delCount, addCount.get() - delCount.get(), writer.numDocs()); assertEquals("index=" + writer.segString() + " addCount=" + addCount + " delCount=" + delCount, addCount.get() - delCount.get(), writer.numDocs());
assertFalse(writer.anyNonBulkMerges); assertFalse(writer.anyNonBulkMerges);
doClose(); doClose();
writer.close(false); writer.close(false);
// Cannot shutdown until after writer is closed because
// writer has merged segment warmer that uses IS to run
// searches, and that IS may be using this es!
if (es != null) {
es.shutdown();
es.awaitTermination(1, TimeUnit.SECONDS);
}
_TestUtil.checkIndex(dir); _TestUtil.checkIndex(dir);
dir.close(); dir.close();
_TestUtil.rmDir(tempDir); _TestUtil.rmDir(tempDir);