Search in sources :

Example 1 with Store

use of io.dingodb.store.row.metadata.Store in project dingo by dingodb.

the class StoreEngine method init.

@Override
public synchronized boolean init(final StoreEngineOptions opts) {
    if (this.started) {
        LOG.info("[StoreEngine] already started.");
        return true;
    }
    DescriberManager.getInstance().addDescriber(this);
    this.storeOpts = Requires.requireNonNull(opts, "opts");
    Endpoint serverAddress = Requires.requireNonNull(opts.getServerAddress(), "opts.serverAddress");
    final int port = serverAddress.getPort();
    final String ip = serverAddress.getIp();
    if (ip == null || Utils.IP_ANY.equals(ip)) {
        serverAddress = new Endpoint(NetUtil.getLocalCanonicalHostName(), port);
        opts.setServerAddress(serverAddress);
    }
    final long metricsReportPeriod = opts.getMetricsReportPeriod();
    // init region options
    List<RegionEngineOptions> rOptsList = opts.getRegionEngineOptionsList();
    if (rOptsList == null || rOptsList.isEmpty()) {
        // -1 region
        final RegionEngineOptions rOpts = new RegionEngineOptions();
        rOpts.setRegionId(Constants.DEFAULT_REGION_ID);
        rOptsList = Lists.newArrayList();
        rOptsList.add(rOpts);
        opts.setRegionEngineOptionsList(rOptsList);
    }
    final String clusterName = this.pdClient.getClusterName();
    for (final RegionEngineOptions rOpts : rOptsList) {
        rOpts.setRaftGroupId(JRaftHelper.getJRaftGroupId(clusterName, rOpts.getRegionId()));
        rOpts.setServerAddress(serverAddress);
        if (Strings.isBlank(rOpts.getInitialServerList())) {
            // if blank, extends parent's value
            rOpts.setInitialServerList(opts.getInitialServerList());
        }
        if (rOpts.getNodeOptions() == null) {
            // copy common node options
            rOpts.setNodeOptions(opts.getCommonNodeOptions() == null ? new NodeOptions() : opts.getCommonNodeOptions().copy());
        }
        if (rOpts.getMetricsReportPeriod() <= 0 && metricsReportPeriod > 0) {
            // extends store opts
            rOpts.setMetricsReportPeriod(metricsReportPeriod);
        }
    }
    // init store
    final Store store = this.pdClient.getStoreMetadata(opts);
    if (store == null || store.getRegions() == null || store.getRegions().isEmpty()) {
        LOG.error("Empty store metadata: {}.", store);
        return false;
    }
    this.storeId = store.getId();
    // init executors
    if (this.readIndexExecutor == null) {
        this.readIndexExecutor = StoreEngineHelper.createReadIndexExecutor(opts.getReadIndexCoreThreads());
    }
    if (this.raftStateTrigger == null) {
        this.raftStateTrigger = StoreEngineHelper.createRaftStateTrigger(opts.getLeaderStateTriggerCoreThreads());
    }
    if (this.snapshotExecutor == null) {
        this.snapshotExecutor = StoreEngineHelper.createSnapshotExecutor(opts.getSnapshotCoreThreads(), opts.getSnapshotMaxThreads());
    }
    // init rpc executors
    final boolean useSharedRpcExecutor = opts.isUseSharedRpcExecutor();
    if (!useSharedRpcExecutor) {
        if (this.cliRpcExecutor == null) {
            this.cliRpcExecutor = StoreEngineHelper.createCliRpcExecutor(opts.getCliRpcCoreThreads());
        }
        if (this.raftRpcExecutor == null) {
            this.raftRpcExecutor = StoreEngineHelper.createRaftRpcExecutor(opts.getRaftRpcCoreThreads());
        }
        if (this.kvRpcExecutor == null) {
            this.kvRpcExecutor = StoreEngineHelper.createKvRpcExecutor(opts.getKvRpcCoreThreads());
        }
    }
    // init metrics
    startMetricReporters(metricsReportPeriod);
    // init rpc server
    this.rpcServer = RaftRpcServerFactory.createRaftRpcServer(serverAddress, this.raftRpcExecutor, this.cliRpcExecutor);
    StoreEngineHelper.addKvStoreRequestProcessor(this.rpcServer, this);
    if (!this.rpcServer.init(null)) {
        LOG.error("Fail to init [RpcServer].");
        return false;
    }
    // init db store
    if (!initRawKVStore(opts)) {
        return false;
    }
    if (this.rawKVStore instanceof Describer) {
        DescriberManager.getInstance().addDescriber((Describer) this.rawKVStore);
    }
    // init all region engine
    if (!initAllRegionEngine(opts, store)) {
        LOG.error("Fail to init all [RegionEngine].");
        return false;
    }
    this.startTime = System.currentTimeMillis();
    LOG.info("[StoreEngine] start successfully: {}.", this);
    return this.started = true;
}
Also used : Endpoint(io.dingodb.raft.util.Endpoint) Store(io.dingodb.store.row.metadata.Store) MemoryRawKVStore(io.dingodb.store.row.storage.MemoryRawKVStore) BatchRawKVStore(io.dingodb.store.row.storage.BatchRawKVStore) RocksRawKVStore(io.dingodb.store.row.storage.RocksRawKVStore) NodeOptions(io.dingodb.raft.option.NodeOptions) Endpoint(io.dingodb.raft.util.Endpoint) Describer(io.dingodb.raft.util.Describer)

Example 2 with Store

use of io.dingodb.store.row.metadata.Store in project dingo by dingodb.

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(io.dingodb.store.row.metadata.Store) Region(io.dingodb.store.row.metadata.Region) RegionEngineOptions(io.dingodb.store.row.options.RegionEngineOptions)

Example 3 with Store

use of io.dingodb.store.row.metadata.Store in project dingo by dingodb.

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 : CreateRegionIdRequest(io.dingodb.store.row.cmd.pd.CreateRegionIdRequest) GetClusterInfoRequest(io.dingodb.store.row.cmd.pd.GetClusterInfoRequest) Errors(io.dingodb.store.row.errors.Errors) FailoverClosure(io.dingodb.store.row.client.failover.FailoverClosure) Store(io.dingodb.store.row.metadata.Store) CompletableFuture(java.util.concurrent.CompletableFuture) Cluster(io.dingodb.store.row.metadata.Cluster) SetStoreInfoRequest(io.dingodb.store.row.cmd.pd.SetStoreInfoRequest) RetryRunner(io.dingodb.store.row.client.failover.RetryRunner) FailoverClosureImpl(io.dingodb.store.row.client.failover.impl.FailoverClosureImpl) GetStoreInfoRequest(io.dingodb.store.row.cmd.pd.GetStoreInfoRequest) GetStoreIdRequest(io.dingodb.store.row.cmd.pd.GetStoreIdRequest) Endpoint(io.dingodb.raft.util.Endpoint) FutureHelper(io.dingodb.store.row.client.FutureHelper) FailoverClosureImpl(io.dingodb.store.row.client.failover.impl.FailoverClosureImpl) Store(io.dingodb.store.row.metadata.Store) SetStoreInfoRequest(io.dingodb.store.row.cmd.pd.SetStoreInfoRequest) RetryRunner(io.dingodb.store.row.client.failover.RetryRunner)

Example 4 with Store

use of io.dingodb.store.row.metadata.Store in project dingo by dingodb.

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(io.dingodb.store.row.metadata.Cluster) Store(io.dingodb.store.row.metadata.Store) Region(io.dingodb.store.row.metadata.Region)

Example 5 with Store

use of io.dingodb.store.row.metadata.Store in project dingo by dingodb.

the class RowStoreMetaAdaptorImpl method mapping.

public Store mapping(ExecutorView executorView) {
    if (executorView == null) {
        return null;
    }
    Store store = new Store();
    store.setEndpoint(new Endpoint(executorView.location().getHost(), executorView.location().getPort()));
    store.setId(executorView.resourceId().toString());
    store.setLabels(executorView.labels().entrySet().stream().map(e -> new StoreLabel(e.getKey(), e.getValue())).collect(Collectors.toList()));
    store.setRegions(executorView.apps().stream().map(id -> scheduleMetaAdaptor.namespace().<RegionApp>getApp(id)).map(this::mapping).collect(Collectors.toList()));
    return store;
}
Also used : ExecutorView(io.dingodb.server.coordinator.resource.impl.ExecutorView) StoreStats(io.dingodb.store.row.metadata.StoreStats) GeneralId(io.dingodb.server.coordinator.GeneralId) RegionView(io.dingodb.server.coordinator.app.impl.RegionView) StoreLabel(io.dingodb.store.row.metadata.StoreLabel) BigDecimal(java.math.BigDecimal) RowStoreMetaAdaptor(io.dingodb.server.coordinator.meta.RowStoreMetaAdaptor) Map(java.util.Map) Optional(io.dingodb.common.util.Optional) RegionEpoch(io.dingodb.store.row.metadata.RegionEpoch) Store(io.dingodb.store.row.metadata.Store) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Region(io.dingodb.store.row.metadata.Region) Set(java.util.Set) GeneralIdHelper(io.dingodb.server.coordinator.meta.GeneralIdHelper) Peer(io.dingodb.store.row.metadata.Peer) Collectors(java.util.stream.Collectors) Cluster(io.dingodb.store.row.metadata.Cluster) ScheduleMetaAdaptor(io.dingodb.server.coordinator.meta.ScheduleMetaAdaptor) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ConcurrentHashSet(com.alipay.remoting.util.ConcurrentHashSet) RegionStats(io.dingodb.store.row.metadata.RegionStats) RegionApp(io.dingodb.server.coordinator.app.impl.RegionApp) Endpoint(io.dingodb.raft.util.Endpoint) StoreLabel(io.dingodb.store.row.metadata.StoreLabel) Endpoint(io.dingodb.raft.util.Endpoint) Store(io.dingodb.store.row.metadata.Store) RegionApp(io.dingodb.server.coordinator.app.impl.RegionApp)

Aggregations

Store (io.dingodb.store.row.metadata.Store)8 Cluster (io.dingodb.store.row.metadata.Cluster)6 Endpoint (io.dingodb.raft.util.Endpoint)5 Region (io.dingodb.store.row.metadata.Region)4 NodeOptions (io.dingodb.raft.option.NodeOptions)2 ExecutorView (io.dingodb.server.coordinator.resource.impl.ExecutorView)2 FutureHelper (io.dingodb.store.row.client.FutureHelper)2 FailoverClosure (io.dingodb.store.row.client.failover.FailoverClosure)2 RetryRunner (io.dingodb.store.row.client.failover.RetryRunner)2 FailoverClosureImpl (io.dingodb.store.row.client.failover.impl.FailoverClosureImpl)2 CreateRegionIdRequest (io.dingodb.store.row.cmd.pd.CreateRegionIdRequest)2 GetClusterInfoRequest (io.dingodb.store.row.cmd.pd.GetClusterInfoRequest)2 GetStoreIdRequest (io.dingodb.store.row.cmd.pd.GetStoreIdRequest)2 GetStoreInfoRequest (io.dingodb.store.row.cmd.pd.GetStoreInfoRequest)2 SetStoreInfoRequest (io.dingodb.store.row.cmd.pd.SetStoreInfoRequest)2 Errors (io.dingodb.store.row.errors.Errors)2 RegionEngineOptions (io.dingodb.store.row.options.RegionEngineOptions)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ConcurrentHashSet (com.alipay.remoting.util.ConcurrentHashSet)1