ACCUMULO-1689 Merge branch '1.5.1-SNAPSHOT'
Conflicts:
minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/a028e763
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/a028e763
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/a028e763
Branch: refs/heads/master
Commit: a028e763b0ef1785039d3b0dcb7e04dee18f4f5b
Parents: f0fcd6d f1af6f9
Author: Josh Elser <[email protected]>
Authored: Sun Sep 8 22:28:26 2013 -0400
Committer: Josh Elser <[email protected]>
Committed: Sun Sep 8 22:28:26 2013 -0400
----------------------------------------------------------------------
.../accumulo/minicluster/MiniAccumuloCluster.java | 17 +++++++++++++++++
.../accumulo/minicluster/MiniAccumuloConfig.java | 18 ++++++++++++++++++
.../apache/accumulo/minicluster/ServerType.java | 2 +-
3 files changed, 36 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/a028e763/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
----------------------------------------------------------------------
diff --cc
minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
index fc6c9c0,eff3188..473fe44
---
a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
+++
b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
@@@ -34,21 -30,11 +34,22 @@@ import java.util.List
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
+import java.util.Set;
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.ZooKeeperInstance;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.master.thrift.MasterGoalState;
+import org.apache.accumulo.core.util.Daemon;
+import org.apache.accumulo.core.util.Pair;
import org.apache.accumulo.core.util.UtilWaitThread;
+ import org.apache.accumulo.server.gc.SimpleGarbageCollector;
import org.apache.accumulo.server.master.Master;
+import org.apache.accumulo.server.master.state.SetGoalState;
import org.apache.accumulo.server.tabletserver.TabletServer;
import org.apache.accumulo.server.util.Initialize;
import org.apache.accumulo.server.util.PortUtils;
@@@ -113,33 -101,27 +114,34 @@@ public class MiniAccumuloCluster
} catch (IOException e) {}
}
}
-
- private File libDir;
- private File confDir;
- private File zooKeeperDir;
- private File accumuloDir;
+
+ private boolean initialized = false;
+ private Process zooKeeperProcess = null;
+ private Process masterProcess = null;
++ private Process gcProcess = null;
+ private List<Process> tabletServerProcesses = new ArrayList<Process>();
+
+ private Set<Pair<ServerType,Integer>> debugPorts = new
HashSet<Pair<ServerType,Integer>>();
+
private File zooCfgFile;
- private File logDir;
- private File walogDir;
-
- private Process zooKeeperProcess;
- private Process masterProcess;
- private Process gcProcess;
-
- private int zooKeeperPort;
-
+
+ public List<LogWriter> getLogWriters() {
+ return logWriters;
+ }
+
private List<LogWriter> logWriters = new
ArrayList<MiniAccumuloCluster.LogWriter>();
-
+
private MiniAccumuloConfig config;
- private Process[] tabletServerProcesses;
-
- private Process exec(Class<? extends Object> clazz, String... args) throws
IOException {
+ private MiniDFSCluster miniDFS = null;
+ private List<Process> cleanup = new ArrayList<Process>();
+
+ public Process exec(Class<? extends Object> clazz, String... args) throws
IOException {
+ Process proc = exec(clazz, Collections.singletonList("-Xmx" +
config.getDefaultMemory()), args);
+ cleanup.add(proc);
+ return proc;
+ }
+
+ private Process exec(Class<? extends Object> clazz, List<String>
extraJvmOpts, String... args) throws IOException {
String javaHome = System.getProperty("java.home");
String javaBin = javaHome + File.separator + "bin" + File.separator +
"java";
String classpath = System.getProperty("java.class.path");
@@@ -312,117 -277,49 +314,128 @@@
* @throws IllegalStateException
* if already started
*/
-
public void start() throws IOException, InterruptedException {
- if (zooKeeperProcess != null)
- throw new IllegalStateException("Already started");
-
- Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override
- public void run() {
- try {
- MiniAccumuloCluster.this.stop();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
+
+ if (!initialized) {
+
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ try {
+ MiniAccumuloCluster.this.stop();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
}
+ });
+ }
+
+ if (zooKeeperProcess == null) {
+ zooKeeperProcess = exec(Main.class, ServerType.ZOOKEEPER,
ZooKeeperServerMain.class.getName(), zooCfgFile.getAbsolutePath());
+ }
+
+ if (!initialized) {
+ // sleep a little bit to let zookeeper come up before calling init,
seems to work better
+ UtilWaitThread.sleep(250);
+ Process initProcess = exec(Initialize.class, "--instance-name",
config.getInstanceName(), "--password", config.getRootPassword());
+ int ret = initProcess.waitFor();
+ if (ret != 0) {
+ throw new RuntimeException("Initialize process returned " + ret);
}
- });
-
- zooKeeperProcess = exec(Main.class, ZooKeeperServerMain.class.getName(),
zooCfgFile.getAbsolutePath());
-
- // sleep a little bit to let zookeeper come up before calling init, seems
to work better
- UtilWaitThread.sleep(250);
-
- Process initProcess = exec(Initialize.class, "--instance-name",
INSTANCE_NAME, "--password", config.getRootPassword());
- int ret = initProcess.waitFor();
+ initialized = true;
+ }
+
+ for (int i = tabletServerProcesses.size(); i < config.getNumTservers();
i++) {
+ tabletServerProcesses.add(exec(TabletServer.class,
ServerType.TABLET_SERVER));
+ }
+ int ret = 0;
+ for (int i = 0; i < 5; i++) {
+ ret = exec(Main.class, SetGoalState.class.getName(),
MasterGoalState.NORMAL.toString()).waitFor();
+ if (ret == 0)
+ break;
+ UtilWaitThread.sleep(1000);
+ }
if (ret != 0) {
- throw new RuntimeException("Initialize process returned " + ret);
+ throw new RuntimeException("Could not set master goal state, process
returned " + ret);
}
-
- tabletServerProcesses = new Process[config.getNumTservers()];
- for (int i = 0; i < config.getNumTservers(); i++) {
- tabletServerProcesses[i] = exec(TabletServer.class);
+ if (masterProcess == null) {
+ masterProcess = exec(Master.class, ServerType.MASTER);
}
-
- masterProcess = exec(Master.class);
-
+ if (config.shouldRunGC()) {
- gcProcess = exec(SimpleGarbageCollector.class);
++ gcProcess = exec(SimpleGarbageCollector.class,
ServerType.GARBAGE_COLLECTOR);
+ }
}
-
+
+ private List<String> buildRemoteDebugParams(int port) {
+ return Arrays.asList(new String[] {"-Xdebug",
String.format("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=%d",
port)});
+ }
+
+ /**
+ * @return generated remote debug ports if in debug mode.
+ * @since 1.6.0
+ */
+ public Set<Pair<ServerType,Integer>> getDebugPorts() {
+ return debugPorts;
+ }
+
+ List<ProcessReference> references(Process... procs) {
+ List<ProcessReference> result = new ArrayList<ProcessReference>();
+ for (Process proc : procs) {
+ result.add(new ProcessReference(proc));
+ }
+ return result;
+ }
+
+ public Map<ServerType,Collection<ProcessReference>> getProcesses() {
+ Map<ServerType,Collection<ProcessReference>> result = new
HashMap<ServerType,Collection<ProcessReference>>();
+ result.put(ServerType.MASTER, references(masterProcess));
+ result.put(ServerType.TABLET_SERVER,
references(tabletServerProcesses.toArray(new Process[0])));
+ result.put(ServerType.ZOOKEEPER, references(zooKeeperProcess));
++ result.put(ServerType.GARBAGE_COLLECTOR, references(gcProcess));
+ return result;
+ }
+
+ public void killProcess(ServerType type, ProcessReference proc) throws
ProcessNotFoundException, InterruptedException {
+ boolean found = false;
+ switch (type) {
+ case MASTER:
+ if (proc.equals(masterProcess)) {
+ masterProcess.destroy();
+ masterProcess = null;
+ found = true;
+ }
+ break;
+ case TABLET_SERVER:
+ for (Process tserver : tabletServerProcesses) {
+ if (proc.equals(tserver)) {
+ tabletServerProcesses.remove(tserver);
+ tserver.destroy();
+ found = true;
+ break;
+ }
+ }
+ break;
+ case ZOOKEEPER:
+ if (proc.equals(zooKeeperProcess)) {
+ zooKeeperProcess.destroy();
+ zooKeeperProcess = null;
+ found = true;
+ }
+ break;
++ case GARBAGE_COLLECTOR:
++ if (proc.equals(gcProcess)) {
++ gcProcess.destroy();
++ gcProcess = null;
++ found= true;
++ }
++ break;
+ }
+ if (!found)
+ throw new ProcessNotFoundException();
+ }
+
/**
* @return Accumulo instance name
*/
@@@ -457,31 -354,11 +470,35 @@@
tserver.destroy();
}
}
-
- for (LogWriter lw : logWriters)
- lw.flush();
-
- if (gcProcess != null)
++ if (gcProcess != null) {
+ gcProcess.destroy();
++ }
+
+ zooKeeperProcess = null;
+ masterProcess = null;
++ gcProcess = null;
+ tabletServerProcesses.clear();
+ if (config.useMiniDFS() && miniDFS != null)
+ miniDFS.shutdown();
+ for (Process p : cleanup)
+ p.destroy();
+ miniDFS = null;
+ }
+
+ /**
+ * @since 1.6.0
+ */
+ public MiniAccumuloConfig getConfig() {
+ return config;
+ }
+
+ /**
+ * Utility method to get a connector to the MAC.
+ *
+ * @since 1.6.0
+ */
+ public Connector getConnector(String user, String passwd) throws
AccumuloException, AccumuloSecurityException {
+ Instance instance = new ZooKeeperInstance(this.getInstanceName(),
this.getZooKeepers());
+ return instance.getConnector(user, new PasswordToken(passwd));
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/a028e763/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
----------------------------------------------------------------------
diff --cc
minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
index 2080108,81fbe29..2d6393f
---
a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
+++
b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
@@@ -30,33 -25,14 +30,34 @@@ import org.apache.accumulo.server.util.
*
* @since 1.5.0
*/
-
public class MiniAccumuloConfig {
+ private static final String DEFAULT_INSTANCE_SECRET = "DONTTELL";
+
private File dir = null;
private String rootPassword = null;
- private Map<String,String> siteConfig = Collections.emptyMap();
+ private Map<String,String> siteConfig = new HashMap<String,String>();
private int numTservers = 2;
+ private Map<ServerType,Long> memoryConfig = new HashMap<ServerType,Long>();
+
+ private boolean jdwpEnabled = false;
+
+ private String instanceName = "miniInstance";
+
+ private File libDir;
+ private File confDir;
+ private File zooKeeperDir;
+ private File accumuloDir;
+ private File logDir;
+ private File walogDir;
+
+ private Integer zooKeeperPort;
+ private long defaultMemorySize = 128 * 1024 * 1024;
+
+ private boolean initialized = false;
+
+ private boolean useMiniDFS = false;
+ private boolean runGC = false;
/**
* @param dir
@@@ -70,78 -47,16 +71,79 @@@
this.rootPassword = rootPassword;
}
- public File getDir() {
- return dir;
+ /**
+ * Set directories and fully populate site config
+ */
+ MiniAccumuloConfig initialize() {
+
+ // Sanity checks
+ if (this.getDir().exists() && !this.getDir().isDirectory())
+ throw new IllegalArgumentException("Must pass in directory, " +
this.getDir() + " is a file");
+
+ if (this.getDir().exists() && this.getDir().list().length != 0)
+ throw new IllegalArgumentException("Directory " + this.getDir() + " is
not empty");
+
+ if (!initialized) {
+ libDir = new File(dir, "lib");
+ confDir = new File(dir, "conf");
+ accumuloDir = new File(dir, "accumulo");
+ zooKeeperDir = new File(dir, "zookeeper");
+ logDir = new File(dir, "logs");
+ walogDir = new File(dir, "walogs");
+
+ String[] paths = {"$ACCUMULO_HOME/lib/.*.jar",
"$ZOOKEEPER_HOME/zookeeper[^.].*.jar", "$HADOOP_PREFIX/[^.].*.jar",
"$HADOOP_PREFIX/lib/[^.].*.jar",
+ "$HADOOP_PREFIX/share/hadoop/common/.*.jar",
"$HADOOP_PREFIX/share/hadoop/common/lib/.*.jar",
"$HADOOP_PREFIX/share/hadoop/hdfs/.*.jar",
+ "$HADOOP_PREFIX/share/hadoop/mapreduce/.*.jar"};
+
+ String classpath = StringUtil.join(Arrays.asList(paths), ",");
+
+ mergeProp(Property.INSTANCE_DFS_URI.getKey(), "file:///");
+ mergeProp(Property.INSTANCE_DFS_DIR.getKey(),
accumuloDir.getAbsolutePath());
+ mergeProp(Property.INSTANCE_SECRET.getKey(), DEFAULT_INSTANCE_SECRET);
+ mergeProp(Property.TSERV_PORTSEARCH.getKey(), "true");
+ mergeProp(Property.LOGGER_DIR.getKey(), walogDir.getAbsolutePath());
+ mergeProp(Property.TSERV_DATACACHE_SIZE.getKey(), "10M");
+ mergeProp(Property.TSERV_INDEXCACHE_SIZE.getKey(), "10M");
+ mergeProp(Property.TSERV_MAXMEM.getKey(), "50M");
+ mergeProp(Property.TSERV_WALOG_MAX_SIZE.getKey(), "100M");
+ mergeProp(Property.TSERV_NATIVEMAP_ENABLED.getKey(), "false");
+ mergeProp(Property.TRACE_TOKEN_PROPERTY_PREFIX + ".password",
getRootPassword());
+ // since there is a small amount of memory, check more frequently for
majc... setting may not be needed in 1.5
+ mergeProp(Property.TSERV_MAJC_DELAY.getKey(), "3");
+ mergeProp(Property.GENERAL_CLASSPATHS.getKey(), classpath);
+ mergeProp(Property.GENERAL_DYNAMIC_CLASSPATHS.getKey(),
libDir.getAbsolutePath());
++ mergeProp(Property.GC_CYCLE_DELAY.getKey(), "30s");
+ mergePropWithRandomPort(Property.MASTER_CLIENTPORT.getKey());
+ mergePropWithRandomPort(Property.TRACE_PORT.getKey());
+ mergePropWithRandomPort(Property.TSERV_CLIENTPORT.getKey());
+ mergePropWithRandomPort(Property.MONITOR_PORT.getKey());
+ mergePropWithRandomPort(Property.GC_PORT.getKey());
+
+ // zookeeper port should be set explicitly in this class, not just on
the site config
+ if (zooKeeperPort == null)
+ zooKeeperPort = PortUtils.getRandomFreePort();
+ siteConfig.put(Property.INSTANCE_ZK_HOST.getKey(), "localhost:" +
zooKeeperPort);
+ initialized = true;
+ }
+ return this;
}
- public String getRootPassword() {
- return rootPassword;
+ /**
+ * Set a given key/value on the site config if it doesn't already exist
+ */
+ private void mergeProp(String key, String value) {
+ if (!siteConfig.containsKey(key)) {
+ siteConfig.put(key, value);
+ }
}
- public int getNumTservers() {
- return numTservers;
+ /**
+ * Sets a given key with a random port for the value on the site config if
it doesn't already exist.
+ */
+ private void mergePropWithRandomPort(String key) {
+ if (!siteConfig.containsKey(key)) {
+ siteConfig.put(key, PortUtils.getRandomFreePort() + "");
+ }
}
/**
@@@ -179,179 -90,18 +181,195 @@@
}
/**
+ * Calling this method is optional. A random port is generated by default
+ *
+ * @param zooKeeperPort
+ * A valid (and unused) port to use for the zookeeper
+ *
+ * @since 1.6.0
+ */
+ public MiniAccumuloConfig setZooKeeperPort(int zooKeeperPort) {
+ this.zooKeeperPort = zooKeeperPort;
+ return this;
+ }
+
+ /**
+ * Sets the amount of memory to use in the master process. Calling this
method is optional. Default memory is 128M
+ *
+ * @param serverType
+ * the type of server to apply the memory settings
+ * @param memory
+ * amount of memory to set
+ *
+ * @param memoryUnit
+ * the units for which to apply with the memory size
+ *
+ * @since 1.6.0
+ */
+ public MiniAccumuloConfig setMemory(ServerType serverType, long memory,
MemoryUnit memoryUnit) {
+ this.memoryConfig.put(serverType, memoryUnit.toBytes(memory));
+ return this;
+ }
+
+ /**
+ * Sets the default memory size to use. This value is also used when a
ServerType has not been configured explicitly. Calling this method is optional.
Default
+ * memory is 128M
+ *
+ * @param memory
+ * amount of memory to set
+ *
+ * @param memoryUnit
+ * the units for which to apply with the memory size
+ *
+ * @since 1.6.0
+ */
+ public MiniAccumuloConfig setDefaultMemory(long memory, MemoryUnit
memoryUnit) {
+ this.defaultMemorySize = memoryUnit.toBytes(memory);
+ return this;
+ }
+
+ /**
+ * @return a copy of the site config
+ */
+ public Map<String,String> getSiteConfig() {
+ return new HashMap<String,String>(siteConfig);
+ }
+
+ /**
+ * @return name of configured instance
+ *
+ * @since 1.6.0
+ */
+ public String getInstanceName() {
+ return instanceName;
+ }
+
+ /**
+ * @return The configured zookeeper port
+ *
+ * @since 1.6.0
+ */
+ public int getZooKeeperPort() {
+ return zooKeeperPort;
+ }
+
+ File getLibDir() {
+ return libDir;
+ }
+
+ File getConfDir() {
+ return confDir;
+ }
+
+ File getZooKeeperDir() {
+ return zooKeeperDir;
+ }
+
+ File getAccumuloDir() {
+ return accumuloDir;
+ }
+
+ public File getLogDir() {
+ return logDir;
+ }
+
+ File getWalogDir() {
+ return walogDir;
+ }
+
+ /**
+ * @param serverType
+ * get configuration for this server type
+ *
+ * @return memory configured in bytes, returns default if this server type
is not configured
+ *
+ * @since 1.6.0
+ */
+ public long getMemory(ServerType serverType) {
+ return memoryConfig.containsKey(serverType) ?
memoryConfig.get(serverType) : defaultMemorySize;
+ }
+
+ /**
+ * @return memory configured in bytes
+ *
+ * @since 1.6.0
+ */
+ public long getDefaultMemory() {
+ return defaultMemorySize;
+ }
+
+ /**
+ * @return zookeeper connection string
+ *
+ * @since 1.6.0
+ */
+ public String getZooKeepers() {
+ return siteConfig.get(Property.INSTANCE_ZK_HOST.getKey());
+ }
+
+ /**
+ * @return the base directory of the cluster configuration
+ */
+ public File getDir() {
+ return dir;
+ }
+
+ /**
+ * @return the root password of this cluster configuration
+ */
+ public String getRootPassword() {
+ return rootPassword;
+ }
+
+ /**
+ * @return the number of tservers configured for this cluster
+ */
+ public int getNumTservers() {
+ return numTservers;
+ }
+
+ /**
+ * @return is the current configuration in jdwpEnabled mode?
+ *
+ * @since 1.6.0
+ */
+ public boolean isJDWPEnabled() {
+ return jdwpEnabled;
+ }
+
+ /**
+ * @param jdwpEnabled
+ * should the processes run remote jdwpEnabled servers?
+ * @return the current instance
+ *
+ * @since 1.6.0
+ */
+ public MiniAccumuloConfig setJDWPEnabled(boolean jdwpEnabled) {
+ this.jdwpEnabled = jdwpEnabled;
+ return this;
+ }
+
+ public boolean useMiniDFS() {
+ return useMiniDFS;
+ }
+
+ public void useMiniDFS(boolean useMiniDFS) {
+ this.useMiniDFS = useMiniDFS;
+ }
++
++ /**
+ * Whether or not the Accumulo garbage collector proces will run
+ * @return
+ */
+ public boolean shouldRunGC() {
+ return runGC;
+ }
+
+ /**
+ * Sets if the Accumulo garbage collector process should run
+ * @param shouldRunGC
+ */
+ public void runGC(boolean shouldRunGC) {
+ runGC = shouldRunGC;
+ }
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/a028e763/minicluster/src/main/java/org/apache/accumulo/minicluster/ServerType.java
----------------------------------------------------------------------
diff --cc
minicluster/src/main/java/org/apache/accumulo/minicluster/ServerType.java
index 22258ec,0000000..3590a20
mode 100644,000000..100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/ServerType.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/ServerType.java
@@@ -1,35 -1,0 +1,35 @@@
+/*
+ * 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.accumulo.minicluster;
+
+/**
+ * @since 1.6.0
+ */
+
+public enum ServerType {
- MASTER("Master"), ZOOKEEPER("ZooKeeper"), TABLET_SERVER("TServer");
++ MASTER("Master"), ZOOKEEPER("ZooKeeper"), TABLET_SERVER("TServer"),
GARBAGE_COLLECTOR("GC");
+
+ private final String prettyPrint;
+
+ public String prettyPrint() {
+ return prettyPrint;
+ }
+
+ ServerType(String prettyPrint) {
+ this.prettyPrint = prettyPrint;
+ }
+}