Esempio n. 1
0
        public virtual void TestConvertBlockCommand()
        {
            Org.Apache.Hadoop.Hdfs.Protocol.Block[] blocks = new Org.Apache.Hadoop.Hdfs.Protocol.Block
                                                             [] { new Org.Apache.Hadoop.Hdfs.Protocol.Block(21), new Org.Apache.Hadoop.Hdfs.Protocol.Block
                                                                      (22) };
            DatanodeInfo[][] dnInfos = new DatanodeInfo[][] { new DatanodeInfo[1], new DatanodeInfo
                                                              [2] };
            dnInfos[0][0] = DFSTestUtil.GetLocalDatanodeInfo();
            dnInfos[1][0] = DFSTestUtil.GetLocalDatanodeInfo();
            dnInfos[1][1] = DFSTestUtil.GetLocalDatanodeInfo();
            string[][] storageIDs = new string[][] { new string[] { "s00" }, new string[] { "s10"
                                                                                            , "s11" } };
            StorageType[][] storageTypes = new StorageType[][] { new StorageType[] { StorageType
                                                                                     .Default }, new StorageType[] { StorageType.Default, StorageType.Default } };
            BlockCommand bc = new BlockCommand(DatanodeProtocol.DnaTransfer, "bp1", blocks, dnInfos
                                               , storageTypes, storageIDs);

            DatanodeProtocolProtos.BlockCommandProto bcProto = PBHelper.Convert(bc);
            BlockCommand bc2 = PBHelper.Convert(bcProto);

            NUnit.Framework.Assert.AreEqual(bc.GetAction(), bc2.GetAction());
            NUnit.Framework.Assert.AreEqual(bc.GetBlocks().Length, bc2.GetBlocks().Length);
            Org.Apache.Hadoop.Hdfs.Protocol.Block[] blocks2 = bc2.GetBlocks();
            for (int i = 0; i < blocks.Length; i++)
            {
                NUnit.Framework.Assert.AreEqual(blocks[i], blocks2[i]);
            }
            DatanodeInfo[][] dnInfos2 = bc2.GetTargets();
            NUnit.Framework.Assert.AreEqual(dnInfos.Length, dnInfos2.Length);
            for (int i_1 = 0; i_1 < dnInfos.Length; i_1++)
            {
                DatanodeInfo[] d1 = dnInfos[i_1];
                DatanodeInfo[] d2 = dnInfos2[i_1];
                NUnit.Framework.Assert.AreEqual(d1.Length, d2.Length);
                for (int j = 0; j < d1.Length; j++)
                {
                    Compare(d1[j], d2[j]);
                }
            }
        }
Esempio n. 2
0
        /// <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);
        }