Search in sources :

Example 1 with PageMemoryEx

use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx in project ignite by apache.

the class IgnitePdsCheckpointSimulationWithRealCpDisabledTest method testDirtyFlag.

/**
 * @throws Exception if failed.
 */
public void testDirtyFlag() throws Exception {
    IgniteEx ig = startGrid(0);
    ig.active(true);
    GridCacheSharedContext<Object, Object> shared = ig.context().cache().context();
    int cacheId = shared.cache().cache(cacheName).context().cacheId();
    GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) shared.database();
    // Disable integrated checkpoint thread.
    dbMgr.enableCheckpoints(false);
    PageMemoryEx mem = (PageMemoryEx) dbMgr.dataRegion(null).pageMemory();
    FullPageId[] pageIds = new FullPageId[100];
    DummyPageIO pageIO = new DummyPageIO();
    ig.context().cache().context().database().checkpointReadLock();
    try {
        for (int i = 0; i < pageIds.length; i++) pageIds[i] = new FullPageId(mem.allocatePage(cacheId, 0, PageIdAllocator.FLAG_DATA), cacheId);
        for (FullPageId fullId : pageIds) {
            long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
            try {
                // page is dirty right after allocation
                assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
                long pageAddr = mem.writeLock(fullId.groupId(), fullId.pageId(), page);
                try {
                    pageIO.initNewPage(pageAddr, fullId.pageId(), mem.pageSize());
                    assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
                } finally {
                    mem.writeUnlock(fullId.groupId(), fullId.pageId(), page, null, true);
                }
                assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
            } finally {
                mem.releasePage(fullId.groupId(), fullId.pageId(), page);
            }
        }
    } finally {
        ig.context().cache().context().database().checkpointReadUnlock();
    }
    Collection<FullPageId> cpPages = mem.beginCheckpoint();
    ig.context().cache().context().database().checkpointReadLock();
    try {
        for (FullPageId fullId : pageIds) {
            assertTrue(cpPages.contains(fullId));
            ByteBuffer buf = ByteBuffer.allocate(mem.pageSize());
            long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
            try {
                assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
                long pageAddr = mem.writeLock(fullId.groupId(), fullId.pageId(), page);
                try {
                    assertFalse(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
                    for (int i = PageIO.COMMON_HEADER_END; i < mem.pageSize(); i++) PageUtils.putByte(pageAddr, i, (byte) 1);
                } finally {
                    mem.writeUnlock(fullId.groupId(), fullId.pageId(), page, null, true);
                }
                assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
                buf.rewind();
                mem.getForCheckpoint(fullId, buf, null);
                buf.position(PageIO.COMMON_HEADER_END);
                while (buf.hasRemaining()) assertEquals((byte) 0, buf.get());
            } finally {
                mem.releasePage(fullId.groupId(), fullId.pageId(), page);
            }
        }
    } finally {
        ig.context().cache().context().database().checkpointReadUnlock();
    }
    mem.finishCheckpoint();
    for (FullPageId fullId : pageIds) {
        long page = mem.acquirePage(fullId.groupId(), fullId.pageId());
        try {
            assertTrue(mem.isDirty(fullId.groupId(), fullId.pageId(), page));
        } finally {
            mem.releasePage(fullId.groupId(), fullId.pageId(), page);
        }
    }
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) DummyPageIO(org.apache.ignite.internal.processors.cache.persistence.DummyPageIO) ByteBuffer(java.nio.ByteBuffer) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Example 2 with PageMemoryEx

use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx 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 PageMemoryEx

use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx 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 PageMemoryEx

use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx in project ignite by apache.

the class GridCacheDatabaseSharedManager method getPageMemoryForCacheGroup.

/**
 * Obtains PageMemory reference from cache descriptor instead of cache context.
 *
 * @param grpId Cache group id.
 * @return PageMemoryEx instance.
 * @throws IgniteCheckedException if no DataRegion is configured for a name obtained from cache descriptor.
 */
