Class TransportReplicationAction<Request extends ReplicationRequest<Request>,ReplicaRequest extends ReplicationRequest<ReplicaRequest>,Response extends ReplicationResponse>

java.lang.Object
org.opensearch.action.support.TransportAction<Request,Response>
org.opensearch.action.support.replication.TransportReplicationAction<Request,ReplicaRequest,Response>
Direct Known Subclasses:
GlobalCheckpointSyncAction, PublishCheckpointAction, RetentionLeaseBackgroundSyncAction, TransportShardFlushAction, TransportShardRefreshAction, TransportVerifyShardBeforeCloseAction, TransportVerifyShardIndexBlockAction, TransportWriteAction

public abstract class TransportReplicationAction<Request extends ReplicationRequest<Request>,ReplicaRequest extends ReplicationRequest<ReplicaRequest>,Response extends ReplicationResponse> extends TransportAction<Request,Response>
Base class for requests that should be executed on a primary copy followed by replica copies. Subclasses can resolve the target shard and provide implementation for primary and replica operations.

The action samples cluster state on the receiving node to reroute to node with primary copy and on the primary node to validate request before primary operation followed by sampling state again for resolving nodes with replica copies to perform replication.

Opensearch.internal:
  • Field Details

    • REPLICATION_RETRY_TIMEOUT

      public static final Setting<org.opensearch.common.unit.TimeValue> REPLICATION_RETRY_TIMEOUT
      The timeout for retrying replication requests.
    • REPLICATION_INITIAL_RETRY_BACKOFF_BOUND

      public static final Setting<org.opensearch.common.unit.TimeValue> REPLICATION_INITIAL_RETRY_BACKOFF_BOUND
      The maximum bound for the first retry backoff for failed replication operations. The backoff bound will increase exponential if failures continue.
    • PRIMARY_ACTION_SUFFIX

      public static final String PRIMARY_ACTION_SUFFIX
      Making primary and replica actions suffixes as constant
      See Also:
    • REPLICA_ACTION_SUFFIX

      public static final String REPLICA_ACTION_SUFFIX
      See Also:
    • threadPool

      protected final ThreadPool threadPool
    • transportService

      protected final TransportService transportService
    • clusterService

      protected final ClusterService clusterService
    • shardStateAction

      protected final ShardStateAction shardStateAction
    • indicesService

      protected final IndicesService indicesService
    • transportOptions

      protected final TransportRequestOptions transportOptions
    • executor

      protected final String executor
    • forceExecutionOnPrimary

      protected final boolean forceExecutionOnPrimary
    • transportReplicaAction

      protected final String transportReplicaAction
    • transportPrimaryAction

      protected final String transportPrimaryAction
  • Constructor Details

  • Method Details

    • doExecute

      protected void doExecute(Task task, Request request, org.opensearch.core.action.ActionListener<Response> listener)
      Specified by:
      doExecute in class TransportAction<Request extends ReplicationRequest<Request>,Response extends ReplicationResponse>
    • newReplicasProxy

      protected ReplicationOperation.Replicas<ReplicaRequest> newReplicasProxy()
    • primaryTermValidationReplicasProxy

      protected ReplicationOperation.Replicas<ReplicaRequest> primaryTermValidationReplicasProxy()
      This returns a ReplicaProxy that is used for primary term validation. The default behavior is that the control must not reach inside the performOn method for ReplicationActions. However, the implementations of the underlying class can provide primary term validation proxy that can allow performOn method to make calls to replica.
      Returns:
      Primary term validation replicas proxy.
    • getReplicationMode

      public ReplicationMode getReplicationMode(IndexShard indexShard)
      This method is used for defining the ReplicationMode override per TransportReplicationAction.
      Parameters:
      indexShard - index shard used to determining the policy.
      Returns:
      the overridden replication mode.
    • newResponseInstance

      protected abstract Response newResponseInstance(org.opensearch.core.common.io.stream.StreamInput in) throws IOException
      Throws:
      IOException
    • resolveRequest

      protected void resolveRequest(IndexMetadata indexMetadata, Request request)
      Resolves derived values in the request. For example, the target shard id of the incoming request, if not set at request construction. Additional processing or validation of the request should be done here.
      Parameters:
      indexMetadata - index metadata of the concrete index this request is going to operate on
      request - the request to resolve
    • shardOperationOnPrimary

      protected abstract void shardOperationOnPrimary(Request shardRequest, IndexShard primary, org.opensearch.core.action.ActionListener<TransportReplicationAction.PrimaryResult<ReplicaRequest,Response>> listener)
      Primary operation on node with primary copy.
      Parameters:
      shardRequest - the request to the primary shard
      primary - the primary shard to perform the operation on
    • shardOperationOnReplica

      protected abstract void shardOperationOnReplica(ReplicaRequest shardRequest, IndexShard replica, org.opensearch.core.action.ActionListener<TransportReplicationAction.ReplicaResult> listener)
      Execute the specified replica operation. This is done under a permit from IndexShard.acquireReplicaOperationPermit(long, long, long, ActionListener, String, Object).
      Parameters:
      shardRequest - the request to the replica shard
      replica - the replica shard to perform the operation on
    • globalBlockLevel

      @Nullable protected ClusterBlockLevel globalBlockLevel()
      Cluster level block to check before request execution. Returning null means that no blocks need to be checked.
    • indexBlockLevel

      @Nullable public ClusterBlockLevel indexBlockLevel()
      Index level block to check before request execution. Returning null means that no blocks need to be checked.
    • transportOptions

      protected TransportRequestOptions transportOptions(Settings settings)
    • retryPrimaryException

      protected boolean retryPrimaryException(Throwable e)
    • checkOperationLimits

      protected org.opensearch.common.lease.Releasable checkOperationLimits(Request request)
    • handlePrimaryRequest

      protected void handlePrimaryRequest(TransportReplicationAction.ConcreteShardRequest<Request> request, TransportChannel channel, Task task)
    • checkPrimaryLimits

      protected org.opensearch.common.lease.Releasable checkPrimaryLimits(Request request, boolean rerouteWasLocal, boolean localRerouteInitiatedByNodeClient)
    • adaptResponse

      protected void adaptResponse(Response response, IndexShard indexShard)
    • handleReplicaRequest

      protected void handleReplicaRequest(TransportReplicationAction.ConcreteReplicaRequest<ReplicaRequest> replicaRequest, TransportChannel channel, Task task)
    • checkReplicaLimits

      protected org.opensearch.common.lease.Releasable checkReplicaLimits(ReplicaRequest request)
    • getIndexShard

      protected IndexShard getIndexShard(org.opensearch.core.index.shard.ShardId shardId)
    • acquirePrimaryOperationPermit

      protected void acquirePrimaryOperationPermit(IndexShard primary, Request request, org.opensearch.core.action.ActionListener<org.opensearch.common.lease.Releasable> onAcquired)
      Executes the logic for acquiring one or more operation permit on a primary shard. The default is to acquire a single permit but this method can be overridden to acquire more.
    • acquireReplicaOperationPermit

      protected void acquireReplicaOperationPermit(IndexShard replica, ReplicaRequest request, org.opensearch.core.action.ActionListener<org.opensearch.common.lease.Releasable> onAcquired, long primaryTerm, long globalCheckpoint, long maxSeqNoOfUpdatesOrDeletes)
      Executes the logic for acquiring one or more operation permit on a replica shard. The default is to acquire a single permit but this method can be overridden to acquire more.
    • setPhase

      protected static void setPhase(ReplicationTask task, String phase)
      Sets the current phase on the task if it isn't null. Pulled into its own method because its more convenient that way.