This is an automated email from the ASF dual-hosted git repository.
errose28 pushed a commit to branch HDDS-14496-zdu
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/HDDS-14496-zdu by this push:
new 032821150a6 HDDS-15379. Remove unused classes from the old upgrade
framework (#10370)
032821150a6 is described below
commit 032821150a6299f9a0330d9b0ce4af6b16b7b5d5
Author: Ethan Rose <[email protected]>
AuthorDate: Wed Jun 10 14:36:47 2026 -0400
HDDS-15379. Remove unused classes from the old upgrade framework (#10370)
Co-authored-by: Cursor <[email protected]>
---
.../hadoop/hdds/upgrade/HDDSLayoutFeature.java | 36 ---
.../hdds/upgrade/HDDSLayoutVersionManager.java | 75 -----
.../upgrade/AbstractLayoutVersionManager.java | 206 ------------
.../ozone/upgrade/BasicUpgradeFinalizer.java | 360 ---------------------
.../DefaultUpgradeFinalizationExecutor.java | 71 ----
.../ozone/upgrade/LayoutVersionManagerMXBean.java | 27 --
.../ozone/upgrade/UpgradeFinalizationExecutor.java | 32 --
.../hadoop/ozone/upgrade/UpgradeFinalizer.java | 106 ------
.../hdds/upgrade/TestHDDSLayoutVersionManager.java | 132 --------
.../InjectedUpgradeFinalizationExecutor.java | 124 -------
.../upgrade/TestAbstractLayoutVersionManager.java | 203 ------------
.../ozone/upgrade/TestBasicUpgradeFinalizer.java | 237 --------------
.../TestDefaultUpgradeFinalizationExecutor.java | 89 -----
.../ozone/upgrade/TestUpgradeFinalizerActions.java | 79 -----
.../hadoop/ozone/upgrade/UpgradeTestUtils.java | 34 --
.../apache/hadoop/hdds/scm/node/DatanodeInfo.java | 1 -
.../server/upgrade/FinalizationManagerImpl.java | 12 +-
.../server/upgrade/FinalizationStateManager.java | 11 -
.../upgrade/FinalizationStateManagerImpl.java | 11 -
.../upgrade/SCMUpgradeFinalizationContext.java | 99 ------
.../scm/server/upgrade/SCMUpgradeFinalizer.java | 85 -----
.../scm/upgrade/FinalizationManagerTestImpl.java | 52 ---
22 files changed, 1 insertion(+), 2081 deletions(-)
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/upgrade/HDDSLayoutFeature.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/upgrade/HDDSLayoutFeature.java
index 8cb957aeac1..9978787e43d 100644
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/upgrade/HDDSLayoutFeature.java
+++
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/upgrade/HDDSLayoutFeature.java
@@ -21,13 +21,11 @@
import static java.util.stream.Collectors.toMap;
import java.util.Arrays;
-import java.util.Optional;
import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.hadoop.hdds.ComponentVersion;
import org.apache.hadoop.hdds.HDDSVersion;
import org.apache.hadoop.ozone.upgrade.LayoutFeature;
-import org.apache.hadoop.ozone.upgrade.UpgradeAction;
/**
* List of HDDS Layout Features. All version management has been migrated to
{@link HDDSVersion} and no new additions
@@ -65,38 +63,12 @@ public enum HDDSLayoutFeature implements LayoutFeature {
private final int layoutVersion;
private final String description;
- private UpgradeAction<?> scmAction;
- private UpgradeAction<?> datanodeAction;
HDDSLayoutFeature(final int layoutVersion, String description) {
this.layoutVersion = layoutVersion;
this.description = description;
}
- /**
- * Associates an SCM upgrade action with this feature. Only the first
upgrade action registered will be used.
- *
- * @param action The upgrade action to associate with this feature.
- */
- public void addScmAction(UpgradeAction<?> action) {
- // Required by SpotBugs since this setter exists in an enum.
- if (this.scmAction == null) {
- this.scmAction = action;
- }
- }
-
- /**
- * Associates a Datanode upgrade action with this feature. Only the first
upgrade action registered will be used.
- *
- * @param action The upgrade action to associate with this feature.
- */
- public void addDatanodeAction(UpgradeAction<?> action) {
- // Required by SpotBugs since this setter exists in an enum.
- if (this.datanodeAction == null) {
- this.datanodeAction = action;
- }
- }
-
@Override
public int layoutVersion() {
return layoutVersion;
@@ -135,12 +107,4 @@ public static HDDSLayoutFeature deserialize(int version) {
public String toString() {
return name() + " (" + serialize() + ")";
}
-
- public Optional<UpgradeAction<?>> scmAction() {
- return Optional.ofNullable(scmAction);
- }
-
- public Optional<UpgradeAction<?>> datanodeAction() {
- return Optional.ofNullable(datanodeAction);
- }
}
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/upgrade/HDDSLayoutVersionManager.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/upgrade/HDDSLayoutVersionManager.java
deleted file mode 100644
index b890a7c6bf6..00000000000
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/upgrade/HDDSLayoutVersionManager.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.hdds.upgrade;
-
-import com.google.common.annotations.VisibleForTesting;
-import java.io.IOException;
-import org.apache.hadoop.ozone.upgrade.AbstractLayoutVersionManager;
-import org.apache.hadoop.ozone.upgrade.ComponentUpgradeActionProvider;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Class to manage layout versions and features for Storage Container Manager
- * and DataNodes.
- */
-@SuppressWarnings("FinalClass")
-public class HDDSLayoutVersionManager extends
- AbstractLayoutVersionManager<HDDSLayoutFeature> {
-
- private static final Logger LOG =
- LoggerFactory.getLogger(HDDSLayoutVersionManager.class);
-
- public HDDSLayoutVersionManager(int layoutVersion,
- ComponentUpgradeActionProvider<?> scmProvider,
- ComponentUpgradeActionProvider<?> dnProvider) throws IOException {
- init(layoutVersion, HDDSLayoutFeature.values());
- registerUpgradeActions(scmProvider, dnProvider);
- }
-
- public static int maxLayoutVersion() {
- HDDSLayoutFeature[] features = HDDSLayoutFeature.values();
- return features[features.length - 1].layoutVersion();
- }
-
- @VisibleForTesting
- void registerUpgradeActions(ComponentUpgradeActionProvider<?> scmProvider,
- ComponentUpgradeActionProvider<?> dnProvider) {
- if (scmProvider != null) {
- scmProvider.load().forEach((feature, action) -> {
- HDDSLayoutFeature hddsFeature = (HDDSLayoutFeature) feature;
- if (hddsFeature.layoutVersion() > getMetadataLayoutVersion()) {
- hddsFeature.addScmAction(action);
- } else {
- LOG.debug("Skipping SCM Upgrade Action {} since it has been
finalized.", action.name());
- }
- });
- }
-
- if (dnProvider != null) {
- dnProvider.load().forEach((feature, action) -> {
- HDDSLayoutFeature hddsFeature = (HDDSLayoutFeature) feature;
- if (hddsFeature.layoutVersion() > getMetadataLayoutVersion()) {
- hddsFeature.addDatanodeAction(action);
- } else {
- LOG.debug("Skipping Datanode Upgrade Action {} since it has been
finalized.", action.name());
- }
- });
- }
- }
-}
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/AbstractLayoutVersionManager.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/AbstractLayoutVersionManager.java
deleted file mode 100644
index 6baf0b7ee8a..00000000000
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/AbstractLayoutVersionManager.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.upgrade;
-
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.ALREADY_FINALIZED;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_REQUIRED;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.TreeMap;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import javax.management.ObjectName;
-import org.apache.hadoop.metrics2.util.MBeans;
-import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Layout Version Manager containing generic method implementations.
- */
-@SuppressWarnings("visibilitymodifier")
-public abstract class AbstractLayoutVersionManager<T extends LayoutFeature>
- implements LayoutVersionManagerMXBean {
-
- private static final Logger LOG =
- LoggerFactory.getLogger(AbstractLayoutVersionManager.class);
-
- private volatile int metadataLayoutVersion; // MLV.
- private volatile int softwareLayoutVersion; // SLV.
- @VisibleForTesting
- protected final TreeMap<Integer, LayoutFeature> features = new TreeMap<>();
- private volatile Status currentUpgradeState;
- // Allows querying upgrade state while an upgrade is in progress.
- // Note that MLV may have been incremented during the upgrade
- // by the time the value is read/used.
- private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
- private ObjectName mBean;
-
- protected void init(int version, T[] lfs) throws IOException {
- lock.writeLock().lock();
- try {
- metadataLayoutVersion = version;
- initializeFeatures(lfs);
- softwareLayoutVersion = features.lastKey();
- if (softwareIsBehindMetaData()) {
- throw new IOException(
- String.format("Cannot initialize VersionManager. Metadata " +
- "layout version (%d) > software layout version (%d)",
- metadataLayoutVersion, softwareLayoutVersion));
- } else if (metadataLayoutVersion == softwareLayoutVersion) {
- currentUpgradeState = ALREADY_FINALIZED;
- } else {
- currentUpgradeState = FINALIZATION_REQUIRED;
- }
-
- LayoutFeature mlvFeature = features.get(metadataLayoutVersion);
- LayoutFeature slvFeature = features.get(softwareLayoutVersion);
- LOG.info("Initializing Layout version manager with metadata layout" +
- " = {} (version = {}), software layout = {} (version = {})",
- mlvFeature, mlvFeature.layoutVersion(),
- slvFeature, slvFeature.layoutVersion());
-
- mBean = MBeans.register("LayoutVersionManager",
- getClass().getSimpleName(), this);
- } finally {
- lock.writeLock().unlock();
- }
- }
-
- public Status getUpgradeState() {
- lock.readLock().lock();
- try {
- return currentUpgradeState;
- } finally {
- lock.readLock().unlock();
- }
- }
-
- public void setUpgradeState(Status status) {
- lock.writeLock().lock();
- try {
- currentUpgradeState = status;
- } finally {
- lock.writeLock().unlock();
- }
- }
-
- private void initializeFeatures(T[] lfs) {
- Arrays.stream(lfs).forEach(f -> {
- Preconditions.checkArgument(!features.containsKey(f.layoutVersion()));
- features.put(f.layoutVersion(), f);
- });
- }
-
- public void finalized(T layoutFeature) {
- lock.writeLock().lock();
- try {
- if (layoutFeature.layoutVersion() == metadataLayoutVersion + 1) {
- metadataLayoutVersion = layoutFeature.layoutVersion();
- LOG.info("Layout feature {} has been finalized.", layoutFeature);
- if (!needsFinalization()) {
- LOG.info("Finalization is complete.");
- }
- } else {
- String versionMsg = "Software layout version: " + softwareLayoutVersion
- + ", Metadata layout version: " + metadataLayoutVersion
- + ", Feature Layout version: " + layoutFeature.layoutVersion()
- + ".";
-
- if (layoutFeature.layoutVersion() <= metadataLayoutVersion) {
- LOG.info("Finalize attempt on a layoutFeature which has already "
- + "been finalized. " + versionMsg + " This can happen when " +
- "Raft Log is replayed during service restart.");
- } else {
- throw new IllegalArgumentException(
- "Finalize attempt on a layoutFeature that is newer than the " +
- "next feature to be finalized. " + versionMsg);
- }
- }
- } finally {
- lock.writeLock().unlock();
- }
- }
-
- private boolean softwareIsBehindMetaData() {
- lock.readLock().lock();
- try {
- return metadataLayoutVersion > softwareLayoutVersion;
- } finally {
- lock.readLock().unlock();
- }
- }
-
- @Override
- public int getMetadataLayoutVersion() {
- lock.readLock().lock();
- try {
- return metadataLayoutVersion;
- } finally {
- lock.readLock().unlock();
- }
- }
-
- @Override
- public int getSoftwareLayoutVersion() {
- return softwareLayoutVersion;
- }
-
- public boolean needsFinalization() {
- lock.readLock().lock();
- try {
- return metadataLayoutVersion < softwareLayoutVersion;
- } finally {
- lock.readLock().unlock();
- }
- }
-
- public boolean isAllowed(LayoutFeature layoutFeature) {
- lock.readLock().lock();
- try {
- return layoutFeature.layoutVersion() <= metadataLayoutVersion;
- } finally {
- lock.readLock().unlock();
- }
- }
-
- public LayoutFeature getFeature(int layoutVersion) {
- return features.get(layoutVersion);
- }
-
- public Iterable<LayoutFeature> unfinalizedFeatures() {
- lock.readLock().lock();
- try {
- return new ArrayList<>(features
- .tailMap(metadataLayoutVersion + 1)
- .values());
- } finally {
- lock.readLock().unlock();
- }
- }
-
- public void close() {
- if (mBean != null) {
- MBeans.unregister(mBean);
- mBean = null;
- }
- }
-}
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/BasicUpgradeFinalizer.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/BasicUpgradeFinalizer.java
deleted file mode 100644
index d7f28a17e88..00000000000
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/BasicUpgradeFinalizer.java
+++ /dev/null
@@ -1,360 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.upgrade;
-
-import static
org.apache.hadoop.ozone.upgrade.UpgradeException.ResultCodes.APPARENT_VERSION_UPDATE_FAILED;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeException.ResultCodes.INVALID_REQUEST;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeException.ResultCodes.UPGRADE_FINALIZATION_FAILED;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.FINALIZATION_IN_PROGRESS_MSG;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.FINALIZATION_REQUIRED_MSG;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.FINALIZED_MSG;
-import static org.apache.hadoop.ozone.upgrade.UpgradeFinalization.STARTING_MSG;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_DONE;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_IN_PROGRESS;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_REQUIRED;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.STARTING_FINALIZATION;
-
-import com.google.common.annotations.VisibleForTesting;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-import org.apache.hadoop.ozone.common.Storage;
-import org.apache.hadoop.ozone.upgrade.UpgradeException.ResultCodes;
-import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status;
-import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.StatusAndMessages;
-import org.apache.hadoop.util.Time;
-import org.apache.ratis.protocol.exceptions.NotLeaderException;
-
-/**
- * Base UpgradeFinalizer implementation to be extended by services.
- */
-public abstract class BasicUpgradeFinalizer
- <T, V extends AbstractLayoutVersionManager> implements UpgradeFinalizer<T>
{
-
- private final V versionManager;
- private String clientID;
- private T component;
- private UpgradeFinalizationExecutor<T> finalizationExecutor;
- // Ensures that there is only one finalization thread running at a time.
- private final Lock finalizationLock;
-
- private final Queue<String> msgs = new ConcurrentLinkedQueue<>();
- private boolean isDone = false;
-
- public BasicUpgradeFinalizer(V versionManager) {
- this(versionManager, new DefaultUpgradeFinalizationExecutor<>());
- }
-
- public BasicUpgradeFinalizer(V versionManager,
- UpgradeFinalizationExecutor<T> executor) {
- this.versionManager = versionManager;
- this.finalizationExecutor = executor;
- this.finalizationLock = new ReentrantLock();
- }
-
- @Override
- public StatusAndMessages finalize(String upgradeClientID, T service)
- throws IOException {
- // In some components, finalization can be driven asynchronously by a
- // thread, not a single serialized Ratis request.
- // A second request could closely follow the first before it
- // sets the finalization status to FINALIZATION_IN_PROGRESS.
- // Therefore, a lock is used to make sure only one finalization thread is
- // running at a time.
- if (isFinalized(versionManager.getUpgradeState())) {
- return FINALIZED_MSG;
- }
- if (finalizationLock.tryLock()) {
- try {
- StatusAndMessages response = initFinalize(upgradeClientID, service);
- // If we were able to enter the lock and finalization status is "in
- // progress", we should resume finalization because the last attempt
- // was interrupted. If an attempt was currently ongoing, the lock
- // would have been held.
- if (response.status() == FINALIZATION_REQUIRED ||
- response.status() == FINALIZATION_IN_PROGRESS) {
- finalizationExecutor.execute(service, this);
- return STARTING_MSG;
- }
- // Else, the initial response we got from initFinalize can be used,
- // since we do not need to start/resume finalization.
- return response;
- } catch (NotLeaderException e) {
- LOG.info("Leader change encountered during finalization. This " +
- "component will continue finalization as directed by the new " +
- "leader.", e);
- return FINALIZATION_IN_PROGRESS_MSG;
- } finally {
- finalizationLock.unlock();
- }
- } else {
- // Finalization has not completed, but another thread holds the lock to
- // run finalization.
- return FINALIZATION_IN_PROGRESS_MSG;
- }
- }
-
- @Override
- public void finalize(T service) throws IOException {
- UpgradeFinalization.Status status = versionManager.getUpgradeState();
- if (isFinalized(status)) {
- return;
- }
- if (status == FINALIZATION_REQUIRED) {
- finalizationExecutor.execute(service, this);
- }
- }
-
- @Override
- public synchronized StatusAndMessages reportStatus(
- String upgradeClientID, boolean takeover) throws UpgradeException {
- if (takeover) {
- clientID = upgradeClientID;
- }
- assertClientId(upgradeClientID);
- List<String> returningMsgs = new ArrayList<>(msgs.size() + 10);
- Status status = versionManager.getUpgradeState();
- while (!msgs.isEmpty()) {
- returningMsgs.add(msgs.poll());
- }
- return new StatusAndMessages(status, returningMsgs);
- }
-
- @Override
- public synchronized Status getStatus() {
- return versionManager.getUpgradeState();
- }
-
- /**
- * Child classes may override this method to set when finalization has
- * begun progress.
- */
- protected void preFinalizeUpgrade(T service) throws IOException {
- versionManager.setUpgradeState(FINALIZATION_IN_PROGRESS);
- }
-
- /**
- * Child classes may override this method to delay finalization being
- * marked done until a set of post finalize actions complete.
- */
- protected void postFinalizeUpgrade(T service) throws IOException {
- versionManager.setUpgradeState(FINALIZATION_DONE);
- }
-
- @Override
- public void finalizeAndWaitForCompletion(
- String upgradeClientID, T service, long maxTimeToWaitInSeconds)
- throws IOException {
-
- StatusAndMessages response = finalize(upgradeClientID, service);
- LOG.info("Finalization Messages : {} ", response.msgs());
- if (isFinalized(response.status())) {
- return;
- }
-
- boolean success = false;
- long endTime = Time.monotonicNow() +
- TimeUnit.SECONDS.toMillis(maxTimeToWaitInSeconds);
- while (Time.monotonicNow() < endTime) {
- try {
- response = reportStatus(upgradeClientID, false);
- LOG.info("Finalization Messages : {} ", response.msgs());
- if (isFinalized(response.status())) {
- success = true;
- break;
- }
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- throw new IOException("Finalization Wait thread interrupted!");
- }
- }
- if (!success) {
- throw new IOException(
- String.format("Unable to finalize after waiting for %d seconds",
- maxTimeToWaitInSeconds));
- }
- }
-
- @VisibleForTesting
- public boolean isFinalizationDone() {
- return isDone;
- }
-
- @VisibleForTesting
- public void markFinalizationDone() {
- isDone = true;
- }
-
- public V getVersionManager() {
- return versionManager;
- }
-
- private synchronized StatusAndMessages initFinalize(
- String upgradeClientID, T id) throws UpgradeException {
- switch (versionManager.getUpgradeState()) {
- case STARTING_FINALIZATION:
- return STARTING_MSG;
- case FINALIZATION_IN_PROGRESS:
- return FINALIZATION_IN_PROGRESS_MSG;
- case FINALIZATION_DONE:
- case ALREADY_FINALIZED:
- if (versionManager.needsFinalization()) {
- throw new UpgradeException("Upgrade found in inconsistent state. " +
- "Upgrade state is FINALIZATION Complete while MLV has not been " +
- "upgraded to SLV.", INVALID_REQUEST);
- }
- return FINALIZED_MSG;
- default:
- if (!versionManager.needsFinalization()) {
- throw new UpgradeException("Upgrade found in inconsistent state. " +
- "Upgrade state is FINALIZATION_REQUIRED while MLV has been " +
- "upgraded to SLV.", INVALID_REQUEST);
- }
- versionManager.setUpgradeState(STARTING_FINALIZATION);
-
- this.clientID = upgradeClientID;
- this.component = id;
- return FINALIZATION_REQUIRED_MSG;
- }
- }
-
- private void assertClientId(String id) throws UpgradeException {
- if (this.clientID == null || !this.clientID.equals(id)) {
- throw new UpgradeException("Unknown client tries to get finalization " +
- "status.\n The requester is not the initiating client of the " +
- "finalization, if you want to take over, and get unsent status " +
- "messages, check -takeover option.", INVALID_REQUEST);
- }
- }
-
- private static boolean isFinalized(Status status) {
- return status.equals(Status.ALREADY_FINALIZED)
- || status.equals(FINALIZATION_DONE);
- }
-
- public abstract void finalizeLayoutFeature(LayoutFeature lf, T context)
- throws UpgradeException;
-
- public void finalizeLayoutFeatures(Iterable<LayoutFeature> features, T
context)
- throws UpgradeException {
- for (LayoutFeature lf : features) {
- finalizeLayoutFeature(lf, context);
- }
- }
-
- protected void finalizeLayoutFeature(LayoutFeature lf, Optional<?
- extends UpgradeAction> action, Storage storage)
- throws UpgradeException {
- runFinalizationAction(lf, action);
- updateLayoutVersionInVersionFile(lf, storage);
- versionManager.finalized(lf);
- }
-
- protected void runFinalizationAction(LayoutFeature feature,
- Optional<? extends UpgradeAction> action) throws UpgradeException {
-
- if (!action.isPresent()) {
- emitNOOPMsg(feature.toString());
- } else {
- LOG.info("Running finalization actions for layout feature: {}", feature);
- try {
- action.get().execute(component);
- } catch (Exception e) {
- logFinalizationFailureAndThrow(e, feature.toString());
- }
- }
- }
-
- protected void updateLayoutVersionInVersionFile(LayoutFeature feature,
- Storage config)
- throws UpgradeException {
- int prevLayoutVersion = currentStoredLayoutVersion(config);
-
- updateStorageLayoutVersion(feature.layoutVersion(), config);
- try {
- persistStorage(config);
- } catch (IOException e) {
- updateStorageLayoutVersion(prevLayoutVersion, config);
- logLayoutVersionUpdateFailureAndThrow(e);
- }
- }
-
- private int currentStoredLayoutVersion(Storage config) {
- return config.getApparentVersion();
- }
-
- private void updateStorageLayoutVersion(int version, Storage config) {
- config.setApparentVersion(version);
- }
-
- private void persistStorage(Storage config) throws IOException {
- config.persistCurrentState();
- }
-
- protected void emitNOOPMsg(String feature) {
- String msg = "No onFinalize work defined for feature: " + feature + ".";
-
- logAndEmit(msg);
- }
-
- protected void emitStartingMsg() {
- String msg = "Finalization started.";
- logAndEmit(msg);
- }
-
- protected void emitFinishedMsg() {
- String msg = "Finalization is done.";
- logAndEmit(msg);
- }
-
- protected void logAndEmit(String msg) {
- LOG.info(msg);
- msgs.offer(msg);
- }
-
- protected void logFinalizationFailureAndThrow(Exception e, String feature)
- throws UpgradeException {
- String msg = "Error during finalization of " + feature + ".";
- logAndThrow(e, msg, UPGRADE_FINALIZATION_FAILED);
- }
-
- private void logLayoutVersionUpdateFailureAndThrow(IOException e)
- throws UpgradeException {
- String msg = "Updating the LayoutVersion in the VERSION file failed.";
- logAndThrow(e, msg, APPARENT_VERSION_UPDATE_FAILED);
- }
-
- private void logAndThrow(Exception e, String msg, ResultCodes resultCode)
- throws UpgradeException {
- LOG.error(msg, e);
- throw new UpgradeException(msg, e, resultCode);
- }
-
- @VisibleForTesting
- public void setFinalizationExecutor(DefaultUpgradeFinalizationExecutor<T>
- executor) {
- finalizationExecutor = executor;
- }
-}
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/DefaultUpgradeFinalizationExecutor.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/DefaultUpgradeFinalizationExecutor.java
deleted file mode 100644
index fe689ae1517..00000000000
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/DefaultUpgradeFinalizationExecutor.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.upgrade;
-
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_REQUIRED;
-
-import java.io.IOException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * DefaultUpgradeFinalizationExecutor for driving the main part of
finalization.
- * Unit/Integration tests can override this to provide error injected version
- * of this class.
- */
-public class DefaultUpgradeFinalizationExecutor<T>
- implements UpgradeFinalizationExecutor<T> {
- static final Logger LOG =
- LoggerFactory.getLogger(DefaultUpgradeFinalizationExecutor.class);
-
- public DefaultUpgradeFinalizationExecutor() {
- }
-
- @Override
- public void execute(T component, BasicUpgradeFinalizer<T, ?> finalizer)
- throws IOException {
- try {
- finalizer.emitStartingMsg();
-
- finalizer.preFinalizeUpgrade(component);
-
- finalizeFeatures(component, finalizer,
- finalizer.getVersionManager().unfinalizedFeatures());
-
- finalizer.postFinalizeUpgrade(component);
-
- finalizer.emitFinishedMsg();
- } catch (Exception e) {
- LOG.warn("Upgrade Finalization failed with following Exception. ", e);
- if (finalizer.getVersionManager().needsFinalization()) {
- finalizer.getVersionManager()
- .setUpgradeState(FINALIZATION_REQUIRED);
- throw e;
- }
- } finally {
- // Used for testing.
- finalizer.markFinalizationDone();
- }
- }
-
- protected void finalizeFeatures(T component,
- BasicUpgradeFinalizer<T, ?> finalizer, Iterable<LayoutFeature> lfs)
- throws UpgradeException {
- finalizer.finalizeLayoutFeatures(lfs, component);
- }
-}
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutVersionManagerMXBean.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutVersionManagerMXBean.java
deleted file mode 100644
index 6b571ddb427..00000000000
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/LayoutVersionManagerMXBean.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.upgrade;
-
-/**
- * Interface for exposing Layout version metrics to JMX.
- */
-public interface LayoutVersionManagerMXBean {
- int getMetadataLayoutVersion();
-
- int getSoftwareLayoutVersion();
-}
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/UpgradeFinalizationExecutor.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/UpgradeFinalizationExecutor.java
deleted file mode 100644
index ca013e05000..00000000000
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/UpgradeFinalizationExecutor.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.upgrade;
-
-import java.io.IOException;
-
-/**
- * An upgrade finalization executor runs the finalization methods of an
- * {@link UpgradeFinalizer}, providing them the state they need to operate
- * and optionally injecting actions in between.
- * @param <T> The component or context that the {@link UpgradeFinalizer}
- * needs to run.
- */
-public interface UpgradeFinalizationExecutor<T> {
- void execute(T component, BasicUpgradeFinalizer<T, ?> finalizer)
- throws IOException;
-}
diff --git
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/UpgradeFinalizer.java
b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/UpgradeFinalizer.java
deleted file mode 100644
index 94aa9d34f7e..00000000000
---
a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/ozone/upgrade/UpgradeFinalizer.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.upgrade;
-
-import java.io.IOException;
-import org.apache.hadoop.hdds.annotation.InterfaceAudience;
-import org.apache.hadoop.hdds.annotation.InterfaceStability;
-import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status;
-import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.StatusAndMessages;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Interface to define the upgrade finalizer implementations.
- * The role of this class is to manage the LayoutFeature finalization and
- * activation, after an upgrade was done.
- * For different service types, where this has relevance, there should be
- * an implementation for this interface, that handles the finalization process
- * in tandem with the corresponding version manager, and Storage.
- * @param <T> The service type which the implementation is bound to, this
- * defines the type that is provided to {@link LayoutFeature}'s
- * {@link org.apache.hadoop.ozone.upgrade.UpgradeAction}
- */
[email protected]
[email protected]
-public interface UpgradeFinalizer<T> {
-
- Logger LOG = LoggerFactory.getLogger(UpgradeFinalizer.class);
-
- /**
- * Finalize the metadata upgrade.
- * The provided client ID will be eligible to get the status messages,
- * the service provided will be provided to the
- * {@link org.apache.hadoop.ozone.upgrade.UpgradeAction}s of
- * the {@link LayoutFeature}s being finalized.
- * @param upgradeClientID the initiating client's identifier.
- * @param service the service on which we run finalization.
- * @return the status after running finalization logic, with messages to be
- * provided to the client
- * @throws IOException if the finalization fails at any stage.
- */
- StatusAndMessages finalize(String upgradeClientID, T service)
- throws IOException;
-
- /**
- * Finalize the metadata upgrade. If finalization is not needed or is
already underway, this call is a noop.
- * @param service the service on which we run finalization.
- * @throws IOException if the finalization fails at any stage.
- */
- void finalize(T service) throws IOException;
-
- /**
- * Finalize the component if needed, and wait until completion.
- * @param upgradeClientID the initiating client's identifier.
- * @param service the service on which we run finalization.
- * @param timeoutInSeconds max time to wait for finalization in seconds.
- * @throws IOException
- */
- void finalizeAndWaitForCompletion(String upgradeClientID, T service,
- long timeoutInSeconds) throws IOException;
-
- /**
- * Gets a status report about the finalization process.
- * This method has a meaning, when the client polls the server from time to
- * time for the status, and the server runs the finalization in the
- * background.
- * The background finalization can supply the messages back to the polling
- * client in this method.
- * @param upgradeClientId the identifier of the client initiated finalization
- * @param takeover if a new client wants to take over, from the original
- * client, this should be set to true, and in this case, the
- * new client ID will be eligible to get status updates.
- * A finalizer implementation can decide to ignore this
- * parameter, in which case it may return status to any
- * client.
- * @return the status of the finalization.
- * @throws IOException if the implementation requires a dedicated client to
- * report progress to, and if the client ID is not the initiating
- * client ID while takover is not specified to be true.
- * Or in any other I/O failure scenario.
- */
- StatusAndMessages reportStatus(String upgradeClientId, boolean takeover)
- throws IOException;
-
- /**
- * Get a readonly status of the finalization.
- * @return the status of the finalization
- */
- Status getStatus();
-
-}
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/upgrade/TestHDDSLayoutVersionManager.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/upgrade/TestHDDSLayoutVersionManager.java
deleted file mode 100644
index 08b4d96c908..00000000000
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/upgrade/TestHDDSLayoutVersionManager.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.hdds.upgrade;
-
-import static
org.apache.hadoop.hdds.upgrade.HDDSLayoutFeature.DATANODE_SCHEMA_V2;
-import static org.apache.hadoop.hdds.upgrade.HDDSLayoutFeature.INITIAL_VERSION;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.doCallRealMethod;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-import org.apache.hadoop.hdds.ComponentVersion;
-import org.apache.hadoop.ozone.upgrade.ComponentUpgradeActionProvider;
-import org.apache.hadoop.ozone.upgrade.UpgradeAction;
-import org.junit.jupiter.api.Test;
-
-/**
- * Class to test HDDS upgrade action registrations.
- */
-public class TestHDDSLayoutVersionManager {
-
- /**
- * Mock component for testing upgrade actions.
- */
- public static class MockComponent {
- public void mockMethodScm() {
- }
-
- public void mockMethodDn() {
- }
- }
-
- /**
- * Mock SCM upgrade action for testing.
- */
- public static class MockScmUpgradeAction implements
UpgradeAction<MockComponent> {
- @Override
- public void execute(MockComponent arg) {
- arg.mockMethodScm();
- }
- }
-
- /**
- * Mock Datanode upgrade action for testing.
- */
- public static class MockDnUpgradeAction implements
UpgradeAction<MockComponent> {
- @Override
- public void execute(MockComponent arg) {
- arg.mockMethodDn();
- }
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testUpgradeActionsRegistered() throws Exception {
- ComponentUpgradeActionProvider<UpgradeAction<MockComponent>> scmProvider =
() -> {
- Map<ComponentVersion, UpgradeAction<MockComponent>> map = new
HashMap<>();
- map.put(INITIAL_VERSION, new MockScmUpgradeAction());
- return map;
- };
-
- ComponentUpgradeActionProvider<UpgradeAction<MockComponent>> dnProvider =
() -> {
- Map<ComponentVersion, UpgradeAction<MockComponent>> map = new
HashMap<>();
- map.put(DATANODE_SCHEMA_V2, new MockDnUpgradeAction());
- return map;
- };
-
- //Cluster is finalized, hence should not register.
- Optional<UpgradeAction<?>> action = INITIAL_VERSION.scmAction();
- assertFalse(action.isPresent());
- Optional<UpgradeAction<?>> dnAction = DATANODE_SCHEMA_V2.datanodeAction();
- assertFalse(dnAction.isPresent());
-
- // Start from an unfinalized version manager.
- HDDSLayoutVersionManager lvm = mock(HDDSLayoutVersionManager.class);
- when(lvm.getMetadataLayoutVersion()).thenReturn(-1);
-
- doCallRealMethod().when(lvm).registerUpgradeActions(any(), any());
- lvm.registerUpgradeActions(scmProvider, dnProvider);
-
- action = INITIAL_VERSION.scmAction();
- assertTrue(action.isPresent());
- assertEquals(MockScmUpgradeAction.class, action.get().getClass());
- assertFalse(INITIAL_VERSION.datanodeAction().isPresent());
- MockComponent mockObj = mock(MockComponent.class);
- ((UpgradeAction<MockComponent>) action.get()).execute(mockObj);
- verify(mockObj, times(1)).mockMethodScm();
- verify(mockObj, times(0)).mockMethodDn();
-
- dnAction = DATANODE_SCHEMA_V2.datanodeAction();
- assertTrue(dnAction.isPresent());
- assertEquals(MockDnUpgradeAction.class, dnAction.get().getClass());
- assertFalse(DATANODE_SCHEMA_V2.scmAction().isPresent());
- mockObj = mock(MockComponent.class);
- ((UpgradeAction<MockComponent>) dnAction.get()).execute(mockObj);
- verify(mockObj, times(0)).mockMethodScm();
- verify(mockObj, times(1)).mockMethodDn();
- }
-
- @Test
- public void testHDDSLayoutFeaturesHaveIncreasingLayoutVersion() {
- HDDSLayoutFeature[] values = HDDSLayoutFeature.values();
- int currVersion = -1;
- for (HDDSLayoutFeature lf : values) {
- assertEquals(currVersion + 1, lf.layoutVersion());
- currVersion = lf.layoutVersion();
- }
- }
-}
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/InjectedUpgradeFinalizationExecutor.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/InjectedUpgradeFinalizationExecutor.java
deleted file mode 100644
index 510d1f3aa07..00000000000
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/InjectedUpgradeFinalizationExecutor.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.upgrade;
-
-import static
org.apache.hadoop.ozone.upgrade.InjectedUpgradeFinalizationExecutor.UpgradeTestInjectionPoints.AFTER_COMPLETE_FINALIZATION;
-import static
org.apache.hadoop.ozone.upgrade.InjectedUpgradeFinalizationExecutor.UpgradeTestInjectionPoints.AFTER_POST_FINALIZE_UPGRADE;
-import static
org.apache.hadoop.ozone.upgrade.InjectedUpgradeFinalizationExecutor.UpgradeTestInjectionPoints.AFTER_PRE_FINALIZE_UPGRADE;
-import static
org.apache.hadoop.ozone.upgrade.InjectedUpgradeFinalizationExecutor.UpgradeTestInjectionPoints.BEFORE_PRE_FINALIZE_UPGRADE;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_REQUIRED;
-
-import java.io.IOException;
-import java.util.concurrent.Callable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Failure injected extension of DefaultUpgradeFinalizationExecutor that
- * can be used by Unit/Integration Tests.
- */
-public class InjectedUpgradeFinalizationExecutor<T> extends
- DefaultUpgradeFinalizationExecutor<T> {
- static final Logger LOG =
- LoggerFactory.getLogger(InjectedUpgradeFinalizationExecutor.class);
-
- private Callable<Boolean> injectTestFunction;
- private UpgradeTestInjectionPoints testInjectionPoint;
-
- /**
- * Enum to denote failure injection points in finalization.
- */
- public enum UpgradeTestInjectionPoints {
- BEFORE_PRE_FINALIZE_UPGRADE(1),
- AFTER_PRE_FINALIZE_UPGRADE(2),
- AFTER_COMPLETE_FINALIZATION(4),
- AFTER_POST_FINALIZE_UPGRADE(5);
-
- private int val;
- UpgradeTestInjectionPoints(int value) {
- val = value;
- }
-
- public int getValue() {
- return val;
- }
- }
-
- static class UpgradeTestInjectionAbort extends Exception {
- UpgradeTestInjectionAbort() {
- }
- }
-
- @Override
- public void execute(T component, BasicUpgradeFinalizer<T, ?> finalizer)
- throws IOException {
- try {
- injectTestFunctionAtThisPoint(BEFORE_PRE_FINALIZE_UPGRADE);
- finalizer.emitStartingMsg();
-
- finalizer.preFinalizeUpgrade(component);
- injectTestFunctionAtThisPoint(AFTER_PRE_FINALIZE_UPGRADE);
-
- super.finalizeFeatures(component, finalizer,
- finalizer.getVersionManager().unfinalizedFeatures());
- injectTestFunctionAtThisPoint(AFTER_COMPLETE_FINALIZATION);
-
- finalizer.postFinalizeUpgrade(component);
- injectTestFunctionAtThisPoint(AFTER_POST_FINALIZE_UPGRADE);
-
- finalizer.emitFinishedMsg();
- } catch (Exception e) {
- LOG.warn("Upgrade Finalization failed with following Exception.", e);
- if (finalizer.getVersionManager().needsFinalization()) {
- finalizer.getVersionManager()
- .setUpgradeState(FINALIZATION_REQUIRED);
- }
- } finally {
- finalizer.markFinalizationDone();
- }
- }
-
- /**
- * Interface to inject arbitrary failures for stress testing.
- * @param injectedTestFunction that will be called
- * code execution reached injectTestFunctionAtThisPoint() location.
- * @param pointIndex code execution point for a given thread.
- */
- public void configureTestInjectionFunction(
- UpgradeTestInjectionPoints pointIndex,
- Callable<Boolean> injectedTestFunction) {
- injectTestFunction = injectedTestFunction;
- testInjectionPoint = pointIndex;
- }
-
- /**
- * Interface to inject error at a given point in an upgrade thread.
- * @param pointIndex TestFunction Injection point in an upgrade thread.
- * @return "true" if the calling thread should not continue with further
- * upgrade processing, "false" otherwise.
- */
- public void injectTestFunctionAtThisPoint(
- UpgradeTestInjectionPoints pointIndex) throws Exception {
- if ((testInjectionPoint != null) &&
- (pointIndex.getValue() == testInjectionPoint.getValue()) &&
- (injectTestFunction != null) && injectTestFunction.call()) {
- throw new UpgradeTestInjectionAbort();
- }
- return;
- }
-}
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestAbstractLayoutVersionManager.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestAbstractLayoutVersionManager.java
deleted file mode 100644
index 6cd9391e28f..00000000000
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestAbstractLayoutVersionManager.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.upgrade;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.io.IOException;
-import java.lang.management.ManagementFactory;
-import java.util.Iterator;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import org.apache.hadoop.hdds.ComponentVersion;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.MockitoAnnotations;
-import org.mockito.Spy;
-
-/**
- * Test generic layout management init and APIs.
- */
-public class TestAbstractLayoutVersionManager {
-
- @Spy
- private AbstractLayoutVersionManager<LayoutFeature> versionManager;
-
- @BeforeEach
- public void setup() {
- MockitoAnnotations.initMocks(this);
- }
-
- @AfterEach
- public void close() {
- versionManager.close();
- }
-
- @Test
- public void testInitializationWithFeaturesToBeFinalized() throws Exception {
- versionManager.init(1, getTestLayoutFeatures(3));
-
- assertEquals(3, versionManager.features.size());
-
- assertEquals(1, versionManager.getMetadataLayoutVersion());
- assertEquals(3, versionManager.getSoftwareLayoutVersion());
-
- assertTrue(versionManager.needsFinalization());
-
- Iterator<LayoutFeature> it =
- versionManager.unfinalizedFeatures().iterator();
- assertNotNull(it.next());
- assertNotNull(it.next());
- }
-
- @Test
- public void testInitializationWithUpToDateMetadataVersion() throws Exception
{
- versionManager.init(2, getTestLayoutFeatures(2));
-
- assertEquals(2, versionManager.features.size());
-
- assertEquals(2, versionManager.getMetadataLayoutVersion());
- assertEquals(2, versionManager.getSoftwareLayoutVersion());
-
- assertFalse(versionManager.needsFinalization());
- assertFalse(versionManager.unfinalizedFeatures().iterator().hasNext());
- }
-
- @Test
- public void testInitFailsIfNotEnoughLayoutFeaturesForVersion() {
-
- assertThrowsExactly(IOException.class,
- () -> versionManager.init(3, getTestLayoutFeatures(2)),
- "Cannot initialize VersionManager.");
- }
-
- @Test
- public void testFeatureFinalization() throws Exception {
- LayoutFeature[] lfs = getTestLayoutFeatures(3);
- versionManager.init(1, lfs);
-
- versionManager.finalized(lfs[1]);
-
- assertEquals(3, versionManager.features.size());
-
- assertEquals(2, versionManager.getMetadataLayoutVersion());
- assertEquals(3, versionManager.getSoftwareLayoutVersion());
-
- assertTrue(versionManager.needsFinalization());
-
- Iterator<LayoutFeature> it =
- versionManager.unfinalizedFeatures().iterator();
- assertNotNull(it.next());
- assertFalse(it.hasNext());
- }
-
- @Test
- public void testFeatureFinalizationFailsIfTheFinalizedFeatureIsNotTheNext()
- throws IOException {
- LayoutFeature[] lfs = getTestLayoutFeatures(3);
- versionManager.init(1, lfs);
-
- assertThrows(IllegalArgumentException.class,
- () -> versionManager.finalized(lfs[2]));
- }
-
- @Test
- public void testFeatureFinalizationIfFeatureIsAlreadyFinalized()
- throws IOException {
- /*
- * Feature finalization call is idempotent, it should not have any
- * side effects even if it's executed again.
- */
- LayoutFeature[] lfs = getTestLayoutFeatures(3);
- versionManager.init(2, lfs);
- assertEquals(2, versionManager.getMetadataLayoutVersion());
- versionManager.finalized(lfs[0]);
- assertEquals(2, versionManager.getMetadataLayoutVersion());
- versionManager.finalized(lfs[1]);
- assertEquals(2, versionManager.getMetadataLayoutVersion());
- }
-
- @Test
- public void testUnfinalizedFeaturesAreNotAllowed() throws Exception {
- LayoutFeature[] lfs = getTestLayoutFeatures(3);
- versionManager.init(1, lfs);
-
- assertTrue(versionManager.isAllowed(lfs[0]));
-
- assertFalse(versionManager.isAllowed(lfs[1]));
- assertFalse(versionManager.isAllowed(lfs[2]));
-
- versionManager.finalized(lfs[1]);
-
- assertTrue(versionManager.isAllowed(lfs[0]));
- assertTrue(versionManager.isAllowed(lfs[1]));
-
- assertFalse(versionManager.isAllowed(lfs[2]));
- }
-
- @Test
- public void testJmx() throws Exception {
- final int numLayoutFeatures = 3;
- final int metadataLayoutVersion = 1;
- versionManager.init(metadataLayoutVersion,
- getTestLayoutFeatures(numLayoutFeatures));
-
- MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- ObjectName bean = new ObjectName(
- "Hadoop:service=LayoutVersionManager," +
- "name=" + versionManager.getClass().getSimpleName());
-
- Object mlv = mbs.getAttribute(bean, "MetadataLayoutVersion");
- assertEquals(metadataLayoutVersion, mlv);
- Object slv = mbs.getAttribute(bean, "SoftwareLayoutVersion");
- assertEquals(numLayoutFeatures, slv);
- }
-
- private LayoutFeature[] getTestLayoutFeatures(int num) {
- LayoutFeature[] lfs = new LayoutFeature[num];
- int k = 0;
- for (int i = 1; i <= num; i++) {
- int finalI = i;
- lfs[k++] = new LayoutFeature() {
- @Override
- public int layoutVersion() {
- return finalI;
- }
-
- @Override
- public String description() {
- return null;
- }
-
- @Override
- public ComponentVersion nextVersion() {
- // TODO HDDS-14826 will remove this test. No need to add handling
for this new method.
- return null;
- }
- };
- }
- return lfs;
- }
-
-}
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestBasicUpgradeFinalizer.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestBasicUpgradeFinalizer.java
deleted file mode 100644
index 29cac62fbb2..00000000000
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestBasicUpgradeFinalizer.java
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.upgrade;
-
-import static
org.apache.hadoop.ozone.upgrade.TestUpgradeFinalizerActions.MockLayoutFeature.VERSION_1;
-import static
org.apache.hadoop.ozone.upgrade.TestUpgradeFinalizerActions.MockLayoutFeature.VERSION_3;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.ALREADY_FINALIZED;
-import static
org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_DONE;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-import static org.mockito.Mockito.anyString;
-import static org.mockito.Mockito.doCallRealMethod;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.inOrder;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import org.apache.hadoop.ozone.common.Storage;
-import
org.apache.hadoop.ozone.upgrade.InjectedUpgradeFinalizationExecutor.UpgradeTestInjectionPoints;
-import
org.apache.hadoop.ozone.upgrade.TestUpgradeFinalizerActions.MockLayoutVersionManager;
-import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.StatusAndMessages;
-import org.junit.jupiter.api.Test;
-import org.mockito.InOrder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Test for BasicUpgradeFinalizer.
- */
-public class TestBasicUpgradeFinalizer {
-
- private static final Logger LOG =
- LoggerFactory.getLogger(TestBasicUpgradeFinalizer.class);
-
- @Test
- public void testFinalizerPhasesAreInvokedInOrder() throws IOException {
- SimpleTestFinalizer finalizer = spy(SimpleTestFinalizer.class);
- InOrder inOrder = inOrder(finalizer);
-
- Object mockObj = mock(Object.class);
- doCallRealMethod().when(finalizer).finalize(anyString(),
- eq(mockObj));
-
- finalizer.finalize("test-client-1", mockObj);
-
- StatusAndMessages res = finalizer.reportStatus("test-client-1", false);
- assertEquals(FINALIZATION_DONE, res.status());
-
- inOrder.verify(finalizer).preFinalizeUpgrade(eq(mockObj));
- inOrder.verify(finalizer).finalizeLayoutFeature(
- eq(
- TestUpgradeFinalizerActions.MockLayoutFeature.VERSION_2),
- eq(mockObj));
- inOrder.verify(finalizer).finalizeLayoutFeature(
- eq(
- TestUpgradeFinalizerActions.MockLayoutFeature.VERSION_3),
- eq(mockObj));
- inOrder.verify(finalizer).postFinalizeUpgrade(eq(mockObj));
-
- assertTrue(finalizer.isFinalizationDone());
- assertTrue(finalizer.preCalled && finalizer.finalizeCalled &&
- finalizer.postCalled);
- }
-
- @Test
- public void testAlreadyFinalizedDoesNotTriggerNewFinalization()
- throws IOException {
- SimpleTestFinalizer finalizer = new SimpleTestFinalizer(
- new MockLayoutVersionManager(VERSION_3.layoutVersion()));
-
- Object mockObj = mock(Object.class);
- StatusAndMessages res =
- finalizer.finalize("test-client-1", mockObj);
-
- // TODO this test class will be removed with BasicUpgradeFinalizer when
all components are migrated to the new
- // version framework.
- assertEquals(ALREADY_FINALIZED, res.status());
- assertFalse(finalizer.preCalled || finalizer.finalizeCalled ||
- finalizer.postCalled);
- }
-
-
- /**
- * Tests that the upgrade finalizer gives expected statuses when multiple
- * clients invoke finalize and query finalize status simultaneously.
- * @throws Exception
- */
- @Test
- public void testConcurrentFinalization() throws Exception {
- CountDownLatch pauseLatch = new CountDownLatch(1);
- CountDownLatch unpauseLatch = new CountDownLatch(1);
- // Pause finalization to test concurrent finalize requests. The injection
- // point to pause at does not matter.
- InjectedUpgradeFinalizationExecutor<Object> executor =
- UpgradeTestUtils.newPausingFinalizationExecutor(
- UpgradeTestInjectionPoints.AFTER_PRE_FINALIZE_UPGRADE,
- pauseLatch, unpauseLatch, LOG);
- SimpleTestFinalizer finalizer =
- new SimpleTestFinalizer(
- new MockLayoutVersionManager(VERSION_1.layoutVersion()), executor);
-
- // The first finalize call should block until the executor is unpaused.
- Future<?> firstFinalizeFuture = runFinalization(finalizer,
- UpgradeFinalization.Status.STARTING_FINALIZATION);
- // Wait for finalization to pause at the halting point.
- pauseLatch.await();
-
- Future<?> secondFinalizeFuture = runFinalization(finalizer,
- UpgradeFinalization.Status.FINALIZATION_IN_PROGRESS);
- Future<?> finalizeQueryFuture = runFinalizationQuery(finalizer,
- UpgradeFinalization.Status.FINALIZATION_IN_PROGRESS);
-
- // While finalization is paused, the two following requests should have
- // reported it is in progress.
- secondFinalizeFuture.get();
- finalizeQueryFuture.get();
-
- // Now resume finalization so the initial finalize request can complete.
- unpauseLatch.countDown();
- firstFinalizeFuture.get();
-
- // All subsequent queries should return finalization done, even if they
- // land in parallel.
- List<Future<?>> finalizeFutures = new ArrayList<>();
- for (int i = 0; i < 10; i++) {
- finalizeFutures.add(runFinalizationQuery(finalizer,
- UpgradeFinalization.Status.FINALIZATION_DONE));
- }
-
- // Wait for all queries to complete.
- for (Future<?> finalizeFuture: finalizeFutures) {
- finalizeFuture.get();
- }
- }
-
- private Future<?> runFinalization(
- BasicUpgradeFinalizer<Object, MockLayoutVersionManager> finalizer,
- UpgradeFinalization.Status expectedStatus) {
- return Executors.newSingleThreadExecutor().submit(() -> {
- try {
- StatusAndMessages result = finalizer.finalize("test", new Object());
- assertEquals(expectedStatus, result.status());
- } catch (Exception ex) {
- LOG.error("Finalization failed", ex);
- fail("Finalization failed with exception: " +
- ex.getMessage());
- }
- });
- }
-
- private Future<?> runFinalizationQuery(UpgradeFinalizer<Object> finalizer,
- UpgradeFinalization.Status expectedStatus) {
- return Executors.newSingleThreadExecutor().submit(() -> {
- assertEquals(expectedStatus, finalizer.getStatus());
- });
- }
-
- /**
- * Yet another mock finalizer.
- */
- static class SimpleTestFinalizer extends BasicUpgradeFinalizer<Object,
- MockLayoutVersionManager> {
-
- private boolean preCalled = false;
- private boolean finalizeCalled = false;
- private boolean postCalled = false;
-
- /**
- * Invoked by Mockito.
- */
- SimpleTestFinalizer() throws IOException {
- super(new MockLayoutVersionManager(VERSION_1.layoutVersion()));
- }
-
- SimpleTestFinalizer(MockLayoutVersionManager lvm) {
- super(lvm);
- }
-
- SimpleTestFinalizer(MockLayoutVersionManager lvm,
- UpgradeFinalizationExecutor<Object> executor) {
- super(lvm, executor);
- }
-
- @Override
- protected void preFinalizeUpgrade(Object service) throws IOException {
- super.preFinalizeUpgrade(service);
- preCalled = true;
- }
-
- @Override
- protected void postFinalizeUpgrade(Object service) throws IOException {
- super.postFinalizeUpgrade(service);
- postCalled = true;
- }
-
- @Override
- public void finalizeLayoutFeature(LayoutFeature lf, Object service)
- throws UpgradeException {
- Storage mockStorage = mock(Storage.class);
- InOrder inOrder = inOrder(mockStorage);
-
- super.finalizeLayoutFeature(lf, lf.action(), mockStorage);
-
- inOrder.verify(mockStorage).setApparentVersion(eq(lf.layoutVersion()));
- try {
- inOrder.verify(mockStorage).persistCurrentState();
- } catch (IOException ex) {
- throw new UpgradeException(ex,
- UpgradeException.ResultCodes.UPGRADE_FINALIZATION_FAILED);
- }
- finalizeCalled = true;
- }
- }
-}
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestDefaultUpgradeFinalizationExecutor.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestDefaultUpgradeFinalizationExecutor.java
deleted file mode 100644
index 04460cfda84..00000000000
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestDefaultUpgradeFinalizationExecutor.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.upgrade;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import org.junit.jupiter.api.Test;
-
-/**
- * Test for DefaultUpgradeFinalizationExecutor.
- */
-public class TestDefaultUpgradeFinalizationExecutor {
-
- @Test
- public void testPreFinalizeFailureThrowsException() {
- AbstractLayoutVersionManager mockLvm =
- mock(AbstractLayoutVersionManager.class);
- when(mockLvm.needsFinalization()).thenReturn(true);
-
- BasicUpgradeFinalizer uf = new BasicUpgradeFinalizer(mockLvm) {
- @Override
- protected void preFinalizeUpgrade(Object service) throws IOException {
- throw new IOException("Failure!");
- }
-
- @Override
- protected void postFinalizeUpgrade(Object service) {
- }
-
- @Override
- public void finalizeLayoutFeature(LayoutFeature layoutFeatture,
- Object service) {
- }
- };
-
- DefaultUpgradeFinalizationExecutor executor =
- new DefaultUpgradeFinalizationExecutor();
- IOException ioException = assertThrows(IOException.class,
- () -> executor.execute(new Object(), uf));
- assertEquals("Failure!", ioException.getMessage());
- }
-
- @Test
- public void testPostFinalizeFailureDoesNotThrowException() throws Exception {
- AbstractLayoutVersionManager mockLvm =
- mock(AbstractLayoutVersionManager.class);
- when(mockLvm.needsFinalization()).thenReturn(false);
-
- BasicUpgradeFinalizer uf =
- new BasicUpgradeFinalizer(mockLvm) {
- @Override
- protected void preFinalizeUpgrade(Object service) {
- }
-
- @Override
- protected void postFinalizeUpgrade(Object service)
- throws IOException {
- throw new IOException("Failure!");
- }
-
- @Override
- public void finalizeLayoutFeature(LayoutFeature lf, Object service) {
- }
- };
-
- DefaultUpgradeFinalizationExecutor executor =
- new DefaultUpgradeFinalizationExecutor();
- executor.execute(new Object(), uf);
- }
-}
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestUpgradeFinalizerActions.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestUpgradeFinalizerActions.java
deleted file mode 100644
index 205d8c3c87d..00000000000
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/TestUpgradeFinalizerActions.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.ozone.upgrade;
-
-import java.io.IOException;
-
-/**
- * Class to test upgrade related actions.
- */
-public class TestUpgradeFinalizerActions {
-
- static class MockComponent {
- public void mockMethodScm() {
- }
-
- public void mockMethodDn() {
- }
- }
-
- static class MockLayoutVersionManager extends
- AbstractLayoutVersionManager<MockLayoutFeature> {
-
- MockLayoutVersionManager(int lV) throws IOException {
- init(lV, MockLayoutFeature.values());
- }
- }
-
- /**
- * Mock Layout Feature list.
- */
- enum MockLayoutFeature implements LayoutFeature {
- VERSION_1(1),
- VERSION_2(2),
- VERSION_3(3);
-
- private int layoutVersion;
-
- MockLayoutFeature(final int layoutVersion) {
- this.layoutVersion = layoutVersion;
- }
-
- @Override
- public int layoutVersion() {
- return layoutVersion;
- }
-
- @Override
- public String description() {
- return null;
- }
-
- @Override
- public MockLayoutFeature nextVersion() {
- // TODO HDDS-14826 will remove the tests that are using this. No need to
provide an implementation for this new
- // method.
- return null;
- }
-
- @Override
- public String toString() {
- return name() + " (" + serialize() + ")";
- }
- }
-}
diff --git
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/UpgradeTestUtils.java
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/UpgradeTestUtils.java
index dc1dbc104df..5413cba3f0a 100644
---
a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/UpgradeTestUtils.java
+++
b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/ozone/upgrade/UpgradeTestUtils.java
@@ -22,11 +22,8 @@
import java.io.IOException;
import java.util.Properties;
import java.util.UUID;
-import java.util.concurrent.CountDownLatch;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.apache.hadoop.ozone.common.StorageInfo;
-import
org.apache.hadoop.ozone.upgrade.InjectedUpgradeFinalizationExecutor.UpgradeTestInjectionPoints;
-import org.slf4j.Logger;
/**
* Upgrade related test utility methods.
@@ -65,35 +62,4 @@ public static File createVersionFile(File parentDir,
return versionFile;
}
-
- /**
- * @param haltingPoint Where to halt finalization in the returned
- * executor's {@code execute} method.
- * @param pauseLatch The latch that will be counted down 1 by the
- * executor when the upgrade finalization has been paused.
- * @param unpauseLatch The latch that the caller should count down to
- * resume upgrade finalization.
- * @param log Where to log messages about pausing and resuming finalization.
- * @return A new InjectedUpgradeFinalizationExecutor
- */
- public static <T> InjectedUpgradeFinalizationExecutor<T>
- newPausingFinalizationExecutor(UpgradeTestInjectionPoints haltingPoint,
- CountDownLatch pauseLatch, CountDownLatch unpauseLatch, Logger log) {
- InjectedUpgradeFinalizationExecutor<T>
- executor = new InjectedUpgradeFinalizationExecutor<>();
- executor.configureTestInjectionFunction(haltingPoint, () -> {
- log.info("Halting upgrade finalization at point: {}", haltingPoint);
- try {
- pauseLatch.countDown();
- unpauseLatch.await();
- } catch (InterruptedException ex) {
- Thread.currentThread().interrupt();
- throw new IOException("SCM test finalization interrupted.", ex);
- }
- log.info("Upgrade finalization resumed from point: {}", haltingPoint);
- return false;
- });
-
- return executor;
- }
}
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DatanodeInfo.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DatanodeInfo.java
index c2410fc6848..54e996ec3bf 100644
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DatanodeInfo.java
+++
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/node/DatanodeInfo.java
@@ -111,7 +111,6 @@ public void updateLastHeartbeatTime(long
milliSecondsSinceEpoch) {
/**
* Updates the last known apparent and software versions for this datanode.
- * Updates the last known version reported by this datanode.
*/
public void updateLastKnownVersions(LayoutVersionProto version) {
if (version == null) {
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationManagerImpl.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationManagerImpl.java
index f02a8231d54..c1c26a8cb6b 100644
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationManagerImpl.java
+++
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationManagerImpl.java
@@ -17,7 +17,6 @@
package org.apache.hadoop.hdds.scm.server.upgrade;
-import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.util.Objects;
import org.apache.hadoop.hdds.scm.ha.SCMHAManager;
@@ -26,18 +25,9 @@
/**
* Class to initiate SCM finalization and query its progress.
*/
-public class FinalizationManagerImpl implements FinalizationManager {
+public final class FinalizationManagerImpl implements FinalizationManager {
private final FinalizationStateManager finalizationStateManager;
- /**
- * For test classes to inject their own state manager.
- */
- @VisibleForTesting
- protected FinalizationManagerImpl(Builder builder,
- FinalizationStateManager stateManager) throws IOException {
- this.finalizationStateManager = stateManager;
- }
-
private FinalizationManagerImpl(Builder builder) throws IOException {
this.finalizationStateManager = new FinalizationStateManagerImpl.Builder()
.setFinalizationStore(builder.finalizationStore)
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationStateManager.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationStateManager.java
index 0b8d550ab34..07c46f8f1b2 100644
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationStateManager.java
+++
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationStateManager.java
@@ -32,17 +32,6 @@ public interface FinalizationStateManager extends SCMHandler
{
@Replicate
void finalizeUpgrade() throws IOException;
- /**
- * Legacy layout-feature finalization API. Retained until obsolete finalizer
classes are removed.
- */
- @Replicate
- void finalizeLayoutFeatures(Integer toLayoutVersion) throws IOException;
-
- /**
- * Legacy finalization context. Retained until obsolete finalizer classes
are removed.
- */
- void setUpgradeContext(SCMUpgradeFinalizationContext context);
-
/**
* Called on snapshot installation.
*/
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationStateManagerImpl.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationStateManagerImpl.java
index 491e32c9582..db7bcad2de5 100644
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationStateManagerImpl.java
+++
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/FinalizationStateManagerImpl.java
@@ -51,17 +51,6 @@ public void finalizeUpgrade() throws IOException {
OzoneConsts.APPARENT_VERSION_KEY,
String.valueOf(versionManager.getApparentVersion().serialize()));
}
- @Override
- public void setUpgradeContext(SCMUpgradeFinalizationContext context) {
- // Retained for compile compatibility with SCMUpgradeFinalizer until it is
removed in a follow-up PR.
- }
-
- @Override
- public void finalizeLayoutFeatures(Integer toLayoutVersion) throws
IOException {
- throw new UnsupportedOperationException(
- "Layout feature finalization was removed; use finalizeUpgrade()
instead.");
- }
-
/**
* Called on snapshot installation, which is coordinated by Ratis.
*/
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/SCMUpgradeFinalizationContext.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/SCMUpgradeFinalizationContext.java
deleted file mode 100644
index 5d5b021f6f0..00000000000
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/SCMUpgradeFinalizationContext.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.hdds.scm.server.upgrade;
-
-import java.util.Objects;
-import org.apache.hadoop.hdds.scm.ha.SCMContext;
-import org.apache.hadoop.hdds.scm.node.NodeManager;
-import org.apache.hadoop.hdds.scm.server.SCMStorageConfig;
-
-/**
- * Provided to methods in the {@link SCMUpgradeFinalizer} to supply objects
- * needed to operate.
- */
-public final class SCMUpgradeFinalizationContext {
- private final NodeManager nodeManager;
- private final FinalizationStateManager finalizationStateManager;
- private final SCMStorageConfig storage;
- private final SCMContext scmContext;
-
- private SCMUpgradeFinalizationContext(Builder builder) {
- nodeManager = builder.nodeManager;
- finalizationStateManager = builder.finalizationStateManager;
- storage = builder.storage;
- scmContext = builder.scmContext;
- }
-
- public NodeManager getNodeManager() {
- return nodeManager;
- }
-
- public FinalizationStateManager getFinalizationStateManager() {
- return finalizationStateManager;
- }
-
- public SCMContext getSCMContext() {
- return scmContext;
- }
-
- public SCMStorageConfig getStorage() {
- return storage;
- }
-
- /**
- * Builds an {@link SCMUpgradeFinalizationContext}.
- */
- public static final class Builder {
- private NodeManager nodeManager;
- private FinalizationStateManager finalizationStateManager;
- private SCMStorageConfig storage;
- private SCMContext scmContext;
-
- public Builder() {
- }
-
- public Builder setSCMContext(SCMContext context) {
- this.scmContext = context;
- return this;
- }
-
- public Builder setNodeManager(NodeManager nodeManager) {
- this.nodeManager = nodeManager;
- return this;
- }
-
- public Builder setFinalizationStateManager(
- FinalizationStateManager finalizationStateManager) {
- this.finalizationStateManager = finalizationStateManager;
- return this;
- }
-
- public Builder setStorage(SCMStorageConfig storage) {
- this.storage = storage;
- return this;
- }
-
- public SCMUpgradeFinalizationContext build() {
- Objects.requireNonNull(scmContext, "scmContext == null");
- Objects.requireNonNull(nodeManager, "nodeManager == null");
- Objects.requireNonNull(storage, "storage == null");
- Objects.requireNonNull(finalizationStateManager,
"finalizationStateManager == null");
- return new SCMUpgradeFinalizationContext(this);
- }
- }
-}
diff --git
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/SCMUpgradeFinalizer.java
b/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/SCMUpgradeFinalizer.java
deleted file mode 100644
index fed89dc1621..00000000000
---
a/hadoop-hdds/server-scm/src/main/java/org/apache/hadoop/hdds/scm/server/upgrade/SCMUpgradeFinalizer.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.hdds.scm.server.upgrade;
-
-import java.io.IOException;
-import org.apache.hadoop.hdds.upgrade.HDDSLayoutFeature;
-import org.apache.hadoop.hdds.upgrade.HDDSLayoutVersionManager;
-import org.apache.hadoop.ozone.upgrade.BasicUpgradeFinalizer;
-import org.apache.hadoop.ozone.upgrade.LayoutFeature;
-import org.apache.hadoop.ozone.upgrade.UpgradeException;
-import org.apache.hadoop.ozone.upgrade.UpgradeFinalizationExecutor;
-
-/**
- * UpgradeFinalizer for the Storage Container Manager service.
- *
- * This class contains the actions to drive finalization on the leader SCM,
- * while followers are updated through replicated methods in
- * {@link FinalizationStateManager}.
- */
-public class SCMUpgradeFinalizer extends
- BasicUpgradeFinalizer<SCMUpgradeFinalizationContext,
- HDDSLayoutVersionManager> {
-
- public SCMUpgradeFinalizer(HDDSLayoutVersionManager versionManager,
- UpgradeFinalizationExecutor<SCMUpgradeFinalizationContext> executor) {
- super(versionManager, executor);
- }
-
- @Override
- public void finalizeLayoutFeature(LayoutFeature lf,
- SCMUpgradeFinalizationContext context) throws UpgradeException {
- throw new UnsupportedOperationException("FinalizeLayoutFeature is not
supported in this implemementation. " +
- "Please use finalizeLayoutFeatures instead.");
- }
-
- @Override
- public void finalizeLayoutFeatures(Iterable<LayoutFeature> features,
SCMUpgradeFinalizationContext context)
- throws UpgradeException {
- int lastLv = -1;
- for (LayoutFeature lf : features) {
- lastLv = lf.layoutVersion();
- }
- try {
- if (lastLv > -1) {
- // If there are no feature to finalize we just skip this and the
finalize operation is a noop.
- context.getFinalizationStateManager().finalizeLayoutFeatures(lastLv);
- } else {
- LOG.info("No layout features to finalize.");
- }
- } catch (IOException ex) {
- throw new UpgradeException(ex,
UpgradeException.ResultCodes.UPGRADE_FINALIZATION_FAILED);
- }
- }
-
- /**
- * Run on each SCM (leader and follower) when a layout feature is being
- * finalized to run its finalization actions, update the VERSION file.
- *
- * @param lf The layout feature that is being finalized.
- * @param context Supplier of objects needed to run the steps.
- * @throws UpgradeException
- */
- void replicatedFinalizationSteps(HDDSLayoutFeature lf,
- SCMUpgradeFinalizationContext context) throws UpgradeException {
- // Run upgrade actions and update VERSION file.
- super.finalizeLayoutFeature(lf,
- lf.scmAction(),
- context.getStorage());
- }
-}
diff --git
a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/upgrade/FinalizationManagerTestImpl.java
b/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/upgrade/FinalizationManagerTestImpl.java
deleted file mode 100644
index 4e92010d3d2..00000000000
---
a/hadoop-hdds/server-scm/src/test/java/org/apache/hadoop/hdds/scm/upgrade/FinalizationManagerTestImpl.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hadoop.hdds.scm.upgrade;
-
-import java.io.IOException;
-import org.apache.hadoop.hdds.scm.server.upgrade.FinalizationManager;
-import org.apache.hadoop.hdds.scm.server.upgrade.FinalizationManagerImpl;
-import org.apache.hadoop.hdds.scm.server.upgrade.FinalizationStateManager;
-
-/**
- * An implementation of {@link FinalizationManager} that supports injecting
- * the {@link FinalizationStateManager} for testing.
- */
-public class FinalizationManagerTestImpl extends FinalizationManagerImpl {
-
- public FinalizationManagerTestImpl(Builder builder) throws IOException {
- super(builder, builder.finalizationStateManager);
- }
-
- /**
- * Builds a {@link FinalizationManagerTestImpl}.
- */
- public static class Builder extends FinalizationManagerImpl.Builder {
- private FinalizationStateManager finalizationStateManager;
-
- public Builder setFinalizationStateManager(
- FinalizationStateManager stateManager) {
- this.finalizationStateManager = stateManager;
- return this;
- }
-
- @Override
- public FinalizationManagerTestImpl build() throws IOException {
- return new FinalizationManagerTestImpl(this);
- }
- }
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]