Skip to content

Commit a140bcb

Browse files
igorbernstein2garrettjonesgoogle
authored andcommitted
---
yaml --- r: 9077 b: refs/heads/master c: 54cd111 h: refs/heads/master i: 9075: 4798255
1 parent 72faf62 commit a140bcb

8 files changed

Lines changed: 334 additions & 7 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 65de2f3f12a01aef016d9c8031702f7df459ffc3
2+
refs/heads/master: 54cd111d6313d604b2c97e472feaf8102927caea
33
refs/heads/travis: 47e4fee4fd5af9b2a8ce46f23c72ec95f9b195b2
44
refs/heads/gh-pages: 8e9b065ba06cd7a4af306aaea1010aade81670e0
55
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444

trunk/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataClient.java

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.api.gax.rpc.UnaryCallable;
2424
import com.google.bigtable.admin.v2.InstanceName;
2525
import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation;
26+
import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow;
2627
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub;
2728
import com.google.cloud.bigtable.data.v2.models.KeyOffset;
2829
import com.google.cloud.bigtable.data.v2.models.Query;
@@ -334,12 +335,6 @@ public UnaryCallable<RowMutation, Void> mutateRowCallable() {
334335
return stub.mutateRowCallable();
335336
}
336337

337-
/** Close the clients and releases all associated resources. */
338-
@Override
339-
public void close() throws Exception {
340-
stub.close();
341-
}
342-
343338
/**
344339
* Convenience method to asynchronously mutate a row atomically based on the output of a filter.
345340
*
@@ -383,4 +378,54 @@ public ApiFuture<Boolean> checkAndMutateRowAsync(ConditionalRowMutation mutation
383378
public UnaryCallable<ConditionalRowMutation, Boolean> checkAndMutateRowCallable() {
384379
return stub.checkAndMutateRowCallable();
385380
}
381+
382+
/**
383+
* Convenience method that asynchronously modifies a row atomically on the server. The method
384+
* reads the latest existing timestamp and value from the specified columns and writes a new
385+
* entry. The new value for the timestamp is the greater of the existing timestamp or the current
386+
* server time. The method returns the new contents of all modified cells.
387+
*
388+
* <p>Sample code:
389+
*
390+
* <pre>{@code
391+
* InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
392+
* try (BigtableClient bigtableClient = BigtableClient.create(instanceName)) {
393+
* ReadModifyWriteRow mutation = ReadModifyWriteRow.create("[TABLE]", "[KEY]")
394+
* .increment("[FAMILY]", "[QUALIFIER]", 1)
395+
* .append("[FAMILY2]", "[QUALIFIER2]", "suffix");
396+
*
397+
* ApiFuture<Row> success = bigtableClient.readModifyWriteRowAsync(mutation);
398+
* }</pre>
399+
*/
400+
public ApiFuture<Row> readModifyWriteRowAsync(ReadModifyWriteRow mutation) {
401+
return readModifyWriteRowCallable().futureCall(mutation);
402+
}
403+
404+
/**
405+
* Modifies a row atomically on the server. The method reads the latest existing timestamp and
406+
* value from the specified columns and writes a new entry. The new value for the timestamp is the
407+
* greater of the existing timestamp or the current server time. The method returns the new
408+
* contents of all modified cells.
409+
*
410+
* <p>Sample code:
411+
*
412+
* <pre>{@code
413+
* InstanceName instanceName = InstanceName.of("[PROJECT]", "[INSTANCE]");
414+
* try (BigtableClient bigtableClient = BigtableClient.create(instanceName)) {
415+
* ReadModifyWriteRow mutation = ReadModifyWriteRow.create("[TABLE]", "[KEY]")
416+
* .increment("[FAMILY]", "[QUALIFIER]", 1)
417+
* .append("[FAMILY2]", "[QUALIFIER2]", "suffix");
418+
*
419+
* Row row = bigtableClient.readModifyWriteRowCallable().call(mutation);
420+
* }</pre>
421+
*/
422+
public UnaryCallable<ReadModifyWriteRow, Row> readModifyWriteRowCallable() {
423+
return stub.readModifyWriteRowCallable();
424+
}
425+
426+
/** Close the clients and releases all associated resources. */
427+
@Override
428+
public void close() throws Exception {
429+
stub.close();
430+
}
386431
}

