Skip to content

Commit 70cbe94

Browse files
authored
HDDS-15063. Switch OM to the new Versioning Framework (#10099)
1 parent cbc79b5 commit 70cbe94

50 files changed

Lines changed: 241 additions & 1046 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

hadoop-hdds/common/src/main/java/org/apache/hadoop/ozone/OzoneConsts.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,9 @@ public final class OzoneConsts {
434434
public static final String SCM_ROOT_CA = "scm";
435435
public static final String SCM_ROOT_CA_PREFIX = SCM_ROOT_CA + "@";
436436

437-
// Layout Version written into Meta Table ONLY during finalization.
438-
public static final String LAYOUT_VERSION_KEY = "#LAYOUTVERSION";
439-
// Key written to Meta Table to indicate a component undergoing finalization.
440-
// Currently this is only used on SCM, but may be useful on OM if/when
441-
// finalizing one layout feature per Ratis request is implemented in
442-
// HDDS-4286.
443-
public static final String FINALIZING_KEY = "#FINALIZING";
437+
// Apparent Version written into Meta Table ONLY during finalization.
438+
// The name "layout version" is kept for backwards compatibility.
439+
public static final String APPARENT_VERSION_KEY = "#LAYOUTVERSION";
444440

445441
// Kerberos constants
446442
public static final String KERBEROS_CONFIG_VALUE = "kerberos";

hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/upgrade/HDDSVersionManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ private static ComponentVersion computeApparentVersion(int serializedApparentVer
5959

6060
@Override
6161
protected void runUpgradeAction(ComponentVersion componentVersion) throws UpgradeException {
62-
// TODO HDDS-14826: Register upgrade actions based on annotations
62+
// TODO HDDS-15129: Register upgrade actions based on annotations
6363
}
6464
}

hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/AbstractLayoutVersionManager.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*/
3939
@SuppressWarnings("visibilitymodifier")
4040
public abstract class AbstractLayoutVersionManager<T extends LayoutFeature>
41-
implements LayoutVersionManager, LayoutVersionManagerMXBean {
41+
implements LayoutVersionManagerMXBean {
4242

4343
private static final Logger LOG =
4444
LoggerFactory.getLogger(AbstractLayoutVersionManager.class);
@@ -164,7 +164,6 @@ public int getSoftwareLayoutVersion() {
164164
return softwareLayoutVersion;
165165
}
166166

167-
@Override
168167
public boolean needsFinalization() {
169168
lock.readLock().lock();
170169
try {
@@ -174,7 +173,6 @@ public boolean needsFinalization() {
174173
}
175174
}
176175

177-
@Override
178176
public boolean isAllowed(LayoutFeature layoutFeature) {
179177
lock.readLock().lock();
180178
try {
@@ -184,12 +182,10 @@ public boolean isAllowed(LayoutFeature layoutFeature) {
184182
}
185183
}
186184

187-
@Override
188185
public LayoutFeature getFeature(int layoutVersion) {
189186
return features.get(layoutVersion);
190187
}
191188

192-
@Override
193189
public Iterable<LayoutFeature> unfinalizedFeatures() {
194190
lock.readLock().lock();
195191
try {
@@ -201,7 +197,6 @@ public Iterable<LayoutFeature> unfinalizedFeatures() {
201197
}
202198
}
203199

204-
@Override
205200
public void close() {
206201
if (mBean != null) {
207202
MBeans.unregister(mBean);

hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutVersionManager.java

Lines changed: 0 additions & 69 deletions
This file was deleted.

hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationStateManagerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private void finalizeLayoutFeatureLocal(HDDSLayoutFeature layoutFeature)
8484
upgradeFinalizer.replicatedFinalizationSteps(layoutFeature, upgradeContext);
8585
}
8686
transactionBuffer.addToBuffer(finalizationStore,
87-
OzoneConsts.LAYOUT_VERSION_KEY, String.valueOf(layoutFeature.layoutVersion()));
87+
OzoneConsts.APPARENT_VERSION_KEY, String.valueOf(layoutFeature.layoutVersion()));
8888
}
8989

9090
/**
@@ -132,7 +132,7 @@ public synchronized void reinitialize(Table<String, String> newFinalizationStore
132132
*/
133133
private int getDBLayoutVersion() throws IOException {
134134
String dbLayoutVersion = finalizationStore.get(
135-
OzoneConsts.LAYOUT_VERSION_KEY);
135+
OzoneConsts.APPARENT_VERSION_KEY);
136136
if (dbLayoutVersion == null) {
137137
return versionManager.getMetadataLayoutVersion();
138138
} else {

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestHSyncUpgrade.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void init() throws Exception {
117117
conf.setTimeDuration(OZONE_OM_LEASE_HARD_LIMIT,
118118
EXPIRE_THRESHOLD_MS, TimeUnit.MILLISECONDS);
119119
conf.set(OzoneConfigKeys.OZONE_OM_LEASE_SOFT_LIMIT, "0s");
120-
conf.setInt(OMStorage.TESTING_INIT_LAYOUT_VERSION_KEY, OMLayoutFeature.MULTITENANCY_SCHEMA.layoutVersion());
120+
conf.setInt(OMStorage.TESTING_INIT_APPARENT_VERSION_KEY, OMLayoutFeature.MULTITENANCY_SCHEMA.layoutVersion());
121121

122122
ClientConfigForTesting.newBuilder(StorageUnit.BYTES)
123123
.setBlockSize(BLOCK_SIZE)

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMBucketLayoutUpgrade.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717

1818
package org.apache.hadoop.ozone.om;
1919

20-
import static org.apache.hadoop.ozone.OzoneConsts.LAYOUT_VERSION_KEY;
20+
import static org.apache.hadoop.ozone.OzoneConsts.APPARENT_VERSION_KEY;
2121
import static org.apache.hadoop.ozone.om.OMUpgradeTestUtils.waitForFinalization;
2222
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.NOT_SUPPORTED_OPERATION_PRIOR_FINALIZATION;
2323
import static org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature.INITIAL_VERSION;
24-
import static org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager.maxLayoutVersion;
2524
import static org.junit.jupiter.api.Assertions.assertEquals;
2625
import static org.junit.jupiter.api.Assertions.assertNull;
2726
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -31,10 +30,12 @@
3130
import java.util.Set;
3231
import java.util.UUID;
3332
import org.apache.commons.lang3.RandomStringUtils;
33+
import org.apache.hadoop.hdds.ComponentVersion;
3434
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
3535
import org.apache.hadoop.hdds.utils.IOUtils;
3636
import org.apache.hadoop.ozone.MiniOzoneCluster;
3737
import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl;
38+
import org.apache.hadoop.ozone.OzoneManagerVersion;
3839
import org.apache.hadoop.ozone.client.OzoneClient;
3940
import org.apache.hadoop.ozone.om.exceptions.OMException;
4041
import org.apache.hadoop.ozone.om.helpers.BucketLayout;
@@ -79,15 +80,15 @@ class TestOMBucketLayoutUpgrade {
7980
private MiniOzoneHAClusterImpl cluster;
8081
private OzoneManager ozoneManager;
8182
private static final String VOLUME_NAME = "vol-" + UUID.randomUUID();
82-
private final int fromLayoutVersion = INITIAL_VERSION.layoutVersion();
83+
private final ComponentVersion fromVersion = INITIAL_VERSION;
8384
private OzoneManagerProtocol omClient;
8485

8586
private OzoneClient client;
8687

8788
@BeforeAll
8889
void setup() throws Exception {
8990
OzoneConfiguration conf = new OzoneConfiguration();
90-
conf.setInt(OMStorage.TESTING_INIT_LAYOUT_VERSION_KEY, fromLayoutVersion);
91+
conf.setInt(OMStorage.TESTING_INIT_APPARENT_VERSION_KEY, fromVersion.serialize());
9192
String omServiceId = UUID.randomUUID().toString();
9293
MiniOzoneHAClusterImpl.Builder builder = MiniOzoneCluster.newHABuilder(conf);
9394
builder.setOMServiceId(omServiceId)
@@ -120,10 +121,10 @@ void shutdown() {
120121
@Test
121122
@Order(PRE_UPGRADE)
122123
void omLayoutBeforeUpgrade() throws IOException {
123-
assertEquals(fromLayoutVersion,
124-
ozoneManager.getVersionManager().getMetadataLayoutVersion());
124+
assertEquals(fromVersion,
125+
ozoneManager.getVersionManager().getApparentVersion());
125126
assertNull(ozoneManager.getMetadataManager().getMetaTable()
126-
.get(LAYOUT_VERSION_KEY));
127+
.get(APPARENT_VERSION_KEY));
127128
}
128129

129130
/**
@@ -157,11 +158,12 @@ void finalizeUpgrade() throws Exception {
157158

158159
waitForFinalization(omClient);
159160

160-
final String expectedVersion = String.valueOf(maxLayoutVersion());
161+
final String expectedVersion =
162+
String.valueOf(OzoneManagerVersion.SOFTWARE_VERSION.serialize());
161163
LambdaTestUtils.await(30000, 3000,
162164
() -> expectedVersion.equals(
163165
ozoneManager.getMetadataManager().getMetaTable()
164-
.get(LAYOUT_VERSION_KEY)));
166+
.get(APPARENT_VERSION_KEY)));
165167
}
166168

167169
@Order(POST_UPGRADE)

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMUpgradeFinalization.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717

1818
package org.apache.hadoop.ozone.om;
1919

20-
import static org.apache.hadoop.ozone.OzoneConsts.LAYOUT_VERSION_KEY;
20+
import static org.apache.hadoop.ozone.OzoneConsts.APPARENT_VERSION_KEY;
2121
import static org.apache.hadoop.ozone.om.OMUpgradeTestUtils.assertClusterPrepared;
2222
import static org.apache.hadoop.ozone.om.OMUpgradeTestUtils.waitForFinalization;
2323
import static org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature.INITIAL_VERSION;
24-
import static org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager.maxLayoutVersion;
2524
import static org.apache.ozone.test.GenericTestUtils.waitFor;
2625
import static org.junit.jupiter.api.Assertions.assertEquals;
2726
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -34,6 +33,7 @@
3433
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
3534
import org.apache.hadoop.ozone.MiniOzoneCluster;
3635
import org.apache.hadoop.ozone.MiniOzoneHAClusterImpl;
36+
import org.apache.hadoop.ozone.OzoneManagerVersion;
3737
import org.apache.hadoop.ozone.audit.AuditEventStatus;
3838
import org.apache.hadoop.ozone.audit.AuditLogTestUtils;
3939
import org.apache.hadoop.ozone.audit.OMAction;
@@ -43,6 +43,7 @@
4343
import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.StatusAndMessages;
4444
import org.apache.ratis.util.LifeCycle;
4545
import org.junit.jupiter.api.AfterAll;
46+
import org.junit.jupiter.api.Assertions;
4647
import org.junit.jupiter.api.BeforeEach;
4748
import org.junit.jupiter.api.Test;
4849

@@ -73,6 +74,12 @@ void testOMUpgradeFinalizationWithOneOMDown() throws Exception {
7374

7475
try (OzoneClient client = cluster.newClient()) {
7576
List<OzoneManager> runningOms = cluster.getOzoneManagersList();
77+
for (OzoneManager om : runningOms) {
78+
assertEquals(INITIAL_VERSION, om.getVersionManager().getApparentVersion());
79+
// The OMs have not been finalized yet, so no version has been written to the DB.
80+
Assertions.assertNull(om.getMetadataManager().getMetaTable().get(APPARENT_VERSION_KEY));
81+
}
82+
7683
final int shutdownOMIndex = 2;
7784
OzoneManager downedOM = cluster.getOzoneManager(shutdownOMIndex);
7885
cluster.stopOzoneManager(shutdownOMIndex);
@@ -110,19 +117,17 @@ void testOMUpgradeFinalizationWithOneOMDown() throws Exception {
110117
waitFor(() -> !omStateMachine.getLifeCycle().getCurrentState()
111118
.isPausingOrPaused(), 1000, 60000);
112119

113-
assertEquals(maxLayoutVersion(),
114-
downedOM.getVersionManager().getMetadataLayoutVersion());
115-
String lvString = downedOM.getMetadataManager().getMetaTable()
116-
.get(LAYOUT_VERSION_KEY);
117-
assertNotNull(lvString);
118-
assertEquals(maxLayoutVersion(), Integer.parseInt(lvString));
120+
assertEquals(OzoneManagerVersion.SOFTWARE_VERSION, downedOM.getVersionManager().getApparentVersion());
121+
String dbVersionString = downedOM.getMetadataManager().getMetaTable().get(APPARENT_VERSION_KEY);
122+
assertNotNull(dbVersionString);
123+
assertEquals(OzoneManagerVersion.SOFTWARE_VERSION.serialize(), Integer.parseInt(dbVersionString));
119124
}
120125
}
121126
}
122127

123128
private static MiniOzoneHAClusterImpl newCluster(OzoneConfiguration conf)
124129
throws IOException {
125-
conf.setInt(OMStorage.TESTING_INIT_LAYOUT_VERSION_KEY, INITIAL_VERSION.layoutVersion());
130+
conf.setInt(OMStorage.TESTING_INIT_APPARENT_VERSION_KEY, INITIAL_VERSION.serialize());
126131
MiniOzoneHAClusterImpl.Builder builder = MiniOzoneCluster.newHABuilder(conf);
127132
builder.setOMServiceId(UUID.randomUUID().toString())
128133
.setNumOfOzoneManagers(3)

hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmStartupSlvLessThanMlv.java renamed to hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOmStartupInvalidApparentVersion.java

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,64 +17,66 @@
1717

1818
package org.apache.hadoop.ozone.om;
1919

20+
import static org.apache.hadoop.ozone.OzoneManagerVersion.SOFTWARE_VERSION;
2021
import static org.junit.jupiter.api.Assertions.assertEquals;
2122
import static org.junit.jupiter.api.Assertions.assertThrows;
2223

2324
import java.io.File;
25+
import java.io.IOException;
2426
import java.nio.file.Files;
2527
import java.nio.file.Path;
2628
import java.nio.file.Paths;
2729
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
2830
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
2931
import org.apache.hadoop.ozone.MiniOzoneCluster;
3032
import org.apache.hadoop.ozone.MiniOzoneClusterImpl;
31-
import org.apache.hadoop.ozone.om.exceptions.OMException;
3233
import org.apache.hadoop.ozone.om.upgrade.OMLayoutFeature;
33-
import org.apache.hadoop.ozone.upgrade.LayoutFeature;
3434
import org.apache.hadoop.ozone.upgrade.UpgradeTestUtils;
3535
import org.apache.ozone.test.GenericTestUtils;
3636
import org.junit.jupiter.api.Test;
3737
import org.junit.jupiter.api.io.TempDir;
3838

3939
/**
40-
* Test that the ozone manager will not start when it loads a VERSION file
41-
* indicating a metadata layout version larger than its software layout version.
40+
* Ensures OM does not start when the VERSION file records an apparent version newer than the software version
41+
* baked into this process ({@link org.apache.hadoop.ozone.OzoneManagerVersion#SOFTWARE_VERSION}).
4242
*/
43-
public class TestOmStartupSlvLessThanMlv {
43+
public class TestOmStartupInvalidApparentVersion {
4444

4545
@TempDir
4646
private Path folder;
4747

4848
@Test
49-
public void testStartupSlvLessThanMlv() throws Exception {
50-
// Add subdirectories under the temporary folder where the version file
51-
// will be placed.
49+
public void testStartupFailsWhenApparentVersionBetweenLastLayoutFeatureAndZdu()
50+
throws Exception {
51+
assertStartupFailsWithComponentVersionMessage(OMLayoutFeature.SNAPSHOT_DEFRAG.layoutVersion() + 1);
52+
}
53+
54+
@Test
55+
public void testStartupFailsWhenApparentVersionBeyondLastKnownComponentVersion()
56+
throws Exception {
57+
assertStartupFailsWithComponentVersionMessage(SOFTWARE_VERSION.serialize() + 1);
58+
}
59+
60+
private void assertStartupFailsWithComponentVersionMessage(int serializedApparentVersion)
61+
throws Exception {
5262
String subDir = folder.toAbsolutePath() + "/om/current";
5363
File omSubdir = Files.createDirectories(Paths.get(subDir)).toFile();
5464

5565
OzoneConfiguration conf = new OzoneConfiguration();
56-
conf.set(OMConfigKeys.OZONE_OM_DB_DIRS,
57-
folder.toAbsolutePath().toString());
58-
59-
// Set metadata layout version larger than software layout version.
60-
int largestSlv = 0;
61-
for (LayoutFeature f: OMLayoutFeature.values()) {
62-
largestSlv = Math.max(largestSlv, f.layoutVersion());
63-
}
64-
int mlv = largestSlv + 1;
66+
conf.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.toAbsolutePath().toString());
6567

66-
// Create version file with MLV > SLV, which should fail the cluster build.
67-
UpgradeTestUtils.createVersionFile(omSubdir, HddsProtos.NodeType.OM, mlv);
68+
UpgradeTestUtils.createVersionFile(omSubdir, HddsProtos.NodeType.OM, serializedApparentVersion);
6869

6970
MiniOzoneCluster.Builder clusterBuilder = MiniOzoneCluster.newBuilder(conf);
7071

72+
String expectedMessage =
73+
"Initialization failed. Disk contains unknown apparent version " + serializedApparentVersion
74+
+ " for software version " + SOFTWARE_VERSION + ". Make sure OM was not downgraded after"
75+
+ " finalization";
76+
7177
GenericTestUtils.withLogDisabled(MiniOzoneClusterImpl.class, () -> {
72-
OMException omException = assertThrows(OMException.class,
73-
clusterBuilder::build);
74-
String expectedMessage = String.format("Cannot initialize " +
75-
"VersionManager. Metadata layout version (%s) > software layout" +
76-
" version (%s)", mlv, mlv - 1);
77-
assertEquals(expectedMessage, omException.getMessage());
78+
IOException ioException = assertThrows(IOException.class, clusterBuilder::build);
79+
assertEquals(expectedMessage, ioException.getMessage());
7880
});
7981
}
8082
}

0 commit comments

Comments
 (0)