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

etcdctl: find leader when promoting learner #28

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion etcdctl/ctlv3/command/member_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,37 @@ func memberPromoteCommandFunc(cmd *cobra.Command, args []string) {
}

ctx, cancel := commandCtx(cmd)
resp, err := mustClientFromCmd(cmd).MemberPromote(ctx, id)
eps, err := endpointsFromCmd(cmd)
if err != nil {
ExitWithError(ExitError, err)
}

var (
leaderEp string
leaderFound bool
)
for _, ep := range eps {
Copy link

Choose a reason for hiding this comment

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

If ctx has a deadline, loop multiple times over the endpoints until the deadline expires or a leader is found? This would reduce the odd of a leader change causing this operation to fail.

Copy link

Choose a reason for hiding this comment

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

Ignore if we can do a server side request foward like mentioned in #28 (comment)

cfg := clientConfigFromCmd(cmd)
cfg.endpoints = []string{ep}
cli := cfg.mustClient()
resp, serr := cli.Status(ctx, ep)
if serr != nil {
ExitWithError(ExitError, serr)
}
if resp.Header.GetMemberId() == resp.Leader {
leaderFound = true
leaderEp = ep
break
}
cli.Close()
}
if !leaderFound {
ExitWithError(ExitBadArgs, fmt.Errorf("no leader endpoint found in %v", eps))
}

cfg := clientConfigFromCmd(cmd)
cfg.endpoints = []string{leaderEp}
resp, err := cfg.mustClient().MemberPromote(ctx, id)
cancel()
if err != nil {
ExitWithError(ExitError, err)
Expand Down