[HBASE-22591] : RecoverableZooKeeper improvement for getData, getChil… (#310)
HBASE-22591 RecoverableZooKeeper improvement for getData, getChildren, exists and removal of unused reference Signed-off-by: Wellington Chevreuil <wchevreuil@apache.org>
This commit is contained in:
parent
5f2699e02f
commit
214553d17a
|
@ -26,7 +26,6 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.trace.TraceUtil;
|
import org.apache.hadoop.hbase.trace.TraceUtil;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
|
|
||||||
import org.apache.hadoop.hbase.util.RetryCounter;
|
import org.apache.hadoop.hbase.util.RetryCounter;
|
||||||
import org.apache.hadoop.hbase.util.RetryCounterFactory;
|
import org.apache.hadoop.hbase.util.RetryCounterFactory;
|
||||||
import org.apache.htrace.core.TraceScope;
|
import org.apache.htrace.core.TraceScope;
|
||||||
|
@ -169,7 +168,6 @@ public class RecoverableZooKeeper {
|
||||||
boolean isRetry = false; // False for first attempt, true for all retries.
|
boolean isRetry = false; // False for first attempt, true for all retries.
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
|
||||||
checkZk().delete(path, version);
|
checkZk().delete(path, version);
|
||||||
return;
|
return;
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
|
@ -205,12 +203,21 @@ public class RecoverableZooKeeper {
|
||||||
* @return A Stat instance
|
* @return A Stat instance
|
||||||
*/
|
*/
|
||||||
public Stat exists(String path, Watcher watcher) throws KeeperException, InterruptedException {
|
public Stat exists(String path, Watcher watcher) throws KeeperException, InterruptedException {
|
||||||
|
return exists(path, watcher, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Stat exists(String path, Watcher watcher, Boolean watch)
|
||||||
|
throws InterruptedException, KeeperException {
|
||||||
try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.exists")) {
|
try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.exists")) {
|
||||||
RetryCounter retryCounter = retryCounterFactory.create();
|
RetryCounter retryCounter = retryCounterFactory.create();
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
Stat nodeStat;
|
||||||
Stat nodeStat = checkZk().exists(path, watcher);
|
if (watch == null) {
|
||||||
|
nodeStat = checkZk().exists(path, watcher);
|
||||||
|
} else {
|
||||||
|
nodeStat = checkZk().exists(path, watch);
|
||||||
|
}
|
||||||
return nodeStat;
|
return nodeStat;
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
switch (e.code()) {
|
switch (e.code()) {
|
||||||
|
@ -235,29 +242,7 @@ public class RecoverableZooKeeper {
|
||||||
* @return A Stat instance
|
* @return A Stat instance
|
||||||
*/
|
*/
|
||||||
public Stat exists(String path, boolean watch) throws KeeperException, InterruptedException {
|
public Stat exists(String path, boolean watch) throws KeeperException, InterruptedException {
|
||||||
try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.exists")) {
|
return exists(path, null, watch);
|
||||||
RetryCounter retryCounter = retryCounterFactory.create();
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
|
||||||
Stat nodeStat = checkZk().exists(path, watch);
|
|
||||||
return nodeStat;
|
|
||||||
} catch (KeeperException e) {
|
|
||||||
switch (e.code()) {
|
|
||||||
case CONNECTIONLOSS:
|
|
||||||
retryOrThrow(retryCounter, e, "exists");
|
|
||||||
break;
|
|
||||||
case OPERATIONTIMEOUT:
|
|
||||||
retryOrThrow(retryCounter, e, "exists");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
retryCounter.sleepUntilNextRetry();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void retryOrThrow(RetryCounter retryCounter, KeeperException e,
|
private void retryOrThrow(RetryCounter retryCounter, KeeperException e,
|
||||||
|
@ -277,12 +262,21 @@ public class RecoverableZooKeeper {
|
||||||
*/
|
*/
|
||||||
public List<String> getChildren(String path, Watcher watcher)
|
public List<String> getChildren(String path, Watcher watcher)
|
||||||
throws KeeperException, InterruptedException {
|
throws KeeperException, InterruptedException {
|
||||||
|
return getChildren(path, watcher, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> getChildren(String path, Watcher watcher, Boolean watch)
|
||||||
|
throws InterruptedException, KeeperException {
|
||||||
try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.getChildren")) {
|
try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.getChildren")) {
|
||||||
RetryCounter retryCounter = retryCounterFactory.create();
|
RetryCounter retryCounter = retryCounterFactory.create();
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
List<String> children;
|
||||||
List<String> children = checkZk().getChildren(path, watcher);
|
if (watch == null) {
|
||||||
|
children = checkZk().getChildren(path, watcher);
|
||||||
|
} else {
|
||||||
|
children = checkZk().getChildren(path, watch);
|
||||||
|
}
|
||||||
return children;
|
return children;
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
switch (e.code()) {
|
switch (e.code()) {
|
||||||
|
@ -308,29 +302,7 @@ public class RecoverableZooKeeper {
|
||||||
*/
|
*/
|
||||||
public List<String> getChildren(String path, boolean watch)
|
public List<String> getChildren(String path, boolean watch)
|
||||||
throws KeeperException, InterruptedException {
|
throws KeeperException, InterruptedException {
|
||||||
try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.getChildren")) {
|
return getChildren(path, null, watch);
|
||||||
RetryCounter retryCounter = retryCounterFactory.create();
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
|
||||||
List<String> children = checkZk().getChildren(path, watch);
|
|
||||||
return children;
|
|
||||||
} catch (KeeperException e) {
|
|
||||||
switch (e.code()) {
|
|
||||||
case CONNECTIONLOSS:
|
|
||||||
retryOrThrow(retryCounter, e, "getChildren");
|
|
||||||
break;
|
|
||||||
case OPERATIONTIMEOUT:
|
|
||||||
retryOrThrow(retryCounter, e, "getChildren");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
retryCounter.sleepUntilNextRetry();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -339,12 +311,21 @@ public class RecoverableZooKeeper {
|
||||||
*/
|
*/
|
||||||
public byte[] getData(String path, Watcher watcher, Stat stat)
|
public byte[] getData(String path, Watcher watcher, Stat stat)
|
||||||
throws KeeperException, InterruptedException {
|
throws KeeperException, InterruptedException {
|
||||||
|
return getData(path, watcher, null, stat);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] getData(String path, Watcher watcher, Boolean watch, Stat stat)
|
||||||
|
throws InterruptedException, KeeperException {
|
||||||
try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.getData")) {
|
try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.getData")) {
|
||||||
RetryCounter retryCounter = retryCounterFactory.create();
|
RetryCounter retryCounter = retryCounterFactory.create();
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
byte[] revData;
|
||||||
byte[] revData = checkZk().getData(path, watcher, stat);
|
if (watch == null) {
|
||||||
|
revData = checkZk().getData(path, watcher, stat);
|
||||||
|
} else {
|
||||||
|
revData = checkZk().getData(path, watch, stat);
|
||||||
|
}
|
||||||
return ZKMetadata.removeMetaData(revData);
|
return ZKMetadata.removeMetaData(revData);
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
switch (e.code()) {
|
switch (e.code()) {
|
||||||
|
@ -370,29 +351,7 @@ public class RecoverableZooKeeper {
|
||||||
*/
|
*/
|
||||||
public byte[] getData(String path, boolean watch, Stat stat)
|
public byte[] getData(String path, boolean watch, Stat stat)
|
||||||
throws KeeperException, InterruptedException {
|
throws KeeperException, InterruptedException {
|
||||||
try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.getData")) {
|
return getData(path, null, watch, stat);
|
||||||
RetryCounter retryCounter = retryCounterFactory.create();
|
|
||||||
while (true) {
|
|
||||||
try {
|
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
|
||||||
byte[] revData = checkZk().getData(path, watch, stat);
|
|
||||||
return ZKMetadata.removeMetaData(revData);
|
|
||||||
} catch (KeeperException e) {
|
|
||||||
switch (e.code()) {
|
|
||||||
case CONNECTIONLOSS:
|
|
||||||
retryOrThrow(retryCounter, e, "getData");
|
|
||||||
break;
|
|
||||||
case OPERATIONTIMEOUT:
|
|
||||||
retryOrThrow(retryCounter, e, "getData");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
retryCounter.sleepUntilNextRetry();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -407,12 +366,9 @@ public class RecoverableZooKeeper {
|
||||||
RetryCounter retryCounter = retryCounterFactory.create();
|
RetryCounter retryCounter = retryCounterFactory.create();
|
||||||
byte[] newData = ZKMetadata.appendMetaData(id, data);
|
byte[] newData = ZKMetadata.appendMetaData(id, data);
|
||||||
boolean isRetry = false;
|
boolean isRetry = false;
|
||||||
long startTime;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
startTime = EnvironmentEdgeManager.currentTime();
|
return checkZk().setData(path, newData, version);
|
||||||
Stat nodeStat = checkZk().setData(path, newData, version);
|
|
||||||
return nodeStat;
|
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
switch (e.code()) {
|
switch (e.code()) {
|
||||||
case CONNECTIONLOSS:
|
case CONNECTIONLOSS:
|
||||||
|
@ -457,9 +413,7 @@ public class RecoverableZooKeeper {
|
||||||
RetryCounter retryCounter = retryCounterFactory.create();
|
RetryCounter retryCounter = retryCounterFactory.create();
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
return checkZk().getACL(path, stat);
|
||||||
List<ACL> nodeACL = checkZk().getACL(path, stat);
|
|
||||||
return nodeACL;
|
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
switch (e.code()) {
|
switch (e.code()) {
|
||||||
case CONNECTIONLOSS:
|
case CONNECTIONLOSS:
|
||||||
|
@ -488,9 +442,7 @@ public class RecoverableZooKeeper {
|
||||||
RetryCounter retryCounter = retryCounterFactory.create();
|
RetryCounter retryCounter = retryCounterFactory.create();
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
return checkZk().setACL(path, acls, version);
|
||||||
Stat nodeStat = checkZk().setACL(path, acls, version);
|
|
||||||
return nodeStat;
|
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
switch (e.code()) {
|
switch (e.code()) {
|
||||||
case CONNECTIONLOSS:
|
case CONNECTIONLOSS:
|
||||||
|
@ -549,12 +501,9 @@ public class RecoverableZooKeeper {
|
||||||
CreateMode createMode) throws KeeperException, InterruptedException {
|
CreateMode createMode) throws KeeperException, InterruptedException {
|
||||||
RetryCounter retryCounter = retryCounterFactory.create();
|
RetryCounter retryCounter = retryCounterFactory.create();
|
||||||
boolean isRetry = false; // False for first attempt, true for all retries.
|
boolean isRetry = false; // False for first attempt, true for all retries.
|
||||||
long startTime;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
startTime = EnvironmentEdgeManager.currentTime();
|
return checkZk().create(path, data, acl, createMode);
|
||||||
String nodePath = checkZk().create(path, data, acl, createMode);
|
|
||||||
return nodePath;
|
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
switch (e.code()) {
|
switch (e.code()) {
|
||||||
case NODEEXISTS:
|
case NODEEXISTS:
|
||||||
|
@ -608,9 +557,7 @@ public class RecoverableZooKeeper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
return checkZk().create(newPath, data, acl, createMode);
|
||||||
String nodePath = checkZk().create(newPath, data, acl, createMode);
|
|
||||||
return nodePath;
|
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
switch (e.code()) {
|
switch (e.code()) {
|
||||||
case CONNECTIONLOSS:
|
case CONNECTIONLOSS:
|
||||||
|
@ -666,9 +613,7 @@ public class RecoverableZooKeeper {
|
||||||
Iterable<Op> multiOps = prepareZKMulti(ops);
|
Iterable<Op> multiOps = prepareZKMulti(ops);
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
return checkZk().multi(multiOps);
|
||||||
List<OpResult> opResults = checkZk().multi(multiOps);
|
|
||||||
return opResults;
|
|
||||||
} catch (KeeperException e) {
|
} catch (KeeperException e) {
|
||||||
switch (e.code()) {
|
switch (e.code()) {
|
||||||
case CONNECTIONLOSS:
|
case CONNECTIONLOSS:
|
||||||
|
@ -693,12 +638,10 @@ public class RecoverableZooKeeper {
|
||||||
assert(lastSlashIdx != -1);
|
assert(lastSlashIdx != -1);
|
||||||
String parent = path.substring(0, lastSlashIdx);
|
String parent = path.substring(0, lastSlashIdx);
|
||||||
String nodePrefix = path.substring(lastSlashIdx+1);
|
String nodePrefix = path.substring(lastSlashIdx+1);
|
||||||
long startTime = EnvironmentEdgeManager.currentTime();
|
|
||||||
List<String> nodes = checkZk().getChildren(parent, false);
|
List<String> nodes = checkZk().getChildren(parent, false);
|
||||||
List<String> matching = filterByPrefix(nodes, nodePrefix);
|
List<String> matching = filterByPrefix(nodes, nodePrefix);
|
||||||
for (String node : matching) {
|
for (String node : matching) {
|
||||||
String nodePath = parent + "/" + node;
|
String nodePath = parent + "/" + node;
|
||||||
startTime = EnvironmentEdgeManager.currentTime();
|
|
||||||
Stat stat = checkZk().exists(nodePath, false);
|
Stat stat = checkZk().exists(nodePath, false);
|
||||||
if (stat != null) {
|
if (stat != null) {
|
||||||
return nodePath;
|
return nodePath;
|
||||||
|
@ -725,10 +668,6 @@ public class RecoverableZooKeeper {
|
||||||
return zk;
|
return zk;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized byte[] getSessionPasswd() {
|
|
||||||
return zk == null ? null : zk.getSessionPasswd();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sync(String path, AsyncCallback.VoidCallback cb, Object ctx) throws KeeperException {
|
public void sync(String path, AsyncCallback.VoidCallback cb, Object ctx) throws KeeperException {
|
||||||
checkZk().sync(path, cb, null);
|
checkZk().sync(path, cb, null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue