use of com.alipay.sofa.jraft.rhea.metadata.Store in project sofa-jraft by sofastack.
the class DefaultMetadataStore method getClusterInfo.
@Override
public Cluster getClusterInfo(final long clusterId) {
final Set<Long> storeIds = getClusterIndex(clusterId);
if (storeIds == null) {
return null;
}
final List<byte[]> storeKeys = Lists.newArrayList();
for (final Long storeId : storeIds) {
final String storeInfoKey = MetadataKeyHelper.getStoreInfoKey(clusterId, storeId);
storeKeys.add(BytesUtil.writeUtf8(storeInfoKey));
}
final Map<ByteArray, byte[]> storeInfoBytes = this.rheaKVStore.bMultiGet(storeKeys);
final List<Store> stores = Lists.newArrayListWithCapacity(storeInfoBytes.size());
for (final byte[] storeBytes : storeInfoBytes.values()) {
final Store store = this.serializer.readObject(storeBytes, Store.class);
stores.add(store);
}
return new Cluster(clusterId, stores);
}
use of com.alipay.sofa.jraft.rhea.metadata.Store in project sofa-jraft by sofastack.
the class DefaultPlacementDriverService method handleSetStoreInfoRequest.
@Override
public void handleSetStoreInfoRequest(final SetStoreInfoRequest request, final RequestProcessClosure<BaseRequest, BaseResponse> closure) {
final long clusterId = request.getClusterId();
final SetStoreInfoResponse response = new SetStoreInfoResponse();
response.setClusterId(clusterId);
LOG.info("Handling {}.", request);
if (!this.isLeader) {
response.setError(Errors.NOT_LEADER);
closure.sendResponse(response);
return;
}
try {
final CompletableFuture<Store> future = this.metadataStore.updateStoreInfo(clusterId, request.getStore());
future.whenComplete((prevStore, throwable) -> {
if (throwable == null) {
response.setValue(prevStore);
} else {
LOG.error("Failed to handle: {}, {}.", request, StackTraceUtil.stackTrace(throwable));
response.setError(Errors.forException(throwable));
}
closure.sendResponse(response);
});
} catch (final Throwable t) {
LOG.error("Failed to handle: {}, {}.", request, StackTraceUtil.stackTrace(t));
response.setError(Errors.forException(t));
closure.sendResponse(response);
}
}
use of com.alipay.sofa.jraft.rhea.metadata.Store 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);
}
}
}
use of com.alipay.sofa.jraft.rhea.metadata.Store in project sofa-jraft by sofastack.
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 com.alipay.sofa.jraft.rhea.metadata.Store in project sofa-jraft by sofastack.
the class MetadataRpcClient method internalUpdateStoreInfo.
private void internalUpdateStoreInfo(final long clusterId, final Store store, final CompletableFuture<Store> future, final int retriesLeft, final Errors lastCause) {
final RetryRunner retryRunner = retryCause -> internalUpdateStoreInfo(clusterId, store, future, retriesLeft - 1, retryCause);
final FailoverClosure<Store> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
final SetStoreInfoRequest request = new SetStoreInfoRequest();
request.setClusterId(clusterId);
request.setStore(store);
this.pdRpcService.callPdServerWithRpc(request, closure, lastCause);
}
Aggregations