This is an automated email from the ASF dual-hosted git repository.

DomGarguilo pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/2.1 by this push:
     new 8a0683b339 Avoid creating a new process just to set goal state in MAC 
(#6582)
8a0683b339 is described below

commit 8a0683b339ce76e5261e08fa57597ad3576b8bcc
Author: Dom G. <[email protected]>
AuthorDate: Fri Oct 9 12:37:59 2026 -0400

    Avoid creating a new process just to set goal state in MAC (#6582)
    
    * Avoid creating a new JVM to set goal state in MAC
    
    * refactor set goal state logic into helper method
---
 .../miniclusterImpl/MiniAccumuloClusterImpl.java      | 16 ++++------------
 .../apache/accumulo/manager/state/SetGoalState.java   | 19 +++++++++++++++----
 2 files changed, 19 insertions(+), 16 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 4bce23d5e9..fc9d86ec63 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 class MiniAccumuloClusterImpl implements 
AccumuloCluster {
 
     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 ad7cf9abd5..a044f3f950 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.core.singletons.SingletonManager.Mode;
 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 class SetGoalState {
       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);
+  }
+
 }

Reply via email to