Search in sources :

Example 1 with GridDhtPartitionsStateValidator

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator in project ignite by apache.

the class GridCachePartitionsStateValidatorSelfTest method testPartitionCacheSizesValidation.

/**
 * Test partition cache sizes validation.
 */
@Test
public void testPartitionCacheSizesValidation() {
    UUID remoteNode = UUID.randomUUID();
    UUID ignoreNode = UUID.randomUUID();
    // For partitions 0 and 2 we have inconsistent update counters.
    Map<Integer, T2<Long, Long>> updateCountersMap = new HashMap<>();
    updateCountersMap.put(0, new T2<>(2L, 2L));
    updateCountersMap.put(1, new T2<>(2L, 2L));
    updateCountersMap.put(2, new T2<>(5L, 5L));
    // For partitions 0 and 2 we have inconsistent cache sizes.
    Map<Integer, Long> cacheSizesMap = new HashMap<>();
    cacheSizesMap.put(0, 2L);
    cacheSizesMap.put(1, 2L);
    cacheSizesMap.put(2, 2L);
    // Form single messages map.
    Map<UUID, GridDhtPartitionsSingleMessage> messages = new HashMap<>();
    messages.put(remoteNode, from(updateCountersMap, cacheSizesMap));
    messages.put(ignoreNode, from(updateCountersMap, cacheSizesMap));
    GridDhtPartitionsStateValidator validator = new GridDhtPartitionsStateValidator(cctxMock);
    // (partId, (nodeId, cacheSize))
    Map<Integer, Map<UUID, Long>> result = validator.validatePartitionsSizes(topologyMock, messages, Sets.newHashSet(ignoreNode));
    // Check that validation result contains all necessary information.
    Assert.assertEquals(2, result.size());
    Assert.assertTrue(result.containsKey(0));
    Assert.assertTrue(result.containsKey(2));
    Assert.assertTrue(result.get(0).get(localNodeId) == 1L);
    Assert.assertTrue(result.get(0).get(remoteNode) == 2L);
    Assert.assertTrue(result.get(2).get(localNodeId) == 3L);
    Assert.assertTrue(result.get(2).get(remoteNode) == 2L);
}
Also used : HashMap(java.util.HashMap) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsStateValidator(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) T2(org.apache.ignite.internal.util.typedef.T2) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with GridDhtPartitionsStateValidator

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator in project ignite by apache.

the class GridCachePartitionsStateValidationTest method testPartitionCountersConsistencyOnExchange.

/**
 * Test that all nodes send correct {@link GridDhtPartitionsSingleMessage} with consistent update counters.
 *
 * @throws Exception If failed.
 */
