HBase client and gRPC Java compatibility

Imagine, that you need to use the HBase client and gRPC in the same Java application. The code for connecting dependencies to Maven will look something like this:

<!-- HBase -->
<dependency>
  <groupId>org.apache.hbase</groupId>
  <artifactId>hbase-client</artifactId>
  <version>1.2.3</version>
</dependency>
<dependency>
  <groupId>org.apache.hbase</groupId>
  <artifactId>hbase-common</artifactId>
  <version>1.2.3</version>
</dependency>

<!-- gRPC -->
<dependency>
  
  <groupId>io.grpc</groupId>
  
  <artifactId>grpc-netty</artifactId>
  
  <version>1.16.1</version>

</dependency>

<dependency>
 
  <groupId>io.grpc</groupId>
  
  <artifactId>grpc-protobuf</artifactId>
  
  <version>1.16.1</version>

</dependency>
<dependency>
 
  <groupId>io.grpc</groupId>
 
  <artifactId>grpc-stub</artifactId>
  
  <version>1.16.1</version>

</dependency>

If you run the application and execute the request through the HBase client, there will be an exception:

java.lang.IllegalAccessError: tried to access method com.google.common.base.Stopwatch.<init>()V from class org.apache.hadoop.hbase.zookeeper.MetaTableLocator
        at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:601) ...

The problem is that HBase uses an earlier version of Google Protobuf – 2.5.0, than gRPC. The solution to the problem is quite easy: starting with the HBase client version 2.0.0, the shaded Protobuf classes appeared there, so there is no conflict. You just need to update the HBase client version to 2.0.0:

<dependency>
  <groupId>org.apache.hbase</groupId>
  <artifactId>hbase-client</artifactId>
  <version>2.0.0</version>
</dependency>
<dependency>
  <groupId>org.apache.hbase</groupId>
  <artifactId>hbase-common</artifactId>
  <version>2.0.0</version>
</dependency>

If you still have any questions, feel free to ask me in the comments under this article, or write me on promark33@gmail.com.

If I saved your day, you can support me :)

Leave a Reply

Your email address will not be published.