Example usage for org.apache.hadoop.hdfs.protocol DatanodeInfo getXferAddr

List of usage examples for org.apache.hadoop.hdfs.protocol DatanodeInfo getXferAddr

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.protocol DatanodeInfo getXferAddr.

Prototype

public String getXferAddr(boolean useHostname) 

Source Link

Usage

From source file:com.mellanox.r4h.DFSClient.java

License:Apache License

/**
 * Connect to the given datanode's datantrasfer port, and return
 * the resulting IOStreamPair. This includes encryption wrapping, etc.
 *//*  ww w . j  a  va  2 s .  c  om*/
private IOStreamPair connectToDN(DatanodeInfo dn, int timeout, LocatedBlock lb) throws IOException {
    boolean success = false;
    Socket sock = null;
    try {
        sock = socketFactory.createSocket();
        String dnAddr = dn.getXferAddr(getConf().getConnectToDnViaHostname());
        if (LOG.isDebugEnabled()) {
            LOG.debug("Connecting to datanode " + dnAddr);
        }
        NetUtils.connect(sock, NetUtils.createSocketAddr(dnAddr), timeout);
        sock.setSoTimeout(timeout);

        OutputStream unbufOut = NetUtils.getOutputStream(sock);
        InputStream unbufIn = NetUtils.getInputStream(sock);
        IOStreamPair ret = saslClient.newSocketSend(sock, unbufOut, unbufIn, this, lb.getBlockToken(), dn);
        success = true;
        return ret;
    } finally {
        if (!success) {
            IOUtils.closeSocket(sock);
        }
    }
}

From source file:com.mellanox.r4h.DFSInputStream.java

License:Apache License

/**
 * Get the best node from which to stream the data.
 * /*w ww.j a v  a 2  s  .  c om*/
 * @param block
 *            LocatedBlock, containing nodes in priority order.
 * @param ignoredNodes
 *            Do not choose nodes in this array (may be null)
 * @return The DNAddrPair of the best node.
 * @throws IOException
 */
private DNAddrPair getBestNodeDNAddrPair(LocatedBlock block, Collection<DatanodeInfo> ignoredNodes)
        throws IOException {
    DatanodeInfo[] nodes = block.getLocations();
    StorageType[] storageTypes = block.getStorageTypes();
    DatanodeInfo chosenNode = null;
    StorageType storageType = null;
    if (nodes != null) {
        for (int i = 0; i < nodes.length; i++) {
            if (!deadNodes.containsKey(nodes[i])
                    && (ignoredNodes == null || !ignoredNodes.contains(nodes[i]))) {
                chosenNode = nodes[i];
                // Storage types are ordered to correspond with nodes, so use the same
                // index to get storage type.
                if (storageTypes != null && i < storageTypes.length) {
                    storageType = storageTypes[i];
                }
                break;
            }
        }
    }
    if (chosenNode == null) {
        throw new IOException("No live nodes contain block " + block.getBlock() + " after checking nodes = "
                + Arrays.toString(nodes) + ", ignoredNodes = " + ignoredNodes);
    }
    final String dnAddr = chosenNode.getXferAddr(dfsClient.getConf().getConnectToDnViaHostname());
    if (DFSClient.LOG.isDebugEnabled()) {
        DFSClient.LOG.debug("Connecting to datanode " + dnAddr);
    }
    InetSocketAddress targetAddr = NetUtils.createSocketAddr(dnAddr);
    return new DNAddrPair(chosenNode, targetAddr, storageType);
}

From source file:com.mellanox.r4h.DFSOutputStream.java

License:Apache License

/**
 * Create a socket for a write pipeline/*from   w  w  w  .  j  av  a 2  s . c  o m*/
 * 
 * @param first
 *            the first datanode
 * @param length
 *            the pipeline length
 * @param client
 *            client
 * @return the socket connected to the first datanode
 */
static Socket createSocketForPipeline(final DatanodeInfo first, final int length, final DFSClient client)
        throws IOException {
    final String dnAddr = first.getXferAddr(client.getConf().getConnectToDnViaHostname());
    if (DFSClient.LOG.isDebugEnabled()) {
        DFSClient.LOG.debug("Connecting to datanode " + dnAddr);
    }
    final InetSocketAddress isa = NetUtils.createSocketAddr(dnAddr);
    final Socket sock = client.socketFactory.createSocket();
    final int timeout = client.getDatanodeReadTimeout(length);
    NetUtils.connect(sock, isa, client.getRandomLocalInterfaceAddr(), client.getConf().getSocketTimeout());
    sock.setSoTimeout(timeout);
    sock.setSendBufferSize(HdfsConstants.DEFAULT_DATA_SOCKET_SIZE);
    if (DFSClient.LOG.isDebugEnabled()) {
        DFSClient.LOG.debug("Send buf size " + sock.getSendBufferSize());
    }
    return sock;
}