only fork a refresh if it actually needs to be refreshed

This commit is contained in:
kimchy 2011-02-11 02:27:29 +02:00
parent 7c4d574a32
commit fc88cccfb4
1 changed files with 32 additions and 21 deletions

View File

@ -581,7 +581,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
private void startScheduledTasksIfNeeded() {
if (refreshInterval.millis() > 0) {
refreshScheduledFuture = threadPool.schedule(new EngineRefresher(), refreshInterval, ThreadPool.ExecutionType.THREADED);
refreshScheduledFuture = threadPool.schedule(new EngineRefresher(), refreshInterval, ThreadPool.ExecutionType.DEFAULT);
logger.debug("scheduling refresher every {}", refreshInterval);
} else {
logger.debug("scheduled refresher disabled");
@ -605,6 +605,15 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
}
private class EngineRefresher implements Runnable {
@Override public void run() {
// we check before if a refresh is needed, if not, we reschedule, otherwise, we fork, refresh, and then reschedule
if (!engine().refreshNeeded()) {
if (state != IndexShardState.CLOSED) {
refreshScheduledFuture = threadPool.schedule(this, refreshInterval, ThreadPool.ExecutionType.DEFAULT);
}
return;
}
threadPool.cached().execute(new Runnable() {
@Override public void run() {
try {
if (engine.refreshNeeded()) {
@ -626,9 +635,11 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
logger.warn("Failed to perform scheduled engine refresh", e);
}
if (state != IndexShardState.CLOSED) {
refreshScheduledFuture = threadPool.schedule(this, refreshInterval, ThreadPool.ExecutionType.THREADED);
refreshScheduledFuture = threadPool.schedule(this, refreshInterval, ThreadPool.ExecutionType.DEFAULT);
}
}
});
}
}
private class EngineOptimizer implements Runnable {