jiacai2050 commented on code in PR #140:
URL: https://github.com/apache/horaedb-docs/pull/140#discussion_r1805747252
##########
content/cn/docs/design/wal_on_disk.md:
##########
@@ -0,0 +1,142 @@
+---
+title: "基于本地磁盘的 WAL"
+---
+
+## 架构
+
+本节将介绍基于本地磁盘的单机版 WAL(Write-Ahead Log,以下简称日志)的实现。在此实现中,日志按 region 级别进行管理。
+
+```
+ ┌────────────────────────────┐
+ │ HoraeDB │
+ │ │
+ │ ┌────────────────────────┐ │
+ │ │ WAL │ │ ┌────────────────────────┐
+ │ │ │ │ │ │
+ │ │ ...... │ │ │ File System │
+ │ │ │ │ │ │
+ │ │ ┌────────────────────┐ │ │ manage │ ┌────────────────────┐ │
+ Write ─────┼─┼─► Region ├─┼─┼─────────┼─► Region Dir │ │
+ │ │ │ │ │ │ │ │ │ │
+ Read ─────┼─┼─► ┌────────────┐ │ │ │ mmap │ │ ┌────────────────┐ │ │
+ │ │ │ │ Segment 0 ├───┼─┼─┼─────────┼─┼─► Segment File 0 │ │ │
+ │ │ │ └────────────┘ │ │ │ │ │ └────────────────┘ │ │
+Delete ─────┼─┼─► ┌────────────┐ │ │ │ mmap │ │ ┌────────────────┐ │ │
+ │ │ │ │ Segment 1 ├───┼─┼─┼─────────┼─┼─► SegmenteFile 1 │ │ │
+ │ │ │ └────────────┘ │ │ │ │ │ └────────────────┘ │ │
+ │ │ │ ┌────────────┐ │ │ │ mmap │ │ ┌────────────────┐ │ │
+ │ │ │ │ Segment 2 ├───┼─┼─┼─────────┼─┼─► SegmenteFile 2 │ │ │
+ │ │ │ └────────────┘ │ │ │ │ │ └────────────────┘ │ │
+ │ │ │ ...... │ │ │ │ │ ...... │ │
+ │ │ └────────────────────┘ │ │ │ └────────────────────┘ │
+ │ │ ...... │ │ │ ...... │
+ │ └────────────────────────┘ │ └────────────────────────┘
+ └────────────────────────────┘
+```
+
+## 数据模型
+
+### 文件路径
+
+每个 region 都拥有一个目录,用于管理该 region 的所有 segment。目录名为 region 的 ID。每个 segment 的命名方式为
`segment_<id>.wal`,ID 从 0 开始递增。
+
+### Segment 的格式
+
+一个 region 中所有表的日志都存储在 segments 中,并按照 sequence number 从小到大排列。segment 文件的结构如下:
+
+```
+ Segment0 Segment1
+┌────────────┐ ┌────────────┐
+│ Magic Num │ │ Magic Num │
+├────────────┤ ├────────────┤
+│ Record │ │ Record │
+├────────────┤ ├────────────┤
+│ Record │ │ Record │
+├────────────┤ ├────────────┤ ....
+│ Record │ │ Record │
+├────────────┤ ├────────────┤
+│ ... │ │ ... │
+│ │ │ │
+└────────────┘ └────────────┘
+ segment_0.wal segment_1.wal
+```
+
+在内存中,每个 segment 还会存储一些额外的信息以供读写和删除操作使用:
+
+```
+pub struct Segment {
+ /// A hashmap storing both min and max sequence numbers of records within
+ /// this segment for each `TableId`.
+ table_ranges: HashMap<TableId, (SequenceNumber, SequenceNumber)>,
+
+ /// An optional vector of positions within the segment.
+ record_position: Vec<Position>,
+
+ ...
+}
+```
+
+### 日志格式
+
+segment 中的日志格式如下:
+
+```
++---------+--------+--------+------------+--------------+--------------+-------+
Review Comment:
When release 2.1.0, I find the `length` field is not required, so I remove
in it https://github.com/apache/horaedb/pull/1576, so you may need to update
here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]