Class TransportReplicationAction<Request extends ReplicationRequest<Request>,ReplicaRequest extends ReplicationRequest<ReplicaRequest>,Response extends ReplicationResponse>
- java.lang.Object
-
- org.elasticsearch.action.support.TransportAction<Request,Response>
-
- org.elasticsearch.action.support.replication.TransportReplicationAction<Request,ReplicaRequest,Response>
-
- Direct Known Subclasses:
GlobalCheckpointSyncAction,RetentionLeaseBackgroundSyncAction,TransportShardFlushAction,TransportShardRefreshAction,TransportVerifyShardBeforeCloseAction,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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classTransportReplicationAction.ConcreteReplicaRequest<R extends TransportRequest>static classTransportReplicationAction.ConcreteShardRequest<R extends TransportRequest>a wrapper class to encapsulate a request when being sent to a specific allocation idstatic classTransportReplicationAction.PrimaryResult<ReplicaRequest extends ReplicationRequest<ReplicaRequest>,Response extends ReplicationResponse>static classTransportReplicationAction.ReplicaResponsestatic classTransportReplicationAction.ReplicaResultprotected classTransportReplicationAction.ReplicasProxyTheReplicasProxyis an implementation of theReplicasinterface that performs the actualReplicaRequeston the replica shards.static classTransportReplicationAction.RetryOnReplicaException
-
Field Summary
Fields Modifier and Type Field Description protected ClusterServiceclusterServiceprotected java.lang.Stringexecutorprotected IndexNameExpressionResolverindexNameExpressionResolverprotected IndicesServiceindicesServiceprotected ShardStateActionshardStateActionprotected ThreadPoolthreadPoolprotected TransportRequestOptionstransportOptionsprotected java.lang.StringtransportPrimaryActionprotected java.lang.StringtransportReplicaActionprotected TransportServicetransportService-
Fields inherited from class org.elasticsearch.action.support.TransportAction
actionName, logger, taskManager
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTransportReplicationAction(Settings settings, java.lang.String actionName, TransportService transportService, ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Writeable.Reader<Request> requestReader, Writeable.Reader<ReplicaRequest> replicaRequestReader, java.lang.String executor)protectedTransportReplicationAction(Settings settings, java.lang.String actionName, TransportService transportService, ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Writeable.Reader<Request> requestReader, Writeable.Reader<ReplicaRequest> replicaRequestReader, java.lang.String executor, boolean syncGlobalCheckpointAfterOperation, boolean forceExecutionOnPrimary)
-
Method Summary
Modifier and Type Method Description protected voidacquirePrimaryOperationPermit(IndexShard primary, Request request, ActionListener<Releasable> onAcquired)Executes the logic for acquiring one or more operation permit on a primary shard.protected voidacquireReplicaOperationPermit(IndexShard replica, ReplicaRequest request, ActionListener<Releasable> onAcquired, long primaryTerm, long globalCheckpoint, long maxSeqNoOfUpdatesOrDeletes)Executes the logic for acquiring one or more operation permit on a replica shard.protected voiddoExecute(Task task, Request request, ActionListener<Response> listener)protected ClusterBlockLevelglobalBlockLevel()Cluster level block to check before request execution.protected voidhandleOperationRequest(Request request, TransportChannel channel, Task task)protected voidhandlePrimaryRequest(TransportReplicationAction.ConcreteShardRequest<Request> request, TransportChannel channel, Task task)protected voidhandleReplicaRequest(TransportReplicationAction.ConcreteReplicaRequest<ReplicaRequest> replicaRequest, TransportChannel channel, Task task)ClusterBlockLevelindexBlockLevel()Index level block to check before request execution.protected ReplicationOperation.Replicas<ReplicaRequest>newReplicasProxy()protected abstract ResponsenewResponseInstance(StreamInput in)protected booleanresolveIndex()True if provided index should be resolved when resolving requestprotected voidresolveRequest(IndexMetaData indexMetaData, Request request)Resolves derived values in the request.protected booleanretryPrimaryException(java.lang.Throwable e)protected abstract voidshardOperationOnPrimary(Request shardRequest, IndexShard primary, ActionListener<TransportReplicationAction.PrimaryResult<ReplicaRequest,Response>> listener)Primary operation on node with primary copy.protected abstract TransportReplicationAction.ReplicaResultshardOperationOnReplica(ReplicaRequest shardRequest, IndexShard replica)Synchronously execute the specified replica operation.protected TransportRequestOptionstransportOptions(Settings settings)-
Methods inherited from class org.elasticsearch.action.support.TransportAction
execute, execute, execute
-
-
-
-
Field Detail
-
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
-
indexNameExpressionResolver
protected final IndexNameExpressionResolver indexNameExpressionResolver
-
transportOptions
protected final TransportRequestOptions transportOptions
-
executor
protected final java.lang.String executor
-
transportReplicaAction
protected final java.lang.String transportReplicaAction
-
transportPrimaryAction
protected final java.lang.String transportPrimaryAction
-
-
Constructor Detail
-
TransportReplicationAction
protected TransportReplicationAction(Settings settings, java.lang.String actionName, TransportService transportService, ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Writeable.Reader<Request> requestReader, Writeable.Reader<ReplicaRequest> replicaRequestReader, java.lang.String executor)
-
TransportReplicationAction
protected TransportReplicationAction(Settings settings, java.lang.String actionName, TransportService transportService, ClusterService clusterService, IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, Writeable.Reader<Request> requestReader, Writeable.Reader<ReplicaRequest> replicaRequestReader, java.lang.String executor, boolean syncGlobalCheckpointAfterOperation, boolean forceExecutionOnPrimary)
-
-
Method Detail
-
doExecute
protected void doExecute(Task task, Request request, ActionListener<Response> listener)
- Specified by:
doExecutein classTransportAction<Request extends ReplicationRequest<Request>,Response extends ReplicationResponse>
-
newReplicasProxy
protected ReplicationOperation.Replicas<ReplicaRequest> newReplicasProxy()
-
newResponseInstance
protected abstract Response newResponseInstance(StreamInput in) throws java.io.IOException
- Throws:
java.io.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 onrequest- the request to resolve
-
shardOperationOnPrimary
protected abstract void shardOperationOnPrimary(Request shardRequest, IndexShard primary, ActionListener<TransportReplicationAction.PrimaryResult<ReplicaRequest,Response>> listener)
Primary operation on node with primary copy.- Parameters:
shardRequest- the request to the primary shardprimary- the primary shard to perform the operation on
-
shardOperationOnReplica
protected abstract TransportReplicationAction.ReplicaResult shardOperationOnReplica(ReplicaRequest shardRequest, IndexShard replica) throws java.lang.Exception
Synchronously execute the specified replica operation. This is done under a permit fromIndexShard.acquireReplicaOperationPermit(long, long, long, ActionListener, String, Object).- Parameters:
shardRequest- the request to the replica shardreplica- the replica shard to perform the operation on- Throws:
java.lang.Exception
-
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.
-
resolveIndex
protected boolean resolveIndex()
True if provided index should be resolved when resolving request
-
transportOptions
protected TransportRequestOptions transportOptions(Settings settings)
-
retryPrimaryException
protected boolean retryPrimaryException(java.lang.Throwable e)
-
handleOperationRequest
protected void handleOperationRequest(Request request, TransportChannel channel, Task task)
-
handlePrimaryRequest
protected void handlePrimaryRequest(TransportReplicationAction.ConcreteShardRequest<Request> request, TransportChannel channel, Task task)
-
handleReplicaRequest
protected void handleReplicaRequest(TransportReplicationAction.ConcreteReplicaRequest<ReplicaRequest> replicaRequest, TransportChannel channel, Task task)
-
acquirePrimaryOperationPermit
protected void acquirePrimaryOperationPermit(IndexShard primary, Request request, ActionListener<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, ActionListener<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.
-
-