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 #2415

Merged
merged 44 commits into from
Dec 13, 2024
Merged

feat: introduce java.time #2415

merged 44 commits into from
Dec 13, 2024

Conversation

diegomarquezp
Copy link
Contributor

@diegomarquezp diegomarquezp commented Nov 14, 2024

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).

Note: https://cloud.google.com/bigtable/docs/reference/sql/data-types#timestamp_type implies that nanosecond precision will be ignored.

@product-auto-label product-auto-label bot added size: l Pull request size is large. api: bigtable Issues related to the googleapis/java-bigtable API. labels Nov 14, 2024
@diegomarquezp diegomarquezp added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 20, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Nov 20, 2024
@diegomarquezp
Copy link
Contributor Author

ci / windows failing in several PRs - see this job from #2425

@diegomarquezp diegomarquezp marked this pull request as ready for review November 22, 2024 02:12
@diegomarquezp diegomarquezp requested review from a team as code owners November 22, 2024 02:12
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. Bigtable team for final approval

@diegomarquezp diegomarquezp removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Dec 7, 2024
Copy link
Contributor

@mutianf mutianf left a comment

Choose a reason for hiding this comment

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

I reviewed the following:

  • common/Type.java
  • data/v2/BigtableDataSettings.java
  • data/v2/stub
  • data/v2/metrics
  • gaxx/retrying
  • and tests related to these changes.

@@ -124,9 +123,10 @@ public void attemptCancelled() {
}
}

public void attemptFailed(Throwable error, 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.

Instead of deleting this method, should attemptFailled call attemptFailedDuration?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We moved all references in gax to attemptFailedDuration
googleapis/sdk-platform-java#1872

However it still makes sense to keep both. I'll push a commit with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed our tracking sheet has a new comment in there. Confirmed it should be as you pointed out.

@@ -38,7 +38,7 @@ public class BigtableBatchingCallSettingsTest {
BatchingSettings.newBuilder()
.setElementCountThreshold(10L)
.setRequestByteThreshold(20L)
.setDelayThreshold(Duration.ofMillis(5))
Copy link
Contributor

Choose a reason for hiding this comment

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

Im wondering if we should keep the test code the same so that we can verify these settings are ported to the new settings correctly? We can leave a todo to update them in a separate PR.

@@ -149,11 +149,11 @@ public void testAttemptCancelled() {
public void testAttemptFailed() {
RuntimeException error = new RuntimeException();
Duration delay = Duration.ofMillis(10);
compositeTracer.attemptFailed(error, delay);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here, I think we should keep calling attemptFailed and verify attemptFailedDuration gets called?

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Dec 11, 2024
Copy link
Contributor

@jackdingilian jackdingilian left a comment

Choose a reason for hiding this comment

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

I reviewed the following files and their corresponding tests:
internal/AbstractProtoStructReader.java
internal/ResultSetImpl.java
models/ChangeStreamMutation.java
models/ChangeStreamRecordAdapter.java
models/Heartbeat.java
models/ReadChangeStreamQuery.java
models/sql/SqlType.java
models/sql/Statement.java
models/sql/StructReader.java
changestream/ChangeStreamStateMachine.java


/** This method is obsolete. Use {@link #setCommitTime(java.time.Instant)} instead. */
@ObsoleteApi("Use setCommitTime(java.time.Instant) instead")
abstract Builder setCommitTimestamp(org.threeten.bp.Instant commitTimestamp);
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 it would be better to remove the threeten setter, only store it as java.time.Instant, and then reverse the overload of getCommitTime(stamp) above.

The builder is fully internal, we just need to maintain backwards compatibility for the getter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the catch. This was indeed stated in the tracking sheet. I'll update this as an internal class.


abstract Builder setTieBreaker(int tieBreaker);

abstract ImmutableList.Builder<Entry> entriesBuilder();

abstract Builder setToken(@Nonnull String token);

abstract Builder setEstimatedLowWatermark(Instant estimatedLowWatermark);
Builder setLowWatermarkTime(java.time.Instant estimatedLowWatermark) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as for commit time. Also if we need to keep both setters this should be 'setEstimatedLowWatermarkTime'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, done.

}

/** This method is obsolete. Use {@link #setLowWatermarkTime(java.time.Instant)} instead. */
@ObsoleteApi("Use setEstimatedLowWatermarkInstant(java.time.Instant) instead")
Copy link
Contributor

Choose a reason for hiding this comment

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

setEstimatedLowWatermarkInstant should be setEstimatedLowWatermarkTime

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be removed since it's an internal api change as per #2415 (comment)

heartbeat.getEstimatedLowWatermark().getSeconds(),
heartbeat.getEstimatedLowWatermark().getNanos()));
}

@InternalApi("Intended for use by the BigtableIO in apache/beam only.")
public abstract ChangeStreamContinuationToken getChangeStreamContinuationToken();

/** This method is obsolete. Use {@link #getEstimatedLowWatermarkInstant()} instead. */
@ObsoleteApi("Use getEstimatedLowWatermarkInstant() instead")
public abstract org.threeten.bp.Instant getEstimatedLowWatermark();
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as in ChangeStreamMutation. Wouldn't it be better to store this as java.time.Instant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, done.

@InternalApi("Intended for use by the BigtableIO in apache/beam only.")
public abstract Instant getEstimatedLowWatermark();
public java.time.Instant getEstimatedLowWatermarkInstant() {
Copy link
Contributor

Choose a reason for hiding this comment

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

In ChangeStreamMutation we call this getEstimatedLowWatermarkTime. We should be consistent w that naming here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed as this is an internal api. I only kept the java.time version

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Dec 11, 2024
@@ -110,8 +109,7 @@ static Builder createGcMutation(
@Nonnull
public abstract String getSourceClusterId();

/** Get the commit timestamp of the current mutation. */
public abstract Instant getCommitTimestamp();
public abstract java.time.Instant getCommitTimestamp();
Copy link
Contributor

Choose a reason for hiding this comment

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

We still need the threeten getter here, since this is used by beam users. Same for Heartbeat below

Copy link
Contributor

Choose a reason for hiding this comment

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

And for estimatedLowWatermark

@product-auto-label product-auto-label bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Dec 12, 2024
@diegomarquezp
Copy link
Contributor Author

diegomarquezp commented Dec 12, 2024

@jackdingilian thanks for the review and apologies for the misunderstanding. This time I got it right:

  • ChangeStreamMutation.Builder setters directly switched to java.time, no overloads.
  • ChangeStreamMutation getters have been swapped: java.time is abstract and threeten delegates.
  • We respect the java.time name getEstimatedLowWatermarkTime (the Instant suffix was corrected)
  • Heartbeat getters have been swapped: java.time is abstract and threeten delegates.

@diegomarquezp diegomarquezp added the automerge Merge the pull request once unit tests and other checks pass. label Dec 13, 2024
@gcf-merge-on-green gcf-merge-on-green bot merged commit bb96c3e into main Dec 13, 2024
22 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 13, 2024
@gcf-merge-on-green gcf-merge-on-green bot deleted the introduce-java-time branch December 13, 2024 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the googleapis/java-bigtable API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants