Skip to content

Commit 3ce4cbc

Browse files
authored
deps: upgrade hbase2 to 2.3.6 (#3429)
* deps: upgrade hbase2 to 2.3.6 * clean up test * fix comment * Update async registery class * fix test * use BigtableConfiguration in BigtableEnv * clean up code * add more comments to BigtableAsyncRegistry * use version properties in pom file * use 1.12.7 for bytebuddy
1 parent 6741053 commit 3ce4cbc

File tree

16 files changed

+236
-81
lines changed

16 files changed

+236
-81
lines changed

bigtable-client-core-parent/bigtable-hbase/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ limitations under the License.
168168
</exclusions>
169169
</dependency>
170170

171+
<dependency>
172+
<groupId>net.bytebuddy</groupId>
173+
<artifactId>byte-buddy</artifactId>
174+
<version>${byte.buddy.version}</version>
175+
</dependency>
176+
171177
<!-- Test -->
172178
<dependency>
173179
<groupId>com.google.cloud.bigtable</groupId>

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.auth.Credentials;
2121
import com.google.common.base.Preconditions;
2222
import org.apache.hadoop.conf.Configuration;
23+
import org.apache.hadoop.hbase.client.BigtableAsyncRegistry;
2324
import org.apache.hadoop.hbase.client.Connection;
2425

2526
/** This class provides a simplified mechanism of creating a programmatic Bigtable Connection. */
@@ -104,7 +105,7 @@ private static Configuration injectBigtableImpls(Configuration configuration) {
104105
configuration.set(
105106
HBASE_CLIENT_ASYNC_CONNECTION_IMPL, BIGTABLE_HBASE_CLIENT_ASYNC_CONNECTION_CLASS);
106107
configuration.set(
107-
HBASE_CLIENT_ASYNC_REGISTRY_IMPL, BIGTABLE_HBASE_CLIENT_ASYNC_REGISTRY_CLASS);
108+
HBASE_CLIENT_ASYNC_REGISTRY_IMPL, BigtableAsyncRegistry.getSubClass().getName());
108109
} catch (ClassNotFoundException ignored) {
109110
// Skip if any of the async connection class doesn't exist
110111
}
@@ -193,7 +194,7 @@ public static Configuration withCredentials(Configuration conf, Credentials cred
193194
@Deprecated
194195
public static Configuration asyncConfigure(Configuration conf) {
195196
conf.set(HBASE_CLIENT_ASYNC_CONNECTION_IMPL, BIGTABLE_HBASE_CLIENT_ASYNC_CONNECTION_CLASS);
196-
conf.set(HBASE_CLIENT_ASYNC_REGISTRY_IMPL, BIGTABLE_HBASE_CLIENT_ASYNC_REGISTRY_CLASS);
197+
conf.set(HBASE_CLIENT_ASYNC_REGISTRY_IMPL, BigtableAsyncRegistry.getSubClass().getName());
197198
return conf;
198199
}
199200

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.hadoop.hbase.client;
17+
18+
import com.google.api.core.InternalApi;
19+
import com.google.common.collect.ImmutableList;
20+
import java.util.List;
21+
import java.util.concurrent.CompletableFuture;
22+
import net.bytebuddy.ByteBuddy;
23+
import net.bytebuddy.dynamic.DynamicType;
24+
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
25+
import net.bytebuddy.dynamic.loading.InjectionClassLoader;
26+
import net.bytebuddy.implementation.FixedValue;
27+
import net.bytebuddy.implementation.InvocationHandlerAdapter;
28+
import net.bytebuddy.implementation.MethodCall;
29+
import net.bytebuddy.matcher.ElementMatchers;
30+
import org.apache.hadoop.conf.Configuration;
31+
32+
/**
33+
* Bigtable implementation of org.apache.hadoop.hbase.client.ConnectionRegistry or
34+
* org.apache.hadoop.hbase.client.AsyncRegistry depending on the HBase 2 version. The default HBase
35+
* 2 implementation provided by ZKAsyncRegistry / ZKConnectionRegistry assumes a ZooKeeper
36+
* environment, which is not the case for Bigtable.
37+
*
38+
* <p>This class is injected via the system property: "hbase.client.registry.impl". For further
39+
* details See HConstants#CLIENT_CONNECTION_REGISTRY_IMPL_CONF_KEY,
40+
* AsyncRegistry#createAsyncConnection() for hbase < 2.3 and
41+
* ConnectionFactory#createAsyncConnection() for hbase >= 2.3.
42+
*
43+
* <p>For internal use only - public for technical reasons.
44+
*/
45+
@InternalApi("For internal usage only")
46+
public class BigtableAsyncRegistry {
47+
48+
private static Class<? extends BigtableAsyncRegistry> subClass = null;
49+
50+
/** Constructor for org.apache.hadoop.hbase.client.ZKConnectionRegistry for hbase >= 2.3. */
51+
public BigtableAsyncRegistry() {}
52+
53+
/**
54+
* Constructor for org.apache.hadoop.hbase.client.ZKAsyncRegistry for hbase < 2.3. Configuration
55+
* is not used in BigtableAsyncRegistry.
56+
*/
57+
public BigtableAsyncRegistry(Configuration conf) {}
58+
59+
/**
60+
* Implements the async connection registry class depending on which class is present in the class
61+
* path. #close and #getClusterId are implemented. #getClusterId is used in
62+
* ConnectionFactory#getAsyncConnection, so a non null return value is required for successful
63+
* creation of asyncConnection. Throws {@link UnsupportedOperationException} on all other methods.
64+
*/
65+
private static Class<? extends BigtableAsyncRegistry> createSubClass()
66+
throws NoSuchMethodException {
67+
List<String> classNames =
68+
ImmutableList.of(
69+
"org.apache.hadoop.hbase.client.ConnectionRegistry",
70+
"org.apache.hadoop.hbase.client.AsyncRegistry");
71+
72+
DynamicType.Builder<BigtableAsyncRegistry> subclassBuilder =
73+
new ByteBuddy().subclass(BigtableAsyncRegistry.class);
74+
75+
for (String className : classNames) {
76+
try {
77+
subclassBuilder = subclassBuilder.implement(Class.forName(className));
78+
} catch (ClassNotFoundException e) {
79+
continue;
80+
}
81+
}
82+
83+
return subclassBuilder
84+
.method(ElementMatchers.isAbstract())
85+
.intercept(
86+
InvocationHandlerAdapter.of(new AbstractBigtableAdmin.UnsupportedOperationsHandler()))
87+
.method(ElementMatchers.named("close"))
88+
.intercept(MethodCall.invoke(BigtableAsyncRegistry.class.getDeclaredMethod("closeNoop")))
89+
.method(ElementMatchers.named("getClusterId"))
90+
.intercept(FixedValue.value((CompletableFuture.completedFuture("NoopClusterId"))))
91+
.make()
92+
.load(InjectionClassLoader.getSystemClassLoader(), ClassLoadingStrategy.Default.INJECTION)
93+
.getLoaded();
94+
}
95+
96+
public static synchronized Class<? extends BigtableAsyncRegistry> getSubClass() {
97+
if (subClass == null) {
98+
try {
99+
subClass = createSubClass();
100+
} catch (NoSuchMethodException e) {
101+
throw new RuntimeException(e);
102+
}
103+
if (subClass == null) {
104+
throw new RuntimeException(
105+
"Couldn't find org.apache.hadoop.hbase.client.ConnectionRegistry or org.apache.hadoop.hbase.client.AsyncRegistry in the classpath");
106+
}
107+
}
108+
return subClass;
109+
}
110+
111+
public void closeNoop() {}
112+
}

bigtable-hbase-1.x-parent/bigtable-hbase-1.x-hadoop/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ limitations under the License.
213213
<classEntry>org/apache/hadoop/hbase/client/AbstractBigtableAdmin</classEntry>
214214
<classEntry>org/apache/hadoop/hbase/client/AbstractBigtableConnection</classEntry>
215215
<classEntry>org/apache/hadoop/hbase/client/CommonConnection</classEntry>
216+
<classEntry>org/apache/hadoop/hbase/client/BigtableAsyncRegistry</classEntry>
216217
</allowedJarClassEntries>
217218
</configuration>
218219
</execution>

bigtable-hbase-1.x-parent/bigtable-hbase-1.x-shaded/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ limitations under the License.
361361
<classEntry>org/apache/hadoop/hbase/client/AbstractBigtableAdmin</classEntry>
362362
<classEntry>org/apache/hadoop/hbase/client/AbstractBigtableConnection</classEntry>
363363
<classEntry>org/apache/hadoop/hbase/client/CommonConnection</classEntry>
364+
<classEntry>org/apache/hadoop/hbase/client/BigtableAsyncRegistry</classEntry>
364365
</allowedJarClassEntries>
365366
</configuration>
366367
</execution>

bigtable-hbase-1.x-parent/bigtable-hbase-1.x/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ limitations under the License.
149149
<dependency>
150150
<groupId>net.bytebuddy</groupId>
151151
<artifactId>byte-buddy</artifactId>
152-
<version>1.12.7</version>
152+
<version>${byte.buddy.version}</version>
153153
</dependency>
154154

155155

bigtable-hbase-2.x-parent/bigtable-hbase-2.x-hadoop/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ limitations under the License.
3232

3333
<properties>
3434
<!-- define a property that can be ignored by renovate -->
35-
<hbase2-hadoop-slf4j.version>1.7.25</hbase2-hadoop-slf4j.version>
35+
<hbase2-hadoop-slf4j.version>1.7.30</hbase2-hadoop-slf4j.version>
3636
</properties>
3737

3838
<dependencies>

bigtable-hbase-2.x-parent/bigtable-hbase-2.x-integration-tests/pom.xml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ limitations under the License.
3535
<hbase.version>${hbase2.version}</hbase.version>
3636
<google.bigtable.connection.impl>com.google.cloud.bigtable.hbase2_x.BigtableConnection</google.bigtable.connection.impl>
3737
<google.bigtable.async.connection.impl>org.apache.hadoop.hbase.client.BigtableAsyncConnection</google.bigtable.async.connection.impl>
38-
<google.bigtable.registry.impl>org.apache.hadoop.hbase.client.BigtableAsyncRegistry</google.bigtable.registry.impl>
3938
<test.timeout>1800</test.timeout>
4039
</properties>
4140

@@ -160,9 +159,9 @@ limitations under the License.
160159
</includes>
161160
<excludedGroups>KnownEmulatorGap,KnownGap</excludedGroups>
162161
<systemPropertyVariables>
163-
<google.bigtable.test_env>bigtable</google.bigtable.test_env>
164162
<google.bigtable.project.id>fake-project</google.bigtable.project.id>
165163
<google.bigtable.instance.id>fake-instance</google.bigtable.instance.id>
164+
<google.bigtable.test_env>bigtable</google.bigtable.test_env>
166165
</systemPropertyVariables>
167166
<environmentVariables>
168167
<BIGTABLE_EMULATOR_HOST>${bigtable.emulator.endpoint}</BIGTABLE_EMULATOR_HOST>
@@ -216,6 +215,10 @@ limitations under the License.
216215
<groupId>org.apache.hbase</groupId>
217216
<artifactId>hbase-shaded-client</artifactId>
218217
</exclusion>
218+
<exclusion>
219+
<groupId>org.slf4j</groupId>
220+
<artifactId>slf4j-api</artifactId>
221+
</exclusion>
219222
</exclusions>
220223
</dependency>
221224

@@ -262,6 +265,12 @@ limitations under the License.
262265
<artifactId>hbase-shaded-testing-util</artifactId>
263266
<version>${hbase2.version}</version>
264267
<scope>test</scope>
268+
<exclusions>
269+
<exclusion>
270+
<groupId>org.slf4j</groupId>
271+
<artifactId>slf4j-api</artifactId>
272+
</exclusion>
273+
</exclusions>
265274
</dependency>
266275

267276
<!-- Misc -->
@@ -285,6 +294,13 @@ limitations under the License.
285294
<scope>test</scope>
286295
</dependency>
287296

297+
<dependency>
298+
<groupId>org.slf4j</groupId>
299+
<artifactId>slf4j-api</artifactId>
300+
<version>${slf4j.version}</version>
301+
<scope>test</scope>
302+
</dependency>
303+
288304
<dependency>
289305
<groupId>org.slf4j</groupId>
290306
<artifactId>slf4j-log4j12</artifactId>

bigtable-hbase-2.x-parent/bigtable-hbase-2.x-shaded/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ limitations under the License.
4848
<type>pom</type>
4949
<scope>import</scope>
5050
</dependency>
51+
<dependency>
52+
<groupId>org.slf4j</groupId>
53+
<artifactId>slf4j-api</artifactId>
54+
<version>${beam-slf4j.version}</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.slf4j</groupId>
58+
<artifactId>slf4j-log4j12</artifactId>
59+
<version>${beam-slf4j.version}</version>
60+
</dependency>
5161
</dependencies>
5262
</dependencyManagement>
5363

@@ -164,6 +174,7 @@ limitations under the License.
164174
<!-- exclude hbase-shaded-client & all of its dependencies -->
165175
<exclude>org.apache.hbase:hbase-shaded-client</exclude>
166176
<exclude>org.slf4j:slf4j-api</exclude>
177+
<exclude>org.slf4j:slf4j-log4j12</exclude>
167178
<exclude>log4j:log4j</exclude>
168179
<exclude>org.apache.htrace:htrace-core4</exclude>
169180
<exclude>org.apache.yetus:audience-annotations</exclude>

bigtable-hbase-2.x-parent/bigtable-hbase-2.x/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ limitations under the License.
8484
<groupId>org.slf4j</groupId>
8585
<artifactId>slf4j-log4j12</artifactId>
8686
</exclusion>
87+
<exclusion>
88+
<groupId>org.slf4j</groupId>
89+
<artifactId>slf4j-api</artifactId>
90+
</exclusion>
8791
</exclusions>
8892
</dependency>
8993
<dependency>
@@ -145,7 +149,7 @@ limitations under the License.
145149
<dependency>
146150
<groupId>net.bytebuddy</groupId>
147151
<artifactId>byte-buddy</artifactId>
148-
<version>1.12.7</version>
152+
<version>${byte.buddy.version}</version>
149153
</dependency>
150154

151155
<!-- Test dependencies-->

0 commit comments

Comments
 (0)