pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
37.12k stars 5.83k forks source link

[proposal] use SQL to manage the TiDB-Binlog toolset #9201

Closed WangXiangUSTC closed 4 years ago

WangXiangUSTC commented 5 years ago

Feature Request

Support some SQLs to manage the TiDB-Binlog toolset.

Background

  1. Now we don't know whether a TiDB instance enable the binlog, we need check the TiDB's config file, or look the config information in TiDB's log. It is inconvenience.

  2. We must restart the TiDB instance if we need enable or close the TiDB's binlog, it is inconvenience too.

  3. If we want check the pump and drainer's status, we need use another tool binlogctl, and the command of binlogctl is complicated, not easy to use.

Feature

View status of binlog and TiDB-Binlog toolset

1. Check binlog is enable or not

Add a variable named log_bin, just same with MySQL.

mysql> show variables like '%log_bin%';
+----------------+--------+
| Variable_name   | Value    |
+----------------+--------+
| log_bin                | ON        |
+----------------+--------+
2. View Pump's status

Support SQL show pump status

mysql> show pump status;
+-------------+---------------------+------------+------------------------------+-----------------------------+
|  NodeID   |      Address       |   State     |    Max_Commit_Ts      |     Update_Time         |
+-------------+---------------------+------------+------------------------------+-----------------------------+
|   pump1   | 127.0.0.1:8249 | Online     | 405808620969656321| 2019-01-01 01:01:01 |
+-------------+---------------------+------------+------------------------------+-----------------------------+
|   pump2   | 127.0.0.2:8249 | Online     | 405808620969656322| 2019-01-01 01:01:02 |
+-------------+---------------------+------------+------------------------------+-----------------------------+
3. View Drainer's status

Support SQL show drainer status

mysql> show drainer status;
+-------------+---------------------+------------+------------------------------+-----------------------------+
|  NodeID   |      Address       |   State     |    Max_Commit_Ts      |     Update_Time         |
+-------------+---------------------+------------+------------------------------+-----------------------------+
|   drainer1  | 127.0.0.1:8250 | Online    | 405808620969656321| 2019-01-01 01:01:01 |
+-------------+---------------------+------------+------------------------------+-----------------------------+
|  drainer2  | 127.0.0.2:8250 | Online     | 405808620969656322| 2019-01-01 01:01:02 |
+-------------+---------------------+------------+------------------------------+-----------------------------+

Manage binlog and TiDB-Binlog toolset

4. Close binlog

Add a new variable log_bin, if set this value to 0, will close the binlog. The scope can be global, server or session.

set log_bin = 0;
5. Enable binlog

Use the variable above, set this value to 1 to enable binlog.

set log_bin = 1;
6. Change the write binlog's strategy in pump client

Add a new variable named binlog_strategy, the value can be range, hash and so on. The scope can be global to server.

set binlog_strategy = "range";
7. Update Pump's state

Add SQL looks like below:

change pump to pump_state='paused' for NodeID "127.0.0.1:8249";
8. Update Drainer's state

Add SQL looks like below:

change drainer to drainer_state='paused' for NodeID "127.0.0.1:8250";

TODO List

1. Support variable log_bin

2. Support SQL show pump status and show drainer status

just like binlogctl, get pump and drainer status in PD, reference: binlogctl

3. Support close or enable binlog by set log_bin

4. Support change the write binlog's strategy in pump client

pump client's code reference: pump client

5. Support update Pump or Drainer's status

just like binlogctl, if Pump or Drainer is alive, send http request to Pump/Drainer, otherwise update the status saved in PD directly.

morgo commented 5 years ago

On (4), MySQL does not support global scope for this because it is dangerous. It would be better not to encourage the syntax, even if TiDB behaves differently.

May I recommend either: a) Modeling based on the command start slave? So for example 'start binlog', 'stop binlog'. b) Using the name tidb_binlog instead.

There are security issues with letting a user disable binlogging for their session too. Since the toolchain supports filtering downstream, we could maybe also propose that the tidb_binlog setting is only global? I am open to feedback here.

