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");
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");
/** * Keep appending entries, make sure the rolling is correct. */ @Test public void testAppendAndRoll() throws Exception { RaftServerConfigKeys.Log.setPreallocatedSize(properties, SizeInBytes.valueOf("16KB")); RaftServerConfigKeys.Log.setSegmentSizeMax(properties, SizeInBytes.valueOf("128KB")); List<SegmentRange> ranges = prepareRanges(1, 1024, 0); final byte[] content = new byte[1024]; List<LogEntryProto> entries = prepareLogEntries(ranges, () -> new String(content)); try (SegmentedRaftLog raftLog = new SegmentedRaftLog(peerId, null, storage, -1, properties)) { raftLog.open(RaftServerConstants.INVALID_LOG_INDEX, null); // append entries to the raftlog entries.stream().map(raftLog::appendEntry).forEach(CompletableFuture::join); } try (SegmentedRaftLog raftLog = new SegmentedRaftLog(peerId, null, storage, -1, properties)) { raftLog.open(RaftServerConstants.INVALID_LOG_INDEX, null); // check if the raft log is correct checkEntries(raftLog, entries, 0, entries.size()); Assert.assertEquals(9, raftLog.getRaftLogCache().getNumOfSegments()); } }
@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); }
/** * Keep appending entries, make sure the rolling is correct. */ @Test public void testAppendAndRoll() throws Exception { RaftServerConfigKeys.Log.setPreallocatedSize(properties, SizeInBytes.valueOf("16KB")); RaftServerConfigKeys.Log.setSegmentSizeMax(properties, SizeInBytes.valueOf("128KB")); List<SegmentRange> ranges = prepareRanges(0, 1, 1024, 0); final byte[] content = new byte[1024]; List<LogEntryProto> entries = prepareLogEntries(ranges, () -> new String(content)); try (SegmentedRaftLog raftLog = new SegmentedRaftLog(peerId, null, storage, -1, properties)) { raftLog.open(RaftServerConstants.INVALID_LOG_INDEX, null); // append entries to the raftlog entries.stream().map(raftLog::appendEntry).forEach(CompletableFuture::join); } try (SegmentedRaftLog raftLog = new SegmentedRaftLog(peerId, null, storage, -1, properties)) { raftLog.open(RaftServerConstants.INVALID_LOG_INDEX, null); // check if the raft log is correct checkEntries(raftLog, entries, 0, entries.size()); Assert.assertEquals(9, raftLog.getRaftLogCache().getNumOfSegments()); } }
@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); }
@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")); return ParameterizedBaseTest.getMiniRaftClusters(prop, 3); }