trunk/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/BigtableDataSettings.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.api.gax.rpc.UnaryCallSettings;
2121
import com.google.bigtable.admin.v2.InstanceName;
2222
import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation;
23+
import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow;
2324
import com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStubSettings;
2425
import com.google.cloud.bigtable.data.v2.models.KeyOffset;
2526
import com.google.cloud.bigtable.data.v2.models.Query;
@@ -95,6 +96,11 @@ public UnaryCallSettings<ConditionalRowMutation, Boolean> checkAndMutateRowSetti
9596
return getTypedStubSettings().checkAndMutateRowSettings();
9697
}
9798

99+
/** Returns the object with the settings used for calls to ReadModifyWriteRow. */
100+
public UnaryCallSettings<ReadModifyWriteRow, Row> readModifyWriteRowSettings() {
101+
return getTypedStubSettings().readModifyWriteRowSettings();
102+
}
103+
98104
@SuppressWarnings("unchecked")
99105
EnhancedBigtableStubSettings getTypedStubSettings() {
100106
return (EnhancedBigtableStubSettings) getStubSettings();
@@ -175,6 +181,11 @@ public UnaryCallSettings.Builder<ConditionalRowMutation, Boolean> checkAndMutate
175181
return getTypedStubSettings().checkAndMutateRowSettings();
176182
}
177183

