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);
}
}
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();
}
}
Aggregations