Schema validation library for sentry-options.
Schemas are loaded once into a [SchemaRegistry] and shared via Arc.
Values are validated against schemas as complete objects.
Refresh-on-read scheme
Values are held in a [ValuesStore] that wraps an [ArcSwap] for
lock-free reads. There is no background thread — every load() decides
whether the cached snapshot is stale and, if so, the calling thread
refreshes it.
Each load() does:
- Read
nowandlast_updated(anAtomicU64of nanoseconds since a monotonic baseline) withAcquire. - Compute a per-call jitter in
[0, 1s)from the address of a stack local — different threads have different stack bases, so the value differs across threads. Nothread_localis involved. - If
now - last_updated < threshold + jitter, return the current snapshot. Otherwise: a. Read all values files from disk and build the new map. b. On success, publish the new map into theArcSwap(last-writer-wins under contention). c.compare_exchangelast_updatedfrom the previously-observed value tonowwithAcqRel. The Release on the timestamp publishes the priorArcSwap::store: any reader that Acquire-loads the bumped timestamp and short-circuits the refresh is guaranteed to subsequently load the new snapshot. d. On a parse/validation failure, leave the old map in place — the bumped timestamp makes other threads back off until the next window.
Multiple threads racing through the stale window will redundantly read
files and publish; the last ArcSwap::store wins. The jitter spreads
the threshold boundary so that the herd doesn't cross it together. On
error the timestamp is still bumped so a broken values directory does
not turn into an I/O storm.