Skip to content

Output a version of MySQL Connector/J. #110

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

Merged
merged 8 commits into from
Jun 20, 2017

Conversation

hiroyuki-sato
Copy link
Member

Overview

I would like to update MySQL Connector/J to a newer version. (5.1.42 or newer)
But It has incompatibility change.
We(I and @hito4t) decided that the plugin output a warning message like This plugin will update Connector/J on next release...
This PR for implement this warning.

Detail

@hito4t, Could you give me some advice?

  • When output a version information and warning?
  • How to output current Connector/J version.
    • How to get current Driver version (hard code, get version info from libraries)
  • How to implement it.

When output a version information and warning?

I think I should the message should output before Loaded plugin embulk/input/mysql from a load path.

Example.

2017-06-10 11:04:02.020 +0900: Embulk v0.8.22
2017-06-10 11:04:14.232 +0900 [INFO] (0001:preview): MySQL Connector/J version 5.1.34
2017-06-10 11:04:13.835 +0900 [INFO] (0001:preview): Loaded plugin embulk/input/mysql from a load path
.... and some warning message here

How to output current Connector/J version?

I would like to output warning message with current MySQL Connector/J version.
So I tried to get it.

The current experimental implementation get version info from Package object.

First I tried to get the version info from Driver class.
But It can't get sub minor version (z part in x.y.z).
That's why I used this way.

Do you have any alternative idea?

Driver driver;
try {
    driver = new com.mysql.jdbc.Driver();

    int major = driver.getMajorVersion();
    int minor = driver.getMinorVersion();
    logger.info(String.format(Locale.ENGLISH,"driver version %d.%d",major,minor));
}
catch (SQLException e) {
    throw Throwables.propagate(e);
}

@hito4t
Copy link
Contributor

hito4t commented Jun 12, 2017

Thank you for the PR!

How to output current Connector/J version.
How to get current Driver version (hard code, get version info from libraries)

How to implement it.

We can get driver information by java.sql.DatabaseMetaData object gotten by java.sql.Connection#getMetaData() .

DatabaseMetaData of MySQL Connector/J will return following values.

  • getDriverMajorVersion() -> 5
  • getDriverMinorVersion() -> 1
  • getDriverName() -> "MySQL Connector Java"
  • getDriverVersion() -> "mysql-connector-java-5.1.34 ( Revision: [email protected] )"

We should output a result of getDriverVersion() because other methods won't return enough information.

When output a version information and warning?

I think we should do in setupTask method before checking timezone.

And it must be useful if driver version is shown in not also embulk-output-mysql but also all embulk-output-jdbc plugins.
For example, we can do in AbstractJdbcInputPlugin#transaction method before calling setupTask .

@hiroyuki-sato
Copy link
Member Author

@hito4t Thank you for your comment.

I used java.sql.Connection#getMetaData()
What do you think this implementation?

I'll change later the following part
`This plugin will update MySQL Connector/J version on next release...``

Copy link
Contributor

@hito4t hito4t left a comment

Choose a reason for hiding this comment

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

Thank you!
Please check comments.

try {
DatabaseMetaData meta = connection.getMetaData();
logger.info(String.format(Locale.ENGLISH,"Using JDBC Driver %s",meta.getDriverVersion()));
} catch( SQLException e ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we don't need to catch SQLException because Connection#getMetaData#getDriverVersion doesn't throw an exception normally.
If thrown, we can't access database after all.

Copy link
Member Author

Choose a reason for hiding this comment

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

Throw the exception instead of catch.

@@ -185,6 +185,7 @@ public ConfigDiff transaction(ConfigSource config,
Schema schema;
try (JdbcInputConnection con = newConnection(task)) {
// TODO incremental_columns is not set => get primary key
con.showDriverVersion();
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment above (// TODO incremental_columns ...) should be above the following line (schema = setupTask(con, task);).

Copy link
Member Author

@hiroyuki-sato hiroyuki-sato Jun 14, 2017

Choose a reason for hiding this comment

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

Move comment to propper place.

@hiroyuki-sato
Copy link
Member Author

@hito4t Thank you for reviewing.

Please take a look again.
I fixed your review and add log detail.

It output the message like the below.

2017-06-14 14:11:22.435 +0900 [WARN] (0001:preview): This plugin will update MySQL Connector/J version on a future release.
2017-06-14 14:11:22.435 +0900 [WARN] (0001:preview): It has some incompatibility change.
2017-06-14 14:11:22.435 +0900 [WARN] (0001:preview): Please read a document and make sure configuration carefully before update the plugin.

@hito4t
Copy link
Contributor

hito4t commented Jun 15, 2017

Thank you!
Shall we elaborate the waning message?

  • All plugins must upgrade drivers one day. I think "near future" is better than "future".
  • It would be useful if users could know what "incompatibility" is (as written in Add mysql ssl option #109 (comment)).
  • I think "Please read a document ..." is not needed because users should read a document even if driver is not upgraded.

@hiroyuki-sato
Copy link
Member Author

@hito4t
Thank you!
What do you think this message?
I read release note again. It seems that the incompatibility change are noTimezoneConversionForDateType and cacheDefaultTimezone only.

This plugin will update MySQL Connector/J version in the near future release.
It has some incompatibility change.
For example, the 5.1.35 introduce noTimezoneConversionForDateType and cacheDefaultTimezone options.
Please confirm your configuration before update the plugin.

@hito4t
Copy link
Contributor

hito4t commented Jun 20, 2017

@hiroyuki-sato
Thank you!
That's nice.
Please commit the source after correcting errors.
some incompatibility change -> some incompatibility changes
the 5.1.35 introduce -> the 5.1.35 introduced
before update -> before updating

@hiroyuki-sato
Copy link
Member Author

hiroyuki-sato commented Jun 20, 2017

@hito4t

Thank you for your comment!.

I fixed some errors.
Please take a look again when you can.

2017-06-20 14:44:16.325 +0900 [WARN] (0001:preview): This plugin will update MySQL Connector/J version in the near future release.
2017-06-20 14:44:16.325 +0900 [WARN] (0001:preview): It has some incompatibility changes.
2017-06-20 14:44:16.325 +0900 [WARN] (0001:preview): For example, the 5.1.35 introduced noTimezoneConversionForDateType and cacheDefaultTimezone options.
2017-06-20 14:44:16.325 +0900 [WARN] (0001:preview): Please read a document and make sure configuration carefully before updating the plugin.

@hito4t hito4t merged commit 80a3343 into embulk:master Jun 20, 2017
@hiroyuki-sato
Copy link
Member Author

Thank you!

@hiroyuki-sato hiroyuki-sato deleted the mysql_jdbc_version branch June 20, 2017 09:57
@hito4t hito4t changed the title [WIP] Output a version of MySQL Connector/J. Output a version of MySQL Connector/J. Jun 21, 2017
@hito4t hito4t added this to the 0.8.4 milestone Jun 23, 2017
@hito4t
Copy link
Contributor

hito4t commented Jun 23, 2017

I'd like to resolve #113 before upgrading MySQL Connector/J.

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

Successfully merging this pull request may close these issues.

2 participants