-
Notifications
You must be signed in to change notification settings - Fork 766
server, config: support updating leader lease online #10631
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
8834eea
6459a2c
b42ab1d
fef4d94
b95a776
5e0d188
a0226b0
3559834
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 |
|---|---|---|
|
|
@@ -1013,6 +1013,7 @@ func (s *Server) GetServiceMiddlewareConfig() *config.ServiceMiddlewareConfig { | |
| // GetConfig gets the config information. | ||
| func (s *Server) GetConfig() *config.Config { | ||
| cfg := s.cfg.Clone() | ||
| cfg.LeaderLease = s.persistOptions.GetLeaderLease() | ||
|
Member
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 keeps the leader response fresh, but follower
Member
Author
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. Fixed in c334f2830 by copying LeaderLease from the leader config in the follower GET /config merge path. |
||
| cfg.Schedule = *s.persistOptions.GetScheduleConfig().Clone() | ||
| cfg.Replication = *s.persistOptions.GetReplicationConfig().Clone() | ||
| cfg.PDServerCfg = *s.persistOptions.GetPDServerConfig().Clone() | ||
|
|
@@ -1356,6 +1357,25 @@ func (s *Server) SetPDServerConfig(cfg config.PDServerConfig) error { | |
| return nil | ||
| } | ||
|
|
||
| // SetLeaderLease sets the PD leader lease timeout. | ||
| func (s *Server) SetLeaderLease(lease int64) error { | ||
| if !config.IsValidLeaderLease(lease) { | ||
| return errors.Errorf("leader lease must be positive, got %d", lease) | ||
| } | ||
| old := s.persistOptions.GetLeaderLease() | ||
| s.persistOptions.SetLeaderLease(lease) | ||
| if err := s.persistOptions.Persist(s.storage); err != nil { | ||
| s.persistOptions.SetLeaderLease(old) | ||
| log.Error("failed to update leader lease", | ||
| zap.Int64("new", lease), | ||
| zap.Int64("old", old), | ||
| errs.ZapError(err)) | ||
| return err | ||
| } | ||
| log.Info("leader lease is updated", zap.Int64("new", lease), zap.Int64("old", old)) | ||
| return nil | ||
| } | ||
|
|
||
| // SetLabelPropertyConfig sets the label property config. | ||
| func (s *Server) SetLabelPropertyConfig(cfg config.LabelPropertyConfig) error { | ||
| old := s.persistOptions.GetLabelPropertyConfig() | ||
|
|
@@ -1737,7 +1757,13 @@ func (s *Server) leaderLoop() { | |
|
|
||
| func (s *Server) campaignLeader() { | ||
| log.Info("start to campaign PD leader", zap.String("campaign-leader-name", s.Name())) | ||
| if err := s.member.Campaign(s.ctx, s.cfg.LeaderLease); err != nil { | ||
| if err := s.persistOptions.Reload(s.storage); err != nil { | ||
| log.Warn("failed to reload persisted configuration before campaign", | ||
| errs.ZapError(err), | ||
| zap.String("campaign-leader-name", s.Name())) | ||
| return | ||
| } | ||
| if err := s.member.Campaign(s.ctx, s.persistOptions.GetLeaderLease()); err != nil { | ||
| if err.Error() == errs.ErrEtcdTxnConflict.Error() { | ||
| log.Info("campaign PD leader meets error due to txn conflict, another PD may campaign successfully", | ||
| zap.String("campaign-leader-name", s.Name())) | ||
|
|
@@ -1770,12 +1796,12 @@ func (s *Server) campaignLeader() { | |
| keepLeaderDuration := time.Since(keepLeaderStart) | ||
| log.Info("keep leader lease completed", zap.Duration("cost", keepLeaderDuration), zap.String("campaign-leader-name", s.Name())) | ||
|
|
||
| reloadConfigStart := time.Now() | ||
| postKeepReloadStart := time.Now() | ||
| if err := s.reloadConfigFromKV(); err != nil { | ||
| log.Warn("failed to reload configuration", errs.ZapError(err), zap.Duration("cost", time.Since(reloadConfigStart))) | ||
| log.Warn("failed to reload configuration", errs.ZapError(err), zap.Duration("cost", time.Since(postKeepReloadStart))) | ||
| return | ||
| } | ||
| reloadConfigDuration := time.Since(reloadConfigStart) | ||
| reloadConfigDuration := time.Since(postKeepReloadStart) | ||
| log.Info("reload config from KV completed", zap.Duration("cost", reloadConfigDuration)) | ||
|
|
||
| loadTTLStart := time.Now() | ||
|
|
@@ -2230,7 +2256,7 @@ func (s *Server) GetTSOProxyRecvFromClientTimeout() time.Duration { | |
|
|
||
| // GetLease returns the leader lease. | ||
| func (s *Server) GetLease() int64 { | ||
| return s.cfg.GetLease() | ||
| return s.persistOptions.GetLeaderLease() | ||
| } | ||
|
|
||
| // GetTSOSaveInterval returns TSO save interval. | ||
|
|
||
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.
Please consider version-gating this API until all PD members understand the persisted lease. During rolling upgrade, an old PD can still persist
lease: 0in the config blob, which makes the new code ignore the online value and fall back to local toml on the next campaign.