only fork a refresh if it actually needs to be refreshed
This commit is contained in:
parent
7c4d574a32
commit
fc88cccfb4
|
@ -581,7 +581,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
||||||
|
|
||||||
private void startScheduledTasksIfNeeded() {
|
private void startScheduledTasksIfNeeded() {
|
||||||
if (refreshInterval.millis() > 0) {
|
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);
|
logger.debug("scheduling refresher every {}", refreshInterval);
|
||||||
} else {
|
} else {
|
||||||
logger.debug("scheduled refresher disabled");
|
logger.debug("scheduled refresher disabled");
|
||||||
|
@ -606,28 +606,39 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
|
||||||
|
|
||||||
private class EngineRefresher implements Runnable {
|
private class EngineRefresher implements Runnable {
|
||||||
@Override public void run() {
|
@Override public void run() {
|
||||||
try {
|
// we check before if a refresh is needed, if not, we reschedule, otherwise, we fork, refresh, and then reschedule
|
||||||
if (engine.refreshNeeded()) {
|
if (!engine().refreshNeeded()) {
|
||||||
engine.refresh(new Engine.Refresh(false));
|
if (state != IndexShardState.CLOSED) {
|
||||||
|
refreshScheduledFuture = threadPool.schedule(this, refreshInterval, ThreadPool.ExecutionType.DEFAULT);
|
||||||
}
|
}
|
||||||
} catch (EngineClosedException e) {
|
return;
|
||||||
// we are being closed, ignore
|
}
|
||||||
} catch (RefreshFailedEngineException e) {
|
threadPool.cached().execute(new Runnable() {
|
||||||
if (e.getCause() instanceof InterruptedException) {
|
@Override public void run() {
|
||||||
// ignore, we are being shutdown
|
try {
|
||||||
} else if (e.getCause() instanceof ClosedByInterruptException) {
|
if (engine.refreshNeeded()) {
|
||||||
// ignore, we are being shutdown
|
engine.refresh(new Engine.Refresh(false));
|
||||||
} else if (e.getCause() instanceof ThreadInterruptedException) {
|
}
|
||||||
// ignore, we are being shutdown
|
} catch (EngineClosedException e) {
|
||||||
} else {
|
// we are being closed, ignore
|
||||||
logger.warn("Failed to perform scheduled engine refresh", e);
|
} catch (RefreshFailedEngineException e) {
|
||||||
|
if (e.getCause() instanceof InterruptedException) {
|
||||||
|
// ignore, we are being shutdown
|
||||||
|
} else if (e.getCause() instanceof ClosedByInterruptException) {
|
||||||
|
// ignore, we are being shutdown
|
||||||
|
} else if (e.getCause() instanceof ThreadInterruptedException) {
|
||||||
|
// ignore, we are being shutdown
|
||||||
|
} else {
|
||||||
|
logger.warn("Failed to perform scheduled engine refresh", e);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn("Failed to perform scheduled engine refresh", e);
|
||||||
|
}
|
||||||
|
if (state != IndexShardState.CLOSED) {
|
||||||
|
refreshScheduledFuture = threadPool.schedule(this, refreshInterval, ThreadPool.ExecutionType.DEFAULT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
});
|
||||||
logger.warn("Failed to perform scheduled engine refresh", e);
|
|
||||||
}
|
|
||||||
if (state != IndexShardState.CLOSED) {
|
|
||||||
refreshScheduledFuture = threadPool.schedule(this, refreshInterval, ThreadPool.ExecutionType.THREADED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue