org.apache.ratis.netty.NettyConfigKeys Java Examples
The following examples show how to use
org.apache.ratis.netty.NettyConfigKeys.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseServer.java From incubator-ratis with Apache License 2.0 | 6 votes |
/** * Sets common Ratis server properties for both the log and metadata state machines. */ void setRaftProperties(RaftProperties properties) { // Set the ports for the server GrpcConfigKeys.Server.setPort(properties, opts.getPort()); NettyConfigKeys.Server.setPort(properties, opts.getPort()); // Ozone sets the leader election timeout (min) to 1second. long leaderElectionTimeoutMinVal = getLeaderElectionTimeoutMin(); TimeDuration leaderElectionTimeoutMin = TimeDuration.valueOf(leaderElectionTimeoutMinVal, TimeUnit.MILLISECONDS); RaftServerConfigKeys.Rpc.setTimeoutMin(properties, leaderElectionTimeoutMin); long leaderElectionTimeoutMaxVal = getLeaderElectionTimeoutMax(); TimeDuration leaderElectionMaxTimeout = TimeDuration.valueOf( leaderElectionTimeoutMaxVal, TimeUnit.MILLISECONDS); RaftServerConfigKeys.Rpc.setTimeoutMax(properties, leaderElectionMaxTimeout); }
Example #2
Source File: NettyRpcService.java From incubator-ratis with Apache License 2.0 | 5 votes |
/** Constructs a netty server with the given port. */ private NettyRpcService(RaftServer server) { super(server::getId, id -> new NettyRpcProxy.PeerMap(id.toString(), server.getProperties())); this.server = server; final ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { final ChannelPipeline p = ch.pipeline(); p.addLast(new ProtobufVarint32FrameDecoder()); p.addLast(new ProtobufDecoder(RaftNettyServerRequestProto.getDefaultInstance())); p.addLast(new ProtobufVarint32LengthFieldPrepender()); p.addLast(new ProtobufEncoder()); p.addLast(new InboundHandler()); } }; final int port = NettyConfigKeys.Server.port(server.getProperties()); channelFuture = new ServerBootstrap() .group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(initializer) .bind(port); }
Example #3
Source File: MetadataServer.java From ratis with Apache License 2.0 | 5 votes |
public void start() throws IOException { final ServerOpts opts = getServerOpts(); if (opts.getHost() == null) { opts.setHost(LogServiceUtils.getHostName()); } this.lifeCycle = new LifeCycle(this.id); RaftProperties properties = new RaftProperties(); if(opts.getWorkingDir() != null) { RaftServerConfigKeys.setStorageDirs(properties, Collections.singletonList(new File(opts.getWorkingDir()))); } GrpcConfigKeys.Server.setPort(properties, opts.getPort()); NettyConfigKeys.Server.setPort(properties, opts.getPort()); Set<RaftPeer> peers = getPeersFromQuorum(opts.getMetaQuorum()); RaftGroupId raftMetaGroupId = RaftGroupId.valueOf(opts.getMetaGroupId()); RaftGroup metaGroup = RaftGroup.valueOf(raftMetaGroupId, peers); metaStateMachine = new MetaStateMachine(raftMetaGroupId, RaftGroupId.valueOf(opts.getLogServerGroupId())); server = RaftServer.newBuilder() .setGroup(metaGroup) .setServerId(RaftPeerId.valueOf(id)) .setStateMachineRegistry(raftGroupId -> { if(raftGroupId.equals(META_GROUP_ID)) { return metaStateMachine; } return null; }) .setProperties(properties).build(); lifeCycle.startAndTransition(() -> { server.start(); }, IOException.class); }
Example #4
Source File: NettyRpcService.java From ratis with Apache License 2.0 | 5 votes |
/** Constructs a netty server with the given port. */ private NettyRpcService(RaftServer server) { super(server::getId, id -> new NettyRpcProxy.PeerMap(id.toString())); this.server = server; final ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { final ChannelPipeline p = ch.pipeline(); p.addLast(new ProtobufVarint32FrameDecoder()); p.addLast(new ProtobufDecoder(RaftNettyServerRequestProto.getDefaultInstance())); p.addLast(new ProtobufVarint32LengthFieldPrepender()); p.addLast(new ProtobufEncoder()); p.addLast(new InboundHandler()); } }; final int port = NettyConfigKeys.Server.port(server.getProperties()); channelFuture = new ServerBootstrap() .group(bossGroup, workerGroup) .channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(initializer) .bind(port); }
Example #5
Source File: TestConfUtils.java From incubator-ratis with Apache License 2.0 | 4 votes |
@Test public void testNettyConfigKeys() { ConfUtils.printAll(NettyConfigKeys.class); }
Example #6
Source File: LogServer.java From ratis with Apache License 2.0 | 4 votes |
public void start() throws IOException { final ServerOpts opts = getServerOpts(); Set<RaftPeer> peers = LogServiceUtils.getPeersFromQuorum(opts.getMetaQuorum()); RaftProperties properties = new RaftProperties(); properties.set("raft.client.rpc.request.timeout", "100000"); GrpcConfigKeys.Server.setPort(properties, opts.getPort()); NettyConfigKeys.Server.setPort(properties, opts.getPort()); InetSocketAddress addr = new InetSocketAddress(opts.getHost(), opts.getPort()); if(opts.getWorkingDir() != null) { RaftServerConfigKeys.setStorageDirs(properties, Collections.singletonList(new File(opts.getWorkingDir()))); } String id = opts.getHost() +"_" + opts.getPort(); RaftPeer peer = new RaftPeer(RaftPeerId.valueOf(id), addr); final RaftGroupId logServerGroupId = RaftGroupId.valueOf(opts.getLogServerGroupId()); RaftGroup all = RaftGroup.valueOf(logServerGroupId, peer); RaftGroup meta = RaftGroup.valueOf(RaftGroupId.valueOf(opts.getMetaGroupId()), peers); raftServer = RaftServer.newBuilder() .setStateMachineRegistry(new StateMachine.Registry() { private final StateMachine managementMachine = new ManagementStateMachine(); private final StateMachine logMachine = new LogStateMachine(); @Override public StateMachine apply(RaftGroupId raftGroupId) { // TODO this looks wrong. Why isn't this metaGroupId? if(raftGroupId.equals(logServerGroupId)) { return managementMachine; } return logMachine; } }) .setProperties(properties) .setServerId(RaftPeerId.valueOf(id)) .setGroup(all) .build(); raftServer.start(); metaClient = RaftClient.newBuilder() .setRaftGroup(meta) .setClientId(ClientId.randomId()) .setProperties(properties) .build(); metaClient.send(() -> MetaServiceProtoUtil.toPingRequestProto(peer).toByteString()); }