Skip to content

Commit

Permalink
*: use another etcd client for election (#6409) (#6454)
Browse files Browse the repository at this point in the history
ref #6403, ref #6409

Signed-off-by: ti-chi-bot <[email protected]>
Signed-off-by: Ryan Leung <[email protected]>

Co-authored-by: Ryan Leung <[email protected]>
Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored May 24, 2023
1 parent 91efbda commit d086bd5
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ type Server struct {
member *member.Member
// etcd client
client *clientv3.Client
// electionClient is used for leader election.
electionClient *clientv3.Client
// http client
httpClient *http.Client
clusterID uint64 // pd cluster id.
Expand Down Expand Up @@ -333,12 +335,18 @@ func (s *Server) startEtcd(ctx context.Context) error {

lgc := zap.NewProductionConfig()
lgc.Encoding = log.ZapEncodingName
client, err := clientv3.New(clientv3.Config{
clientConfig := clientv3.Config{
Endpoints: endpoints,
DialTimeout: etcdTimeout,
TLS: tlsConfig,
LogConfig: &lgc,
})
}
client, err := clientv3.New(clientConfig)
if err != nil {
return errs.ErrNewEtcdClient.Wrap(err).GenWithStackByCause()
}

s.electionClient, err = clientv3.New(clientConfig)
if err != nil {
return errs.ErrNewEtcdClient.Wrap(err).GenWithStackByCause()
}
Expand Down Expand Up @@ -370,7 +378,7 @@ func (s *Server) startEtcd(ctx context.Context) error {
failpoint.Inject("memberNil", func() {
time.Sleep(1500 * time.Millisecond)
})
s.member = member.NewMember(etcd, client, etcdServerID)
s.member = member.NewMember(etcd, s.electionClient, etcdServerID)
return nil
}

Expand Down Expand Up @@ -497,6 +505,11 @@ func (s *Server) Close() {
log.Error("close etcd client meet error", errs.ZapError(errs.ErrCloseEtcdClient, err))
}
}
if s.electionClient != nil {
if err := s.electionClient.Close(); err != nil {
log.Error("close election client meet error", errs.ZapError(errs.ErrCloseEtcdClient, err))
}
}

if s.httpClient != nil {
s.httpClient.CloseIdleConnections()
Expand Down

0 comments on commit d086bd5

Please sign in to comment.