Dynamodb 简明教程
DynamoDB - Error Handling
在请求处理失败时,DynamoDB 会引发错误。每个错误都包含以下组件:HTTP 状态码、异常名称和消息。错误管理依赖于传播错误的SDK或您的代码。
On unsuccessful processing of a request, DynamoDB throws an error. Each error consists of the following components: HTTP status code, exception name, and message. Error management rests on your SDK, which propagates errors, or your own code.
Codes and Messages
异常会被划分为不同的HTTP首部状态码。4xx和5xx持有与请求问题和AWS相关的错误。
Exceptions fall into different HTTP header status codes. The 4xx and 5xx hold errors related to request issues and AWS.
HTTP 4xx类别的以下异常包括:−
A selection of exceptions in the HTTP 4xx category are as follows −
-
AccessDeniedException − The client failed to sign the request correctly.
-
ConditionalCheckFailedException − A condition evaluated to false.
-
IncompleteSignatureException − The request included an incomplete signature.
HTTP 5xx 类别的异常如下所示:−
Exceptions in the HTTP 5xx category are as follows −
-
Internal Server Error
-
Service Unavailable
Retries and Backoff Algorithms
错误来自各种来源,例如服务器、交换机、负载平衡器以及其他结构和系统。通用解决方案包括支持可靠性的简单重试。所有 SDK 都自动包含此逻辑,并且您可以设置重试参数以满足您的应用程序需求。
Errors come from a variety of sources such as servers, switches, load balancers, and other pieces of structures and systems. Common solutions consist of simple retries, which supports reliability. All SDKs include this logic automatically, and you can set retry parameters to suit your application needs.
For example −Java 提供了一个 maxErrorRetry 值来停止重试。
For example − Java offers a maxErrorRetry value to stop retries.
Amazon 建议除了重试之外,还使用退避解决方案,以控制流。这包括逐渐增加重试之间的等待时间,并最终在相当短的时间后停止重试。请注意,SDK 会自动执行重试,但不会执行指数退避。
Amazon recommends using a backoff solution in addition to retries in order to control flow. This consists of progressively increasing wait periods between retries and eventually stopping after a fairly short period. Note SDKs perform automatic retries, but not exponential backoff.
以下程序是重试退避的一个示例:−
The following program is an example of the retry backoff −
public enum Results {
SUCCESS,
NOT_READY,
THROTTLED,
SERVER_ERROR
}
public static void DoAndWaitExample() {
try {
// asynchronous operation.
long token = asyncOperation();
int retries = 0;
boolean retry = false;
do {
long waitTime = Math.min(getWaitTime(retries), MAX_WAIT_INTERVAL);
System.out.print(waitTime + "\n");
// Pause for result
Thread.sleep(waitTime);
// Get result
Results result = getAsyncOperationResult(token);
if (Results.SUCCESS == result) {
retry = false;
} else if (Results.NOT_READY == result) {
retry = true;
} else if (Results.THROTTLED == result) {
retry = true;
} else if (Results.SERVER_ERROR == result) {
retry = true;
} else {
// stop on other error
retry = false;
}
} while (retry && (retries++ < MAX_RETRIES));
}
catch (Exception ex) {
}
}
public static long getWaitTime(int retryCount) {
long waitTime = ((long) Math.pow(3, retryCount) * 100L);
return waitTime;
}