Search in sources :

Example 1 with DomainPeer

use of org.apache.hadoop.hdfs.net.DomainPeer in project hadoop by apache.

the class TestShortCircuitCache method testAllocShm.

@Test(timeout = 60000)
public void testAllocShm() throws Exception {
    BlockReaderTestUtil.enableShortCircuitShmTracing();
    TemporarySocketDirectory sockDir = new TemporarySocketDirectory();
    Configuration conf = createShortCircuitConf("testAllocShm", sockDir);
    MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
    cluster.waitActive();
    DistributedFileSystem fs = cluster.getFileSystem();
    final ShortCircuitCache cache = fs.getClient().getClientContext().getShortCircuitCache();
    cache.getDfsClientShmManager().visit(new Visitor() {

        @Override
        public void visit(HashMap<DatanodeInfo, PerDatanodeVisitorInfo> info) throws IOException {
            // The ClientShmManager starts off empty
            Assert.assertEquals(0, info.size());
        }
    });
    DomainPeer peer = getDomainPeerToDn(conf);
    MutableBoolean usedPeer = new MutableBoolean(false);
    ExtendedBlockId blockId = new ExtendedBlockId(123, "xyz");
    final DatanodeInfo datanode = new DatanodeInfoBuilder().setNodeID(cluster.getDataNodes().get(0).getDatanodeId()).build();
    // Allocating the first shm slot requires using up a peer.
    Slot slot = cache.allocShmSlot(datanode, peer, usedPeer, blockId, "testAllocShm_client");
    Assert.assertNotNull(slot);
    Assert.assertTrue(usedPeer.booleanValue());
    cache.getDfsClientShmManager().visit(new Visitor() {

        @Override
        public void visit(HashMap<DatanodeInfo, PerDatanodeVisitorInfo> info) throws IOException {
            // The ClientShmManager starts off empty
            Assert.assertEquals(1, info.size());
            PerDatanodeVisitorInfo vinfo = info.get(datanode);
            Assert.assertFalse(vinfo.disabled);
            Assert.assertEquals(0, vinfo.full.size());
            Assert.assertEquals(1, vinfo.notFull.size());
        }
    });
    cache.scheduleSlotReleaser(slot);
    // Wait for the slot to be released, and the shared memory area to be
    // closed.  Since we didn't register this shared memory segment on the
    // server, it will also be a test of how well the server deals with
    // bogus client behavior.
    GenericTestUtils.waitFor(new Supplier<Boolean>() {

        @Override
        public Boolean get() {
            final MutableBoolean done = new MutableBoolean(false);
            try {
                cache.getDfsClientShmManager().visit(new Visitor() {

                    @Override
                    public void visit(HashMap<DatanodeInfo, PerDatanodeVisitorInfo> info) throws IOException {
                        done.setValue(info.get(datanode).full.isEmpty() && info.get(datanode).notFull.isEmpty());
                    }
                });
            } catch (IOException e) {
                LOG.error("error running visitor", e);
            }
            return done.booleanValue();
        }
    }, 10, 60000);
    cluster.shutdown();
    sockDir.close();
}
Also used : DatanodeInfo(org.apache.hadoop.hdfs.protocol.DatanodeInfo) MiniDFSCluster(org.apache.hadoop.hdfs.MiniDFSCluster) Configuration(org.apache.hadoop.conf.Configuration) Visitor(org.apache.hadoop.hdfs.shortcircuit.DfsClientShmManager.Visitor) CacheVisitor(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitCache.CacheVisitor) ExtendedBlockId(org.apache.hadoop.hdfs.ExtendedBlockId) DatanodeInfoBuilder(org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder) HashMap(java.util.HashMap) DatanodeInfoBuilder(org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) IOException(java.io.IOException) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) DomainPeer(org.apache.hadoop.hdfs.net.DomainPeer) TemporarySocketDirectory(org.apache.hadoop.net.unix.TemporarySocketDirectory) PerDatanodeVisitorInfo(org.apache.hadoop.hdfs.shortcircuit.DfsClientShmManager.PerDatanodeVisitorInfo) Slot(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.Slot) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) Test(org.junit.Test)

Example 2 with DomainPeer

use of org.apache.hadoop.hdfs.net.DomainPeer in project hadoop by apache.

the class BlockReaderFactory method getRemoteBlockReaderFromDomain.

/**
   * Get a BlockReaderRemote that communicates over a UNIX domain socket.
   *
   * @return The new BlockReader, or null if we failed to create the block
   * reader.
   *
   * @throws InvalidToken    If the block token was invalid.
   * Potentially other security-related execptions.
   */
private BlockReader getRemoteBlockReaderFromDomain() throws IOException {
    if (pathInfo == null) {
        pathInfo = clientContext.getDomainSocketFactory().getPathInfo(inetSocketAddress, conf.getShortCircuitConf());
    }
    if (!pathInfo.getPathState().getUsableForDataTransfer()) {
        PerformanceAdvisory.LOG.debug("{}: not trying to create a " + "remote block reader because the UNIX domain socket at {}" + " is not usable.", this, pathInfo);
        return null;
    }
    LOG.trace("{}: trying to create a remote block reader from the UNIX domain " + "socket at {}", this, pathInfo.getPath());
    while (true) {
        BlockReaderPeer curPeer = nextDomainPeer();
        if (curPeer == null)
            break;
        if (curPeer.fromCache)
            remainingCacheTries--;
        DomainPeer peer = (DomainPeer) curPeer.peer;
        BlockReader blockReader = null;
        try {
            blockReader = getRemoteBlockReader(peer);
            return blockReader;
        } catch (IOException ioe) {
            IOUtilsClient.cleanup(LOG, peer);
            if (isSecurityException(ioe)) {
                LOG.trace("{}: got security exception while constructing a remote " + " block reader from the unix domain socket at {}", this, pathInfo.getPath(), ioe);
                throw ioe;
            }
            if (curPeer.fromCache) {
                // Handle an I/O error we got when using a cached peer.  These are
                // considered less serious because the underlying socket may be stale.
                LOG.debug("Closed potentially stale domain peer {}", peer, ioe);
            } else {
                // Handle an I/O error we got when using a newly created domain peer.
                // We temporarily disable the domain socket path for a few minutes in
                // this case, to prevent wasting more time on it.
                LOG.warn("I/O error constructing remote block reader.  Disabling " + "domain socket " + peer.getDomainSocket(), ioe);
                clientContext.getDomainSocketFactory().disableDomainSocketPath(pathInfo.getPath());
                return null;
            }
        } finally {
            if (blockReader == null) {
                IOUtilsClient.cleanup(LOG, peer);
            }
        }
    }
    return null;
}
Also used : BlockReader(org.apache.hadoop.hdfs.BlockReader) IOException(java.io.IOException) DomainPeer(org.apache.hadoop.hdfs.net.DomainPeer)

Example 3 with DomainPeer

use of org.apache.hadoop.hdfs.net.DomainPeer in project hadoop by apache.

the class BlockReaderFactory method createShortCircuitReplicaInfo.

/**
   * Fetch a pair of short-circuit block descriptors from a local DataNode.
   *
   * @return    Null if we could not communicate with the datanode,
   *            a new ShortCircuitReplicaInfo object otherwise.
   *            ShortCircuitReplicaInfo objects may contain either an
   *            InvalidToken exception, or a ShortCircuitReplica object ready to
   *            use.
   */
@Override
public ShortCircuitReplicaInfo createShortCircuitReplicaInfo() {
    if (createShortCircuitReplicaInfoCallback != null) {
        ShortCircuitReplicaInfo info = createShortCircuitReplicaInfoCallback.createShortCircuitReplicaInfo();
        if (info != null)
            return info;
    }
    LOG.trace("{}: trying to create ShortCircuitReplicaInfo.", this);
    BlockReaderPeer curPeer;
    while (true) {
        curPeer = nextDomainPeer();
        if (curPeer == null)
            break;
        if (curPeer.fromCache)
            remainingCacheTries--;
        DomainPeer peer = (DomainPeer) curPeer.peer;
        Slot slot = null;
        ShortCircuitCache cache = clientContext.getShortCircuitCache();
        try {
            MutableBoolean usedPeer = new MutableBoolean(false);
            slot = cache.allocShmSlot(datanode, peer, usedPeer, new ExtendedBlockId(block.getBlockId(), block.getBlockPoolId()), clientName);
            if (usedPeer.booleanValue()) {
                LOG.trace("{}: allocShmSlot used up our previous socket {}.  " + "Allocating a new one...", this, peer.getDomainSocket());
                curPeer = nextDomainPeer();
                if (curPeer == null)
                    break;
                peer = (DomainPeer) curPeer.peer;
            }
            ShortCircuitReplicaInfo info = requestFileDescriptors(peer, slot);
            clientContext.getPeerCache().put(datanode, peer);
            return info;
        } catch (IOException e) {
            if (slot != null) {
                cache.freeSlot(slot);
            }
            if (curPeer.fromCache) {
                // Handle an I/O error we got when using a cached socket.
                // These are considered less serious, because the socket may be stale.
                LOG.debug("{}: closing stale domain peer {}", this, peer, e);
                IOUtilsClient.cleanup(LOG, peer);
            } else {
                // Handle an I/O error we got when using a newly created socket.
                // We temporarily disable the domain socket path for a few minutes in
                // this case, to prevent wasting more time on it.
                LOG.warn(this + ": I/O error requesting file descriptors.  " + "Disabling domain socket " + peer.getDomainSocket(), e);
                IOUtilsClient.cleanup(LOG, peer);
                clientContext.getDomainSocketFactory().disableDomainSocketPath(pathInfo.getPath());
                return null;
            }
        }
    }
    return null;
}
Also used : ExtendedBlockId(org.apache.hadoop.hdfs.ExtendedBlockId) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean) Slot(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.Slot) IOException(java.io.IOException) ShortCircuitReplicaInfo(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitReplicaInfo) ShortCircuitCache(org.apache.hadoop.hdfs.shortcircuit.ShortCircuitCache) DomainPeer(org.apache.hadoop.hdfs.net.DomainPeer)

Aggregations

IOException (java.io.IOException)3 DomainPeer (org.apache.hadoop.hdfs.net.DomainPeer)3 MutableBoolean (org.apache.commons.lang.mutable.MutableBoolean)2 ExtendedBlockId (org.apache.hadoop.hdfs.ExtendedBlockId)2 Slot (org.apache.hadoop.hdfs.shortcircuit.ShortCircuitShm.Slot)2 HashMap (java.util.HashMap)1 Configuration (org.apache.hadoop.conf.Configuration)1 BlockReader (org.apache.hadoop.hdfs.BlockReader)1 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)1 MiniDFSCluster (org.apache.hadoop.hdfs.MiniDFSCluster)1 DatanodeInfo (org.apache.hadoop.hdfs.protocol.DatanodeInfo)1 DatanodeInfoBuilder (org.apache.hadoop.hdfs.protocol.DatanodeInfo.DatanodeInfoBuilder)1 PerDatanodeVisitorInfo (org.apache.hadoop.hdfs.shortcircuit.DfsClientShmManager.PerDatanodeVisitorInfo)1 Visitor (org.apache.hadoop.hdfs.shortcircuit.DfsClientShmManager.Visitor)1 ShortCircuitCache (org.apache.hadoop.hdfs.shortcircuit.ShortCircuitCache)1 CacheVisitor (org.apache.hadoop.hdfs.shortcircuit.ShortCircuitCache.CacheVisitor)1 ShortCircuitReplicaInfo (org.apache.hadoop.hdfs.shortcircuit.ShortCircuitReplicaInfo)1 TemporarySocketDirectory (org.apache.hadoop.net.unix.TemporarySocketDirectory)1 Test (org.junit.Test)1