org.apache.ratis.RaftConfigKeys Java Examples

The following examples show how to use org.apache.ratis.RaftConfigKeys. 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: MiniRaftClusterWithSimulatedRpc.java    From ratis with Apache License 2.0 6 votes vote down vote up
@Override
public MiniRaftClusterWithSimulatedRpc newCluster(
    String[] ids, RaftProperties prop) {
  RaftConfigKeys.Rpc.setType(prop, SimulatedRpc.INSTANCE);
  if (ThreadLocalRandom.current().nextBoolean()) {
    // turn off simulate latency half of the times.
    prop.setInt(SimulatedRequestReply.SIMULATE_LATENCY_KEY, 0);
  }
  final int simulateLatencyMs = ConfUtils.getInt(prop::getInt,
      SimulatedRequestReply.SIMULATE_LATENCY_KEY,
      SimulatedRequestReply.SIMULATE_LATENCY_DEFAULT, LOG::info, requireMin(0));
  final SimulatedRequestReply<RaftServerRequest, RaftServerReply> serverRequestReply
      = new SimulatedRequestReply<>(simulateLatencyMs);
  final SimulatedClientRpc client2serverRequestReply
      = new SimulatedClientRpc(simulateLatencyMs);
  return new MiniRaftClusterWithSimulatedRpc(ids, prop,
      serverRequestReply, client2serverRequestReply);
}
 
Example #2
Source File: RaftClient.java    From ratis with Apache License 2.0 6 votes vote down vote up
/** @return a {@link RaftClient} object. */
public RaftClient build() {
  if (clientId == null) {
    clientId = ClientId.randomId();
  }
  if (properties != null) {
    if (clientRpc == null) {
      final RpcType rpcType = RaftConfigKeys.Rpc.type(properties, LOG::debug);
      final ClientFactory factory = ClientFactory.cast(rpcType.newFactory(parameters));
      clientRpc = factory.newRaftClientRpc(clientId, properties);
    }
  }
  return ClientImplUtils.newRaftClient(clientId,
      Objects.requireNonNull(group, "The 'group' field is not initialized."),
      leaderId,
      Objects.requireNonNull(clientRpc, "The 'clientRpc' field is not initialized."),
      properties, retryPolicy);
}
 
Example #3
Source File: MiniRaftClusterWithSimulatedRpc.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
@Override
public MiniRaftClusterWithSimulatedRpc newCluster(
    String[] ids, RaftProperties prop) {
  RaftConfigKeys.Rpc.setType(prop, SimulatedRpc.INSTANCE);
  if (ThreadLocalRandom.current().nextBoolean()) {
    // turn off simulate latency half of the times.
    prop.setInt(SimulatedRequestReply.SIMULATE_LATENCY_KEY, 0);
  }
  final int simulateLatencyMs = ConfUtils.getInt(prop::getInt,
      SimulatedRequestReply.SIMULATE_LATENCY_KEY,
      SimulatedRequestReply.SIMULATE_LATENCY_DEFAULT, LOG::info, requireMin(0));
  final SimulatedRequestReply<RaftServerRequest, RaftServerReply> serverRequestReply
      = new SimulatedRequestReply<>(simulateLatencyMs);
  final SimulatedClientRpc client2serverRequestReply
      = new SimulatedClientRpc(simulateLatencyMs);
  return new MiniRaftClusterWithSimulatedRpc(ids, prop,
      serverRequestReply, client2serverRequestReply);
}
 
Example #4
Source File: RaftClient.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
/** @return a {@link RaftClient} object. */
public RaftClient build() {
  if (clientId == null) {
    clientId = ClientId.randomId();
  }
  if (properties != null) {
    if (clientRpc == null) {
      final RpcType rpcType = RaftConfigKeys.Rpc.type(properties, LOG::debug);
      final ClientFactory factory = ClientFactory.cast(rpcType.newFactory(parameters));
      clientRpc = factory.newRaftClientRpc(clientId, properties);
    }
  }
  return ClientImplUtils.newRaftClient(clientId,
      Objects.requireNonNull(group, "The 'group' field is not initialized."),
      leaderId,
      Objects.requireNonNull(clientRpc, "The 'clientRpc' field is not initialized."),
      properties, retryPolicy);
}
 
