Implement a persistent key-value store that supports the following operations for string keys and string values:
-
put(key, value)
-
get(key)
-
delete(key)
Part 1
Keep data in memory during execution, but support persistence to disk with:
-
serialize()
to write the current state to a single file
-
deserialize()
to rebuild the store from that file after restart
You may choose any reasonable on-disk format, as long as the data can be written and loaded correctly.
Part 2
Now assume each file on disk has a maximum size limit. Extend the store so persistence is spread across multiple files:
-
when the current file reaches the size limit, continue writing to a new file
-
on startup, reconstruct the latest key-value state from all files
Follow-up
-
How would you handle concurrent readers and writers safely?
-
What changes would you make to avoid corruption during crashes?
-
Write a few basic test cases for normal operations and recovery from disk.