Bug: [hbase-examples] MultiThreadedClientExample throws java.lang.ClassCastException
Status: Resolved | Priority: Minor | Resolution: Fixed
Created: 26/Jul/23 05:53

Tried using run() method call of [https://github.com/apache/hbase/blob/master/hbase-examples/src/main/java/org/apache/hadoop/hbase/client/example/MultiThreadedClientExample.java|https://github.com/apache/hbase/blob/master/hbase-examples/src/main/java/org/apache/hadoop/hbase/client/example/MultiThreadedClientExample.java.] Following the stack trace of error during runtime
{code:java}
Exception in thread "main" java.io.IOException: java.lang.reflect.UndeclaredThrowableException
    at org.apache.hadoop.hbase.client.ConnectionFactory.lambda$createConnection$1(ConnectionFactory.java:235)
    at org.apache.hadoop.hbase.trace.TraceUtil.trace(TraceUtil.java:216)
    at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:218)
    at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:160)
    at org.apache.hadoop.hbase.client.example.MultiThreadedClientExample.run(MultiThreadedClientExample.java:136)
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:76)
    at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:90)
    at <classname>.runMultiThreadedRWOps(xxxxxx)
    at <classname>.main(xxxxxx)
Caused by: java.lang.reflect.UndeclaredThrowableException
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1780)
    at org.apache.hadoop.hbase.security.User$SecureHadoopUser.runAs(User.java:328)
    at org.apache.hadoop.hbase.client.ConnectionFactory.lambda$createConnection$1(ConnectionFactory.java:232)
    ... 8 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedConstructorAccessor16.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.apache.hadoop.hbase.client.ConnectionFactory.lambda$null$0(ConnectionFactory.java:233)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1762)
    ... 10 more
Caused by: java.lang.ClassCastException: java.util.concurrent.ForkJoinPool cannot be cast to java.util.concurrent.ThreadPoolExecutor
    at org.apache.hadoop.hbase.client.ConnectionImplementation.<init>(ConnectionImplementation.java:283)
    at org.apache.hadoop.hbase.client.ConnectionImplementation.<init>(ConnectionImplementation.java:270)
    ... 17 more
{code}

Reason: due to HBASE-22244 Make use of MetricsConnection in async client following changes
{code:java}
  // thread executor shared by all Table instances created
  // by this connection
  private volatile ExecutorService batchPool = null; got modified to private volatile ThreadPoolExecutor batchPool = null;
{code}

ExecutorService got changed to ThreadPoolExecutor. ExecutorService is compatible with ForkJoinPool however ThreadPoolExecutor is not compatible.