use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class IncomingBuffers method close.
@Override
public void close() throws Exception {
try (AutoCloseableLock lock = exclusiveCloseLock.open()) {
closed = true;
AutoCloseables.close(collectorMap.values());
}
}
use of org.apache.drill.common.concurrent.AutoCloseableLock in project drill by apache.
the class IncomingBuffers method batchArrived.
public boolean batchArrived(final IncomingDataBatch incomingBatch) throws FragmentSetupException, IOException {
// Otherwise we would leak memory.
try (AutoCloseableLock lock = sharedIncomingBatchLock.open()) {
if (closed) {
return false;
}
if (incomingBatch.getHeader().getIsLastBatch()) {
streamsRemaining.decrementAndGet();
}
final int sendMajorFragmentId = incomingBatch.getHeader().getSendingMajorFragmentId();
DataCollector collector = collectorMap.get(sendMajorFragmentId);
if (collector == null) {
throw new FragmentSetupException(String.format("We received a major fragment id that we were not expecting. The id was %d. %s", sendMajorFragmentId, Arrays.toString(collectorMap.values().toArray())));
}
synchronized (collector) {
final RawFragmentBatch newRawFragmentBatch = incomingBatch.newRawFragmentBatch(context.getAllocator());
boolean decrementedToZero = collector.batchArrived(incomingBatch.getHeader().getSendingMinorFragmentId(), newRawFragmentBatch);
newRawFragmentBatch.release();
// we should only return true if remaining required has been decremented and is currently equal to zero.
return decrementedToZero;
}
}
}
Aggregations