Search in sources :

Example 1 with PagesListNodeIO

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

the class PagesListSetNextRecord method applyDelta.

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

Example 2 with PagesListNodeIO

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

the class PagesListAddPageRecord method applyDelta.

/** {@inheritDoc} */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
    PagesListNodeIO io = PagesListNodeIO.VERSIONS.forPage(pageAddr);
    int cnt = io.addPage(pageAddr, dataPageId, pageMem.pageSize());
    assert cnt >= 0 : cnt;
}
Also used : PagesListNodeIO(org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO)

Example 3 with PagesListNodeIO

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

the class PagesListInitNewPageRecord method applyDelta.

/** {@inheritDoc} */
@Override
public void applyDelta(PageMemory pageMem, long pageAddr) throws IgniteCheckedException {
    PagesListNodeIO io = PageIO.getPageIO(PageIO.T_PAGE_LIST_NODE, ioVer);
    io.initNewPage(pageAddr, pageId(), pageMem.pageSize());
    io.setPreviousId(pageAddr, prevPageId);
    if (addDataPageId != 0L) {
        int cnt = io.addPage(pageAddr, addDataPageId, pageMem.pageSize());
        assert cnt == 0 : cnt;
    }
}
Also used : PagesListNodeIO(org.apache.ignite.internal.processors.cache.database.freelist.io.PagesListNodeIO)

Example 4 with PagesListNodeIO

use of org.apache.ignite.internal.processors.cache.database.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, DataPageIO 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;
            bucketsSize[bucket].decrementAndGet();
            if (needWalDeltaRecord(pageId, page, null))
                wal.log(new PagesListRemovePageRecord(cacheId, pageId, dataId));
            // Reset free list page ID.
            dataIO.setFreeListPageId(dataAddr, 0L);
            if (needWalDeltaRecord(dataId, dataPage, null))
                wal.log(new DataPageSetFreeListPageRecord(cacheId, 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.database.freelist.io.PagesListNodeIO) PagesListRemovePageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListRemovePageRecord)

Example 5 with PagesListNodeIO

use of org.apache.ignite.internal.processors.cache.database.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(cacheId, prevId, nextId));
            nextIO.setPreviousId(nextAddr, prevId);
            if (needWalDeltaRecord(nextId, nextPage, null))
                wal.log(new PagesListSetPreviousRecord(cacheId, 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.database.freelist.io.PagesListNodeIO) PagesListSetNextRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord)

Aggregations

PagesListNodeIO (org.apache.ignite.internal.processors.cache.database.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.database.freelist.io.PagesListMetaIO)1 DataPageIO (org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO)1 PageIO (org.apache.ignite.internal.processors.cache.database.tree.io.PageIO)1 GridLongList (org.apache.ignite.internal.util.GridLongList)1