Details

    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;
      For example,

      select a, b from (select (@id:=@id+1) as id, a, b from t group by c order by d) tt where id < 10;
      select @a:=b, c from t
      ...
      

      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.

      Attachments

        Issue Links

          Activity

            dapeng dapeng huang created issue -
            dapeng dapeng huang made changes -
            Field Original Value New Value
            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 let session user variables consistent; 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;
            For example,
            {code:java}
            select a, b from (select (@id:=@id+1) as id, a, b from t group by c order by d) tt where id < 10;
            select @a:=b, c from t
            ...
            {code}

            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.
            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;
            For example,
            {code:java}
            select a, b from (select (@id:=@id+1) as id, a, b from t group by c order by d) tt where id < 10;
            select @a:=b, c from t
            ...
            {code}

            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.
            dapeng dapeng huang made changes -
            svoj Sergey Vojtovich made changes -
            Fix Version/s 10.3 [ 22126 ]
            svoj Sergey Vojtovich made changes -
            Assignee Oleksandr Byelkin [ sanja ]
            svoj Sergey Vojtovich made changes -
            Labels contribution foundation

            Could be task described in more details?

            What variables to track?
            What to do with new variables?
            What memory and speed penalty is acceptable?

            Please define the task properly.

            sanja Oleksandr Byelkin added a comment - Could be task described in more details? What variables to track? What to do with new variables? What memory and speed penalty is acceptable? Please define the task properly.
            dapeng dapeng huang added a comment -

            What variables to track?

            session user variables

            What to do with new variables?

            using session track mechanism to inform proxy which user variables changed and the value; the info store in ok packet just like MDEV-8931 tracking system variables;

            What memory and speed penalty is acceptable?

            just a little, maybe more bandwidth consumption

            dapeng dapeng huang added a comment - What variables to track? session user variables What to do with new variables? using session track mechanism to inform proxy which user variables changed and the value; the info store in ok packet just like MDEV-8931 tracking system variables; What memory and speed penalty is acceptable? just a little, maybe more bandwidth consumption
            sanja Oleksandr Byelkin added a comment - - edited

            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?
            so, what to track?

            (after defining what to track question about penalty will be more clear)

            sanja Oleksandr Byelkin added a comment - - edited 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? so, what to track? (after defining what to track question about penalty will be more clear)
            dapeng dapeng huang added a comment -

            Report list of changed variables with its new values will be enough , I think the penalty should be negligibleï¼›

            dapeng dapeng huang added a comment - Report list of changed variables with its new values will be enough , I think the penalty should be negligibleï¼›
            sanja Oleksandr Byelkin added a comment - - edited

            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.

            sanja Oleksandr Byelkin added a comment - - edited 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.
            markus makela markus makela added a comment -

            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:

            SET @a = 1;
            

            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 MXS-1756).

            markus makela markus makela added a comment - 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: SET @a = 1; 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 MXS-1756 ).
            sanja Oleksandr Byelkin made changes -
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.3 [ 22126 ]
            svoj Sergey Vojtovich made changes -
            Assignee Oleksandr Byelkin [ sanja ] Sergey Vojtovich [ svoj ]
            svoj Sergey Vojtovich made changes -
            Status Open [ 1 ] Confirmed [ 10101 ]
            svoj Sergey Vojtovich made changes -
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.4 [ 22408 ]
            svoj Sergey Vojtovich added a comment - serg , please review patch for this task https://github.com/MariaDB/server/commit/fd4bac9c5e23443d059d6e65ffe8eda319ea25d9
            svoj Sergey Vojtovich made changes -
            Assignee Sergey Vojtovich [ svoj ] Sergei Golubchik [ serg ]
            Status Confirmed [ 10101 ] In Review [ 10002 ]
            svoj Sergey Vojtovich made changes -
            Assignee Sergei Golubchik [ serg ] Robert Bindar [ robertbindar ]
            svoj Sergey Vojtovich added a comment - robertbindar , please review https://github.com/MariaDB/server/commit/69b05a7d7a3c3630232fa12a5131d86ec80afdd4 , it is reimplementation of contributed patch.
            svoj Sergey Vojtovich made changes -
            Assignee Robert Bindar [ robertbindar ] Sergey Vojtovich [ svoj ]
            svoj Sergey Vojtovich made changes -
            Component/s Server [ 13907 ]
            Fix Version/s 10.5.0 [ 23709 ]
            Fix Version/s 10.5 [ 23123 ]
            Resolution Fixed [ 1 ]
            Status In Review [ 10002 ] Closed [ 6 ]

            there is no support in client, no real test (and support in mysqltest.cc), no documentation

            sanja Oleksandr Byelkin added a comment - there is no support in client, no real test (and support in mysqltest.cc), no documentation
            sanja Oleksandr Byelkin made changes -

            The patch appered to be non working (no surprise because it has no tests).

            sanja Oleksandr Byelkin added a comment - The patch appered to be non working (no surprise because it has no tests).
            sanja Oleksandr Byelkin made changes -
            sanja Oleksandr Byelkin made changes -
            Resolution Fixed [ 1 ]
            Status Closed [ 6 ] Stalled [ 10000 ]
            sanja Oleksandr Byelkin made changes -
            Assignee Sergey Vojtovich [ svoj ] Oleksandr Byelkin [ sanja ]
            sanja Oleksandr Byelkin made changes -
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.5.0 [ 23709 ]
            sanja Oleksandr Byelkin made changes -
            Priority Major [ 3 ] Critical [ 2 ]

            Current implementation forgot about:

            • NULL
            • variables types
            • charset for string and precision for numbers
            sanja Oleksandr Byelkin added a comment - Current implementation forgot about: NULL variables types charset for string and precision for numbers
            bar Alexander Barkov added a comment - - edited

            I'd propose to return variable tracking as:

            • the variable name
            • the variable value expression

            So the proxy will reconstruct a SET statement using this simple function:

            spnrintf(buff, "SET @%s=%s", name, expr);
            

            The server will put all necessary metadata into the expression itself.
            For example, in case of a string data, it would send the expression in this format:

            _latin1'str' COLLATE latin1_german2_ci
            

            Note, we will eventually support user defined types in user variables. An arbitrary data type has an arbitrary amount of data type attributes.
            So sending the basic metadata (e.g, length, precision, scale), like we do it in the result set in the client-server protocol, won't always be enough: this metadata is incomplete.

            bar Alexander Barkov added a comment - - edited I'd propose to return variable tracking as: the variable name the variable value expression So the proxy will reconstruct a SET statement using this simple function: spnrintf(buff, "SET @%s=%s" , name , expr); The server will put all necessary metadata into the expression itself. For example, in case of a string data, it would send the expression in this format: _latin1 'str' COLLATE latin1_german2_ci Note, we will eventually support user defined types in user variables. An arbitrary data type has an arbitrary amount of data type attributes. So sending the basic metadata (e.g, length, precision, scale), like we do it in the result set in the client-server protocol, won't always be enough: this metadata is incomplete.
            bar Alexander Barkov added a comment - - edited

            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:

            INSERT INTO t2 VALUES ( NAME_CONST('rec1.a',10),  NAME_CONST('rec1.b',_latin1'b10' COLLATE 'latin1_swedish_ci'))
            

            Notice, the expression contains all metadata:

            • in case of a number it's just 10 - an integer literal. It does not need any additional metatada.
            • In case of a string it's more complex: the expression, among the value itself, contains the character set and the collation

            This approach proved to be functional. Why not reuse it for variable tracking?

            Some more binlog examples for other data types:

            INSERT INTO t1 VALUES ( NAME_CONST('b8',_binary'a' COLLATE 'binary')=0x61)
            INSERT INTO t1 VALUES ( NAME_CONST('t0',TIME'01:01:01')=10101)
            INSERT INTO t1 VALUES ( NAME_CONST('dt0',TIMESTAMP'2001-01-01 01:01:01')=20010101010101)
            

            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:
            we can reuse a lot of code in the server for variable tracking.

            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.

            bar Alexander Barkov added a comment - - edited 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: INSERT INTO t2 VALUES ( NAME_CONST( 'rec1.a' ,10), NAME_CONST( 'rec1.b' ,_latin1 'b10' COLLATE 'latin1_swedish_ci' )) Notice, the expression contains all metadata: in case of a number it's just 10 - an integer literal. It does not need any additional metatada. In case of a string it's more complex: the expression, among the value itself, contains the character set and the collation This approach proved to be functional. Why not reuse it for variable tracking? Some more binlog examples for other data types: INSERT INTO t1 VALUES ( NAME_CONST( 'b8' ,_binary 'a' COLLATE 'binary' )=0x61) INSERT INTO t1 VALUES ( NAME_CONST( 't0' , TIME '01:01:01' )=10101) INSERT INTO t1 VALUES ( NAME_CONST( 'dt0' , TIMESTAMP '2001-01-01 01:01:01' )=20010101010101) 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: we can reuse a lot of code in the server for variable tracking. 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.
            markus makela markus makela added a comment -

            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.

            markus makela markus makela added a comment - 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.
            serg Sergei Golubchik made changes -
            Rank Ranked higher
            sanja Oleksandr Byelkin made changes -
            sanja Oleksandr Byelkin made changes -
            serg Sergei Golubchik made changes -
            ralf.gebhardt Ralf Gebhardt made changes -
            Priority Critical [ 2 ] Major [ 3 ]
            ralf.gebhardt Ralf Gebhardt made changes -
            Fix Version/s 10.6 [ 24028 ]
            julien.fritsch Julien Fritsch made changes -
            serg Sergei Golubchik made changes -
            serg Sergei Golubchik made changes -
            julien.fritsch Julien Fritsch made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            serg Sergei Golubchik made changes -
            Priority Critical [ 2 ] Major [ 3 ]
            serg Sergei Golubchik made changes -
            serg Sergei Golubchik made changes -
            serg Sergei Golubchik made changes -
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 87803 ] MariaDB v4 [ 131695 ]
            georg Georg Richter made changes -

            People

              sanja Oleksandr Byelkin
              dapeng dapeng huang
              Votes:
              0 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.