Example #5
Source File: RaftServerProxy.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
RaftServerProxy(RaftPeerId id, StateMachine.Registry stateMachineRegistry,
    RaftProperties properties, Parameters parameters) {
  this.properties = properties;
  this.stateMachineRegistry = stateMachineRegistry;

  final RpcType rpcType = RaftConfigKeys.Rpc.type(properties, LOG::info);
  this.factory = ServerFactory.cast(rpcType.newFactory(parameters));

  this.serverRpc = factory.newRaftServerRpc(this);
  this.id = id != null? id: RaftPeerId.valueOf(getIdStringFrom(serverRpc));
  this.lifeCycle = new LifeCycle(this.id + "-" + getClass().getSimpleName());

  this.implExecutor = Executors.newSingleThreadExecutor();
}
 
Example #6
Source File: RaftServerProxy.java    From ratis with Apache License 2.0 5 votes vote down vote up
RaftServerProxy(RaftPeerId id, StateMachine.Registry stateMachineRegistry,
    RaftProperties properties, Parameters parameters) {
  this.properties = properties;
  this.stateMachineRegistry = stateMachineRegistry;

  final RpcType rpcType = RaftConfigKeys.Rpc.type(properties, LOG::info);
  this.factory = ServerFactory.cast(rpcType.newFactory(parameters));

  this.serverRpc = factory.newRaftServerRpc(this);
  this.id = id != null? id: RaftPeerId.valueOf(getIdStringFrom(serverRpc));
  this.lifeCycle = new LifeCycle(this.id + "-" + getClass().getSimpleName());
}
 
Example #7
Source File: Client.java    From ratis with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
  int raftSegmentPreallocatedSize = 1024 * 1024 * 1024;
  RaftProperties raftProperties = new RaftProperties();
  RaftConfigKeys.Rpc.setType(raftProperties, SupportedRpcType.GRPC);
  GrpcConfigKeys.setMessageSizeMax(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.Appender.setBufferByteLimit(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setWriteBufferSize(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setPreallocatedSize(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setSegmentSizeMax(raftProperties,
      SizeInBytes.valueOf(1 * 1024 * 1024 * 1024));

  RaftServerConfigKeys.Log.setMaxCachedSegmentNum(raftProperties, 2);

  RaftClientConfigKeys.Rpc.setRequestTimeout(raftProperties,
      TimeDuration.valueOf(50000, TimeUnit.MILLISECONDS));
  RaftClientConfigKeys.Async.setSchedulerThreads(raftProperties, 10);
  RaftClientConfigKeys.Async.setMaxOutstandingRequests(raftProperties, 1000);


  final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(raftGroupId)),
      parsePeers(peers));

  RaftClient.Builder builder =
      RaftClient.newBuilder().setProperties(raftProperties);
  builder.setRaftGroup(raftGroup);
  builder.setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
  RaftClient client = builder.build();

  operation(client);
}
 
Example #8
Source File: XceiverServerRatis.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
private RpcType setRpcType(RaftProperties properties) {
  final String rpcType = conf.get(
      OzoneConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_KEY,
      OzoneConfigKeys.DFS_CONTAINER_RATIS_RPC_TYPE_DEFAULT);
  final RpcType rpc = SupportedRpcType.valueOfIgnoreCase(rpcType);
  RaftConfigKeys.Rpc.setType(properties, rpc);
  return rpc;
}
 
Example #9
Source File: Client.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
@Override
public void run() throws Exception {
  int raftSegmentPreallocatedSize = 1024 * 1024 * 1024;
  RaftProperties raftProperties = new RaftProperties();
  RaftConfigKeys.Rpc.setType(raftProperties, SupportedRpcType.GRPC);
  GrpcConfigKeys.setMessageSizeMax(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.Appender.setBufferByteLimit(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setWriteBufferSize(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setPreallocatedSize(raftProperties,
      SizeInBytes.valueOf(raftSegmentPreallocatedSize));
  RaftServerConfigKeys.Log.setSegmentSizeMax(raftProperties,
      SizeInBytes.valueOf(1 * 1024 * 1024 * 1024));

  RaftServerConfigKeys.Log.setSegmentCacheNumMax(raftProperties, 2);

  RaftClientConfigKeys.Rpc.setRequestTimeout(raftProperties,
      TimeDuration.valueOf(50000, TimeUnit.MILLISECONDS));
  RaftClientConfigKeys.Async.setOutstandingRequestsMax(raftProperties, 1000);


  final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())),
          getPeers());

  RaftClient.Builder builder =
      RaftClient.newBuilder().setProperties(raftProperties);
  builder.setRaftGroup(raftGroup);
  builder.setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
  RaftClient client = builder.build();

  operation(client);
}
 
Example #10
Source File: RatisHelper.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("checkstyle:ParameterNumber")
private static RaftClient newRaftClient(RpcType rpcType, RaftPeerId leader,
    RaftGroup group, RetryPolicy retryPolicy,
    GrpcTlsConfig tlsConfig, ConfigurationSource ozoneConfiguration) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("newRaftClient: {}, leader={}, group={}",
        rpcType, leader, group);
  }
  final RaftProperties properties = new RaftProperties();

  RaftConfigKeys.Rpc.setType(properties, rpcType);

  // Set the ratis client headers which are matching with regex.
  createRaftClientProperties(ozoneConfiguration, properties);

  RaftClient.Builder builder =  RaftClient.newBuilder()
      .setRaftGroup(group)
      .setLeaderId(leader)
      .setProperties(properties)
      .setRetryPolicy(retryPolicy);

  // TODO: GRPC TLS only for now, netty/hadoop RPC TLS support later.
  if (tlsConfig != null && rpcType == SupportedRpcType.GRPC) {
    builder.setParameters(GrpcFactory.newRaftParameters(tlsConfig));
  }
  return builder.build();
}
 
