Search in sources :

Example 16 with AutoCloseableLock

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());
    }
}
Also used : AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock)

Example 17 with AutoCloseableLock

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;
        }
    }
}
Also used : RawFragmentBatch(org.apache.drill.exec.record.RawFragmentBatch) AutoCloseableLock(org.apache.drill.common.concurrent.AutoCloseableLock) FragmentSetupException(org.apache.drill.exec.exception.FragmentSetupException)

Aggregations

AutoCloseableLock (org.apache.drill.common.concurrent.AutoCloseableLock)17 IOException (java.io.IOException)5 VersionMismatchException (org.apache.drill.exec.exception.VersionMismatchException)3 OutputStream (java.io.OutputStream)2 Path (org.apache.hadoop.fs.Path)2 Function (com.google.common.base.Function)1 ByteBuf (io.netty.buffer.ByteBuf)1 List (java.util.List)1 Map (java.util.Map)1 Queue (java.util.Queue)1 ImmutableEntry (org.apache.drill.common.collections.ImmutableEntry)1 FragmentSetupException (org.apache.drill.exec.exception.FragmentSetupException)1 CustomMessage (org.apache.drill.exec.proto.BitControl.CustomMessage)1 RawFragmentBatch (org.apache.drill.exec.record.RawFragmentBatch)1 Response (org.apache.drill.exec.rpc.Response)1 UserRpcException (org.apache.drill.exec.rpc.UserRpcException)1 CustomResponse (org.apache.drill.exec.rpc.control.Controller.CustomResponse)1 FileStatus (org.apache.hadoop.fs.FileStatus)1