Example usage for org.apache.hadoop.hdfs.shortcircuit ShortCircuitReplicaInfo getReplica

List of usage examples for org.apache.hadoop.hdfs.shortcircuit ShortCircuitReplicaInfo getReplica

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.shortcircuit ShortCircuitReplicaInfo getReplica.

Prototype

public ShortCircuitReplica getReplica() 

Source Link

Usage

From source file:BlockReaderFactory.java

License:Apache License

private BlockReader getBlockReaderLocal() throws InvalidToken {
    if (LOG.isTraceEnabled()) {
        LOG.trace(this + ": trying to construct a BlockReaderLocal " + "for short-circuit reads.");
    }/*from w  w  w. j  a  v  a 2  s. c o  m*/
    if (pathInfo == null) {
        pathInfo = clientContext.getDomainSocketFactory().getPathInfo(inetSocketAddress, conf);
    }
    if (!pathInfo.getPathState().getUsableForShortCircuit()) {
        PerformanceAdvisory.LOG.debug(this + ": " + pathInfo + " is not "
                + "usable for short circuit; giving up on BlockReaderLocal.");
        return null;
    }
    ShortCircuitCache cache = clientContext.getShortCircuitCache();
    ExtendedBlockId key = new ExtendedBlockId(block.getBlockId(), block.getBlockPoolId());
    ShortCircuitReplicaInfo info = cache.fetchOrCreate(key, this);
    InvalidToken exc = info.getInvalidTokenException();
    if (exc != null) {
        if (LOG.isTraceEnabled()) {
            LOG.trace(this + ": got InvalidToken exception while trying to " + "construct BlockReaderLocal via "
                    + pathInfo.getPath());
        }
        throw exc;
    }
    if (info.getReplica() == null) {
        if (LOG.isTraceEnabled()) {
            PerformanceAdvisory.LOG.debug(this + ": failed to get " + "ShortCircuitReplica. Cannot construct "
                    + "BlockReaderLocal via " + pathInfo.getPath());
        }
        return null;
    }
    return new BlockReaderLocal.Builder(conf).setFilename(fileName).setBlock(block).setStartOffset(startOffset)
            .setShortCircuitReplica(info.getReplica()).setVerifyChecksum(verifyChecksum)
            .setCachingStrategy(cachingStrategy).setStorageType(storageType).build();
}