Skip to content

Commit

Permalink
fix: change DBStats to use uint32 instead of uint64 to make it work o…
Browse files Browse the repository at this point in the history
…n i386
  • Loading branch information
vmihailenco committed Sep 22, 2021
1 parent 7daf77c commit caca2a7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 26 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const (
)

type DBStats struct {
Queries uint64
Errors uint64
Queries uint32
Errors uint32
}

type DBOption func(db *DB)
Expand Down Expand Up @@ -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),
}
}

Expand Down
14 changes: 0 additions & 14 deletions driver/pgdriver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions driver/pgdriver/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"strconv"
"sync"
"sync/atomic"
"time"

"github.com/uptrace/bun"
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion migrate/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit caca2a7

Please sign in to comment.