Expand description
Deterministic generation clock.
Synthetic generation must be byte-identical across runs with the same
(config, seed). Many records stamp created_at / updated_at /
generated_at with wall-clock time, which breaks that guarantee. This
module provides a process-global deterministic epoch: while it is set,
now returns a fixed, seed-derived timestamp instead of the wall clock,
so every timestamp that routes through now becomes reproducible.
The epoch is stored in a global atomic (not a thread_local!, unlike
crate::serde_decimal) because generation fans out across worker threads
under parallel = true; a thread-local set on the main thread would not be
visible to those workers.
§Usage
The orchestrator wraps a generation run in a DeterministicClockGuard
built from the run’s seed; on drop the wall clock is restored. Outside a
guard, now is exactly Utc::now().
§Limitation
The epoch is process-global, so two generation runs executing concurrently in the same process would share it. CLI generation is sequential; callers that generate concurrently in-process (e.g. a server) should serialize the deterministic-clock scope or accept wall-clock timestamps.
Structs§
- Deterministic
Clock Guard - RAII guard: sets the deterministic epoch on construction and restores the wall clock on drop. Hold it for the lifetime of a generation run.
Functions§
- epoch_
from_ seed - Derive a deterministic epoch from a run seed and the config start date.
- is_
deterministic - Whether a deterministic epoch is currently active.
- next_
document_ id - A document id for a model constructor: a seeded sequential UUID when the
deterministic context is active, otherwise
Uuid::now_v7(). Use this in place ofUuid::now_v7()in generation model constructors. - now
- The current timestamp: the deterministic epoch if one is set, else the
real wall clock. Use this in generation code instead of
Utc::now(). - set_
deterministic_ epoch - Set (or clear) the process-global deterministic epoch.
- set_
deterministic_ uuids - Activate (or clear) the deterministic UUID fallback used by model
constructors.
Some(seed)resets the counter and makesnext_document_idreturn seeded sequential UUIDs;NonerestoresUuid::now_v7().