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

Added missing Rollback transaction #219

Merged
merged 2 commits into from
May 7, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

* Replace hardcoded version string + globs with build variables ([#213](https://github.com/microsoft/durabletask-mssql/pull/213))
* Fix deadlock issue on orchestration creation ([#218](https://github.com/microsoft/durabletask-mssql/pull/218)) - contributed by [@microrama](https://github.com/microrama)
* Add missing transaction rollbacks in sprocs ([#219](https://github.com/microsoft/durabletask-mssql/pull/219)) - contributed by [@bhugot](https://github.com/bhugot)

## v1.2.3

Expand Down
22 changes: 17 additions & 5 deletions src/DurableTask.SqlServer/Scripts/logic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ BEGIN

-- The instance ID is not auto-start and doesn't already exist, so we fail.
IF @@ROWCOUNT = 0
THROW 50000, 'The instance does not exist.', 1;
BEGIN
ROLLBACK TRANSACTION;
THROW 50000, 'The instance does not exist.', 1;
END
END

-- Payloads are stored separately from the events
Expand Down Expand Up @@ -473,8 +476,10 @@ BEGIN
)

IF @existingStatus IS NULL
BEGIN
ROLLBACK TRANSACTION;
THROW 50000, 'The instance does not exist.', 1;

END
-- If the instance is already completed, no need to terminate it.
IF @existingStatus IN ('Pending', 'Running')
BEGIN
Expand Down Expand Up @@ -835,8 +840,10 @@ BEGIN
WHERE [TaskHub] = @TaskHub and [InstanceID] = @InstanceID

IF @@ROWCOUNT = 0
BEGIN
ROLLBACK TRANSACTION;
THROW 50000, 'The instance does not exist.', 1;

END
-- External event messages can create new instances
-- NOTE: There is a chance this could result in deadlocks if two
-- instances are sending events to each other at the same time
Expand Down Expand Up @@ -1079,7 +1086,10 @@ BEGIN
-- Ignore PK violations here, which can happen when multiple clients
-- try to add messages at the same time for the same instance
IF ERROR_NUMBER() <> 2627 -- 2627 is PK violation
THROW
BEGIN
ROLLBACK TRANSACTION;
THROW;
END
END CATCH

-- Insert new event data payloads into the Payloads table in batches.
Expand Down Expand Up @@ -1368,8 +1378,10 @@ BEGIN
-- This can happen if the message was completed by another worker, in which
-- case we don't want any of the side-effects to persist.
IF @@ROWCOUNT <> (SELECT COUNT(*) FROM @CompletedTasks)
BEGIN
ROLLBACK TRANSACTION;
THROW 50002, N'Failed to delete the completed task events(s). They may have been deleted by another worker, in which case the current execution is likely a duplicate. Any results or pending side-effects of this task activity execution will be discarded.', 1;

END
COMMIT TRANSACTION
END
GO
Expand Down
Loading