Example usage for org.apache.hadoop.hdfs.shortcircuit ShortCircuitCache fetchOrCreate

List of usage examples for org.apache.hadoop.hdfs.shortcircuit ShortCircuitCache fetchOrCreate

Introduction

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

Prototype

public ShortCircuitReplicaInfo fetchOrCreate(ExtendedBlockId key, ShortCircuitReplicaCreator creator) 

Source Link

Document

Fetch or create a replica.

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.");
    }/*w  w  w  .j  av a2s.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();
}