use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounter 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.PartitionUpdateCounter 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.PartitionUpdateCounter in project ignite by apache.
the class GridCommonAbstractTest method assertCountersSame.
/**
* @param partId Partition.
* @param withReserveCntr {@code True} to compare reserve counters. Because reserve counters are synced during
* @param cacheName Cache name.
* PME invoking with {@code true} makes sense only after PME was finished.
*/
protected void assertCountersSame(int partId, boolean withReserveCntr, String cacheName) throws AssertionFailedError {
PartitionUpdateCounter cntr0 = null;
List<T3<String, @Nullable PartitionUpdateCounter, Boolean>> cntrMap = G.allGrids().stream().filter(ignite -> !ignite.configuration().isClientMode()).map(ignite -> new T3<>(ignite.name(), counter(partId, cacheName, ignite.name()), ignite.affinity(cacheName).isPrimary(ignite.cluster().localNode(), partId))).collect(toList());
for (T3<String, PartitionUpdateCounter, Boolean> cntr : cntrMap) {
if (cntr.get2() == null)
continue;
if (cntr0 != null) {
assertEquals("Expecting same counters [partId=" + partId + ", cntrs=" + cntrMap + ']', cntr0, cntr.get2());
if (withReserveCntr)
assertEquals("Expecting same reservation counters [partId=" + partId + ", cntrs=" + cntrMap + ']', cntr0.reserved(), cntr.get2().reserved());
}
cntr0 = cntr.get2();
}
}
use of org.apache.ignite.internal.processors.cache.PartitionUpdateCounter 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.PartitionUpdateCounter in project ignite by apache.
the class PagesPossibleCorruptionDiagnosticTest method testCorruptedNodeFailsOnStart.
/**
* Tests that node with corrupted partition fails on start.
*/
@Test
public void testCorruptedNodeFailsOnStart() throws Exception {
IgniteEx ignite = startGrid(0);
ignite.cluster().state(ClusterState.ACTIVE);
IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(new CacheConfiguration<Integer, Integer>(DEFAULT_CACHE_NAME).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setAffinity(new RendezvousAffinityFunction(false, 1)));
cache.put(1, 1);
PartitionUpdateCounter counter = counter(0, DEFAULT_CACHE_NAME, ignite.name());
counter.update(10, 5);
forceCheckpoint();
FilePageStore store = filePageStore(ignite, 0);
stopAllGrids();
store.ensure();
// Index of meta page is always 0.
int metaPageIdx = 0;
long offset = store.headerSize() + metaPageIdx * PAGE_SIZE + PART_META_REUSE_LIST_ROOT_OFF;
writeLongToFileByOffset(store.getFileAbsolutePath(), offset, 0L);
try {
startGrid(0);
} catch (Exception ignored) {
/* No-op. */
}
assertTrue(correctFailure);
}
Aggregations