* @throws IOException
*/
private boolean processCommand(DatanodeCommand cmd) throws IOException, InterruptedException {
if (cmd == null)
return true;
final BlockCommand bcmd = cmd instanceof BlockCommand? (BlockCommand)cmd: null;
boolean retValue = true;
long startTime = System.currentTimeMillis();
switch(cmd.getAction()) {
case DatanodeProtocol.DNA_TRANSFER:
// Send a copy of a block to another datanode
anode.transferBlocks(servicePair.namespaceId, 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 (anode.blockScanner != null) {
//TODO temporary
anode.blockScanner.deleteBlocks(servicePair.namespaceId, toDelete);
}
servicePair.removeReceivedBlocks(toDelete);
data.invalidate(servicePair.namespaceId, toDelete);
} catch(IOException e) {
anode.checkDiskError();
throw e;
}
myMetrics.blocksRemoved.inc(toDelete.length);
break;
case DatanodeProtocol.DNA_SHUTDOWN:
// shut down the data node
servicePair.shutdown();
retValue = false;
break;
case DatanodeProtocol.DNA_REGISTER:
// namenode requested a registration - at start or if NN lost contact
LOG.info("AvatarDatanodeCommand action: DNA_REGISTER");
if (shouldRun()) {
servicePair.register(namenode, namenodeAddress);
firstBlockReportSent = false;
scheduleBlockReport(0);
}
break;
case DatanodeProtocol.DNA_FINALIZE:
anode.getStorage().finalizedUpgrade(servicePair.namespaceId);
break;
case UpgradeCommand.UC_ACTION_START_UPGRADE:
// start distributed upgrade here
servicePair.processUpgradeCommand((UpgradeCommand)cmd);
break;
case DatanodeProtocol.DNA_RECOVERBLOCK:
anode.recoverBlocks(servicePair.namespaceId, bcmd.getBlocks(), bcmd.getTargets());
break;
case DatanodeProtocols.DNA_BACKOFF:
// We can get a BACKOFF request as a response to a full block report.
setBackoff(true);
break;
case DatanodeProtocols.DNA_CLEARPRIMARY:
LOG.info("CLEAR PRIMARY requested by : " + this.avatarnodeAddress);
retValue = clearPrimary();
break;
case DatanodeProtocols.DNA_RETRY:
// We will get a RETRY request as a response to only a full block report.
LOG.info(this.avatarnodeAddress + " has requested the retry of : "
+ bcmd.getBlocks().length + " blocks in response to a full block"
+ " report");
// Retry the blocks that failed on the Standby.
processFailedBlocks(bcmd.getBlocks(), bcmd.getBlocks().length);
break;
default:
LOG.warn("Unknown DatanodeCommand action: " + cmd.getAction());
}