satellite/metabase: use pgxutil.Conn helper

Clean up underlying pgx.Conn extraction with helper.

Change-Id: Ie43f663a6036c439e675df54fccd3605c4d8d69e
This commit is contained in:
Egon Elbre 2021-05-24 21:37:24 +03:00
parent e460dc51f7
commit e7cf369cd8
3 changed files with 6 additions and 29 deletions

2
go.mod
View File

@ -56,6 +56,6 @@ require (
storj.io/common v0.0.0-20210504141454-bcb03a80052f storj.io/common v0.0.0-20210504141454-bcb03a80052f
storj.io/drpc v0.0.20 storj.io/drpc v0.0.20
storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7 storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7
storj.io/private v0.0.0-20210511083637-239fca6e9894 storj.io/private v0.0.0-20210524180731-c53cb26153ff
storj.io/uplink v1.5.0-rc.1.0.20210512164354-e2e5889614a9 storj.io/uplink v1.5.0-rc.1.0.20210512164354-e2e5889614a9
) )

4
go.sum
View File

@ -859,7 +859,7 @@ storj.io/drpc v0.0.20/go.mod h1:eAxUDk8HWvGl9iqznpuphtZ+WIjIGPJFqNXuKHgRiMM=
storj.io/monkit-jaeger v0.0.0-20210225162224-66fb37637bf6/go.mod h1:gj4vuCeyCRjRmH8LIrgoyU9Dc9uR6H+/GcDUXmTbf80= storj.io/monkit-jaeger v0.0.0-20210225162224-66fb37637bf6/go.mod h1:gj4vuCeyCRjRmH8LIrgoyU9Dc9uR6H+/GcDUXmTbf80=
storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7 h1:zi0w9zoBfvuqysSAqxJT1Ton2YB5IhyMM3/3CISjlrQ= storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7 h1:zi0w9zoBfvuqysSAqxJT1Ton2YB5IhyMM3/3CISjlrQ=
storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7/go.mod h1:gj4vuCeyCRjRmH8LIrgoyU9Dc9uR6H+/GcDUXmTbf80= storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7/go.mod h1:gj4vuCeyCRjRmH8LIrgoyU9Dc9uR6H+/GcDUXmTbf80=
storj.io/private v0.0.0-20210511083637-239fca6e9894 h1:ANILx94AKXmvXAf+hs0HMb85Qi2Y4k7RjEb9S7OhK+M= storj.io/private v0.0.0-20210524180731-c53cb26153ff h1:8PmjrrpFWYSmjctmPloifwlV+mCwYLfipsS7BuC2kkk=
storj.io/private v0.0.0-20210511083637-239fca6e9894/go.mod h1:iAc+LGwXYCe+YRRTlkfkg95ZBEL8pWHLVZ508/KQjOs= storj.io/private v0.0.0-20210524180731-c53cb26153ff/go.mod h1:iAc+LGwXYCe+YRRTlkfkg95ZBEL8pWHLVZ508/KQjOs=
storj.io/uplink v1.5.0-rc.1.0.20210512164354-e2e5889614a9 h1:F+A+Ki4eo3uzYXxesihRBq7PYBhU8MgfZeebd4O8hio= storj.io/uplink v1.5.0-rc.1.0.20210512164354-e2e5889614a9 h1:F+A+Ki4eo3uzYXxesihRBq7PYBhU8MgfZeebd4O8hio=
storj.io/uplink v1.5.0-rc.1.0.20210512164354-e2e5889614a9/go.mod h1:geRW2dh4rvPhgruFZbN71LSYkMmCJLpwg0y8K/uLr3Y= storj.io/uplink v1.5.0-rc.1.0.20210512164354-e2e5889614a9/go.mod h1:geRW2dh4rvPhgruFZbN71LSYkMmCJLpwg0y8K/uLr3Y=

View File

@ -9,10 +9,10 @@ import (
"time" "time"
"github.com/jackc/pgx/v4" "github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/stdlib"
"github.com/zeebo/errs" "github.com/zeebo/errs"
"go.uber.org/zap" "go.uber.org/zap"
"storj.io/private/dbutil/pgxutil"
"storj.io/private/tagsql" "storj.io/private/tagsql"
) )
@ -175,29 +175,7 @@ func (db *DB) deleteObjectsAndSegments(ctx context.Context, objects []ObjectStre
return nil return nil
} }
conn, err := db.db.Conn(ctx) err = pgxutil.Conn(ctx, db.db, func(conn *pgx.Conn) error {
if err != nil {
return Error.New("unable to get the raw conn: %w", err)
}
defer func() { err = errs.Combine(err, conn.Close()) }()
err = conn.Raw(ctx, func(driverConn interface{}) (err error) {
defer func() {
if closable, ok := driverConn.(interface{ Close() error }); ok {
err = errs.Combine(err, closable.Close())
}
}()
var pgxconn *pgx.Conn
switch conn := driverConn.(type) {
case interface{ StdlibConn() *stdlib.Conn }:
pgxconn = conn.StdlibConn().Conn()
case *stdlib.Conn:
pgxconn = conn.Conn()
default:
return Error.New("invalid raw conn driver %T", driverConn)
}
var batch pgx.Batch var batch pgx.Batch
for _, obj := range objects { for _, obj := range objects {
obj := obj obj := obj
@ -215,7 +193,7 @@ func (db *DB) deleteObjectsAndSegments(ctx context.Context, objects []ObjectStre
batch.Queue(`COMMIT TRANSACTION`) batch.Queue(`COMMIT TRANSACTION`)
} }
results := pgxconn.SendBatch(ctx, &batch) results := conn.SendBatch(ctx, &batch)
defer func() { err = errs.Combine(err, results.Close()) }() defer func() { err = errs.Combine(err, results.Close()) }()
var errlist errs.Group var errlist errs.Group
@ -229,6 +207,5 @@ func (db *DB) deleteObjectsAndSegments(ctx context.Context, objects []ObjectStre
if err != nil { if err != nil {
return Error.New("unable to delete expired objects: %w", err) return Error.New("unable to delete expired objects: %w", err)
} }
return nil return nil
} }