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

Aligns timezone behavior with JDBC #240

Conversation

mirromutth
Copy link
Contributor

@mirromutth mirromutth commented Feb 19, 2024

Motivation:

Aligns timezone behavior with mysql-connector-j

See also #190

Modification:

  • Add preserveInstants, connectionTimeZone and forceConnectionTimeZoneToSession support
  • Default connectionTimeZone to "LOCAL"
  • Mark serverZoneId as deprecated. It will notice users to use connectionTimeZone instead
  • Add TimeZoneIntegrationTest to test JDBC alignment of time zone behavior
  • Correct OffsetTimeCodec to not convert time zone, OffsetTime is not an instant value

Result:

Users can now specify the local time zone to connection, allowing forcing the specified connection time zone on session.

@mirromutth mirromutth added the enhancement New feature or request label Feb 19, 2024
@mirromutth mirromutth added this to the 1.1.2 milestone Feb 19, 2024
@mirromutth mirromutth marked this pull request as draft February 19, 2024 06:12
@jchrys
Copy link
Collaborator

jchrys commented Feb 19, 2024

Would it be possible to consider setting the default value for the connectionTimeZone property to 'LOCAL', aligning with the default used by mysql-connector-j? to enhance consistency for developers familiar with mysql-connector-j's defaults.

@mirromutth mirromutth force-pushed the 190-aligning-serverzoneid-behavior-with-connectiontimezonemysql-connector-j branch 4 times, most recently from 2c87dd5 to 3dfebff Compare February 19, 2024 09:54
@mirromutth
Copy link
Contributor Author

mirromutth commented Feb 19, 2024

Would it be possible to consider setting the default value for the connectionTimeZone property to 'LOCAL', aligning with the default used by mysql-connector-j? to enhance consistency for developers familiar with mysql-connector-j's defaults.

This will break the current behavior. Currently, the configuration option serverZoneId=null would be equivalent to connectionTimeZone=SERVER&preserveInstants=true&forceConnectionTimeZoneToSession=false.

If we do, existing users (without serverZoneId configured) upgrade r2dbc-mysql to 1.1.2, it may unexpectedly cause date time types to use the local time zone. But, they are sent/responded to/from server, so they should be server time zone.

@mirromutth mirromutth requested a review from jchrys February 19, 2024 10:06
@mirromutth mirromutth marked this pull request as ready for review February 19, 2024 10:06
@mirromutth mirromutth changed the title Add connectionTimeZone and forceConnectionTimeZoneToSession support Aligns timezone behavior with JDBC Feb 19, 2024
@mirromutth
Copy link
Contributor Author

mirromutth commented Feb 20, 2024

In my personal opinion, I think we only need to write a migration guide wiki for new users who switch from jdbc to r2dbc.

It should contain:

  • What attributes we have but jdbc does not
  • What attributes we don’t have but jdbc does, why not, and how to migrate
  • Which attributes we have with jdbc, but are different (such as naming and values), how to migrate them (like time zone attributes)

This also helps us clarify what we should do next.

WDYT? @jchrys

@mirromutth mirromutth force-pushed the 190-aligning-serverzoneid-behavior-with-connectiontimezonemysql-connector-j branch 2 times, most recently from d776881 to 819c1b7 Compare February 20, 2024 05:17
@jchrys
Copy link
Collaborator

jchrys commented Feb 20, 2024

