Search in sources :

Example 1 with DomainSocket

use of org.apache.hadoop.net.unix.DomainSocket in project hadoop by apache.

the class DomainSocketFactory method createSocket.

public DomainSocket createSocket(PathInfo info, int socketTimeout) {
    Preconditions.checkArgument(info.getPathState() != PathState.UNUSABLE);
    boolean success = false;
    DomainSocket sock = null;
    try {
        sock = DomainSocket.connect(info.getPath());
        sock.setAttribute(DomainSocket.RECEIVE_TIMEOUT, socketTimeout);
        success = true;
    } catch (IOException e) {
        LOG.warn("error creating DomainSocket", e);
    // fall through
    } finally {
        if (!success) {
            if (sock != null) {
                IOUtils.closeQuietly(sock);
            }
            pathMap.put(info.getPath(), PathState.UNUSABLE);
            sock = null;
        }
    }
    return sock;
}
Also used : DomainSocket(org.apache.hadoop.net.unix.DomainSocket) IOException(java.io.IOException)

Example 2 with DomainSocket

use of org.apache.hadoop.net.unix.DomainSocket in project hadoop by apache.

the class DomainPeerServer method accept.

@Override
public Peer accept() throws IOException, SocketTimeoutException {
    DomainSocket connSock = sock.accept();
    Peer peer = null;
    boolean success = false;
    try {
        peer = new DomainPeer(connSock);
        success = true;
        return peer;
    } finally {
        if (!success) {
            if (peer != null)
                peer.close();
            connSock.close();
        }
    }
}
Also used : DomainSocket(org.apache.hadoop.net.unix.DomainSocket)

Example 3 with DomainSocket

use of org.apache.hadoop.net.unix.DomainSocket in project hadoop by apache.

the class DataXceiver method requestShortCircuitShm.

@Override
public void requestShortCircuitShm(String clientName) throws IOException {
    NewShmInfo shmInfo = null;
    boolean success = false;
    DomainSocket sock = peer.getDomainSocket();
    try {
        if (sock == null) {
            sendShmErrorResponse(ERROR_INVALID, "Bad request from " + peer + ": must request a shared " + "memory segment over a UNIX domain socket.");
            return;
        }
        try {
            shmInfo = datanode.shortCircuitRegistry.createNewMemorySegment(clientName, sock);
            // After calling #{ShortCircuitRegistry#createNewMemorySegment}, the
            // socket is managed by the DomainSocketWatcher, not the DataXceiver.
            releaseSocket();
        } catch (UnsupportedOperationException e) {
            sendShmErrorResponse(ERROR_UNSUPPORTED, "This datanode has not been configured to support " + "short-circuit shared memory segments.");
            return;
        } catch (IOException e) {
            sendShmErrorResponse(ERROR, "Failed to create shared file descriptor: " + e.getMessage());
            return;
        }
        sendShmSuccessResponse(sock, shmInfo);
        success = true;
    } finally {
        if (ClientTraceLog.isInfoEnabled()) {
            if (success) {
                BlockSender.ClientTraceLog.info(String.format("cliID: %s, src: 127.0.0.1, dest: 127.0.0.1, " + "op: REQUEST_SHORT_CIRCUIT_SHM," + " shmId: %016x%016x, srvID: %s, success: true", clientName, shmInfo.getShmId().getHi(), shmInfo.getShmId().getLo(), datanode.getDatanodeUuid()));
            } else {
                BlockSender.ClientTraceLog.info(String.format("cliID: %s, src: 127.0.0.1, dest: 127.0.0.1, " + "op: REQUEST_SHORT_CIRCUIT_SHM, " + "shmId: n/a, srvID: %s, success: false", clientName, datanode.getDatanodeUuid()));
            }
        }
        if ((!success) && (peer == null)) {
            // bad behavior inside the poll() call.  See HADOOP-11802 for details.
            try {
                LOG.warn("Failed to send success response back to the client.  " + "Shutting down socket for " + shmInfo.getShmId() + ".");
                sock.shutdown();
            } catch (IOException e) {
                LOG.warn("Failed to shut down socket in error handler", e);
            }
        }
        IOUtils.cleanup(null, shmInfo);
    }
}
Also used : DomainSocket(org.apache.hadoop.net.unix.DomainSocket) NewShmInfo(org.apache.hadoop.hdfs.server.datanode.ShortCircuitRegistry.NewShmInfo) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 4 with DomainSocket

use of org.apache.hadoop.net.unix.DomainSocket in project hadoop by apache.

the class DataXceiver method requestShortCircuitFds.

