use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class IgniteSequentialNodeCrashRecoveryTest method captureDirtyPages.
/**
* @param g Ignite instance.
* @throws IgniteCheckedException If failed.
*/
private Collection<FullPageId> captureDirtyPages(IgniteEx g) throws IgniteCheckedException {
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) g.context().cache().context().database();
dbMgr.checkpointReadLock();
try {
// Moving free list pages to offheap.
for (CacheGroupContext group : g.context().cache().cacheGroups()) {
((GridCacheOffheapManager) group.offheap()).onMarkCheckpointBegin(new DummyCheckpointContext());
}
} finally {
dbMgr.checkpointReadUnlock();
}
// Capture a set of dirty pages.
PageMemoryImpl pageMem = (PageMemoryImpl) dbMgr.dataRegion("default").pageMemory();
return pageMem.dirtyPages();
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext 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();
}
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class VisorFindAndDeleteGarbageInPersistenceClosure method cleanup.
/**
* By calling this method we would delete found garbage in partitions and would try to
* cleanup indexes.
*
* @param grpIdToPartIdToGarbageCount GrpId -> PartId -> Garbage count.
*/
private void cleanup(Map<Integer, Map<Integer, Long>> grpIdToPartIdToGarbageCount) throws IgniteCheckedException {
for (Map.Entry<Integer, Map<Integer, Long>> e : grpIdToPartIdToGarbageCount.entrySet()) {
int grpId = e.getKey();
CacheGroupContext groupContext = ignite.context().cache().cacheGroup(grpId);
assert groupContext != null;
for (Integer cacheId : e.getValue().keySet()) {
groupContext.shared().database().checkpointReadLock();
try {
groupContext.offheap().stopCache(cacheId, true);
} finally {
groupContext.shared().database().checkpointReadUnlock();
}
((GridCacheOffheapManager) groupContext.offheap()).findAndCleanupLostIndexesForStoppedCache(cacheId);
}
}
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class VisorFindAndDeleteGarbageInPersistenceClosure method calcListOfPartitions.
/**
* @param grpIds Group ids to generate list of partitions for.
*/
private List<T2<CacheGroupContext, GridDhtLocalPartition>> calcListOfPartitions(Set<Integer> grpIds) {
List<T2<CacheGroupContext, GridDhtLocalPartition>> partArgs = new ArrayList<>();
for (Integer grpId : grpIds) {
CacheGroupContext grpCtx = ignite.context().cache().cacheGroup(grpId);
List<GridDhtLocalPartition> parts = grpCtx.topology().localPartitions();
for (GridDhtLocalPartition part : parts) partArgs.add(new T2<>(grpCtx, part));
}
// To decrease contention on same group.
Collections.shuffle(partArgs);
return partArgs;
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class VisorFindAndDeleteGarbageInPersistenceClosure method calcCacheGroupIds.
/**
* @return Set of cache group ids to scan for garbage on.
*/
private Set<Integer> calcCacheGroupIds() {
Set<Integer> grpIds = new HashSet<>();
Set<String> missingCacheGroups = new HashSet<>();
if (!F.isEmpty(grpNames)) {
for (String grpName : grpNames) {
CacheGroupContext groupContext = ignite.context().cache().cacheGroup(CU.cacheId(grpName));
if (groupContext == null) {
missingCacheGroups.add(grpName);
continue;
}
if (groupContext.sharedGroup())
grpIds.add(groupContext.groupId());
else
log.warning("Group[name=" + grpName + "] is not shared one, it couldn't contain garbage from destroyed caches.");
}
if (!missingCacheGroups.isEmpty()) {
StringBuilder strBuilder = new StringBuilder("The following cache groups do not exist: ");
for (String name : missingCacheGroups) strBuilder.append(name).append(", ");
strBuilder.delete(strBuilder.length() - 2, strBuilder.length());
throw new IgniteException(strBuilder.toString());
}
} else {
Collection<CacheGroupContext> groups = ignite.context().cache().cacheGroups();
for (CacheGroupContext grp : groups) {
if (!grp.systemCache() && !grp.isLocal())
grpIds.add(grp.groupId());
}
}
return grpIds;
}
Aggregations