Search in sources :

Example 1 with AbstractDataPageIo

use of org.apache.ignite.internal.pagememory.io.AbstractDataPageIo in project ignite-3 by apache.

the class PagesList method putDataPage.

/**
 * Puts data page to page-list cache.
 *
 * @param pagesCache Page-list cache onheap.
 * @param dataId Data page ID.
 * @param dataAddr Data page address.
 * @param bucket Bucket.
 * @return {@code true} If succeeded.
 * @throws IgniteInternalCheckedException If failed.
 */
private boolean putDataPage(PagesCache pagesCache, final long dataId, final long dataAddr, int bucket) throws IgniteInternalCheckedException {
    if (pagesCache.add(dataId)) {
        incrementBucketSize(bucket);
        AbstractDataPageIo dataIo = pageMem.ioRegistry().resolve(dataAddr);
        if (dataIo.getFreeListPageId(dataAddr) != 0L) {
            dataIo.setFreeListPageId(dataAddr, 0L);
        }
        pageCacheChanged();
        return true;
    } else {
        return false;
    }
}
Also used : AbstractDataPageIo(org.apache.ignite.internal.pagememory.io.AbstractDataPageIo)

Example 2 with AbstractDataPageIo

use of org.apache.ignite.internal.pagememory.io.AbstractDataPageIo in project ignite-3 by apache.

the class PagesList method putDataPage.

/**
 * Puts data page.
 *
 * @param pageId Page ID.
 * @param pageAddr Page address.
 * @param io IO.
 * @param dataId Data page ID.
 * @param dataAddr Data page address.
 * @param bucket Bucket.
 * @param statHolder Statistics holder to track IO operations.
 * @return {@code true} If succeeded.
 * @throws IgniteInternalCheckedException If failed.
 */
private boolean putDataPage(final long pageId, final long pageAddr, PagesListNodeIo io, final long dataId, final long dataAddr, int bucket, IoStatisticsHolder statHolder) throws IgniteInternalCheckedException {
    if (io.getNextId(pageAddr) != 0L) {
        // Splitted.
        return false;
    }
    int idx = io.addPage(pageAddr, dataId, pageSize());
    if (idx == -1) {
        handlePageFull(pageId, pageAddr, io, dataId, dataAddr, bucket, statHolder);
    } else {
        incrementBucketSize(bucket);
        AbstractDataPageIo dataIo = pageMem.ioRegistry().resolve(dataAddr);
        dataIo.setFreeListPageId(dataAddr, pageId);
    }
    return true;
}
Also used : AbstractDataPageIo(org.apache.ignite.internal.pagememory.io.AbstractDataPageIo)

Example 3 with AbstractDataPageIo

use of org.apache.ignite.internal.pagememory.io.AbstractDataPageIo in project ignite-3 by apache.

the class PagesList method handlePageFull.

/**
 * Handles the added page.
 *
 * @param pageId Page ID.
 * @param pageAddr Page address.
 * @param io IO.
 * @param dataId Data page ID.
 * @param dataAddr Data page address.
 * @param bucket Bucket index.
 * @param statHolder Statistics holder to track IO operations.
 * @throws IgniteInternalCheckedException If failed.
 */
