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

    • 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, 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, OpenSearchException 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(ShardId shardId, String reason)
      cancel all ongoing targets for the given shard
      Parameters:
      reason - reason for cancellation
      shardId - shardId for which to cancel targets
      Returns:
      true if a target was cancelled