store
ModuleWhere the scheduler's Claim lives: in process (MemoryStore) or
shared through Redis (RedisStore).
Contents
use utopia_schedule::Claim;pub struct ClaimThe scheduler's shared record: who leads, until when, how far coverage has been committed, and how much of the source had been read when it got there.
Leadership and coverage share one lifecycle (the leader advances both on every commit), so they share one record, and one compare-and-swap makes the commit fenced: a deposed leader's late write no longer matches the stored token and cannot rewind coverage.
Every moment is Unix seconds with microsecond precision, the unit
Clock works in.
use utopia_schedule::MemoryStore;pub struct MemoryStoreIn-process claim storage. Coverage and leadership survive ticks but not
restarts, and only schedulers sharing the store (through an Arc)
contend; use shared storage in production.
use utopia_schedule::{Claim, MemoryStore, Store};
let store = MemoryStore::new();
assert!(store.swap(None, &Claim::new("leader", 100.5, None, None)).await?);
assert!(!store.swap(None, &Claim::new("standby", 200.0, None, None)).await?);
assert_eq!(store.load().await?.unwrap().token, "leader");use utopia_schedule::RedisStore;pub struct RedisStore<C = ConnectionManager>Claim storage in Redis: one hash per scheduler, replaced through a Lua compare-and-swap so leadership and coverage move together or not at all.
The connection is a ConnectionManager by default, which reconnects
on the next command when the connection drops.
Debug.use utopia_schedule::Store;pub trait Store: Send + SyncWhere the Claim lives. Back it with shared storage (RedisStore,
or a database row) and replicas elect one dispatcher, a replacement
resumes coverage where its predecessor stopped, and a deposed leader's
late commit is rejected instead of rewinding the watermark.
Implementations must make Store::swap atomic: on Redis a Lua script,
on a database UPDATE … WHERE token = ?.