-
Notifications
You must be signed in to change notification settings - Fork 774
mcs: use the configured lease for the service registry #11017
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 all commits
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 |
|---|---|---|
|
|
@@ -104,6 +104,11 @@ type server interface { | |
| diagnosticspb.DiagnosticsServer | ||
| StartTimestamp() int64 | ||
| Name() string | ||
| // GetLeaderLease returns the configured leader lease in seconds. It is | ||
| // reused as the service registry lease TTL. Services without a lease | ||
| // config should return 0, in which case discovery.DefaultLeaseInSeconds | ||
| // is used. | ||
| GetLeaderLease() int64 | ||
| } | ||
|
|
||
| // InitClient initializes the etcd and http clients. | ||
|
|
@@ -295,9 +300,12 @@ func Register(s server, serviceName string) (*discovery.ServiceRegistryEntry, *d | |
| if err != nil { | ||
| return nil, nil, err | ||
| } | ||
| // Reuse the configured leader lease as the registry lease TTL, but never | ||
| // go below discovery.DefaultLeaseInSeconds to keep the registry entry | ||
| // stable. | ||
| lease := max(s.GetLeaderLease(), discovery.DefaultLeaseInSeconds) | ||
|
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 introduces another behavior change that is not covered by the PR description: the registry contains all service instances, not only the primary. Therefore, increasing the registry TTL also delays removal of crashed followers. For example, with
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. Thanks for addressing the retry interval and deregistration timeout. Could you clarify whether the longer failure-detection window is an intentional tradeoff here? I verified it on the latest head with a small embedded-etcd test using the actual
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. Using the leader lease here also extends the registry TTL for followers. A crashed high-priority TSO follower may remain discoverable and cause the healthy primary to transfer leadership to an offline node. Please keep follower discovery liveness independent from the leader lease. |
||
| serviceRegister := discovery.NewServiceRegister(s.Context(), s.GetEtcdClient(), | ||
| serviceName, s.GetAdvertiseListenAddr(), serializedEntry, | ||
| discovery.DefaultLeaseInSeconds) | ||
| serviceName, s.GetAdvertiseListenAddr(), serializedEntry, lease) | ||
|
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 value also becomes the timeout in |
||
| if err := serviceRegister.Register(); err != nil { | ||
| log.Error("failed to register the service", zap.String("service-name", serviceName), errs.ZapError(err)) | ||
| return nil, nil, err | ||
|
|
||
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.
Using the leader TTL here also changes
ServiceRegister.renewKeepalive, which waitsttl/2before its first re-registration attempt. Withlease = 60, an expired registry entry remains absent for another 30 seconds, potentially prolonging the healthy-primary eviction this change is intended to prevent. Please retry immediately or use a capped, TTL-independent backoff.