private PageMemoryEx getPageMemoryForCacheGroup(int grpId) throws IgniteCheckedException {
    // TODO IGNITE-5075: cache descriptor can be removed.
    GridCacheSharedContext sharedCtx = context();
    CacheGroupDescriptor desc = sharedCtx.cache().cacheGroupDescriptors().get(grpId);
    if (desc == null)
        throw new IgniteCheckedException("Failed to find cache group descriptor [grpId=" + grpId + ']');
    String memPlcName = desc.config().getDataRegionName();
    return (PageMemoryEx) sharedCtx.database().dataRegion(memPlcName).pageMemory();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheGroupDescriptor(org.apache.ignite.internal.processors.cache.CacheGroupDescriptor) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext)

Example 5 with PageMemoryEx

use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx in project ignite by apache.

the class GridCacheDatabaseSharedManager method finalizeCheckpointOnRecovery.

/**
 * @throws IgniteCheckedException If failed.
 */
private void finalizeCheckpointOnRecovery(long cpTs, UUID cpId, WALPointer walPtr) throws IgniteCheckedException {
    assert cpTs != 0;
    ByteBuffer tmpWriteBuf = ByteBuffer.allocateDirect(pageSize());
    long start = System.currentTimeMillis();
    Collection<DataRegion> memPolicies = context().database().dataRegions();
    List<IgniteBiTuple<PageMemory, Collection<FullPageId>>> cpEntities = new ArrayList<>(memPolicies.size());
    for (DataRegion memPlc : memPolicies) {
        if (memPlc.config().isPersistenceEnabled()) {
            PageMemoryEx pageMem = (PageMemoryEx) memPlc.pageMemory();
            cpEntities.add(new IgniteBiTuple<PageMemory, Collection<FullPageId>>(pageMem, (pageMem).beginCheckpoint()));
        }
    }
    tmpWriteBuf.order(ByteOrder.nativeOrder());
    // Identity stores set.
    Collection<PageStore> updStores = new HashSet<>();
    int cpPagesCnt = 0;
    for (IgniteBiTuple<PageMemory, Collection<FullPageId>> e : cpEntities) {
        PageMemoryEx pageMem = (PageMemoryEx) e.get1();
        Collection<FullPageId> cpPages = e.get2();
        cpPagesCnt += cpPages.size();
        for (FullPageId fullId : cpPages) {
            tmpWriteBuf.rewind();
            Integer tag = pageMem.getForCheckpoint(fullId, tmpWriteBuf, null);
            if (tag != null) {
                tmpWriteBuf.rewind();
                PageStore store = storeMgr.writeInternal(fullId.groupId(), fullId.pageId(), tmpWriteBuf, tag, true);
                tmpWriteBuf.rewind();
                updStores.add(store);
            }
        }
    }
    long written = U.currentTimeMillis();
    for (PageStore updStore : updStores) updStore.sync();
    long fsync = U.currentTimeMillis();
    for (IgniteBiTuple<PageMemory, Collection<FullPageId>> e : cpEntities) ((PageMemoryEx) e.get1()).finishCheckpoint();
    writeCheckpointEntry(tmpWriteBuf, cpTs, cpId, walPtr, null, CheckpointEntryType.END);
    cctx.pageStore().finishRecover();
    if (log.isInfoEnabled())
        log.info(String.format("Checkpoint finished [cpId=%s, pages=%d, markPos=%s, " + "pagesWrite=%dms, fsync=%dms, total=%dms]", cpId, cpPagesCnt, walPtr, written - start, fsync - written, fsync - start));
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) PageStore(org.apache.ignite.internal.pagemem.store.PageStore) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) ByteBuffer(java.nio.ByteBuffer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Collection(java.util.Collection) PageMemoryEx(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) HashSet(java.util.HashSet)

Aggregations

PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)18 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)8 PagePartitionMetaIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 ByteBuffer (java.nio.ByteBuffer)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 HashMap (java.util.HashMap)4 WALIterator (org.apache.ignite.internal.pagemem.wal.WALIterator)4 WALPointer (org.apache.ignite.internal.pagemem.wal.WALPointer)4 WALRecord (org.apache.ignite.internal.pagemem.wal.record.WALRecord)4 PageDeltaRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PageDeltaRecord)4 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)4 GridDhtPartitionState (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionState)4 File (java.io.File)3 RandomAccessFile (java.io.RandomAccessFile)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)3 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)3 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)3