Search in sources :

Example 1 with Describer

use of io.dingodb.raft.util.Describer 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 Describer

use of io.dingodb.raft.util.Describer in project dingo by dingodb.

the class DingoRowStoreDescribeSignalHandler method handle.

@Override
public void handle(final String signalName) {
    final List<Describer> describers = DescriberManager.getInstance().getAllDescribers();
    if (describers.isEmpty()) {
        return;
    }
    try {
        final File file = getOutputFile(DIR, BASE_NAME);
        LOG.info("Describing dingo store with signal: {} to file: {}.", signalName, file);
        try (final PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file, true), StandardCharsets.UTF_8))) {
            final Describer.Printer printer = new Describer.DefaultPrinter(out);
            for (final Describer describer : describers) {
                describer.describe(printer);
            }
        }
    } catch (final IOException e) {
        LOG.error("Fail to describe dingo store: {}.", describers, e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File) Describer(io.dingodb.raft.util.Describer) PrintWriter(java.io.PrintWriter)

Aggregations

Describer (io.dingodb.raft.util.Describer)2 NodeOptions (io.dingodb.raft.option.NodeOptions)1 Endpoint (io.dingodb.raft.util.Endpoint)1 Store (io.dingodb.store.row.metadata.Store)1 BatchRawKVStore (io.dingodb.store.row.storage.BatchRawKVStore)1 MemoryRawKVStore (io.dingodb.store.row.storage.MemoryRawKVStore)1 RocksRawKVStore (io.dingodb.store.row.storage.RocksRawKVStore)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1