use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopologyImpl in project ignite by apache.
the class ResetLostPartitionTest method getPartitionsStates.
/**
* @param gridNumber Grid number.
* @param cacheName Cache name.
* @return Partitions states for given cache name.
*/
private List<GridDhtPartitionState> getPartitionsStates(int gridNumber, String cacheName) {
CacheGroupContext cgCtx = grid(gridNumber).context().cache().cacheGroup(CU.cacheId(cacheName));
GridDhtPartitionTopologyImpl top = (GridDhtPartitionTopologyImpl) cgCtx.topology();
return top.localPartitions().stream().map(GridDhtLocalPartition::state).collect(Collectors.toList());
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopologyImpl in project ignite by apache.
the class TxCrossCacheRemoteMultiplePartitionReservationTest method testRemoteCommitPartitionReservations.
/**
*/
@Test
public void testRemoteCommitPartitionReservations() throws Exception {
try {
IgniteEx crd = startGrids(2);
awaitPartitionMapExchange();
IgniteEx client = startClientGrid("client");
IgniteCache<Object, Object> cache1 = client.cache(CACHE1);
IgniteCache<Object, Object> cache2 = client.cache(CACHE2);
List<Integer> evictingIds = evictingPartitionsAfterJoin(crd, crd.cache(CACHE1), 10);
int[] backupParts = crd.affinity(CACHE1).backupPartitions(crd.localNode());
Arrays.sort(backupParts);
int evictingBackupPartId = -1;
for (int id : evictingIds) {
if (Arrays.binarySearch(backupParts, id) >= 0) {
evictingBackupPartId = id;
break;
}
}
assertTrue(evictingBackupPartId != -1);
startGrid(2);
awaitPartitionMapExchange(true, true, null);
// Mock partition after re-create.
final int finalEvictingBackupPartId = evictingBackupPartId;
Map<Integer, AtomicInteger> reserveCntrs = new ConcurrentHashMap<>();
GridDhtPartitionTopologyImpl.PartitionFactory factory = new GridDhtPartitionTopologyImpl.PartitionFactory() {
@Override
public GridDhtLocalPartition create(GridCacheSharedContext ctx, CacheGroupContext grp, int id, boolean recovery) {
return id != finalEvictingBackupPartId ? new GridDhtLocalPartition(ctx, grp, id, recovery) : new GridDhtLocalPartition(ctx, grp, id, recovery) {
@Override
public boolean reserve() {
reserveCntrs.computeIfAbsent(grp.groupId(), integer -> new AtomicInteger()).incrementAndGet();
return super.reserve();
}
};
}
};
Stream.of(CACHE1, CACHE2).map(cache -> (GridDhtPartitionTopologyImpl) crd.cachex(cache).context().topology()).forEach(topology -> topology.partitionFactory(factory));
stopGrid(2);
awaitPartitionMapExchange(true, true, null);
reserveCntrs.values().forEach(cntr -> cntr.set(0));
// backup commits.
try (Transaction tx = client.transactions().txStart()) {
cache1.put(evictingBackupPartId, 0);
cache2.put(evictingBackupPartId, 0);
tx.commit();
}
assertEquals("Expecting same reservations count for all caches [cntrs=" + reserveCntrs.toString() + ']', 1, reserveCntrs.values().stream().map(AtomicInteger::get).distinct().count());
} finally {
stopAllGrids();
}
}
Aggregations