Design an In-Memory Database With Transactions
Problem
Implement an in-memory key-value database supporting set(key, value), get(key), and delete(key), with records that can hold multiple fields, plus nested transactions via begin(), commit(), and rollback().
Requirements
set,get,deleteoperate on keys (and named fields within a record).begin()opens a transaction; transactions may be nested.rollback()discards changes made since the most recentbegin(), restoring the prior state.commit()permanently applies all currently open transactions' changes.
Areas to design
- How to snapshot or log changes so a nested
rollbackrestores exactly the right state. - Whether
commitfolds one level into its parent or flushes every open level. - Isolation: what
getsees while a transaction is open. - Edge cases: rollback/commit with no open transaction; deleting a key that was set in an outer transaction.
added …