Search in sources :

Example 16 with Closeable

use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.

the class AllocationManager method associate.

private BufferLedger associate(final BaseAllocator allocator, final boolean retain) {
    allocator.assertOpen();
    if (root != allocator.root) {
        throw new IllegalStateException("A buffer can only be associated between two allocators that share the same root.");
    }
    try (@SuppressWarnings("unused") Closeable read = readLock.open()) {
        final BufferLedger ledger = map.get(allocator);
        if (ledger != null) {
            if (retain) {
                ledger.inc();
            }
            return ledger;
        }
    }
    try (@SuppressWarnings("unused") Closeable write = writeLock.open()) {
        // we have to recheck existing ledger since a second reader => writer could be competing with us.
        final BufferLedger existingLedger = map.get(allocator);
        if (existingLedger != null) {
            if (retain) {
                existingLedger.inc();
            }
            return existingLedger;
        }
        final BufferLedger ledger = new BufferLedger(allocator, new ReleaseListener(allocator));
        if (retain) {
            ledger.inc();
        }
        BufferLedger oldLedger = map.put(allocator, ledger);
        Preconditions.checkArgument(oldLedger == null);
        allocator.associateLedger(ledger);
        return ledger;
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable)

Example 17 with Closeable

use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.

the class VersionedDelegatingStore method contains.

@Override
public boolean contains(final String key, final DataChangeVersion dataChangeVersion) {
    try (@SuppressWarnings("unused") Closeable lock = readLock.open()) {
        boolean contains = store.contains(key);
        dataChangeVersion.setVersion(version);
        return contains;
    }
}
Also used : Closeable(org.apache.drill.common.AutoCloseables.Closeable)

Example 18 with Closeable

use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.

the class FunctionRegistryHolder method getAllJarsWithFunctionHolders.

/**
 * Retrieves all functions (holders) associated with all the jars
 * This is read operation, so several users can perform this operation at the same time.
 * @return list of all functions, mapped by their sources
 */
public Map<String, List<FunctionHolder>> getAllJarsWithFunctionHolders() {
    Map<String, List<FunctionHolder>> allFunctionHoldersByJar = new HashMap<>();
    try (@SuppressWarnings("unused") Closeable lock = readLock.open()) {
        for (String jarName : jars.keySet()) {
            // Capture functionHolders here
            List<FunctionHolder> drillFuncHolderList = new LinkedList<>();
            Map<String, Queue<String>> functionsInJar = jars.get(jarName);
            for (Map.Entry<String, Queue<String>> functionEntry : functionsInJar.entrySet()) {
                String fnName = functionEntry.getKey();
                Queue<String> fnSignatureList = functionEntry.getValue();
                // Get all FunctionHolders (irrespective of source)
                Map<String, DrillFuncHolder> functionHolders = functions.get(fnName);
                // Iterate for matching entries and populate new Map
                for (Map.Entry<String, DrillFuncHolder> entry : functionHolders.entrySet()) {
                    if (fnSignatureList.contains(entry.getKey())) {
                        drillFuncHolderList.add(new FunctionHolder(fnName, entry.getKey(), entry.getValue()));
                    }
                }
            }
            allFunctionHoldersByJar.put(jarName, drillFuncHolderList);
        }
    }
    return allFunctionHoldersByJar;
}
Also used : DrillFuncHolder(org.apache.drill.exec.expr.fn.DrillFuncHolder) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Closeable(org.apache.drill.common.AutoCloseables.Closeable) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Queue(java.util.Queue) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with Closeable

use of org.apache.drill.common.AutoCloseables.Closeable in project drill by apache.

the class CustomHandlerRegistry method handle.

public Response handle(CustomMessage message, DrillBuf dBody) throws RpcException {
    final ParsingHandler<?, ?> handler;
    try (@SuppressWarnings("unused") Closeable lock = read.open()) {
        handler = handlers.get(message.getType());
    }
    if (handler == null) {
        throw new UserRpcException(endpoint, "Unable to handle message.", new IllegalStateException(String.format("Unable to handle message. The message type provided [%d] did not have a registered handler.", message.getType())));
    }
    final CustomResponse<?> customResponse = handler.onMessage(message.getMessage(), dBody);
    @SuppressWarnings("unchecked") final CustomMessage responseMessage = CustomMessage.newBuilder().setMessage(ByteString.copyFrom(((Controller.CustomSerDe<Object>) handler.getResponseSerDe()).serializeToSend(customResponse.getMessage()))).setType(message.getType()).build();
    // make sure we don't pass in a null array.
    final ByteBuf[] dBodies = customResponse.getBodies() == null ? new DrillBuf[0] : customResponse.getBodies();
    return new Response(RpcType.RESP_CUSTOM, responseMessage, dBodies);
}
Also used : Response(org.apache.drill.exec.rpc.Response) CustomResponse(org.apache.drill.exec.rpc.control.Controller.CustomResponse) UserRpcException(org.apache.drill.exec.rpc.UserRpcException) Closeable(org.apache.drill.common.AutoCloseables.Closeable) CustomMessage(org.apache.drill.exec.proto.BitControl.CustomMessage) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

Closeable (org.apache.drill.common.AutoCloseables.Closeable)19 List (java.util.List)3 Map (java.util.Map)3 Queue (java.util.Queue)3 ByteBuf (io.netty.buffer.ByteBuf)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)2 VersionMismatchException (org.apache.drill.exec.exception.VersionMismatchException)2 CustomMessage (org.apache.drill.exec.proto.BitControl.CustomMessage)2 Response (org.apache.drill.exec.rpc.Response)2 UserRpcException (org.apache.drill.exec.rpc.UserRpcException)2 CustomResponse (org.apache.drill.exec.rpc.control.Controller.CustomResponse)2 DrillFuncHolder (org.apache.drill.exec.expr.fn.DrillFuncHolder)1