← Inside orch contents

Chapter 34 worked answers

These answers use baseline cbfc94ade5b57e449d6b73bf1485b1c5b1647022 and the chapter's linked execution records. Procedures remain scoped to disposable resources.

1. A local map is not distributed authority

Each LocalElector owns its own mutex/map. Two different instances can each see an empty map and acquire scheduler. The one-leader test shares one elector, so its exclusion claim is scoped to that shared instance. PostgreSQL coordination needs the same authoritative database session space and matching name; separate primaries can each permit an owner.

2. Loss ordering is observable

Run go test ./internal/leadership -count=1 -v in the disposable copy. The recorded run passed. The wrapper acquires, the callback closes started, the test waits for started, then Lose closes the lease channel. The wrapper cancels the child context, the cooperative callback returns context.Canceled, and the metric becomes false. Channels establish ordering without timing sleeps. A callback ignoring its context is outside this success argument.

3. Done is not SQL unlock

postgres.go90–92 calls close on cancellation; close105–109 closes Done and returns the connection to the pool. A live pooled PostgreSQL session can keep its advisory lock. Release67–71 sees Done closed and returns without pg_advisory_unlock. The actual full-schema record observed successor blockage after cancellation/release and acquisition only after the original pool closed. This is a package-level session cleanup finding, not proof of a production HA deployment. Repair must explicitly unlock or terminate the relevant session without returning a still-locked live connection to general reuse.

4. Reject the memory-replica shortcut

Independent MemoryService processes have divergent records and credentials. First implement durable transactional API/controller parity, persistent cluster identity, one verified database primary, and readiness tied to that authority. Then wire per-controller leases with bounded reacquisition, cooperative cancellation, explicit connection cleanup and idempotent effects. Test in-flight effects and database partitions separately. An API health response cannot prove shared state or that an old leader's external request stopped.

See the corresponding chapter claim ledger for exact immutable source anchors and limitations.

Return to Chapter 34.