Search in sources :

Example 1 with PageMetaIO

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

the class GridCacheOffheapManager method addPartitions.

/**
 * @param ctx Context.
 */
private void addPartitions(Context ctx) throws IgniteCheckedException {
    int grpId = grp.groupId();
    PageMemoryEx pageMem = (PageMemoryEx) grp.dataRegion().pageMemory();
    long metaPageId = PageMemory.META_PAGE_ID;
    long metaPage = pageMem.acquirePage(grpId, metaPageId);
    try {
        long metaPageAddr = pageMem.writeLock(grpId, metaPageId, metaPage);
        if (metaPageAddr == 0L) {
            U.warn(log, "Failed to acquire write lock for index meta page [grpId=" + grpId + ", metaPageId=" + metaPageId + ']');
            return;
        }
        boolean changed = false;
        try {
            PageMetaIO metaIo = PageMetaIO.getPageIO(metaPageAddr);
            int pageCnt = this.ctx.pageStore().pages(grpId, PageIdAllocator.INDEX_PARTITION);
            changed = metaIo.setCandidatePageCount(metaPageAddr, pageCnt);
            // Following method doesn't modify page data, it only reads last allocated page count from it.
            addPartition(null, ctx.partitionStatMap(), metaPageAddr, metaIo, grpId, PageIdAllocator.INDEX_PARTITION, pageCnt, -1);
        } finally {
            pageMem.writeUnlock(grpId, metaPageId, metaPage, null, changed);
        }
    } finally {
        pageMem.releasePage(grpId, metaPageId, metaPage);
    }
}
Also used : PageMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)

Example 2 with PageMetaIO

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

the class TxLog method init.

/**
 * @param ctx Kernal context.
 * @throws IgniteCheckedException If failed.
 */
private void init(GridKernalContext ctx) throws IgniteCheckedException {
    String txLogName = TX_LOG_CACHE_NAME + "##Tree";
    DataRegion txLogDataRegion = mgr.dataRegion(TX_LOG_CACHE_NAME);
    GridCacheSharedContext<?, ?> cacheCtx = ctx.cache().context();
    if (CU.isPersistenceEnabled(ctx.config())) {
        String txLogReuseListName = TX_LOG_CACHE_NAME + "##ReuseList";
        mgr.checkpointReadLock();
        try {
            IgniteWriteAheadLogManager wal = cacheCtx.wal();
            PageMemoryEx pageMemory = (PageMemoryEx) txLogDataRegion.pageMemory();
            long metaId = PageMemory.META_PAGE_ID;
            long metaPage = pageMemory.acquirePage(TX_LOG_CACHE_ID, metaId);
            long treeRoot, reuseListRoot;
            boolean isNew = false;
            try {
                long pageAddr = pageMemory.writeLock(TX_LOG_CACHE_ID, metaId, metaPage);
                try {
                    if (PageIO.getType(pageAddr) != PageIO.T_META) {
                        // Initialize new page.
                        PageMetaIO io = PageMetaIOV2.VERSIONS.latest();
                        PageMetrics metrics = txLogDataRegion.metrics().pageMetrics();
                        io.initNewPage(pageAddr, metaId, pageMemory.pageSize(), metrics);
                        treeRoot = pageMemory.allocatePage(TX_LOG_CACHE_ID, INDEX_PARTITION, FLAG_IDX);
                        reuseListRoot = pageMemory.allocatePage(TX_LOG_CACHE_ID, INDEX_PARTITION, FLAG_IDX);
                        assert PageIdUtils.flag(treeRoot) == FLAG_IDX;
                        assert PageIdUtils.flag(reuseListRoot) == FLAG_IDX;
                        io.setTreeRoot(pageAddr, treeRoot);
                        io.setReuseListRoot(pageAddr, reuseListRoot);
                        if (PageHandler.isWalDeltaRecordNeeded(pageMemory, TX_LOG_CACHE_ID, metaId, metaPage, wal, null))
                            assert io.getType() == PageIO.T_META;
                        wal.log(new MetaPageInitRecord(TX_LOG_CACHE_ID, metaId, io.getType(), io.getVersion(), treeRoot, reuseListRoot));
                        isNew = true;
                    } else {
                        PageMetaIO io = PageIO.getPageIO(pageAddr);
                        treeRoot = io.getTreeRoot(pageAddr);
                        reuseListRoot = io.getReuseListRoot(pageAddr);
                        assert PageIdUtils.flag(treeRoot) == FLAG_IDX : U.hexLong(treeRoot) + ", TX_LOG_CACHE_ID=" + TX_LOG_CACHE_ID;
                        assert PageIdUtils.flag(reuseListRoot) == FLAG_IDX : U.hexLong(reuseListRoot) + ", TX_LOG_CACHE_ID=" + TX_LOG_CACHE_ID;
                    }
                } finally {
                    pageMemory.writeUnlock(TX_LOG_CACHE_ID, metaId, metaPage, null, isNew);
                }
            } finally {
                pageMemory.releasePage(TX_LOG_CACHE_ID, metaId, metaPage);
            }
            reuseList = new ReuseListImpl(TX_LOG_CACHE_ID, txLogReuseListName, pageMemory, wal, reuseListRoot, isNew, cacheCtx.diagnostic().pageLockTracker(), ctx, null, FLAG_IDX);
            tree = new TxLogTree(TX_LOG_CACHE_NAME, pageMemory, wal, treeRoot, reuseList, ctx.failure(), isNew, cacheCtx.diagnostic().pageLockTracker());
            ((GridCacheDatabaseSharedManager) mgr).addCheckpointListener(this, txLogDataRegion);
        } finally {
            mgr.checkpointReadUnlock();
        }
    } else {
        PageMemory pageMemory = txLogDataRegion.pageMemory();
        ReuseList reuseList1 = mgr.reuseList(TX_LOG_CACHE_NAME);
        long treeRoot;
        if ((treeRoot = reuseList1.takeRecycledPage()) == 0L)
            treeRoot = pageMemory.allocatePage(TX_LOG_CACHE_ID, INDEX_PARTITION, FLAG_IDX);
        tree = new TxLogTree(txLogName, pageMemory, null, treeRoot, reuseList1, ctx.failure(), true, cacheCtx.diagnostic().pageLockTracker());
    }
}
Also used : PageMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics) MetaPageInitRecord(org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord) ReuseListImpl(org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseListImpl) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) ReuseList(org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList) DataRegion(org.apache.ignite.internal.processors.cache.persistence.DataRegion)

