Repository navigation
feat(engine)!: atomic increment, replace and multi-key get and delete on the store - #2969
Merged
Merged
Conversation
This was referenced Nov 9, 2026
…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
force-pushed
the
feature/store-increment-multi-key
branch
from
November 9, 2026 22:29
a509133 to
c245382
Compare
…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
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.
Description
StoreHandlernames rate-limit counters and idempotency records as its purpose, but cannot update state atomically. A caller must hold a TTL-boundedlockaroundgetandput, 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 addsdelta, 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, sogetstays consistent.get(List<String> keys, Consumer<List<String>> completion): values in key order,nullfor 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 equalsexpected; the completion receivestrueif replaced,falseif the key is absent or holds a different value.ttlapplies to the new value,nullmeans 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:
StoreHandlergains 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'stype: teststore handler. The test store honoursttlforincrementandreplace;putandputIfAbsentkeep their existing non-expiring behaviour.The
type: testbinding'sassertions.storecan now assert the new operations (incrementwithdelta,get/deletewithkeys,replacewithexpected, and numeric, list or booleanexpect), so a store implementation can be tested through a live engine.Tests:
MemoryStoreHandlerIT(memory store) andEngineIT(engine test store) drive increment (creation at zero, TTL on creation only, new value returned, decimal stored form, expiry), multi-key get (key order,nullfor absent or expired), multi-key delete (count of live keys removed) and replace (match, mismatch, absent, expired, null TTL, TTL applied and expiring) throughassertions.store, with schema validation in each spec'sSchemaTest.Fixes #2960
🤖 Generated with Claude Code
https://claude.ai/code/session_01SiHVoWeSyfpCijiv8RnjXE