Search in sources :

Example 1 with LongListReuseBag

use of org.apache.ignite.internal.processors.cache.persistence.tree.reuse.LongListReuseBag in project ignite 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 IgniteCheckedException If failed.
 */
public final long destroy(@Nullable IgniteInClosure<L> c, boolean forceDestroy) throws IgniteCheckedException {
    close();
    if (!markDestroyed() && !forceDestroy)
        return 0;
    if (reuseList == null)
        return -1;
    LongListReuseBag bag = new LongListReuseBag();
    long pagesCnt = 0;
    AtomicLong lockHoldStartTime = new AtomicLong(U.currentTimeMillis());
    Deque<GridTuple3<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 GridTuple3<>(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, metaPage, metaPageAddr, null));
            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.processors.cache.persistence.tree.reuse.LongListReuseBag) AtomicLong(java.util.concurrent.atomic.AtomicLong) LinkedList(java.util.LinkedList) GridTuple3(org.apache.ignite.internal.util.lang.GridTuple3)

Example 2 with LongListReuseBag

use of org.apache.ignite.internal.processors.cache.persistence.tree.reuse.LongListReuseBag in project ignite by apache.

the class AbstractFreeList method removeDataRowByLink.

/**
 * {@inheritDoc}
 */
@Override
public void removeDataRowByLink(long link, IoStatisticsHolder statHolder) throws IgniteCheckedException {
    assert link != 0;
    try {
        long pageId = PageIdUtils.pageId(link);
        int itemId = PageIdUtils.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) {
            memMetrics.decrementLargeEntriesPages();
            itemId = PageIdUtils.itemId(nextLink);
            pageId = PageIdUtils.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 (IgniteCheckedException | 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.processors.cache.persistence.tree.reuse.LongListReuseBag) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) LongListReuseBag(org.apache.ignite.internal.processors.cache.persistence.tree.reuse.LongListReuseBag) ReuseBag(org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseBag)

Example 3 with LongListReuseBag

use of org.apache.ignite.internal.processors.cache.persistence.tree.reuse.LongListReuseBag in project ignite by apache.

the class PagesPossibleCorruptionDiagnosticTest method testDiagnosticCollectedOnCorruptedPageList.

/**
 * Tests page list pages are collected in {@link CorruptedFreeListException}.
 */
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_PAGES_LIST_DISABLE_ONHEAP_CACHING, value = "true")
public void testDiagnosticCollectedOnCorruptedPageList() throws Exception {
    IgniteEx ignite = startGrid(0);
    ignite.cluster().state(ClusterState.ACTIVE);
    IgniteCache<Integer, Integer> cache = ignite.getOrCreateCache(new CacheConfiguration<Integer, Integer>(DEFAULT_CACHE_NAME).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setAffinity(new RendezvousAffinityFunction(false, 1)));
    cache.put(1, 1);
    cache.remove(1);
    int grpId = cacheGroupId(DEFAULT_CACHE_NAME, null);
    IgniteCacheOffheapManager.CacheDataStore dataStore = ignite.context().cache().cacheGroup(grpId).offheap().cacheDataStores().iterator().next();
    GridCacheOffheapManager.GridCacheDataStore store = (GridCacheOffheapManager.GridCacheDataStore) dataStore;
    AbstractFreeList freeList = store.getCacheStoreFreeList();
    ReuseBag bag = new LongListReuseBag();
    bag.addFreePage(pageId(0, FLAG_DATA, 10));
    bag.addFreePage(pageId(0, FLAG_DATA, 11));
    long[] pages = null;
    try {
        freeList.addForRecycle(bag);
    } catch (CorruptedFreeListException e) {
        pages = e.pageIds();
    }
    assertNotNull(pages);
}
Also used : LongListReuseBag(org.apache.ignite.internal.processors.cache.persistence.tree.reuse.LongListReuseBag) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) LongListReuseBag(org.apache.ignite.internal.processors.cache.persistence.tree.reuse.LongListReuseBag) ReuseBag(org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseBag) AbstractFreeList(org.apache.ignite.internal.processors.cache.persistence.freelist.AbstractFreeList) IgniteEx(org.apache.ignite.internal.IgniteEx) CorruptedFreeListException(org.apache.ignite.internal.processors.cache.persistence.freelist.CorruptedFreeListException) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Aggregations

LongListReuseBag (org.apache.ignite.internal.processors.cache.persistence.tree.reuse.LongListReuseBag)3 ReuseBag (org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseBag)2 LinkedList (java.util.LinkedList)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteCacheOffheapManager (org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager)1 AbstractFreeList (org.apache.ignite.internal.processors.cache.persistence.freelist.AbstractFreeList)1 CorruptedFreeListException (org.apache.ignite.internal.processors.cache.persistence.freelist.CorruptedFreeListException)1 GridTuple3 (org.apache.ignite.internal.util.lang.GridTuple3)1 WithSystemProperty (org.apache.ignite.testframework.junits.WithSystemProperty)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1