// because if only forward seeks are being done, then there is no benefit to building
// and index for the block... could consider using the index if it exist but not
// causing the build of an index... doing this could slow down some use cases and
// and speed up others.
MByteSequence valbs = new MByteSequence(new byte[64], 0, 0);
SkippR skippr = RelativeKey.fastSkip(currBlock, startKey, valbs, prevKey, getTopKey());
if (skippr.skipped > 0) {
entriesLeft -= skippr.skipped;
val = new Value(valbs.toArray());
prevKey = skippr.prevKey;
rk = skippr.rk;
}
reseek = false;
}
if (iiter.previousIndex() == 0 && getTopKey().equals(firstKey) && startKey.compareTo(firstKey) <= 0) {
// seeking before the beginning of the file, and already positioned at the first key in the file
// so there is nothing to do
reseek = false;
}
}
if (reseek) {
iiter = index.lookup(startKey);
reset();
if (!iiter.hasNext()) {
// past the last key
} else {
// if the index contains the same key multiple times, then go to the
// earliest index entry containing the key
while (iiter.hasPrevious() && iiter.peekPrevious().getKey().equals(iiter.peek().getKey())) {
iiter.previous();
}
if (iiter.hasPrevious())
prevKey = new Key(iiter.peekPrevious().getKey()); // initially prevKey is the last key of the prev block
else
prevKey = new Key(); // first block in the file, so set prev key to minimal key
IndexEntry indexEntry = iiter.next();
entriesLeft = indexEntry.getNumEntries();
currBlock = getDataBlock(indexEntry);
checkRange = range.afterEndKey(indexEntry.getKey());
if (!checkRange)
hasTop = true;
MByteSequence valbs = new MByteSequence(new byte[64], 0, 0);
Key currKey = null;
if (currBlock.isIndexable()) {
BlockIndex blockIndex = BlockIndex.getIndex(currBlock, indexEntry);
if (blockIndex != null) {
BlockIndexEntry bie = blockIndex.seekBlock(startKey, currBlock);
if (bie != null) {
// we are seeked to the current position of the key in the index
// need to prime the read process and read this key from the block
RelativeKey tmpRk = new RelativeKey();
tmpRk.setPrevKey(bie.getPrevKey());
tmpRk.readFields(currBlock);
val = new Value();
val.readFields(currBlock);
valbs = new MByteSequence(val.get(), 0, val.getSize());
// just consumed one key from the input stream, so subtract one from entries left
entriesLeft = bie.getEntriesLeft() - 1;
prevKey = new Key(bie.getPrevKey());
currKey = tmpRk.getKey();
}
}
}
SkippR skippr = RelativeKey.fastSkip(currBlock, startKey, valbs, prevKey, currKey);
prevKey = skippr.prevKey;
entriesLeft -= skippr.skipped;
val = new Value(valbs.toArray());
// set rk when everything above is successful, if exception
// occurs rk will not be set
rk = skippr.rk;
}
}