}
// open the reader early, giving it a FINAL descriptor type so that it is indistinguishable for other consumers
SegmentedFile ifile = iwriter.builder.openEarly(link.filenameFor(Component.PRIMARY_INDEX));
SegmentedFile dfile = dbuilder.openEarly(link.filenameFor(Component.DATA));
SSTableReader sstable = SSTableReader.internalOpen(descriptor.asType(Descriptor.Type.FINAL),
components, metadata,
partitioner, ifile,
dfile, iwriter.summary.build(partitioner, exclusiveUpperBoundOfReadableIndex),
iwriter.bf, maxDataAge, sstableMetadata, SSTableReader.OpenReason.EARLY);
// now it's open, find the ACTUAL last readable key (i.e. for which the data file has also been flushed)
sstable.first = getMinimalKey(first);
sstable.last = getMinimalKey(exclusiveUpperBoundOfReadableIndex);
DecoratedKey inclusiveUpperBoundOfReadableData = iwriter.getMaxReadableKey(1);
if (inclusiveUpperBoundOfReadableData == null)
return null;
int offset = 2;
while (true)
{
RowIndexEntry indexEntry = sstable.getPosition(inclusiveUpperBoundOfReadableData, SSTableReader.Operator.GT);
if (indexEntry != null && indexEntry.position <= dataFile.getLastFlushOffset())
break;
inclusiveUpperBoundOfReadableData = iwriter.getMaxReadableKey(offset++);
if (inclusiveUpperBoundOfReadableData == null)
return null;