use of com.alipay.sofa.jraft.rhea.metadata.Cluster 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.Cluster in project sofa-jraft by sofastack.
the class MetadataRpcClient method internalGetClusterInfo.
private void internalGetClusterInfo(final long clusterId, final CompletableFuture<Cluster> future, final int retriesLeft, final Errors lastCause) {
final RetryRunner retryRunner = retryCause -> internalGetClusterInfo(clusterId, future, retriesLeft - 1, retryCause);
final FailoverClosure<Cluster> closure = new FailoverClosureImpl<>(future, retriesLeft, retryRunner);
final GetClusterInfoRequest request = new GetClusterInfoRequest();
request.setClusterId(clusterId);
this.pdRpcService.callPdServerWithRpc(request, closure, lastCause);
}
use of com.alipay.sofa.jraft.rhea.metadata.Cluster 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.Cluster in project sofa-jraft by sofastack.
the class DefaultPlacementDriverService method handleGetClusterInfoRequest.
@Override
public void handleGetClusterInfoRequest(final GetClusterInfoRequest request, final RequestProcessClosure<BaseRequest, BaseResponse> closure) {
final long clusterId = request.getClusterId();
final GetClusterInfoResponse response = new GetClusterInfoResponse();
response.setClusterId(clusterId);
if (!this.isLeader) {
response.setError(Errors.NOT_LEADER);
closure.sendResponse(response);
return;
}
try {
final Cluster cluster = this.metadataStore.getClusterInfo(clusterId);
response.setValue(cluster);
} catch (final Throwable t) {
LOG.error("Failed to handle: {}, {}.", request, StackTraceUtil.stackTrace(t));
response.setError(Errors.forException(t));
}
closure.sendResponse(response);
}
Aggregations