Search in sources :

Example 6 with PagePartitionMetaIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO 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

PagePartitionMetaIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)6 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)5 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)2 GridDhtPartitionState (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)1 IgniteWriteAheadLogManager (org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager)1 MetaPageInitRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord)1 MetaPageUpdatePartitionDataRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord)1 CacheGroupContext (org.apache.ignite.internal.processors.cache.CacheGroupContext)1 RootPage (org.apache.ignite.internal.processors.cache.persistence.RootPage)1 CacheFreeListImpl (org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeListImpl)1 CacheDataRowStore (org.apache.ignite.internal.processors.cache.tree.CacheDataRowStore)1