Skip to content

Commit 7988537

Browse files
authored
HDDS-14826. Prepare OM to switch from LayoutVersionManager to ComponentVersionManager (#10098)
1 parent f639c57 commit 7988537

35 files changed

Lines changed: 662 additions & 214 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.hadoop.ozone.upgrade;
19+
20+
import java.util.Map;
21+
import org.apache.hadoop.hdds.ComponentVersion;
22+
23+
/**
24+
* Supplies upgrade actions keyed by {@link ComponentVersion}. Implementations typically perform classpath scanning or
25+
* return a fixed map for tests. The component version manager decides when each action is invoked.
26+
*
27+
* @param <A> concrete upgrade action type (for example OM-specific or HDDS-specific)
28+
*/
29+
@FunctionalInterface
30+
public interface ComponentUpgradeActionProvider<A> {
31+
32+
/**
33+
* Returns all upgrade actions from this provider, keyed by component version.
34+
* <p>
35+
* Implementations must return a newly allocated map on each call; the caller may retain and use it directly.
36+
*/
37+
Map<ComponentVersion, A> load();
38+
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ public String toString() {
106106
public enum ResultCodes {
107107
OK,
108108
INVALID_REQUEST,
109-
UPDATE_LAYOUT_VERSION_FAILED,
110-
LAYOUT_FEATURE_FINALIZATION_FAILED,
111-
PREFINALIZE_ACTION_VALIDATION_FAILED,
112-
FIRST_UPGRADE_START_ACTION_FAILED,
113-
PREFINALIZE_VALIDATION_FAILED;
109+
APPARENT_VERSION_UPDATE_FAILED,
110+
UPGRADE_FINALIZATION_FAILED,
111+
FINALIZE_UPGRADE_ACTION_FAILED,
114112
}
115113
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,19 @@ public final class UpgradeFinalization {
4949
);
5050

5151
/**
52-
* Default message to provide when the service is in ALREADY_FINALIZED state.
52+
* Returned from finalize upgrade commands when finalization is not required.
5353
*/
5454
public static final StatusAndMessages FINALIZED_MSG = new StatusAndMessages(
5555
Status.ALREADY_FINALIZED, Collections.emptyList()
5656
);
5757

58+
/**
59+
* Returned from progress/status queries when finalization is not required.
60+
*/
61+
public static final StatusAndMessages FINALIZATION_DONE_MSG = new StatusAndMessages(
62+
Status.FINALIZATION_DONE, Collections.emptyList()
63+
);
64+
5865
/**
5966
* Represents the current state in which the service is with regards to
6067
* finalization after an upgrade.

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/helpers/DatanodeIdYaml.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ private static DatanodeDetailsYaml getDatanodeDetailsYaml(
261261
HDDSLayoutFeature layoutFeature
262262
= f.getAnnotation(BelongsToHDDSLayoutVersion.class).value();
263263
if (layoutFeature.layoutVersion() >
264-
datanodeLayoutStorage.getLayoutVersion()) {
264+
datanodeLayoutStorage.getApparentVersion()) {
265265
continue;
266266
}
267267
}

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/common/statemachine/DatanodeStateMachine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public DatanodeStateMachine(HddsDatanodeService hddsDatanodeService,
168168
datanodeDetails.getUuidString());
169169

170170
layoutVersionManager = new HDDSLayoutVersionManager(
171-
layoutStorage.getLayoutVersion());
171+
layoutStorage.getApparentVersion());
172172
upgradeFinalizer = new DataNodeUpgradeFinalizer(layoutVersionManager);
173173
VersionedDatanodeFeatures.initialize(layoutVersionManager);
174174

hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/upgrade/DataNodeUpgradeFinalizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void finalizeLayoutFeature(LayoutFeature layoutFeature,
4747
String msg = String.format("Failed to finalize datanode layout feature " +
4848
"%s. It is not an HDDS Layout Feature.", layoutFeature);
4949
throw new UpgradeException(msg,
50-
UpgradeException.ResultCodes.LAYOUT_FEATURE_FINALIZATION_FAILED);
50+
UpgradeException.ResultCodes.UPGRADE_FINALIZATION_FAILED);
5151
}
5252
}
5353
}

hadoop-hdds/docs/content/design/upgrade-dev-primer.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@ Downgrade to a lower version is allowed from the pre-finalized state. This invol
3636
org.apache.hadoop.hdds.upgrade.HDDSLayoutFeature
3737
Class to add a new layout feature being brought in. Layout version is typically 1 + last layout feature in that catalog.
3838

39-
## LayoutVersionManager
40-
org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager
41-
org.apache.hadoop.hdds.upgrade.HDDSLayoutVersionManager
42-
Every component carries an instance of this interface, which provides APIs to get runtime layout version, and if a feature is allowed based on that or not.
39+
## Version management (OM vs HDDS)
4340

44-
The LayoutVersionManager interface carries an API that can be used to check if a feature is allowed in the current layout version.
45-
org.apache.hadoop.ozone.upgrade.LayoutVersionManager#isAllowed(org.apache.hadoop.ozone.upgrade.LayoutFeature)
41+
**Ozone Manager** uses [`org.apache.hadoop.ozone.om.upgrade.OMVersionManager`](https://github.com/apache/ozone/blob/master/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/OMVersionManager.java) ([`org.apache.hadoop.ozone.upgrade.ComponentVersionManager`](https://github.com/apache/ozone/blob/master/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/ComponentVersionManager.java)), with upgrade actions discovered via [`org.apache.hadoop.ozone.om.upgrade.OMUpgradeActionProvider`](https://github.com/apache/ozone/blob/master/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/upgrade/OMUpgradeActionProvider.java). It exposes apparent/software `ComponentVersion` and `isAllowed(ComponentVersion)` for gating.
42+
43+
**SCM / DataNode** continue to use [`org.apache.hadoop.hdds.upgrade.HDDSLayoutVersionManager`](https://github.com/apache/ozone/blob/master/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/upgrade/HDDSLayoutVersionManager.java) ([`org.apache.hadoop.ozone.upgrade.AbstractLayoutVersionManager`](https://github.com/apache/ozone/blob/master/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/AbstractLayoutVersionManager.java)), which provides metadata/software layout integers and `isAllowed(LayoutFeature)`.
4644

4745
## @DisallowedUntilLayoutVersion Annotation
4846
Method level annotation used to "disallow" an API if current layout version does not include the associated layout feature. Currently it is added only to the OM module, but can easily be moved down to a common module based on need on the HDDS layer.

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,45 @@
2020
import java.io.IOException;
2121
import org.apache.hadoop.hdds.ComponentVersion;
2222
import org.apache.hadoop.hdds.HDDSVersion;
23+
import org.apache.hadoop.ozone.common.Storage;
2324
import org.apache.hadoop.ozone.upgrade.ComponentVersionManager;
25+
import org.apache.hadoop.ozone.upgrade.UpgradeException;
2426

2527
/**
2628
* Component version manager for HDDS (Datanodes and SCM).
2729
*/
2830
public class HDDSVersionManager extends ComponentVersionManager {
29-
public HDDSVersionManager(int serializedApparentVersion) throws IOException {
30-
super(computeApparentVersion(serializedApparentVersion), HDDSVersion.SOFTWARE_VERSION);
31+
public HDDSVersionManager(Storage storage) throws IOException {
32+
super(storage, computeApparentVersion(storage.getApparentVersion()), HDDSVersion.SOFTWARE_VERSION);
3133
}
3234

3335
/**
34-
* If the apparent version stored on the disk is >= 100, it indicates the component has been finalized for the
35-
* ZDU feature, and the apparent version corresponds to a version in {@link HDDSVersion}.
36-
* If the apparent version stored on the disk is < 100, it indicates the component is not yet finalized for the
37-
* ZDU feature, and the apparent version corresponds to a version in {@link HDDSLayoutFeature}.
36+
* If the apparent version stored on the disk is &gt;= {@link HDDSVersion#ZDU} serialized, the apparent version is
37+
* resolved via {@link HDDSVersion#deserialize(int)}. Values with no matching {@link HDDSVersion} fail startup with
38+
* the persisted integer in the exception message.
39+
* If the value is below that threshold, the apparent version is resolved as a {@link HDDSLayoutFeature}. Integers in
40+
* the gap between the largest {@link HDDSLayoutFeature} and ZDU are not valid legacy layout values; startup fails
41+
* with the persisted integer in the exception message.
3842
*/
39-
private static ComponentVersion computeApparentVersion(int serializedApparentVersion) {
40-
if (serializedApparentVersion < HDDSVersion.ZDU.serialize()) {
41-
return HDDSLayoutFeature.deserialize(serializedApparentVersion);
43+
private static ComponentVersion computeApparentVersion(int serializedApparentVersion) throws IOException {
44+
if (serializedApparentVersion >= HDDSVersion.ZDU.serialize()) {
45+
HDDSVersion fromHdds = HDDSVersion.deserialize(serializedApparentVersion);
46+
if (fromHdds != HDDSVersion.FUTURE_VERSION) {
47+
return fromHdds;
48+
}
4249
} else {
43-
return HDDSVersion.deserialize(serializedApparentVersion);
50+
ComponentVersion fromLayout = HDDSLayoutFeature.deserialize(serializedApparentVersion);
51+
if (fromLayout != null) {
52+
return fromLayout;
53+
}
4454
}
55+
throw new IOException("Initialization failed. Disk contains unknown apparent version " + serializedApparentVersion +
56+
" for software version " + HDDSVersion.SOFTWARE_VERSION + ". Make sure this component was not downgraded" +
57+
" after finalization");
4558
}
4659

47-
// TODO HDDS-14826: Register upgrade actions based on annotations
60+
@Override
61+
protected void runUpgradeAction(ComponentVersion componentVersion) throws UpgradeException {
62+
// TODO HDDS-14826: Register upgrade actions based on annotations
63+
}
4864
}

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,12 @@ public void setClusterId(String clusterId) throws IOException {
124124
}
125125
}
126126

127-
public int getLayoutVersion() {
128-
return storageInfo.getLayoutVersion();
127+
public int getApparentVersion() {
128+
return storageInfo.getApparentVersion();
129129
}
130130

131-
public void setLayoutVersion(int version) {
132-
storageInfo.setLayoutVersion(version);
133-
}
134-
135-
public void setFirstUpgradeActionLayoutVersion(int version) {
136-
storageInfo.setFirstUpgradeActionLayoutVersion(version);
137-
}
138-
139-
public int getFirstUpgradeActionLayoutVersion() {
140-
return storageInfo.getFirstUpgradeActionLayoutVersion();
131+
public void setApparentVersion(int version) {
132+
storageInfo.setApparentVersion(version);
141133
}
142134

143135
/**
@@ -288,8 +280,7 @@ public void persistCurrentState() throws IOException {
288280
storageInfo.writeTo(getVersionFile());
289281
}
290282

291-
protected static int getInitLayoutVersion(OzoneConfiguration conf,
292-
String configKey,
283+
protected static int getInitApparentVersion(OzoneConfiguration conf, String configKey,
293284
IntSupplier defaultLvSupplier) {
294285
int lV = conf.getInt(configKey, OZONE_INIT_DEFAULT_LAYOUT_VERSION_DEFAULT);
295286
if (lV == OZONE_INIT_DEFAULT_LAYOUT_VERSION_DEFAULT) {

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ public class StorageInfo {
6161
*/
6262
private static final String LAYOUT_VERSION = "layoutVersion";
6363

64-
private static final String FIRST_UPGRADE_ACTION_LAYOUT_VERSION =
65-
"firstUpgradeActionLayoutVersion";
66-
6764
private static final int INVALID_LAYOUT_VERSION = -1;
6865

6966
/**
@@ -93,7 +90,7 @@ public StorageInfo(NodeType type, File propertiesFile)
9390
verifyNodeType(type);
9491
verifyClusterId();
9592
verifyCreationTime();
96-
verifyLayoutVersion();
93+
verifyApparentVersion();
9794
}
9895

9996
public NodeType getNodeType() {
@@ -112,15 +109,15 @@ public Long getCreationTime() {
112109
return null;
113110
}
114111

115-
public int getLayoutVersion() {
112+
public int getApparentVersion() {
116113
String layout = properties.getProperty(LAYOUT_VERSION);
117114
if (layout != null) {
118115
return Integer.parseInt(layout);
119116
}
120117
return 0;
121118
}
122119

123-
private void verifyLayoutVersion() {
120+
private void verifyApparentVersion() {
124121
String layout = getProperty(LAYOUT_VERSION);
125122
if (layout == null) {
126123
LOG.warn("Found " + STORAGE_FILE_VERSION + " file without any layout " +
@@ -129,20 +126,6 @@ private void verifyLayoutVersion() {
129126
}
130127
}
131128

132-
public int getFirstUpgradeActionLayoutVersion() {
133-
String upgradingTo =
134-
properties.getProperty(FIRST_UPGRADE_ACTION_LAYOUT_VERSION);
135-
if (upgradingTo != null) {
136-
return Integer.parseInt(upgradingTo);
137-
}
138-
return INVALID_LAYOUT_VERSION;
139-
}
140-
141-
public void setFirstUpgradeActionLayoutVersion(int layoutVersion) {
142-
properties.setProperty(
143-
FIRST_UPGRADE_ACTION_LAYOUT_VERSION, Integer.toString(layoutVersion));
144-
}
145-
146129
public String getProperty(String key) {
147130
return properties.getProperty(key);
148131
}
@@ -159,7 +142,7 @@ public void setClusterId(String clusterId) {
159142
properties.setProperty(CLUSTER_ID, clusterId);
160143
}
161144

162-
public void setLayoutVersion(int version) {
145+
public void setApparentVersion(int version) {
163146
properties.setProperty(LAYOUT_VERSION, Integer.toString(version));
164147
}
165148

0 commit comments

Comments
 (0)