You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
143705: raft: replace MsgStorageAppend protocol r=tbg a=pav-kv
This PR replaces the `MsgStorageAppend` protocol with a more ergonomic / strongly-typed API.
Benefits of this change:
- 3 fields are removed from `raftpb.Message`, and its in-memory size is decreased from 184 to 144 bytes.
- Storage interaction is completely removed from `raftpb.Message`, and there is a cleaner separation between messages and local storage interaction.
- Improved readability and safety of the `Ready` API.
- Log storage code upstream of `pkg/raft` can use the new `StorageAppend/Ack` types to carry their semantics.
---
The old flow:
1. If there are pending storage writes, `RawNode.Ready()` constructs a `MsgStorageAppend` and puts it in `Ready.Messages`.
2. The application filters it out from other messages, and sends it to local storage.
3. When the write is done, the `RawNode` must be notified, and some messages (such as `MsgAppResp`) must be sent to other peers. The `MsgStorageAppend` contains a list of remote and local messages in `Responses`, which includes a `MsgStorageAppendResp`. The application filters out local messages and steps them into the `RawNode`. It sends all other messages via raft transport.
---
The new flow:
1. If there are pending storage writes, `RawNode.Ready()` constructs a `StorageAppend` struct and embeds it into `Ready`.
2. All messages in `Ready.Messages` are not subject to durability, so can be sent immediately without filtering.
3. The application sends `Ready.StorageWrite` to local storage.
4. When the write is done/durable, the application routes the `StorageAppend.Ack()` to `RawNode.AckAppend(ack)` method, to notify the local `RawNode`, and sends all remote messages in `ack.Responses` via the raft transport.
----
Part of #143652, #124440
Co-authored-by: Pavel Kalinnikov <[email protected]>
0 commit comments