Search in sources :

Example 86 with CacheGroupContext

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

Example 87 with CacheGroupContext

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();
    }
}
Also used : Arrays(java.util.Arrays) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Transaction(org.apache.ignite.transactions.Transaction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) FULL_SYNC(org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC) IgniteCache(org.apache.ignite.IgniteCache) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Stream(java.util.stream.Stream) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Map(java.util.Map) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionTopologyImpl(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopologyImpl) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Transaction(org.apache.ignite.transactions.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) GridDhtPartitionTopologyImpl(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopologyImpl) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 88 with CacheGroupContext

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 -&gt; PartId -&gt; 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);
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridCacheOffheapManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheOffheapManager) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) HashMap(java.util.HashMap) Map(java.util.Map)

Example 89 with CacheGroupContext

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) T2(org.apache.ignite.internal.util.typedef.T2)

Example 90 with CacheGroupContext

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteException(org.apache.ignite.IgniteException) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) HashSet(java.util.HashSet)

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