use of io.dingodb.raft.option.ReplicatorOptions in project dingo by dingodb.
the class ReplicatorGroupImpl method init.
@Override
public boolean init(final NodeId nodeId, final ReplicatorGroupOptions opts) {
this.dynamicTimeoutMs = opts.getHeartbeatTimeoutMs();
this.electionTimeoutMs = opts.getElectionTimeoutMs();
this.raftOptions = opts.getRaftOptions();
this.commonOptions = new ReplicatorOptions();
this.commonOptions.setDynamicHeartBeatTimeoutMs(this.dynamicTimeoutMs);
this.commonOptions.setElectionTimeoutMs(this.electionTimeoutMs);
this.commonOptions.setRaftRpcService(opts.getRaftRpcClientService());
this.commonOptions.setLogManager(opts.getLogManager());
this.commonOptions.setBallotBox(opts.getBallotBox());
this.commonOptions.setNode(opts.getNode());
this.commonOptions.setTerm(0);
this.commonOptions.setGroupId(nodeId.getGroupId());
this.commonOptions.setServerId(nodeId.getPeerId());
this.commonOptions.setSnapshotStorage(opts.getSnapshotStorage());
this.commonOptions.setTimerManager(opts.getTimerManager());
return true;
}
use of io.dingodb.raft.option.ReplicatorOptions in project dingo by dingodb.
the class Replicator method notifyReplicatorStatusListener.
/**
* Notify replicator event(such as created, error, destroyed) to replicatorStateListener which is implemented by users.
*
* @param replicator replicator object
* @param event replicator's state listener event type
* @param status replicator's error detailed status
*/
private static void notifyReplicatorStatusListener(final Replicator replicator, final ReplicatorEvent event, final Status status, final ReplicatorStateListener.ReplicatorState newState) {
final ReplicatorOptions replicatorOpts = Requires.requireNonNull(replicator.getOpts(), "replicatorOptions");
final Node node = Requires.requireNonNull(replicatorOpts.getNode(), "node");
final PeerId peer = Requires.requireNonNull(replicatorOpts.getPeerId(), "peer");
final List<ReplicatorStateListener> listenerList = node.getReplicatorStatueListeners();
for (int i = 0; i < listenerList.size(); i++) {
final ReplicatorStateListener listener = listenerList.get(i);
if (listener != null) {
try {
switch(event) {
case CREATED:
RpcUtils.runInThread(() -> listener.onCreated(peer));
break;
case ERROR:
RpcUtils.runInThread(() -> listener.onError(peer, status));
break;
case DESTROYED:
RpcUtils.runInThread(() -> listener.onDestroyed(peer));
break;
case STATE_CHANGED:
RpcUtils.runInThread(() -> listener.stateChanged(peer, newState));
default:
break;
}
} catch (final Exception e) {
LOG.error("Fail to notify ReplicatorStatusListener, listener={}, event={}.", listener, event);
}
}
}
}
use of io.dingodb.raft.option.ReplicatorOptions 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;
}
Aggregations