Skip to content

Commit d6af871

Browse files
committed
docs: update getting started
1 parent 6f877a5 commit d6af871

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

.github/workflows/doc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
cd guide
2222
curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.28/mdbook-v0.4.28-x86_64-unknown-linux-gnu.tar.gz | tar xzf -
2323
echo $PWD >> $GITHUB_PATH
24+
cargo install mdbook-toc
2425
./mdbook build
2526
- name: Deploy
2627
uses: JamesIves/github-pages-deploy-action@v4

guide/src/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[Introduction](./introduction.md)
44

5-
- [Getting started](./start.md)
5+
- [Getting Started](./start.md)
66
- [Usage](./usage/index.md)
77
- [Tonbo](./usage/tonbo.md)
88
- [Python Binding](./usage/python.md)
@@ -18,5 +18,6 @@
1818
- [Building](./contribution/build.md)
1919
- [Testing](./contribution/testing.md)
2020
- [TonboLite](./tonbolite/index.md)
21+
- [Getting Started](./tonbolite/start.md)
2122
- [Building](./tonbolite/build.md)
2223
- [Usage](./tonbolite/usage.md)

guide/src/start.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,58 @@ while let Some(entry) = scan.next().await.transpose().unwrap() {
138138
}
139139
```
140140

141+
### Persistence
142+
As Tonbo uses LSM(Log-Structured-Merge Tree) as the underlying data structure, some data are in the memory(mem). If you want to persist these data, you can use the `flush` method.
143+
144+
If WAL is enabled, the data will be persisted to disk automatically. But as tonbo has buffer for WAL by default, you need to call `flush_wal` method if you want to ensure that all the data will be recovered. If you don not want to use buffer for WAL, you can disable it by setting `wal_buffer_size` to 0.
145+
146+
```rust
147+
let options = DbOption::new(
148+
Path::from_filesystem_path("./db_path/users").unwrap(),
149+
&UserSchema,
150+
).wal_buffer_size(0);
151+
```
152+
153+
If you don't want to use WAL, you can disable it by setting the `DbOption::disable_wal`. But please ensure that losing data is acceptable for you.
154+
```rust
155+
let options = DbOption::new(
156+
Path::from_filesystem_path("./db_path/users").unwrap(),
157+
&UserSchema,
158+
).disable_wal(true);
159+
```
160+
161+
> **Note**: If you disable WAL, there is nothing to do with `flush_wal`. You need to call `flush` method to persist the memory data.
162+
>
163+
> If you enable WAL and set `wal_buffer_size` to 0, you do not need to call `flush_wal` method, since WAL will be flushed to disk before writing.
164+
165+
### Using in S3
166+
167+
If you want to use Tonbo in S3, you can configure `DbOption` to specify which part of the data to store in S3 and which part to store in local disk. Here is an example:
168+
169+
```rust
170+
let s3_option = FsOptions::S3 {
171+
bucket: "wasm-data".to_string(),
172+
credential: Some(AwsCredential {
173+
key_id: "key_id".to_string(),
174+
secret_key: "secret_key".to_string(),
175+
token: None,
176+
}),
177+
endpoint: None,
178+
sign_payload: None,
179+
checksum: None,
180+
region: Some("region".to_string()),
181+
};
182+
let options = DbOption::new(
183+
Path::from_filesystem_path("./db_path/users").unwrap(),
184+
&UserSchema,
185+
).level_path(2, "l2", s3_option.clone())
186+
).level_path(3, "l3", s3_option);
187+
```
188+
189+
In this example, the data of level 2 and level 3 will be stored in S3 and the rest of the data will be stored in local disk.
190+
191+
For more configuration options, please refer to the [Configuration](./usage/conf.md) section.
192+
141193
## What next?
142194
- To learn more about tonbo in Rust or in WASM, you can refer to [Tonbo API](./usage/tonbo.md)
143195
- To use tonbo in python, you can refer to [Python API](./usage/python.md)

guide/src/tonbolite/start.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Getting Started
2+
3+
TODO

guide/src/usage/tonbo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Transactions support easily reading the state of keys that are currently batched
183183

184184
You can use `get` method to get a record by key, and `get` method will return a `UserRef` instance. This `UserRef` instance is a struct that tonbo generates for you in the compile time. All fields except primary key are `Option` type, because you may not have set them when you create the record. You can also pass a `Projection` to specify which fields you want to get. `Projection::All` will get all fields, `Projection::Parts(Vec<&str>)` will get only primary key, `email` and `bytes` fields(other fields will be `None`).
185185

186-
You can use `scan` method to scan all records that in the specified range. `scan` method will return a `Scan` instance. You can use `taken` method to get a `Stream` instance and iterate all records that satisfied. Tonbo also supports pushing down filters and projections. You can use `Scan::projection(vec!["id", "email"])` to specify which fields you want to get and use `Scan::limit(10)` to limit the number of records you want to get.
186+
You can use `scan` method to scan all records that in the specified range. `scan` method will return a `Scan` instance. You can use `take` method to get a `Stream` instance and iterate all records that satisfied. Tonbo also supports pushing down filters and projections. You can use `Scan::projection(vec!["id", "email"])` to specify which fields you want to get and use `Scan::limit(10)` to limit the number of records you want to get.
187187

188188
```rust
189189
let txn = db.transaction().await;

0 commit comments

Comments
 (0)