separate writeAllowed check to actual operation compared to optimize/flush/refresh

This commit is contained in:
Shay Banon 2011-12-08 14:14:04 +02:00
parent b7d3f8fc99
commit 76af8425f0
1 changed files with 11 additions and 4 deletions

View File

@ -410,7 +410,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
@Override
public void refresh(Engine.Refresh refresh) throws ElasticSearchException {
writeAllowed();
verifyStarted();
if (logger.isTraceEnabled()) {
logger.trace("refresh with {}", refresh);
}
@ -475,7 +475,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
@Override
public void flush(Engine.Flush flush) throws ElasticSearchException {
writeAllowed();
verifyStarted();
if (logger.isTraceEnabled()) {
logger.trace("flush with {}", flush);
}
@ -486,7 +486,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
@Override
public void optimize(Engine.Optimize optimize) throws ElasticSearchException {
writeAllowed();
verifyStarted();
if (logger.isTraceEnabled()) {
logger.trace("optimize with {}", optimize);
}
@ -505,7 +505,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
@Override
public void recover(Engine.RecoveryHandler recoveryHandler) throws EngineException {
writeAllowed();
verifyStarted();
engine.recover(recoveryHandler);
}
@ -648,6 +648,13 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
}
}
public void verifyStarted() throws IllegalIndexShardStateException {
IndexShardState state = this.state; // one time volatile read
if (state != IndexShardState.STARTED) {
throw new IndexShardNotStartedException(shardId, state);
}
}
private void startScheduledTasksIfNeeded() {
if (refreshInterval.millis() > 0) {
refreshScheduledFuture = threadPool.schedule(refreshInterval, ThreadPool.Names.SAME, new EngineRefresher());