use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class TestRaftLogReadWrite method setup.
@Before
public void setup() {
storageDir = getTestDir();
RaftProperties properties = new RaftProperties();
RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(storageDir));
this.segmentMaxSize = RaftServerConfigKeys.Log.segmentSizeMax(properties).getSize();
this.preallocatedSize = RaftServerConfigKeys.Log.preallocatedSize(properties).getSize();
this.bufferSize = RaftServerConfigKeys.Log.writeBufferSize(properties).getSizeInt();
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class TestSegmentedRaftLog method setup.
@Before
public void setup() throws Exception {
storageDir = getTestDir();
properties = new RaftProperties();
RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(storageDir));
storage = RaftStorageTestUtils.newRaftStorage(storageDir);
this.segmentMaxSize = RaftServerConfigKeys.Log.segmentSizeMax(properties).getSize();
this.preallocatedSize = RaftServerConfigKeys.Log.preallocatedSize(properties).getSize();
this.bufferSize = RaftServerConfigKeys.Log.writeBufferSize(properties).getSizeInt();
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class Server method run.
@Override
public void run() throws Exception {
RaftPeerId peerId = RaftPeerId.valueOf(id);
RaftProperties properties = new RaftProperties();
final int port = NetUtils.createSocketAddr(getPeer(peerId).getAddress()).getPort();
GrpcConfigKeys.Server.setPort(properties, port);
Optional.ofNullable(getPeer(peerId).getClientAddress()).ifPresent(address -> GrpcConfigKeys.Client.setPort(properties, NetUtils.createSocketAddr(address).getPort()));
Optional.ofNullable(getPeer(peerId).getAdminAddress()).ifPresent(address -> GrpcConfigKeys.Admin.setPort(properties, NetUtils.createSocketAddr(address).getPort()));
RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(storageDir));
StateMachine stateMachine = new ArithmeticStateMachine();
final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())), getPeers());
RaftServer raftServer = RaftServer.newBuilder().setServerId(RaftPeerId.valueOf(id)).setStateMachine(stateMachine).setProperties(properties).setGroup(raftGroup).build();
raftServer.start();
for (; raftServer.getLifeCycleState() != LifeCycle.State.CLOSED; ) {
TimeUnit.SECONDS.sleep(1);
}
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class Server method run.
@Override
public void run() throws Exception {
JVMMetrics.initJvmMetrics(TimeDuration.valueOf(10, TimeUnit.SECONDS));
RaftPeerId peerId = RaftPeerId.valueOf(id);
RaftProperties properties = new RaftProperties();
// Avoid leader change affect the performance
RaftServerConfigKeys.Rpc.setTimeoutMin(properties, TimeDuration.valueOf(2, TimeUnit.SECONDS));
RaftServerConfigKeys.Rpc.setTimeoutMax(properties, TimeDuration.valueOf(3, TimeUnit.SECONDS));
final int port = NetUtils.createSocketAddr(getPeer(peerId).getAddress()).getPort();
GrpcConfigKeys.Server.setPort(properties, port);
Optional.ofNullable(getPeer(peerId).getClientAddress()).ifPresent(address -> GrpcConfigKeys.Client.setPort(properties, NetUtils.createSocketAddr(address).getPort()));
Optional.ofNullable(getPeer(peerId).getAdminAddress()).ifPresent(address -> GrpcConfigKeys.Admin.setPort(properties, NetUtils.createSocketAddr(address).getPort()));
String dataStreamAddress = getPeer(peerId).getDataStreamAddress();
if (dataStreamAddress != null) {
final int dataStreamport = NetUtils.createSocketAddr(dataStreamAddress).getPort();
NettyConfigKeys.DataStream.setPort(properties, dataStreamport);
RaftConfigKeys.DataStream.setType(properties, SupportedDataStreamType.NETTY);
}
RaftServerConfigKeys.setStorageDir(properties, storageDir);
RaftServerConfigKeys.Write.setElementLimit(properties, 40960);
RaftServerConfigKeys.Write.setByteLimit(properties, SizeInBytes.valueOf("1000MB"));
ConfUtils.setFiles(properties::setFiles, FileStoreCommon.STATEMACHINE_DIR_KEY, storageDir);
RaftServerConfigKeys.DataStream.setAsyncRequestThreadPoolSize(properties, writeThreadNum);
RaftServerConfigKeys.DataStream.setAsyncWriteThreadPoolSize(properties, writeThreadNum);
ConfUtils.setInt(properties::setInt, FileStoreCommon.STATEMACHINE_WRITE_THREAD_NUM, writeThreadNum);
ConfUtils.setInt(properties::setInt, FileStoreCommon.STATEMACHINE_READ_THREAD_NUM, readThreadNum);
ConfUtils.setInt(properties::setInt, FileStoreCommon.STATEMACHINE_COMMIT_THREAD_NUM, commitThreadNum);
ConfUtils.setInt(properties::setInt, FileStoreCommon.STATEMACHINE_DELETE_THREAD_NUM, deleteThreadNum);
StateMachine stateMachine = new FileStoreStateMachine(properties);
final RaftGroup raftGroup = RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())), getPeers());
RaftServer raftServer = RaftServer.newBuilder().setServerId(RaftPeerId.valueOf(id)).setStateMachine(stateMachine).setProperties(properties).setGroup(raftGroup).build();
raftServer.start();
for (; raftServer.getLifeCycleState() != LifeCycle.State.CLOSED; ) {
TimeUnit.SECONDS.sleep(1);
}
}
use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.
the class ParameterizedBaseTest method getMiniRaftClusters.
public static <S extends StateMachine> Collection<Object[]> getMiniRaftClusters(Class<S> stateMachineClass, int clusterSize, Class<?>... clusterClasses) {
final RaftProperties prop = new RaftProperties();
// avoid flaky behaviour in CI environment
RaftServerConfigKeys.Rpc.setTimeoutMin(prop, TimeDuration.valueOf(300, TimeUnit.MILLISECONDS));
RaftServerConfigKeys.Rpc.setTimeoutMax(prop, TimeDuration.valueOf(600, TimeUnit.MILLISECONDS));
prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, stateMachineClass, StateMachine.class);
return getMiniRaftClusters(prop, clusterSize, clusterClasses);
}
Aggregations