Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Hubs] Handle cases where desired worker count exceeds int.MaxInt #39468

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,20 @@ internal static TargetScalerResult ThrottleScaleDownIfNecessaryInternal(TargetSc
internal TargetScalerResult GetScaleResultInternal(TargetScalerContext context, long eventCount, int partitionCount)
{
int desiredConcurrency = GetDesiredConcurrencyInternal(context);
int desiredWorkerCount = (int)Math.Ceiling(eventCount / (decimal)desiredConcurrency);

int desiredWorkerCount;
try
{
checked
{
desiredWorkerCount = (int)Math.Ceiling(eventCount / (decimal)desiredConcurrency);
}
}
catch (OverflowException)
{
desiredWorkerCount = int.MaxValue;
}

int[] sortedValidWorkerCounts = GetSortedValidWorkerCountsForPartitionCount(partitionCount);
int validatedTargetWorkerCount = GetValidWorkerCount(desiredWorkerCount, sortedValidWorkerCounts);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,17 @@ public void ThrottleScaleDownIfNecessaryInternal_ReturnsExpected(int currentTarg

[Test]
// Using default concurrency of 10.
[TestCase(10, 10, 1)]
[TestCase(20, 10, 2)]
[TestCase(30, 10, 3)]
[TestCase(60, 10, 10)]
[TestCase(70, 10, 10)]
[TestCase(150, 10, 10)]
public void GetScaleResultInternal_ReturnsExpected(long eventCount, int partitionCount, int expectedTargetWorkerCount)
[TestCase(10, 10, null, 1)]
[TestCase(20, 10, null, 2)]
[TestCase(30, 10, null, 3)]
[TestCase(60, 10, null, 10)]
[TestCase(70, 10, null, 10)]
[TestCase(150, 10, null, 10)]
[TestCase(2147483650, 1, 1, 1)] // Testing eventCount > int.MaxInt is 2147483647
[TestCase(21474836500, 1000, 1, 1000)] // Testing eventCount > int.MaxInt is 2147483647, with concurrency 1 to force overflow
public void GetScaleResultInternal_ReturnsExpected(long eventCount, int partitionCount, int? concurrency, int expectedTargetWorkerCount)
{
TargetScalerResult result = _targetScaler.GetScaleResultInternal(new TargetScalerContext { }, eventCount, partitionCount);
TargetScalerResult result = _targetScaler.GetScaleResultInternal(new TargetScalerContext { InstanceConcurrency = concurrency }, eventCount, partitionCount);
Assert.AreEqual(expectedTargetWorkerCount, result.TargetWorkerCount);
}

Expand Down