diff --git a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java index 4bce23d5e9b..fc9d86ec63f 100644 --- a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java +++ b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java @@ -614,18 +614,10 @@ public synchronized void start() throws IOException, InterruptedException { control.start(ServerType.TABLET_SERVER); - int ret = 0; - for (int i = 0; i < 5; i++) { - ret = exec(Main.class, SetGoalState.class.getName(), ManagerGoalState.NORMAL.toString()) - .getProcess().waitFor(); - if (ret == 0) { - break; - } - sleepUninterruptibly(1, TimeUnit.SECONDS); - } - if (ret != 0) { - throw new IllegalStateException("Could not set manager goal state, process returned " + ret - + ". Check the logs in " + config.getLogDir() + " for errors."); + try { + SetGoalState.setGoalState(getServerContext(), ManagerGoalState.NORMAL); + } catch (KeeperException e) { + throw new IllegalStateException("Could not set manager goal state", e); } control.start(ServerType.MANAGER); diff --git a/server/manager/src/main/java/org/apache/accumulo/manager/state/SetGoalState.java b/server/manager/src/main/java/org/apache/accumulo/manager/state/SetGoalState.java index ad7cf9abd57..a044f3f950c 100644 --- a/server/manager/src/main/java/org/apache/accumulo/manager/state/SetGoalState.java +++ b/server/manager/src/main/java/org/apache/accumulo/manager/state/SetGoalState.java @@ -29,6 +29,7 @@ import org.apache.accumulo.manager.upgrade.RenameMasterDirInZK; import org.apache.accumulo.server.ServerContext; import org.apache.accumulo.server.security.SecurityUtil; +import org.apache.zookeeper.KeeperException; import com.google.common.base.Preconditions; @@ -38,13 +39,15 @@ public class SetGoalState { * Utility program that will change the goal state for the manager from the command line. */ public static void main(String[] args) throws Exception { + final ManagerGoalState targetGoalState; try { Preconditions.checkArgument(args.length == 1); - ManagerGoalState.valueOf(args[0]); + targetGoalState = ManagerGoalState.valueOf(args[0]); } catch (IllegalArgumentException e) { System.err.println( "Usage: accumulo " + SetGoalState.class.getName() + " [NORMAL|SAFE_MODE|CLEAN_STOP]"); System.exit(-1); + return; } try { @@ -53,12 +56,20 @@ public static void main(String[] args) throws Exception { var context = new ServerContext(siteConfig); RenameMasterDirInZK.renameMasterDirInZK(context); context.waitForZookeeperAndHdfs(); - context.getZooReaderWriter().putPersistentData( - context.getZooKeeperRoot() + Constants.ZMANAGER_GOAL_STATE, args[0].getBytes(UTF_8), - NodeExistsPolicy.OVERWRITE); + setGoalState(context, targetGoalState); } finally { SingletonManager.setMode(Mode.CLOSED); } } + /** + * Writes the manager goal state to ZooKeeper, overwriting the current value. + */ + public static void setGoalState(ServerContext context, ManagerGoalState targetGoalState) + throws KeeperException, InterruptedException { + context.getZooReaderWriter().putPersistentData( + context.getZooKeeperRoot() + Constants.ZMANAGER_GOAL_STATE, + targetGoalState.name().getBytes(UTF_8), NodeExistsPolicy.OVERWRITE); + } + }