if (this.readers == null) {
return super.getNext();
}
while (currentReaderIndexStart < this.readers.length) {
IndexedStorageRecordReader r = this.readers[currentReaderIndexStart];
this.prepareToRead(r, null);
Tuple tuple = super.getNext();
if (tuple == null) {
currentReaderIndexStart++;
r.close();
continue; //next Reader
}
//if we haven't yet initialized the indexManager (by reading the first index key)
if (r.indexManager.lastIndexKeyTuple == null) {
//initialize the indexManager
if (r.indexManager.ReadIndex() == null) {
//There should never be a case where there is a non-null record - but no corresponding index.
throw new IOException("Missing Index for Tuple: " + tuple);
}
}
r.indexManager.numberOfTuples--;
if (r.indexManager.numberOfTuples == 0) {
if (r.indexManager.ReadIndex() == null) {
r.close();
currentReaderIndexStart++;
} else {
//Since the index of the current reader was increased, we may need to push the
//current reader back in the sorted list of readers.
sortReader(currentReaderIndexStart);