-
Notifications
You must be signed in to change notification settings - Fork 240
Operation handling for reliable receipts #1637
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
Changes from 16 commits
e056a35
0585016
3678677
22f7a50
77d478f
387af52
b29c640
91255ab
d75e801
9c53fff
283dce4
9ebfc42
b16ed26
7fb6b08
e8fbe13
7ac8f7e
098a188
5839d3c
b5c4555
40fe22e
456279a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Copyright © 2023 Kaleido, Inc. | ||
| // Copyright © 2025 Kaleido, Inc. | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
@@ -93,6 +93,37 @@ func (ou *operationUpdater) pickWorker(ctx context.Context, id *fftypes.UUID, up | |
| return ou.workQueues[worker] | ||
| } | ||
|
|
||
| // SubmitBulkOperationUpdates will wait for the commit to DB before calling the onCommit | ||
| func (ou *operationUpdater) SubmitBulkOperationUpdates(ctx context.Context, updates []*core.OperationUpdate) error { | ||
| validUpdates := []*core.OperationUpdate{} | ||
| for _, update := range updates { | ||
| ns, _, err := core.ParseNamespacedOpID(ctx, update.NamespacedOpID) | ||
| if err != nil { | ||
| log.L(ctx).Warnf("Unable to update operation '%s' due to invalid ID: %s", update.NamespacedOpID, err) | ||
| continue | ||
| } | ||
|
|
||
| if ns != ou.manager.namespace { | ||
EnriqueL8 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| log.L(ou.ctx).Debugf("Ignoring operation update from different namespace '%s'", ns) | ||
| continue | ||
| } | ||
|
|
||
| validUpdates = append(validUpdates, update) | ||
| } | ||
|
|
||
| // Notice how this is not using the workers and is synchronous | ||
| // The reason is because we want for all updates to be stored at once in this order | ||
| // If offloaded into workers the updates would be processed in parallel, in different DB TX and in a different order | ||
| // Up to the caller to retry if this fails | ||
| err := ou.doBatchUpdateAsGroup(ctx, validUpdates) | ||
| if err != nil { | ||
| log.L(ctx).Warnf("Exiting while updating operations: %s", err) | ||
| return err | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (ou *operationUpdater) SubmitOperationUpdate(ctx context.Context, update *core.OperationUpdate) { | ||
| ns, id, err := core.ParseNamespacedOpID(ctx, update.NamespacedOpID) | ||
| if err != nil { | ||
|
|
@@ -181,25 +212,32 @@ func (ou *operationUpdater) updaterLoop(index int) { | |
| } | ||
| } | ||
|
|
||
| func (ou *operationUpdater) doBatchUpdateAsGroup(ctx context.Context, updates []*core.OperationUpdate) error { | ||
| err := ou.database.RunAsGroup(ctx, func(ctx context.Context) error { | ||
| return ou.doBatchUpdate(ctx, updates) | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| for _, update := range updates { | ||
| if update.OnComplete != nil { | ||
|
||
| update.OnComplete() | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (ou *operationUpdater) doBatchUpdateWithRetry(ctx context.Context, updates []*core.OperationUpdate) error { | ||
| return ou.retry.Do(ctx, "operation update", func(attempt int) (retry bool, err error) { | ||
| err = ou.database.RunAsGroup(ctx, func(ctx context.Context) error { | ||
| return ou.doBatchUpdate(ctx, updates) | ||
| }) | ||
| err = ou.doBatchUpdateAsGroup(ctx, updates) | ||
| if err != nil { | ||
| return true, err | ||
| } | ||
| for _, update := range updates { | ||
| if update.OnComplete != nil { | ||
| update.OnComplete() | ||
| } | ||
| } | ||
| return false, nil | ||
| }) | ||
| } | ||
|
|
||
| func (ou *operationUpdater) doBatchUpdate(ctx context.Context, updates []*core.OperationUpdate) error { | ||
|
|
||
| // Get all the operations that match | ||
| opIDs := make([]*fftypes.UUID, 0, len(updates)) | ||
| for _, update := range updates { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.