persist: compaction — drop snapshotted prefix, monotonic seq + 11 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m0s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 1m0s
Backend now tracks last-seq as a monotonic high-water mark (survives truncation) and exposes :truncate-through. compaction.sx: persist/compact checkpoints then drops events with seq <= snapshot seq; should-compact?/ maybe-compact give an explicit every-N policy. Determinism: post-compaction replay value == uncompacted full replay. Phase 3 complete, 76/76. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
; persist/log — the log facet: append-only event streams. seq is assigned
|
||||
; sequentially per stream (1-based). Reads return events oldest-first.
|
||||
; persist/log — the log facet: append-only event streams. seq is assigned from
|
||||
; a monotonic per-stream high-water mark (1-based) held by the backend, so it
|
||||
; keeps climbing even after the log prefix is compacted away. Reads return the
|
||||
; events currently stored, oldest-first.
|
||||
; Requires: lib/persist/event.sx, lib/persist/backend.sx.
|
||||
|
||||
; current length of a stream
|
||||
; logical last seq assigned in a stream (0 if none) — survives compaction
|
||||
(define
|
||||
persist/stream-len
|
||||
(fn (b stream) (len (persist/backend-read b stream))))
|
||||
persist/last-seq
|
||||
(fn (b stream) (persist/backend-last-seq b stream)))
|
||||
|
||||
; last seq in a stream (0 if empty)
|
||||
(define persist/last-seq (fn (b stream) (persist/stream-len b stream)))
|
||||
; number of events physically stored in a stream (shrinks on compaction)
|
||||
(define
|
||||
persist/count
|
||||
(fn (b stream) (len (persist/backend-read b stream))))
|
||||
|
||||
; append an event, auto-assigning the next seq. Returns the stored event.
|
||||
(define
|
||||
@@ -21,7 +25,7 @@
|
||||
((ev (persist/event stream seq type at data)))
|
||||
(begin (persist/backend-append b stream ev) ev)))))
|
||||
|
||||
; read all events in a stream, oldest-first
|
||||
; read all events currently stored in a stream, oldest-first
|
||||
(define persist/read (fn (b stream) (persist/backend-read b stream)))
|
||||
|
||||
; read events with seq >= from
|
||||
@@ -33,5 +37,7 @@
|
||||
(fn (e) (>= (persist/event-seq e) from))
|
||||
(persist/read b stream))))
|
||||
|
||||
; number of events in a stream
|
||||
(define persist/count (fn (b stream) (persist/stream-len b stream)))
|
||||
; drop events with seq <= n (compaction); the seq counter is untouched
|
||||
(define
|
||||
persist/truncate
|
||||
(fn (b stream n) (persist/backend-truncate b stream n)))
|
||||
|
||||
Reference in New Issue
Block a user