-
Notifications
You must be signed in to change notification settings - Fork 447
fix(cloud): drop tasks past payload store retention #4369
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
Open
grutt
wants to merge
5
commits into
main
Choose a base branch
from
fix--drop-tasks-past-payload-store-retention
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.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
28a23d2
fix: drop tasks past payload store retention
grutt 9679534
fix: remove n+1
grutt d5d0fff
Merge branch 'main' into fix--drop-tasks-past-payload-store-retention
grutt 502725f
sensible returns signature
grutt cc22079
Merge branch 'main' into fix--drop-tasks-past-payload-store-retention
grutt 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -509,6 +509,15 @@ func (d *DispatcherImpl) handleTaskBulkAssignedTask(ctx context.Context, msg *ms | |
| toRetryMu.Unlock() | ||
| } | ||
|
|
||
| toFail := []*sqlcv1.V1Task{} | ||
| toFailMu := sync.Mutex{} | ||
|
|
||
| fail := func(task *sqlcv1.V1Task) { | ||
| toFailMu.Lock() | ||
| toFail = append(toFail, task) | ||
| toFailMu.Unlock() | ||
| } | ||
|
|
||
| for _, innerMsg := range msgs { | ||
| // load the step runs from the database | ||
| taskIds := make([]int64, 0) | ||
|
|
@@ -517,7 +526,7 @@ func (d *DispatcherImpl) handleTaskBulkAssignedTask(ctx context.Context, msg *ms | |
| taskIds = append(taskIds, tasks...) | ||
| } | ||
|
|
||
| taskIdToData, err := d.populateTaskData(ctx, requeue, msg.TenantID, taskIds) | ||
| taskIdToData, err := d.populateTaskData(ctx, requeue, fail, msg.TenantID, taskIds) | ||
|
|
||
| if err != nil { | ||
| // we've already handled the requeue in populateTaskData, and we've logged the error, so we just continue | ||
|
|
@@ -544,6 +553,10 @@ func (d *DispatcherImpl) handleTaskBulkAssignedTask(ctx context.Context, msg *ms | |
| outerErr = multierror.Append(outerErr, fmt.Errorf("could not retry failed tasks: %w", err)) | ||
| } | ||
|
|
||
| if err := d.handleNonRetryableFailures(ctx, msg.TenantID, toFail); err != nil { | ||
| outerErr = multierror.Append(outerErr, fmt.Errorf("could not fail tasks with missing payloads: %w", err)) | ||
| } | ||
|
|
||
| if outerErr != nil { | ||
| d.l.Error().Ctx(ctx).Err(outerErr).Msg("failed to handle task assigned bulk message") | ||
| } | ||
|
|
@@ -642,6 +655,7 @@ type V1TaskWithPayloadAndInvocationCount struct { | |
| func (d *DispatcherImpl) populateTaskData( | ||
| ctx context.Context, | ||
| requeue func(task *sqlcv1.V1Task), | ||
| fail func(task *sqlcv1.V1Task), | ||
| tenantId uuid.UUID, | ||
| taskIds []int64, | ||
| ) (map[int64]*V1TaskWithPayloadAndInvocationCount, error) { | ||
|
|
@@ -707,10 +721,35 @@ func (d *DispatcherImpl) populateTaskData( | |
|
|
||
| inputs, err := d.repov1.Payloads().Retrieve(ctx, nil, retrievePayloadOpts...) | ||
|
|
||
| // FIXME: we should differentiate between a retryable error and a non-retryable error here; | ||
| // for example, if we're hitting an S3 rate limit for payloads that exist in S3, we should retry; | ||
| // however, if the payloads simply don't exist, we should fail the tasks instead of requeuing them. | ||
| // The tasks will eventually fail but the extra retries are wasteful. | ||
| if err != nil && errors.Is(err, v1.ErrPayloadNotFound) { | ||
| // The bulk retrieval doesn't tell us which task's payload is missing, so retry each task | ||
| // individually: tasks whose payloads are permanently gone are failed (otherwise they'd be | ||
| // requeued forever), and the rest proceed or requeue as usual. | ||
| inputs = make(map[v1.RetrievePayloadOpts][]byte) | ||
| remaining := make([]*sqlcv1.V1Task, 0, len(bulkDatas)) | ||
|
|
||
| for i, task := range bulkDatas { | ||
| taskInputs, taskErr := d.repov1.Payloads().Retrieve(ctx, nil, retrievePayloadOpts[i]) | ||
|
|
||
| switch { | ||
| case taskErr == nil: | ||
| for opt, input := range taskInputs { | ||
| inputs[opt] = input | ||
| } | ||
|
|
||
| remaining = append(remaining, task) | ||
| case errors.Is(taskErr, v1.ErrPayloadNotFound): | ||
| d.l.Error().Ctx(ctx).Err(taskErr).Int64("task_id", task.ID).Msg("task input payload no longer exists in external store, failing task") | ||
| fail(task) | ||
| default: | ||
| requeue(task) | ||
| } | ||
| } | ||
|
|
||
| bulkDatas = remaining | ||
| err = nil | ||
| } | ||
|
|
||
| if err != nil { | ||
| for _, task := range bulkDatas { | ||
| requeue(task) | ||
|
|
@@ -956,6 +995,55 @@ func (d *DispatcherImpl) handleRetries( | |
| return retryGroup.Wait() | ||
| } | ||
|
|
||
| // handleNonRetryableFailures permanently fails tasks whose input payloads no longer exist in the | ||
| // external payload store, since requeueing them can never succeed. | ||
| func (d *DispatcherImpl) handleNonRetryableFailures( | ||
| ctx context.Context, | ||
| tenantId uuid.UUID, | ||
| toFail []*sqlcv1.V1Task, | ||
| ) error { | ||
| if len(toFail) == 0 { | ||
| return nil | ||
| } | ||
|
|
||
| failCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
|
|
||
| failGroup := errgroup.Group{} | ||
|
|
||
| for _, _task := range toFail { | ||
| task := _task | ||
|
|
||
| failGroup.Go(func() error { | ||
|
Contributor
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. do we do this kind of thing concurrently in other places? just checking to make sure we're being consistent, not sure off the top of my head |
||
| msg, err := tasktypesv1.FailedTaskMessage( | ||
| tenantId, | ||
| task.ID, | ||
| task.InsertedAt, | ||
| task.ExternalID, | ||
| task.WorkflowRunID, | ||
| task.RetryCount, | ||
| true, | ||
| "Could not retrieve task input: the payload no longer exists in the external payload store.", | ||
| true, | ||
| ) | ||
|
|
||
| if err != nil { | ||
| return fmt.Errorf("could not create failed task message: %w", err) | ||
| } | ||
|
|
||
| err = d.mqv1.SendMessage(failCtx, msgqueue.TASK_PROCESSING_QUEUE, msg) | ||
|
|
||
| if err != nil { | ||
| return fmt.Errorf("could not send failed task message: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| }) | ||
| } | ||
|
|
||
| return failGroup.Wait() | ||
| } | ||
|
|
||
| func (d *DispatcherImpl) handleTaskCancelled(ctx context.Context, msg *msgqueue.Message) error { | ||
| ctx, span := telemetry.NewSpanWithCarrier(ctx, "tasks-cancelled", msg.OtelCarrier) | ||
| defer span.End() | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.