Search in sources :

Example 1 with PagePartitionMetaIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO in project ignite by apache.

the class MetaPageUpdatePartitionDataRecord method applyDelta.

/**
 * {@inheritDoc}
 */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
    PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.forPage(pageAddr);
    io.setUpdateCounter(pageAddr, updateCntr);
    io.setGlobalRemoveId(pageAddr, globalRmvId);
    io.setSize(pageAddr, partSize);
    io.setCountersPageId(pageAddr, cntrsPageId);
    io.setPartitionState(pageAddr, state);
    io.setCandidatePageCount(pageAddr, allocatedIdxCandidate);
}
Also used : PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)

Example 2 with PagePartitionMetaIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO in project ignite by apache.

the class MetaStorage method getOrAllocateMetas.

/**
 */
private void getOrAllocateMetas() throws IgniteCheckedException {
    PageMemoryEx pageMem = (PageMemoryEx) dataRegion.pageMemory();
    int partId = 0;
    long partMetaId = pageMem.partitionMetaPageId(METASTORAGE_CACHE_ID, partId);
    long partMetaPage = pageMem.acquirePage(METASTORAGE_CACHE_ID, partMetaId);
    try {
        if (readOnly) {
            long pageAddr = pageMem.readLock(METASTORAGE_CACHE_ID, partMetaId, partMetaPage);
            try {
                if (PageIO.getType(pageAddr) != PageIO.T_PART_META) {
                    empty = true;
                    return;
                }
                PagePartitionMetaIO io = PageIO.getPageIO(pageAddr);
                treeRoot = new RootPage(new FullPageId(io.getTreeRoot(pageAddr), METASTORAGE_CACHE_ID), false);
                reuseListRoot = new RootPage(new FullPageId(io.getReuseListRoot(pageAddr), METASTORAGE_CACHE_ID), false);
                rmvId.set(io.getGlobalRemoveId(pageAddr));
            } finally {
                pageMem.readUnlock(METASTORAGE_CACHE_ID, partId, partMetaPage);
            }
        } else {
            boolean allocated = false;
            long pageAddr = pageMem.writeLock(METASTORAGE_CACHE_ID, partMetaId, partMetaPage);
            try {
                long treeRoot, reuseListRoot;
                if (PageIO.getType(pageAddr) != PageIO.T_PART_META) {
                    // Initialize new page.
                    PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.latest();
                    io.initNewPage(pageAddr, partMetaId, pageMem.pageSize());
                    treeRoot = pageMem.allocatePage(METASTORAGE_CACHE_ID, partId, PageMemory.FLAG_DATA);
                    reuseListRoot = pageMem.allocatePage(METASTORAGE_CACHE_ID, partId, PageMemory.FLAG_DATA);
                    assert PageIdUtils.flag(treeRoot) == PageMemory.FLAG_DATA;
                    assert PageIdUtils.flag(reuseListRoot) == PageMemory.FLAG_DATA;
                    io.setTreeRoot(pageAddr, treeRoot);
                    io.setReuseListRoot(pageAddr, reuseListRoot);
                    if (PageHandler.isWalDeltaRecordNeeded(pageMem, METASTORAGE_CACHE_ID, partMetaId, partMetaPage, wal, null))
                        wal.log(new MetaPageInitRecord(METASTORAGE_CACHE_ID, partMetaId, io.getType(), io.getVersion(), treeRoot, reuseListRoot));
                    allocated = true;
                } else {
                    PagePartitionMetaIO io = PageIO.getPageIO(pageAddr);
                    treeRoot = io.getTreeRoot(pageAddr);
                    reuseListRoot = io.getReuseListRoot(pageAddr);
                    rmvId.set(io.getGlobalRemoveId(pageAddr));
                    assert PageIdUtils.flag(treeRoot) == PageMemory.FLAG_DATA : U.hexLong(treeRoot) + ", part=" + partId + ", METASTORAGE_CACHE_ID=" + METASTORAGE_CACHE_ID;
                    assert PageIdUtils.flag(reuseListRoot) == PageMemory.FLAG_DATA : U.hexLong(reuseListRoot) + ", part=" + partId + ", METASTORAGE_CACHE_ID=" + METASTORAGE_CACHE_ID;
                }
                this.treeRoot = new RootPage(new FullPageId(treeRoot, METASTORAGE_CACHE_ID), allocated);
                this.reuseListRoot = new RootPage(new FullPageId(reuseListRoot, METASTORAGE_CACHE_ID), allocated);
            } finally {
                pageMem.writeUnlock(METASTORAGE_CACHE_ID, partMetaId, partMetaPage, null, allocated);
            }
        }
    } finally {
        pageMem.releasePage(METASTORAGE_CACHE_ID, partMetaId, partMetaPage);
    }
}
Also used : RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) MetaPageInitRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 3 with PagePartitionMetaIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO in project ignite by apache.

