zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iv...@apache.org
Subject svn commit: r1432966 - in /zookeeper/bookkeeper/branches/branch-4.2: ./ bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/ bookkeeper-server/src/main/java/org/apache/bookkeeper/repli...
Date Mon, 14 Jan 2013 16:02:48 GMT
Author: ivank
Date: Mon Jan 14 16:02:47 2013
New Revision: 1432966

URL: http://svn.apache.org/viewvc?rev=1432966&view=rev
Log:
BOOKKEEPER-472: Provide an option to start Autorecovery along with Bookie Servers (umamahesh
via ivank)

Added:
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/ReplicationTestUtil.java
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestAutoRecoveryAlongWithBookieServers.java
Modified:
    zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AutoRecoveryMain.java
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestReplicationWorker.java
    zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java
    zookeeper/bookkeeper/branches/branch-4.2/hedwig-server/src/test/java/org/apache/hedwig/server/persistence/BookKeeperTestBase.java

Modified: zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt?rev=1432966&r1=1432965&r2=1432966&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt (original)
+++ zookeeper/bookkeeper/branches/branch-4.2/CHANGES.txt Mon Jan 14 16:02:47 2013
@@ -320,6 +320,8 @@ Release 4.2.0 - 2013-01-14
 
         BOOKKEEPER-293: Periodic checking of ledger replication status (ivank)
 
+        BOOKKEEPER-472: Provide an option to start Autorecovery along with Bookie Servers
(umamahesh via ivank)
+
       hedwig-server:
 
         BOOKKEEPER-250: Need a ledger manager like interface to manage metadata operations
in Hedwig (sijie via ivank)

Modified: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java?rev=1432966&r1=1432965&r2=1432966&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
Mon Jan 14 16:02:47 2013
@@ -64,6 +64,7 @@ public class ServerConfiguration extends
     protected final static String DISK_USAGE_THRESHOLD = "diskUsageThreshold";
     protected final static String DISK_CHECK_INTERVAL = "diskCheckInterval";
     protected final static String AUDITOR_PERIODIC_CHECK_INTERVAL = "auditorPeriodicCheckInterval";
+    protected final static String AUTO_RECOVERY_DAEMON_ENABLED = "autoRecoveryDaemonEnabled";
 
     /**
      * Construct a default configuration object
@@ -666,4 +667,28 @@ public class ServerConfiguration extends
     public long getAuditorPeriodicCheckInterval() {
         return getLong(AUDITOR_PERIODIC_CHECK_INTERVAL, 86400);
     }
+
+    /**
+     * Sets that whether the auto-recovery service can start along with Bookie
+     * server itself or not
+     *
+     * @param enabled
+     *            - true if need to start auto-recovery service. Otherwise
+     *            false.
+     * @return ServerConfiguration
+     */
+    public ServerConfiguration setAutoRecoveryDaemonEnabled(boolean enabled) {
+        setProperty(AUTO_RECOVERY_DAEMON_ENABLED, enabled);
+        return this;
+    }
+
+    /**
+     * Get whether the Bookie itself can start auto-recovery service also or not
+     *
+     * @return true - if Bookie should start auto-recovery service along with
+     *         it. false otherwise.
+     */
+    public boolean isAutoRecoveryDaemonEnabled() {
+        return getBoolean(AUTO_RECOVERY_DAEMON_ENABLED, false);
+    }
 }

Modified: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java?rev=1432966&r1=1432965&r2=1432966&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/BookieServer.java
Mon Jan 14 16:02:47 2013
@@ -39,6 +39,9 @@ import org.apache.bookkeeper.bookie.Exit
 import org.apache.bookkeeper.conf.ServerConfiguration;
 import org.apache.bookkeeper.jmx.BKMBeanRegistry;
 import org.apache.bookkeeper.proto.NIOServerFactory.Cnxn;
+import org.apache.bookkeeper.replication.AutoRecoveryMain;
+import org.apache.bookkeeper.replication.ReplicationException.CompatibilityException;
+import org.apache.bookkeeper.replication.ReplicationException.UnavailableException;
 import org.apache.bookkeeper.util.MathUtils;
 
 import com.google.common.annotations.VisibleForTesting;
@@ -73,12 +76,18 @@ public class BookieServer implements NIO
     final BKStats bkStats = BKStats.getInstance();
     final boolean isStatsEnabled;
     protected BookieServerBean jmxBkServerBean;
+    private AutoRecoveryMain autoRecoveryMain = null;
+    private boolean isAutoRecoveryDaemonEnabled;
 
-    public BookieServer(ServerConfiguration conf) 
-            throws IOException, KeeperException, InterruptedException, BookieException {
+    public BookieServer(ServerConfiguration conf) throws IOException,
+            KeeperException, InterruptedException, BookieException,
+            UnavailableException, CompatibilityException {
         this.conf = conf;
         this.bookie = newBookie(conf);
-
+        isAutoRecoveryDaemonEnabled = conf.isAutoRecoveryDaemonEnabled();
+        if (isAutoRecoveryDaemonEnabled) {
+            this.autoRecoveryMain = new AutoRecoveryMain(conf);
+        }
         isStatsEnabled = conf.isStatisticsEnabled();
     }
 
@@ -87,10 +96,13 @@ public class BookieServer implements NIO
         return new Bookie(conf);
     }
 
-    public void start() throws IOException {
+    public void start() throws IOException, UnavailableException {
         nioServerFactory = new NIOServerFactory(conf, this);
 
         this.bookie.start();
+        if (isAutoRecoveryDaemonEnabled && this.autoRecoveryMain != null) {
+            this.autoRecoveryMain.start();
+        }
 
         nioServerFactory.start();
         running = true;
@@ -136,6 +148,9 @@ public class BookieServer implements NIO
         }
         nioServerFactory.shutdown();
         exitCode = bookie.shutdown();
+        if (isAutoRecoveryDaemonEnabled && this.autoRecoveryMain != null) {
+            this.autoRecoveryMain.shutdown();
+        }
         running = false;
 
         // unregister JMX
@@ -180,6 +195,16 @@ public class BookieServer implements NIO
     }
 
     /**
+     * Whether auto-recovery service running with Bookie?
+     *
+     * @return true if auto-recovery service is running, otherwise return false
+     */
+    public boolean isAutoRecoveryRunning() {
+        return this.autoRecoveryMain != null
+                && this.autoRecoveryMain.isAutoRecoveryRunning();
+    }
+
+    /**
      * Whether nio server is running?
      *
      * @return true if nio server is running, otherwise return false
@@ -216,7 +241,9 @@ public class BookieServer implements NIO
                 } catch (InterruptedException ie) {
                     // do nothing
                 }
-                if (!isBookieRunning() || !isNioServerRunning()) {
+                if (!isBookieRunning()
+                        || !isNioServerRunning()
+                        || (isAutoRecoveryDaemonEnabled && !isAutoRecoveryRunning()))
{
                     shutdown();
                     break;
                 }
@@ -227,6 +254,8 @@ public class BookieServer implements NIO
     static final Options bkOpts = new Options();
     static {
         bkOpts.addOption("c", "conf", true, "Configuration for Bookie Server");
+        bkOpts.addOption("withAutoRecovery", false,
+                "Start Autorecovery service Bookie server");
         bkOpts.addOption("h", "help", false, "Print help message");
     }
 
@@ -275,6 +304,10 @@ public class BookieServer implements NIO
                 return conf;
             }
 
+            if (cmdLine.hasOption("withAutoRecovery")) {
+                conf.setAutoRecoveryDaemonEnabled(true);
+            }
+
             if (leftArgs.length < 4) {
                 throw new IllegalArgumentException();
             }

Modified: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AutoRecoveryMain.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AutoRecoveryMain.java?rev=1432966&r1=1432965&r2=1432966&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AutoRecoveryMain.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/AutoRecoveryMain.java
Mon Jan 14 16:02:47 2013
@@ -59,6 +59,7 @@ public class AutoRecoveryMain {
     private AutoRecoveryDeathWatcher deathWatcher;
     private int exitCode;
     private volatile boolean shuttingDown = false;
+    private volatile boolean running = false;
 
     public AutoRecoveryMain(ServerConfiguration conf) throws IOException,
             InterruptedException, KeeperException, UnavailableException,
@@ -92,6 +93,7 @@ public class AutoRecoveryMain {
         auditorElector.start();
         replicationWorker.start();
         deathWatcher.start();
+        running = true;
     }
 
     /*
@@ -113,6 +115,7 @@ public class AutoRecoveryMain {
             return;
         }
         shuttingDown = true;
+        running = false;
         this.exitCode = exitCode;
         try {
             deathWatcher.interrupt();
@@ -137,6 +140,11 @@ public class AutoRecoveryMain {
         return exitCode;
     }
 
+    /** Is auto-recovery service running? */
+    public boolean isAutoRecoveryRunning() {
+        return running;
+    }
+
     /*
      * DeathWatcher for AutoRecovery daemons.
      */

Modified: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java?rev=1432966&r1=1432965&r2=1432966&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
Mon Jan 14 16:02:47 2013
@@ -31,6 +31,8 @@ import java.util.concurrent.TimeUnit;
 import org.apache.bookkeeper.bookie.BookieException;
 import org.apache.bookkeeper.conf.ServerConfiguration;
 import org.apache.bookkeeper.proto.BookieServer;
+import org.apache.bookkeeper.replication.ReplicationException.CompatibilityException;
+import org.apache.bookkeeper.replication.ReplicationException.UnavailableException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.zookeeper.CreateMode;
@@ -121,8 +123,10 @@ public class LocalBookKeeper {
             LOG.error("Interrupted while creating znodes", e);
         }
     }
-    private void runBookies(ServerConfiguration baseConf) 
-            throws IOException, KeeperException, InterruptedException, BookieException {
+
+    private void runBookies(ServerConfiguration baseConf) throws IOException,
+            KeeperException, InterruptedException, BookieException,
+            UnavailableException, CompatibilityException {
         LOG.info("Starting Bookie(s)");
         // Create Bookie Servers (B1, B2, B3)
 
@@ -149,8 +153,9 @@ public class LocalBookKeeper {
         }
     }
 
-    public static void main(String[] args)
-            throws IOException, KeeperException, InterruptedException, BookieException {
+    public static void main(String[] args) throws IOException, KeeperException,
+            InterruptedException, BookieException, UnavailableException,
+            CompatibilityException {
         if(args.length < 1) {
             usage();
             System.exit(-1);

Added: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/ReplicationTestUtil.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/ReplicationTestUtil.java?rev=1432966&view=auto
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/ReplicationTestUtil.java
(added)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/ReplicationTestUtil.java
Mon Jan 14 16:02:47 2013
@@ -0,0 +1,59 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.bookkeeper.replication;
+
+import java.util.List;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.ZooKeeper;
+
+/** Utility class for replication tests */
+public class ReplicationTestUtil {
+
+    /** Checks whether ledger is in under-replication */
+    static boolean isLedgerInUnderReplication(ZooKeeper zkc, long id,
+            String basePath) throws KeeperException, InterruptedException {
+        List<String> children;
+        try {
+            children = zkc.getChildren(basePath, true);
+        } catch (KeeperException.NoNodeException nne) {
+            return false;
+        }
+
+        boolean isMatched = false;
+        for (String child : children) {
+            if (child.startsWith("urL") && child.contains(String.valueOf(id))) {
+                isMatched = true;
+                break;
+            } else {
+                String path = basePath + '/' + child;
+                try {
+                    if (zkc.getChildren(path, false).size() > 0) {
+                        isMatched = isLedgerInUnderReplication(zkc, id, path);
+                    }
+                } catch (KeeperException.NoNodeException nne) {
+                    return false;
+                }
+            }
+
+        }
+        return isMatched;
+    }
+}

Added: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestAutoRecoveryAlongWithBookieServers.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestAutoRecoveryAlongWithBookieServers.java?rev=1432966&view=auto
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestAutoRecoveryAlongWithBookieServers.java
(added)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestAutoRecoveryAlongWithBookieServers.java
Mon Jan 14 16:02:47 2013
@@ -0,0 +1,99 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.bookkeeper.replication;
+
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.apache.bookkeeper.client.BookKeeper;
+import org.apache.bookkeeper.client.LedgerEntry;
+import org.apache.bookkeeper.client.LedgerHandle;
+import org.apache.bookkeeper.client.LedgerHandleAdapter;
+import org.apache.bookkeeper.test.BookKeeperClusterTestCase;
+import org.apache.bookkeeper.util.BookKeeperConstants;
+import org.junit.Test;
+
+public class TestAutoRecoveryAlongWithBookieServers extends
+        BookKeeperClusterTestCase {
+
+    private String basePath = "";
+
+    public TestAutoRecoveryAlongWithBookieServers() {
+        super(3);
+        baseConf.setAutoRecoveryDaemonEnabled(true);
+        basePath = baseClientConf.getZkLedgersRootPath() + '/'
+                + BookKeeperConstants.UNDER_REPLICATION_NODE
+                + BookKeeperConstants.DEFAULT_ZK_LEDGERS_ROOT_PATH;
+    }
+
+    /** Tests that the auto recovery service along with Bookie servers itself */
+    @Test(timeout = 60000)
+    public void testAutoRecoveryAlongWithBookieServers() throws Exception {
+        LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32,
+                "testpasswd".getBytes());
+        byte[] testData = "testBuiltAutoRecovery".getBytes();
+
+        for (int i = 0; i < 10; i++) {
+            lh.addEntry(testData);
+        }
+        lh.close();
+        InetSocketAddress replicaToKill = LedgerHandleAdapter
+                .getLedgerMetadata(lh).getEnsembles().get(0L).get(0);
+
+        killBookie(replicaToKill);
+
+        int startNewBookie = startNewBookie();
+        InetSocketAddress newBkAddr = new InetSocketAddress(InetAddress
+                .getLocalHost().getHostAddress(), startNewBookie);
+
+        while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh.getId(),
+                basePath)) {
+            Thread.sleep(100);
+        }
+
+        // Killing all bookies except newly replicated bookie
+        Set<Entry<Long, ArrayList<InetSocketAddress>>> entrySet = LedgerHandleAdapter
+                .getLedgerMetadata(lh).getEnsembles().entrySet();
+        for (Entry<Long, ArrayList<InetSocketAddress>> entry : entrySet) {
+            ArrayList<InetSocketAddress> bookies = entry.getValue();
+            for (InetSocketAddress bookie : bookies) {
+                if (bookie.equals(newBkAddr)) {
+                    continue;
+                }
+                killBookie(bookie);
+            }
+        }
+
+        // Should be able to read the entries from 0-9
+        LedgerHandle lhs = bkc.openLedgerNoRecovery(lh.getId(),
+                BookKeeper.DigestType.CRC32, "testpasswd".getBytes());
+        Enumeration<LedgerEntry> entries = lhs.readEntries(0, 9);
+        assertTrue("Should have the elements", entries.hasMoreElements());
+        while (entries.hasMoreElements()) {
+            LedgerEntry entry = entries.nextElement();
+            assertEquals("testBuiltAutoRecovery", new String(entry.getEntry()));
+        }
+    }
+}

Modified: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestReplicationWorker.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestReplicationWorker.java?rev=1432966&r1=1432965&r2=1432966&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestReplicationWorker.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestReplicationWorker.java
Mon Jan 14 16:02:47 2013
@@ -23,7 +23,6 @@ import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.Enumeration;
-import java.util.List;
 import java.util.Set;
 import java.util.Map.Entry;
 
@@ -40,7 +39,6 @@ import org.apache.bookkeeper.test.MultiL
 import org.apache.bookkeeper.util.BookKeeperConstants;
 import org.apache.bookkeeper.util.ZkUtils;
 import org.apache.bookkeeper.zookeeper.ZooKeeperWatcherBase;
-import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.ZooKeeper;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -130,7 +128,8 @@ public class TestReplicationWorker exten
             underReplicationManager.markLedgerUnderreplicated(lh.getId(),
                     replicaToKill.toString());
 
-            while (isLedgerInUnderReplication(lh.getId(), basePath)) {
+            while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh
+                    .getId(), basePath)) {
                 Thread.sleep(100);
             }
 
@@ -177,13 +176,15 @@ public class TestReplicationWorker exten
             int counter = 100;
             while (counter-- > 0) {
                 assertTrue("Expecting that replication should not complete",
-                        isLedgerInUnderReplication(lh.getId(), basePath));
+                        ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh
+                                .getId(), basePath));
                 Thread.sleep(100);
             }
             // restart killed bookie
             bs.add(startBookie(killedBookieConfig));
             bsConfs.add(killedBookieConfig);
-            while (isLedgerInUnderReplication(lh.getId(), basePath)) {
+            while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh
+                    .getId(), basePath)) {
                 Thread.sleep(100);
             }
             // Should be able to read the entries from 0-9
@@ -239,13 +240,15 @@ public class TestReplicationWorker exten
             int counter = 10;
             while (counter-- > 0) {
                 assertTrue("Expecting that replication should not complete",
-                        isLedgerInUnderReplication(lh.getId(), basePath));
+                        ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh
+                                .getId(), basePath));
                 Thread.sleep(100);
             }
             // restart killed bookie
             bs.add(startBookie(killedBookieConfig));
             bsConfs.add(killedBookieConfig);
-            while (isLedgerInUnderReplication(lh.getId(), basePath)) {
+            while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh
+                    .getId(), basePath)) {
                 Thread.sleep(100);
             }
             // Should be able to read the entries from 0-9
@@ -288,7 +291,8 @@ public class TestReplicationWorker exten
             // Also mark ledger as in UnderReplication
             underReplicationManager.markLedgerUnderreplicated(lh.getId(),
                     replicaToKill.toString());
-            while (isLedgerInUnderReplication(lh.getId(), basePath)) {
+            while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh
+                    .getId(), basePath)) {
                 Thread.sleep(100);
             }
         } finally {
@@ -348,11 +352,13 @@ public class TestReplicationWorker exten
             underReplicationManager.markLedgerUnderreplicated(lh2.getId(),
                     replicaToKillFromSecondLedger.toString());
 
-            while (isLedgerInUnderReplication(lh1.getId(), basePath)) {
+            while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh1
+                    .getId(), basePath)) {
                 Thread.sleep(100);
             }
 
-            while (isLedgerInUnderReplication(lh2.getId(), basePath)) {
+            while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh2
+                    .getId(), basePath)) {
                 Thread.sleep(100);
             }
 
@@ -403,8 +409,8 @@ public class TestReplicationWorker exten
 
             underReplicationManager.markLedgerUnderreplicated(lh.getId(),
                     replicaToKill.toString());
-            while (isLedgerInUnderReplication(lh.getId(),
-                    basePath)) {
+            while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh
+                    .getId(), basePath)) {
                 Thread.sleep(100);
             }
             killAllBookies(lh, newBkAddr);
@@ -465,7 +471,8 @@ public class TestReplicationWorker exten
 
             underReplicationManager.markLedgerUnderreplicated(lh.getId(),
                     replicaToKill.toString());
-            while (isLedgerInUnderReplication(lh.getId(), basePath)) {
+            while (ReplicationTestUtil.isLedgerInUnderReplication(zkc, lh
+                    .getId(), basePath)) {
                 Thread.sleep(100);
             }
 
@@ -535,35 +542,6 @@ public class TestReplicationWorker exten
         }
     }
 
-    private boolean isLedgerInUnderReplication(long id, String basePath)
-            throws KeeperException, InterruptedException {
-        List<String> children;
-        try {
-            children = zkc.getChildren(basePath, true);
-        } catch (KeeperException.NoNodeException nne) {
-            return false;
-        }
-
-        boolean isMatched = false;
-        for (String child : children) {
-            if (child.startsWith("urL") && child.contains(String.valueOf(id))) {
-                isMatched = true;
-                break;
-            } else {
-                String path = basePath + '/' + child;
-                try {
-                    if (zkc.getChildren(path, false).size() > 0) {
-                        isMatched = isLedgerInUnderReplication(id, path);
-                    }
-                } catch (KeeperException.NoNodeException nne) {
-                    return false;
-                }
-            }
-
-        }
-        return isMatched;
-    }
-
     private void verifyRecoveredLedgers(LedgerHandle lh, long startEntryId,
             long endEntryId) throws BKException, InterruptedException {
         LedgerHandle lhs = bkc.openLedgerNoRecovery(lh.getId(),

Modified: zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java?rev=1432966&r1=1432965&r2=1432966&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/BookKeeperClusterTestCase.java
Mon Jan 14 16:02:47 2013
@@ -337,7 +337,8 @@ public abstract class BookKeeperClusterT
      * @throws BookieException
      */
     public void restartBookies()
-            throws InterruptedException, IOException, KeeperException, BookieException {
+            throws InterruptedException, IOException, KeeperException,
+            BookieException, UnavailableException, CompatibilityException {
         restartBookies(null);
     }
 
@@ -353,7 +354,8 @@ public abstract class BookKeeperClusterT
      * @throws BookieException
      */
     public void restartBookies(ServerConfiguration newConf)
-        throws InterruptedException, IOException, KeeperException, BookieException {
+            throws InterruptedException, IOException, KeeperException,
+            BookieException, UnavailableException, CompatibilityException {
         // shut down bookie server
         for (BookieServer server : bs) {
             server.shutdown();
@@ -382,7 +384,8 @@ public abstract class BookKeeperClusterT
      * @throws IOException
      */
     public int startNewBookie()
-            throws IOException, InterruptedException, KeeperException, BookieException {
+            throws IOException, InterruptedException, KeeperException,
+            BookieException, UnavailableException, CompatibilityException {
         ServerConfiguration conf = newServerConfiguration();
         bsConfs.add(conf);
         bs.add(startBookie(conf));
@@ -400,7 +403,7 @@ public abstract class BookKeeperClusterT
      */
     protected BookieServer startBookie(ServerConfiguration conf)
             throws IOException, InterruptedException, KeeperException,
-            BookieException {
+            BookieException, UnavailableException, CompatibilityException {
         BookieServer server = new BookieServer(conf);
         server.start();
 
@@ -427,7 +430,8 @@ public abstract class BookKeeperClusterT
      * recovery for this bookie, if isAutoRecoveryEnabled is true.
      */
     protected BookieServer startBookie(ServerConfiguration conf, final Bookie b)
-            throws IOException, InterruptedException, KeeperException, BookieException {
+            throws IOException, InterruptedException, KeeperException,
+            BookieException, UnavailableException, CompatibilityException {
         BookieServer server = new BookieServer(conf) {
             @Override
             protected Bookie newBookie(ServerConfiguration conf) {

Modified: zookeeper/bookkeeper/branches/branch-4.2/hedwig-server/src/test/java/org/apache/hedwig/server/persistence/BookKeeperTestBase.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/branches/branch-4.2/hedwig-server/src/test/java/org/apache/hedwig/server/persistence/BookKeeperTestBase.java?rev=1432966&r1=1432965&r2=1432966&view=diff
==============================================================================
--- zookeeper/bookkeeper/branches/branch-4.2/hedwig-server/src/test/java/org/apache/hedwig/server/persistence/BookKeeperTestBase.java
(original)
+++ zookeeper/bookkeeper/branches/branch-4.2/hedwig-server/src/test/java/org/apache/hedwig/server/persistence/BookKeeperTestBase.java
Mon Jan 14 16:02:47 2013
@@ -25,6 +25,8 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Random;
 
+import org.apache.bookkeeper.replication.ReplicationException.CompatibilityException;
+import org.apache.bookkeeper.replication.ReplicationException.UnavailableException;
 import org.apache.bookkeeper.test.PortManager;
 
 import org.apache.bookkeeper.bookie.Bookie;
@@ -78,7 +80,9 @@ public class BookKeeperTestBase extends 
 
     class TestBookieServer extends BookieServer {
         public TestBookieServer(ServerConfiguration conf)
-            throws IOException, KeeperException, InterruptedException, BookieException {
+            throws IOException,
+                KeeperException, InterruptedException, BookieException,
+                UnavailableException, CompatibilityException {
             super(conf);
         }
 



Mime
View raw message