only call refresh if its needed, so we check outside of the readLock when async refreshing

This commit is contained in:
kimchy 2011-02-11 01:53:48 +02:00
parent df4f4f056a
commit 7c4d574a32
3 changed files with 12 additions and 1 deletions

View File

@ -66,6 +66,11 @@ public interface Engine extends IndexShardComponent, CloseableComponent {
Searcher searcher() throws EngineException;
/**
* Returns <tt>true</tt> if a refresh is really needed.
*/
boolean refreshNeeded();
/**
* Refreshes the engine for new search operations to reflect the latest
* changes. Pass <tt>true</tt> if the refresh operation should include

View File

@ -588,6 +588,10 @@ public class RobinEngine extends AbstractIndexShardComponent implements Engine,
}
}
@Override public boolean refreshNeeded() {
return dirty;
}
@Override public void refresh(Refresh refresh) throws EngineException {
if (indexWriter == null) {
throw new EngineClosedException(shardId);

View File

@ -607,7 +607,9 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
private class EngineRefresher implements Runnable {
@Override public void run() {
try {
engine.refresh(new Engine.Refresh(false));
if (engine.refreshNeeded()) {
engine.refresh(new Engine.Refresh(false));
}
} catch (EngineClosedException e) {
// we are being closed, ignore
} catch (RefreshFailedEngineException e) {