Avatar CS Knowledge Wiki

28 - Transaction and OCC

In this chapter, you will implement all interfaces of . Your implementation will maintain a private workspace for modifications inside a transaction, and commi…

In this chapter, you will implement all interfaces of Transaction. Your implementation will maintain a private workspace for modifications inside a transaction, and commit them in batch, so that all modifications within the transaction will only be visible to the transaction itself until commit. We only check for conflicts (i.e., serializable conflicts) when commit, and this is optimistic concurrency control.

Task 1: Local Workspace + Put and Delete#

You can now implement put and delete by inserting the corresponding key/value to the local_storage, which is a skiplist memtable without key timestamp. Note that for deletes, you will still need to implement it as inserting an empty value, instead of removing a value from the skiplist.

Task 2: Get and Scan#

For get, you should first probe the local storage. If a value is found, return the value or None depending on whether it is a deletion marker. For scan, you will need to implement a TxnLocalIterator for the skiplist as in chapter 1.1 when you implement the iterator for a memtable without key timestamp. You will need to store a TwoMergeIterator<TxnLocalIterator, FusedIterator<LsmIterator>> in the TxnLocalIterator. And, lastly, given that the TwoMergeIterator will retain the deletion markers in the child iterators, you will need to modify your TxnIterator implementation to correctly handle deletions.

Task 3: Commit#

We assume that a transaction will only be used on a single thread. Once your transaction enters the commit phase, you should set self.committed to true, so that users cannot do any other operations on the transaction. You put, delete, scan, and get implementation should error if the transaction is already committed.

Your commit implementation should simply collect all key-value pairs from the local storage and submit a write batch to the storage engine.

Test Your Understanding#

  • With all the things we have implemented up to this point, does the system satisfy snapshot isolation? If not, what else do we need to do to support snapshot isolation?
  • What if the user wants to batch import data (i.e., 1TB)? If they use the transaction API to do that, will you give them some advice? Is there any opportunity to optimize for this case?
  • What is optimistic concurrency control? What would the system be like if we implement pessimistic concurrency control instead in Mini-LSM?

Bonus Tasks#

  • Spill to Disk. If the private workspace of a transaction gets too large, you may flush some of the data to the disk.
Knowledge map

知识图谱

当前文档、同目录指南与引用关系。

准备中 全局图谱

正在构建知识图谱...

拖动节点 · 滚动缩放 · 点击打开

帮助与支持

这篇文档有帮助吗?

请给我们反馈以改进文档质量
(点击按钮后会打开邮箱)

帮助改进文档

所有文档均开源,发现问题或不清楚的地方?提交 PR 来帮助改进。

编辑此页面 了解如何贡献 →

需要更多帮助?

加入社区或直接联系获取支持

文件管理器 /
位置 /
内容
Knowledge explorer

知识图谱

全部知识 准备图谱...
文章 文档 标签 分类

正在加载知识网络...

拖动节点 · 滚动缩放 · 单击查看详情 · 双击打开页面
标签云 / Tag Cloud