Class ReplicationCollection<T extends ReplicationTarget>

java.lang.Object
org.opensearch.indices.replication.common.ReplicationCollection<T>

public class ReplicationCollection<T extends ReplicationTarget> extends Object
This class holds a collection of all on going replication events on the current node (i.e., the node is the target node of those events). The class is used to guarantee concurrent semantics such that once an event was done/cancelled/failed no other thread will be able to find it. Last, the ReplicationCollection.ReplicationRef inner class verifies that temporary files and store will only be cleared once on going usage is finished.
Opensearch.internal:
  • Constructor Details

    • ReplicationCollection

      public ReplicationCollection(org.apache.logging.log4j.Logger logger, ThreadPool threadPool)
  • Method Details

    • startSafe

      public long startSafe(T target, org.opensearch.common.unit.TimeValue activityTimeout)
      Starts a new target event for a given shard, fails the given target if this shard is already replicating.
      Parameters:
      target - ReplicationTarget to start
      activityTimeout - timeout for entire replication event
      Returns:
      The replication id
    • start

      public long start(T target, org.opensearch.common.unit.TimeValue activityTimeout)
      Starts a new target event for the given shard, source node and state
      Returns:
      the id of the new target event.
    • reset

      public T reset(long id, org.opensearch.common.unit.TimeValue activityTimeout)
      Resets the target event and performs a restart on the current index shard
      Returns:
      newly created Target
      See Also:
    • getTarget

      public T getTarget(long id)
    • get

      public ReplicationCollection.ReplicationRef<T> get(long id)
      gets the ReplicationTarget for a given id. The ShardTarget returned has it's ref count already incremented to make sure it's safe to use. However, you must call AbstractRefCounted.decRef() when you are done with it, typically by using this method in a try-with-resources clause.

      Returns null if target event is not found

    • getSafe

      public ReplicationCollection.ReplicationRef<T> getSafe(long id, org.opensearch.core.index.shard.ShardId shardId)
      Similar to get(long) but throws an exception if no target is found
    • cancel

      public boolean cancel(long id, String reason)
      cancel the target with the given id (if found) and remove it from the target collection
    • fail

      public void fail(long id, ReplicationFailedException e, boolean sendShardFailure)
      fail the target with the given id (if found) and remove it from the target collection
      Parameters:
      id - id of the target to fail
      e - exception with reason for the failure
      sendShardFailure - true a shard failed message should be sent to the master
    • markAsDone

      public void markAsDone(long id)
      mark the target with the given id as done (if found)
    • size

      public int size()
      the number of ongoing target events
    • cancelForShard

      public boolean cancelForShard(org.opensearch.core.index.shard.ShardId shardId, String reason)
      cancel all ongoing targets for the given shard
      Parameters:
      shardId - shardId for which to cancel targets
      reason - reason for cancellation
      Returns:
      true if a target was cancelled
    • requestCancel

      public void requestCancel(org.opensearch.core.index.shard.ShardId shardId, String reason)
      Trigger cancel on the target but do not remove it from the collection. This is intended to be called to ensure replication events are removed from the collection only when the target has closed.
      Parameters:
      shardId - ShardId shard events to cancel
      reason - String reason for cancellation
    • getOngoingReplicationTarget

      public T getOngoingReplicationTarget(org.opensearch.core.index.shard.ShardId shardId)
      Get target for shard
      Parameters:
      shardId - shardId
      Returns:
      ReplicationTarget for input shardId