Search in sources :

Example 41 with IgniteInternalFuture

use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.

the class CacheLateAffinityAssignmentTest method doTestCoordLeaveBlockedFinishExchangeMessage.

/**
 * Coordinator leaves without sending all {@link GridDhtPartitionsFullMessage} messages,
 * exchange must be completed.
 *
 * @param cnt Number of nodes.
 * @param stopId Node to stop.
 * @param lastClient {@code True} if last started node is client.
 * @param blockedIds Nodes not receiving exchange finish message.
 * @throws Exception If failed.
 */
private void doTestCoordLeaveBlockedFinishExchangeMessage(int cnt, int stopId, boolean lastClient, int... blockedIds) throws Exception {
    int ord = 1;
    for (int i = 0; i < cnt; i++) {
        if (i == cnt - 1 && lastClient)
            startClient(ord - 1, ord++);
        else
            startServer(ord - 1, ord++);
    }
    awaitPartitionMapExchange();
    TestRecordingCommunicationSpi spi0 = TestRecordingCommunicationSpi.spi(grid(0));
    final Set<String> blocked = new HashSet<>();
    for (int id : blockedIds) {
        String name = grid(id).name();
        blocked.add(name);
    }
    spi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode node, Message msg) {
            return blocked.contains(node.attribute(IgniteNodeAttributes.ATTR_IGNITE_INSTANCE_NAME)) && (msg instanceof GridDhtPartitionsFullMessage) && (((GridDhtPartitionsFullMessage) msg).exchangeId() != null);
        }
    });
    checkAffinity(cnt, topVer(ord - 1, 1), true);
    stopNode(stopId, ord);
    AffinityTopologyVersion topVer = topVer(ord, 0);
    List<IgniteInternalFuture<?>> futs = new ArrayList<>(cnt);
    List<Ignite> grids = G.allGrids();
    for (Ignite ignite : grids) futs.add(affinityReadyFuture(topVer, ignite));
    assertEquals(futs.size(), grids.size());
    for (int i = 0; i < futs.size(); i++) {
        final IgniteInternalFuture<?> fut = futs.get(i);
        Ignite ignite = grids.get(i);
        if (!blocked.contains(ignite.name())) {
            GridTestUtils.waitForCondition(new GridAbsPredicate() {

                @Override
                public boolean apply() {
                    return fut.isDone();
                }
            }, 5000);
            assertTrue(ignite.name(), fut.isDone());
        } else
            assertFalse(ignite.name(), fut.isDone());
    }
    ord++;
    // Triggers exchange completion from new coordinator.
    stopNode(0, ord);
    checkAffinity(cnt - 2, topVer(ord - 1, 0), true, false);
    checkAffinity(cnt - 2, topVer(ord, 0), true);
    awaitPartitionMapExchange();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) CacheAffinityChangeMessage(org.apache.ignite.internal.processors.cache.CacheAffinityChangeMessage) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) Ignite(org.apache.ignite.Ignite) HashSet(java.util.HashSet)

Example 42 with IgniteInternalFuture

use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.

the class CacheLateAffinityAssignmentTest method testNodeLeaveExchangeWaitAffinityMessage.

/**
 * @throws Exception If failed.
 */
public void testNodeLeaveExchangeWaitAffinityMessage() throws Exception {
    System.setProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1, "true");
    try {
        Ignite ignite0 = startServer(0, 1);
        startServer(1, 2);
        startServer(2, 3);
        checkAffinity(3, topVer(3, 1), true);
        checkOrderCounters(3, topVer(3, 1));
        startClient(3, 4);
        checkAffinity(4, topVer(4, 0), true);
        TestTcpDiscoverySpi discoSpi = (TestTcpDiscoverySpi) ignite0.configuration().getDiscoverySpi();
        discoSpi.blockCustomEvent();
        stopGrid(1);
        List<IgniteInternalFuture<?>> futs = affFutures(3, topVer(5, 0));
        U.sleep(1000);
        for (IgniteInternalFuture<?> fut : futs) assertFalse(fut.isDone());
        discoSpi.stopBlock();
        checkAffinity(3, topVer(5, 0), false);
        checkOrderCounters(3, topVer(5, 0));
    } finally {
        System.clearProperty(IGNITE_EXCHANGE_COMPATIBILITY_VER_1);
    }
}
Also used : Ignite(org.apache.ignite.Ignite) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Example 43 with IgniteInternalFuture

use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.

the class CacheLockReleaseNodeLeaveTest method testLockTopologyChange.

/**
 * @throws Exception If failed.
 */
