-
Notifications
You must be signed in to change notification settings - Fork 550
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
Client session tracking #1092
Client session tracking #1092
Conversation
Thank you! Few things needed:
|
7f127dc
to
50d2b64
Compare
ext/mysql2/client.c
Outdated
@@ -1613,6 +1641,21 @@ void init_mysql2_client() { | |||
INT2NUM(0)); | |||
#endif | |||
|
|||
#ifdef CLIENT_SESSION_TRACK | |||
rb_define_method(cMysql2Client, "session_track", rb_mysql_client_session_track, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern I'd like to follow is to always define this method on the object, and within the method, if the feature is unavailable, to return Qnil.
a7ada4b
to
aacf1ad
Compare
@sodabrew I've made the following changes
|
Also seems like the failing test is due to network failure. I'm unable to rerun the failing build, hum. |
Hi @sodabrew, do you have some time to review this PR? |
ecde7d6
to
85fe0c8
Compare
c = Mysql2::Client.new( | ||
host: "127.0.0.1", | ||
username: "root", | ||
flags: "SESSION_TRACK", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this example might be wrong? Should it be flags: Mysql2::Client::SESSION_TRACK
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can pass all sorts of things to flags
😁 -- https://github.com/brianmario/mysql2/blob/master/lib/mysql2/client.rb#L56L57 -- so this will work. It might be better to encourage the use of the constant for style reasons though? The other examples do.
Allow compilation with mariadb-connector-c
This is a great feature. Thank you for contributing it. |
@@ -1,6 +1,6 @@ | |||
require 'spec_helper' | |||
|
|||
RSpec.describe Mysql2::Client do | |||
RSpec.describe Mysql2::Client do # rubocop:disable Metrics/BlockLength |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance to disable/extend this rubocop rule in specs only? rspec is usually bunch of huge blocks by design.
Thanks again for this the support for this feature! |
This adds support for Oracle/Percona MySQL 5.7+ session tracking to the client.
Docs on the function: https://dev.mysql.com/doc/refman/5.7/en/mysql-session-track-get-first.html
At Shopify, we wanted to be able to tell which GTID was generated by a given
COMMIT
so that when we are reading from delayed replicas we can be sure that a given replica has the data that we want on it. This is pretty much the exact flow that's described by the Oracle worklog entry describing the implementation of the featureExample usage:
I mirrored the implementation of
client.last_id
-- I noticed that wasn't documented in theREADME.md
so I hadn't added this, but if you have any suggestions about how or where to document this feature I'd appreciate that.I believe that all the
ifdef
ing is right to not compile this feature for MariaDB (which doesn't support it).