Learner replicas used for queries when not specified
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Queries are incorrectly routed to TiKV learner replicas when the session variable tidb_replica_read is set to 'follower'. The expected behavior is for queries to only be directed to follower or leader replicas, completely avoiding learners. This issue was observed in TiDB Community Edition v8.5.1.
### 1. Minimal reproduce step (Required)
- Create a secondary KV cluster with label $mode = readonly and other tags as needed
- Add placement rules for any table to add learner replicas on the new KVs
- Execute queries with session or global variable `tidb_replica_read = 'follower'`
### 2. What did you expect to see? (Required)
With `tidb_replica_read = 'follower'` the expected behavior is that KVs with learner replicas are not used at all.
### 3. What did you see instead (Required)
TiKV learner replicas are being used on queries that should only happen in followers or leaders.
A TiKV with only learner replicas:

### 4. What is your TiDB version? (Required)
Release Version: v8.5.1
Edition: Community
Git Commit Hash: fea86c8e35ad4a86a5e1160701f99493c2ee547c
Git Branch: HEAD
UTC Build Time: 2025-01-16 07:39:42
GoVersion: go1.23.4
Race Enabled: false
Check Table Before Drop: false
Store: tikv
Contributor guide
Assessment
This issue has not been assessed yet.