2626import com .google .cloud .bigtable .data .v2 .wrappers .KeyOffset ;
2727import com .google .cloud .bigtable .data .v2 .wrappers .Query ;
2828import com .google .cloud .bigtable .data .v2 .wrappers .Row ;
29+ import com .google .cloud .bigtable .data .v2 .wrappers .RowMutation ;
2930import com .google .common .base .Preconditions ;
31+ import com .google .common .collect .ImmutableSet ;
3032import java .util .List ;
33+ import java .util .Set ;
3134import javax .annotation .Nonnull ;
3235import org .threeten .bp .Duration ;
3336
@@ -67,11 +70,27 @@ public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableS
6770 private static final int MAX_MESSAGE_SIZE = 256 * 1024 * 1024 ;
6871 private static final String SERVER_DEFAULT_APP_PROFILE_ID = "" ;
6972
73+ private static final Set <Code > DEFAULT_RETRY_CODES =
74+ ImmutableSet .of (Code .DEADLINE_EXCEEDED , Code .UNAVAILABLE , Code .ABORTED );
75+
76+ private static final RetrySettings DEFAULT_RETRY_SETTINGS =
77+ RetrySettings .newBuilder ()
78+ .setMaxAttempts (10 )
79+ .setTotalTimeout (Duration .ofHours (1 ))
80+ .setInitialRetryDelay (Duration .ofMillis (100 ))
81+ .setRetryDelayMultiplier (1.3 )
82+ .setMaxRetryDelay (Duration .ofMinutes (1 ))
83+ .setInitialRpcTimeout (Duration .ofSeconds (20 ))
84+ .setRpcTimeoutMultiplier (1 )
85+ .setMaxRpcTimeout (Duration .ofSeconds (20 ))
86+ .build ();
87+
7088 private final InstanceName instanceName ;
7189 private final String appProfileId ;
7290
7391 private final ServerStreamingCallSettings <Query , Row > readRowsSettings ;
7492 private final UnaryCallSettings <String , List <KeyOffset >> sampleRowKeysSettings ;
93+ private final UnaryCallSettings <RowMutation , Void > mutateRowSettings ;
7594
7695 private EnhancedBigtableStubSettings (Builder builder ) {
7796 super (builder );
@@ -81,6 +100,7 @@ private EnhancedBigtableStubSettings(Builder builder) {
81100 // Per method settings.
82101 readRowsSettings = builder .readRowsSettings .build ();
83102 sampleRowKeysSettings = builder .sampleRowKeysSettings .build ();
103+ mutateRowSettings = builder .mutateRowSettings .build ();
84104 }
85105
86106 /** Create a new builder. */
@@ -108,6 +128,11 @@ public UnaryCallSettings<String, List<KeyOffset>> sampleRowKeysSettings() {
108128 return sampleRowKeysSettings ;
109129 }
110130
131+ /** Returns the object with the settings used for calls to MutateRow. */
132+ public UnaryCallSettings <RowMutation , Void > mutateRowSettings () {
133+ return mutateRowSettings ;
134+ }
135+
111136 /** Returns a builder containing all the values of this settings class. */
112137 public Builder toBuilder () {
113138 return new Builder (this );
@@ -120,6 +145,7 @@ public static class Builder extends StubSettings.Builder<EnhancedBigtableStubSet
120145
121146 private final ServerStreamingCallSettings .Builder <Query , Row > readRowsSettings ;
122147 private final UnaryCallSettings .Builder <String , List <KeyOffset >> sampleRowKeysSettings ;
148+ private final UnaryCallSettings .Builder <RowMutation , Void > mutateRowSettings ;
123149
124150 /**
125151 * Initializes a new Builder with sane defaults for all settings.
@@ -148,36 +174,25 @@ private Builder() {
148174 readRowsSettings = ServerStreamingCallSettings .newBuilder ();
149175 /* TODO: copy timeouts, retryCodes & retrySettings from baseSettings.readRows once it exists in GAPIC */
150176 readRowsSettings
151- .setRetryableCodes (Code .DEADLINE_EXCEEDED , Code .UNAVAILABLE , Code .ABORTED )
177+ .setRetryableCodes (DEFAULT_RETRY_CODES )
178+ .setRetrySettings (DEFAULT_RETRY_SETTINGS )
152179 .setTimeoutCheckInterval (Duration .ofSeconds (10 ))
153- .setIdleTimeout (Duration .ofMinutes (5 ))
154- .setRetrySettings (
155- RetrySettings .newBuilder ()
156- .setMaxAttempts (10 )
157- .setTotalTimeout (Duration .ofHours (1 ))
158- .setInitialRetryDelay (Duration .ofMillis (100 ))
159- .setRetryDelayMultiplier (1.3 )
160- .setMaxRetryDelay (Duration .ofMinutes (1 ))
161- .setInitialRpcTimeout (Duration .ofSeconds (20 ))
162- .setRpcTimeoutMultiplier (1 )
163- .setMaxRpcTimeout (Duration .ofSeconds (20 ))
164- .build ());
180+ .setIdleTimeout (Duration .ofMinutes (5 ));
165181
166182 sampleRowKeysSettings = UnaryCallSettings .newUnaryCallSettingsBuilder ();
167183 /* TODO: copy retryCodes & retrySettings from baseSettings.sampleRowKeysSettings once it exists in GAPIC */
168184 sampleRowKeysSettings
169185 .setRetryableCodes (Code .DEADLINE_EXCEEDED , Code .UNAVAILABLE , Code .ABORTED )
170- .setRetrySettings (
171- RetrySettings .newBuilder ()
172- .setMaxAttempts (10 )
173- .setTotalTimeout (Duration .ofMinutes (1 ))
174- .setInitialRetryDelay (Duration .ofMillis (100 ))
175- .setRetryDelayMultiplier (1.3 )
176- .setMaxRetryDelay (Duration .ofMinutes (1 ))
177- .setInitialRpcTimeout (Duration .ofSeconds (20 ))
178- .setRpcTimeoutMultiplier (1 )
179- .setMaxRpcTimeout (Duration .ofSeconds (20 ))
180- .build ());
186+ .setRetrySettings (DEFAULT_RETRY_SETTINGS );
187+
188+ // NOTE: This client enforces client side timestamps, which makes all mutations retryable.
189+ // However, since the base GAPIC client allows for server side timestamps, it is not
190+ // configured to enable retries. So the retry settings have to be defined here instead of
191+ // being copied from the BigtableStubSettings.
192+ mutateRowSettings = UnaryCallSettings .newUnaryCallSettingsBuilder ();
193+ mutateRowSettings
194+ .setRetryableCodes (DEFAULT_RETRY_CODES )
195+ .setRetrySettings (DEFAULT_RETRY_SETTINGS );
181196 }
182197
183198 private Builder (EnhancedBigtableStubSettings settings ) {
@@ -188,6 +203,7 @@ private Builder(EnhancedBigtableStubSettings settings) {
188203 // Per method settings.
189204 readRowsSettings = settings .readRowsSettings .toBuilder ();
190205 sampleRowKeysSettings = settings .sampleRowKeysSettings .toBuilder ();
206+ mutateRowSettings = settings .mutateRowSettings .toBuilder ();
191207 }
192208
193209 // <editor-fold desc="Private Helpers">
@@ -245,6 +261,11 @@ public UnaryCallSettings.Builder<String, List<KeyOffset>> sampleRowKeysSettings(
245261 return sampleRowKeysSettings ;
246262 }
247263
264+ /** Returns the builder for the settings used for calls to MutateRow. */
265+ public UnaryCallSettings .Builder <RowMutation , Void > mutateRowSettings () {
266+ return mutateRowSettings ;
267+ }
268+
248269 @ SuppressWarnings ("unchecked" )
249270 public EnhancedBigtableStubSettings build () {
250271 Preconditions .checkState (instanceName != null , "InstanceName must be set" );
0 commit comments