public void testLockTopologyChange() throws Exception {
    final int nodeCnt = 5;
    int threadCnt = 8;
    final int keys = 100;
    try {
        final AtomicBoolean stop = new AtomicBoolean(false);
        Queue<IgniteInternalFuture<Long>> q = new ArrayDeque<>(nodeCnt);
        for (int i = 0; i < nodeCnt; i++) {
            final Ignite ignite = startGrid(i);
            IgniteInternalFuture<Long> f = GridTestUtils.runMultiThreadedAsync(new Runnable() {

                @Override
                public void run() {
                    while (!Thread.currentThread().isInterrupted() && !stop.get()) {
                        IgniteCache<Integer, Integer> cache = ignite.cache(REPLICATED_TEST_CACHE);
                        for (int i = 0; i < keys; i++) {
                            Lock lock = cache.lock(i);
                            lock.lock();
                            cache.put(i, i);
                            lock.unlock();
                        }
                    }
                }
            }, threadCnt, "test-lock-thread");
            q.add(f);
            U.sleep(1_000);
        }
        stop.set(true);
        IgniteInternalFuture<Long> f;
        while ((f = q.poll()) != null) f.get(2_000);
    } finally {
        stopAllGrids();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ArrayDeque(java.util.ArrayDeque) Lock(java.util.concurrent.locks.Lock)

Example 44 with IgniteInternalFuture

use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.

the class IgniteCacheCreatePutMultiNodeSelfTest method testStartNodes.

/**
 * @throws Exception If failed.
 */
public void testStartNodes() throws Exception {
    try {
        Collection<IgniteInternalFuture<?>> futs = new ArrayList<>(GRID_CNT);
        int scale = 3;
        final CyclicBarrier barrier = new CyclicBarrier(GRID_CNT * scale);
        final AtomicReferenceArray<Exception> err = new AtomicReferenceArray<>(GRID_CNT * scale);
        for (int i = 0; i < GRID_CNT * scale; i++) {
            if (i < GRID_CNT)
                startGrid(i);
            final int idx = i;
            IgniteInternalFuture<Void> fut = GridTestUtils.runAsync(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    Ignite ignite = ignite(idx % GRID_CNT);
                    try {
                        for (int k = 0; k < 50; k++) {
                            barrier.await();
                            String cacheName = "cache-" + k;
                            IgniteCache<Integer, Integer> cache = getCache(ignite, cacheName);
                            for (int i = 0; i < 100; i++) cache.getAndPut(i, i);
                            barrier.await();
                            ignite.destroyCache(cacheName);
                        }
                    } catch (Exception e) {
                        err.set(idx, e);
                    }
                    return null;
                }
            });
            futs.add(fut);
        }
        for (IgniteInternalFuture<?> fut : futs) fut.get(getTestTimeout());
        info("Errors: " + err);
        for (int i = 0; i < err.length(); i++) {
            Exception ex = err.get(i);
            if (ex != null)
                throw ex;
        }
    } finally {
        stopAllGrids();
    }
}
Also used : ArrayList(java.util.ArrayList) IgniteCache(org.apache.ignite.IgniteCache) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) Ignite(org.apache.ignite.Ignite)

Example 45 with IgniteInternalFuture

use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.

the class IgniteTxMultiThreadedAbstractTest method testOptimisticSerializableConsistency.

/**
 * @throws Exception If failed.
 */
public void testOptimisticSerializableConsistency() throws Exception {
    final IgniteCache<Integer, Long> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    final int THREADS = 3;
    final int ITERATIONS = 100;
    for (int key0 = 100_000; key0 < 100_000 + 20; key0++) {
        final int key = key0;
        cache.put(key, 0L);
        List<IgniteInternalFuture<Collection<Long>>> futs = new ArrayList<>(THREADS);
        for (int i = 0; i < THREADS; i++) {
            futs.add(GridTestUtils.runAsync(new Callable<Collection<Long>>() {

                @Override
                public Collection<Long> call() throws Exception {
                    Collection<Long> res = new ArrayList<>();
                    for (int i = 0; i < ITERATIONS; i++) {
                        while (true) {
                            try (Transaction tx = grid(0).transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
                                long val = cache.get(key);
                                cache.put(key, val + 1);
                                tx.commit();
                                assertTrue(res.add(val + 1));
                                break;
                            } catch (TransactionOptimisticException ignored) {
                            // Retry.
                            }
                        }
                    }
                    return res;
                }
            }));
        }
        long total = 0;
        List<Collection<Long>> cols = new ArrayList<>(THREADS);
        for (IgniteInternalFuture<Collection<Long>> fut : futs) {
            Collection<Long> col = fut.get();
            assertEquals(ITERATIONS, col.size());
            total += col.size();
            cols.add(col);
        }
        log.info("Cache value: " + cache.get(key));
        Set<Long> duplicates = new HashSet<>();
        for (Collection<Long> col1 : cols) {
            for (Long val1 : col1) {
                for (Collection<Long> col2 : cols) {
                    if (col1 == col2)
                        continue;
                    for (Long val2 : col2) {
                        if (val1.equals(val2)) {
                            duplicates.add(val2);
                            break;
                        }
                    }
                }
            }
        }
        assertTrue("Found duplicated values: " + duplicates, duplicates.isEmpty());
        assertEquals((long) THREADS * ITERATIONS, total);
        // Try to update one more time to make sure cache is in consistent state.
        try (Transaction tx = grid(0).transactions().txStart(OPTIMISTIC, SERIALIZABLE)) {
            long val = cache.get(key);
            cache.put(key, val);
            tx.commit();
        }
        for (int i = 0; i < gridCount(); i++) assertEquals(total, grid(i).cache(DEFAULT_CACHE_NAME).get(key));
    }
}
Also used : TransactionOptimisticException(org.apache.ignite.transactions.TransactionOptimisticException) ArrayList(java.util.ArrayList) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable) Transaction(org.apache.ignite.transactions.Transaction) Collection(java.util.Collection) HashSet(java.util.HashSet)

Aggregations

IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)245 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)114 Ignite (org.apache.ignite.Ignite)71 ArrayList (java.util.ArrayList)52 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)46 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)46 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)43 IgniteException (org.apache.ignite.IgniteException)33 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)29 UUID (java.util.UUID)28 IgniteCache (org.apache.ignite.IgniteCache)28 ClusterNode (org.apache.ignite.cluster.ClusterNode)28 Callable (java.util.concurrent.Callable)27 HashMap (java.util.HashMap)25 Map (java.util.Map)25 CountDownLatch (java.util.concurrent.CountDownLatch)24 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)19 CacheException (javax.cache.CacheException)16 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)16 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)16