[MDEV-16470] Session user variables tracker Created: 2018-06-12 Updated: 2022-04-25 |
|
| Status: | Stalled |
| Project: | MariaDB Server |
| Component/s: | Server |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major |
| Reporter: | dapeng huang | Assignee: | Oleksandr Byelkin |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | contribution, foundation | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||
| Description |
|
When using a proxy, such as MaxScale to do read/write split, It is not easy to keep session state consistent between different backends, especially for session user variables; When execute stored procedure, or do some select with user variable modification,It is hard for proxy to notice that a variable was changed, and get the lasted value;
Currently, Maxscale route these queries to every backends or route all to master, it is not efficient and sometimes not correct; So we suggest that server provide a session user variables tracker to inform proxy the what variable changed, and the lasted value, then propagate the results to other backends. |
| Comments |
| Comment by Oleksandr Byelkin [ 2018-06-12 ] | ||||
|
Could be task described in more details? What variables to track? Please define the task properly. | ||||
| Comment by dapeng huang [ 2018-06-13 ] | ||||
session user variables
using session track mechanism to inform proxy which user variables changed and the value; the info store in ok packet just like
just a little, maybe more bandwidth consumption | ||||
| Comment by Oleksandr Byelkin [ 2018-06-13 ] | ||||
|
Do you need to track all session variable, individual list of variables, report only existence of some changes of some variables, report list of all changed variables, report list of variables with its new values, report list of all changed variables with old and new value? (after defining what to track question about penalty will be more clear) | ||||
| Comment by dapeng huang [ 2018-06-26 ] | ||||
|
Report list of changed variables with its new values will be enough , I think the penalty should be negligible; | ||||
| Comment by Oleksandr Byelkin [ 2018-06-26 ] | ||||
|
You have not answered if it is all user variables or variables by some list. About penalty, not sure. It will be memory penalty for sure (name and values storing) also it is in times more complex then just report if there was some changes. BTW do you realise that you still will not have info about global variables (which are not session nor user).? Also could you collect and put all requirements in the task description. | ||||
| Comment by markus makela [ 2018-06-26 ] | ||||
|
If I understand this correctly, the idea is to return all changed user variables in the OK packet. This means that the following SQL statement:
Would return the key a and value 1. This would allow the client to know what user variables have changed after calling something with a side-effect e.g. a stored procedure. This would mainly benefit proxies and other systems that intend to use the values of these variables for other purposes. In the case of MaxScale, it would propagate these changes to other servers when executed on one server (see | ||||
| Comment by Sergey Vojtovich [ 2019-06-20 ] | ||||
|
serg, please review patch for this task https://github.com/MariaDB/server/commit/fd4bac9c5e23443d059d6e65ffe8eda319ea25d9 | ||||
| Comment by Sergey Vojtovich [ 2019-09-20 ] | ||||
|
robertbindar, please review https://github.com/MariaDB/server/commit/69b05a7d7a3c3630232fa12a5131d86ec80afdd4, it is reimplementation of contributed patch. | ||||
| Comment by Oleksandr Byelkin [ 2020-05-11 ] | ||||
|
there is no support in client, no real test (and support in mysqltest.cc), no documentation | ||||
| Comment by Oleksandr Byelkin [ 2020-06-05 ] | ||||
|
The patch appered to be non working (no surprise because it has no tests). | ||||
| Comment by Oleksandr Byelkin [ 2020-06-11 ] | ||||
|
Current implementation forgot about:
| ||||
| Comment by Alexander Barkov [ 2020-06-11 ] | ||||
|
I'd propose to return variable tracking as:
So the proxy will reconstruct a SET statement using this simple function:
The server will put all necessary metadata into the expression itself.
Note, we will eventually support user defined types in user variables. An arbitrary data type has an arbitrary amount of data type attributes. | ||||
| Comment by Alexander Barkov [ 2020-06-11 ] | ||||
|
i suppose the proxy does not need to parse the expression. It only needs to get the variable name and its value from one backend and transparently transfer this exact value to another backend. Using the expression format looks the best for me. We already use the same approach in binary log by replacing user variables and SP variables with NAME_CONST() expressions:
Notice, the expression contains all metadata:
This approach proved to be functional. Why not reuse it for variable tracking? Some more binlog examples for other data types:
Notice, every data type encodes its values in its own way. In the way that the server will re-parse it back without any data loss. There is a good advantage in this approach: So a new data type will have to implement the functionality (to print a variable value as an expression) only one time, and it will be reused both for binary logging and variable tracking. | ||||
| Comment by markus makela [ 2020-06-12 ] | ||||
|
I think Bar's proposal would be pretty good as it'd still allow the admin tool to see the value with a simple SELECT <insert constant here> AS <variable name>. This removes all client-side requirements for the feature to be used. it'd involve an extra round-trip but it's probably not super critical when it's used by interactive applications and I think doing things in SQL is more portable than implementing it in the connectors. |