mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
ctlv3: ensure synced member list before printing env vars on member add
In cases of multiple endpoints, it's possible member add would get a its member list from a member that has not yet recognized the membership update. Instead, confirm that the member list response is from the member that acked the member add or from a member that has synced with the cluster following the member add. Fixes #7498
This commit is contained in:
parent
e5462f74f1
commit
9d9be2bc86
@ -107,7 +107,8 @@ func memberAddCommandFunc(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
urls := strings.Split(memberPeerURLs, ",")
|
urls := strings.Split(memberPeerURLs, ",")
|
||||||
ctx, cancel := commandCtx(cmd)
|
ctx, cancel := commandCtx(cmd)
|
||||||
resp, err := mustClientFromCmd(cmd).MemberAdd(ctx, urls)
|
cli := mustClientFromCmd(cmd)
|
||||||
|
resp, err := cli.MemberAdd(ctx, urls)
|
||||||
cancel()
|
cancel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ExitWithError(ExitError, err)
|
ExitWithError(ExitError, err)
|
||||||
@ -118,12 +119,24 @@ func memberAddCommandFunc(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
if _, ok := (display).(*simplePrinter); ok {
|
if _, ok := (display).(*simplePrinter); ok {
|
||||||
ctx, cancel = commandCtx(cmd)
|
ctx, cancel = commandCtx(cmd)
|
||||||
listResp, err := mustClientFromCmd(cmd).MemberList(ctx)
|
listResp, err := cli.MemberList(ctx)
|
||||||
cancel()
|
// get latest member list; if there's failover new member might have outdated list
|
||||||
|
for {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ExitWithError(ExitError, err)
|
ExitWithError(ExitError, err)
|
||||||
|
}
|
||||||
|
if listResp.Header.MemberId == resp.Header.MemberId {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
// quorum get to sync cluster list
|
||||||
|
gresp, gerr := cli.Get(ctx, "_")
|
||||||
|
if gerr != nil {
|
||||||
|
ExitWithError(ExitError, err)
|
||||||
|
}
|
||||||
|
resp.Header.MemberId = gresp.Header.MemberId
|
||||||
|
listResp, err = cli.MemberList(ctx)
|
||||||
}
|
}
|
||||||
|
cancel()
|
||||||
|
|
||||||
conf := []string{}
|
conf := []string{}
|
||||||
for _, memb := range listResp.Members {
|
for _, memb := range listResp.Members {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user