From f102a059369ef67e517828245eb745f6e0df6850 Mon Sep 17 00:00:00 2001 From: Dom G Date: Wed, 7 Oct 2026 17:53:29 -0400 Subject: [PATCH 1/2] Avoid creating a new JVM to set goal state in MAC --- .../MiniAccumuloClusterImpl.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) 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 cf550433f25..862880bf1c8 100644 --- a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java +++ b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java @@ -82,7 +82,6 @@ import org.apache.accumulo.core.rpc.clients.ThriftClientTypes; import org.apache.accumulo.core.trace.TraceUtil; import org.apache.accumulo.core.util.Pair; -import org.apache.accumulo.manager.state.SetGoalState; import org.apache.accumulo.minicluster.MiniAccumuloCluster; import org.apache.accumulo.minicluster.ServerType; import org.apache.accumulo.server.ServerContext; @@ -613,18 +612,12 @@ 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 { + getServerContext().getZooReaderWriter().putPersistentData( + getServerContext().getZooKeeperRoot() + Constants.ZMANAGER_GOAL_STATE, + ManagerGoalState.NORMAL.name().getBytes(UTF_8), ZooUtil.NodeExistsPolicy.OVERWRITE); + } catch (KeeperException e) { + throw new IllegalStateException("Could not set manager goal state", e); } control.start(ServerType.MANAGER); From 65f0dd8891a2d5b942f770a9f9bdf9144aeb5b37 Mon Sep 17 00:00:00 2001 From: Dom G Date: Fri, 9 Oct 2026 11:24:25 -0400 Subject: [PATCH 2/2] refactor set goal state logic into helper method --- .../MiniAccumuloClusterImpl.java | 5 ++--- .../accumulo/manager/state/SetGoalState.java | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) 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 ce0b51dcff1..fc9d86ec63f 100644 --- a/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java +++ b/minicluster/src/main/java/org/apache/accumulo/miniclusterImpl/MiniAccumuloClusterImpl.java @@ -83,6 +83,7 @@ import org.apache.accumulo.core.trace.TraceUtil; import org.apache.accumulo.core.util.Pair; import org.apache.accumulo.core.util.Timer; +import org.apache.accumulo.manager.state.SetGoalState; import org.apache.accumulo.minicluster.MiniAccumuloCluster; import org.apache.accumulo.minicluster.ServerType; import org.apache.accumulo.server.ServerContext; @@ -614,9 +615,7 @@ public synchronized void start() throws IOException, InterruptedException { control.start(ServerType.TABLET_SERVER); try { - getServerContext().getZooReaderWriter().putPersistentData( - getServerContext().getZooKeeperRoot() + Constants.ZMANAGER_GOAL_STATE, - ManagerGoalState.NORMAL.name().getBytes(UTF_8), ZooUtil.NodeExistsPolicy.OVERWRITE); + SetGoalState.setGoalState(getServerContext(), ManagerGoalState.NORMAL); } catch (KeeperException e) { throw new IllegalStateException("Could not set manager goal state", e); } 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); + } + }