-
Notifications
You must be signed in to change notification settings - Fork 58
Add large-payload blob auto-purge (opt-in singleton job, worker/SDK side) #758
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
Draft
YunchuWang
wants to merge
1
commit into
main
Choose a base branch
from
yunchuwang-wangbill-blob-payload-autopurge-sdk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.DurableTask.Client; | ||
|
|
||
| /// <summary> | ||
| /// Serializable acknowledgement that the worker has deleted the blob for a tombstoned payload, so the | ||
| /// backend can hard-delete the soft-deleted row. Mirrors the <c>PayloadPurgeAck</c> protobuf message. | ||
| /// </summary> | ||
| /// <param name="PartitionId">The backend partition that owns the payload row.</param> | ||
| /// <param name="InstanceKey">The orchestration instance key the payload belongs to.</param> | ||
| /// <param name="PayloadId">The backend identifier of the soft-deleted payload row.</param> | ||
| public sealed record PayloadPurgeAckDto(int PartitionId, long InstanceKey, long PayloadId); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.DurableTask.Client; | ||
|
|
||
| /// <summary> | ||
| /// Serializable representation of a tombstoned payload the backend has soft-deleted and whose blob the | ||
| /// worker should delete. Mirrors the <c>TombstonedPayload</c> protobuf message but is safe to pass through | ||
| /// the orchestration/activity boundary. | ||
| /// </summary> | ||
| /// <param name="PartitionId">The backend partition that owns the payload row.</param> | ||
| /// <param name="InstanceKey">The orchestration instance key the payload belongs to.</param> | ||
| /// <param name="PayloadId">The backend identifier of the soft-deleted payload row.</param> | ||
| /// <param name="Token">The externalized payload token whose backing blob should be deleted.</param> | ||
| public sealed record TombstonedPayloadDto(int PartitionId, long InstanceKey, long PayloadId, string Token); | ||
|
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. remove suffix dto? |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,7 +114,7 @@ | |
|
|
||
| DateTimeOffset? startAt = options?.StartAt; | ||
| this.logger.SchedulingOrchestration( | ||
| request.InstanceId ?? string.Empty, | ||
| orchestratorName, | ||
| sizeInBytes: request.Input != null ? Encoding.UTF8.GetByteCount(request.Input) : 0, | ||
| startAt.GetValueOrDefault(DateTimeOffset.UtcNow)); | ||
|
|
@@ -624,6 +624,49 @@ | |
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override async Task<List<TombstonedPayloadDto>> GetTombstonedPayloadsAsync( | ||
| int limit, CancellationToken cancellation = default) | ||
| { | ||
| P.GetTombstonedPayloadsResponse response = await this.sidecarClient.GetTombstonedPayloadsAsync( | ||
|
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. lets add limit range check, not here whenever limit is specified, > 0 and < 1000 |
||
| new P.GetTombstonedPayloadsRequest { Limit = limit }, | ||
| cancellationToken: cancellation); | ||
|
|
||
| List<TombstonedPayloadDto> result = new(response.Payloads.Count); | ||
| foreach (P.TombstonedPayload payload in response.Payloads) | ||
| { | ||
| result.Add(new TombstonedPayloadDto( | ||
| payload.PartitionId, payload.InstanceKey, payload.PayloadId, payload.Token)); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override async Task AckPurgedPayloadsAsync( | ||
| IEnumerable<PayloadPurgeAckDto> acks, CancellationToken cancellation = default) | ||
| { | ||
| Check.NotNull(acks); | ||
|
|
||
| P.AckPurgedPayloadsRequest request = new(); | ||
| foreach (PayloadPurgeAckDto ack in acks) | ||
| { | ||
| request.Acks.Add(new P.PayloadPurgeAck | ||
| { | ||
| PartitionId = ack.PartitionId, | ||
| InstanceKey = ack.InstanceKey, | ||
| PayloadId = ack.PayloadId, | ||
| }); | ||
| } | ||
|
|
||
| if (request.Acks.Count == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| await this.sidecarClient.AckPurgedPayloadsAsync(request, cancellationToken: cancellation); | ||
| } | ||
|
|
||
| static AsyncDisposable GetCallInvoker(GrpcDurableTaskClientOptions options, ILogger logger, out CallInvoker callInvoker) | ||
| { | ||
| Func<GrpcChannel, CancellationToken, Task<GrpcChannel>>? recreator = options.Internal.ChannelRecreator; | ||
|
|
||
36 changes: 36 additions & 0 deletions
36
src/Extensions/AzureBlobPayloads/AutoPurge/Activities/AckPurgedPayloadsActivity.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.DurableTask.Client; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.DurableTask.AzureBlobPayloads; | ||
|
|
||
| /// <summary> | ||
| /// Activity that acknowledges to the backend the payloads whose blobs the worker has deleted, so the backend | ||
| /// can hard-delete the soft-deleted rows. | ||
| /// </summary> | ||
| /// <param name="client">The Durable Task client used to acknowledge purged payloads to the backend.</param> | ||
| /// <param name="logger">The logger instance.</param> | ||
| [DurableTask] | ||
| public class AckPurgedPayloadsActivity( | ||
| DurableTaskClient client, | ||
| ILogger<AckPurgedPayloadsActivity> logger) | ||
| : TaskActivity<List<PayloadPurgeAckDto>, object?> | ||
| { | ||
| readonly DurableTaskClient client = Check.NotNull(client); | ||
| readonly ILogger<AckPurgedPayloadsActivity> logger = Check.NotNull(logger); | ||
|
|
||
| /// <inheritdoc/> | ||
| public override async Task<object?> RunAsync(TaskActivityContext context, List<PayloadPurgeAckDto> input) | ||
| { | ||
| if (input is null || input.Count == 0) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| await this.client.AckPurgedPayloadsAsync(input, CancellationToken.None); | ||
| this.logger.BlobPurgeAckedPayloads(input.Count); | ||
| return null; | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
src/Extensions/AzureBlobPayloads/AutoPurge/Activities/DeleteExternalBlobActivity.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.DurableTask.AzureBlobPayloads; | ||
|
|
||
| /// <summary> | ||
| /// Activity that deletes a single externalized payload blob given its token. Deletion is idempotent, so | ||
| /// re-delivered tokens and concurrent workers are safe. On failure the payload is left tombstoned so a later | ||
| /// purge cycle can retry it. | ||
| /// </summary> | ||
| /// <param name="store">The payload store used to delete blobs.</param> | ||
| /// <param name="logger">The logger instance.</param> | ||
| [DurableTask] | ||
| public class DeleteExternalBlobActivity( | ||
| PayloadStore store, | ||
| ILogger<DeleteExternalBlobActivity> logger) | ||
| : TaskActivity<string, bool> | ||
| { | ||
| readonly PayloadStore store = Check.NotNull(store); | ||
| readonly ILogger<DeleteExternalBlobActivity> logger = Check.NotNull(logger); | ||
|
|
||
| /// <inheritdoc/> | ||
| public override async Task<bool> RunAsync(TaskActivityContext context, string input) | ||
| { | ||
| Check.NotNullOrEmpty(input, nameof(input)); | ||
|
|
||
| try | ||
| { | ||
| await this.store.DeleteAsync(input, CancellationToken.None); | ||
| return true; | ||
| } | ||
| catch (Exception ex) when (ex is not OutOfMemoryException and not StackOverflowException) | ||
| { | ||
| // Leave the payload tombstoned so the backend re-streams it on a later cycle; a single bad token | ||
| // must not fail the whole batch. | ||
| this.logger.BlobPurgeDeleteFailed(ex, input); | ||
| return false; | ||
| } | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/Extensions/AzureBlobPayloads/AutoPurge/Activities/GetTombstonedPayloadsActivity.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Microsoft.DurableTask.Client; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.DurableTask.AzureBlobPayloads; | ||
|
|
||
| /// <summary> | ||
| /// Activity that fetches a batch of tombstoned payloads from the backend for the auto-purge job to delete. | ||
| /// </summary> | ||
| /// <param name="client">The Durable Task client used to query the backend for tombstoned payloads.</param> | ||
| /// <param name="logger">The logger instance.</param> | ||
| [DurableTask] | ||
| public class GetTombstonedPayloadsActivity( | ||
| DurableTaskClient client, | ||
| ILogger<GetTombstonedPayloadsActivity> logger) | ||
| : TaskActivity<int, List<TombstonedPayloadDto>> | ||
| { | ||
| readonly DurableTaskClient client = Check.NotNull(client); | ||
| readonly ILogger<GetTombstonedPayloadsActivity> logger = Check.NotNull(logger); | ||
|
|
||
| /// <inheritdoc/> | ||
| public override async Task<List<TombstonedPayloadDto>> RunAsync(TaskActivityContext context, int input) | ||
| { | ||
| int limit = input > 0 ? input : 500; | ||
| List<TombstonedPayloadDto> payloads = | ||
| await this.client.GetTombstonedPayloadsAsync(limit, CancellationToken.None); | ||
| this.logger.BlobPurgeFetchedTombstones(payloads.Count); | ||
| return payloads; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove suffix dto?