Search in sources :

Example 21 with Region

use of com.alipay.sofa.jraft.rhea.metadata.Region in project sofa-jraft by sofastack.

the class SnapshotBenchmark method doSlowSnapshotLoad.

private void doSlowSnapshotLoad(final String snapshotPath, final LocalFileMeta meta) {
    try {
        this.dbOptions.setFastSnapshot(false);
        final Region region = new Region();
        KVStoreAccessHelper.loadSnapshot(this.kvStore, snapshotPath, meta, region);
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : Region(com.alipay.sofa.jraft.rhea.metadata.Region) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 22 with Region

use of com.alipay.sofa.jraft.rhea.metadata.Region in project sofa-jraft by sofastack.

the class AbstractPlacementDriverClient method getLocalRegionMetadata.

protected Region getLocalRegionMetadata(final RegionEngineOptions opts) {
    final long regionId = Requires.requireNonNull(opts.getRegionId(), "opts.regionId");
    Requires.requireTrue(regionId >= Region.MIN_ID_WITH_MANUAL_CONF, "opts.regionId must >= " + Region.MIN_ID_WITH_MANUAL_CONF);
    Requires.requireTrue(regionId < Region.MAX_ID_WITH_MANUAL_CONF, "opts.regionId must < " + Region.MAX_ID_WITH_MANUAL_CONF);
    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()));
    this.regionRouteTable.addOrUpdateRegion(region);
    return region;
}
Also used : Configuration(com.alipay.sofa.jraft.conf.Configuration) Region(com.alipay.sofa.jraft.rhea.metadata.Region) RegionEpoch(com.alipay.sofa.jraft.rhea.metadata.RegionEpoch)

Example 23 with Region

use of com.alipay.sofa.jraft.rhea.metadata.Region in project sofa-jraft by sofastack.

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 long 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;
    }
}
Also used : Endpoint(com.alipay.sofa.jraft.util.Endpoint) Region(com.alipay.sofa.jraft.rhea.metadata.Region) RegionEngine(com.alipay.sofa.jraft.rhea.RegionEngine) Instruction(com.alipay.sofa.jraft.rhea.metadata.Instruction)

Example 24 with Region

use of com.alipay.sofa.jraft.rhea.metadata.Region in project sofa-jraft by sofastack.

the class InstructionProcessor method processSplit.

private boolean processSplit(final Instruction instruction) {
    try {
        final Instruction.RangeSplit rangeSplit = instruction.getRangeSplit();
        if (rangeSplit == null) {
            return false;
        }
        final Long newRegionId = rangeSplit.getNewRegionId();
        if (newRegionId == null) {
            LOG.error("RangeSplit#newRegionId must not be null, {}.", instruction);
            return false;
        }
        final Region region = instruction.getRegion();
        final long 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;
    }
}
Also used : Status(com.alipay.sofa.jraft.Status) BaseKVStoreClosure(com.alipay.sofa.jraft.rhea.storage.BaseKVStoreClosure) Instruction(com.alipay.sofa.jraft.rhea.metadata.Instruction) CompletableFuture(java.util.concurrent.CompletableFuture) Region(com.alipay.sofa.jraft.rhea.metadata.Region) RegionEngine(com.alipay.sofa.jraft.rhea.RegionEngine)

Example 25 with Region

use of com.alipay.sofa.jraft.rhea.metadata.Region in project sofa-jraft by sofastack.

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);
        }
    }
}
Also used : Cluster(com.alipay.sofa.jraft.rhea.metadata.Cluster) Store(com.alipay.sofa.jraft.rhea.metadata.Store) Region(com.alipay.sofa.jraft.rhea.metadata.Region)

Aggregations

Region (com.alipay.sofa.jraft.rhea.metadata.Region)67 KVEntry (com.alipay.sofa.jraft.rhea.storage.KVEntry)35 List (java.util.List)35 Map (java.util.Map)35 Status (com.alipay.sofa.jraft.Status)34 Lists (com.alipay.sofa.jraft.rhea.util.Lists)34 BytesUtil (com.alipay.sofa.jraft.util.BytesUtil)34 Endpoint (com.alipay.sofa.jraft.util.Endpoint)33 KVIterator (com.alipay.sofa.jraft.rhea.storage.KVIterator)31 KVStoreClosure (com.alipay.sofa.jraft.rhea.storage.KVStoreClosure)31 RawKVStore (com.alipay.sofa.jraft.rhea.storage.RawKVStore)31 Sequence (com.alipay.sofa.jraft.rhea.storage.Sequence)31 ByteArray (com.alipay.sofa.jraft.rhea.util.ByteArray)31 DistributedLock (com.alipay.sofa.jraft.rhea.util.concurrent.DistributedLock)31 TimeUnit (java.util.concurrent.TimeUnit)31 CASEntry (com.alipay.sofa.jraft.rhea.storage.CASEntry)30 Requires (com.alipay.sofa.jraft.util.Requires)30 Logger (org.slf4j.Logger)30 LoggerFactory (org.slf4j.LoggerFactory)30 RegionEngine (com.alipay.sofa.jraft.rhea.RegionEngine)29