This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
dm-master: leader election #367
Merged
csuzhangxc
merged 20 commits into
pingcap:master
from
csuzhangxc:master-leader-election
Nov 26, 2019
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1464ce3
*: add etcd leader election
csuzhangxc e7e0ad9
*: support get member's ID and leader's ID
csuzhangxc 45e8d3b
election: add election test case; refine code
csuzhangxc 1d0b22d
election: fix key watch; add more tests
csuzhangxc bc54f9d
Merge branch 'master' into master-leader-election
csuzhangxc ede2549
election: add more tests
csuzhangxc 792b41c
*: extract CreateClient for etcd
csuzhangxc 3179fc3
master: elect leader when starting
csuzhangxc 1d47595
Merge remote-tracking branch 'origin/master-leader-election' into mas…
csuzhangxc 7d45b14
election: add some log
csuzhangxc 12385f3
election: remove useless code
csuzhangxc d2059a6
*: fix CI
csuzhangxc f2540ef
election: refactor leader notify API
csuzhangxc 89b753c
master: update election usage
csuzhangxc dbb87d0
tests: update others_integration.txt to match the CI
csuzhangxc 80ae3d2
*: address comment
csuzhangxc 5c4c820
*: address comment
csuzhangxc b99ae46
election: address comments
csuzhangxc 708c2c1
*: address comments
csuzhangxc 93f6b07
Merge remote-tracking branch 'remotes/origin/master' into master-lead…
csuzhangxc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package master | ||
|
||
import ( | ||
"context" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/pingcap/dm/pkg/log" | ||
) | ||
|
||
func (s *Server) electionNotify(ctx context.Context) { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case leader := <-s.election.LeaderNotify(): | ||
// output the leader info. | ||
if leader { | ||
log.L().Info("current member become the leader", zap.String("current member", s.cfg.Name)) | ||
} else { | ||
_, leaderID, err2 := s.election.LeaderInfo(ctx) | ||
if err2 == nil { | ||
log.L().Info("current member retire from the leader", zap.String("leader", leaderID), zap.String("current member", s.cfg.Name)) | ||
} else { | ||
log.L().Error("get leader info", zap.Error(err2)) | ||
amyangfei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
case err := <-s.election.ErrorNotify(): | ||
// handle errors here, we do no meaningful things now. | ||
// but maybe: | ||
// 1. trigger an alert | ||
// 2. shutdown the DM-master process | ||
log.L().Error("receive error from election", zap.Error(err)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
why need this function, seems
toBeLeader
andretireLeader
already print the logThere 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.
toBeLeader
andretireLeader
only log the leadership of the current member.this function is used to show the usage of
Election
(and also log the leader name even if it's not the current member), do you think should we need to remove it?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.
one more thing,
pkg/election
is a pkg, but this function is in the application. Maybe we need to add some metrics for the leadership later, and do that in this function is better.so, how about removing the log in
pkg/election
?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.
if master needs to do something(for example: meet error in the election, master exit) according to the election's result I think putting here is better.
it is up to you
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.
I chose to remove the log in
pkg/election
in b99ae46.