Return-Path: Delivered-To: apmail-hadoop-hbase-commits-archive@minotaur.apache.org Received: (qmail 18024 invoked from network); 12 May 2009 01:48:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 12 May 2009 01:48:50 -0000 Received: (qmail 1914 invoked by uid 500); 12 May 2009 01:48:50 -0000 Delivered-To: apmail-hadoop-hbase-commits-archive@hadoop.apache.org Received: (qmail 1869 invoked by uid 500); 12 May 2009 01:48:50 -0000 Mailing-List: contact hbase-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hbase-dev@hadoop.apache.org Delivered-To: mailing list hbase-commits@hadoop.apache.org Received: (qmail 1859 invoked by uid 99); 12 May 2009 01:48:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 May 2009 01:48:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 May 2009 01:48:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 407B323889CF; Tue, 12 May 2009 01:48:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r773757 - in /hadoop/hbase/trunk: ./ src/java/org/apache/hadoop/hbase/zookeeper/ src/test/org/apache/hadoop/hbase/ Date: Tue, 12 May 2009 01:48:21 -0000 To: hbase-commits@hadoop.apache.org From: stack@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090512014821.407B323889CF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: stack Date: Tue May 12 01:48:20 2009 New Revision: 773757 URL: http://svn.apache.org/viewvc?rev=773757&view=rev Log: HBASE-1345 Remove distributed mode from MiniZooKeeper Modified: hadoop/hbase/trunk/CHANGES.txt hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/HBaseClusterTestCase.java hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/MiniZooKeeperCluster.java hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestZooKeeper.java Modified: hadoop/hbase/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=773757&r1=773756&r2=773757&view=diff ============================================================================== --- hadoop/hbase/trunk/CHANGES.txt (original) +++ hadoop/hbase/trunk/CHANGES.txt Tue May 12 01:48:20 2009 @@ -226,6 +226,7 @@ HBASE-1405 Threads.shutdown has unnecessary branch HBASE-1407 Changing internal structure of ImmutableBytesWritable contructor (Erik Holstad via Stack) + HBASE-1345 Remove distributed mode from MiniZooKeeper (Nitay Joffe via Stack) OPTIMIZATIONS Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java?rev=773757&r1=773756&r2=773757&view=diff ============================================================================== --- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java (original) +++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java Tue May 12 01:48:20 2009 @@ -139,6 +139,11 @@ quorumServers = servers; } + /** @return comma separated host:port list of ZooKeeper quorum servers. */ + public static String getQuorumServers() { + return quorumServers; + } + private static void loadZooKeeperConfig() { Properties properties = null; try { Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/HBaseClusterTestCase.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/HBaseClusterTestCase.java?rev=773757&r1=773756&r2=773757&view=diff ============================================================================== --- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/HBaseClusterTestCase.java (original) +++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/HBaseClusterTestCase.java Tue May 12 01:48:20 2009 @@ -43,7 +43,6 @@ protected MiniDFSCluster dfsCluster; protected MiniZooKeeperCluster zooKeeperCluster; protected int regionServers; - protected int numZooKeeperPeers; protected boolean startDfs; private boolean openMetaTable = true; @@ -75,7 +74,6 @@ super(); this.startDfs = startDfs; this.regionServers = regionServers; - this.numZooKeeperPeers = 1; } protected void setOpenMetaTable(boolean val) { @@ -98,7 +96,7 @@ // Note that this is done before we create the MiniHBaseCluster because we // need to edit the config to add the ZooKeeper servers. this.zooKeeperCluster = new MiniZooKeeperCluster(); - this.zooKeeperCluster.startup(numZooKeeperPeers, testDir); + this.zooKeeperCluster.startup(testDir); // start the mini cluster this.cluster = new MiniHBaseCluster(conf, regionServers); Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/MiniZooKeeperCluster.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/MiniZooKeeperCluster.java?rev=773757&r1=773756&r2=773757&view=diff ============================================================================== --- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/MiniZooKeeperCluster.java (original) +++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/MiniZooKeeperCluster.java Tue May 12 01:48:20 2009 @@ -26,9 +26,7 @@ import java.io.OutputStream; import java.io.Reader; import java.net.BindException; -import java.net.InetSocketAddress; import java.net.Socket; -import java.util.HashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -37,8 +35,6 @@ import org.apache.zookeeper.server.NIOServerCnxn; import org.apache.zookeeper.server.ZooKeeperServer; import org.apache.zookeeper.server.persistence.FileTxnLog; -import org.apache.zookeeper.server.quorum.QuorumPeer; -import org.apache.zookeeper.server.quorum.QuorumPeer.QuorumServer; /** * TODO: Most of the code in this class is ripped from ZooKeeper tests. Instead @@ -49,21 +45,12 @@ private static final Log LOG = LogFactory.getLog(MiniZooKeeperCluster.class); // TODO: make this more configurable? - private static final int LEADER_PORT_START = 31810; // use non-standard port private static final int TICK_TIME = 2000; - private static final int INIT_LIMIT = 3; - private static final int SYNC_LIMIT = 3; private static final int CONNECTION_TIMEOUT = 30000; private boolean started; - private int clientPortStart = 21810; // use non-standard port - private int numPeers; - private File baseDir; - private String quorumServers; - - // for distributed mode. - private QuorumPeer[] quorumPeers; - // for standalone mode. + private int clientPort = 21810; // use non-standard port + private NIOServerCnxn.Factory standaloneServerFactory; /** Create mini ZooKeeper cluster. */ @@ -82,109 +69,41 @@ } /** - * @return String ZooKeeper quorum servers. - */ - public String getQuorumServers() { - return quorumServers; - } - - /** - * @param numPeers * @param baseDir * @throws IOException * @throws InterruptedException */ - public void startup(int numPeers, File baseDir) throws IOException, + public void startup(File baseDir) throws IOException, InterruptedException { setupTestEnv(); shutdown(); - if (numPeers < 1) { - return; - } - - this.numPeers = numPeers; - this.baseDir = baseDir.getAbsoluteFile(); - if (isDistributed()) { - startupDistributed(); - } else { - startupStandalone(); - } - - started = true; - } - - private void startupStandalone() throws IOException, InterruptedException { - File dir = new File(baseDir, "zookeeper-standalone"); + File dir = new File(baseDir, "zookeeper").getAbsoluteFile(); recreateDir(dir); ZooKeeperServer server = new ZooKeeperServer(dir, dir, TICK_TIME); while (true) { try { - standaloneServerFactory = new NIOServerCnxn.Factory(clientPortStart); + standaloneServerFactory = new NIOServerCnxn.Factory(clientPort); } catch (BindException e) { - LOG.info("Faild binding ZK Server to client port: " + clientPortStart); + LOG.info("Faild binding ZK Server to client port: " + clientPort); //this port is already in use. try to use another - clientPortStart++; + clientPort++; continue; } break; } standaloneServerFactory.startup(server); - quorumServers = "localhost:" + clientPortStart; + String quorumServers = "localhost:" + clientPort; ZooKeeperWrapper.setQuorumServers(quorumServers); - if (!waitForServerUp(clientPortStart, CONNECTION_TIMEOUT)) { + if (!waitForServerUp(clientPort, CONNECTION_TIMEOUT)) { throw new IOException("Waiting for startup of standalone server"); } - } - - // XXX: From o.a.zk.t.QuorumTest.startServers - private void startupDistributed() throws IOException { - // Create map of peers - HashMap peers = new HashMap(); - for (int id = 1; id <= numPeers; ++id) { - int port = LEADER_PORT_START + id; - InetSocketAddress addr = new InetSocketAddress("localhost", port); - QuorumServer server = new QuorumServer(id, addr); - peers.put(Long.valueOf(id), server); - } - - StringBuffer serversBuffer = new StringBuffer(); - - // Initialize each quorum peer. - quorumPeers = new QuorumPeer[numPeers]; - for (int id = 1; id <= numPeers; ++id) { - File dir = new File(baseDir, "zookeeper-peer-" + id); - recreateDir(dir); - - int port = clientPortStart + id; - quorumPeers[id - 1] = new QuorumPeer(peers, dir, dir, port, 0, id, - TICK_TIME, INIT_LIMIT, SYNC_LIMIT); - - if (id > 1) { - serversBuffer.append(","); - } - serversBuffer.append("localhost:" + port); - } - - quorumServers = serversBuffer.toString(); - ZooKeeperWrapper.setQuorumServers(quorumServers); - // Start quorum peer threads. - for (QuorumPeer qp : quorumPeers) { - qp.start(); - } - - // Wait for quorum peers to be up before going on. - for (int id = 1; id <= numPeers; ++id) { - int port = clientPortStart + id; - if (!waitForServerUp(port, CONNECTION_TIMEOUT)) { - throw new IOException("Waiting for startup of peer " + id); - } - } + started = true; } private void recreateDir(File dir) throws IOException { @@ -200,49 +119,18 @@ /** * @throws IOException - * @throws InterruptedException */ - public void shutdown() throws IOException, InterruptedException { + public void shutdown() throws IOException { if (!started) { return; } - if (isDistributed()) { - shutdownDistributed(); - } else { - shutdownStandalone(); - } - - started = false; - } - - private boolean isDistributed() { - return numPeers > 1; - } - - private void shutdownDistributed() throws IOException, InterruptedException { - for (QuorumPeer qp : quorumPeers) { - qp.shutdown(); - qp.join(CONNECTION_TIMEOUT); - if (qp.isAlive()) { - throw new IOException("QuorumPeer " + qp.getId() - + " failed to shutdown"); - } - } - - for (int id = 1; id <= quorumPeers.length; ++id) { - int port = clientPortStart + id; - if (!waitForServerDown(port, CONNECTION_TIMEOUT)) { - throw new IOException("Waiting for shutdown of peer " + id); - } - } - } - - private void shutdownStandalone() throws IOException { standaloneServerFactory.shutdown(); - if (!waitForServerDown(clientPortStart, CONNECTION_TIMEOUT)) { + if (!waitForServerDown(clientPort, CONNECTION_TIMEOUT)) { throw new IOException("Waiting for shutdown of standalone server"); } + + started = false; } // XXX: From o.a.zk.t.ClientBase Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestZooKeeper.java URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestZooKeeper.java?rev=773757&r1=773756&r2=773757&view=diff ============================================================================== --- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestZooKeeper.java (original) +++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/TestZooKeeper.java Tue May 12 01:48:20 2009 @@ -94,7 +94,7 @@ public void testClientSessionExpired() throws IOException, InterruptedException { new HTable(conf, HConstants.META_TABLE_NAME); - String quorumServers = zooKeeperCluster.getQuorumServers(); + String quorumServers = ZooKeeperWrapper.getQuorumServers(); int sessionTimeout = conf.getInt("zookeeper.session.timeout", 2 * 1000); Watcher watcher = new EmptyWatcher(); HConnection connection = HConnectionManager.getConnection(conf); @@ -118,7 +118,7 @@ try { new HTable(conf, HConstants.META_TABLE_NAME); - String quorumServers = zooKeeperCluster.getQuorumServers(); + String quorumServers = ZooKeeperWrapper.getQuorumServers(); int sessionTimeout = conf.getInt("zookeeper.session.timeout", 2 * 1000); Watcher watcher = new EmptyWatcher();