Search in sources :

Example 21 with Endpoint

use of io.dingodb.raft.util.Endpoint in project dingo by dingodb.

the class PeerId method parse.

/**
 * Parse peerId from string that generated by {@link #toString()}
 * This method can support parameter string values are below:
 *
 * <pre>
 * PeerId.parse("a:b")          = new PeerId("a", "b", 0 , -1)
 * PeerId.parse("a:b:c")        = new PeerId("a", "b", "c", -1)
 * PeerId.parse("a:b::d")       = new PeerId("a", "b", 0, "d")
 * PeerId.parse("a:b:c:d")      = new PeerId("a", "b", "c", "d")
 * </pre>
 */
public boolean parse(final String s) {
    if (StringUtils.isEmpty(s)) {
        return false;
    }
    final String[] tmps = Utils.parsePeerId(s);
    if (tmps.length < 2 || tmps.length > 4) {
        return false;
    }
    try {
        final int port = Integer.parseInt(tmps[1]);
        this.endpoint = new Endpoint(tmps[0], port);
        switch(tmps.length) {
            case 3:
                this.idx = Integer.parseInt(tmps[2]);
                break;
            case 4:
                if (tmps[2].equals("")) {
                    this.idx = 0;
                } else {
                    this.idx = Integer.parseInt(tmps[2]);
                }
                this.priority = Integer.parseInt(tmps[3]);
                break;
            default:
                break;
        }
        this.str = null;
        return true;
    } catch (final Exception e) {
        LOG.error("Parse peer from string failed: {}.", s, e);
        return false;
    }
}
Also used : Endpoint(io.dingodb.raft.util.Endpoint) Endpoint(io.dingodb.raft.util.Endpoint)

Example 22 with Endpoint

use of io.dingodb.raft.util.Endpoint in project dingo by dingodb.

the class DefaultDingoRowStore method init.

@Override
public synchronized boolean init(final DingoRowStoreOptions opts) {
    if (this.started) {
        LOG.info("[DefaultDingoRowStore] already started.");
        return true;
    }
    DescriberManager.getInstance().addDescriber(RouteTable.getInstance());
    this.opts = opts;
    // init placement driver
    final PlacementDriverOptions pdOpts = opts.getPlacementDriverOptions();
    final String clusterName = opts.getClusterName();
    Requires.requireNonNull(pdOpts, "opts.placementDriverOptions");
    Requires.requireNonNull(clusterName, "opts.clusterName");
    if (Strings.isBlank(pdOpts.getInitialServerList())) {
        // if blank, extends parent's value
        pdOpts.setInitialServerList(opts.getInitialServerList());
    }
    if (pdOpts.isFake()) {
        this.pdClient = new FakePlacementDriverClient(opts.getClusterId(), clusterName);
    } else {
        this.pdClient = new RemotePlacementDriverClient(opts.getClusterId(), clusterName);
    }
    if (!this.pdClient.init(pdOpts)) {
        LOG.error("Fail to init [PlacementDriverClient].");
        return false;
    }
    // init compress strategies
    ZipStrategyManager.init(opts);
    // init store engine
    final StoreEngineOptions stOpts = opts.getStoreEngineOptions();
    if (stOpts != null) {
        stOpts.setInitialServerList(opts.getInitialServerList());
        this.storeEngine = new StoreEngine(this.pdClient, this.stateListenerContainer);
        if (!this.storeEngine.init(stOpts)) {
            LOG.error("Fail to init [StoreEngine].");
            return false;
        }
    }
    final Endpoint selfEndpoint = this.storeEngine == null ? null : this.storeEngine.getSelfEndpoint();
    final RpcOptions rpcOpts = opts.getRpcOptions();
    Requires.requireNonNull(rpcOpts, "opts.rpcOptions");
    this.dingoRowStoreRpcService = new DefaultDingoRowStoreRpcService(this.pdClient, selfEndpoint) {

        @Override
        public Endpoint getLeader(final String regionId, final boolean forceRefresh, final long timeoutMillis) {
            final Endpoint leader = getLeaderByRegionEngine(regionId);
            if (leader != null) {
                return leader;
            }
            return super.getLeader(regionId, forceRefresh, timeoutMillis);
        }
    };
    if (!this.dingoRowStoreRpcService.init(rpcOpts)) {
        LOG.error("Fail to init [DingoRowStoreRpcService].");
        return false;
    }
    this.failoverRetries = opts.getFailoverRetries();
    this.futureTimeoutMillis = opts.getFutureTimeoutMillis();
    this.onlyLeaderRead = opts.isOnlyLeaderRead();
    if (opts.isUseParallelKVExecutor()) {
        final int numWorkers = Utils.cpus();
        final int bufSize = numWorkers << 4;
        final String name = "parallel-kv-executor";
        final ThreadFactory threadFactory = Constants.THREAD_AFFINITY_ENABLED ? new AffinityNamedThreadFactory(name, true) : new NamedThreadFactory(name, true);
        this.kvDispatcher = new TaskDispatcher(bufSize, numWorkers, WaitStrategyType.LITE_BLOCKING_WAIT, threadFactory);
    }
    this.batchingOpts = opts.getBatchingOptions();
    if (this.batchingOpts.isAllowBatching()) {
        this.getBatching = new GetBatching(KeyEvent::new, "get_batching", new GetBatchingHandler("get", false));
        this.getBatchingOnlySafe = new GetBatching(KeyEvent::new, "get_batching_only_safe", new GetBatchingHandler("get_only_safe", true));
        this.putBatching = new PutBatching(KVEvent::new, "put_batching", new PutBatchingHandler("put"));
    }
    LOG.info("[DefaultDingoRowStore] start successfully, options: {}.", opts);
    return this.started = true;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) AffinityNamedThreadFactory(io.dingodb.store.row.util.concurrent.AffinityNamedThreadFactory) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory) PlacementDriverOptions(io.dingodb.store.row.options.PlacementDriverOptions) AffinityNamedThreadFactory(io.dingodb.store.row.util.concurrent.AffinityNamedThreadFactory) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory) RemotePlacementDriverClient(io.dingodb.store.row.client.pd.RemotePlacementDriverClient) Endpoint(io.dingodb.raft.util.Endpoint) StoreEngine(io.dingodb.store.row.StoreEngine) RpcOptions(io.dingodb.store.row.options.RpcOptions) Endpoint(io.dingodb.raft.util.Endpoint) TaskDispatcher(io.dingodb.store.row.util.concurrent.disruptor.TaskDispatcher) FakePlacementDriverClient(io.dingodb.store.row.client.pd.FakePlacementDriverClient) StoreEngineOptions(io.dingodb.store.row.options.StoreEngineOptions) AffinityNamedThreadFactory(io.dingodb.store.row.util.concurrent.AffinityNamedThreadFactory)

