Search in sources :

Example 46 with Region

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

the class RegionRouteTable method removeRegion.

public boolean removeRegion(final long regionId) {
    final StampedLock stampedLock = this.stampedLock;
    final long stamp = stampedLock.writeLock();
    try {
        final Region region = this.regionTable.remove(regionId);
        if (region != null) {
            final byte[] startKey = BytesUtil.nullToEmpty(region.getStartKey());
            return this.rangeTable.remove(startKey) != null;
        }
    } finally {
        stampedLock.unlockWrite(stamp);
    }
    return false;
}
Also used : StampedLock(java.util.concurrent.locks.StampedLock) Region(io.dingodb.store.row.metadata.Region)

Example 47 with Region

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

the class RegionRouteTable method splitRegion.

public void splitRegion(final String leftId, final Region right) {
    Requires.requireNonNull(right, "right");
    Requires.requireNonNull(right.getRegionEpoch(), "right.regionEpoch");
    final StampedLock stampedLock = this.stampedLock;
    final long stamp = stampedLock.writeLock();
    try {
        final Region left = this.regionTable.get(leftId);
        Requires.requireNonNull(left, "left");
        final byte[] leftStartKey = BytesUtil.nullToEmpty(left.getStartKey());
        final byte[] leftEndKey = left.getEndKey();
        final String rightId = right.getId();
        final byte[] rightStartKey = right.getStartKey();
        final byte[] rightEndKey = right.getEndKey();
        Requires.requireNonNull(rightStartKey, "rightStartKey");
        Requires.requireTrue(BytesUtil.compare(leftStartKey, rightStartKey) < 0, "leftStartKey must < rightStartKey");
        if (leftEndKey == null || rightEndKey == null) {
            Requires.requireTrue(leftEndKey == rightEndKey, "leftEndKey must == rightEndKey");
        } else {
            Requires.requireTrue(BytesUtil.compare(leftEndKey, rightEndKey) == 0, "leftEndKey must == rightEndKey");
            Requires.requireTrue(BytesUtil.compare(rightStartKey, rightEndKey) < 0, "rightStartKey must < rightEndKey");
        }
        final RegionEpoch leftEpoch = left.getRegionEpoch();
        leftEpoch.setVersion(leftEpoch.getVersion() + 1);
        left.setEndKey(rightStartKey);
        this.regionTable.put(rightId, right.copy());
        this.rangeTable.put(rightStartKey, rightId);
    } finally {
        stampedLock.unlockWrite(stamp);
    }
}
Also used : StampedLock(java.util.concurrent.locks.StampedLock) Region(io.dingodb.store.row.metadata.Region) RegionEpoch(io.dingodb.store.row.metadata.RegionEpoch)

Example 48 with Region

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

the class RegionHeartbeatHandler method split.

private Instruction split(RegionHeartbeatRequest request) {
    Region region = request.getRegion();
    RegionStats regionStats = request.getRegionStats();
    clusterStatsManager.addOrUpdateRegionStats(region, regionStats);
    final Set<String> stores = rowStoreMetaAdaptor.storeLocation().keySet();
    if (stores.isEmpty()) {
        return null;
    }
    if (clusterStatsManager.regionSize() >= stores.size()) {
        // one store one region is perfect
        return null;
    }
    final Pair<Region, RegionStats> modelWorker = clusterStatsManager.findModelWorkerRegion();
    if (!isSplitNeeded(request, modelWorker)) {
        return null;
    }
    final String newRegionId = rowStoreMetaAdaptor.newRegionId().seqNo().toString();
    final Instruction.RangeSplit rangeSplit = new Instruction.RangeSplit();
    rangeSplit.setNewRegionId(newRegionId);
    final Instruction instruction = new Instruction();
    instruction.setRegion(modelWorker.getKey().copy());
    instruction.setRangeSplit(rangeSplit);
    return instruction;
}
Also used : RegionStats(io.dingodb.store.row.metadata.RegionStats) Region(io.dingodb.store.row.metadata.Region) Instruction(io.dingodb.store.row.metadata.Instruction)

Example 49 with Region

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

the class RowStoreMetaAdaptorImpl method mapping.

public Region mapping(RegionApp regionApp) {
    if (regionApp == null) {
        return null;
    }
    String regionId = regionApp.regionId();
    RegionView regionView = scheduleMetaAdaptor.regionView(regionApp.view());
    List<Peer> peerIds = regionView.nodeResources().stream().map(id -> new Peer(regionId, id.toString(), GeneralIdHelper.storeEndpoint(id))).collect(Collectors.toList());
    return new Region(regionId, regionApp.startKey(), regionApp.endKey(), new RegionEpoch(regionApp.version(), regionView.confVer()), peerIds);
}
Also used : ExecutorView(io.dingodb.server.coordinator.resource.impl.ExecutorView) StoreStats(io.dingodb.store.row.metadata.StoreStats) GeneralId(io.dingodb.server.coordinator.GeneralId) RegionView(io.dingodb.server.coordinator.app.impl.RegionView) StoreLabel(io.dingodb.store.row.metadata.StoreLabel) BigDecimal(java.math.BigDecimal) RowStoreMetaAdaptor(io.dingodb.server.coordinator.meta.RowStoreMetaAdaptor) Map(java.util.Map) Optional(io.dingodb.common.util.Optional) RegionEpoch(io.dingodb.store.row.metadata.RegionEpoch) Store(io.dingodb.store.row.metadata.Store) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Region(io.dingodb.store.row.metadata.Region) Set(java.util.Set) GeneralIdHelper(io.dingodb.server.coordinator.meta.GeneralIdHelper) Peer(io.dingodb.store.row.metadata.Peer) Collectors(java.util.stream.Collectors) Cluster(io.dingodb.store.row.metadata.Cluster) ScheduleMetaAdaptor(io.dingodb.server.coordinator.meta.ScheduleMetaAdaptor) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ConcurrentHashSet(com.alipay.remoting.util.ConcurrentHashSet) RegionStats(io.dingodb.store.row.metadata.RegionStats) RegionApp(io.dingodb.server.coordinator.app.impl.RegionApp) Endpoint(io.dingodb.raft.util.Endpoint) RegionView(io.dingodb.server.coordinator.app.impl.RegionView) Peer(io.dingodb.store.row.metadata.Peer) Region(io.dingodb.store.row.metadata.Region) RegionEpoch(io.dingodb.store.row.metadata.RegionEpoch)

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