use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.
the class RegionRouteTable method findRegionsByKvEntries.
/**
* Returns the list of regions to which the keys belongs.
*/
public Map<Region, List<KVEntry>> findRegionsByKvEntries(final List<KVEntry> kvEntries) {
Requires.requireNonNull(kvEntries, "kvEntries");
final Map<Region, List<KVEntry>> regionMap = Maps.newHashMap();
final StampedLock stampedLock = this.stampedLock;
final long stamp = stampedLock.readLock();
try {
for (final KVEntry kvEntry : kvEntries) {
final Region region = findRegionByKeyWithoutLock(kvEntry.getKey());
regionMap.computeIfAbsent(region, k -> Lists.newArrayList()).add(kvEntry);
}
return regionMap;
} finally {
stampedLock.unlockRead(stamp);
}
}
use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.
the class RegionRouteTable method findRegionsByCASEntries.
/**
* Returns the list of regions to which the keys belongs.
*/
@SuppressWarnings("checkstyle:AbbreviationAsWordInName")
public Map<Region, List<CASEntry>> findRegionsByCASEntries(final List<CASEntry> casEntries) {
Requires.requireNonNull(casEntries, "casEntries");
final Map<Region, List<CASEntry>> regionMap = Maps.newHashMap();
final StampedLock stampedLock = this.stampedLock;
final long stamp = stampedLock.readLock();
try {
for (final CASEntry casEntry : casEntries) {
final Region region = findRegionByKeyWithoutLock(casEntry.getKey());
regionMap.computeIfAbsent(region, k -> Lists.newArrayList()).add(casEntry);
}
return regionMap;
} finally {
stampedLock.unlockRead(stamp);
}
}
use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.
the class RegionRouteTable method getRegionById.
public Region getRegionById(final String regionId) {
final StampedLock stampedLock = this.stampedLock;
long stamp = stampedLock.tryOptimisticRead();
// validate() emit a load-fence, but no store-fence. So you should only have
// load instructions inside a block of tryOptimisticRead() / validate(),
// because it is meant to the a read-only operation, and therefore, it is fine
// to use the loadFence() function to avoid re-ordering.
Region region = safeCopy(this.regionTable.get(regionId));
if (!stampedLock.validate(stamp)) {
stamp = stampedLock.readLock();
try {
region = safeCopy(this.regionTable.get(regionId));
} finally {
stampedLock.unlockRead(stamp);
}
}
return region;
}
use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.
the class RowStoreMetaAdaptorImpl method mapping.
public ExecutorView mapping(Store store) {
if (store == null) {
return null;
}
GeneralId generalId = GeneralId.fromStr(store.getId());
ExecutorView view = new ExecutorView(generalId, store.getEndpoint());
store.getRegions().stream().map(Region::getId).map(GeneralIdHelper::region).forEach(view::addApp);
return view;
}
use of io.dingodb.store.row.metadata.Region in project dingo by dingodb.
the class RemotePlacementDriverClient method getStoreMetadata.
@Override
public Store getStoreMetadata(final StoreEngineOptions opts) {
final Endpoint selfEndpoint = opts.getServerAddress();
/**
* for debugger.
*/
for (RegionEngineOptions opt : opts.getRegionEngineOptionsList()) {
LOG.info("RegionEngineOptions-before: update from local conf. opt:{}", opt.toString());
}
// remote conf is the preferred
final Store remoteStore = this.metadataRpcClient.getStoreInfo(this.clusterId, selfEndpoint);
if (!remoteStore.isEmpty()) {
final List<Region> regions = remoteStore.getRegions();
Long metricsReportPeriodMs = opts.getMetricsReportPeriod();
if (opts.getRegionEngineOptionsList() != null && opts.getRegionEngineOptionsList().size() > 0) {
metricsReportPeriodMs = opts.getRegionEngineOptionsList().get(0).getMetricsReportPeriod();
}
opts.getRegionEngineOptionsList().clear();
for (final Region region : regions) {
super.regionRouteTable.addOrUpdateRegion(region);
RegionEngineOptions engineOptions = new RegionEngineOptions();
engineOptions.setRegionId(region.getId());
engineOptions.setStartKey(BytesUtil.readUtf8(region.getStartKey()));
engineOptions.setStartKeyBytes(region.getStartKey());
engineOptions.setEndKey(BytesUtil.readUtf8(region.getEndKey()));
engineOptions.setEndKeyBytes(region.getEndKey());
engineOptions.setNodeOptions(new NodeOptions());
engineOptions.setRaftGroupId(JRaftHelper.getJRaftGroupId(this.clusterName, region.getId()));
String raftDataPath = JRaftHelper.getRaftDataPath(opts.getRaftStoreOptions().getDataPath(), region.getId(), opts.getServerAddress().getPort());
engineOptions.setRaftDataPath(raftDataPath);
engineOptions.setServerAddress(opts.getServerAddress());
String initServerList = region.getPeers().stream().map(x -> x.getEndpoint().toString()).collect(Collectors.joining(","));
engineOptions.setInitialServerList(initServerList);
engineOptions.setMetricsReportPeriod(metricsReportPeriodMs);
opts.getRegionEngineOptionsList().add(engineOptions);
}
/**
* for debugger.
*/
for (RegionEngineOptions opt : opts.getRegionEngineOptionsList()) {
LOG.info("RegionEngineOptions-After: update from remote PD. opt:{}", opt.toString());
}
return remoteStore;
}
// local conf
final Store localStore = new Store();
final List<RegionEngineOptions> rOptsList = opts.getRegionEngineOptionsList();
final List<Region> regionList = Lists.newArrayListWithCapacity(rOptsList.size());
localStore.setId(remoteStore.getId());
localStore.setEndpoint(selfEndpoint);
for (final RegionEngineOptions rOpts : rOptsList) {
regionList.add(getLocalRegionMetadata(rOpts));
}
localStore.setRegions(regionList);
refreshStore(localStore);
return localStore;
}
Aggregations