Search in sources :

Example 36 with RaftProperties

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();
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) Before(org.junit.Before)

Example 37 with RaftProperties

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();
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) Before(org.junit.Before)

Example 38 with RaftProperties

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);
    }
}
Also used : StateMachine(org.apache.ratis.statemachine.StateMachine) ArithmeticStateMachine(org.apache.ratis.examples.arithmetic.ArithmeticStateMachine) RaftServer(org.apache.ratis.server.RaftServer) RaftProperties(org.apache.ratis.conf.RaftProperties) ArithmeticStateMachine(org.apache.ratis.examples.arithmetic.ArithmeticStateMachine) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) RaftGroup(org.apache.ratis.protocol.RaftGroup)

Example 39 with RaftProperties

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);
    }
}
Also used : StateMachine(org.apache.ratis.statemachine.StateMachine) FileStoreStateMachine(org.apache.ratis.examples.filestore.FileStoreStateMachine) RaftServer(org.apache.ratis.server.RaftServer) RaftProperties(org.apache.ratis.conf.RaftProperties) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) ByteString(org.apache.ratis.thirdparty.com.google.protobuf.ByteString) RaftGroup(org.apache.ratis.protocol.RaftGroup) FileStoreStateMachine(org.apache.ratis.examples.filestore.FileStoreStateMachine)

Example 40 with RaftProperties

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);
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties)

Aggregations

RaftProperties (org.apache.ratis.conf.RaftProperties)54 Test (org.junit.Test)22 BaseTest (org.apache.ratis.BaseTest)14 Before (org.junit.Before)12 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)9 RaftServer (org.apache.ratis.server.RaftServer)8 File (java.io.File)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 RaftClient (org.apache.ratis.client.RaftClient)7 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Parameters (org.apache.ratis.conf.Parameters)4 LogEntryProto (org.apache.ratis.proto.RaftProtos.LogEntryProto)4 RaftGroupId (org.apache.ratis.protocol.RaftGroupId)4 RaftGroupMemberId (org.apache.ratis.protocol.RaftGroupMemberId)4 RaftGroup (org.apache.ratis.protocol.RaftGroup)3 StateMachine (org.apache.ratis.statemachine.StateMachine)3 TimeDuration (org.apache.ratis.util.TimeDuration)3 List (java.util.List)2 UUID (java.util.UUID)2