Google Cloud Bigtable Java Client - tcnative error

2019-08-03 13:09发布

问题:

I am trying to connect to Cloud Bigtable; however, I'm getting issues with netty-tcnative not being found.

Maven dependencies:

<dependency>
    <groupId>com.google.cloud.bigtable</groupId>
    <artifactId>bigtable-hbase-1.2</artifactId>
    <version>0.9.2</version>
</dependency>

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-tcnative-boringssl-static</artifactId>
    <version>1.1.33.Fork19</version>
</dependency>

Error output:

ERROR 2016-09-09 22:26:00,969 [main] com.google.cloud.bigtable.grpc.BigtableSession: Neither Jetty ALPN nor OpenSSL are available. OpenSSL unavailability cause:
java.lang.IllegalArgumentException: Failed to load any of the given libraries: [netty-tcnative-osx-x86_64, netty-tcnative]    
Exception in thread "BigtableSession-startup-2" java.lang.ExceptionInInitializerError
at com.google.cloud.bigtable.grpc.BigtableSession$3.run(BigtableSession.java:194)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: zip file closed
at java.util.zip.ZipFile.ensureOpen(ZipFile.java:634)
at java.util.zip.ZipFile.getEntry(ZipFile.java:305)
at java.util.jar.JarFile.getEntry(JarFile.java:227)
at java.util.jar.JarFile.getJarEntry(JarFile.java:210)
at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:840)
at sun.misc.URLClassPath.getResource(URLClassPath.java:199)
at java.net.URLClassLoader$1.run(URLClassLoader.java:358)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.mule.module.launcher.FineGrainedControlClassLoader.findClass(FineGrainedControlClassLoader.java:175)
at org.mule.module.launcher.MuleApplicationClassLoader.findClass(MuleApplicationClassLoader.java:134)
at org.mule.module.launcher.FineGrainedControlClassLoader.loadClass(FineGrainedControlClassLoader.java:119)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.google.bigtable.repackaged.io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:36)
at com.google.bigtable.repackaged.io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:58)
at com.google.bigtable.repackaged.io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:47)
at com.google.bigtable.repackaged.io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:58)
at com.google.bigtable.repackaged.io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:77)
at com.google.bigtable.repackaged.io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:72)
at com.google.bigtable.repackaged.io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:59)
at com.google.cloud.bigtable.grpc.BigtableSessionSharedThreadPools.init(BigtableSessionSharedThreadPools.java:85)
at com.google.cloud.bigtable.grpc.BigtableSessionSharedThreadPools.<init>(BigtableSessionSharedThreadPools.java:77)
at com.google.cloud.bigtable.grpc.BigtableSessionSharedThreadPools.<clinit>(BigtableSessionSharedThreadPools.java:45)
... 4 more
Exception in thread "BigtableSession-startup-1" java.lang.IllegalStateException: zip file closed
at java.util.zip.ZipFile.ensureOpen(ZipFile.java:634)
at java.util.zip.ZipFile.getEntry(ZipFile.java:305)
at java.util.jar.JarFile.getEntry(JarFile.java:227)
at java.util.jar.JarFile.getJarEntry(JarFile.java:210)
at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:840)
at sun.misc.URLClassPath.getResource(URLClassPath.java:199)
at java.net.URLClassLoader$1.run(URLClassLoader.java:358)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.mule.module.launcher.FineGrainedControlClassLoader.findClass(FineGrainedControlClassLoader.java:175)
at org.mule.module.launcher.MuleApplicationClassLoader.findClass(MuleApplicationClassLoader.java:134)
at org.mule.module.launcher.FineGrainedControlClassLoader.loadClass(FineGrainedControlClassLoader.java:119)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.google.bigtable.repackaged.com.google.api.client.http.javanet.NetHttpTransport$Builder.trustCertificates(NetHttpTransport.java:270)
at com.google.bigtable.repackaged.com.google.api.client.googleapis.javanet.GoogleNetHttpTransport.newTrustedTransport(GoogleNetHttpTransport.java:55)
at com.google.cloud.bigtable.config.CredentialFactory.getHttpTransport(CredentialFactory.java:94)
at com.google.cloud.bigtable.grpc.BigtableSession$2.run(BigtableSession.java:183)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

回答1:

This issue was due to Mule's class loader. Mule runs each app in its own class loader. Need to move this to Mule's common class loader (java.class.path), rather than the app class loader. Ensuring both BigTable client library and tcnative is in the same classpath.

This issue would arise in other containers such as Tomcat, as they follow similar class loader patterns.