-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Description
Describe the feature:
Currently, the addRefreshListener method in the IndexShard class is publicly exposed, but expects to receive a Translog.Location and Consumer to add a new RefreshListener. This is fine in the context of indexation where the Translog is readily available, but as a plugin developer there is no way to publicly retrieve the Translog, especially when extending an IndexModule to react to different state changes of shards such as void afterIndexShardStarted(IndexShard indexShard) and void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, Settings indexSettings)
I'm proposing one of two changes within the IndexShard class:
- Publicly expose the
Enginefrom withinIndexShard. This used to be the case, but was changed in previous commits a while back. This would allow plugins to grab theTranslogas well as the last write location and thus build their ownRefreshListeners.
-or-
- Add a new public method within
IndexShardwhich would look something like this
public void addRefreshListenerAtLatestWriteLocation(Consumer<boolean> listener) {
Translog.Location latestLocation = getEngine().getTranslogLastWriteLocation();
addRefreshListener(latestLocation, listener);
}
This method would be safer than option 1 since it keeps the Engine accessor package private. Since it is read only, I don't think this would introduce any synchronization issues.
Making either of these changes would enable plugin developers to make use of RefreshListeners within a cluster and fulfill a couple of use-cases:
-
Retrieve metrics on refresh rates at a shard level rather than an average of all shard refreshes at an index level. This is nice for those of us that maintain clusters with hundreds of shards and the average refresh rate is not particularly useful for us.
-
Build plugins that make use of shard level refresh data and perform actions such as application level cache invalidation based on when data on a specific shard is available for search