Interface IndexEventListener

All Known Implementing Classes:
PeerRecoverySourceService, PeerRecoveryTargetService, SearchService, SnapshotShardsService, SyncedFlushService

public interface IndexEventListener
An index event listener is the primary extension point for plugins and build-in services to react / listen to per-index and per-shard events. These listeners are registered per-index via IndexModule.addIndexEventListener(IndexEventListener). All listeners have the same lifecycle as the IndexService they are created for.

An IndexEventListener can be used across multiple indices and shards since all callback methods receive sufficient local state via their arguments. Yet, if an instance is shared across indices they might be called concurrently and should not modify local state without sufficient synchronization.

  • Method Details

    • shardRoutingChanged

      default void shardRoutingChanged(IndexShard indexShard, @Nullable ShardRouting oldRouting, ShardRouting newRouting)
      Called when the shard routing has changed state.
      Parameters:
      indexShard - The index shard
      oldRouting - The old routing state (can be null)
      newRouting - The new routing state
    • afterIndexShardCreated

      default void afterIndexShardCreated(IndexShard indexShard)
      Called after the index shard has been created.
    • afterIndexShardStarted

      default void afterIndexShardStarted(IndexShard indexShard)
      Called after the index shard has been started.
    • beforeIndexShardClosed

      default void beforeIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, Settings indexSettings)
      Called before the index shard gets closed.
      Parameters:
      indexShard - The index shard
    • afterIndexShardClosed

      default void afterIndexShardClosed(ShardId shardId, @Nullable IndexShard indexShard, Settings indexSettings)
      Called after the index shard has been closed.
      Parameters:
      shardId - The shard id
    • indexShardStateChanged

      default void indexShardStateChanged(IndexShard indexShard, @Nullable IndexShardState previousState, IndexShardState currentState, @Nullable String reason)
      Called after a shard's IndexShardState changes. The order of concurrent events is preserved. The execution must be lightweight.
      Parameters:
      indexShard - the shard the new state was applied to
      previousState - the previous index shard state if there was one, null otherwise
      currentState - the new shard state
      reason - the reason for the state change if there is one, null otherwise
    • onShardInactive

      default void onShardInactive(IndexShard indexShard)
      Called when a shard is marked as inactive
      Parameters:
      indexShard - The shard that was marked inactive
    • beforeIndexCreated

      default void beforeIndexCreated(Index index, Settings indexSettings)
      Called before the index gets created. Note that this is also called when the index is created on data nodes
    • afterIndexCreated

      default void afterIndexCreated(IndexService indexService)
      Called after the index has been created.
    • beforeIndexRemoved

      default void beforeIndexRemoved(IndexService indexService, IndicesClusterStateService.AllocatedIndices.IndexRemovalReason reason)
      Called before the index get closed.
      Parameters:
      indexService - The index service
      reason - the reason for index removal
    • afterIndexRemoved

      default void afterIndexRemoved(Index index, IndexSettings indexSettings, IndicesClusterStateService.AllocatedIndices.IndexRemovalReason reason)
      Called after the index has been removed.
      Parameters:
      index - The index
      reason - the reason for index removal
    • beforeIndexShardCreated

      default void beforeIndexShardCreated(ShardRouting routing, Settings indexSettings)
      Called before the index shard gets created, before obtaining the shard lock.
      Parameters:
      routing - the routing entry that caused the shard to be created.
      indexSettings - the shards index settings
    • beforeIndexShardDeleted

      default void beforeIndexShardDeleted(ShardId shardId, Settings indexSettings)
      Called before the index shard gets deleted from disk Note: this method is only executed on the first attempt of deleting the shard. Retries are will not invoke this method.
      Parameters:
      shardId - The shard id
      indexSettings - the shards index settings
    • afterIndexShardDeleted

      default void afterIndexShardDeleted(ShardId shardId, Settings indexSettings)
      Called after the index shard has been deleted from disk. Note: this method is only called if the deletion of the shard did finish without an exception
      Parameters:
      shardId - The shard id
      indexSettings - the shards index settings
    • beforeIndexAddedToCluster

      default void beforeIndexAddedToCluster(Index index, Settings indexSettings)
      Called on the Master node only before the IndexService instances is created to simulate an index creation. This happens right before the index and it's metadata is registered in the cluster state
    • onStoreCreated

      default void onStoreCreated(ShardId shardId)
      Called when the given shards store is created. The shard store is created before the shard is created.
      Parameters:
      shardId - the shard ID the store belongs to
    • onStoreClosed

      default void onStoreClosed(ShardId shardId)
      Called when the given shards store is closed. The store is closed once all resource have been released on the store. This implies that all index readers are closed and no recoveries are running.
      Parameters:
      shardId - the shard ID the store belongs to
    • beforeIndexShardRecovery

      default void beforeIndexShardRecovery(IndexShard indexShard, IndexSettings indexSettings)
      Called before the index shard starts to recover. Note: unlike all other methods in this class, this method is not called using the cluster state update thread. When this method is called the shard already transitioned to the RECOVERING state.
      Parameters:
      indexShard - the shard that is about to recover
      indexSettings - the shard's index settings