use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.
the class GrpcClient method notifyReady.
private void notifyReady(final Endpoint endpoint) {
LOG.info("The channel {} has successfully established.", endpoint);
clearConnFailuresCount(endpoint);
final ReplicatorGroup rpGroup = this.replicatorGroup;
if (rpGroup != null) {
try {
RpcUtils.runInThread(() -> {
final PeerId peer = new PeerId();
if (peer.parse(endpoint.toString())) {
LOG.info("Peer {} is connected.", peer);
rpGroup.checkReplicator(peer, true);
} else {
LOG.error("Fail to parse peer: {}.", endpoint);
}
});
} catch (final Throwable t) {
LOG.error("Fail to check replicator {}.", endpoint, t);
}
}
}
use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.
the class ElectionNode method init.
@Override
public boolean init(final ElectionNodeOptions opts) {
if (this.started) {
LOG.info("[ElectionNode: {}] already started.", opts.getServerAddress());
return true;
}
// node options
NodeOptions nodeOpts = opts.getNodeOptions();
if (nodeOpts == null) {
nodeOpts = new NodeOptions();
}
this.fsm = new ElectionOnlyStateMachine(this.listeners);
nodeOpts.setFsm(this.fsm);
final Configuration initialConf = new Configuration();
if (!initialConf.parse(opts.getInitialServerAddressList())) {
throw new IllegalArgumentException("Fail to parse initConf: " + opts.getInitialServerAddressList());
}
// Set the initial cluster configuration
nodeOpts.setInitialConf(initialConf);
final String dataPath = opts.getDataPath();
try {
FileUtils.forceMkdir(new File(dataPath));
} catch (final IOException e) {
LOG.error("Fail to make dir for dataPath {}.", dataPath);
return false;
}
// Set the data path
// Log, required
nodeOpts.setLogUri(Paths.get(dataPath, "log").toString());
// Metadata, required
nodeOpts.setRaftMetaUri(Paths.get(dataPath, "meta").toString());
// nodeOpts.setSnapshotUri(Paths.get(dataPath, "snapshot").toString());
final String groupId = opts.getGroupId();
final PeerId serverId = new PeerId();
if (!serverId.parse(opts.getServerAddress())) {
throw new IllegalArgumentException("Fail to parse serverId: " + opts.getServerAddress());
}
final RpcServer rpcServer = RaftRpcServerFactory.createRaftRpcServer(serverId.getEndpoint());
this.raftGroupService = new RaftGroupService(groupId, serverId, nodeOpts, rpcServer);
this.node = this.raftGroupService.start();
if (this.node != null) {
this.started = true;
}
return this.started;
}
use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.
the class PriorityElectionNode method init.
@Override
public boolean init(final PriorityElectionNodeOptions opts) {
if (this.started) {
LOG.info("[PriorityElectionNode: {}] already started.", opts.getServerAddress());
return true;
}
// node options
NodeOptions nodeOpts = opts.getNodeOptions();
if (nodeOpts == null) {
nodeOpts = new NodeOptions();
}
this.fsm = new PriorityElectionOnlyStateMachine(this.listeners);
// Set the initial PriorityElectionOnlyStateMachine
nodeOpts.setFsm(this.fsm);
final Configuration initialConf = new Configuration();
if (!initialConf.parse(opts.getInitialServerAddressList())) {
throw new IllegalArgumentException("Fail to parse initConf: " + opts.getInitialServerAddressList());
}
// Set the initial cluster configuration
nodeOpts.setInitialConf(initialConf);
final String dataPath = opts.getDataPath();
try {
FileUtils.forceMkdir(new File(dataPath));
} catch (final IOException e) {
LOG.error("Fail to make dir for dataPath {}.", dataPath);
return false;
}
// Set the data path
// Log, required
nodeOpts.setLogUri(Paths.get(dataPath, "log").toString());
// Metadata, required
nodeOpts.setRaftMetaUri(Paths.get(dataPath, "meta").toString());
// nodeOpts.setSnapshotUri(Paths.get(dataPath, "snapshot").toString());
final String groupId = opts.getGroupId();
final PeerId serverId = new PeerId();
if (!serverId.parse(opts.getServerAddress())) {
throw new IllegalArgumentException("Fail to parse serverId: " + opts.getServerAddress());
}
/**
* Set priority value, required for priority-based election, it must be a positive value when
* enable the feature, some special value meaning:
* <ul>
* <li>-1 : disable priority-based election.</li>
* <li>0: will never participate in election.</li>
* <li>1: minimum value</li>
* </ul>
* value.
*/
nodeOpts.setElectionPriority(serverId.getPriority());
final RpcServer rpcServer = RaftRpcServerFactory.createRaftRpcServer(serverId.getEndpoint());
this.raftGroupService = new RaftGroupService(groupId, serverId, nodeOpts, rpcServer);
this.node = this.raftGroupService.start();
if (this.node != null) {
this.started = true;
}
return this.started;
}
use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.
the class LogManagerImpl method oldConfFromMeta.
private Configuration oldConfFromMeta(final SnapshotMeta meta) {
final Configuration oldConf = new Configuration();
for (int i = 0; i < meta.getOldPeersCount(); i++) {
final PeerId peer = new PeerId();
peer.parse(meta.getOldPeers(i));
oldConf.addPeer(peer);
}
for (int i = 0; i < meta.getOldLearnersCount(); i++) {
final PeerId peer = new PeerId();
peer.parse(meta.getOldLearners(i));
oldConf.addLearner(peer);
}
return oldConf;
}
use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.
the class LogManagerImpl method confFromMeta.
private Configuration confFromMeta(final SnapshotMeta meta) {
final Configuration conf = new Configuration();
for (int i = 0; i < meta.getPeersCount(); i++) {
final PeerId peer = new PeerId();
peer.parse(meta.getPeers(i));
conf.addPeer(peer);
}
for (int i = 0; i < meta.getLearnersCount(); i++) {
final PeerId peer = new PeerId();
peer.parse(meta.getLearners(i));
conf.addLearner(peer);
}
return conf;
}
Aggregations