use of org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord in project ignite by apache.
the class MetaStorage method getOrAllocateMetas.
/**
* Initializing the selected partition for use as MetaStorage
*
* @param partId Partition id.
* @return true if the partion is empty
*/
private boolean getOrAllocateMetas(int partId) throws IgniteCheckedException {
empty = false;
PageMemoryEx pageMem = (PageMemoryEx) dataRegion.pageMemory();
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 true;
}
PagePartitionMetaIO io = PageIO.getPageIO(pageAddr);
long treeRoot = io.getTreeRoot(pageAddr);
long reuseListRoot = io.getReuseListRoot(pageAddr);
checkRootsPageIdFlag(treeRoot, reuseListRoot);
this.treeRoot = new RootPage(new FullPageId(treeRoot, METASTORAGE_CACHE_ID), false);
this.reuseListRoot = new RootPage(new FullPageId(reuseListRoot, 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();
PageMetrics metrics = pageMem.metrics().cacheGrpPageMetrics(METASTORAGE_CACHE_ID);
// MetaStorage never encrypted so realPageSize == pageSize.
io.initNewPage(pageAddr, partMetaId, pageMem.pageSize(), metrics);
treeRoot = pageMem.allocatePage(METASTORAGE_CACHE_ID, partId, FLAG_AUX);
reuseListRoot = pageMem.allocatePage(METASTORAGE_CACHE_ID, partId, FLAG_AUX);
assert PageIdUtils.flag(treeRoot) == FLAG_AUX;
assert PageIdUtils.flag(reuseListRoot) == FLAG_AUX;
io.setTreeRoot(pageAddr, treeRoot);
io.setReuseListRoot(pageAddr, reuseListRoot);
if (PageHandler.isWalDeltaRecordNeeded(pageMem, METASTORAGE_CACHE_ID, partMetaId, partMetaPage, wal, null)) {
assert io.getType() == PageIO.T_PART_META;
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));
checkRootsPageIdFlag(treeRoot, reuseListRoot);
}
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);
}
return false;
}
use of org.apache.ignite.internal.pagemem.wal.record.delta.MetaPageInitRecord in project ignite by apache.
the class GridCacheOffheapManager method getOrAllocateCacheMetas.
/**
* @return Meta root pages info.
* @throws IgniteCheckedException If failed.
*/
private Metas getOrAllocateCacheMetas() throws IgniteCheckedException {
PageMemoryEx pageMem = (PageMemoryEx) grp.dataRegion().pageMemory();
IgniteWriteAheadLogManager wal = ctx.wal();
int grpId = grp.groupId();
long metaId = PageMemory.META_PAGE_ID;
long metaPage = pageMem.acquirePage(grpId, metaId);
try {
long pageAddr = pageMem.writeLock(grpId, metaId, metaPage);
boolean allocated = false;
boolean markDirty = false;
try {
long metastoreRoot, reuseListRoot;
PageMetaIOV2 io = (PageMetaIOV2) PageMetaIO.VERSIONS.latest();
if (PageIO.getType(pageAddr) != PageIO.T_META) {
PageMetrics metrics = pageMem.metrics().cacheGrpPageMetrics(grpId);
io.initNewPage(pageAddr, metaId, pageMem.realPageSize(grpId), metrics);
metastoreRoot = pageMem.allocatePage(grpId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX);
reuseListRoot = pageMem.allocatePage(grpId, PageIdAllocator.INDEX_PARTITION, PageMemory.FLAG_IDX);
io.setTreeRoot(pageAddr, metastoreRoot);
io.setReuseListRoot(pageAddr, reuseListRoot);
if (isWalDeltaRecordNeeded(pageMem, grpId, metaId, metaPage, wal, null)) {
assert io.getType() == PageIO.T_META;
wal.log(new MetaPageInitRecord(grpId, metaId, io.getType(), io.getVersion(), metastoreRoot, reuseListRoot));
}
allocated = true;
} else {
if (io != PageIO.getPageIO(pageAddr)) {
if (log.isDebugEnabled()) {
log.debug("Upgrade index partition meta page version: [grpId=" + grpId + ", oldVer=" + PagePartitionMetaIO.getVersion(pageAddr) + ", newVer=" + io.getVersion() + ']');
}
io.upgradePage(pageAddr);
markDirty = true;
}
metastoreRoot = io.getTreeRoot(pageAddr);
reuseListRoot = io.getReuseListRoot(pageAddr);
int encrPageCnt = io.getEncryptedPageCount(pageAddr);
if (encrPageCnt > 0) {
ctx.kernalContext().encryption().setEncryptionState(grp, PageIdAllocator.INDEX_PARTITION, io.getEncryptedPageIndex(pageAddr), encrPageCnt);
markDirty = true;
}
assert reuseListRoot != 0L;
if (markDirty && isWalDeltaRecordNeeded(pageMem, grpId, metaId, metaPage, wal, null)) {
wal.log(new PageSnapshot(new FullPageId(PageIdAllocator.INDEX_PARTITION, grpId), pageAddr, pageMem.pageSize(), pageMem.realPageSize(grpId)));
}
}
return new Metas(new RootPage(new FullPageId(metastoreRoot, grpId), allocated), new RootPage(new FullPageId(reuseListRoot, grpId), allocated), null, null);
} finally {
pageMem.writeUnlock(grpId, metaId, metaPage, null, allocated || markDirty);
}
} finally {
pageMem.releasePage(grpId, metaId, metaPage);
}
}
Aggregations