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