Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HDDS-11819. Improve mock datanode version handling in MiniOzoneCluster #7632

Merged
merged 2 commits into from
Jan 3, 2025
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 @@ -102,6 +102,9 @@ public class HddsDatanodeService extends GenericCli implements ServicePlugin {
private static final Logger LOG = LoggerFactory.getLogger(
HddsDatanodeService.class);

public static final String TESTING_DATANODE_VERSION_INITIAL = "testing.hdds.datanode.version.initial";
public static final String TESTING_DATANODE_VERSION_CURRENT = "testing.hdds.datanode.version.current";

private OzoneConfiguration conf;
private SecurityConfig secConf;
private DatanodeDetails datanodeDetails;
Expand Down Expand Up @@ -432,15 +435,14 @@ private DatanodeDetails initializeDatanodeDetails()
DatanodeDetails details;
if (idFile.exists()) {
details = ContainerUtils.readDatanodeDetailsFrom(idFile);
// Current version is always overridden to the latest
details.setCurrentVersion(getDefaultCurrentVersion());
} else {
// There is no datanode.id file, this might be the first time datanode
// is started.
details = DatanodeDetails.newBuilder().setUuid(UUID.randomUUID()).build();
details.setInitialVersion(getDefaultInitialVersion());
details.setCurrentVersion(getDefaultCurrentVersion());
details.setInitialVersion(getInitialVersion());
}
// Current version is always overridden to the latest
details.setCurrentVersion(getCurrentVersion());
return details;
}

