use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.
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;
}
use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.
the class AbstractPlacementDriverClient method transferLeader.
@Override
public boolean transferLeader(final String regionId, final Peer peer, final boolean refreshConf) {
Requires.requireNonNull(peer, "peer");
Requires.requireNonNull(peer.getEndpoint(), "peer.endpoint");
final String raftGroupId = JRaftHelper.getJRaftGroupId(this.clusterName, regionId);
final Configuration conf = RouteTable.getInstance().getConfiguration(raftGroupId);
final Status status = this.cliService.transferLeader(raftGroupId, conf, JRaftHelper.toJRaftPeerId(peer));
if (status.isOk()) {
if (refreshConf) {
refreshRouteConfiguration(regionId);
}
return true;
}
LOG.error("Fail to [transferLeader], [regionId: {}, peer: {}], status: {}.", regionId, peer, status);
return false;
}
use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.
the class AbstractPlacementDriverClient method getLuckyPeer.
@Override
public Endpoint getLuckyPeer(final String regionId, final boolean forceRefresh, final long timeoutMillis, final Endpoint unExpect) {
final String raftGroupId = JRaftHelper.getJRaftGroupId(this.clusterName, regionId);
final RouteTable routeTable = RouteTable.getInstance();
if (forceRefresh) {
final long deadline = System.currentTimeMillis() + timeoutMillis;
final StringBuilder error = new StringBuilder();
// or in the 'leader-transfer' state, it needs to be re-tried
for (; ; ) {
try {
final Status st = routeTable.refreshConfiguration(this.cliClientService, raftGroupId, 5000);
if (st.isOk()) {
break;
}
error.append(st.toString());
} catch (final InterruptedException e) {
ThrowUtil.throwException(e);
} catch (final TimeoutException e) {
error.append(e.getMessage());
}
if (System.currentTimeMillis() < deadline) {
LOG.debug("Fail to get peers, retry again, {}.", error);
error.append(", ");
try {
Thread.sleep(5);
} catch (final InterruptedException e) {
ThrowUtil.throwException(e);
}
} else {
throw new RouteTableException(error.toString());
}
}
}
final Configuration configs = routeTable.getConfiguration(raftGroupId);
if (configs == null) {
throw new RouteTableException("empty configs in group: " + raftGroupId);
}
final List<PeerId> peerList = configs.getPeers();
if (peerList == null || peerList.isEmpty()) {
throw new RouteTableException("empty peers in group: " + raftGroupId);
}
final int size = peerList.size();
if (size == 1) {
return peerList.get(0).getEndpoint();
}
final RoundRobinLoadBalancer balancer = RoundRobinLoadBalancer.getInstance(regionId);
for (int i = 0; i < size; i++) {
final PeerId candidate = balancer.select(peerList);
final Endpoint luckyOne = candidate.getEndpoint();
if (!luckyOne.equals(unExpect)) {
return luckyOne;
}
}
throw new RouteTableException("have no choice in group(peers): " + raftGroupId);
}
use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.
the class AbstractPlacementDriverClient method addReplica.
@Override
public boolean addReplica(final String regionId, final Peer peer, final boolean refreshConf) {
Requires.requireNonNull(peer, "peer");
Requires.requireNonNull(peer.getEndpoint(), "peer.endpoint");
final String raftGroupId = JRaftHelper.getJRaftGroupId(this.clusterName, regionId);
final Configuration conf = RouteTable.getInstance().getConfiguration(raftGroupId);
final Status status = this.cliService.addPeer(raftGroupId, conf, JRaftHelper.toJRaftPeerId(peer));
if (status.isOk()) {
if (refreshConf) {
refreshRouteConfiguration(regionId);
}
return true;
}
LOG.error("Fail to [addReplica], [regionId: {}, peer: {}], status: {}.", regionId, peer, status);
return false;
}
use of io.dingodb.raft.conf.Configuration in project dingo by dingodb.
the class AbstractPlacementDriverClient method getLocalRegionMetadata.
protected Region getLocalRegionMetadata(final RegionEngineOptions opts) {
final String regionId = Requires.requireNonNull(opts.getRegionId(), "opts.regionId");
final byte[] startKey = opts.getStartKeyBytes();
final byte[] endKey = opts.getEndKeyBytes();
final String initialServerList = opts.getInitialServerList();
final Region region = new Region();
final Configuration conf = new Configuration();
// region
region.setId(regionId);
region.setStartKey(startKey);
region.setEndKey(endKey);
region.setRegionEpoch(new RegionEpoch(-1, -1));
// peers
Requires.requireTrue(Strings.isNotBlank(initialServerList), "opts.initialServerList is blank");
conf.parse(initialServerList);
region.setPeers(JRaftHelper.toPeerList(conf.listPeers()));
this.regionRouteTable.addOrUpdateRegion(region);
return region;
}
Aggregations