-
Notifications
You must be signed in to change notification settings - Fork 327
reset pending orchestrations when worker restart #1355
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 1 commit
7080fe8
2d9f611
80e0d68
c7a6691
211d909
74f891b
65e91b2
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 |
|---|---|---|
|
|
@@ -216,11 +216,60 @@ public async Task DrainAsync(string partitionId, CloseReason reason, Cancellatio | |
| } | ||
| finally | ||
| { | ||
| // Remove the partition from memory | ||
| // Make dequeued-but-undispatched messages visible before dropping the partition. | ||
| await this.AbandonPendingMessagesAsync(partitionId); | ||
|
Member
Author
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. Fixed in 2d9f611. Drain now waits for the dequeue loop to stop before scanning pending batches, and |
||
|
|
||
| this.RemoveQueue(partitionId, reason, caller); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Abandons all pending (dequeued but not yet dispatched) messages for the specified partition, | ||
| /// making them immediately visible in the Azure Storage queue for the new partition owner. | ||
| /// This prevents a throughput gap equal to the visibility timeout duration when a partition | ||
| /// is released during drain. | ||
| /// </summary> | ||
| async Task AbandonPendingMessagesAsync(string partitionId) | ||
| { | ||
| var messagesToAbandon = new List<(ControlQueue Queue, MessageData Message)>(); | ||
|
|
||
| lock (this.messageAndSessionLock) | ||
| { | ||
| var node = this.pendingOrchestrationMessageBatches.First; | ||
| while (node != null) | ||
| { | ||
| LinkedListNode<PendingMessageBatch>? next = node.Next; | ||
| PendingMessageBatch batch = node.Value; | ||
|
|
||
| if (string.Equals(batch.ControlQueue.Name, partitionId, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| foreach (MessageData message in batch.Messages) | ||
| { | ||
| messagesToAbandon.Add((batch.ControlQueue, message)); | ||
| } | ||
|
|
||
|
Member
Author
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. Fixed in 2d9f611. Prefetch now checks whether the pending-batch node is still active before fetching history, before enqueueing, and before scheduling retries, so detached or released batches exit instead of retrying. |
||
| this.pendingOrchestrationMessageBatches.Remove(node); | ||
| } | ||
|
|
||
| node = next; | ||
| } | ||
| } | ||
|
|
||
| if (messagesToAbandon.Count > 0) | ||
| { | ||
| this.settings.Logger.PartitionManagerInfo( | ||
| this.storageAccountName, | ||
| this.settings.TaskHubName, | ||
| this.settings.WorkerId, | ||
| partitionId, | ||
| $"Abandoning {messagesToAbandon.Count} pending message(s) during drain to make them immediately visible for the new partition owner."); | ||
|
|
||
| await messagesToAbandon.ParallelForEachAsync( | ||
| this.settings.MaxStorageOperationConcurrency, | ||
| item => item.Queue.AbandonMessageForDrainAsync(item.Message)); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// This method enumerates all the provided queue messages looking for ExecutionStarted messages. If any are found, it | ||
| /// queries table storage to ensure that each message has a matching record in the Instances table. If not, this method | ||
|
|
@@ -592,6 +641,12 @@ async Task ScheduleOrchestrationStatePrefetch( | |
|
|
||
| lock (this.messageAndSessionLock) | ||
| { | ||
| // Drain may have removed this batch after it was queued for dispatch. | ||
| if (node.List != this.pendingOrchestrationMessageBatches) | ||
| { | ||
| continue; | ||
| } | ||
|
Member
Author
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. Resolved in c7a6691. |
||
|
|
||
| PendingMessageBatch nextBatch = node.Value; | ||
| this.pendingOrchestrationMessageBatches.Remove(node); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.