Search in sources :

Example 1 with MetadataStorage

use of org.apache.ignite.internal.processors.cache.database.MetadataStorage in project ignite by apache.

the class MetadataStorageSelfTest 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, MetadataStorage> 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));
            MetadataStorage metaStore = storeMap.get(cacheId);
            if (metaStore == null) {
                metaStore = new MetadataStorage(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 : HashMap(java.util.HashMap) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) AtomicLong(java.util.concurrent.atomic.AtomicLong) RootPage(org.apache.ignite.internal.processors.cache.database.RootPage) MetadataStorage(org.apache.ignite.internal.processors.cache.database.MetadataStorage) HashMap(java.util.HashMap) Map(java.util.Map) FullPageId(org.apache.ignite.internal.pagemem.FullPageId)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)1 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)1 MetadataStorage (org.apache.ignite.internal.processors.cache.database.MetadataStorage)1 RootPage (org.apache.ignite.internal.processors.cache.database.RootPage)1