Expand Down Expand Up @@ -680,16 +682,14 @@ private String reconfigReplicationStreamsLimit(String value) {
/**
* Returns the initial version of the datanode.
*/
@VisibleForTesting
public static int getDefaultInitialVersion() {
return DatanodeVersion.CURRENT_VERSION;
private int getInitialVersion() {
return conf.getInt(TESTING_DATANODE_VERSION_INITIAL, DatanodeVersion.CURRENT_VERSION);
}

/**
* Returns the current version of the datanode.
*/
@VisibleForTesting
public static int getDefaultCurrentVersion() {
return DatanodeVersion.CURRENT_VERSION;
private int getCurrentVersion() {
return conf.getInt(TESTING_DATANODE_VERSION_CURRENT, DatanodeVersion.CURRENT_VERSION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.UUID;
import java.util.concurrent.TimeoutException;

import org.apache.hadoop.hdds.DatanodeVersion;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
Expand Down Expand Up @@ -305,9 +304,6 @@ abstract class Builder {
protected boolean includeRecon = false;
protected boolean includeS3G = false;

protected int dnInitialVersion = DatanodeVersion.FUTURE_VERSION.toProtoValue();
protected int dnCurrentVersion = DatanodeVersion.COMBINED_PUTBLOCK_WRITECHUNK_RPC.toProtoValue();

protected int numOfDatanodes = 3;
protected boolean startDataNodes = true;
protected CertificateClient certClient;
Expand Down Expand Up @@ -379,30 +375,6 @@ public Builder setNumDatanodes(int val) {
return this;
}

/**
* Set the initialVersion for all datanodes.
*
* @param val initialVersion value to be set for all datanodes.
*
* @return MiniOzoneCluster.Builder
*/
public Builder setDatanodeInitialVersion(int val) {
dnInitialVersion = val;
return this;
}

/**
* Set the currentVersion for all datanodes.
*
* @param val currentVersion value to be set for all datanodes.
*
* @return MiniOzoneCluster.Builder
*/
public Builder setDatanodeCurrentVersion(int val) {
dnCurrentVersion = val;
return this;
}

public Builder setDatanodeFactory(DatanodeFactory factory) {
this.dnFactory = factory;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hdds.DatanodeVersion;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.annotation.InterfaceAudience;
import org.apache.hadoop.hdds.client.RatisReplicationConfig;
Expand Down Expand Up @@ -110,8 +109,6 @@
import static org.apache.ozone.test.GenericTestUtils.PortAllocator.localhostWithFreePort;

import org.hadoop.ozone.recon.codegen.ReconSqlDbConfig;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -145,7 +142,6 @@ public class MiniOzoneClusterImpl implements MiniOzoneCluster {
private CertificateClient caClient;
private final Set<AutoCloseable> clients = ConcurrentHashMap.newKeySet();
private SecretKeyClient secretKeyClient;
private static MockedStatic mockDNStatic = Mockito.mockStatic(HddsDatanodeService.class);

/**
* Creates a new MiniOzoneCluster with Recon.
Expand Down Expand Up @@ -427,16 +423,6 @@ private void waitForHddsDatanodeToStop(DatanodeDetails dn)
}, 1000, waitForClusterToBeReadyTimeout);
}

private static void overrideDatanodeVersions(int dnInitialVersion, int dnCurrentVersion) {
// FUTURE_VERSION (-1) is not a valid version for a datanode, using it as a marker when version is not overridden
if (dnInitialVersion != DatanodeVersion.FUTURE_VERSION.toProtoValue()) {
mockDNStatic.when(HddsDatanodeService::getDefaultInitialVersion).thenReturn(dnInitialVersion);
}
if (dnCurrentVersion != DatanodeVersion.FUTURE_VERSION.toProtoValue()) {
mockDNStatic.when(HddsDatanodeService::getDefaultCurrentVersion).thenReturn(dnCurrentVersion);
}
}

@Override
public void restartHddsDatanode(int i, boolean waitForDatanode)
throws InterruptedException, TimeoutException {
Expand Down Expand Up @@ -869,9 +855,6 @@ protected List<HddsDatanodeService> createHddsDatanodes()
throws IOException {
List<HddsDatanodeService> hddsDatanodes = new ArrayList<>();

// Override default datanode initial and current version if necessary
overrideDatanodeVersions(dnInitialVersion, dnCurrentVersion);

for (int i = 0; i < numOfDatanodes; i++) {
OzoneConfiguration dnConf = dnFactory.apply(conf);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.hadoop.ozone;

import org.apache.hadoop.hdds.DatanodeVersion;
import org.apache.hadoop.hdds.conf.ConfigurationTarget;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.container.common.DatanodeLayoutStorage;
Expand All @@ -39,6 +40,8 @@
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.HDDS_DATANODE_DIR_DU_RESERVED;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.HDDS_DATANODE_DIR_KEY;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.HDDS_REST_HTTP_ADDRESS_KEY;
import static org.apache.hadoop.ozone.HddsDatanodeService.TESTING_DATANODE_VERSION_CURRENT;
import static org.apache.hadoop.ozone.HddsDatanodeService.TESTING_DATANODE_VERSION_INITIAL;
import static org.apache.hadoop.ozone.OzoneConfigKeys.HDDS_CONTAINER_IPC_PORT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.HDDS_CONTAINER_RATIS_ADMIN_PORT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.HDDS_CONTAINER_RATIS_DATANODE_STORAGE_DIR;
Expand All @@ -58,11 +61,15 @@ public class UniformDatanodesFactory implements MiniOzoneCluster.DatanodeFactory
private final int numDataVolumes;
private final String reservedSpace;
private final Integer layoutVersion;
private final DatanodeVersion initialVersion;
private final DatanodeVersion currentVersion;

protected UniformDatanodesFactory(Builder builder) {
numDataVolumes = builder.numDataVolumes;
layoutVersion = builder.layoutVersion;
reservedSpace = builder.reservedSpace;
currentVersion = builder.currentVersion;
initialVersion = builder.initialVersion != null ? builder.initialVersion : builder.currentVersion;
}

@Override
Expand Down Expand Up @@ -104,6 +111,13 @@ public OzoneConfiguration apply(OzoneConfiguration conf) throws IOException {
layoutStorage.initialize();
}

if (initialVersion != null) {
dnConf.setInt(TESTING_DATANODE_VERSION_INITIAL, initialVersion.toProtoValue());
}
if (currentVersion != null) {
dnConf.setInt(TESTING_DATANODE_VERSION_CURRENT, currentVersion.toProtoValue());
}

return dnConf;
}

Expand Down Expand Up @@ -131,6 +145,8 @@ public static class Builder {
private int numDataVolumes = 1;
private String reservedSpace;
private Integer layoutVersion;
private DatanodeVersion initialVersion;
private DatanodeVersion currentVersion;

/**
* Sets the number of data volumes per datanode.
Expand Down Expand Up @@ -158,6 +174,16 @@ public Builder setLayoutVersion(int layoutVersion) {
return this;
}

public Builder setInitialVersion(DatanodeVersion version) {
this.initialVersion = version;
return this;
}

public Builder setCurrentVersion(DatanodeVersion version) {
this.currentVersion = version;
return this;
}

public UniformDatanodesFactory build() {
return new UniformDatanodesFactory(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.hadoop.ozone.HddsDatanodeService;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.ozone.UniformDatanodesFactory;
import org.apache.hadoop.ozone.client.ObjectStore;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneClientFactory;
Expand Down Expand Up @@ -74,7 +75,7 @@ public class TestBlockDataStreamOutput {
private static String volumeName;
private static String bucketName;
private static String keyString;
private static final int DN_OLD_VERSION = DatanodeVersion.SEPARATE_RATIS_PORTS_AVAILABLE.toProtoValue();
private static final DatanodeVersion DN_OLD_VERSION = DatanodeVersion.SEPARATE_RATIS_PORTS_AVAILABLE;

/**
* Create a MiniDFSCluster for testing.
Expand Down Expand Up @@ -110,7 +111,9 @@ public static void init() throws Exception {

cluster = MiniOzoneCluster.newBuilder(conf)
.setNumDatanodes(5)
.setDatanodeCurrentVersion(DN_OLD_VERSION)
.setDatanodeFactory(UniformDatanodesFactory.newBuilder()
.setCurrentVersion(DN_OLD_VERSION)
.build())
.build();
cluster.waitForClusterToBeReady();
//the easiest way to create an open container is creating a key
Expand Down Expand Up @@ -281,7 +284,7 @@ public void testDatanodeVersion() throws Exception {
List<HddsDatanodeService> dns = cluster.getHddsDatanodes();
for (HddsDatanodeService dn : dns) {
DatanodeDetails details = dn.getDatanodeDetails();
assertEquals(DN_OLD_VERSION, details.getCurrentVersion());
assertEquals(DN_OLD_VERSION.toProtoValue(), details.getCurrentVersion());
}

String keyName = getKeyName();
Expand All @@ -292,7 +295,7 @@ public void testDatanodeVersion() throws Exception {
// Now check 3 DNs in a random pipeline returns the correct DN versions
List<DatanodeDetails> streamDnDetails = stream.getPipeline().getNodes();
for (DatanodeDetails details : streamDnDetails) {
assertEquals(DN_OLD_VERSION, details.getCurrentVersion());
assertEquals(DN_OLD_VERSION.toProtoValue(), details.getCurrentVersion());
}
}

Expand Down
Loading
Loading