Package org.apache.bookkeeper.zookeeper
Class ZooWorker
- java.lang.Object
-
- org.apache.bookkeeper.zookeeper.ZooWorker
-
class ZooWorker extends java.lang.Object
Provide a mechanism to perform an operation on ZooKeeper that is safe on disconnections and recoverable errors.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interface
ZooWorker.ZooCallable<T>
-
Field Summary
Fields Modifier and Type Field Description (package private) int
attempts
(package private) long
elapsedTimeMs
(package private) RetryPolicy
retryPolicy
(package private) long
startTimeNanos
(package private) OpStatsLogger
statsLogger
-
Constructor Summary
Constructors Constructor Description ZooWorker(RetryPolicy retryPolicy, OpStatsLogger statsLogger)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allowRetry(int rc)
static boolean
isRecoverableException(int rc)
Check whether the given result code is recoverable by retry.static boolean
isRecoverableException(org.apache.zookeeper.KeeperException exception)
Check whether the given exception is recoverable by retry.long
nextRetryWaitTime()
static <T> T
syncCallWithRetries(ZooKeeperClient client, ZooWorker.ZooCallable<T> proc, RetryPolicy retryPolicy, com.google.common.util.concurrent.RateLimiter rateLimiter, OpStatsLogger statsLogger)
Execute a sync zookeeper operation with a given retry policy.
-
-
-
Field Detail
-
attempts
int attempts
-
startTimeNanos
long startTimeNanos
-
elapsedTimeMs
long elapsedTimeMs
-
retryPolicy
final RetryPolicy retryPolicy
-
statsLogger
final OpStatsLogger statsLogger
-
-
Constructor Detail
-
ZooWorker
ZooWorker(RetryPolicy retryPolicy, OpStatsLogger statsLogger)
-
-
Method Detail
-
allowRetry
public boolean allowRetry(int rc)
-
nextRetryWaitTime
public long nextRetryWaitTime()
-
isRecoverableException
public static boolean isRecoverableException(int rc)
Check whether the given result code is recoverable by retry.- Parameters:
rc
- result code- Returns:
- true if given result code is recoverable.
-
isRecoverableException
public static boolean isRecoverableException(org.apache.zookeeper.KeeperException exception)
Check whether the given exception is recoverable by retry.- Parameters:
exception
- given exception- Returns:
- true if given exception is recoverable.
-
syncCallWithRetries
public static <T> T syncCallWithRetries(ZooKeeperClient client, ZooWorker.ZooCallable<T> proc, RetryPolicy retryPolicy, com.google.common.util.concurrent.RateLimiter rateLimiter, OpStatsLogger statsLogger) throws org.apache.zookeeper.KeeperException, java.lang.InterruptedException
Execute a sync zookeeper operation with a given retry policy.- Parameters:
client
- ZooKeeper client.proc
- Synchronous zookeeper operation wrapped in aCallable
.retryPolicy
- Retry policy to execute the synchronous operation.rateLimiter
- Rate limiter for zookeeper callsstatsLogger
- Stats Logger for zookeeper client.- Returns:
- result of the zookeeper operation
- Throws:
org.apache.zookeeper.KeeperException
- any non-recoverable exception or recoverable exception exhausted all retires.java.lang.InterruptedException
- the operation is interrupted.
-
-