Skip to content

Commit

Permalink
revert context changes
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed May 15, 2023
1 parent e7f7d4c commit 2581d64
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pkg/dashboard/adapter/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (m *Manager) updateInfo() {
m.isLeader = true

var err error
if m.members, err = cluster.GetMembers(m.srv.GetClient().Ctx(), m.srv.GetClient()); err != nil {
if m.members, err = cluster.GetMembers(m.srv.GetClient()); err != nil {
log.Warn("failed to get members", errs.ZapError(err))
m.members = nil
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/member/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (m *EmbeddedEtcdMember) ResignEtcdLeader(ctx context.Context, from string,
log.Info("try to resign etcd leader to next pd-server", zap.String("from", from), zap.String("to", nextEtcdLeader))
// Determine next etcd leader candidates.
var etcdLeaderIDs []uint64
res, err := etcdutil.ListEtcdMembers(ctx, m.client)
res, err := etcdutil.ListEtcdMembers(m.client)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/etcdutil/etcdutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func AddEtcdMember(client *clientv3.Client, urls []string) (*clientv3.MemberAddR
}

// ListEtcdMembers returns a list of internal etcd members.
func ListEtcdMembers(ctx context.Context, client *clientv3.Client) (*clientv3.MemberListResponse, error) {
ctx, cancel := context.WithTimeout(ctx, DefaultRequestTimeout)
func ListEtcdMembers(client *clientv3.Client) (*clientv3.MemberListResponse, error) {
ctx, cancel := context.WithTimeout(client.Ctx(), DefaultRequestTimeout)
listResp, err := client.MemberList(ctx)
cancel()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/utils/etcdutil/etcdutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestMemberHelpers(t *testing.T) {
<-etcd1.Server.ReadyNotify()

// Test ListEtcdMembers
listResp1, err := ListEtcdMembers(client1.Ctx(), client1)
listResp1, err := ListEtcdMembers(client1)
re.NoError(err)
re.Len(listResp1.Members, 1)
// types.ID is an alias of uint64.
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestMemberHelpers(t *testing.T) {
_, err = RemoveEtcdMember(client1, uint64(etcd2.Server.ID()))
re.NoError(err)

listResp3, err := ListEtcdMembers(client1.Ctx(), client1)
listResp3, err := ListEtcdMembers(client1)
re.NoError(err)
re.Len(listResp3.Members, 1)
re.Equal(uint64(etcd1.Server.ID()), listResp3.Members[0].ID)
Expand Down Expand Up @@ -266,7 +266,7 @@ func TestEtcdClientSync(t *testing.T) {
etcd1.Close()

// Check the client can get the new member with the new endpoints.
listResp3, err := ListEtcdMembers(client1.Ctx(), client1)
listResp3, err := ListEtcdMembers(client1)
re.NoError(err)
re.Len(listResp3.Members, 1)
re.Equal(uint64(etcd2.Server.ID()), listResp3.Members[0].ID)
Expand Down Expand Up @@ -386,7 +386,7 @@ func checkAddEtcdMember(t *testing.T, cfg1 *embed.Config, client *clientv3.Clien

func checkMembers(re *require.Assertions, client *clientv3.Client, etcds []*embed.Etcd) {
// Check the client can get the new member.
listResp, err := ListEtcdMembers(client.Ctx(), client)
listResp, err := ListEtcdMembers(client)
re.NoError(err)
re.Len(listResp.Members, len(etcds))
inList := func(m *etcdserverpb.Member) bool {
Expand Down
2 changes: 1 addition & 1 deletion server/api/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func newHealthHandler(svr *server.Server, rd *render.Render) *healthHandler {
// @Router /health [get]
func (h *healthHandler) GetHealthStatus(w http.ResponseWriter, r *http.Request) {
client := h.svr.GetClient()
members, err := cluster.GetMembers(r.Context(), client)
members, err := cluster.GetMembers(client)
if err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
Expand Down
6 changes: 3 additions & 3 deletions server/api/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (h *memberHandler) DeleteMemberByName(w http.ResponseWriter, r *http.Reques
// Get etcd ID by name.
var id uint64
name := mux.Vars(r)["name"]
listResp, err := etcdutil.ListEtcdMembers(r.Context(), client)
listResp, err := etcdutil.ListEtcdMembers(client)
if err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
Expand Down Expand Up @@ -287,7 +287,7 @@ func (h *leaderHandler) GetLeader(w http.ResponseWriter, r *http.Request) {
// @Failure 500 {string} string "PD server failed to proceed the request."
// @Router /leader/resign [post]
func (h *leaderHandler) ResignLeader(w http.ResponseWriter, r *http.Request) {
err := h.svr.GetMember().ResignEtcdLeader(r.Context(), h.svr.Name(), "")
err := h.svr.GetMember().ResignEtcdLeader(h.svr.Context(), h.svr.Name(), "")
if err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
Expand All @@ -304,7 +304,7 @@ func (h *leaderHandler) ResignLeader(w http.ResponseWriter, r *http.Request) {
// @Failure 500 {string} string "PD server failed to proceed the request."
// @Router /leader/transfer/{nextLeader} [post]
func (h *leaderHandler) TransferLeader(w http.ResponseWriter, r *http.Request) {
err := h.svr.GetMember().ResignEtcdLeader(r.Context(), h.svr.Name(), mux.Vars(r)["next_leader"])
err := h.svr.GetMember().ResignEtcdLeader(h.svr.Context(), h.svr.Name(), mux.Vars(r)["next_leader"])
if err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
return
Expand Down
8 changes: 4 additions & 4 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2120,7 +2120,7 @@ func (c *RaftCluster) resetClusterMetrics() {
}

func (c *RaftCluster) collectHealthStatus() {
members, err := GetMembers(c.etcdClient.Ctx(), c.etcdClient)
members, err := GetMembers(c.etcdClient)
if err != nil {
log.Error("get members error", errs.ZapError(err))
}
Expand Down Expand Up @@ -2672,8 +2672,8 @@ func CheckHealth(client *http.Client, members []*pdpb.Member) map[uint64]*pdpb.M
}

// GetMembers return a slice of Members.
func GetMembers(ctx context.Context, etcdClient *clientv3.Client) ([]*pdpb.Member, error) {
listResp, err := etcdutil.ListEtcdMembers(ctx, etcdClient)
func GetMembers(etcdClient *clientv3.Client) ([]*pdpb.Member, error) {
listResp, err := etcdutil.ListEtcdMembers(etcdClient)
if err != nil {
return nil, err
}
Expand All @@ -2694,7 +2694,7 @@ func GetMembers(ctx context.Context, etcdClient *clientv3.Client) ([]*pdpb.Membe

// IsClientURL returns whether addr is a ClientUrl of any member.
func IsClientURL(addr string, etcdClient *clientv3.Client) bool {
members, err := GetMembers(etcdClient.Ctx(), etcdClient)
members, err := GetMembers(etcdClient)
if err != nil {
return false
}
Expand Down
4 changes: 2 additions & 2 deletions server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (s *GrpcServer) GetClusterInfo(ctx context.Context, _ *pdpb.GetClusterInfoR
}

// GetMembers implements gRPC PDServer.
func (s *GrpcServer) GetMembers(ctx context.Context, _ *pdpb.GetMembersRequest) (*pdpb.GetMembersResponse, error) {
func (s *GrpcServer) GetMembers(context.Context, *pdpb.GetMembersRequest) (*pdpb.GetMembersResponse, error) {
// Here we purposely do not check the cluster ID because the client does not know the correct cluster ID
// at startup and needs to get the cluster ID with the first request (i.e. GetMembers).
if s.IsClosed() {
Expand All @@ -139,7 +139,7 @@ func (s *GrpcServer) GetMembers(ctx context.Context, _ *pdpb.GetMembersRequest)
},
}, nil
}
members, err := cluster.GetMembers(ctx, s.GetClient())
members, err := cluster.GetMembers(s.GetClient())
if err != nil {
return &pdpb.GetMembersResponse{
Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, err.Error()),
Expand Down
4 changes: 2 additions & 2 deletions server/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func PrepareJoinCluster(cfg *config.Config) error {
}
defer client.Close()

listResp, err := etcdutil.ListEtcdMembers(client.Ctx(), client)
listResp, err := etcdutil.ListEtcdMembers(client)
if err != nil {
return err
}
Expand Down Expand Up @@ -171,7 +171,7 @@ func PrepareJoinCluster(cfg *config.Config) error {
)

for i := 0; i < listMemberRetryTimes; i++ {
listResp, err = etcdutil.ListEtcdMembers(client.Ctx(), client)
listResp, err = etcdutil.ListEtcdMembers(client)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (s *Server) startEtcd(ctx context.Context) error {
}

// update advertise peer urls.
etcdMembers, err := etcdutil.ListEtcdMembers(newCtx, s.client)
etcdMembers, err := etcdutil.ListEtcdMembers(s.client)
if err != nil {
return err
}
Expand Down Expand Up @@ -872,7 +872,7 @@ func (s *Server) GetMembers() ([]*pdpb.Member, error) {
if s.IsClosed() {
return nil, errs.ErrServerNotStarted.FastGenByArgs()
}
return cluster.GetMembers(s.GetClient().Ctx(), s.GetClient())
return cluster.GetMembers(s.GetClient())
}

// GetServiceMiddlewareConfig gets the service middleware config information.
Expand Down
2 changes: 1 addition & 1 deletion tests/pdctl/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestHealth(t *testing.T) {
defer tc.Destroy()

client := tc.GetEtcdClient()
members, err := cluster.GetMembers(client.Ctx(), client)
members, err := cluster.GetMembers(client)
re.NoError(err)
healthMembers := cluster.CheckHealth(tc.GetHTTPClient(), members)
healths := []api.Health{}
Expand Down
6 changes: 3 additions & 3 deletions tests/pdctl/member/member_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ func TestMember(t *testing.T) {
// member delete name <member_name>
err = svr.Destroy()
re.NoError(err)
members, err := etcdutil.ListEtcdMembers(client.Ctx(), client)
members, err := etcdutil.ListEtcdMembers(client)
re.NoError(err)
re.Len(members.Members, 3)
args = []string{"-u", pdAddr, "member", "delete", "name", name}
_, err = pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
testutil.Eventually(re, func() bool {
members, err = etcdutil.ListEtcdMembers(client.Ctx(), client)
members, err = etcdutil.ListEtcdMembers(client)
re.NoError(err)
return len(members.Members) == 2
})
Expand All @@ -104,7 +104,7 @@ func TestMember(t *testing.T) {
_, err = pdctl.ExecuteCommand(cmd, args...)
re.NoError(err)
testutil.Eventually(re, func() bool {
members, err = etcdutil.ListEtcdMembers(client.Ctx(), client)
members, err = etcdutil.ListEtcdMembers(client)
re.NoError(err)
return len(members.Members) == 2
})
Expand Down
10 changes: 5 additions & 5 deletions tests/server/join/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestSimpleJoin(t *testing.T) {

pd1 := cluster.GetServer("pd1")
client := pd1.GetEtcdClient()
members, err := etcdutil.ListEtcdMembers(client.Ctx(), client)
members, err := etcdutil.ListEtcdMembers(client)
re.NoError(err)
re.Len(members.Members, 1)

Expand All @@ -58,7 +58,7 @@ func TestSimpleJoin(t *testing.T) {
re.NoError(err)
_, err = os.Stat(path.Join(pd2.GetConfig().DataDir, "join"))
re.False(os.IsNotExist(err))
members, err = etcdutil.ListEtcdMembers(client.Ctx(), client)
members, err = etcdutil.ListEtcdMembers(client)
re.NoError(err)
re.Len(members.Members, 2)
re.Equal(pd1.GetClusterID(), pd2.GetClusterID())
Expand All @@ -73,7 +73,7 @@ func TestSimpleJoin(t *testing.T) {
re.NoError(err)
_, err = os.Stat(path.Join(pd3.GetConfig().DataDir, "join"))
re.False(os.IsNotExist(err))
members, err = etcdutil.ListEtcdMembers(client.Ctx(), client)
members, err = etcdutil.ListEtcdMembers(client)
re.NoError(err)
re.Len(members.Members, 3)
re.Equal(pd1.GetClusterID(), pd3.GetClusterID())
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestFailedAndDeletedPDJoinsPreviousCluster(t *testing.T) {
res := cluster.RunServer(pd3)
re.Error(<-res)

members, err := etcdutil.ListEtcdMembers(client.Ctx(), client)
members, err := etcdutil.ListEtcdMembers(client)
re.NoError(err)
re.Len(members.Members, 2)
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestDeletedPDJoinsPreviousCluster(t *testing.T) {
res := cluster.RunServer(pd3)
re.Error(<-res)

members, err := etcdutil.ListEtcdMembers(client.Ctx(), client)
members, err := etcdutil.ListEtcdMembers(client)
re.NoError(err)
re.Len(members.Members, 2)
}
Expand Down

0 comments on commit 2581d64

Please sign in to comment.