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