the class MetaStorage method saveStoreMetadata.

/**
 * @throws IgniteCheckedException If failed.
 */
private void saveStoreMetadata() throws IgniteCheckedException {
    PageMemoryEx pageMem = (PageMemoryEx) pageMemory();
    int partId = 0;
    long partMetaId = pageMem.partitionMetaPageId(METASTORAGE_CACHE_ID, partId);
    long partMetaPage = pageMem.acquirePage(METASTORAGE_CACHE_ID, partMetaId);
    try {
        long partMetaPageAddr = pageMem.writeLock(METASTORAGE_CACHE_ID, partMetaId, partMetaPage);
        if (partMetaPageAddr == 0L) {
            U.warn(log, "Failed to acquire write lock for meta page [metaPage=" + partMetaPage + ']');
            return;
        }
        boolean changed = false;
        try {
            PagePartitionMetaIO io = PageIO.getPageIO(partMetaPageAddr);
            changed |= io.setGlobalRemoveId(partMetaPageAddr, rmvId.get());
        } finally {
            pageMem.writeUnlock(METASTORAGE_CACHE_ID, partMetaId, partMetaPage, null, changed);
        }
    } finally {
        pageMem.releasePage(METASTORAGE_CACHE_ID, partMetaId, partMetaPage);
    }
}
Also used : PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)

Example 4 with PagePartitionMetaIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO in project ignite by apache.

the class GridCacheOffheapManager method saveStoreMetadata.

/**
 * @param store Store to save metadata.
 * @throws IgniteCheckedException If failed.
 */
private boolean saveStoreMetadata(CacheDataStore store, Context ctx, boolean saveMeta, boolean beforeDestroy) throws IgniteCheckedException {
    RowStore rowStore0 = store.rowStore();
    boolean needSnapshot = ctx != null && ctx.nextSnapshot() && ctx.needToSnapshot(grp.cacheOrGroupName());
    boolean wasSaveToMeta = false;
    if (rowStore0 != null) {
        CacheFreeListImpl freeList = (CacheFreeListImpl) rowStore0.freeList();
        freeList.saveMetadata();
        long updCntr = store.updateCounter();
        int size = store.fullSize();
        long rmvId = globalRemoveId().get();
        PageMemoryEx pageMem = (PageMemoryEx) grp.dataRegion().pageMemory();
        IgniteWriteAheadLogManager wal = this.ctx.wal();
        if (size > 0 || updCntr > 0) {
            GridDhtPartitionState state = null;
            // localPartition will not acquire writeLock here because create=false.
            GridDhtLocalPartition part = null;
            if (!grp.isLocal()) {
                if (beforeDestroy)
                    state = GridDhtPartitionState.EVICTED;
                else {
                    part = getPartition(store);
                    if (part != null && part.state() != GridDhtPartitionState.EVICTED)
                        state = part.state();
                }
                // Do not save meta for evicted partitions on next checkpoints.
                if (state == null)
                    return false;
            }
            int grpId = grp.groupId();
            long partMetaId = pageMem.partitionMetaPageId(grpId, store.partId());
            long partMetaPage = pageMem.acquirePage(grpId, partMetaId);
            try {
                long partMetaPageAddr = pageMem.writeLock(grpId, partMetaId, partMetaPage);
                if (partMetaPageAddr == 0L) {
                    U.warn(log, "Failed to acquire write lock for meta page [metaPage=" + partMetaPage + ", saveMeta=" + saveMeta + ", beforeDestroy=" + beforeDestroy + ", size=" + size + ", updCntr=" + updCntr + ", state=" + state + ']');
                    return false;
                }
                boolean changed = false;
                try {
                    PagePartitionMetaIO io = PageIO.getPageIO(partMetaPageAddr);
                    changed |= io.setUpdateCounter(partMetaPageAddr, updCntr);
                    changed |= io.setGlobalRemoveId(partMetaPageAddr, rmvId);
                    changed |= io.setSize(partMetaPageAddr, size);
                    if (state != null)
                        changed |= io.setPartitionState(partMetaPageAddr, (byte) state.ordinal());
                    else
                        assert grp.isLocal() : grp.cacheOrGroupName();
                    long cntrsPageId;
                    if (grp.sharedGroup()) {
                        long initCntrPageId = io.getCountersPageId(partMetaPageAddr);
                        Map<Integer, Long> newSizes = store.cacheSizes();
                        Map<Integer, Long> prevSizes = readSharedGroupCacheSizes(pageMem, grpId, initCntrPageId);
                        if (prevSizes != null && prevSizes.equals(newSizes))
                            // Preventing modification of sizes pages for store
                            cntrsPageId = initCntrPageId;
                        else {
                            cntrsPageId = writeSharedGroupCacheSizes(pageMem, grpId, initCntrPageId, store.partId(), newSizes);
                            if (initCntrPageId == 0 && cntrsPageId != 0) {
                                io.setCountersPageId(partMetaPageAddr, cntrsPageId);
                                changed = true;
                            }
                        }
                    } else
                        cntrsPageId = 0L;
                    int pageCnt;
                    if (needSnapshot) {
                        pageCnt = this.ctx.pageStore().pages(grpId, store.partId());
                        io.setCandidatePageCount(partMetaPageAddr, size == 0 ? 0 : pageCnt);
                        if (saveMeta) {
                            saveMeta(ctx);
                            wasSaveToMeta = true;
                        }
                        if (state == OWNING) {
                            assert part != null;
                            if (!addPartition(part, ctx.partitionStatMap(), partMetaPageAddr, io, grpId, store.partId(), this.ctx.pageStore().pages(grpId, store.partId()), store.fullSize()))
                                U.warn(log, "Partition was concurrently evicted grpId=" + grpId + ", partitionId=" + part.id());
                        } else if (state == MOVING || state == RENTING) {
                            if (ctx.partitionStatMap().forceSkipIndexPartition(grpId)) {
                                if (log.isInfoEnabled())
                                    log.info("Will not include SQL indexes to snapshot because there is " + "a partition not in " + OWNING + " state [grp=" + grp.cacheOrGroupName() + ", partId=" + store.partId() + ", state=" + state + ']');
                            }
                        }
                        changed = true;
                    } else
                        pageCnt = io.getCandidatePageCount(partMetaPageAddr);
                    if (PageHandler.isWalDeltaRecordNeeded(pageMem, grpId, partMetaId, partMetaPage, wal, null))
                        wal.log(new MetaPageUpdatePartitionDataRecord(grpId, partMetaId, updCntr, rmvId, size, cntrsPageId, state == null ? -1 : (byte) state.ordinal(), pageCnt));
                } finally {
                    pageMem.writeUnlock(grpId, partMetaId, partMetaPage, null, changed);
                }
            } finally {
                pageMem.releasePage(grpId, partMetaId, partMetaPage);
            }
        } else if (needSnapshot)
            tryAddEmptyPartitionToSnapshot(store, ctx);
        ;
    } else if (needSnapshot)
        tryAddEmptyPartitionToSnapshot(store, ctx);
    return wasSaveToMeta;
}
Also used : CacheFreeListImpl(org.apache.ignite.internal.processors.cache.persistence.freelist.CacheFreeListImpl) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) CacheDataRowStore(org.apache.ignite.internal.processors.cache.tree.CacheDataRowStore) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState) MetaPageUpdatePartitionDataRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageUpdatePartitionDataRecord) 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)