@Test
public void testPartitionCountersConsistencyOnExchange() throws Exception {
    // Reopen https://issues.apache.org/jira/browse/IGNITE-10766 if starts failing with forced MVCC
    IgniteEx ignite = startGrids(4);
    ignite.cluster().active(true);
    awaitPartitionMapExchange();
    final String atomicCacheName = "atomic-cache";
    final String txCacheName = "tx-cache";
    Ignite client = startClientGrid(4);
    IgniteCache atomicCache = client.getOrCreateCache(new CacheConfiguration<>(atomicCacheName).setAtomicityMode(CacheAtomicityMode.ATOMIC).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setBackups(2).setAffinity(new RendezvousAffinityFunction(false, 32)));
    IgniteCache txCache = client.getOrCreateCache(new CacheConfiguration<>(txCacheName).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC).setBackups(2).setAffinity(new RendezvousAffinityFunction(false, 32)));
    for (int it = 0; it < 10; it++) {
        SingleMessageInterceptorCommunicationSpi spi = (SingleMessageInterceptorCommunicationSpi) ignite.configuration().getCommunicationSpi();
        spi.clear();
        // Stop load future.
        final AtomicBoolean stop = new AtomicBoolean();
        // Run atomic load.
        IgniteInternalFuture atomicLoadFuture = GridTestUtils.runMultiThreadedAsync(() -> {
            int k = 0;
            while (!stop.get()) {
                k++;
                try {
                    atomicCache.put(k, k);
                } catch (Exception ignored) {
                }
            }
        }, 1, "atomic-load");
        // Run tx load.
        IgniteInternalFuture txLoadFuture = GridTestUtils.runMultiThreadedAsync(() -> {
            final int txOps = 5;
            while (!stop.get()) {
                List<Integer> randomKeys = Stream.generate(() -> ThreadLocalRandom.current().nextInt(5)).limit(txOps).sorted().collect(Collectors.toList());
                try (Transaction tx = ignite.transactions().txStart(OPTIMISTIC, READ_COMMITTED)) {
                    for (Integer key : randomKeys) txCache.put(key, key);
                    tx.commit();
                } catch (Exception ignored) {
                }
            }
        }, 4, "tx-load");
        // Wait for some data.
        Thread.sleep(1000);
        // Prevent sending full message.
        spi.blockFullMessage();
        // Trigger exchange.
        IgniteInternalFuture nodeStopFuture = GridTestUtils.runAsync(() -> stopGrid(3));
        try {
            spi.waitUntilAllSingleMessagesAreSent();
            List<GridDhtPartitionsSingleMessage> interceptedMessages = spi.getMessages();
            // Associate each message with existing node UUID.
            Map<UUID, GridDhtPartitionsSingleMessage> messagesMap = new HashMap<>();
            for (int i = 0; i < interceptedMessages.size(); i++) messagesMap.put(grid(i + 1).context().localNodeId(), interceptedMessages.get(i));
            GridDhtPartitionsStateValidator validator = new GridDhtPartitionsStateValidator(ignite.context().cache().context());
            // Validate partition update counters. If counters are not consistent, exception will be thrown.
            validator.validatePartitionsUpdateCounters(ignite.cachex(atomicCacheName).context().topology(), messagesMap, Collections.emptySet());
            validator.validatePartitionsUpdateCounters(ignite.cachex(txCacheName).context().topology(), messagesMap, Collections.emptySet());
        } finally {
            // Stop load and resume exchange.
            spi.unblockFullMessage();
            stop.set(true);
            atomicLoadFuture.get();
            txLoadFuture.get();
            nodeStopFuture.get();
        }
        // Return grid to initial state.
        startGrid(3);
        awaitPartitionMapExchange();
    }
}
Also used : HashMap(java.util.HashMap) IgniteCache(org.apache.ignite.IgniteCache) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsStateValidator(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) UUID(java.util.UUID) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with GridDhtPartitionsStateValidator

use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator in project ignite by apache.

the class GridCachePartitionsStateValidatorSelfTest method testPartitionCountersValidation.

/**
 * Test partition update counters validation.
 */
@Test
public void testPartitionCountersValidation() {
    UUID remoteNode = UUID.randomUUID();
    UUID ignoreNode = UUID.randomUUID();
    // For partitions 0 and 2 we have inconsistent update counters.
    Map<Integer, T2<Long, Long>> updateCountersMap = new HashMap<>();
    updateCountersMap.put(0, new T2<>(2L, 2L));
    updateCountersMap.put(1, new T2<>(2L, 2L));
    updateCountersMap.put(2, new T2<>(5L, 5L));
    // For partitions 0 and 2 we have inconsistent cache sizes.
    Map<Integer, Long> cacheSizesMap = new HashMap<>();
    cacheSizesMap.put(0, 2L);
    cacheSizesMap.put(1, 2L);
    cacheSizesMap.put(2, 2L);
    // Form single messages map.
    Map<UUID, GridDhtPartitionsSingleMessage> messages = new HashMap<>();
    messages.put(remoteNode, from(updateCountersMap, cacheSizesMap));
    messages.put(ignoreNode, from(updateCountersMap, cacheSizesMap));
    GridDhtPartitionsStateValidator validator = new GridDhtPartitionsStateValidator(cctxMock);
    // (partId, (nodeId, updateCounter))
    Map<Integer, Map<UUID, Long>> result = validator.validatePartitionsUpdateCounters(topologyMock, messages, Sets.newHashSet(ignoreNode));
    // Check that validation result contains all necessary information.
    Assert.assertEquals(2, result.size());
    Assert.assertTrue(result.containsKey(0));
    Assert.assertTrue(result.containsKey(2));
    Assert.assertTrue(result.get(0).get(localNodeId) == 1L);
    Assert.assertTrue(result.get(0).get(remoteNode) == 2L);
    Assert.assertTrue(result.get(2).get(localNodeId) == 3L);
    Assert.assertTrue(result.get(2).get(remoteNode) == 5L);
}
Also used : HashMap(java.util.HashMap) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) GridDhtPartitionsStateValidator(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map) T2(org.apache.ignite.internal.util.typedef.T2) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)3 UUID (java.util.UUID)3 GridDhtPartitionsSingleMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage)3 GridDhtPartitionsStateValidator (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionsStateValidator)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 Test (org.junit.Test)3 Map (java.util.Map)2 T2 (org.apache.ignite.internal.util.typedef.T2)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)1 Transaction (org.apache.ignite.transactions.Transaction)1