This is an automated email from the ASF dual-hosted git repository.
dlmarion 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 89efffe440 Added 'accumulo upgrade --prepare' command to prepare for
upgrade (#5438)
89efffe440 is described below
commit 89efffe44065ce6c647e6d514632441e8f796a9b
Author: Dave Marion <[email protected]>
AuthorDate: Fri Apr 4 15:42:45 2025 -0400
Added 'accumulo upgrade --prepare' command to prepare for upgrade (#5438)
Added `accumulo upgrade --prepare` command which is intended to be used
after an instance is shutdown in preparation for an upgrade to the next
minor or major release. This is not intended to be used for bugfix
releases. `accumulo upgrade --prepare` will validate that no Fate
transactions
exist, create a marker node in ZooKeeper that this utility has been run,
then
proceed to remove all locks in ZooKeeper for the Accumulo servers.
Accumulo server processes will not start with the upgrade marker node
present in
ZooKeeper, so if this utility is run by mistake on a bugfix upgrade, then
the
user will need to remove it manually. If the user decides to abort the
upgrade
process after running this utility, then they will need to remove the marker
node from ZooKeeper manually as well.
---
.../java/org/apache/accumulo/core/Constants.java | 2 +
.../org/apache/accumulo/server/AbstractServer.java | 14 ++
.../apache/accumulo/server/util/UpgradeUtil.java | 146 +++++++++++++++++++++
.../apache/accumulo/test/start/KeywordStartIT.java | 2 +
4 files changed, 164 insertions(+)
diff --git a/core/src/main/java/org/apache/accumulo/core/Constants.java
b/core/src/main/java/org/apache/accumulo/core/Constants.java
index 1caf157e90..2a36272bea 100644
--- a/core/src/main/java/org/apache/accumulo/core/Constants.java
+++ b/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_ready";
+
/**
* Base znode for storing secret keys that back delegation tokens
*/
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java
b/server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java
index 1ab7c186c3..20f7db5b12 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java
@@ -38,6 +38,7 @@ import org.apache.accumulo.core.util.Halt;
import org.apache.accumulo.core.util.threads.Threads;
import org.apache.accumulo.server.metrics.ProcessMetrics;
import org.apache.accumulo.server.security.SecurityUtil;
+import org.apache.zookeeper.KeeperException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -68,6 +69,19 @@ public abstract class AbstractServer
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 to a minor or major
version greater than "
+ + Constants.VERSION + ", no servers can be started."
+ + " To undo this state and abort upgrade preparations delete
the zookeeper node: "
+ + upgradePrepNode);
+ }
+ } catch (KeeperException | InterruptedException e) {
+ throw new IllegalStateException(
+ "Error checking for upgrade preparation node (" + upgradePrepNode +
") in zookeeper", e);
+ }
log.info("Version " + Constants.VERSION);
log.info("Instance " + context.getInstanceID());
context.init(appName);
diff --git
a/server/base/src/main/java/org/apache/accumulo/server/util/UpgradeUtil.java
b/server/base/src/main/java/org/apache/accumulo/server/util/UpgradeUtil.java
new file mode 100644
index 0000000000..5c880da99d
--- /dev/null
+++ b/server/base/src/main/java/org/apache/accumulo/server/util/UpgradeUtil.java
@@ -0,0 +1,146 @@
+/*
+ * 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 UpgradeUtil implements KeywordExecutable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(UpgradeUtil.class);
+
+ static class Opts extends Help {
+ @Parameter(names = "--prepare",
+ 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 prepare = false;
+ }
+
+ @Override
+ public String keyword() {
+ return "upgrade";
+ }
+
+ @Override
+ public String description() {
+ return "utility used to perform various upgrade steps for an Accumulo
instance";
+ }
+
+ @Override
+ public void execute(String[] args) throws Exception {
+ Opts opts = new Opts();
+ opts.parseArgs(keyword(), args);
+
+ if (!opts.prepare) {
+ 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.prepare) {
+ final String zUpgradepath = Constants.ZROOT + "/" + iid +
Constants.ZPREPARE_FOR_UPGRADE;
+ try {
+ if (zoo.exists(zUpgradepath)) {
+ 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);
+ }
+
+ LOG.info("Creating {} node in zookeeper, servers will be prevented from"
+ + " starting while this node exists", zUpgradepath);
+ try {
+ zoo.putPersistentData(zUpgradepath, new byte[0],
NodeExistsPolicy.SKIP);
+ } catch (KeeperException | InterruptedException e) {
+ throw new IllegalStateException("Error creating " + zUpgradepath
+ + " node in zookeeper. Check for any issues and retry.", e);
+ }
+
+ LOG.info("Forcing removal of all server locks");
+ new ZooZap().zap(siteConf, "-manager", "-compaction-coordinators",
"-tservers", "-compactors",
+ "-sservers");
+
+ LOG.info("Instance {} prepared for upgrade. Server processes will not
start while"
+ + " in this state. To undo this state and abort upgrade preparations
delete"
+ + " the zookeeper node: {}. If you abort and restart the instance,
then you "
+ + " should re-run this utility before upgrading.", iid.canonical(),
zUpgradepath);
+ }
+
+ }
+
+}
diff --git
a/test/src/main/java/org/apache/accumulo/test/start/KeywordStartIT.java
b/test/src/main/java/org/apache/accumulo/test/start/KeywordStartIT.java
index 5579510723..2eb578be53 100644
--- a/test/src/main/java/org/apache/accumulo/test/start/KeywordStartIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/start/KeywordStartIT.java
@@ -66,6 +66,7 @@ import org.apache.accumulo.server.util.DumpZookeeper;
import org.apache.accumulo.server.util.ECAdmin;
import org.apache.accumulo.server.util.Info;
import org.apache.accumulo.server.util.LoginProperties;
+import org.apache.accumulo.server.util.UpgradeUtil;
import org.apache.accumulo.server.util.ZooKeeperMain;
import org.apache.accumulo.server.util.ZooZap;
import org.apache.accumulo.shell.Shell;
@@ -155,6 +156,7 @@ public class KeywordStartIT {
expectSet.put("split-large", SplitLarge.class);
expectSet.put("sserver", ScanServerExecutable.class);
expectSet.put("tserver", TServerExecutable.class);
+ expectSet.put("upgrade", UpgradeUtil.class);
expectSet.put("version", Version.class);
expectSet.put("wal-info", LogReader.class);
expectSet.put("zoo-info-viewer", ZooInfoViewer.class);