Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
qujihan committed Nov 9, 2024
1 parent 5f465af commit 9516cb2
Show file tree
Hide file tree
Showing 41 changed files with 2,624 additions and 81 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Generate PDF
on: push
jobs:
render_pdf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: typst-community/setup-typst@v3
- name: download typst-book-template
run: |
git submodule update --init --recursive
pip install requests
pip install tqdm
make font
make c
- uses: actions/upload-artifact@v4
id: artifact-upload-step
with:
name: from_zero_to_distributed_database.pdf
path: 从零开始的分布式数据库生活.pdf
- run: echo 'Artifact URL is ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.artifact-upload-step.outputs.artifact-id }}'
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
*.pdf
*.pdf
typst*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "typst-book-template"]
path = typst-book-template
url = https://github.com/qujihan/typst-book-template.git
[submodule "fonts"]
path = fonts
url = https://github.com/qujihan/fonts.git
54 changes: 44 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,58 @@
# 从零开始的数据库生活(toyDB走读笔记)
<div align="center">
<strong>
<samp>
</samp>
</strong>
</div>

> [toyDB](https://github.com/erikgrinaker/toydb) 仓库
# WIP. 从零开始的分布式数据库生活

[![Generate PDF](https://github.com/qujihan/toydb-book/actions/workflows/build.yml/badge.svg)](https://github.com/qujihan/toydb-book/actions/workflows/build.yml)
[![下载最新版本](https://img.shields.io/badge/%E7%82%B9%E8%BF%99%E9%87%8C-%E4%B8%8B%E8%BD%BDrelease%E7%89%88%E6%9C%AC-red.svg "下载最新版本")](https://nightly.link/qujihan/toydb-book/workflows/build/main/from_zero_to_distributed_database.pdf.zip)

# 编译本书
- python(以及tqdm模块)
- typst
- typstyle(格式化typ代码所需)

所需组件
- python(tqdm, requests)
- [typst](https://typst.app/)
- [typstyle]()

```shell
git clone https://github.com/qujihan/toydb-book.git

# 下载依赖
cd toydb-book && git submodule update --init --recursive

# 推荐安装 tqdm(只是为了下载界面好看一点)
# pip install tqdm
pip install requests # 下载字体使用
pip install tqdm # 为了下载界面好看一点

# 下载所需字体
python typst-book-template/fonts/download.py
# 与 python3 ./typst-book-template/fonts/download.py --proxy 相同
make font

# 编译
python typst-book-template/op.py c
```
# 与 python3 ./typst-book-template/op.py c 相同
make c
```

## TODO
正在把理解理成书中....
- 存储引擎
- [] Bitcask存储引擎
- [] MVCC
- 共识算法 Raft
- [] Message
- [] Node
- [] Log
- SQL引擎
- [] Type
- [] Engine
- [] Parse
- [] Planner
- [] Execution
- [] 编码


# 一些推广
- [typst](https://typst.app/): 全新的排版工具
- [typst-book-template](https://github.com/qujihan/typst-book-template): typst生成书籍的模板, 本书使用的模板(为了本书专门写的, 后来改造成了一个模板)
1 change: 1 addition & 0 deletions fonts
Submodule fonts added at 061b54
11 changes: 11 additions & 0 deletions fonts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"lora": [
"https://github.com/cyrealtype/Lora-Cyrillic/releases/download/v3.005/Lora-v3.005.zip"
],
"CaskaydiaCove Nerd Font": [
"https://github.com/ryanoasis/nerd-fonts/releases/download/v3.2.1/CascadiaCode.zip"
],
"Han-serif": [
"https://github.com/adobe-fonts/source-han-serif/releases/download/2.002R/09_SourceHanSerifSC.zip"
]
}
21 changes: 18 additions & 3 deletions main.typ
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
#import "typst-book-template/book.typ": *

#show: book.with(info: (
#set text(lang: "zh")
#show: book.with(info:(
title: "从零开始的分布式数据库生活 \n (From Zero to Distributed Database)",
name: "Quhaha",
title: "从零开始的数据库生活 \n (From Zero to Database)",
latin-font: ("Lora"),
cjk-font: ("Source Han Serif SC",),
code-font: ("CaskaydiaCove NF",),
))

#set heading(supplement: "")
#show ref: it => {
if it.element.func() == heading {
link(it.target, "" + it + "" + it.element.body)
} else {
link(it.target, it)
}
}

#include "src/chapter1.typ"
#include "src/chapter2.typ"
#include "src/chapter3.typ"
#include "src/chapter4.typ"
#include "src/chapter5.typ"
#include "src/chapter5.typ"
#include "src/chapter6.typ"
#include "src/chapter7.typ"
15 changes: 15 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
file_name := "从零开始的分布式数据库生活.pdf"

.PHONY: w c f font

w:
typst w main.typ ${file_name} --font-path ./fonts/

c:
typst c main.typ ${file_name} --font-path ./fonts/

f:
typstyle format-all ./

font:
python3 ./fonts/download.py --proxy
5 changes: 0 additions & 5 deletions metadata.json

This file was deleted.

8 changes: 6 additions & 2 deletions src/chapter1.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#import "../typst-book-template/book.typ": *
#let path-prefix = figure-root-path + "src/pics/"

= 前言
== 为什么选择toydb
== toydb的整体架构
== 为什么选择ToyDB
== ToyDB的整体架构

#pic(path-prefix + "architecture.svg", "ToyDB的整体架构")
57 changes: 8 additions & 49 deletions src/chapter2.typ
Original file line number Diff line number Diff line change
@@ -1,51 +1,10 @@
#import "../typst-book-template/book.typ": *
= 存储引擎

ToyDB使用一个可替换的key/value存储引擎, 通过storage_sql和storage_raft选项分别配置SQL和Raft存储引擎. 关于更高层的SQL存储引擎将在SQL部分单独讨论.

== 二进制编码

== Key/Value存储

一个存储引擎存储任意的key/value对作为二进制字节切片, 并实现`storage::Engine`这个trait.

#code(
"toydb/src/storage/engine.rs",
"strong::Engine",
```rust
/// A key/value storage engine, where both keys and values are arbitrary byte
/// strings between 0 B and 2 GB, stored in lexicographical key order. Writes
/// are only guaranteed durable after calling flush().
///
/// Only supports single-threaded use since all methods (including reads) take a
/// mutable reference -- serialized access can't be avoided anyway, since both
/// Raft execution and file access is serial.
pub trait Engine: std::fmt::Display + Send + Sync {
/// The iterator returned by scan(). Traits can't return "impl Trait", and
/// we don't want to use trait objects, so the type must be specified.
type ScanIterator<'a>: DoubleEndedIterator<Item = Result<(Vec<u8>, Vec<u8>)>> + 'a
where
Self: 'a;
/// Deletes a key, or does nothing if it does not exist.
fn delete(&mut self, key: &[u8]) -> Result<()>;
#let path-prefix = figure-root-path + "src/pics/"

/// Flushes any buffered data to the underlying storage medium.
fn flush(&mut self) -> Result<()>;
/// Gets a value for a key, if it exists.
fn get(&mut self, key: &[u8]) -> Result<Option<Vec<u8>>>;
/// Iterates over an ordered range of key/value pairs.
fn scan<R: std::ops::RangeBounds<Vec<u8>>>(&mut self, range: R) -> Self::ScanIterator<'_>;
/// Sets a value for a key, replacing the existing value if any.
fn set(&mut self, key: &[u8], value: Vec<u8>) -> Result<()>;
}
```
)


== MVCC事务

=== MVCC中的取舍
= 存储引擎
#include "chapter2/intro.typ"
#include "chapter2/engine.typ"
#include "chapter2/bitcask.typ"
#include "chapter2/memory.typ"
#include "chapter2/mvcc.typ"
#include "chapter2/summary.typ"
Loading

0 comments on commit 9516cb2

Please sign in to comment.