Skip to content

Commit

Permalink
disable Linearizable
Browse files Browse the repository at this point in the history
Signed-off-by: lhy1024 <[email protected]>
  • Loading branch information
lhy1024 committed Aug 7, 2024
1 parent ebb1a76 commit fe1dbf8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/utils/etcdutil/etcdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/tikv/pd/pkg/utils/logutil"
"github.com/tikv/pd/pkg/utils/syncutil"
"github.com/tikv/pd/pkg/utils/typeutil"
"go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/api/v3/mvccpb"
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
etcdtypes "go.etcd.io/etcd/client/pkg/v3/types"
Expand Down Expand Up @@ -119,12 +120,17 @@ func ListEtcdMembers(ctx context.Context, client *clientv3.Client) (*clientv3.Me
time.Sleep(time.Duration(d) * time.Second)
})
newCtx, cancel := context.WithTimeout(ctx, DefaultRequestTimeout)
listResp, err := client.MemberList(newCtx)
// After the etcd server is upgraded to v3.5.0, the MemberList API will return the member list in a linearizable way by default.
// It is introduced by https://github.com/etcd-io/etcd/pull/11639
// If Linearizable is set to false, the member list will be returned with server's local data.
// If Linearizable is set to true, it is served with linearizable guarantee. If the server is disconnected from quorum, `MemberList` call will fail.
c := clientv3.RetryClusterClient(client)
resp, err := c.MemberList(newCtx, &etcdserverpb.MemberListRequest{Linearizable: false})
cancel()
if err != nil {
return listResp, errs.ErrEtcdMemberList.Wrap(err).GenWithStackByCause()
return (*clientv3.MemberListResponse)(resp), errs.ErrEtcdMemberList.Wrap(err).GenWithStackByCause()
}
return listResp, nil
return (*clientv3.MemberListResponse)(resp), nil
}

// RemoveEtcdMember removes a member by the given id.
Expand Down

0 comments on commit fe1dbf8

Please sign in to comment.