Class ReplicationRequest<Request extends ReplicationRequest<Request>>

All Implemented Interfaces:
IndicesRequest, Writeable, RefCounted, TaskAwareRequest, TransportRequest
Direct Known Subclasses:
BasicReplicationRequest, GlobalCheckpointSyncAction.Request, ReplicatedWriteRequest, RetentionLeaseBackgroundSyncAction.Request, ShardFlushRequest, ShardRefreshReplicaRequest, TransportVerifyShardBeforeCloseAction.ShardRequest, TransportVerifyShardIndexBlockAction.ShardRequest

public abstract class ReplicationRequest<Request extends ReplicationRequest<Request>> extends LegacyActionRequest implements IndicesRequest
Requests that are run on a particular replica, first on the primary and then on the replicas like IndexRequest or TransportShardRefreshAction.
  • Field Details

    • DEFAULT_TIMEOUT

      public static final TimeValue DEFAULT_TIMEOUT
    • shardId

      protected final ShardId shardId
      Target shard the request should execute on. In case of index and delete requests, shard id gets resolved by the transport action before performing request operation and at request creation time for shard-level bulk, refresh and flush requests.
    • timeout

      protected TimeValue timeout
    • index

      protected String index
    • reshardSplitShardCountSummary

      protected final int reshardSplitShardCountSummary
      The reshardSplitShardCountSummary has been added to accommodate the Resharding feature. This is populated when the coordinator is deciding which shards a request applies to. For example, BulkOperation splits an incoming bulk request into shard level BulkShardRequest based on its cluster state view of the number of shards that are ready for indexing. The purpose of this metadata is to reconcile the cluster state visible at the coordinating node with that visible at the source shard node. (w.r.t resharding). When an index is being split, there is a point in time when the newly created shard (target shard) takes over its portion of the document space from the original shard (source shard). Although the handoff is atomic at the original (source shard) and new shards (target shard), there is a window of time between the coordinating node creating a shard request and the shard receiving and processing it. This field is used by the original shard (source shard) when it processes the request to detect whether the coordinator's view of the new shard's state when it created the request matches the shard's current state, or whether the request must be reprocessed taking into account the current shard states. Note that we are able to get away with a single number, instead of an array of target shard states, because we only allow splits in increments of 2x. Example 1: Suppose we are resharding an index from 2 -> 4 shards. While splitting a bulk request, the coordinator observes that target shards are not ready for indexing. So requests that are meant for shard 0 and 2 are bundled together, sent to shard 0 with “reshardSplitShardCountSummary” 2 in the request. Requests that are meant for shard 1 and 3 are bundled together, sent to shard 1 with “reshardSplitShardCountSummary” 2 in the request. Example 2: Suppose we are resharding an index from 4 -> 8 shards. While splitting a bulk request, the coordinator observes that source shard 0 has completed HANDOFF but source shards 1, 2, 3 have not completed handoff. So, the shard-bulk-request it sends to shard 0 and 4 has the "reshardSplitShardCountSummary" 8, while the shard-bulk-request it sends to shard 1,2,3 has the "reshardSplitShardCountSummary" 4. Note that in this case no shard-bulk-request is sent to shards 5, 6, 7 and the requests that were meant for these target shards are bundled together with and sent to their source shards. A value of 0 indicates an INVALID reshardSplitShardCountSummary. Hence, a request with INVALID reshardSplitShardCountSummary will be treated as a Summary mismatch on the source shard node.
    • waitForActiveShards

      protected ActiveShardCount waitForActiveShards
      The number of shard copies that must be active before proceeding with the replication action.
  • Constructor Details

  • Method Details

    • timeout

      public final Request timeout(TimeValue timeout)
      A timeout to wait if the index operation can't be performed immediately. Defaults to 1m.
    • timeout

      public TimeValue timeout()
    • index

      public String index()
    • index

      public final Request index(String index)
    • indices

      public String[] indices()
      Description copied from interface: IndicesRequest
      Returns the array of indices that the action relates to
      Specified by:
      indices in interface IndicesRequest
    • indicesOptions

      public IndicesOptions indicesOptions()
      Description copied from interface: IndicesRequest
      Returns the indices options used to resolve indices. They tell for instance whether a single index is accepted, whether an empty array will be converted to _all, and how wildcards will be expanded if needed.
      Specified by:
      indicesOptions in interface IndicesRequest
    • waitForActiveShards

      public ActiveShardCount waitForActiveShards()
    • shardId

      @Nullable public ShardId shardId()
      Returns:
      the shardId of the shard where this operation should be executed on. can be null if the shardID has not yet been resolved
    • reshardSplitShardCountSummary

      public int reshardSplitShardCountSummary()
      Returns:
      The effective shard count as seen by the coordinator when creating this request. can be 0 if this has not yet been resolved.
    • waitForActiveShards

      public final Request waitForActiveShards(ActiveShardCount waitForActiveShards)
      Sets the number of shard copies that must be active before proceeding with the replication operation. Defaults to ActiveShardCount.DEFAULT, which requires one shard copy (the primary) to be active. Set this value to ActiveShardCount.ALL to wait for all shards (primary and all replicas) to be active. Otherwise, use ActiveShardCount.from(int) to set this value to any non-negative integer, up to the total number of shard copies (number of replicas + 1).
    • waitForActiveShards

      public final Request waitForActiveShards(int waitForActiveShards)
      A shortcut for waitForActiveShards(ActiveShardCount) where the numerical shard count is passed in, instead of having to first call ActiveShardCount.from(int) to get the ActiveShardCount.
    • routedBasedOnClusterVersion

      protected Request routedBasedOnClusterVersion(long routedBasedOnClusterVersion)
      Sets the minimum version of the cluster state that is required on the next node before we redirect to another primary. Used to prevent redirect loops, see also AbstractRunnable.doRun()
    • validate

      Specified by:
      validate in class ActionRequest
    • writeTo

      public void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Overrides:
      writeTo in class ActionRequest
      Throws:
      IOException
    • writeThin

      public void writeThin(StreamOutput out) throws IOException
      Thin serialization that does not write shardId and will only write index if it is different from the index name in shardId. Since we do not write shardId, we also do not write reshardSplitShardCountSummary.
      Throws:
      IOException
    • createTask

      public Task createTask(long id, String type, String action, TaskId parentTaskId, Map<String,String> headers)
      Description copied from interface: TaskAwareRequest
      Returns the task object that should be used to keep track of the processing of the request.
      Specified by:
      createTask in interface TaskAwareRequest
    • toString

      public abstract String toString()
      Overrides:
      toString in class AbstractTransportRequest
    • getDescription

      public String getDescription()
      Description copied from interface: TaskAwareRequest
      Returns optional description of the request to be displayed by the task manager
      Specified by:
      getDescription in interface TaskAwareRequest
    • onRetry

      public void onRetry()
      This method is called before this replication request is retried the first time.