Search in sources :

Example 1 with DataPagePayload

use of org.apache.ignite.internal.processors.cache.database.tree.io.DataPagePayload in project ignite by apache.

the class CacheDataRowAdapter method initFromLink.

/**
     * Read row from data pages.
     * Can be called with cctx == null, if cache instance is unknown, but its ID is stored in the data row.
     *
     * @param cctx Cctx.
     * @param sharedCtx Shared context.
     * @param pageMem Page memory.
     * @param rowData Row data.
     */
public final void initFromLink(@Nullable GridCacheContext<?, ?> cctx, GridCacheSharedContext<?, ?> sharedCtx, PageMemory pageMem, RowData rowData) throws IgniteCheckedException {
    assert link != 0 : "link";
    assert key == null : "key";
    CacheObjectContext coctx = null;
    if (cctx != null) {
        cacheId = cctx.memoryPolicy().config().getPageEvictionMode() == DataPageEvictionMode.DISABLED ? cctx.cacheId() : // Force cacheId reading for evictable memory policies.
        0;
        coctx = cctx.cacheObjectContext();
    }
    long nextLink = link;
    IncompleteObject<?> incomplete = null;
    boolean first = true;
    do {
        final long pageId = pageId(nextLink);
        final long page = pageMem.acquirePage(cacheId, pageId);
        try {
            // Non-empty data page must not be recycled.
            long pageAddr = pageMem.readLock(cacheId, pageId, page);
            assert pageAddr != 0L : nextLink;
            try {
                DataPageIO io = DataPageIO.VERSIONS.forPage(pageAddr);
                DataPagePayload data = io.readPayload(pageAddr, itemId(nextLink), pageMem.pageSize());
                nextLink = data.nextLink();
                if (first) {
                    if (nextLink == 0) {
                        // Fast path for a single page row.
                        readFullRow(sharedCtx, coctx, pageAddr + data.offset(), rowData);
                        return;
                    }
                    first = false;
                }
                ByteBuffer buf = pageMem.pageBuffer(pageAddr);
                buf.position(data.offset());
                buf.limit(data.offset() + data.payloadSize());
                boolean keyOnly = rowData == RowData.KEY_ONLY;
                incomplete = readFragment(sharedCtx, coctx, buf, keyOnly, incomplete);
                if (keyOnly && key != null)
                    return;
            } finally {
                pageMem.readUnlock(cacheId, pageId, page);
            }
        } finally {
            pageMem.releasePage(cacheId, pageId, page);
        }
    } while (nextLink != 0);
    assert isReady() : "ready";
}
Also used : DataPageIO(org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO) DataPagePayload(org.apache.ignite.internal.processors.cache.database.tree.io.DataPagePayload) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)1 DataPageIO (org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO)1 DataPagePayload (org.apache.ignite.internal.processors.cache.database.tree.io.DataPagePayload)1