Search in sources :

Example 1 with GridDhtPartitionsSingleMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.

the class GridCachePartitionExchangeManager method createPartitionsSingleMessage.

/**
     * @param targetNode Target node.
     * @param exchangeId ID.
     * @param clientOnlyExchange Client exchange flag.
     * @param sndCounters {@code True} if need send partition update counters.
     * @return Message.
     */
public GridDhtPartitionsSingleMessage createPartitionsSingleMessage(ClusterNode targetNode, @Nullable GridDhtPartitionExchangeId exchangeId, boolean clientOnlyExchange, boolean sndCounters) {
    GridDhtPartitionsSingleMessage m = new GridDhtPartitionsSingleMessage(exchangeId, clientOnlyExchange, cctx.versions().last(), true);
    Map<Object, T2<Integer, Map<Integer, GridDhtPartitionState>>> dupData = new HashMap<>();
    for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
        if (!cacheCtx.isLocal()) {
            GridDhtPartitionMap locMap = cacheCtx.topology().localPartitionMap();
            addPartitionMap(m, dupData, true, cacheCtx.cacheId(), locMap, cacheCtx.affinity().affinityCache().similarAffinityKey());
            if (sndCounters)
                m.partitionUpdateCounters(cacheCtx.cacheId(), cacheCtx.topology().updateCounters(true));
        }
    }
    for (GridClientPartitionTopology top : clientTops.values()) {
        if (m.partitions() != null && m.partitions().containsKey(top.cacheId()))
            continue;
        GridDhtPartitionMap locMap = top.localPartitionMap();
        addPartitionMap(m, dupData, true, top.cacheId(), locMap, top.similarAffinityKey());
        if (sndCounters)
            m.partitionUpdateCounters(top.cacheId(), top.updateCounters(true));
    }
    return m;
}
Also used : GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) HashMap(java.util.HashMap) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) T2(org.apache.ignite.internal.util.typedef.T2) GridClientPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.GridClientPartitionTopology)

Example 2 with GridDhtPartitionsSingleMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.

the class IgniteClusterSnapshotRestoreSelfTest method checkNodeLeftOnExchangeFinish.

/**
 * @param crdStop {@code True} to stop coordinator node.
 * @param expCls Expected exception class.
 * @param expMsg Expected exception message.
 * @throws Exception If failed.
 */
private void checkNodeLeftOnExchangeFinish(boolean crdStop, Class<? extends Throwable> expCls, String expMsg) throws Exception {
    startGridsWithSnapshot(3, CACHE_KEYS_RANGE, true);
    TestRecordingCommunicationSpi node1spi = TestRecordingCommunicationSpi.spi(grid(1));
    TestRecordingCommunicationSpi node2spi = TestRecordingCommunicationSpi.spi(grid(2));
    node1spi.blockMessages((node, msg) -> msg instanceof GridDhtPartitionsSingleMessage);
    node2spi.blockMessages((node, msg) -> msg instanceof GridDhtPartitionsSingleMessage);
    IgniteFuture<Void> fut = grid(1).snapshot().restoreSnapshot(SNAPSHOT_NAME, Collections.singleton(DEFAULT_CACHE_NAME));
    node1spi.waitForBlocked();
    node2spi.waitForBlocked();
    stopGrid(crdStop ? 0 : 2, true);
    node1spi.stopBlock();
    if (crdStop)
        node2spi.stopBlock();
    GridTestUtils.assertThrowsAnyCause(log, () -> fut.get(TIMEOUT), expCls, expMsg);
    awaitPartitionMapExchange();
    ensureCacheAbsent(dfltCacheCfg);
}
Also used : GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi)

Example 3 with GridDhtPartitionsSingleMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.

the class TxPartitionCounterStateConsistencyTest method testLateAffinityChangeDuringExchange.

/**
 * Tests a scenario when stale partition state message can trigger spurious late affinity switching followed by
 * possible primary mapping to moving partition.
 */
@Test
public void testLateAffinityChangeDuringExchange() throws Exception {
    backups = 2;
    Ignite crd = startGridsMultiThreaded(3);
    crd.cluster().active(true);
    awaitPartitionMapExchange();
    for (int p = 0; p < PARTS_CNT; p++) crd.cache(DEFAULT_CACHE_NAME).put(p, p);
    forceCheckpoint();
    int key = primaryKey(grid(2).cache(DEFAULT_CACHE_NAME));
    TestRecordingCommunicationSpi.spi(grid(1)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode clusterNode, Message msg) {
            if (msg instanceof GridDhtPartitionsSingleMessage) {
                GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage) msg;
                return msg0.exchangeId() == null && msg0.partitions().get(CU.cacheId(DEFAULT_CACHE_NAME)).topologyVersion().equals(new AffinityTopologyVersion(4, 0));
            }
            return false;
        }
    });
    stopGrid(2);
    // Fill a queue with a lot of messages.
    for (int i = 0; i < 1000; i++) grid(1).context().cache().context().exchange().refreshPartitions();
    TestRecordingCommunicationSpi.spi(grid(1)).waitForBlocked(1000);
    // Create counter delta for triggering counter rebalance.
    for (int p = 0; p < PARTS_CNT; p++) crd.cache(DEFAULT_CACHE_NAME).put(p, p + 1);
    IgniteConfiguration cfg2 = getConfiguration(getTestIgniteInstanceName(2));
    TestRecordingCommunicationSpi spi2 = (TestRecordingCommunicationSpi) cfg2.getCommunicationSpi();
    spi2.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode clusterNode, Message msg) {
            if (msg instanceof GridDhtPartitionDemandMessage)
                // Prevent any rebalancing to avoid switching partitions to owning.
                return true;
            if (msg instanceof GridDhtPartitionsSingleMessage) {
                GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage) msg;
                return msg0.exchangeId() != null && msg0.exchangeId().topologyVersion().equals(new AffinityTopologyVersion(5, 0));
            }
            return false;
        }
    });
    GridTestUtils.runAsync(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            startGrid(cfg2);
            return null;
        }
    });
    // Delay last single message. It should trigger PME for version 5,0
    spi2.waitForBlocked();
    // Start processing single messages.
    TestRecordingCommunicationSpi.spi(grid(1)).stopBlock();
    // Allow PME to finish.
    spi2.stopBlock();
    grid(0).context().cache().context().exchange().affinityReadyFuture(new AffinityTopologyVersion(5, 1)).get();
    // Primary node for a key will be stopped by FH without a fix.
    grid(0).cache(DEFAULT_CACHE_NAME).put(key, -1);
    for (int i = 0; i < 1000; i++) assertEquals(-1, grid(2).cache(DEFAULT_CACHE_NAME).get(key));
    assertPartitionsSame(idleVerify(crd, DEFAULT_CACHE_NAME));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) 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) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) CacheInvalidStateException(org.apache.ignite.internal.processors.cache.CacheInvalidStateException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignite(org.apache.ignite.Ignite) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) Test(org.junit.Test)

Example 4 with GridDhtPartitionsSingleMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.

the class IgniteWalHistoryReservationsTest method testNodeLeftDuringExchange.

/**
 * @throws Exception If failed.
 */
@Test
public void testNodeLeftDuringExchange() throws Exception {
    MvccFeatureChecker.skipIfNotSupported(MvccFeatureChecker.Feature.ENTRY_LOCK);
    System.setProperty(IGNITE_PDS_WAL_REBALANCE_THRESHOLD, "0");
    final int entryCnt = 10_000;
    final int initGridCnt = 4;
    final Ignite ig0 = startGrids(initGridCnt);
    ig0.cluster().active(true);
    IgniteCache<Object, Object> cache = ig0.cache("cache1");
    for (int k = 0; k < entryCnt; k++) cache.put(k, k);
    forceCheckpoint();
    TestRecordingCommunicationSpi spi = new TestRecordingCommunicationSpi();
    spi.blockMessages((node, msg) -> {
        if (msg instanceof GridDhtPartitionsSingleMessage) {
            GridDhtPartitionsSingleMessage sm = (GridDhtPartitionsSingleMessage) msg;
            return sm.exchangeId() != null;
        }
        return false;
    });
    GridTestUtils.runAsync(new Runnable() {

        @Override
        public void run() {
            try {
                IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(initGridCnt));
                cfg.setCommunicationSpi(spi);
                startGrid(optimize(cfg));
            } catch (Exception e) {
                fail(e.getMessage());
            }
        }
    });
    spi.waitForBlocked();
    boolean reserved = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            for (int g = 0; g < initGridCnt; g++) {
                IgniteEx ig = grid(g);
                if (isReserveListEmpty(ig))
                    return false;
            }
            return true;
        }
    }, 10_000);
    assert reserved;
    spi.stopBlock();
    stopGrid(getTestIgniteInstanceName(initGridCnt - 1), true, false);
    boolean released = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            for (int g = 0; g < initGridCnt - 1; g++) {
                IgniteEx ig = grid(g);
                if (!isReserveListEmpty(ig))
                    return false;
            }
            return true;
        }
    }, 10_000);
    assert released;
    awaitPartitionMapExchange();
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with GridDhtPartitionsSingleMessage

use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage in project ignite by apache.

the class CacheMvccPartitionedSqlTxQueriesWithReducerTest method testQueryUpdateOnUnstableTopologyDoesNotCauseDeadlock.

/**
 * @throws Exception If failed.
 */
@Test
public void testQueryUpdateOnUnstableTopologyDoesNotCauseDeadlock() throws Exception {
    ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 2, DFLT_PARTITION_COUNT).setIndexedTypes(Integer.class, CacheMvccSqlTxQueriesAbstractTest.MvccTestSqlIndexValue.class);
    testSpi = true;
    Ignite updateNode = startGrids(3);
    CountDownLatch latch = new CountDownLatch(1);
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(grid(1));
    spi.blockMessages((node, msg) -> {
        if (msg instanceof GridDhtPartitionsSingleMessage) {
            latch.countDown();
            return true;
        }
        return false;
    });
    CompletableFuture.runAsync(() -> stopGrid(2));
    assertTrue(latch.await(TX_TIMEOUT, TimeUnit.MILLISECONDS));
    CompletableFuture<Void> queryFut = CompletableFuture.runAsync(() -> updateNode.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery("INSERT INTO MvccTestSqlIndexValue (_key, idxVal1) VALUES (1,1),(2,2),(3,3)")).getAll());
    Thread.sleep(300);
    spi.stopBlock();
    try {
        queryFut.get(TX_TIMEOUT, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        assertTrue(X.hasCause(e, ClusterTopologyException.class));
    }
}
Also used : GridDhtPartitionsSingleMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) Test(org.junit.Test)

Aggregations

GridDhtPartitionsSingleMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage)29 Test (org.junit.Test)16 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)15 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)11 Ignite (org.apache.ignite.Ignite)10 IgniteEx (org.apache.ignite.internal.IgniteEx)10 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)10 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 HashMap (java.util.HashMap)8 Message (org.apache.ignite.plugin.extensions.communication.Message)8 UUID (java.util.UUID)7 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 GridDhtPartitionDemandMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)5 GridDhtPartitionsExchangeFuture (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture)5 GridDhtPartitionsFullMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage)5 T2 (org.apache.ignite.internal.util.typedef.T2)5 Map (java.util.Map)4