Example usage for org.apache.hadoop.hdfs.server.protocol ReplicaRecoveryInfo getGenerationStamp

List of usage examples for org.apache.hadoop.hdfs.server.protocol ReplicaRecoveryInfo getGenerationStamp

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.server.protocol ReplicaRecoveryInfo getGenerationStamp.

Prototype

public long getGenerationStamp() 

Source Link

Usage

From source file:common.DataNode.java

License:Apache License

/** Recover a block */
private void recoverBlock(RecoveringBlock rBlock) throws IOException {
    Block block = rBlock.getBlock();/*from   ww  w.j  a va2 s.co m*/
    DatanodeInfo[] targets = rBlock.getLocations();
    DatanodeID[] datanodeids = (DatanodeID[]) targets;
    List<BlockRecord> syncList = new ArrayList<BlockRecord>(datanodeids.length);
    int errorCount = 0;

    //check generation stamps
    for (DatanodeID id : datanodeids) {
        try {
            InterDatanodeProtocol datanode = dnRegistration.equals(id) ? this
                    : DataNode.createInterDataNodeProtocolProxy(id, getConf());
            ReplicaRecoveryInfo info = callInitReplicaRecovery(datanode, rBlock);
            if (info != null && info.getGenerationStamp() >= block.getGenerationStamp()
                    && info.getNumBytes() > 0) {
                syncList.add(new BlockRecord(id, datanode, info));
            }
        } catch (RecoveryInProgressException ripE) {
            InterDatanodeProtocol.LOG.warn("Recovery for replica " + block + " on data-node " + id
                    + " is already in progress. Recovery id = " + rBlock.getNewGenerationStamp()
                    + " is aborted.", ripE);
            return;
        } catch (IOException e) {
            ++errorCount;
            InterDatanodeProtocol.LOG.warn(
                    "Failed to obtain replica info for block (=" + block + ") from datanode (=" + id + ")", e);
        }
    }

    if (errorCount == datanodeids.length) {
        throw new IOException(
                "All datanodes failed: block=" + block + ", datanodeids=" + Arrays.asList(datanodeids));
    }

    syncBlock(rBlock, syncList);
}