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

feat: introduce java.time variables and methods #3495

Merged
merged 6 commits into from
Dec 5, 2024

Conversation

diegomarquezp
Copy link
Contributor

This PR introduces java.time alternatives to existing org.threeten.bp.* methods, as well as switching internal variables (if any) to java.time

The main constraint is to keep the changes backwards compatible, so for each existing threeten method "method1(org.threeten.bp.Duration)" we will add an alternative with a Duration (or Timestamp when applicable) suffix: "method1Duration(java.time.Duration)".

For most cases, the implementation will be held in the java.time method and the old threeten method will just delegate the call to it. However, for the case of abstract classes, the implementation will be kept in the threeten method to avoid breaking changes (i.e. users that already overloaded the method in their user code).

@diegomarquezp diegomarquezp requested a review from a team as a code owner November 21, 2024 20:32
@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Nov 21, 2024
@diegomarquezp diegomarquezp marked this pull request as draft November 21, 2024 20:32
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label Nov 21, 2024
@diegomarquezp diegomarquezp added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 21, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 21, 2024
@diegomarquezp diegomarquezp marked this pull request as ready for review November 21, 2024 22:50
@diegomarquezp diegomarquezp requested a review from a team as a code owner November 21, 2024 22:50
@diegomarquezp diegomarquezp requested a review from lqiu96 November 21, 2024 22:50
@diegomarquezp diegomarquezp requested a review from lqiu96 November 22, 2024 19:11
@@ -275,7 +275,7 @@ public void onSessionCreateFailure(Throwable t, int createFailureForSessionCount

private static void maybeWaitForSessionCreation(
SessionPoolOptions sessionPoolOptions, ApiFuture<SessionReference> future) {
org.threeten.bp.Duration waitDuration = sessionPoolOptions.getWaitForMinSessions();
java.time.Duration waitDuration = sessionPoolOptions.getWaitForMinSessions();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: java.time.Duration is already imported in this class. Can't we just remove org.threeten.bp.

@@ -109,7 +108,7 @@ public void attemptCancelled() {
}

@Override
public void attemptFailed(Throwable error, Duration delay) {
public void attemptFailed(Throwable error, org.threeten.bp.Duration delay) {
Copy link
Contributor

@sakthivelmanii sakthivelmanii Nov 26, 2024

Choose a reason for hiding this comment

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

nit: Can we import java.time.Duration so that we can remove java.time. in attemptFailedDuration method? https://github.com/googleapis/java-spanner/blob/main/google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java#L119

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@Override
public void attemptFailed(Throwable error, Duration delay) {
public void attemptFailedDuration(Throwable error, java.time.Duration delay) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Can we import java.time.Duration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -63,8 +66,8 @@ public class SessionPoolOptions {
@Deprecated private final long initialWaitForSessionTimeoutMillis;

private final boolean autoDetectDialect;
private final Duration waitForMinSessions;
private final Duration acquireSessionTimeout;
private final java.time.Duration waitForMinSessions;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We can import java.time.Duration so that in future we don't have a confusion on which class to use

Copy link
Contributor

Choose a reason for hiding this comment

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

and also it avoids so many changes in the code which is not really necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@sakthivelmanii
Copy link
Contributor

sakthivelmanii commented Nov 26, 2024

@diegomarquezp Can we make sure following in all the files?

import java.time.Duration in all the files(whereever is required) and use org.threeten.bp.Duration directly in obsolete methods. This avoids lot of code changes which is unnecessary. This also provides the standard that java.time.Duration should be used.

@diegomarquezp
Copy link
Contributor Author

diegomarquezp commented Nov 27, 2024

@diegomarquezp Can we make sure following in all the files?

import java.time.Duration in all the files(whereever is required) and use org.threeten.bp.Duration directly in obsolete methods. This avoids lot of code changes which is unnecessary. This also provides the standard that java.time.Duration should be used.

@sakthivelmanii Thanks for the review! Before switching to import java.time.Duration I'd like to double check if our rationale for not importing java.time.* seems sound to you: this is mainly to make it clear to the reader that there are two Duration/Instant classes coexisting in the same file and attention should be paid. We deliberately added these changes just to make this differentiation as explicit as possible. We've been doing it this way in other repos (e.g. googleapis/java-pubsub#2271 (comment)) (doesn't mean it should be done as in other repos).

Promoting java.time as the standard also makes sense, and it's ultimately the Spanner team's call, but wanted to make sure our approach doesn't come up as unintended. I'm happy to move forward either way.

@@ -106,26 +106,26 @@ public boolean hasDuration() {
});
}

org.threeten.bp.Duration asDuration() {
java.time.Duration asDuration() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to keep this one in favor of com.google.protobuf.Duration

Copy link
Contributor

@lqiu96 lqiu96 left a comment

Choose a reason for hiding this comment

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

LGTM. Spanner team for approval.

@diegomarquezp diegomarquezp added the automerge Merge the pull request once unit tests and other checks pass. label Dec 5, 2024
@gcf-merge-on-green gcf-merge-on-green bot merged commit 8a7d533 into main Dec 5, 2024
34 checks passed
@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Dec 5, 2024
@gcf-merge-on-green gcf-merge-on-green bot deleted the introduce-java-time branch December 5, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants