@InterfaceAudience.Private public class RecoverableZooKeeper extends Object
Modifier and Type | Field and Description |
---|---|
private byte[] |
id |
private String |
identifier |
private static org.slf4j.Logger |
LOG |
private String |
quorumServers |
private RetryCounterFactory |
retryCounterFactory |
private int |
sessionTimeout |
private org.apache.zookeeper.Watcher |
watcher |
private org.apache.zookeeper.ZooKeeper |
zk |
Constructor and Description |
---|
RecoverableZooKeeper(String quorumServers,
int sessionTimeout,
org.apache.zookeeper.Watcher watcher,
int maxRetries,
int retryIntervalMillis,
int maxSleepTime) |
RecoverableZooKeeper(String quorumServers,
int sessionTimeout,
org.apache.zookeeper.Watcher watcher,
int maxRetries,
int retryIntervalMillis,
int maxSleepTime,
String identifier) |
Modifier and Type | Method and Description |
---|---|
protected org.apache.zookeeper.ZooKeeper |
checkZk()
Try to create a ZooKeeper connection.
|
void |
close() |
String |
create(String path,
byte[] data,
List<org.apache.zookeeper.data.ACL> acl,
org.apache.zookeeper.CreateMode createMode)
NONSEQUENTIAL create is idempotent operation.
|
private String |
createNonSequential(String path,
byte[] data,
List<org.apache.zookeeper.data.ACL> acl,
org.apache.zookeeper.CreateMode createMode) |
private String |
createSequential(String path,
byte[] data,
List<org.apache.zookeeper.data.ACL> acl,
org.apache.zookeeper.CreateMode createMode) |
void |
delete(String path,
int version)
delete is an idempotent operation.
|
org.apache.zookeeper.data.Stat |
exists(String path,
boolean watch)
exists is an idempotent operation.
|
org.apache.zookeeper.data.Stat |
exists(String path,
org.apache.zookeeper.Watcher watcher)
exists is an idempotent operation.
|
private static List<String> |
filterByPrefix(List<String> nodes,
String... prefixes)
Filters the given node list by the given prefixes.
|
private String |
findPreviousSequentialNode(String path) |
List<org.apache.zookeeper.data.ACL> |
getAcl(String path,
org.apache.zookeeper.data.Stat stat)
getAcl is an idempotent operation.
|
List<String> |
getChildren(String path,
boolean watch)
getChildren is an idempotent operation.
|
List<String> |
getChildren(String path,
org.apache.zookeeper.Watcher watcher)
getChildren is an idempotent operation.
|
byte[] |
getData(String path,
boolean watch,
org.apache.zookeeper.data.Stat stat)
getData is an idempotent operation.
|
byte[] |
getData(String path,
org.apache.zookeeper.Watcher watcher,
org.apache.zookeeper.data.Stat stat)
getData is an idempotent operation.
|
String |
getIdentifier() |
long |
getSessionId() |
byte[] |
getSessionPasswd() |
org.apache.zookeeper.ZooKeeper.States |
getState() |
org.apache.zookeeper.ZooKeeper |
getZooKeeper() |
List<org.apache.zookeeper.OpResult> |
multi(Iterable<org.apache.zookeeper.Op> ops)
Run multiple operations in a transactional manner.
|
private Iterable<org.apache.zookeeper.Op> |
prepareZKMulti(Iterable<org.apache.zookeeper.Op> ops)
Convert Iterable of
Op we got into the ZooKeeper.Op
instances to actually pass to multi (need to do this in order to appendMetaData). |
void |
reconnectAfterExpiration() |
private void |
retryOrThrow(RetryCounter retryCounter,
org.apache.zookeeper.KeeperException e,
String opName) |
org.apache.zookeeper.data.Stat |
setAcl(String path,
List<org.apache.zookeeper.data.ACL> acls,
int version)
setAcl is an idempotent operation.
|
org.apache.zookeeper.data.Stat |
setData(String path,
byte[] data,
int version)
setData is NOT an idempotent operation.
|
void |
sync(String path,
org.apache.zookeeper.AsyncCallback.VoidCallback cb,
Object ctx) |
private static final org.slf4j.Logger LOG
private org.apache.zookeeper.ZooKeeper zk
private final RetryCounterFactory retryCounterFactory
private final String identifier
private final byte[] id
private final org.apache.zookeeper.Watcher watcher
private final int sessionTimeout
private final String quorumServers
public RecoverableZooKeeper(String quorumServers, int sessionTimeout, org.apache.zookeeper.Watcher watcher, int maxRetries, int retryIntervalMillis, int maxSleepTime) throws IOException
IOException
public RecoverableZooKeeper(String quorumServers, int sessionTimeout, org.apache.zookeeper.Watcher watcher, int maxRetries, int retryIntervalMillis, int maxSleepTime, String identifier) throws IOException
IOException
protected org.apache.zookeeper.ZooKeeper checkZk() throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperException
- if a ZooKeeper operation failspublic void reconnectAfterExpiration() throws IOException, org.apache.zookeeper.KeeperException, InterruptedException
IOException
org.apache.zookeeper.KeeperException
InterruptedException
public void delete(String path, int version) throws InterruptedException, org.apache.zookeeper.KeeperException
InterruptedException
org.apache.zookeeper.KeeperException
public org.apache.zookeeper.data.Stat exists(String path, org.apache.zookeeper.Watcher watcher) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public org.apache.zookeeper.data.Stat exists(String path, boolean watch) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
private void retryOrThrow(RetryCounter retryCounter, org.apache.zookeeper.KeeperException e, String opName) throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperException
public List<String> getChildren(String path, org.apache.zookeeper.Watcher watcher) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public List<String> getChildren(String path, boolean watch) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public byte[] getData(String path, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public byte[] getData(String path, boolean watch, org.apache.zookeeper.data.Stat stat) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public org.apache.zookeeper.data.Stat setData(String path, byte[] data, int version) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public List<org.apache.zookeeper.data.ACL> getAcl(String path, org.apache.zookeeper.data.Stat stat) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public org.apache.zookeeper.data.Stat setAcl(String path, List<org.apache.zookeeper.data.ACL> acls, int version) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public String create(String path, byte[] data, List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode) throws org.apache.zookeeper.KeeperException, InterruptedException
NONSEQUENTIAL create is idempotent operation. Retry before throwing exceptions. But this function will not throw the NodeExist exception back to the application.
But SEQUENTIAL is NOT idempotent operation. It is necessary to add identifier to the path to verify, whether the previous one is successful or not.
org.apache.zookeeper.KeeperException
InterruptedException
private String createNonSequential(String path, byte[] data, List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
private String createSequential(String path, byte[] data, List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
private Iterable<org.apache.zookeeper.Op> prepareZKMulti(Iterable<org.apache.zookeeper.Op> ops) throws UnsupportedOperationException
Op
we got into the ZooKeeper.Op
instances to actually pass to multi (need to do this in order to appendMetaData).UnsupportedOperationException
public List<org.apache.zookeeper.OpResult> multi(Iterable<org.apache.zookeeper.Op> ops) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
private String findPreviousSequentialNode(String path) throws org.apache.zookeeper.KeeperException, InterruptedException
org.apache.zookeeper.KeeperException
InterruptedException
public long getSessionId()
public void close() throws InterruptedException
InterruptedException
public org.apache.zookeeper.ZooKeeper.States getState()
public org.apache.zookeeper.ZooKeeper getZooKeeper()
public byte[] getSessionPasswd()
public void sync(String path, org.apache.zookeeper.AsyncCallback.VoidCallback cb, Object ctx) throws org.apache.zookeeper.KeeperException
org.apache.zookeeper.KeeperException
private static List<String> filterByPrefix(List<String> nodes, String... prefixes)
nodes
- the nodes to filterprefixes
- the prefixes to include in the resultpublic String getIdentifier()
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.