feat(server-02): promote EventStore to global-sequence store with subscribeAll
StoredEvent gains sessionSequence: Long (per-session monotonic); existing sequence field becomes the global monotonic cursor across the entire store. SqliteEventStore allocates both counters inside the same BEGIN IMMEDIATE transaction and emits to a global MutableSharedFlow after commit. InMemoryEventStore mirrors this with an AtomicLong global counter and a suspend-on-overflow SharedFlow. EventStore interface gains subscribeAll() and lastGlobalSequence(). Contract tests updated and extended to cover global-sequence and cross-session subscribeAll invariants.
This commit is contained in:
@@ -12,5 +12,6 @@ data class NewEvent(
|
||||
data class StoredEvent(
|
||||
val metadata: EventMetadata,
|
||||
val sequence: Long,
|
||||
val sessionSequence: Long,
|
||||
val payload: EventPayload
|
||||
)
|
||||
|
||||
@@ -42,6 +42,10 @@ interface EventStore {
|
||||
*/
|
||||
fun subscribe(sessionId: SessionId): Flow<StoredEvent>
|
||||
|
||||
fun subscribeAll(): Flow<StoredEvent>
|
||||
|
||||
suspend fun lastGlobalSequence(): Long
|
||||
|
||||
/**
|
||||
* Iterate every event in the store across all sessions, in monotonic insertion order.
|
||||
* Intended for batch jobs (e.g. CAS liveness scans). Implementations should stream lazily.
|
||||
|
||||
Reference in New Issue
Block a user