diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index 2f5df139997..7723b7ae200 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -48,6 +48,8 @@ import org.elasticsearch.index.shard.*; import org.elasticsearch.index.shard.recovery.RecoveryStatus; import org.elasticsearch.index.store.Store; import org.elasticsearch.index.translog.Translog; +import org.elasticsearch.indices.IndicesLifecycle; +import org.elasticsearch.indices.InternalIndicesLifecycle; import org.elasticsearch.threadpool.ThreadPool; import javax.annotation.Nullable; @@ -72,6 +74,8 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I private final IndexCache indexCache; + private final InternalIndicesLifecycle indicesLifecycle; + private final Store store; private final Engine engine; @@ -91,9 +95,10 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I 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) { super(shardId, indexSettings); + this.indicesLifecycle = (InternalIndicesLifecycle) indicesLifecycle; this.store = store; this.engine = engine; this.translog = translog; @@ -191,6 +196,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I logger.debug("state: [{}]->[{}], reason [{}]", state, IndexShardState.STARTED, reason); state = IndexShardState.STARTED; } + indicesLifecycle.afterIndexShardStarted(this); return this; } @@ -435,6 +441,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I // clear unreferenced files translog.clearUnreferenced(); + indicesLifecycle.afterIndexShardStarted(this); } public void performRecoveryOperation(Translog.Operation operation) throws ElasticSearchException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java index 0a5e7c427c4..074923735aa 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java @@ -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. * diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java index 498327177ef..3ebf8dd0739 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java @@ -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) { for (Listener listener : listeners) { listener.beforeIndexClosed(indexService, delete);