Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade pgx to v5 and use trimmed sql-migrate (Rebase:4bf4c19) #1067

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 8 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,21 @@ module github.com/heroiclabs/nakama/v3
go 1.21

require (
github.com/bits-and-blooms/bitset v1.5.0
github.com/blugelabs/bluge v0.2.2
github.com/blugelabs/bluge_segment_api v0.2.0
github.com/blugelabs/query_string v0.3.0
github.com/dop251/goja v0.0.0-20231014103939-873a1496dc8e
github.com/go-gorp/gorp/v3 v3.1.0
github.com/gofrs/uuid/v5 v5.0.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/golang/snappy v0.0.4
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0
github.com/heroiclabs/nakama-common v1.30.0
github.com/jackc/pgconn v1.14.0
github.com/heroiclabs/sql-migrate v0.0.0-20230615133120-fb3ad977aaaf
github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
github.com/jackc/pgtype v1.14.0
github.com/jackc/pgx/v4 v4.18.1
github.com/prometheus/client_golang v1.16.0
github.com/rubenv/sql-migrate v1.2.0
github.com/jackc/pgx/v5 v5.5.0
github.com/stretchr/testify v1.8.4
github.com/twmb/murmur3 v1.1.8
github.com/uber-go/tally/v4 v4.1.7
go.uber.org/atomic v1.11.0
go.uber.org/zap v1.24.0
Expand All @@ -44,6 +37,7 @@ require (
github.com/RoaringBitmap/roaring v0.9.4 // indirect
github.com/axiomhq/hyperloglog v0.0.0-20191112132149-a4c4c47bc57f // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.5.0 // indirect
github.com/blevesearch/go-porterstemmer v1.0.3 // indirect
github.com/blevesearch/mmap-go v1.0.4 // indirect
github.com/blevesearch/segment v0.9.0 // indirect
Expand All @@ -58,25 +52,26 @@ require (
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
github.com/gofrs/uuid v4.3.0+incompatible // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/klauspost/compress v1.15.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/twmb/murmur3 v1.1.8 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
Expand Down
663 changes: 9 additions & 654 deletions go.sum

Large diffs are not rendered by default.

55 changes: 40 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,11 @@ import (
"github.com/heroiclabs/nakama/v3/migrate"
"github.com/heroiclabs/nakama/v3/server"
"github.com/heroiclabs/nakama/v3/social"
_ "github.com/jackc/pgx/v4/stdlib"
"github.com/jackc/pgx/v5/stdlib"
_ "github.com/jackc/pgx/v5/stdlib" // Blank import to register SQL driver
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"google.golang.org/protobuf/encoding/protojson"

_ "github.com/bits-and-blooms/bitset"
_ "github.com/go-gorp/gorp/v3"
_ "github.com/golang/snappy"
_ "github.com/prometheus/client_golang/prometheus"
_ "github.com/twmb/murmur3"
)

const cookieFilename = ".cookie"
Expand Down Expand Up @@ -71,13 +66,34 @@ func main() {

tmpLogger := server.NewJSONLogger(os.Stdout, zapcore.InfoLevel, server.JSONFormat)

ctx, ctxCancelFn := context.WithCancel(context.Background())

if len(os.Args) > 1 {
switch os.Args[1] {
case "--version":
fmt.Println(semver)
return
case "migrate":
migrate.Parse(os.Args[2:], tmpLogger)
config := server.ParseArgs(tmpLogger, os.Args[2:])
config.ValidateDatabase(tmpLogger)
db := server.DbConnect(ctx, tmpLogger, config, true)
defer db.Close()

conn, err := db.Conn(ctx)
if err != nil {
tmpLogger.Fatal("Failed to acquire db conn for migration", zap.Error(err))
}

if err = conn.Raw(func(driverConn any) error {
pgxConn := driverConn.(*stdlib.Conn).Conn()
migrate.RunCmd(ctx, tmpLogger, pgxConn, os.Args[2], config.GetLimit(), config.GetLogger().Format)

return nil
}); err != nil {
conn.Close()
tmpLogger.Fatal("Failed to acquire pgx conn for migration", zap.Error(err))
}
conn.Close()
return
case "check":
// Parse any command line args to look up runtime path.
Expand Down Expand Up @@ -108,7 +124,7 @@ func main() {

config := server.ParseArgs(tmpLogger, os.Args)
logger, startupLogger := server.SetupLogging(tmpLogger, config)
configWarnings := server.CheckConfig(logger, config)
configWarnings := config.Validate(logger)

startupLogger.Info("Nakama starting")
startupLogger.Info("Node", zap.String("name", config.GetName()), zap.String("version", semver), zap.String("runtime", runtime.Version()), zap.Int("cpu", runtime.NumCPU()), zap.Int("proc", runtime.GOMAXPROCS(0)))
Expand All @@ -125,14 +141,23 @@ func main() {
}
startupLogger.Info("Database connections", zap.Strings("dsns", redactedAddresses))

// Global server context.
ctx, ctxCancelFn := context.WithCancel(context.Background())

db, dbVersion := server.DbConnect(ctx, startupLogger, config)
startupLogger.Info("Database information", zap.String("version", dbVersion))
db := server.DbConnect(ctx, startupLogger, config, false)

// Check migration status and fail fast if the schema has diverged.
migrate.StartupCheck(startupLogger, db)
conn, err := db.Conn(context.Background())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this leaks connection. needs conn.Close() on success and errors paths

if err != nil {
logger.Fatal("Failed to acquire db conn for migration check", zap.Error(err))
}

if err = conn.Raw(func(driverConn any) error {
pgxConn := driverConn.(*stdlib.Conn).Conn()
migrate.Check(ctx, startupLogger, pgxConn)
return nil
}); err != nil {
conn.Close()
logger.Fatal("Failed to acquire pgx conn for migration check", zap.Error(err))
}
conn.Close()

// Access to social provider integrations.
socialClient := social.NewClient(logger, 5*time.Second, config.GetGoogleAuth().OAuthConfig)
Expand Down
Loading
Loading