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 @@ -49,6 +49,8 @@ public class DatanodeDetails extends NodeImpl implements
private String hostName;
private List<Port> ports;
private String certSerialId;
private HddsProtos.NodeOperationalState persistedOpState;
private long persistedOpStateExpiryEpochSec = 0;

/**
* Constructs DatanodeDetails instance. DatanodeDetails.Builder is used
Expand All @@ -59,15 +61,23 @@ public class DatanodeDetails extends NodeImpl implements
* @param networkLocation DataNode's network location path
* @param ports Ports used by the DataNode
* @param certSerialId serial id from SCM issued certificate.
* @param persistedOpState Operational State stored on DN.
* @param persistedOpStateExpiryEpochSec Seconds after the epoch the stored
* state should expire.
*/
@SuppressWarnings("checkstyle:ParameterNumber")
private DatanodeDetails(String uuid, String ipAddress, String hostName,
String networkLocation, List<Port> ports, String certSerialId) {
String networkLocation, List<Port> ports, String certSerialId,
HddsProtos.NodeOperationalState persistedOpState,
long persistedOpStateExpiryEpochSec) {
super(hostName, networkLocation, NetConstants.NODE_COST_DEFAULT);
this.uuid = UUID.fromString(uuid);
this.ipAddress = ipAddress;
this.hostName = hostName;
this.ports = ports;
this.certSerialId = certSerialId;
this.persistedOpState = persistedOpState;
this.persistedOpStateExpiryEpochSec = persistedOpStateExpiryEpochSec;
}

