hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nspiegelb...@apache.org
Subject svn commit: r1183536 - in /hbase/branches/0.89-fb: ./ src/main/java/org/apache/hadoop/hbase/util/ src/main/java/org/apache/hadoop/hbase/zookeeper/ src/main/resources/hbase-webapps/master/ src/test/java/org/apache/hadoop/hbase/zookeeper/
Date Fri, 14 Oct 2011 22:34:50 GMT
Author: nspiegelberg
Date: Fri Oct 14 22:34:49 2011
New Revision: 1183536

URL: http://svn.apache.org/viewvc?rev=1183536&view=rev
Log:
HBASE-4568 Make zk dump jsp response faster

Modified:
    hbase/branches/0.89-fb/pom.xml
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/RetryCounter.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
    hbase/branches/0.89-fb/src/main/resources/hbase-webapps/master/zk.jsp
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/zookeeper/TestHQuorumPeer.java

Modified: hbase/branches/0.89-fb/pom.xml
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/pom.xml?rev=1183536&r1=1183535&r2=1183536&view=diff
==============================================================================
--- hbase/branches/0.89-fb/pom.xml (original)
+++ hbase/branches/0.89-fb/pom.xml Fri Oct 14 22:34:49 2011
@@ -445,7 +445,7 @@
     <junit.version>4.8.1</junit.version>
     <mockito-all.version>1.8.4</mockito-all.version>
     <log4j.version>1.2.15</log4j.version>
-    <zookeeper.version>3.3.1</zookeeper.version>
+    <zookeeper.version>3.3.3</zookeeper.version>
 
     <commons-httpclient.version>3.1</commons-httpclient.version>
     <commons-lang.version>2.5</commons-lang.version>
@@ -517,7 +517,7 @@
         <scope>test</scope>
       </dependency>
       <dependency>
-        <groupId>org.apache.hadoop</groupId>
+        <groupId>org.apache.zookeeper</groupId>
         <artifactId>zookeeper</artifactId>
         <version>${zookeeper.version}</version>
       </dependency>
@@ -622,7 +622,7 @@
     </dependency>
 
     <dependency>
-      <groupId>org.apache.hadoop</groupId>
+      <groupId>org.apache.zookeeper</groupId>
       <artifactId>zookeeper</artifactId>
     </dependency>
 

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/RetryCounter.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/RetryCounter.java?rev=1183536&r1=1183535&r2=1183536&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/RetryCounter.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/RetryCounter.java Fri
Oct 14 22:34:49 2011
@@ -2,12 +2,17 @@ package org.apache.hadoop.hbase.util;
 
 import java.util.concurrent.TimeUnit;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper;
+
 public class RetryCounter {
+  private static final Log LOG = LogFactory.getLog(RetryCounter.class);
   private final int maxRetries;
   private int retriesRemaining;
   private final int retryIntervalMillis;
   private final TimeUnit timeUnit;
-
+  
   public RetryCounter(int maxRetries,
   int retryIntervalMillis, TimeUnit timeUnit) {
     this.maxRetries = maxRetries;
@@ -20,8 +25,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() {

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java?rev=1183536&r1=1183535&r2=1183536&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/HQuorumPeer.java
Fri Oct 14 22:34:49 2011
@@ -98,7 +98,7 @@ public class HQuorumPeer {
     return address.equals("localhost") || address.equals("127.0.0.1");
   }
 
-  private static void writeMyID(Properties properties) throws IOException {
+  static void writeMyID(Properties properties) throws IOException {
     long myId = -1;
 
     Configuration conf = HBaseConfiguration.create();

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java?rev=1183536&r1=1183535&r2=1183536&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
Fri Oct 14 22:34:49 2011
@@ -117,8 +117,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;
@@ -155,8 +153,6 @@ public class RecoverableZooKeeper {
             throw e;
         }
       }
-      LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
-          "ZooKeeper after sleeping "+retryIntervalMillis+" ms");
       retryCounter.sleepUntilNextRetry();
       retryCounter.useRetry();
     }
@@ -192,8 +188,6 @@ public class RecoverableZooKeeper {
             throw e;
         }
       }
-      LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
-          "ZooKeeper after sleeping "+retryIntervalMillis+" ms");
       retryCounter.sleepUntilNextRetry();
       retryCounter.useRetry();
     }
@@ -229,8 +223,6 @@ public class RecoverableZooKeeper {
             throw e;
         }
       }
-      LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
-          "ZooKeeper after sleeping "+retryIntervalMillis+" ms");
       retryCounter.sleepUntilNextRetry();
       retryCounter.useRetry();
     }
@@ -266,8 +258,6 @@ public class RecoverableZooKeeper {
             throw e;
         }
       }
-      LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
-          "ZooKeeper after sleeping "+retryIntervalMillis+" ms");
       retryCounter.sleepUntilNextRetry();
       retryCounter.useRetry();
     }
@@ -305,8 +295,6 @@ public class RecoverableZooKeeper {
             throw e;
         }
       }
-      LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
-          "ZooKeeper after sleeping "+retryIntervalMillis+" ms");
       retryCounter.sleepUntilNextRetry();
       retryCounter.useRetry();
     }
@@ -344,8 +332,6 @@ public class RecoverableZooKeeper {
             throw e;
         }
       }
-      LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
-          "ZooKeeper after sleeping "+retryIntervalMillis+" ms");
       retryCounter.sleepUntilNextRetry();
       retryCounter.useRetry();
     }
@@ -405,8 +391,6 @@ public class RecoverableZooKeeper {
             throw e;
         }
       }
-      LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
-          "ZooKeeper after sleeping "+retryIntervalMillis+" ms");
       retryCounter.sleepUntilNextRetry();
       retryCounter.useRetry();
     }
