Skip to content

Commit 23e856b

Browse files
committed
Doc: add upgrade-guide from 0.8 to 0.9
1 parent 068e51a commit 23e856b

File tree

6 files changed

+193
-4
lines changed

6 files changed

+193
-4
lines changed

change-log.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Summary:
1212
- [22cd3bb4](https://github.com/datafuselabs/openraft/commit/22cd3bb423ddaf21c1f4d70917f689e79a9cacb6) remove deprecated RaftNetwork methods without `option` argument.
1313
- [a1c7f6e6](https://github.com/datafuselabs/openraft/commit/a1c7f6e63b3b0b385a2d6289fd406c31cca18834) remove openraft-0.7 compatibility support.
1414
- Added:
15-
- [d629dbeb](https://github.com/datafuselabs/openraft/commit/d629dbeb65f73e3133e548fe48deb6a645f0dd5a) add ChangeMembers::SetNodes (#876).
15+
- [d629dbeb](https://github.com/datafuselabs/openraft/commit/d629dbeb65f73e3133e548fe48deb6a645f0dd5a) add `ChangeMembers::SetNodes` (#876).
1616
- [104983db](https://github.com/datafuselabs/openraft/commit/104983db6bf5a60cd28e0b7237bfd2937a50168a) add 'singlethreaded' raft mode (#878).
1717
- [942ec78b](https://github.com/datafuselabs/openraft/commit/942ec78bc367665ce82516ad3458e479d895b0ea) save committed log id.
1818
- [6d42c6e2](https://github.com/datafuselabs/openraft/commit/6d42c6e24c3bc752ffcaa331df48b5a41eb763b7) permit follower log to revert to earlier state with `--features loosen-follower-log-revert`.
@@ -142,7 +142,7 @@ Detail:
142142

143143
### Added:
144144

145-
- Added: [d629dbeb](https://github.com/datafuselabs/openraft/commit/d629dbeb65f73e3133e548fe48deb6a645f0dd5a) add ChangeMembers::SetNodes (#876); by 张炎泼; 2023-06-22
145+
- Added: [d629dbeb](https://github.com/datafuselabs/openraft/commit/d629dbeb65f73e3133e548fe48deb6a645f0dd5a) add `ChangeMembers::SetNodes` (#876); by 张炎泼; 2023-06-22
146146

147147
During dynamic cluster changes, we sometimes need to update an existing
148148
node, for example changing its network address.

change-log/v0.9.0.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Summary:
1010
- [22cd3bb4](https://github.com/datafuselabs/openraft/commit/22cd3bb423ddaf21c1f4d70917f689e79a9cacb6) remove deprecated RaftNetwork methods without `option` argument.
1111
- [a1c7f6e6](https://github.com/datafuselabs/openraft/commit/a1c7f6e63b3b0b385a2d6289fd406c31cca18834) remove openraft-0.7 compatibility support.
1212
- Added:
13-
- [d629dbeb](https://github.com/datafuselabs/openraft/commit/d629dbeb65f73e3133e548fe48deb6a645f0dd5a) add ChangeMembers::SetNodes (#876).
13+
- [d629dbeb](https://github.com/datafuselabs/openraft/commit/d629dbeb65f73e3133e548fe48deb6a645f0dd5a) add `ChangeMembers::SetNodes` (#876).
1414
- [104983db](https://github.com/datafuselabs/openraft/commit/104983db6bf5a60cd28e0b7237bfd2937a50168a) add 'singlethreaded' raft mode (#878).
1515
- [942ec78b](https://github.com/datafuselabs/openraft/commit/942ec78bc367665ce82516ad3458e479d895b0ea) save committed log id.
1616
- [6d42c6e2](https://github.com/datafuselabs/openraft/commit/6d42c6e24c3bc752ffcaa331df48b5a41eb763b7) permit follower log to revert to earlier state with `--features loosen-follower-log-revert`.
@@ -140,7 +140,7 @@ Detail:
140140

141141
### Added:
142142

143-
- Added: [d629dbeb](https://github.com/datafuselabs/openraft/commit/d629dbeb65f73e3133e548fe48deb6a645f0dd5a) add ChangeMembers::SetNodes (#876); by 张炎泼; 2023-06-22
143+
- Added: [d629dbeb](https://github.com/datafuselabs/openraft/commit/d629dbeb65f73e3133e548fe48deb6a645f0dd5a) add `ChangeMembers::SetNodes` (#876); by 张炎泼; 2023-06-22
144144

145145
During dynamic cluster changes, we sometimes need to update an existing
146146
node, for example changing its network address.

openraft/src/docs/docs.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ When upgrading an Openraft application, consult:
1515
- [`v0.6-to-v0.7`](`crate::docs::upgrade_guide::upgrade_06_07`);
1616
- [`v0.7-to-v0.8`](`crate::docs::upgrade_guide::upgrade_07_08`);
1717
- [`v0.8.3-to-v0.8.4`](`crate::docs::upgrade_guide::upgrade_083_084`);
18+
- [`v0.8-to-v0.9`](`crate::docs::upgrade_guide::upgrade_08_09`);
1819

1920
To learn about the data structures used in Openraft and the commit protocol, see
2021
- [`feature_flags`](crate::docs::feature_flags);

openraft/src/docs/upgrade_guide/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ pub mod upgrade_07_08 {
99
pub mod upgrade_083_084 {
1010
//! See: [Guide for upgrading v0.8.3 to v0.8.4](https://docs.rs/openraft/0.8.9/openraft/docs/upgrade_guide/upgrade_083_084)
1111
}
12+
pub mod upgrade_08_09 {
13+
#![doc = include_str!("upgrade-v08-v09.md")]
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Guide for upgrading from [v0.8](https://github.com/datafuselabs/openraft/tree/v0.8.9) to [v0.9](https://github.com/datafuselabs/openraft/tree/release-0.9):
2+
3+
[Change log v0.9.0](https://github.com/datafuselabs/openraft/blob/release-0.9/change-log.md)
4+
5+
6+
## Major changes:
7+
8+
- Removed Compatibility support for v0.7.
9+
10+
- Add [`AsyncRuntime`][] as an abstraction for async runtime.
11+
An application can use a different async runtime other than [`tokio`][] by implementing the [`AsyncRuntime`] trait.
12+
13+
- `committed` log id can be optionally saved with [`RaftLogStorage::save_committed()`][].
14+
15+
- New errors: [`PayloadTooLarge`][]: to inform Openraft to split append entries request into smaller ones.
16+
17+
- New API: support linearizable read: [`Raft::ensure_linearizable()`][].
18+
19+
- New API to support generic snapshot data transfer with the following new APIs:
20+
21+
- [`Raft::get_snapshot()`][]
22+
- [`Raft::begin_receiving_snapshot()`][]
23+
- [`Raft::install_full_snapshot()`][]
24+
- [`RaftNetwork::full_snapshot()`][]
25+
26+
- New feature flags:
27+
28+
- [`singlethreaded`][]: Run Openraft in a single threaded environment, i.e., without requiring `Send` bound.
29+
- [`loosen-follower-log-revert`][]: Allows cleaning a follower's data, useful for testing.
30+
- [`generic-snapshot-data`][]: Remove `AsyncRead + AsyncWrite` bound from snapshot data. Let application define its own snapshot data transfer.
31+
32+
33+
## Upgrade `RaftTypeConfig`
34+
35+
- Add `AsyncRuntime` to `RaftTypeConfig` to specify the async runtime to use.
36+
Openraft provides a default implementations: `TokioRuntime`.
37+
For example:
38+
```ignore
39+
openraft::declare_raft_types!(
40+
pub TypeConfig:
41+
// ...
42+
AsyncRuntime = TokioRuntime
43+
);
44+
```
45+
46+
You can just implement the [`AsyncRuntime`][] trait for your own async runtime and use it in `RaftTypeConfig`.
47+
48+
## Upgrade log storage: save committed log id
49+
50+
In v0.9, `save_committed()` is added to `RaftLogStorage` trait to optionally save the `committed` log id.
51+
For example:
52+
```ignore
53+
impl RaftLogStorage for YourStorage {
54+
// ...
55+
fn save_committed(&self, committed: u64) -> Result<(), StorageError> {
56+
// ...
57+
}
58+
}
59+
```
60+
61+
If committed log id is saved,
62+
the committed log will be applied to state machine via [`RaftStateMachine::apply()`][] upon startup,
63+
if they are not already applied.
64+
65+
Not implementing `save_committed()` will not affect correctness.
66+
67+
## Upgrade snapshot transmission
68+
69+
In v0.9, an application can use its own snapshot data transfer by enabling [`generic-snapshot-data`][] feature flag.
70+
With this flag enabled, the snapshot data can be arbitrary type
71+
and is no longer required to implement `AsyncRead + AsyncWrite` trait.
72+
73+
To use arbitrary snapshot data, the application needs to:
74+
75+
- Specify the snapshot data type in `RaftTypeConfig`:
76+
```ignore
77+
openraft::declare_raft_types!(
78+
pub TypeConfig:
79+
// ...
80+
SnapshotData = YourSnapshotData
81+
);
82+
```
83+
84+
- implement the snapshot transfer in the application's network layer by implementing the [`RaftNetwork`] trait.
85+
For example:
86+
```ignore
87+
impl RaftNetwork for YourNetwork {
88+
// ...
89+
fn full_snapshot(&self, /*...*/) -> Result<_,_> {
90+
// ...
91+
}
92+
}
93+
```
94+
95+
`full_snapshot()` allows for the transfer of snapshot data using any preferred method.
96+
Openraft provides a default implementation in [`Chunked`][].
97+
[`Chunked`][] just delegate the transmission to several calls
98+
to the old chunk-based API `RaftNetwork::install_snapshot()`.
99+
If you want to minimize the changes in your application,
100+
just call `Chunked::send_snapshot()` in `full_snapshot()`:
101+
```ignore
102+
impl RaftNetwork for YourNetwork {
103+
async fn full_snapshot(&mut self, vote: Vote<C::NodeId>, snapshot: Snapshot<C>, /*...*/
104+
) -> Result<SnapshotResponse<C::NodeId>, StreamingError<C, Fatal<C::NodeId>>> {
105+
let resp = Chunked::send_snapshot(self, vote, snapshot, /*...*/).await?;
106+
Ok(resp)
107+
}
108+
}
109+
```
110+
111+
Refer to: [the default chunk-based snapshot sending](https://github.com/datafuselabs/openraft/blob/2cc7170ffaf87c674e5ca13370402528f8ab3958/openraft/src/network/network.rs#L129)
112+
113+
- On the receiving end,
114+
when the application finished receiving the snapshot data,
115+
it should call [`Raft::install_full_snapshot()`][] to install it.
116+
117+
`Chunked::receive_snapshot` provides a default chunk-based implementation for receiving snapshot data.
118+
The application can just use it:
119+
120+
```ignore
121+
async fn handle_install_snapshot_request(
122+
&self,
123+
req: InstallSnapshotRequest<C>,
124+
) -> Result<_, _>
125+
where C::SnapshotData: AsyncRead + AsyncWrite + AsyncSeek + Unpin,
126+
{
127+
let my_vote = self.with_raft_state(|state| *state.vote_ref()).await?;
128+
let resp = InstallSnapshotResponse { vote: my_vote };
129+
130+
let finished_snapshot = {
131+
use crate::network::snapshot_transport::Chunked;
132+
use crate::network::snapshot_transport::SnapshotTransport;
133+
134+
let mut streaming = self.snapshot.lock().await;
135+
Chunked::receive_snapshot(&mut *streaming, self, req).await?
136+
};
137+
138+
if let Some(snapshot) = finished_snapshot {
139+
let resp = self.install_full_snapshot(req_vote, snapshot).await?;
140+
return Ok(resp.into());
141+
}
142+
Ok(resp)
143+
}
144+
```
145+
146+
Refer to: [the default chunk-based snapshot receiving](https://github.com/datafuselabs/openraft/blob/c9a463f5ce73d1e7dd66eabfe909fe8d5a087f0e/openraft/src/raft/mod.rs#L447)
147+
148+
Note that the application is responsible for maintaining a streaming state [`Streaming`][]
149+
during receiving chunks.
150+
151+
152+
153+
[`AsyncRuntime`]: `crate::AsyncRuntime`
154+
[`RPCOption`]: `crate::network::RPCOption`
155+
[`Chunked`]: `crate::network::snapshot_transport::Chunked`
156+
[`Chunked::receive_snapshot`]: `crate::network::snapshot_transport::Chunked::receive_snapshot`
157+
[`Streaming`]: `crate::network::snapshot_transport::Streaming`
158+
159+
[`PayloadTooLarge`]: `crate::error::PayloadTooLarge`
160+
161+
[`Raft::ensure_linearizable()`]: `crate::Raft::ensure_linearizable`
162+
[`Raft::get_snapshot()`]: `crate::Raft::get_snapshot`
163+
[`Raft::begin_receiving_snapshot()`]: `crate::Raft::begin_receiving_snapshot`
164+
[`Raft::install_full_snapshot()`]: `crate::Raft::install_full_snapshot`
165+
166+
[`RaftNetwork`]: `crate::network::RaftNetwork`
167+
[`RaftNetwork::full_snapshot()`]: `crate::network::RaftNetwork::full_snapshot`
168+
169+
[`RaftLogStorage::save_committed()`]: `crate::storage::RaftLogStorage::save_committed`
170+
171+
[`RaftStateMachine::apply()`]: `crate::storage::RaftStateMachine::apply`
172+
173+
[`singlethreaded`]: `crate::docs::feature_flags#feature-flag-singlethreaded`
174+
[`loosen-follower-log-revert`]: `crate::docs::feature_flags#feature-flag-loosen-follower-log-revert`
175+
[`generic-snapshot-data`]: `crate::docs::feature_flags#feature-flag-generic-snapshot-data`
176+
[`tracing-log`]: `crate::docs::feature_flags#feature-flag-tracing-log`
177+
178+
[`tokio`]: https://tokio.rs/
179+
[`monoio`]: https://github.com/bytedance/monoio

openraft/src/docs/upgrade_guide/upgrade.md

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ A commit message starting with these keywords needs attention:
1616

1717
- Fix: bug fix. No modification is required.
1818

19+
## Upgrade from [v0.8](https://github.com/datafuselabs/openraft/tree/v0.8.9) to [v0.9](https://github.com/datafuselabs/openraft/tree/release-0.9):
20+
21+
[Change log v0.9.0](https://github.com/datafuselabs/openraft/blob/release-0.9/change-log.md)
22+
23+
[Guide for upgrading v0.8 to v0.9](`crate::docs::upgrade_guide::upgrade_08_09`)
24+
1925
## Upgrade from [v0.8.3](https://github.com/datafuselabs/openraft/tree/v0.8.3) to [v0.8.4](https://github.com/datafuselabs/openraft/tree/v0.8.4):
2026

2127
[Change log v0.8.4](https://github.com/datafuselabs/openraft/blob/release-0.8/change-log.md)

0 commit comments

Comments
 (0)