use of com.alipay.sofa.jraft.core.CliServiceImpl in project nacos by alibaba.
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.core.CliServiceImpl in project sofa-jraft by sofastack.
the class DefaultRheaKVCliService method initCli.
private void initCli(CliOptions cliOpts) {
if (cliOpts == null) {
cliOpts = new CliOptions();
cliOpts.setTimeoutMs(5000);
cliOpts.setMaxRetry(3);
}
this.opts = cliOpts;
this.cliService = RaftServiceFactory.createAndInitCliService(cliOpts);
final CliClientService cliClientService = ((CliServiceImpl) this.cliService).getCliClientService();
Requires.requireNonNull(cliClientService, "cliClientService");
this.rpcClient = ((AbstractClientService) cliClientService).getRpcClient();
}
use of com.alipay.sofa.jraft.core.CliServiceImpl 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.core.CliServiceImpl in project jdchain-core by blockchain-jd-com.
the class RaftNodeServer method init.
private void init(RaftServerSettings raftServerSettings) {
this.selfPeerId = nodeSettingsToPeerId(raftServerSettings.getReplicaSettings());
this.configuration = new Configuration();
for (NodeSettings nodeSettings : raftServerSettings.getConsensusSettings().getNodes()) {
this.configuration.addPeer(nodeSettingsToPeerId(nodeSettings));
}
if (!this.configuration.contains(selfPeerId)) {
this.configuration.addPeer(selfPeerId);
}
this.clientAuthencationService = new RaftClientAuthenticationService(this);
CliOptions cliOptions = new CliOptions();
cliOptions.setRpcConnectTimeoutMs(this.serverSettings.getRaftNetworkSettings().getRpcConnectTimeoutMs());
cliOptions.setRpcDefaultTimeout(this.serverSettings.getRaftNetworkSettings().getRpcDefaultTimeoutMs());
cliOptions.setRpcInstallSnapshotTimeout(this.serverSettings.getRaftNetworkSettings().getRpcSnapshotTimeoutMs());
this.raftClientService = (CliClientServiceImpl) ((CliServiceImpl) RaftServiceFactory.createAndInitCliService(cliOptions)).getCliClientService();
this.rpcClient = this.raftClientService.getRpcClient();
this.nodeOptions = initNodeOptions(raftServerSettings);
this.nodeOptions.setInitialConf(this.configuration);
LedgerRepository ledgerRepository = LedgerManageUtils.getLedgerRepository(this.ledgerHashDigest);
this.messageBus = new MessageBusComponent(raftServerSettings.getRaftSettings().getDisruptorBufferSize());
this.blockSerializer = new SimpleBlockSerializerService();
this.blockProposer = new BlockProposerService(ledgerRepository);
this.blockCommitter = new BlockCommitService(this.realmName, this.messageHandle, ledgerRepository, this.messageBus);
this.blockCommitter.registerCallBack((BlockCommitCallback) blockProposer);
this.blockSyncer = new BlockSyncService(ledgerRepository, this.rpcClient, this.serverSettings.getRaftNetworkSettings().getRpcRequestTimeoutMs());
messageBus.register(BLOCK_CATCH_UP_TOPIC, (Subcriber) this.blockSyncer);
this.stateMachine = new RaftConsensusStateMachine(this.blockCommitter, this.blockSerializer, this.blockSyncer, ledgerRepository);
this.nodeOptions.setFsm(stateMachine);
RaftNodeServerContext.getInstance().init(this);
}
Aggregations