Search in sources :

Example 1 with GridCacheFuture

use of org.apache.ignite.internal.processors.cache.GridCacheFuture in project ignite by apache.

the class GridCommandHandlerAbstractTest method checkUserFutures.

/**
 * Checks if all non-system txs and non-system mvcc futures are finished.
 */
protected void checkUserFutures() {
    for (Ignite ignite : G.allGrids()) {
        IgniteEx ig = (IgniteEx) ignite;
        final Collection<GridCacheFuture<?>> futs = ig.context().cache().context().mvcc().activeFutures();
        boolean hasFutures = false;
        for (GridCacheFuture<?> fut : futs) {
            if (!fut.isDone()) {
                // skipping system tx futures if possible
                if (fut instanceof GridNearTxPrepareFutureAdapter && ((GridNearTxPrepareFutureAdapter) fut).tx().system())
                    continue;
                if (fut instanceof GridDhtTxPrepareFuture && ((GridDhtTxPrepareFuture) fut).tx().system())
                    continue;
                log.error("Expecting no active future [node=" + ig.localNode().id() + ", fut=" + fut + ']');
                hasFutures = true;
            }
        }
        if (hasFutures)
            fail("Some mvcc futures are not finished");
        Collection<IgniteInternalTx> txs = ig.context().cache().context().tm().activeTransactions().stream().filter(tx -> !tx.system()).collect(Collectors.toSet());
        for (IgniteInternalTx tx : txs) log.error("Expecting no active transaction [node=" + ig.localNode().id() + ", tx=" + tx + ']');
        if (!txs.isEmpty())
            fail("Some transaction are not finished");
    }
}
Also used : KEYSTORE_PATH(org.apache.ignite.internal.encryption.AbstractEncryptionTest.KEYSTORE_PATH) Arrays(java.util.Arrays) KeystoreEncryptionSpi(org.apache.ignite.spi.encryption.keystore.KeystoreEncryptionSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) DirectoryStream(java.nio.file.DirectoryStream) DFLT_CHECKPOINT_FREQ(org.apache.ignite.configuration.DataStorageConfiguration.DFLT_CHECKPOINT_FREQ) ByteArrayInputStream(java.io.ByteArrayInputStream) IDLE_DUMP_FILE_PREFIX(org.apache.ignite.internal.processors.cache.verify.VerifyBackupPartitionsDumpTask.IDLE_DUMP_FILE_PREFIX) Arrays.asList(java.util.Arrays.asList) Path(java.nio.file.Path) GridDhtTxPrepareFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture) WALMode(org.apache.ignite.configuration.WALMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) GridClientFactory(org.apache.ignite.internal.client.GridClientFactory) CommandHandler(org.apache.ignite.internal.commandline.CommandHandler) Collection(java.util.Collection) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) IgniteCache(org.apache.ignite.IgniteCache) DFLT_REENCRYPTION_RATE_MBPS(org.apache.ignite.configuration.EncryptionConfiguration.DFLT_REENCRYPTION_RATE_MBPS) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) EncryptionConfiguration(org.apache.ignite.configuration.EncryptionConfiguration) Files.newDirectoryStream(java.nio.file.Files.newDirectoryStream) Handler(java.util.logging.Handler) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Objects.nonNull(java.util.Objects.nonNull) Files.delete(java.nio.file.Files.delete) System.lineSeparator(java.lang.System.lineSeparator) ByteArrayOutputStream(java.io.ByteArrayOutputStream) U(org.apache.ignite.internal.util.typedef.internal.U) ArrayList(java.util.ArrayList) ClusterNode(org.apache.ignite.cluster.ClusterNode) IdleVerify(org.apache.ignite.internal.commandline.cache.IdleVerify) String.join(java.lang.String.join) KEYSTORE_PASSWORD(org.apache.ignite.internal.encryption.AbstractEncryptionTest.KEYSTORE_PASSWORD) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) GridCommandHandlerTestUtils.addSslParams(org.apache.ignite.util.GridCommandHandlerTestUtils.addSslParams) PrintStream(java.io.PrintStream) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) DFLT_REENCRYPTION_BATCH_SIZE(org.apache.ignite.configuration.EncryptionConfiguration.DFLT_REENCRYPTION_BATCH_SIZE) GridNearTxPrepareFutureAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareFutureAdapter) Ignite(org.apache.ignite.Ignite) File(java.io.File) GridCacheFuture(org.apache.ignite.internal.processors.cache.GridCacheFuture) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) ConnectorConfiguration(org.apache.ignite.configuration.ConnectorConfiguration) Paths(java.nio.file.Paths) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IGNITE_ENABLE_EXPERIMENTAL_COMMAND(org.apache.ignite.IgniteSystemProperties.IGNITE_ENABLE_EXPERIMENTAL_COMMAND) EVT_CONSISTENCY_VIOLATION(org.apache.ignite.events.EventType.EVT_CONSISTENCY_VIOLATION) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) InputStream(java.io.InputStream) IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) GridNearTxPrepareFutureAdapter(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareFutureAdapter) GridDhtTxPrepareFuture(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxPrepareFuture) GridCacheFuture(org.apache.ignite.internal.processors.cache.GridCacheFuture)

Example 2 with GridCacheFuture

use of org.apache.ignite.internal.processors.cache.GridCacheFuture in project ignite by apache.

the class GridCommonAbstractTest method checkFutures.

/**
 * Checks if all txs and mvcc futures are finished.
 */
protected void checkFutures() {
    for (Ignite ignite : G.allGrids()) {
        IgniteEx ig = (IgniteEx) ignite;
        final Collection<GridCacheFuture<?>> futs = ig.context().cache().context().mvcc().activeFutures();
        boolean hasFutures = false;
        for (GridCacheFuture<?> fut : futs) {
            if (!fut.isDone()) {
                log.error("Expecting no active future [node=" + ig.localNode().id() + ", fut=" + fut + ']');
                hasFutures = true;
            }
        }
        if (hasFutures)
            fail("Some cache futures are not finished");
        Collection<IgniteInternalTx> txs = ig.context().cache().context().tm().activeTransactions();
        for (IgniteInternalTx tx : txs) log.error("Expecting no active transaction [node=" + ig.localNode().id() + ", tx=" + tx + ']');
        if (!txs.isEmpty())
            fail("Some transaction are not finished");
    }
}
Also used : IgniteInternalTx(org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) GridCacheFuture(org.apache.ignite.internal.processors.cache.GridCacheFuture)

Example 3 with GridCacheFuture

use of org.apache.ignite.internal.processors.cache.GridCacheFuture in project ignite by apache.

the class CacheGetReadFromBackupFailoverTest method testFailover.

/**
 * @throws Exception If failed.
 */
@Test
public void testFailover() throws Exception {
    Ignite ignite = ignite(0);
    ignite.cluster().active(true);
    ThreadLocalRandom rnd = ThreadLocalRandom.current();
    try (IgniteDataStreamer<Object, Object> stmr = ignite.dataStreamer(TX_CACHE)) {
        for (int i = 0; i < KEYS_CNT; i++) stmr.addData(i, rnd.nextLong());
    }
    try (IgniteDataStreamer<Object, Object> stmr = ignite.dataStreamer(ATOMIC_CACHE)) {
        for (int i = 0; i < KEYS_CNT; i++) stmr.addData(i, rnd.nextLong());
    }
    AtomicInteger idx = new AtomicInteger(-1);
    AtomicInteger successGet = new AtomicInteger();
    IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
        ThreadLocalRandom rnd0 = ThreadLocalRandom.current();
        while (!stop.get()) {
            Ignite ig = null;
            while (ig == null) {
                int n = rnd0.nextInt(gridCount());
                if (idx.get() != n) {
                    try {
                        ig = ignite(n);
                    } catch (IgniteIllegalStateException e) {
                    // No-op.
                    }
                }
            }
            try {
                if (rnd.nextBoolean()) {
                    ig.cache(TX_CACHE).get(rnd0.nextLong(KEYS_CNT));
                    ig.cache(ATOMIC_CACHE).get(rnd0.nextLong(KEYS_CNT));
                } else {
                    ig.cache(TX_CACHE).getAll(rnd.longs(16, 0, KEYS_CNT).boxed().collect(Collectors.toSet()));
                    ig.cache(ATOMIC_CACHE).getAll(rnd.longs(16, 0, KEYS_CNT).boxed().collect(Collectors.toSet()));
                }
                successGet.incrementAndGet();
            } catch (CacheException e) {
                if (!X.hasCause(e, NodeStoppingException.class))
                    throw e;
            }
        }
    }, "load-thread");
    long startTime = System.currentTimeMillis();
    while (System.currentTimeMillis() - startTime < 30 * 1000L) {
        int idx0 = idx.get();
        if (idx0 >= 0)
            startGrid(idx0);
        U.sleep(500);
        int next = rnd.nextInt(gridCount());
        idx.set(next);
        stopGrid(next);
        U.sleep(500);
    }
    stop.set(true);
    while (true) {
        try {
            fut.get(10_000);
            break;
        } catch (IgniteFutureTimeoutCheckedException e) {
            for (Ignite i : G.allGrids()) {
                IgniteEx ex = (IgniteEx) i;
                log.info(">>>> " + ex.context().localNodeId());
                GridCacheMvccManager mvcc = ex.context().cache().context().mvcc();
                for (GridCacheFuture<?> fut0 : mvcc.activeFutures()) {
                    log.info("activeFut - " + fut0);
                }
                for (GridCacheFuture<?> fut0 : mvcc.atomicFutures()) {
                    log.info("atomicFut - " + fut0);
                }
            }
        }
    }
    Assert.assertTrue(String.valueOf(successGet.get()), successGet.get() > 50);
    Throwable e = err.get();
    if (e != null) {
        log.error("Test failed", e);
        fail("Test failed");
    }
}
Also used : GridCacheMvccManager(org.apache.ignite.internal.processors.cache.GridCacheMvccManager) CacheException(javax.cache.CacheException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException) GridCacheFuture(org.apache.ignite.internal.processors.cache.GridCacheFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

Ignite (org.apache.ignite.Ignite)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 GridCacheFuture (org.apache.ignite.internal.processors.cache.GridCacheFuture)3 IgniteInternalTx (org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 String.join (java.lang.String.join)1 System.lineSeparator (java.lang.System.lineSeparator)1 DirectoryStream (java.nio.file.DirectoryStream)1 Files.delete (java.nio.file.Files.delete)1 Files.newDirectoryStream (java.nio.file.Files.newDirectoryStream)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1