Avatar CS Knowledge Wiki

05 - Course Overview

We have 3 parts (weeks) for this tutorial. In the first week, we will focus on the storage structure and the storage format of an LSM storage engine. In the se…

Tutorial Structure#

图片

We have 3 parts (weeks) for this tutorial. In the first week, we will focus on the storage structure and the storage format of an LSM storage engine. In the second week, we will dive into compactions in depth and implement persistence support for the storage engine. In the third week, we will implement multi-version concurrency control.

To set up the environment, please take a look at Environment Setup ↗.

Overview of LSM#

An LSM storage engine generally contains 3 parts:

  • Write-ahead log to persist temporary data for recovery.
  • SSTs on the disk for maintaining a tree structure.
  • Mem-tables in memory for batching small writes.

The storage engine generally provides the following interfaces:

  • Put(key, value): store a key-value pair in the LSM tree.
  • Delete(key): remove a key and its corresponding value.
  • Get(key): get the value corresponding to a key.
  • Scan(range): get a range of key-value pairs.

To ensure persistence,

  • Sync(): ensure all the operations before sync are persisted to the disk.

Some engines choose to combine Put and Delete into a single operation called WriteBatch, which accepts a batch of key value pairs.

In this tutorial, we assume the LSM tree is using leveled compaction algorithm, which is commonly used in real-world systems.

Write Path#

图片

The write path of LSM contains 4 steps:

  • Write the key-value pair to write-ahead log, so that it can be recovered after the storage engine crashes.
  • Write the key-value pair to memtable. After (1) and (2) completes, we can notify the user that the write operation is completed.
  • When a memtable is full, we will freeze them into immutable memtables, and will flush them to the disk as SST files in the background.
  • We will compact some files in some level into lower levels to maintain a good shape for the LSM tree, so that read amplification is low.

Read Path#

图片

When we want to read a key,

  • We will first probe all the memtables from latest to oldest.
  • If the key is not found, we will then search the entire LSM tree containing SSTs to find the data.

There are two types of read: lookup and scan. Lookup finds one key in the LSM tree, while scan iterates all keys within a range in the storage engine. We will cover both of them throughout the tutorial.

Knowledge map

知识图谱

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

准备中 全局图谱

正在构建知识图谱...

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

帮助与支持

这篇文档有帮助吗?

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

帮助改进文档

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

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

需要更多帮助?

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

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

知识图谱

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

正在加载知识网络...

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