Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yb-client jar compiled against jdk 11 does not work with jdk 8 #6712

Open
iSignal opened this issue Dec 21, 2020 · 2 comments
Open

yb-client jar compiled against jdk 11 does not work with jdk 8 #6712

iSignal opened this issue Dec 21, 2020 · 2 comments

Comments

@iSignal
Copy link
Contributor

iSignal commented Dec 21, 2020

Repro steps:

  1. Create a yb cluster locally at 127.0.0.1 by running yb-ctl or yugabyted
  2. Ensure java -version shows > Java 8 (Java 9 at least) and run ./yb_build.sh --java-only
  3. Install Java 8 in a different dir. Run <path to java8> -jar java/yb-cli/target/yb-cli-0.8.0-SNAPSHOT.jar. At the prompt, type the commands connect --masters 127.0.0.1:7100 and list masters
  4. See the error Failed to fetch masters info for database at 127.0.0.1:7100, error: com.stumbleupon.async.TimeoutException: Timed out after 10000ms when joining Deferred@503928724(state=RUNNING, result=tablet_locations { tablet_id: "YB Master" replicas { ts_info { permanent_uuid: "e4443d784f6847c08a792e6f2535f667" private_rpc_addresses { host: "127.0.0.1" port: 7100 } } role: LEADER } stale: false partition { partition_key_start: "" partition_key_end: "" } } , callback=release master lookup permit -> retry RPC -> wakeup thread Spring Shell, errback=release master lookup permit -> retry RPC after error -> wakeup thread Spring Shell)

The same error also repros through YW create universe.


When running with DEBUG logging the full details of the error are seen (ips are different):

2020-12-20 19:50:12 DEBUG TabletClient:606 - [Peer YB Master - 172.151.29.141:7100] [id: 0xd2aa4ea4, /10.150.0.148:43978 => /172.151.29.141:7100] EXCEPTION: java.lang.NoSuchMethodError: java.nio.CharBuffer.flip()Ljava/nio/CharBuffer;
2020-12-20 19:50:12 DEBUG TabletClient:700 - [Peer YB Master - 172.151.29.141:7100] Unexpected exception java.nio.CharBuffer.flip()Ljava/nio/CharBuffer; from downstream on [id: 0xd2aa4ea4, /10.150.0.148:43978 => /172.151.29.141:7100]
java.lang.NoSuchMethodError: java.nio.CharBuffer.flip()Ljava/nio/CharBuffer;
        at org.yb.util.Slices.decodeString(Slices.java:174)
        at org.yb.util.Slice.toString(Slice.java:705)
        at org.yb.util.Slice.toString(Slice.java:692)
        at org.yb.client.AsyncYBClient.discoverTablets(AsyncYBClient.java:1679)
        at org.yb.client.AsyncYBClient$MasterLookupCB.call(AsyncYBClient.java:1603)
        at org.yb.client.AsyncYBClient$MasterLookupCB.call(AsyncYBClient.java:1595)
        at com.stumbleupon.async.Deferred.doCall(Deferred.java:1280)
        at com.stumbleupon.async.Deferred.runCallbacks(Deferred.java:1259)
        at com.stumbleupon.async.Deferred.callback(Deferred.java:1002)
        at org.yb.client.GetMasterRegistrationReceived$GetMasterRegistrationCB.call(GetMasterRegistrationReceived.java:193)
        at org.yb.client.GetMasterRegistrationReceived$GetMasterRegistrationCB.call(GetMasterRegistrationReceived.java:165)
        at com.stumbleupon.async.Deferred.doCall(Deferred.java:1280)
        at com.stumbleupon.async.Deferred.runCallbacks(Deferred.java:1259)
        at com.stumbleupon.async.Deferred.callback(Deferred.java:1002)
        at org.yb.client.YRpc.handleCallback(YRpc.java:180)
        at org.yb.client.YRpc.callback(YRpc.java:193)
        at org.yb.client.TabletClient.decode(TabletClient.java:440)
        at org.yb.client.TabletClient.decode(TabletClient.java:98)
        at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:500)
        at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:435)
        at org.yb.client.TabletClient.handleUpstream(TabletClient.java:608)
        at org.jboss.netty.handler.timeout.ReadTimeoutHandler.messageReceived(ReadTimeoutHandler.java:184)
        at org.yb.client.AsyncYBClient$TabletClientPipeline.sendUpstream(AsyncYBClient.java:2088)
        at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
        at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
        at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
        at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
        at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318)
        at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
        at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

The reason for this error is that the flip method of CharBuffer has a different signature in Java 8 and Java 11 (returns ByteBuffer vs Buffer). This causes a "runtime link" error (a more accurate description is at apache/felix#114).

@Arnav15

@gunnarmorling
Copy link

To prevent this, build with --release=8 instead of --source and --target. At Debezium, we also happened to run into this, and I blogged about it just today :)

@iSignal
Copy link
Contributor Author

iSignal commented Dec 30, 2020

@gunnarmorling : Your blog post is the clearest description of the underlying signature mismatch I've seen on this topic so far, thanks for writing it and pointing us to it.

iSignal added a commit that referenced this issue Mar 10, 2021
Summary:
See #6712 for
more details. The signature of ByteBuffer::flip changed between JDK 8 and 9. So when
the client is compiled using Java >8 and run with Java 8, it fails to
"link" the flip method and results in a NoSuchMethod error.

The fix converts the code to always use Buffer.flip instead of the
derived method. This should be not result in a loss of functionality
because the implementation of the flip in the derived class seems to be
the same as the parent class but just returns a different type. See
http://hg.openjdk.java.net/jdk9/sandbox/jdk/file/7d9bd66d2bb9/src/java.base/share/classes/java/nio/X-Buffer.java.template#l1148

The issue highlights another problem in the Java RPC client - it seems
like the error NoSuchMethodException is just swallowed somewhere along
the path. The 'sync' YBClient calls the AsyncYBClient but it might not
provide an 'errback' for the error that results from this call.

Test Plan:
Compile with Java 11, run with Java 8, verify the error is
fixed.

Reviewers: arnav, streddy, daniel

Reviewed By: streddy, daniel

Subscribers: streddy, yugaware

Differential Revision: https://phabricator.dev.yugabyte.com/D10183
YintongMa pushed a commit to YintongMa/yugabyte-db that referenced this issue May 26, 2021
Summary:
See yugabyte#6712 for
more details. The signature of ByteBuffer::flip changed between JDK 8 and 9. So when
the client is compiled using Java >8 and run with Java 8, it fails to
"link" the flip method and results in a NoSuchMethod error.

The fix converts the code to always use Buffer.flip instead of the
derived method. This should be not result in a loss of functionality
because the implementation of the flip in the derived class seems to be
the same as the parent class but just returns a different type. See
http://hg.openjdk.java.net/jdk9/sandbox/jdk/file/7d9bd66d2bb9/src/java.base/share/classes/java/nio/X-Buffer.java.template#l1148

The issue highlights another problem in the Java RPC client - it seems
like the error NoSuchMethodException is just swallowed somewhere along
the path. The 'sync' YBClient calls the AsyncYBClient but it might not
provide an 'errback' for the error that results from this call.

Test Plan:
Compile with Java 11, run with Java 8, verify the error is
fixed.

Reviewers: arnav, streddy, daniel

Reviewed By: streddy, daniel

Subscribers: streddy, yugaware

Differential Revision: https://phabricator.dev.yugabyte.com/D10183
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants