A cluster id is an address - one octet of the subnet, one byte of the MAC - so it is bounded at 254 and has to be recycled. Until now it was recycled by me, by reading the running clusters and typing the next free number into a tfvars. That works exactly as long as one person does it at a time. The store hands them out instead. Choosing a free address and claiming it are a single statement, so there is no window between the two, and an advisory lock keeps concurrent allocators from wasting attempts on the same number. Neither of those is the guarantee: the partial unique index is, and it also covers a writer that never took the lock. Tested against a real PostgreSQL, because everything worth testing here is the database's behaviour. Twenty simultaneous callers get twenty different addresses. A deliberately naive allocator, turned loose at the same width, had 17 of its 20 inserts rejected by the index and still could not seat two live clusters at one address - which is what says the passing case above passed for a reason and not by luck. The tests found one thing: a lease of zero meant "no expiry", but nothing said so, and there was no way to attach an expiry afterwards. Both fixed - SetLease is how a lease gets extended anyway. Each test builds the schema in a scratch schema and drops it, and aborts if current_schema() is not that one, so this runs against the production database without touching it. Verified afterwards: no scratch schemas left, both real tables untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
20 lines
503 B
AMPL
20 lines
503 B
AMPL
module github.com/ilkermanap/hpcod
|
|
|
|
go 1.25.0
|
|
|
|
require (
|
|
github.com/jackc/pgx/v5 v5.11.0
|
|
golang.org/x/crypto v0.55.0
|
|
gopkg.in/yaml.v3 v3.0.1
|
|
)
|
|
|
|
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.2 // indirect
|
|
github.com/kr/text v0.2.0 // indirect
|
|
github.com/rogpeppe/go-internal v1.16.0 // indirect
|
|
golang.org/x/sync v0.22.0 // indirect
|
|
golang.org/x/text v0.41.0 // indirect
|
|
)
|