Search in sources :

Example 21 with FailureContext

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;
}
Also used : IgniteOutOfMemoryException(org.apache.ignite.internal.mem.IgniteOutOfMemoryException) FailureContext(org.apache.ignite.failure.FailureContext) PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)

Example 22 with FailureContext

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));
        }
    });
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) FailureContext(org.apache.ignite.failure.FailureContext)

Example 23 with FailureContext

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);
}
Also used : Path(java.nio.file.Path) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) LogListener(org.apache.ignite.testframework.LogListener) WALIterator(org.apache.ignite.internal.pagemem.wal.WALIterator) Arrays(java.util.Arrays) DiagnosticProcessor.walDirs(org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.walDirs) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) CorruptedTreeException(org.apache.ignite.internal.processors.cache.persistence.tree.CorruptedTreeException) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) FailureContext(org.apache.ignite.failure.FailureContext) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) Path(java.nio.file.Path) DiagnosticProcessor.corruptedPagesFile(org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.corruptedPagesFile) SegmentRouter(org.apache.ignite.internal.processors.cache.persistence.wal.SegmentRouter) DFLT_WAL_PATH(org.apache.ignite.configuration.DataStorageConfiguration.DFLT_WAL_PATH) F(org.apache.ignite.internal.util.typedef.F) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) LongStream(java.util.stream.LongStream) FailureType(org.apache.ignite.failure.FailureType) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) DEFAULT_TARGET_FOLDER(org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.DEFAULT_TARGET_FOLDER) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) WALRecord(org.apache.ignite.internal.pagemem.wal.record.WALRecord) Test(org.junit.Test) File(java.io.File) T2(org.apache.ignite.internal.util.typedef.T2) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Collectors.toList(java.util.stream.Collectors.toList) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridTestUtils.getFieldValue(org.apache.ignite.testframework.GridTestUtils.getFieldValue) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Pattern(java.util.regex.Pattern) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) LogListener(org.apache.ignite.testframework.LogListener) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) FailureContext(org.apache.ignite.failure.FailureContext) IgniteEx(org.apache.ignite.internal.IgniteEx) CorruptedTreeException(org.apache.ignite.internal.processors.cache.persistence.tree.CorruptedTreeException) DiagnosticProcessor.corruptedPagesFile(org.apache.ignite.internal.processors.diagnostic.DiagnosticProcessor.corruptedPagesFile) File(java.io.File) GridAbstractTest(org.apache.ignite.testframework.junits.GridAbstractTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 24 with FailureContext

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());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) FailureContext(org.apache.ignite.failure.FailureContext) IgniteEx(org.apache.ignite.internal.IgniteEx) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Example 25 with FailureContext

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());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) FailureContext(org.apache.ignite.failure.FailureContext) IgniteEx(org.apache.ignite.internal.IgniteEx) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Aggregations

FailureContext (org.apache.ignite.failure.FailureContext)54 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)20 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)13 Ignite (org.apache.ignite.Ignite)11 IOException (java.io.IOException)9 AbstractFailureHandler (org.apache.ignite.failure.AbstractFailureHandler)9 IgniteEx (org.apache.ignite.internal.IgniteEx)9 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)9 Test (org.junit.Test)9 IgniteException (org.apache.ignite.IgniteException)8 File (java.io.File)6 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)6 StorageException (org.apache.ignite.internal.processors.cache.persistence.StorageException)6 LogListener (org.apache.ignite.testframework.LogListener)5 WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)4 ByteBuffer (java.nio.ByteBuffer)3 UUID (java.util.UUID)3 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)3