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());
}
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));
}
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());
}
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);
}
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();
}
}
Aggregations