Search in sources :

Example 1 with LongListReuseBag

use of org.apache.ignite.internal.pagememory.reuse.LongListReuseBag in project ignite-3 by apache.

the class BplusTree method destroy.

/**
 * Destroys tree. This method is allowed to be invoked only when the tree is out of use (no concurrent operations are trying to read or
 * update the tree after destroy beginning).
 *
 * @param c Visitor closure. Visits only leaf pages.
 * @param forceDestroy Whether to proceed with destroying, even if tree is already marked as destroyed (see {@link #markDestroyed()}).
 * @return Number of pages recycled from this tree. If the tree was destroyed by someone else concurrently returns {@code 0}, otherwise
 *      it should return at least {@code 2} (for meta page and root page), unless this tree is used as metadata storage, or {@code -1}
 *      if we don't have a reuse list and did not do recycling at all.
 * @throws IgniteInternalCheckedException If failed.
 */
public final long destroy(@Nullable Consumer<L> c, boolean forceDestroy) throws IgniteInternalCheckedException {
    close();
    if (!markDestroyed() && !forceDestroy) {
        return 0;
    }
    if (reuseList == null) {
        return -1;
    }
    LongListReuseBag bag = new LongListReuseBag();
    long pagesCnt = 0;
    AtomicLong lockHoldStartTime = new AtomicLong(FastTimestamps.coarseCurrentTimeMillis());
    Deque<IgniteTuple3<Long, Long, Long>> lockedPages = new LinkedList<>();
    final long lockMaxTime = maxLockHoldTime();
    long metaPage = acquirePage(metaPageId);
    try {
        // No checks, we must be out of use.
        long metaPageAddr = writeLock(metaPageId, metaPage);
        lockedPages.push(new IgniteTuple3<>(metaPageId, metaPage, metaPageAddr));
        try {
            assert metaPageAddr != 0L;
            int rootLvl = getRootLevel(metaPageAddr);
            if (rootLvl < 0) {
                fail("Root level: " + rootLvl);
            }
            long rootPageId = getFirstPageId(metaPageId, metaPage, rootLvl, metaPageAddr);
            pagesCnt += destroyDownPages(bag, rootPageId, rootLvl, c, lockHoldStartTime, lockMaxTime, lockedPages);
            bag.addFreePage(recyclePage(metaPageId, metaPageAddr));
            pagesCnt++;
        } finally {
            writeUnlock(metaPageId, metaPage, metaPageAddr, true);
            lockedPages.pop();
        }
    } finally {
        releasePage(metaPageId, metaPage);
    }
    reuseList.addForRecycle(bag);
    assert bag.isEmpty() : bag.size();
    return pagesCnt;
}
Also used : LongListReuseBag(org.apache.ignite.internal.pagememory.reuse.LongListReuseBag) AtomicLong(java.util.concurrent.atomic.AtomicLong) IgniteTuple3(org.apache.ignite.lang.IgniteTuple3) LinkedList(java.util.LinkedList)

Example 2 with LongListReuseBag

use of org.apache.ignite.internal.pagememory.reuse.LongListReuseBag in project ignite-3 by apache.

the class AbstractFreeList method removeDataRowByLink.

/**
 * {@inheritDoc}
 */
@Override
public void removeDataRowByLink(long link, IoStatisticsHolder statHolder) throws IgniteInternalCheckedException {
    assert link != 0;
    try {
        long pageId = pageId(link);
        int itemId = itemId(link);
        ReuseBag bag = new LongListReuseBag();
        long nextLink = write(pageId, rmvRow, bag, itemId, FAIL_L, statHolder);
        // Can't fail here.
        assert nextLink != FAIL_L;
        while (nextLink != 0L) {
            itemId = itemId(nextLink);
            pageId = pageId(nextLink);
            nextLink = write(pageId, rmvRow, bag, itemId, FAIL_L, statHolder);
            // Can't fail here.
            assert nextLink != FAIL_L;
        }
        reuseList.addForRecycle(bag);
    } catch (AssertionError e) {
        throw corruptedFreeListException(e);
    } catch (IgniteInternalCheckedException | Error e) {
        throw e;
    } catch (Throwable t) {
        throw new CorruptedFreeListException("Failed to remove data by link", t, grpId);
    }
}
Also used : LongListReuseBag(org.apache.ignite.internal.pagememory.reuse.LongListReuseBag) IgniteInternalCheckedException(org.apache.ignite.lang.IgniteInternalCheckedException) LongListReuseBag(org.apache.ignite.internal.pagememory.reuse.LongListReuseBag) ReuseBag(org.apache.ignite.internal.pagememory.reuse.ReuseBag)

Aggregations

LongListReuseBag (org.apache.ignite.internal.pagememory.reuse.LongListReuseBag)2 LinkedList (java.util.LinkedList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ReuseBag (org.apache.ignite.internal.pagememory.reuse.ReuseBag)1 IgniteInternalCheckedException (org.apache.ignite.lang.IgniteInternalCheckedException)1 IgniteTuple3 (org.apache.ignite.lang.IgniteTuple3)1