Search in sources :

Example 1 with PartitionUpdateCounterTrackingImpl

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

the class PartitionUpdateCounterTest method testMixedModeMultithreaded.

/**
 * Test multithreaded updates of pc in various modes.
 *
 * @throws Exception If failed.
 */
@Test
public void testMixedModeMultithreaded() throws Exception {
    PartitionUpdateCounter pc = new PartitionUpdateCounterTrackingImpl(null);
    AtomicBoolean stop = new AtomicBoolean();
    Queue<long[]> reservations = new ConcurrentLinkedQueue<>();
    LongAdder reserveCntr = new LongAdder();
    IgniteInternalFuture<?> fut = multithreadedAsync(() -> {
        while (!stop.get() || !reservations.isEmpty()) {
            if (!stop.get() && ThreadLocalRandom.current().nextBoolean()) {
                int size = ThreadLocalRandom.current().nextInt(9) + 1;
                // Only update if stop flag is set.
                reservations.add(new long[] { pc.reserve(size), size });
                reserveCntr.add(size);
            } else {
                long[] reserved = reservations.poll();
                if (reserved == null)
                    continue;
                pc.update(reserved[0], reserved[1]);
            }
        }
    }, Runtime.getRuntime().availableProcessors() * 2, "updater-thread");
    doSleep(10_000);
    stop.set(true);
    fut.get();
    assertTrue(reservations.isEmpty());
    log.info("counter=" + pc.toString() + ", reserveCntrLocal=" + reserveCntr.sum());
    assertTrue(pc.sequential());
    assertTrue(pc.get() == pc.reserved());
    assertEquals(reserveCntr.sum(), pc.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) LongAdder(java.util.concurrent.atomic.LongAdder) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with PartitionUpdateCounterTrackingImpl

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

the class PartitionUpdateCounterTest method testStaleUpdate.

/**
 * Test if pc correctly reports stale (before current counter) updates.
 * This information is used for logging rollback records only once.
 */
@Test
public void testStaleUpdate() {
    PartitionUpdateCounter pc = new PartitionUpdateCounterTrackingImpl(null);
    assertTrue(pc.update(0, 1));
    assertFalse(pc.update(0, 1));
    assertTrue(pc.update(2, 1));
    assertFalse(pc.update(2, 1));
    assertTrue(pc.update(1, 1));
    assertFalse(pc.update(1, 1));
}
Also used : PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with PartitionUpdateCounterTrackingImpl

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

the class PartitionUpdateCounterTest method testOverlap.

/**
 */
@Test
public void testOverlap() {
    PartitionUpdateCounter pc = new PartitionUpdateCounterTrackingImpl(null);
    assertTrue(pc.update(13, 3));
    assertTrue(pc.update(6, 7));
    assertFalse(pc.update(13, 3));
    assertFalse(pc.update(6, 7));
    Iterator<long[]> iter = pc.iterator();
    assertTrue(iter.hasNext());
    long[] upd = iter.next();
    assertEquals(6, upd[0]);
    assertEquals(10, upd[1]);
    assertFalse(iter.hasNext());
}
Also used : PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with PartitionUpdateCounterTrackingImpl

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

the class PartitionUpdateCounterTest method testGapsSerialization.

/**
 */
@Test
public void testGapsSerialization() {
    PartitionUpdateCounter pc = new PartitionUpdateCounterTrackingImpl(null);
    Random r = new Random();
    for (int c = 1; c < 500; c++) pc.update(c * 4, r.nextInt(3) + 1);
    final byte[] bytes = pc.getBytes();
    PartitionUpdateCounter pc2 = new PartitionUpdateCounterTrackingImpl(null);
    pc2.init(0, bytes);
    NavigableMap q0 = U.field(pc, "queue");
    NavigableMap q1 = U.field(pc2, "queue");
    assertEquals(q0, q1);
}
Also used : PartitionUpdateCounterTrackingImpl(org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl) Random(java.util.Random) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) NavigableMap(java.util.NavigableMap) PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with PartitionUpdateCounterTrackingImpl

use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl 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)

Aggregations

PartitionUpdateCounter (org.apache.ignite.internal.processors.cache.PartitionUpdateCounter)10 PartitionUpdateCounterTrackingImpl (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl)10 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)9 Test (org.junit.Test)9 IgniteEx (org.apache.ignite.internal.IgniteEx)3 PartitionUpdateCounterErrorWrapper (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterErrorWrapper)3 NavigableMap (java.util.NavigableMap)2 Random (java.util.Random)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 LongAdder (java.util.concurrent.atomic.LongAdder)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 PartitionUpdateCounterVolatileImpl (org.apache.ignite.internal.processors.cache.PartitionUpdateCounterVolatileImpl)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Queue (java.util.Queue)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1