Search in sources :

Example 76 with GridDhtLocalPartition

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

the class CachePartitionLostAfterSupplierHasLeftTest method doTestPartitionLostWhileClearing.

/**
 * Test scenario: last supplier has left while a partition on demander is cleared before sending first demand request.
 *
 * @param cnt Nodes count.
 * @param mode Test mode: 0 - reset while clearing, 1 - restart while clearing and activate all, 2 - restart while
 *             clearing and activate in wrong order.
 * @throws Exception If failed.
 */
private void doTestPartitionLostWhileClearing(int cnt, int mode) throws Exception {
    IgniteEx crd = startGrids(cnt);
    crd.cluster().baselineAutoAdjustEnabled(false);
    crd.cluster().active(true);
    int partId = -1;
    int idx0 = 0;
    int idx1 = 1;
    for (int p = 0; p < PARTS_CNT; p++) {
        List<ClusterNode> nodes = new ArrayList<>(crd.affinity(DEFAULT_CACHE_NAME).mapPartitionToPrimaryAndBackups(p));
        if (grid(nodes.get(0)) == grid(idx0) && grid(nodes.get(1)) == grid(idx1)) {
            partId = p;
            break;
        }
    }
    assertTrue(partId >= 0);
    final int keysCnt = 10_010;
    List<Integer> keys = partitionKeys(grid(idx0).cache(DEFAULT_CACHE_NAME), partId, keysCnt, 0);
    load(grid(idx0), DEFAULT_CACHE_NAME, keys.subList(0, keysCnt - 10));
    stopGrid(idx1);
    load(grid(idx0), DEFAULT_CACHE_NAME, keys.subList(keysCnt - 10, keysCnt));
    TestRecordingCommunicationSpi.spi(grid(0)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {

        @Override
        public boolean apply(ClusterNode clusterNode, Message msg) {
            if (msg instanceof GridDhtPartitionSupplyMessage) {
                GridDhtPartitionSupplyMessage msg0 = (GridDhtPartitionSupplyMessage) msg;
                return msg0.groupId() == CU.cacheId(DEFAULT_CACHE_NAME);
            }
            return false;
        }
    });
    IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(idx1));
    ((TestRecordingCommunicationSpi) cfg.getCommunicationSpi()).blockMessages((node, msg) -> {
        if (msg instanceof GridDhtPartitionDemandMessage) {
            GridDhtPartitionDemandMessage demandMsg = (GridDhtPartitionDemandMessage) msg;
            return CU.cacheId(DEFAULT_CACHE_NAME) == demandMsg.groupId();
        }
        return false;
    });
    IgniteEx g1 = startGrid(optimize(cfg));
    // Stop supplier in the middle of rebalancing.
    stopGrid(idx0);
    TestRecordingCommunicationSpi.spi(g1).stopBlock();
    final GridDhtLocalPartition part = g1.cachex(DEFAULT_CACHE_NAME).context().topology().localPartition(partId);
    assertTrue("Unexpected partition state [p=" + partId + ", expected=" + GridDhtPartitionState.LOST + ", actual=" + part.state() + ']', GridTestUtils.waitForCondition(() -> part.state() == GridDhtPartitionState.LOST, 30_000));
    assertTrue(g1.cachex(DEFAULT_CACHE_NAME).lostPartitions().contains(partId));
    if (mode != 0) {
        stopAllGrids();
        if (mode == 1) {
            crd = startGrids(cnt);
            crd.cluster().active(true);
        } else if (mode == 2) {
            crd = startGrid(idx1);
            crd.cluster().active(true);
            startGrid(idx0);
        } else
            fail("Mode: " + mode);
        awaitPartitionMapExchange();
        assertPartitionsSame(idleVerify(crd, DEFAULT_CACHE_NAME));
    } else {
        // Will own a clearing partition.
        g1.resetLostPartitions(Collections.singletonList(DEFAULT_CACHE_NAME));
        awaitPartitionMapExchange();
        // Expecting partition in OWNING state.
        final PartitionUpdateCounter cntr = counter(partId, DEFAULT_CACHE_NAME, g1.name());
        assertNotNull(cntr);
        // Counter must be reset.
        assertEquals(0, cntr.get());
        // Puts done concurrently with clearing after reset should not be lost.
        g1.cache(DEFAULT_CACHE_NAME).putAll(keys.stream().collect(Collectors.toMap(k -> k, v -> -1)));
        GridTestUtils.waitForCondition(() -> g1.context().cache().context().evict().total() == 0, 30_000);
        for (Integer key : keys) assertEquals("key=" + key.toString(), -1, g1.cache(DEFAULT_CACHE_NAME).get(key));
    }
}
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) ArrayList(java.util.ArrayList) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)

