Example usage for org.apache.hadoop.hdfs.server.protocol BlockCommand getBlocks

List of usage examples for org.apache.hadoop.hdfs.server.protocol BlockCommand getBlocks

Introduction

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

Prototype

public Block[] getBlocks() 

Source Link

Usage

From source file:common.DataNode.java

License:Apache License

/**
 * //  w ww . j  av  a  2  s.  c o m
 * @param cmd
 * @return true if further processing may be required or false otherwise. 
 * @throws IOException
 */
private boolean processCommand(DatanodeCommand cmd) throws IOException {
    if (cmd == null)
        return true;
    final BlockCommand bcmd = cmd instanceof BlockCommand ? (BlockCommand) cmd : null;

    switch (cmd.getAction()) {
    case DatanodeProtocol.DNA_TRANSFER:
        // Send a copy of a block to another datanode
        transferBlocks(bcmd.getBlocks(), bcmd.getTargets());
        myMetrics.blocksReplicated.inc(bcmd.getBlocks().length);
        break;
    case DatanodeProtocol.DNA_INVALIDATE:
        //
        // Some local block(s) are obsolete and can be 
        // safely garbage-collected.
        //
        Block toDelete[] = bcmd.getBlocks();
        try {
            if (blockScanner != null) {
                blockScanner.deleteBlocks(toDelete);
            }
            data.invalidate(toDelete);
        } catch (IOException e) {
            checkDiskError();
            throw e;
        }
        myMetrics.blocksRemoved.inc(toDelete.length);
        break;
    case DatanodeProtocol.DNA_SHUTDOWN:
        // shut down the data node
        this.shutdown();
        return false;
    case DatanodeProtocol.DNA_REGISTER:
        // namenode requested a registration - at start or if NN lost contact
        LOG.info("DatanodeCommand action: DNA_REGISTER");
        if (shouldRun) {
            register();
        }
        break;
    case DatanodeProtocol.DNA_FINALIZE:
        storage.finalizeUpgrade();
        break;
    case UpgradeCommand.UC_ACTION_START_UPGRADE:
        // start distributed upgrade here
        processDistributedUpgradeCommand((UpgradeCommand) cmd);
        break;
    case DatanodeProtocol.DNA_RECOVERBLOCK:
        recoverBlocks(((BlockRecoveryCommand) cmd).getRecoveringBlocks());
        break;
    case DatanodeProtocol.DNA_ACCESSKEYUPDATE:
        LOG.info("DatanodeCommand action: DNA_ACCESSKEYUPDATE");
        if (isAccessTokenEnabled) {
            accessTokenHandler.setKeys(((KeyUpdateCommand) cmd).getExportedKeys());
        }
        break;
    default:
        LOG.warn("Unknown DatanodeCommand action: " + cmd.getAction());
    }
    return true;
}