private void handlePageFull(final long pageId, final long pageAddr, PagesListNodeIo io, final long dataId, final long dataAddr, int bucket, IoStatisticsHolder statHolder) throws IgniteInternalCheckedException {
    AbstractDataPageIo dataIo = pageMem.ioRegistry().resolve(dataAddr);
    // Attempt to add page failed: the node page is full.
    if (isReuseBucket(bucket)) {
        // We can put only empty data pages to reuse bucket.
        assert dataIo.isEmpty(dataAddr);
        // Change page type to index and add it as next node page to this list.
        long newDataId = changeType(dataId, FLAG_AUX);
        setupNextPage(io, pageId, pageAddr, newDataId, dataAddr);
        // In reuse bucket the page itself can be used as a free page.
        incrementBucketSize(bucket);
        updateTail(bucket, pageId, newDataId);
    } else {
        // Just allocate a new node page and add our data page there.
        final long nextId = allocatePage(null);
        final long nextPage = acquirePage(nextId, statHolder);
        try {
            // Newly allocated page.
            long nextPageAddr = writeLock(nextId, nextPage);
            assert nextPageAddr != 0L;
            try {
                setupNextPage(io, pageId, pageAddr, nextId, nextPageAddr);
                int idx = io.addPage(nextPageAddr, dataId, pageSize());
                assert idx != -1;
                dataIo.setFreeListPageId(dataAddr, nextId);
                incrementBucketSize(bucket);
                updateTail(bucket, pageId, nextId);
            } finally {
                writeUnlock(nextId, nextPage, nextPageAddr, true);
            }
        } finally {
            releasePage(nextId, nextPage);
        }
    }
}
Also used : AbstractDataPageIo(org.apache.ignite.internal.pagememory.io.AbstractDataPageIo)

Example 4 with AbstractDataPageIo

use of org.apache.ignite.internal.pagememory.io.AbstractDataPageIo in project ignite-3 by apache.

the class AbstractFreeList method insertDataRows.

/**
 * Reduces the workload on the free list by writing multiple rows into a single memory page at once.
 *
 * <p>Rows are sequentially added to the page as long as there is enough free space on it. If the row is large then those fragments
 * that occupy the whole memory page are written to other pages, and the remainder is added to the current one.
 *
 * @param rows Rows.
 * @param statHolder Statistics holder to track IO operations.
 * @throws IgniteInternalCheckedException If failed.
 */
@Override
public void insertDataRows(Collection<T> rows, IoStatisticsHolder statHolder) throws IgniteInternalCheckedException {
    try {
        IgniteCursor<T> cur = IgniteCursor.wrap(rows.iterator());
        int written = COMPLETE;
        while (written != COMPLETE || cur.next()) {
            T row = cur.get();
            // If eviction is required - free up memory before locking the next page.
            while (evictionTracker.evictionRequired()) {
                evictionTracker.evictDataPage();
            }
            if (written == COMPLETE) {
                written = writeWholePages(row, statHolder);
                continue;
            }
            AbstractDataPageIo initIo = null;
            long pageId = takePage(row.size() - written, row, statHolder);
            if (pageId == 0L) {
                pageId = allocateDataPage(row.partition());
                initIo = row.ioVersions().latest();
            }
            written = write(pageId, writeRowsHnd, initIo, cur, written, FAIL_I, statHolder);
            // We can't fail here.
            assert written != FAIL_I;
        }
    } catch (RuntimeException e) {
        throw new CorruptedFreeListException("Failed to insert data rows", e, grpId);
    }
}
Also used : AbstractDataPageIo(org.apache.ignite.internal.pagememory.io.AbstractDataPageIo)

Example 5 with AbstractDataPageIo

use of org.apache.ignite.internal.pagememory.io.AbstractDataPageIo in project ignite-3 by apache.

the class AbstractFreeList method writeSinglePage.

/**
 * Take a page and write row on it.
 *
 * @param row Row to write.
 * @param written Written size.
 * @param statHolder Statistics holder to track IO operations.
 * @return Number of bytes written, {@link #COMPLETE} if the row was fully written.
 * @throws IgniteInternalCheckedException If failed.
 */
private int writeSinglePage(T row, int written, IoStatisticsHolder statHolder) throws IgniteInternalCheckedException {
    AbstractDataPageIo initIo = null;
    long pageId = takePage(row.size() - written, row, statHolder);
    if (pageId == 0L) {
        pageId = allocateDataPage(row.partition());
        initIo = row.ioVersions().latest();
    }
    written = write(pageId, writeRowHnd, initIo, row, written, FAIL_I, statHolder);
    // We can't fail here.
    assert written != FAIL_I;
    return written;
}
Also used : AbstractDataPageIo(org.apache.ignite.internal.pagememory.io.AbstractDataPageIo)

Aggregations

AbstractDataPageIo (org.apache.ignite.internal.pagememory.io.AbstractDataPageIo)5