Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow creating a managed channel #3824

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,12 @@ public class BigtableOptionsFactory {
/** Tracing cookie to send in the header with the requests */
@BetaApi("The API for setting tracing cookie is not yet stable and may change in the future")
public static final String BIGTABLE_TRACING_COOKIE = "google.bigtable.tracing.cookie.header";

/**
* If this option is set to true, log a warning when creating a managed connection instead of
* throwing invalid argument exception.
*/
@BetaApi("This API is not yet stable and may change in the future")
public static final String MANAGED_CONNECTION_WARNING =
"google.bigtable.managed.connection.warning";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.api.core.InternalApi;
import com.google.cloud.bigtable.hbase.BigtableBufferedMutator;
import com.google.cloud.bigtable.hbase.BigtableHBaseVersion;
import com.google.cloud.bigtable.hbase.BigtableOptionsFactory;
import com.google.cloud.bigtable.hbase.BigtableRegionLocator;
import com.google.cloud.bigtable.hbase.adapters.Adapters;
import com.google.cloud.bigtable.hbase.adapters.HBaseRequestAdapter;
Expand Down Expand Up @@ -107,7 +108,12 @@ public AbstractBigtableConnection(Configuration conf) throws IOException {
protected AbstractBigtableConnection(
Configuration conf, boolean managed, ExecutorService pool, User user) throws IOException {
if (managed) {
throw new IllegalArgumentException("Bigtable does not support managed connections.");
if (conf.getBoolean(BigtableOptionsFactory.MANAGED_CONNECTION_WARNING, false)) {
LOG.warn(
"Bigtable does not support managed connections. This connection will end up leaking.");
} else {
throw new IllegalArgumentException("Bigtable does not support managed connections.");
}
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;

import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.bigtable.v2.BigtableGrpc;
import com.google.bigtable.v2.MutateRowRequest;
import com.google.bigtable.v2.MutateRowResponse;
Expand Down Expand Up @@ -50,13 +52,15 @@
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.VersionInfo;
import org.junit.After;
Expand Down Expand Up @@ -222,12 +226,37 @@ public void testHeaders() throws IOException {
}
}

@Test
public void testManagedConnectionWarning() throws IOException {
Configuration configuration = new Configuration(false);
configuration.set(BigtableOptionsFactory.PROJECT_ID_KEY, PROJECT_ID);
configuration.set(BigtableOptionsFactory.INSTANCE_ID_KEY, INSTANCE_ID);
configuration.set(BigtableOptionsFactory.BIGTABLE_NULL_CREDENTIAL_ENABLE_KEY, "true");
configuration.set(BigtableOptionsFactory.BIGTABLE_DATA_CHANNEL_COUNT_KEY, "1");
configuration.set(
BigtableOptionsFactory.BIGTABLE_EMULATOR_HOST_KEY, HOST_NAME + ":" + server.getPort());
configuration.set(BigtableOptionsFactory.MANAGED_CONNECTION_WARNING, "true");
try {
Connection newConnection =
new TestBigtableConnectionImpl(
configuration, true, Executors.newSingleThreadExecutor(), null);
newConnection.close();
} catch (InvalidArgumentException e) {
fail("Should not throw invalid argument exception");
}
}

private class TestBigtableConnectionImpl extends AbstractBigtableConnection {

TestBigtableConnectionImpl(Configuration conf) throws IOException {
super(conf);
}

TestBigtableConnectionImpl(Configuration conf, boolean managed, ExecutorService pool, User user)
throws IOException {
super(conf, managed, pool, user);
}

@Override
protected SampledRowKeysAdapter createSampledRowKeysAdapter(
TableName tableName, ServerName serverName) {
Expand Down