Repository navigation
fix issue 148 - sub-orchestrations cannot reuse existing instance ids #330
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
base: main
Are you sure you want to change the base?
Changes from all commits
a416b83
24c4404
98262b1
254f143
0eb6b01
705d14f
9e54896
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -253,9 +253,11 @@ BEGIN | |
| BEGIN | ||
| BEGIN TRANSACTION | ||
|
|
||
| -- UPDLOCK waits for a checkpoint that is recreating this ID as a sub-orchestration. | ||
| -- No HOLDLOCK: its key-range locks would block unrelated instances with adjacent IDs. | ||
| DECLARE @existingStatus varchar(30) = ( | ||
| SELECT TOP 1 existing.[RuntimeStatus] | ||
| FROM Instances existing WITH (HOLDLOCK) | ||
| FROM Instances existing WITH (UPDLOCK) | ||
| WHERE [TaskHub] = @TaskHub AND [InstanceID] = @InstanceID | ||
| ) | ||
|
|
||
|
|
@@ -823,6 +825,34 @@ BEGIN | |
| SET @IsContinueAsNew = 1 | ||
| END | ||
|
|
||
| -- Sub-orchestration instance ID reuse case: https://github.com/microsoft/durabletask-mssql/issues/148 | ||
| -- Purge the existing instance data so that the "Create sub-orchestration instances" statement further below can overwrite it. | ||
| -- NOTE: This must happen before any new payloads or events are written below, otherwise the | ||
| -- incoming sub-orchestration state would be purged along with the existing state. | ||
| -- UPDLOCK keeps the rows locked until commit, so a concurrent checkpoint or CreateInstance can't recreate | ||
| -- an instance between this status check and the purge. Status is filtered separately to lock non-terminal rows too. | ||
| DECLARE @StartedSubOrchestrations TABLE ([InstanceID] varchar(100) NOT NULL, [RuntimeStatus] varchar(30) NULL) | ||
| INSERT INTO @StartedSubOrchestrations ([InstanceID], [RuntimeStatus]) | ||
| SELECT I.[InstanceID], I.[RuntimeStatus] | ||
| FROM Instances I WITH (UPDLOCK) | ||
| WHERE I.[TaskHub] = @TaskHub | ||
| AND I.[InstanceID] IN ( | ||
| SELECT E.[InstanceID] | ||
| FROM @NewOrchestrationEvents E | ||
| WHERE E.[EventType] = 'ExecutionStarted' | ||
| AND E.[InstanceID] <> @InstanceID) -- never touch the instance being checkpointed | ||
|
|
||
| DECLARE @SubOrchestrationsToRecreate InstanceIDs | ||
| INSERT INTO @SubOrchestrationsToRecreate ([InstanceID]) | ||
| SELECT [InstanceID] | ||
| FROM @StartedSubOrchestrations | ||
| WHERE [RuntimeStatus] IN ('Completed', 'Failed', 'Terminated') | ||
|
|
||
| IF EXISTS (SELECT 1 FROM @SubOrchestrationsToRecreate) | ||
| BEGIN | ||
| EXEC __SchemaNamePlaceholder__.PurgeInstanceStateByID @SubOrchestrationsToRecreate | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P1] Reject stale child checkpoints after reusing an instance ID Purging the completed child's history removes the duplicate-checkpoint protection for its previous execution. If a delayed checkpoint from that execution arrives after the child has been recreated, Please prevent checkpoints for a previous execution from modifying the replacement while preserving legitimate ContinueAsNew behavior, and add a regression that checkpoints the old child after its ID is reused. |
||
| END | ||
|
|
||
| -- Custom status case #1: Setting the custom status for the first time | ||
| IF @ExistingCustomStatusPayload IS NULL AND @CustomStatusPayload IS NOT NULL | ||
| BEGIN | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.