Search in sources :

Example 1 with Cluster

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

Example 2 with Cluster

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);
}
Also used : Store(com.alipay.sofa.jraft.rhea.metadata.Store) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner) FailoverClosure(com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure) CreateRegionIdRequest(com.alipay.sofa.jraft.rhea.cmd.pd.CreateRegionIdRequest) CompletableFuture(java.util.concurrent.CompletableFuture) GetStoreInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.GetStoreInfoRequest) Errors(com.alipay.sofa.jraft.rhea.errors.Errors) Cluster(com.alipay.sofa.jraft.rhea.metadata.Cluster) GetStoreIdRequest(com.alipay.sofa.jraft.rhea.cmd.pd.GetStoreIdRequest) SetStoreInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.SetStoreInfoRequest) GetClusterInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.GetClusterInfoRequest) Endpoint(com.alipay.sofa.jraft.util.Endpoint) FutureHelper(com.alipay.sofa.jraft.rhea.client.FutureHelper) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) GetClusterInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.GetClusterInfoRequest) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) Cluster(com.alipay.sofa.jraft.rhea.metadata.Cluster) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner)

Example 3 with Cluster

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

Example 4 with Cluster

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

Aggregations

Cluster (com.alipay.sofa.jraft.rhea.metadata.Cluster)4 Store (com.alipay.sofa.jraft.rhea.metadata.Store)3 FutureHelper (com.alipay.sofa.jraft.rhea.client.FutureHelper)1 RheaKVStore (com.alipay.sofa.jraft.rhea.client.RheaKVStore)1 FailoverClosure (com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure)1 RetryRunner (com.alipay.sofa.jraft.rhea.client.failover.RetryRunner)1 FailoverClosureImpl (com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl)1 CreateRegionIdRequest (com.alipay.sofa.jraft.rhea.cmd.pd.CreateRegionIdRequest)1 GetClusterInfoRequest (com.alipay.sofa.jraft.rhea.cmd.pd.GetClusterInfoRequest)1 GetClusterInfoResponse (com.alipay.sofa.jraft.rhea.cmd.pd.GetClusterInfoResponse)1 GetStoreIdRequest (com.alipay.sofa.jraft.rhea.cmd.pd.GetStoreIdRequest)1 GetStoreInfoRequest (com.alipay.sofa.jraft.rhea.cmd.pd.GetStoreInfoRequest)1 SetStoreInfoRequest (com.alipay.sofa.jraft.rhea.cmd.pd.SetStoreInfoRequest)1 Errors (com.alipay.sofa.jraft.rhea.errors.Errors)1 Region (com.alipay.sofa.jraft.rhea.metadata.Region)1 ByteArray (com.alipay.sofa.jraft.rhea.util.ByteArray)1 Endpoint (com.alipay.sofa.jraft.util.Endpoint)1 CompletableFuture (java.util.concurrent.CompletableFuture)1