5

I have a small sample code in which I try to establish a connection to a remote HBase entity. The code runs on a windows machine without HBase installed and I try to connect to a remote Ubuntu Server that has it installed and running. The IP in the below snippet is of course just a placeholder.

The code is as follows:

public static void main(String[] args) {

    Configuration conf = HBaseConfiguration.create();
    HBaseAdmin admin = null;

    String ip = "10.10.10.10";
    String port = "2181";

    conf.set("hbase.zookeeper.quorum", ip);
    conf.set("hbase.zookeeper.property.clientPort", port);

    try {
        admin = new HBaseAdmin(conf);
        boolean bool = admin.tableExists("sensor_data");
        System.out.println("Table exists? " + bool);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

But for some reason I get this error:

org.apache.hadoop.hbase.DoNotRetryIOException: 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.client.RpcRetryingCaller.translateException(RpcRetryingCaller.java:229)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:202)
at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:320)
at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:295)
at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:160)
at org.apache.hadoop.hbase.client.ClientScanner.<init>(ClientScanner.java:155)
at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:811)
at org.apache.hadoop.hbase.MetaTableAccessor.fullScan(MetaTableAccessor.java:602)
at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:366)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:303)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:313)
at com.twoBM.Tests.HBaseWriter.main(HBaseWriter.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: 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:596)
at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:580)
at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable(MetaTableLocator.java:559)
at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getMetaRegionLocation(ZooKeeperRegistry.java:61)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateMeta(ConnectionManager.java:1185)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion(ConnectionManager.java:1152)
at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:300)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:153)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:61)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200)
... 15 more

I am using Gradle to build my project and currently I am only using the two following dependencies:

compile 'org.apache.hive:hive-jdbc:2.1.0'
compile 'org.apache.hbase:hbase:1.1.6'

Does anyone know to fix this problem? I have tried googling this problem, but without any of the found links providing an actual solution.

Best regards

Zeliax
  • 4,987
  • 10
  • 51
  • 79
  • 2
    What version of hadoop are you running? This sounds like the same dependency conflict described here: http://stackoverflow.com/q/31547463/3009 – highlycaffeinated Sep 27 '16 at 13:06
  • I am not completely sure, but I believe it is version 2.7.2. Thanks for the link however! :D – Zeliax Sep 27 '16 at 13:14
  • Why hadoop version is relevant? We talk of hbase version (the one on cluster vs the one used by client app); zookeeper version might also be of [secondary] interest. +1 to highlycaffeinated's opinion about dependencies conflict. – patrungel Sep 27 '16 at 18:52
  • You can also try running the different version of the hbase client jar. It is the issue mainly with version 1.1.1. https://mvnrepository.com/artifact/org.apache.hbase/hbase-client. – Jacob Joy Dec 18 '19 at 14:55

3 Answers3

10

This is definitely Google Guava's dependency conflict. The default constructor of Stopwatch class became private since Guava v.17 and marked deprecated even earlier.

So to HBase Java client works properly you need Guava v.16 or earlier. Check the way you build your application (Maven/Gradle/Classpath) and find the dependency which uses Guava v.17+. After that, you can resolve the conflict.

maxteneff
  • 1,523
  • 12
  • 28
  • Does that mean I need to find the Hbase dependency that uses guava v.17+ or do I just need to download guava v.17+ as a standalone? – Zeliax Sep 28 '16 at 20:05
  • How did you build your application? If you use Maven or Gradle then you add any dependencies. One of them is HBase which uses Guava v.12 by default. And most likely you added another dependency which uses Guava v.17+. So you should do anything with your dependencies to change version of Guava to <= v.16. For instance you can delete unnecessary dependencies or forced to change the version of Guava. – maxteneff Sep 28 '16 at 20:31
  • I am building my application using gradle. Is it possible to exclude the guava dependency from the package that includes it? – Zeliax Sep 29 '16 at 04:46
  • Probably this answer should help you: http://stackoverflow.com/questions/30728533/gradle-override-transitive-dependency-by-version-classifier – maxteneff Sep 29 '16 at 04:57
  • I tried using the link you provided, but as far as I could find only one of my dependencies use guava, and that is the hbase v 1.2.3. And it uses guava v. 12.0.1 `12.0.1`. Even with the method from your provided link it doesn't work :( – Zeliax Sep 29 '16 at 08:35
  • Thanks it helped me a lot ! It worked for me, I downgraded my guava from 21 to 16. My use was for a kafka/hbase connector. – kulssaka Apr 11 '17 at 09:21
0

I received the same error and had to spend for 5 days to know the issue. I added following dependency and its gone.

<dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>15.0</version>
</dependency>
Nandakishore
  • 981
  • 1
  • 9
  • 22
-1

You can use maven shade plugin to solve this issue. That a look at this blog post. Here is an example (actually a snippet from my working pom.)

  <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.0.0</version>
            <executions>
                <execution>
                    <id>assemble-all</id>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <!--<finalName>PROJECT_NAME-${project.version}-shaded</finalName>-->
                        <relocations>
                            <relocation>
                                <pattern>com.google.common</pattern>
                                <shadedPattern>shaded.com.google.common</shadedPattern>
                            </relocation>
                            <relocation>
                                <pattern>com.google.protobuf</pattern>
                                <shadedPattern>shaded.com.google.protobuf</shadedPattern>
                            </relocation>
                        </relocations>
                        <artifactSet>
                            <includes>
                                <include>*:*</include>
                            </includes>
                        </artifactSet>
                    </configuration>
                </execution>
            </executions>
        </plugin>
gorros
  • 1,411
  • 1
  • 18
  • 29