protected override string FormatObject(string format, object arg, IFormatProvider formatProvider) { ByteQuantifiedSize byteQuantifiedSize = (ByteQuantifiedSize)arg; if (byteQuantifiedSize.ToGB() > 0UL) { return(Strings.ByteQuantifiedSizeAsGB(byteQuantifiedSize.ToGB())); } if (byteQuantifiedSize.ToMB() > 0UL) { return(Strings.ByteQuantifiedSizeAsMB(byteQuantifiedSize.ToMB())); } return(Strings.ByteQuantifiedSizeAsKB(byteQuantifiedSize.ToKB())); }
public static string ToAppropriateUnitFormatString(this ByteQuantifiedSize size, string valueFormat) { if (size.ToTB() > 0UL) { return(string.Format(OwaOptionStrings.MailboxUsageUnitTB, string.Format(CultureInfo.InvariantCulture, valueFormat, new object[] { size.ToBytes() / 1099511627776.0 }))); } if (size.ToGB() > 0UL) { return(string.Format(OwaOptionStrings.MailboxUsageUnitGB, string.Format(CultureInfo.InvariantCulture, valueFormat, new object[] { size.ToBytes() / 1073741824.0 }))); } if (size.ToMB() > 0UL) { return(string.Format(OwaOptionStrings.MailboxUsageUnitMB, string.Format(CultureInfo.InvariantCulture, valueFormat, new object[] { size.ToBytes() / 1048576.0 }))); } if (size.ToKB() > 0UL) { return(string.Format(OwaOptionStrings.MailboxUsageUnitKB, string.Format(CultureInfo.InvariantCulture, valueFormat, new object[] { size.ToBytes() / 1024.0 }))); } return(string.Format(CultureInfo.InvariantCulture, OwaOptionStrings.MailboxUsageUnitB, new object[] { size.ToBytes() })); }
protected virtual IBatchSizeReducer GetFactorBasedBatchSizeReducer(ByteQuantifiedSize maximumSize, ByteQuantifiedSize totalSize, ILogger logger) { double weightReductionFactor = maximumSize.ToMB() / totalSize.ToMB(); return(this.CreateFactorBasedReducer(logger, weightReductionFactor)); }
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; } } } } } } }
public Band(Band.BandProfile bandProfile, ByteQuantifiedSize minSize, ByteQuantifiedSize maxSize, double mailboxSizeWeightFactor, bool includeOnlyPhysicalMailboxes = false, TimeSpan?minLastLogonAge = null, TimeSpan?maxLastLogonAge = null) : this(bandProfile, minSize.ToMB(), maxSize.ToMB(), mailboxSizeWeightFactor, includeOnlyPhysicalMailboxes, minLastLogonAge, maxLastLogonAge) { }