Search in sources :

Example 1 with PagePartitionCountersIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionCountersIO in project ignite by apache.

the class GridCacheOffheapManager method readSharedGroupCacheSizes.

/**
 * Loads cache sizes for all caches in shared group.
 *
 * @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.
 * @return Cache sizes if store belongs to group containing multiple caches and sizes are available in memory. May
 * return null if counter page does not exist.
 * @throws IgniteCheckedException If page memory operation failed.
 */
@Nullable
public static Map<Integer, Long> readSharedGroupCacheSizes(PageSupport pageMem, int grpId, long cntrsPageId) throws IgniteCheckedException {
    if (cntrsPageId == 0L)
        return null;
    Map<Integer, Long> cacheSizes = new HashMap<>();
    long nextId = cntrsPageId;
    while (true) {
        long curId = nextId;
        long curPage = pageMem.acquirePage(grpId, curId);
        try {
            long curAddr = pageMem.readLock(grpId, curId, curPage);
            assert curAddr != 0;
            try {
                PagePartitionCountersIO cntrsIO = PageIO.getPageIO(curAddr);
                if (cntrsIO.readCacheSizes(curAddr, cacheSizes))
                    break;
                nextId = cntrsIO.getNextCountersPageId(curAddr);
                assert nextId != 0;
            } finally {
                pageMem.readUnlock(grpId, curId, curPage);
            }
        } finally {
            pageMem.releasePage(grpId, curId, curPage);
        }
    }
    return cacheSizes;
}
Also used : PagePartitionCountersIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionCountersIO) HashMap(java.util.HashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PagePartitionCountersIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionCountersIO in project ignite by apache.

the class RandomLruPageReplacementPolicy method isStoreMetadataPage.

/**
 * @param absPageAddr Absolute page address
 * @return {@code True} if page is related to partition metadata, which is loaded in saveStoreMetadata().
 */
private static boolean isStoreMetadataPage(long absPageAddr) {
    try {
        long dataAddr = absPageAddr + PAGE_OVERHEAD;
        int type = PageIO.getType(dataAddr);
        int ver = PageIO.getVersion(dataAddr);
        PageIO io = PageIO.getPageIO(type, ver);
        return io instanceof PagePartitionMetaIO || io instanceof PagesListMetaIO || io instanceof PagePartitionCountersIO;
    } catch (IgniteCheckedException ignored) {
        return false;
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) PagePartitionCountersIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionCountersIO) PagesListMetaIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO)

Example 3 with PagePartitionCountersIO

use of org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionCountersIO 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;
}
Also used : PagePartitionCountersIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionCountersIO) PageMetrics(org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)

Aggregations

PagePartitionCountersIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionCountersIO)3 HashMap (java.util.HashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 PagesListMetaIO (org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO)1 PageMetrics (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)1 PageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO)1 PagePartitionMetaIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO)1 Nullable (org.jetbrains.annotations.Nullable)1