/// <summary>For the given datanode, choose a candidate and then schedule it.</summary> /// <returns>true if a candidate is chosen; false if no candidates is chosen.</returns> private bool Choose4One <C>(Dispatcher.DDatanode.StorageGroup g, ICollection <C> candidates , Matcher matcher) where C : Dispatcher.DDatanode.StorageGroup { IEnumerator <C> i = candidates.GetEnumerator(); C chosen = ChooseCandidate(g, i, matcher); if (chosen == null) { return(false); } if (g is Dispatcher.Source) { MatchSourceWithTargetToMove((Dispatcher.Source)g, chosen); } else { MatchSourceWithTargetToMove((Dispatcher.Source)chosen, g); } if (!chosen.HasSpaceForScheduling()) { i.Remove(); } return(true); }
private void Add(Dispatcher.Source source, Dispatcher.DDatanode.StorageGroup target ) { sources.Put(source); if (target != null) { targets.Put(target); GetTargetStorages(target.GetStorageType()).AddItem(target); } }
private void MatchSourceWithTargetToMove(Dispatcher.Source source, Dispatcher.DDatanode.StorageGroup target) { long size = Math.Min(source.AvailableSizeToMove(), target.AvailableSizeToMove()); Dispatcher.Task task = new Dispatcher.Task(target, size); source.AddTask(task); target.IncScheduledSize(task.GetSize()); dispatcher.Add(source, target); Log.Info("Decided to move " + StringUtils.ByteDesc(size) + " bytes from " + source .GetDisplayName() + " to " + target.GetDisplayName()); }
internal virtual Dispatcher.DBlock NewDBlock(Block block, IList <Mover.MLocation> locations) { Dispatcher.DBlock db = new Dispatcher.DBlock(block); foreach (Mover.MLocation ml in locations) { Dispatcher.DDatanode.StorageGroup source = storages.GetSource(ml); if (source != null) { db.AddLocation(source); } } return(db); }
/// <exception cref="System.IO.IOException"/> internal virtual void Init() { InitStoragePolicies(); IList <DatanodeStorageReport> reports = dispatcher.Init(); foreach (DatanodeStorageReport r in reports) { Dispatcher.DDatanode dn = dispatcher.NewDatanode(r.GetDatanodeInfo()); foreach (StorageType t in StorageType.GetMovableTypes()) { Dispatcher.Source source = dn.AddSource(t, long.MaxValue, dispatcher); long maxRemaining = GetMaxRemaining(r, t); Dispatcher.DDatanode.StorageGroup target = maxRemaining > 0L ? dn.AddTarget(t, maxRemaining ) : null; storages.Add(source, target); } } }
/// <summary>Choose the target storage within same Datanode if possible.</summary> internal virtual bool ChooseTargetInSameNode(Dispatcher.DBlock db, Dispatcher.Source source, IList <StorageType> targetTypes) { foreach (StorageType t in targetTypes) { Dispatcher.DDatanode.StorageGroup target = this._enclosing.storages.GetTarget(source .GetDatanodeInfo().GetDatanodeUuid(), t); if (target == null) { continue; } Dispatcher.PendingMove pm = source.AddPendingMove(db, target); if (pm != null) { this._enclosing.dispatcher.ExecutePendingMove(pm); return(true); } } return(false); }