Skip to content
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

fix: DB write of upsert pins in run as group #1598

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ __debug*
containerlogs
.vscode/*.log
.idea
doc-site/site
doc-site/site
doc-site/venv
9 changes: 7 additions & 2 deletions internal/events/batch_pin_complete.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -125,10 +125,15 @@ func (em *eventManager) persistContexts(ctx context.Context, batchPin *blockchai
log.L(ctx).Warnf("Batch insert of pins failed - assuming replay and performing upserts: %s", err)

// Fall back to an upsert
// Use a different context to not re-use DB TX from a group run
// We only get here if it fails so this would never work in the same DB TX
upsertCtx, cancel := context.WithCancel(ctx)
defer cancel()
for _, pin := range pins {
if err := em.database.UpsertPin(ctx, pin); err != nil {
if err := em.database.UpsertPin(upsertCtx, pin); err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a very bad idea to intentionally do this outside the database transaction.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The batch insert above should be non-fatal (should be configured to return an empty result on conflict)

}
}

return nil
}
Loading