For commands (7) and (8) these don't quite feel natural to me (it's not namespaced). Maybe it could be modeled on the syntax for replication channels in MySQL 5.7+?

WangXiangUSTC commented 5 years ago

thanks for your suggestions, I will take a look and update this proposal. @morgo

IANTHEREAL commented 5 years ago

I perfer the tidb_binlog setting is only global, it would simplify something (e.g. maybe we don't need run-ddl any more). Or we can imagine, what scenario would we need to turn off tidb_binlog of one tidb server/session in TiDB cluster?

WangXiangUSTC commented 5 years ago

I think the global scope is necessary for tidb_binlog, and we can also support the session and server scope. we need set some limit to avoid some error, for example ddl must generate binlog in all scope type, and we need notice user must be very careful when change the tidb_binlog's scope. @morgo @GregoryIan

WangXiangUSTC commented 5 years ago

hi morgo, could you please provide a example of sql for update pump's state. we have several pumps, every pump have a unique nodeID, and the nodeID is set by user. @morgo

IANTHEREAL commented 5 years ago

we can also support the session and server scope. we need set some limit to avoid some error. is it necessary? give a example why we need it?

WangXiangUSTC commented 5 years ago

some user want ignore generate binlog in load stage @GregoryIan

morgo commented 5 years ago

@WangXiangUSTC I will get back to you with example syntax early next week. I want to run it by some users at FOSDEM.

In regards to if session should be supported, I would say we need to understand the use case. For an example in MySQL that really increases complexity: you can change the character set on a per column, table, schema or global basis. There is no strong use case for this, and it makes debugging very hard!

WangXiangUSTC commented 5 years ago

@morgo thanks ok, we can only support global scope for open/close binlog now.

morgo commented 5 years ago

Okay, I have the following feedback:

(If you want to implement per-session at a later point in time, that's fine too.)

WangXiangUSTC commented 5 years ago
  1. I have already use sql set tidb_binlog = 0; and set tidb_binlog = 1; to close or open binlog, is it necessary to change tidb_binlog to log_bin?
  2. we can support scope global firstly. And if need support scope session, we can do it later @morgo
morgo commented 5 years ago
  1. I have already use sql set tidb_binlog = 0; and set tidb_binlog = 1; to close or open binlog, is it necessary to change tidb_binlog to log_bin?

I am slowly trying to fix variables so they no longer show dummy data (it creates issues for users who are trying to debug problems). So we would need to at least alias log_bin to tidb_binlog. Aliases are good to help upgrades, but they are not good for usability since they need to be explained and documented (which is the preferred way? is there a difference which option I use?)

  1. we can support scope global firstly. And if need support scope session, we can do it later @morgo

Sounds good.

WangXiangUSTC commented 5 years ago

thanks for your suggestion, I already updated this proposal @morgo

aliiohs commented 5 years ago

i want to implements the frist one int todo list.

yangwenmai commented 5 years ago

I want to impl the 3rd one in todo list.

WangXiangUSTC commented 5 years ago

@aliiohs @yangwenmai thanks

caohe commented 5 years ago

I'd like to implement the 2nd one.

  1. Support SQL show pump status and show drainer status
WangXiangUSTC commented 5 years ago

@caohe thanks

aliiohs commented 5 years ago

I want to impl the 5rd one in todo list.

qxhy123 commented 5 years ago

I'd like to impl the 4th:

  1. Support change the write binlog's strategy in pump client
WangXiangUSTC commented 5 years ago

@aliiohs @qxhy123 thanks

morgo commented 5 years ago

One more feature request: For any SHOW command we add, we should also add an information_schema table. It is quite quick to do, and helps users join against the tables.

morgo commented 5 years ago

I showed this to a MySQL user today, and they suggested that this command is not MySQL-like:

change drainer to drainer_state='paused' for NodeID "127.0.0.1:8250";

It should be modeled on stop slave:

STOP DRAINER for NodeID "127.0.0.1:8250";
ghost commented 4 years ago

@WangXiangUSTC can this issue be closed?

WangXiangUSTC commented 4 years ago

@nullnotnil OK