Search in sources :

Example 1 with PagesListAddPageRecord

use of org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord in project ignite by apache.

the class PagesList method putDataPage.

/**
     * @param pageId Page ID.
     * @param page Page pointer.
     * @param pageAddr Page address.
     * @param io IO.
     * @param dataId Data page ID.
     * @param dataPage Data page pointer.
     * @param dataAddr Data page address.
     * @param bucket Bucket.
     * @return {@code true} If succeeded.
     * @throws IgniteCheckedException If failed.
     */
private boolean putDataPage(final long pageId, final long page, final long pageAddr, PagesListNodeIO io, final long dataId, final long dataPage, final long dataAddr, int bucket) throws IgniteCheckedException {
    if (io.getNextId(pageAddr) != 0L)
        // Splitted.
        return false;
    int idx = io.addPage(pageAddr, dataId, pageSize());
    if (idx == -1)
        handlePageFull(pageId, page, pageAddr, io, dataId, dataPage, dataAddr, bucket);
    else {
        bucketsSize[bucket].incrementAndGet();
        if (needWalDeltaRecord(pageId, page, null))
            wal.log(new PagesListAddPageRecord(cacheId, pageId, dataId));
        DataPageIO dataIO = DataPageIO.VERSIONS.forPage(dataAddr);
        dataIO.setFreeListPageId(dataAddr, pageId);
        if (needWalDeltaRecord(dataId, dataPage, null))
            wal.log(new DataPageSetFreeListPageRecord(cacheId, dataId, pageId));
    }
    return true;
}
Also used : DataPageIO(org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO) DataPageSetFreeListPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.DataPageSetFreeListPageRecord) PagesListAddPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord)

Example 2 with PagesListAddPageRecord

use of org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord in project ignite by apache.

the class PagesList method putReuseBag.

/**
     * @param pageId Page ID.
     * @param page Page pointer.
     * @param pageAddr Page address.
     * @param io IO.
     * @param bag Reuse bag.
     * @param bucket Bucket.
     * @return {@code true} If succeeded.
     * @throws IgniteCheckedException if failed.
     */
@SuppressWarnings("ForLoopReplaceableByForEach")
private boolean putReuseBag(final long pageId, final long page, final long pageAddr, PagesListNodeIO io, ReuseBag bag, int bucket) throws IgniteCheckedException {
    if (io.getNextId(pageAddr) != 0L)
        // Splitted.
        return false;
    long nextId;
    long prevId = pageId;
    long prevPage = page;
    long prevAddr = pageAddr;
    Boolean walPlc = null;
    // TODO may be unlock right away and do not keep all these pages locked?
    GridLongList locked = null;
    try {
        while ((nextId = bag.pollFreePage()) != 0L) {
            int idx = io.addPage(prevAddr, nextId, pageSize());
            if (idx == -1) {
                // Attempt to add page failed: the node page is full.
                final long nextPage = acquirePage(nextId);
                try {
                    // Page from reuse bag can't be concurrently recycled.
                    long nextPageAddr = writeLock(nextId, nextPage);
                    assert nextPageAddr != 0L;
                    if (locked == null) {
                        locked = new GridLongList(6);
                    }
                    locked.add(nextId);
                    locked.add(nextPage);
                    locked.add(nextPageAddr);
                    setupNextPage(io, prevId, prevAddr, nextId, nextPageAddr);
                    if (needWalDeltaRecord(prevId, prevPage, walPlc))
                        wal.log(new PagesListSetNextRecord(cacheId, prevId, nextId));
                    // Here we should never write full page, because it is known to be new.
                    if (needWalDeltaRecord(nextId, nextPage, FALSE))
                        wal.log(new PagesListInitNewPageRecord(cacheId, nextId, io.getType(), io.getVersion(), nextId, prevId, 0L));
                    // In reuse bucket the page itself can be used as a free page.
                    if (isReuseBucket(bucket))
                        bucketsSize[bucket].incrementAndGet();
                    // Switch to this new page, which is now a part of our list
                    // to add the rest of the bag to the new page.
                    prevAddr = nextPageAddr;
                    prevId = nextId;
                    prevPage = nextPage;
                    // Starting from tis point all wal records are written for reused pages from the bag.
                    // This mean that we use delta records only.
                    walPlc = FALSE;
                } finally {
                    releasePage(nextId, nextPage);
                }
            } else {
                // TODO: use single WAL record for bag?
                if (needWalDeltaRecord(prevId, prevPage, walPlc))
                    wal.log(new PagesListAddPageRecord(cacheId, prevId, nextId));
                bucketsSize[bucket].incrementAndGet();
            }
        }
    } finally {
        if (locked != null) {
            // We have to update our bucket with the new tail.
            updateTail(bucket, pageId, prevId);
            // Release write.
            for (int i = 0; i < locked.size(); i += 3) {
                writeUnlock(locked.get(i), locked.get(i + 1), locked.get(i + 2), FALSE, true);
            }
        }
    }
    return true;
}
Also used : PagesListAddPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord) GridLongList(org.apache.ignite.internal.util.GridLongList) PagesListSetNextRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord) PagesListInitNewPageRecord(org.apache.ignite.internal.pagemem.wal.record.delta.PagesListInitNewPageRecord)

Aggregations

PagesListAddPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListAddPageRecord)2 DataPageSetFreeListPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.DataPageSetFreeListPageRecord)1 PagesListInitNewPageRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListInitNewPageRecord)1 PagesListSetNextRecord (org.apache.ignite.internal.pagemem.wal.record.delta.PagesListSetNextRecord)1 DataPageIO (org.apache.ignite.internal.processors.cache.database.tree.io.DataPageIO)1 GridLongList (org.apache.ignite.internal.util.GridLongList)1