use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.
the class RocksDBSegmentLogStorageTest method testTruncateSuffixWithDifferentValueSize.
@Test
public void testTruncateSuffixWithDifferentValueSize() throws Exception {
// shutdown the old one
this.logStorage.shutdown();
// Set value threshold to be 32 bytes.
this.logStorage = new RocksDBSegmentLogStorage(this.path, new RaftOptions(), 32, 64);
final LogStorageOptions opts = newLogStorageOptions();
this.logStorage.init(opts);
int term = 1;
for (int i = 0; i < 10; i++) {
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(i, term, i)));
}
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(10, term, 64)));
for (int i = 11; i < 20; i++) {
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(i, term, i)));
}
for (int i = 0; i < 20; i++) {
assertNotNull(this.logStorage.getEntry(i));
}
assertEquals(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead().getWrotePos(), 179);
this.logStorage.truncateSuffix(15);
for (int i = 0; i < 20; i++) {
if (i <= 15) {
assertNotNull(this.logStorage.getEntry(i));
} else {
assertNull(this.logStorage.getEntry(i));
}
}
assertEquals(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead().getWrotePos(), 102);
this.logStorage.truncateSuffix(13);
for (int i = 0; i < 20; i++) {
if (i <= 13) {
assertNotNull(this.logStorage.getEntry(i));
} else {
assertNull(this.logStorage.getEntry(i));
}
}
assertEquals(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead().getWrotePos(), 102);
this.logStorage.truncateSuffix(5);
for (int i = 0; i < 20; i++) {
if (i <= 5) {
assertNotNull(this.logStorage.getEntry(i));
} else {
assertNull(this.logStorage.getEntry(i));
}
}
assertNull(((RocksDBSegmentLogStorage) this.logStorage).getLastSegmentFileForRead());
this.logStorage.appendEntries(Arrays.asList(TestUtils.mockEntry(20, term, 10)));
assertNotNull(this.logStorage.getEntry(20));
}
use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.
the class SnapshotFileReaderTest method testReadMetaFile.
@Test
public void testReadMetaFile() throws Exception {
final ByteBufferCollector bufRef = ByteBufferCollector.allocate(1024);
final LocalFileMetaOutter.LocalFileMeta meta = addDataMeta();
assertEquals(-1, this.reader.readFile(bufRef, Snapshot.JRAFT_SNAPSHOT_META_FILE, 0, Integer.MAX_VALUE));
final ByteBuffer buf = bufRef.getBuffer();
buf.flip();
final LocalSnapshotMetaTable newTable = new LocalSnapshotMetaTable(new RaftOptions());
newTable.loadFromIoBufferAsRemote(buf);
Assert.assertEquals(meta, newTable.getFileMeta("data"));
}
use of com.alipay.sofa.jraft.option.RaftOptions in project sofa-jraft by sofastack.
the class RemoteFileCopierTest method testInitFail.
@Test
public void testInitFail() {
Mockito.when(rpcService.connect(new Endpoint("localhost", 8081))).thenReturn(false);
assertFalse(copier.init("remote://localhost:8081/999", null, new SnapshotCopierOptions(rpcService, timerManager, new RaftOptions(), new NodeOptions())));
}
use of com.alipay.sofa.jraft.option.RaftOptions in project mmqtt by MrHKing.
the class JRaftServer method init.
void init(RaftConfig config) {
this.raftConfig = config;
this.serializer = SerializeFactory.getDefault();
Loggers.RAFT.info("Initializes the Raft protocol, raft-config info : {}", config);
RaftExecutor.init(config);
final String self = config.getSelfMember();
String[] info = InternetAddressUtil.splitIPPortStr(self);
selfIp = info[0];
selfPort = Integer.parseInt(info[1]);
localPeerId = PeerId.parsePeer(self);
nodeOptions = new NodeOptions();
// Set the election timeout time. The default is 5 seconds.
int electionTimeout = Math.max(ConvertUtils.toInt(config.getVal(RaftSysConstants.RAFT_ELECTION_TIMEOUT_MS), RaftSysConstants.DEFAULT_ELECTION_TIMEOUT), RaftSysConstants.DEFAULT_ELECTION_TIMEOUT);
rpcRequestTimeoutMs = ConvertUtils.toInt(raftConfig.getVal(RaftSysConstants.RAFT_RPC_REQUEST_TIMEOUT_MS), RaftSysConstants.DEFAULT_RAFT_RPC_REQUEST_TIMEOUT_MS);
nodeOptions.setSharedElectionTimer(true);
nodeOptions.setSharedVoteTimer(true);
nodeOptions.setSharedStepDownTimer(true);
nodeOptions.setSharedSnapshotTimer(true);
nodeOptions.setElectionTimeoutMs(electionTimeout);
RaftOptions raftOptions = RaftOptionsBuilder.initRaftOptions(raftConfig);
nodeOptions.setRaftOptions(raftOptions);
// open jraft node metrics record function
nodeOptions.setEnableMetrics(true);
CliOptions cliOptions = new CliOptions();
this.cliService = RaftServiceFactory.createAndInitCliService(cliOptions);
this.cliClientService = (CliClientServiceImpl) ((CliServiceImpl) this.cliService).getCliClientService();
}
use of com.alipay.sofa.jraft.option.RaftOptions in project jdchain-core by blockchain-jd-com.
the class RaftConfig method buildRaftOptions.
public static RaftOptions buildRaftOptions(RaftSettings raftSettings) {
RaftOptions raftOptions = new RaftOptions();
raftOptions.setMaxByteCountPerRpc(raftSettings.getMaxByteCountPerRpc());
raftOptions.setMaxEntriesSize(raftSettings.getMaxEntriesSize());
raftOptions.setMaxBodySize(raftSettings.getMaxBodySize());
raftOptions.setMaxAppendBufferSize(raftSettings.getMaxAppendBufferSize());
raftOptions.setMaxElectionDelayMs(raftSettings.getMaxElectionDelayMs());
raftOptions.setElectionHeartbeatFactor(raftSettings.getElectionHeartbeatFactor());
raftOptions.setApplyBatch(raftSettings.getApplyBatch());
raftOptions.setSync(raftSettings.isSync());
raftOptions.setSyncMeta(raftSettings.isSyncMeta());
raftOptions.setDisruptorBufferSize(raftSettings.getDisruptorBufferSize());
raftOptions.setReplicatorPipeline(raftSettings.isReplicatorPipeline());
raftOptions.setMaxReplicatorInflightMsgs(raftSettings.getMaxReplicatorInflightMsgs());
return raftOptions;
}
Aggregations