Implement a simple key–value store that persists data on disk.
You must store the data in fixed-size shards, where each shard is saved in one file. If a shard file reaches its maximum size, new writes must go into a new shard file. The store must support shutdown (persist) and restore (recover).
You are given helper functions:
encode(key, value) -> bytes
to serialize a key/value record
decode(bytes) -> (key, value)
to deserialize a record
Assume keys and values are strings (or byte arrays), and encode/decode are inverses for valid records.
Design and implement (language-agnostic) functions/methods equivalent to:
put(key, value)
key
.
get(key) -> value | null
key
, or
null
/
None
if missing.
delete(key)
(optional if you want to support removals)
key
if it exists.
shutdown()
restore(directory_path)
(or constructor-based restore)
SHARD_SIZE_BYTES
.
put/get
and
restore
.