use of org.apache.ignite.internal.pagememory.CorruptedDataStructureException in project ignite-3 by apache.
the class BplusTree method findLast.
/**
* Returns a value mapped to the greatest key, or {@code null} if tree is empty or no entry matches the passed filter.
*
* @param c Filter closure.
* @return Value.
* @throws IgniteInternalCheckedException If failed.
*/
public T findLast(final TreeRowClosure<L, T> c) throws IgniteInternalCheckedException {
checkDestroyed();
Get g = null;
try {
if (c == null) {
g = new GetOne(null, null, null, true);
doFind(g);
return (T) g.row;
} else {
GetLast getLast = new GetLast(c);
g = getLast;
return getLast.find();
}
} catch (CorruptedDataStructureException e) {
throw e;
} catch (IgniteInternalCheckedException e) {
throw new IgniteInternalCheckedException("Runtime failure on last row lookup", e);
} catch (RuntimeException | AssertionError e) {
Get g0 = g;
long[] pageIds = pages(g == null, () -> new long[] { g0.pageId });
throw corruptedTreeException("Runtime failure on last row lookup", e, grpId, pageIds);
} finally {
checkDestroyed();
}
}
use of org.apache.ignite.internal.pagememory.CorruptedDataStructureException in project ignite-3 by apache.
the class BplusTree method iterate.
/**
* Iterates over the tree.
*
* @param lower Lower bound inclusive.
* @param upper Upper bound inclusive.
* @param c Closure applied for all found items, iteration is stopped if closure returns {@code false}.
* @throws IgniteInternalCheckedException If failed.
*/
public void iterate(L lower, L upper, TreeRowClosure<L, T> c) throws IgniteInternalCheckedException {
checkDestroyed();
ClosureCursor cursor = new ClosureCursor(lower, upper, c);
try {
cursor.iterate();
} catch (CorruptedDataStructureException e) {
throw e;
} catch (IgniteInternalCheckedException e) {
throw new IgniteInternalCheckedException("Runtime failure on bounds: [lower=" + lower + ", upper=" + upper + "]", e);
} catch (RuntimeException | AssertionError e) {
throw corruptedTreeException("Runtime failure on bounds: [lower=" + lower + ", upper=" + upper + "]", e, grpId, pages(cursor.getCursor != null, () -> new long[] { cursor.getCursor.pageId }));
} finally {
checkDestroyed();
}
}
use of org.apache.ignite.internal.pagememory.CorruptedDataStructureException in project ignite-3 by apache.
the class BplusTree method findOne.
/**
* Returns found result or {@code null}.
*
* @param row Lookup row for exact match.
* @param x Implementation specific argument, {@code null} always means that we need to return full detached data row.
* @throws IgniteInternalCheckedException If failed.
*/
@Nullable
public final <R> R findOne(L row, @Nullable TreeRowClosure<L, T> c, Object x) throws IgniteInternalCheckedException {
checkDestroyed();
GetOne g = new GetOne(row, c, x, false);
try {
doFind(g);
return (R) g.row;
} catch (CorruptedDataStructureException e) {
throw e;
} catch (IgniteInternalCheckedException e) {
throw new IgniteInternalCheckedException("Runtime failure on lookup row: " + row, e);
} catch (RuntimeException | AssertionError e) {
throw corruptedTreeException("Runtime failure on lookup row: " + row, e, grpId, g.pageId);
} finally {
checkDestroyed();
}
}
use of org.apache.ignite.internal.pagememory.CorruptedDataStructureException in project ignite-3 by apache.
the class BplusTree method find.
/**
* Getting the cursor through the rows of the tree.
*
* @param lower Lower bound or {@code null} if unbounded.
* @param upper Upper bound or {@code null} if unbounded.
* @param lowIncl {@code true} if lower bound is inclusive.
* @param upIncl {@code true} if upper bound is inclusive.
* @param c Filter closure.
* @param x Implementation specific argument, {@code null} always means that we need to return full detached data row.
* @return Cursor.
* @throws IgniteInternalCheckedException If failed.
*/
public IgniteCursor<T> find(@Nullable L lower, @Nullable L upper, boolean lowIncl, boolean upIncl, TreeRowClosure<L, T> c, @Nullable Object x) throws IgniteInternalCheckedException {
checkDestroyed();
ForwardCursor cursor = new ForwardCursor(lower, upper, lowIncl, upIncl, c, x);
try {
if (lower == null) {
return findLowerUnbounded(upper, upIncl, c, x);
}
cursor.find();
return cursor;
} catch (CorruptedDataStructureException e) {
throw e;
} catch (IgniteInternalCheckedException e) {
throw new IgniteInternalCheckedException("Runtime failure on bounds: [lower=" + lower + ", upper=" + upper + "]", e);
} catch (RuntimeException | AssertionError e) {
long[] pageIds = pages(lower == null || cursor == null || cursor.getCursor == null, () -> new long[] { cursor.getCursor.pageId });
throw corruptedTreeException("Runtime failure on bounds: [lower=" + lower + ", upper=" + upper + "]", e, grpId, pageIds);
} finally {
checkDestroyed();
}
}
use of org.apache.ignite.internal.pagememory.CorruptedDataStructureException in project ignite-3 by apache.
the class BplusTree method doPut.
/**
* Does a put.
*
* @param row New value.
* @param needOld {@code True} If need return old value.
* @return Old row.
* @throws IgniteInternalCheckedException If failed.
*/
private T doPut(T row, boolean needOld) throws IgniteInternalCheckedException {
checkDestroyed();
Put p = new Put(row, needOld);
try {
for (; ; ) {
// Go down with retries.
p.init();
Result res = putDown(p, p.rootId, 0L, p.rootLvl);
switch(res) {
case RETRY:
case RETRY_ROOT:
continue;
case FOUND:
// We may need to perform an inner replace on the upper level.
if (!p.isFinished()) {
res = p.finishTail();
// If not found, then the root split has happened and operation should be retried from the actual root.
if (res == RETRY || res == NOT_FOUND) {
p.releaseTail();
assert p.checkTailLevel(getRootLevel()) : "tail=" + p.tail + ", res=" + res;
continue;
}
}
return p.oldRow;
default:
throw new IllegalStateException("Result: " + res);
}
}
} catch (CorruptedDataStructureException e) {
throw e;
} catch (IgniteInternalCheckedException e) {
throw new IgniteInternalCheckedException("Runtime failure on row: " + row, e);
} catch (RuntimeException | AssertionError e) {
throw corruptedTreeException("Runtime failure on row: " + row, e, grpId, p.pageId);
} finally {
checkDestroyed();
}
}
Aggregations