public virtual long GetCapacity() { if (configuredCapacity < 0) { long remaining = usage.GetCapacity() - reserved; return(remaining > 0 ? remaining : 0); } return(configuredCapacity); }
public virtual void TestVolumeSize() { Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = null; // Set aside fifth of the total capacity as reserved long reserved = 10000; conf.SetLong(DFSConfigKeys.DfsDatanodeDuReservedKey, reserved); try { cluster = new MiniDFSCluster.Builder(conf).Build(); cluster.WaitActive(); FSNamesystem namesystem = cluster.GetNamesystem(); DatanodeManager dm = cluster.GetNamesystem().GetBlockManager().GetDatanodeManager (); // Ensure the data reported for each data node is right IList <DatanodeDescriptor> live = new AList <DatanodeDescriptor>(); IList <DatanodeDescriptor> dead = new AList <DatanodeDescriptor>(); dm.FetchDatanodes(live, dead, false); NUnit.Framework.Assert.IsTrue(live.Count == 1); long used; long remaining; long configCapacity; long nonDFSUsed; long bpUsed; float percentUsed; float percentRemaining; float percentBpUsed; foreach (DatanodeDescriptor datanode in live) { used = datanode.GetDfsUsed(); remaining = datanode.GetRemaining(); nonDFSUsed = datanode.GetNonDfsUsed(); configCapacity = datanode.GetCapacity(); percentUsed = datanode.GetDfsUsedPercent(); percentRemaining = datanode.GetRemainingPercent(); bpUsed = datanode.GetBlockPoolUsed(); percentBpUsed = datanode.GetBlockPoolUsedPercent(); Log.Info("Datanode configCapacity " + configCapacity + " used " + used + " non DFS used " + nonDFSUsed + " remaining " + remaining + " perentUsed " + percentUsed + " percentRemaining " + percentRemaining); NUnit.Framework.Assert.IsTrue(configCapacity == (used + remaining + nonDFSUsed)); NUnit.Framework.Assert.IsTrue(percentUsed == DFSUtil.GetPercentUsed(used, configCapacity )); NUnit.Framework.Assert.IsTrue(percentRemaining == DFSUtil.GetPercentRemaining(remaining , configCapacity)); NUnit.Framework.Assert.IsTrue(percentBpUsed == DFSUtil.GetPercentUsed(bpUsed, configCapacity )); } DF df = new DF(new FilePath(cluster.GetDataDirectory()), conf); // // Currently two data directories are created by the data node // in the MiniDFSCluster. This results in each data directory having // capacity equals to the disk capacity of the data directory. // Hence the capacity reported by the data node is twice the disk space // the disk capacity // // So multiply the disk capacity and reserved space by two // for accommodating it // int numOfDataDirs = 2; long diskCapacity = numOfDataDirs * df.GetCapacity(); reserved *= numOfDataDirs; configCapacity = namesystem.GetCapacityTotal(); used = namesystem.GetCapacityUsed(); nonDFSUsed = namesystem.GetNonDfsUsedSpace(); remaining = namesystem.GetCapacityRemaining(); percentUsed = namesystem.GetPercentUsed(); percentRemaining = namesystem.GetPercentRemaining(); bpUsed = namesystem.GetBlockPoolUsedSpace(); percentBpUsed = namesystem.GetPercentBlockPoolUsed(); Log.Info("Data node directory " + cluster.GetDataDirectory()); Log.Info("Name node diskCapacity " + diskCapacity + " configCapacity " + configCapacity + " reserved " + reserved + " used " + used + " remaining " + remaining + " nonDFSUsed " + nonDFSUsed + " remaining " + remaining + " percentUsed " + percentUsed + " percentRemaining " + percentRemaining + " bpUsed " + bpUsed + " percentBpUsed " + percentBpUsed); // Ensure new total capacity reported excludes the reserved space NUnit.Framework.Assert.IsTrue(configCapacity == diskCapacity - reserved); // Ensure new total capacity reported excludes the reserved space NUnit.Framework.Assert.IsTrue(configCapacity == (used + remaining + nonDFSUsed)); // Ensure percent used is calculated based on used and present capacity NUnit.Framework.Assert.IsTrue(percentUsed == DFSUtil.GetPercentUsed(used, configCapacity )); // Ensure percent used is calculated based on used and present capacity NUnit.Framework.Assert.IsTrue(percentBpUsed == DFSUtil.GetPercentUsed(bpUsed, configCapacity )); // Ensure percent used is calculated based on used and present capacity NUnit.Framework.Assert.IsTrue(percentRemaining == ((float)remaining * 100.0f) / ( float)configCapacity); } finally { if (cluster != null) { cluster.Shutdown(); } } }