@Override
public void requestShortCircuitFds(final ExtendedBlock blk, final Token<BlockTokenIdentifier> token, SlotId slotId, int maxVersion, boolean supportsReceiptVerification) throws IOException {
    updateCurrentThreadName("Passing file descriptors for block " + blk);
    DataOutputStream out = getBufferedOutputStream();
    checkAccess(out, true, blk, token, Op.REQUEST_SHORT_CIRCUIT_FDS, BlockTokenIdentifier.AccessMode.READ);
    BlockOpResponseProto.Builder bld = BlockOpResponseProto.newBuilder();
    FileInputStream[] fis = null;
    SlotId registeredSlotId = null;
    boolean success = false;
    try {
        try {
            if (peer.getDomainSocket() == null) {
                throw new IOException("You cannot pass file descriptors over " + "anything but a UNIX domain socket.");
            }
            if (slotId != null) {
                boolean isCached = datanode.data.isCached(blk.getBlockPoolId(), blk.getBlockId());
                datanode.shortCircuitRegistry.registerSlot(ExtendedBlockId.fromExtendedBlock(blk), slotId, isCached);
                registeredSlotId = slotId;
            }
            fis = datanode.requestShortCircuitFdsForRead(blk, token, maxVersion);
            Preconditions.checkState(fis != null);
            bld.setStatus(SUCCESS);
            bld.setShortCircuitAccessVersion(DataNode.CURRENT_BLOCK_FORMAT_VERSION);
        } catch (ShortCircuitFdsVersionException e) {
            bld.setStatus(ERROR_UNSUPPORTED);
            bld.setShortCircuitAccessVersion(DataNode.CURRENT_BLOCK_FORMAT_VERSION);
            bld.setMessage(e.getMessage());
        } catch (ShortCircuitFdsUnsupportedException e) {
            bld.setStatus(ERROR_UNSUPPORTED);
            bld.setMessage(e.getMessage());
        } catch (IOException e) {
            bld.setStatus(ERROR);
            bld.setMessage(e.getMessage());
        }
        bld.build().writeDelimitedTo(socketOut);
        if (fis != null) {
            FileDescriptor[] fds = new FileDescriptor[fis.length];
            for (int i = 0; i < fds.length; i++) {
                fds[i] = fis[i].getFD();
            }
            byte[] buf = new byte[1];
            if (supportsReceiptVerification) {
                buf[0] = (byte) USE_RECEIPT_VERIFICATION.getNumber();
            } else {
                buf[0] = (byte) DO_NOT_USE_RECEIPT_VERIFICATION.getNumber();
            }
            DomainSocket sock = peer.getDomainSocket();
            sock.sendFileDescriptors(fds, buf, 0, buf.length);
            if (supportsReceiptVerification) {
                LOG.trace("Reading receipt verification byte for " + slotId);
                int val = sock.getInputStream().read();
                if (val < 0) {
                    throw new EOFException();
                }
            } else {
                LOG.trace("Receipt verification is not enabled on the DataNode.  " + "Not verifying " + slotId);
            }
            success = true;
        }
    } finally {
        if ((!success) && (registeredSlotId != null)) {
            LOG.info("Unregistering " + registeredSlotId + " because the " + "requestShortCircuitFdsForRead operation failed.");
            datanode.shortCircuitRegistry.unregisterSlot(registeredSlotId);
        }
        if (ClientTraceLog.isInfoEnabled()) {
            DatanodeRegistration dnR = datanode.getDNRegistrationForBP(blk.getBlockPoolId());
            BlockSender.ClientTraceLog.info(String.format("src: 127.0.0.1, dest: 127.0.0.1, op: REQUEST_SHORT_CIRCUIT_FDS," + " blockid: %s, srvID: %s, success: %b", blk.getBlockId(), dnR.getDatanodeUuid(), success));
        }
        if (fis != null) {
            IOUtils.cleanup(null, fis);
        }
    }
}
Also used : ShortCircuitFdsVersionException(org.apache.hadoop.hdfs.server.datanode.DataNode.ShortCircuitFdsVersionException) DataOutputStream(java.io.DataOutputStream) BlockOpResponseProto(org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.BlockOpResponseProto) ShortCircuitFdsUnsupportedException(org.apache.hadoop.hdfs.server.datanode.DataNode.ShortCircuitFdsUnsupportedException) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) FileDescriptor(java.io.FileDescriptor) SlotId(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.SlotId) DatanodeRegistration(org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration) DomainSocket(org.apache.hadoop.net.unix.DomainSocket) EOFException(java.io.EOFException)

Example 5 with DomainSocket

use of org.apache.hadoop.net.unix.DomainSocket in project hadoop by apache.

the class BlockReaderFactory method requestFileDescriptors.

/**
   * Request file descriptors from a DomainPeer.
   *
   * @param peer   The peer to use for communication.
   * @param slot   If non-null, the shared memory slot to associate with the
   *               new ShortCircuitReplica.
   *
   * @return  A ShortCircuitReplica object if we could communicate with the
   *          datanode; null, otherwise.
   * @throws  IOException If we encountered an I/O exception while communicating
   *          with the datanode.
   */
private ShortCircuitReplicaInfo requestFileDescriptors(DomainPeer peer, Slot slot) throws IOException {
    ShortCircuitCache cache = clientContext.getShortCircuitCache();
    final DataOutputStream out = new DataOutputStream(new BufferedOutputStream(peer.getOutputStream()));
    SlotId slotId = slot == null ? null : slot.getSlotId();
    new Sender(out).requestShortCircuitFds(block, token, slotId, 1, failureInjector.getSupportsReceiptVerification());
    DataInputStream in = new DataInputStream(peer.getInputStream());
    BlockOpResponseProto resp = BlockOpResponseProto.parseFrom(PBHelperClient.vintPrefixed(in));
    DomainSocket sock = peer.getDomainSocket();
    failureInjector.injectRequestFileDescriptorsFailure();
    switch(resp.getStatus()) {
        case SUCCESS:
            byte[] buf = new byte[1];
            FileInputStream[] fis = new FileInputStream[2];
            sock.recvFileInputStreams(fis, buf, 0, buf.length);
            ShortCircuitReplica replica = null;
            try {
                ExtendedBlockId key = new ExtendedBlockId(block.getBlockId(), block.getBlockPoolId());
                if (buf[0] == USE_RECEIPT_VERIFICATION.getNumber()) {
                    LOG.trace("Sending receipt verification byte for slot {}", slot);
                    sock.getOutputStream().write(0);
                }
                replica = new ShortCircuitReplica(key, fis[0], fis[1], cache, Time.monotonicNow(), slot);
                return new ShortCircuitReplicaInfo(replica);
            } catch (IOException e) {
                // This indicates an error reading from disk, or a format error.  Since
                // it's not a socket communication problem, we return null rather than
                // throwing an exception.
                LOG.warn(this + ": error creating ShortCircuitReplica.", e);
                return null;
            } finally {
                if (replica == null) {
                    IOUtilsClient.cleanup(DFSClient.LOG, fis[0], fis[1]);
                }
            }
        case ERROR_UNSUPPORTED:
            if (!resp.hasShortCircuitAccessVersion()) {
                LOG.warn("short-circuit read access is disabled for " + "DataNode " + datanode + ".  reason: " + resp.getMessage());
                clientContext.getDomainSocketFactory().disableShortCircuitForPath(pathInfo.getPath());
            } else {
                LOG.warn("short-circuit read access for the file " + fileName + " is disabled for DataNode " + datanode + ".  reason: " + resp.getMessage());
            }
            return null;
        case ERROR_ACCESS_TOKEN:
            String msg = "access control error while " + "attempting to set up short-circuit access to " + fileName + resp.getMessage();
            LOG.debug("{}:{}", this, msg);
            return new ShortCircuitReplicaInfo(new InvalidToken(msg));
        default:
            LOG.warn(this + ": unknown response code " + resp.getStatus() + " while attempting to set up short-circuit access. " + resp.getMessage());
            clientContext.getDomainSocketFactory().disableShortCircuitForPath(pathInfo.getPath());
            return null;
    }
}
Also used : ExtendedBlockId(org.apache.hadoop.hdfs.ExtendedBlockId) DataOutputStream(java.io.DataOutputStream) BlockOpResponseProto(org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.BlockOpResponseProto) IOException(java.io.IOException) ShortCircuitCache(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitCache) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) Sender(org.apache.hadoop.hdfs.protocol.datatransfer.Sender) SlotId(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.SlotId) ShortCircuitReplica(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitReplica) DomainSocket(org.apache.hadoop.net.unix.DomainSocket) InvalidToken(org.apache.hadoop.security.token.SecretManager.InvalidToken) ShortCircuitReplicaInfo(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitReplicaInfo) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

DomainSocket (org.apache.hadoop.net.unix.DomainSocket)5 IOException (java.io.IOException)4 DataOutputStream (java.io.DataOutputStream)2 FileInputStream (java.io.FileInputStream)2 InterruptedIOException (java.io.InterruptedIOException)2 BlockOpResponseProto (org.apache.hadoop.hdfs.protocol.proto.DataTransferProtos.BlockOpResponseProto)2 SlotId (org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.SlotId)2 BufferedOutputStream (java.io.BufferedOutputStream)1 DataInputStream (java.io.DataInputStream)1 EOFException (java.io.EOFException)1 FileDescriptor (java.io.FileDescriptor)1 ExtendedBlockId (org.apache.hadoop.hdfs.ExtendedBlockId)1 Sender (org.apache.hadoop.hdfs.protocol.datatransfer.Sender)1 ShortCircuitFdsUnsupportedException (org.apache.hadoop.hdfs.server.datanode.DataNode.ShortCircuitFdsUnsupportedException)1 ShortCircuitFdsVersionException (org.apache.hadoop.hdfs.server.datanode.DataNode.ShortCircuitFdsVersionException)1 NewShmInfo (org.apache.hadoop.hdfs.server.datanode.ShortCircuitRegistry.NewShmInfo)1 DatanodeRegistration (org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration)1 ShortCircuitCache (org.apache.hadoop.hdfs.shortcircuit.ShortCircuitCache)1 ShortCircuitReplica (org.apache.hadoop.hdfs.shortcircuit.ShortCircuitReplica)1 ShortCircuitReplicaInfo (org.apache.hadoop.hdfs.shortcircuit.ShortCircuitReplicaInfo)1