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;
}
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);
}
}
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;
}
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);
}
Aggregations