protected DatanodeDetails(DatanodeDetails datanodeDetails) {
Expand All @@ -78,6 +88,9 @@ protected DatanodeDetails(DatanodeDetails datanodeDetails) {
this.hostName = datanodeDetails.hostName;
this.ports = datanodeDetails.ports;
this.setNetworkName(datanodeDetails.getNetworkName());
this.persistedOpState = datanodeDetails.getPersistedOpState();
this.persistedOpStateExpiryEpochSec =
datanodeDetails.getPersistedOpStateExpiryEpochSec();
}

/**
Expand Down Expand Up @@ -155,6 +168,46 @@ public List<Port> getPorts() {
return ports;
}

/**
* Return the persistedOpState. If the stored value is null, return the
* default value of IN_SERVICE.
*
* @return The OperationalState persisted on the datanode.
*/
public HddsProtos.NodeOperationalState getPersistedOpState() {
if (persistedOpState == null) {
return HddsProtos.NodeOperationalState.IN_SERVICE;
} else {
return persistedOpState;
}
}

/**
* Set the persistedOpState for this instance.
*
* @param state The new operational state.
*/
public void setPersistedOpState(HddsProtos.NodeOperationalState state) {
this.persistedOpState = state;
}

/**
* Get the persistedOpStateExpiryEpochSec for the instance.
* @return Seconds from the epoch when the operational state should expire.
*/
public long getPersistedOpStateExpiryEpochSec() {
return persistedOpStateExpiryEpochSec;
}

/**
* Set persistedOpStateExpiryEpochSec.
* @param expiry The number of second after the epoch the operational state
* should expire.
*/
public void setPersistedOpStateExpiryEpochSec(long expiry) {
this.persistedOpStateExpiryEpochSec = expiry;
}

/**
* Given the name returns port number, null if the asked port is not found.
*
Expand Down Expand Up @@ -200,6 +253,13 @@ public static DatanodeDetails getFromProtoBuf(
if (datanodeDetailsProto.hasNetworkLocation()) {
builder.setNetworkLocation(datanodeDetailsProto.getNetworkLocation());
}
if (datanodeDetailsProto.hasPersistedOpState()) {
builder.setPersistedOpState(datanodeDetailsProto.getPersistedOpState());
}
if (datanodeDetailsProto.hasPersistedOpStateExpiry()) {
builder.setPersistedOpStateExpiry(
datanodeDetailsProto.getPersistedOpStateExpiry());
}
return builder.build();
}

Expand All @@ -226,6 +286,10 @@ public HddsProtos.DatanodeDetailsProto getProtoBufMessage() {
if (!Strings.isNullOrEmpty(getNetworkLocation())) {
builder.setNetworkLocation(getNetworkLocation());
}
if (persistedOpState != null) {
builder.setPersistedOpState(persistedOpState);
}
builder.setPersistedOpStateExpiry(persistedOpStateExpiryEpochSec);

for (Port port : ports) {
builder.addPorts(HddsProtos.Port.newBuilder()
Expand All @@ -246,6 +310,8 @@ public String toString() {
", networkLocation: " +
getNetworkLocation() +
", certSerialId: " + certSerialId +
", persistedOpState: " + persistedOpState +
", persistedOpStateExpiryEpochSec: " + persistedOpStateExpiryEpochSec +
"}";
}

Expand Down Expand Up @@ -285,6 +351,8 @@ public static final class Builder {
private String networkLocation;
private List<Port> ports;
private String certSerialId;
private HddsProtos.NodeOperationalState persistedOpState;
private long persistedOpStateExpiryEpochSec = 0;

/**
* Default private constructor. To create Builder instance use
Expand Down Expand Up @@ -373,6 +441,31 @@ public Builder setCertSerialId(String certId) {
return this;
}

/**
* Adds persistedOpState.
*
* @param state The operational state persisted on the datanode
*
* @return DatanodeDetails.Builder
*/
public Builder setPersistedOpState(HddsProtos.NodeOperationalState state) {
this.persistedOpState = state;
return this;
}

/**
* Adds persistedOpStateExpiryEpochSec.
*
* @param expiry The seconds after the epoch the operational state should
* expire.
*
* @return DatanodeDetails.Builder
*/
public Builder setPersistedOpStateExpiry(long expiry) {
this.persistedOpStateExpiryEpochSec = expiry;
return this;
}

/**
* Builds and returns DatanodeDetails instance.
*
Expand All @@ -384,7 +477,8 @@ public DatanodeDetails build() {
networkLocation = NetConstants.DEFAULT_RACK;
}
DatanodeDetails dn = new DatanodeDetails(id, ipAddress, hostName,
networkLocation, ports, certSerialId);
networkLocation, ports, certSerialId, persistedOpState,
persistedOpStateExpiryEpochSec);
if (networkName != null) {
dn.setNetworkName(networkName);
}
Expand Down
2 changes: 2 additions & 0 deletions hadoop-hdds/common/src/main/proto/hdds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ message DatanodeDetailsProto {
// network name, can be Ip address or host name, depends
optional string networkName = 6;
optional string networkLocation = 7; // Network topology location
optional NodeOperationalState persistedOpState = 8; // The Operational state persisted in the datanode.id file
optional int64 persistedOpStateExpiry = 9; // The seconds after the epoch when the OpState should expire
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;

Expand Down Expand Up @@ -82,6 +83,12 @@ public static DatanodeDetails readDatanodeIdFile(File path)
.setIpAddress(datanodeDetailsYaml.getIpAddress())
.setHostName(datanodeDetailsYaml.getHostName())
.setCertSerialId(datanodeDetailsYaml.getCertSerialId());
if (datanodeDetailsYaml.getPersistedOpState() != null) {
builder.setPersistedOpState(HddsProtos.NodeOperationalState.valueOf(
datanodeDetailsYaml.getPersistedOpState()));
}
builder.setPersistedOpStateExpiry(
datanodeDetailsYaml.getPersistedOpStateExpiryEpochSec());

if (!MapUtils.isEmpty(datanodeDetailsYaml.getPortDetails())) {
for (Map.Entry<String, Integer> portEntry :
Expand All @@ -105,6 +112,8 @@ public static class DatanodeDetailsYaml {
private String ipAddress;
private String hostName;
private String certSerialId;
private String persistedOpState;
private long persistedOpStateExpiryEpochSec = 0;
private Map<String, Integer> portDetails;

public DatanodeDetailsYaml() {
Expand All @@ -113,11 +122,15 @@ public DatanodeDetailsYaml() {

private DatanodeDetailsYaml(String uuid, String ipAddress,
String hostName, String certSerialId,
String persistedOpState,
long persistedOpStateExpiryEpochSec,
Map<String, Integer> portDetails) {
this.uuid = uuid;
this.ipAddress = ipAddress;
this.hostName = hostName;
this.certSerialId = certSerialId;
this.persistedOpState = persistedOpState;
this.persistedOpStateExpiryEpochSec = persistedOpStateExpiryEpochSec;
this.portDetails = portDetails;
}

Expand All @@ -137,6 +150,14 @@ public String getCertSerialId() {
return certSerialId;
}

public String getPersistedOpState() {
return persistedOpState;
}

public long getPersistedOpStateExpiryEpochSec() {
return persistedOpStateExpiryEpochSec;
}

public Map<String, Integer> getPortDetails() {
return portDetails;
}
Expand All @@ -157,6 +178,14 @@ public void setCertSerialId(String certSerialId) {
this.certSerialId = certSerialId;
}

public void setPersistedOpState(String persistedOpState) {
this.persistedOpState = persistedOpState;
}

public void setPersistedOpStateExpiryEpochSec(long opStateExpiryEpochSec) {
this.persistedOpStateExpiryEpochSec = opStateExpiryEpochSec;
}

public void setPortDetails(Map<String, Integer> portDetails) {
this.portDetails = portDetails;
}
Expand All @@ -172,11 +201,17 @@ private static DatanodeDetailsYaml getDatanodeDetailsYaml(
}
}

String persistedOpString = null;
if (datanodeDetails.getPersistedOpState() != null) {
persistedOpString = datanodeDetails.getPersistedOpState().name();
}
return new DatanodeDetailsYaml(
datanodeDetails.getUuid().toString(),
datanodeDetails.getIpAddress(),
datanodeDetails.getHostName(),
datanodeDetails.getCertSerialId(),
persistedOpString,
datanodeDetails.getPersistedOpStateExpiryEpochSec(),
portDetails);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
.DeleteContainerCommandHandler;
import org.apache.hadoop.ozone.container.common.statemachine.commandhandler
.ReplicateContainerCommandHandler;
import org.apache.hadoop.ozone.container.common.statemachine.commandhandler.SetNodeOperationalStateCommandHandler;
import org.apache.hadoop.ozone.container.keyvalue.TarContainerPacker;
import org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer;
import org.apache.hadoop.ozone.container.replication.ContainerReplicator;
Expand Down Expand Up @@ -138,6 +139,7 @@ public DatanodeStateMachine(DatanodeDetails datanodeDetails,
dnConf.getContainerDeleteThreads()))
.addHandler(new ClosePipelineCommandHandler())
.addHandler(new CreatePipelineCommandHandler(conf))
.addHandler(new SetNodeOperationalStateCommandHandler(conf))
.setConnectionManager(connectionManager)
.setContainer(container)
.setContext(context)
Expand Down
Loading