tikv / tikv/pd

[Performance] Leader Election Slow - No Caching of Cluster State

Open
#10,785 1 comment 0 reactions 0 assignees View on GitHub
contribution needs-type
Dominant language
Go
Stars
1.2k
Forks
783
Avg merge
5d 21h
Merged PRs (30d)
36

Description

## Description
Leader election is slow due to missing caching of cluster state. Every election queries database for full cluster state without caching, causing unnecessary latency during leadership transitions.

## Steps to Reproduce
1. PD cluster detects leader failure
2. Initiates leader election process
3. Queries full cluster state for each candidate
4. No caching of state information
5. Election takes 2-3 seconds instead of <100ms

## Environment Information
- System: PD leader election
- Query: Cluster topology and state
- Caching: Not implemented
- Frequency: On every election

## Expected Behavior
- Cluster state cached locally
- Cache invalidated on topology changes
- Leader election <100ms
- Background cache refresh

## Actual Behavior
- No caching of state
- Full query for every election
- 2-3 second election time
- Impact on availability

## Code Reference
- File: `server/election.go`
- Method: `electLeader()` - no state caching
- Missing: Local state cache
- Missing: Cache invalidation logic

## Additional Context
Level 2 performance issue. Fix requires:
- Implementing cluster state cache
- Cache invalidation on topology changes
- Incremental updates
- Performance benchmarking

## Suggested Labels
`performance`, `optimization`, `caching`, `leader-election`, `availability`

Contributor guide

Open the contributing guide

Research direction

Start in server/election.go at electLeader() and trace how full cluster state is queried during leader election. Define the cache, topology-change invalidation, incremental updates, and background refresh from the issue requirements, then add performance benchmarks to verify election time falls below 100ms.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
distributed-systems, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.