Search in sources :

Example 26 with Region

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);
    }
}
Also used : Requires(io.dingodb.raft.util.Requires) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Region(io.dingodb.store.row.metadata.Region) Lists(io.dingodb.store.row.util.Lists) Maps(io.dingodb.store.row.util.Maps) NavigableMap(java.util.NavigableMap) List(java.util.List) TreeMap(java.util.TreeMap) RouteTableException(io.dingodb.store.row.errors.RouteTableException) Map(java.util.Map) BytesUtil(io.dingodb.raft.util.BytesUtil) KVEntry(io.dingodb.store.row.storage.KVEntry) Comparator(java.util.Comparator) RegionEpoch(io.dingodb.store.row.metadata.RegionEpoch) CASEntry(io.dingodb.store.row.storage.CASEntry) StampedLock(java.util.concurrent.locks.StampedLock) KVEntry(io.dingodb.store.row.storage.KVEntry) Region(io.dingodb.store.row.metadata.Region) StampedLock(java.util.concurrent.locks.StampedLock) List(java.util.List)

Example 27 with Region

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);
    }
}
Also used : Requires(io.dingodb.raft.util.Requires) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Region(io.dingodb.store.row.metadata.Region) Lists(io.dingodb.store.row.util.Lists) Maps(io.dingodb.store.row.util.Maps) NavigableMap(java.util.NavigableMap) List(java.util.List) TreeMap(java.util.TreeMap) RouteTableException(io.dingodb.store.row.errors.RouteTableException) Map(java.util.Map) BytesUtil(io.dingodb.raft.util.BytesUtil) KVEntry(io.dingodb.store.row.storage.KVEntry) Comparator(java.util.Comparator) RegionEpoch(io.dingodb.store.row.metadata.RegionEpoch) CASEntry(io.dingodb.store.row.storage.CASEntry) StampedLock(java.util.concurrent.locks.StampedLock) Region(io.dingodb.store.row.metadata.Region) StampedLock(java.util.concurrent.locks.StampedLock) List(java.util.List) CASEntry(io.dingodb.store.row.storage.CASEntry)

Example 28 with Region

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;
}
Also used : StampedLock(java.util.concurrent.locks.StampedLock) Region(io.dingodb.store.row.metadata.Region)

Example 29 with 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;
}
Also used : ExecutorView(io.dingodb.server.coordinator.resource.impl.ExecutorView) Region(io.dingodb.store.row.metadata.Region) GeneralId(io.dingodb.server.coordinator.GeneralId)

Example 30 with Region

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;
}
Also used : Logger(org.slf4j.Logger) Store(io.dingodb.store.row.metadata.Store) RegionEngineOptions(io.dingodb.store.row.options.RegionEngineOptions) StoreEngineOptions(io.dingodb.store.row.options.StoreEngineOptions) LoggerFactory(org.slf4j.LoggerFactory) Region(io.dingodb.store.row.metadata.Region) RouteTable(io.dingodb.raft.RouteTable) NodeOptions(io.dingodb.raft.option.NodeOptions) Lists(io.dingodb.store.row.util.Lists) Collectors(java.util.stream.Collectors) Cluster(io.dingodb.store.row.metadata.Cluster) Strings(io.dingodb.store.row.util.Strings) PlacementDriverOptions(io.dingodb.store.row.options.PlacementDriverOptions) List(java.util.List) PeerId(io.dingodb.raft.entity.PeerId) RouteTableException(io.dingodb.store.row.errors.RouteTableException) BytesUtil(io.dingodb.raft.util.BytesUtil) Endpoint(io.dingodb.raft.util.Endpoint) JRaftHelper(io.dingodb.store.row.JRaftHelper) Endpoint(io.dingodb.raft.util.Endpoint) Store(io.dingodb.store.row.metadata.Store) Region(io.dingodb.store.row.metadata.Region) NodeOptions(io.dingodb.raft.option.NodeOptions) RegionEngineOptions(io.dingodb.store.row.options.RegionEngineOptions)

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