Skip to content

Commit

Permalink
v1: Set RAFT_UPDATE_STATE flag when the state changes
Browse files Browse the repository at this point in the history
Signed-off-by: Free Ekanayaka <free@ekanayaka.io>
  • Loading branch information
freeekanayaka committed Dec 22, 2023
1 parent 9ad319a commit a640a70
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/raft.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ struct raft_update
#define RAFT_UPDATE_ENTRIES 1 << 2
#define RAFT_UPDATE_SNAPSHOT 1 << 3
#define RAFT_UPDATE_MESSAGES 1 << 4
#define RAFT_UPDATE_STATE 1 << 5

/**
* version field MUST be filled out by user.
Expand Down
2 changes: 2 additions & 0 deletions src/convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ static void convertSetState(struct raft *r, unsigned short new_state)
* respect to the paper we have an additional "unavailable" state, which is
* the initial or final state. */
tracef("old_state:%u new_state:%u", r->state, new_state);
assert(r->state != new_state);
assert((r->state == RAFT_UNAVAILABLE && new_state == RAFT_FOLLOWER) ||
(r->state == RAFT_FOLLOWER && new_state == RAFT_CANDIDATE) ||
(r->state == RAFT_CANDIDATE && new_state == RAFT_FOLLOWER) ||
Expand All @@ -31,6 +32,7 @@ static void convertSetState(struct raft *r, unsigned short new_state)
(r->state == RAFT_CANDIDATE && new_state == RAFT_UNAVAILABLE) ||
(r->state == RAFT_LEADER && new_state == RAFT_UNAVAILABLE));
r->state = new_state;
r->update->flags |= RAFT_UPDATE_STATE;
}

/* Clear follower state. */
Expand Down

0 comments on commit a640a70

Please sign in to comment.