184+
/** Returns the builder with the settings used for calls to ReadModifyWriteRow. */
185+
public UnaryCallSettings.Builder<ReadModifyWriteRow, Row> readModifyWriteRowSettings() {
186+
return getTypedStubSettings().readModifyWriteRowSettings();
187+
}
188+
178189
@SuppressWarnings("unchecked")
179190
private EnhancedBigtableStubSettings.Builder getTypedStubSettings() {
180191
return (EnhancedBigtableStubSettings.Builder) getStubSettings();
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright 2018 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.bigtable.data.v2.models;
17+
18+
import com.google.api.core.InternalApi;
19+
import com.google.bigtable.v2.ReadModifyWriteRowRequest;
20+
import com.google.bigtable.v2.ReadModifyWriteRule;
21+
import com.google.bigtable.v2.TableName;
22+
import com.google.cloud.bigtable.data.v2.internal.RequestContext;
23+
import com.google.common.base.Preconditions;
24+
import com.google.protobuf.ByteString;
25+
import javax.annotation.Nonnull;
26+
27+
/** Wraps a {@link ReadModifyWriteRowRequest}. */
28+
public final class ReadModifyWriteRow {
29+
private final String tableId;
30+
private final ReadModifyWriteRowRequest.Builder builder = ReadModifyWriteRowRequest.newBuilder();
31+
32+
private ReadModifyWriteRow(@Nonnull String tableId, @Nonnull ByteString key) {
33+
Preconditions.checkNotNull(tableId, "tableId can't be null.");
34+
Preconditions.checkNotNull(key, "key can't be null.");
35+
this.tableId = tableId;
36+
37+
builder.setRowKey(key);
38+
}
39+
40+
public static ReadModifyWriteRow create(@Nonnull String tableId, @Nonnull String key) {
41+
Preconditions.checkNotNull(key, "key can't be null.");
42+
return new ReadModifyWriteRow(tableId, ByteString.copyFromUtf8(key));
43+
}
44+
45+
public static ReadModifyWriteRow create(@Nonnull String tableId, @Nonnull ByteString key) {
46+
return new ReadModifyWriteRow(tableId, key);
47+
}
48+
49+
/**
50+
* Appends the value to the existing value of the cell. If the targeted cell is unset, it will be
51+
* treated as containing the empty string.
52+
*/
53+
public ReadModifyWriteRow append(
54+
@Nonnull String familyName, @Nonnull String qualifier, @Nonnull String value) {
55+
return append(familyName, ByteString.copyFromUtf8(qualifier), ByteString.copyFromUtf8(value));
56+
}
57+
58+
/**
59+
* Appends the value to the existing value of the cell. If the targeted cell is unset, it will be
60+
* treated as containing the empty string.
61+
*/
62+
public ReadModifyWriteRow append(
63+
@Nonnull String familyName, @Nonnull ByteString qualifier, @Nonnull ByteString value) {
64+
Validations.validateFamily(familyName);
65+
Preconditions.checkNotNull(qualifier, "Qualifier can't be null");
66+
Preconditions.checkNotNull(value, "Value can't be null");
67+
Preconditions.checkArgument(!value.isEmpty(), "Value can't be empty");
68+
69+
ReadModifyWriteRule rule =
70+
ReadModifyWriteRule.newBuilder()
71+
.setFamilyName(familyName)
72+
.setColumnQualifier(qualifier)
73+
.setAppendValue(value)
74+
.build();
75+
76+
builder.addRules(rule);
77+
78+
return this;
79+
}
80+
81+
/**
82+
* Adds `amount` be added to the existing value. If the targeted cell is unset, it will be treated
83+
* as containing a zero. Otherwise, the targeted cell must contain an 8-byte value (interpreted as
84+
* a 64-bit big-endian signed integer), or the entire request will fail.
85+
*/
86+
public ReadModifyWriteRow increment(
87+
@Nonnull String familyName, @Nonnull String qualifier, long amount) {
88+
return increment(familyName, ByteString.copyFromUtf8(qualifier), amount);
89+
}
90+
91+
/**
92+
* Adds `amount` be added to the existing value. If the targeted cell is unset, it will be treated
93+
* as containing a zero. Otherwise, the targeted cell must contain an 8-byte value (interpreted as
94+
* a 64-bit big-endian signed integer), or the entire request will fail.
95+
*/
96+
public ReadModifyWriteRow increment(
97+
@Nonnull String familyName, @Nonnull ByteString qualifier, long amount) {
98+
Validations.validateFamily(familyName);
99+
Preconditions.checkNotNull(qualifier, "Qualifier can't be null");
100+
101+
ReadModifyWriteRule rule =
102+
ReadModifyWriteRule.newBuilder()
103+
.setFamilyName(familyName)
104+
.setColumnQualifier(qualifier)
105+
.setIncrementAmount(amount)
106+
.build();
107+
108+
builder.addRules(rule);
109+
return this;
110+
}
111+
112+
@InternalApi
113+
public ReadModifyWriteRowRequest toProto(RequestContext requestContext) {
114+
TableName tableName =
115+
TableName.of(
116+
requestContext.getInstanceName().getProject(),
117+
requestContext.getInstanceName().getInstance(),
118+
tableId);
119+
return builder
120+
.setTableName(tableName.toString())
121+
.setAppProfileId(requestContext.getAppProfileId())
122+
.build();
123+
}
124+
}

trunk/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter;
3131
import com.google.cloud.bigtable.data.v2.models.KeyOffset;
3232
import com.google.cloud.bigtable.data.v2.models.Query;
33+
import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow;
3334
import com.google.cloud.bigtable.data.v2.models.Row;
3435
import com.google.cloud.bigtable.data.v2.models.RowAdapter;
3536
import com.google.cloud.bigtable.data.v2.models.RowMutation;
@@ -59,6 +60,7 @@ public class EnhancedBigtableStub implements AutoCloseable {
5960
private final UnaryCallable<String, List<KeyOffset>> sampleRowKeysCallable;
6061
private final UnaryCallable<RowMutation, Void> mutateRowCallable;
6162
private final UnaryCallable<ConditionalRowMutation, Boolean> checkAndMutateRowCallable;
63+
private final UnaryCallable<ReadModifyWriteRow, Row> readModifyWriteRowCallable;
6264

6365
public static EnhancedBigtableStub create(EnhancedBigtableStubSettings settings)
6466
throws IOException {
@@ -97,6 +99,7 @@ public static EnhancedBigtableStub create(EnhancedBigtableStubSettings settings)
9799
sampleRowKeysCallable = createSampleRowKeysCallable();
98100
mutateRowCallable = createMutateRowCallable();
99101
checkAndMutateRowCallable = createCheckAndMutateRowCallable();
102+
readModifyWriteRowCallable = createReadModifyWriteRowCallable();
100103
}
101104

102105
// <editor-fold desc="Callable creators">
@@ -152,6 +155,15 @@ public ApiFuture<Boolean> futureCall(ConditionalRowMutation request, ApiCallCont
152155
}
153156
};
154157
}
158+
159+
private UnaryCallable<ReadModifyWriteRow, Row> createReadModifyWriteRowCallable() {
160+
return new UnaryCallable<ReadModifyWriteRow, Row>() {
161+
@Override
162+
public ApiFuture<Row> futureCall(ReadModifyWriteRow request, ApiCallContext context) {
163+
throw new UnsupportedOperationException("todo");
164+
}
165+
};
166+
}
155167
// </editor-fold>
156168

