TreeCursor cursor = new TreeCursor(this, txn); cursor.autoload(autoload); byte[] endKey = cursor.randomNode(lowKey, highKey); if (endKey == null) { if (cursor.compareKeyTo(lowKey) < 0) { cursor.findNearby(lowKey); while (cursor.key() != null) { byte[] key = cursor.key(); byte[] value = cursor.value(); if (value != null) { cursor.valueStats(stats); if (stats[0] > 0 && (evictionFilter == null || evictionFilter.isAllowed(key, value))) cursor.store(null); cursor.nextLe(endKey); cursor.reset();
@Override public Stats analyze(byte[] lowKey, byte[] highKey) throws IOException { TreeCursor cursor = new TreeCursor(this, Transaction.BOGUS); try { cursor.autoload(false); cursor.random(lowKey, highKey); return cursor.key() == null ? new Stats(0, 0, 0, 0, 0) : cursor.analyze(); } catch (Throwable e) { cursor.reset(); throw e; } }
private void txnStore(byte[] key, byte[] value) throws IOException { Transaction txn = mDatabase.newAlwaysRedoTransaction(); try { TreeCursor c = new TreeCursor(this, txn); try { c.mKeyOnly = true; c.doFind(key); c.commit(value); } finally { c.reset(); } } catch (Throwable e) { txn.reset(); throw e; } }
/** * Non-transactionally deletes all entries in the tree. No other cursors or threads can be * active in the tree. The root node is prepared for deletion as a side effect. * * @return false if stopped because database is closed */ final boolean deleteAll() throws IOException { return new TreeCursor(this, Transaction.BOGUS).deleteAll(); }
@Override public long count(byte[] lowKey, byte[] highKey) throws IOException { TreeCursor cursor = new TreeCursor(this, Transaction.BOGUS); TreeCursor high = null; try { if (highKey != null) { high = new TreeCursor(this, Transaction.BOGUS); high.autoload(false); high.find(highKey); if (high.mKey == null) { // Found nothing. return 0; } } return cursor.count(lowKey, high); } finally { cursor.reset(); if (high != null) { high.reset(); } } }
reset(); return LockResult.UNOWNED; reset(); CursorFrame frame = new CursorFrame(); Node node = latchRootNode(); node = finishSplitShared(frame, node); pos = randomPosition(rnd, node, lowKey, highKey); } catch (Throwable e) { node.releaseShared(); throw cleanup(e, frame); resetLatched(node); if (isRangeEmpty(lowKey, highKey)) { return LockResult.UNOWNED; LocalTransaction txn; try { txn = prepareFind(node.retrieveKey(pos)); } catch (Throwable e) { resetLatched(node); throw e; if ((result = tryLockKey(txn)) == null) { result = doLoad(txn, VARIANT_REGULAR, mKeyOnly);
reset(); return null; reset(); CursorFrame frame = new CursorFrame(); Node node = latchRootNode(); node = finishSplitShared(frame, node); } else { try { pos = randomPosition(rnd, node, lowKey, highKey); } catch (Throwable e) { node.releaseShared(); throw cleanup(e, frame); resetLatched(node); if (isRangeEmpty(lowKey, highKey)) { return null; LocalTransaction txn; try { txn = prepareFind(startKey); } catch (Throwable e) { resetLatched(node); throw e; if ((result = tryLockKey(txn)) == null) {
@Override public final LockResult findNearby(byte[] key) throws IOException { LocalTransaction txn = prepareFind(key); node = latchRootNode(); } else { node = frame.acquireShared(); if (node.mSplit != null) { node = finishSplitShared(frame, node); frame.mNodePos = pos; try { LockResult result = tryLockKey(txn); if (result == null) { mValue = NOT_LOADED; return doLoad(txn, VARIANT_REGULAR, mKeyOnly); } else if ((pos != ~0 || (node.type() & Node.LOW_EXTREMITY) != 0) && (~pos <= node.highestLeafPos() || (node.type() & Node.HIGH_EXTREMITY) != 0)) LockResult result = tryLockKey(txn); if (result == null) { mValue = NOT_LOADED; return doLoad(txn, VARIANT_REGULAR, mKeyOnly); node = finishSplitShared(frame, node); } catch (Throwable e) { node.releaseShared();
TreeCursor trashCursor = new TreeCursor(mTrash, Transaction.BOGUS); try { trashCursor.find(trashKey); byte[] fragmented = trashCursor.value(); if (fragmented != null) { TreeCursor ixCursor = new TreeCursor(index, Transaction.BOGUS); try { ixCursor.find(indexKey); ixCursor.storeFragmented(fragmented); ixCursor.reset(); } catch (Throwable e) { throw closeOnFailure(ixCursor, e); trashCursor.store(null); trashCursor.reset(); } catch (Throwable e) { throw closeOnFailure(trashCursor, e);
TreeCursor cursor = new TreeCursor(mTrash, Transaction.BOGUS); try { cursor.autoload(false); cursor.findGt(prefix); while (true) { byte[] key = cursor.key(); if (key == null || compareUnsigned(key, 0, 8, prefix, 0, 8) != 0) { break; cursor.load(); byte[] value = cursor.value(); /*P*/ byte[] fragmented = p_transfer(value); CommitLock.Shared shared = commitLock.acquireShared(); try { db.deleteFragments(fragmented, 0, value.length); cursor.store(null); } finally { shared.release(); p_delete(fragmented); cursor.next(); cursor.reset(); } catch (Throwable e) { throw closeOnFailure(cursor, e);
encodeLongBE(prefix, 0, txnId); TreeCursor cursor = new TreeCursor(mTrash, Transaction.BOGUS); try { cursor.autoload(false); cursor.findGt(prefix); byte[] key = cursor.key(); if (key == null || compareUnsigned(key, 0, 8, prefix, 0, 8) != 0) { arraycopy(prefix, 0, key, 0, 8); key[8] = (byte) 0xff; cursor.findNearby(key); } else { cursor.findNearby(decrementReverseUnsignedVar(key, 8));
} catch (Throwable e) { node.releaseShared(); throw cleanup(e, frame); } catch (Throwable e) { node.releaseShared(); throw cleanup(e, frame); node = finishSplitShared(frame, node); pos = frame.mNodePos; if (variant >= VARIANT_NO_LOCK) { result = LockResult.UNOWNED; } else if ((result = tryLockKey(txn)) == null) { return doLoad(txn, variant, mKeyOnly); } catch (Throwable e) { node.releaseShared(); throw cleanup(e, frame); node = latchToChild(node, childPos); } catch (Throwable e) { throw cleanup(e, frame); node.releaseShared(); sibling.releaseShared(); throw cleanup(e, frame);
/** * @param view view to pass to observer * @return false if should stop */ final boolean verifyTree(Index view, VerificationObserver observer) throws IOException { TreeCursor cursor = new TreeCursor(this, Transaction.BOGUS); try { cursor.autoload(false); cursor.first(); // must start with loaded key int height = cursor.height(); if (!observer.indexBegin(view, height)) { cursor.reset(); return false; } if (!cursor.verify(height, observer)) { cursor.reset(); return false; } cursor.reset(); } catch (Throwable e) { observer.failed = true; throw e; } return true; }
final CommitLock commitLock = db.commitLock(); TreeCursor cursor = new TreeCursor(mTrash, Transaction.BOGUS); try { cursor.autoload(false); cursor.findGt(prefix); byte[] key = cursor.key(); if (key == null || compareUnsigned(key, 0, 8, prefix, 0, 8) != 0) { break; cursor.next(); cursor.reset(); } catch (Throwable e) { throw closeOnFailure(cursor, e);
final CommitLock commitLock = db.commitLock(); TreeCursor cursor = new TreeCursor(mTrash, Transaction.BOGUS); try { cursor.autoload(false); cursor.first(); if (cursor.key() != null) { if (listener != null) { listener.notify(EventType.RECOVERY_DELETE_FRAGMENTS, cursor.next(); } while (cursor.key() != null); cursor.reset(); } catch (Throwable e) { throw closeOnFailure(cursor, e);
int height = height(); } else { frameNodes[level] = node; long id = compactFrame(highestNodeId, frame, node); if (id > highestNodeId) { frame = leafSharedNotSplit(); Node node = frame.mNode; nextLeaf(); if ((frame = mLeaf) == null) { int nodePos = frame.mNodePos; if (nodePos >= 0 && node.isFragmentedLeafValue(nodePos)) { int pLen = pageSize(node.mPage); TreeValueStream stream = new TreeValueStream(this); long pos = 0; node = null; stream.doWrite(pos, TreeValueStream.TOUCH_VALUE, 0, 0); frame = leafSharedNotSplit(); node = frame.mNode; if (node.mId > highestNodeId) { nextAny(); frame = leafSharedNotSplit(); Node next = frame.mNode;
LocalDatabase db = mTrash.mDatabase; final CommitLock commitLock = db.commitLock(); TreeCursor cursor = new TreeCursor(mTrash, Transaction.BOGUS); try { cursor.first(); if (cursor.key() != null) { if (listener != null) { listener.notify(EventType.RECOVERY_DELETE_FRAGMENTS, byte[] value = cursor.value(); /*P*/ byte[] fragmented = p_transfer(value); try { try { db.deleteFragments(fragmented, 0, value.length); cursor.store(null); } finally { shared.release(); p_delete(fragmented); cursor.next(); } while (cursor.key() != null); cursor.reset(); } catch (Throwable e) { throw closeOnFailure(cursor, e);
TreeCursor cursor = new TreeCursor(this, Transaction.BOGUS); try { cursor.autoload(false); cursor.firstAny(); if (!cursor.compact(highestNodeId, observer)) { return false; cursor.reset();
final CursorFrame leaf = leafExclusive(); final CommitLock.Shared shared = commitLock(leaf); try { Node node = notSplitDirty(leaf); node = postInsert(leaf, node, key); throw handleException(e, false); } finally { shared.release();
autoload(false); firstAny(); Node node = notSplitDirty(mLeaf); } else if (!deleteLowestNode(mLeaf, node)) { mLeaf = null; reset(); return;