Search in sources :

Example 1 with PartitionUpdateCounterErrorWrapper

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounterErrorWrapper in project ignite by apache.

the class IgnitePdsSpuriousRebalancingOnNodeJoinTest method testNoSpuriousRebalancing.

/**
 */
@SuppressWarnings("ConstantConditions")
@Test
public void testNoSpuriousRebalancing() throws Exception {
    try {
        IgniteEx crd = startGrids(2);
        crd.cluster().active(true);
        crd.cluster().baselineAutoAdjustEnabled(false);
        List<Integer> moving = movingKeysAfterJoin(crd, DEFAULT_CACHE_NAME, 10);
        int[] primParts = crd.affinity(DEFAULT_CACHE_NAME).primaryPartitions(crd.localNode());
        Arrays.sort(primParts);
        // This partition will be new primary on joining node.
        int primChangePartId = -1;
        for (int id : moving) {
            if (Arrays.binarySearch(primParts, id) >= 0) {
                primChangePartId = id;
                break;
            }
        }
        assertTrue(primChangePartId != -1);
        startGrid(2);
        // Trigger partition movement.
        resetBaselineTopology();
        awaitPartitionMapExchange();
        GridCacheContext<Object, Object> ctx = crd.cachex(DEFAULT_CACHE_NAME).context();
        AffinityAssignment a0 = ctx.affinity().assignment(new AffinityTopologyVersion(3, 1));
        List<ClusterNode> nodes = a0.get(primChangePartId);
        assertEquals(3, nodes.size());
        assertEquals(crd.configuration().getConsistentId(), nodes.get(0).consistentId());
        awaitPartitionMapExchange();
        for (int k = 0; k < PARTS * 2; k++) crd.cache(DEFAULT_CACHE_NAME).put(k, k);
        forceCheckpoint();
        stopGrid(2);
        // Forge the counter on coordinator for switching partition.
        GridDhtLocalPartition part = ctx.topology().localPartition(primChangePartId);
        assertNotNull(part);
        PartitionUpdateCounter cntr0 = part.dataStore().partUpdateCounter();
        assertTrue(cntr0 instanceof PartitionUpdateCounterErrorWrapper);
        PartitionUpdateCounterTrackingImpl delegate = U.field(cntr0, "delegate");
        AtomicLong cntr = U.field(delegate, "cntr");
        cntr.set(cntr.get() - 1);
        TestRecordingCommunicationSpi.spi(crd).record((node, msg) -> msg instanceof GridDhtPartitionDemandMessage);
        startGrid(2);
        awaitPartitionMapExchange();
        // Expecting no rebalancing.
        List<Object> msgs = TestRecordingCommunicationSpi.spi(crd).recordedMessages(true);
        assertTrue("Rebalancing is not expected " + msgs, msgs.isEmpty());
    } finally {
        stopAllGrids();
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AffinityAssignment(org.apache.ignite.internal.processors.affinity.AffinityAssignment) PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) PartitionUpdateCounterErrorWrapper(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterErrorWrapper) AtomicLong(java.util.concurrent.atomic.AtomicLong) 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) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with PartitionUpdateCounterErrorWrapper

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounterErrorWrapper in project ignite by apache.

the class PartitionUpdateCounterTest method testWithPersistentNode.

/**
 * @param mode Mode.
 */
private void testWithPersistentNode(CacheAtomicityMode mode) throws Exception {
    this.mode = mode;
    try {
        IgniteEx grid0 = startGrid(0);
        grid0.cluster().baselineAutoAdjustEnabled(false);
        grid0.cluster().active(true);
        grid0.cluster().baselineAutoAdjustEnabled(false);
        grid0.cache(DEFAULT_CACHE_NAME).put(0, 0);
        startGrid(1);
        grid0.cluster().setBaselineTopology(2);
        awaitPartitionMapExchange();
        grid0.cache(DEFAULT_CACHE_NAME).put(1, 1);
        assertPartitionsSame(idleVerify(grid0, DEFAULT_CACHE_NAME));
        printPartitionState(DEFAULT_CACHE_NAME, 0);
        stopGrid(grid0.name(), false);
        grid0 = startGrid(grid0.name());
        awaitPartitionMapExchange();
        PartitionUpdateCounter cntr = counter(0, grid0.name());
        assertTrue(cntr instanceof PartitionUpdateCounterErrorWrapper);
        PartitionUpdateCounter delegate = U.field(cntr, "delegate");
        if (mode == CacheAtomicityMode.TRANSACTIONAL)
            assertTrue(delegate instanceof PartitionUpdateCounterTrackingImpl);
        else if (mode == CacheAtomicityMode.ATOMIC)
            assertTrue(delegate instanceof PartitionUpdateCounterVolatileImpl);
        assertEquals(cntr.initial(), cntr.get());
    } finally {
        stopAllGrids();
    }
}
Also used : PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) IgniteEx(org.apache.ignite.internal.IgniteEx) PartitionUpdateCounterVolatileImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterVolatileImpl) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) PartitionUpdateCounterErrorWrapper(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterErrorWrapper)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)2 PartitionUpdateCounter (org.apache.ignite.internal.processors.cache.PartitionUpdateCounter)2 PartitionUpdateCounterErrorWrapper (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterErrorWrapper)2 PartitionUpdateCounterTrackingImpl (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1 AffinityAssignment (org.apache.ignite.internal.processors.affinity.AffinityAssignment)1 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)1 PartitionUpdateCounterVolatileImpl (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterVolatileImpl)1 GridDhtPartitionDemandMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage)1 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1