@Override
public IterOutcome next() {
stats.startProcessing();
try{
RawFragmentBatch batch;
try {
stats.startWait();
batch = fragProvider.getNext();
// skip over empty batches. we do this since these are basically control messages.
while (batch != null && !batch.getHeader().getIsOutOfMemory() && batch.getHeader().getDef().getRecordCount() == 0 && !first) {
batch = fragProvider.getNext();
}
} finally {
stats.stopWait();
}
first = false;
if (batch == null) {
batchLoader.clear();
if (context.isCancelled()) {
return IterOutcome.STOP;
}
return IterOutcome.NONE;
}
if (batch.getHeader().getIsOutOfMemory()) {
return IterOutcome.OUT_OF_MEMORY;
}
// logger.debug("Next received batch {}", batch);
RecordBatchDef rbd = batch.getHeader().getDef();
boolean schemaChanged = batchLoader.load(rbd, batch.getBody());
stats.addLongStat(Metric.BYTES_RECEIVED, batch.getByteCount());
batch.release();
if(schemaChanged) {
this.schema = batchLoader.getSchema();
stats.batchReceived(0, rbd.getRecordCount(), true);
return IterOutcome.OK_NEW_SCHEMA;
} else {