Example usage for org.apache.hadoop.fs BlockLocation getStorageIds

List of usage examples for org.apache.hadoop.fs BlockLocation getStorageIds

Introduction

In this page you can find the example usage for org.apache.hadoop.fs BlockLocation getStorageIds.

Prototype

public String[] getStorageIds() 

Source Link

Document

Get the storageID of each replica of the block.

Usage

From source file:org.apache.impala.catalog.HdfsTable.java

License:Apache License

/**
 * Loads the disk IDs for BlockLocation 'location' and its corresponding file block.
 * HDFS API for BlockLocation returns a storageID UUID string for each disk
 * hosting the block, which is then mapped to a 0-based integer id called disk ID.
 * Returns the number of unknown disk IDs encountered in this process.
 *///from w  w  w  .  j a v  a 2s. co  m
private int loadDiskIds(BlockLocation location, THdfsFileBlock fileBlock) {
    int unknownDiskIdCount = 0;
    String[] storageIds = location.getStorageIds();
    String[] hosts;
    try {
        hosts = location.getHosts();
    } catch (IOException e) {
        LOG.error("Couldn't get hosts for block: " + location.toString(), e);
        return unknownDiskIdCount;
    }
    if (storageIds.length != hosts.length) {
        LOG.error("Number of storage IDs and number of hosts for block: " + location.toString()
                + " mismatch. Skipping disk ID loading for this block.");
        return unknownDiskIdCount;
    }
    int[] diskIDs = new int[storageIds.length];
    for (int i = 0; i < storageIds.length; ++i) {
        if (Strings.isNullOrEmpty(storageIds[i])) {
            diskIDs[i] = -1;
            ++unknownDiskIdCount;
        } else {
            diskIDs[i] = DiskIdMapper.INSTANCE.getDiskId(hosts[i], storageIds[i]);
        }
    }
    FileBlock.setDiskIds(diskIDs, fileBlock);
    return unknownDiskIdCount;
}