Search in sources :

Example 6 with MetaPageInitRecord

use of org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord in project ignite by apache.

the class MetaStorage method getOrAllocateMetas.

/**
 * Initializing the selected partition for use as MetaStorage
 *
 * @param partId Partition id.
 * @return true if the partion is empty
 */
private boolean getOrAllocateMetas(int partId) throws IgniteCheckedException {
    empty = false;
    PageMemoryEx pageMem = (PageMemoryEx) dataRegion.pageMemory();
    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 true;
                }
                PagePartitionMetaIO io = PageIO.getPageIO(pageAddr);
                long treeRoot = io.getTreeRoot(pageAddr);
                long reuseListRoot = io.getReuseListRoot(pageAddr);
                checkRootsPageIdFlag(treeRoot, reuseListRoot);
                this.treeRoot = new RootPage(new FullPageId(treeRoot, METASTORAGE_CACHE_ID), false);
                this.reuseListRoot = new RootPage(new FullPageId(reuseListRoot, 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();
                    PageMetrics metrics = pageMem.metrics().cacheGrpPageMetrics(METASTORAGE_CACHE_ID);
                    // MetaStorage never encrypted so realPageSize == pageSize.
                    io.initNewPage(pageAddr, partMetaId, pageMem.pageSize(), metrics);
                    treeRoot = pageMem.allocatePage(METASTORAGE_CACHE_ID, partId, FLAG_AUX);
                    reuseListRoot = pageMem.allocatePage(METASTORAGE_CACHE_ID, partId, FLAG_AUX);
                    assert PageIdUtils.flag(treeRoot) == FLAG_AUX;
                    assert PageIdUtils.flag(reuseListRoot) == FLAG_AUX;
                    io.setTreeRoot(pageAddr, treeRoot);
                    io.setReuseListRoot(pageAddr, reuseListRoot);
                    if (PageHandler.isWalDeltaRecordNeeded(pageMem, METASTORAGE_CACHE_ID, partMetaId, partMetaPage, wal, null)) {
                        assert io.getType() == PageIO.T_PART_META;
                        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));
                    checkRootsPageIdFlag(treeRoot, reuseListRoot);
                }
                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);
    }
    return false;
}
Also used : RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics) 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 7 with MetaPageInitRecord

use of org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord in project ignite by apache.

the class GridCacheOffheapManager method getOrAllocateCacheMetas.

/**
 * @return Meta root pages info.
 * @throws IgniteCheckedException If failed.
 */
private Metas getOrAllocateCacheMetas() throws IgniteCheckedException {
    PageMemoryEx pageMem = (PageMemoryEx) grp.dataRegion().pageMemory();
    IgniteWriteAheadLogManager wal = ctx.wal();
    int grpId = grp.groupId();
    long metaId = PageMemory.META_PAGE_ID;
    long metaPage = pageMem.acquirePage(grpId, metaId);
    try {
        long pageAddr = pageMem.writeLock(grpId, metaId, metaPage);
        boolean allocated = false;
        boolean markDirty = false;
        try {
            long metastoreRoot, reuseListRoot;
            PageMetaIOV2 io = (PageMetaIOV2) PageMetaIO.VERSIONS.latest();
            if (PageIO.getType(pageAddr) != PageIO.T_META) {
                PageMetrics metrics = pageMem.metrics().cacheGrpPageMetrics(grpId);
                io.initNewPage(pageAddr, metaId, pageMem.realPageSize(grpId), metrics);
                metastoreRoot = pageMem.allocatePage(grpId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX);
                reuseListRoot = pageMem.allocatePage(grpId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX);
                io.setTreeRoot(pageAddr, metastoreRoot);
                io.setReuseListRoot(pageAddr, reuseListRoot);
                if (isWalDeltaRecordNeeded(pageMem, grpId, metaId, metaPage, wal, null)) {
                    assert io.getType() == PageIO.T_META;
                    wal.log(new MetaPageInitRecord(grpId, metaId, io.getType(), io.getVersion(), metastoreRoot, reuseListRoot));
                }
                allocated = true;
            } else {
                if (io != PageIO.getPageIO(pageAddr)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Upgrade index partition meta page version: [grpId=" + grpId + ", oldVer=" + PagePartitionMetaIO.getVersion(pageAddr) + ", newVer=" + io.getVersion() + ']');
                    }
                    io.upgradePage(pageAddr);
                    markDirty = true;
                }
                metastoreRoot = io.getTreeRoot(pageAddr);
                reuseListRoot = io.getReuseListRoot(pageAddr);
                int encrPageCnt = io.getEncryptedPageCount(pageAddr);
                if (encrPageCnt > 0) {
                    ctx.kernalContext().encryption().setEncryptionState(grp, PageIdAllocator.INDEX_PARTITION, io.getEncryptedPageIndex(pageAddr), encrPageCnt);
                    markDirty = true;
                }
                assert reuseListRoot != 0L;
                if (markDirty && isWalDeltaRecordNeeded(pageMem, grpId, metaId, metaPage, wal, null)) {
                    wal.log(new PageSnapshot(new FullPageId(PageIdAllocator.INDEX_PARTITION, grpId), pageAddr, pageMem.pageSize(), pageMem.realPageSize(grpId)));
                }
            }
            return new Metas(new RootPage(new FullPageId(metastoreRoot, grpId), allocated), new RootPage(new FullPageId(reuseListRoot, grpId), allocated), null, null);
        } finally {
            pageMem.writeUnlock(grpId, metaId, metaPage, null, allocated || markDirty);
        }
    } finally {
        pageMem.releasePage(grpId, metaId, metaPage);
    }
}
Also used : IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) PageMetaIOV2(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIOV2) PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics) MetaPageInitRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) PageSnapshot(org.apache.ignite.internal.pagemem.wal.record.PageSnapshot) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Aggregations

MetaPageInitRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord)7 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)5 PageSnapshot (org.apache.ignite.internal.pagemem.wal.record.PageSnapshot)4 UUID (java.util.UUID)3 CheckpointRecord (org.apache.ignite.internal.pagemem.wal.record.CheckpointRecord)3 DataRecord (org.apache.ignite.internal.pagemem.wal.record.DataRecord)3 MemoryRecoveryRecord (org.apache.ignite.internal.pagemem.wal.record.MemoryRecoveryRecord)3 MetastoreDataRecord (org.apache.ignite.internal.pagemem.wal.record.MetastoreDataRecord)3 DataPageInsertFragmentRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertFragmentRecord)3 DataPageInsertRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageInsertRecord)3 DataPageRemoveRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageRemoveRecord)3 DataPageSetFreeListPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageSetFreeListPageRecord)3 DataPageUpdateRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageUpdateRecord)3 FixCountRecord (org.apache.ignite.internal.pagemem.wal.record.delta.FixCountRecord)3 FixLeftmostChildRecord (org.apache.ignite.internal.pagemem.wal.record.delta.FixLeftmostChildRecord)3 FixRemoveId (org.apache.ignite.internal.pagemem.wal.record.delta.FixRemoveId)3 InitNewPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord)3 MetaPageAddRootRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageAddRootRecord)3 MetaPageCutRootRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageCutRootRecord)3 MetaPageInitRootInlineRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRootInlineRecord)3