Skip to content

Commit

Permalink
Add shard closing listener
Browse files Browse the repository at this point in the history
After elastic#108145, the after shard closed listener is no longer called
on the cluster state applier thread. Introduce another event that
is called on the applier thread.

Relates elastic#108145
  • Loading branch information
henningandersen committed May 6, 2024
1 parent 92feb1e commit 71e060f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ public void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexSh
}
}

@Override
public void afterIndexShardClosing(ShardId shardId, @Nullable IndexShard indexShard, Settings indexSettings) {
for (IndexEventListener listener : listeners) {
try {
listener.afterIndexShardClosing(shardId, indexShard, indexSettings);
} catch (Exception e) {
logger.warn(() -> "[" + shardId.getId() + "] failed to invoke after shard closing callback", e);
throw e;
}
}
}

@Override
public void afterIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, Settings indexSettings) {
for (IndexEventListener listener : listeners) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ public void onFailure(Exception e) {
onResponse(null); // otherwise ignore the exception
}
}, l -> indexShard.close(reason, flushEngine, closeExecutor, l));
listener.afterIndexShardClosing(sId, indexShard, indexSettings);
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ default void afterIndexShardStarted(IndexShard indexShard) {}
*/
default void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, Settings indexSettings) {}

/**
* Called after the index shard has been marked closed. It could still be waiting for the async close of the engine.
*/
default void afterIndexShardClosing(ShardId shardId, @Nullable IndexShard indexShard, Settings indexSettings) {}

/**
* Called after the index shard has been closed.
*
Expand Down

0 comments on commit 71e060f

Please sign in to comment.