Skip to content

Commit 0e4016f

Browse files
authored
fix: allow creating a managed channel (#3824)
* fix: allow creating a managed channel * small fixes
1 parent 7cfb177 commit 0e4016f

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

bigtable-client-core-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableOptionsFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,12 @@ public class BigtableOptionsFactory {
306306
/** Tracing cookie to send in the header with the requests */
307307
@BetaApi("The API for setting tracing cookie is not yet stable and may change in the future")
308308
public static final String BIGTABLE_TRACING_COOKIE = "google.bigtable.tracing.cookie.header";
309+
310+
/**
311+
* If this option is set to true, log a warning when creating a managed connection instead of
312+
* throwing illegal argument exception.
313+
*/
314+
@BetaApi("This API is not yet stable and may change in the future")
315+
public static final String MANAGED_CONNECTION_WARNING =
316+
"google.bigtable.managed.connection.warning";
309317
}

bigtable-client-core-parent/bigtable-hbase/src/main/java/org/apache/hadoop/hbase/client/AbstractBigtableConnection.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.api.core.InternalApi;
2020
import com.google.cloud.bigtable.hbase.BigtableBufferedMutator;
2121
import com.google.cloud.bigtable.hbase.BigtableHBaseVersion;
22+
import com.google.cloud.bigtable.hbase.BigtableOptionsFactory;
2223
import com.google.cloud.bigtable.hbase.BigtableRegionLocator;
2324
import com.google.cloud.bigtable.hbase.adapters.Adapters;
2425
import com.google.cloud.bigtable.hbase.adapters.HBaseRequestAdapter;
@@ -107,7 +108,12 @@ public AbstractBigtableConnection(Configuration conf) throws IOException {
107108
protected AbstractBigtableConnection(
108109
Configuration conf, boolean managed, ExecutorService pool, User user) throws IOException {
109110
if (managed) {
110-
throw new IllegalArgumentException("Bigtable does not support managed connections.");
111+
if (conf.getBoolean(BigtableOptionsFactory.MANAGED_CONNECTION_WARNING, false)) {
112+
LOG.warn(
113+
"Bigtable does not support managed connections. This connection will end up leaking.");
114+
} else {
115+
throw new IllegalArgumentException("Bigtable does not support managed connections.");
116+
}
111117
}
112118

113119
try {

bigtable-client-core-parent/bigtable-hbase/src/test/java/org/apache/hadoop/hbase/client/TestAbstractBigtableConnection.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.Assert.assertEquals;
2121
import static org.junit.Assert.assertFalse;
2222
import static org.junit.Assert.assertTrue;
23+
import static org.junit.Assert.fail;
2324
import static org.mockito.Mockito.when;
2425

2526
import com.google.bigtable.v2.BigtableGrpc;
@@ -50,13 +51,15 @@
5051
import java.util.List;
5152
import java.util.concurrent.BlockingQueue;
5253
import java.util.concurrent.ExecutorService;
54+
import java.util.concurrent.Executors;
5355
import java.util.concurrent.TimeUnit;
5456
import java.util.concurrent.atomic.AtomicReference;
5557
import org.apache.hadoop.conf.Configuration;
5658
import org.apache.hadoop.hbase.HRegionInfo;
5759
import org.apache.hadoop.hbase.HRegionLocation;
5860
import org.apache.hadoop.hbase.ServerName;
5961
import org.apache.hadoop.hbase.TableName;
62+
import org.apache.hadoop.hbase.security.User;
6063
import org.apache.hadoop.hbase.util.Bytes;
6164
import org.apache.hadoop.hbase.util.VersionInfo;
6265
import org.junit.After;
@@ -222,12 +225,35 @@ public void testHeaders() throws IOException {
222225
}
223226
}
224227

228+
@Test
229+
public void testManagedConnectionOverride() throws IOException {
230+
Configuration configuration = new Configuration(false);
231+
configuration.set(BigtableOptionsFactory.PROJECT_ID_KEY, PROJECT_ID);
232+
configuration.set(BigtableOptionsFactory.INSTANCE_ID_KEY, INSTANCE_ID);
233+
configuration.setBoolean(BigtableOptionsFactory.BIGTABLE_NULL_CREDENTIAL_ENABLE_KEY, true);
234+
configuration.setInt(BigtableOptionsFactory.BIGTABLE_DATA_CHANNEL_COUNT_KEY, 1);
235+
configuration.set(
236+
BigtableOptionsFactory.BIGTABLE_EMULATOR_HOST_KEY, HOST_NAME + ":" + server.getPort());
237+
configuration.setBoolean(BigtableOptionsFactory.MANAGED_CONNECTION_WARNING, true);
238+
try (Connection newConnection =
239+
new TestBigtableConnectionImpl(
240+
configuration, true, Executors.newSingleThreadExecutor(), null)) {
241+
} catch (IllegalArgumentException e) {
242+
fail("Should not throw IllegalArgumentException");
243+
}
244+
}
245+
225246
private class TestBigtableConnectionImpl extends AbstractBigtableConnection {
226247

227248
TestBigtableConnectionImpl(Configuration conf) throws IOException {
228249
super(conf);
229250
}
230251

252+
TestBigtableConnectionImpl(Configuration conf, boolean managed, ExecutorService pool, User user)
253+
throws IOException {
254+
super(conf, managed, pool, user);
255+
}
256+
231257
@Override
232258
protected SampledRowKeysAdapter createSampledRowKeysAdapter(
233259
TableName tableName, ServerName serverName) {

0 commit comments

Comments
 (0)