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
_lsand_treeEndpoints 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 (
_lsor_list):GET /kv/{path}/_ls(orGET /kv/{path}/_listfor 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:*).readscope 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)._lslogic: Recursively query sub-prefixes via Merkle tree traversal.depthorlimitto avoid overload._ls.Integration with Existing Systems
cluster/merkle.go(e.g., addGetKeysInRange(startKey, endKey) []stringmethod) to traverse nodes covering the prefix range without fetching full values. ReusebuildMerkleTreeFromPairsandfilterPairsByRangefromhandlers.go.KVRangeRequest/KVRangeResponseintypes.goandgetKVRangeHandler(strip values to return just keys for efficiency).authService.Middleware(e.g.,readscope). Respectallow_anonymous_read.key_listing_enabled: truetotypes.Configfor optional disable (e.g., for security in public clusters).consistent: truequery 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 likegetKeyListHandlerandgetKeyTreeHandler.server/routes.go: Wire up routes under KV section.integration_test.shwith prefix listing assertions.README.mdunder REST API > Data Operations.