Is it possible to execute SQL on the primary node or primary shard?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 可以指定到主节点或主分片上执行SQL吗?

| username: TiDBer_E1Wsk2fd

[TiDB Usage Environment] Production Environment
[TiDB Version] v5.3.0
[Reproduction Path] Successfully update a piece of data in the current thread, then after a 9ms interval, the MQ message processing will query the previously updated data and find that it cannot be found.
[Encountered Problem: Problem Phenomenon and Impact] Is it caused by replication delay? Can we force reading data from the primary shard?

| username: h5n1 | Original post link

Is this querying the previously updated data in the same session? Could you describe it in more detail? By default, TiDB read and write operations occur on the region leader node, which is the primary shard. If you enable something like follower read, it will read data from other replicas.

| username: 我是咖啡哥 | Original post link

By default, read and write operations are performed on the leader node.
Are you using multiple threads and multiple transactions? The updated data might not have been committed yet, so other transactions haven’t been able to retrieve it?

| username: TiDBer_E1Wsk2fd | Original post link

  1. They are not in the same session because the latter thread consumes messages from the MQ and then queries the database.
| username: TiDBer_E1Wsk2fd | Original post link

  1. The request thread and the MQ consumption thread are not the same.
  2. According to your idea, I will confirm with the development team whether the transaction was not committed but the MQ was sent out. In this case, the transaction cannot be queried during consumption because they are not the same transaction, and consistency in reading cannot be guaranteed.
| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.