Example 23 with Endpoint

use of io.dingodb.raft.util.Endpoint in project dingo by dingodb.

the class JRaftHelper method toPeer.

public static Peer toPeer(final PeerId peerId) {
    Requires.requireNonNull(peerId, "peerId");
    final Endpoint endpoint = peerId.getEndpoint();
    Requires.requireNonNull(endpoint, "peerId.endpoint");
    final Peer peer = new Peer();
    peer.setId("-1");
    peer.setStoreId("-1");
    peer.setEndpoint(endpoint.copy());
    return peer;
}
Also used : Endpoint(io.dingodb.raft.util.Endpoint) Peer(io.dingodb.store.row.metadata.Peer)

Example 24 with Endpoint

use of io.dingodb.raft.util.Endpoint in project dingo by dingodb.

the class RegionHeartbeatHandler method balance.

private Instruction balance(Region region, RegionStats regionStats) {
    final long clusterId = 0;
    final String storeId = regionStats.getLeader().getStoreId();
    final ClusterStatsManager clusterStatsManager = ClusterStatsManager.getInstance(clusterId);
    clusterStatsManager.addOrUpdateLeader(storeId, region.getId());
    // check if the modelWorker
    final Pair<Set<String>, Integer> modelWorkers = clusterStatsManager.findModelWorkerStores(1);
    final Set<String> modelWorkerStoreIds = modelWorkers.getKey();
    final int modelWorkerLeaders = modelWorkers.getValue();
    if (!modelWorkerStoreIds.contains(storeId)) {
        return null;
    }
    log.info("[Cluster] model worker stores is: {}, it has {} leaders.", modelWorkerStoreIds, modelWorkerLeaders);
    final List<Peer> peers = region.getPeers();
    if (peers == null) {
        return null;
    }
    final List<Endpoint> endpoints = Lists.transform(peers, Peer::getEndpoint);
    final Map<String, Endpoint> storeIds = rowStoreMetaAdaptor.storeLocation();
    // find lazyWorkers
    final List<Pair<String, Integer>> lazyWorkers = clusterStatsManager.findLazyWorkerStores(storeIds.keySet());
    if (lazyWorkers.isEmpty()) {
        return null;
    }
    for (int i = lazyWorkers.size() - 1; i >= 0; i--) {
        final Pair<String, Integer> worker = lazyWorkers.get(i);
        if (modelWorkerLeaders - worker.getValue() <= 1) {
            // no need to transfer
            lazyWorkers.remove(i);
        }
    }
    if (lazyWorkers.isEmpty()) {
        return null;
    }
    final Pair<String, Integer> laziestWorker = tryToFindLaziestWorker(lazyWorkers);
    if (laziestWorker == null) {
        return null;
    }
    final String lazyWorkerStoreId = laziestWorker.getKey();
    log.info("[Cluster: {}], lazy worker store is: {}, it has {} leaders.", clusterId, lazyWorkerStoreId, laziestWorker.getValue());
    final Instruction.TransferLeader transferLeader = new Instruction.TransferLeader();
    transferLeader.setMoveToStoreId(lazyWorkerStoreId);
    transferLeader.setMoveToEndpoint(storeIds.get(lazyWorkerStoreId));
    final Instruction instruction = new Instruction();
    instruction.setRegion(region.copy());
    instruction.setTransferLeader(transferLeader);
    log.info("[Cluster: {}], send 'instruction.transferLeader': {} to region: {}.", clusterId, instruction, region);
    return instruction;
}
Also used : ClusterStatsManager(io.dingodb.server.coordinator.meta.ClusterStatsManager) Set(java.util.Set) Peer(io.dingodb.store.row.metadata.Peer) Instruction(io.dingodb.store.row.metadata.Instruction) Endpoint(io.dingodb.raft.util.Endpoint) Endpoint(io.dingodb.raft.util.Endpoint) Pair(io.dingodb.store.row.util.Pair)

