Skip to content

kvr 0.2.0

Latest

Choose a tag to compare

@github-actions github-actions released this 09 Nov 01:22
v0.2.0
9b4c0f9

Added

  • --version / -V flag on the kvr-server binary — prints kvr-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 matching v* it reruns CI (via workflow_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_entries is now chainable; a max_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_expired and 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 from main() 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).
  • TTL protocol command (opcode 0x09) — query remaining TTL for a key.
    Returns permanent/remaining-ms, or NOT_FOUND for missing/expired keys.
  • TtlInfo enum and ShardedKV::ttl() library method.
  • ShardedKV::len_active() method — O(n) count of non-expired entries.
  • --ping client mode in the kvr-server binary
    (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, SnapshotSaver trait) so the
    server and bench_wire can no longer diverge on protocol behavior.
  • CI: clippy --all-targets, MSRV check (Rust 1.70), cargo audit, Docker
    build + healthcheck verification, and a --release build.
  • rust-version = "1.70" MSRV declaration in Cargo.toml.

Changed

  • The server binary is renamed to kvr-server — the [[bin]] name in
    Cargo.toml changes from server to kvr-server (the source path
    src/bin/server.rs is unchanged); the Docker image now builds and copies
    kvr-server. The non-Unix error message now reads kvr-server requires Unix (UDS).
  • Per-value size limit — ShardedKV::with_max_value_bytes(n) (chainable
    builder, 0 = unlimited) rejects oversized values in set/set_with_ttl
    before touching the entry: a rejected overwrite preserves the existing
    value and TTL. load_entry (snapshot restore) bypasses the limit,
    mirroring the max_entries policy. Server env: KVR_MAX_VALUE_BYTES
    (default 1 MiB = no-op for wire traffic); an oversized SET/SETX returns
    0xFF ERROR, never 0x13 STORE_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 returns 0xFF. UDS SAVE unchanged. TCP_NODELAY set 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 via take(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 returns 0xFF and skips (does not purge) later keys.
    SCAN keeps only the limit smallest 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_expired uses
    HashMap::retain with 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 &str instead of
    per-request String allocations (GET/DEL/EXISTS/TTL/SCAN).
  • handle_client write 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-deps is warning-free.
  • Hot-path performance: set()/set_with_ttl() now use HashMap::entry
    (one lookup instead of two) and del() uses a single remove().
  • mget() no longer takes a write lock on plain misses — only expired
    entries trigger the write-lock removal path.
  • Correctness: an EntryReservation RAII 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
    enforce MAX_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/grep to the --ping client
    mode (the old approach was broken three ways: nc not installed, dash
    printf lacking \xHH, locale-dependent grep).
  • Snapshot durability: fsync errors are propagated, the .tmp file is written
    with 0600 permissions, 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::register API.
  • bench_wire now calls the shared protocol::dispatch instead of a divergent
    inline reimplementation.
  • SCAN purges expired entries during shard iteration, and
    collect_for_snapshot() filters expired entries at save time.
  • Simplified the ShardedKV::get shard read path (? operator instead of
    is_none()/unwrap()); updated crate-level rustdoc and scan()/
    sweep_expired()/len() docs for the new lazy-purge behavior.
  • len() documentation corrected to "approximate physical count" (the load
    was also changed from Acquire to Relaxed).

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.