Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
RedisLabs Raft
Commits
0f2f98bc
Unverified
Commit
0f2f98bc
authored
Mar 06, 2022
by
Ozan Tezcan
Committed by
GitHub
Mar 06, 2022
Browse files
Check if the node is leader inside raft_get_index_to_sync() (#85)
parent
d718d2c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/raft.h
View file @
0f2f98bc
...
...
@@ -1550,7 +1550,7 @@ raft_index_t raft_get_num_snapshottable_logs(raft_server_t* me_);
* another thread. Also, users should call raft_flush() often to update
* persisted log index and to send new appendentries messages.
*
* Example
:
* Example:
*
* void server_loop() {
* while (1) {
...
...
@@ -1587,6 +1587,10 @@ int raft_set_auto_flush(raft_server_t* me, int flush);
* This function is only useful when auto flush is disabled. Same index will be
* reported once.
*
* If the node is not the leader, it returns zero. For followers, disk flush is
* synchronous. sync() callback is called when an appendentries message
* received. So, this function does not makes sense if the node is a follower.
*
* @param[in] raft The Raft server
* @return entry index need to be written to the disk.
* '0' if there is no new entry to write to the disk
...
...
src/raft_server.c
View file @
0f2f98bc
...
...
@@ -2159,10 +2159,11 @@ static int raft_update_commit_idx(raft_server_t* me_)
raft_index_t
raft_get_index_to_sync
(
raft_server_t
*
me_
)
{
raft_server_private_t
*
me
=
(
raft_server_private_t
*
)
me_
;
raft_index_t
idx
=
raft_get_current_idx
(
me_
);
if
(
me
->
next_sync_index
>
idx
)
if
(
!
raft_is_leader
(
me_
)
||
idx
<
me
->
next_sync_index
)
{
return
0
;
}
me
->
next_sync_index
=
idx
+
1
;
return
idx
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment