use of org.apache.ignite.internal.pagememory.CorruptedDataStructureException 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();
}
}
use of org.apache.ignite.internal.pagememory.CorruptedDataStructureException 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();
}
}
use of org.apache.ignite.internal.pagememory.CorruptedDataStructureException 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();
}
}
Aggregations