Search in sources :

Example 1 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class MiniRaftCluster method newRaftServer.

private RaftServerProxy newRaftServer(RaftPeerId id, RaftGroup group, boolean format) {
    try {
        final File dir = getStorageDir(id);
        if (format) {
            FileUtils.deleteFully(dir);
            LOG.info("Formatted directory {}", dir);
        }
        final RaftProperties prop = new RaftProperties(properties);
        RaftServerConfigKeys.setStorageDir(prop, dir);
        final StateMachine stateMachine = getStateMachine4Test(properties);
        return newRaftServer(id, stateMachine, group, prop);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : StateMachine(org.apache.ratis.statemachine.StateMachine) BaseStateMachine(org.apache.ratis.statemachine.impl.BaseStateMachine) RaftProperties(org.apache.ratis.conf.RaftProperties) IOException(java.io.IOException) File(java.io.File)

Example 2 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class RaftAsyncTests method setup.

@Before
public void setup() {
    properties = new RaftProperties();
    properties.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
    TimeDuration retryCacheExpiryDuration = TimeDuration.valueOf(5, TimeUnit.SECONDS);
    RaftServerConfigKeys.RetryCache.setExpiryTime(properties, retryCacheExpiryDuration);
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) TimeDuration(org.apache.ratis.util.TimeDuration)

Example 3 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class RaftExceptionBaseTest method setup.

@Before
public void setup() throws IOException {
    final RaftProperties prop = getProperties();
    RaftServerConfigKeys.Log.Appender.setBufferCapacity(prop, SizeInBytes.valueOf("4KB"));
    cluster = newCluster(NUM_PEERS);
    cluster.start();
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) Before(org.junit.Before)

Example 4 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class TestBatchAppend method data.

@Parameterized.Parameters
public static Collection<Object[]> data() throws IOException {
    RaftProperties prop = new RaftProperties();
    prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
    RaftServerConfigKeys.Log.setSegmentSizeMax(prop, SizeInBytes.valueOf("8KB"));
    // enable batch appending
    RaftServerConfigKeys.Log.Appender.setBatchEnabled(prop, true);
    // set batch appending buffer size to 4KB
    RaftServerConfigKeys.Log.Appender.setBufferCapacity(prop, SizeInBytes.valueOf("8KB"));
    return ParameterizedBaseTest.getMiniRaftClusters(prop, 3);
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties)

Example 5 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class TestCacheEviction method testEvictionInSegmentedLog.

@Test
public void testEvictionInSegmentedLog() throws Exception {
    final RaftProperties prop = new RaftProperties();
    prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
    RaftServerConfigKeys.Log.setSegmentSizeMax(prop, SizeInBytes.valueOf("8KB"));
    RaftServerConfigKeys.Log.setPreallocatedSize(prop, SizeInBytes.valueOf("8KB"));
    final RaftPeerId peerId = RaftPeerId.valueOf("s0");
    final int maxCachedNum = RaftServerConfigKeys.Log.maxCachedSegmentNum(prop);
    File storageDir = getTestDir();
    RaftServerConfigKeys.setStorageDir(prop, storageDir);
    RaftStorage storage = new RaftStorage(storageDir, RaftServerConstants.StartupOption.REGULAR);
    RaftServerImpl server = Mockito.mock(RaftServerImpl.class);
    ServerState state = Mockito.mock(ServerState.class);
    Mockito.when(server.getState()).thenReturn(state);
    Mockito.when(server.getFollowerNextIndices()).thenReturn(new long[] {});
    Mockito.when(state.getLastAppliedIndex()).thenReturn(0L);
    SegmentedRaftLog raftLog = new SegmentedRaftLog(peerId, server, storage, -1, prop);
    raftLog.open(RaftServerConstants.INVALID_LOG_INDEX, null);
    List<SegmentRange> slist = TestSegmentedRaftLog.prepareRanges(maxCachedNum, 7, 0);
    LogEntryProto[] entries = generateEntries(slist);
    raftLog.append(entries).forEach(CompletableFuture::join);
    // check the current cached segment number: the last segment is still open
    Assert.assertEquals(maxCachedNum - 1, raftLog.getRaftLogCache().getCachedSegmentNum());
    Mockito.when(server.getFollowerNextIndices()).thenReturn(new long[] { 21, 40, 40 });
    Mockito.when(state.getLastAppliedIndex()).thenReturn(35L);
    slist = TestSegmentedRaftLog.prepareRanges(2, 7, 7 * maxCachedNum);
    entries = generateEntries(slist);
    raftLog.append(entries).forEach(CompletableFuture::join);
    // check the cached segment number again. since the slowest follower is on
    // index 21, the eviction should happen and evict 3 segments
    Assert.assertEquals(maxCachedNum + 1 - 3, raftLog.getRaftLogCache().getCachedSegmentNum());
}
Also used : SegmentRange(org.apache.ratis.server.storage.TestSegmentedRaftLog.SegmentRange) ServerState(org.apache.ratis.server.impl.ServerState) RaftProperties(org.apache.ratis.conf.RaftProperties) RaftServerImpl(org.apache.ratis.server.impl.RaftServerImpl) CompletableFuture(java.util.concurrent.CompletableFuture) LogEntryProto(org.apache.ratis.shaded.proto.RaftProtos.LogEntryProto) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) File(java.io.File) Test(org.junit.Test) BaseTest(org.apache.ratis.BaseTest)

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