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,7 @@ 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);
long desiredWorkerCount = (long)Math.Ceiling(eventCount / (decimal)desiredConcurrency);
chiangvincent marked this conversation as resolved.
Show resolved Hide resolved
int[] sortedValidWorkerCounts = GetSortedValidWorkerCountsForPartitionCount(partitionCount);
int validatedTargetWorkerCount = GetValidWorkerCount(desiredWorkerCount, sortedValidWorkerCounts);

Expand Down Expand Up @@ -163,9 +163,15 @@ internal static int[] GetSortedValidWorkerCountsForPartitionCount(int partitionC
/// <param name="workerCount">The value that we want to find in the sortedValues list (if it exists), or the next largest element.</param>
/// <param name="sortedValidWorkerCountList">The list of valid worker counts. This must be sorted.</param>
/// <returns></returns>
internal static int GetValidWorkerCount(int workerCount, int[] sortedValidWorkerCountList)
internal static int GetValidWorkerCount(long workerCount, int[] sortedValidWorkerCountList)
{
int i = Array.BinarySearch(sortedValidWorkerCountList, workerCount);
// Handling cases where workerCount exceeds int.MaxInt
if (workerCount > int.MaxValue)
{
return sortedValidWorkerCountList.Last();
}

int i = Array.BinarySearch(sortedValidWorkerCountList, (int)workerCount);
if (i >= 0)
{
return sortedValidWorkerCountList[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public void TestGetSortedValidWorkerCountsForPartitionCount(int partitionCount,
[TestCase(21, new[] { 1, 4, 10, 20 }, 20)]
[TestCase(0, new[] { 1, 4, 10, 20 }, 1)]
[TestCase(10, new[] { 1, 4, 10, 20 }, 10)]
public void GetSortedValidWorkerCountsForPartitionCount_ReturnsExpected(int workerCount, int[] sortedWorkerCountList, int expectedValidWorkerCount)
[TestCase(2147483650, new[] { 1, 4, 10, 20 }, 20)] // workerCount exceeds MaxInt
[TestCase(2147483650, new[] { 1 }, 1)]
public void GetSortedValidWorkerCountsForPartitionCount_ReturnsExpected(long workerCount, int[] sortedWorkerCountList, int expectedValidWorkerCount)
{
int actualValidWorkerCount = EventHubsTargetScaler.GetValidWorkerCount(workerCount, sortedWorkerCountList);
Assert.AreEqual(expectedValidWorkerCount, actualValidWorkerCount);
Expand Down
Loading