Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic GTID tracking. #77

Merged
merged 1 commit into from Aug 23, 2018
Merged

Conversation

dveeden
Copy link
Collaborator

@dveeden dveeden commented Dec 18, 2016

https://rt.cpan.org/Public/Bug/Display.html?id=119122
https://dev.mysql.com/doc/refman/5.7/en/mysql-session-track-get-first.html

This code is only tested at a very basic level.

  • The test runs, but other tests fail on a GTID enabled server. For example:
t/53comment.t ........................... DBD::mysql::db do failed: Statement violates GTID consistency: CREATE TEMPORARY TABLE and DROP TEMPORARY TABLE can only be executed outside transactional context.  These statements are also not allowed in a function or trigger because functions and triggers are also considered to be multi-statement transactions. at t/53comment.t line 32.
  • This is specific for GTID tracking and doesn't to schema/state/variable tracking. This could be made in a more generic feature, but currently I think this more specific feature makes sense.
  • This is tested against 5.7 and it should be possible to compile it against 5.6 and below (with loss of function)
  • I did not test against MariaDB server
  • I did not test compilation against MariaDB libraries
  • It probably works against MariaDB: https://jira.mariadb.org/browse/MDEV-8931
  • MariaDB has a different GTID implementation, so it might behave differently (e.g. test might fail because the MariaDB implementation has a shorter GTID)
  • The test only runs against a server were this is enabled in the config, so this gets very limited testing. Unfortunately this can't be enabled dynamically, so we can't enable it during the test.

Example:

#!/usr/bin/perl
use v5.24.0;
use DBI;

my $dbh = DBI->connect("DBI:mysql:database=test;mysql_socket=/tmp/mysql_sandbox5717.sock",
                       "msandbox", "msandbox",
                       {'RaiseError' => 1});

$dbh->do('FLUSH PRIVILEGES');
say "GTID= $dbh->{'mysql_gtids'}";

$dbh->disconnect();

@mbeijen
Copy link
Contributor

mbeijen commented Dec 19, 2016

Hi Daniël, thanks for the pull request.
I found this also does not compile against mysql-connector-c version 6.1.6 which are 5.6 libraries;

dbdimp.c:2859:58: error: use of undeclared identifier 'SESSION_TRACK_GTIDS'; did you mean 'SESSION_TRACK_SCHEMA'?
      if (mysql_session_track_get_first(imp_dbh->pmysql, SESSION_TRACK_GTIDS, &data, &length) == 0)
                                                         ^~~~~~~~~~~~~~~~~~~
                                                         SESSION_TRACK_SCHEMA

Maybe it is better to depend on if SESSION_TRACK_GTIDS is defined than to define on the version number.

@dveeden
Copy link
Collaborator Author

dveeden commented Dec 20, 2016

I used the version number from https://dev.mysql.com/doc/refman/5.7/en/mysql-session-track-get-first.html which is for the function, but not for SESSION_TRACK_GTIDS. I've now fixed the version number.

Note that Connector/C 6.1.6 is not 5.6, but 5.7..

$ rpm -qf /usr/include/mysql/mysql_com.h
mysql-connector-c-devel-6.1.6-1.el7.i686

$ grep -w MYSQL_VERSION_ID /usr/include/mysql/mysql_version.h 
#define MYSQL_VERSION_ID            50706

Changing this to check if SESSION_TRACK_GTIDS is defined might indeed be a better option.

@pali
Copy link
Member

pali commented Jan 29, 2017

Hi! Please rebase your patches on top of master branch. Travis CI is now configured to test DBD::mysql with different MySQL & MariaDB versions.

@pali
Copy link
Member

pali commented Jan 29, 2017

So... it does not compile with MariaDB client.

dbdimp.c Outdated
@@ -2854,6 +2854,24 @@ SV* dbd_db_FETCH_attrib(SV *dbh, imp_dbh_t *imp_dbh, SV *keysv)
result= sv_2mortal((newRV_noinc((SV*)hv)));
}

#if (MYSQL_VERSION_ID >= 50708) && (MYSQL_VERSION_ID <= MARIADB_VERSION_10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this feature is not supported by MariaDB client, then rather check that MARIADB_BASE_VERSION is not defined.

In future Oracle can decide that MySQL version could be increased to 10 or 11 and this code stop working.

@dveeden dveeden force-pushed the session_track_gtid branch 2 times, most recently from 12670fb to e323801 Compare March 28, 2017 19:37
@CaptTofu
Copy link
Member

CaptTofu commented Sep 5, 2017

can we move this along? Any objections?

@dveeden
Copy link
Collaborator Author

dveeden commented Jan 10, 2018

What needs to be done to get this merged?

@dveeden
Copy link
Collaborator Author

dveeden commented Jan 10, 2018

This might be a slightly better example:

#!/usr/bin/perl
use v5.24.0;
use DBI;

my $master_dbh = DBI->connect("DBI:mysql:database=test;host=mymaster", "myuser", "mypass");
my $slave_dbh = DBI->connect("DBI:mysql:database=test;host=myslave1", "myuser", "mypass");

# Write to the master
$master_dbh->do('SET SESSION session_track_gtids=OWN_GTID');
$master_dbh->do("INSERT INTO t1() VALUES()");
my $gtid = $master_dbh->{'mysql_gtids'};
$master_dbh->disconnect();
say "GTID= $gtid";

# Wait until the GTID hits the slave (or timeout)
my $sth = $slave_dbh->prepare("SELECT WAIT_FOR_EXECUTED_GTID_SET(?, 10)");
$sth->execute($gtid);
if ($sth->fetchrow_arrayref()->[0] != 0) {
  say "Got timeout";
}
$sth->finish();
$slave_dbh->disconnect();

@CaptTofu
Copy link
Member

I merged this this morning - time to get a release going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants