Skip to content

Update follower read and learner read descriptions #21470

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zyguan
Copy link
Contributor

@zyguan zyguan commented Jul 29, 2025

First-time contributors' checklist

What is changed, added or deleted? (Required)

The description of follower-read and learner-read is inaccurate, and related behaviors have been adjusted in the newer version of tidb, so the corresponding documentation has been revised accordingly.

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)
  • v6.1 (TiDB 6.1 versions)
  • v5.4 (TiDB 5.4 versions)

What is the related PR or file link(s)?

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

@ti-chi-bot ti-chi-bot bot added missing-translation-status This PR does not have translation status info. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 29, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @zyguan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates the documentation for TiDB's tidb_replica_read system variable, specifically clarifying the behavior of follower and learner read modes. The changes reflect recent adjustments in TiDB's replica reading logic and provide important version-specific details for older releases to ensure the documentation is accurate and up-to-date.

Highlights

  • follower read mode behavior: The description for tidb_replica_read set to follower has been updated. It now clarifies that TiDB also considers reading from learner replicas with equal priority, and if no follower or learner replicas are available, it will fall back to reading from the leader replica.
  • learner read mode behavior: The description for tidb_replica_read set to learner has been revised. Previously, it stated that an error would be returned if no learner replica was available; now, it clarifies that TiDB will attempt to read from available leader or follower replicas in such cases.
  • Version-specific notes: A new note has been added to specify the behavior for TiDB versions up to and including v7.5, detailing that follower and learner read modes would return an error if no appropriate replicas were available, contrasting with the newer fallback behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

ti-chi-bot bot commented Jul 29, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lilin90 for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the documentation for follower and learner reads to reflect new behaviors in recent TiDB versions. The changes clarify that when tidb_replica_read is set to follower or learner, TiDB will now fall back to other replica types if the preferred type is unavailable, instead of returning an error. My review includes suggestions to improve clarity and conciseness, and to align the text with the documentation style guide. The style guide elements referenced in this review include clarity, simplicity, readability, present tense, and second person.

@@ -33,7 +33,7 @@ Default: leader
This variable is used to set the expected data read mode.

- When the value of `tidb_replica_read` is set to `leader` or an empty string, TiDB maintains its default behavior and sends all read operations to the leader replica to perform.
- When the value of `tidb_replica_read` is set to `follower`, TiDB selects a follower replica of the Region to perform all read operations.
- When the value of `tidb_replica_read` is set to `follower`, TiDB selects a follower replica of the Region to perform all read operations. When a Region has learner replicas, TiDB also considers reading data from learner replicas. In this case, follower replicas and learner replicas have the same priority. If there are no available follower or learner replicas in the current Region, TiDB will read from the leader replica.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

For better readability and conciseness, combine the sentences describing the behavior for follower reads. This makes the logic easier to follow.12

Style Guide References

Suggested change
- When the value of `tidb_replica_read` is set to `follower`, TiDB selects a follower replica of the Region to perform all read operations. When a Region has learner replicas, TiDB also considers reading data from learner replicas. In this case, follower replicas and learner replicas have the same priority. If there are no available follower or learner replicas in the current Region, TiDB will read from the leader replica.
- When the value of `tidb_replica_read` is set to `follower`, TiDB selects a follower replica of the Region to perform read operations. If the Region has learner replicas, TiDB also considers them for reads with the same priority. If no available follower or learner replicas exist in the current Region, TiDB reads from the leader replica.

Footnotes

  1. The style guide emphasizes clarity, simplicity, completeness, and readability. (link)

  2. The style guide recommends avoiding unnecessary words and repetition. (link)

@@ -42,13 +42,18 @@ This variable is used to set the expected data read mode.
- If the estimated result of a read request is greater than or equal to the value of [`tidb_adaptive_closest_read_threshold`](/system-variables.md#tidb_adaptive_closest_read_threshold-new-in-v630), TiDB prefers to select a replica in the same availability zone for read operations. To avoid unbalanced distribution of read traffic across availability zones, TiDB dynamically detects the distribution of availability zones for all online TiDB and TiKV nodes. In each availability zone, the number of TiDB nodes whose `closest-adaptive` configuration takes effect is limited, which is always the same as the number of TiDB nodes in the availability zone with the fewest TiDB nodes, and the other TiDB nodes automatically read from the leader replica. For example, if TiDB nodes are distributed across 3 availability zones (A, B, and C), where A and B each contains 3 TiDB nodes and C contains only 2 TiDB nodes, the number of TiDB nodes whose `closest-adaptive` configuration takes effect in each availability zone is 2, and the other TiDB node in each of the A and B availability zones automatically selects the leader replica for read operations.
- If the estimated result of a read request is less than the value of [`tidb_adaptive_closest_read_threshold`](/system-variables.md#tidb_adaptive_closest_read_threshold-new-in-v630), TiDB can only select the leader replica for read operations.

- When the value of `tidb_replica_read` is set to `learner`, TiDB reads data from the learner replica. If there is no learner replica in the Region, TiDB returns an error.
- When the value of `tidb_replica_read` is set to `learner`, TiDB reads data from the learner replica. If there is no available learner replica in the Region, TiDB will read data from available leader or follower replicas.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

To improve clarity and adhere to the style guide's preference for present tense, rephrase this sentence to be more direct and concise.12

Style Guide References

Suggested change
- When the value of `tidb_replica_read` is set to `learner`, TiDB reads data from the learner replica. If there is no available learner replica in the Region, TiDB will read data from available leader or follower replicas.
- When the value of `tidb_replica_read` is set to `learner`, TiDB reads data from the learner replica. If no learner replica is available in the Region, TiDB reads from an available leader or follower replica.

Footnotes

  1. The style guide emphasizes clarity, simplicity, completeness, and readability. (link)

  2. The style guide recommends using the present tense unless describing historical behavior. (link)

Comment on lines +55 to +56
> - When the value of `tidb_replica_read` is set to `follower` and no follower or learner replicas are available, TiDB returns an error.
> - When the value of `tidb_replica_read` is set to `learner` and no learner replicas are available, TiDB returns an error.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

To align with the style guide's recommendation of using the second person ("you"), rephrase these points. This makes the documentation more user-centric.1

Style Guide References

Suggested change
> - When the value of `tidb_replica_read` is set to `follower` and no follower or learner replicas are available, TiDB returns an error.
> - When the value of `tidb_replica_read` is set to `learner` and no learner replicas are available, TiDB returns an error.
- If you set `tidb_replica_read` to `follower` and no follower or learner replicas are available, TiDB returns an error.
- If you set `tidb_replica_read` to `learner` and no learner replicas are available, TiDB returns an error.

Footnotes

  1. The style guide recommends writing in the second person ("you") when addressing users. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing-translation-status This PR does not have translation status info. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant