Добавить X-Instance-Id, задержку drain при SIGTERM и отдельный запуск миграций
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
// Package postgres opens the connection pool and applies the schema.
|
||||
//
|
||||
// Pool size and server-side timeouts are constants rather than settings: they
|
||||
// bound how long one request can hold a connection, and the request deadline
|
||||
// of the API is chosen against them.
|
||||
// Server-side timeouts are constants rather than settings: they bound how
|
||||
// long one request can hold a connection, and the request deadline of the API
|
||||
// is chosen against them. The pool size is a setting, because the scaling
|
||||
// study varies it.
|
||||
package postgres
|
||||
|
||||
import (
|
||||
@@ -27,7 +28,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
maxConns = 10
|
||||
connectTimeout = time.Second
|
||||
statementTimeout = 5 * time.Second
|
||||
idleInTxTimeout = 10 * time.Second
|
||||
@@ -35,7 +35,7 @@ const (
|
||||
|
||||
const codeUniqueViolation = "23505"
|
||||
|
||||
func NewPool(ctx context.Context, dsn string) (*pgxpool.Pool, error) {
|
||||
func NewPool(ctx context.Context, dsn string, maxConns int32) (*pgxpool.Pool, error) {
|
||||
cfg, err := pgxpool.ParseConfig(dsn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse database url: %w", err)
|
||||
|
||||
@@ -184,8 +184,21 @@ func TestClassifyMarksUnreachableDatabaseAsUnavailable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The pool size is an experiment variable of the scaling study, so it is
|
||||
// passed in rather than fixed.
|
||||
func TestNewPoolUsesTheRequestedSize(t *testing.T) {
|
||||
pool, err := postgres.NewPool(context.Background(), db.DSN, 3)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer pool.Close()
|
||||
if got := pool.Config().MaxConns; got != 3 {
|
||||
t.Fatalf("MaxConns = %d, want 3", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassifyRealConnectFailure(t *testing.T) {
|
||||
_, err := postgres.NewPool(context.Background(), "postgres://u:p@127.0.0.1:1/db?connect_timeout=1")
|
||||
_, err := postgres.NewPool(context.Background(), "postgres://u:p@127.0.0.1:1/db?connect_timeout=1", 1)
|
||||
if err == nil {
|
||||
t.Fatal("NewPool to a closed port must fail")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user