tikv / tikv/pd

mcs: use the configured lease for the service registry instead of a fixed value

Open
#11,016 0 comments 0 reactions 0 assignees View on GitHub
type/enhancement
Dominant language
Go
Stars
1.2k
Forks
783
Avg merge
5d 21h
Merged PRs (30d)
36

Description

## Enhancement Task

### Background

When a microservice (TSO / Scheduling / Resource Manager / Router) registers itself into the service registry via `discovery.Register`, the registry lease TTL is hardcoded to `discovery.DefaultLeaseInSeconds` (5s):

```go
serviceRegister := discovery.NewServiceRegister(s.Context(), s.GetEtcdClient(),
serviceName, s.GetAdvertiseListenAddr(), serializedEntry,
discovery.DefaultLeaseInSeconds)
```

Each of these services already exposes a configurable `lease` (`LeaderLease`, toml key `lease`, default `constant.DefaultLease = 5`), used for the primary/leader election. The registry lease, however, stays fixed and ignores it.

### Problem

When the configured leader lease is larger than the fixed registry lease (`config lease > DefaultLeaseInSeconds`), the two leases expire on different timescales. Under network jitter or etcd pressure the shorter **registry** lease can fail/expire first, while the longer **leader/primary** lease is still held.

As a result, the PD server evicts the node whose registry lease has lapsed even though it still legitimately holds its primary lease. This tears down a healthy primary, causing the primary lease to fail — a self-inflicted failover that would not happen if the registry lease were at least as long as the configured lease.

### Proposal

Reuse the configured leader lease as the registry lease TTL, with `discovery.DefaultLeaseInSeconds` as a lower bound so the registry entry never expires faster than the current default:

- Add `GetLeaderLease() int64` to the `server` interface in `pkg/mcs/utils/util.go`.
- In `Register`, use `lease := max(s.GetLeaderLease(), discovery.DefaultLeaseInSeconds)`.
- Each service returns its configured lease; the Router service has no lease config and returns `0`, so it falls back to the default.

### Scope

- Only the **register lease** path is affected. The primary/leader election lease is unchanged.
- Backward compatible: all lease-bearing configs default to `5`, so `max(5, 5) = 5` keeps current behavior; only an explicitly configured larger `lease` changes the registry TTL.

Contributor guide

Open the contributing guide

Research direction

Start in pkg/mcs/utils/util.go and trace the Register path that constructs discovery.NewServiceRegister. Check how TSO, Scheduling, Resource Manager, and Router expose their lease settings, then verify the registry TTL uses the configured lease with discovery.DefaultLeaseInSeconds as the lower bound. Done means larger configured leases are honored while Router and default-5 configurations retain the existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, distributed-systems
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.