Class AsyncProcess
The caller sends a buffer of operation, by calling submit. This class extract from this list the operations it can send, i.e. the operations that are on region that are not considered as busy. The process is asynchronous, i.e. it returns immediately when if has finished to iterate on the list. If, and only if, the maximum number of current task is reached, the call to submit will block. Alternatively, the caller can call submitAll, in which case all the operations will be sent. Each call to submit returns a future-like object that can be used to track operation progress.
The class manages internally the retries.
The errors are tracked inside the Future object that is returned. The results are always tracked inside the Future object and can be retrieved when the call has finished. Partial results can also be retrieved if some part of multi-request failed.
This class is thread safe. Internally, the class is thread safe enough to manage simultaneously new submission and results arising from older operations.
Internally, this class works with Row, this mean it could be theoretically used for gets
as well.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ClusterConnection(package private) final ConnectionConfigurationprivate static final AtomicLongprivate static final intstatic final int(package private) final longprivate static final org.slf4j.Loggerstatic final StringConfiguration to decide whether to log details for batch errorstatic final String(package private) final booleanWhether to log details for batch errorsprivate static final AsyncRequestFutureReturn value from a submit that didn't contain any requests.(package private) final intprivate final intstatic final String(package private) final long(package private) final RequestControllerThe traffic control for requests.private final RpcRetryingCallerFactory(package private) final RpcControllerFactory(package private) longstatic final StringConfigure the number of failures after which the client will start logging.(package private) final int -
Constructor Summary
ConstructorsConstructorDescriptionAsyncProcess(ClusterConnection hc, org.apache.hadoop.conf.Configuration conf, RpcRetryingCallerFactory rpcCaller, RpcControllerFactory rpcFactory) AsyncProcess(ClusterConnection hc, org.apache.hadoop.conf.Configuration conf, RpcRetryingCallerFactory rpcCaller, RpcControllerFactory rpcFactory, int retriesNumber) -
Method Summary
Modifier and TypeMethodDescription(package private) static voidaddAction(ServerName server, byte[] regionName, Action action, Map<ServerName, MultiAction> actionsByServer, long nonceGroup) Helper that is used when grouping the actions per region server.private intcheckOperationTimeout(int operationTimeout) private intcheckRpcTimeout(int rpcTimeout) private <CResult> AsyncRequestFuturecheckTask(AsyncProcessTask<CResult> task) private intcheckTimeout(String name, int timeout) (package private) <CResult> AsyncRequestFutureImpl<CResult>createAsyncRequestFuture(AsyncProcessTask task, List<Action> actions, long nonceGroup) protected RpcRetryingCaller<AbstractResponse>createCaller(CancellableRegionServerCallable callable, int rpcTimeout) Create a caller.(package private) ConnectionImplementation.ServerErrorTrackerCreates the server error tracker to use inside process.(package private) voiddecTaskCounters(Collection<byte[]> regions, ServerName sn) private static booleanhasIncrementOrAppend(Row action) private static booleanhasIncrementOrAppend(RowMutations mutations) (package private) voidincTaskCounters(Collection<byte[]> regions, ServerName sn) (package private) static booleanisReplicaGet(Row row) private voidsetNonce(NonceGenerator ng, Row r, Action action) <CResult> AsyncRequestFuturesubmit(AsyncProcessTask<CResult> task) The submitted task may be not accomplished at all if there are too many running tasks or other limits.private <CResult> AsyncRequestFuturesubmit(AsyncProcessTask<CResult> task, boolean atLeastOne) Extract from the rows list what we can submit.private <CResult> AsyncRequestFuturesubmitAll(AsyncProcessTask task) Submit immediately the list of rows, whatever the server status.(package private) <CResult> AsyncRequestFuturesubmitMultiActions(AsyncProcessTask task, List<Action> retainedActions, long nonceGroup, List<Exception> locationErrors, List<Integer> locationErrorRows, Map<ServerName, MultiAction> actionsByServer) protected voidwaitForMaximumCurrentTasks(int max, TableName tableName) Wait until the async does not have more than max tasks in progress.
-
Field Details
-
LOG
-
COUNTER
-
PRIMARY_CALL_TIMEOUT_KEY
- See Also:
-
START_LOG_ERRORS_AFTER_COUNT_KEY
Configure the number of failures after which the client will start logging. A few failures is fine: region moved, then is not opened, then is overloaded. We try to have an acceptable heuristic for the number of errors we don't log. 5 was chosen because we wait for 1s at this stage.- See Also:
-
DEFAULT_START_LOG_ERRORS_AFTER_COUNT
- See Also:
-
LOG_DETAILS_FOR_BATCH_ERROR
Configuration to decide whether to log details for batch error- See Also:
-
NO_REQS_RESULT
Return value from a submit that didn't contain any requests. -
id
-
connection
-
connectionConfiguration
-
rpcCallerFactory
-
rpcFactory
-
startLogErrorsCnt
-
numTries
-
serverTrackerTimeout
long serverTrackerTimeout -
-
logBatchErrorDetails
Whether to log details for batch errors -
requestController
The traffic control for requests. -
LOG_DETAILS_PERIOD
- See Also:
-
DEFAULT_LOG_DETAILS_PERIOD
- See Also:
-
periodToLog
-
-
Constructor Details
-
AsyncProcess
AsyncProcess(ClusterConnection hc, org.apache.hadoop.conf.Configuration conf, RpcRetryingCallerFactory rpcCaller, RpcControllerFactory rpcFactory) -
AsyncProcess
AsyncProcess(ClusterConnection hc, org.apache.hadoop.conf.Configuration conf, RpcRetryingCallerFactory rpcCaller, RpcControllerFactory rpcFactory, int retriesNumber)
-
-
Method Details
-
submit
public <CResult> AsyncRequestFuture submit(AsyncProcessTask<CResult> task) throws InterruptedIOException The submitted task may be not accomplished at all if there are too many running tasks or other limits.- Type Parameters:
CResult- The class to cast the result- Parameters:
task- The setting and data- Throws:
InterruptedIOException
-
submit
private <CResult> AsyncRequestFuture submit(AsyncProcessTask<CResult> task, boolean atLeastOne) throws InterruptedIOException Extract from the rows list what we can submit. The rows we can not submit are kept in the list. Does not send requests to replicas (not currently used for anything other than streaming puts anyway).- Parameters:
task- The setting and dataatLeastOne- true if we should submit at least a subset.- Throws:
InterruptedIOException
-
submitMultiActions
<CResult> AsyncRequestFuture submitMultiActions(AsyncProcessTask task, List<Action> retainedActions, long nonceGroup, List<Exception> locationErrors, List<Integer> locationErrorRows, Map<ServerName, MultiAction> actionsByServer) -
addAction
static void addAction(ServerName server, byte[] regionName, Action action, Map<ServerName, MultiAction> actionsByServer, long nonceGroup) Helper that is used when grouping the actions per region server.- Parameters:
server- - serverregionName- - regionNameaction- - the action to add to the multiactionactionsByServer- the multiaction per servernonceGroup- Nonce group.
-
submitAll
Submit immediately the list of rows, whatever the server status. Kept for backward compatibility: it allows to be used with the batch interface that return an array of objects.- Parameters:
task- The setting and data
-
checkTask
-
setNonce
-
hasIncrementOrAppend
-
hasIncrementOrAppend
-
checkTimeout
-
checkOperationTimeout
-
checkRpcTimeout
-
createAsyncRequestFuture
<CResult> AsyncRequestFutureImpl<CResult> createAsyncRequestFuture(AsyncProcessTask task, List<Action> actions, long nonceGroup) -
waitForMaximumCurrentTasks
protected void waitForMaximumCurrentTasks(int max, TableName tableName) throws InterruptedIOException Wait until the async does not have more than max tasks in progress.- Throws:
InterruptedIOException
-
getLogger
-
incTaskCounters
-
decTaskCounters
-
createCaller
protected RpcRetryingCaller<AbstractResponse> createCaller(CancellableRegionServerCallable callable, int rpcTimeout) Create a caller. Isolated to be easily overridden in the tests. -
createServerErrorTracker
Creates the server error tracker to use inside process. Currently, to preserve the main assumption about current retries, and to work well with the retry-limit-based calculation, the calculation is local per Process object. We may benefit from connection-wide tracking of server errors.- Returns:
- ServerErrorTracker to use, null if there is no ServerErrorTracker on this connection
-
isReplicaGet
-