recover

suspend fun recover()

Reload persisted metric state from store. Call once at startup before any calls to the mutating methods, so the readers see the persisted series from the start. A mutating call made first reads its kind itself before it writes, so skipping this never overwrites what is on disk. Idempotent: a second call re-reads the same bytes and joins them into memory, so a series memory already holds ahead of the store, an increment a refused write left there say, is kept.

If persisted state is corrupt or absent for a given kind, that kind starts fresh (a warning is logged). The other kinds are unaffected.

A refused read, a CancellationException the store mints at this live caller from its own withTimeout included, costs its kind alone and fails closed (#3390): a later call that would write that kind, record or a merge* method, reads it again first, or, inside the kind's backoff window below, refuses it without reading, and while the read is still refused or skipped admits nothing of that kind and writes nothing of it. A record returns a MetricExportResult.Partial listing those updates as uncounted, and a merge* a MetricWriteResult.Failure; either carries a MetricKindUnreadException for the kind. Updates of the other kinds in the same batch go ahead. The read that lands joins the persisted series into memory and that turn runs. Until then the readers see what memory already held of the kind: nothing, unless an earlier read of it in this process landed, in which case memory keeps that read's series and the refusal changes none of them. Starting fresh here instead wrote a map naming only this run's series over the persisted one: a durable sum of 5 read back as 1.

The re-reads back off per kind, counted in the kind's own turns: after k refused reads of a kind in a row, the next 2^k − 1 turns that touch the kind, k capped at 6 so at most 63, refuse it as a refused read does, without touching the store (#3436). A turn that does not touch the kind spends nothing of its window. A batch refused for an overflow spends one as well, since it would have read the kind; it still counts no turn on health. A refused histograms read backs off the histograms alone. A long outage of a kind then costs one store read per 64 of its turns rather than one per turn, each paying the store's timeout. This call is an explicit request, so it always reads every kind, window or not; a read of a kind that lands, here or in a turn, closes that kind's window and resets its k, and one refused here counts toward k like any other.

Serialized with every write turn by the same mutex, so it may run concurrently with them. A cancellation of the caller's own job still propagates (#3388).