I 100% agree with your solution. I cannot deny that is the right way.
However, given the ongoing issue(a year long) with Micronaut, as highlighted here (micronaut-projects/micronaut-data#2388), I face a challenge. Suggestions to set the default connectionTimeZone to LOCAL (as well as to match the behavior of mysql-connector-j) or to switch the default codec for TIMESTAMP and DATETIME fields to LocalDateTime.class(to aligned with mariadb-r2dbc and dev.miku's) were not accepted. (I think not accepting is reasonable)
I think we need another solution. But I don't have one right now for it. I'm not trying to insist, but I would genuinely like to hear your thoughts on this. (including request changes on their end.) Could you please join the discussion and share your insights?

@mirromutth mirromutth force-pushed the 190-aligning-serverzoneid-behavior-with-connectiontimezonemysql-connector-j branch 6 times, most recently from 8399327 to cfe05a2 Compare February 21, 2024 02:21
@mirromutth
Copy link
Contributor Author

mirromutth commented Feb 21, 2024

@jchrys , the default connectionTimeZone is LOCAL now

The default type mappings of DATETIME will be fixed at other PR

@jchrys
Copy link
Collaborator

jchrys commented Feb 21, 2024

@mirromutth
I really appreciate for your efforts on this issue. Could you kindly elaborate on the rationale behind setting the default connectionTimeZone to LOCAL and adjusting DATETIME type mappings in the upcoming PR?

@mirromutth
Copy link
Contributor Author

@mirromutth I really appreciate for your efforts on this issue. Could you kindly elaborate on the rationale behind setting the default connectionTimeZone to LOCAL and adjusting DATETIME type mappings in the upcoming PR?

@jchrys Based on the discussion in micronaut-projects/micronaut-data#2388, I realized that if we tried to use different time zone modes by default, it might cause more complicated problems for some existing projects.

Like I said, in my opinion, ZonedDateTime and server time zone makes more sense. However, if LocalDateTime and the JVM local time zone are widely accepted by other existing projects, we can't really change about it.

So, keep things simple.

@jchrys
Copy link
Collaborator

jchrys commented Feb 21, 2024

@mirromutth I really appreciate for your efforts on this issue. Could you kindly elaborate on the rationale behind setting the default connectionTimeZone to LOCAL and adjusting DATETIME type mappings in the upcoming PR?

@jchrys Based on the discussion in micronaut-projects/micronaut-data#2388, I realized that if we tried to use different time zone modes by default, it might cause more complicated problems for some existing projects.

Like I said, in my opinion, ZonedDateTime and server time zone makes more sense. However, if LocalDateTime and the JVM local time zone are widely accepted by other existing projects, we can't really change about it.

So, keep things simple.

@mirromutth
Thank you for your explanation. I got it.

Copy link
Collaborator

@jchrys jchrys left a comment

Choose a reason for hiding this comment

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

overall lgtm.
just a nit and suggestions.

- Add `preserveInstants`, `connectionTimeZone` and `forceConnectionTimeZoneToSession`
- Default `connectionTimeZone` to "LOCAL"
- Mark `serverZoneId` as deprecated. It will notice users to use `connectionTimeZone` instead
- Add `TimeZoneIntegrationTest` to test JDBC alignment of time zone behavior
- Correct `OffsetTimeCodec` to not convert time zone
@mirromutth mirromutth force-pushed the 190-aligning-serverzoneid-behavior-with-connectiontimezonemysql-connector-j branch from cfe05a2 to 5a9b931 Compare February 22, 2024 06:58
Copy link
Collaborator

@jchrys jchrys left a comment

Choose a reason for hiding this comment

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

LGTM.
Given this changes default behavior(?), which version do you think best suits this change? (wonder if 1.1.2 would be enough for this changes WDYT?)

@mirromutth
Copy link
Contributor Author

I think we can release it and #243 on 1.1.2. This version mainly deals with date time and time zone problems.

While this may bring some breaking changes, we can add some wiki for it.

@jchrys
Copy link
Collaborator

jchrys commented Feb 22, 2024

I think we can release it and #243 on 1.1.2. This version mainly deals with date time and time zone problems.

While this may bring some breaking changes, we can add some wiki for it.

Got it. Thanks :D

@mirromutth mirromutth merged commit c0f72df into trunk Feb 22, 2024
15 checks passed
@mirromutth mirromutth deleted the 190-aligning-serverzoneid-behavior-with-connectiontimezonemysql-connector-j branch February 22, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Aligning serverZoneId Behavior with connectionTimeZone(mysql-connector-j)
2 participants