157169
// <editor-fold desc="Callable accessors">
@@ -170,6 +182,10 @@ public UnaryCallable<RowMutation, Void> mutateRowCallable() {
170182
public UnaryCallable<ConditionalRowMutation, Boolean> checkAndMutateRowCallable() {
171183
return checkAndMutateRowCallable;
172184
}
185+
186+
public UnaryCallable<ReadModifyWriteRow, Row> readModifyWriteRowCallable() {
187+
return readModifyWriteRowCallable;
188+
}
173189
// </editor-fold>
174190

175191
@Override

trunk/google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubSettings.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation;
2727
import com.google.cloud.bigtable.data.v2.models.KeyOffset;
2828
import com.google.cloud.bigtable.data.v2.models.Query;
29+
import com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow;
2930
import com.google.cloud.bigtable.data.v2.models.Row;
3031
import com.google.cloud.bigtable.data.v2.models.RowMutation;
3132
import com.google.common.base.Preconditions;
@@ -93,6 +94,7 @@ public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableS
9394
private final UnaryCallSettings<String, List<KeyOffset>> sampleRowKeysSettings;
9495
private final UnaryCallSettings<RowMutation, Void> mutateRowSettings;
9596
private final UnaryCallSettings<ConditionalRowMutation, Boolean> checkAndMutateRowSettings;
97+
private final UnaryCallSettings<ReadModifyWriteRow, Row> readModifyWriteRowSettings;
9698

9799
private EnhancedBigtableStubSettings(Builder builder) {
98100
super(builder);
@@ -104,6 +106,7 @@ private EnhancedBigtableStubSettings(Builder builder) {
104106
sampleRowKeysSettings = builder.sampleRowKeysSettings.build();
105107
mutateRowSettings = builder.mutateRowSettings.build();
106108
checkAndMutateRowSettings = builder.checkAndMutateRowSettings.build();
109+
readModifyWriteRowSettings = builder.readModifyWriteRowSettings.build();
107110
}
108111

109112
/** Create a new builder. */
@@ -141,6 +144,11 @@ public UnaryCallSettings<ConditionalRowMutation, Boolean> checkAndMutateRowSetti
141144
return checkAndMutateRowSettings;
142145
}
143146

147+
/** Returns the object with the settings used for calls to ReadModifyWriteRow. */
148+
public UnaryCallSettings<ReadModifyWriteRow, Row> readModifyWriteRowSettings() {
149+
return readModifyWriteRowSettings;
150+
}
151+
144152
/** Returns a builder containing all the values of this settings class. */
145153
public Builder toBuilder() {
146154
return new Builder(this);
@@ -156,6 +164,7 @@ public static class Builder extends StubSettings.Builder<EnhancedBigtableStubSet
156164
private final UnaryCallSettings.Builder<RowMutation, Void> mutateRowSettings;
157165
private final UnaryCallSettings.Builder<ConditionalRowMutation, Boolean>
158166
checkAndMutateRowSettings;
167+
private final UnaryCallSettings.Builder<ReadModifyWriteRow, Row> readModifyWriteRowSettings;
159168

160169
/**
161170
* Initializes a new Builder with sane defaults for all settings.
@@ -206,6 +215,9 @@ private Builder() {
206215

207216
checkAndMutateRowSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
208217
copyRetrySettings(baseDefaults.checkAndMutateRowSettings(), checkAndMutateRowSettings);
218+
219+
readModifyWriteRowSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
220+
copyRetrySettings(baseDefaults.readModifyWriteRowSettings(), readModifyWriteRowSettings);
209221
}
210222

211223
private Builder(EnhancedBigtableStubSettings settings) {
@@ -218,6 +230,7 @@ private Builder(EnhancedBigtableStubSettings settings) {
218230
sampleRowKeysSettings = settings.sampleRowKeysSettings.toBuilder();
219231
mutateRowSettings = settings.mutateRowSettings.toBuilder();
220232
checkAndMutateRowSettings = settings.checkAndMutateRowSettings.toBuilder();
233+
readModifyWriteRowSettings = settings.readModifyWriteRowSettings.toBuilder();
221234
}
222235

223236
// <editor-fold desc="Private Helpers">
@@ -285,6 +298,11 @@ public UnaryCallSettings.Builder<ConditionalRowMutation, Boolean> checkAndMutate
285298
return checkAndMutateRowSettings;
286299
}
287300

301+
/** Returns the builder with the settings used for calls to ReadModifyWriteRow. */
302+
public UnaryCallSettings.Builder<ReadModifyWriteRow, Row> readModifyWriteRowSettings() {
303+
return readModifyWriteRowSettings;
304+
}
305+
288306
@SuppressWarnings("unchecked")
289307
public EnhancedBigtableStubSettings build() {
290308
Preconditions.checkState(instanceName != null, "InstanceName must be set");

0 commit comments

Comments
 (0)