// ----------------------------------------------------------------------------- // IHybridLogicalClock.cs // Sprint: SPRINT_20260105_002_001_LB_hlc_core_library // Task: HLC-003 - Define HLC interface // ----------------------------------------------------------------------------- namespace StellaOps.HybridLogicalClock; /// /// Hybrid Logical Clock for monotonic timestamp generation across distributed nodes. /// /// /// HLC combines physical (wall-clock) time with logical counters to provide: /// - Monotonic timestamps even under clock skew /// - Causal ordering guarantees across distributed nodes /// - Deterministic tie-breaking for concurrent events /// public interface IHybridLogicalClock { /// /// Generate next timestamp for local event. /// /// /// This should be called for every event that needs ordering: /// - Job enqueue /// - State transitions /// - Audit log entries /// /// New monotonically increasing HLC timestamp HlcTimestamp Tick(); /// /// Update clock on receiving remote timestamp, return merged result. /// /// /// Called when receiving a message from another node to ensure /// causal ordering is maintained across the distributed system. /// /// Timestamp from remote node /// New timestamp that is greater than both local clock and remote timestamp /// If clock skew exceeds configured threshold HlcTimestamp Receive(HlcTimestamp remote); /// /// Current clock state (for persistence/recovery). /// HlcTimestamp Current { get; } /// /// Node identifier for this clock instance. /// string NodeId { get; } } /// /// Persistent storage for HLC state (survives restarts). /// /// /// Implementations should ensure atomic updates to prevent state loss /// during concurrent access or node failures. /// public interface IHlcStateStore { /// /// Load last persisted HLC state for node. /// /// Node identifier to load state for /// Cancellation token /// Last persisted timestamp, or null if no state exists Task LoadAsync(string nodeId, CancellationToken ct = default); /// /// Persist HLC state. /// /// /// Called after each tick to ensure state survives restarts. /// Implementations may batch or debounce writes for performance. /// /// Current timestamp to persist /// Cancellation token Task SaveAsync(HlcTimestamp timestamp, CancellationToken ct = default); }