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

[Cosmos DB] Handle cases where desired worker count exceeds int.MaxInt #873

Merged
merged 7 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/WebJobs.Extensions.CosmosDB/Trigger/CosmosDBTargetScaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,19 @@ internal TargetScalerResult GetScaleResultInternal(TargetScalerContext context,
concurrency = DefaultMaxItemsPerInvocation;
}

int targetWorkerCount = (int)Math.Ceiling(remainingWork / (decimal)concurrency);
int targetWorkerCount;

try
{
checked
{
targetWorkerCount = (int)Math.Ceiling(remainingWork / (decimal)concurrency);
}
}
catch (OverflowException)
{
targetWorkerCount = int.MaxValue;
}

string targetScaleMessage = $"Target worker count for function '{_functionId}' is '{targetWorkerCount}' (MonitoredContainerId='{_monitoredContainer.Id}', MonitoredContainerDatabaseId='{_monitoredContainer.Database.Id}', RemainingWork ='{remainingWork}', Concurrency='{concurrency}').";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public CosmosDBTargetScalerTests()
[InlineData(null, 0, 3, 0)]
[InlineData(50, 200, 0, 4)]
[InlineData(-50, 200, 0, 2)]
[InlineData(1, 2147483650, 1, 1)]
[InlineData(1, 2147483650, 2147483647, 2147483647)]
[InlineData(2, 2147483650, 1073741825, 1073741825)]
public void GetScaleResultInternal(int? concurrency, long remainingWork, int partitionCount, int expectedTargetWorkerCount)
{
TargetScalerContext targetScalerContext = new TargetScalerContext
Expand Down