我正在实现一个嵌入式键值存储,并希望在其中支持事务。这是我现在一直在研究的模型:
Basic operations supported :
- put(K,V)
- get(K)
- delete(K)
Steps for a put(K,V) :
- Log the K,V into a WAL and flush it to disk.
- Write the actual data on disk. [I do have buffering implemented but
we can ignore it for this question].
我读过的所有文献都谈到在日志记录中维护以下状态(在 WAL 中):
TxId, OldValue, NewValue
其中 OldValue 将用于 Undo,而 NewValue 用于 Redo。
我的问题是如何获得每个键 K 的 OldValue ?如果我需要搜索我的键值存储,即get(K)
每个put(K,V)
操作,那么这将非常低效,因为我将每次写入与通过存储搜索前一个值联系起来(因为它可能不存在于内存缓存中.)