add internal event when an index shard is started

This commit is contained in:
kimchy 2011-01-12 20:47:35 +02:00
parent 5e27e3fca4
commit f8b1a8e38b
3 changed files with 21 additions and 1 deletions

View File

@ -48,6 +48,8 @@ import org.elasticsearch.index.shard.*;
import org.elasticsearch.index.shard.recovery.RecoveryStatus; import org.elasticsearch.index.shard.recovery.RecoveryStatus;
import org.elasticsearch.index.store.Store; import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.indices.IndicesLifecycle;
import org.elasticsearch.indices.InternalIndicesLifecycle;
import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.threadpool.ThreadPool;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -72,6 +74,8 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
private final IndexCache indexCache; private final IndexCache indexCache;
private final InternalIndicesLifecycle indicesLifecycle;
private final Store store; private final Store store;
private final Engine engine; private final Engine engine;
@ -91,9 +95,10 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
private RecoveryStatus peerRecoveryStatus; private RecoveryStatus peerRecoveryStatus;
@Inject public InternalIndexShard(ShardId shardId, @IndexSettings Settings indexSettings, Store store, Engine engine, Translog translog, @Inject public InternalIndexShard(ShardId shardId, @IndexSettings Settings indexSettings, IndicesLifecycle indicesLifecycle, Store store, Engine engine, Translog translog,
ThreadPool threadPool, MapperService mapperService, IndexQueryParserService queryParserService, IndexCache indexCache) { ThreadPool threadPool, MapperService mapperService, IndexQueryParserService queryParserService, IndexCache indexCache) {
super(shardId, indexSettings); super(shardId, indexSettings);
this.indicesLifecycle = (InternalIndicesLifecycle) indicesLifecycle;
this.store = store; this.store = store;
this.engine = engine; this.engine = engine;
this.translog = translog; this.translog = translog;
@ -191,6 +196,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
logger.debug("state: [{}]->[{}], reason [{}]", state, IndexShardState.STARTED, reason); logger.debug("state: [{}]->[{}], reason [{}]", state, IndexShardState.STARTED, reason);
state = IndexShardState.STARTED; state = IndexShardState.STARTED;
} }
indicesLifecycle.afterIndexShardStarted(this);
return this; return this;
} }
@ -435,6 +441,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
// clear unreferenced files // clear unreferenced files
translog.clearUnreferenced(); translog.clearUnreferenced();
indicesLifecycle.afterIndexShardStarted(this);
} }
public void performRecoveryOperation(Translog.Operation operation) throws ElasticSearchException { public void performRecoveryOperation(Translog.Operation operation) throws ElasticSearchException {

View File

@ -77,6 +77,13 @@ public interface IndicesLifecycle {
} }
/**
* Called after the index shard has been started.
*/
public void afterIndexShardStarted(IndexShard indexShard) {
}
/** /**
* Called before the index get closed. * Called before the index get closed.
* *

View File

@ -73,6 +73,12 @@ public class InternalIndicesLifecycle extends AbstractComponent implements Indic
} }
} }
public void afterIndexShardStarted(IndexShard indexShard) {
for (Listener listener : listeners) {
listener.afterIndexShardStarted(indexShard);
}
}
public void beforeIndexClosed(IndexService indexService, boolean delete) { public void beforeIndexClosed(IndexService indexService, boolean delete) {
for (Listener listener : listeners) { for (Listener listener : listeners) {
listener.beforeIndexClosed(indexService, delete); listener.beforeIndexClosed(indexService, delete);