Search in sources :

Example 11 with IgniteInternalCheckedException

use of org.apache.ignite.lang.IgniteInternalCheckedException in project ignite-3 by apache.

the class BplusTree method invoke.

/**
 * {@inheritDoc}
 */
@Override
public void invoke(L row, Object z, InvokeClosure<T> c) throws IgniteInternalCheckedException {
    checkDestroyed();
    Invoke x = new Invoke(row, z, c);
    try {
        for (; ; ) {
            x.init();
            Result res = invokeDown(x, x.rootId, 0L, 0L, x.rootLvl);
            switch(res) {
                case RETRY:
                case RETRY_ROOT:
                    continue;
                default:
                    if (!x.isFinished()) {
                        res = x.tryFinish();
                        if (res == RETRY || res == RETRY_ROOT) {
                            continue;
                        }
                        assert x.isFinished() : res;
                    }
                    return;
            }
        }
    } catch (CorruptedDataStructureException e) {
        throw e;
    } catch (IgniteInternalCheckedException e) {
        throw new IgniteInternalCheckedException("Runtime failure on search row: " + row, e);
    } catch (RuntimeException | AssertionError e) {
        throw corruptedTreeException("Runtime failure on search row: " + row, e, grpId, x.pageId);
    } finally {
        x.releaseAll();
        checkDestroyed();
    }
}
Also used : IgniteInternalCheckedException(org.apache.ignite.lang.IgniteInternalCheckedException) CorruptedDataStructureException(org.apache.ignite.internal.pagememory.CorruptedDataStructureException)

Example 12 with IgniteInternalCheckedException

use of org.apache.ignite.lang.IgniteInternalCheckedException in project ignite-3 by apache.

the class BplusTree method doRemove.

/**
 * Does a remove.
 *
 * @param row Lookup row.
 * @param needOld {@code True} if need return removed row.
 * @return Removed row.
 * @throws IgniteInternalCheckedException If failed.
 */
private T doRemove(L row, boolean needOld) throws IgniteInternalCheckedException {
    assert !sequentialWriteOptsEnabled;
    checkDestroyed();
    Remove r = new Remove(row, needOld);
    try {
        for (; ; ) {
            r.init();
            Result res = removeDown(r, r.rootId, 0L, 0L, r.rootLvl);
            switch(res) {
                case RETRY:
                case RETRY_ROOT:
                    continue;
                default:
                    if (!r.isFinished()) {
                        res = r.finishTail();
                        // If not found, then the tree grew beyond our call stack -> retry from the actual root.
                        if (res == RETRY || res == NOT_FOUND) {
                            assert r.checkTailLevel(getRootLevel()) : "tail=" + r.tail + ", res=" + res;
                            continue;
                        }
                        assert res == FOUND : res;
                    }
                    assert r.isFinished();
                    return r.rmvd;
            }
        }
    } catch (CorruptedDataStructureException e) {
        throw e;
    } catch (IgniteInternalCheckedException e) {
        throw new IgniteInternalCheckedException("Runtime failure on search row: " + row, e);
    } catch (RuntimeException | AssertionError e) {
        throw corruptedTreeException("Runtime failure on search row: " + row, e, grpId, r.pageId);
    } finally {
        r.releaseAll();
        checkDestroyed();
    }
}
Also used : IgniteInternalCheckedException(org.apache.ignite.lang.IgniteInternalCheckedException) CorruptedDataStructureException(org.apache.ignite.internal.pagememory.CorruptedDataStructureException)

Example 13 with IgniteInternalCheckedException

use of org.apache.ignite.lang.IgniteInternalCheckedException in project ignite-3 by apache.

the class BplusTree method findFirst.

/**
 * Returns a value mapped to the lowest key, or {@code null} if tree is empty or no entry matches the passed filter.
 *
 * @param filter Filter closure.
 * @return Value.
 * @throws IgniteInternalCheckedException If failed.
 */
public T findFirst(TreeRowClosure<L, T> filter) throws IgniteInternalCheckedException {
    checkDestroyed();
    long curPageId = 0L;
    long nextPageId = 0L;
    try {
        for (; ; ) {
            long metaPage = acquirePage(metaPageId);
            try {
                // Level 0 is always at the bottom.
                curPageId = getFirstPageId(metaPageId, metaPage, 0);
            } finally {
                releasePage(metaPageId, metaPage);
            }
            long curPage = acquirePage(curPageId);
            try {
                long curPageAddr = readLock(curPageId, curPage);
                if (curPageAddr == 0) {
                    // The first page has gone: restart scan.
                    continue;
                }
                try {
                    BplusIo<L> io = io(curPageAddr);
                    assert io.isLeaf();
                    for (; ; ) {
                        int cnt = io.getCount(curPageAddr);
                        for (int i = 0; i < cnt; ++i) {
                            if (filter == null || filter.apply(this, io, curPageAddr, i)) {
                                return getRow(io, curPageAddr, i);
                            }
                        }
                        nextPageId = io.getForward(curPageAddr);
                        if (nextPageId == 0) {
                            return null;
                        }
                        long nextPage = acquirePage(nextPageId);
                        try {
                            long nextPageAddr = readLock(nextPageId, nextPage);
                            // In the current implementation the next page can't change when the current page is locked.
                            assert nextPageAddr != 0 : nextPageAddr;
                            try {
                                long pa = curPageAddr;
                                // Set to zero to avoid double unlocking in finalizer.
                                curPageAddr = 0;
                                readUnlock(curPageId, curPage, pa);
                                long p = curPage;
                                // Set to zero to avoid double release in finalizer.
                                curPage = 0;
                                releasePage(curPageId, p);
                                curPageId = nextPageId;
                                curPage = nextPage;
                                curPageAddr = nextPageAddr;
                                nextPage = 0;
                                nextPageAddr = 0;
                            } finally {
                                if (nextPageAddr != 0) {
                                    readUnlock(nextPageId, nextPage, nextPageAddr);
                                }
                            }
                        } finally {
                            if (nextPage != 0) {
                                releasePage(nextPageId, nextPage);
                            }
                        }
                    }
                } finally {
                    if (curPageAddr != 0) {
                        readUnlock(curPageId, curPage, curPageAddr);
                    }
                }
            } finally {
                if (curPage != 0) {
                    releasePage(curPageId, curPage);
                }
            }
        }
    } catch (CorruptedDataStructureException e) {
        throw e;
    } catch (IgniteInternalCheckedException e) {
        throw new IgniteInternalCheckedException("Runtime failure on first row lookup", e);
    } catch (RuntimeException | AssertionError e) {
        throw corruptedTreeException("Runtime failure on first row lookup", e, grpId, curPageId, nextPageId);
    } finally {
        checkDestroyed();
    }
}
Also used : IgniteInternalCheckedException(org.apache.ignite.lang.IgniteInternalCheckedException) CorruptedDataStructureException(org.apache.ignite.internal.pagememory.CorruptedDataStructureException)

Example 14 with IgniteInternalCheckedException

use of org.apache.ignite.lang.IgniteInternalCheckedException 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)

Example 15 with IgniteInternalCheckedException

use of org.apache.ignite.lang.IgniteInternalCheckedException in project ignite-3 by apache.

the class ExecutionServiceImpl method executeFragment.

private void executeFragment(Query<RowT> qry, FragmentPlan plan, ExecutionContext<RowT> ectx) {
    String origNodeId = ectx.originatingNodeId();
    Outbox<RowT> node = new LogicalRelImplementor<>(ectx, affSrvc, mailboxRegistry, exchangeSrvc).go(plan.root());
    qry.addFragment(new RunningFragment<>(node, ectx));
    try {
        msgSrvc.send(origNodeId, FACTORY.queryStartResponse().queryId(qry.id()).fragmentId(ectx.fragmentId()).build());
    } catch (IgniteInternalCheckedException e) {
        IgniteInternalException wrpEx = new IgniteInternalException("Failed to send reply. [nodeId=" + origNodeId + ']', e);
        throw wrpEx;
    }
    node.init();
}
Also used : IgniteInternalCheckedException(org.apache.ignite.lang.IgniteInternalCheckedException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException)

Aggregations

IgniteInternalCheckedException (org.apache.ignite.lang.IgniteInternalCheckedException)15 CorruptedDataStructureException (org.apache.ignite.internal.pagememory.CorruptedDataStructureException)8 Nullable (org.jetbrains.annotations.Nullable)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections.emptyIterator (java.util.Collections.emptyIterator)2 Collections.shuffle (java.util.Collections.shuffle)2 Collections.singleton (java.util.Collections.singleton)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Queue (java.util.Queue)2 Random (java.util.Random)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 BlockingQueue (java.util.concurrent.BlockingQueue)2