Repository navigation
Releases
Releases · treeol/kvrust
kvr 0.2.0
Added
--version/-Vflag on thekvr-serverbinary — printskvr-server <version>to stdout and exits, for scripts and the install smoke test.- Tag-triggered release workflow (
.github/workflows/release.yml) — on a tag
push matchingv*it reruns CI (viaworkflow_call), builds three binaries
(kvr-server-x86_64-linux-gnu,kvr-server-aarch64-linux-gnu,
kvr-server-x86_64-linux-musl), smoke-tests each, and publishes
checksummed release assets. - Views into capacity/limit state and a chainable builder so limits compose
(with_max_entriesis now chainable; amax_value_bytes()getter lets the
wire layer distinguish size rejection from capacity). - Permit-before-accept connection admission — at the connection cap,
new connections wait in the kernel backlog instead of being accepted
and then blocked holding unread, uncounted sockets. - Bounded graceful-shutdown drain — in-flight client requests are drained
to a deadline before the shutdown snapshot is written, so the snapshot is
not lost to a stop-grace SIGKILL caused by unbounded client joins. Acceptors
are stopped and joined before draining; background threads (sweeper,
periodic snapshot) are joined before the final save. Best-effort: idle
clients blocked in reads cannot observe the flag and are detached; the
total shutdown (snapshot fsync, a detached SAVE holding the save mutex)
has no deadline. - Per-connection frame-read buffer reuse (
read_frame_into) with a 64 KiB
shrink floor — no per-request allocation, no per-connection 1 MiB pin. - Panic payloads from client handlers are downcast and logged with
connection context (never request contents); client-thread registry
with pruning. - Wire tests: TCP/SAVE dispatch matrix, shutdown in-flight completion and
exit-on-disconnect, drain-deadline detachment, snapshot size-bound
boundary, valid-CRC crafted-count rejection, read_frame_into reuse,
value-size response codes, MGET budget boundaries. - Explicit TTL read-time filtering contract (Contract A), now documented
in the library docs, README, and code comments: no key- or value-returning
operation ever serves an entry whose absolute expiry deadline (UNIX epoch
ms, inclusive at the deadline) is at or before the time sampled by that
operation — regardless of sweep timing or sweeper disablement. Snapshot
restore applies the same strict filter at the restore timestamp, so a key
that expires during downtime is never served after restart. kvr::is_expired_at(expires_at, now)— the single shared expiry predicate;
Entry::is_expiredand snapshot restore now both delegate to it.- Deterministic TTL tests using a
#[cfg(test)]-only thread-local clock
override (freeze_clock_at): boundary triple (before / exactly-at / after
the deadline) across every read path, overwrite/refresh semantics
(SETX recomputes the deadline, SET clears TTL, zero-TTL rejection is
non-mutating, expired-entry revival), sweep-independence, and clock-guard
mechanics — no sleeps, no sweeper dependency. restore_snapshot_at(store, entries, now)in the server: the restart-time
expiry filter is extracted frommain()and is now directly testable;
tests cover expired-during-downtime (skipping keys whose deadline is at or
before the sampled restore timestamp), inclusive boundary, deadline
preservation, and a hand-crafted KVR1 snapshot fixture with an
expired record (hand-crafted because save-time filtering would never
write one), plus a real-writer no-sleep variant (save a far-future
deadline, restore at a timestamp beyond it).TTLprotocol command (opcode0x09) — query remaining TTL for a key.
Returns permanent/remaining-ms, or NOT_FOUND for missing/expired keys.TtlInfoenum andShardedKV::ttl()library method.ShardedKV::len_active()method — O(n) count of non-expired entries.--pingclient mode in thekvr-serverbinary
(kvr-server --ping <socket>), used by the Docker HEALTHCHECK to replace
the broken nc/printf/grep chain.- Shared protocol module
src/protocol.rs(dispatch,read_frame,
write_frame, opcode/response constants,SnapshotSavertrait) so the
server andbench_wirecan no longer diverge on protocol behavior. - CI: clippy
--all-targets, MSRV check (Rust 1.70),cargo audit, Docker
build + healthcheck verification, and a--releasebuild. rust-version = "1.70"MSRV declaration inCargo.toml.
Changed
- The
serverbinary is renamed tokvr-server— the[[bin]]name in
Cargo.tomlchanges fromservertokvr-server(the source path
src/bin/server.rsis unchanged); the Docker image now builds and copies
kvr-server. The non-Unix error message now readskvr-server requires Unix (UDS). - Per-value size limit —
ShardedKV::with_max_value_bytes(n)(chainable
builder, 0 = unlimited) rejects oversized values inset/set_with_ttl
before touching the entry: a rejected overwrite preserves the existing
value and TTL.load_entry(snapshot restore) bypasses the limit,
mirroring themax_entriespolicy. Server env:KVR_MAX_VALUE_BYTES
(default 1 MiB = no-op for wire traffic); an oversized SET/SETX returns
0xFFERROR, never0x13STORE_FULL. - Connection read AND write timeouts —
KVR_READ_TIMEOUT_SECS/
KVR_WRITE_TIMEOUT_SECS(defaults 30s). A client that stops reading
can no longer pin a connection thread forever; timeouts of 0 refuse
startup. Stream configuration failures are logged instead of silently
ignored. - SAVE disabled over TCP — the unauthenticated debug listener can no
longer trigger snapshot saves (all-shard read locks + fsync); SAVE over
TCP returns0xFF. UDS SAVE unchanged.TCP_NODELAYset on accepted
TCP sockets. - Snapshot load size bound —
KVR_SNAPSHOT_MAX_BYTES(0 = unlimited
default): the file is opened once, size-checked on the handle (no
TOCTOU), and read viatake(max+1). Bounds loading, not saving. - Bounded-allocation MGET and SCAN — MGET parses and validates all
keys before touching the store, then assembles the response under a
1 MiB budget checked before each value is cloned (mget_capped);
exhaustion returns0xFFand skips (does not purge) later keys.
SCAN keeps only thelimitsmallest live matches per shard in a
max-heap (compared before cloning) with a saturating match counter —
allocation is O(limit) instead of O(all matches); traversal is still
O(n) (the purge pass requires full iteration).sweep_expireduses
HashMap::retainwith len-diff accounting (no key-clone Vec). - MGET response assembly no longer clones all requested values before
checking the 1 MiB limit (previously a 256-key MGET of near-1 MiB values
cloned ~256 MiB before rejecting); wire behavior (response bytes) is
unchanged for successful and rejected requests alike. - Keys parsed from wire frames are now borrowed
&strinstead of
per-requestStringallocations (GET/DEL/EXISTS/TTL/SCAN). handle_clientwrite errors are classified like read errors: timeouts,
resets, and closed pipes are quiet client lifecycle, not log noise.- The shutdown path acknowledges a documented best-effort criterion: a
client still mid-request at the drain deadline is detached and its last
unacked write may not reach the shutdown snapshot. - Snapshot format doc comments fixed (unclosed
<key>/<val>HTML tags);
cargo doc --no-depsis warning-free. - Hot-path performance:
set()/set_with_ttl()now useHashMap::entry
(one lookup instead of two) anddel()uses a singleremove(). mget()no longer takes a write lock on plain misses — only expired
entries trigger the write-lock removal path.- Correctness: an
EntryReservationRAII guard closes the panic window
between reserving an entry slot and inserting it; snapshot save now rejects
oversized keys/values instead of silently truncating them; GET responses
enforceMAX_FRAME_SIZE; protocol dispatch uses checked arithmetic against
overflow;now_ms()returns 0 instead of panicking on a pre-epoch clock. - Docker healthcheck switched from
nc/printf/grepto the--pingclient
mode (the old approach was broken three ways:ncnot installed, dash
printflacking\xHH, locale-dependentgrep). - Snapshot durability: fsync errors are propagated, the
.tmpfile is written
with0600permissions, and the parent directory is fsynced after rename. - Configuration is fail-fast: malformed
KVR_*values refuse startup instead
of silently falling back to defaults. - Signal handling uses the safe
signal_hook::flag::registerAPI. bench_wirenow calls the sharedprotocol::dispatchinstead of a divergent
inline reimplementation.SCANpurges expired entries during shard iteration, and
collect_for_snapshot()filters expired entries at save time.- Simplified the
ShardedKV::getshard read path (?operator instead of
is_none()/unwrap()); updated crate-level rustdoc andscan()/
sweep_expired()/len()docs for the new lazy-purge behavior. len()documentation corrected to "approximate physical count" (the load
was also changed fromAcquiretoRelaxed).
Binaries: kvr-server-x86_64-linux-gnu and kvr-server-aarch64-linux-gnu are dynamically linked against glibc 2.35+ (built on Ubuntu 22.04). kvr-server-x86_64-linux-musl is statically linked and runs in any rootfs. Every binary is started and answers a PING in CI. Verify with sha256sum --check --ignore-missing SHA256SUMS.