Beispiel #1
0
 public IEnumerable <BandMailboxRebalanceData> ReduceBatchSize(IEnumerable <BandMailboxRebalanceData> results)
 {
     this.logger.Log(MigrationEventType.Information, "Reducing rebalance weights by a factor of {0}.", new object[]
     {
         this.factor
     });
     foreach (BandMailboxRebalanceData result in results)
     {
         BandMailboxRebalanceData reducedResult = new BandMailboxRebalanceData(result.SourceDatabase, result.TargetDatabase, new LoadMetricStorage())
         {
             RebalanceBatchName    = result.RebalanceBatchName,
             ConstraintSetIdentity = result.ConstraintSetIdentity
         };
         foreach (LoadMetric metric in result.RebalanceInformation.Metrics)
         {
             reducedResult.RebalanceInformation[metric] = (long)((double)result.RebalanceInformation[metric] * this.factor);
         }
         yield return(reducedResult);
     }
     yield break;
 }
Beispiel #2
0
 protected ByteQuantifiedSize GetRebalanceDatumSize(BandMailboxRebalanceData datum)
 {
     return((from metric in datum.RebalanceInformation.Metrics
             where metric.IsSize
             select metric).Aggregate(ByteQuantifiedSize.Zero, (ByteQuantifiedSize current, LoadMetric metric) => current + datum.RebalanceInformation.GetSizeMetric(metric)));
 }
        private void BalanceBand(Band band, double totalDatabaseWeight, BandData[] bandData)
        {
            this.logger.Log(MigrationEventType.Information, "Balancing band '{0}' with '{1}' data entries.", new object[]
            {
                band,
                bandData.Count <BandData>()
            });
            double             moveUnitsPerWeight = (double)bandData.Sum((BandData data) => data.TotalWeight) / totalDatabaseWeight;
            double             num                = (band.Profile == Band.BandProfile.SizeBased) ? band.MailboxSizeWeightFactor : 0.0;
            double             deviation          = (double)this.settings.WeightDeviationPercent / 100.0;
            ByteQuantifiedSize byteQuantifiedSize = ByteQuantifiedSize.FromGB((ulong)this.settings.MaximumAmountOfDataPerRoundGb);

            this.logger.Log(MigrationEventType.Verbose, "Moving with a deviation of '{0}', a minimum delta of '{1}' and a maximum of '{2}' per database.", new object[]
            {
                deviation,
                num,
                byteQuantifiedSize
            });
            List <BandData> list = (from data in bandData
                                    orderby this.GetBandDelta(moveUnitsPerWeight, deviation, data) descending
                                    select data).ToList <BandData>();

            foreach (BandData bandData2 in list)
            {
                double num2 = this.GetBandDelta(moveUnitsPerWeight, deviation, bandData2);
                this.logger.Log(MigrationEventType.Verbose, "Attempting to balance band {0} for database {1}, current delta is {2}.", new object[]
                {
                    band,
                    bandData2.Database,
                    num2
                });
                LoadMetric instance = PhysicalSize.Instance;
                if (num2 <= num)
                {
                    this.logger.Log(MigrationEventType.Information, "Not balancing band {0} for database {1} because delta {2} is either less than the minimum of {3} or database has no more available space ({4}). We're done.", new object[]
                    {
                        band,
                        bandData2.Database,
                        num2,
                        num,
                        bandData2.Database.AvailableCapacity.GetSizeMetric(instance)
                    });
                    break;
                }
                foreach (BandData bandData3 in from data in bandData
                         orderby data.TotalWeight
                         select data)
                {
                    if (!bandData3.Database.CanAcceptBalancingLoad)
                    {
                        this.logger.Log(MigrationEventType.Verbose, "Database {0} can not be used as target because it can't take LB load.", new object[]
                        {
                            bandData3.Database
                        });
                    }
                    else
                    {
                        double num3 = this.GetBandDelta(moveUnitsPerWeight, 0.0 - deviation, bandData3);
                        this.logger.Log(MigrationEventType.Verbose, "Trying to place weight into {0} (current delta: {1}).", new object[]
                        {
                            bandData3.Database,
                            num3
                        });
                        ByteQuantifiedSize sizeMetric = bandData3.Database.AvailableCapacity.GetSizeMetric(instance);
                        if (0.0 - num3 > sizeMetric.ToMB())
                        {
                            this.logger.Log(MigrationEventType.Verbose, "Target delta of {0} is larger than the {1} available space in the database, adjusting.", new object[]
                            {
                                num3,
                                sizeMetric
                            });
                            num3 = 0.0 - sizeMetric.ToMB();
                            this.logger.Log(MigrationEventType.Verbose, "New target delta is {0}.", new object[]
                            {
                                num3
                            });
                        }
                        if (num3 >= 0.0)
                        {
                            this.logger.Log(MigrationEventType.Verbose, "Target database is above the threshold, skipping as a target.", new object[0]);
                        }
                        else
                        {
                            ByteQuantifiedSize sizeMetric2 = bandData3.Database.CommittedLoad.GetSizeMetric(instance);
                            ByteQuantifiedSize byteQuantifiedSize2;
                            if (sizeMetric2 > byteQuantifiedSize)
                            {
                                byteQuantifiedSize2 = ByteQuantifiedSize.Zero;
                            }
                            else
                            {
                                byteQuantifiedSize2 = byteQuantifiedSize - sizeMetric2;
                            }
                            int num4 = (int)Math.Floor(byteQuantifiedSize2.ToMB() / band.MailboxSizeWeightFactor);
                            if (num4 <= 0)
                            {
                                this.logger.Log(MigrationEventType.Verbose, "Target database committed load is {0} which is over the limit of {1}, skipping as a target.", new object[]
                                {
                                    sizeMetric2,
                                    byteQuantifiedSize
                                });
                            }
                            else
                            {
                                int num5 = (int)Math.Min(Math.Round(Math.Min(Math.Abs(num2), Math.Abs(num3))), (double)num4);
                                this.logger.Log(MigrationEventType.Verbose, "Projected to move {0} units out of {1} and into {2}", new object[]
                                {
                                    num5,
                                    bandData2.Database,
                                    bandData3.Database
                                });
                                if (num5 > 0)
                                {
                                    ByteQuantifiedSize value             = ByteQuantifiedSize.FromMB((ulong)((double)num5 * band.MailboxSizeWeightFactor));
                                    LoadMetricStorage  loadMetricStorage = new LoadMetricStorage();
                                    loadMetricStorage[band] = (long)num5;
                                    BandMailboxRebalanceData item = new BandMailboxRebalanceData(bandData2.Database, bandData3.Database, loadMetricStorage);
                                    bandData3.TotalWeight += num5;
                                    LoadMetricStorage committedLoad;
                                    LoadMetric        metric;
                                    (committedLoad = bandData3.Database.CommittedLoad)[metric = instance] = committedLoad[metric] + (long)value.ToBytes();
                                    this.totalDataSelectedToMove += value;
                                    bandData2.TotalWeight        -= num5;
                                    this.results.Add(item);
                                    num2 -= (double)num5;
                                }
                                if (num2 <= num)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }