use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.
the class FilePageStoreManager method initializeForMetastorage.
/**
* {@inheritDoc}
*/
@Override
public void initializeForMetastorage() throws IgniteCheckedException {
assert storeWorkDir != null;
int grpId = MetaStorage.METASTORAGE_CACHE_ID;
if (!idxCacheStores.containsKey(grpId)) {
DataRegion dataRegion = cctx.database().dataRegion(GridCacheDatabaseSharedManager.METASTORE_DATA_REGION_NAME);
PageMetrics pageMetrics = dataRegion.metrics().cacheGrpPageMetrics(grpId);
CacheStoreHolder holder = initDir(new File(storeWorkDir, MetaStorage.METASTORAGE_DIR_NAME), grpId, MetaStorage.METASTORAGE_PARTITIONS.size(), pageMetrics, false);
CacheStoreHolder old = idxCacheStores.put(grpId, holder);
assert old == null : "Non-null old store holder for metastorage";
}
}
use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics 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.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.
the class MvccProcessorImpl method txLogPageStoreInit.
/**
* @param mgr Database shared manager.
* @throws IgniteCheckedException If failed.
*/
private void txLogPageStoreInit(IgniteCacheDatabaseSharedManager mgr) throws IgniteCheckedException {
assert CU.isPersistenceEnabled(ctx.config());
DataRegion dataRegion = mgr.dataRegion(TX_LOG_CACHE_NAME);
PageMetrics pageMetrics = dataRegion.metrics().cacheGrpPageMetrics(TX_LOG_CACHE_ID);
// noinspection ConstantConditions
ctx.cache().context().pageStore().initialize(TX_LOG_CACHE_ID, 0, TX_LOG_CACHE_NAME, pageMetrics);
}
use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics in project ignite by apache.
the class GridCacheOffheapManager method writeSharedGroupCacheSizes.
/**
* Saves cache sizes for all caches in shared group. Unconditionally marks pages as dirty.
*
* @param pageMem page memory to perform operations on pages.
* @param grpId Cache group ID.
* @param cntrsPageId Counters page ID, if zero is provided that means no counters page exist.
* @param partId Partition ID.
* @param sizes Cache sizes of all caches in group. Not null.
* @return new counter page Id. Same as {@code cntrsPageId} or new value if cache size pages were initialized.
* @throws IgniteCheckedException if page memory operation failed.
*/
public static long writeSharedGroupCacheSizes(PageMemory pageMem, int grpId, long cntrsPageId, int partId, Map<Integer, Long> sizes) throws IgniteCheckedException {
byte[] data = PagePartitionCountersIO.VERSIONS.latest().serializeCacheSizes(sizes);
int items = data.length / PagePartitionCountersIO.ITEM_SIZE;
boolean init = cntrsPageId == 0;
if (init && !sizes.isEmpty())
cntrsPageId = pageMem.allocatePage(grpId, partId, PageIdAllocator.FLAG_AUX);
long nextId = cntrsPageId;
int written = 0;
PageMetrics metrics = pageMem.metrics().cacheGrpPageMetrics(grpId);
while (written != items) {
long curId = nextId;
long curPage = pageMem.acquirePage(grpId, curId);
try {
long curAddr = pageMem.writeLock(grpId, curId, curPage);
assert curAddr != 0;
try {
PagePartitionCountersIO partCntrIo;
if (init) {
partCntrIo = PagePartitionCountersIO.VERSIONS.latest();
partCntrIo.initNewPage(curAddr, curId, pageMem.realPageSize(grpId), metrics);
} else
partCntrIo = PageIO.getPageIO(curAddr);
written += partCntrIo.writeCacheSizes(pageMem.realPageSize(grpId), curAddr, data, written);
nextId = partCntrIo.getNextCountersPageId(curAddr);
if (written != items && (init = nextId == 0)) {
// allocate new counters page
nextId = pageMem.allocatePage(grpId, partId, PageIdAllocator.FLAG_AUX);
partCntrIo.setNextCountersPageId(curAddr, nextId);
}
} finally {
// Write full page
pageMem.writeUnlock(grpId, curId, curPage, Boolean.TRUE, true);
}
} finally {
pageMem.releasePage(grpId, curId, curPage);
}
}
return cntrsPageId;
}
use of org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics 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