Skip to content

feat(engine)!: atomic increment, replace and multi-key get and delete on the store - #2969

Merged
jfallows merged 2 commits into
developfrom
feature/store-increment-multi-key
Nov 10, 2026
Merged

jfallows merged 2 commits into
developfrom
feature/store-increment-multi-key

Conversation

@jfallows

@jfallows jfallows commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

StoreHandler names rate-limit counters and idempotency records as its purpose, but cannot update state atomically. A caller must hold a TTL-bounded lock around get and put, which costs several round trips, contends under load, and loses an update if the lease lapses between the read and the write. Reading or removing several known keys takes one call per key.

This adds four operations to StoreHandler:

  • increment(String key, long delta, Duration ttl, BiConsumer<String, Long> completion): atomically adds delta, creating the key at zero if absent with the TTL applied on creation only. The completion receives the new value; the stored form is a decimal string, so get stays consistent.
  • get(List<String> keys, Consumer<List<String>> completion): values in key order, null for an absent key.
  • delete(List<String> keys, LongConsumer completion): best-effort and non-atomic across keys; the completion receives the count removed.
  • replace(String key, String expected, String value, Duration ttl, Consumer<Boolean> completion): atomically sets the key only if its current value equals expected; the completion receives true if replaced, false if the key is absent or holds a different value. ttl applies to the new value, null means no expiry.

None of them has a default implementation, so every store implements them natively with the semantics of its own backend. The async contract is unchanged: completion fires strictly later, on the caller's I/O thread.

Breaking change: StoreHandler gains four abstract methods, so every implementation, in this repository or outside it, must implement them. Release notes should call this out.

Implementations updated: the memory store (MemoryStoreHandler, native compare-and-set on its concurrent map, honouring expiry) and the engine's type: test store handler. The test store honours ttl for increment and replace; put and putIfAbsent keep their existing non-expiring behaviour.

The type: test binding's assertions.store can now assert the new operations (increment with delta, get/delete with keys, replace with expected, and numeric, list or boolean expect), so a store implementation can be tested through a live engine.

Tests: MemoryStoreHandlerIT (memory store) and EngineIT (engine test store) drive increment (creation at zero, TTL on creation only, new value returned, decimal stored form, expiry), multi-key get (key order, null for absent or expired), multi-key delete (count of live keys removed) and replace (match, mismatch, absent, expired, null TTL, TTL applied and expiring) through assertions.store, with schema validation in each spec's SchemaTest.

Fixes #2960

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoWeSyfpCijiv8RnjXE

…lete to StoreHandler

StoreHandler names rate-limit counters and idempotency records as its
purpose but cannot update state atomically: a caller must hold a
TTL-bounded lock around get and put, which costs several round trips,
contends under load and loses updates if the lease lapses. Reading or
removing several known keys takes one call per key.

Add increment, replace (conditional update), multi-key get and multi-key
delete. None has a default implementation, so every store implements
them natively. The memory store and the engine test store do so, with
TTL honoured on creation (increment) and on the new value (replace).

BREAKING CHANGE: StoreHandler gains four abstract methods; every
implementation must implement them.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoWeSyfpCijiv8RnjXE
@jfallows
jfallows force-pushed the feature/store-increment-multi-key branch from a509133 to c245382 Compare November 9, 2026 22:29
@jfallows jfallows changed the title feat(engine): atomic increment and multi-key get and delete on the store feat(engine)!: atomic increment, replace and multi-key get and delete on the store Nov 9, 2026
@jfallows
jfallows removed this pull request from stack #3028 November 9, 2026 22:30
@jfallows
jfallows changed the base branch from feature/classifier-locator to develop November 9, 2026 22:31
…from the test binding

The new StoreHandler operations had no way to be driven through a live
engine, so their contract could only be checked by unit tests that call a
handler directly. Extend assertions.store on the type: test binding to
cover them, and test the memory store and the engine test store through
it.

Assertion shapes:
- increment: key, delta, optional ttl, optional numeric expect
- get with keys: ordered expect list, null elements for absent keys
- delete with keys: numeric expect of keys removed
- replace: key, expected, value, optional ttl, boolean expect

The single-key and multi-key forms of get and delete are selected by the
presence of key or keys. The test store now honours ttl for increment and
replace; put and putIfAbsent keep their existing non-expiring behaviour.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SiHVoWeSyfpCijiv8RnjXE
@jfallows
jfallows merged commit 291279f into develop Nov 10, 2026
102 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(engine): atomic increment and multi-key get and delete on the store

2 participants