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
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
71aa9a8
feat: introduce java.time to java-bigtable
diegomarquezp Nov 14, 2024
62dd45f
fix tests i
diegomarquezp Nov 14, 2024
959a469
chore: generate libraries at Thu Nov 14 16:52:48 UTC 2024
cloud-java-bot Nov 14, 2024
ca275dc
fix tests
diegomarquezp Nov 14, 2024
a7746ad
make protobuf timestamp conversion fully precise (epoch seconds + nanos)
diegomarquezp Nov 14, 2024
321c952
Merge branch 'introduce-java-time' of https://github.com/googleapis/j…
diegomarquezp Nov 14, 2024
d25d6ef
resolve to microsecond level
diegomarquezp Nov 18, 2024
796aa4b
Revert "make protobuf timestamp conversion fully precise (epoch secon…
diegomarquezp Nov 18, 2024
a7e6167
restore ms precision
diegomarquezp Nov 18, 2024
0072191
fix precision in tests
diegomarquezp Nov 19, 2024
99600a6
fix tests
diegomarquezp Nov 19, 2024
3765977
fix tests, clirr
diegomarquezp Nov 19, 2024
38b13e9
fix test proxy
diegomarquezp Nov 20, 2024
f6efe6b
format
diegomarquezp Nov 20, 2024
41bc6ea
format ii
diegomarquezp Nov 20, 2024
e06a104
fix ITs
diegomarquezp Nov 22, 2024
fc920b0
fix it, timestamp precision
diegomarquezp Nov 22, 2024
9b6927a
Merge branch 'main' into introduce-java-time
diegomarquezp Nov 22, 2024
987c343
Merge remote-tracking branch 'origin/main' into introduce-java-time
diegomarquezp Nov 25, 2024
173d961
Merge remote-tracking branch 'refs/remotes/origin/introduce-java-time…
diegomarquezp Nov 25, 2024
de505d2
solve review comments
diegomarquezp Nov 25, 2024
dc19a86
treat tracer classes as internal
diegomarquezp Dec 5, 2024
ff1b0fa
Merge remote-tracking branch 'origin/main' into introduce-java-time
diegomarquezp Dec 5, 2024
5b6d8af
reset admin changes
diegomarquezp Dec 5, 2024
efe806b
update sql files (internal)
diegomarquezp Dec 5, 2024
812c5a5
format tracer files
diegomarquezp Dec 5, 2024
7deadf3
adapt admin tests
diegomarquezp Dec 5, 2024
e2b1621
adapt sql tests
diegomarquezp Dec 5, 2024
dde9326
changes in change stream
diegomarquezp Dec 5, 2024
6122ff1
chore: generate libraries at Thu Dec 5 23:02:28 UTC 2024
cloud-java-bot Dec 5, 2024
70d6712
ignore changes in beta and internal surface
diegomarquezp Dec 6, 2024
413703d
Merge branch 'introduce-java-time' of https://github.com/googleapis/j…
diegomarquezp Dec 6, 2024
21c4614
change imports instead of using full qualified names
diegomarquezp Dec 6, 2024
253d351
chore: generate libraries at Fri Dec 6 18:47:10 UTC 2024
cloud-java-bot Dec 6, 2024
ad9fa48
simplify imports
diegomarquezp Dec 6, 2024
07c939a
fix test proxy i
diegomarquezp Dec 6, 2024
d13c96b
Merge branch 'introduce-java-time' of https://github.com/googleapis/j…
diegomarquezp Dec 6, 2024
540b19d
restore metrics
diegomarquezp Dec 11, 2024
ce6a279
use threeten methods in tests
diegomarquezp Dec 11, 2024
51657d8
convert to internal changes in change stream classes
diegomarquezp Dec 11, 2024
06501e7
Revert "convert to internal changes in change stream classes"
diegomarquezp Dec 12, 2024
ed0213d
convert to internal changes in change stream classes ii
diegomarquezp Dec 12, 2024
5994e4f
fix clirr
diegomarquezp Dec 13, 2024
7ce813f
Merge branch 'main' into introduce-java-time
diegomarquezp Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions google-cloud-bigtable/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,25 @@
<className>com/google/cloud/bigtable/data/v2/stub/metrics/DefaultMetricsProvider</className>
<method>*</method>
</difference>
<difference>
<!-- InternalApi was updated -->
<differenceType>7006</differenceType>
<className>com/google/cloud/bigtable/data/v2/internal/*</className>
<method>*getTimestamp(*)</method>
<to>java.time.Instant</to>
</difference>
<difference>
<!-- BetaApi was updated -->
<differenceType>7006</differenceType>
<className>com/google/cloud/bigtable/data/v2/models/sql/StructReader</className>
<method>*getTimestamp(*)</method>
<to>java.time.Instant</to>
</difference>
<difference>
<!-- BetaApi was updated -->
<differenceType>7005</differenceType>
<className>com/google/cloud/bigtable/data/v2/models/sql/Statement$Builder</className>
<method>*setTimestampParam(java.lang.String, org.threeten.bp.Instant)</method>
<to>*setTimestampParam(java.lang.String, java.time.Instant)</to>
</difference>
</differences>
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.protobuf.ByteString;
import java.time.Instant;
diegomarquezp marked this conversation as resolved.
Show resolved Hide resolved
import java.util.List;
import org.threeten.bp.Instant;

/**
* Shared type implementations. Right now this is only used by SqlType but this will become a shared
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.threeten.bp.Duration;

/**
* Settings class to configure an instance of {@link BigtableDataClient}.
Expand Down Expand Up @@ -134,9 +133,11 @@ public static Builder newBuilderForEmulator(String hostname, int port) {
.setMaxInboundMessageSize(256 * 1024 * 1024)
.setChannelPoolSettings(ChannelPoolSettings.staticallySized(1))
.setChannelConfigurator(ManagedChannelBuilder::usePlaintext)
.setKeepAliveTime(Duration.ofSeconds(61)) // sends ping in this interval
.setKeepAliveTimeout(
Duration.ofSeconds(10)) // wait this long before considering the connection dead
.setKeepAliveTimeDuration(
java.time.Duration.ofSeconds(61)) // sends ping in this interval
.setKeepAliveTimeoutDuration(
java.time.Duration.ofSeconds(
10)) // wait this long before considering the connection dead
.build());

LOGGER.info("Connecting to the Bigtable emulator at " + hostname + ":" + port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import com.google.protobuf.Timestamp;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.threeten.bp.Instant;

@InternalApi
public abstract class AbstractProtoStructReader implements StructReader {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
import com.google.cloud.bigtable.data.v2.stub.sql.SqlServerStream;
import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import java.time.Instant;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.threeten.bp.Instant;

/**
* The primary implementation of a ResultSet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
*/
package com.google.cloud.bigtable.data.v2.models;

