Skip to content

Commit

Permalink
Add Experimental DirectPath support
Browse files Browse the repository at this point in the history
  • Loading branch information
igorbernstein2 committed Oct 17, 2019
1 parent f9e5ff8 commit c0a77ef
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 166 deletions.
2 changes: 1 addition & 1 deletion google-cloud-bigtable/pom.xml
Expand Up @@ -174,7 +174,7 @@
</goals>
<configuration>
<systemPropertyVariables>
<bigtable.env>direct_path</bigtable.env>
<bigtable.env>prod</bigtable.env>
<!-- TODO(igorbernstein): This property should be auto set by gax -->
<io.grpc.internal.DnsNameResolverProvider.enable_grpclb>true</io.grpc.internal.DnsNameResolverProvider.enable_grpclb>
</systemPropertyVariables>
Expand Down
Expand Up @@ -42,6 +42,7 @@
import com.google.common.collect.ImmutableSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import org.threeten.bp.Duration;

Expand Down Expand Up @@ -74,10 +75,18 @@
* }</pre>
*/
public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableStubSettings> {
private static final Logger logger = Logger.getLogger(EnhancedBigtableStubSettings.class.getName());

// The largest message that can be received is a 256 MB ReadRowsResponse.
private static final int MAX_MESSAGE_SIZE = 256 * 1024 * 1024;
private static final String SERVER_DEFAULT_APP_PROFILE_ID = "";

// TODO(igorbernstein2): Remove this once DirectPath goes to public beta
// Temporary endpoint for the DirectPath private alpha
private static final String DIRECT_PATH_ENV_VAR = "GOOGLE_CLOUD_ENABLE_DIRECT_PATH";
private static final String DIRECT_PATH_ENDPOINT = "directpath-bigtable.googleapis.com:443";
private static final String DIRECT_PATH_SYS_PROP = "io.grpc.internal.DnsNameResolverProvider.enable_grpclb";

private static final Set<Code> IDEMPOTENT_RETRY_CODES =
ImmutableSet.of(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE);

Expand Down Expand Up @@ -133,6 +142,17 @@ public class EnhancedBigtableStubSettings extends StubSettings<EnhancedBigtableS
private EnhancedBigtableStubSettings(Builder builder) {
super(builder);

if (DIRECT_PATH_ENDPOINT.equals(builder.getEndpoint())) {
logger.warning("Using connecting to Bigtable using DirectPath."
+ " This is currently an experimental feature and should not be used in production.");

if (!"true".equals(System.getProperty(DIRECT_PATH_SYS_PROP))) {
logger.severe(
"Can't enable DirectPath without grpclb, the system property " + DIRECT_PATH_SYS_PROP
+ " must be set to true");
}
}

// Since point reads & streaming reads share the same base callable that converts grpc errors
// into ApiExceptions, they must have the same retry codes.
Preconditions.checkState(
Expand Down Expand Up @@ -404,7 +424,13 @@ private Builder() {
// Defaults provider
BigtableStubSettings.Builder baseDefaults = BigtableStubSettings.newBuilder();

setEndpoint(baseDefaults.getEndpoint());
// TODO(igorbernstein): remove this once DirectPath goes to public Beta and uses the default endpoint.
if (isDirectPathEnabled()) {
setEndpoint(DIRECT_PATH_ENDPOINT);
} else {
setEndpoint(baseDefaults.getEndpoint());
}

setTransportChannelProvider(defaultTransportChannelProvider());
setStreamWatchdogCheckInterval(baseDefaults.getStreamWatchdogCheckInterval());
setStreamWatchdogProvider(baseDefaults.getStreamWatchdogProvider());
Expand Down Expand Up @@ -503,6 +529,22 @@ private static void copyRetrySettings(
dest.setRetryableCodes(source.getRetryableCodes());
dest.setRetrySettings(source.getRetrySettings());
}

// TODO(igorbernstein): Remove this once DirectPath goes to public beta
// Extracted from InstantiatingGrpcChannelProvider#isDirectPathEnabled
private static boolean isDirectPathEnabled() {
String whiteList = System.getenv(DIRECT_PATH_ENV_VAR);
if (whiteList == null) {
return false;
}

for (String service : whiteList.split(",")) {
if (!service.isEmpty() && DIRECT_PATH_ENDPOINT.contains(service)) {
return true;
}
}
return false;
}
// </editor-fold>

// <editor-fold desc="Public API">
Expand Down
Expand Up @@ -39,7 +39,7 @@ public class LargeRowIT {
@Test
public void testWriteRead() throws Exception {
// TODO(igorbernstein2): remove this once direct path supports large messages
assume().that(testEnvRule.env()).isNotInstanceOf(DirectPathEnv.class);
assume().that(testEnvRule.env().isDirectPathEnabled()).isTrue();

String rowKey = UUID.randomUUID().toString();
String familyId = testEnvRule.env().getFamilyId();
Expand Down
Expand Up @@ -71,6 +71,10 @@ public boolean isInstanceAdminSupported() {
return true;
}

public boolean isDirectPathEnabled() {
return "bigtable".equals(System.getenv("GOOGLE_CLOUD_ENABLE_DIRECT_PATH"));
}

void cleanUpStale() {
cleanupStaleTables();
if (isInstanceAdminSupported()) {
Expand Down

This file was deleted.

Expand Up @@ -63,9 +63,6 @@ protected void before() throws Throwable {
case "prod":
testEnv = ProdEnv.fromSystemProperties();
break;
case "direct_path":
testEnv = DirectPathEnv.create();
break;
default:
throw new IllegalArgumentException(
String.format(
Expand Down

0 comments on commit c0a77ef

Please sign in to comment.