Questions about Variable Scope Issues

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

Original topic: 变量作用域问题疑问

| username: 考试没答案

[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version]
[Reproduction Path] What operations were performed when the issue occurred
[Encountered Issue: Issue Phenomenon and Impact] Variable scope issue query
[Resource Configuration] Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachment: Screenshot/Logs/Monitoring]

| username: 考试没答案 | Original post link

How do you set this instance level???

| username: forever | Original post link

SET SESSION xxx= ‘xxx’;
This is at the instance level.

| username: Soysauce520 | Original post link

The cluster configuration under this link shows that they are also parameter variables. If you use set global to set them, you will find that it only affects one instance. For example, the default tidb_slow_log_threshold is 300. If you enter a TiDB server and set it to 1s, it will only take effect on this one TiDB server and will not synchronize to other TiDB servers.

| username: buddyyuan | Original post link

Some parameters are global but can take effect on individual instances. Are you referring to this type of parameter?

| username: zhanggame1 | Original post link

You must have misread the documentation. These are configuration file parameters, not variables. Variables are stored in TiKV.

| username: zhanggame1 | Original post link

I believe there are no instance-level variables. Instance-level settings are configured in each TiDB configuration file, but those are not variable configurations.

| username: 考试没答案 | Original post link

Yes, it is this type of parameter. It is probably not set through TiDB, but rather through commands like edit-config.

| username: buddyyuan | Original post link

Refer to the official documentation:

It contains the introduction of variables.
Persisted to the cluster: No, it only applies to the current TiDB instance connection.

| username: 考试没答案 | Original post link

—Setting the Scope of TiDB Variables

set session autocommit='off';   -- session level

set global autocommit='off';  -- global level

set config pd log.level='info';   -- cluster level configuration, can also be configured with edit-config

set config '192.168.2.22:2379' log.level='warning';   -- instance level configuration of cluster parameters, can also be configured with edit-config

global: Effective for new session connections, not effective for the current or already established sessions
session: Effective only in the current session
instance: Effective after the instance on the node restarts


It seems that this type of parameter is instance.tidb_slow_log_threshold

– For example

mysql -h192.168.2.22 -uroot -poracle -P4000
set global tidb_slow_log_threshold=1000;

mysql> show config where type='tidb' and name like '%tidb_slow_log_threshold%';
+------+-------------------+----------------------------------+-------+
| Type | Instance          | Name                             | Value |
+------+-------------------+----------------------------------+-------+
| tidb | 192.168.2.21:4000 | instance.tidb_slow_log_threshold | 300   |
| tidb | 192.168.2.23:4000 | instance.tidb_slow_log_threshold | 300   |
| tidb | 192.168.2.22:4000 | instance.tidb_slow_log_threshold | 1000  |
+------+-------------------+----------------------------------+-------+

Note: 300 is the default value. 1000 is the modified value.

– Cluster restart

mysql> show config where type='tidb' and name like '%tidb_slow_log_threshold%';
+------+-------------------+----------------------------------+-------+
| Type | Instance          | Name                             | Value |
+------+-------------------+----------------------------------+-------+
| tidb | 192.168.2.22:4000 | instance.tidb_slow_log_threshold | 300   |
| tidb | 192.168.2.23:4000 | instance.tidb_slow_log_threshold | 300   |
| tidb | 192.168.2.21:4000 | instance.tidb_slow_log_threshold | 300   |
+------+-------------------+----------------------------------+-------+

Note: After tiup cluster stop tpln_qa, the value reverts to the default value.

| username: ShawnYan | Original post link

You need to understand the basic concepts again. I also read it several times initially.

| username: 考试没答案 | Original post link

I have also gone through it several times. I have questions about the 303 video. The teacher hasn’t explained it yet!

| username: zhanggame1 | Original post link

My document clearly explains how to modify some parameters, such as changing the number of replicas.

| username: 这里介绍不了我 | Original post link

This is indeed worth watching several times.

| username: Kongdom | Original post link

:+1: Well summarized

| username: system | Original post link

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