use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class PageMemoryNoStoreImpl method allocatePage.
/**
* {@inheritDoc}
*/
@Override
public long allocatePage(int grpId, int partId, byte flags) {
assert started;
long relPtr = borrowFreePage(grpId);
long absPtr = 0;
if (relPtr != INVALID_REL_PTR) {
int pageIdx = PageIdUtils.pageIndex(relPtr);
Segment seg = segment(pageIdx);
absPtr = seg.absolute(pageIdx);
} else {
// No segments contained a free page.
Segment[] seg0 = segments;
Segment allocSeg = seg0[seg0.length - 1];
while (allocSeg != null) {
relPtr = allocSeg.allocateFreePage(flags);
if (relPtr != INVALID_REL_PTR) {
absPtr = allocSeg.absolute(PageIdUtils.pageIndex(relPtr));
allocatedPages.incrementAndGet();
PageMetrics grpPageMetrics = dataRegionMetrics.cacheGrpPageMetrics(grpId);
grpPageMetrics.totalPages().increment();
break;
} else
allocSeg = addSegment(seg0);
}
}
if (relPtr == INVALID_REL_PTR) {
IgniteOutOfMemoryException oom = new IgniteOutOfMemoryException("Out of memory in data region [" + "name=" + dataRegionCfg.getName() + ", initSize=" + U.readableSize(dataRegionCfg.getInitialSize(), false) + ", maxSize=" + U.readableSize(dataRegionCfg.getMaxSize(), false) + ", persistenceEnabled=" + dataRegionCfg.isPersistenceEnabled() + "] Try the following:" + U.nl() + " ^-- Increase maximum off-heap memory size (DataRegionConfiguration.maxSize)" + U.nl() + " ^-- Enable Ignite persistence (DataRegionConfiguration.persistenceEnabled)" + U.nl() + " ^-- Enable eviction or expiration policies");
if (ctx != null)
ctx.kernalContext().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, oom));
throw oom;
}
assert (relPtr & ~PageIdUtils.PAGE_IDX_MASK) == 0 : U.hexLong(relPtr & ~PageIdUtils.PAGE_IDX_MASK);
// Assign page ID according to flags and partition ID.
long pageId = PageIdUtils.pageId(partId, flags, (int) relPtr);
writePageId(absPtr, pageId);
// TODO pass an argument to decide whether the page should be cleaned.
GridUnsafe.setMemory(absPtr + PAGE_OVERHEAD, sysPageSize - PAGE_OVERHEAD, (byte) 0);
return pageId;
}
use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class ClusterProcessor method onReadyForWrite.
/**
* {@inheritDoc}
*/
@Override
public void onReadyForWrite(DistributedMetaStorage metastorage) {
this.metastorage = metastorage;
ctx.closure().runLocalSafe((GridPlainRunnable) () -> {
try {
ClusterIdAndTag idAndTag = new ClusterIdAndTag(cluster.id(), cluster.tag());
if (log.isInfoEnabled())
log.info("Writing cluster ID and tag to metastorage on ready for write " + idAndTag);
metastorage.writeAsync(CLUSTER_ID_TAG_KEY, idAndTag);
} catch (IgniteCheckedException e) {
ctx.failure().process(new FailureContext(FailureType.CRITICAL_ERROR, e));
}
});
}
use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class DiagnosticProcessorTest method testOutputDiagnosticCorruptedPagesInfo.
/**
* Check that when an CorruptedTreeException is thrown, a "corruptedPages_TIMESTAMP.txt"
* will be created and a warning will be in the log.
*
* @throws Exception If failed.
*/
@Test
public void testOutputDiagnosticCorruptedPagesInfo() throws Exception {
ListeningTestLogger listeningTestLog = new ListeningTestLogger(GridAbstractTest.log);
IgniteEx n = startGrid(0, cfg -> {
cfg.setGridLogger(listeningTestLog);
});
n.cluster().state(ClusterState.ACTIVE);
awaitPartitionMapExchange();
for (int i = 0; i < 10_000; i++) n.cache(DEFAULT_CACHE_NAME).put(i, "val_" + i);
assertNotNull(n.context().diagnostic());
T2<Integer, Long> anyPageId = findAnyPageId(n);
assertNotNull(anyPageId);
LogListener logLsnr = LogListener.matches("CorruptedTreeException has occurred. " + "To diagnose it, make a backup of the following directories: ").build();
listeningTestLog.registerListener(logLsnr);
n.context().failure().process(new FailureContext(FailureType.CRITICAL_ERROR, new CorruptedTreeException("Test ex", null, DEFAULT_CACHE_NAME, anyPageId.get1(), anyPageId.get2())));
assertTrue(logLsnr.check());
Path diagnosticPath = getFieldValue(n.context().diagnostic(), "diagnosticPath");
List<File> corruptedPagesFiles = Arrays.stream(diagnosticPath.toFile().listFiles()).filter(f -> corruptedPagesFileNamePattern().matcher(f.getName()).matches()).collect(toList());
assertEquals(1, corruptedPagesFiles.size());
assertTrue(corruptedPagesFiles.get(0).length() > 0);
}
use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class FailureProcessorThreadDumpThrottlingTest method testThrottling.
/**
* Tests that thread dumps will be throttled and will be generated again after timeout exceeded.
*/
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DUMP_THREADS_ON_FAILURE, value = "true")
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DUMP_THREADS_ON_FAILURE_THROTTLING_TIMEOUT, value = "3000")
public void testThrottling() throws Exception {
LogListener dumpLsnr = LogListener.matches(THREAD_DUMP_MSG).times(2).build();
LogListener throttledLsnr = LogListener.matches("Thread dump is hidden").times(2).build();
testLog.registerListener(dumpLsnr);
testLog.registerListener(throttledLsnr);
IgniteEx ignite = ignite(0);
FailureContext failureCtx = new FailureContext(SYSTEM_WORKER_BLOCKED, new Throwable("Failure context error"));
for (int i = 0; i < 2; i++) ignite.context().failure().process(failureCtx);
U.sleep(3000);
for (int i = 0; i < 2; i++) ignite.context().failure().process(failureCtx);
assertTrue(dumpLsnr.check());
assertTrue(throttledLsnr.check());
}
use of org.apache.ignite.failure.FailureContext in project ignite by apache.
the class FailureProcessorThreadDumpThrottlingTest method testNoThrottling.
/**
* Tests that thread dumps will get for every failure for disabled throttling.
*/
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DUMP_THREADS_ON_FAILURE, value = "true")
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DUMP_THREADS_ON_FAILURE_THROTTLING_TIMEOUT, value = "0")
public void testNoThrottling() throws Exception {
LogListener lsnr = LogListener.matches(THREAD_DUMP_MSG).times(2).build();
testLog.registerListener(lsnr);
IgniteEx ignite = ignite(0);
FailureContext failureCtx = new FailureContext(SYSTEM_WORKER_BLOCKED, new Throwable("Failure context error"));
for (int i = 0; i < 2; i++) ignite.context().failure().process(failureCtx);
assertTrue(lsnr.check());
}
Aggregations