Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Term increment is skipped in one-node clusters #689

Open
cole-miller opened this issue Aug 23, 2024 · 0 comments
Open

Term increment is skipped in one-node clusters #689

cole-miller opened this issue Aug 23, 2024 · 0 comments

Comments

@cole-miller
Copy link
Contributor

When the current configuration contains only one node, we have a fast path in raft to skip the election and move directly from follower to leader:

dqlite/src/raft/convert.c

Lines 171 to 180 in 6035a35

/* Fast-forward to leader if we're the only voting server in the
* configuration. */
server = configurationGet(&r->configuration, r->id);
assert(server != NULL);
assert(server->role == RAFT_VOTER);
if (n_voters == 1) {
tracef("self elect and convert to leader");
return convertToLeader(r);
}

This is great, but because the election code is responsible for incrementing the term number, we end up skipping this update for one-node clusters as well. This means we can have two distinct leaders that share a term number, as happens in this test:

TEST(cluster, dataOnNewNode, setUp, tearDown, 0, cluster_params)

I think this behavior is unintuitive at best and we should add a term number increase on the fast path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant