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