Example #11
Source File: MiniRaftClusterWithNetty.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@Override
public MiniRaftClusterWithNetty newCluster(String[] ids, RaftProperties prop) {
  RaftConfigKeys.Rpc.setType(prop, SupportedRpcType.NETTY);
  return new MiniRaftClusterWithNetty(ids, prop);
}
 
Example #12
Source File: MiniRaftClusterWithGrpc.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@Override
public MiniRaftClusterWithGrpc newCluster(
    String[] ids, RaftProperties prop) {
  RaftConfigKeys.Rpc.setType(prop, SupportedRpcType.GRPC);
  return new MiniRaftClusterWithGrpc(ids, prop);
}
 
Example #13
Source File: MiniRaftClusterWithHadoopRpc.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
public MiniRaftClusterWithHadoopRpc newCluster(
    String[] ids, RaftProperties prop, Configuration conf) {
  RaftConfigKeys.Rpc.setType(prop, SupportedRpcType.HADOOP);
  HadoopConfigKeys.Ipc.setAddress(conf, "0.0.0.0:0");
  return new MiniRaftClusterWithHadoopRpc(ids, prop, conf);
}
 
Example #14
Source File: MiniRaftClusterWithHadoopRpc.java    From ratis with Apache License 2.0 4 votes vote down vote up
public MiniRaftClusterWithHadoopRpc newCluster(
    String[] ids, RaftProperties prop, Configuration conf) {
  RaftConfigKeys.Rpc.setType(prop, SupportedRpcType.HADOOP);
  HadoopConfigKeys.Ipc.setAddress(conf, "0.0.0.0:0");
  return new MiniRaftClusterWithHadoopRpc(ids, prop, conf);
}
 
Example #15
Source File: MiniRaftClusterWithGrpc.java    From ratis with Apache License 2.0 4 votes vote down vote up
@Override
public MiniRaftClusterWithGrpc newCluster(
    String[] ids, RaftProperties prop) {
  RaftConfigKeys.Rpc.setType(prop, SupportedRpcType.GRPC);
  return new MiniRaftClusterWithGrpc(ids, prop);
}
 
Example #16
Source File: MiniRaftClusterWithNetty.java    From ratis with Apache License 2.0 4 votes vote down vote up
@Override
public MiniRaftClusterWithNetty newCluster(String[] ids, RaftProperties prop) {
  RaftConfigKeys.Rpc.setType(prop, SupportedRpcType.NETTY);
  return new MiniRaftClusterWithNetty(ids, prop);
}
 
Example #17
Source File: TestConfUtils.java    From incubator-ratis with Apache License 2.0 4 votes vote down vote up
@Test
public void testRaftConfigKeys() {
  ConfUtils.printAll(RaftConfigKeys.class);
}