Search in sources :

Example 11 with PagesListNodeIO

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

the class PagesList method fairMerge.

/**
 * Link previous and next to each other.
 * @param prevId Previous Previous page ID.
 * @param pageId Page ID.
 * @param nextId Next page ID.
 * @param nextPage Next page absolute pointer.
 * @param nextAddr Next page address.
 * @throws IgniteCheckedException If failed.
 */
private void fairMerge(final long prevId, long pageId, long nextId, long nextPage, long nextAddr) throws IgniteCheckedException {
    long prevPage = acquirePage(prevId);
    try {
        // No check, we keep a reference.
        final long prevAddr = writeLock(prevId, prevPage);
        assert prevAddr != 0L;
        try {
            PagesListNodeIO prevIO = PagesListNodeIO.VERSIONS.forPage(prevAddr);
            PagesListNodeIO nextIO = PagesListNodeIO.VERSIONS.forPage(nextAddr);
            // These references must be updated at the same time in write locks.
            assert prevIO.getNextId(prevAddr) == pageId;
            assert nextIO.getPreviousId(nextAddr) == pageId;
            prevIO.setNextId(prevAddr, nextId);
            if (needWalDeltaRecord(prevId, prevPage, null))
                wal.log(new PagesListSetNextRecord(grpId, prevId, nextId));
            nextIO.setPreviousId(nextAddr, prevId);
            if (needWalDeltaRecord(nextId, nextPage, null))
                wal.log(new PagesListSetPreviousRecord(grpId, nextId, prevId));
        } finally {
            writeUnlock(prevId, prevPage, prevAddr, true);
        }
    } finally {
        releasePage(prevId, prevPage);
    }
}
Also used : PagesListSetPreviousRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetPreviousRecord) PagesListNodeIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO) PagesListSetNextRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord)

Example 12 with PagesListNodeIO

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

the class PagesList method removeDataPage.

/**
 * @param dataId Data page ID.
 * @param dataPage Data page pointer.
 * @param dataAddr Data page address.
 * @param dataIO Data page IO.
 * @param bucket Bucket index.
 * @throws IgniteCheckedException If failed.
 * @return {@code True} if page was removed.
 */
protected final boolean removeDataPage(final long dataId, final long dataPage, final long dataAddr, AbstractDataPageIO dataIO, int bucket) throws IgniteCheckedException {
    final long pageId = dataIO.getFreeListPageId(dataAddr);
    assert pageId != 0;
    final long page = acquirePage(pageId);
    try {
        long nextId;
        long recycleId = 0L;
        // Explicit check.
        long pageAddr = writeLock(pageId, page);
        if (pageAddr == 0L)
            return false;
        boolean rmvd = false;
        try {
            PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
            rmvd = io.removePage(pageAddr, dataId);
            if (!rmvd)
                return false;
            decrementBucketSize(bucket);
            if (needWalDeltaRecord(pageId, page, null))
                wal.log(new PagesListRemovePageRecord(grpId, pageId, dataId));
            // Reset free list page ID.
            dataIO.setFreeListPageId(dataAddr, 0L);
            if (needWalDeltaRecord(dataId, dataPage, null))
                wal.log(new DataPageSetFreeListPageRecord(grpId, dataId, 0L));
            if (!io.isEmpty(pageAddr))
                // In optimistic case we still have something in the page and can leave it as is.
                return true;
            // If the page is empty, we have to try to drop it and link next and previous with each other.
            nextId = io.getNextId(pageAddr);
            // because if we will need to lock previous page, the locking order will be already correct.
            if (nextId == 0L) {
                long prevId = io.getPreviousId(pageAddr);
                recycleId = mergeNoNext(pageId, page, pageAddr, prevId, bucket);
            }
        } finally {
            writeUnlock(pageId, page, pageAddr, rmvd);
        }
        // Perform a fair merge after lock release (to have a correct locking order).
        if (nextId != 0L)
            recycleId = merge(pageId, page, nextId, bucket);
        if (recycleId != 0L)
            reuseList.addForRecycle(new SingletonReuseBag(recycleId));
        return true;
    } finally {
        releasePage(pageId, page);
    }
}
Also used : DataPageSetFreeListPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageSetFreeListPageRecord) PagesListNodeIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO) PagesListRemovePageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListRemovePageRecord)

Example 13 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);
                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[bucket].get() : "Wrong bucket size counter [exp=" + res + ", cntr=" + bucketsSize[bucket].get() + ']';
    return res;
}
Also used : PagesListNodeIO(org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO)

Aggregations

PagesListNodeIO (org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListNodeIO)13 PagesListRemovePageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListRemovePageRecord)2 PagesListSetPreviousRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetPreviousRecord)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 DataPageSetFreeListPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageSetFreeListPageRecord)1 InitNewPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.InitNewPageRecord)1 PagesListInitNewPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListInitNewPageRecord)1 PagesListSetNextRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord)1 PagesListMetaIO (org.apache.ignite.internal.processors.cache.persistence.freelist.io.PagesListMetaIO)1 AbstractDataPageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.AbstractDataPageIO)1 PageIO (org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO)1 GridLongList (org.apache.ignite.internal.util.GridLongList)1