Created Cancelled
Start the standby on demand Stacked on #145. **Judge this one on the numbers, which are small.** ## What The standby was started whether or not anything read from it. `replicatedDBStandby` is an `IO Standby` now, started by the first test that asks for one and by nothing else, memoised behind an `MVar` so concurrent askers share one and it is stopped with the suite only if it was ever started. `postgresqlStandbySetupFunc`'s bracket became an `acquireStandby` acquire/release pair so that deferring it was possible at all. ## What it is worth Measured on top of #145, a suite subset of 74 tests that never touch a replica, three runs each: | | run 1 | run 2 | run 3 | |---|---|---|---| | lazy | 0.44s | 0.45s | 0.45s | | eager | 0.64s | 0.61s | 0.61s | **About 0.17s per process that never reads a replica.** Whole-suite runs show nothing at all, because a suite that reads its replica even once starts the standby anyway and laziness only defers the cost: worker-gen 5.7s eager vs 5.5s lazy, leader-gen 49–55s eager vs 50.6s lazy, all within noise. Under mutation testing, one process per mutant, 0.17s a mutant at 8-way parallelism is on the order of ten seconds across a check that runs for 136–1742s. ## Why it is a separate PR This started life bundled with #145 on the theory that it was the real fix and the flag was a detail. That was backwards. Before #145 a standby cost 13.5s to start and deferring it would have been worth having; after #145 it costs 0.17s and this buys an `MVar`, an acquire/release split, and a breaking API change for that. Splitting them so the flag can land on its own merits and this can be judged, or dropped, on its own. ## Breaking `replicatedDBStandby :: Standby` becomes `replicatedDBStandby :: IO Standby`, so `0.6.0.0`. Anything reaching into a `ReplicatedDB` for its standby runs the action instead. `postgresqlStandbySetupFunc` is unchanged. ## Tests `StandbySpec` asks the primary what is streaming from it, which is the one place the answer is not a matter of opinion: nothing until something asks, and the same standby however often it is asked for after that.