import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant;

import com.google.api.core.InternalApi;
import com.google.api.core.ObsoleteApi;
import com.google.auto.value.AutoValue;
import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange;
import com.google.cloud.bigtable.data.v2.stub.changestream.ChangeStreamRecordMerger;
import com.google.common.collect.ImmutableList;
import com.google.protobuf.ByteString;
import java.io.Serializable;
import javax.annotation.Nonnull;
import org.threeten.bp.Instant;

/**
* A ChangeStreamMutation represents a list of mods(represented by List<{@link Entry}>) targeted at
Expand Down Expand Up @@ -73,13 +75,13 @@ public enum MutationType {
static Builder createUserMutation(
@Nonnull ByteString rowKey,
@Nonnull String sourceClusterId,
Instant commitTimestamp,
java.time.Instant commitTimestamp,
int tieBreaker) {
return builder()
.setRowKey(rowKey)
.setType(MutationType.USER)
.setSourceClusterId(sourceClusterId)
.setCommitTimestamp(commitTimestamp)
.setCommitTime(commitTimestamp)
.setTieBreaker(tieBreaker);
}

Expand All @@ -89,12 +91,12 @@ static Builder createUserMutation(
* mutation.
*/
static Builder createGcMutation(
@Nonnull ByteString rowKey, Instant commitTimestamp, int tieBreaker) {
@Nonnull ByteString rowKey, java.time.Instant commitTimestamp, int tieBreaker) {
return builder()
.setRowKey(rowKey)
.setType(MutationType.GARBAGE_COLLECTION)
.setSourceClusterId("")
.setCommitTimestamp(commitTimestamp)
.setCommitTime(commitTimestamp)
.setTieBreaker(tieBreaker);
}

