mirror of https://github.com/apache/lucene.git
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:
parent
dc4450207f
commit
09c2d563f1
|
@ -309,17 +309,28 @@ public class NRTManager implements Closeable {
|
|||
final IndexSearcher startSearcher = noDeletesSearchingGen.get() > searchingGen.get() ? noDeletesCurrentSearcher : currentSearcher;
|
||||
final IndexReader nextReader = startSearcher.getIndexReader().reopen(writer, applyDeletes);
|
||||
|
||||
if (nextReader != startSearcher.getIndexReader()) {
|
||||
final IndexSearcher nextSearcher = new IndexSearcher(nextReader, es);
|
||||
if (warmer != null) {
|
||||
boolean success = false;
|
||||
try {
|
||||
warmer.warm(nextSearcher);
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
nextReader.decRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Transfer reference to swapSearcher:
|
||||
swapSearcher(nextSearcher,
|
||||
newSearcherGen,
|
||||
applyDeletes);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Steals a reference from newSearcher:
|
||||
|
|
|
@ -142,7 +142,15 @@ public class SearcherManager implements Closeable {
|
|||
if (newReader != currentSearcher.getIndexReader()) {
|
||||
IndexSearcher newSearcher = new IndexSearcher(newReader, es);
|
||||
if (warmer != null) {
|
||||
boolean success = false;
|
||||
try {
|
||||
warmer.warm(newSearcher);
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
newReader.decRef();
|
||||
}
|
||||
}
|
||||
}
|
||||
swapSearcher(newSearcher);
|
||||
return true;
|
||||
|
|
|
@ -752,17 +752,18 @@ public class IndexSearcher implements Closeable {
|
|||
public TopDocs call() throws IOException {
|
||||
final TopDocs docs = searcher.search (slice.leaves, weight, filter, after, nDocs);
|
||||
final ScoreDoc[] scoreDocs = docs.scoreDocs;
|
||||
lock.lock();
|
||||
try {
|
||||
for (int j = 0; j < scoreDocs.length; j++) { // merge scoreDocs into hq
|
||||
final ScoreDoc scoreDoc = scoreDocs[j];
|
||||
//it would be so nice if we had a thread-safe insert
|
||||
lock.lock();
|
||||
try {
|
||||
if (scoreDoc == hq.insertWithOverflow(scoreDoc))
|
||||
if (scoreDoc == hq.insertWithOverflow(scoreDoc)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
return docs;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
releaseSearcher(s);
|
||||
|
||||
if (es != null) {
|
||||
es.shutdown();
|
||||
es.awaitTermination(1, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
writer.commit();
|
||||
|
||||
assertEquals("index=" + writer.segString() + " addCount=" + addCount + " delCount=" + delCount, addCount.get() - delCount.get(), writer.numDocs());
|
||||
|
||||
assertFalse(writer.anyNonBulkMerges);
|
||||
doClose();
|
||||
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);
|
||||
dir.close();
|
||||
_TestUtil.rmDir(tempDir);
|
||||
|
|
Loading…
Reference in New Issue