Search in sources :

Example 16 with PagesListNodeIO

use of org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO in project ignite by apache.

the class PagesListRemovePageRecord method applyDelta.

/**
 * {@inheritDoc}
 */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
    PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
    boolean rmvd = io.removePage(pageAddr, rmvdPageId);
    assert rmvd;
}
Also used : PagesListNodeIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO)

Example 17 with PagesListNodeIO

use of org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO in project ignite by apache.

the class PagesListSetPreviousRecord method applyDelta.

/**
 * {@inheritDoc}
 */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
    PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
    io.setPreviousId(pageAddr, prevPageId);
}
Also used : PagesListNodeIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO)

Example 18 with PagesListNodeIO

use of org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO in project ignite by apache.

the class PagesList method merge.

/**
 * @param pageId Page ID.
 * @param page Page pointer.
 * @param nextId Next page ID.
 * @param bucket Bucket index.
 * @param statHolder Statistics holder to track IO operations.
 * @return Page ID to recycle.
 * @throws IgniteCheckedException If failed.
 */
private long merge(final long pageId, final long page, long nextId, int bucket, IoStatisticsHolder statHolder) throws IgniteCheckedException {
    // We should do mergeNoNext then.
    assert nextId != 0;
    // Lock all the pages in correct order (from next to previous) and do the merge in retry loop.
    for (; ; ) {
        final long curId = nextId;
        final long curPage = curId == 0L ? 0L : acquirePage(curId, statHolder);
        try {
            boolean write = false;
            // Explicit check.
            final long curAddr = curPage == 0L ? 0L : writeLock(curId, curPage);
            // Explicit check.
            final long pageAddr = writeLock(pageId, page);
            if (pageAddr == 0L) {
                if (// Unlock next page if needed.
                curAddr != 0L)
                    writeUnlock(curId, curPage, curAddr, false);
                // Someone has merged or taken our empty page concurrently. Nothing to do here.
                return 0L;
            }
            try {
                PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
                if (!io.isEmpty(pageAddr))
                    // No need to merge anymore.
                    return 0L;
                // Check if we see a consistent state of the world.
                if (io.getNextId(pageAddr) == curId && (curId == 0L) == (curAddr == 0L)) {
                    long recycleId = doMerge(pageId, page, pageAddr, io, curId, curPage, curAddr, bucket, statHolder);
                    write = true;
                    // Done.
                    return recycleId;
                }
                // Reread next page ID and go for retry.
                nextId = io.getNextId(pageAddr);
            } finally {
                if (curAddr != 0L)
                    writeUnlock(curId, curPage, curAddr, write);
                writeUnlock(pageId, page, pageAddr, write);
            }
        } finally {
            if (curPage != 0L)
                releasePage(curId, curPage);
        }
    }
}
Also used : PagesListNodeIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO)

Example 19 with PagesListNodeIO

use of org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO in project ignite by apache.

the class PagesList method storedPagesCount.

/**
 * !!! For tests only, does not provide any correctness guarantees for concurrent access.
 *
 * @param bucket Bucket index.
 * @return Number of pages stored in this list.
 * @throws IgniteCheckedException If failed.
 */
protected final long storedPagesCount(int bucket) throws IgniteCheckedException {
    long res = 0;
    Stripe[] tails = getBucket(bucket);
    if (tails != null) {
        for (Stripe tail : tails) {
            long tailId = tail.tailId;
            while (tailId != 0L) {
                final long pageId = tailId;
                final long page = acquirePage(pageId, IoStatisticsHolderNoOp.INSTANCE);
                try {
                    long pageAddr = readLock(pageId, page);
                    assert pageAddr != 0L;
                    try {
                        PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
                        int cnt = io.getCount(pageAddr);
                        assert cnt >= 0;
                        res += cnt;
                        tailId = io.getPreviousId(pageAddr);
                        // In reuse bucket the page itself can be used as a free page.
                        if (isReuseBucket(bucket) && tailId != 0L)
                            res++;
                    } finally {
                        readUnlock(pageId, page, pageAddr);
                    }
                } finally {
                    releasePage(pageId, page);
                }
            }
        }
    }
    assert res == bucketsSize.get(bucket) : "Wrong bucket size counter [exp=" + res + ", cntr=" + bucketsSize.get(bucket) + ']';
    return res;
}
Also used : PagesListNodeIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO)

Example 20 with PagesListNodeIO

use of org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO in project ignite by apache.

the class IgniteIndexReader method getPageList.

/**
 * Get single page list.
 *
 * @param pageListStartId Id of the start page of the page list.
 * @param pageStat Page types statistics.
 * @return List of page ids.
 */
private List<Long> getPageList(long pageListStartId, Map<Class, Long> pageStat) {
    List<Long> res = new LinkedList<>();
    long nextNodeId = pageListStartId;
    ByteBuffer nodeBuf = allocateBuffer(pageSize);
    ByteBuffer pageBuf = allocateBuffer(pageSize);
    long nodeAddr = bufferAddress(nodeBuf);
    long pageAddr = bufferAddress(pageBuf);
    try {
        while (nextNodeId != 0) {
            try {
                nodeBuf.rewind();
                readPage(idxStore, nextNodeId, nodeBuf);
                PagesListNodeIO io = PageIO.getPageIO(nodeAddr);
                for (int i = 0; i < io.getCount(nodeAddr); i++) {
                    pageBuf.rewind();
                    long pageId = normalizePageId(io.getAt(nodeAddr, i));
                    res.add(pageId);
                    readPage(idxStore, pageId, pageBuf);
                    PageIO pageIO = PageIO.getPageIO(pageAddr);
                    pageStat.compute(pageIO.getClass(), (k, v) -> v == null ? 1 : v + 1);
                }
                nextNodeId = io.getNextId(nodeAddr);
            } catch (IgniteCheckedException e) {
                throw new IgniteException(e.getMessage(), e);
            }
        }
    } finally {
        freeBuffer(nodeBuf);
        freeBuffer(pageBuf);
    }
    return res;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) AtomicLong(java.util.concurrent.atomic.AtomicLong) PagesListNodeIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) AbstractDataPageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.AbstractDataPageIO)

Aggregations

PagesListNodeIO (org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO)20 PagesListRemovePageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListRemovePageRecord)4 PagesListSetPreviousRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetPreviousRecord)4 AbstractDataPageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.AbstractDataPageIO)3 PageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO)3 DataPageSetFreeListPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageSetFreeListPageRecord)2 PagesListSetNextRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 InitNewPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord)1 PagesListInitNewPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListInitNewPageRecord)1 PagesListMetaIO (org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO)1 PageMetrics (org.apache.ignite.internal.processors.cache.persistence.pagemem.PageMetrics)1 GridLongList (org.apache.ignite.internal.util.GridLongList)1