From caca2a7130288dec49fa26b49c8550140ee52f4c Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Wed, 22 Sep 2021 13:21:43 +0300 Subject: [PATCH] fix: change DBStats to use uint32 instead of uint64 to make it work on i386 --- Makefile | 3 ++- db.go | 8 ++++---- driver/pgdriver/driver.go | 14 -------------- driver/pgdriver/listener.go | 4 ---- hook.go | 4 ++-- migrate/migration.go | 2 +- 6 files changed, 9 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 54744c61..e121c1d8 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,8 @@ test: set -e; for dir in $(ALL_GO_MOD_DIRS); do \ echo "go test in $${dir}"; \ (cd "$${dir}" && \ - go test ./... && \ + go test && \ + env GOOS=linux GOARCH=386 go test && \ go vet); \ done diff --git a/db.go b/db.go index 8514ca93..9c9c8f9f 100644 --- a/db.go +++ b/db.go @@ -18,8 +18,8 @@ const ( ) type DBStats struct { - Queries uint64 - Errors uint64 + Queries uint32 + Errors uint32 } type DBOption func(db *DB) @@ -70,8 +70,8 @@ func (db *DB) String() string { func (db *DB) DBStats() DBStats { return DBStats{ - Queries: atomic.LoadUint64(&db.stats.Queries), - Errors: atomic.LoadUint64(&db.stats.Errors), + Queries: atomic.LoadUint32(&db.stats.Queries), + Errors: atomic.LoadUint32(&db.stats.Errors), } } diff --git a/driver/pgdriver/driver.go b/driver/pgdriver/driver.go index 197770af..14cf6eea 100644 --- a/driver/pgdriver/driver.go +++ b/driver/pgdriver/driver.go @@ -66,15 +66,8 @@ func (d Driver) Open(name string) (driver.Conn, error) { //------------------------------------------------------------------------------ -type DriverStats struct { - Queries uint64 - Errors uint64 -} - type Connector struct { cfg *Config - - stats DriverStats } func NewConnector(opts ...DriverOption) *Connector { @@ -103,13 +96,6 @@ func (d *Connector) Config() *Config { return d.cfg } -func (d *Connector) Stats() DriverStats { - return DriverStats{ - Queries: atomic.LoadUint64(&d.stats.Queries), - Errors: atomic.LoadUint64(&d.stats.Errors), - } -} - //------------------------------------------------------------------------------ type Conn struct { diff --git a/driver/pgdriver/listener.go b/driver/pgdriver/listener.go index 937c80fa..e493575e 100644 --- a/driver/pgdriver/listener.go +++ b/driver/pgdriver/listener.go @@ -5,7 +5,6 @@ import ( "errors" "strconv" "sync" - "sync/atomic" "time" "github.com/uptrace/bun" @@ -66,11 +65,8 @@ func (ln *Listener) conn(ctx context.Context) (*Conn, error) { return ln.cn, nil } - atomic.AddUint64(&ln.driver.stats.Queries, 1) - cn, err := ln._conn(ctx) if err != nil { - atomic.AddUint64(&ln.driver.stats.Errors, 1) return nil, err } diff --git a/hook.go b/hook.go index 88f8adbf..ea6fc330 100644 --- a/hook.go +++ b/hook.go @@ -53,7 +53,7 @@ func (db *DB) beforeQuery( query string, queryArgs []interface{}, ) (context.Context, *QueryEvent) { - atomic.AddUint64(&db.stats.Queries, 1) + atomic.AddUint32(&db.stats.Queries, 1) if len(db.queryHooks) == 0 { return ctx, nil @@ -86,7 +86,7 @@ func (db *DB) afterQuery( case nil, sql.ErrNoRows: // nothing default: - atomic.AddUint64(&db.stats.Errors, 1) + atomic.AddUint32(&db.stats.Errors, 1) } if event == nil { diff --git a/migrate/migration.go b/migrate/migration.go index 79f13f97..87881d6a 100644 --- a/migrate/migration.go +++ b/migrate/migration.go @@ -190,7 +190,7 @@ func (ms MigrationSlice) LastGroupID() int64 { var lastGroupID int64 for i := range ms { groupID := ms[i].GroupID - if groupID != 0 && groupID > lastGroupID { + if groupID > lastGroupID { lastGroupID = groupID } }