Skip to content

Commit bc8df24

Browse files
authored
Created UpgradeUtilIT, fixed issues in UpgradeUtil (apache#5454)
1 parent 89efffe commit bc8df24

File tree

2 files changed

+105
-3
lines changed

2 files changed

+105
-3
lines changed

server/base/src/main/java/org/apache/accumulo/server/util/UpgradeUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package org.apache.accumulo.server.util;
2020

2121
import org.apache.accumulo.core.Constants;
22-
import org.apache.accumulo.core.cli.Help;
22+
import org.apache.accumulo.core.cli.ConfigOpts;
2323
import org.apache.accumulo.core.conf.Property;
2424
import org.apache.accumulo.core.conf.SiteConfiguration;
2525
import org.apache.accumulo.core.data.InstanceId;
@@ -46,7 +46,7 @@ public class UpgradeUtil implements KeywordExecutable {
4646

4747
private static final Logger LOG = LoggerFactory.getLogger(UpgradeUtil.class);
4848

49-
static class Opts extends Help {
49+
static class Opts extends ConfigOpts {
5050
@Parameter(names = "--prepare",
5151
description = "prepare an older version instance for an upgrade to a newer non-bugfix release."
5252
+ " This command should be run using the older version of software after the instance is shut down.")
@@ -110,7 +110,7 @@ public void execute(String[] args) throws Exception {
110110
LOG.info("Checking for existing fate transactions");
111111
try {
112112
// Adapted from UpgradeCoordinator.abortIfFateTransactions
113-
if (!zoo.getChildren(Constants.ZFATE).isEmpty()) {
113+
if (!zoo.getChildren(Constants.ZROOT + "/" + iid + Constants.ZFATE).isEmpty()) {
114114
throw new IllegalStateException("Cannot complete upgrade preparation"
115115
+ " because FATE transactions exist. You can start a tserver, but"
116116
+ " not the Manager, then use the shell to delete completed"
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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.test.upgrade;
20+
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertFalse;
23+
import static org.junit.jupiter.api.Assertions.assertThrows;
24+
import static org.junit.jupiter.api.Assertions.assertTrue;
25+
26+
import java.util.UUID;
27+
28+
import org.apache.accumulo.core.Constants;
29+
import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeExistsPolicy;
30+
import org.apache.accumulo.harness.AccumuloClusterHarness;
31+
import org.apache.accumulo.minicluster.ServerType;
32+
import org.apache.accumulo.server.ServerContext;
33+
import org.apache.accumulo.server.util.UpgradeUtil;
34+
import org.apache.accumulo.test.util.Wait;
35+
import org.junit.jupiter.api.Test;
36+
37+
public class UpgradeUtilIT extends AccumuloClusterHarness {
38+
39+
@Test
40+
public void testPrepareFailsDueToManagerUp() throws Exception {
41+
ServerContext ctx = getCluster().getServerContext();
42+
43+
ctx.getZooReaderWriter().putPersistentData(
44+
ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE, new byte[0],
45+
NodeExistsPolicy.SKIP);
46+
assertTrue(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE));
47+
48+
System.setProperty("accumulo.properties", "file://" + getCluster().getAccumuloPropertiesPath());
49+
IllegalStateException ise = assertThrows(IllegalStateException.class,
50+
() -> new UpgradeUtil().execute(new String[] {"--prepare"}));
51+
assertEquals("Manager is running, shut it down and retry this operation", ise.getMessage());
52+
assertFalse(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE));
53+
54+
}
55+
56+
@Test
57+
public void testPrepareFailsDueToFateTransactions() throws Exception {
58+
ServerContext ctx = getCluster().getServerContext();
59+
60+
ctx.getZooReaderWriter().putPersistentData(
61+
ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE, new byte[0],
62+
NodeExistsPolicy.SKIP);
63+
assertTrue(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE));
64+
65+
assertTrue(ctx.getZooReader().getChildren(ctx.getZooKeeperRoot() + Constants.ZFATE).isEmpty());
66+
ctx.getZooReaderWriter().putEphemeralData(
67+
ctx.getZooKeeperRoot() + Constants.ZFATE + "/" + UUID.randomUUID(), new byte[0]);
68+
assertFalse(ctx.getZooReader().getChildren(ctx.getZooKeeperRoot() + Constants.ZFATE).isEmpty());
69+
70+
getCluster().getClusterControl().stopAllServers(ServerType.MANAGER);
71+
Wait.waitFor(() -> ctx.getZooReader()
72+
.getChildren(ctx.getZooKeeperRoot() + Constants.ZMANAGER_LOCK).isEmpty());
73+
74+
System.setProperty("accumulo.properties", "file://" + getCluster().getAccumuloPropertiesPath());
75+
IllegalStateException ise = assertThrows(IllegalStateException.class,
76+
() -> new UpgradeUtil().execute(new String[] {"--prepare"}));
77+
assertTrue(ise.getMessage()
78+
.startsWith("Cannot complete upgrade preparation because FATE transactions exist."));
79+
assertFalse(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE));
80+
81+
}
82+
83+
@Test
84+
public void testPrepareSucceeds() throws Exception {
85+
ServerContext ctx = getCluster().getServerContext();
86+
87+
ctx.getZooReaderWriter().putPersistentData(
88+
ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE, new byte[0],
89+
NodeExistsPolicy.SKIP);
90+
assertTrue(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE));
91+
92+
getCluster().getClusterControl().stopAllServers(ServerType.MANAGER);
93+
Wait.waitFor(() -> ctx.getZooReader()
94+
.getChildren(ctx.getZooKeeperRoot() + Constants.ZMANAGER_LOCK).isEmpty());
95+
96+
System.setProperty("accumulo.properties", "file://" + getCluster().getAccumuloPropertiesPath());
97+
new UpgradeUtil().execute(new String[] {"--prepare"});
98+
assertTrue(ctx.getZooReader().exists(ctx.getZooKeeperRoot() + Constants.ZPREPARE_FOR_UPGRADE));
99+
100+
}
101+
102+
}

0 commit comments

Comments
 (0)