Package org.apache.hadoop.hbase.client
Class AsyncRequestFutureImpl<CResult>
java.lang.Object
org.apache.hadoop.hbase.client.AsyncRequestFutureImpl<CResult>
- All Implemented Interfaces:
AsyncRequestFuture
The context, and return value, for a single submit/submitAll call. Note on how this class (one AP
submit) works. Initially, all requests are split into groups by server; request is sent to each
server in parallel; the RPC calls are not async so a thread per server is used. Every time some
actions fail, regions/locations might have changed, so we re-group them by server and region
again and send these groups in parallel too. The result, in case of retries, is a "tree" of
threads, with parent exiting after scheduling children. This is why lots of code doesn't require
any synchronization.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classRunnable (that can be submitted to thread pool) that waits for when it's time to issue replica calls, finds region replicas, groups the requests by replica and issues the calls (on separate threads, via sendMultiAction).private static classSync point for calls to multiple replicas for the same user request (Get).static enum(package private) final classRunnable (that can be submitted to thread pool) that submits MultiAction to a single server. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicLongprivate final AsyncProcessprivate final Batch.Callback<CResult>private final Set<CancellableRegionServerCallable>private final CancellableRegionServerCallableprivate final BatchErrorsprivate final ConnectionImplementation.ServerErrorTrackerprivate final booleanprivate static final org.slf4j.Loggerprivate final longprivate final intprivate final ExecutorServiceprivate final int[]Indices of replica gets in results.private final ObjectThe lock controls access to results.private final Object[]Result array.private final intprivate final TableNameprivate RetryingTimeTracker -
Constructor Summary
ConstructorsConstructorDescriptionAsyncRequestFutureImpl(AsyncProcessTask task, List<Action> actions, long nonceGroup, AsyncProcess asyncProcess) -
Method Summary
Modifier and TypeMethodDescriptionprivate StringbuildDetailedErrorMsg(String string, int index) private voidcleanServerCache(ServerName server, Throwable regionException) private MultiServerCallablecreateCallable(ServerName server, TableName tableName, MultiAction multi) Create a callable.private StringcreateLog(int numAttempt, int failureCount, int replaySize, ServerName sn, Throwable error, long backOffTime, boolean willRetry, String startTime, int failed, int stopped) Creates the server error tracker to use inside process.(package private) AsyncRequestFutureImpl<CResult>.SingleServerRequestRunnablecreateSingleServerRequest(MultiAction multiAction, int numAttempt, ServerName server, Set<CancellableRegionServerCallable> callsInProgress) private voiddecActionCounter(int index) private voidfailAll(MultiAction actions, ServerName server, int numAttempt, Throwable throwable) Fail all the actions from this multiaction after an OperationTimeoutExceededExceptionprivate RegionLocationsfindAllLocationsOrFail(Action action, boolean useCache) private LonggetBackoff(ServerName server, byte[] regionName) protected Set<CancellableRegionServerCallable>private Collection<? extends Runnable>getNewMultiActionRunnable(ServerName server, MultiAction multiAction, int numAttempt) (package private) longprivate longprivate HRegionLocationgetReplicaLocationOrFail(Action action) Object[](package private) voidgroupAndSendMultiAction(List<Action> currentActions, int numAttempt) Group a list of actions per region servers, and send them.booleanhasError()private voidinvokeCallBack(byte[] regionName, byte[] row, CResult result) private booleanisActionComplete(int index, Row row) Checks if the action is complete; used on error to prevent needless retries.private booleanSome checked calls send a callable with their own tracker.private voidlogNoResubmit(ServerName oldServer, int numAttempt, int failureCount, Throwable throwable, int failed, int stopped) (package private) AsyncRequestFutureImpl.RetrymanageError(int originalIndex, Row row, AsyncRequestFutureImpl.Retry canRetry, Throwable throwable, ServerName server) Check that we can retry acts accordingly: logs, set the error status.private voidmanageLocationError(Action action, Exception ex) private voidreceiveGlobalFailure(MultiAction rsActions, ServerName server, int numAttempt, Throwable t, boolean clearServerCache) Resubmit all the actions from this multiaction after a failure.private voidreceiveMultiAction(MultiAction multiAction, ServerName server, MultiResponse responses, int numAttempt) Called when we receive the result of a server query.private voidresubmit(ServerName oldServer, List<Action> toReplay, int numAttempt, int failureCount, Throwable throwable) Log as much info as possible, and, if there is something to replay, submit it again after a back off sleep.(package private) voidsendMultiAction(Map<ServerName, MultiAction> actionsByServer, int numAttempt, List<Action> actionsForReplicaThread, boolean reuseThread) Send a multi action structure to the servers, after a delay depending on the attempt number.private voidsetError(int index, Row row, Throwable throwable, ServerName server) Sets the error from a particular action.private voidSets the non-error result from a particular action.private voidstartWaitingForReplicaCalls(List<Action> actionsForReplicaThread) Starts waiting to issue replica calls on a different thread; or issues them immediately.trySetResultSimple(int index, Row row, boolean isError, Object result, ServerName server, boolean isFromReplica) Tries to set the result or error for a particular action as if there were no replica calls.private voidupdateCachedLocations(ServerName server, byte[] regionName, byte[] row, Throwable rowException) private voidupdateResult(int index, Object result) protected voidupdateStats(ServerName server, MultiResponse resp) voidWait until all tasks are executed, successfully or not.private booleanwaitUntilDone(long cutoff)
-
Field Details
-
LOG
-
tracker
-
callback
-
errors
-
errorsByServer
-
pool
-
callsInProgress
-
tableName
-
actionsInProgress
-
replicaResultLock
The lock controls access to results. It is only held when populating results where there might be several callers (eventual consistency gets). For other requests, there's one unique call going on per result index. -
results
Result array. Null if results are not needed. Otherwise, each index corresponds to the action index in initial actions submitted. For most request types, has null-s for requests that are not done, and result/exception for those that are done. For eventual-consistency gets, initially the same applies; at some point, replica calls might be started, and ReplicaResultState is put at the corresponding indices. The returning calls check the type to detect when this is the case. After all calls are done, ReplicaResultState-s are replaced with results for the user. -
replicaGetIndices
Indices of replica gets in results. If null, all or no actions are replica-gets. -
hasAnyReplicaGets
-
nonceGroup
-
currentCallable
-
operationTimeout
-
rpcTimeout
-
asyncProcess
-
requestAttributes
-
-
Constructor Details
-
AsyncRequestFutureImpl
public AsyncRequestFutureImpl(AsyncProcessTask task, List<Action> actions, long nonceGroup, AsyncProcess asyncProcess)
-
-
Method Details
-
getCallsInProgress
-
createSingleServerRequest
AsyncRequestFutureImpl<CResult>.SingleServerRequestRunnable createSingleServerRequest(MultiAction multiAction, int numAttempt, ServerName server, Set<CancellableRegionServerCallable> callsInProgress) -
isOperationTimeoutExceeded
Some checked calls send a callable with their own tracker. This method checks the operation timeout against the appropriate tracker, or returns false if no tracker. -
getRemainingTime
-
groupAndSendMultiAction
Group a list of actions per region servers, and send them.- Parameters:
currentActions- - the list of row to submitnumAttempt- - the current numAttempt (first attempt is 1)
-
getReplicaLocationOrFail
-
manageLocationError
-
findAllLocationsOrFail
-
sendMultiAction
void sendMultiAction(Map<ServerName, MultiAction> actionsByServer, int numAttempt, List<Action> actionsForReplicaThread, boolean reuseThread) Send a multi action structure to the servers, after a delay depending on the attempt number. Asynchronous.- Parameters:
actionsByServer- the actions structured by regionsnumAttempt- the attempt number.actionsForReplicaThread- original actions for replica thread; null on non-first call.
-
getNewMultiActionRunnable
private Collection<? extends Runnable> getNewMultiActionRunnable(ServerName server, MultiAction multiAction, int numAttempt) -
getBackoff
- Parameters:
server- server location where the target region is hostedregionName- name of the region which we are going to write some data- Returns:
- the amount of time the client should wait until it submit a request to the specified server and region
-
startWaitingForReplicaCalls
Starts waiting to issue replica calls on a different thread; or issues them immediately. -
manageError
AsyncRequestFutureImpl.Retry manageError(int originalIndex, Row row, AsyncRequestFutureImpl.Retry canRetry, Throwable throwable, ServerName server) Check that we can retry acts accordingly: logs, set the error status.- Parameters:
originalIndex- the position in the list sentrow- the rowcanRetry- if false, we won't retry whatever the settings.throwable- the throwable, if any (can be null)server- the location, if any (can be null)- Returns:
- true if the action can be retried, false otherwise.
-
failAll
Fail all the actions from this multiaction after an OperationTimeoutExceededException- Parameters:
actions- the actions still to do from the initial listserver- the destinationnumAttempt- the number of attempts so farthrowable- the throwable that caused the failure
-
receiveGlobalFailure
private void receiveGlobalFailure(MultiAction rsActions, ServerName server, int numAttempt, Throwable t, boolean clearServerCache) Resubmit all the actions from this multiaction after a failure.- Parameters:
rsActions- the actions still to do from the initial listserver- the destinationnumAttempt- the number of attempts so fart- the throwable (if any) that caused the resubmit
-
resubmit
private void resubmit(ServerName oldServer, List<Action> toReplay, int numAttempt, int failureCount, Throwable throwable) Log as much info as possible, and, if there is something to replay, submit it again after a back off sleep. -
logNoResubmit
private void logNoResubmit(ServerName oldServer, int numAttempt, int failureCount, Throwable throwable, int failed, int stopped) -
receiveMultiAction
private void receiveMultiAction(MultiAction multiAction, ServerName server, MultiResponse responses, int numAttempt) Called when we receive the result of a server query.- Parameters:
multiAction- - the multiAction we sentserver- - the location. It's used as a server name.responses- - the response, if anynumAttempt- - the attempt
-
updateCachedLocations
private void updateCachedLocations(ServerName server, byte[] regionName, byte[] row, Throwable rowException) -
invokeCallBack
-
cleanServerCache
-
updateStats
-
createLog
private String createLog(int numAttempt, int failureCount, int replaySize, ServerName sn, Throwable error, long backOffTime, boolean willRetry, String startTime, int failed, int stopped) -
setResult
Sets the non-error result from a particular action.- Parameters:
action- Action (request) that the server responded to.result- The result.
-
setError
Sets the error from a particular action.- Parameters:
index- Original action index.row- Original request.throwable- The resulting error.server- The source server.
-
isActionComplete
Checks if the action is complete; used on error to prevent needless retries. Does not synchronize, assuming element index/field accesses are atomic. This is an opportunistic optimization check, doesn't have to be strict.- Parameters:
index- Original action index.row- Original request.
-
trySetResultSimple
private AsyncRequestFutureImpl.ReplicaResultState trySetResultSimple(int index, Row row, boolean isError, Object result, ServerName server, boolean isFromReplica) Tries to set the result or error for a particular action as if there were no replica calls.- Returns:
- null if successful; replica state if there were in fact replica calls.
-
decActionCounter
-
buildDetailedErrorMsg
-
waitUntilDone
Description copied from interface:AsyncRequestFutureWait until all tasks are executed, successfully or not.- Specified by:
waitUntilDonein interfaceAsyncRequestFuture- Throws:
InterruptedIOException
-
waitUntilDone
- Throws:
InterruptedException
-
hasError
- Specified by:
hasErrorin interfaceAsyncRequestFuture
-
getFailedOperations
- Specified by:
getFailedOperationsin interfaceAsyncRequestFuture
-
getErrors
- Specified by:
getErrorsin interfaceAsyncRequestFuture
-
getResults
- Specified by:
getResultsin interfaceAsyncRequestFuture- Throws:
InterruptedIOException
-
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
-
createCallable
private MultiServerCallable createCallable(ServerName server, TableName tableName, MultiAction multi) Create a callable. Isolated to be easily overridden in the tests. -
updateResult
-
getNumberOfActionsInProgress
long getNumberOfActionsInProgress()
-