Commit c3064082 authored by Yossi Gottlieb's avatar Yossi Gottlieb
Browse files

Fix virtraft membership tests.

This fixes an issue with virtraft2 which was not able to perform
REMOVE_NODE when DEMOTE_NODE was applied. The previous fix of directly
removing nodes was not aligned with how virtraft2 manages nodes.
parent 2b8aa47d
...@@ -860,6 +860,17 @@ int raft_apply_entry(raft_server_t* me_) ...@@ -860,6 +860,17 @@ int raft_apply_entry(raft_server_t* me_)
log_idx, ety->id, ety->data_len); log_idx, ety->id, ety->data_len);
me->last_applied_idx++; me->last_applied_idx++;
/* voting cfg change is now complete. we have to update it before calling
* applylog to allow the callback to push a new membership change entry
* if needed (e.g. remove after demote).
*
* TODO: is there possibly an off-by-one bug hidden here? requiring
* checking log_idx >= voting_cfg_change_log_idx rather than plain ==.
*/
if (log_idx >= me->voting_cfg_change_log_idx)
me->voting_cfg_change_log_idx = -1;
if (me->cb.applylog) if (me->cb.applylog)
{ {
int e = me->cb.applylog(me_, me->udata, ety, me->last_applied_idx); int e = me->cb.applylog(me_, me->udata, ety, me->last_applied_idx);
...@@ -869,13 +880,6 @@ int raft_apply_entry(raft_server_t* me_) ...@@ -869,13 +880,6 @@ int raft_apply_entry(raft_server_t* me_)
} }
} }
/* voting cfg change is now complete.
* TODO: there seem to be a possible off-by-one bug hidden here, requiring
* checking log_idx >= voting_cfg_change_log_idx rather than plain ==.
*/
if (log_idx >= me->voting_cfg_change_log_idx)
me->voting_cfg_change_log_idx = -1;
if (!raft_entry_is_cfg_change(ety)) if (!raft_entry_is_cfg_change(ety))
goto exit; goto exit;
......
...@@ -575,7 +575,7 @@ class Network(object): ...@@ -575,7 +575,7 @@ class Network(object):
return return
# Create a new configuration entry to be processed by the leader # Create a new configuration entry to be processed by the leader
ety = self.add_entry(lib.RAFT_LOGTYPE_REMOVE_NODE, ety = self.add_entry(lib.RAFT_LOGTYPE_DEMOTE_NODE,
ChangeRaftEntry(server.id)) ChangeRaftEntry(server.id))
assert server.connection_status == NODE_CONNECTED assert server.connection_status == NODE_CONNECTED
assert(lib.raft_entry_is_cfg_change(ety)) assert(lib.raft_entry_is_cfg_change(ety))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment