Search in sources :

Example 1 with NamedThreadFactory

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

the class ReadOnlyServiceImpl method init.

@Override
public boolean init(final ReadOnlyServiceOptions opts) {
    this.node = opts.getNode();
    this.nodeMetrics = this.node.getNodeMetrics();
    this.fsmCaller = opts.getFsmCaller();
    this.raftOptions = opts.getRaftOptions();
    this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("ReadOnlyService-PendingNotify-Scanner", true));
    this.readIndexDisruptor = // 
    DisruptorBuilder.<ReadIndexEvent>newInstance().setEventFactory(// 
    new ReadIndexEventFactory()).setRingBufferSize(// 
    this.raftOptions.getDisruptorBufferSize()).setThreadFactory(// 
    new NamedThreadFactory("JRaft-ReadOnlyService-Disruptor-", true)).setWaitStrategy(// 
    new BlockingWaitStrategy()).setProducerType(// 
    ProducerType.MULTI).build();
    this.readIndexDisruptor.handleEventsWith(new ReadIndexEventHandler());
    this.readIndexDisruptor.setDefaultExceptionHandler(new LogExceptionHandler<Object>(getClass().getSimpleName()));
    this.readIndexQueue = this.readIndexDisruptor.start();
    if (this.nodeMetrics.getMetricRegistry() != null) {
        // 
        this.nodeMetrics.getMetricRegistry().register("jraft-read-only-service-disruptor", new DisruptorMetricSet(this.readIndexQueue));
    }
    // listen on lastAppliedLogIndex change events.
    this.fsmCaller.addLastAppliedLogIndexListener(this);
    // start scanner
    this.scheduledExecutorService.scheduleAtFixedRate(() -> onApplied(this.fsmCaller.getLastAppliedIndex()), this.raftOptions.getMaxElectionDelayMs(), this.raftOptions.getMaxElectionDelayMs(), TimeUnit.MILLISECONDS);
    return true;
}
Also used : BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory) DisruptorMetricSet(io.dingodb.raft.util.DisruptorMetricSet)

Example 2 with NamedThreadFactory

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

the class LogManagerImpl method init.

