-
Notifications
You must be signed in to change notification settings - Fork 720
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
client: print more info when leader disconnect #7907
base: master
Are you sure you want to change the base?
Changes from all commits
fdc5578
3cb6185
79dc489
1aaf5c8
4de33c2
165a51c
80ac87f
6119ca3
6700333
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -991,30 +991,46 @@ | |
log.Info("[pd] update member urls", zap.Strings("old-urls", oldURLs), zap.Strings("new-urls", urls)) | ||
} | ||
|
||
func (c *pdServiceDiscovery) switchLeader(url string) (bool, error) { | ||
// switchLeader switches the leader of the PD cluster. | ||
// Note: For current implementation, when initializing the client, the connection to leader should be established. | ||
// Otherwise, the initialization will fail. | ||
func (c *pdServiceDiscovery) switchLeader(url string) (change bool, err error) { | ||
oldLeader := c.getLeaderServiceClient() | ||
if url == oldLeader.GetURL() && oldLeader.GetClientConn() != nil { | ||
return false, nil | ||
} | ||
|
||
newConn, err := c.GetOrCreateGRPCConn(url) | ||
var newConn *grpc.ClientConn | ||
newConn, err = c.GetOrCreateGRPCConn(url) | ||
// If gRPC connect is created successfully or leader is new, still saves. | ||
if url != oldLeader.GetURL() || newConn != nil { | ||
if url != oldLeader.GetURL() { | ||
change = true | ||
Comment on lines
+1006
to
+1007
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This check and introducing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the client continues to fail to establish a connection with the leader, there will be situations where |
||
log.Info("[pd] switch leader", zap.String("new-leader", url), zap.String("old-leader", oldLeader.GetURL())) | ||
} | ||
if err == nil { | ||
change = true | ||
log.Info("[pd] successfully connected to leader", zap.String("leader", url)) | ||
} else { | ||
log.Warn("[pd] failed to connect leader", zap.String("leader", url), errs.ZapError(err)) | ||
} | ||
if change { | ||
// Set PD leader and Global TSO Allocator (which is also the PD leader) | ||
// Note: Even if the connection is not established, the leader is still updated. | ||
// The reason is that the leader has transferred to another PD server, and the client should | ||
// update the member information. Meanwhile, the client must know the newest leader for follower proxy. | ||
leaderClient := newPDServiceClient(url, url, newConn, true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even if the connection is not established, the leader is still updated. |
||
c.leader.Store(leaderClient) | ||
} | ||
// Run callbacks | ||
if c.tsoGlobalAllocLeaderUpdatedCb != nil { | ||
if err := c.tsoGlobalAllocLeaderUpdatedCb(url); err != nil { | ||
return true, err | ||
// Run callbacks | ||
if c.tsoGlobalAllocLeaderUpdatedCb != nil { | ||
if err := c.tsoGlobalAllocLeaderUpdatedCb(url); err != nil { | ||
return change, err | ||
} | ||
} | ||
for _, cb := range c.leaderSwitchedCbs { | ||
cb() | ||
} | ||
} | ||
for _, cb := range c.leaderSwitchedCbs { | ||
cb() | ||
} | ||
log.Info("[pd] switch leader", zap.String("new-leader", url), zap.String("old-leader", oldLeader.GetURL())) | ||
return true, err | ||
return | ||
} | ||
|
||
func (c *pdServiceDiscovery) updateFollowers(members []*pdpb.Member, leaderID uint64, leaderURL string) (changed bool) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might fail to connect to the leader?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the leader does change and it will affect the follower proxy