Class ReplicationCollection<T extends ReplicationTarget>
java.lang.Object
org.opensearch.indices.replication.common.ReplicationCollection<T>
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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
a reference toReplicationTarget
, which implementsAutoCloseable
. -
Constructor Summary
ConstructorDescriptionReplicationCollection
(org.apache.logging.log4j.Logger logger, ThreadPool threadPool) -
Method Summary
Modifier and TypeMethodDescriptionboolean
cancel the target with the given id (if found) and remove it from the target collectionboolean
cancelForShard
(org.opensearch.core.index.shard.ShardId shardId, String reason) cancel all ongoing targets for the given shardvoid
fail
(long id, ReplicationFailedException e, boolean sendShardFailure) fail the target with the given id (if found) and remove it from the target collectionget
(long id) gets theReplicationTarget
for a given id.getOngoingReplicationTarget
(org.opensearch.core.index.shard.ShardId shardId) Get target for shardgetSafe
(long id, org.opensearch.core.index.shard.ShardId shardId) Similar toget(long)
but throws an exception if no target is foundgetTarget
(long id) void
markAsDone
(long id) mark the target with the given id as done (if found)void
requestCancel
(org.opensearch.core.index.shard.ShardId shardId, String reason) Trigger cancel on the target but do not remove it from the collection.reset
(long id, org.opensearch.common.unit.TimeValue activityTimeout) Resets the target event and performs a restart on the current index shardint
size()
the number of ongoing target eventslong
Starts a new target event for the given shard, source node and statelong
Starts a new target event for a given shard, fails the given target if this shard is already replicating.
-
Constructor Details
-
ReplicationCollection
-
-
Method Details
-
startSafe
Starts a new target event for a given shard, fails the given target if this shard is already replicating.- Parameters:
target
- ReplicationTarget to startactivityTimeout
- timeout for entire replication event- Returns:
- The replication id
-
start
Starts a new target event for the given shard, source node and state- Returns:
- the id of the new target event.
-
reset
Resets the target event and performs a restart on the current index shard- Returns:
- newly created Target
- See Also:
-
getTarget
-
get
gets theReplicationTarget
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 callAbstractRefCounted.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 toget(long)
but throws an exception if no target is found -
cancel
cancel the target with the given id (if found) and remove it from the target collection -
fail
fail the target with the given id (if found) and remove it from the target collection- Parameters:
id
- id of the target to faile
- exception with reason for the failuresendShardFailure
- 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
cancel all ongoing targets for the given shard- Parameters:
shardId
- shardId for which to cancel targetsreason
- reason for cancellation- Returns:
- true if a target was cancelled
-
requestCancel
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 cancelreason
-String
reason for cancellation
-
getOngoingReplicationTarget
Get target for shard- Parameters:
shardId
- shardId- Returns:
- ReplicationTarget for input shardId
-