|
42 | 42 | import com.google.common.collect.ImmutableSet;
|
43 | 43 | import java.util.List;
|
44 | 44 | import java.util.Set;
|
| 45 | +import java.util.logging.Logger; |
45 | 46 | import javax.annotation.Nonnull;
|
46 | 47 | import org.threeten.bp.Duration;
|
47 | 48 |
|
|
74 | 75 | * }</pre>
|
75 | 76 | */
|
76 | 77 | public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableStubSettings> {
|
| 78 | + private static final Logger logger = |
| 79 | + Logger.getLogger(EnhancedBigtableStubSettings.class.getName()); |
| 80 | + |
77 | 81 | // The largest message that can be received is a 256 MB ReadRowsResponse.
|
78 | 82 | private static final int MAX_MESSAGE_SIZE = 256 * 1024 * 1024;
|
79 | 83 | private static final String SERVER_DEFAULT_APP_PROFILE_ID = "";
|
80 | 84 |
|
| 85 | + // TODO(igorbernstein2): Remove this once DirectPath goes to public beta |
| 86 | + // Temporary endpoint for the DirectPath private alpha |
| 87 | + private static final String DIRECT_PATH_ENV_VAR = "GOOGLE_CLOUD_ENABLE_DIRECT_PATH"; |
| 88 | + private static final String DIRECT_PATH_ENDPOINT = "directpath-bigtable.googleapis.com:443"; |
| 89 | + |
81 | 90 | private static final Set<Code> IDEMPOTENT_RETRY_CODES =
|
82 | 91 | ImmutableSet.of(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE);
|
83 | 92 |
|
@@ -133,6 +142,12 @@ public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableS
|
133 | 142 | private EnhancedBigtableStubSettings(Builder builder) {
|
134 | 143 | super(builder);
|
135 | 144 |
|
| 145 | + if (DIRECT_PATH_ENDPOINT.equals(builder.getEndpoint())) { |
| 146 | + logger.warning( |
| 147 | + "Connecting to Bigtable using DirectPath." |
| 148 | + + " This is currently an experimental feature and should not be used in production."); |
| 149 | + } |
| 150 | + |
136 | 151 | // Since point reads & streaming reads share the same base callable that converts grpc errors
|
137 | 152 | // into ApiExceptions, they must have the same retry codes.
|
138 | 153 | Preconditions.checkState(
|
@@ -404,7 +419,14 @@ private Builder() {
|
404 | 419 | // Defaults provider
|
405 | 420 | BigtableStubSettings.Builder baseDefaults = BigtableStubSettings.newBuilder();
|
406 | 421 |
|
407 |
| - setEndpoint(baseDefaults.getEndpoint()); |
| 422 | + // TODO(igorbernstein): remove this once DirectPath goes to public Beta and uses the default |
| 423 | + // endpoint. |
| 424 | + if (isDirectPathEnabled()) { |
| 425 | + setEndpoint(DIRECT_PATH_ENDPOINT); |
| 426 | + } else { |
| 427 | + setEndpoint(baseDefaults.getEndpoint()); |
| 428 | + } |
| 429 | + |
408 | 430 | setTransportChannelProvider(defaultTransportChannelProvider());
|
409 | 431 | setStreamWatchdogCheckInterval(baseDefaults.getStreamWatchdogCheckInterval());
|
410 | 432 | setStreamWatchdogProvider(baseDefaults.getStreamWatchdogProvider());
|
@@ -503,6 +525,22 @@ private static void copyRetrySettings(
|
503 | 525 | dest.setRetryableCodes(source.getRetryableCodes());
|
504 | 526 | dest.setRetrySettings(source.getRetrySettings());
|
505 | 527 | }
|
| 528 | + |
| 529 | + // TODO(igorbernstein): Remove this once DirectPath goes to public beta |
| 530 | + // Extracted from InstantiatingGrpcChannelProvider#isDirectPathEnabled |
| 531 | + private static boolean isDirectPathEnabled() { |
| 532 | + String whiteList = System.getenv(DIRECT_PATH_ENV_VAR); |
| 533 | + if (whiteList == null) { |
| 534 | + return false; |
| 535 | + } |
| 536 | + |
| 537 | + for (String service : whiteList.split(",")) { |
| 538 | + if (!service.isEmpty() && DIRECT_PATH_ENDPOINT.contains(service)) { |
| 539 | + return true; |
| 540 | + } |
| 541 | + } |
| 542 | + return false; |
| 543 | + } |
506 | 544 | // </editor-fold>
|
507 | 545 |
|
508 | 546 | // <editor-fold desc="Public API">
|
|
0 commit comments