Skip to content
Merged
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
22 changes: 15 additions & 7 deletions src/DurableTask.AzureStorage/Partitioning/TablePartitionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,13 @@ public async Task<ReadTableReponse> ReadAndWriteTableAsync(bool isShuttingDown,

// Ensure worker is listening to the control queue iff either:
// 1) worker just claimed the lease,
// 2) worker was already the owner in the partitions table and is not actively draining the queue. Note that during draining, we renew the lease but do not want to listen to new messages. Otherwise, we'll never finish draining our in-memory messages.
bool isRenewingToDrainQueue = renewedLease & response.IsDrainingPartition;
// 2) worker was already the owner in the partitions table and is not actively draining the queue.
// Note that during draining, we renew the lease but do not want to listen to new messages.
// Otherwise, we'll never finish draining our in-memory messages.
// When draining completes, and the worker may decide to release the lease. In that moment,
// IsDrainingPartition can still be true but renewedLease can be false — without checking
// !releasedLease, the worker could incorrectly resume listening just before releasing the lease.
bool isRenewingToDrainQueue = renewedLease && response.IsDrainingPartition && !releasedLease;
if (claimedLease || !isRenewingToDrainQueue)
{
// Notify the orchestration session manager that we acquired a lease for one of the partitions.
Expand Down Expand Up @@ -505,7 +510,8 @@ void RenewOrReleaseMyLease(
partition,
ref releasedLease,
ref renewedLease,
ref drainedLease);
ref drainedLease,
CloseReason.LeaseLost);
}
}

Expand Down Expand Up @@ -583,7 +589,8 @@ void TryDrainAndReleaseAllPartitions(
partition,
ref releasedLease,
ref renewedLease,
ref drainedLease);
ref drainedLease,
CloseReason.Shutdown);

if (releasedLease)
{
Expand Down Expand Up @@ -661,7 +668,7 @@ await this.partitionTable.ReplaceEntityAsync(
partition,
etag,
forceShutdownToken);

this.settings.Logger.LeaseStealingSucceeded(
this.storageAccountName,
this.settings.TaskHubName,
Expand Down Expand Up @@ -815,7 +822,8 @@ void CheckDrainTask(
TablePartitionLease partition,
ref bool releasedLease,
ref bool renewedLease,
ref bool drainedLease)
ref bool drainedLease,
CloseReason reason)
{
// Check if drain process has started.
if (this.backgroundDrainTasks.TryGetValue(partition.RowKey!, out Task? drainTask))
Expand Down Expand Up @@ -844,7 +852,7 @@ void CheckDrainTask(
}
else// If drain task hasn't been started yet, start it and keep renewing the lease to prevent it from expiring.
{
this.DrainPartition(partition, CloseReason.Shutdown);
this.DrainPartition(partition, reason);
this.RenewLease(partition);
renewedLease = true;
drainedLease = true;
Expand Down
Loading