Skip to content

Commit 7cd9cd8

Browse files
feat: Add E2E fallback to the spanner client. (#4282)
* Add GCPFallback support * formatting * fix imports * Add fallback test to GapicSpannerRpcTest * respond to comments * fixes * add minFailedCalls parameter to createFallbackChannelOptions * limit collected eef metrics * fix test * remove unintentional changes * formatting fix * formatting fixes * formatting fixes * merge fixes * address comments --------- Co-authored-by: rahul2393 <irahul@google.com>
1 parent 2e638f1 commit 7cd9cd8

3 files changed

Lines changed: 410 additions & 50 deletions

File tree

java-spanner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ public static GcpChannelPoolOptions createDefaultDynamicChannelPoolOptions() {
253253
private final String compressorName;
254254
private final boolean leaderAwareRoutingEnabled;
255255
private final boolean enableDirectAccess;
256+
private final boolean enableGcpFallback;
256257
private final DirectedReadOptions directedReadOptions;
257258
private final boolean useVirtualThreads;
258259
private final OpenTelemetry openTelemetry;
@@ -918,6 +919,7 @@ protected SpannerOptions(Builder builder) {
918919
compressorName = builder.compressorName;
919920
leaderAwareRoutingEnabled = builder.leaderAwareRoutingEnabled;
920921
enableDirectAccess = builder.enableDirectAccess;
922+
enableGcpFallback = builder.enableGcpFallback;
921923
directedReadOptions = builder.directedReadOptions;
922924
useVirtualThreads = builder.useVirtualThreads;
923925
openTelemetry = builder.openTelemetry;
@@ -980,6 +982,10 @@ default boolean isEnableDirectAccess() {
980982
return false;
981983
}
982984

985+
default boolean isEnableGcpFallback() {
986+
return false;
987+
}
988+
983989
default boolean isEnableBuiltInMetrics() {
984990
return true;
985991
}
@@ -1029,6 +1035,8 @@ private static class SpannerEnvironmentImpl implements SpannerEnvironment {
10291035
private static final String SPANNER_ENABLE_API_TRACING = "SPANNER_ENABLE_API_TRACING";
10301036
private static final String GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS =
10311037
"GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS";
1038+
private static final String GOOGLE_SPANNER_ENABLE_GCP_FALLBACK =
1039+
"GOOGLE_SPANNER_ENABLE_GCP_FALLBACK";
10321040
private static final String SPANNER_ENABLE_END_TO_END_TRACING =
10331041
"SPANNER_ENABLE_END_TO_END_TRACING";
10341042
private static final String SPANNER_DISABLE_BUILTIN_METRICS = "SPANNER_DISABLE_BUILTIN_METRICS";
@@ -1068,6 +1076,11 @@ public boolean isEnableDirectAccess() {
10681076
return Boolean.parseBoolean(System.getenv(GOOGLE_SPANNER_ENABLE_DIRECT_ACCESS));
10691077
}
10701078

1079+
@Override
1080+
public boolean isEnableGcpFallback() {
1081+
return Boolean.parseBoolean(System.getenv(GOOGLE_SPANNER_ENABLE_GCP_FALLBACK));
1082+
}
1083+
10711084
@Override
10721085
public boolean isEnableBuiltInMetrics() {
10731086
return !Boolean.parseBoolean(System.getenv(SPANNER_DISABLE_BUILTIN_METRICS));
@@ -1169,6 +1182,7 @@ public static class Builder
11691182
private String emulatorHost = System.getenv("SPANNER_EMULATOR_HOST");
11701183
private boolean leaderAwareRoutingEnabled = true;
11711184
private boolean enableDirectAccess = SpannerOptions.environment.isEnableDirectAccess();
1185+
private boolean enableGcpFallback = SpannerOptions.environment.isEnableGcpFallback();
11721186
private DirectedReadOptions directedReadOptions;
11731187
private boolean useVirtualThreads = false;
11741188
private OpenTelemetry openTelemetry;
@@ -1278,6 +1292,7 @@ protected Builder() {
12781292
this.channelConfigurator = options.channelConfigurator;
12791293
this.interceptorProvider = options.interceptorProvider;
12801294
this.enableDirectAccess = options.enableDirectAccess;
1295+
this.enableGcpFallback = options.enableGcpFallback;
12811296
this.directedReadOptions = options.directedReadOptions;
12821297
this.useVirtualThreads = options.useVirtualThreads;
12831298
this.enableApiTracing = options.enableApiTracing;
@@ -2338,6 +2353,10 @@ public Boolean isEnableDirectAccess() {
23382353
return enableDirectAccess;
23392354
}
23402355

2356+
public Boolean isEnableGcpFallback() {
2357+
return enableGcpFallback;
2358+
}
2359+
23412360
@ObsoleteApi("Use isEnableDirectAccess() instead")
23422361
@Deprecated
23432362
public boolean isAttemptDirectPath() {

0 commit comments

Comments
 (0)