public virtual void TestScheduleSameBlock() { Configuration conf = new HdfsConfiguration(); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(4).Build(); try { cluster.WaitActive(); DistributedFileSystem dfs = cluster.GetFileSystem(); string file = "/testScheduleSameBlock/file"; { FSDataOutputStream @out = dfs.Create(new Path(file)); @out.WriteChars("testScheduleSameBlock"); @out.Close(); } Org.Apache.Hadoop.Hdfs.Server.Mover.Mover mover = NewMover(conf); mover.Init(); Mover.Processor processor = new Mover.Processor(this); LocatedBlock lb = dfs.GetClient().GetLocatedBlocks(file, 0).Get(0); IList <Mover.MLocation> locations = Mover.MLocation.ToLocations(lb); Mover.MLocation ml = locations[0]; Dispatcher.DBlock db = mover.NewDBlock(lb.GetBlock().GetLocalBlock(), locations); IList <StorageType> storageTypes = new AList <StorageType>(Arrays.AsList(StorageType .Default, StorageType.Default)); NUnit.Framework.Assert.IsTrue(processor.ScheduleMoveReplica(db, ml, storageTypes) ); NUnit.Framework.Assert.IsFalse(processor.ScheduleMoveReplica(db, ml, storageTypes )); } finally { cluster.Shutdown(); } }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> internal static int Run(IDictionary <URI, IList <Path> > namenodes, Configuration conf ) { long sleeptime = conf.GetLong(DFSConfigKeys.DfsHeartbeatIntervalKey, DFSConfigKeys .DfsHeartbeatIntervalDefault) * 2000 + conf.GetLong(DFSConfigKeys.DfsNamenodeReplicationIntervalKey , DFSConfigKeys.DfsNamenodeReplicationIntervalDefault) * 1000; AtomicInteger retryCount = new AtomicInteger(0); Log.Info("namenodes = " + namenodes); IList <NameNodeConnector> connectors = Sharpen.Collections.EmptyList(); try { connectors = NameNodeConnector.NewNameNodeConnectors(namenodes, typeof(Org.Apache.Hadoop.Hdfs.Server.Mover.Mover ).Name, MoverIdPath, conf, NameNodeConnector.DefaultMaxIdleIterations); while (connectors.Count > 0) { Sharpen.Collections.Shuffle(connectors); IEnumerator <NameNodeConnector> iter = connectors.GetEnumerator(); while (iter.HasNext()) { NameNodeConnector nnc = iter.Next(); Org.Apache.Hadoop.Hdfs.Server.Mover.Mover m = new Org.Apache.Hadoop.Hdfs.Server.Mover.Mover (nnc, conf, retryCount); ExitStatus r = m.Run(); if (r == ExitStatus.Success) { IOUtils.Cleanup(Log, nnc); iter.Remove(); } else { if (r != ExitStatus.InProgress) { // must be an error statue, return return(r.GetExitCode()); } } } Sharpen.Thread.Sleep(sleeptime); } return(ExitStatus.Success.GetExitCode()); } finally { foreach (NameNodeConnector nnc in connectors) { IOUtils.Cleanup(Log, nnc); } } }