HBASE-4568 Make zk dump jsp response faster

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1183166 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nicolas Spiegelberg 2011-10-13 23:49:15 +00:00
parent 8d8dc87d0d
commit fc5c533c59
5 changed files with 49 additions and 52 deletions

View File

@ -618,6 +618,7 @@ Release 0.92.0 - Unreleased
and CF config (Mikhail Bautin)
HBASE-4558 Refactor TestOpenedRegionHandler and TestOpenRegionHandler.(Ram)
HBASE-4558 Addendum for TestMasterFailover (Ram) - Breaks the build
HBASE-4568 Make zk dump jsp response faster
TASKS

View File

@ -21,7 +21,11 @@ package org.apache.hadoop.hbase.util;
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class RetryCounter {
private static final Log LOG = LogFactory.getLog(RetryCounter.class);
private final int maxRetries;
private int retriesRemaining;
private final int retryIntervalMillis;
@ -39,8 +43,16 @@ public class RetryCounter {
return maxRetries;
}
/**
* Sleep for a exponentially back off time
* @throws InterruptedException
*/
public void sleepUntilNextRetry() throws InterruptedException {
timeUnit.sleep(retryIntervalMillis);
int attempts = getAttemptTimes();
long sleepTime = (long) (retryIntervalMillis * Math.pow(2, attempts));
LOG.info("The " + attempts + " times to retry after sleeping " + sleepTime
+ " ms");
timeUnit.sleep(sleepTime);
}
public boolean shouldRetry() {

View File

@ -132,8 +132,6 @@ public class RecoverableZooKeeper {
throw e;
}
}
LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
"ZooKeeper after sleeping "+retryIntervalMillis+" ms");
retryCounter.sleepUntilNextRetry();
retryCounter.useRetry();
isRetry = true;
@ -170,8 +168,6 @@ public class RecoverableZooKeeper {
throw e;
}
}
LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
"ZooKeeper after sleeping "+retryIntervalMillis+" ms");
retryCounter.sleepUntilNextRetry();
retryCounter.useRetry();
}
@ -207,8 +203,6 @@ public class RecoverableZooKeeper {
throw e;
}
}
LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
"ZooKeeper after sleeping "+retryIntervalMillis+" ms");
retryCounter.sleepUntilNextRetry();
retryCounter.useRetry();
}
@ -244,8 +238,6 @@ public class RecoverableZooKeeper {
throw e;
}
}
LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
"ZooKeeper after sleeping "+retryIntervalMillis+" ms");
retryCounter.sleepUntilNextRetry();
retryCounter.useRetry();
}
@ -281,8 +273,6 @@ public class RecoverableZooKeeper {
throw e;
}
}
LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
"ZooKeeper after sleeping "+retryIntervalMillis+" ms");
retryCounter.sleepUntilNextRetry();
retryCounter.useRetry();
}
@ -320,8 +310,6 @@ public class RecoverableZooKeeper {
throw e;
}
}
LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
"ZooKeeper after sleeping "+retryIntervalMillis+" ms");
retryCounter.sleepUntilNextRetry();
retryCounter.useRetry();
}
@ -359,8 +347,6 @@ public class RecoverableZooKeeper {
throw e;
}
}
LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
"ZooKeeper after sleeping "+retryIntervalMillis+" ms");
retryCounter.sleepUntilNextRetry();
retryCounter.useRetry();
}
@ -419,8 +405,6 @@ public class RecoverableZooKeeper {
throw e;
}
}
LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
"ZooKeeper after sleeping "+retryIntervalMillis+" ms");
retryCounter.sleepUntilNextRetry();
retryCounter.useRetry();
}
@ -509,8 +493,6 @@ public class RecoverableZooKeeper {
throw e;
}
}
LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
"ZooKeeper after sleeping "+retryIntervalMillis+" ms");
retryCounter.sleepUntilNextRetry();
retryCounter.useRetry();
isRetry = true;
@ -550,8 +532,6 @@ public class RecoverableZooKeeper {
throw e;
}
}
LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
"ZooKeeper after sleeping "+retryIntervalMillis+" ms");
retryCounter.sleepUntilNextRetry();
retryCounter.useRetry();
}

