public virtual void TestSendOOBToPeers() { DataNode dn = cluster.GetDataNodes()[0]; DataXceiverServer spyXserver = Org.Mockito.Mockito.Spy(dn.GetXferServer()); ArgumentNullException e = new ArgumentNullException(); Org.Mockito.Mockito.DoThrow(e).When(spyXserver).SendOOBToPeers(); dn.xserver = spyXserver; try { dn.Shutdown(); } catch (Exception t) { NUnit.Framework.Assert.Fail("DataNode shutdown should not have thrown exception " + t); } }
/// <summary> /// This method should handle all commands from Active namenode except /// DNA_REGISTER which should be handled earlier itself. /// </summary> /// <param name="cmd"/> /// <returns>true if further processing may be required or false otherwise.</returns> /// <exception cref="System.IO.IOException"/> private bool ProcessCommandFromActive(DatanodeCommand cmd, BPServiceActor actor) { BlockCommand bcmd = cmd is BlockCommand ? (BlockCommand)cmd : null; BlockIdCommand blockIdCmd = cmd is BlockIdCommand ? (BlockIdCommand)cmd : null; switch (cmd.GetAction()) { case DatanodeProtocol.DnaTransfer: { // Send a copy of a block to another datanode dn.TransferBlocks(bcmd.GetBlockPoolId(), bcmd.GetBlocks(), bcmd.GetTargets(), bcmd .GetTargetStorageTypes()); dn.metrics.IncrBlocksReplicated(bcmd.GetBlocks().Length); break; } case DatanodeProtocol.DnaInvalidate: { // // Some local block(s) are obsolete and can be // safely garbage-collected. // Block[] toDelete = bcmd.GetBlocks(); try { // using global fsdataset dn.GetFSDataset().Invalidate(bcmd.GetBlockPoolId(), toDelete); } catch (IOException e) { // Exceptions caught here are not expected to be disk-related. throw; } dn.metrics.IncrBlocksRemoved(toDelete.Length); break; } case DatanodeProtocol.DnaCache: { Log.Info("DatanodeCommand action: DNA_CACHE for " + blockIdCmd.GetBlockPoolId() + " of [" + BlockIdArrayToString(blockIdCmd.GetBlockIds()) + "]"); dn.GetFSDataset().Cache(blockIdCmd.GetBlockPoolId(), blockIdCmd.GetBlockIds()); break; } case DatanodeProtocol.DnaUncache: { Log.Info("DatanodeCommand action: DNA_UNCACHE for " + blockIdCmd.GetBlockPoolId() + " of [" + BlockIdArrayToString(blockIdCmd.GetBlockIds()) + "]"); dn.GetFSDataset().Uncache(blockIdCmd.GetBlockPoolId(), blockIdCmd.GetBlockIds()); break; } case DatanodeProtocol.DnaShutdown: { // TODO: DNA_SHUTDOWN appears to be unused - the NN never sends this command // See HDFS-2987. throw new NotSupportedException("Received unimplemented DNA_SHUTDOWN"); } case DatanodeProtocol.DnaFinalize: { string bp = ((FinalizeCommand)cmd).GetBlockPoolId(); Log.Info("Got finalize command for block pool " + bp); System.Diagnostics.Debug.Assert(GetBlockPoolId().Equals(bp), "BP " + GetBlockPoolId () + " received DNA_FINALIZE " + "for other block pool " + bp); dn.FinalizeUpgradeForPool(bp); break; } case DatanodeProtocol.DnaRecoverblock: { string who = "NameNode at " + actor.GetNNSocketAddress(); dn.RecoverBlocks(who, ((BlockRecoveryCommand)cmd).GetRecoveringBlocks()); break; } case DatanodeProtocol.DnaAccesskeyupdate: { Log.Info("DatanodeCommand action: DNA_ACCESSKEYUPDATE"); if (dn.isBlockTokenEnabled) { dn.blockPoolTokenSecretManager.AddKeys(GetBlockPoolId(), ((KeyUpdateCommand)cmd). GetExportedKeys()); } break; } case DatanodeProtocol.DnaBalancerbandwidthupdate: { Log.Info("DatanodeCommand action: DNA_BALANCERBANDWIDTHUPDATE"); long bandwidth = ((BalancerBandwidthCommand)cmd).GetBalancerBandwidthValue(); if (bandwidth > 0) { DataXceiverServer dxcs = (DataXceiverServer)dn.dataXceiverServer.GetRunnable(); Log.Info("Updating balance throttler bandwidth from " + dxcs.balanceThrottler.GetBandwidth () + " bytes/s " + "to: " + bandwidth + " bytes/s."); dxcs.balanceThrottler.SetBandwidth(bandwidth); } break; } default: { Log.Warn("Unknown DatanodeCommand action: " + cmd.GetAction()); break; } } return(true); }