Search in sources :

Example 1 with Store

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

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

Example 3 with Store

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

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

Example 5 with 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);
}
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) FailoverClosureImpl(com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl) Store(com.alipay.sofa.jraft.rhea.metadata.Store) SetStoreInfoRequest(com.alipay.sofa.jraft.rhea.cmd.pd.SetStoreInfoRequest) RetryRunner(com.alipay.sofa.jraft.rhea.client.failover.RetryRunner)

Aggregations

Store (com.alipay.sofa.jraft.rhea.metadata.Store)10 RheaKVStore (com.alipay.sofa.jraft.rhea.client.RheaKVStore)4 Cluster (com.alipay.sofa.jraft.rhea.metadata.Cluster)4 Endpoint (com.alipay.sofa.jraft.util.Endpoint)4 Region (com.alipay.sofa.jraft.rhea.metadata.Region)3 RegionEngineOptions (com.alipay.sofa.jraft.rhea.options.RegionEngineOptions)3 FutureHelper (com.alipay.sofa.jraft.rhea.client.FutureHelper)2 FailoverClosure (com.alipay.sofa.jraft.rhea.client.failover.FailoverClosure)2 RetryRunner (com.alipay.sofa.jraft.rhea.client.failover.RetryRunner)2 FailoverClosureImpl (com.alipay.sofa.jraft.rhea.client.failover.impl.FailoverClosureImpl)2 CreateRegionIdRequest (com.alipay.sofa.jraft.rhea.cmd.pd.CreateRegionIdRequest)2 GetClusterInfoRequest (com.alipay.sofa.jraft.rhea.cmd.pd.GetClusterInfoRequest)2 GetStoreIdRequest (com.alipay.sofa.jraft.rhea.cmd.pd.GetStoreIdRequest)2 GetStoreInfoRequest (com.alipay.sofa.jraft.rhea.cmd.pd.GetStoreInfoRequest)2 SetStoreInfoRequest (com.alipay.sofa.jraft.rhea.cmd.pd.SetStoreInfoRequest)2 Errors (com.alipay.sofa.jraft.rhea.errors.Errors)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)1 HeartbeatSender (com.alipay.sofa.jraft.rhea.client.pd.HeartbeatSender)1 RemotePlacementDriverClient (com.alipay.sofa.jraft.rhea.client.pd.RemotePlacementDriverClient)1