[MDEV-16382] Add tracking support for gtid_current_pos Created: 2018-06-04  Updated: 2023-07-20

Status: Open
Project: MariaDB Server
Component/s: None
Fix Version/s: None

Type: Task Priority: Major
Reporter: markus makela Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None


 Description   

The tracking of last_gtid makes it possible to detect changes in GTID within the session. Adding tracking support for all GTID related variables (mainly gtid_current_pos) would enable the detection of GTID changes done by other sessions.

This change would provide functionality similar to that of the MySQL 5.7 GTID tracking but with no changes to protocol.



 Comments   
Comment by Daniel Black [ 2023-07-20 ]

is this needed now that the session system variable monitoring is implemented?

Comment by markus makela [ 2023-07-20 ]

I don't think changes in gtid_current_pos are sent to clients. I haven't tested it with the latest releases, has there been a change that would add tracking for it?

Comment by Daniel Black [ 2023-07-20 ]

If its added to session_track_system_variables='gtid_current_pos' does it track? If not that probably could be considered a bug.

Comment by markus makela [ 2023-07-20 ]

Doesn't seem to, I tested with both session_track_system_variables=* and session_track_system_variables=gtid_current_pos,gtid_slave_pos,gtid_binlog_pos using the following test program:

void print_status_changes(MYSQL* c)
{
    const char* ptr = nullptr;
    size_t len = 0;
 
    if (mysql_session_track_get_first(c, SESSION_TRACK_SYSTEM_VARIABLES, &ptr, &len) == 0)
    {
        std::cout << std::string_view(ptr, len) << std::endl;
 
        while (mysql_session_track_get_next(c, SESSION_TRACK_SYSTEM_VARIABLES, &ptr, &len) == 0)
        {
            std::cout << std::string_view(ptr, len) << std::endl;
        }
    }
}
 
int main(int argc, char** argv)
{
    MYSQL* c = mysql_init(nullptr);
 
    if (!mysql_real_connect(c, "127.0.0.1", "maxuser", "maxpwd", nullptr, 3000, nullptr, CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS))
    {
        std::cout << "Connect: " << mysql_error(c) << std::endl;
    }
    else
    {
        auto queries = {
            "SELECT 1",
            "SET autocommit=0",
            "SET autocommit=1,tx_isolation='REPEATABLE-READ'",
            "CREATE OR REPLACE TABLE test.t1(id INT)",
            "INSERT INTO test.t1 VALUES (1)",
            "SET @myvar=1,autocommit=0,sql_notes=0",
            "SELECT 1",
            "COMMIT",
        };
        
        for (auto query : queries)
        {
            std::cout << query << std::endl;
            mysql_query(c, query);
            auto res = mysql_store_result(c);
            print_status_changes(c);
            mysql_free_result(res);
            std::cout << std::endl;
            sleep(1);
        }
    }
 
    mysql_close(c);
    return 0;
}

This is the output it produced with session_track_system_variables=*:

SELECT 1
 
SET autocommit=0
autocommit
OFF
 
SET autocommit=1,tx_isolation='REPEATABLE-READ'
autocommit
ON
tx_isolation
REPEATABLE-READ
 
CREATE OR REPLACE TABLE test.t1(id INT)
last_gtid
0-3000-22
 
INSERT INTO test.t1 VALUES (1)
last_gtid
0-3000-23
 
SET @myvar=1,autocommit=0,sql_notes=0
autocommit
OFF
sql_notes
OFF
 
SELECT 1
autocommit
OFF
sql_notes
OFF
 
COMMIT

With session_track_system_variables=gtid_current_pos,gtid_slave_pos,gtid_binlog_pos it prints nothing since the GTID position variables aren't included in the tracking.

Generated at Thu Feb 08 08:28:30 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.