Search in sources :

Example 21 with Region

use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.

the class AbstractPlacementDriverClient method initRouteTableByRegion.

protected void initRouteTableByRegion(final RegionRouteTableOptions 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()));
    // update raft route table
    RouteTable.getInstance().updateConfiguration(JRaftHelper.getJRaftGroupId(clusterName, regionId), conf);
    this.regionRouteTable.addOrUpdateRegion(region);
}
Also used : Configuration(io.dingodb.raft.conf.Configuration) Region(io.dingodb.store.row.metadata.Region) RegionEpoch(io.dingodb.store.row.metadata.RegionEpoch)

Example 22 with Region

use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.

the class FakePlacementDriverClient method getStoreMetadata.

@Override
public Store getStoreMetadata(final StoreEngineOptions opts) {
    final Store store = new Store();
    final List<RegionEngineOptions> rOptsList = opts.getRegionEngineOptionsList();
    final List<Region> regionList = Lists.newArrayListWithCapacity(rOptsList.size());
    store.setId("-1");
    store.setEndpoint(opts.getServerAddress());
    for (final RegionEngineOptions rOpts : rOptsList) {
        regionList.add(getLocalRegionMetadata(rOpts));
    }
    store.setRegions(regionList);
    return store;
}
Also used : Store(io.dingodb.store.row.metadata.Store) Region(io.dingodb.store.row.metadata.Region) RegionEngineOptions(io.dingodb.store.row.options.RegionEngineOptions)

Example 23 with Region

use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.

the class InstructionProcessor method processTransferLeader.

private boolean processTransferLeader(final Instruction instruction) {
    try {
        final Instruction.TransferLeader transferLeader = instruction.getTransferLeader();
        if (transferLeader == null) {
            return false;
        }
        final Endpoint toEndpoint = transferLeader.getMoveToEndpoint();
        if (toEndpoint == null) {
            LOG.error("TransferLeader#toEndpoint must not be null, {}.", instruction);
            return false;
        }
        final Region region = instruction.getRegion();
        final String regionId = region.getId();
        final RegionEngine engine = this.storeEngine.getRegionEngine(regionId);
        if (engine == null) {
            LOG.error("Could not found regionEngine, {}.", instruction);
            return false;
        }
        if (!region.equals(engine.getRegion())) {
            LOG.warn("Instruction [{}] is out of date.", instruction);
            return false;
        }
        return engine.transferLeadershipTo(toEndpoint);
    } catch (final Throwable t) {
        LOG.error("Caught an exception on #processTransferLeader: {}.", StackTraceUtil.stackTrace(t));
        return false;
    }
}
Also used : Endpoint(io.dingodb.raft.util.Endpoint) Region(io.dingodb.store.row.metadata.Region) RegionEngine(io.dingodb.store.row.RegionEngine) Instruction(io.dingodb.store.row.metadata.Instruction)

Example 24 with Region

use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.

the class InstructionProcessor method processSplit.

private boolean processSplit(final Instruction instruction) {
    try {
        final Instruction.RangeSplit rangeSplit = instruction.getRangeSplit();
        if (rangeSplit == null) {
            return false;
        }
        final String newRegionId = rangeSplit.getNewRegionId();
        if (newRegionId == null) {
            LOG.error("RangeSplit#newRegionId must not be null, {}.", instruction);
            return false;
        }
        final Region region = instruction.getRegion();
        final String regionId = region.getId();
        final RegionEngine engine = this.storeEngine.getRegionEngine(regionId);
        if (engine == null) {
            LOG.error("Could not found regionEngine, {}.", instruction);
            return false;
        }
        if (!region.equals(engine.getRegion())) {
            LOG.warn("Instruction [{}] is out of date.", instruction);
            return false;
        }
        final CompletableFuture<Status> future = new CompletableFuture<>();
        this.storeEngine.applySplit(regionId, newRegionId, new BaseKVStoreClosure() {

            @Override
            public void run(Status status) {
                future.complete(status);
            }
        });
        final Status status = future.get(20, TimeUnit.SECONDS);
        final boolean ret = status.isOk();
        if (ret) {
            LOG.info("Range-split succeeded, instruction: {}.", instruction);
        } else {
            LOG.warn("Range-split failed: {}, instruction: {}.", status, instruction);
        }
        return ret;
    } catch (final Throwable t) {
        LOG.error("Caught an exception on #processSplit: {}.", StackTraceUtil.stackTrace(t));
        return false;
    }
}
Also used : Status(io.dingodb.raft.Status) CompletableFuture(java.util.concurrent.CompletableFuture) BaseKVStoreClosure(io.dingodb.store.row.storage.BaseKVStoreClosure) Region(io.dingodb.store.row.metadata.Region) RegionEngine(io.dingodb.store.row.RegionEngine) Instruction(io.dingodb.store.row.metadata.Instruction)

Example 25 with Region

use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.

the class RemotePlacementDriverClient method refreshRouteTable.

@Override
protected void refreshRouteTable() {
    final Cluster cluster = this.metadataRpcClient.getClusterInfo(this.clusterId);
    if (cluster == null) {
        LOG.warn("Cluster info is empty: {}.", this.clusterId);
        return;
    }
    final List<Store> stores = cluster.getStores();
    if (stores == null || stores.isEmpty()) {
        LOG.error("Stores info is empty: {}.", this.clusterId);
        return;
    }
    for (final Store store : stores) {
        final List<Region> regions = store.getRegions();
        if (regions == null || regions.isEmpty()) {
            LOG.error("Regions info is empty: {} - {}.", this.clusterId, store.getId());
            continue;
        }
        for (final Region region : regions) {
            super.regionRouteTable.addOrUpdateRegion(region);
        }
    }
}
Also used : Cluster(io.dingodb.store.row.metadata.Cluster) Store(io.dingodb.store.row.metadata.Store) Region(io.dingodb.store.row.metadata.Region)

Aggregations

Region (io.dingodb.store.row.metadata.Region)49 List (java.util.List)32 Map (java.util.Map)32 BytesUtil (io.dingodb.raft.util.BytesUtil)31 Endpoint (io.dingodb.raft.util.Endpoint)31 Lists (io.dingodb.store.row.util.Lists)31 Logger (org.slf4j.Logger)31 LoggerFactory (org.slf4j.LoggerFactory)31 Requires (io.dingodb.raft.util.Requires)30 CASEntry (io.dingodb.store.row.storage.CASEntry)30 KVEntry (io.dingodb.store.row.storage.KVEntry)30 Status (io.dingodb.raft.Status)29 RegionEngine (io.dingodb.store.row.RegionEngine)29 RouteTable (io.dingodb.raft.RouteTable)28 PeerId (io.dingodb.raft.entity.PeerId)28 JRaftHelper (io.dingodb.store.row.JRaftHelper)28 Histogram (com.codahale.metrics.Histogram)27 EventFactory (com.lmax.disruptor.EventFactory)27 EventHandler (com.lmax.disruptor.EventHandler)27 RingBuffer (com.lmax.disruptor.RingBuffer)27