Исправить замечания ревью кода: убрать повтор в AppendOnce за счёт запаса у чистки ключей, вынести MessagePayload и SameContent, принять X-Request-Id от балансировщика, упростить фоновые задачи сервера, сократить комментарии

This commit is contained in:
2026-11-04 12:19:49 +03:00
parent c9d0f73221
commit 7fbd781ca3
25 changed files with 207 additions and 247 deletions
+6 -8
View File
@@ -2,8 +2,7 @@
//
// 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.
// is chosen against them.
package postgres
import (
@@ -75,21 +74,20 @@ func NewPool(ctx context.Context, dsn string, maxConns int32) (*pgxpool.Pool, er
return pool, nil
}
// Migrate applies pending migrations and returns the versions it applied. A
// session advisory lock serialises concurrent starts, so several API
// replicas may call it at once; applied versions are recorded, which makes a
// repeated run a no-op.
// Migrate applies pending migrations and returns their versions; a session
// advisory lock makes overlapping runs wait for each other.
func Migrate(ctx context.Context, pool *pgxpool.Pool) ([]int64, error) {
db := stdlib.OpenDBFromPool(pool)
defer db.Close()
locker, err := lock.NewPostgresSessionLocker()
if err != nil {
return nil, fmt.Errorf("migration lock: %w", err)
}
db := stdlib.OpenDBFromPool(pool)
provider, err := goose.NewProvider(goose.DialectPostgres, db, migrations.FS, goose.WithSessionLocker(locker))
if err != nil {
db.Close()
return nil, fmt.Errorf("load migrations: %w", err)
}
defer provider.Close()
results, err := provider.Up(ctx)
if err != nil {
return nil, fmt.Errorf("apply migrations: %w", err)
@@ -190,8 +190,6 @@ 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 {