Skip to content

Commit

Permalink
fix: DB write of upsert pins in run as group
Browse files Browse the repository at this point in the history
Signed-off-by: Enrique Lacal <[email protected]>
  • Loading branch information
EnriqueL8 committed Nov 12, 2024
1 parent 62ee71f commit 6d10892
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
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
}
}

return nil
}

0 comments on commit 6d10892

Please sign in to comment.