Search in sources :

Example 6 with GridTimeoutObject

use of org.apache.ignite.internal.processors.timeout.GridTimeoutObject in project ignite by apache.

the class StartNodeCallableImpl method initTimer.

/**
 * Initialize timer to wait for command execution.
 *
 * @param cmd Command to log.
 */
private GridTimeoutObject initTimer(String cmd) {
    GridTimeoutObject to = new GridTimeoutObjectAdapter(EXECUTE_WAIT_TIME) {

        private final Thread thread = Thread.currentThread();

        @Override
        public void onTimeout() {
            thread.interrupt();
        }

        @Override
        public String toString() {
            return S.toString("GridTimeoutObject", "cmd", cmd, "thread", thread);
        }
    };
    boolean wasAdded = proc.addTimeoutObject(to);
    assert wasAdded : "Timeout object was not added: " + to;
    return to;
}
Also used : GridTimeoutObjectAdapter(org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

Example 7 with GridTimeoutObject

use of org.apache.ignite.internal.processors.timeout.GridTimeoutObject in project ignite by apache.

the class IgniteTxRemoveTimeoutObjectsTest method logTimeoutObjectsFrequency.

/**
 * Print the number of each timeout object type on each grid to the log.
 */
private void logTimeoutObjectsFrequency() {
    StringBuilder sb = new StringBuilder("Timeout objects frequency [");
    for (Ignite ignite : G.allGrids()) {
        IgniteEx igniteEx = (IgniteEx) ignite;
        Map<String, Integer> objFreqMap = new HashMap<>();
        Set<GridTimeoutObject> objs = getTimeoutObjects(igniteEx);
        for (GridTimeoutObject obj : objs) {
            String clsName = obj.getClass().getSimpleName();
            Integer cnt = objFreqMap.get(clsName);
            if (cnt == null)
                objFreqMap.put(clsName, 1);
            else
                objFreqMap.put(clsName, cnt + 1);
        }
        sb.append("[").append(igniteEx.name()).append(": size=").append(objs.size()).append(", ");
        for (Map.Entry<String, Integer> entry : objFreqMap.entrySet()) {
            sb.append(entry.getKey()).append("=").append(entry.getValue()).append(", ");
        }
        sb.delete(sb.length() - 2, sb.length()).append("]; ");
    }
    sb.delete(sb.length() - 2, sb.length()).append("]");
    info(sb.toString().replaceAll("distributed.IgniteTxRemoveTimeoutObjectsTest", "Grid"));
}
Also used : HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) HashMap(java.util.HashMap) Map(java.util.Map) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

Example 8 with GridTimeoutObject

use of org.apache.ignite.internal.processors.timeout.GridTimeoutObject in project ignite by apache.

the class WriteAheadLogManagerSelfTest method testNoRaceAutoArchiveAndDeactivation.

/**
 * Checking the absence of a race between the deactivation of the VAL and
 * automatic archiving, which may lead to a fail of the node.
 *
 * @throws Exception If failed.
 */
@Test
public void testNoRaceAutoArchiveAndDeactivation() throws Exception {
    for (int i = 0; i < 10; i++) {
        if (log.isInfoEnabled())
            log.info(">>> Test iteration:" + i);
        IgniteEx n = startGrid(0, cfg -> {
            cfg.getDataStorageConfiguration().setWalAutoArchiveAfterInactivity(10);
        });
        n.cluster().state(ACTIVE);
        awaitPartitionMapExchange();
        GridTimeoutObject timeoutObj = timeoutRollover(n);
        assertNotNull(timeoutObj);
        n.cache(DEFAULT_CACHE_NAME).put(current().nextInt(), new byte[16]);
        CountDownLatch l = new CountDownLatch(1);
        AtomicBoolean stop = new AtomicBoolean();
        IgniteInternalFuture<Object> fut = runAsync(() -> {
            l.countDown();
            while (!stop.get()) lastRecordLoggedMs(n).set(1);
        });
        assertTrue(l.await(getTestTimeout(), MILLISECONDS));
        walMgr(n).onDeActivate(n.context());
        stop.set(true);
        fut.get(getTestTimeout());
        assertEquals(1, G.allGrids().size());
        stopAllGrids();
        cleanPersistenceDir();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) CountDownLatch(java.util.concurrent.CountDownLatch) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 9 with GridTimeoutObject

use of org.apache.ignite.internal.processors.timeout.GridTimeoutObject in project ignite by apache.

the class WriteAheadLogManagerSelfTest method testAutoArchiveWithoutNullPointerException.

/**
 * Check that auto archive will execute without {@link NullPointerException}.
 *
 * @throws Exception If failed.
 */
@Test
public void testAutoArchiveWithoutNullPointerException() throws Exception {
    setRootLoggerDebugLevel();
    LogListener logLsnr0 = LogListener.matches("Checking if WAL rollover required").build();
    LogListener logLsnr1 = LogListener.matches(Pattern.compile("Rollover segment \\[\\d+ to \\d+\\], recordType=null")).build();
    IgniteEx n = startGrid(0, cfg -> {
        cfg.setGridLogger(new ListeningTestLogger(log, logLsnr0, logLsnr1)).getDataStorageConfiguration().setWalAutoArchiveAfterInactivity(100_000);
    });
    n.cluster().state(ACTIVE);
    awaitPartitionMapExchange();
    GridTimeoutObject timeoutObj = timeoutRollover(n);
    assertNotNull(timeoutObj);
    n.cache(DEFAULT_CACHE_NAME).put(current().nextInt(), new byte[16]);
    disableWal(n);
    lastRecordLoggedMs(n).set(1);
    timeoutObj.onTimeout();
    assertTrue(logLsnr0.check());
    assertTrue(logLsnr1.check());
}
Also used : LogListener(org.apache.ignite.testframework.LogListener) IgniteEx(org.apache.ignite.internal.IgniteEx) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 10 with GridTimeoutObject

use of org.apache.ignite.internal.processors.timeout.GridTimeoutObject in project ignite by apache.

the class FileWriteAheadLogManager method stop0.

/**
 * {@inheritDoc}
 */
@Override
protected void stop0(boolean cancel) {
    final GridTimeoutProcessor.CancelableTask schedule = backgroundFlushSchedule;
    if (schedule != null)
        schedule.close();
    final GridTimeoutObject timeoutObj = nextAutoArchiveTimeoutObj;
    if (timeoutObj != null)
        cctx.time().removeTimeoutObject(timeoutObj);
    final FileWriteHandle currHnd = currentHandle();
    try {
        if (mode == WALMode.BACKGROUND) {
            if (currHnd != null)
                currHnd.flush(null);
        }
        if (currHnd != null)
            currHnd.close(false);
        if (walWriter != null)
            walWriter.shutdown();
        if (archiver != null)
            archiver.shutdown();
        if (compressor != null)
            compressor.shutdown();
        if (decompressor != null)
            decompressor.shutdown();
    } catch (Exception e) {
        U.error(log, "Failed to gracefully close WAL segment: " + this.currHnd.fileIO, e);
    }
}
Also used : GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) StorageException(org.apache.ignite.internal.pagemem.wal.StorageException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

Aggregations

GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)5 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 IgniteUuid (org.apache.ignite.lang.IgniteUuid)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3 UUID (java.util.UUID)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)3 GridTimeoutObjectAdapter (org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter)3 EOFException (java.io.EOFException)2 FileNotFoundException (java.io.FileNotFoundException)2 Time (java.sql.Time)2 ArrayList (java.util.ArrayList)2