Skip to content

Commit

Permalink
Fix integer overflow issues in GetScaleMetric and QueryManyOrchestrat…
Browse files Browse the repository at this point in the history
…ions (#155)
  • Loading branch information
bhugot committed Mar 28, 2023
1 parent a806eea commit 15228ea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ _TeamCity*
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
*.ncrunch*

# MightyMoose
*.mm.*
Expand Down Expand Up @@ -437,3 +438,4 @@ $RECYCLE.BIN/

# The build keeps auto-generating this file. We do not want this.
/.nuget/NuGet.Config

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v1.1.2

### Updates

* Fix integer overflow issues in GetScaleMetric and QueryManyOrchestrations ([#155](https://github.com/microsoft/durabletask-mssql/pull/155)) - contributed by [@bhugot](https://github.com/bhugot)

## v1.1.1

### Updates
Expand Down
18 changes: 9 additions & 9 deletions src/DurableTask.SqlServer/Scripts/logic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ BEGIN
DECLARE @taskHub varchar(50) = __SchemaNamePlaceholder__.CurrentTaskHub()
DECLARE @now datetime2 = SYSUTCDATETIME()

DECLARE @liveInstances int = 0
DECLARE @liveTasks int = 0
DECLARE @liveInstances bigint = 0
DECLARE @liveTasks bigint = 0

SELECT
@liveInstances = COUNT(DISTINCT E.[InstanceID]),
@liveTasks = COUNT(T.[InstanceID])
@liveInstances = COUNT_BIG(DISTINCT E.[InstanceID]),
@liveTasks = COUNT_BIG(T.[InstanceID])
FROM Instances I WITH (NOLOCK)
LEFT OUTER JOIN NewEvents E WITH (NOLOCK) ON E.[TaskHub] = @taskHub AND E.[InstanceID] = I.[InstanceID]
LEFT OUTER JOIN NewTasks T WITH (NOLOCK) ON T.[TaskHub] = @taskHub AND T.[InstanceID] = I.[InstanceID]
Expand All @@ -65,12 +65,12 @@ BEGIN
DECLARE @taskHub varchar(50) = __SchemaNamePlaceholder__.CurrentTaskHub()
DECLARE @now datetime2 = SYSUTCDATETIME()

DECLARE @liveInstances int = 0
DECLARE @liveTasks int = 0
DECLARE @liveInstances bigint = 0
DECLARE @liveTasks bigint = 0

SELECT
@liveInstances = COUNT(DISTINCT E.[InstanceID]),
@liveTasks = COUNT(T.[InstanceID])
@liveInstances = COUNT_BIG(DISTINCT E.[InstanceID]),
@liveTasks = COUNT_BIG(T.[InstanceID])
FROM Instances I WITH (NOLOCK)
LEFT OUTER JOIN NewEvents E WITH (NOLOCK) ON E.[TaskHub] = @taskHub AND E.[InstanceID] = I.[InstanceID]
LEFT OUTER JOIN NewTasks T WITH (NOLOCK) ON T.[TaskHub] = @taskHub AND T.[InstanceID] = I.[InstanceID]
Expand Down Expand Up @@ -1057,7 +1057,7 @@ GO

CREATE OR ALTER PROCEDURE __SchemaNamePlaceholder__._QueryManyOrchestrations
@PageSize smallint = 100,
@PageNumber smallint = 0,
@PageNumber int = 0,
@FetchInput bit = 1,
@FetchOutput bit = 1,
@CreatedTimeFrom datetime2 = NULL,
Expand Down
4 changes: 2 additions & 2 deletions src/DurableTask.SqlServer/SqlOrchestrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -811,13 +811,13 @@ public async Task<IReadOnlyCollection<OrchestrationState>> GetManyOrchestrations
using SqlCommand command = this.GetSprocCommand(connection, $"{this.settings.SchemaName}._QueryManyOrchestrations");

command.Parameters.Add("@PageSize", SqlDbType.SmallInt).Value = query.PageSize;
command.Parameters.Add("@PageNumber", SqlDbType.SmallInt).Value = query.PageNumber;
command.Parameters.Add("@PageNumber", SqlDbType.Int).Value = query.PageNumber;
command.Parameters.Add("@FetchInput", SqlDbType.Bit).Value = query.FetchInput;
command.Parameters.Add("@FetchOutput", SqlDbType.Bit).Value = query.FetchOutput;
command.Parameters.Add("@CreatedTimeFrom", SqlDbType.DateTime2).Value = createdTimeFrom;
command.Parameters.Add("@CreatedTimeTo", SqlDbType.DateTime2).Value = createdTimeTo;
command.Parameters.Add("@InstanceIDPrefix", SqlDbType.VarChar, size: 100).Value = query.InstanceIdPrefix ?? SqlString.Null;
command.Parameters.Add("@ExcludeSubOrchestrations", SqlDbType.SmallInt).Value = query.ExcludeSubOrchestrations;
command.Parameters.Add("@ExcludeSubOrchestrations", SqlDbType.Bit).Value = query.ExcludeSubOrchestrations;

if (query.StatusFilter?.Count > 0)
{
Expand Down
2 changes: 1 addition & 1 deletion test/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ docker pull mcr.microsoft.com/mssql/server:$tag

# Start the SQL Server docker container with the specified edition
Write-Host "Starting SQL Server $tag $sqlpid docker container on port $port" -ForegroundColor DarkYellow
docker run $additinalRunFlags --name mssql-server -e 'ACCEPT_EULA=Y' -e "SA_PASSWORD=$pw" -e "MSSQL_PID=$sqlpid" -p ${port}:1433 -d mcr.microsoft.com/mssql/server:$tag
docker run $additinalRunFlags --name mssql-server -e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$pw" -e "MSSQL_PID=$sqlpid" -p ${port}:1433 -d mcr.microsoft.com/mssql/server:$tag

# The container needs a bit more time before it can start accepting commands
Write-Host "Sleeping for 30 seconds to let the container finish initializing..." -ForegroundColor Yellow
Expand Down

0 comments on commit 15228ea

Please sign in to comment.