Ensure NrtFutures are notified promptly of new search generation
The internal waiting generation counter in ControlledRealTimeReopenThread is only increased when waitForGeneration is called. This controls whether the min or max refresh time is used for waiting. Because NrtFuture.get is not called directly and listeners may be used instead, this was not guaranteed to happen, leading to long delays. Fix this by doing a dummy wait for 0ms at future construction time. Change the order of refresh listener initialization so any removeIfDone calls are made only after the internal listener within ControlledRealTimeReopenThread updates its searching generation. Change-Id: I0edf4a3d38a160496afaf0587cf14b6fee2f2aa5
This commit is contained in:
@@ -106,6 +106,23 @@ class SubIndex {
|
||||
writer.getIndexWriter(), true, new SearcherFactory());
|
||||
|
||||
notDoneNrtFutures = Sets.newConcurrentHashSet();
|
||||
|
||||
reopenThread = new ControlledRealTimeReopenThread<IndexSearcher>(
|
||||
writer, searcherManager,
|
||||
0.500 /* maximum stale age (seconds) */,
|
||||
0.010 /* minimum stale age (seconds) */);
|
||||
reopenThread.setName("NRT " + dirName);
|
||||
reopenThread.setPriority(Math.min(
|
||||
Thread.currentThread().getPriority() + 2,
|
||||
Thread.MAX_PRIORITY));
|
||||
reopenThread.setDaemon(true);
|
||||
|
||||
// This must be added after the reopen thread is created. The reopen thread
|
||||
// adds its own listener which copies its internally last-refreshed
|
||||
// generation to the searching generation. removeIfDone() depends on the
|
||||
// searching generation being up to date when calling
|
||||
// reopenThread.waitForGeneration(gen, 0), therefore the reopen thread's
|
||||
// internal listener needs to be called first.
|
||||
searcherManager.addListener(new RefreshListener() {
|
||||
@Override
|
||||
public void beforeRefresh() throws IOException {
|
||||
@@ -119,15 +136,6 @@ class SubIndex {
|
||||
}
|
||||
});
|
||||
|
||||
reopenThread = new ControlledRealTimeReopenThread<IndexSearcher>(
|
||||
writer, searcherManager,
|
||||
0.500 /* maximum stale age (seconds) */,
|
||||
0.010 /* minimum stale age (seconds) */);
|
||||
reopenThread.setName("NRT " + dirName);
|
||||
reopenThread.setPriority(Math.min(
|
||||
Thread.currentThread().getPriority() + 2,
|
||||
Thread.MAX_PRIORITY));
|
||||
reopenThread.setDaemon(true);
|
||||
reopenThread.start();
|
||||
}
|
||||
|
||||
@@ -189,6 +197,9 @@ class SubIndex {
|
||||
|
||||
NrtFuture(long gen) {
|
||||
this.gen = gen;
|
||||
// Tell the reopen thread we are waiting on this generation so it uses the
|
||||
// min stale time when refreshing.
|
||||
isGenAvailableNowForCurrentSearcher();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user