Example 5 with PagePartitionMetaIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO in project ignite by apache.

the class GridCacheDatabaseSharedManager method readPartitionState.

/**
 * @param grpCtx Group context.
 * @param partId Partition ID.
 * @return Partition state.
 */
public GridDhtPartitionState readPartitionState(CacheGroupContext grpCtx, int partId) {
    int grpId = grpCtx.groupId();
    PageMemoryEx pageMem = (PageMemoryEx) grpCtx.dataRegion().pageMemory();
    try {
        if (storeMgr.exists(grpId, partId)) {
            storeMgr.ensure(grpId, partId);
            if (storeMgr.pages(grpId, partId) > 1) {
                long partMetaId = pageMem.partitionMetaPageId(grpId, partId);
                long partMetaPage = pageMem.acquirePage(grpId, partMetaId);
                try {
                    long pageAddr = pageMem.readLock(grpId, partMetaId, partMetaPage);
                    try {
                        if (PageIO.getType(pageAddr) == PageIO.T_PART_META) {
                            PagePartitionMetaIO io = PagePartitionMetaIO.VERSIONS.forPage(pageAddr);
                            GridDhtPartitionState state = GridDhtPartitionState.fromOrdinal((int) io.getPartitionState(pageAddr));
                            if (state == null)
                                state = GridDhtPartitionState.MOVING;
                            return state;
                        }
                    } finally {
                        pageMem.readUnlock(grpId, partMetaId, partMetaPage);
                    }
                } finally {
                    pageMem.releasePage(grpId, partMetaId, partMetaPage);
                }
            }
        }
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to read partition state (will default to MOVING) [grp=" + grpCtx + ", partId=" + partId + "]", e);
    }
    return GridDhtPartitionState.MOVING;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)

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