use of org.apache.ignite.failure.FailureContext 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.failure.FailureContext in project ignite by apache.
the class GridEncryptionManager method doChangeMasterKey.
/**
* Sets up master key and re-encrypt group keys. Writes changes to WAL and MetaStorage.
*
* @param name New master key name.
*/
private void doChangeMasterKey(String name) {
if (log.isInfoEnabled())
log.info("Start master key change [masterKeyName=" + name + ']');
masterKeyChangeLock.writeLock().lock();
try {
getSpi().setMasterKeyName(name);
synchronized (metaStorageMux) {
ctx.cache().context().database().checkpointReadLock();
try {
writeKeysToWal();
assert writeToMetaStoreEnabled;
writeKeysToMetaStore(true);
} finally {
ctx.cache().context().database().checkpointReadUnlock();
}
}
if (log.isInfoEnabled())
log.info("Master key successfully changed [masterKeyName=" + name + ']');
} catch (Exception e) {
U.error(log, "Unable to change master key locally.", e);
ctx.failure().process(new FailureContext(CRITICAL_ERROR, new IgniteException("Unable to change master key locally.", e)));
} finally {
masterKeyChangeLock.writeLock().unlock();
}
}
use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class CheckpointTimeoutLock method failCheckpointReadLock.
/**
* Invokes critical failure processing. Always throws.
*
* @throws CheckpointReadLockTimeoutException If node was not invalidated as result of handling.
* @throws IgniteException If node was invalidated as result of handling.
*/
private void failCheckpointReadLock() throws CheckpointReadLockTimeoutException, IgniteException {
String msg = "Checkpoint read lock acquisition has been timed out.";
IgniteException e = new IgniteException(msg);
if (failureProcessor.process(new FailureContext(SYSTEM_CRITICAL_OPERATION_TIMEOUT, e)))
throw e;
throw new CheckpointReadLockTimeoutException(msg);
}
use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class FileWriteAheadLogManager method initNextWriteHandle.
/**
* Fills the file header for a new segment. Calling this method signals we are done with the segment and it can be
* archived. If we don't have prepared file yet and achiever is busy this method blocks.
*
* @param cur Current file write handle released by WAL writer.
* @return Initialized file handle.
* @throws IgniteCheckedException If exception occurred.
*/
private FileWriteHandle initNextWriteHandle(FileWriteHandle cur) throws IgniteCheckedException {
IgniteCheckedException error = null;
try {
File nextFile = pollNextFile(cur.getSegmentId());
if (log.isDebugEnabled())
log.debug("Switching to a new WAL segment: " + nextFile.getAbsolutePath());
SegmentIO fileIO = null;
FileWriteHandle hnd;
boolean interrupted = false;
if (switchSegmentRecordOffset != null)
switchSegmentRecordOffset.set((int) ((cur.getSegmentId() + 1) % dsCfg.getWalSegments()), 0);
while (true) {
try {
fileIO = new SegmentIO(cur.getSegmentId() + 1, ioFactory.create(nextFile));
IgniteInClosure<FileIO> lsnr = createWalFileListener;
if (lsnr != null)
lsnr.apply(fileIO);
hnd = fileHandleManager.nextHandle(fileIO, serializer);
if (interrupted)
Thread.currentThread().interrupt();
break;
} catch (ClosedByInterruptException ignore) {
interrupted = true;
Thread.interrupted();
if (fileIO != null) {
try {
fileIO.close();
} catch (IOException ignored) {
// No-op.
}
fileIO = null;
}
}
}
hnd.writeHeader();
return hnd;
} catch (IgniteCheckedException e) {
throw error = e;
} catch (IOException e) {
throw error = new StorageException("Unable to initialize WAL segment", e);
} finally {
if (error != null)
cctx.kernalContext().failure().process(new FailureContext(CRITICAL_ERROR, error));
}
}
use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class FsyncFileWriteHandle method flush.
/**
* @param expHead Expected head of chain. If head was changed, flush is not performed in this thread
* @throws StorageException If failed.
*/
private boolean flush(WALRecord expHead, boolean stop) throws StorageException {
if (expHead.previous() == null) {
FakeRecord frHead = (FakeRecord) expHead;
if (// Protects from CASing terminal FakeRecord(true) to FakeRecord(false)
!stop || frHead.stop)
return false;
}
// Fail-fast before CAS.
checkNode();
if (!head.compareAndSet(expHead, new FakeRecord(new WALPointer(getSegmentId(), (int) nextPosition(expHead), 0), stop)))
return false;
if (expHead.chainSize() == 0)
return false;
// Any failure in this code must invalidate the environment.
try {
// We can safely allow other threads to start building next chains while we are doing flush here.
ByteBuffer buf;
boolean tmpBuf = false;
if (expHead.chainSize() > tlbSize) {
buf = GridUnsafe.allocateBuffer(expHead.chainSize());
// We need to manually release this temporary direct buffer.
tmpBuf = true;
} else
buf = tlb.get();
try {
long pos = fillBuffer(buf, expHead);
writeBuffer(pos, buf);
} finally {
if (tmpBuf)
GridUnsafe.freeBuffer(buf);
}
return true;
} catch (Throwable e) {
StorageException se = e instanceof StorageException ? (StorageException) e : new StorageException("Unable to write", new IOException(e));
cctx.kernalContext().failure().process(new FailureContext(CRITICAL_ERROR, se));
// All workers waiting for a next segment must be woken up and stopped
signalNextAvailable();
throw se;
}
}
Aggregations