Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
public class RegisterValidatorProcessor extends AbstractProcessor {

public static final String ANNOTATION_SIMPLE_NAME = "RegisterValidator";
public static final String VERSION_CLASS_NAME = "org.apache.hadoop.ozone.Version";
public static final String VERSION_CLASS_NAME = "org.apache.hadoop.hdds.ComponentVersion";
public static final String REQUEST_PROCESSING_PHASE_CLASS_NAME = "org.apache.hadoop.ozone.om.request.validation" +
".RequestProcessingPhase";
public static final String APPLY_BEFORE_METHOD_NAME = "applyBefore";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public ContainerCommandResponseProto sendCommand(
futureHashMap = new HashMap<>();
if (!request.hasVersion()) {
ContainerCommandRequestProto.Builder builder = ContainerCommandRequestProto.newBuilder(request);
builder.setVersion(ClientVersion.CURRENT.toProtoValue());
builder.setVersion(ClientVersion.CURRENT.serialize());
request = builder.build();
}
for (DatanodeDetails dn : datanodeList) {
Expand Down Expand Up @@ -380,7 +380,7 @@ private XceiverClientReply sendCommandWithTraceIDAndRetry(
ContainerCommandRequestProto.newBuilder(request)
.setTraceID(TracingUtil.exportCurrentSpan());
if (!request.hasVersion()) {
builder.setVersion(ClientVersion.CURRENT.toProtoValue());
builder.setVersion(ClientVersion.CURRENT.serialize());
}
return sendCommandWithRetry(builder.build(), validators);
});
Expand Down Expand Up @@ -611,7 +611,7 @@ public XceiverClientReply sendCommandAsync(
ContainerCommandRequestProto.newBuilder(request)
.setTraceID(TracingUtil.exportCurrentSpan());
if (!request.hasVersion()) {
builder.setVersion(ClientVersion.CURRENT.toProtoValue());
builder.setVersion(ClientVersion.CURRENT.serialize());
}
XceiverClientReply asyncReply =
sendCommandAsync(builder.build(), pipeline.getFirstNode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private boolean allDataNodesSupportPiggybacking() {
for (DatanodeDetails dn : pipeline.getNodes()) {
LOG.debug("dn = {}, version = {}", dn, dn.getCurrentVersion());
if (dn.getCurrentVersion() <
COMBINED_PUTBLOCK_WRITECHUNK_RPC.toProtoValue()) {
COMBINED_PUTBLOCK_WRITECHUNK_RPC.serialize()) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private boolean allDataNodesSupportStreamBlock(Pipeline pipeline) {
// return true only if all DataNodes in the pipeline are on a version
// that supports for reading a block by streaming chunks..
for (DatanodeDetails dn : pipeline.getNodes()) {
if (dn.getCurrentVersion() < STREAM_BLOCK_SUPPORT.toProtoValue()) {
if (dn.getCurrentVersion() < STREAM_BLOCK_SUPPORT.serialize()) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public XceiverClientReply sendCommandAsync(ContainerCommandRequestProto request)

if (!request.hasVersion()) {
request = ContainerCommandRequestProto.newBuilder(request)
.setVersion(ClientVersion.CURRENT.toProtoValue()).build();
.setVersion(ClientVersion.CURRENT.serialize()).build();
}
final ContainerCommandResponseProto.Builder builder =
ContainerCommandResponseProto.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,21 @@

package org.apache.hadoop.hdds;

import org.apache.hadoop.ozone.Versioned;
import java.util.Optional;
import org.apache.hadoop.ozone.upgrade.UpgradeAction;

/**
* Base type for component version enums.
*/
public interface ComponentVersion extends Versioned {
public interface ComponentVersion {
int serialize();

/**
* Returns the description of the version enum value.
* @return the description of the version enum value.
*/
String description();

/**
* Returns the value that represents the enum in a protocol message
* transferred over the wire.
* @return the version associated with the enum value.
*/
int toProtoValue();

@Override
default int version() {
return toProtoValue();
default Optional<? extends UpgradeAction> action() {
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum HDDSVersion implements ComponentVersion {

private static final Map<Integer, HDDSVersion> BY_PROTO_VALUE =
Arrays.stream(values())
.collect(toMap(HDDSVersion::toProtoValue, identity()));
.collect(toMap(HDDSVersion::serialize, identity()));

private final int version;
private final String description;
Expand All @@ -60,10 +60,15 @@ public String description() {
}

@Override
public int toProtoValue() {
public int serialize() {
return version;
}

@Override
public String toString() {
return name() + " (" + serialize() + ")";
}

public static HDDSVersion fromProtoValue(int value) {
return BY_PROTO_VALUE.getOrDefault(value, FUTURE_VERSION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public static DatanodeDetails.Builder newBuilder(
builder.setCurrentVersion(datanodeDetailsProto.getCurrentVersion());
} else {
// fallback to version 1 if not present
builder.setCurrentVersion(HDDSVersion.SEPARATE_RATIS_PORTS_AVAILABLE.toProtoValue());
builder.setCurrentVersion(HDDSVersion.SEPARATE_RATIS_PORTS_AVAILABLE.serialize());
}
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static ContainerCommandRequestMessage toMessage(
b.setTraceID(traceId);
}
if (!request.hasVersion()) {
b.setVersion(ClientVersion.CURRENT.toProtoValue());
b.setVersion(ClientVersion.CURRENT.serialize());
}

ByteString data = ByteString.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public enum HDDSLayoutFeature implements LayoutFeature {

////////////////////////////// //////////////////////////////

private int layoutVersion;
private String description;
private final int layoutVersion;
private final String description;
private HDDSUpgradeAction scmAction;
private HDDSUpgradeAction datanodeAction;

Expand Down Expand Up @@ -90,6 +90,11 @@ public String description() {
return description;
}

@Override
public String toString() {
return name() + " (" + serialize() + ")";
}

public Optional<HDDSUpgradeAction> scmAction() {
return Optional.ofNullable(scmAction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package org.apache.hadoop.hdds.upgrade;

import org.apache.hadoop.ozone.upgrade.LayoutFeature.UpgradeAction;
import org.apache.hadoop.ozone.upgrade.UpgradeAction;

/**
* Upgrade Action for SCM and DataNodes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public enum ClientVersion implements ComponentVersion {

private static final Map<Integer, ClientVersion> BY_PROTO_VALUE =
Arrays.stream(values())
.collect(toMap(ClientVersion::toProtoValue, identity()));
.collect(toMap(ClientVersion::serialize, identity()));

private final int version;
private final String description;
Expand All @@ -66,17 +66,22 @@ public String description() {
}

@Override
public int toProtoValue() {
public int serialize() {
return version;
}

@Override
public String toString() {
return name() + " (" + serialize() + ")";
}

public static ClientVersion fromProtoValue(int value) {
return BY_PROTO_VALUE.getOrDefault(value, FUTURE_VERSION);
}

private static ClientVersion latest() {
return Arrays.stream(ClientVersion.values())
.max(Comparator.comparingInt(ComponentVersion::toProtoValue)).orElse(null);
.max(Comparator.comparingInt(ComponentVersion::serialize)).orElse(null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public enum OzoneManagerVersion implements ComponentVersion {

private static final Map<Integer, OzoneManagerVersion> BY_PROTO_VALUE =
Arrays.stream(values())
.collect(toMap(OzoneManagerVersion::toProtoValue, identity()));
.collect(toMap(OzoneManagerVersion::serialize, identity()));

private final int version;
private final String description;
Expand All @@ -78,10 +78,15 @@ public String description() {
}

@Override
public int toProtoValue() {
public int serialize() {
return version;
}

@Override
public String toString() {
return name() + " (" + serialize() + ")";
}

public static OzoneManagerVersion fromProtoValue(int value) {
return BY_PROTO_VALUE.getOrDefault(value, FUTURE_VERSION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,16 @@

package org.apache.hadoop.ozone.upgrade;

import java.util.Optional;
import org.apache.hadoop.ozone.Versioned;
import org.apache.hadoop.hdds.ComponentVersion;

/**
* Generic Layout feature interface for Ozone.
*/
public interface LayoutFeature extends Versioned {
String name();

public interface LayoutFeature extends ComponentVersion {
int layoutVersion();

String description();

default Optional<? extends UpgradeAction> action() {
return Optional.empty();
}

/**
* Generic UpgradeAction interface. An upgrade action is an operation that
* is run at least once as a pre-requisite to finalizing a layout feature.
* @param <T>
*/
interface UpgradeAction<T> {

default String name() {
return getClass().getSimpleName();
}

void execute(T arg) throws Exception;
}

@Override
default int version() {
default int serialize() {
return this.layoutVersion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
* limitations under the License.
*/

package org.apache.hadoop.ozone;
package org.apache.hadoop.ozone.upgrade;

/**
* Base class defining the version in the entire system.
* Generic UpgradeAction interface. An upgrade action is an operation that
* is run at least once as a pre-requisite to finalizing a layout feature.
* @param <T> action argument type
*/
public interface Versioned {
int version();
public interface UpgradeAction<T> {

default String name() {
return getClass().getSimpleName();
}

void execute(T arg) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testFutureVersionHasTheHighestOrdinal(
public void testFuturVersionHasMinusOneAsProtoRepresentation(
ComponentVersion[] values, ComponentVersion defaultValue,
ComponentVersion futureValue) {
assertEquals(-1, futureValue.toProtoValue());
assertEquals(-1, futureValue.serialize());

}

Expand All @@ -76,7 +76,7 @@ public void testFuturVersionHasMinusOneAsProtoRepresentation(
public void testDefaultVersionHasZeroAsProtoRepresentation(
ComponentVersion[] values, ComponentVersion defaultValue,
ComponentVersion futureValue) {
assertEquals(0, defaultValue.toProtoValue());
assertEquals(0, defaultValue.serialize());
}

// versions are increasing monotonically by one
Expand All @@ -85,10 +85,10 @@ public void testDefaultVersionHasZeroAsProtoRepresentation(
public void testAssignedProtoRepresentations(
ComponentVersion[] values, ComponentVersion defaultValue,
ComponentVersion futureValue) {
int startValue = defaultValue.toProtoValue();
int startValue = defaultValue.serialize();
// we skip the future version at the last position
for (int i = 0; i < values.length - 1; i++) {
assertEquals(values[i].toProtoValue(), startValue++);
assertEquals(values[i].serialize(), startValue++);
}
assertEquals(values.length, ++startValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ void protoIncludesNewPortsOnlyForV1() {
DatanodeDetails subject = MockDatanodeDetails.randomDatanodeDetails();

HddsProtos.DatanodeDetailsProto proto =
subject.toProto(DEFAULT_VERSION.toProtoValue());
subject.toProto(DEFAULT_VERSION.serialize());
assertPorts(proto, V0_PORTS);

HddsProtos.DatanodeDetailsProto protoV1 =
subject.toProto(VERSION_HANDLES_UNKNOWN_DN_PORTS.toProtoValue());
subject.toProto(VERSION_HANDLES_UNKNOWN_DN_PORTS.serialize());
assertPorts(protoV1, ALL_PORTS);
}

Expand All @@ -74,16 +74,16 @@ public void testNewBuilderCurrentVersion() {
Set<Port.Name> requiredPorts = Stream.of(Port.Name.STANDALONE, Port.Name.RATIS)
.collect(Collectors.toSet());
HddsProtos.DatanodeDetailsProto.Builder protoBuilder =
dn.toProtoBuilder(DEFAULT_VERSION.toProtoValue(), requiredPorts);
dn.toProtoBuilder(DEFAULT_VERSION.serialize(), requiredPorts);
protoBuilder.clearCurrentVersion();
DatanodeDetails dn2 = DatanodeDetails.newBuilder(protoBuilder.build()).build();
assertEquals(HDDSVersion.SEPARATE_RATIS_PORTS_AVAILABLE.toProtoValue(), dn2.getCurrentVersion());
assertEquals(HDDSVersion.SEPARATE_RATIS_PORTS_AVAILABLE.serialize(), dn2.getCurrentVersion());

// test that if the current version is set, it is used
protoBuilder =
dn.toProtoBuilder(DEFAULT_VERSION.toProtoValue(), requiredPorts);
dn.toProtoBuilder(DEFAULT_VERSION.serialize(), requiredPorts);
DatanodeDetails dn3 = DatanodeDetails.newBuilder(protoBuilder.build()).build();
assertEquals(HDDSVersion.CURRENT.toProtoValue(), dn3.getCurrentVersion());
assertEquals(HDDSVersion.CURRENT.serialize(), dn3.getCurrentVersion());
}

public static void assertPorts(HddsProtos.DatanodeDetailsProto dn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static ContainerCommandRequestProto newPutSmallFile(
.setContainerID(blockID.getContainerID())
.setDatanodeUuid(UUID.randomUUID().toString())
.setPutSmallFile(putSmallFileRequest)
.setVersion(ClientVersion.CURRENT.toProtoValue())
.setVersion(ClientVersion.CURRENT.serialize())
.build();
}

Expand All @@ -113,7 +113,7 @@ static ContainerCommandRequestProto newWriteChunk(
.setContainerID(blockID.getContainerID())
.setDatanodeUuid(UUID.randomUUID().toString())
.setWriteChunk(writeChunkRequest)
.setVersion(ClientVersion.CURRENT.toProtoValue())
.setVersion(ClientVersion.CURRENT.serialize())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public void protoIncludesNewPortsOnlyForV1() throws IOException {
Pipeline subject = MockPipeline.createPipeline(3);

HddsProtos.Pipeline proto =
subject.getProtobufMessage(DEFAULT_VERSION.toProtoValue());
subject.getProtobufMessage(DEFAULT_VERSION.serialize());
for (HddsProtos.DatanodeDetailsProto dn : proto.getMembersList()) {
assertPorts(dn, V0_PORTS);
}

HddsProtos.Pipeline protoV1 = subject.getProtobufMessage(
VERSION_HANDLES_UNKNOWN_DN_PORTS.toProtoValue());
VERSION_HANDLES_UNKNOWN_DN_PORTS.serialize());
for (HddsProtos.DatanodeDetailsProto dn : protoV1.getMembersList()) {
assertPorts(dn, ALL_PORTS);
}
Expand Down
Loading
Loading