Example 77 with GridDhtLocalPartition

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

the class GridCacheRebalancingSyncSelfTest method checkPartitionMapExchangeFinished.

/**
 */
public static void checkPartitionMapExchangeFinished() {
    for (Ignite g : G.allGrids()) {
        IgniteKernal g0 = (IgniteKernal) g;
        for (IgniteCacheProxy<?, ?> c : g0.context().cache().jcaches()) {
            CacheConfiguration cfg = c.context().config();
            if (cfg.getCacheMode() != LOCAL && cfg.getRebalanceMode() != NONE) {
                GridDhtCacheAdapter<?, ?> dht = dht(c);
                GridDhtPartitionTopology top = dht.topology();
                List<GridDhtLocalPartition> locs = top.localPartitions();
                for (GridDhtLocalPartition loc : locs) {
                    GridDhtPartitionState actl = loc.state();
                    boolean res = GridDhtPartitionState.OWNING.equals(actl);
                    if (!res)
                        printPartitionState(c);
                    assertTrue("Wrong local partition state part=" + loc.id() + ", should be OWNING [state=" + actl + "], node=" + g0.name() + " cache=" + c.getName(), res);
                    Collection<ClusterNode> affNodes = g0.affinity(cfg.getName()).mapPartitionToPrimaryAndBackups(loc.id());
                    assertTrue(affNodes.contains(g0.localNode()));
                }
                for (Ignite remote : G.allGrids()) {
                    IgniteKernal remote0 = (IgniteKernal) remote;
                    IgniteCacheProxy<?, ?> remoteC = remote0.context().cache().jcache(cfg.getName());
                    GridDhtCacheAdapter<?, ?> remoteDht = dht(remoteC);
                    GridDhtPartitionTopology remoteTop = remoteDht.topology();
                    GridDhtPartitionMap pMap = remoteTop.partitionMap(true).get(((IgniteKernal) g).localNodeId());
                    assertEquals(pMap.size(), locs.size());
                    for (Map.Entry entry : pMap.entrySet()) {
                        assertTrue("Wrong remote partition state part=" + entry.getKey() + ", should be OWNING [state=" + entry.getValue() + "], node=" + remote.name() + " cache=" + c.getName(), entry.getValue() == GridDhtPartitionState.OWNING);
                    }
                    for (GridDhtLocalPartition loc : locs) assertTrue(pMap.containsKey(loc.id()));
                }
            }
        }
    }
    log.info("checkPartitionMapExchangeFinished finished");
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) Ignite(org.apache.ignite.Ignite) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) Map(java.util.Map) GridDhtPartitionMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 78 with GridDhtLocalPartition

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

the class IgniteWalHistoryReservationsTest method testRemovesArePreloadedIfHistoryIsAvailable.

/**
 * @throws Exception If failed.
 */
