fix: resolve small issues in db transactions (#5522)

* fix: use the db transaction reader and writer

* fix: internal/server: use ctx when scanning rows

* fix(host): pass db tx reader/writer into helper funcs

* fix: more precise nil check against db.Reader & db.Writer

---------

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
This commit is contained in:
Damian DebkowskiandJohan Brandhorst-Satzkorn authored and GitHub committed 2025-02-06 12:20:39 -08:00
1 parent 2d802fe3f5
commit acc40e0d08
20 files changed
+139 -27

No files matched your search

+1 -1
View File
@@ -179,7 +179,7 @@ func (r *Repository) upsertAccount(ctx context.Context, am *AuthMethod, IdTokenC
var rowCnt int
for rows.Next() {
rowCnt += 1
err = r.reader.ScanRows(ctx, rows, &result)
err = reader.ScanRows(ctx, rows, &result)
if err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to scan rows for account"))
}
@@ -11,6 +11,7 @@ import (
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/util"
)
// SetManagedGroupMemberships will set the managed groups for the given account
@@ -207,7 +208,7 @@ func (r *Repository) ListManagedGroupMembershipsByMember(ctx context.Context, wi
limit = opts.withLimit
}
reader := r.reader
if opts.withReader != nil {
if !util.IsNil(opts.withReader) {
reader = opts.withReader
}
var mgs []*ManagedGroupMemberAccount
@@ -232,7 +233,7 @@ func (r *Repository) ListManagedGroupMembershipsByGroup(ctx context.Context, wit
limit = opts.withLimit
}
reader := r.reader
if opts.withReader != nil {
if !util.IsNil(opts.withReader) {
reader = opts.withReader
}
var mgs []*ManagedGroupMemberAccount
+1 -1
View File
@@ -147,7 +147,7 @@ func (amr *AuthMethodRepository) ListDeletedIds(ctx context.Context, since time.
var deletedAuthMethodIDs []string
var transactionTimestamp time.Time
if _, err := amr.writer.DoTx(ctx, db.StdRetryCnt, db.ExpBackoff{}, func(r db.Reader, w db.Writer) error {
rows, err := amr.writer.Query(ctx, listDeletedIdsQuery, []any{sql.Named("since", since)})
rows, err := w.Query(ctx, listDeletedIdsQuery, []any{sql.Named("since", since)})
if err != nil {
return errors.Wrap(ctx, err, op)
}