Search in sources :

Example 26 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.

the class BlockedEvictionsTest method testCacheGroupDestroy_Volatile.

/**
 * @throws Exception If failed.
 */
@Test
public void testCacheGroupDestroy_Volatile() throws Exception {
    AtomicReference<IgniteInternalFuture> ref = new AtomicReference<>();
    testOperationDuringEviction(false, 1, p -> {
        IgniteInternalFuture fut = runAsync(new Runnable() {

            @Override
            public void run() {
                grid(0).destroyCache(DEFAULT_CACHE_NAME);
            }
        });
        doSleep(500);
        // Cache stop should be blocked by concurrent unfinished eviction.
        assertFalse(fut.isDone());
        ref.set(fut);
    }, this::preload);
    try {
        ref.get().get(10_000);
    } catch (IgniteFutureTimeoutCheckedException e) {
        fail(X.getFullStackTrace(e));
    }
    PartitionsEvictManager mgr = grid(0).context().cache().context().evict();
    // Group eviction context should remain in map.
    Map evictionGroupsMap = U.field(mgr, "evictionGroupsMap");
    assertFalse("Group context must be cleaned up", evictionGroupsMap.containsKey(CU.cacheId(DEFAULT_CACHE_NAME)));
    grid(0).getOrCreateCache(cacheConfiguration());
    assertEquals(2, evictionGroupsMap.size());
    assertPartitionsSame(idleVerify(grid(0), DEFAULT_CACHE_NAME));
}
Also used : IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Map(java.util.Map) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 27 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.

the class GridCacheColocatedDebugTest method testConcurrentCheckThreadChain.

/**
 * Covers scenario when thread chain locks acquisition for XID 1 should be continued during unsuccessful attempt
 * to acquire lock on certain key for XID 2 (XID 1 with uncompleted chain becomes owner of this key instead).
 *
 * Scenario:
 * 1) Start 1 server node with transactional cache
 * 2) With 10 threads, perform 100000 transactions with massive puts
 * 2.1) Every put affects the same common key, which is not first and not last in the keys list
 * 3) Expected: 100000 transaction should end, load threads shouldn't hang for more than 5 seconds
 *
 * @throws Exception If failed.
 */