Example 3 with PageMetaIO

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

the class MetaPageInitRecord method applyDelta.

/**
 * {@inheritDoc}
 */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
    PageMetaIO io = PageMetaIO.getPageIO(ioType, ioVer);
    PageMetrics metrics = pageMem.metrics().cacheGrpPageMetrics(groupId());
    io.initNewPage(pageAddr, newPageId, pageMem.realPageSize(groupId()), metrics);
    io.setTreeRoot(pageAddr, treeRoot);
    io.setReuseListRoot(pageAddr, reuseListRoot);
}
Also used : PageMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO) PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)

Example 4 with PageMetaIO

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

the class MetaPageUpdateLastSuccessfulFullSnapshotId method applyDelta.

/**
 * {@inheritDoc}
 */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
    PageMetaIO io = PageMetaIO.VERSIONS.forPage(pageAddr);
    io.setLastSuccessfulFullSnapshotId(pageAddr, lastSuccessfulFullSnapshotId);
}
Also used : PageMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO)

Example 5 with PageMetaIO

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

the class MetaPageUpdateLastAllocatedIndex method applyDelta.

/**
 * {@inheritDoc}
 */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
    int type = PageIO.getType(pageAddr);
    assert type == PageIO.T_META || type == PageIO.T_PART_META;
    PageMetaIO io = PageIO.getPageIO(type, PageIO.getVersion(pageAddr));
    io.setLastAllocatedPageCount(pageAddr, lastAllocatedIdx);
}
Also used : PageMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO)

Aggregations

PageMetaIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PageMetaIO)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)2 PageMetrics (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)2 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 Integer.parseInt (java.lang.Integer.parseInt)1 String.format (java.lang.String.format)1 ByteBuffer (java.nio.ByteBuffer)1 FileChannel (java.nio.channels.FileChannel)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1