public class CustomRetryStrategy extends Object implements RetryStrategy
RetryStrategy, 重试逻辑用于判断在发生异常时是否需要重试, 并给出本次重试的时间间隔.
DefaultRetryStrategy为TableStore SDK默认的重试逻辑.| Constructor and Description |
|---|
CustomRetryStrategy() |
CustomRetryStrategy(long timeout,
TimeUnit unit) |
CustomRetryStrategy(long timeout,
TimeUnit unit,
boolean retryUnIdempotentWriteOperation) |
| Modifier and Type | Method and Description |
|---|---|
RetryStrategy |
clone()
返回一个同类型且尚未重试的RetryStrategy对象。
|
int |
getRetries()
返回当前重试的次数
|
long |
nextPause(String action,
Exception ex)
若返回0,代表不可重试,否则返回本次重试的间隔时间。
重试间隔的基础值(base),会随着重试次数倍增,最大不超过MAX_BASE。
为了请求的平滑性考虑,实际的重试间隔会在base基础上做一些随机的浮动。
|
boolean |
shouldRetry(String action,
Exception ex)
幂等操作:
本策略中,认为所有读相关的操作是幂等的,而所有写相关的操作会被认为是非幂等的。
重试策略,规则为:
1.
|
public CustomRetryStrategy()
public CustomRetryStrategy(long timeout,
TimeUnit unit)
public CustomRetryStrategy(long timeout,
TimeUnit unit,
boolean retryUnIdempotentWriteOperation)
timeout - 重试超时时间unit - 超时时间单位retryUnIdempotentWriteOperation - 是否在可能非幂等的情况下重试写操作public RetryStrategy clone()
RetryStrategyclone in interface RetryStrategyclone in class Objectpublic int getRetries()
RetryStrategygetRetries in interface RetryStrategypublic boolean shouldRetry(String action, Exception ex)
action - 操作名,比如"ListTable"、"GetRow"、"PutRow"等ex - 上次访问失败的错误信息、为ClientException或OTSExceptionpublic long nextPause(String action, Exception ex)
nextPause in interface RetryStrategyaction - 操作名,比如"ListTable"、"GetRow"、"PutRow"等ex - 上次访问失败的错误信息、为ClientException或TableStoreExceptionCopyright © 2024. All Rights Reserved.