Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.bigtable.v2.Mutation.DeleteFromRow;
import com.google.bigtable.v2.Mutation.MergeToCell;
import com.google.bigtable.v2.Mutation.SetCell;
import com.google.bigtable.v2.Mutation.TimestampOrigin;
import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
Expand All @@ -32,6 +33,8 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import javax.annotation.Nonnull;

Expand Down Expand Up @@ -154,9 +157,9 @@ public Mutation setCell(
@Override
public Mutation setCell(
@Nonnull String familyName, @Nonnull ByteString qualifier, @Nonnull ByteString value) {
long timestamp = System.currentTimeMillis() * 1_000;
long timestamp = Instant.EPOCH.until(Instant.now(), ChronoUnit.MICROS);

return setCell(familyName, qualifier, timestamp, value);
return setCell(familyName, qualifier, timestamp, value, TimestampOrigin.CLIENT_AUTO_GENERATED);
}

@Override
Expand All @@ -165,6 +168,15 @@ public Mutation setCell(
@Nonnull ByteString qualifier,
long timestamp,
@Nonnull ByteString value) {
return setCell(familyName, qualifier, timestamp, value, TimestampOrigin.USER_SPECIFIED);
}

private Mutation setCell(
@Nonnull String familyName,
@Nonnull ByteString qualifier,
long timestamp,
@Nonnull ByteString value,
TimestampOrigin timestampOrigin) {
Validations.validateFamily(familyName);
Preconditions.checkNotNull(qualifier, "qualifier can't be null.");
Preconditions.checkNotNull(value, "value can't be null.");
Expand All @@ -182,6 +194,7 @@ public Mutation setCell(
.setTimestampMicros(timestamp)
.setValue(value)
.build())
.setTimestampOrigin(timestampOrigin)
.build());

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,8 @@ private Builder() {
.setDirectAccessRequested(isDirectPathRequested)
.setTrafficDirectorEnabled(isDirectPathRequested)
.setPeerInfo(true)
.setSessionsCompatible(true);
.setSessionsCompatible(true)
.setMicrosecondTimestamp(true);
}

private Builder(EnhancedBigtableStubSettings settings) {
Expand Down Expand Up @@ -1008,6 +1009,7 @@ public EnhancedBigtableStubSettings build() {

featureFlags.setRoutingCookie(true);
featureFlags.setRetryInfo(true);
featureFlags.setMicrosecondTimestamp(true);
// client_Side_metrics_enabled feature flag is only set when a user is running with a
// DefaultMetricsProvider. This may cause false negatives when a user registered the
// metrics on their CustomOpenTelemetryMetricsProvider.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public class BulkMutateIT {

@Test(timeout = 60 * 1000)
public void test() throws IOException, InterruptedException {
assume()
.withMessage("Emulator does not support microsecond timestamp granularity")
.that(testEnvRule.env())
.isNotInstanceOf(EmulatorEnv.class);

BigtableDataSettings settings = testEnvRule.env().getDataClientSettings();
String rowPrefix = UUID.randomUUID().toString();
// Set target latency really low so it'll trigger adjusting thresholds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public class CheckAndMutateIT {

@Test
public void test() throws Exception {
assume()
.withMessage("Emulator does not support microsecond timestamp granularity")
.that(testEnvRule.env())
.isNotInstanceOf(EmulatorEnv.class);

TableId tableId = testEnvRule.env().getTableId();
String familyId = testEnvRule.env().getFamilyId();
String rowKey = UUID.randomUUID().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public class MutateRowIT {

@Test
public void test() throws Exception {
assume()
.withMessage("Emulator does not support microsecond timestamp granularity")
.that(testEnvRule.env())
.isNotInstanceOf(EmulatorEnv.class);

String rowKey = UUID.randomUUID().toString();
String familyId = testEnvRule.env().getFamilyId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.bigtable.v2.Mutation.DeleteFromFamily;
import com.google.bigtable.v2.Mutation.DeleteFromRow;
import com.google.bigtable.v2.Mutation.MergeToCell;
import com.google.bigtable.v2.Mutation.TimestampOrigin;
import com.google.cloud.bigtable.data.v2.models.Range.TimestampRange;
import com.google.common.primitives.Longs;
import com.google.protobuf.ByteString;
Expand All @@ -30,6 +31,8 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -48,7 +51,7 @@ public void setUp() {

@Test
public void setCellTest() {
long minTimestamp = System.currentTimeMillis() * 1_000;
long minTimestamp = Instant.EPOCH.until(Instant.now(), ChronoUnit.MICROS);

mutation
.setCell(
Expand All @@ -65,7 +68,7 @@ public void setCellTest() {

List<com.google.bigtable.v2.Mutation> actual = mutation.getMutations();

long maxTimestamp = System.currentTimeMillis() * 1_000;
long maxTimestamp = Instant.EPOCH.until(Instant.now(), ChronoUnit.MICROS);
com.google.common.collect.Range<Long> expectedTimestampRange =
com.google.common.collect.Range.closed(minTimestamp, maxTimestamp);

Expand All @@ -77,27 +80,31 @@ public void setCellTest() {
assertThat(actual.get(0).getSetCell().getValue())
.isEqualTo(ByteString.copyFromUtf8("fake-value"));
assertThat(actual.get(0).getSetCell().getTimestampMicros()).isEqualTo(1_000);
assertThat(actual.get(0).getTimestampOrigin()).isEqualTo(TimestampOrigin.USER_SPECIFIED);

assertThat(actual.get(1).getSetCell().getFamilyName()).isEqualTo("fake-family");
assertThat(actual.get(1).getSetCell().getColumnQualifier())
.isEqualTo(ByteString.copyFromUtf8("fake-qualifier"));
assertThat(actual.get(1).getSetCell().getValue())
.isEqualTo(ByteString.copyFromUtf8("fake-value"));
assertThat(actual.get(1).getSetCell().getTimestampMicros()).isIn(expectedTimestampRange);
assertThat(actual.get(1).getTimestampOrigin()).isEqualTo(TimestampOrigin.CLIENT_AUTO_GENERATED);

assertThat(actual.get(2).getSetCell().getFamilyName()).isEqualTo("fake-family2");
assertThat(actual.get(2).getSetCell().getColumnQualifier())
.isEqualTo(ByteString.copyFromUtf8("fake-qualifier2"));
assertThat(actual.get(2).getSetCell().getValue())
.isEqualTo(ByteString.copyFromUtf8("fake-value2"));
assertThat(actual.get(2).getSetCell().getTimestampMicros()).isEqualTo(1_000);
assertThat(actual.get(2).getTimestampOrigin()).isEqualTo(TimestampOrigin.USER_SPECIFIED);

assertThat(actual.get(3).getSetCell().getFamilyName()).isEqualTo("fake-family2");
assertThat(actual.get(3).getSetCell().getColumnQualifier())
.isEqualTo(ByteString.copyFromUtf8("fake-qualifier2"));
assertThat(actual.get(3).getSetCell().getValue())
.isEqualTo(ByteString.copyFromUtf8("fake-value2"));
assertThat(actual.get(3).getSetCell().getTimestampMicros()).isIn(expectedTimestampRange);
assertThat(actual.get(3).getTimestampOrigin()).isEqualTo(TimestampOrigin.CLIENT_AUTO_GENERATED);

assertThat(Mutation.fromProtoUnsafe(actual).getMutations()).isEqualTo(actual);
}
Expand All @@ -113,6 +120,7 @@ public void setCellWithServerSideTimestamp() {
List<com.google.bigtable.v2.Mutation> actual = mutation.getMutations();
assertThat(actual.get(0).getSetCell().getTimestampMicros())
.isEqualTo(Mutation.SERVER_SIDE_TIMESTAMP);
assertThat(actual.get(0).getTimestampOrigin()).isEqualTo(TimestampOrigin.USER_SPECIFIED);
}

@Test
Expand Down Expand Up @@ -276,6 +284,10 @@ public void testWithLongValue() {

assertThat(actualMutation.getSetCell().getValue())
.isEqualTo(ByteString.copyFrom(Longs.toByteArray(100_000L)));
assertThat(mutations.get(0).getTimestampOrigin())
.isEqualTo(TimestampOrigin.CLIENT_AUTO_GENERATED);
assertThat(mutations.get(1).getTimestampOrigin())
.isEqualTo(TimestampOrigin.CLIENT_AUTO_GENERATED);

assertThat(mutations.get(2).getSetCell())
.isEqualTo(
Expand All @@ -285,6 +297,7 @@ public void testWithLongValue() {
.setTimestampMicros(30_000L)
.setValue(ByteString.copyFrom(Longs.toByteArray(20_000L)))
.build());
assertThat(mutations.get(2).getTimestampOrigin()).isEqualTo(TimestampOrigin.USER_SPECIFIED);
}

@Test
Expand Down
Loading
Loading