@Override
public boolean init(final LogManagerOptions opts) {
    this.writeLock.lock();
    try {
        if (opts.getLogStorage() == null) {
            LOG.error("Fail to init log manager, log storage is null");
            return false;
        }
        this.raftOptions = opts.getRaftOptions();
        this.nodeMetrics = opts.getNodeMetrics();
        this.logStorage = opts.getLogStorage();
        this.configManager = opts.getConfigurationManager();
        LogStorageOptions lsOpts = new LogStorageOptions();
        lsOpts.setConfigurationManager(this.configManager);
        lsOpts.setLogEntryCodecFactory(opts.getLogEntryCodecFactory());
        lsOpts.setRaftLogStorageOptions(opts.getRaftLogStorageOptions());
        if (!this.logStorage.init(lsOpts)) {
            LOG.error("Fail to init logStorage");
            return false;
        }
        this.firstLogIndex = this.logStorage.getFirstLogIndex();
        this.lastLogIndex = this.logStorage.getLastLogIndex();
        this.diskId = new LogId(this.lastLogIndex, getTermFromLogStorage(this.lastLogIndex));
        this.fsmCaller = opts.getFsmCaller();
        this.disruptor = // 
        DisruptorBuilder.<StableClosureEvent>newInstance().setEventFactory(// 
        new StableClosureEventFactory()).setRingBufferSize(// 
        opts.getDisruptorBufferSize()).setThreadFactory(// 
        new NamedThreadFactory("JRaft-LogManager-Disruptor-", true)).setProducerType(// 
        ProducerType.MULTI).setWaitStrategy(new BlockingWaitStrategy()).build();
        this.disruptor.handleEventsWith(new StableClosureEventHandler());
        this.disruptor.setDefaultExceptionHandler(new LogExceptionHandler<Object>(this.getClass().getSimpleName(), (event, ex) -> reportError(-1, "LogManager handle event error")));
        this.diskQueue = this.disruptor.start();
        if (this.nodeMetrics.getMetricRegistry() != null) {
            this.nodeMetrics.getMetricRegistry().register("jraft-log-manager-disruptor", new DisruptorMetricSet(this.diskQueue));
        }
    } finally {
        this.writeLock.unlock();
    }
    return true;
}
Also used : RaftException(io.dingodb.raft.error.RaftException) Requires(io.dingodb.raft.util.Requires) RaftError(io.dingodb.raft.error.RaftError) LogId(io.dingodb.raft.entity.LogId) LoggerFactory(org.slf4j.LoggerFactory) LogEntryCorruptedException(io.dingodb.raft.error.LogEntryCorruptedException) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) NodeMetrics(io.dingodb.raft.core.NodeMetrics) LogEntry(io.dingodb.raft.entity.LogEntry) LogExceptionHandler(io.dingodb.raft.util.LogExceptionHandler) ArrayList(java.util.ArrayList) com.lmax.disruptor(com.lmax.disruptor) SnapshotMeta(io.dingodb.raft.entity.RaftOutter.SnapshotMeta) LogStorage(io.dingodb.raft.storage.LogStorage) Map(java.util.Map) ConfigurationEntry(io.dingodb.raft.conf.ConfigurationEntry) EntryType(io.dingodb.raft.entity.EnumOutter.EntryType) ThreadHelper(io.dingodb.raft.util.ThreadHelper) LogManager(io.dingodb.raft.storage.LogManager) RaftOptions(io.dingodb.raft.option.RaftOptions) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) DisruptorMetricSet(io.dingodb.raft.util.DisruptorMetricSet) Logger(org.slf4j.Logger) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory) ArrayDeque(io.dingodb.raft.util.ArrayDeque) LogManagerOptions(io.dingodb.raft.option.LogManagerOptions) ProducerType(com.lmax.disruptor.dsl.ProducerType) ErrorType(io.dingodb.raft.entity.EnumOutter.ErrorType) Status(io.dingodb.raft.Status) Configuration(io.dingodb.raft.conf.Configuration) Utils(io.dingodb.raft.util.Utils) FSMCaller(io.dingodb.raft.FSMCaller) DisruptorBuilder(io.dingodb.raft.util.DisruptorBuilder) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Lock(java.util.concurrent.locks.Lock) PeerId(io.dingodb.raft.entity.PeerId) ConfigurationManager(io.dingodb.raft.conf.ConfigurationManager) LogStorageOptions(io.dingodb.raft.option.LogStorageOptions) SegmentList(io.dingodb.raft.util.SegmentList) Disruptor(com.lmax.disruptor.dsl.Disruptor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory) DisruptorMetricSet(io.dingodb.raft.util.DisruptorMetricSet) LogStorageOptions(io.dingodb.raft.option.LogStorageOptions) LogId(io.dingodb.raft.entity.LogId)

Example 3 with NamedThreadFactory

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

the class DefaultPlacementDriverRpcService method createRpcCallbackExecutor.

private ThreadPoolExecutor createRpcCallbackExecutor(final RpcOptions opts) {
    final int callbackExecutorCorePoolSize = opts.getCallbackExecutorCorePoolSize();
    final int callbackExecutorMaximumPoolSize = opts.getCallbackExecutorMaximumPoolSize();
    if (callbackExecutorCorePoolSize <= 0 || callbackExecutorMaximumPoolSize <= 0) {
        return null;
    }
    final String name = "dingo-row-store-pd-rpc-callback";
    return // 
    ThreadPoolUtil.newBuilder().poolName(// 
    name).enableMetric(// 
    true).coreThreads(// 
    callbackExecutorCorePoolSize).maximumThreads(// 
    callbackExecutorMaximumPoolSize).keepAliveSeconds(// 
    120L).workQueue(// 
    new ArrayBlockingQueue<>(opts.getCallbackExecutorQueueCapacity())).threadFactory(// 
    new NamedThreadFactory(name, true)).rejectedHandler(// 
    new CallerRunsPolicyWithReport(name)).build();
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory) Endpoint(io.dingodb.raft.util.Endpoint) CallerRunsPolicyWithReport(io.dingodb.store.row.util.concurrent.CallerRunsPolicyWithReport)

Example 4 with NamedThreadFactory

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

the class StoreHeartbeatSender method init.

