Search in sources :

Example 91 with CacheGroupContext

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) IgniteLogger(org.apache.ignite.IgniteLogger) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) ArrayList(java.util.ArrayList) IgniteCallable(org.apache.ignite.lang.IgniteCallable) HashSet(java.util.HashSet) Future(java.util.concurrent.Future) GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) LoggerResource(org.apache.ignite.resources.LoggerResource) ExecutorService(java.util.concurrent.ExecutorService) F(org.apache.ignite.internal.util.typedef.F) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) Executors(java.util.concurrent.Executors) GridIterator(org.apache.ignite.internal.util.lang.GridIterator) T2(org.apache.ignite.internal.util.typedef.T2) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) List(java.util.List) CU(org.apache.ignite.internal.util.typedef.internal.CU) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) Collections(java.util.Collections) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 92 with CacheGroupContext

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);
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) GridEncryptionManager(org.apache.ignite.internal.managers.encryption.GridEncryptionManager) FileChannel(java.nio.channels.FileChannel) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) ByteBuffer(java.nio.ByteBuffer) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) File(java.io.File)

Example 93 with CacheGroupContext

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);
}
Also used : CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Example 94 with CacheGroupContext

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);
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) Nullable(org.jetbrains.annotations.Nullable)

Example 95 with CacheGroupContext

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;
}
Also used : GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) CacheGroupDescriptor(org.apache.ignite.internal.processors.cache.CacheGroupDescriptor) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Aggregations

CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)103 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)31 IgniteEx (org.apache.ignite.internal.IgniteEx)29 Map (java.util.Map)27 HashMap (java.util.HashMap)24 IgniteException (org.apache.ignite.IgniteException)22 ArrayList (java.util.ArrayList)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 Test (org.junit.Test)20 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition)19 List (java.util.List)17 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)16 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology)16 HashSet (java.util.HashSet)13 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)12 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)12 GridCacheSharedContext (org.apache.ignite.internal.processors.cache.GridCacheSharedContext)12 Set (java.util.Set)11 Collection (java.util.Collection)10