Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import org.apache.hadoop.hdds.scm.container.ReplicationManagerReport;
import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.StatusAndMessages;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.StatusAndMessages;

/**
* The interface to call into underlying container layer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.apache.hadoop.hdds.scm.container.ReplicationManagerReport;
import org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline;
import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.StatusAndMessages;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.StatusAndMessages;
import org.apache.hadoop.security.KerberosInfo;
import org.apache.hadoop.security.token.Token;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* 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.util.Collection;
import java.util.Collections;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.hdds.annotation.InterfaceStability;

/** Client-side interface of upgrade finalization. */
@InterfaceAudience.Private
@InterfaceStability.Evolving
public final class UpgradeFinalization {

/**
* Default message can be used to indicate the starting of finalization.
*/
public static final StatusAndMessages STARTING_MSG = new StatusAndMessages(
Status.STARTING_FINALIZATION,
Collections.singletonList("Starting Finalization")
);

public static final StatusAndMessages FINALIZATION_IN_PROGRESS_MSG = new StatusAndMessages(
Status.FINALIZATION_IN_PROGRESS,
Collections.singletonList("Finalization in progress")
);

public static final StatusAndMessages FINALIZATION_REQUIRED_MSG = new StatusAndMessages(
Status.FINALIZATION_REQUIRED,
Collections.singletonList("Finalization required")
);

/**
* Default message to provide when the service is in ALREADY_FINALIZED state.
*/
public static final StatusAndMessages FINALIZED_MSG = new StatusAndMessages(
Status.ALREADY_FINALIZED, Collections.emptyList()
);

/**
* Represents the current state in which the service is with regards to
* finalization after an upgrade.
* The state transitions are the following:
* {@code ALREADY_FINALIZED} - no entry no exit from this status without restart.
* After an upgrade:
* {@code FINALIZATION_REQUIRED -(finalize)-> STARTING_FINALIZATION
* -> FINALIZATION_IN_PROGRESS -> FINALIZATION_DONE} from finalization done
* there is no more move possible, after a restart the service can end up in:
* {@code FINALIZATION_REQUIRED}, if the finalization failed and have not reached
* {@code FINALIZATION_DONE},
* - or it can be {@code ALREADY_FINALIZED} if the finalization was successfully done.
*/
public enum Status {
ALREADY_FINALIZED,
STARTING_FINALIZATION,
FINALIZATION_IN_PROGRESS,
FINALIZATION_DONE,
FINALIZATION_REQUIRED,
}

/**
* A class that holds the current service status, and if the finalization is
* ongoing, the messages that should be passed to the initiating client of
* finalization.
* This translates to a counterpart in the RPC layer.
*/
public static final class StatusAndMessages {
private final Status status;
private final Collection<String> msgs;

/**
* Constructs a StatusAndMessages tuple from the given params.
* @param status the finalization status of the service
* @param msgs the messages to be transferred to the client
*/
public StatusAndMessages(Status status, Collection<String> msgs) {
this.status = status;
this.msgs = msgs;
}

/**
* Provides the status.
* @return the upgrade finalization status.
*/
public Status status() {
return status;
}

/**
* Provides the messages, or an empty list if there are no messages.
* @return a list with possibly multiple messages.
*/
public Collection<String> msgs() {
return msgs;
}
}

private UpgradeFinalization() {
// no instances
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
import org.apache.hadoop.ozone.container.upgrade.DataNodeUpgradeFinalizer;
import org.apache.hadoop.ozone.container.upgrade.VersionedDatanodeFeatures;
import org.apache.hadoop.ozone.protocol.commands.SCMCommand;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.StatusAndMessages;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalizer;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.StatusAndMessages;
import org.apache.hadoop.util.Time;
import org.apache.ratis.util.ExitUtils;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.hadoop.ozone.container.common.statemachine.commandhandler;

import static org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.FINALIZATION_REQUIRED;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_REQUIRED;

import java.util.concurrent.atomic.AtomicLong;
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.FinalizeNewLayoutVersionCommandProto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.apache.hadoop.ozone.container.upgrade;

import static org.apache.hadoop.ozone.upgrade.UpgradeException.ResultCodes.PREFINALIZE_VALIDATION_FAILED;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.FINALIZATION_IN_PROGRESS;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.FINALIZATION_REQUIRED;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_IN_PROGRESS;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_REQUIRED;

import java.io.IOException;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
import org.apache.hadoop.ipc.ProtocolTranslator;
import org.apache.hadoop.ipc.RPC;
import org.apache.hadoop.ozone.ClientVersion;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalizer;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.StatusAndMessages;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalization;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.StatusAndMessages;
import org.apache.hadoop.ozone.util.ProtobufUtils;
import org.apache.hadoop.security.token.Token;

Expand Down Expand Up @@ -1135,7 +1135,7 @@ public StatusAndMessages finalizeScmUpgrade(String upgradeClientID)

UpgradeFinalizationStatus status = response.getStatus();
return new StatusAndMessages(
UpgradeFinalizer.Status.valueOf(status.getStatus().name()),
UpgradeFinalization.Status.valueOf(status.getStatus().name()),
status.getMessagesList());
}

Expand All @@ -1158,7 +1158,7 @@ public StatusAndMessages queryUpgradeFinalizationProgress(

UpgradeFinalizationStatus status = response.getStatus();
return new StatusAndMessages(
UpgradeFinalizer.Status.valueOf(status.getStatus().name()),
UpgradeFinalization.Status.valueOf(status.getStatus().name()),
status.getMessagesList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package org.apache.hadoop.ozone.upgrade;

import static org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.ALREADY_FINALIZED;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.FINALIZATION_REQUIRED;
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;
Expand All @@ -31,7 +31,7 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.management.ObjectName;
import org.apache.hadoop.metrics2.util.MBeans;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
import static org.apache.hadoop.ozone.upgrade.UpgradeException.ResultCodes.LAYOUT_FEATURE_FINALIZATION_FAILED;
import static org.apache.hadoop.ozone.upgrade.UpgradeException.ResultCodes.PREFINALIZE_ACTION_VALIDATION_FAILED;
import static org.apache.hadoop.ozone.upgrade.UpgradeException.ResultCodes.UPDATE_LAYOUT_VERSION_FAILED;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.FINALIZATION_DONE;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.FINALIZATION_IN_PROGRESS;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.FINALIZATION_REQUIRED;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.STARTING_FINALIZATION;
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;
Expand All @@ -44,6 +48,8 @@
import org.apache.hadoop.ozone.upgrade.LayoutFeature.UpgradeAction;
import org.apache.hadoop.ozone.upgrade.LayoutFeature.UpgradeActionType;
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.ratis.protocol.exceptions.NotLeaderException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.hadoop.ozone.upgrade;

import static org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.FINALIZATION_REQUIRED;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_REQUIRED;

import java.io.IOException;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
package org.apache.hadoop.ozone.upgrade;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.hdds.annotation.InterfaceStability;
import org.apache.hadoop.ozone.common.Storage;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status;
import org.apache.hadoop.ozone.upgrade.UpgradeFinalization.StatusAndMessages;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -44,89 +43,6 @@ public interface UpgradeFinalizer<T> {

Logger LOG = LoggerFactory.getLogger(UpgradeFinalizer.class);

/**
* Represents the current state in which the service is with regards to
* finalization after an upgrade.
* The state transitions are the following:
* {@code ALREADY_FINALIZED} - no entry no exit from this status without restart.
* After an upgrade:
* {@code FINALIZATION_REQUIRED -(finalize)-> STARTING_FINALIZATION
* -> FINALIZATION_IN_PROGRESS -> FINALIZATION_DONE} from finalization done
* there is no more move possible, after a restart the service can end up in:
* {@code FINALIZATION_REQUIRED}, if the finalization failed and have not reached
* {@code FINALIZATION_DONE},
* - or it can be {@code ALREADY_FINALIZED} if the finalization was successfully done.
*/
enum Status {
ALREADY_FINALIZED,
STARTING_FINALIZATION,
FINALIZATION_IN_PROGRESS,
FINALIZATION_DONE,
FINALIZATION_REQUIRED,
}

/**
* A class that holds the current service status, and if the finalization is
* ongoing, the messages that should be passed to the initiating client of
* finalization.
* This translates to a counterpart in the RPC layer.
*/
class StatusAndMessages {
private Status status;
private Collection<String> msgs;

/**
* Constructs a StatusAndMessages tuple from the given params.
* @param status the finalization status of the service
* @param msgs the messages to be transferred to the client
*/
public StatusAndMessages(Status status, Collection<String> msgs) {
this.status = status;
this.msgs = msgs;
}

/**
* Provides the status.
* @return the upgrade finalization status.
*/
public Status status() {
return status;
}

/**
* Provides the messages, or an empty list if there are no messages.
* @return a list with possibly multiple messages.
*/
public Collection<String> msgs() {
return msgs;
}
}

/**
* Default message can be used to indicate the starting of finalization.
*/
StatusAndMessages STARTING_MSG = new StatusAndMessages(
Status.STARTING_FINALIZATION,
Arrays.asList("Starting Finalization")
);

StatusAndMessages FINALIZATION_IN_PROGRESS_MSG = new StatusAndMessages(
Status.FINALIZATION_IN_PROGRESS,
Arrays.asList("Finalization in progress")
);

StatusAndMessages FINALIZATION_REQUIRED_MSG = new StatusAndMessages(
Status.FINALIZATION_REQUIRED,
Arrays.asList("Finalization required")
);

/**
* Default message to provide when the service is in ALREADY_FINALIZED state.
*/
StatusAndMessages FINALIZED_MSG = new StatusAndMessages(
Status.ALREADY_FINALIZED, Collections.emptyList()
);

/**
* Finalize the metadata upgrade.
* The provided client ID will be eligible to get the status messages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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.UpgradeFinalizer.Status.FINALIZATION_REQUIRED;
import static org.apache.hadoop.ozone.upgrade.UpgradeFinalization.Status.FINALIZATION_REQUIRED;

import java.io.IOException;
import java.util.concurrent.Callable;
Expand Down
Loading