@Test
public void testRemovesArePreloadedIfHistoryIsAvailable() throws Exception {
    Assume.assumeFalse("https://issues.apache.org/jira/browse/IGNITE-10551", MvccFeatureChecker.forcedMvcc());
    int entryCnt = 10_000;
    IgniteEx ig0 = (IgniteEx) startGrids(2);
    ig0.cluster().active(true);
    IgniteCache<Integer, Integer> cache = ig0.cache("cache1");
    for (int k = 0; k < entryCnt; k++) cache.put(k, k);
    stopGrid(1);
    for (int k = 0; k < entryCnt; k += 2) cache.remove(k);
    IgniteEx ig1 = startGrid(1);
    awaitPartitionMapExchange();
    IgniteCache<Integer, Integer> cache1 = ig1.cache("cache1");
    assertEquals(entryCnt / 2, cache.size());
    assertEquals(entryCnt / 2, cache1.size());
    for (Integer k = 0; k < entryCnt; k++) {
        if (k % 2 == 0) {
            assertTrue("k=" + k, !cache.containsKey(k));
            assertTrue("k=" + k, !cache1.containsKey(k));
        } else {
            assertEquals("k=" + k, k, cache.get(k));
            assertEquals("k=" + k, k, cache1.get(k));
        }
    }
    for (int p = 0; p < ig1.affinity("cache1").partitions(); p++) {
        GridDhtLocalPartition p0 = ig0.context().cache().cache("cache1").context().topology().localPartition(p);
        GridDhtLocalPartition p1 = ig1.context().cache().cache("cache1").context().topology().localPartition(p);
        assertTrue(p0.updateCounter() > 0);
        assertEquals(p0.updateCounter(), p1.updateCounter());
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 79 with GridDhtLocalPartition

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

the class IgniteWalHistoryReservationsTest method testNodeIsClearedIfHistoryIsUnavailable.

/**
 * @throws Exception If failed.
 */
@Test
public void testNodeIsClearedIfHistoryIsUnavailable() throws Exception {
    Assume.assumeFalse("https://issues.apache.org/jira/browse/IGNITE-10551", MvccFeatureChecker.forcedMvcc());
    int entryCnt = 10_000;
    IgniteEx ig0 = (IgniteEx) startGrids(2);
    ig0.cluster().active(true);
    IgniteCache<Integer, Integer> cache = ig0.cache("cache1");
    for (int k = 0; k < entryCnt; k++) cache.put(k, k);
    forceCheckpoint();
    stopGrid(1);
    for (int k = 0; k < entryCnt; k += 2) cache.remove(k);
    forceCheckpoint();
    for (Integer k = 0; k < entryCnt; k++) {
        if (k % 2 == 0)
            assertTrue("k=" + k, !cache.containsKey(k));
        else
            assertEquals("k=" + k, k, cache.get(k));
    }
    IgniteEx ig1 = startGrid(1);
    awaitPartitionMapExchange();
    IgniteCache<Integer, Integer> cache1 = ig1.cache("cache1");
    assertEquals(entryCnt / 2, cache.size());
    assertEquals(entryCnt / 2, cache1.size());
    for (Integer k = 0; k < entryCnt; k++) {
        if (k % 2 == 0) {
            assertTrue("k=" + k, !cache.containsKey(k));
            assertTrue("k=" + k, !cache1.containsKey(k));
        } else {
            assertEquals("k=" + k, k, cache.get(k));
            assertEquals("k=" + k, k, cache1.get(k));
        }
    }
    for (int p = 0; p < ig1.affinity("cache1").partitions(); p++) {
        GridDhtLocalPartition p0 = ig0.context().cache().cache("cache1").context().topology().localPartition(p);
        GridDhtLocalPartition p1 = ig1.context().cache().cache("cache1").context().topology().localPartition(p);
        assertTrue(p0.updateCounter() > 0);
        assertEquals(p0.updateCounter(), p1.updateCounter());
    }
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 80 with GridDhtLocalPartition

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

the class IgnitePdsWithTtlTest method waitAndCheckExpired.

/**
 */
protected void waitAndCheckExpired(IgniteEx srv, final IgniteCache<Integer, byte[]> cache) throws IgniteCheckedException {
    boolean awaited = GridTestUtils.waitForCondition(new PA() {

        @Override
        public boolean apply() {
            return cache.size() == 0;
        }
    }, TimeUnit.SECONDS.toMillis(EXPIRATION_TIMEOUT + EXPIRATION_TIMEOUT / 2));
    assertTrue("Cache is not empty. size=" + cache.size(), awaited);
    printStatistics((IgniteCacheProxy) cache, "After timeout");
    GridCacheSharedContext ctx = srv.context().cache().context();
    GridCacheContext cctx = ctx.cacheContext(CU.cacheId(CACHE_NAME_ATOMIC));
    // Check partitions through internal API.
    for (int partId = 0; partId < PART_SIZE; ++partId) {
        GridDhtLocalPartition locPart = cctx.dht().topology().localPartition(partId);
        if (locPart == null)
            continue;
        GridCursor cur = locPart.dataStore().cursor();
        assertFalse(cur.next());
        assertEquals(0, locPart.fullSize());
    }
    for (int i = 0; i < ENTRIES; i++) assertNull(cache.get(i));
}
Also used : PA(org.apache.ignite.internal.util.typedef.PA) GridCursor(org.apache.ignite.internal.util.lang.GridCursor) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext)

Aggregations

GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)95 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)21 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)19 IgniteEx (org.apache.ignite.internal.IgniteEx)19 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)19 ArrayList (java.util.ArrayList)18 Map (java.util.Map)18 Test (org.junit.Test)18 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)16 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 ClusterNode (org.apache.ignite.cluster.ClusterNode)15 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)15 HashMap (java.util.HashMap)14 HashSet (java.util.HashSet)13 AtomicLong (java.util.concurrent.atomic.AtomicLong)13 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)13 Ignite (org.apache.ignite.Ignite)12 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)12 IgniteException (org.apache.ignite.IgniteException)11