Expand All @@ -110,8 +112,14 @@ static Builder createGcMutation(
@Nonnull
public abstract String getSourceClusterId();

/** This method is obsolete. Use {@link #getCommitTime()} instead. */
@ObsoleteApi("Use getCommitTime() instead")
public org.threeten.bp.Instant getCommitTimestamp() {
return toThreetenInstant(getCommitTime());
}

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

/**
* Get the tie breaker of the current mutation. This is used to resolve conflicts when multiple
Expand All @@ -123,8 +131,14 @@ static Builder createGcMutation(
@Nonnull
public abstract String getToken();

/** This method is obsolete. Use {@link #getEstimatedLowWatermarkTime()} instead. */
@ObsoleteApi("Use getEstimatedLowWatermarkTime() instead")
public org.threeten.bp.Instant getEstimatedLowWatermark() {
return toThreetenInstant(getEstimatedLowWatermarkTime());
}

/** Get the low watermark of the current mutation. */
public abstract Instant getEstimatedLowWatermark();
public abstract java.time.Instant getEstimatedLowWatermarkTime();

/** Get the list of mods of the current mutation. */
@Nonnull
Expand All @@ -145,15 +159,15 @@ abstract static class Builder {

abstract Builder setSourceClusterId(@Nonnull String sourceClusterId);

abstract Builder setCommitTimestamp(Instant commitTimestamp);
abstract Builder setCommitTime(java.time.Instant commitTimestamp);

abstract Builder setTieBreaker(int tieBreaker);

abstract ImmutableList.Builder<Entry> entriesBuilder();

abstract Builder setToken(@Nonnull String token);

abstract Builder setEstimatedLowWatermark(Instant estimatedLowWatermark);
abstract Builder setEstimatedLowWatermarkTime(java.time.Instant estimatedLowWatermark);

Builder setCell(
@Nonnull String familyName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.google.bigtable.v2.ReadChangeStreamResponse;
import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange;
import com.google.protobuf.ByteString;
import java.time.Instant;
import javax.annotation.Nonnull;
import org.threeten.bp.Instant;

/**
* An extension point that allows end users to plug in a custom implementation of logical change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange;
import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import java.time.Instant;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.threeten.bp.Instant;

/**
* Default implementation of a {@link ChangeStreamRecordAdapter} that uses {@link
Expand Down Expand Up @@ -112,8 +112,7 @@ public void startUserMutation(

/** {@inheritDoc} */
@Override
public void startGcMutation(
@Nonnull ByteString rowKey, Instant commitTimestamp, int tieBreaker) {
public void startGcMutation(ByteString rowKey, Instant commitTimestamp, int tieBreaker) {
this.changeStreamMutationBuilder =
ChangeStreamMutation.createGcMutation(rowKey, commitTimestamp, tieBreaker);
}
Expand Down Expand Up @@ -176,9 +175,9 @@ public void finishCell() {
/** {@inheritDoc} */
@Override
public ChangeStreamRecord finishChangeStreamMutation(
@Nonnull String token, Instant estimatedLowWatermark) {
String token, Instant estimatedLowWatermark) {
this.changeStreamMutationBuilder.setToken(token);
this.changeStreamMutationBuilder.setEstimatedLowWatermark(estimatedLowWatermark);
this.changeStreamMutationBuilder.setEstimatedLowWatermarkTime(estimatedLowWatermark);
return this.changeStreamMutationBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package com.google.cloud.bigtable.data.v2.models;

import static com.google.api.gax.util.TimeConversionUtils.toThreetenInstant;

import com.google.api.core.InternalApi;
import com.google.api.core.ObsoleteApi;
import com.google.auto.value.AutoValue;
import com.google.bigtable.v2.ReadChangeStreamResponse;
import java.io.Serializable;
import javax.annotation.Nonnull;
import org.threeten.bp.Instant;

/** A simple wrapper for {@link ReadChangeStreamResponse.Heartbeat}. */
@InternalApi("Intended for use by the BigtableIO in apache/beam only.")
Expand All @@ -29,22 +31,29 @@ public abstract class Heartbeat implements ChangeStreamRecord, Serializable {
private static final long serialVersionUID = 7316215828353608504L;

private static Heartbeat create(
ChangeStreamContinuationToken changeStreamContinuationToken, Instant estimatedLowWatermark) {
ChangeStreamContinuationToken changeStreamContinuationToken,
java.time.Instant estimatedLowWatermark) {
return new AutoValue_Heartbeat(changeStreamContinuationToken, estimatedLowWatermark);
}

/** Wraps the protobuf {@link ReadChangeStreamResponse.Heartbeat}. */
static Heartbeat fromProto(@Nonnull ReadChangeStreamResponse.Heartbeat heartbeat) {
return create(
ChangeStreamContinuationToken.fromProto(heartbeat.getContinuationToken()),
Instant.ofEpochSecond(
java.time.Instant.ofEpochSecond(
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 #getEstimatedLowWatermarkTime()} instead. */
@ObsoleteApi("Use getEstimatedLowWatermarkTime() instead")
public org.threeten.bp.Instant getEstimatedLowWatermark() {
return toThreetenInstant(getEstimatedLowWatermarkTime());
}

@InternalApi("Intended for use by the BigtableIO in apache/beam only.")
public abstract Instant getEstimatedLowWatermark();
public abstract java.time.Instant getEstimatedLowWatermarkTime();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
*/
package com.google.cloud.bigtable.data.v2.models;

import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeDuration;
import static com.google.api.gax.util.TimeConversionUtils.toJavaTimeInstant;

import com.google.api.core.InternalApi;
import com.google.api.core.ObsoleteApi;
import com.google.bigtable.v2.ReadChangeStreamRequest;
import com.google.bigtable.v2.RowRange;
import com.google.bigtable.v2.StreamContinuationTokens;
Expand All @@ -36,7 +40,6 @@
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.threeten.bp.Instant;

/** A simple wrapper to construct a query for the ReadChangeStream RPC. */
@InternalApi("Intended for use by the BigtableIO in apache/beam only.")
Expand Down Expand Up @@ -143,8 +146,14 @@ public ReadChangeStreamQuery streamPartition(ByteStringRange range) {
return streamPartition(rangeBuilder.build());
}

/** This method is obsolete. Use {@link #startTime(java.time.Instant)} instead. */
@ObsoleteApi("Use startTime(java.time.Instant) instead")
public ReadChangeStreamQuery startTime(org.threeten.bp.Instant value) {
return startTime(toJavaTimeInstant(value));
}

/** Sets the startTime to read the change stream. */
public ReadChangeStreamQuery startTime(Instant value) {
public ReadChangeStreamQuery startTime(java.time.Instant value) {
Preconditions.checkState(
!builder.hasContinuationTokens(),
"startTime and continuationTokens can't be specified together");
Expand All @@ -156,8 +165,14 @@ public ReadChangeStreamQuery startTime(Instant value) {
return this;
}

/** This method is obsolete. Use {@link #endTime(java.time.Instant)} instead. */
@ObsoleteApi("Use endTime(java.time.Instant) instead")
public ReadChangeStreamQuery endTime(org.threeten.bp.Instant value) {
return endTime(toJavaTimeInstant(value));
}

/** Sets the endTime to read the change stream. */
public ReadChangeStreamQuery endTime(Instant value) {
public ReadChangeStreamQuery endTime(java.time.Instant value) {
builder.setEndTime(
Timestamp.newBuilder()
.setSeconds(value.getEpochSecond())
Expand All @@ -181,8 +196,14 @@ public ReadChangeStreamQuery continuationTokens(
return this;
}

/** Sets the heartbeat duration for the change stream. */
/** This method is obsolete. Use {@link #heartbeatDuration(java.time.Duration)} instead. */
@ObsoleteApi("Use heartbeatDuration(java.time.Duration) instead")
public ReadChangeStreamQuery heartbeatDuration(org.threeten.bp.Duration duration) {
return heartbeatDuration(toJavaTimeDuration(duration));
}

/** Sets the heartbeat duration for the change stream. */
public ReadChangeStreamQuery heartbeatDuration(java.time.Duration duration) {
builder.setHeartbeatDuration(
Duration.newBuilder()
.setSeconds(duration.getSeconds())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import com.google.cloud.bigtable.common.Type.StructWithSchema;
import com.google.protobuf.ByteString;
import java.io.Serializable;
import java.time.Instant;
import java.util.List;
import org.threeten.bp.Instant;

/**
* Represents a data type in a SQL query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import com.google.common.collect.ImmutableMap;
import com.google.protobuf.ByteString;
import com.google.protobuf.Timestamp;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.threeten.bp.Instant;

/**
* A SQL statement that can be executed by calling {@link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import com.google.api.core.BetaApi;
import com.google.cloud.Date;
import com.google.protobuf.ByteString;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import org.threeten.bp.Instant;

/**
* An interface for reading the columns of a {@code Struct} or {@code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Stopwatch;
import com.google.common.util.concurrent.RateLimiter;
import java.time.Duration;
import java.time.Instant;
diegomarquezp marked this conversation as resolved.
Show resolved Hide resolved
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import org.threeten.bp.Duration;
import org.threeten.bp.Instant;

class RateLimitingServerStreamingCallable
extends ServerStreamingCallable<MutateRowsRequest, MutateRowsResponse> {
Expand Down
Loading
Loading