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