RangeConstraint rangeConstraint,
CursorImpl finalPositionCursor) {
/* Start with the entry at the cursor position. */
final Tree tree = databaseImpl.getTree();
BIN curBin = latchBIN();
int prevIndex = getIndex();
long count = 0;
try {
while (true) {
/* Skip entries in the current BIN. */
count = skipEntries
(forward, maxCount, rangeConstraint, finalPositionCursor,
curBin, prevIndex, count);
if (count < 0) {
return (- count);
}
/*
* Get the parent IN at level two. The BIN is unlatched by
* getParentINForChildIN. Before releasing the BIN latch, get
* the search key for the last entry.
*/
final byte[] idKey = (curBin.getNEntries() == 0) ?
curBin.getIdentifierKey() :
(forward ?
curBin.getKey(curBin.getNEntries() - 1) :
curBin.getKey(0));
final BIN binToFind = curBin;
curBin = null; // BIN latch will be released.
final SearchResult result = tree.getParentINForChildIN
(binToFind, true /*requireExactMatch*/,
CacheMode.UNCHANGED);
final IN parent = result.parent;
boolean fetchOrWait = false;
try {
if (!result.exactParentFound) {
throw EnvironmentFailureException.unexpectedState
("Cannot get parent of BIN id=" +
binToFind.getNodeId() + " key=" +
Arrays.toString(idKey));
}
/*
* Find previous child BIN by matching idKey rather than