Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public static void setRaftStorageDir(final RaftProperties properties,
String storageDir = haConf.getRatisStorageDir();
if (Strings.isNullOrEmpty(storageDir)) {
storageDir = ServerUtils.getDefaultRatisDirectory(conf);
} else {
storageDir =
(new File(ServerUtils.getOzoneMetaDirPath(conf), storageDir))
.getPath();
}
RaftServerConfigKeys.setStorageDir(properties,
Collections.singletonList(new File(storageDir)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class SCMHAConfiguration {

@Config(key = "ratis.storage.dir",
type = ConfigType.STRING,
defaultValue = "",
defaultValue = "scm-ratis",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is workaround to config SCM ratis storage dir value. The usual way that config value in SCMHAConfiguration seems break. I will file a JIRA to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We won't need this line of change after #1739

tags = {OZONE, SCM, HA, RATIS},
description = "Storage directory used by SCM to write Ratis logs."
)
Expand Down Expand Up @@ -165,6 +165,10 @@ public String getRatisStorageDir() {
return ratisStorageDir;
}

public void setRatisStorageDir(String dir) {
this.ratisStorageDir = dir;
}

public InetSocketAddress getRatisBindAddress() {
return NetUtils.createSocketAddr(ratisBindHost, ratisBindPort);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ public RaftPeerId getPeerId() {
Arrays.stream(conf.getTrimmedStrings(ScmConfigKeys.OZONE_SCM_NAMES))
.map(scmName -> HddsUtils.getHostName(scmName).get())
.collect(Collectors.toList());

final List<RaftPeer> raftPeers = new ArrayList<>();
for (int i = 0; i < hosts.size(); ++i) {
String nodeId = "scm" + i;
RaftPeerId peerId = RaftPeerId.getRaftPeerId(nodeId);

String host = hosts.get(i);
if (InetAddress.getByName(host).equals(localHost)) {
if (InetAddress.getByName(host).equals(localHost)
|| host.toLowerCase().equals("localhost")) {
selfPeerId = peerId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ public static void quasiCloseContainer(ContainerManagerV2 containerManager,
public static StorageContainerManager getScmSimple(OzoneConfiguration conf)
throws IOException, AuthenticationException {
SCMConfigurator configurator = new SCMConfigurator();
configurator.setSCMHAManager(MockSCMHAManager.getInstance(true));
conf.set(ScmConfigKeys.OZONE_SCM_NAMES, "localhost");
conf.setBoolean(ScmConfigKeys.OZONE_SCM_HA_ENABLE_KEY, true);
return StorageContainerManager.createSCM(conf, configurator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.hadoop.ozone.om.OMConfigKeys;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.OmMultipartInfo;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -99,6 +100,12 @@ public void init() throws Exception {
o3fs = (OzoneFileSystem) FileSystem.get(new URI(rootPath), conf);
}

@After
public void shutdown() {
if (cluster != null) {
cluster.shutdown();
}
}

@Test
public void test() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,18 @@ abstract class Builder {
protected boolean startDataNodes = true;
protected CertificateClient certClient;
protected int pipelineNumLimit = DEFAULT_PIPELIME_LIMIT;
protected boolean useMockSCMHAManager = false;

protected Builder(OzoneConfiguration conf) {
this.conf = conf;
setClusterId(UUID.randomUUID().toString());
}

public Builder setUseMockSCMHAManager(boolean use) {
this.useMockSCMHAManager = use;
return this;
}

/**
* Sets the cluster Id.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,21 @@ public void waitForClusterToBeReady()
throws TimeoutException, InterruptedException {
GenericTestUtils.waitFor(() -> {
final int healthy = scm.getNodeCount(HEALTHY);
// When SCM HA is not enabled, scm is always leader.
final boolean checkScmLeader = scm.checkLeader();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!

final boolean isNodeReady = healthy == hddsDatanodes.size();
final boolean exitSafeMode = !scm.isInSafeMode();

LOG.info("{}. Got {} of {} DN Heartbeats.",
isNodeReady ? "Nodes are ready" : "Waiting for nodes to be ready",
healthy, hddsDatanodes.size());
LOG.info(checkScmLeader ? "SCM became leader" :
"SCM has not become leader");
LOG.info(exitSafeMode ? "Cluster exits safe mode" :
"Waiting for cluster to exit safe mode",
healthy, hddsDatanodes.size());

return isNodeReady && exitSafeMode;
return isNodeReady && exitSafeMode && checkScmLeader;
}, 1000, waitForClusterToBeReadyTimeout);
}

Expand Down Expand Up @@ -631,7 +635,12 @@ protected StorageContainerManager createSCM()
configureSCM();
SCMStorageConfig scmStore = new SCMStorageConfig(conf);
initializeScmStorage(scmStore);
StorageContainerManager scm = TestUtils.getScmSimple(conf);
StorageContainerManager scm;
if (useMockSCMHAManager) {
scm = TestUtils.getScm(conf);
} else {
scm = TestUtils.getScmSimple(conf);
}
HealthyPipelineSafeModeRule rule =
scm.getScmSafeModeManager().getHealthyPipelineSafeModeRule();
if (rule != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static void init() throws Exception {
conf.setQuietMode(false);
cluster =
MiniOzoneCluster.newBuilder(conf).setNumDatanodes(10).setHbInterval(200)
.build();
.setUseMockSCMHAManager(true).build();
cluster.waitForClusterToBeReady();
cluster.waitForPipelineTobeReady(HddsProtos.ReplicationFactor.ONE, 60000);
//the easiest way to create an open container is creating a key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public void init() throws Exception {
.setStreamBufferFlushSize(flushSize)
.setStreamBufferMaxSize(maxFlushSize)
.setStreamBufferSizeUnit(StorageUnit.BYTES)
.setUseMockSCMHAManager(true)
.build();
cluster.waitForClusterToBeReady();
//the easiest way to create an open container is creating a key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public void init() throws Exception {
.setStreamBufferFlushSize(flushSize)
.setStreamBufferMaxSize(maxFlushSize)
.setStreamBufferSizeUnit(StorageUnit.BYTES)
.setUseMockSCMHAManager(true)
.build();
cluster.waitForClusterToBeReady();
//the easiest way to create an open container is creating a key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void setUp() throws Exception {

cluster = MiniOzoneCluster.newBuilder(conf)
.setNumDatanodes(numOfDatanodes)
.setUseMockSCMHAManager(true)
.build();
cluster.waitForClusterToBeReady();
setManagers();
Expand Down