|
44 | 44 | import java.lang.reflect.Constructor;
|
45 | 45 | import java.lang.reflect.InvocationTargetException;
|
46 | 46 | import java.net.URL;
|
| 47 | +import java.time.Duration; |
47 | 48 | import java.util.ArrayList;
|
48 | 49 | import java.util.Arrays;
|
49 | 50 | import java.util.Collections;
|
@@ -357,6 +358,9 @@ private static String generateGuardedConnectionPropertyError(
|
357 | 358 | ConnectionProperty.createStringProperty(
|
358 | 359 | OPTIMIZER_STATISTICS_PACKAGE_PROPERTY_NAME, ""),
|
359 | 360 | ConnectionProperty.createBooleanProperty("returnCommitStats", "", false),
|
| 361 | + ConnectionProperty.createStringProperty( |
| 362 | + "maxCommitDelay", |
| 363 | + "The maximum commit delay in milliseconds that should be applied to commit requests from this connection."), |
360 | 364 | ConnectionProperty.createBooleanProperty(
|
361 | 365 | "autoConfigEmulator",
|
362 | 366 | "Automatically configure the connection to try to connect to the Cloud Spanner emulator (true/false). "
|
@@ -689,6 +693,7 @@ public static Builder newBuilder() {
|
689 | 693 | private final String userAgent;
|
690 | 694 | private final QueryOptions queryOptions;
|
691 | 695 | private final boolean returnCommitStats;
|
| 696 | + private final Long maxCommitDelay; |
692 | 697 | private final boolean autoConfigEmulator;
|
693 | 698 | private final Dialect dialect;
|
694 | 699 | private final RpcPriority rpcPriority;
|
@@ -744,6 +749,7 @@ private ConnectionOptions(Builder builder) {
|
744 | 749 | queryOptionsBuilder.setOptimizerStatisticsPackage(parseOptimizerStatisticsPackage(this.uri));
|
745 | 750 | this.queryOptions = queryOptionsBuilder.build();
|
746 | 751 | this.returnCommitStats = parseReturnCommitStats(this.uri);
|
| 752 | + this.maxCommitDelay = parseMaxCommitDelay(this.uri); |
747 | 753 | this.autoConfigEmulator = parseAutoConfigEmulator(this.uri);
|
748 | 754 | this.dialect = parseDialect(this.uri);
|
749 | 755 | this.usePlainText = this.autoConfigEmulator || parseUsePlainText(this.uri);
|
@@ -1074,6 +1080,27 @@ static boolean parseReturnCommitStats(String uri) {
|
1074 | 1080 | return Boolean.parseBoolean(value);
|
1075 | 1081 | }
|
1076 | 1082 |
|
| 1083 | + @VisibleForTesting |
| 1084 | + static Long parseMaxCommitDelay(String uri) { |
| 1085 | + String value = parseUriProperty(uri, "maxCommitDelay"); |
| 1086 | + try { |
| 1087 | + Long millis = value == null ? null : Long.valueOf(value); |
| 1088 | + if (millis != null && millis < 0L) { |
| 1089 | + throw SpannerExceptionFactory.newSpannerException( |
| 1090 | + ErrorCode.INVALID_ARGUMENT, "maxCommitDelay must be >=0"); |
| 1091 | + } |
| 1092 | + return millis; |
| 1093 | + } catch (NumberFormatException numberFormatException) { |
| 1094 | + throw SpannerExceptionFactory.newSpannerException( |
| 1095 | + ErrorCode.INVALID_ARGUMENT, |
| 1096 | + "Invalid value for maxCommitDelay: " |
| 1097 | + + value |
| 1098 | + + "\n" |
| 1099 | + + "The value must be a positive integer indicating the number of " |
| 1100 | + + "milliseconds to use as the max delay."); |
| 1101 | + } |
| 1102 | + } |
| 1103 | + |
1077 | 1104 | static boolean parseAutoConfigEmulator(String uri) {
|
1078 | 1105 | String value = parseUriProperty(uri, "autoConfigEmulator");
|
1079 | 1106 | return Boolean.parseBoolean(value);
|
@@ -1405,6 +1432,11 @@ public boolean isReturnCommitStats() {
|
1405 | 1432 | return returnCommitStats;
|
1406 | 1433 | }
|
1407 | 1434 |
|
| 1435 | + /** The max_commit_delay that should be applied to commit operations on this connection. */ |
| 1436 | + public Duration getMaxCommitDelay() { |
| 1437 | + return maxCommitDelay == null ? null : Duration.ofMillis(maxCommitDelay); |
| 1438 | + } |
| 1439 | + |
1408 | 1440 | /**
|
1409 | 1441 | * Whether connections created by this {@link ConnectionOptions} will automatically try to connect
|
1410 | 1442 | * to the emulator using the default host/port of the emulator, and automatically create the
|
|
0 commit comments