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

Refactor: Engine::initialize() sets server state to Candidate #296

Merged
merged 1 commit into from
Apr 16, 2022

Conversation

drmingdrmer
Copy link
Member

@drmingdrmer drmingdrmer commented Apr 16, 2022

Changelog

Refactor: Engine::initialize() sets server state to Candidate


This change is Reviewable

- Feature: impl TryFrom<BTreeMap> for Membership.

- part of databendlabs#292
self.commands.push(Command::MoveInputCursorBy { n: l });

// With the new config, start to elect to become leader
Copy link
Contributor

@lichuang lichuang Apr 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can not get the point: why the node init state is candidate instead of follower?

Copy link
Contributor

@lichuang lichuang Apr 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it means no matter the node startup in whatever situation, even if it join a cluster, it must start an election?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After initializing the cluster(by appending a membership log), the cluster should elect a leader ASAP.
The behavior for a follower is to wait for a timeout before starting elect(by entering candidate state). Thus we can just avoid the follower state and enter candidate state at once.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it means no matter the node startup in whatever situation, even if it join a cluster, it must start an election?

It must be a mistake to join a node into an existing cluster by initialize() it.
To join, it does not call initialize().

It should send a change-membership RPC to the existing cluster leader to start replicating logs to the new node.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it means no matter the node startup in whatever situation, even if it join a cluster, it must start an election?

BTW, the election will never win. The new node does not have any log on it thus it will be rejected.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to me that init as a follower or a candidate has not too much different, they all have advantages and disadvantages, as you like:)

@drmingdrmer drmingdrmer merged commit aa67db3 into databendlabs:main Apr 16, 2022
@drmingdrmer drmingdrmer deleted the 6-set-server-state branch April 16, 2022 15:53
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

Successfully merging this pull request may close these issues.

2 participants