use of org.apache.ignite.internal.worker.WorkersRegistry in project ignite by apache.
the class SystemWorkersBlockingTest method testSingleWorker_NotInInfiniteLoop.
/**
* Tests that repeatedly calling {@link WorkersRegistry#onIdle} in single registered {@link GridWorker}
* doesn't lead to infinite loop.
*
* @throws Exception If failed.
*/
@Test
public void testSingleWorker_NotInInfiniteLoop() throws Exception {
WorkersRegistry registry = new WorkersRegistry((w, e) -> {
}, SYSTEM_WORKER_BLOCKED_TIMEOUT, log());
CountDownLatch finishLatch = new CountDownLatch(1);
GridWorker worker = new GridWorker("test", "test-worker", log, registry) {
@Override
protected void body() {
while (!Thread.currentThread().isInterrupted()) {
onIdle();
LockSupport.parkNanos(1000);
}
finishLatch.countDown();
}
};
runWorker(worker);
Thread.sleep(2 * SYSTEM_WORKER_BLOCKED_TIMEOUT);
workerExecutor.shutdownNow();
assertTrue(workerExecutor.awaitTermination(SYSTEM_WORKER_BLOCKED_TIMEOUT, TimeUnit.MILLISECONDS));
}
use of org.apache.ignite.internal.worker.WorkersRegistry in project ignite by apache.
the class PoolProcessor method start.
/**
* {@inheritDoc}
*/
@Override
public void start() throws IgniteCheckedException {
super.start();
IgniteConfiguration cfg = ctx.config();
UncaughtExceptionHandler oomeHnd = ctx.uncaughtExceptionHandler();
UncaughtExceptionHandler excHnd = new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
ctx.failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
}
};
validateThreadPoolSize(cfg.getPublicThreadPoolSize(), "public");
execSvc = createExecutorService("pub", cfg.getIgniteInstanceName(), cfg.getPublicThreadPoolSize(), cfg.getPublicThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.PUBLIC_POOL, oomeHnd);
execSvc.allowCoreThreadTimeOut(true);
validateThreadPoolSize(cfg.getServiceThreadPoolSize(), "service");
svcExecSvc = createExecutorService("svc", cfg.getIgniteInstanceName(), cfg.getServiceThreadPoolSize(), cfg.getServiceThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.SERVICE_POOL, oomeHnd);
svcExecSvc.allowCoreThreadTimeOut(true);
validateThreadPoolSize(cfg.getSystemThreadPoolSize(), "system");
sysExecSvc = createExecutorService("sys", cfg.getIgniteInstanceName(), cfg.getSystemThreadPoolSize(), cfg.getSystemThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.SYSTEM_POOL, oomeHnd);
sysExecSvc.allowCoreThreadTimeOut(true);
validateThreadPoolSize(cfg.getStripedPoolSize(), "stripedPool");
WorkersRegistry workerRegistry = ctx.workersRegistry();
stripedExecSvc = createStripedExecutor(cfg.getStripedPoolSize(), cfg.getIgniteInstanceName(), "sys", log, new IgniteInClosure<Throwable>() {
@Override
public void apply(Throwable t) {
ctx.failure().process(new FailureContext(SYSTEM_WORKER_TERMINATION, t));
}
}, false, workerRegistry, cfg.getFailureDetectionTimeout());
// Note that since we use 'LinkedBlockingQueue', number of
// maximum threads has no effect.
// Note, that we do not pre-start threads here as management pool may
// not be needed.
validateThreadPoolSize(cfg.getManagementThreadPoolSize(), "management");
mgmtExecSvc = createExecutorService("mgmt", cfg.getIgniteInstanceName(), cfg.getManagementThreadPoolSize(), cfg.getManagementThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.MANAGEMENT_POOL, oomeHnd);
mgmtExecSvc.allowCoreThreadTimeOut(true);
// Note that since we use 'LinkedBlockingQueue', number of
// maximum threads has no effect.
// Note, that we do not pre-start threads here as class loading pool may
// not be needed.
validateThreadPoolSize(cfg.getPeerClassLoadingThreadPoolSize(), "peer class loading");
p2pExecSvc = createExecutorService("p2p", cfg.getIgniteInstanceName(), cfg.getPeerClassLoadingThreadPoolSize(), cfg.getPeerClassLoadingThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.P2P_POOL, oomeHnd);
p2pExecSvc.allowCoreThreadTimeOut(true);
dataStreamerExecSvc = createStripedExecutor(cfg.getDataStreamerThreadPoolSize(), cfg.getIgniteInstanceName(), "data-streamer", log, new IgniteInClosure<Throwable>() {
@Override
public void apply(Throwable t) {
ctx.failure().process(new FailureContext(SYSTEM_WORKER_TERMINATION, t));
}
}, true, workerRegistry, cfg.getFailureDetectionTimeout());
// Note that we do not pre-start threads here as this pool may not be needed.
validateThreadPoolSize(cfg.getAsyncCallbackPoolSize(), "async callback");
callbackExecSvc = new IgniteStripedThreadPoolExecutor(cfg.getAsyncCallbackPoolSize(), cfg.getIgniteInstanceName(), "callback", oomeHnd, false, 0);
if (cfg.getConnectorConfiguration() != null) {
validateThreadPoolSize(cfg.getConnectorConfiguration().getThreadPoolSize(), "connector");
restExecSvc = createExecutorService("rest", cfg.getIgniteInstanceName(), cfg.getConnectorConfiguration().getThreadPoolSize(), cfg.getConnectorConfiguration().getThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, oomeHnd);
restExecSvc.allowCoreThreadTimeOut(true);
}
validateThreadPoolSize(cfg.getUtilityCacheThreadPoolSize(), "utility cache");
utilityCacheExecSvc = createExecutorService("utility", cfg.getIgniteInstanceName(), cfg.getUtilityCacheThreadPoolSize(), cfg.getUtilityCacheThreadPoolSize(), cfg.getUtilityCacheKeepAliveTime(), new LinkedBlockingQueue<>(), GridIoPolicy.UTILITY_CACHE_POOL, oomeHnd);
utilityCacheExecSvc.allowCoreThreadTimeOut(true);
affExecSvc = createExecutorService("aff", cfg.getIgniteInstanceName(), 1, 1, DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.AFFINITY_POOL, oomeHnd);
affExecSvc.allowCoreThreadTimeOut(true);
if (IgniteComponentType.INDEXING.inClassPath()) {
int cpus = Runtime.getRuntime().availableProcessors();
idxExecSvc = createExecutorService("idx", cfg.getIgniteInstanceName(), cpus, cpus * 2, 3000L, new LinkedBlockingQueue<>(1000), GridIoPolicy.IDX_POOL, oomeHnd);
int buildIdxThreadPoolSize = cfg.getBuildIndexThreadPoolSize();
validateThreadPoolSize(buildIdxThreadPoolSize, "build-idx");
buildIdxExecSvc = createExecutorService("build-idx-runner", cfg.getIgniteInstanceName(), buildIdxThreadPoolSize, buildIdxThreadPoolSize, DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, oomeHnd);
buildIdxExecSvc.allowCoreThreadTimeOut(true);
}
validateThreadPoolSize(cfg.getQueryThreadPoolSize(), "query");
qryExecSvc = createExecutorService("query", cfg.getIgniteInstanceName(), cfg.getQueryThreadPoolSize(), cfg.getQueryThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.QUERY_POOL, oomeHnd);
qryExecSvc.allowCoreThreadTimeOut(true);
schemaExecSvc = createExecutorService("schema", cfg.getIgniteInstanceName(), 2, 2, DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.SCHEMA_POOL, oomeHnd);
schemaExecSvc.allowCoreThreadTimeOut(true);
validateThreadPoolSize(cfg.getRebalanceThreadPoolSize(), "rebalance");
rebalanceExecSvc = createExecutorService("rebalance", cfg.getIgniteInstanceName(), cfg.getRebalanceThreadPoolSize(), cfg.getRebalanceThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, excHnd);
rebalanceExecSvc.allowCoreThreadTimeOut(true);
if (CU.isPersistenceEnabled(ctx.config())) {
snpExecSvc = createExecutorService(SNAPSHOT_RUNNER_THREAD_PREFIX, cfg.getIgniteInstanceName(), cfg.getSnapshotThreadPoolSize(), cfg.getSnapshotThreadPoolSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, excHnd);
snpExecSvc.allowCoreThreadTimeOut(true);
reencryptExecSvc = createExecutorService("reencrypt", ctx.igniteInstanceName(), 1, 1, DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, oomeHnd);
reencryptExecSvc.allowCoreThreadTimeOut(true);
}
if (cfg.getClientConnectorConfiguration() != null) {
thinClientExec = new IgniteThreadPoolExecutor("client-connector", cfg.getIgniteInstanceName(), cfg.getClientConnectorConfiguration().getThreadPoolSize(), cfg.getClientConnectorConfiguration().getThreadPoolSize(), 0, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, oomeHnd);
}
rebalanceStripedExecSvc = createStripedThreadPoolExecutor(cfg.getRebalanceThreadPoolSize(), cfg.getIgniteInstanceName(), "rebalance-striped", excHnd, true, DFLT_THREAD_KEEP_ALIVE_TIME);
if (!F.isEmpty(cfg.getExecutorConfiguration())) {
validateCustomExecutorsConfiguration(cfg.getExecutorConfiguration());
customExecs = new HashMap<>();
for (ExecutorConfiguration execCfg : cfg.getExecutorConfiguration()) {
ThreadPoolExecutor exec = createExecutorService(execCfg.getName(), cfg.getIgniteInstanceName(), execCfg.getSize(), execCfg.getSize(), DFLT_THREAD_KEEP_ALIVE_TIME, new LinkedBlockingQueue<>(), GridIoPolicy.UNDEFINED, oomeHnd);
customExecs.put(execCfg.getName(), exec);
}
}
}
use of org.apache.ignite.internal.worker.WorkersRegistry in project ignite by apache.
the class GridNioServerWrapper method resetNioServer.
/**
* Recreates tpcSrvr socket instance.
*
* @return Server instance.
* @throws IgniteCheckedException Thrown if it's not possible to create server.
*/
public GridNioServer<Message> resetNioServer() throws IgniteCheckedException {
if (cfg.boundTcpPort() >= 0)
throw new IgniteCheckedException("Tcp NIO server was already created on port " + cfg.boundTcpPort());
IgniteCheckedException lastEx = null;
// If configured TCP port is busy, find first available in range.
int lastPort = cfg.localPort() == -1 ? -1 : cfg.localPortRange() == 0 ? cfg.localPort() : cfg.localPort() + cfg.localPortRange() - 1;
for (int port = cfg.localPort(); port <= lastPort; port++) {
try {
MessageFactory msgFactory = new MessageFactory() {
private MessageFactory impl;
@Nullable
@Override
public Message create(short type) {
if (impl == null)
impl = stateProvider.getSpiContext().messageFactory();
assert impl != null;
return impl.create(type);
}
};
GridNioMessageReaderFactory readerFactory = new GridNioMessageReaderFactory() {
private IgniteSpiContext context;
private MessageFormatter formatter;
@Override
public MessageReader reader(GridNioSession ses, MessageFactory msgFactory) throws IgniteCheckedException {
final IgniteSpiContext ctx = stateProvider.getSpiContextWithoutInitialLatch();
if (formatter == null || context != ctx) {
context = ctx;
formatter = context.messageFormatter();
}
assert formatter != null;
ConnectionKey key = ses.meta(CONN_IDX_META);
return key != null ? formatter.reader(key.nodeId(), msgFactory) : null;
}
};
GridNioMessageWriterFactory writerFactory = new GridNioMessageWriterFactory() {
private IgniteSpiContext context;
private MessageFormatter formatter;
@Override
public MessageWriter writer(GridNioSession ses) throws IgniteCheckedException {
final IgniteSpiContext ctx = stateProvider.getSpiContextWithoutInitialLatch();
if (formatter == null || context != ctx) {
context = ctx;
formatter = context.messageFormatter();
}
assert formatter != null;
ConnectionKey key = ses.meta(CONN_IDX_META);
return key != null ? formatter.writer(key.nodeId()) : null;
}
};
GridDirectParser parser = new GridDirectParser(log.getLogger(GridDirectParser.class), msgFactory, readerFactory);
IgnitePredicate<Message> skipRecoveryPred = msg -> msg instanceof RecoveryLastReceivedMessage;
boolean clientMode = Boolean.TRUE.equals(igniteCfg.isClientMode());
IgniteBiInClosure<GridNioSession, Integer> queueSizeMonitor = !clientMode && cfg.slowClientQueueLimit() > 0 ? this::checkClientQueueSize : null;
List<GridNioFilter> filters = new ArrayList<>();
if (tracing instanceof GridTracingManager && ((GridManager) tracing).enabled())
filters.add(new GridNioTracerFilter(log, tracing));
filters.add(new GridNioCodecFilter(parser, log, true));
filters.add(new GridConnectionBytesVerifyFilter(log));
if (stateProvider.isSslEnabled()) {
GridNioSslFilter sslFilter = new GridNioSslFilter(igniteCfg.getSslContextFactory().create(), true, ByteOrder.LITTLE_ENDIAN, log, metricMgr == null ? null : metricMgr.registry(COMMUNICATION_METRICS_GROUP_NAME));
sslFilter.directMode(true);
sslFilter.wantClientAuth(true);
sslFilter.needClientAuth(true);
filters.add(sslFilter);
}
GridNioServer.Builder<Message> builder = GridNioServer.<Message>builder().address(cfg.localHost()).port(port).listener(srvLsnr).logger(log).selectorCount(cfg.selectorsCount()).igniteInstanceName(igniteInstanceName).serverName("tcp-comm").tcpNoDelay(cfg.tcpNoDelay()).directBuffer(cfg.directBuffer()).byteOrder(ByteOrder.LITTLE_ENDIAN).socketSendBufferSize(cfg.socketSendBuffer()).socketReceiveBufferSize(cfg.socketReceiveBuffer()).sendQueueLimit(cfg.messageQueueLimit()).directMode(true).writeTimeout(cfg.socketWriteTimeout()).selectorSpins(cfg.selectorSpins()).filters(filters.toArray(new GridNioFilter[filters.size()])).writerFactory(writerFactory).skipRecoveryPredicate(skipRecoveryPred).messageQueueSizeListener(queueSizeMonitor).tracing(tracing).readWriteSelectorsAssign(cfg.usePairedConnections());
if (metricMgr != null) {
builder.workerListener(workersRegistry).metricRegistry(metricMgr.registry(COMMUNICATION_METRICS_GROUP_NAME));
}
GridNioServer<Message> srvr = builder.build();
cfg.boundTcpPort(port);
// Ack Port the TCP server was bound to.
if (log.isInfoEnabled()) {
log.info("Successfully bound communication NIO server to TCP port " + "[port=" + cfg.boundTcpPort() + ", locHost=" + cfg.localHost() + ", selectorsCnt=" + cfg.selectorsCount() + ", selectorSpins=" + srvr.selectorSpins() + ", pairedConn=" + cfg.usePairedConnections() + ']');
}
srvr.idleTimeout(cfg.idleConnectionTimeout());
return srvr;
} catch (IgniteCheckedException e) {
if (X.hasCause(e, SSLException.class))
throw new IgniteSpiException("Failed to create SSL context. SSL factory: " + igniteCfg.getSslContextFactory() + '.', e);
lastEx = e;
if (log.isDebugEnabled())
log.debug("Failed to bind to local port (will try next port within range) [port=" + port + ", locHost=" + cfg.localHost() + ']');
eRegistrySupplier.get().onException("Failed to bind to local port (will try next port within range) [port=" + port + ", locHost=" + cfg.localHost() + ']', e);
}
}
// If free port wasn't found.
throw new IgniteCheckedException("Failed to bind to any port within range [startPort=" + cfg.localPort() + ", portRange=" + cfg.localPortRange() + ", locHost=" + cfg.localHost() + ']', lastEx);
}
use of org.apache.ignite.internal.worker.WorkersRegistry in project ignite by apache.
the class FailureHandlingConfigurationTest method testPartialCfgParamsPropagation.
/**
* @throws Exception If failed.
*/
@Test
public void testPartialCfgParamsPropagation() throws Exception {
sysWorkerBlockedTimeout = 30_000L;
checkpointReadLockTimeout = null;
IgniteEx ignite = startGrid(0);
ignite.cluster().active(true);
WorkersRegistry reg = ignite.context().workersRegistry();
IgniteCacheDatabaseSharedManager dbMgr = ignite.context().cache().context().database();
FailureHandlingMxBean mBean = getMBean();
assertEquals(sysWorkerBlockedTimeout.longValue(), reg.getSystemWorkerBlockedTimeout());
assertEquals(sysWorkerBlockedTimeout.longValue(), dbMgr.checkpointReadLockTimeout());
assertEquals(sysWorkerBlockedTimeout.longValue(), mBean.getSystemWorkerBlockedTimeout());
assertEquals(sysWorkerBlockedTimeout.longValue(), mBean.getCheckpointReadLockTimeout());
}
use of org.apache.ignite.internal.worker.WorkersRegistry in project ignite by apache.
the class FailureHandlingConfigurationTest method testCfgParamsPropagation.
/**
* @throws Exception If failed.
*/
@Test
public void testCfgParamsPropagation() throws Exception {
sysWorkerBlockedTimeout = 30_000L;
checkpointReadLockTimeout = 20_000L;
IgniteEx ignite = startGrid(0);
ignite.cluster().active(true);
WorkersRegistry reg = ignite.context().workersRegistry();
IgniteCacheDatabaseSharedManager dbMgr = ignite.context().cache().context().database();
FailureHandlingMxBean mBean = getMBean();
assertEquals(sysWorkerBlockedTimeout.longValue(), reg.getSystemWorkerBlockedTimeout());
assertEquals(checkpointReadLockTimeout.longValue(), dbMgr.checkpointReadLockTimeout());
assertEquals(sysWorkerBlockedTimeout.longValue(), mBean.getSystemWorkerBlockedTimeout());
assertEquals(checkpointReadLockTimeout.longValue(), mBean.getCheckpointReadLockTimeout());
}
Aggregations