if (sampledPosition == null)
return null;
// get either a buffered or a mmap'd input for the on-disk index
long p = sampledPosition.indexPosition;
FileDataInput input;
if (indexBuffers == null)
{
input = new BufferedRandomAccessFile(indexFilename(), "r");
((BufferedRandomAccessFile)input).seek(p);
}
else
{
input = indexInputAt(p);
}
// scan the on-disk index, starting at the nearest sampled position
try
{
int i = 0;
do
{
// handle exact sampled index hit
IndexSummary.KeyPosition kp = indexSummary.getSpannedIndexPosition(input.getAbsolutePosition());
if (kp != null && kp.key.equals(decoratedKey))
return indexSummary.getSpannedDataPosition(kp);
// if using mmapped i/o, skip to the next mmap buffer if necessary
if (input.isEOF() || kp != null)
{
if (indexBuffers == null) // not mmap-ing, just one index input
break;
FileDataInput oldInput = input;
if (kp == null)
{
input = indexInputAt(input.getAbsolutePosition());
}
else
{
long nextUnspannedPostion = input.getAbsolutePosition()
+ 2 + FBUtilities.encodedUTF8Length(StorageService.getPartitioner().convertToDiskFormat(kp.key))
+ 8;
input = indexInputAt(nextUnspannedPostion);
}
oldInput.close();
if (input == null)
break;
continue;
}