Skip to content

Commit 89efffe

Browse files
authored
Added 'accumulo upgrade --prepare' command to prepare for upgrade (apache#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.
1 parent db03e34 commit 89efffe

File tree

4 files changed

+164
-0
lines changed

4 files changed

+164
-0
lines changed

core/src/main/java/org/apache/accumulo/core/Constants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public class Constants {
9494
public static final String ZHDFS_RESERVATIONS = "/hdfs_reservations";
9595
public static final String ZRECOVERY = "/recovery";
9696

97+
public static final String ZPREPARE_FOR_UPGRADE = "/upgrade_ready";
98+
9799
/**
98100
* Base znode for storing secret keys that back delegation tokens
99101
*/

server/base/src/main/java/org/apache/accumulo/server/AbstractServer.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.accumulo.core.util.threads.Threads;
3939
import org.apache.accumulo.server.metrics.ProcessMetrics;
4040
import org.apache.accumulo.server.security.SecurityUtil;
41+
import org.apache.zookeeper.KeeperException;
4142
import org.slf4j.Logger;
4243
import org.slf4j.LoggerFactory;
4344

@@ -68,6 +69,19 @@ protected AbstractServer(String appName, ServerOpts opts, String[] args) {
6869
var siteConfig = opts.getSiteConfiguration();
6970
SecurityUtil.serverLogin(siteConfig);
7071
context = new ServerContext(siteConfig);
72+
final String upgradePrepNode = context.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE;
73+
try {
74+
if (context.getZooReader().exists(upgradePrepNode)) {
75+
throw new IllegalStateException(
76+
"Instance has been prepared for upgrade to a minor or major version greater than "
77+
+ Constants.VERSION + ", no servers can be started."
78+
+ " To undo this state and abort upgrade preparations delete the zookeeper node: "
79+
+ upgradePrepNode);
80+
}
81+
} catch (KeeperException | InterruptedException e) {
82+
throw new IllegalStateException(
83+
"Error checking for upgrade preparation node (" + upgradePrepNode + ") in zookeeper", e);
84+
}
7185
log.info("Version " + Constants.VERSION);
7286
log.info("Instance " + context.getInstanceID());
7387
context.init(appName);
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.accumulo.server.util;
20+
21+
import org.apache.accumulo.core.Constants;
22+
import org.apache.accumulo.core.cli.Help;
23+
import org.apache.accumulo.core.conf.Property;
24+
import org.apache.accumulo.core.conf.SiteConfiguration;
25+
import org.apache.accumulo.core.data.InstanceId;
26+
import org.apache.accumulo.core.fate.zookeeper.ServiceLock;
27+
import org.apache.accumulo.core.fate.zookeeper.ServiceLock.ServiceLockPath;
28+
import org.apache.accumulo.core.fate.zookeeper.ZooReaderWriter;
29+
import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
30+
import org.apache.accumulo.core.volume.VolumeConfiguration;
31+
import org.apache.accumulo.server.fs.VolumeManager;
32+
import org.apache.accumulo.server.security.SecurityUtil;
33+
import org.apache.accumulo.start.spi.KeywordExecutable;
34+
import org.apache.hadoop.conf.Configuration;
35+
import org.apache.hadoop.fs.Path;
36+
import org.apache.zookeeper.KeeperException;
37+
import org.slf4j.Logger;
38+
import org.slf4j.LoggerFactory;
39+
40+
import com.beust.jcommander.JCommander;
41+
import com.beust.jcommander.Parameter;
42+
import com.google.auto.service.AutoService;
43+
44+
@AutoService(KeywordExecutable.class)
45+
public class UpgradeUtil implements KeywordExecutable {
46+
47+
private static final Logger LOG = LoggerFactory.getLogger(UpgradeUtil.class);
48+
49+
static class Opts extends Help {
50+
@Parameter(names = "--prepare",
51+
description = "prepare an older version instance for an upgrade to a newer non-bugfix release."
52+
+ " This command should be run using the older version of software after the instance is shut down.")
53+
boolean prepare = false;
54+
}
55+
56+
@Override
57+
public String keyword() {
58+
return "upgrade";
59+
}
60+
61+
@Override
62+
public String description() {
63+
return "utility used to perform various upgrade steps for an Accumulo instance";
64+
}
65+
66+
@Override
67+
public void execute(String[] args) throws Exception {
68+
Opts opts = new Opts();
69+
opts.parseArgs(keyword(), args);
70+
71+
if (!opts.prepare) {
72+
new JCommander(opts).usage();
73+
return;
74+
}
75+
76+
var siteConf = SiteConfiguration.auto();
77+
// Login as the server on secure HDFS
78+
if (siteConf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
79+
SecurityUtil.serverLogin(siteConf);
80+
}
81+
82+
String volDir = VolumeConfiguration.getVolumeUris(siteConf).iterator().next();
83+
Path instanceDir = new Path(volDir, "instance_id");
84+
InstanceId iid = VolumeManager.getInstanceIDFromHdfs(instanceDir, new Configuration());
85+
ZooReaderWriter zoo = new ZooReaderWriter(siteConf);
86+
87+
if (opts.prepare) {
88+
final String zUpgradepath = Constants.ZROOT + "/" + iid + Constants.ZPREPARE_FOR_UPGRADE;
89+
try {
90+
if (zoo.exists(zUpgradepath)) {
91+
zoo.delete(zUpgradepath);
92+
}
93+
} catch (KeeperException | InterruptedException e) {
94+
throw new IllegalStateException("Error creating or checking for " + zUpgradepath
95+
+ " node in zookeeper: " + e.getMessage(), e);
96+
}
97+
98+
LOG.info("Upgrade specified, validating that Manager is stopped");
99+
final ServiceLockPath mgrPath =
100+
ServiceLock.path(Constants.ZROOT + "/" + iid + Constants.ZMANAGER_LOCK);
101+
try {
102+
if (ServiceLock.getLockData(zoo.getZooKeeper(), mgrPath) != null) {
103+
throw new IllegalStateException(
104+
"Manager is running, shut it down and retry this operation");
105+
}
106+
} catch (KeeperException | InterruptedException e) {
107+
throw new IllegalStateException("Error trying to determine if Manager lock is held", e);
108+
}
109+
110+
LOG.info("Checking for existing fate transactions");
111+
try {
112+
// Adapted from UpgradeCoordinator.abortIfFateTransactions
113+
if (!zoo.getChildren(Constants.ZFATE).isEmpty()) {
114+
throw new IllegalStateException("Cannot complete upgrade preparation"
115+
+ " because FATE transactions exist. You can start a tserver, but"
116+
+ " not the Manager, then use the shell to delete completed"
117+
+ " transactions and fail pending or in-progress transactions."
118+
+ " Once all of the FATE transactions have been removed you can"
119+
+ " retry this operation.");
120+
}
121+
} catch (KeeperException | InterruptedException e) {
122+
throw new IllegalStateException("Error checking for existing FATE transactions", e);
123+
}
124+
125+
LOG.info("Creating {} node in zookeeper, servers will be prevented from"
126+
+ " starting while this node exists", zUpgradepath);
127+
try {
128+
zoo.putPersistentData(zUpgradepath, new byte[0], NodeExistsPolicy.SKIP);
129+
} catch (KeeperException | InterruptedException e) {
130+
throw new IllegalStateException("Error creating " + zUpgradepath
131+
+ " node in zookeeper. Check for any issues and retry.", e);
132+
}
133+
134+
LOG.info("Forcing removal of all server locks");
135+
new ZooZap().zap(siteConf, "-manager", "-compaction-coordinators", "-tservers", "-compactors",
136+
"-sservers");
137+
138+
LOG.info("Instance {} prepared for upgrade. Server processes will not start while"
139+
+ " in this state. To undo this state and abort upgrade preparations delete"
140+
+ " the zookeeper node: {}. If you abort and restart the instance, then you "
141+
+ " should re-run this utility before upgrading.", iid.canonical(), zUpgradepath);
142+
}
143+
144+
}
145+
146+
}

test/src/main/java/org/apache/accumulo/test/start/KeywordStartIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import org.apache.accumulo.server.util.ECAdmin;
6767
import org.apache.accumulo.server.util.Info;
6868
import org.apache.accumulo.server.util.LoginProperties;
69+
import org.apache.accumulo.server.util.UpgradeUtil;
6970
import org.apache.accumulo.server.util.ZooKeeperMain;
7071
import org.apache.accumulo.server.util.ZooZap;
7172
import org.apache.accumulo.shell.Shell;
@@ -155,6 +156,7 @@ public void testExpectedClasses() {
155156
expectSet.put("split-large", SplitLarge.class);
156157
expectSet.put("sserver", ScanServerExecutable.class);
157158
expectSet.put("tserver", TServerExecutable.class);
159+
expectSet.put("upgrade", UpgradeUtil.class);
158160
expectSet.put("version", Version.class);
159161
expectSet.put("wal-info", LogReader.class);
160162
expectSet.put("zoo-info-viewer", ZooInfoViewer.class);

0 commit comments

Comments
 (0)