@@ -494,8 +478,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;
@@ -535,8 +517,6 @@ public class RecoverableZooKeeper {
             throw e;
         }
       }
-      LOG.info("The "+retryCounter.getAttemptTimes()+" times to retry " +
-          "ZooKeeper after sleeping "+retryIntervalMillis+" ms");
       retryCounter.sleepUntilNextRetry();
       retryCounter.useRetry();
     }

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java?rev=1183536&r1=1183535&r2=1183536&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java
Fri Oct 14 22:34:49 2011
@@ -27,6 +27,7 @@ import java.io.PrintWriter;
 import java.io.InputStream;
 import java.io.ByteArrayInputStream;
 import java.io.DataInputStream;
+import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -145,6 +146,8 @@ public class ZooKeeperWrapper implements
   private Set<String> unassignedZNodesWatched = new HashSet<String>();
 
   private List<Watcher> listeners = Collections.synchronizedList(new ArrayList<Watcher>());
+  
+  private int zkDumpConnectionTimeOut;
 
   // return the singleton given the name of the instance
   public static ZooKeeperWrapper getInstance(Configuration conf, String name) {
@@ -204,8 +207,10 @@ public class ZooKeeperWrapper implements
     rgnsInTransitZNode  = getZNode(parentZNode, regionsInTransitZNodeName);
     masterElectionZNode = getZNode(parentZNode, masterAddressZNodeName);
     clusterStateZNode   = getZNode(parentZNode, stateZNodeName);
-    int retryNum = conf.getInt("zookeeper.connection.retry.num",3);
-    int retryFreq = conf.getInt("zookeeper.connection.retry.freq",1000);
+    int retryNum = conf.getInt("zookeeper.connection.retry.num", 6);
+    int retryFreq = conf.getInt("zookeeper.connection.retry.freq", 1000);
+    zkDumpConnectionTimeOut = conf.getInt("zookeeper.dump.connection.timeout", 
+        1000);
     connectToZk(retryNum,retryFreq);
   }
 
@@ -366,7 +371,7 @@ public class ZooKeeperWrapper implements
     for (String server : servers) {
       sb.append("\n    - ").append(server);
       try {
-        String[] stat = getServerStats(server);
+        String[] stat = getServerStats(server, this.zkDumpConnectionTimeOut);
         for (String s : stat) {
           sb.append("\n        ").append(s);
         }
@@ -377,18 +382,6 @@ public class ZooKeeperWrapper implements
   }
 
   /**
-   * 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 String[] getServerStats(String server)
-  throws IOException {
-    return getServerStats(server, 60 * 1000);
-  }
-
-  /**
    * Gets the statistics from the given server.
    *
    * @param server  The server to get the statistics from.
@@ -399,17 +392,24 @@ public class ZooKeeperWrapper implements
   public 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);
+    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(
       socket.getInputStream()));
     out.println("stat");
     out.flush();
+    
     ArrayList<String> res = new ArrayList<String>();
     while (true) {
-      String line = in.readLine();
+      String line = in.readLine();    
       if (line != null) res.add(line);
       else break;
     }

Modified: hbase/branches/0.89-fb/src/main/resources/hbase-webapps/master/zk.jsp
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/resources/hbase-webapps/master/zk.jsp?rev=1183536&r1=1183535&r2=1183536&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/resources/hbase-webapps/master/zk.jsp (original)
+++ hbase/branches/0.89-fb/src/main/resources/hbase-webapps/master/zk.jsp Fri Oct 14 22:34:49
2011
@@ -9,10 +9,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();
-  ZooKeeperWrapper wrapper = connection.getZooKeeperWrapper();
+  ZooKeeperWrapper wrapper = master.getZooKeeperWrapper();
 %>
 
 <?xml version="1.0" encoding="UTF-8" ?>

Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/zookeeper/TestHQuorumPeer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/zookeeper/TestHQuorumPeer.java?rev=1183536&r1=1183535&r2=1183536&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/zookeeper/TestHQuorumPeer.java
(original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/zookeeper/TestHQuorumPeer.java
Fri Oct 14 22:34:49 2011
@@ -87,7 +87,11 @@ public class TestHQuorumPeer extends HBa
     String s =
       "dataDir=${hbase.tmp.dir}/zookeeper\n" +
       "clientPort=2181\n" +
-      "server.0=${hbase.master.hostname}:2888:3888\n";
+      "initLimit=2\n" +
+      "syncLimit=2\n" +
+      "server.0=${hbase.master.hostname}:2888:3888\n" +
+      "server.1=server1:2888:3888\n" +
+      "server.2=server2:2888:3888\n";
 
     System.setProperty("hbase.master.hostname", "localhost");
     InputStream is = new ByteArrayInputStream(s.getBytes());
@@ -96,14 +100,15 @@ public class TestHQuorumPeer extends HBa
     assertEquals(dataDir.toString(), properties.get("dataDir"));
     assertEquals(Integer.valueOf(2181), Integer.valueOf(properties.getProperty("clientPort")));
     assertEquals("localhost:2888:3888", properties.get("server.0"));
-
+    
+    HQuorumPeer.writeMyID(properties);
     QuorumPeerConfig config = new QuorumPeerConfig();
     config.parseProperties(properties);
 
     assertEquals(dataDir.toString(), config.getDataDir());
     assertEquals(2181, config.getClientPortAddress().getPort());
     Map<Long,QuorumServer> servers = config.getServers();
-    assertEquals(1, servers.size());
+    assertEquals(3, servers.size());
     assertTrue(servers.containsKey(Long.valueOf(0)));
     QuorumServer server = servers.get(Long.valueOf(0));
     assertEquals("localhost", server.addr.getHostName());



Mime
View raw message