From e1c8baf112a0cfb5ac5bfaaab3e195c56e513690 Mon Sep 17 00:00:00 2001 From: Engineering Team Date: Tue, 7 Jul 2026 22:56:07 +0800 Subject: [PATCH] feat(kv): add Reader read-only seam interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reader { Get; Scan; ScanRange } names the read-only surface shared by Store and Snapshot, so a read path can be written against either the live Store or a consistent point-in-time Snapshot. Two compile-time assertions (var _ Reader = (Store)(nil) / (Snapshot)(nil)) prove both satisfy it — and would catch a regression that dropped a read method from either. Purely additive: Store/Snapshot/Batch/Snapshotter method sets are unchanged, so every existing implementer keeps satisfying them. No consumer yet — this only adds the seam; wiring the search read path onto a snapshot is a separate change. go1.24.2: core build green (the assertions are the check); gofmt clean. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- core/kv/kv.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/kv/kv.go b/core/kv/kv.go index f287c92..839daba 100644 --- a/core/kv/kv.go +++ b/core/kv/kv.go @@ -79,3 +79,21 @@ type Snapshot interface { // through the Snapshot after its Close are undefined; callers must not do that. Close() error } + +// Reader is the read-only surface shared by Store and Snapshot — the same +// Get/Scan/ScanRange methods. Their semantics (value handling on Get; the +// callback slice-validity and stop-on-false rules on Scan/ScanRange) are as +// documented on Store and Snapshot, which remain the canonical contract; this +// interface only names the shared subset so a read path can be written against +// either the live Store or a consistent point-in-time Snapshot. +type Reader interface { + Get(key []byte) ([]byte, error) + Scan(prefix []byte, cb func(key, value []byte) bool) error + ScanRange(begin, end []byte, cb func(key, value []byte) bool) error +} + +// Store and Snapshot both satisfy Reader (compile-time assertions). +var ( + _ Reader = (Store)(nil) + _ Reader = (Snapshot)(nil) +)