You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2013/07/09 00:53:33 UTC
svn commit: r1501003 -
/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
Author: stack
Date: Mon Jul 8 22:53:32 2013
New Revision: 1501003
URL: http://svn.apache.org/r1501003
Log:
HBASE-8895 Misc: replace hbase.client.retries.number w/ define and remove unused imports; ADDENDUM UNDO OVERCOMMIT IN RECOVERABLEZOOKEEPER
Modified:
hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
Modified: hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java?rev=1501003&r1=1501002&r2=1501003&view=diff
==============================================================================
--- hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java (original)
+++ hbase/trunk/hbase-client/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java Mon Jul 8 22:53:32 2013
@@ -23,8 +23,8 @@ import org.apache.commons.logging.LogFac
import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.classification.InterfaceStability;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.util.BasicRetryAccountant;
-import org.apache.hadoop.hbase.util.RetryAccountant;
+import org.apache.hadoop.hbase.util.RetryCounter;
+import org.apache.hadoop.hbase.util.RetryCounterFactory;
import org.apache.zookeeper.AsyncCallback;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
@@ -76,7 +76,7 @@ public class RecoverableZooKeeper {
private static final Log LOG = LogFactory.getLog(RecoverableZooKeeper.class);
// the actual ZooKeeper client instance
volatile private ZooKeeper zk;
- private final BasicRetryAccountantFactory retryCounterFactory;
+ private final RetryCounterFactory retryCounterFactory;
// An identifier of this process in the cluster
private final String identifier;
private final byte[] id;
@@ -111,7 +111,7 @@ public class RecoverableZooKeeper {
// TODO: Add support for zk 'chroot'; we don't add it to the quorumServers String as we should.
this.zk = new ZooKeeper(quorumServers, sessionTimeout, watcher);
this.retryCounterFactory =
- new BasicRetryAccountantFactory(maxRetries, retryIntervalMillis);
+ new RetryCounterFactory(maxRetries, retryIntervalMillis);
if (identifier == null || identifier.length() == 0) {
// the identifier = processID@hostName
@@ -146,7 +146,7 @@ public class RecoverableZooKeeper {
*/
public void delete(String path, int version)
throws InterruptedException, KeeperException {
- RetryAccountant retryCounter = retryCounterFactory.create();
+ RetryCounter retryCounter = retryCounterFactory.create();
boolean isRetry = false; // False for first attempt, true for all retries.
while (true) {
try {
@@ -173,7 +173,8 @@ public class RecoverableZooKeeper {
throw e;
}
}
- retryCounter.sleep();
+ retryCounter.sleepUntilNextRetry();
+ retryCounter.useRetry();
isRetry = true;
}
}
@@ -184,7 +185,7 @@ public class RecoverableZooKeeper {
*/
public Stat exists(String path, Watcher watcher)
throws KeeperException, InterruptedException {
- RetryAccountant retryCounter = retryCounterFactory.create();
+ RetryCounter retryCounter = retryCounterFactory.create();
while (true) {
try {
return zk.exists(path, watcher);
@@ -200,7 +201,8 @@ public class RecoverableZooKeeper {
throw e;
}
}
- retryCounter.sleep();
+ retryCounter.sleepUntilNextRetry();
+ retryCounter.useRetry();
}
}
@@ -210,7 +212,7 @@ public class RecoverableZooKeeper {
*/
public Stat exists(String path, boolean watch)
throws KeeperException, InterruptedException {
- RetryAccountant retryCounter = retryCounterFactory.create();
+ RetryCounter retryCounter = retryCounterFactory.create();
while (true) {
try {
return zk.exists(path, watch);
@@ -226,15 +228,17 @@ public class RecoverableZooKeeper {
throw e;
}
}
- retryCounter.sleep();
+ retryCounter.sleepUntilNextRetry();
+ retryCounter.useRetry();
}
}
- private void retryOrThrow(RetryAccountant retryCounter, KeeperException e,
+ private void retryOrThrow(RetryCounter retryCounter, KeeperException e,
String opName) throws KeeperException {
LOG.warn("Possibly transient ZooKeeper, quorum=" + quorumServers + ", exception=" + e);
- if (!retryCounter.retry()) {
- LOG.error("ZooKeeper " + opName + " failed " + retryCounter);
+ if (!retryCounter.shouldRetry()) {
+ LOG.error("ZooKeeper " + opName + " failed after "
+ + retryCounter.getMaxRetries() + " retries");
throw e;
}
}
@@ -245,7 +249,7 @@ public class RecoverableZooKeeper {
*/
public List<String> getChildren(String path, Watcher watcher)
throws KeeperException, InterruptedException {
- RetryAccountant retryCounter = retryCounterFactory.create();
+ RetryCounter retryCounter = retryCounterFactory.create();
while (true) {
try {
return zk.getChildren(path, watcher);
@@ -261,7 +265,8 @@ public class RecoverableZooKeeper {
throw e;
}
}
- retryCounter.sleep();
+ retryCounter.sleepUntilNextRetry();
+ retryCounter.useRetry();
}
}
@@ -271,7 +276,7 @@ public class RecoverableZooKeeper {
*/
public List<String> getChildren(String path, boolean watch)
throws KeeperException, InterruptedException {
- RetryAccountant retryCounter = retryCounterFactory.create();
+ RetryCounter retryCounter = retryCounterFactory.create();
while (true) {
try {
return zk.getChildren(path, watch);
@@ -287,7 +292,8 @@ public class RecoverableZooKeeper {
throw e;
}
}
- retryCounter.sleep();
+ retryCounter.sleepUntilNextRetry();
+ retryCounter.useRetry();
}
}
@@ -297,7 +303,7 @@ public class RecoverableZooKeeper {
*/
public byte[] getData(String path, Watcher watcher, Stat stat)
throws KeeperException, InterruptedException {
- RetryAccountant retryCounter = retryCounterFactory.create();
+ RetryCounter retryCounter = retryCounterFactory.create();
while (true) {
try {
byte[] revData = zk.getData(path, watcher, stat);
@@ -314,7 +320,8 @@ public class RecoverableZooKeeper {
throw e;
}
}
- retryCounter.sleep();
+ retryCounter.sleepUntilNextRetry();
+ retryCounter.useRetry();
}
}
@@ -324,7 +331,7 @@ public class RecoverableZooKeeper {
*/
public byte[] getData(String path, boolean watch, Stat stat)
throws KeeperException, InterruptedException {
- RetryAccountant retryCounter = retryCounterFactory.create();
+ RetryCounter retryCounter = retryCounterFactory.create();
while (true) {
try {
byte[] revData = zk.getData(path, watch, stat);
@@ -341,7 +348,8 @@ public class RecoverableZooKeeper {
throw e;
}
}
- retryCounter.sleep();
+ retryCounter.sleepUntilNextRetry();
+ retryCounter.useRetry();
}
}
@@ -353,7 +361,7 @@ public class RecoverableZooKeeper {
*/
public Stat setData(String path, byte[] data, int version)
throws KeeperException, InterruptedException {
- RetryAccountant retryCounter = retryCounterFactory.create();
+ RetryCounter retryCounter = retryCounterFactory.create();
byte[] newData = appendMetaData(data);
boolean isRetry = false;
while (true) {
@@ -386,7 +394,8 @@ public class RecoverableZooKeeper {
throw e;
}
}
- retryCounter.sleep();
+ retryCounter.sleepUntilNextRetry();
+ retryCounter.useRetry();
isRetry = true;
}
}
@@ -427,7 +436,7 @@ public class RecoverableZooKeeper {
private String createNonSequential(String path, byte[] data, List<ACL> acl,
CreateMode createMode) throws KeeperException, InterruptedException {
- RetryAccountant retryCounter = retryCounterFactory.create();
+ RetryCounter retryCounter = retryCounterFactory.create();
boolean isRetry = false; // False for first attempt, true for all retries.
while (true) {
try {
@@ -464,7 +473,8 @@ public class RecoverableZooKeeper {
throw e;
}
}
- retryCounter.sleep();
+ retryCounter.sleepUntilNextRetry();
+ retryCounter.useRetry();
isRetry = true;
}
}
@@ -472,7 +482,7 @@ public class RecoverableZooKeeper {
private String createSequential(String path, byte[] data,
List<ACL> acl, CreateMode createMode)
throws KeeperException, InterruptedException {
- RetryAccountant retryCounter = retryCounterFactory.create();
+ RetryCounter retryCounter = retryCounterFactory.create();
boolean first = true;
String newPath = path+this.identifier;
while (true) {
@@ -498,7 +508,8 @@ public class RecoverableZooKeeper {
throw e;
}
}
- retryCounter.sleep();
+ retryCounter.sleepUntilNextRetry();
+ retryCounter.useRetry();
}
}
/**
@@ -534,7 +545,7 @@ public class RecoverableZooKeeper {
*/
public List<OpResult> multi(Iterable<Op> ops)
throws KeeperException, InterruptedException {
- RetryAccountant retryCounter = retryCounterFactory.create();
+ RetryCounter retryCounter = retryCounterFactory.create();
Iterable<Op> multiOps = prepareZKMulti(ops);
while (true) {
try {
@@ -551,7 +562,8 @@ public class RecoverableZooKeeper {
throw e;
}
}
- retryCounter.sleep();
+ retryCounter.sleepUntilNextRetry();
+ retryCounter.useRetry();
}
}
@@ -659,22 +671,4 @@ public class RecoverableZooKeeper {
public String getIdentifier() {
return identifier;
}
-
- /**
- * Factory to create {@link BasicRetryAccountant}s. Saves having to have maxRetries and
- * retryIntervalMillis available everywhere.
- */
- static class BasicRetryAccountantFactory {
- private final int maxRetries;
- private final int retryIntervalMillis;
-
- BasicRetryAccountantFactory(int maxRetries, int retryIntervalMillis) {
- this.maxRetries = maxRetries;
- this.retryIntervalMillis = retryIntervalMillis;
- }
-
- RetryAccountant create() {
- return new BasicRetryAccountant(maxRetries, retryIntervalMillis);
- }
- }
-}
\ No newline at end of file
+}