Example 25 with Endpoint

use of io.dingodb.raft.util.Endpoint in project dingo by dingodb.

the class TableMetaAdaptorImpl method rangeLocationGroup.

@Override
public NavigableMap<byte[], LocationGroup> rangeLocationGroup() {
    NavigableMap<byte[], LocationGroup> result = new TreeMap<>(BytesUtil.getDefaultByteArrayComparator());
    Map<GeneralId, AppView<?, ?>> map = this.scheduleMetaAdaptor.namespaceView().appViews();
    for (Map.Entry<GeneralId, AppView<?, ?>> entry : map.entrySet()) {
        if (entry.getValue() instanceof RegionView) {
            RegionView view = (RegionView) entry.getValue();
            ExecutorView executorView = this.scheduleMetaAdaptor.executorView(view.leader());
            Endpoint endpoint = executorView.stats().getLocation();
            Location location = new Location(endpoint.getIp(), endpoint.getPort(), DATA_DIR);
            List<Location> locationList = view.nodeResources().stream().map(id -> this.scheduleMetaAdaptor.namespaceView().<ExecutorView>getResourceView(id)).map(ExecutorView::location).collect(Collectors.toList());
            LocationGroup locationGroup = new LocationGroup(location, locationList);
            RegionApp regionApp = this.scheduleMetaAdaptor.regionApp(view.app());
            result.put(BytesUtil.nullToEmpty(regionApp.startKey()), locationGroup);
        }
    }
    return result;
}
Also used : AppView(io.dingodb.server.coordinator.app.AppView) ExecutorView(io.dingodb.server.coordinator.resource.impl.ExecutorView) TreeMap(java.util.TreeMap) RegionApp(io.dingodb.server.coordinator.app.impl.RegionApp) GeneralId(io.dingodb.server.coordinator.GeneralId) Endpoint(io.dingodb.raft.util.Endpoint) RegionView(io.dingodb.server.coordinator.app.impl.RegionView) LocationGroup(io.dingodb.meta.LocationGroup) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Location(io.dingodb.meta.Location)

Aggregations

Endpoint (io.dingodb.raft.util.Endpoint)25 Store (io.dingodb.store.row.metadata.Store)6 PeerId (io.dingodb.raft.entity.PeerId)5 Cluster (io.dingodb.store.row.metadata.Cluster)5 NodeOptions (io.dingodb.raft.option.NodeOptions)4 Status (io.dingodb.raft.Status)3 FutureHelper (io.dingodb.store.row.client.FutureHelper)3 FailoverClosure (io.dingodb.store.row.client.failover.FailoverClosure)3 RetryRunner (io.dingodb.store.row.client.failover.RetryRunner)3 FailoverClosureImpl (io.dingodb.store.row.client.failover.impl.FailoverClosureImpl)3 CreateRegionIdRequest (io.dingodb.store.row.cmd.pd.CreateRegionIdRequest)3 GetClusterInfoRequest (io.dingodb.store.row.cmd.pd.GetClusterInfoRequest)3 GetStoreIdRequest (io.dingodb.store.row.cmd.pd.GetStoreIdRequest)3 GetStoreInfoRequest (io.dingodb.store.row.cmd.pd.GetStoreInfoRequest)3 SetStoreInfoRequest (io.dingodb.store.row.cmd.pd.SetStoreInfoRequest)3 Region (io.dingodb.store.row.metadata.Region)3 StoreStats (io.dingodb.store.row.metadata.StoreStats)3 RouteTable (io.dingodb.raft.RouteTable)2 Configuration (io.dingodb.raft.conf.Configuration)2 RpcServer (io.dingodb.raft.rpc.RpcServer)2