raft: replace raft_start_candidate with _promote
raft_state_candiate() made the instance a candidate until it was reconfigured or raft_stop_candidate() was called. It was used during promotion of a 'manual' instance. This however was relatively hard to use - raft_stop_candidate() had a flag 'do_demote' which was passed as true only by Raft internally, and it also wasn't very consistent with box.promote() which works for one term only. One of the next patches is going to need Raft promotion again but for just one term. In order not to use raft_start/stop_leader() again, this patch replaces them with raft_promote() and raft_restore(). raft_promote() works very similar to box.promote() - it bumps the term and makes the instance a candidate for this term. If it wins, it stays a leader until next term happens. Otherwise either a new term is started and the node stops being a leader, or another node becomes a leader. In the former case raft_promote() might be called again to retry. Replacement couldn't be done independently from box/ changes, because raft_start/stop_candidate couldn't be kept - any term bump runs raft_restore() which is the same as raft_stop_candidate(do_demote=true), and that makes the old functions useless. Hence the patch also includes box/ changes. Part of #6018
Showing
- src/box/box.cc 8 additions, 19 deletionssrc/box/box.cc
- src/box/errcode.h 1 addition, 1 deletionsrc/box/errcode.h
- src/box/raft.c 49 additions, 9 deletionssrc/box/raft.c
- src/box/raft.h 2 additions, 2 deletionssrc/box/raft.h
- src/lib/raft/raft.c 53 additions, 45 deletionssrc/lib/raft/raft.c
- src/lib/raft/raft.h 8 additions, 5 deletionssrc/lib/raft/raft.h
- test/box/error.result 1 addition, 1 deletiontest/box/error.result
- test/unit/raft.c 23 additions, 18 deletionstest/unit/raft.c
- test/unit/raft.result 13 additions, 9 deletionstest/unit/raft.result
- test/unit/raft_test_utils.c 6 additions, 11 deletionstest/unit/raft_test_utils.c
- test/unit/raft_test_utils.h 5 additions, 11 deletionstest/unit/raft_test_utils.h
Loading
Please register or sign in to comment