|
@@ -18,9 +18,7 @@
|
|
|
|
|
|
package org.apache.hadoop.ozone.container.common.transport.server.ratis;
|
|
|
|
|
|
-import com.google.common.base.Preconditions;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
-import org.apache.hadoop.net.NetUtils;
|
|
|
import org.apache.hadoop.ozone.OzoneConfigKeys;
|
|
|
import org.apache.hadoop.ozone.container.common.interfaces.ContainerDispatcher;
|
|
|
import org.apache.hadoop.ozone.container.common.transport.server.XceiverServerSpi;
|
|
@@ -28,23 +26,25 @@ import org.apache.ratis.RaftConfigKeys;
|
|
|
import org.apache.ratis.conf.RaftProperties;
|
|
|
import org.apache.ratis.grpc.GrpcConfigKeys;
|
|
|
import org.apache.ratis.netty.NettyConfigKeys;
|
|
|
-import org.apache.ratis.protocol.RaftPeer;
|
|
|
import org.apache.ratis.protocol.RaftPeerId;
|
|
|
import org.apache.ratis.rpc.RpcType;
|
|
|
import org.apache.ratis.rpc.SupportedRpcType;
|
|
|
import org.apache.ratis.server.RaftServer;
|
|
|
import org.apache.ratis.server.RaftServerConfigKeys;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* Creates a ratis server endpoint that acts as the communication layer for
|
|
|
* Ozone containers.
|
|
|
*/
|
|
|
public final class XceiverServerRatis implements XceiverServerSpi {
|
|
|
+ static final Logger LOG = LoggerFactory.getLogger(XceiverServerRatis.class);
|
|
|
+
|
|
|
static RaftProperties newRaftProperties(
|
|
|
RpcType rpc, int port, String storageDir) {
|
|
|
final RaftProperties properties = new RaftProperties();
|
|
@@ -62,37 +62,31 @@ public final class XceiverServerRatis implements XceiverServerSpi {
|
|
|
Configuration ozoneConf, ContainerDispatcher dispatcher)
|
|
|
throws IOException {
|
|
|
final String id = ozoneConf.get(
|
|
|
- OzoneConfigKeys.DFS_CONTAINER_RATIS_DATANODE_ADDRESS);
|
|
|
- final Collection<String> servers = ozoneConf.getStringCollection(
|
|
|
- OzoneConfigKeys.DFS_CONTAINER_RATIS_CONF);
|
|
|
+ OzoneConfigKeys.DFS_CONTAINER_RATIS_SERVER_ID);
|
|
|
+ final int port = ozoneConf.getInt(
|
|
|
+ OzoneConfigKeys.DFS_CONTAINER_IPC_PORT,
|
|
|
+ OzoneConfigKeys.DFS_CONTAINER_IPC_PORT_DEFAULT);
|
|
|
final String storageDir = ozoneConf.get(
|
|
|
OzoneConfigKeys.DFS_CONTAINER_RATIS_DATANODE_STORAGE_DIR);
|
|
|
final String rpcType = ozoneConf.get(
|
|
|
OzoneConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_KEY,
|
|
|
OzoneConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_DEFAULT);
|
|
|
final RpcType rpc = SupportedRpcType.valueOfIgnoreCase(rpcType);
|
|
|
- return new XceiverServerRatis(id, servers, storageDir, dispatcher, rpc);
|
|
|
+ return new XceiverServerRatis(id, port, storageDir, dispatcher, rpc);
|
|
|
}
|
|
|
|
|
|
private final int port;
|
|
|
private final RaftServer server;
|
|
|
|
|
|
private XceiverServerRatis(
|
|
|
- String id, Collection<String> servers, String storageDir,
|
|
|
+ String id, int port, String storageDir,
|
|
|
ContainerDispatcher dispatcher, RpcType rpcType) throws IOException {
|
|
|
- Preconditions.checkArgument(servers.contains(id),
|
|
|
- "%s is not one of %s specified in %s",
|
|
|
- id, servers, OzoneConfigKeys.DFS_CONTAINER_RATIS_CONF);
|
|
|
-
|
|
|
- final List<RaftPeer> peers = servers.stream()
|
|
|
- .map(addr -> new RaftPeer(new RaftPeerId(addr), addr))
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- this.port = NetUtils.createSocketAddr(id).getPort();
|
|
|
+ Objects.requireNonNull(id, "id == null");
|
|
|
+ this.port = port;
|
|
|
|
|
|
this.server = RaftServer.newBuilder()
|
|
|
- .setServerId(new RaftPeerId(id))
|
|
|
- .setPeers(peers)
|
|
|
+ .setServerId(RaftPeerId.valueOf(id))
|
|
|
+ .setPeers(Collections.emptyList())
|
|
|
.setProperties(newRaftProperties(rpcType, port, storageDir))
|
|
|
.setStateMachine(new ContainerStateMachine(dispatcher))
|
|
|
.build();
|
|
@@ -100,6 +94,8 @@ public final class XceiverServerRatis implements XceiverServerSpi {
|
|
|
|
|
|
@Override
|
|
|
public void start() throws IOException {
|
|
|
+ LOG.info("Starting {} {} at port {}", getClass().getSimpleName(),
|
|
|
+ server.getId(), getIPCPort());
|
|
|
server.start();
|
|
|
}
|
|
|
|