use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class VisorFindAndDeleteGarbageInPersistenceClosure method processPartition.
/**
* @param grpCtx Group context.
* @param part Local partition.
*/
private Map<Integer, Map<Integer, Long>> processPartition(CacheGroupContext grpCtx, GridDhtLocalPartition part) {
if (!part.reserve())
return Collections.emptyMap();
Map<Integer, Map<Integer, Long>> stoppedCachesForGrpId = new HashMap<>();
try {
if (part.state() != GridDhtPartitionState.OWNING)
return Collections.emptyMap();
GridIterator<CacheDataRow> it = grpCtx.offheap().partitionIterator(part.id());
while (it.hasNextX()) {
CacheDataRow row = it.nextX();
if (row.cacheId() == 0)
break;
int cacheId = row.cacheId();
GridCacheContext cacheCtx = grpCtx.shared().cacheContext(row.cacheId());
if (cacheCtx == null)
stoppedCachesForGrpId.computeIfAbsent(grpCtx.groupId(), (x) -> new HashMap<>()).compute(cacheId, (x, y) -> y == null ? 1 : y + 1);
}
} catch (IgniteCheckedException e) {
U.error(log, "Failed to process partition [grpId=" + grpCtx.groupId() + ", partId=" + part.id() + "]", e);
return Collections.emptyMap();
} finally {
part.release();
}
processedPartitions.incrementAndGet();
printProgressIfNeeded();
return stoppedCachesForGrpId;
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class AbstractEncryptionTest method checkGroupKey.
/**
* Ensures that all pages of page store have expected encryption key identifier.
*
* @param grpId Cache group ID.
* @param expKeyId Encryption key ID.
* @param timeout Timeout to wait for encryption to complete.
* @throws Exception If failed.
*/
protected void checkGroupKey(int grpId, int expKeyId, long timeout) throws Exception {
awaitEncryption(G.allGrids(), grpId, timeout);
for (Ignite g : G.allGrids()) {
IgniteEx grid = (IgniteEx) g;
if (grid.context().clientNode())
continue;
info("Validating encryption key [node=" + g.cluster().localNode().id() + ", grp=" + grpId + "]");
CacheGroupContext grp = grid.context().cache().cacheGroup(grpId);
if (grp == null || !grp.affinityNode()) {
info("Context doesn't exits on " + grid.localNode().id());
continue;
}
GridEncryptionManager encryption = grid.context().encryption();
assertEquals(grid.localNode().id().toString(), (byte) expKeyId, encryption.getActiveKey(grpId).id());
IgniteInternalFuture<Void> fut = encryption.reencryptionFuture(grpId);
// The future will be completed after the checkpoint, forcecheckpoint does nothing
// if the checkpoint has already been scheduled.
GridTestUtils.waitForCondition(() -> {
if (fut.isDone())
return true;
try {
forceCheckpoint(g);
} catch (IgniteCheckedException e) {
throw new RuntimeException(e);
}
return fut.isDone();
}, timeout);
assertTrue(fut.isDone());
assertEquals(0, encryption.getBytesLeftForReencryption(grpId));
List<Integer> parts = IntStream.range(0, grp.shared().affinity().affinity(grpId).partitions()).boxed().collect(Collectors.toList());
parts.add(INDEX_PARTITION);
int realPageSize = grp.dataRegion().pageMemory().realPageSize(grpId);
int encryptionBlockSize = grp.shared().kernalContext().config().getEncryptionSpi().blockSize();
for (int p : parts) {
FilePageStore pageStore = (FilePageStore) ((FilePageStoreManager) grp.shared().pageStore()).getStore(grpId, p);
if (!pageStore.exists())
continue;
long state = grid.context().encryption().getEncryptionState(grpId, p);
String msg = String.format("p=%d, off=%d, total=%d", p, ReencryptStateUtils.pageIndex(state), ReencryptStateUtils.pageCount(state));
assertEquals(msg, 0, ReencryptStateUtils.pageCount(state));
assertEquals(msg, 0, ReencryptStateUtils.pageIndex(state));
long startPageId = PageIdUtils.pageId(p, PageIdAllocator.FLAG_DATA, 0);
int pagesCnt = pageStore.pages();
int pageSize = pageStore.getPageSize();
ByteBuffer pageBuf = ByteBuffer.allocate(pageSize);
Path path = new File(pageStore.getFileAbsolutePath()).toPath();
try (FileChannel ch = FileChannel.open(path, StandardOpenOption.READ)) {
for (int n = 0; n < pagesCnt; n++) {
long pageId = startPageId + n;
long pageOff = pageStore.pageOffset(pageId);
pageBuf.position(0);
ch.position(pageOff);
ch.read(pageBuf);
pageBuf.position(realPageSize + encryptionBlockSize);
int pageCrc = pageBuf.getInt();
int pageKeyId = pageBuf.get() & 0xff;
// If this page is empty we can skip it.
if (pageCrc == 0 && pageKeyId == 0) {
pageBuf.position(0);
boolean emptyPage = false;
while (pageBuf.hasRemaining() && !emptyPage) emptyPage = pageBuf.getLong() == 0;
if (emptyPage)
continue;
}
msg = String.format("File=%s, page=%d", pageStore.getFileAbsolutePath(), n);
assertEquals(msg, expKeyId, pageKeyId);
}
}
}
}
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class AbstractEncryptionTest method isReencryptionInProgress.
/**
* @param node Node.
* @param grpId Cache group ID.
* @return {@code True} If reencryption of the specified group is not yet complete.
*/
protected boolean isReencryptionInProgress(IgniteEx node, int grpId) {
CacheGroupContext grp = node.context().cache().cacheGroup(grpId);
if (grp == null || !grp.affinityNode())
return false;
for (int p = 0; p < grp.affinity().partitions(); p++) {
long state = node.context().encryption().getEncryptionState(grpId, p);
if (ReencryptStateUtils.pageIndex(state) != ReencryptStateUtils.pageCount(state))
return true;
}
long state = node.context().encryption().getEncryptionState(grpId, INDEX_PARTITION);
return ReencryptStateUtils.pageIndex(state) != ReencryptStateUtils.pageCount(state);
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class CacheParallelStartTest method assertCaches.
/**
*/
private void assertCaches(IgniteEx igniteEx) {
for (int i = 0; i < GROUPS_COUNT; i++) {
Collection<GridCacheContext> caches = igniteEx.context().cache().cacheGroup(CU.cacheId(STATIC_CACHE_CACHE_GROUP_NAME + i)).caches();
assertEquals(CACHES_COUNT / GROUPS_COUNT, caches.size());
@Nullable CacheGroupContext cacheGrp = igniteEx.context().cache().cacheGroup(CU.cacheId(STATIC_CACHE_CACHE_GROUP_NAME + i));
for (GridCacheContext cacheContext : caches) assertEquals(cacheContext.group(), cacheGrp);
}
}
use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.
the class CachePartitionLossWithRestartsTest method waitForDetection.
/**
* @param node Node.
* @param topVer Topology version.
*/
private GridDhtPartitionTopology waitForDetection(IgniteEx node, AffinityTopologyVersion topVer) throws Exception {
GridCacheSharedContext<Object, Object> cctx = node.context().cache().context();
CacheGroupDescriptor desc = cctx.affinity().cacheGroups().get(CU.cacheId(DEFAULT_CACHE_NAME));
CacheGroupContext grp = cctx.cache().cacheGroup(desc.groupId());
GridDhtPartitionTopology top = grp != null ? grp.topology() : cctx.exchange().clientTopology(desc.groupId(), null);
cctx.exchange().affinityReadyFuture(topVer).get();
cctx.exchange().lastTopologyFuture().get();
return top;
}
Aggregations