Skip to content

Commit f8b1a8e

Browse files
committed
add internal event when an index shard is started
1 parent 5e27e3f commit f8b1a8e

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

modules/elasticsearch/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import org.elasticsearch.index.shard.recovery.RecoveryStatus;
4949
import org.elasticsearch.index.store.Store;
5050
import org.elasticsearch.index.translog.Translog;
51+
import org.elasticsearch.indices.IndicesLifecycle;
52+
import org.elasticsearch.indices.InternalIndicesLifecycle;
5153
import org.elasticsearch.threadpool.ThreadPool;
5254

5355
import javax.annotation.Nullable;
@@ -72,6 +74,8 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
7274

7375
private final IndexCache indexCache;
7476

77+
private final InternalIndicesLifecycle indicesLifecycle;
78+
7579
private final Store store;
7680

7781
private final Engine engine;
@@ -91,9 +95,10 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
9195

9296
private RecoveryStatus peerRecoveryStatus;
9397

94-
@Inject public InternalIndexShard(ShardId shardId, @IndexSettings Settings indexSettings, Store store, Engine engine, Translog translog,
98+
@Inject public InternalIndexShard(ShardId shardId, @IndexSettings Settings indexSettings, IndicesLifecycle indicesLifecycle, Store store, Engine engine, Translog translog,
9599
ThreadPool threadPool, MapperService mapperService, IndexQueryParserService queryParserService, IndexCache indexCache) {
96100
super(shardId, indexSettings);
101+
this.indicesLifecycle = (InternalIndicesLifecycle) indicesLifecycle;
97102
this.store = store;
98103
this.engine = engine;
99104
this.translog = translog;
@@ -191,6 +196,7 @@ public InternalIndexShard start(String reason) throws IndexShardStartedException
191196
logger.debug("state: [{}]->[{}], reason [{}]", state, IndexShardState.STARTED, reason);
192197
state = IndexShardState.STARTED;
193198
}
199+
indicesLifecycle.afterIndexShardStarted(this);
194200
return this;
195201
}
196202

@@ -435,6 +441,7 @@ public void performRecoveryFinalization(boolean withFlush) throws ElasticSearchE
435441

436442
// clear unreferenced files
437443
translog.clearUnreferenced();
444+
indicesLifecycle.afterIndexShardStarted(this);
438445
}
439446

440447
public void performRecoveryOperation(Translog.Operation operation) throws ElasticSearchException {

modules/elasticsearch/src/main/java/org/elasticsearch/indices/IndicesLifecycle.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ public void afterIndexShardCreated(IndexShard indexShard) {
7777

7878
}
7979

80+
/**
81+
* Called after the index shard has been started.
82+
*/
83+
public void afterIndexShardStarted(IndexShard indexShard) {
84+
85+
}
86+
8087
/**
8188
* Called before the index get closed.
8289
*

modules/elasticsearch/src/main/java/org/elasticsearch/indices/InternalIndicesLifecycle.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ public void afterIndexShardCreated(IndexShard indexShard) {
7373
}
7474
}
7575

76+
public void afterIndexShardStarted(IndexShard indexShard) {
77+
for (Listener listener : listeners) {
78+
listener.afterIndexShardStarted(indexShard);
79+
}
80+
}
81+
7682
public void beforeIndexClosed(IndexService indexService, boolean delete) {
7783
for (Listener listener : listeners) {
7884
listener.beforeIndexClosed(indexService, delete);

0 commit comments

Comments
 (0)