Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
Signed-off-by: gengliqi <[email protected]>
  • Loading branch information
gengliqi committed Nov 3, 2020
1 parent d72d121 commit 6c3b23e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions examples/five_mem_node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ fn on_ready(
handle_messages(res.take_messages());
// Apply all committed entries.
handle_committed_entries(raft_group, res.take_committed_entries());
// Advance the apply index.
raft_group.advance_apply();
}

fn example_config() -> Config {
Expand Down
2 changes: 2 additions & 0 deletions examples/single_mem_node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ fn on_ready(raft_group: &mut RawNode<MemStorage>, cbs: &mut HashMap<u8, ProposeC
handle_messages(res.take_messages());
// Apply all committed entries.
handle_committed_entries(res.take_committed_entries());
// Advance the apply index.
raft_group.advance_apply();
}

fn send_propose(logger: Logger, sender: mpsc::Sender<Msg>) {
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,9 @@ need to update the applied index and resume `apply` later:
}
```
6. Call `advance` to prepare for the next `Ready` state. Get the return value `PersistLastReadyResult`
and handle its `messages` and `committed_entries` like step 1 and step 5 does.
6. Call `advance` to notify that the previous work is completed. Get the return value `PersistLastReadyResult`
and handle its `messages` and `committed_entries` like step 1 and step 5 does. Then call `advance_apply`
to advance the applied index inside.
```rust
# use slog::{Drain, o};
Expand All @@ -382,6 +383,7 @@ and handle its `messages` and `committed_entries` like step 1 and step 5 does.
// Like step 1 and 5, you can use functions to make them behave the same.
handle_messages(res.take_messages());
handle_committed_entries(res.take_committed_entries());
node.advance_apply();
```
For more information, check out an [example](examples/single_mem_node/main.rs#L113-L179).
Expand Down

0 comments on commit 6c3b23e

Please sign in to comment.