Skip to content

Provide a way to create RefreshListeners at the tip of the Translog #36541

@clandry94

Description

@clandry94

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:

  1. Publicly expose the Engine from within IndexShard. This used to be the case, but was changed in previous commits a while back. This would allow plugins to grab the Translog as well as the last write location and thus build their own RefreshListeners.

-or-

  1. Add a new public method within IndexShard which 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:

  1. 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.

  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Distributed Indexing/EngineAnything around managing Lucene and the Translog in an open shard.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions