You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2015/05/20 18:56:00 UTC

[2/4] accumulo git commit: ACCUMULO-3000: Added config option and impl to use existing ZooKeeper

ACCUMULO-3000: Added config option and impl to use existing ZooKeeper


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/dd55a161
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/dd55a161
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/dd55a161

Branch: refs/heads/master
Commit: dd55a161bad766158ec5e876a84debeb46de2465
Parents: d353b61
Author: Trent Nadeau <ta...@gmail.com>
Authored: Thu Apr 16 14:35:54 2015 +0000
Committer: Trent Nadeau <ta...@gmail.com>
Committed: Fri May 15 15:19:01 2015 -0400

----------------------------------------------------------------------
 .../minicluster/MiniAccumuloConfig.java         | 13 +++++
 .../minicluster/MiniAccumuloRunner.java         |  4 ++
 .../impl/MiniAccumuloClusterImpl.java           | 59 +++++++++++---------
 .../impl/MiniAccumuloConfigImpl.java            | 37 ++++++++++--
 4 files changed, 83 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd55a161/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
index b71b771..932507d 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
@@ -108,6 +108,19 @@ public class MiniAccumuloConfig {
   }
 
   /**
+   * Configure an existing ZooKeeper instance to use. Calling this method is optional. If not set, a new ZooKeeper instance is created.
+   *
+   * @param existingZooKeepers
+   *          Connection string for a already-running ZooKeeper instance
+   *
+   * @since 1.7.0
+   */
+  public MiniAccumuloConfig setExistingZooKeepers(String existingZooKeepers) {
+    impl.setExistingZooKeepers(existingZooKeepers);
+    return this;
+  }
+
+  /**
    * Sets the amount of memory to use in the master process. Calling this method is optional. Default memory is 128M
    *
    * @param serverType

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd55a161/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloRunner.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloRunner.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloRunner.java
index 13a75b5..1f1be44 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloRunner.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloRunner.java
@@ -75,6 +75,7 @@ public class MiniAccumuloRunner {
   private static final String NUM_T_SERVERS_PROP = "numTServers";
   private static final String DIRECTORY_PROP = "directory";
   private static final String INSTANCE_NAME_PROP = "instanceName";
+  private static final String EXISTING_ZOO_KEEPERS_PROP = "existingZooKeepers";
 
   private static void printProperties() {
     System.out.println("#mini Accumulo cluster runner properties.");
@@ -93,6 +94,7 @@ public class MiniAccumuloRunner {
     System.out.println("#" + TSERVER_MEMORY_PROP + "=128M");
     System.out.println("#" + ZOO_KEEPER_MEMORY_PROP + "=128M");
     System.out.println("#" + JDWP_ENABLED_PROP + "=false");
+    System.out.println("#" + EXISTING_ZOO_KEEPERS_PROP + "=localhost:2181");
 
     System.out.println();
     System.out.println("# Configuration normally placed in accumulo-site.xml can be added using a site. prefix.");
@@ -167,6 +169,8 @@ public class MiniAccumuloRunner {
       config.setZooKeeperPort(Integer.parseInt(opts.prop.getProperty(ZOO_KEEPER_PORT_PROP)));
     if (opts.prop.containsKey(ZOO_KEEPER_STARTUP_TIME_PROP))
       config.setZooKeeperStartupTime(Long.parseLong(opts.prop.getProperty(ZOO_KEEPER_STARTUP_TIME_PROP)));
+    if (opts.prop.containsKey(EXISTING_ZOO_KEEPERS_PROP))
+      config.setExistingZooKeepers(opts.prop.getProperty(EXISTING_ZOO_KEEPERS_PROP));
     if (opts.prop.containsKey(JDWP_ENABLED_PROP))
       config.setJDWPEnabled(Boolean.parseBoolean(opts.prop.getProperty(JDWP_ENABLED_PROP)));
     if (opts.prop.containsKey(ZOO_KEEPER_MEMORY_PROP))

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd55a161/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
index a21ba64..dd20850 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloClusterImpl.java
@@ -375,7 +375,8 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
     mkdirs(config.getLibExtDir());
 
     if (!config.useExistingInstance()) {
-      mkdirs(config.getZooKeeperDir());
+      if (!config.useExistingZooKeepers())
+        mkdirs(config.getZooKeeperDir());
       mkdirs(config.getWalogDir());
       mkdirs(config.getAccumuloDir());
     }
@@ -430,7 +431,7 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
     File siteFile = new File(config.getConfDir(), "accumulo-site.xml");
     writeConfig(siteFile, config.getSiteConfig().entrySet());
 
-    if (!config.useExistingInstance()) {
+    if (!config.useExistingInstance() && !config.useExistingZooKeepers()) {
       zooCfgFile = new File(config.getConfDir(), "zoo.cfg");
       FileWriter fileWriter = new FileWriter(zooCfgFile);
 
@@ -545,32 +546,35 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
         });
       }
 
-      control.start(ServerType.ZOOKEEPER);
+      if (!config.useExistingZooKeepers())
+        control.start(ServerType.ZOOKEEPER);
 
       if (!initialized) {
-        // sleep a little bit to let zookeeper come up before calling init, seems to work better
-        long startTime = System.currentTimeMillis();
-        while (true) {
-          Socket s = null;
-          try {
-            s = new Socket("localhost", config.getZooKeeperPort());
-            s.setReuseAddress(true);
-            s.getOutputStream().write("ruok\n".getBytes());
-            s.getOutputStream().flush();
-            byte buffer[] = new byte[100];
-            int n = s.getInputStream().read(buffer);
-            if (n >= 4 && new String(buffer, 0, 4).equals("imok"))
-              break;
-          } catch (Exception e) {
-            if (System.currentTimeMillis() - startTime >= config.getZooKeeperStartupTime()) {
-              throw new ZooKeeperBindException("Zookeeper did not start within " + (config.getZooKeeperStartupTime() / 1000) + " seconds. Check the logs in "
-                  + config.getLogDir() + " for errors.  Last exception: " + e);
+        if (!config.useExistingZooKeepers()) {
+          // sleep a little bit to let zookeeper come up before calling init, seems to work better
+          long startTime = System.currentTimeMillis();
+          while (true) {
+            Socket s = null;
+            try {
+              s = new Socket("localhost", config.getZooKeeperPort());
+              s.setReuseAddress(true);
+              s.getOutputStream().write("ruok\n".getBytes());
+              s.getOutputStream().flush();
+              byte buffer[] = new byte[100];
+              int n = s.getInputStream().read(buffer);
+              if (n >= 4 && new String(buffer, 0, 4).equals("imok"))
+                break;
+            } catch (Exception e) {
+              if (System.currentTimeMillis() - startTime >= config.getZooKeeperStartupTime()) {
+                throw new ZooKeeperBindException("Zookeeper did not start within " + (config.getZooKeeperStartupTime() / 1000) + " seconds. Check the logs in "
+                    + config.getLogDir() + " for errors.  Last exception: " + e);
+              }
+              // Don't spin absurdly fast
+              Thread.sleep(250);
+            } finally {
+              if (s != null)
+                s.close();
             }
-            // Don't spin absurdly fast
-            Thread.sleep(250);
-          } finally {
-            if (s != null)
-              s.close();
           }
         }
 
@@ -579,6 +583,7 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
         args.add(config.getInstanceName());
         args.add("--user");
         args.add(config.getRootUserName());
+        args.add("--clear-instance-name");
 
         // If we aren't using SASL, add in the root password
         final String saslEnabled = config.getSiteConfig().get(Property.INSTANCE_RPC_SASL_ENABLED.getKey());
@@ -644,7 +649,9 @@ public class MiniAccumuloClusterImpl implements AccumuloCluster {
     MiniAccumuloClusterControl control = getClusterControl();
     result.put(ServerType.MASTER, references(control.masterProcess));
     result.put(ServerType.TABLET_SERVER, references(control.tabletServerProcesses.toArray(new Process[0])));
-    result.put(ServerType.ZOOKEEPER, references(control.zooKeeperProcess));
+    if (null != control.zooKeeperProcess) {
+      result.put(ServerType.ZOOKEEPER, references(control.zooKeeperProcess));
+    }
     if (null != control.gcProcess) {
       result.put(ServerType.GARBAGE_COLLECTOR, references(control.gcProcess));
     }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dd55a161/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloConfigImpl.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloConfigImpl.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloConfigImpl.java
index eab82ba..25f3c99 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloConfigImpl.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/impl/MiniAccumuloConfigImpl.java
@@ -67,6 +67,7 @@ public class MiniAccumuloConfigImpl {
   private int zooKeeperPort = 0;
   private int configuredZooKeeperPort = 0;
   private long zooKeeperStartupTime = 20 * 1000;
+  private String existingZooKeepers;
 
   private long defaultMemorySize = 128 * 1024 * 1024;
 
@@ -157,10 +158,17 @@ public class MiniAccumuloConfigImpl {
 
       if (existingInstance == null || !existingInstance) {
         existingInstance = false;
-        // zookeeper port should be set explicitly in this class, not just on the site config
-        if (zooKeeperPort == 0)
-          zooKeeperPort = PortUtils.getRandomFreePort();
-        siteConfig.put(Property.INSTANCE_ZK_HOST.getKey(), "localhost:" + zooKeeperPort);
+        String zkHost;
+        if (useExistingZooKeepers()) {
+          zkHost = existingZooKeepers;
+        } else {
+          // zookeeper port should be set explicitly in this class, not just on the site config
+          if (zooKeeperPort == 0)
+            zooKeeperPort = PortUtils.getRandomFreePort();
+
+          zkHost = "localhost:" + zooKeeperPort;
+        }
+        siteConfig.put(Property.INSTANCE_ZK_HOST.getKey(), zkHost);
       }
       initialized = true;
     }
@@ -313,6 +321,19 @@ public class MiniAccumuloConfigImpl {
   }
 
   /**
+   * Configure an existing ZooKeeper instance to use. Calling this method is optional. If not set, a new ZooKeeper instance is created.
+   *
+   * @param existingZooKeepers
+   *          Connection string for a already-running ZooKeeper instance
+   *
+   * @since 1.8.0
+   */
+  public MiniAccumuloConfigImpl setExistingZooKeepers(String existingZooKeepers) {
+    this.existingZooKeepers = existingZooKeepers;
+    return this;
+  }
+
+  /**
    * Sets the amount of memory to use in the master process. Calling this method is optional. Default memory is 128M
    *
    * @param serverType
@@ -384,6 +405,14 @@ public class MiniAccumuloConfigImpl {
     return zooKeeperStartupTime;
   }
 
+  public String getExistingZooKeepers() {
+    return existingZooKeepers;
+  }
+
+  public boolean useExistingZooKeepers() {
+    return existingZooKeepers != null && !existingZooKeepers.isEmpty();
+  }
+
   File getLibDir() {
     return libDir;
   }