hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1299872 [2/2] - in /hbase/trunk/src: main/java/org/apache/hadoop/hbase/ main/java/org/apache/hadoop/hbase/client/ main/java/org/apache/hadoop/hbase/mapreduce/replication/ main/java/org/apache/hadoop/hbase/replication/ main/java/org/apache/...
Date Mon, 12 Mar 2012 21:20:34 GMT
Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/replication/ReplicationZookeeper.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/replication/ReplicationZookeeper.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/replication/ReplicationZookeeper.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/replication/ReplicationZookeeper.java
Mon Mar 12 21:20:33 2012
@@ -19,6 +19,7 @@
  */
 package org.apache.hadoop.hbase.replication;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -76,7 +77,7 @@ import org.apache.zookeeper.KeeperExcept
  * </pre>
  */
 @InterfaceAudience.Private
-public class ReplicationZookeeper {
+public class ReplicationZookeeper implements Closeable{
   private static final Log LOG =
     LogFactory.getLog(ReplicationZookeeper.class);
   // Name of znode we use to lock when failover
@@ -746,6 +747,12 @@ public class ReplicationZookeeper {
     return peersZNode;
   }
 
+  @Override
+  public void close() throws IOException {
+    if (statusTracker != null)
+      statusTracker.stop();
+  }
+
   /**
    * Tracker for status of the replication
    */

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java Mon Mar 12 21:20:33
2012
@@ -58,22 +58,15 @@ import org.apache.hadoop.hbase.MasterNot
 import org.apache.hadoop.hbase.ServerName;
 import org.apache.hadoop.hbase.ZooKeeperConnectionException;
 import org.apache.hadoop.hbase.catalog.MetaReader;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.client.HConnection;
-import org.apache.hadoop.hbase.client.HConnectionManager;
+import org.apache.hadoop.hbase.client.*;
 import org.apache.hadoop.hbase.client.HConnectionManager.HConnectable;
-import org.apache.hadoop.hbase.client.MetaScanner;
 import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
-import org.apache.hadoop.hbase.client.Put;
-import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.ipc.HRegionInterface;
 import org.apache.hadoop.hbase.master.MasterFileSystem;
 import org.apache.hadoop.hbase.regionserver.HRegion;
 import org.apache.hadoop.hbase.regionserver.wal.HLog;
 import org.apache.hadoop.hbase.util.HBaseFsck.ErrorReporter.ERROR_CODE;
-import org.apache.hadoop.hbase.zookeeper.RootRegionTracker;
-import org.apache.hadoop.hbase.zookeeper.ZKTable;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.*;
 import org.apache.hadoop.io.MultipleIOException;
 import org.apache.zookeeper.KeeperException;
 
@@ -137,10 +130,9 @@ public class HBaseFsck {
     executor.allowCoreThreadTimeOut(true);
   }
 
-  public void connect() throws MasterNotRunningException,
-      ZooKeeperConnectionException {
+  public void connect() throws IOException {
     admin = new HBaseAdmin(conf);
-    status = admin.getMaster().getClusterStatus();
+    status = admin.getClusterStatus();
     connection = admin.getConnection();
   }
 

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/Merge.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/Merge.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/Merge.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/util/Merge.java Mon Mar 12 21:20:33
2012
@@ -96,7 +96,7 @@ public class Merge extends Configured im
     LOG.info("Verifying that HBase is not running...");
     try {
       HBaseAdmin.checkHBaseAvailable(getConf());
-      LOG.fatal("HBase cluster must be off-line.");
+      LOG.fatal("HBase cluster must be off-line, and is not. Aborting.");
       return -1;
     } catch (ZooKeeperConnectionException zkce) {
       // If no zk, presume no master.

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RecoverableZooKeeper.java
Mon Mar 12 21:20:33 2012
@@ -296,7 +296,7 @@ public class RecoverableZooKeeper {
     RetryCounter retryCounter = retryCounterFactory.create();
     while (true) {
       try {
-        byte[] revData = zk.getData(path, watcher, stat);       
+        byte[] revData = zk.getData(path, watcher, stat);
         return this.removeMetaData(revData);
       } catch (KeeperException e) {
         switch (e.code()) {

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java Mon
Mar 12 21:20:33 2012
@@ -90,7 +90,7 @@ public class RootRegionTracker extends Z
    * @return Returns null if <code>data</code> is null else converts passed data
    * to a ServerName instance.
    */
-  private static ServerName dataToServerName(final byte [] data) {
+  public static ServerName dataToServerName(final byte [] data) {
     // The str returned could be old style -- pre hbase-1502 -- which was
     // hostname and port seperated by a colon rather than hostname, port and
     // startcode delimited by a ','.

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java Mon Mar 12 21:20:33
2012
@@ -35,9 +35,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.EmptyWatcher;
-import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.*;
 import org.apache.hadoop.hbase.executor.RegionTransitionData;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Threads;
@@ -253,9 +251,6 @@ public class ZKUtil {
   /**
    * Check if the specified node exists.  Sets no watches.
    *
-   * Returns true if node exists, false if not.  Returns an exception if there
-   * is an unexpected zookeeper exception.
-   *
    * @param zkw zk reference
    * @param znode path of node to watch
    * @return version of the node if it exists, -1 if does not exist
@@ -463,7 +458,8 @@ public class ZKUtil {
 
   /**
    * Get znode data. Does not set a watcher.
-   * @return ZNode data
+   * @return ZNode data, null if the node does not exist or if there is an
+   *  error.
    */
   public static byte [] getData(ZooKeeperWatcher zkw, String znode)
   throws KeeperException {
@@ -1172,4 +1168,21 @@ public class ZKUtil {
       throw new IOException(keeperEx);
     }
   }
+
+
+  public static byte[] blockUntilAvailable(
+    final ZooKeeperWatcher zkw, final String znode, final long timeout)
+    throws InterruptedException {
+    if (timeout < 0) throw new IllegalArgumentException();
+    if (zkw == null) throw new IllegalArgumentException();
+    if (znode == null) throw new IllegalArgumentException();
+
+    ZooKeeperNodeTracker znt = new ZooKeeperNodeTracker(zkw, znode, new Abortable() {
+      @Override public void abort(String why, Throwable e) {}
+      @Override public boolean isAborted() {return false;}
+    }) {
+    };
+
+    return znt.blockUntilAvailable(timeout, true);
+  }
 }

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java
(original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperNodeTracker.java
Mon Mar 12 21:20:33 2012
@@ -125,12 +125,38 @@ public abstract class ZooKeeperNodeTrack
     long remaining = timeout;
     if (refresh) {
       try {
+        // This does not create a watch if the node does not exists
         this.data = ZKUtil.getDataAndWatch(watcher, node);
       } catch(KeeperException e) {
+        // We use to abort here, but in some cases the abort is ignored (
+        //  (empty Abortable), so it's better to log...
+        LOG.warn("Unexpected exception handling blockUntilAvailable", e);
         abortable.abort("Unexpected exception handling blockUntilAvailable", e);
       }
     }
+    boolean nodeExistsChecked = (!refresh ||data!=null);
     while (!this.stopped && (notimeout || remaining > 0) && this.data
== null) {
+      if (!nodeExistsChecked) {
+        try {
+          nodeExistsChecked = (ZKUtil.checkExists(watcher, node) != -1);
+        } catch (KeeperException e) {
+          LOG.warn(
+            "Got exception while trying to check existence in  ZooKeeper" +
+            " of the node: "+node+", retrying if timeout not reached",e );
+        }
+
+        // It did not exists, and now it does.
+        if (nodeExistsChecked){
+          LOG.info("Node "+node+" now exists, resetting a watcher");
+          try {
+            // This does not create a watch if the node does not exists
+            this.data = ZKUtil.getDataAndWatch(watcher, node);
+          } catch (KeeperException e) {
+            LOG.warn("Unexpected exception handling blockUntilAvailable", e);
+            abortable.abort("Unexpected exception handling blockUntilAvailable", e);
+          }
+        }
+      }
       // We expect a notification; but we wait with a
       //  a timeout to lower the impact of a race condition if any
       wait(100);
@@ -215,7 +241,8 @@ public abstract class ZooKeeperNodeTrack
     } catch (KeeperException e) {
       abortable
           .abort(
-              "Exception while checking if basenode exists.",
+              "Exception while checking if basenode ("+watcher.baseZNode+
+                ") exists in ZooKeeper.",
               e);
     }
     return true;

Modified: hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java (original)
+++ hbase/trunk/src/main/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWatcher.java Mon
Mar 12 21:20:33 2012
@@ -19,6 +19,7 @@
  */
 package org.apache.hadoop.hbase.zookeeper;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -55,7 +56,7 @@ import org.apache.zookeeper.data.ACL;
  */
 @InterfaceAudience.Public
 @InterfaceStability.Evolving
-public class ZooKeeperWatcher implements Watcher, Abortable {
+public class ZooKeeperWatcher implements Watcher, Abortable, Closeable {
   private static final Log LOG = LogFactory.getLog(ZooKeeperWatcher.class);
 
   // Identifier for this watcher (for logging only).  It is made of the prefix
@@ -69,7 +70,7 @@ public class ZooKeeperWatcher implements
   private RecoverableZooKeeper recoverableZooKeeper;
 
   // abortable in case of zk failure
-  private Abortable abortable;
+  protected Abortable abortable;
 
   // listeners to be notified
   private final List<ZooKeeperListener> listeners =
@@ -438,15 +439,16 @@ public class ZooKeeperWatcher implements
 
   /**
    * Close the connection to ZooKeeper.
+   *
    * @throws InterruptedException
    */
   public void close() {
     try {
       if (recoverableZooKeeper != null) {
         recoverableZooKeeper.close();
-//        super.close();
       }
     } catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
     }
   }
 

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java Mon Mar 12
21:20:33 2012
@@ -1321,28 +1321,38 @@ public class HBaseTestingUtility {
     expireSession(rs.getZooKeeper(), rs);
   }
 
+
+
+  public void expireSession(ZooKeeperWatcher nodeZK) throws Exception {
+   expireSession(nodeZK, false);
+  }
+
+  @Deprecated
   public void expireSession(ZooKeeperWatcher nodeZK, Server server)
     throws Exception {
-    expireSession(nodeZK, server, false);
+    expireSession(nodeZK, false);
   }
 
-  public void expireSession(ZooKeeperWatcher nodeZK, Server server,
-      boolean checkStatus) throws Exception {
+  /**
+   * Expire a ZooKeeer session as recommended in ZooKeeper documentation
+   * http://wiki.apache.org/hadoop/ZooKeeper/FAQ#A4
+   */
+  public void expireSession(ZooKeeperWatcher nodeZK, boolean checkStatus)
+    throws Exception {
     Configuration c = new Configuration(this.conf);
     String quorumServers = ZKConfig.getZKQuorumServersString(c);
-    int sessionTimeout = 500;
     ZooKeeper zk = nodeZK.getRecoverableZooKeeper().getZooKeeper();
     byte[] password = zk.getSessionPasswd();
     long sessionID = zk.getSessionId();
 
     ZooKeeper newZK = new ZooKeeper(quorumServers,
-        sessionTimeout, EmptyWatcher.instance, sessionID, password);
+        1000, EmptyWatcher.instance, sessionID, password);
     newZK.close();
-    final long sleep = 7000; // 7s seems enough to manage the timeout
-    LOG.info("ZK Closed Session 0x" + Long.toHexString(sessionID) +
-      "; sleeping=" + sleep);
+    LOG.info("ZK Closed Session 0x" + Long.toHexString(sessionID));
 
-    Thread.sleep(sleep);
+    // There is actually no reason to sleep here. Session is expired.
+    //  May be for old ZK versions?
+    // Thread.sleep(sleep);
 
     if (checkStatus) {
       new HTable(new Configuration(conf), HConstants.META_TABLE_NAME).close();
@@ -1361,7 +1371,7 @@ public class HBaseTestingUtility {
 
   /**
    * Returns a HBaseAdmin instance.
-   * This instance is shared between HBaseTestingUtility intance users.
+   * This instance is shared between HBaseTestingUtility instance users.
    * Don't close it, it will be closed automatically when the
    * cluster shutdowns
    *
@@ -1371,7 +1381,7 @@ public class HBaseTestingUtility {
   public synchronized HBaseAdmin getHBaseAdmin()
   throws IOException {
     if (hbaseAdmin == null){
-      hbaseAdmin = new HBaseAdmin(new Configuration(getConfiguration()));
+      hbaseAdmin = new HBaseAdmin(getConfiguration());
     }
     return hbaseAdmin;
   }

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java Mon Mar 12 21:20:33
2012
@@ -92,41 +92,41 @@ public class TestZooKeeper {
    * @throws InterruptedException
    */
   @Test
-  public void testClientSessionExpired()
-  throws IOException, InterruptedException {
+  public void testClientSessionExpired() throws Exception {
     LOG.info("testClientSessionExpired");
     Configuration c = new Configuration(TEST_UTIL.getConfiguration());
     new HTable(c, HConstants.META_TABLE_NAME).close();
-    String quorumServers = ZKConfig.getZKQuorumServersString(c);
-    int sessionTimeout = 5 * 1000; // 5 seconds
+
     HConnection connection = HConnectionManager.getConnection(c);
     ZooKeeperWatcher connectionZK = connection.getZooKeeperWatcher();
-    long sessionID = connectionZK.getRecoverableZooKeeper().getSessionId();
-    byte[] password = connectionZK.getRecoverableZooKeeper().getSessionPasswd();
-    ZooKeeper zk = new ZooKeeper(quorumServers, sessionTimeout,
-        EmptyWatcher.instance, sessionID, password);
-    LOG.info("Session timeout=" + zk.getSessionTimeout() +
-      ", original=" + sessionTimeout +
-      ", id=" + zk.getSessionId());
-    zk.close();
 
-    Thread.sleep(sessionTimeout * 3L);
+    TEST_UTIL.expireSession(connectionZK);
+
+    // Depending on how long you wait here, the state after dump will
+    // be 'closed' or 'Connecting'.
+    // There should be no reason to wait, the connection is closed on the server
+    // Thread.sleep(sessionTimeout * 3L);
 
+    LOG.info("Before dump state=" +
+      connectionZK.getRecoverableZooKeeper().getState());
     // provoke session expiration by doing something with ZK
     ZKUtil.dump(connectionZK);
 
     // Check that the old ZK connection is closed, means we did expire
-    System.err.println("ZooKeeper should have timed out");
-    String state = connectionZK.getRecoverableZooKeeper().getState().toString();
-    LOG.info("state=" + connectionZK.getRecoverableZooKeeper().getState());
-    Assert.assertTrue(connectionZK.getRecoverableZooKeeper().getState().
-      equals(States.CLOSED));
+    LOG.info("ZooKeeper should have timed out");
+    States state = connectionZK.getRecoverableZooKeeper().getState();
+    LOG.info("After dump state=" + state);
+    Assert.assertTrue(state == States.CLOSED);
 
     // Check that the client recovered
     ZooKeeperWatcher newConnectionZK = connection.getZooKeeperWatcher();
-    LOG.info("state=" + newConnectionZK.getRecoverableZooKeeper().getState());
-    Assert.assertTrue(newConnectionZK.getRecoverableZooKeeper().getState().equals(
-      States.CONNECTED));
+    //Here, if you wait, you will have a CONNECTED state. If you don't,
+    //  you may have the CONNECTING one.
+    //Thread.sleep(sessionTimeout * 3L);
+    States state2 = newConnectionZK.getRecoverableZooKeeper().getState();
+    LOG.info("After new get state=" +state2);
+    Assert.assertTrue(
+      state2 == States.CONNECTED || state2 == States.CONNECTING);
   }
   
   @Test
@@ -141,6 +141,7 @@ public class TestZooKeeper {
   public void testMasterSessionExpired() throws Exception {
     LOG.info("Starting testMasterSessionExpired");
     TEST_UTIL.expireMasterSession();
+    Thread.sleep(7000); // Helps the test to succeed!!!
     testSanity();
   }
 
@@ -150,7 +151,7 @@ public class TestZooKeeper {
    */
   public void testSanity() throws Exception{
     HBaseAdmin admin =
-      new HBaseAdmin(new Configuration(TEST_UTIL.getConfiguration()));
+      new HBaseAdmin(TEST_UTIL.getConfiguration());
     String tableName = "test"+System.currentTimeMillis();
     HTableDescriptor desc = new HTableDescriptor(tableName);
     HColumnDescriptor family = new HColumnDescriptor("fam");

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestAdmin.java Mon Mar 12 21:20:33
2012
@@ -749,6 +749,7 @@ public class TestAdmin {
     admin.createTable(desc, splitKeys);
     HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
     Map<HRegionInfo, HServerAddress> regions = ht.getRegionsInfo();
+    ht.close();
     assertEquals("Tried to create " + expectedRegions + " regions "
         + "but only found " + regions.size(), expectedRegions, regions.size());
     // Disable table.
@@ -1482,6 +1483,37 @@ public class TestAdmin {
     Assert.assertEquals(initialCount, finalCount) ;
   }
 
+  /**
+   * Check that we have an exception if the cluster is not there.
+   */
+  @Test
+  public void testCheckHBaseAvailableWithoutCluster() {
+    Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
+
+    // Change the ZK address to go to something not used.
+    conf.setInt(
+      "hbase.zookeeper.quorum",
+      conf.getInt("hbase.zookeeper.quorum", 9999)+10);
+
+    int initialCount = HConnectionTestingUtility.getConnectionCount();
+
+    long start = System.currentTimeMillis();
+    try {
+      HBaseAdmin.checkHBaseAvailable(conf);
+      assertTrue(false);
+    } catch (MasterNotRunningException ignored) {
+    } catch (ZooKeeperConnectionException ignored) {
+    }
+    long end = System.currentTimeMillis();
+
+    int finalCount = HConnectionTestingUtility.getConnectionCount();
+
+    Assert.assertEquals(initialCount, finalCount) ;
+
+    LOG.info("It took "+(end-start)+" ms to find out that" +
+      " HBase was not available");
+  }
+
   @org.junit.Rule
   public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
     new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java Mon Mar
12 21:20:33 2012
@@ -19,21 +19,13 @@
  */
 package org.apache.hadoop.hbase.client;
 
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
@@ -53,16 +45,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
-import org.apache.hadoop.hbase.HBaseTestingUtility;
-import org.apache.hadoop.hbase.HColumnDescriptor;
-import org.apache.hadoop.hbase.HConstants;
-import org.apache.hadoop.hbase.HRegionInfo;
-import org.apache.hadoop.hbase.HRegionLocation;
-import org.apache.hadoop.hbase.HServerAddress;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.LargeTests;
-import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.*;
 import org.apache.hadoop.hbase.client.HTable.DaemonThreadFactory;
 import org.apache.hadoop.hbase.client.metrics.ScanMetrics;
 import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
@@ -86,6 +69,7 @@ import org.apache.hadoop.hbase.regionser
 import org.apache.hadoop.hbase.regionserver.HRegionServer;
 import org.apache.hadoop.hbase.regionserver.Store;
 import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
 import org.apache.hadoop.io.DataInputBuffer;
 import org.junit.After;
 import org.junit.AfterClass;
@@ -95,6 +79,8 @@ import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import static org.junit.Assert.*;
+
 /**
  * Run tests that use the HBase clients; {@link HTable} and {@link HTablePool}.
  * Sets up the HBase mini cluster once at start and runs through all client tests.
@@ -214,6 +200,91 @@ public class TestFromClientSide {
      h.close();
    }
 
+   @Test
+   public void testSharedZooKeeper() throws Exception {
+     Configuration newConfig = new Configuration(TEST_UTIL.getConfiguration());
+     newConfig.set(HConstants.HBASE_CLIENT_INSTANCE_ID, "12345");
+
+     // First with a simple ZKW
+     ZooKeeperWatcher z0 = new ZooKeeperWatcher(
+       newConfig, "hconnection", new Abortable() {
+       @Override public void abort(String why, Throwable e) {}
+       @Override public boolean isAborted() {return false;}
+     });
+     z0.getRecoverableZooKeeper().getZooKeeper().exists("/oldZooKeeperWatcher", false);
+     z0.close();
+
+     // Then a ZooKeeperKeepAliveConnection
+     HConnectionManager.HConnectionImplementation connection1 =
+       (HConnectionManager.HConnectionImplementation)
+         HConnectionManager.getConnection(newConfig);
+
+     ZooKeeperKeepAliveConnection z1 = connection1.getKeepAliveZooKeeperWatcher();
+     z1.getRecoverableZooKeeper().getZooKeeper().exists("/z1", false);
+
+     z1.close();
+
+     // will still work, because the real connection is not closed yet
+     // Not do be done in real code
+     z1.getRecoverableZooKeeper().getZooKeeper().exists("/z1afterclose", false);
+
+
+     ZooKeeperKeepAliveConnection z2 = connection1.getKeepAliveZooKeeperWatcher();
+     assertTrue(
+       "ZooKeeperKeepAliveConnection equals on same connection", z1 == z2);
+
+
+
+     Configuration newConfig2 = new Configuration(TEST_UTIL.getConfiguration());
+     newConfig2.set(HConstants.HBASE_CLIENT_INSTANCE_ID, "6789");
+     HConnectionManager.HConnectionImplementation connection2 =
+       (HConnectionManager.HConnectionImplementation)
+         HConnectionManager.getConnection(newConfig2);
+
+     assertTrue("connections should be different ", connection1 != connection2);
+
+     ZooKeeperKeepAliveConnection z3 = connection2.getKeepAliveZooKeeperWatcher();
+     assertTrue(
+       "ZooKeeperKeepAliveConnection should be different" +
+         " on different connections", z1 != z3);
+
+     // Bypass the private access
+     Method m = HConnectionManager.HConnectionImplementation.class.
+       getDeclaredMethod("closeZooKeeperWatcher");
+     m.setAccessible(true);
+     m.invoke(connection2);
+
+     ZooKeeperKeepAliveConnection z4 = connection2.getKeepAliveZooKeeperWatcher();
+     assertTrue(
+       "ZooKeeperKeepAliveConnection should be recreated" +
+         " when previous connections was closed"
+       , z3 != z4);
+
+
+     z2.getRecoverableZooKeeper().getZooKeeper().exists("/z2", false);
+     z4.getRecoverableZooKeeper().getZooKeeper().exists("/z4", false);
+
+
+     HConnectionManager.deleteConnection(newConfig, true);
+     try {
+       z2.getRecoverableZooKeeper().getZooKeeper().exists("/z2", false);
+       assertTrue("We should not have a valid connection for z2", false);
+     } catch (Exception e){
+     }
+
+     z4.getRecoverableZooKeeper().getZooKeeper().exists("/z4", false);
+     // We expect success here.
+
+
+     HConnectionManager.deleteConnection(newConfig2, true);
+     try {
+       z4.getRecoverableZooKeeper().getZooKeeper().exists("/z4", false);
+       assertTrue("We should not have a valid connection for z4", false);
+     } catch (Exception e){
+     }
+   }
+
+
    /**
    * HBASE-2468 use case 1 and 2: region info de/serialization
    */
@@ -4594,7 +4665,7 @@ public class TestFromClientSide {
     assertNotNull(addrAfter);
     assertTrue(addrAfter.getPort() != addrCache.getPort());
     assertEquals(addrAfter.getPort(), addrNoCache.getPort());
-  }  
+  }
 
   @Test
   /**
@@ -4654,8 +4725,9 @@ public class TestFromClientSide {
     regionsList = table.getRegionsInRange(startKey, endKey);
     assertEquals(1, regionsList.size());
   }
-  @org.junit.Rule
-  public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
+
+   @org.junit.Rule
+   public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
     new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
 }
 

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java Mon Mar 12
21:20:33 2012
@@ -20,12 +20,11 @@ package org.apache.hadoop.hbase.master;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.hadoop.hbase.MediumTests;
-import org.apache.hadoop.hbase.ServerName;
+import org.apache.hadoop.hbase.*;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-@Category(MediumTests.class)
+@Category(SmallTests.class)
 public class TestDeadServer {
   @Test public void testIsDead() {
     DeadServer ds = new DeadServer();

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestRollingRestart.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestRollingRestart.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestRollingRestart.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/master/TestRollingRestart.java Mon Mar
12 21:20:33 2012
@@ -45,10 +45,10 @@ import org.junit.experimental.categories
  * Tests the restarting of everything as done during rolling restarts.
  */
 @Category(LargeTests.class)
-public class TestRollingRestart {
+public class  TestRollingRestart {
   private static final Log LOG = LogFactory.getLog(TestRollingRestart.class);
 
-  @Test (timeout=300000)
+  @Test (timeout=500000)
   public void testBasicRollingRestart() throws Exception {
 
     // Start a cluster with 2 masters and 4 regionservers
@@ -181,7 +181,7 @@ public class TestRollingRestart {
       assertEquals(expectedNumRS, cluster.getRegionServerThreads().size());
       num++;
     }
-    Thread.sleep(2000);
+    Thread.sleep(1000);
     assertRegionsAssigned(cluster, regions);
 
     // Bring the RS hosting ROOT down and the RS hosting META down at once

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationPeer.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationPeer.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationPeer.java
(original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationPeer.java
Mon Mar 12 21:20:33 2012
@@ -46,13 +46,14 @@ public class TestReplicationPeer {
     rp = new ReplicationPeer(conf, "clusterKey", "clusterId");
   }
 
+
   @Test(timeout=300000)
   public void testResetZooKeeperSession() throws Exception {
     ZooKeeperWatcher zkw = rp.getZkw();
     zkw.getRecoverableZooKeeper().exists("/1/2", false);
 
     LOG.info("Expiring ReplicationPeer ZooKeeper session.");
-    utility.expireSession(zkw, null, false);
+    utility.expireSession(zkw);
 
     try {
       LOG.info("Attempting to use expired ReplicationPeer ZooKeeper session.");

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteTable.java Mon
Mar 12 21:20:33 2012
@@ -77,8 +77,6 @@ public class TestRemoteTable {
     TEST_UTIL.startMiniCluster();
     REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
     HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
-    LOG.info("Admin Connection=" + admin.getConnection() + ", " + 
-      admin.getConnection().getZooKeeperWatcher());
     if (!admin.tableExists(TABLE)) {
       HTableDescriptor htd = new HTableDescriptor(TABLE);
       htd.addFamily(new HColumnDescriptor(COLUMN_1));
@@ -86,8 +84,6 @@ public class TestRemoteTable {
       htd.addFamily(new HColumnDescriptor(COLUMN_3));
       admin.createTable(htd);
       HTable table = new HTable(TEST_UTIL.getConfiguration(), TABLE);
-      LOG.info("Table connection=" + table.getConnection() + ", " +
-        admin.getConnection().getZooKeeperWatcher());
       Put put = new Put(ROW_1);
       put.add(COLUMN_1, QUALIFIER_1, TS_2, VALUE_1);
       table.put(put);

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/TestMergeTable.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/TestMergeTable.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/TestMergeTable.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/TestMergeTable.java Mon Mar 12
21:20:33 2012
@@ -117,7 +117,7 @@ public class TestMergeTable {
         MetaReader.getTableRegions(ct, desc.getName());
       LOG.info("originalTableRegions size=" + originalTableRegions.size() +
         "; " + originalTableRegions);
-      HBaseAdmin admin = new HBaseAdmin(new Configuration(c));
+      HBaseAdmin admin = new HBaseAdmin(c);
       admin.disableTable(desc.getName());
       HMerge.merge(c, FileSystem.get(c), desc.getName());
       List<HRegionInfo> postMergeTableRegions =

Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/TestMergeTool.java
URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/TestMergeTool.java?rev=1299872&r1=1299871&r2=1299872&view=diff
==============================================================================
--- hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/TestMergeTool.java (original)
+++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/util/TestMergeTool.java Mon Mar 12 21:20:33
2012
@@ -57,7 +57,7 @@ public class TestMergeTool extends HBase
   @Override
   public void setUp() throws Exception {
     // Set the timeout down else this test will take a while to complete.
-    this.conf.setLong("hbase.zookeeper.recoverable.waittime", 1000);
+    this.conf.setLong("hbase.zookeeper.recoverable.waittime", 10);
     // Make it so we try and connect to a zk that is not there (else we might
     // find a zk ensemble put up by another concurrent test and this will
     // mess up this test.  Choose unlikely port. Default test port is 21818.
@@ -186,7 +186,7 @@ public class TestMergeTool extends HBase
   throws Exception {
     Merge merger = new Merge(this.conf);
     LOG.info(msg);
-    System.out.println("fs2=" + this.conf.get("fs.defaultFS"));
+    LOG.info("fs2=" + this.conf.get("fs.defaultFS"));
     int errCode = ToolRunner.run(this.conf, merger,
       new String[] {this.desc.getNameAsString(), regionName1, regionName2}
     );



Mime
View raw message