Search in sources :

Example 11 with CliOptions

use of com.alipay.sofa.jraft.option.CliOptions 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 12 with CliOptions

use of com.alipay.sofa.jraft.option.CliOptions 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);
}
Also used : MessageBusComponent(com.jd.blockchain.consensus.raft.msgbus.MessageBusComponent) NodeSettings(com.jd.blockchain.consensus.NodeSettings) RaftNodeSettings(com.jd.blockchain.consensus.raft.settings.RaftNodeSettings) Configuration(com.alipay.sofa.jraft.conf.Configuration) CliServiceImpl(com.alipay.sofa.jraft.core.CliServiceImpl) LedgerRepository(com.jd.blockchain.ledger.core.LedgerRepository) CliOptions(com.alipay.sofa.jraft.option.CliOptions)

Example 13 with CliOptions

use of com.alipay.sofa.jraft.option.CliOptions in project jdchain-core by blockchain-jd-com.

the class ParticipantManagerService4Raft method createRpcClient.

private CliClientServiceImpl createRpcClient(ParticipantContext context) {
    if (context.getProperty(RPC_CLIENT) != null) {
        return (CliClientServiceImpl) context.getProperty(RPC_CLIENT);
    }
    RaftConsensusSettings consensusSetting = (RaftConsensusSettings) getConsensusSetting(context);
    RaftNetworkSettings networkSettings = consensusSetting.getNetworkSettings();
    SSLSecurity sslSecurity = context.sslSecurity();
    // 启用TLS
    if (sslSecurity != null && sslSecurity.getKeyStore() != null) {
        GmSSLProvider.enableGMSupport(sslSecurity.getProtocol());
        setSystemProperty("bolt.client.ssl.enable", "true");
        setSystemProperty("bolt.client.ssl.keystore", sslSecurity.getTrustStore());
        setSystemProperty("bolt.client.ssl.keystore.password", sslSecurity.getTrustStorePassword());
        setSystemProperty("bolt.client.ssl.keystore.type", sslSecurity.getTrustStoreType() == null ? "JKS" : sslSecurity.getTrustStoreType());
        setSystemProperty("bolt.ssl.protocol", sslSecurity.getProtocol());
        setSystemProperty("bolt.server.ssl.enable", "true");
        setSystemProperty("bolt.server.ssl.keystore", sslSecurity.getKeyStore());
        setSystemProperty("bolt.server.ssl.keyalias", sslSecurity.getKeyAlias());
        setSystemProperty("bolt.server.ssl.keystore.password", sslSecurity.getKeyStorePassword());
        setSystemProperty("bolt.server.ssl.keystore.type", sslSecurity.getKeyStoreType());
        if (sslSecurity.getEnabledProtocols() != null && sslSecurity.getEnabledProtocols().length > 0) {
            setSystemProperty("bolt.ssl.enabled-protocols", String.join(",", sslSecurity.getEnabledProtocols()));
        }
        if (sslSecurity.getCiphers() != null && sslSecurity.getCiphers().length > 0) {
            setSystemProperty("bolt.ssl.ciphers", String.join(",", sslSecurity.getCiphers()));
        }
    }
    CliOptions cliOptions = new CliOptions();
    cliOptions.setRpcConnectTimeoutMs(networkSettings.getRpcConnectTimeoutMs());
    cliOptions.setRpcDefaultTimeout(networkSettings.getRpcDefaultTimeoutMs());
    cliOptions.setRpcInstallSnapshotTimeout(networkSettings.getRpcSnapshotTimeoutMs());
    cliOptions.setTimeoutMs(networkSettings.getRpcRequestTimeoutMs() * 2);
    cliOptions.setMaxRetry(MAX_RETRY_TIMES);
    CliClientServiceImpl clientService = new CliClientServiceImpl();
    clientService.init(cliOptions);
    context.setProperty(RPC_CLIENT, clientService);
    context.setProperty(RPC_QUEST_TIMEOUT_MS, networkSettings.getRpcRequestTimeoutMs() * 2);
    return clientService;
}
Also used : RaftNetworkSettings(com.jd.blockchain.consensus.raft.settings.RaftNetworkSettings) CliClientServiceImpl(com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl) RaftConsensusSettings(com.jd.blockchain.consensus.raft.settings.RaftConsensusSettings) SSLSecurity(utils.net.SSLSecurity) CliOptions(com.alipay.sofa.jraft.option.CliOptions)

Aggregations

CliOptions (com.alipay.sofa.jraft.option.CliOptions)13 PeerId (com.alipay.sofa.jraft.entity.PeerId)6 Configuration (com.alipay.sofa.jraft.conf.Configuration)5 CliServiceImpl (com.alipay.sofa.jraft.core.CliServiceImpl)4 CliClientServiceImpl (com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl)4 Status (com.alipay.sofa.jraft.Status)3 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)2 RaftOptions (com.alipay.sofa.jraft.option.RaftOptions)2 RheaKVCliService (com.alipay.sofa.jraft.rhea.client.RheaKVCliService)2 RheaKVStore (com.alipay.sofa.jraft.rhea.client.RheaKVStore)2 Endpoint (com.alipay.sofa.jraft.util.Endpoint)2 File (java.io.File)2 Before (org.junit.Before)2 Test (org.junit.Test)2 RouteTable (com.alipay.sofa.jraft.RouteTable)1 TestCluster (com.alipay.sofa.jraft.core.TestCluster)1 CliClientService (com.alipay.sofa.jraft.rpc.CliClientService)1 BooleanCommand (com.alipay.sofa.jraft.test.atomic.command.BooleanCommand)1 GetSlotsCommand (com.alipay.sofa.jraft.test.atomic.command.GetSlotsCommand)1 SlotsResponseCommand (com.alipay.sofa.jraft.test.atomic.command.SlotsResponseCommand)1