Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sweep GHA Fix] Fix the failing GitHub Actions #83

Closed
wants to merge 10 commits into from
47 changes: 38 additions & 9 deletions openraft/src/docs/upgrade_guide/upgrade-v07-v08.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Guide for upgrading from [v0.7](https://github.com/datafuselabs/openraft/tree/v0.7.4) to [v0.8](https://github.com/datafuselabs/openraft/tree/release-0.8):
# Guide for upgrading from `v0.7` to `v0.8`:

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

Expand All @@ -13,7 +13,7 @@ To upgrade:
1. Update the application to adopt `v0.8` openraft.
The updated `RaftStorage` implementation must pass [`testing::Suite`](`crate::testing::Suite`):
an example of running it is [`RaftStorage` test suite](https://github.com/datafuselabs/openraft/blob/release-0.8/memstore/src/test.rs),
and the compatibility test: [compatibility test](https://github.com/datafuselabs/openraft/blob/main/rocksstore-compat07/src/compatibility_test.rs)
and the compatibility test: `compatibility test`.

2. Then shutdown all `v0.7` nodes and then bring up `v0.8` nodes.

Expand All @@ -32,13 +32,29 @@ Openraft `v0.8` provides several [`feature_flags`] to provide compatibility with
- `serde`: Make sure that the application uses `serde` to serialize data; Openraft v0.8 provides a compatibility layer that is built upon `serde`.

- `compat-07`: Enable feature flag `compat-07` to enable the compatibility layer [`compat::compat07`](`crate::compat::compat07`).
- Optionally enable feature flag `single-term-leader` if the application wants to use standard raft. See [Multi/single leader in each term](#multisingle-leader-in-each-term) chapter.

- Optionally enable feature flag `single-term-leader` if the application wants to use standard raft. See [Multi/single leader in each term](#multisingle-leader-in-each-term) chapter.

### Upgrade the application codes

- Add type config to define concrete types to use for openraft, See [`RaftTypeConfig`].

Openraft `v0.8` introduces a macro `declare_raft_types` to declare these generic application types that are defined as associated types of `RaftTypeConfig`.
An `v0.8` application should implement [`RaftTypeConfig`]:

```ignore
pub(crate) struct MyTypeConfig {}
impl RaftTypeConfig for MyTypeConfig {
type D = ClientRequest;
type R = ClientResponse;
type NodeId = u64;
type Node = openraft::EmptyNode;
type Entry = openraft::entry::Entry<MyTypeConfig>;
type SnapshotData = Cursor<Vec<u8>;
}
```

Openraft `v0.8` introduces several more generic types to define application types that are defined as associated types of `RaftTypeConfig`.
An `v0.8` application should implement [`RaftTypeConfig`]:

Expand Down Expand Up @@ -74,6 +90,13 @@ Openraft `v0.8` provides several [`feature_flags`] to provide compatibility with

```ignore
openraft::declare_raft_types!(
pub MyTypeConfig:
D = ClientRequest,
R = ClientResponse,
NodeId = u64,
Node = openraft::EmptyNode,
Entry = openraft::entry::Entry<MyTypeConfig>,
SnapshotData = Cursor<Vec<u8>>,
pub MyTypeConfig:
D = ClientRequest,
R = ClientResponse,
Expand All @@ -87,20 +110,25 @@ Openraft `v0.8` provides several [`feature_flags`] to provide compatibility with
- To upgrade to `v0.8`, data types have generic type parameters need to be updated, such as:
- `LogId` becomes `LogId<u64>`,
- `Membership` becomes `Membership<u64, openraft::EmptyNode>`,
- To upgrade to `v0.8`, data types have generic type parameters need to be updated, such as:
- `LogId` becomes `LogId<u64>`,
- `Membership` becomes `Membership<u64, openraft::EmptyNode>`,
- `Entry<D>` becomes `Entry<MyTypeConfig>`.
Where `u64` is node id type in `v0.7` and `MyTypeConfig` is the type config defined in the previous step.
- `Entry<D>` becomes `Entry<MyTypeConfig>`.
Where `u64` is node id type in `v0.7` and `MyTypeConfig` is the type config defined in the previous step.

- Update `RaftStorage` methods implementation according to the
[Storage API changes](#storage-api-changes) chapter.

- Replace `HardState` with `Vote`, and `[read/save]_hard_state` with `[read/write]_vote`.
- Replace `HardState` with `Vote`.
- Replace `EffectiveMembership` with `StoredMembership`.

In order to ensure compatibility with version `0.7`, the storage implementation must replace the types used for deserialization with those supplied by [`compat::compat07`].
[`compat::compat07`] includes types like [`compat::compat07::Entry`] that can be deserialized from both `v0.7` serialized `Entry` and `v0.8` serialized `Entry`.

- Move `RaftNetwork` methods implementation according to the
[Network-API-changes](#network-api-changes) chapter.
- Move `RaftNetwork` and `RaftNetworkFactory` methods implementation according to the
[Network API changes](#network-api-changes), and update the code to split `RaftNetwork` and `RaftNetworkFactory` as follows:

- Use `v0.8` [`Adaptor`] to install `RaftStorage` to `Raft`.

Expand All @@ -123,6 +151,7 @@ Openraft `v0.8` provides several [`feature_flags`] to provide compatibility with
where
C: RaftTypeConfig,
N: RaftNetworkFactory<C>,
S: RaftStorage<C>,
S: RaftStorage<C>,
```

Expand Down Expand Up @@ -175,8 +204,8 @@ And `v0.8` will be compatible with `v0.7` only when it uses `u64` as `NodeId` an
## Implement a compatible storage layer

In addition to enabling `compat-07` feature flag, openraft provides a compatible layer in
[`compat::compat07`] to help application developer to upgrade.
This mod provides several types that can deserialize from both `v0.7` format data and the latest format data.
[`compat::compat07`] to help the application developer to upgrade.
[`compat::compat07`] provides several types that can deserialize from both `v0.7` format data and the latest format data.

An application uses these types to replace the corresponding ones in a
`RaftStorage` implementation, so that `v0.7` data and `v0.8` data can both be read.
Expand Down Expand Up @@ -230,7 +259,7 @@ that can be deserialized from `v0.7` or `v0.8` data, such as

Openraft also provides a testing suite
[`compat::testing::Suite07`] to ensure old data will be correctly read.
An application should ensure that its storage passes this test suite. Just like [rocksdb-compatability-test][compatibility test] does.
An application should ensure that its storage passes this test suite. Just like rocksdb-compatability-test does.

To test compatibility of the application storage API:

Expand Down Expand Up @@ -400,7 +429,7 @@ Function `get_log_entries()` and `try_get_log_entry()` are provided with default
[`compat::compat07::Entry`]: `crate::compat::compat07::Entry`

[compatibility test]: https://github.com/datafuselabs/openraft/blob/release-0.8/rocksstore-compat07/src/compatibility_test.rs
[`RaftStorage` test suite]: https://github.com/datafuselabs/openraft/blob/release-0.8/memstore/src/test.rs
the compatibility test for the application storage API: rocksstore-compat07 at [rocksstore-compat07]


[`compat::testing::Suite07`]: `crate::compat::testing::Suite07`
Loading