From a66d374f597d4a393dbf97fe47ed95a57726ca03 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 11 Nov 2026 14:16:40 -0500 Subject: [PATCH 1/4] libraries: upgrade go-database onto go-core v0.12.0, sqlate v0.7.0, pgx v5.13.0 - Base module requires go-core v0.12.0 (set explicitly: the tag is fetchable but not yet in the proxy's version list) and sqlate v0.7.0. - postgres requires pgx v5.13.0; its indirect go-core and sqlate move to v0.12.0 and v0.7.0. Its go-database requirement stays at v0.11.0 for release prep. - sweep: go-core v0.12.0 replaced reactor's option functions with a trailing reactor.Options, so New passes Options{CancelAfter: CancelWithin(shutdown)}. The sweeper still cancels a running pass at half the shutdown drain; sweep's exported API is unchanged. - No sqlate TxOption/Isolation/ReadOnly use existed to adapt. - go directive stays at 1.27. --- go.mod | 4 ++-- go.sum | 8 ++++---- postgres/go.mod | 6 +++--- postgres/go.sum | 12 ++++++------ sweep/sweep.go | 15 ++++++++------- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index a5e8dba..717bd86 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module github.com/standards-lab/go-database go 1.27 require ( - github.com/standards-lab/go-core v0.11.0 - github.com/standards-lab/sqlate v0.6.1 + github.com/standards-lab/go-core v0.12.0 + github.com/standards-lab/sqlate v0.7.0 ) diff --git a/go.sum b/go.sum index 96e20d4..887392a 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,4 @@ -github.com/standards-lab/go-core v0.11.0 h1:Ls/jdYSRaC6ch187B1xNz39qfWXmSgNpOZ5Ot+2z+U8= -github.com/standards-lab/go-core v0.11.0/go.mod h1:Yl/R+gM9YWczsePBCKXdPGh3FSdZ/5i8SapLIh3BDHU= -github.com/standards-lab/sqlate v0.6.1 h1:Kgp8freMX9Gs2KweBwG4IPzENgUmSJq8+r4tq02cDNw= -github.com/standards-lab/sqlate v0.6.1/go.mod h1:pikNmGf/z3x46SBWFXgt/xKIDZuquSgCoXy5OWBFFR4= +github.com/standards-lab/go-core v0.12.0 h1:sqrzK6QSppEYpwvVAyiWgzNuOsjfK0Kwe86GPuZpHsU= +github.com/standards-lab/go-core v0.12.0/go.mod h1:Yl/R+gM9YWczsePBCKXdPGh3FSdZ/5i8SapLIh3BDHU= +github.com/standards-lab/sqlate v0.7.0 h1:GVb3OCDXwSS9RCxQ2BRIfV73zwBeJBhkvDLBJnTYd/U= +github.com/standards-lab/sqlate v0.7.0/go.mod h1:pikNmGf/z3x46SBWFXgt/xKIDZuquSgCoXy5OWBFFR4= diff --git a/postgres/go.mod b/postgres/go.mod index 4bf4331..e7b818f 100644 --- a/postgres/go.mod +++ b/postgres/go.mod @@ -3,7 +3,7 @@ module github.com/standards-lab/go-database/postgres go 1.27 require ( - github.com/jackc/pgx/v5 v5.12.0 + github.com/jackc/pgx/v5 v5.13.0 github.com/standards-lab/go-database v0.11.0 ) @@ -11,8 +11,8 @@ require ( github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.3 // indirect - github.com/standards-lab/go-core v0.11.0 // indirect - github.com/standards-lab/sqlate v0.6.1 // indirect + github.com/standards-lab/go-core v0.12.0 // indirect + github.com/standards-lab/sqlate v0.7.0 // indirect golang.org/x/sync v0.22.0 // indirect golang.org/x/text v0.41.0 // indirect ) diff --git a/postgres/go.sum b/postgres/go.sum index af89461..b18f296 100644 --- a/postgres/go.sum +++ b/postgres/go.sum @@ -5,18 +5,18 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.12.0 h1:hWwax8YiGT0YiN50U1oIDn5kgR7KC2tG3rmavwpPkxY= -github.com/jackc/pgx/v5 v5.12.0/go.mod h1:u2Fi6no03HCSBYE+ZVdLxbwdu3xyi2vU+K/YNJioSds= +github.com/jackc/pgx/v5 v5.13.0 h1:Hl08k64maU0nrRyVUEbwCnK6/gT0EhMrtAqBHz9/gA4= +github.com/jackc/pgx/v5 v5.13.0/go.mod h1:u2Fi6no03HCSBYE+ZVdLxbwdu3xyi2vU+K/YNJioSds= github.com/jackc/puddle/v2 v2.2.3 h1:f8HoREISb3l5eO9coPgK7U3hKLhWGokOFVcThl5jrao= github.com/jackc/puddle/v2 v2.2.3/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/standards-lab/go-core v0.11.0 h1:Ls/jdYSRaC6ch187B1xNz39qfWXmSgNpOZ5Ot+2z+U8= -github.com/standards-lab/go-core v0.11.0/go.mod h1:Yl/R+gM9YWczsePBCKXdPGh3FSdZ/5i8SapLIh3BDHU= +github.com/standards-lab/go-core v0.12.0 h1:sqrzK6QSppEYpwvVAyiWgzNuOsjfK0Kwe86GPuZpHsU= +github.com/standards-lab/go-core v0.12.0/go.mod h1:Yl/R+gM9YWczsePBCKXdPGh3FSdZ/5i8SapLIh3BDHU= github.com/standards-lab/go-database v0.11.0 h1:VP8AK2oCGIBVJQ+M7U4p86xuH1QOaTLghsEwxmS0P60= github.com/standards-lab/go-database v0.11.0/go.mod h1:luUB/jkgn8pTYndSrGElnh6L/IHmuHeub1W8u+Lo+dY= -github.com/standards-lab/sqlate v0.6.1 h1:Kgp8freMX9Gs2KweBwG4IPzENgUmSJq8+r4tq02cDNw= -github.com/standards-lab/sqlate v0.6.1/go.mod h1:pikNmGf/z3x46SBWFXgt/xKIDZuquSgCoXy5OWBFFR4= +github.com/standards-lab/sqlate v0.7.0 h1:GVb3OCDXwSS9RCxQ2BRIfV73zwBeJBhkvDLBJnTYd/U= +github.com/standards-lab/sqlate v0.7.0/go.mod h1:pikNmGf/z3x46SBWFXgt/xKIDZuquSgCoXy5OWBFFR4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= diff --git a/sweep/sweep.go b/sweep/sweep.go index ed401b3..4608085 100644 --- a/sweep/sweep.go +++ b/sweep/sweep.go @@ -158,12 +158,13 @@ type Sweeper struct { // New builds a Sweeper over db from the reclaimers in regs, logging to // logger. shutdown is the process's drain timeout: the reactor cancels a -// pass still running at half of it ([reactor.CancelWithin]). New refuses, -// with an error and before any I/O, an empty list; a registration with an -// empty name, a name another uses, a nil reclaimer, or a non-positive -// interval or budget; a non-positive shutdown; and a dialect without -// sqlate.TryLocker, as [ErrNoTryLocker], unless [Unlocked]. A nil db or -// logger is a wiring defect and panics. +// pass still running at half of it ([reactor.Options.CancelAfter], set +// by [reactor.CancelWithin]). New refuses, with an error and before any +// I/O, an empty list; a registration with an empty name, a name another +// uses, a nil reclaimer, or a non-positive interval or budget; a +// non-positive shutdown; and a dialect without sqlate.TryLocker, as +// [ErrNoTryLocker], unless [Unlocked]. A nil db or logger is a wiring +// defect and panics. // // Every reclaimer is due at start: New nudges the source, which delivers // as soon as the reactor starts. @@ -220,7 +221,7 @@ func New(db *sqlate.DB, regs []Registration, shutdown time.Duration, logger *slo } s.wake = reactor.Wake(s.tick) s.wake.Nudge() - s.r = reactor.New(s.wake, s.handle, reactor.CancelWithin(shutdown)) + s.r = reactor.New(s.wake, s.handle, reactor.Options{CancelAfter: reactor.CancelWithin(shutdown)}) return s, nil } From a62e256e8c1a9554139c997844ad6af3e80608bf Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 11 Nov 2026 14:17:39 -0500 Subject: [PATCH 2/4] libraries: sweep.New takes sweep.Options sweep.New(db, regs, shutdown, logger, opts Options) replaces the functional options. Options{Unlocked bool; Gate Gate; OnPass Hook}; the zero value keeps the defaults: claim each reclaimer's lock, refuse a dialect without TryLocker as ErrNoTryLocker, hold no gate, and log failed passes at warn. A nil Gate or OnPass means the default, as a nil argument to Gated or OnPass did. The Option type and the Unlocked, Gated, and OnPass functions are removed with no aliases. The Sweeper keeps the Options value it was given, filling OnPass with the warn-logging hook when nil. The reactor still cancels at reactor.CancelWithin(shutdown). Only sweep's own tests called New in this repository; they move to the new form. README, guides, and CHANGELOG are left to the next slice. --- sweep/doc.go | 15 ++++---- sweep/sweep.go | 88 ++++++++++++++++++--------------------------- sweep/sweep_test.go | 66 +++++++++++++++++----------------- 3 files changed, 76 insertions(+), 93 deletions(-) diff --git a/sweep/doc.go b/sweep/doc.go index bf460c7..0eeed9b 100644 --- a/sweep/doc.go +++ b/sweep/doc.go @@ -15,16 +15,17 @@ // non-positive interval or budget, and a non-positive shutdown timeout, // before any I/O. // -// An [Option] configures the rest: +// Its trailing [Options] configures the rest; the zero Options keeps the +// defaults: // -// - [Unlocked] runs without claiming the reclaimers' locks, on a dialect -// without sqlate.TryLocker or with it. Without it, such a dialect is -// [ErrNoTryLocker]. -// - [Gated] sets the [Gate] each pass holds shared, such as go-core's +// - [Options.Unlocked] runs without claiming the reclaimers' locks, on a +// dialect without sqlate.TryLocker or with it. Without it, such a +// dialect is [ErrNoTryLocker]. +// - [Options.Gate] is the [Gate] each pass holds shared, such as go-core's // reactor.Gate, so an operation that holds it exclusively, such as a // schema change, runs with the passes paused. -// - [OnPass] sets the [Hook] each [Pass] is reported to. Without it, a -// pass that returned an error is logged at warn on the sweeper's +// - [Options.OnPass] is the [Hook] each [Pass] is reported to. Without +// it, a pass that returned an error is logged at warn on the sweeper's // logger, and no other pass is. // // # Cycles diff --git a/sweep/sweep.go b/sweep/sweep.go index 4608085..4c9d7d8 100644 --- a/sweep/sweep.go +++ b/sweep/sweep.go @@ -49,7 +49,7 @@ type Registration struct { // ErrNoTryLocker reports a dialect without the sqlate.TryLocker capability, // which a Sweeper needs to claim each reclaimer's lock without waiting; -// [Unlocked] opts out. +// [Options.Unlocked] opts out. var ErrNoTryLocker = errors.New("sweep: dialect has no try-lock capability") // Gate is a quiesce gate each pass holds shared, so an operation that holds @@ -68,7 +68,7 @@ type Pass struct { Name string // More is what the pass reported: whether more may remain. More bool - // Err is the pass's error, or, under [Gated], the gate's failure other + // Err is the pass's error, or, under [Options.Gate], the gate's failure other // than its wait ending, in which case no pass ran. Err error // Duration is how long the pass took, its wait on the gate included. @@ -79,46 +79,27 @@ type Pass struct { // block for long: the sweeper waits on it before the next pass. type Hook func(ctx context.Context, p Pass) -// Option configures a [Sweeper]. -type Option func(*options) - -type options struct { - unlocked bool - gate Gate - hook Hook -} - -// Unlocked lets the sweeper run on a dialect without the sqlate.TryLocker -// capability, or with it, without claiming the locks. Its intended shape is -// a single process, or a consumer that serializes the sweep across -// processes some other way; concurrent sweepers without one each run every -// reclaimer, which their idempotent passes tolerate but no budget bounds. -func Unlocked() Option { - return func(o *options) { o.unlocked = true } -} - -// Gated sets the gate each pass holds shared, from before the pass begins -// until it returns. Without it, or with a nil gate, passes hold none. A -// wait on g that the reactor's drain or the handler's context ends runs no -// pass and reports nothing. Any other failure of g is reported as the -// pass's error, with no pass run, and ends the cycle. -func Gated(g Gate) Option { - return func(o *options) { - if g != nil { - o.gate = g - } - } -} - -// OnPass sets the hook each [Pass] is reported to. Without it, or with a -// nil hook, the sweeper logs each pass that returned an error at warn on -// its logger and nothing else. -func OnPass(h Hook) Option { - return func(o *options) { - if h != nil { - o.hook = h - } - } +// Options configures a [Sweeper]; its zero value claims each reclaimer's +// lock, holds no gate, and logs each failed pass at warn. +type Options struct { + // Unlocked runs the sweeper without claiming the reclaimers' locks, on a + // dialect without the sqlate.TryLocker capability or with it. Its + // intended shape is a single process, or a consumer that serializes the + // sweep across processes some other way; concurrent sweepers without + // one each run every reclaimer, which their idempotent passes tolerate + // but no budget bounds. Without it, a dialect without the capability is + // [ErrNoTryLocker]. + Unlocked bool + // Gate, when non-nil, is held shared by each pass, from before the pass + // begins until it returns; when nil, passes hold none. A wait on it that + // the reactor's drain or the handler's context ends runs no pass and + // reports nothing. Any other failure of it is reported as the pass's + // error, with no pass run, and ends the cycle. + Gate Gate + // OnPass, when non-nil, receives each [Pass]. When nil, the sweeper logs + // each pass that returned an error at warn on its logger and nothing + // else. + OnPass Hook } // Sweeper runs a fixed list of reclaimers as one go-core reactor. Each @@ -143,7 +124,7 @@ type Sweeper struct { regs []Registration names map[string]bool tick time.Duration - opts options + opts Options logger *slog.Logger wake *reactor.Waker r *reactor.Reactor[time.Time] @@ -163,12 +144,13 @@ type Sweeper struct { // I/O, an empty list; a registration with an empty name, a name another // uses, a nil reclaimer, or a non-positive interval or budget; a // non-positive shutdown; and a dialect without sqlate.TryLocker, as -// [ErrNoTryLocker], unless [Unlocked]. A nil db or logger is a wiring -// defect and panics. +// [ErrNoTryLocker], unless opts is [Options.Unlocked]. The zero opts keeps +// the defaults; see [Options]. A nil db or logger is a wiring defect and +// panics. // // Every reclaimer is due at start: New nudges the source, which delivers // as soon as the reactor starts. -func New(db *sqlate.DB, regs []Registration, shutdown time.Duration, logger *slog.Logger, opts ...Option) (*Sweeper, error) { +func New(db *sqlate.DB, regs []Registration, shutdown time.Duration, logger *slog.Logger, opts Options) (*Sweeper, error) { if db == nil { panic("sweep: nil db") } @@ -185,14 +167,14 @@ func New(db *sqlate.DB, regs []Registration, shutdown time.Duration, logger *slo db: db, regs: append([]Registration(nil), regs...), names: make(map[string]bool, len(regs)), + opts: opts, logger: logger, now: time.Now, last: make(map[string]time.Time, len(regs)), nudged: make(map[string]bool, len(regs)), } - s.opts.hook = logPasses(logger) - for _, opt := range opts { - opt(&s.opts) + if s.opts.OnPass == nil { + s.opts.OnPass = logPasses(logger) } for _, reg := range s.regs { switch { @@ -212,7 +194,7 @@ func New(db *sqlate.DB, regs []Registration, shutdown time.Duration, logger *slo s.tick = reg.Policy.Interval } } - if !s.opts.unlocked { + if !s.opts.Unlocked { locker, ok := db.Dialect().(sqlate.TryLocker) if !ok { return nil, ErrNoTryLocker @@ -338,7 +320,7 @@ func (s *Sweeper) cycle(ctx context.Context, drain <-chan struct{}, reg Registra if !ran { return nil } - s.opts.hook(ctx, p) + s.opts.OnPass(ctx, p) // more alone decides: a failed pass that reports more is followed // by another, since a reclaimer's passes are idempotent. A gate // failure ran no pass, so it reports no more and ends the cycle. @@ -403,7 +385,7 @@ func (s *Sweeper) claimFailed(ctx context.Context, name string, err error) error func (s *Sweeper) pass(ctx context.Context, drain <-chan struct{}, reg Registration) (p Pass, ran bool) { p.Name = reg.Name start := time.Now() - if s.opts.gate != nil { + if s.opts.Gate != nil { release, ended, err := s.share(ctx, drain) if ended { return p, false @@ -433,7 +415,7 @@ func (s *Sweeper) share(ctx context.Context, drain <-chan struct{}) (release fun } }() } - release, err = s.opts.gate.Shared(wait) + release, err = s.opts.Gate.Shared(wait) if err != nil { if wait.Err() != nil && errors.Is(err, wait.Err()) { return nil, true, nil diff --git a/sweep/sweep_test.go b/sweep/sweep_test.go index 7e4681e..c6684fb 100644 --- a/sweep/sweep_test.go +++ b/sweep/sweep_test.go @@ -125,11 +125,11 @@ func reg(name string, r sweep.Reclaimer, interval time.Duration, budget int) swe return sweep.Registration{Name: name, Reclaimer: r, Policy: sweep.Policy{Interval: interval, Budget: budget}} } -func newFixture(t *testing.T, dialect sqlate.Dialect, regs []sweep.Registration, shutdown time.Duration, opts ...sweep.Option) fixture { +func newFixture(t *testing.T, dialect sqlate.Dialect, regs []sweep.Registration, shutdown time.Duration, opts sweep.Options) fixture { t.Helper() pool, rec := sqltest.Open(t) l := &logs{} - s, err := sweep.New(sqlate.Wrap(pool, dialect), regs, shutdown, l.logger(), opts...) + s, err := sweep.New(sqlate.Wrap(pool, dialect), regs, shutdown, l.logger(), opts) if err != nil { t.Fatalf("New: %v", err) } @@ -191,7 +191,7 @@ func TestNew_RefusesBeforeAnyIO(t *testing.T) { dialect sqlate.Dialect regs []sweep.Registration shutdown time.Duration - opts []sweep.Option + opts sweep.Options want string is error }{ @@ -205,7 +205,7 @@ func TestNew_RefusesBeforeAnyIO(t *testing.T) { {name: "negative budget", regs: []sweep.Registration{reg("a", r, time.Minute, -1)}, want: "budget must be positive"}, {name: "zero shutdown", regs: []sweep.Registration{reg("a", r, time.Minute, 1)}, shutdown: -1, want: "shutdown must be positive"}, {name: "no try-lock", dialect: sqltest.Dialect{}, regs: []sweep.Registration{reg("a", r, time.Minute, 1)}, is: sweep.ErrNoTryLocker}, - {name: "no try-lock, gated", dialect: sqltest.Dialect{}, regs: []sweep.Registration{reg("a", r, time.Minute, 1)}, opts: []sweep.Option{sweep.Gated(&reactor.Gate{})}, is: sweep.ErrNoTryLocker}, + {name: "no try-lock, gated", dialect: sqltest.Dialect{}, regs: []sweep.Registration{reg("a", r, time.Minute, 1)}, opts: sweep.Options{Gate: &reactor.Gate{}}, is: sweep.ErrNoTryLocker}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { @@ -220,7 +220,7 @@ func TestNew_RefusesBeforeAnyIO(t *testing.T) { } else if shutdown < 0 { shutdown = 0 } - s, err := sweep.New(sqlate.Wrap(pool, dialect), tc.regs, shutdown, slog.New(slog.DiscardHandler), tc.opts...) + s, err := sweep.New(sqlate.Wrap(pool, dialect), tc.regs, shutdown, slog.New(slog.DiscardHandler), tc.opts) if s != nil || err == nil { t.Fatalf("New = %v, %v; want a refusal", s, err) } @@ -238,7 +238,7 @@ func TestNew_RefusesBeforeAnyIO(t *testing.T) { } func TestNew_UnlockedAcceptsADialectWithoutTryLock(t *testing.T) { - f := newFixture(t, sqltest.Dialect{}, []sweep.Registration{reg("a", &reclaimer{}, time.Minute, 1)}, time.Second, sweep.Unlocked()) + f := newFixture(t, sqltest.Dialect{}, []sweep.Registration{reg("a", &reclaimer{}, time.Minute, 1)}, time.Second, sweep.Options{Unlocked: true}) if f.s == nil { t.Fatal("New returned no sweeper") } @@ -249,8 +249,8 @@ func TestNew_WiringDefectsPanic(t *testing.T) { db := sqlate.Wrap(pool, sqltest.LockingDialect{}) regs := []sweep.Registration{reg("a", &reclaimer{}, time.Minute, 1)} for name, call := range map[string]func(){ - "nil db": func() { _, _ = sweep.New(nil, regs, time.Second, slog.New(slog.DiscardHandler)) }, - "nil logger": func() { _, _ = sweep.New(db, regs, time.Second, nil) }, + "nil db": func() { _, _ = sweep.New(nil, regs, time.Second, slog.New(slog.DiscardHandler), sweep.Options{}) }, + "nil logger": func() { _, _ = sweep.New(db, regs, time.Second, nil, sweep.Options{}) }, } { t.Run(name, func(t *testing.T) { defer func() { @@ -274,7 +274,7 @@ func TestHandle_TicksAtTheSmallestInterval(t *testing.T) { reg("slow", slow, 5*time.Minute, 1), reg("fast", &reclaimer{}, time.Minute, 1), reg("rare", &reclaimer{}, time.Hour, 1), - }, time.Second, sweep.Unlocked()) + }, time.Second, sweep.Options{Unlocked: true}) handle := sweep.Handle(f.s) for _, at := range []time.Duration{0, 4*time.Minute + 29*time.Second, 4*time.Minute + 31*time.Second} { @@ -290,7 +290,7 @@ func TestHandle_TicksAtTheSmallestInterval(t *testing.T) { func TestHandle_ClaimsTheLockAndPassesAtTheBudget(t *testing.T) { var p passes r := &reclaimer{} - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 7)}, time.Second, sweep.OnPass(p.hook)) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 7)}, time.Second, sweep.Options{OnPass: p.hook}) f.rec.Queue(claimed()...) if err := sweep.Handle(f.s)(context.Background(), t0); err != nil { @@ -312,7 +312,7 @@ func TestHandle_ClaimsTheLockAndPassesAtTheBudget(t *testing.T) { func TestHandle_ALockHeldElsewhereRunsNoPassAndReportsNothing(t *testing.T) { var p passes r := &reclaimer{} - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, sweep.OnPass(p.hook)) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, sweep.Options{OnPass: p.hook}) f.rec.Queue(flag(false)) if err := sweep.Handle(f.s)(context.Background(), t0); err != nil { @@ -330,7 +330,7 @@ func TestHandle_ALockHeldElsewhereRunsNoPassAndReportsNothing(t *testing.T) { func TestHandle_PassesWhileMoreUnderOneClaim(t *testing.T) { var p passes r := &reclaimer{results: []result{{more: true}, {more: true}, {more: false}}} - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 3)}, time.Second, sweep.OnPass(p.hook)) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 3)}, time.Second, sweep.Options{OnPass: p.hook}) f.rec.Queue(claimed()...) if err := sweep.Handle(f.s)(context.Background(), t0); err != nil { @@ -386,7 +386,7 @@ func TestHandle_ACycleYieldsAtItsIntervalAndStaysDue(t *testing.T) { // Each pass takes 20s of a 1m interval, so the cycle yields after the // third, still reporting more. r := endless("files", nil, c, 20*time.Second) - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, sweep.Options{}) sweep.SetClock(f.s, c.now) handle := sweep.Handle(f.s) @@ -420,7 +420,7 @@ func TestHandle_AYieldingCycleLetsTheReclaimersAfterItRun(t *testing.T) { f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{ reg("a", a, time.Minute, 1), reg("b", b, time.Minute, 1), - }, time.Second) + }, time.Second, sweep.Options{}) sweep.SetClock(f.s, c.now) f.rec.Queue(append(claimed(), claimed()...)...) @@ -442,7 +442,7 @@ func TestHandle_ACycleWhoseLastPassReportsNoMoreIsNotLeftDue(t *testing.T) { c.advance(2 * time.Minute) return nil }} - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, sweep.Options{}) sweep.SetClock(f.s, c.now) handle := sweep.Handle(f.s) @@ -463,7 +463,7 @@ func TestHandle_AFailedPassThatReportsMoreIsFollowedByAnother(t *testing.T) { boom := errors.New("boom") var p passes r := &reclaimer{results: []result{{more: true, err: boom}, {more: false}}} - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, sweep.OnPass(p.hook)) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, sweep.Options{OnPass: p.hook}) f.rec.Queue(claimed()...) if err := sweep.Handle(f.s)(context.Background(), t0); err != nil { @@ -483,7 +483,7 @@ func TestHandle_AFailedPassWithoutMoreEndsTheCycleAndTheNextIntervalRetries(t *t boom := errors.New("boom") var p passes r := &reclaimer{results: []result{{more: false, err: boom}, {more: true}, {more: false}}} - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, sweep.OnPass(p.hook)) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, sweep.Options{OnPass: p.hook}) f.rec.Queue(claimed()...) handle := sweep.Handle(f.s) @@ -514,7 +514,7 @@ func TestHandle_TheDefaultHookLogsOnlyAFailedPass(t *testing.T) { f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{ reg("ok", ok, time.Minute, 1), reg("bad", bad, time.Minute, 1), - }, time.Second) + }, time.Second, sweep.Options{}) f.rec.Queue(append(claimed(), claimed()...)...) if err := sweep.Handle(f.s)(context.Background(), t0); err != nil { @@ -535,7 +535,7 @@ func TestHandle_NudgeRunsOnlyTheNamedReclaimer(t *testing.T) { f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{ reg("a", a, time.Minute, 1), reg("b", b, time.Minute, 1), - }, time.Second) + }, time.Second, sweep.Options{}) handle := sweep.Handle(f.s) f.rec.Queue(append(claimed(), claimed()...)...) if err := handle(context.Background(), t0); err != nil { @@ -564,7 +564,7 @@ func TestHandle_NudgeRunsOnlyTheNamedReclaimer(t *testing.T) { } func TestNudge_AnUnregisteredNamePanics(t *testing.T) { - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("a", &reclaimer{}, time.Minute, 1)}, time.Second) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("a", &reclaimer{}, time.Minute, 1)}, time.Second, sweep.Options{}) defer func() { if recover() == nil { t.Error("Nudge of an unregistered name did not panic") @@ -580,7 +580,7 @@ func TestHandle_EachReclaimerRunsOnItsOwnInterval(t *testing.T) { f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{ reg("fast", fast, time.Minute, 1), reg("slow", slow, 3*time.Minute, 1), - }, time.Second, sweep.Unlocked()) + }, time.Second, sweep.Options{Unlocked: true}) handle := sweep.Handle(f.s) steps := []struct { @@ -613,7 +613,7 @@ func TestHandle_EachReclaimerRunsOnItsOwnInterval(t *testing.T) { func TestHandle_UnlockedTakesNoLock(t *testing.T) { r := &reclaimer{results: []result{{more: true}, {more: false}}} - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, sweep.Unlocked()) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, sweep.Options{Unlocked: true}) if err := sweep.Handle(f.s)(context.Background(), t0); err != nil { t.Fatalf("handle: %v", err) @@ -628,7 +628,7 @@ func TestHandle_UnlockedTakesNoLock(t *testing.T) { func TestHandle_AFailedClaimIsLoggedAndRetriedNextInterval(t *testing.T) { r := &reclaimer{} - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, sweep.Options{}) f.rec.Queue(sqltest.Response{Err: errors.New("lock table full")}) handle := sweep.Handle(f.s) @@ -652,7 +652,7 @@ func TestHandle_AFailedClaimIsLoggedAndRetriedNextInterval(t *testing.T) { } func TestHandle_AFailedReleaseIsLogged(t *testing.T) { - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", &reclaimer{}, time.Minute, 1)}, time.Second) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", &reclaimer{}, time.Minute, 1)}, time.Second, sweep.Options{}) f.rec.Queue(flag(true), flag(false)) if err := sweep.Handle(f.s)(context.Background(), t0); err != nil { @@ -678,7 +678,7 @@ func TestHandle_AnEndedContextReturnsItsErrorAndReleasesTheClaim(t *testing.T) { f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{ reg("files", r, time.Minute, 1), reg("next", next, time.Minute, 1), - }, time.Second, sweep.OnPass(p.hook)) + }, time.Second, sweep.Options{OnPass: p.hook}) f.rec.Queue(claimed()...) if err := sweep.Handle(f.s)(ctx, t0); !errors.Is(err, context.Canceled) { @@ -712,7 +712,7 @@ func TestHandle_EachPassHoldsTheGateShared(t *testing.T) { var order []string r := &reclaimer{name: "files", log: &order, results: []result{{more: true}, {more: false}}} f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, - sweep.Gated(gateLog{log: &order})) + sweep.Options{Gate: gateLog{log: &order}}) f.rec.Queue(claimed()...) if err := sweep.Handle(f.s)(context.Background(), t0); err != nil { @@ -728,7 +728,7 @@ func TestHandle_AGateFailureIsReportedAndRunsNoPass(t *testing.T) { var p passes r := &reclaimer{} f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, - sweep.Gated(gateLog{err: refused}), sweep.OnPass(p.hook)) + sweep.Options{Gate: gateLog{err: refused}, OnPass: p.hook}) f.rec.Queue(claimed()...) if err := sweep.Handle(f.s)(context.Background(), t0); err != nil { @@ -765,7 +765,7 @@ func TestHandle_AGateWaitItsContextEndsRunsNoPass(t *testing.T) { w := waiting{g: g, began: make(chan struct{}, 1)} r := &reclaimer{} f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Minute, 1)}, time.Second, - sweep.Gated(w), sweep.OnPass(p.hook)) + sweep.Options{Gate: w, OnPass: p.hook}) f.rec.Queue(claimed()...) ctx, cancel := context.WithCancel(context.Background()) @@ -790,7 +790,7 @@ func TestSweeper_EveryReclaimerIsDueAtStart(t *testing.T) { f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{ reg("a", mark("a"), time.Hour, 1), reg("b", mark("b"), time.Hour, 1), - }, time.Second, sweep.Unlocked()) + }, time.Second, sweep.Options{Unlocked: true}) if f.s.Ready() { t.Error("Ready before Start") } @@ -819,7 +819,7 @@ func TestSweeper_AYieldingCycleNudgesTheReactor(t *testing.T) { ran <- struct{}{} return nil }} - f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Hour, 1)}, time.Second) + f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Hour, 1)}, time.Second, sweep.Options{}) sweep.SetClock(f.s, c.now) f.rec.Queue(append(claimed(), claimed()...)...) if err := f.s.Start(context.Background()); err != nil { @@ -850,7 +850,7 @@ func TestSweeper_TheDrainStartsNoFurtherPassAndLetsTheOneInFlightFinish(t *testi f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{ reg("files", r, time.Hour, 1), reg("next", next, time.Hour, 1), - }, time.Hour) + }, time.Hour, sweep.Options{}) s = f.s f.rec.Queue(claimed()...) if err := f.s.Start(context.Background()); err != nil { @@ -879,7 +879,7 @@ func TestSweeper_TheDrainsCancellationIsTheReactorsError(t *testing.T) { }} // CancelWithin cancels the pass at half the shutdown timeout. f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Hour, 1)}, 20*time.Millisecond, - sweep.OnPass(p.hook)) + sweep.Options{OnPass: p.hook}) f.rec.Queue(claimed()...) if err := f.s.Start(context.Background()); err != nil { t.Fatal(err) @@ -906,7 +906,7 @@ func TestSweeper_TheDrainEndsAGateWaitWithNoPass(t *testing.T) { w := waiting{g: g, began: make(chan struct{}, 1)} r := &reclaimer{} f := newFixture(t, sqltest.LockingDialect{}, []sweep.Registration{reg("files", r, time.Hour, 1)}, time.Hour, - sweep.Gated(w), sweep.OnPass(p.hook)) + sweep.Options{Gate: w, OnPass: p.hook}) f.rec.Queue(claimed()...) if err := f.s.Start(context.Background()); err != nil { t.Fatal(err) From c836ce0e83d0bc28e2f92faef77f0dc93afbbbd8 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 11 Nov 2026 14:18:52 -0500 Subject: [PATCH 3/4] libraries: go-database docs, changelogs v0.12.0, standards pointer - READMEs, context/README.md and package docs already show only the sweep.Options form (sweep/doc.go moved in the previous slice); the one remaining sweep.Unlocked() mention is in the released v0.10.0 entry, left as history. - CHANGELOG.md v0.12.0 (2026-11-11), in go-core v0.12.0's and sqlate v0.7.0's format: a summary paragraph; Added sweep.Options; Changed sweep.New (Breaking) and the go-core v0.12.0 and sqlate v0.7.0 requirements (Breaking, naming the breaks they pull into an importer's build); Removed sweep.Option, Unlocked, Gated, OnPass (Breaking); and "Migrating from v0.11.0" with old->new sweep.New calls, pointing to go-core's and sqlate's own migration sections for their calls. - postgres/CHANGELOG.md v0.7.0: Breaking go-database v0.12.0 requirement, and the pgx v5.13.0 bump with its Rows.Values panic fix (GHSA-w9rp-vfrh-q8vv) and the database/sql retry-safety fix. postgres/go.mod's go-database requirement stays at v0.11.0 for release prep. - Compare links updated in both changelogs. - STANDARDS.md construction-and-execution pointer names sweep.New's trailing sweep.Options, in the form go-core's and sqlate's pointers use. --- CHANGELOG.md | 59 ++++++++++++++++++++++++++++++++++++++++++- STANDARDS.md | 2 +- postgres/CHANGELOG.md | 18 ++++++++++++- 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01c4158..9be4b42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,62 @@ only; the `postgres` sub-module keeps its own. ## [Unreleased] +## [v0.12.0] - 2026-11-11 + +The sweeper's configuration is a trailing Options struct, not variadic option functions: +`sweep.New` takes a `sweep.Options`, whose zero value keeps the defaults. The requirements move +to go-core v0.12.0 and sqlate v0.7.0, which make the same change to their own constructors and +transactions. + +### Added + +- `sweep.Options`, which configures a Sweeper. `Options.Unlocked` runs without claiming the + reclaimers' locks, `Options.Gate` is the gate each pass holds shared, and `Options.OnPass` is + the hook each `sweep.Pass` is reported to; a nil `Gate` or `OnPass` keeps its default, no gate + and a failed pass logged at warn. + +### Changed + +- **Breaking:** `sweep.New(db, regs, shutdown, logger, opts)` takes a trailing `sweep.Options` in + place of variadic `sweep.Option` values. A call with no option passes `sweep.Options{}`. +- **Breaking:** The `go-core` requirement is v0.12.0, which pulls its options break into an + importer's build: `reactor.New` takes a trailing `reactor.Options` and `event.NewRecorder` an + `event.Options` in place of variadic option values, `reactor.CancelWithin` returns a + `time.Duration` for `reactor.Options.CancelAfter`, and `reactor.Option`, `reactor.CancelAfter`, + `event.Option`, `event.Clock`, and `event.IDs` are removed. +- **Breaking:** The `sqlate` requirement is v0.7.0, which pulls its transaction-options break + into an importer's build: `DB.Begin`, `DB.Transact`, and `Transact` take a trailing + `*sql.TxOptions` in place of variadic `TxOption` values, nil for a default transaction; + `Beginner.Begin` has `DB.Begin`'s new signature; and `TxOption`, `Isolation`, and `ReadOnly` + are removed. + +### Removed + +- **Breaking:** `sweep.Option` and the `sweep.Unlocked`, `sweep.Gated`, and `sweep.OnPass` + option functions, with no aliases. Set `sweep.Options.Unlocked`, `sweep.Options.Gate`, and + `sweep.Options.OnPass`. + +### Migrating from v0.11.0 + +- **A sweeper's options become one `sweep.Options` value.** Leave `Gate` or `OnPass` nil for + its default. + + ```go + // v0.11.0 + s, err := sweep.New(db, regs, shutdown, logger) + s, err := sweep.New(db, regs, shutdown, logger, sweep.Unlocked()) + s, err := sweep.New(db, regs, shutdown, logger, sweep.Gated(gate), sweep.OnPass(hook)) + + // v0.12.0 + s, err := sweep.New(db, regs, shutdown, logger, sweep.Options{}) + s, err := sweep.New(db, regs, shutdown, logger, sweep.Options{Unlocked: true}) + s, err := sweep.New(db, regs, shutdown, logger, sweep.Options{Gate: gate, OnPass: hook}) + ``` + +- **go-core and sqlate calls follow their own changelogs.** go-core v0.12.0's and sqlate + v0.7.0's "Migrating" sections show the `reactor.New`, `event.NewRecorder`, `Begin`, and + `Transact` forms. + ## [v0.11.0] - 2026-11-11 ### Changed @@ -340,7 +396,8 @@ depends on the standard library and `github.com/standards-lab/go-core v0.1.0`. so an unknown field or trailing content in a curated seed file fails the decode. Idempotency stays in the load function's SQL, where the conflict target is known. -[Unreleased]: https://github.com/standards-lab/go-database/compare/v0.11.0...HEAD +[Unreleased]: https://github.com/standards-lab/go-database/compare/v0.12.0...HEAD +[v0.12.0]: https://github.com/standards-lab/go-database/compare/v0.11.0...v0.12.0 [v0.11.0]: https://github.com/standards-lab/go-database/compare/v0.10.0...v0.11.0 [v0.10.0]: https://github.com/standards-lab/go-database/compare/v0.9.0...v0.10.0 [v0.9.0]: https://github.com/standards-lab/go-database/compare/v0.8.0...v0.9.0 diff --git a/STANDARDS.md b/STANDARDS.md index ad876d9..d7be637 100644 --- a/STANDARDS.md +++ b/STANDARDS.md @@ -10,7 +10,7 @@ The judgement calls the standards-reviewer applies to go-database, beyond what ` - `architecture/standards/go-elemental/principles/lifecycle-and-context.md`: `DB`'s `Start`, `Shutdown` and `Ready`, and `admin.Service`'s `Start` and `Ready`; the constructors' panics on an unfinalized `Config` or a missing pool, and `postgres.New`'s error on a reserved option. - `architecture/standards/go-elemental/principles/baseline-standards.md`: `Config`'s pool-size and timeout defaults, and `admin`, which takes every migration set, seed set, catalog and registry from its consumer. - `architecture/standards/go-elemental/principles/utc-times.md`: `postgres.New`'s connections, which scan `timestamptz` in UTC. -- `architecture/standards/go-elemental/principles/construction-and-execution.md`: every new exported function and constructor in `database`, `admin`, `sweep` and `postgres`. +- `architecture/standards/go-elemental/principles/construction-and-execution.md`: `sweep.New` takes its configuration as a trailing `sweep.Options` whose zero value keeps the defaults, and every new exported function and constructor in `database`, `admin`, `sweep` and `postgres` that takes configuration does the same. - `architecture/principles/service-tiers.md`: `DB.Conn`, `Config.Options`, and the `postgres` provider. - `architecture/principles/validation-first.md`: `Config.Finalize`, and `admin`'s verbs, which refuse an argument outside their domain before any I/O. - `architecture/principles/context-architecture.md`: the README and each `doc.go` are the homes. diff --git a/postgres/CHANGELOG.md b/postgres/CHANGELOG.md index 933d719..f4566c5 100644 --- a/postgres/CHANGELOG.md +++ b/postgres/CHANGELOG.md @@ -7,6 +7,21 @@ changelog covers this sub-module only; the base module keeps its own. ## [Unreleased] +## [v0.7.0] - 2026-11-11 + +### Changed + +- **Breaking:** The `go-database` requirement is v0.12.0, which requires `go-core` v0.12.0 and + `sqlate` v0.7.0 and pulls their options break into an importer's build: `sweep.New`, + `reactor.New`, and `event.NewRecorder` take a trailing Options struct, and sqlate's `Begin` + and `Transact` a trailing `*sql.TxOptions`, in place of variadic option functions, which are + removed. +- The `pgx` requirement is v5.13.0, which fixes a panic in `Rows.Values` on a server response + with fewer row values than declared fields + ([GHSA-w9rp-vfrh-q8vv](https://github.com/jackc/pgx/security/advisories/GHSA-w9rp-vfrh-q8vv)), + and no longer marks a connection closed while receiving a response as safe to retry, so + `database/sql` does not repeat a statement that may already have executed. + ## [v0.6.0] - 2026-11-11 ### Changed @@ -104,7 +119,8 @@ The first release of the PostgreSQL provider, against `github.com/standards-lab/ classifying constraint violations arrives with the write path. `postgres.Provider` types the selection constant. -[Unreleased]: https://github.com/standards-lab/go-database/compare/postgres/v0.6.0...HEAD +[Unreleased]: https://github.com/standards-lab/go-database/compare/postgres/v0.7.0...HEAD +[v0.7.0]: https://github.com/standards-lab/go-database/compare/postgres/v0.6.0...postgres/v0.7.0 [v0.6.0]: https://github.com/standards-lab/go-database/compare/postgres/v0.5.0...postgres/v0.6.0 [v0.5.0]: https://github.com/standards-lab/go-database/compare/postgres/v0.4.0...postgres/v0.5.0 [v0.4.0]: https://github.com/standards-lab/go-database/compare/postgres/v0.3.0...postgres/v0.4.0 From ea8c5446f2bfa995703119e70fe5bc038f1c0f31 Mon Sep 17 00:00:00 2001 From: Jaime Still Date: Wed, 11 Nov 2026 14:20:36 -0500 Subject: [PATCH 4/4] libraries: standards review fixes Name sweep.New's unlocked case as opts setting Options.Unlocked (context-architecture: the doc comment is the contract's home). --- sweep/sweep.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sweep/sweep.go b/sweep/sweep.go index 4c9d7d8..160ca03 100644 --- a/sweep/sweep.go +++ b/sweep/sweep.go @@ -144,9 +144,9 @@ type Sweeper struct { // I/O, an empty list; a registration with an empty name, a name another // uses, a nil reclaimer, or a non-positive interval or budget; a // non-positive shutdown; and a dialect without sqlate.TryLocker, as -// [ErrNoTryLocker], unless opts is [Options.Unlocked]. The zero opts keeps -// the defaults; see [Options]. A nil db or logger is a wiring defect and -// panics. +// [ErrNoTryLocker], unless opts sets [Options.Unlocked]. The zero opts +// keeps the defaults; see [Options]. A nil db or logger is a wiring defect +// and panics. // // Every reclaimer is due at start: New nudges the source, which delivers // as soon as the reactor starts.