Search in sources :

Example 21 with RaftOptions

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));
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) LogStorageOptions(com.alipay.sofa.jraft.option.LogStorageOptions) RocksDBSegmentLogStorage(com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage) Test(org.junit.Test)

Example 22 with RaftOptions

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"));
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) LocalFileMetaOutter(com.alipay.sofa.jraft.entity.LocalFileMetaOutter) ByteBufferCollector(com.alipay.sofa.jraft.util.ByteBufferCollector) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) BaseStorageTest(com.alipay.sofa.jraft.storage.BaseStorageTest)

Example 23 with RaftOptions

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())));
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) SnapshotCopierOptions(com.alipay.sofa.jraft.option.SnapshotCopierOptions) Endpoint(com.alipay.sofa.jraft.util.Endpoint) NodeOptions(com.alipay.sofa.jraft.option.NodeOptions) Test(org.junit.Test)

Example 24 with RaftOptions

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();
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) CliServiceImpl(com.alipay.sofa.jraft.core.CliServiceImpl) NodeOptions(com.alipay.sofa.jraft.option.NodeOptions) Endpoint(com.alipay.sofa.jraft.util.Endpoint) CliOptions(com.alipay.sofa.jraft.option.CliOptions)

Example 25 with RaftOptions

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;
}
Also used : RaftOptions(com.alipay.sofa.jraft.option.RaftOptions)

Aggregations

RaftOptions (com.alipay.sofa.jraft.option.RaftOptions)25 Test (org.junit.Test)11 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)9 Endpoint (com.alipay.sofa.jraft.util.Endpoint)9 Before (org.junit.Before)8 File (java.io.File)6 PeerId (com.alipay.sofa.jraft.entity.PeerId)5 LocalFileMetaOutter (com.alipay.sofa.jraft.entity.LocalFileMetaOutter)4 TimerManager (com.alipay.sofa.jraft.core.TimerManager)3 CopyOptions (com.alipay.sofa.jraft.option.CopyOptions)3 LogStorageOptions (com.alipay.sofa.jraft.option.LogStorageOptions)3 SnapshotCopierOptions (com.alipay.sofa.jraft.option.SnapshotCopierOptions)3 BaseStorageTest (com.alipay.sofa.jraft.storage.BaseStorageTest)3 RocksDBSegmentLogStorage (com.alipay.sofa.jraft.storage.log.RocksDBSegmentLogStorage)3 ByteBuffer (java.nio.ByteBuffer)3 Node (com.alipay.sofa.jraft.Node)2 Configuration (com.alipay.sofa.jraft.conf.Configuration)2 ConfigurationManager (com.alipay.sofa.jraft.conf.ConfigurationManager)2 CliServiceImpl (com.alipay.sofa.jraft.core.CliServiceImpl)2 CliOptions (com.alipay.sofa.jraft.option.CliOptions)2