protected void testConcurrentCheckThreadChain(TransactionConcurrency txConcurrency) throws Exception {
    storeEnabled = false;
    startGrid(0);
    try {
        final AtomicLong iterCnt = new AtomicLong();
        int commonKey = 1000;
        int otherKeyPickVariance = 10;
        int otherKeysCnt = 5;
        int maxIterCnt = MAX_ITER_CNT * 10;
        IgniteInternalFuture<?> fut = multithreadedAsync(new Runnable() {

            @Override
            public void run() {
                long threadId = Thread.currentThread().getId();
                long itNum;
                while ((itNum = iterCnt.getAndIncrement()) < maxIterCnt) {
                    Map<Integer, String> vals = U.newLinkedHashMap(otherKeysCnt * 2 + 1);
                    for (int i = 0; i < otherKeysCnt; i++) {
                        int key = ThreadLocalRandom.current().nextInt(otherKeyPickVariance * i, otherKeyPickVariance * (i + 1));
                        vals.put(key, String.valueOf(key) + threadId);
                    }
                    vals.put(commonKey, String.valueOf(commonKey) + threadId);
                    for (int i = 0; i < otherKeysCnt; i++) {
                        int key = ThreadLocalRandom.current().nextInt(commonKey + otherKeyPickVariance * (i + 1), otherKeyPickVariance * (i + 2) + commonKey);
                        vals.put(key, String.valueOf(key) + threadId);
                    }
                    try (Transaction tx = grid(0).transactions().txStart(txConcurrency, READ_COMMITTED)) {
                        jcache(0).putAll(vals);
                        tx.commit();
                    }
                    if (itNum > 0 && itNum % 5000 == 0)
                        info(">>> " + itNum + " iterations completed.");
                }
            }
        }, THREAD_CNT);
        while (true) {
            long prevIterCnt = iterCnt.get();
            try {
                fut.get(5_000);
                break;
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                if (iterCnt.get() == prevIterCnt) {
                    Collection<IgniteInternalTx> hangingTxes = ignite(0).context().cache().context().tm().activeTransactions();
                    fail(hangingTxes.toString());
                }
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Transaction(org.apache.ignite.transactions.Transaction) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Collection(java.util.Collection) Map(java.util.Map)

Example 28 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.

the class IgniteTxOriginatingNodeFailureAbstractSelfTest method testTxOriginatingNodeFails.

/**
 * @param keys Keys to update.
 * @param partial Flag indicating whether to simulate partial prepared state.
 * @throws Exception If failed.
 */
protected void testTxOriginatingNodeFails(Collection<Integer> keys, final boolean partial) throws Exception {
    assertFalse(keys.isEmpty());
    final Collection<IgniteKernal> grids = new ArrayList<>();
    ClusterNode txNode = grid(originatingNode()).localNode();
    for (int i = 1; i < gridCount(); i++) grids.add((IgniteKernal) grid(i));
    final Map<Integer, String> map = new HashMap<>();
    final String initVal = "initialValue";
    for (Integer key : keys) {
        grid(originatingNode()).cache(DEFAULT_CACHE_NAME).put(key, initVal);
        map.put(key, String.valueOf(key));
    }
    Map<Integer, Collection<ClusterNode>> nodeMap = new HashMap<>();
    info("Node being checked: " + grid(1).localNode().id());
    for (Integer key : keys) {
        Collection<ClusterNode> nodes = new ArrayList<>();
        nodes.addAll(grid(1).affinity(DEFAULT_CACHE_NAME).mapKeyToPrimaryAndBackups(key));
        nodes.remove(txNode);
        nodeMap.put(key, nodes);
    }
    info("Starting optimistic tx " + "[values=" + map + ", topVer=" + (grid(1)).context().discovery().topologyVersion() + ']');
    if (partial)
        ignoreMessages(grid(1).localNode().id(), ignoreMessageClass());
    final Ignite txIgniteNode = G.ignite(txNode.id());
    GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            IgniteCache<Integer, String> cache = txIgniteNode.cache(DEFAULT_CACHE_NAME);
            assertNotNull(cache);
            TransactionProxyImpl tx = (TransactionProxyImpl) txIgniteNode.transactions().txStart();
            GridNearTxLocal txEx = tx.tx();
            assertTrue(txEx.optimistic());
            cache.putAll(map);
            try {
                txEx.prepareNearTxLocal().get(3, TimeUnit.SECONDS);
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                info("Failed to wait for prepare future completion: " + partial);
            }
            return null;
        }
    }).get();
    info("Stopping originating node " + txNode);
    G.stop(G.ignite(txNode.id()).name(), true);
    info("Stopped grid, waiting for transactions to complete.");
    boolean txFinished = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            for (IgniteKernal g : grids) {
                GridCacheSharedContext<Object, Object> ctx = g.context().cache().context();
                int txNum = ctx.tm().idMapSize();
                if (txNum != 0)
                    return false;
            }
            return true;
        }
    }, 10000);
    assertTrue(txFinished);
    info("Transactions finished.");
    for (Map.Entry<Integer, Collection<ClusterNode>> e : nodeMap.entrySet()) {
        final Integer key = e.getKey();
        final String val = map.get(key);
        assertFalse(e.getValue().isEmpty());
        for (ClusterNode node : e.getValue()) {
            compute(G.ignite(node.id()).cluster().forNode(node)).call(new IgniteCallable<Void>() {

                /**
                 */
                @IgniteInstanceResource
                private Ignite ignite;

                @Override
                public Void call() throws Exception {
                    IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
                    assertNotNull(cache);
                    assertEquals(partial ? initVal : val, cache.localPeek(key));
                    return null;
                }
            });
        }
    }
    for (Map.Entry<Integer, String> e : map.entrySet()) {
        for (Ignite g : G.allGrids()) {
            UUID locNodeId = g.cluster().localNode().id();
            assertEquals("Check failed for node: " + locNodeId, partial ? initVal : e.getValue(), g.cache(DEFAULT_CACHE_NAME).get(e.getKey()));
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) TransactionProxyImpl(org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl)

Example 29 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.

the class GridServiceDeploymentCompoundFutureSelfTest method testWaitForCompletionOnFailingFuture.

/**
 * @throws Exception If failed.
 */
@Test
public void testWaitForCompletionOnFailingFuture() throws Exception {
    GridServiceDeploymentCompoundFuture<IgniteUuid> compFut = new GridServiceDeploymentCompoundFuture<>();
    int failingFutsNum = 2;
    int completingFutsNum = 5;
    Collection<GridServiceDeploymentFuture> failingFuts = new ArrayList<>(completingFutsNum);
    for (int i = 0; i < failingFutsNum; i++) {
        ServiceConfiguration failingCfg = config("Failed-" + i);
        GridServiceDeploymentFuture<IgniteUuid> failingFut = new GridServiceDeploymentFuture<>(failingCfg, IgniteUuid.randomUuid());
        failingFuts.add(failingFut);
        compFut.add(failingFut);
    }
    List<GridFutureAdapter<Object>> futs = new ArrayList<>(completingFutsNum);
    for (int i = 0; i < completingFutsNum; i++) {
        GridServiceDeploymentFuture<IgniteUuid> fut = new GridServiceDeploymentFuture<>(config(String.valueOf(i)), IgniteUuid.randomUuid());
        futs.add(fut);
        compFut.add(fut);
    }
    compFut.markInitialized();
    List<Exception> causes = new ArrayList<>();
    for (GridServiceDeploymentFuture fut : failingFuts) {
        Exception cause = new Exception("Test error");
        causes.add(cause);
        fut.onDone(cause);
    }
    try {
        compFut.get(100);
        fail("Should never reach here.");
    } catch (IgniteFutureTimeoutCheckedException e) {
        log.info("Expected exception: " + e.getMessage());
    }
    for (GridFutureAdapter<Object> fut : futs) fut.onDone();
    try {
        compFut.get();
        fail("Should never reach here.");
    } catch (IgniteCheckedException ce) {
        log.info("Expected exception: " + ce.getMessage());
        IgniteException e = U.convertException(ce);
        assertTrue(e instanceof ServiceDeploymentException);
        Throwable[] supErrs = e.getSuppressed();
        assertEquals(failingFutsNum, supErrs.length);
        for (int i = 0; i < failingFutsNum; i++) assertEquals(causes.get(i), supErrs[i].getCause());
    }
}
Also used : ArrayList(java.util.ArrayList) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteException(org.apache.ignite.IgniteException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 30 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project gridgain by gridgain.

the class PageMemoryImplTest method testCheckpointBufferCantOverflowWithThrottlingMixedLoad.

/**
 * @throws Exception If failed.
 */
private void testCheckpointBufferCantOverflowWithThrottlingMixedLoad(PageMemoryImpl.ThrottlingPolicy plc) throws Exception {
    PageMemoryImpl memory = createPageMemory(plc, null);
    List<FullPageId> pages = new ArrayList<>();
    for (int i = 0; i < (MAX_SIZE - 10) * MB / PAGE_SIZE / 2; i++) {
        long pageId = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
        FullPageId fullPageId = new FullPageId(pageId, 1);
        pages.add(fullPageId);
        acquireAndReleaseWriteLock(memory, fullPageId);
    }
    memory.beginCheckpoint(new GridFinishedFuture());
    CheckpointMetricsTracker mockTracker = Mockito.mock(CheckpointMetricsTracker.class);
    for (FullPageId checkpointPage : pages) memory.checkpointWritePage(checkpointPage, ByteBuffer.allocate(PAGE_SIZE), (fullPageId, buffer, tag) -> {
    // No-op.
    }, mockTracker);
    memory.finishCheckpoint();
    for (int i = (int) ((MAX_SIZE - 10) * MB / PAGE_SIZE / 2); i < (MAX_SIZE - 20) * MB / PAGE_SIZE; i++) {
        long pageId = memory.allocatePage(1, INDEX_PARTITION, FLAG_IDX);
        FullPageId fullPageId = new FullPageId(pageId, 1);
        pages.add(fullPageId);
        acquireAndReleaseWriteLock(memory, fullPageId);
    }
    memory.beginCheckpoint(new GridFinishedFuture());
    // Mix pages in checkpoint with clean pages
    Collections.shuffle(pages);
    AtomicBoolean stop = new AtomicBoolean(false);
    try {
        GridTestUtils.runAsync(() -> {
            for (FullPageId page : pages) {
                if (// Mark dirty 50% of pages
                ThreadLocalRandom.current().nextDouble() < 0.5)
                    try {
                        acquireAndReleaseWriteLock(memory, page);
                        if (stop.get())
                            break;
                    } catch (IgniteCheckedException e) {
                        log.error("runAsync ended with exception", e);
                        fail();
                    }
            }
        }).get(5_000);
    } catch (IgniteFutureTimeoutCheckedException ex) {
    // Expected.
    } finally {
        stop.set(true);
    }
    memory.finishCheckpoint();
    LongAdderMetric totalThrottlingTime = U.field(memory.metrics(), "totalThrottlingTime");
    assertNotNull(totalThrottlingTime);
    assertTrue(totalThrottlingTime.value() > 0);
}
Also used : PageStore(org.apache.ignite.internal.pagemem.store.PageStore) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) ByteBuffer(java.nio.ByteBuffer) NoopMetricExporterSpi(org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi) GridSystemViewManager(org.apache.ignite.internal.managers.systemview.GridSystemViewManager) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IgnitePluginProcessor(org.apache.ignite.internal.processors.plugin.IgnitePluginProcessor) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) Map(java.util.Map) PageUtils(org.apache.ignite.internal.pagemem.PageUtils) GridTestLog4jLogger(org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger) FailureProcessor(org.apache.ignite.internal.processors.failure.FailureProcessor) CheckpointProgressImpl(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgressImpl) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteOutClosure(org.apache.ignite.lang.IgniteOutClosure) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) DirectMemoryProvider(org.apache.ignite.internal.mem.DirectMemoryProvider) GridInternalSubscriptionProcessor(org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) INDEX_PARTITION(org.apache.ignite.internal.pagemem.PageIdAllocator.INDEX_PARTITION) ByteOrder(java.nio.ByteOrder) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgnitePageStoreManager(org.apache.ignite.internal.pagemem.store.IgnitePageStoreManager) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteOutOfMemoryException(org.apache.ignite.internal.mem.IgniteOutOfMemoryException) JmxSystemViewExporterSpi(org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi) FLAG_IDX(org.apache.ignite.internal.pagemem.PageIdAllocator.FLAG_IDX) CHECKPOINT_POOL_OVERFLOW_ERROR_MSG(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryImpl.CHECKPOINT_POOL_OVERFLOW_ERROR_MSG) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) GridMultiCollectionWrapper(org.apache.ignite.internal.util.GridMultiCollectionWrapper) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CheckpointProgress(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointProgress) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) GridEncryptionManager(org.apache.ignite.internal.managers.encryption.GridEncryptionManager) NoOpFailureHandler(org.apache.ignite.failure.NoOpFailureHandler) NoopEncryptionSpi(org.apache.ignite.spi.encryption.noop.NoopEncryptionSpi) Test(org.junit.Test) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) Mockito(org.mockito.Mockito) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) PluginProvider(org.apache.ignite.plugin.PluginProvider) DummyPageIO(org.apache.ignite.internal.processors.cache.persistence.DummyPageIO) PageStoreWriter(org.apache.ignite.internal.processors.cache.persistence.PageStoreWriter) GridMetricManager(org.apache.ignite.internal.processors.metric.GridMetricManager) GridInClosure3X(org.apache.ignite.internal.util.lang.GridInClosure3X) GridEventStorageManager(org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager) Collections(java.util.Collections) ArrayList(java.util.ArrayList) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Aggregations

IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)74 Test (org.junit.Test)38 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)34 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)31 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)29 Ignite (org.apache.ignite.Ignite)18 IgniteEx (org.apache.ignite.internal.IgniteEx)17 IgniteException (org.apache.ignite.IgniteException)16 ArrayList (java.util.ArrayList)14 Transaction (org.apache.ignite.transactions.Transaction)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 Map (java.util.Map)10 CacheException (javax.cache.CacheException)10 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)8 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)7