Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/DurableTask.AzureStorage/MessageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,12 @@ public async Task<int> DeleteLargeMessageBlobs(string sanitizedInstanceId, Cance
{
int storageOperationCount = 0;

// The trailing '/' keeps the prefix from also matching instances whose id starts with this one.
string blobPrefix = sanitizedInstanceId + "/";
Comment thread
bcederholm marked this conversation as resolved.
Resolved
Comment thread
bcederholm marked this conversation as resolved.
Resolved

try
{
await foreach (Page<Blob> page in this.blobContainer.ListBlobsAsync(sanitizedInstanceId, cancellationToken).AsPages())
await foreach (Page<Blob> page in this.blobContainer.ListBlobsAsync(blobPrefix, cancellationToken).AsPages())
{
storageOperationCount++;

Expand Down
37 changes: 37 additions & 0 deletions test/DurableTask.AzureStorage.Tests/AzureStorageScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,43 @@ public async Task PurgeSingleInstance_WithLargeBlobs_CleansUpBlobs()
}
}

[TestMethod]
public async Task PurgeSingleInstance_DoesNotDeleteBlobsOfInstanceWithPrefixedId()
{
using (TestOrchestrationHost host = TestHelpers.GetTestOrchestrationHost(enableExtendedSessions: false))
{
await host.StartAsync();

string instanceId = Guid.NewGuid().ToString("N");
string otherInstanceId = instanceId + "_other";
string largeMessage = new string('x', 70 * 1024);

TestOrchestrationClient client = await host.StartOrchestrationAsync(
typeof(Orchestrations.Echo), largeMessage, instanceId);
OrchestrationState status = await client.WaitForCompletionAsync(TimeSpan.FromMinutes(2));
Assert.AreEqual(OrchestrationStatus.Completed, status?.OrchestrationStatus);

TestOrchestrationClient otherClient = await host.StartOrchestrationAsync(
typeof(Orchestrations.Echo), largeMessage, otherInstanceId);
status = await otherClient.WaitForCompletionAsync(TimeSpan.FromMinutes(2));
Assert.AreEqual(OrchestrationStatus.Completed, status?.OrchestrationStatus);

int otherBlobCount = await this.GetBlobCount("test-largemessages", otherInstanceId + "/");
Assert.IsTrue(otherBlobCount > 0, "Should have large message blobs before purge");

await client.PurgeInstanceHistory();

Assert.AreEqual(0, await this.GetBlobCount("test-largemessages", instanceId + "/"));
Assert.AreEqual(otherBlobCount, await this.GetBlobCount("test-largemessages", otherInstanceId + "/"));

// Loading the history downloads the large-property blobs, as a replay does.
List<HistoryStateEvent> otherHistoryEvents = await otherClient.GetOrchestrationHistoryAsync(otherInstanceId);
Assert.IsTrue(otherHistoryEvents.Count > 0);

await host.StopAsync();
}
}

[TestMethod]
public async Task PurgeInstance_WithManyHistoryRows_DeletesAll()
{
Expand Down