View File

@ -23,6 +23,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
@ -58,6 +59,7 @@ public class ZKUtil {
// TODO: Replace this with ZooKeeper constant when ZOOKEEPER-277 is resolved.
private static final char ZNODE_PATH_SEPARATOR = '/';
private static int zkDumpConnectionTimeOut;
/**
* Creates a new connection to ZooKeeper, pulling settings and ensemble config
@ -95,6 +97,8 @@ public class ZKUtil {
int retry = conf.getInt("zookeeper.recovery.retry", 3);
int retryIntervalMillis =
conf.getInt("zookeeper.recovery.retry.intervalmill", 1000);
zkDumpConnectionTimeOut = conf.getInt("zookeeper.dump.connection.timeout",
1000);
return new RecoverableZooKeeper(ensemble, timeout, watcher,
retry, retryIntervalMillis);
}
@ -953,7 +957,7 @@ public class ZKUtil {
sb.append("\nRegion server holding ROOT: ").append(
Bytes.toStringBinary(getData(zkw, zkw.rootServerZNode)));
sb.append("\nRegion servers:");
for (String child: listChildrenNoWatch(zkw, zkw.rsZNode)) {
for (String child : listChildrenNoWatch(zkw, zkw.rsZNode)) {
sb.append("\n ").append(child);
}
sb.append("\nQuorum Server Statistics:");
@ -961,7 +965,13 @@ public class ZKUtil {
for (String server : servers) {
sb.append("\n ").append(server);
try {
String[] stat = getServerStats(server);
String[] stat = getServerStats(server, ZKUtil.zkDumpConnectionTimeOut);
if (stat == null) {
sb.append("[Error] invalid quorum server: " + server);
break;
}
for (String s : stat) {
sb.append("\n ").append(s);
}
@ -969,25 +979,13 @@ public class ZKUtil {
sb.append("\n ERROR: ").append(e.getMessage());
}
}
} catch(KeeperException ke) {
} catch (KeeperException ke) {
sb.append("\nFATAL ZooKeeper Exception!\n");
sb.append("\n" + ke.getMessage());
}
return sb.toString();
}
/**
* Gets the statistics from the given server. Uses a 1 minute timeout.
*
* @param server The server to get the statistics from.
* @return The array of response strings.
* @throws IOException When the socket communication fails.
*/
public static String[] getServerStats(String server)
throws IOException {
return getServerStats(server, 60 * 1000);
}
/**
* Gets the statistics from the given server.
*
@ -999,8 +997,18 @@ public class ZKUtil {
public static String[] getServerStats(String server, int timeout)
throws IOException {
String[] sp = server.split(":");
Socket socket = new Socket(sp[0],
sp.length > 1 ? Integer.parseInt(sp[1]) : 2181);
if (sp == null || sp.length == 0) {
return null;
}
String host = sp[0];
int port = sp.length > 1 ? Integer.parseInt(sp[1])
: HConstants.DEFAULT_ZOOKEPER_CLIENT_PORT;
Socket socket = new Socket();
InetSocketAddress sockAddr = new InetSocketAddress(host, port);
socket.connect(sockAddr, timeout);
socket.setSoTimeout(timeout);
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(

View File

@ -11,10 +11,7 @@
import="org.apache.hadoop.hbase.master.HMaster"
import="org.apache.hadoop.hbase.HConstants"%><%
HMaster master = (HMaster)getServletContext().getAttribute(HMaster.MASTER);
Configuration conf = master.getConfiguration();
HBaseAdmin hbadmin = new HBaseAdmin(conf);
HConnection connection = hbadmin.getConnection();
ZooKeeperWatcher watcher = connection.getZooKeeperWatcher();
ZooKeeperWatcher watcher = master.getZooKeeperWatcher();
%>
<?xml version="1.0" encoding="UTF-8" ?>
@ -32,7 +29,6 @@
<hr id="head_rule" />
<pre>
<%= ZKUtil.dump(watcher) %>
<% HConnectionManager.deleteConnection(hbadmin.getConfiguration(), false); %>
</pre>
</body>