Search in sources :

Example 16 with Configuration

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;
}
Also used : Configuration(io.dingodb.raft.conf.Configuration) PeerId(io.dingodb.raft.entity.PeerId)

Example 17 with Configuration

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;
}
Also used : Status(io.dingodb.raft.Status) Configuration(io.dingodb.raft.conf.Configuration)

Example 18 with Configuration

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);
}
Also used : Status(io.dingodb.raft.Status) Configuration(io.dingodb.raft.conf.Configuration) RoundRobinLoadBalancer(io.dingodb.store.row.client.RoundRobinLoadBalancer) RouteTableException(io.dingodb.store.row.errors.RouteTableException) Endpoint(io.dingodb.raft.util.Endpoint) RegionRouteTable(io.dingodb.store.row.client.RegionRouteTable) RouteTable(io.dingodb.raft.RouteTable) Endpoint(io.dingodb.raft.util.Endpoint) TimeoutException(java.util.concurrent.TimeoutException) PeerId(io.dingodb.raft.entity.PeerId)

Example 19 with Configuration

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;
}
Also used : Status(io.dingodb.raft.Status) Configuration(io.dingodb.raft.conf.Configuration)

Example 20 with Configuration

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;
}
Also used : Configuration(io.dingodb.raft.conf.Configuration) Region(io.dingodb.store.row.metadata.Region) RegionEpoch(io.dingodb.store.row.metadata.RegionEpoch)

Aggregations

Configuration (io.dingodb.raft.conf.Configuration)31 PeerId (io.dingodb.raft.entity.PeerId)16 Status (io.dingodb.raft.Status)9 LogId (io.dingodb.raft.entity.LogId)5 ConfigurationEntry (io.dingodb.raft.conf.ConfigurationEntry)3 LogEntry (io.dingodb.raft.entity.LogEntry)3 CliRequests (io.dingodb.raft.rpc.CliRequests)3 TimeoutException (java.util.concurrent.TimeoutException)3 Message (com.google.protobuf.Message)2 RaftException (io.dingodb.raft.error.RaftException)2 NodeOptions (io.dingodb.raft.option.NodeOptions)2 RpcRequests (io.dingodb.raft.rpc.RpcRequests)2 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 com.lmax.disruptor (com.lmax.disruptor)1 Disruptor (com.lmax.disruptor.dsl.Disruptor)1 ProducerType (com.lmax.disruptor.dsl.ProducerType)1 Closure (io.dingodb.raft.Closure)1