Search in sources :

Example 1 with RootPage

use of org.apache.ignite.internal.processors.cache.persistence.RootPage 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 2 with RootPage

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

the class IndexStorageSelfTest method metaAllocation.

/**
 * @throws Exception If failed.
 */
private void metaAllocation() throws Exception {
    PageMemory mem = memory(true);
    int[] cacheIds = new int[] { 1, "partitioned".hashCode(), "replicated".hashCode() };
    Map<Integer, Map<String, RootPage>> allocatedIdxs = new HashMap<>();
    mem.start();
    try {
        final Map<Integer, IndexStorageImpl> storeMap = new HashMap<>();
        for (int i = 0; i < 1_000; i++) {
            int cacheId = cacheIds[i % cacheIds.length];
            Map<String, RootPage> idxMap = allocatedIdxs.get(cacheId);
            if (idxMap == null) {
                idxMap = new HashMap<>();
                allocatedIdxs.put(cacheId, idxMap);
            }
            String idxName;
            do {
                idxName = randomName();
            } while (idxMap.containsKey(idxName));
            IndexStorageImpl metaStore = storeMap.get(cacheId);
            if (metaStore == null) {
                metaStore = new IndexStorageImpl(mem, null, new AtomicLong(), cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX, null, mem.allocatePage(cacheId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX), true);
                storeMap.put(cacheId, metaStore);
            }
            final RootPage rootPage = metaStore.getOrAllocateForTree(idxName);
            assertTrue(rootPage.isAllocated());
            idxMap.put(idxName, rootPage);
        }
        for (int cacheId : cacheIds) {
            Map<String, RootPage> idxMap = allocatedIdxs.get(cacheId);
            for (Map.Entry<String, RootPage> entry : idxMap.entrySet()) {
                String idxName = entry.getKey();
                FullPageId rootPageId = entry.getValue().pageId();
                final RootPage rootPage = storeMap.get(cacheId).getOrAllocateForTree(idxName);
                assertEquals("Invalid root page ID restored [cacheId=" + cacheId + ", idxName=" + idxName + ']', rootPageId, rootPage.pageId());
                assertFalse("Root page already allocated [cacheId=" + cacheId + ", idxName=" + idxName + ']', rootPage.isAllocated());
            }
        }
    } finally {
        mem.stop();
    }
}
Also used : IndexStorageImpl(org.apache.ignite.internal.processors.cache.persistence.IndexStorageImpl) HashMap(java.util.HashMap) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) AtomicLong(java.util.concurrent.atomic.AtomicLong) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) HashMap(java.util.HashMap) Map(java.util.Map) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Aggregations

FullPageId (org.apache.ignite.internal.pagemem.FullPageId)2 RootPage (org.apache.ignite.internal.processors.cache.persistence.RootPage)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)1 MetaPageInitRecord (org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord)1 IndexStorageImpl (org.apache.ignite.internal.processors.cache.persistence.IndexStorageImpl)1 PageMemoryEx (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMemoryEx)1 PagePartitionMetaIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)1