Search in sources :

Example 1 with RaftClientService

use of io.dingodb.raft.rpc.RaftClientService in project dingo by dingodb.

the class ReplicatorGroupImpl method addReplicator.

@Override
public boolean addReplicator(final PeerId peer, final ReplicatorType replicatorType, final boolean sync) {
    Requires.requireTrue(this.commonOptions.getTerm() != 0);
    this.failureReplicators.remove(peer);
    if (this.replicatorMap.containsKey(peer)) {
        return true;
    }
    final ReplicatorOptions opts = this.commonOptions == null ? new ReplicatorOptions() : this.commonOptions.copy();
    opts.setReplicatorType(replicatorType);
    opts.setPeerId(peer);
    if (!sync) {
        final RaftClientService client = opts.getRaftRpcService();
        if (client != null && !client.checkConnection(peer.getEndpoint(), true)) {
            LOG.error("Fail to check replicator connection to peer={}, replicatorType={}.", peer, replicatorType);
            this.failureReplicators.put(peer, replicatorType);
            return false;
        }
    }
    final ThreadId rid = Replicator.start(opts, this.raftOptions);
    if (rid == null) {
        LOG.error("Fail to start replicator to peer={}, replicatorType={}.", peer, replicatorType);
        this.failureReplicators.put(peer, replicatorType);
        return false;
    }
    return this.replicatorMap.put(peer, rid) == null;
}
Also used : RaftClientService(io.dingodb.raft.rpc.RaftClientService) ThreadId(io.dingodb.raft.util.ThreadId) ReplicatorOptions(io.dingodb.raft.option.ReplicatorOptions)

Aggregations

ReplicatorOptions (io.dingodb.raft.option.ReplicatorOptions)1 RaftClientService (io.dingodb.raft.rpc.RaftClientService)1 ThreadId (io.dingodb.raft.util.ThreadId)1