@Override
public synchronized boolean init(final HeartbeatOptions opts) {
    if (this.started) {
        LOG.info("[HeartbeatSender] already started.");
        return true;
    }
    this.statsCollector = new StatsCollector(this.storeEngine);
    this.heartbeatTimer = new HashedWheelTimer(new NamedThreadFactory("heartbeat-timer", true), 50, TimeUnit.MILLISECONDS, 4096);
    this.heartbeatRpcTimeoutMillis = opts.getHeartbeatRpcTimeoutMillis();
    if (this.heartbeatRpcTimeoutMillis <= 0) {
        throw new IllegalArgumentException("Heartbeat rpc timeout millis must > 0, " + this.heartbeatRpcTimeoutMillis);
    }
    final String name = "dingo-row-store-heartbeat-callback";
    this.heartbeatRpcCallbackExecutor = ThreadPoolUtil.newBuilder().poolName(name).enableMetric(true).coreThreads(4).maximumThreads(4).keepAliveSeconds(120L).workQueue(new ArrayBlockingQueue<>(1024)).threadFactory(new NamedThreadFactory(name, true)).rejectedHandler(new DiscardOldPolicyWithReport(name)).build();
    final long storeHeartbeatIntervalSeconds = opts.getStoreHeartbeatIntervalSeconds();
    if (storeHeartbeatIntervalSeconds <= 0) {
        throw new IllegalArgumentException("Store heartbeat interval seconds must > 0, " + storeHeartbeatIntervalSeconds);
    }
    final long now = System.currentTimeMillis();
    final StoreHeartbeatTask storeHeartbeatTask = new StoreHeartbeatTask(storeHeartbeatIntervalSeconds, now, false);
    this.heartbeatTimer.newTimeout(storeHeartbeatTask, storeHeartbeatTask.getNextDelay(), TimeUnit.SECONDS);
    LOG.info("[StoreHeartbeatSender] start successfully, options: {}.", opts);
    return this.started = true;
}
Also used : DiscardOldPolicyWithReport(io.dingodb.store.row.util.concurrent.DiscardOldPolicyWithReport) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory) HashedWheelTimer(io.dingodb.raft.util.timer.HashedWheelTimer)

Example 5 with NamedThreadFactory

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

the class AbstractClientService method initRpcClient.

protected boolean initRpcClient(final int rpcProcessorThreadPoolSize) {
    final RaftRpcFactory factory = RpcFactoryHelper.rpcFactory();
    this.rpcClient = factory.createRpcClient(factory.defaultJRaftClientConfigHelper(this.rpcOptions));
    configRpcClient(this.rpcClient);
    this.rpcClient.init(null);
    this.rpcExecutor = // 
    ThreadPoolUtil.newBuilder().poolName(// 
    "JRaft-RPC-Processor").enableMetric(// 
    true).coreThreads(// 
    rpcProcessorThreadPoolSize / 3).maximumThreads(// 
    rpcProcessorThreadPoolSize).keepAliveSeconds(// 
    60L).workQueue(// 
    new ArrayBlockingQueue<>(10000)).threadFactory(// 
    new NamedThreadFactory("JRaft-RPC-Processor-", true)).build();
    if (this.rpcOptions.getMetricRegistry() != null) {
        this.rpcOptions.getMetricRegistry().register("raft-rpc-client-thread-pool", new ThreadPoolMetricSet(this.rpcExecutor));
        Utils.registerClosureExecutorMetrics(this.rpcOptions.getMetricRegistry());
    }
    return true;
}
Also used : ThreadPoolMetricSet(io.dingodb.raft.util.ThreadPoolMetricSet) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) RaftRpcFactory(io.dingodb.raft.rpc.RaftRpcFactory) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory)

Aggregations

NamedThreadFactory (io.dingodb.raft.util.NamedThreadFactory)12 DisruptorMetricSet (io.dingodb.raft.util.DisruptorMetricSet)4 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)3 Endpoint (io.dingodb.raft.util.Endpoint)3 HashedWheelTimer (io.dingodb.raft.util.timer.HashedWheelTimer)3 Status (io.dingodb.raft.Status)2 ConfigurationEntry (io.dingodb.raft.conf.ConfigurationEntry)2 ConfigurationManager (io.dingodb.raft.conf.ConfigurationManager)2 LogId (io.dingodb.raft.entity.LogId)2 RaftException (io.dingodb.raft.error.RaftException)2 CallerRunsPolicyWithReport (io.dingodb.store.row.util.concurrent.CallerRunsPolicyWithReport)2 DiscardOldPolicyWithReport (io.dingodb.store.row.util.concurrent.DiscardOldPolicyWithReport)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 ThreadFactory (java.util.concurrent.ThreadFactory)2 com.lmax.disruptor (com.lmax.disruptor)1 Disruptor (com.lmax.disruptor.dsl.Disruptor)1 ProducerType (com.lmax.disruptor.dsl.ProducerType)1 FSMCaller (io.dingodb.raft.FSMCaller)1 Configuration (io.dingodb.raft.conf.Configuration)1 NodeMetrics (io.dingodb.raft.core.NodeMetrics)1