Rework session storage: overflow-driven idempotent segments - #27
Merged
Conversation
Demonstrate scoped state deltas, bin inspection, and concurrent append_event load.
Replace the hot-tail-on-session-record + sealed `c:` chunk model with
append-only K_ORDERED segment records (`app:user:session:g:NNNNNNNN`), each a
single `events` Map keyed `"{ts_micros:020d}:{event_id}"`. The key is a pure
function of the event, making append idempotent (a retried map_put overwrites
the same slot) and reads cheap (server-side last-N / after_timestamp via map
index/key ranges).
Rollover reacts to a real RecordTooBig (no client-side byte estimation): the
writer bumps `cur` with a `cur == N` guarded increment so concurrent rollovers
converge. The append hot path is 1 RTT — a no-state-delta append is one
operate; an append carrying state is one batch_write coalescing the segment
write with session/app/user state writes.
Because every hot-path write is now idempotent, add bounded jittered retry on
transient back-pressure: DeviceOverload always, ambiguous TimeoutError where a
re-apply is a no-op (including per-record DeviceOverload in the batch).
create_session retries DeviceOverload only (POLICY_EXISTS_CREATE put is not
timeout-idempotent).
Fixes heavy-concurrency data loss / unrecoverable RecordTooBig on a single hot
session. BREAKING on-disk layout (clean break, no migrator); bump to 0.1.0.
vkagamlyk
approved these changes
Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the hot-tail-on-session-record + sealed
c:chunk model with append-only K_ORDERED segment records (app:user:session:g:NNNNNNNN). Each segment holds oneeventsMap keyed"{ts_micros:020d}:{event_id}".map_putoverwrites the same slot — a timed-out-then-retried append can never duplicate an event.map_get_by_index_range(-N, N)andafter_timestampviamap_get_by_key_range.RecordTooBig; no client-side byte estimation/threshold/flush.curadvances with acur == Nguarded increment so concurrent rollovers converge on the same next index.operate; an append carrying state = onebatch_writecoalescing the segment write with session/app/user state writes (multi-scope appends now match single-scope latency).DeviceOverloadalways (rejected, never applied) and ambiguousTimeoutErrorwhere a re-apply is a no-op, including per-recordDeviceOverloadin the coalescedbatch_write.create_sessionretriesDeviceOverloadonly (POLICY_EXISTS_CREATEput is not timeout-idempotent).Fixes
RecordTooBigon a single hot session (events were dropped when concurrent appends overran the 1 MiB write-block-size).max-record-sizenow raises a clearRecordTooBiginstead of looping.Breaking
<= 0.0.2are not read by this version. Version bumped to 0.1.0.flush_threshold_bytes/huge_event_bytes/max_tail_bytesctor params,codec.estimate_event_size,keys.chunk_key, and thetbytes/chunks/seq/ts_lo/ts_hi/cidxbins.Also includes the previously-staged Atomic Session Append tutorial (updated for the segment model).
Test plan
pytest -m "not aerospike"→ 53 passedpytest tests/test_sessions.py→ 43 passedtests/test_session_retry.py→ 5 passed (overload retried/exhausted, timeout retried/opted-out, other errors propagate)batch_writecoalescing)