Skip to content

Commit

Permalink
client: add connection state in log entry (tikv#2021) (tikv#2027)
Browse files Browse the repository at this point in the history
* client: add connection state in log entry

Signed-off-by: nolouch <nolouch@gmail.com>

* address comments

Signed-off-by: nolouch <nolouch@gmail.com>
  • Loading branch information
sre-bot authored and nolouch committed Dec 17, 2019
1 parent 55fd0e5 commit d1570bf
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func (c *client) updateLeader() error {
for _, u := range c.urls {
ctx, cancel := context.WithTimeout(c.ctx, updateLeaderTimeout)
members, err := c.getMembers(ctx, u)
if err != nil {
log.Warn("cannot update leader", zap.String("address", u), zap.Error(err))
}
cancel()
if err != nil || members.GetLeader() == nil || len(members.GetLeader().GetClientUrls()) == 0 {
select {
Expand All @@ -246,7 +249,8 @@ func (c *client) getMembers(ctx context.Context, url string) (*pdpb.GetMembersRe
}
members, err := pdpb.NewPDClient(cc).GetMembers(ctx, &pdpb.GetMembersRequest{})
if err != nil {
return nil, errors.WithStack(err)
attachErr := errors.Errorf("error:%s target:%s status:%s", err, cc.Target(), cc.GetState().String())
return nil, errors.WithStack(attachErr)
}
return members, nil
}
Expand Down Expand Up @@ -290,6 +294,7 @@ func (c *client) getOrCreateGRPCConn(addr string) (*grpc.ClientConn, error) {
defer c.connMu.Unlock()
if old, ok := c.connMu.clientConns[addr]; ok {
cc.Close()
log.Debug("use old connection", zap.String("target", cc.Target()), zap.String("state", cc.GetState().String()))
return old, nil
}

Expand Down

0 comments on commit d1570bf

Please sign in to comment.