/** * Returns highest leaf or internal position. Caller must hold any latch. */ int highestPos() { int pos = searchVecEnd() - searchVecStart(); if (!isLeaf()) { pos += 2; } return pos; }
/** * Returns highest leaf or internal position. Caller must hold any latch. */ int highestPos() { int pos = searchVecEnd() - searchVecStart(); if (!isLeaf()) { pos += 2; } return pos; }
/** * Caller must hold any latch. */ int availableBytes() { return isLeaf() ? availableLeafBytes() : availableInternalBytes(); }
/** * Caller must hold any latch. */ int availableBytes() { return isLeaf() ? availableLeafBytes() : availableInternalBytes(); }
/** * Caller must hold any latch. */ int availableBytes() { return isLeaf() ? availableLeafBytes() : availableInternalBytes(); }
/** * Returns highest leaf or internal position. Caller must hold any latch. */ int highestPos() { int pos = searchVecEnd() - searchVecStart(); if (!isLeaf()) { pos += 2; } return pos; }
final void writeCachePrimer(final DataOutput dout) throws IOException { traverseLoaded((node) -> { byte[] midKey; try { if (!node.isLeaf()) { return; } int numKeys = node.numKeys(); if (numKeys > 1) { int highPos = numKeys & ~1; midKey = node.midKey(highPos - 2, node, highPos); } else if (numKeys == 1) { midKey = node.retrieveKey(0); } else { return; } } finally { node.releaseExclusive(); } // Omit entries with very large keys. Primer encoding format needs to change // for supporting larger keys. if (midKey.length < 0xffff) { dout.writeShort(midKey.length); dout.write(midKey); } }); // Terminator. dout.writeShort(0xffff); }
final void writeCachePrimer(final DataOutput dout) throws IOException { traverseLoaded((node) -> { byte[] midKey; try { if (!node.isLeaf()) { return; } int numKeys = node.numKeys(); if (numKeys > 1) { int highPos = numKeys & ~1; midKey = node.midKey(highPos - 2, node, highPos); } else if (numKeys == 1) { midKey = node.retrieveKey(0); } else { return; } } finally { node.releaseExclusive(); } // Omit entries with very large keys. Primer encoding format needs to change // for supporting larger keys. if (midKey.length < 0xffff) { dout.writeShort(midKey.length); dout.write(midKey); } }); // Terminator. dout.writeShort(0xffff); }
final void writeCachePrimer(final DataOutput dout) throws IOException { traverseLoaded((node) -> { byte[] midKey; try { if (!node.isLeaf()) { return; } int numKeys = node.numKeys(); if (numKeys > 1) { int highPos = numKeys & ~1; midKey = node.midKey(highPos - 2, node, highPos); } else if (numKeys == 1) { midKey = node.retrieveKey(0); } else { return; } } finally { node.releaseExclusive(); } // Omit entries with very large keys. Primer encoding format needs to change // for supporting larger keys. if (midKey.length < 0xffff) { dout.writeShort(midKey.length); dout.write(midKey); } }); // Terminator. dout.writeShort(0xffff); }
/** * Returns the highest position within the original node as if it had not split. */ final int highestPos(Node node) { int pos; Node sibling = latchSibling(); if (node.isLeaf()) { pos = node.highestLeafPos() + 2 + sibling.highestLeafPos(); } else { pos = node.highestInternalPos() + 2 + sibling.highestInternalPos(); } sibling.releaseShared(); return pos; }
/** * Returns the highest position within the original node as if it had not split. */ final int highestPos(Node node) { int pos; Node sibling = latchSibling(); if (node.isLeaf()) { pos = node.highestLeafPos() + 2 + sibling.highestLeafPos(); } else { pos = node.highestInternalPos() + 2 + sibling.highestInternalPos(); } sibling.releaseShared(); return pos; }
/** * Returns the highest position within the original node as if it had not split. */ final int highestPos(Node node) { int pos; Node sibling = latchSibling(); if (node.isLeaf()) { pos = node.highestLeafPos() + 2 + sibling.highestLeafPos(); } else { pos = node.highestInternalPos() + 2 + sibling.highestInternalPos(); } sibling.releaseShared(); return pos; }
/** * Test method which confirms that cursor frame nodes are at an extremity. Method is not * tolerant of split nodes. * * @param extremity LOW_EXTREMITY or HIGH_EXTREMITY */ public final boolean verifyExtremities(byte extremity) throws IOException { Node node = latchRootNode(); try { while (true) { if ((node.type() & extremity) == 0) { return false; } if (node.isLeaf()) { return true; } int pos = 0; if (extremity == Node.HIGH_EXTREMITY) { pos = node.highestInternalPos(); } node = latchToChild(node, pos); } } finally { node.releaseShared(); } }
/** * Test method which confirms that cursor frame nodes are at an extremity. Method is not * tolerant of split nodes. * * @param extremity LOW_EXTREMITY or HIGH_EXTREMITY */ public final boolean verifyExtremities(byte extremity) throws IOException { Node node = latchRootNode(); try { while (true) { if ((node.type() & extremity) == 0) { return false; } if (node.isLeaf()) { return true; } int pos = 0; if (extremity == Node.HIGH_EXTREMITY) { pos = node.highestInternalPos(); } node = latchToChild(node, pos); } } finally { node.releaseShared(); } }
/** * Test method which confirms that cursor frame nodes are at an extremity. Method is not * tolerant of split nodes. * * @param extremity LOW_EXTREMITY or HIGH_EXTREMITY */ public final boolean verifyExtremities(byte extremity) throws IOException { Node node = latchRootNode(); try { while (true) { if ((node.type() & extremity) == 0) { return false; } if (node.isLeaf()) { return true; } int pos = 0; if (extremity == Node.HIGH_EXTREMITY) { pos = node.highestInternalPos(); } node = mTree.mDatabase.latchToChild(node, pos); } } finally { node.releaseShared(); } }
/** * Moves the cursor to the first subtree leaf node, which might be empty or full of * ghosts. Leaf frame remains latched when method returns normally. * * @param frame frame to bind node to * @param node latched node; can have no keys * @return latched first node, possibly empty, bound by mLeaf frame */ private Node toFirstLeaf(CursorFrame frame, Node node) throws IOException { try { while (true) { frame.bind(node, 0); if (node.mSplit != null) { node = finishSplitShared(frame, node); if (frame.mNodePos != 0) { // Rebind if position changed (possibly negative). frame.bindOrReposition(node, 0); } } if (node.isLeaf()) { mLeaf = frame; return node; } node = latchToChild(node, 0); frame = new CursorFrame(frame); } } catch (Throwable e) { throw cleanup(e, frame); } }
/** * Moves the cursor to the first subtree leaf node, which might be empty or full of * ghosts. Leaf frame remains latched when method returns normally. * * @param frame frame to bind node to * @param node latched node; can have no keys * @return latched first node, possibly empty, bound by mLeaf frame */ private Node toFirstLeaf(CursorFrame frame, Node node) throws IOException { try { while (true) { frame.bind(node, 0); if (node.mSplit != null) { node = finishSplitShared(frame, node); if (frame.mNodePos != 0) { // Rebind if position changed (possibly negative). frame.bindOrReposition(node, 0); } } if (node.isLeaf()) { mLeaf = frame; return node; } node = latchToChild(node, 0); frame = new CursorFrame(frame); } } catch (Throwable e) { throw cleanup(e, frame); } }
/** * Moves the cursor to the first subtree leaf node, which might be empty or full of * ghosts. Leaf frame remains latched when method returns normally. * * @param frame frame to bind node to * @param node latched node; can have no keys * @return latched first node, possibly empty, bound by mFrame */ private Node toFirstLeaf(CursorFrame frame, Node node) throws IOException { try { while (true) { frame.bind(node, 0); if (node.mSplit != null) { node = finishSplitShared(frame, node); if (frame.mNodePos != 0) { // Rebind if position changed (possibly negative). frame.bindOrReposition(node, 0); } } if (node.isLeaf()) { mFrame = frame; return node; } node = mTree.mDatabase.latchToChild(node, 0); frame = new CursorFrame(frame); } } catch (Throwable e) { throw cleanup(e, frame); } }
private static boolean isEmpty(Tree tree) { Node root = tree.mRoot; root.acquireShared(); boolean empty = root.isLeaf() && !root.hasKeys(); root.releaseShared(); if (!empty) { // Double check with a cursor. Tree might be composed of many empty leaf nodes. TreeCursor c = tree.newCursor(Transaction.BOGUS); try { c.mKeyOnly = true; c.first(); empty = c.key() == null; } catch (Throwable e) { // Ignore and keep using the tree for now. } finally { c.reset(); } } return empty; } }
if (node.isLeaf()) {