Skip to content

Commit 6e87f6b

Browse files
committed
Fix chroot in upgrade tracker code
1 parent 5ae8afc commit 6e87f6b

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

server/manager/src/main/java/org/apache/accumulo/manager/upgrade/UpgradeProgressTracker.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,21 @@ public UpgradeProgressTracker(ServerContext context) {
4747
this.context = requireNonNull(context, "ServerContext must be supplied");
4848
}
4949

50-
private String getZPath() {
51-
return context.getZooKeeperRoot() + Constants.ZUPGRADE_PROGRESS;
52-
}
53-
5450
public synchronized void startOrContinueUpgrade() {
5551
var zk = context.getZooSession();
5652
try {
5753
try {
5854
// normally, no upgrade is in progress
5955
var newProgress = new UpgradeProgress(AccumuloDataVersion.getCurrentVersion(context),
6056
AccumuloDataVersion.get());
61-
zk.create(getZPath(), newProgress.toJsonBytes(), ZooUtil.PUBLIC, CreateMode.PERSISTENT);
57+
zk.create(Constants.ZUPGRADE_PROGRESS, newProgress.toJsonBytes(), ZooUtil.PUBLIC,
58+
CreateMode.PERSISTENT);
6259
progress = newProgress;
6360
znodeVersion = 0;
6461
} catch (KeeperException.NodeExistsException e) {
6562
// existing upgrade must already be in progress
6663
var stat = new Stat();
67-
var oldProgressBytes = zk.getData(getZPath(), null, stat);
64+
var oldProgressBytes = zk.getData(Constants.ZUPGRADE_PROGRESS, null, stat);
6865
var oldProgress = UpgradeProgress.fromJsonBytes(oldProgressBytes);
6966
checkState(AccumuloDataVersion.get() == oldProgress.getUpgradeTargetVersion(),
7067
"Upgrade was already started with a different version of software (%s), expecting %s",
@@ -133,7 +130,7 @@ public synchronized void updateMetadataVersion(int newVersion) {
133130

134131
private synchronized void storeProgress() {
135132
try {
136-
final String zpath = getZPath();
133+
final String zpath = Constants.ZUPGRADE_PROGRESS;
137134
final ZooSession zs = context.getZooSession();
138135
try {
139136
var stat = zs.setData(zpath, progress.toJsonBytes(), znodeVersion);
@@ -162,7 +159,7 @@ public synchronized void upgradeComplete() {
162159
AccumuloDataVersion.getCurrentVersion(context), AccumuloDataVersion.get());
163160
final ZooReaderWriter zrw = context.getZooSession().asReaderWriter();
164161
try {
165-
zrw.recursiveDelete(getZPath(), NodeMissingPolicy.SKIP);
162+
zrw.recursiveDelete(Constants.ZUPGRADE_PROGRESS, NodeMissingPolicy.SKIP);
166163
} catch (KeeperException e) {
167164
throw new IllegalStateException("Error clearing the upgrade progress", e);
168165
} catch (InterruptedException e) {

test/src/main/java/org/apache/accumulo/test/upgrade/UpgradeProgressTrackerIT.java

+11-18
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@
3434
import static org.junit.jupiter.api.Assertions.assertTrue;
3535

3636
import java.io.File;
37-
import java.util.UUID;
3837

3938
import org.apache.accumulo.core.Constants;
40-
import org.apache.accumulo.core.data.InstanceId;
4139
import org.apache.accumulo.core.fate.zookeeper.ZooUtil;
4240
import org.apache.accumulo.core.fate.zookeeper.ZooUtil.NodeMissingPolicy;
4341
import org.apache.accumulo.core.volume.Volume;
@@ -69,8 +67,6 @@ public class UpgradeProgressTrackerIT {
6967
@TempDir
7068
private static File tempDir;
7169

72-
private static final String zRoot = ZooUtil.getRoot(InstanceId.of(UUID.randomUUID()));
73-
7470
private static ZooKeeperTestingServer testZk = null;
7571
private static ZooSession zk = null;
7672
private static Volume volume;
@@ -81,7 +77,6 @@ public class UpgradeProgressTrackerIT {
8177
public static void setup() throws Exception {
8278
testZk = new ZooKeeperTestingServer(tempDir);
8379
zk = testZk.newClient();
84-
zk.asReaderWriter().mkdirs(zRoot);
8580
volume = new VolumeImpl(new Path(tempDir.toURI()), new Configuration());
8681
}
8782

@@ -103,7 +98,6 @@ public void beforeTest() {
10398
ctx = createMock(ServerContext.class);
10499
sd = createMock(ServerDirs.class);
105100
vm = createMock(VolumeManagerImpl.class);
106-
expect(ctx.getZooKeeperRoot()).andReturn(zRoot).anyTimes();
107101
expect(ctx.getZooSession()).andReturn(zk).anyTimes();
108102
expect(ctx.getServerDirs()).andReturn(sd).anyTimes();
109103
expect(ctx.getVolumeManager()).andReturn(vm).anyTimes();
@@ -116,8 +110,7 @@ public void beforeTest() {
116110
@AfterEach
117111
public void afterTest() throws KeeperException, InterruptedException {
118112
verify(ctx, sd, vm);
119-
zk.asReaderWriter().recursiveDelete(zRoot + Constants.ZUPGRADE_PROGRESS,
120-
NodeMissingPolicy.SKIP);
113+
zk.asReaderWriter().recursiveDelete(Constants.ZUPGRADE_PROGRESS, NodeMissingPolicy.SKIP);
121114
}
122115

123116
private void expectVersion(int version) {
@@ -127,7 +120,7 @@ private void expectVersion(int version) {
127120
}
128121

129122
private boolean upgradeNodeExists() throws KeeperException, InterruptedException {
130-
return zk.exists(zRoot + Constants.ZUPGRADE_PROGRESS, null) != null;
123+
return zk.exists(Constants.ZUPGRADE_PROGRESS, null) != null;
131124
}
132125

133126
@Test
@@ -136,7 +129,7 @@ public void testUpgradeAlreadyStarted() throws KeeperException, InterruptedExcep
136129
assertFalse(upgradeNodeExists());
137130
var progress =
138131
new UpgradeProgress(AccumuloDataVersion.get() - 2, AccumuloDataVersion.get() - 1);
139-
zk.create(zRoot + Constants.ZUPGRADE_PROGRESS, GSON.get().toJson(progress).getBytes(UTF_8),
132+
zk.create(Constants.ZUPGRADE_PROGRESS, GSON.get().toJson(progress).getBytes(UTF_8),
140133
ZooUtil.PUBLIC, CreateMode.PERSISTENT);
141134
assertTrue(upgradeNodeExists());
142135
var ise =
@@ -161,7 +154,7 @@ public void testGetInitial() throws KeeperException, InterruptedException {
161154
assertEquals(AccumuloDataVersion.get(), progress.getZooKeeperVersion());
162155
assertEquals(AccumuloDataVersion.get(), progress.getRootVersion());
163156
assertEquals(AccumuloDataVersion.get(), progress.getMetadataVersion());
164-
byte[] serialized = zk.asReader().getData(zRoot + Constants.ZUPGRADE_PROGRESS);
157+
byte[] serialized = zk.asReader().getData(Constants.ZUPGRADE_PROGRESS);
165158
assertArrayEquals(GSON.get().toJson(progress).getBytes(UTF_8), serialized);
166159
}
167160

@@ -176,15 +169,15 @@ public void testUpdates() throws KeeperException, InterruptedException {
176169
assertEquals(AccumuloDataVersion.get() - 1, progress.getZooKeeperVersion());
177170
assertEquals(AccumuloDataVersion.get() - 1, progress.getRootVersion());
178171
assertEquals(AccumuloDataVersion.get() - 1, progress.getMetadataVersion());
179-
byte[] serialized = zk.asReader().getData(zRoot + Constants.ZUPGRADE_PROGRESS);
172+
byte[] serialized = zk.asReader().getData(Constants.ZUPGRADE_PROGRESS);
180173
assertArrayEquals(GSON.get().toJson(progress).getBytes(UTF_8), serialized);
181174

182175
// Test updating out of order
183176
assertThrows(IllegalArgumentException.class,
184177
() -> progressTracker.updateMetadataVersion(AccumuloDataVersion.get()));
185178
assertThrows(IllegalArgumentException.class,
186179
() -> progressTracker.updateRootVersion(AccumuloDataVersion.get()));
187-
serialized = zk.asReader().getData(zRoot + Constants.ZUPGRADE_PROGRESS);
180+
serialized = zk.asReader().getData(Constants.ZUPGRADE_PROGRESS);
188181
assertArrayEquals(GSON.get().toJson(progress).getBytes(UTF_8), serialized);
189182

190183
progressTracker.updateZooKeeperVersion(AccumuloDataVersion.get());
@@ -195,7 +188,7 @@ public void testUpdates() throws KeeperException, InterruptedException {
195188
assertEquals(AccumuloDataVersion.get(), progress2.getZooKeeperVersion());
196189
assertEquals(AccumuloDataVersion.get() - 1, progress2.getRootVersion());
197190
assertEquals(AccumuloDataVersion.get() - 1, progress2.getMetadataVersion());
198-
serialized = zk.asReader().getData(zRoot + Constants.ZUPGRADE_PROGRESS);
191+
serialized = zk.asReader().getData(Constants.ZUPGRADE_PROGRESS);
199192
assertArrayEquals(GSON.get().toJson(progress2).getBytes(UTF_8), serialized);
200193

201194
progressTracker.updateRootVersion(AccumuloDataVersion.get());
@@ -206,7 +199,7 @@ public void testUpdates() throws KeeperException, InterruptedException {
206199
assertEquals(AccumuloDataVersion.get(), progress2.getZooKeeperVersion());
207200
assertEquals(AccumuloDataVersion.get(), progress2.getRootVersion());
208201
assertEquals(AccumuloDataVersion.get() - 1, progress2.getMetadataVersion());
209-
serialized = zk.asReader().getData(zRoot + Constants.ZUPGRADE_PROGRESS);
202+
serialized = zk.asReader().getData(Constants.ZUPGRADE_PROGRESS);
210203
assertArrayEquals(GSON.get().toJson(progress2).getBytes(UTF_8), serialized);
211204

212205
progressTracker.updateMetadataVersion(AccumuloDataVersion.get());
@@ -217,7 +210,7 @@ public void testUpdates() throws KeeperException, InterruptedException {
217210
assertEquals(AccumuloDataVersion.get(), progress2.getZooKeeperVersion());
218211
assertEquals(AccumuloDataVersion.get(), progress2.getRootVersion());
219212
assertEquals(AccumuloDataVersion.get(), progress2.getMetadataVersion());
220-
serialized = zk.asReader().getData(zRoot + Constants.ZUPGRADE_PROGRESS);
213+
serialized = zk.asReader().getData(Constants.ZUPGRADE_PROGRESS);
221214
assertArrayEquals(GSON.get().toJson(progress2).getBytes(UTF_8), serialized);
222215
}
223216

@@ -232,11 +225,11 @@ public void testCompleteUpgrade() throws KeeperException, InterruptedException {
232225
assertEquals(AccumuloDataVersion.get(), progress.getZooKeeperVersion());
233226
assertEquals(AccumuloDataVersion.get(), progress.getRootVersion());
234227
assertEquals(AccumuloDataVersion.get(), progress.getMetadataVersion());
235-
byte[] serialized = zk.asReader().getData(zRoot + Constants.ZUPGRADE_PROGRESS);
228+
byte[] serialized = zk.asReader().getData(Constants.ZUPGRADE_PROGRESS);
236229
assertArrayEquals(GSON.get().toJson(progress).getBytes(UTF_8), serialized);
237230

238231
progressTracker.upgradeComplete();
239-
assertFalse(zk.asReader().exists(zRoot + Constants.ZUPGRADE_PROGRESS));
232+
assertFalse(zk.asReader().exists(Constants.ZUPGRADE_PROGRESS));
240233
assertFalse(upgradeNodeExists());
241234
}
242235

0 commit comments

Comments
 (0)