Add _ls
and _tree
Endpoints for Hierarchical Key Listing Using Merkle Tree
#7
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Add
_ls
and_tree
Endpoints for Hierarchical Key Listing Using Merkle TreeIs your feature request related to a problem? Please describe.
KVS supports hierarchical keys (e.g.,
/home/room/closet/socks
), which is great for organizing data like a file system. However, there's currently no built-in way for clients to discover or list subkeys under a given prefix/path. This makes it hard to build intuitive tools or UIs that need to navigate the keyspace, such as a web-based explorer or CLI client.For example:
/home/room/
(e.g.,closet
,bed
,door
).Without this, users must either:
Describe the solution you'd like
Add two new read-only endpoints that leverage the existing Merkle tree infrastructure for efficient prefix-based key listing. This aligns with KVS's modular design, eventual consistency model, and Merkle-based sync (no need for full DB scans—traverse the tree to identify relevant leaf nodes in O(log N) time).
Proposed Endpoints
Direct Children Listing (
_ls
or_list
):GET /kv/{path}/_ls
(orGET /kv/{path}/_list
for clarity).limit
: Max number of keys to return (default: 100, max: 1000).include_metadata
: If true, include basic metadata like timestamps (default: false).{path}
as a prefix (e.g.,/home/room/
→ keys starting with/home/room/
but not/home/room/sub/
).[prefix, prefix~]
(where~
is the next lexicographical prefix)._ts:*
).read
scope ifauth_enabled: true
).Recursive Tree View (
_tree
):GET /kv/{path}/_tree
.depth
: Max recursion depth (default: unlimited, but suggest 5 for safety).limit
: Max total keys (default: 500, max: 5000).include_metadata
: Include timestamps/UUIDs (default: false).format
:json
(default) ornested
(tree-like JSON)._ls
logic: Recursively query sub-prefixes via Merkle tree traversal.depth
orlimit
to avoid overload._ls
.Integration with Existing Systems
cluster/merkle.go
(e.g., addGetKeysInRange(startKey, endKey) []string
method) to traverse nodes covering the prefix range without fetching full values. ReusebuildMerkleTreeFromPairs
andfilterPairsByRange
fromhandlers.go
.KVRangeRequest
/KVRangeResponse
intypes.go
andgetKVRangeHandler
(strip values to return just keys for efficiency).authService.Middleware
(e.g.,read
scope). Respectallow_anonymous_read
.key_listing_enabled: true
totypes.Config
for optional disable (e.g., for security in public clusters).consistent: true
query param to force a quick Merkle refresh if needed.Example Usage
Additional context
cluster/merkle.go
: Extend for key-only range traversal.server/handlers.go
: Add handlers likegetKeyListHandler
andgetKeyTreeHandler
.server/routes.go
: Wire up routes under KV section.integration_test.sh
with prefix listing assertions.README.md
under REST API > Data Operations.