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 @@ -76,7 +76,8 @@ public static void setRaftStorageDir(final RaftProperties properties,
final ConfigurationSource conf) {
String storageDir = haConf.getRatisStorageDir();
if (Strings.isNullOrEmpty(storageDir)) {
storageDir = ServerUtils.getDefaultRatisDirectory(conf);
File metaDirPath = ServerUtils.getOzoneMetaDirPath(conf);
storageDir = (new File(metaDirPath, "scm-ha")).getPath();
}
RaftServerConfigKeys.setStorageDir(properties,
Collections.singletonList(new File(storageDir)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ private Object invokeLocal(Method method, Object[] args)
*/
private Object invokeRatis(Method method, Object[] args)
throws Exception {
LOG.trace("Invoking method {} on target {}", method, ratisHandler);
long startTime = Time.monotonicNowNanos();
final SCMRatisResponse response = ratisHandler.submitRequest(
SCMRatisRequest.of(requestType, method.getName(), args));
LOG.info("Invoking method {} on target {}, cost {}us",
method, ratisHandler, (Time.monotonicNowNanos() - startTime) / 1000.0);
if (response.isSuccess()) {
return response.getResult();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -195,10 +196,7 @@ public RaftPeerId getPeerId() {
InetAddress localHost = InetAddress.getLocalHost();

// fetch hosts from ozone.scm.names
List<String> hosts =
Arrays.stream(conf.getTrimmedStrings(ScmConfigKeys.OZONE_SCM_NAMES))
.map(scmName -> HddsUtils.getHostName(scmName).get())
.collect(Collectors.toList());
List<String> hosts = parseHosts(conf);

final List<RaftPeer> raftPeers = new ArrayList<>();
for (int i = 0; i < hosts.size(); ++i) {
Expand Down Expand Up @@ -232,5 +230,29 @@ public RaftPeerId getPeerId() {

raftGroup = RaftGroup.valueOf(raftGroupId, raftPeers);
}

private List<String> parseHosts(final ConfigurationSource conf)
throws UnknownHostException {
// fetch hosts from ozone.scm.names
List<String> hosts =
Arrays.stream(conf.getTrimmedStrings(ScmConfigKeys.OZONE_SCM_NAMES))
.map(scmName -> HddsUtils.getHostName(scmName).get())
.collect(Collectors.toList());

// if this is not a conf for a multi-server raft cluster,
// it means we are in integration test, and need to augment
// the conf to help build a single-server raft cluster.
if (hosts.size() == 0) {
// ozone.scm.names is not set
hosts.add(InetAddress.getLocalHost().getHostName());
} else if (hosts.size() == 1) {
// ozone.scm.names is set, yet the conf may not be usable.
hosts.set(0, InetAddress.getLocalHost().getHostName());
}

LOG.info("fetch hosts {} from ozone.scm.names {}.",
hosts, conf.get(ScmConfigKeys.OZONE_SCM_NAMES));
return hosts;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ 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.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 @@ -37,6 +37,7 @@
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.OmMultipartInfo;
import org.junit.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
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 @@ -171,15 +171,18 @@ public void waitForClusterToBeReady()
final int healthy = scm.getNodeCount(HEALTHY);
final boolean isNodeReady = healthy == hddsDatanodes.size();
final boolean exitSafeMode = !scm.isInSafeMode();
final boolean checkScmLeader = scm.checkLeader();

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

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

Expand Down