Search in sources :

Example 21 with CacheGroupContext

use of org.apache.ignite.internal.processors.cache.CacheGroupContext in project ignite by apache.

the class GridCacheDatabaseSharedManager method restorePartitionState.

/**
 * @param partStates Partition states.
 * @throws IgniteCheckedException If failed to restore.
 */
private void restorePartitionState(Map<T2<Integer, Integer>, T2<Integer, Long>> partStates, Collection<Integer> ignoreGrps) throws IgniteCheckedException {
    for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
        if (grp.isLocal() || !grp.affinityNode() || ignoreGrps.contains(grp.groupId())) {
            // Local cache has no partitions and its states.
            continue;
        }
        if (!grp.dataRegion().config().isPersistenceEnabled())
            continue;
        int grpId = grp.groupId();
        PageMemoryEx pageMem = (PageMemoryEx) grp.dataRegion().pageMemory();
        for (int i = 0; i < grp.affinity().partitions(); i++) {
            T2<Integer, Long> restore = partStates.get(new T2<>(grpId, i));
            if (storeMgr.exists(grpId, i)) {
                storeMgr.ensure(grpId, i);
                if (storeMgr.pages(grpId, i) <= 1)
                    continue;
                GridDhtLocalPartition part = grp.topology().forceCreatePartition(i);
                assert part != null;
                // TODO: https://issues.apache.org/jira/browse/IGNITE-6097
                grp.offheap().onPartitionInitialCounterUpdated(i, 0);
                checkpointReadLock();
                try {
                    long partMetaId = pageMem.partitionMetaPageId(grpId, i);
                    long partMetaPage = pageMem.acquirePage(grpId, partMetaId);
                    try {
                        long pageAddr = pageMem.writeLock(grpId, partMetaId, partMetaPage);
                        boolean changed = false;
                        try {
                            PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.forPage(pageAddr);
                            if (restore != null) {
                                int stateId = restore.get1();
                                io.setPartitionState(pageAddr, (byte) stateId);
                                changed = updateState(part, stateId);
                                if (stateId == GridDhtPartitionState.OWNING.ordinal() || (stateId == GridDhtPartitionState.MOVING.ordinal() && part.initialUpdateCounter() < restore.get2())) {
                                    part.initialUpdateCounter(restore.get2());
                                    changed = true;
                                }
                            } else
                                updateState(part, (int) io.getPartitionState(pageAddr));
                        } finally {
                            pageMem.writeUnlock(grpId, partMetaId, partMetaPage, null, changed);
                        }
                    } finally {
                        pageMem.releasePage(grpId, partMetaId, partMetaPage);
                    }
                } finally {
                    checkpointReadUnlock();
                }
            } else if (restore != null) {
                GridDhtLocalPartition part = grp.topology().forceCreatePartition(i);
                assert part != null;
                // TODO: https://issues.apache.org/jira/browse/IGNITE-6097
                grp.offheap().onPartitionInitialCounterUpdated(i, 0);
                updateState(part, restore.get1());
            }
        }
        // After partition states are restored, it is necessary to update internal data structures in topology.
        grp.topology().afterStateRestored(grp.topology().lastTopologyChangeVersion());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext)

Aggregations

CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)21 HashMap (java.util.HashMap)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 Map (java.util.Map)6 ConcurrentMap (java.util.concurrent.ConcurrentMap)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 LinkedHashMap (java.util.LinkedHashMap)5 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)5 GridDhtPartitionTopology (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology)5 ArrayList (java.util.ArrayList)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 List (java.util.List)3 UUID (java.util.UUID)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)3 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)3 HashSet (java.util.HashSet)2 Set (java.util.Set)2 IgniteNeedReconnectException (org.apache.ignite.internal.IgniteNeedReconnectException)2 DiscoveryCustomEvent (org.apache.ignite.internal.events.DiscoveryCustomEvent)2