ctubbsii commented on code in PR #5438:
URL: https://github.com/apache/accumulo/pull/5438#discussion_r2029044094


##########
server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java:
##########
@@ -68,6 +69,18 @@ protected AbstractServer(String appName, ServerOpts opts, 
String[] args) {
     var siteConfig = opts.getSiteConfiguration();
     SecurityUtil.serverLogin(siteConfig);
     context = new ServerContext(siteConfig);
+    final String upgradePrepNode = context.getZooKeeperRoot() + 
Constants.ZPREPARE_FOR_UPGRADE;

Review Comment:
   Should we store anything in this node to indicate that it should be upgraded 
to a specific version? Like, should we have something more specific like 
`--prepare-upgrade-to=4.0` or something for future versions to protect against 
upgrading to the wrong intended version?



##########
server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java:
##########
@@ -68,6 +69,18 @@ protected AbstractServer(String appName, ServerOpts opts, 
String[] args) {
     var siteConfig = opts.getSiteConfiguration();
     SecurityUtil.serverLogin(siteConfig);
     context = new ServerContext(siteConfig);
+    final String upgradePrepNode = context.getZooKeeperRoot() + 
Constants.ZPREPARE_FOR_UPGRADE;
+    try {
+      if (context.getZooReader().exists(upgradePrepNode)) {
+        throw new IllegalStateException(
+            "Instance has been prepared for upgrade, no servers can be 
started."
+                + " To undo this state and abort upgrade preparations delete 
the zookeeper node: "

Review Comment:
   Could add more details that it's the next version after the current 
major.minor. Something like:
   
   ```java
               "Instance has been prepared for upgrade to the next major or 
minor version after " + versionThatWroteTheNode + "; no servers can be started."
                   + " To undo this state and abort upgrade preparations, 
delete the zookeeper node for this instance at: "
   ```



##########
server/base/src/main/java/org/apache/accumulo/server/util/UpgradePreparationUtil.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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
+ *
+ *   https://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.server.util;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.conf.SiteConfiguration;
+import org.apache.accumulo.core.data.InstanceId;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock.ServiceLockPath;
+import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
+import org.apache.accumulo.core.volume.VolumeConfiguration;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.security.SecurityUtil;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.zookeeper.KeeperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.google.auto.service.AutoService;
+
+@AutoService(KeywordExecutable.class)
+public class UpgradePreparationUtil implements KeywordExecutable {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(UpgradePreparationUtil.class);
+
+  static class Opts extends Help {
+    @Parameter(names = "--prepare-for-upgrade",
+        description = "prepare an older version instance for an upgrade to a 
newer non-bugfix release."
+            + " This command should be run using the older version of software 
after the instance is shut down.")
+    boolean postShutdownUpgradeCheck = false;
+
+    @Parameter(names = "--force", description = "allow --prepare-for-upgrade 
to run again")
+    boolean force = false;
+  }
+
+  @Override
+  public String keyword() {
+    return "upgrade";
+  }
+
+  @Override
+  public String description() {
+    return "utility used to prepare an instance for a minor or major version 
upgrade";
+  }
+
+  @Override
+  public void execute(String[] args) throws Exception {
+    Opts opts = new Opts();
+    opts.parseArgs(keyword(), args);
+
+    if (!opts.postShutdownUpgradeCheck) {
+      new JCommander(opts).usage();
+      return;
+    }
+
+    var siteConf = SiteConfiguration.auto();
+    // Login as the server on secure HDFS
+    if (siteConf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
+      SecurityUtil.serverLogin(siteConf);
+    }
+
+    String volDir = 
VolumeConfiguration.getVolumeUris(siteConf).iterator().next();
+    Path instanceDir = new Path(volDir, "instance_id");
+    InstanceId iid = VolumeManager.getInstanceIDFromHdfs(instanceDir, new 
Configuration());
+    ZooReaderWriter zoo = new ZooReaderWriter(siteConf);
+
+    if (opts.postShutdownUpgradeCheck) {
+      final String zUpgradepath = Constants.ZROOT + "/" + iid + 
Constants.ZPREPARE_FOR_UPGRADE;
+      try {
+        if (zoo.exists(zUpgradepath)) {
+          if (!opts.force) {
+            throw new IllegalStateException(
+                "'accumulo upgrade --prepare-for-upgrade' must have already 
been run."
+                    + " To run again use 'accumulo upgrade 
--prepare-for-upgrade --force'");
+          } else {
+            zoo.delete(zUpgradepath);
+          }
+        }
+      } catch (KeeperException | InterruptedException e) {
+        throw new IllegalStateException("Error creating or checking for " + 
zUpgradepath
+            + " node in zookeeper: " + e.getMessage(), e);
+      }
+
+      LOG.info("Upgrade specified, validating that Manager is stopped");
+      final ServiceLockPath mgrPath =
+          ServiceLock.path(Constants.ZROOT + "/" + iid + 
Constants.ZMANAGER_LOCK);
+      try {
+        if (ServiceLock.getLockData(zoo.getZooKeeper(), mgrPath) != null) {
+          throw new IllegalStateException(
+              "Manager is running, shut it down and retry this operation");
+        }
+      } catch (KeeperException | InterruptedException e) {
+        throw new IllegalStateException("Error trying to determine if Manager 
lock is held", e);

Review Comment:
   Can we add some primitive to ZooZap we can just call out here? Like 
`--managers --test`? Or maybe we'd have to wait until 4.0 for stuff like that?



##########
server/base/src/main/java/org/apache/accumulo/server/util/UpgradePreparationUtil.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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
+ *
+ *   https://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.server.util;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.conf.SiteConfiguration;
+import org.apache.accumulo.core.data.InstanceId;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock.ServiceLockPath;
+import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
+import org.apache.accumulo.core.volume.VolumeConfiguration;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.security.SecurityUtil;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.zookeeper.KeeperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.google.auto.service.AutoService;
+
+@AutoService(KeywordExecutable.class)
+public class UpgradePreparationUtil implements KeywordExecutable {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(UpgradePreparationUtil.class);
+
+  static class Opts extends Help {
+    @Parameter(names = "--prepare-for-upgrade",
+        description = "prepare an older version instance for an upgrade to a 
newer non-bugfix release."
+            + " This command should be run using the older version of software 
after the instance is shut down.")
+    boolean postShutdownUpgradeCheck = false;
+
+    @Parameter(names = "--force", description = "allow --prepare-for-upgrade 
to run again")
+    boolean force = false;
+  }
+
+  @Override
+  public String keyword() {
+    return "upgrade";
+  }
+
+  @Override
+  public String description() {
+    return "utility used to prepare an instance for a minor or major version 
upgrade";

Review Comment:
   ```suggestion
       return "utility used to perform various steps to upgrade Accumulo";
   ```



##########
server/base/src/main/java/org/apache/accumulo/server/util/UpgradePreparationUtil.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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
+ *
+ *   https://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.server.util;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.conf.SiteConfiguration;
+import org.apache.accumulo.core.data.InstanceId;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock.ServiceLockPath;
+import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
+import org.apache.accumulo.core.volume.VolumeConfiguration;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.security.SecurityUtil;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.zookeeper.KeeperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.google.auto.service.AutoService;
+
+@AutoService(KeywordExecutable.class)
+public class UpgradePreparationUtil implements KeywordExecutable {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(UpgradePreparationUtil.class);
+
+  static class Opts extends Help {
+    @Parameter(names = "--prepare-for-upgrade",
+        description = "prepare an older version instance for an upgrade to a 
newer non-bugfix release."
+            + " This command should be run using the older version of software 
after the instance is shut down.")

Review Comment:
   `--prepare` is probably sufficient, since the word `upgrade` is already in 
the name of the util. It'd be weird if the upgrade util was preparing for 
anything other than upgrade, so the `-for-upgrade` bit is just redundant.



##########
server/base/src/main/java/org/apache/accumulo/server/util/UpgradePreparationUtil.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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
+ *
+ *   https://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.server.util;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.conf.SiteConfiguration;
+import org.apache.accumulo.core.data.InstanceId;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock.ServiceLockPath;
+import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
+import org.apache.accumulo.core.volume.VolumeConfiguration;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.security.SecurityUtil;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.zookeeper.KeeperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.google.auto.service.AutoService;
+
+@AutoService(KeywordExecutable.class)
+public class UpgradePreparationUtil implements KeywordExecutable {

Review Comment:
   KeywordStartIT should pass after adding this new KeywordExecutable. That IT 
is used to ensure that we're careful when adding new utilities, and aren't 
surprised by adding ones that we weren't expecting to add.
   
   Also, maybe just call this `UpgradeUtil`, so it can be made more general 
purpose in subsequent releases, as the entry point for both upgrade prep and to 
initiate the upgrade process in the next release.



##########
core/src/main/java/org/apache/accumulo/core/Constants.java:
##########
@@ -94,6 +94,8 @@ public class Constants {
   public static final String ZHDFS_RESERVATIONS = "/hdfs_reservations";
   public static final String ZRECOVERY = "/recovery";
 
+  public static final String ZPREPARE_FOR_UPGRADE = "/upgrade_prepped";

Review Comment:
   If the node is just called `/upgrade`, you could put the "prepared" state in 
the data, and we could use the same node during the upgrade later, to record a 
newer state like "ready" after the upgrade code runs.
   
   At the very least, I would avoid the word "prepped", because it is an 
informal way of saying "prepared" and we should use words that are easier to 
understand rather than their shorthand counterparts, for non-English native 
speakers. "prepared" is a better word choice here.



##########
server/base/src/main/java/org/apache/accumulo/server/util/UpgradePreparationUtil.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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
+ *
+ *   https://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.server.util;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.conf.SiteConfiguration;
+import org.apache.accumulo.core.data.InstanceId;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock.ServiceLockPath;
+import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
+import org.apache.accumulo.core.volume.VolumeConfiguration;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.security.SecurityUtil;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.zookeeper.KeeperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.google.auto.service.AutoService;
+
+@AutoService(KeywordExecutable.class)
+public class UpgradePreparationUtil implements KeywordExecutable {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(UpgradePreparationUtil.class);
+
+  static class Opts extends Help {
+    @Parameter(names = "--prepare-for-upgrade",
+        description = "prepare an older version instance for an upgrade to a 
newer non-bugfix release."
+            + " This command should be run using the older version of software 
after the instance is shut down.")
+    boolean postShutdownUpgradeCheck = false;
+
+    @Parameter(names = "--force", description = "allow --prepare-for-upgrade 
to run again")
+    boolean force = false;
+  }

Review Comment:
   It seems like `--prepare` should be idempotent, so there shouldn't be a need 
for this force option.



##########
server/base/src/main/java/org/apache/accumulo/server/util/UpgradePreparationUtil.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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
+ *
+ *   https://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.server.util;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.conf.SiteConfiguration;
+import org.apache.accumulo.core.data.InstanceId;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock.ServiceLockPath;
+import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
+import org.apache.accumulo.core.volume.VolumeConfiguration;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.security.SecurityUtil;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.zookeeper.KeeperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.google.auto.service.AutoService;
+
+@AutoService(KeywordExecutable.class)
+public class UpgradePreparationUtil implements KeywordExecutable {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(UpgradePreparationUtil.class);
+
+  static class Opts extends Help {
+    @Parameter(names = "--prepare-for-upgrade",
+        description = "prepare an older version instance for an upgrade to a 
newer non-bugfix release."
+            + " This command should be run using the older version of software 
after the instance is shut down.")
+    boolean postShutdownUpgradeCheck = false;
+
+    @Parameter(names = "--force", description = "allow --prepare-for-upgrade 
to run again")
+    boolean force = false;
+  }
+
+  @Override
+  public String keyword() {
+    return "upgrade";
+  }
+
+  @Override
+  public String description() {
+    return "utility used to prepare an instance for a minor or major version 
upgrade";
+  }
+
+  @Override
+  public void execute(String[] args) throws Exception {
+    Opts opts = new Opts();
+    opts.parseArgs(keyword(), args);
+
+    if (!opts.postShutdownUpgradeCheck) {

Review Comment:
   Could rename the variable to `prepare` also, so we don't have a different 
internal name and user-facing name for the same task.



##########
server/base/src/main/java/org/apache/accumulo/server/util/UpgradePreparationUtil.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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
+ *
+ *   https://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.server.util;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.cli.Help;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.conf.SiteConfiguration;
+import org.apache.accumulo.core.data.InstanceId;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
+import org.apache.accumulo.core.fate.zookeeper.ServiceLock.ServiceLockPath;
+import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
+import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
+import org.apache.accumulo.core.volume.VolumeConfiguration;
+import org.apache.accumulo.server.fs.VolumeManager;
+import org.apache.accumulo.server.security.SecurityUtil;
+import org.apache.accumulo.start.spi.KeywordExecutable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.Path;
+import org.apache.zookeeper.KeeperException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import com.google.auto.service.AutoService;
+
+@AutoService(KeywordExecutable.class)
+public class UpgradePreparationUtil implements KeywordExecutable {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(UpgradePreparationUtil.class);
+
+  static class Opts extends Help {
+    @Parameter(names = "--prepare-for-upgrade",
+        description = "prepare an older version instance for an upgrade to a 
newer non-bugfix release."
+            + " This command should be run using the older version of software 
after the instance is shut down.")
+    boolean postShutdownUpgradeCheck = false;
+
+    @Parameter(names = "--force", description = "allow --prepare-for-upgrade 
to run again")
+    boolean force = false;
+  }
+
+  @Override
+  public String keyword() {
+    return "upgrade";
+  }
+
+  @Override
+  public String description() {
+    return "utility used to prepare an instance for a minor or major version 
upgrade";
+  }
+
+  @Override
+  public void execute(String[] args) throws Exception {
+    Opts opts = new Opts();
+    opts.parseArgs(keyword(), args);
+
+    if (!opts.postShutdownUpgradeCheck) {
+      new JCommander(opts).usage();
+      return;
+    }
+
+    var siteConf = SiteConfiguration.auto();
+    // Login as the server on secure HDFS
+    if (siteConf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
+      SecurityUtil.serverLogin(siteConf);
+    }
+
+    String volDir = 
VolumeConfiguration.getVolumeUris(siteConf).iterator().next();
+    Path instanceDir = new Path(volDir, "instance_id");
+    InstanceId iid = VolumeManager.getInstanceIDFromHdfs(instanceDir, new 
Configuration());
+    ZooReaderWriter zoo = new ZooReaderWriter(siteConf);
+
+    if (opts.postShutdownUpgradeCheck) {
+      final String zUpgradepath = Constants.ZROOT + "/" + iid + 
Constants.ZPREPARE_FOR_UPGRADE;
+      try {
+        if (zoo.exists(zUpgradepath)) {
+          if (!opts.force) {
+            throw new IllegalStateException(
+                "'accumulo upgrade --prepare-for-upgrade' must have already 
been run."
+                    + " To run again use 'accumulo upgrade 
--prepare-for-upgrade --force'");
+          } else {
+            zoo.delete(zUpgradepath);
+          }
+        }
+      } catch (KeeperException | InterruptedException e) {
+        throw new IllegalStateException("Error creating or checking for " + 
zUpgradepath
+            + " node in zookeeper: " + e.getMessage(), e);
+      }
+
+      LOG.info("Upgrade specified, validating that Manager is stopped");
+      final ServiceLockPath mgrPath =
+          ServiceLock.path(Constants.ZROOT + "/" + iid + 
Constants.ZMANAGER_LOCK);
+      try {
+        if (ServiceLock.getLockData(zoo.getZooKeeper(), mgrPath) != null) {
+          throw new IllegalStateException(
+              "Manager is running, shut it down and retry this operation");
+        }
+      } catch (KeeperException | InterruptedException e) {
+        throw new IllegalStateException("Error trying to determine if Manager 
lock is held", e);
+      }
+
+      LOG.info("Checking for existing fate transactions");
+      try {
+        // Adapted from UpgradeCoordinator.abortIfFateTransactions
+        if (!zoo.getChildren(Constants.ZFATE).isEmpty()) {
+          throw new IllegalStateException("Cannot complete upgrade preparation"
+              + " because FATE transactions exist. You can start a tserver, 
but"
+              + " not the Manager, then use the shell to delete completed"
+              + " transactions and fail pending or in-progress transactions."
+              + " Once all of the FATE transactions have been removed you can"
+              + " retry this operation.");
+        }
+      } catch (KeeperException | InterruptedException e) {
+        throw new IllegalStateException("Error checking for existing FATE 
transactions", e);
+      }

Review Comment:
   Can we call out to FateAdmin for this check? Might be nice to delegate these 
responsibilities.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to