-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Kafka compressions Snappy and LZ4 not supported with native builds #2718
Comments
There's https://github.com/airlift/aircompressor but I suppose a switch would involve a patch to Kafka client source. |
Can we do something like #2794? |
It's a bit more tricky as Graal does not support optional "substitutions". In an ideal world, we would remove Snappy if we can't find it in the classpath. I might be somewhat possible for some of the substitution (methods) but not for all (class substitution). |
Will #3060 help? How about https://github.com/quarkusio/quarkus/projects/10?
Given how Kafka clients fail at runtime with the rather opaque error message described above, what's the rationale for removing the compression types at build time? I suppose an alternative could be to let it fail at runtime with an error that is either class loading or JNI, depending on how the build was produced. IMO the latter provides a way forward, while the current approach rules out any attempt at supporting these compressions. Edit: to clarify, I'd be happy to experiment with JNI, but first I'd have to un-patch the Kafka client. I asked initially if support has somehow been ruled out? If so the un-patch would never land in the Quarkus code base and thus the experiments with JNI would be a waste of time. |
From #2999 it looks like JNI support is being strengthened. I also noticed that |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you! |
I think we have optional substitutions now with |
@irenakezic this one might be doable now. See my last comment about adding conditions to the substitions depending on what we have in the classpath (there are a few examples in the code). It might be tricky to test though but you know Kafka so that might help :). |
@gsmet ok thx! I will give it a try but probably not before the weekend. |
@gsmet sorry for taking so long to look into this.
|
Is the fix for supporting these compression algorithms doable or not? I also see that |
It's now doable as GraalVM has added optional substitutions. |
I was able to make a workaround. Therefore I removed https://github.com/quarkusio/quarkus/blob/master/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/runtime/graal/SubstituteSnappy.java#L26-L65 and builded snapshot In my project I added the snappy java dependency: implementation group: 'org.xerial.snappy', name: 'snappy-java', version: '1.1.8.4' In addition the native library snappyjava needs to be loaded by: System.loadLibrary("snappyjava"); This native library file Extract the COPY native/org/xerial/snappy/native/Linux/x86_64/libsnappyjava.so /work/libsnappyjava.so
RUN chmod +x /work/libsnappyjava.so The class I would be happy to try to create a pr. But I would need some directions e.g. What would be the right way of adding the native libraries? How should this in general be approached? Would it be an option to just remove the |
Thanks @spike83! That's a great step forward! Here are a few thoughts:
Which version of GraalVM did you use? |
@cescoffier I'm running the build in docker image quay.io/quarkus/ubi-quarkus-native-image:21.0.0-java11 (id: 31ccea2b17ae) so I would say 21.0. |
Perfect thanks! MethodHandle support has been added in that version, which explains why you don't need any substitutions. |
Hi guys :-) Im trying to use snappy in a native quarkus application too. Thanks for your help :) |
At the moment yes. I will be working on it soon. |
thanks a lot! for now I got it working with the workaround. So no need for a hurry ;-) |
#15174 provides an initial support. The library is embedded in the native image (need to enable snappy and use GraalVM 21+) and loaded when the application starts. The funny thing is that 4 days ago the MethodHandle used in the Kafka client have been removed... However, it would not enable the support on GraalVM 20.3 as it also needs serialization support. |
This limitation is documented in #977 but not in https://quarkus.io/guides/kafka-guide. My question is what level of effort went in to trying to support snappy and gzip? Is JNI with native somehow ruled out, or might it be worth a try after #2412?
Describe the bug
Native builds disable support for message compression types Snappy and Gzip. Any attempt to consume or produce will result in an exception where the compression type is reported as an integer. The enumeration is in https://github.com/apache/kafka/blob/2.2.1/clients/src/main/java/org/apache/kafka/common/record/CompressionType.java.
A review comment in #977 documents the "hack" in https://github.com/quarkusio/quarkus/blob/0.16/extensions/kafka-client/runtime/src/main/java/io/quarkus/kafka/client/runtime/graal/SubstituteSnappy.java.
Expected behavior
Kafka consumers typically handle compression transparently. Compression is per message, not per topic. The broker enumerates supported compressions. Also messages are immutable and AFAIK there is no other way to remove compression than to rewrite the topic.
Actual behavior
For example when trying to consume a message compressed with Snappy:
I haven't tested ZStandard yet. It isn't explicitly disabled, but I think it too requires a native lib.
To Reproduce
snappy
compression.Environment (please complete the following information):
uname -a
orver
: I've only run in docker.java -version
: 8 and 11Workaround
Use a jvm build. Note that with the FROM in the generated Dockerfile (
fabric8/java-alpine-openjdk8-jre
) you must addRUN apk add --no-cache libc6-compat
in order to avoid the errorjava.lang.UnsatisfiedLinkError: /tmp/snappy-1.1.7-3d2397f3-516f-45ab-aad1-94be731682f5-libsnappyjava.so: Error loading shared library ld-linux-x86-64.so.2: No such file or directory
.The text was updated successfully, but these errors were encountered: