Skip to content

Commit 2c03f34

Browse files
author
Sophia Tevosyan
committed
addressing PR comments
1 parent fb1d3e7 commit 2c03f34

5 files changed

Lines changed: 36 additions & 20 deletions

File tree

src/DurableTask.AzureStorage/AzureStorageOrchestrationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ async Task<string> IsExecutableInstanceAsync(
10991099
if (instanceStatus.State.OrchestrationInstance.ExecutionId == runtimeState.OrchestrationInstance.ExecutionId
11001100
&& instanceStatus.State.OrchestrationStatus != runtimeState.OrchestrationStatus)
11011101
{
1102-
await this.trackingStore.UpdateInstanceStatusAndDeleteOrphanedBlobsAsync(
1102+
await this.trackingStore.UpdateInstanceStatusAndDeleteOrphanedBlobsForCompletedOrchestrationAsync(
11031103
runtimeState.OrchestrationInstance.InstanceId,
11041104
runtimeState.OrchestrationInstance.ExecutionId,
11051105
runtimeState,

src/DurableTask.AzureStorage/Tracking/AzureTableTrackingStore.cs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,13 +1043,32 @@ public override Task StartAsync(CancellationToken cancellationToken = default)
10431043
return eTagValue;
10441044
}
10451045

1046-
public override async Task UpdateInstanceStatusAndDeleteOrphanedBlobsAsync(
1046+
public override async Task UpdateInstanceStatusAndDeleteOrphanedBlobsForCompletedOrchestrationAsync(
10471047
string instanceId,
10481048
string executionId,
10491049
OrchestrationRuntimeState runtimeState,
10501050
object trackingStoreContext,
10511051
CancellationToken cancellationToken = default)
10521052
{
1053+
if (runtimeState.OrchestrationStatus != OrchestrationStatus.Completed &&
1054+
runtimeState.OrchestrationStatus != OrchestrationStatus.Canceled &&
1055+
runtimeState.OrchestrationStatus != OrchestrationStatus.Failed &&
1056+
runtimeState.OrchestrationStatus != OrchestrationStatus.Terminated)
1057+
{
1058+
return;
1059+
}
1060+
1061+
TrackingStoreContext context = (TrackingStoreContext)trackingStoreContext;
1062+
if (context.Blobs.Count > 0)
1063+
{
1064+
var tasks = new List<Task>(context.Blobs.Count);
1065+
foreach (string blobName in context.Blobs)
1066+
{
1067+
tasks.Add(this.messageManager.DeleteBlobAsync(blobName));
1068+
}
1069+
await Task.WhenAll(tasks);
1070+
}
1071+
10531072
string sanitizedInstanceId = KeySanitation.EscapePartitionKey(instanceId);
10541073
var instanceEntity = new TableEntity(sanitizedInstanceId, string.Empty)
10551074
{
@@ -1059,7 +1078,7 @@ public override async Task UpdateInstanceStatusAndDeleteOrphanedBlobsAsync(
10591078
["ExecutionId"] = executionId,
10601079
["LastUpdatedTime"] = runtimeState.Events.Last().Timestamp,
10611080
["RuntimeStatus"] = runtimeState.OrchestrationStatus.ToString(),
1062-
["CompletedTime"] = runtimeState.Events.Last().Timestamp // do we want to do this as a rough proxy or DateTime.UtcNow?
1081+
["CompletedTime"] = runtimeState.CompletedTime
10631082
};
10641083

10651084
Stopwatch orchestrationInstanceUpdateStopwatch = Stopwatch.StartNew();
@@ -1073,17 +1092,6 @@ public override async Task UpdateInstanceStatusAndDeleteOrphanedBlobsAsync(
10731092
runtimeState.OrchestrationStatus,
10741093
Utils.GetEpisodeNumber(runtimeState),
10751094
orchestrationInstanceUpdateStopwatch.ElapsedMilliseconds);
1076-
1077-
TrackingStoreContext context = (TrackingStoreContext)trackingStoreContext;
1078-
if (context.Blobs.Count > 0)
1079-
{
1080-
var tasks = new List<Task>(context.Blobs.Count);
1081-
foreach (var blobName in context.Blobs)
1082-
{
1083-
tasks.Add(this.messageManager.DeleteBlobAsync(blobName));
1084-
}
1085-
await Task.WhenAll(tasks);
1086-
}
10871095
}
10881096

10891097
static int GetEstimatedByteCount(TableEntity entity)

src/DurableTask.AzureStorage/Tracking/ITrackingStore.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ interface ITrackingStore
104104
Task<InstanceStatus> FetchInstanceStatusAsync(string instanceId, CancellationToken cancellationToken = default);
105105

106106
/// <summary>
107-
/// Updates the instance status of the specified orchestration instance to match that of <paramref name="runtimeState"/>.
107+
/// Updates the instance status of the specified orchestration instance to match that of <paramref name="runtimeState"/> for a completed orchestration.
108108
/// Also deletes any orphaned blobs of <paramref name="trackingStoreContext"/>.
109-
/// This method is meant to be called in the case that there is an inconsistency between the instance and history table due to a
110-
/// failure during a call to <see cref="UpdateStateAsync"/>.
109+
/// This method is meant to be called in the case that there is an inconsistency between the instance and history table due to a failure during a call to
110+
/// <see cref="UpdateStateAsync"/> for a completing orchestration. If the orchestration is not in a terminal state, the method will immediately return and do nothing.
111111
/// </summary>
112112
/// <param name="instanceId">The ID of the orchestration.</param>
113113
/// <param name="executionId">The execution ID of the orchestration.</param>
114114
/// <param name="runtimeState">The runtime state of the orchestration.</param>
115115
/// <param name="trackingStoreContext">Additional context for the execution that is maintained by the tracking store.</param>
116116
/// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/>.</param>
117-
Task UpdateInstanceStatusAndDeleteOrphanedBlobsAsync(string instanceId, string executionId, OrchestrationRuntimeState runtimeState, object trackingStoreContext, CancellationToken cancellationToken = default);
117+
Task UpdateInstanceStatusAndDeleteOrphanedBlobsForCompletedOrchestrationAsync(string instanceId, string executionId, OrchestrationRuntimeState runtimeState, object trackingStoreContext, CancellationToken cancellationToken = default);
118118

119119
/// <summary>
120120
/// Get The Orchestration State for querying all orchestration instances

src/DurableTask.AzureStorage/Tracking/InstanceStoreBackedTrackingStore.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,21 @@ public override async Task UpdateStatusForTerminationAsync(string instanceId, st
187187
await this.instanceStore.WriteEntitiesAsync(instanceEntity);
188188
}
189189

190-
public override async Task UpdateInstanceStatusAndDeleteOrphanedBlobsAsync(
190+
public override async Task UpdateInstanceStatusAndDeleteOrphanedBlobsForCompletedOrchestrationAsync(
191191
string instanceId,
192192
string executionId,
193193
OrchestrationRuntimeState runtimeState,
194194
object trackingStoreContext,
195195
CancellationToken cancellationToken = default)
196196
{
197+
if (runtimeState.OrchestrationStatus != OrchestrationStatus.Completed &&
198+
runtimeState.OrchestrationStatus != OrchestrationStatus.Canceled &&
199+
runtimeState.OrchestrationStatus != OrchestrationStatus.Failed &&
200+
runtimeState.OrchestrationStatus != OrchestrationStatus.Terminated)
201+
{
202+
return;
203+
}
204+
197205
// No blobs to delete for this tracking store implementation
198206
await instanceStore.WriteEntitiesAsync(new InstanceEntityBase[]
199207
{

src/DurableTask.AzureStorage/Tracking/TrackingStoreBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,6 @@ public virtual Task UpdateStatusForRewindAsync(string instanceId, CancellationTo
110110
public abstract Task<ETag?> UpdateStateAsync(OrchestrationRuntimeState newRuntimeState, OrchestrationRuntimeState oldRuntimeState, string instanceId, string executionId, ETag? eTag, object executionData, CancellationToken cancellationToken = default);
111111

112112
/// <inheritdoc />
113-
public abstract Task UpdateInstanceStatusAndDeleteOrphanedBlobsAsync(string instanceId, string executionId, OrchestrationRuntimeState runtimeState, object trackingStoreContext, CancellationToken cancellationToken = default);
113+
public abstract Task UpdateInstanceStatusAndDeleteOrphanedBlobsForCompletedOrchestrationAsync(string instanceId, string executionId, OrchestrationRuntimeState runtimeState, object trackingStoreContext, CancellationToken cancellationToken = default);
114114
}
115115
}

0 commit comments

Comments
 (0)