Renaming native libraries is easy,
I will change the lib name from snappy to snappyjava.
Thank you for the suggestion.
--
Taro L. Saito
<l...@xerial.org>
University of Tokyo
http://www.xerial.org/leo
Tel. +81-47-136-4065 (64065)
> --
> You received this message because you are subscribed to the Google Groups "Xerial" group.
> To post to this group, send email to xer...@googlegroups.com.
> To unsubscribe from this group, send email to xerial+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/xerial?hl=en.
>
>
I created a snapshot version that renames native libraries from
libsnappy to libsnappyjava:
http://maven.xerial.org/repository/snapshot/org/xerial/snappy/snappy-java/1.0.2-SNAPSHOT/snappy-java-1.0.2-20110602.024416-2.jar
I am not sure this simple renaming works well, since
snappy-java and hadoop-snappy use the same snappy library,
thus function names in both native libraries might collide.
--
Taro L. Saito
<l...@xerial.org>
University of Tokyo
http://www.xerial.org/leo
Tel. +81-47-136-4065 (64065)
The solution you mentioned is possible by supplying JVM arguments, for example,
-Dorg.xerial.snappy.lib.path=(directory path containing libsnappy.so)
-Dorg.xerial.snappy.lib.name=libsnappy.so
(You can also use System.setProperty(...) )
If these two variables are set before calling methods in
org.xerial.snappy.Snappy, snappy-java tries to load the specified
native library instead of the one embedded in snappy-java.jar.
However, UnsatisfiedLinkError is observed when the same native library
(in this case libsnappy.so) is loaded twice in JVM (see also
http://code.google.com/p/snappy-java/#Using_snappy-java_with_Tomcat6_Web_Server
)
Oops, but I noticed now that using libsnappy.so as a replacement of
libsnappyjava.so is impossible, because libsnappyjava contains not
only snappy but also JNI interfaces and codes for invoking the
original API of snappy.
If the UnsatisfiedLinkError is a problem of loading libsnappyjava.so
two or more times, it can be fixed by putting snapy-java-(version).jar
where the parent class loader can find it.
Regards,
--
Taro L. Saito
<l...@xerial.org>
University of Tokyo
http://www.xerial.org/leo
Tel. +81-47-136-4065 (64065)
Technically speaking, splitting .so file into two parts is possible;
snappy and interface accessing to snappy as in the Hadoop Snappy
implementation. But accessing native codes without issuing
loadLibrary(libsnappy.so) would be a difficult problem because we have
to check whether the native code is loaded or not in the other class
outside of org.xerial.snappy.
Java has no function to check whether the specified native library
(e.g., libsnappy.so) is loaded or not in ancestor or parent class
loaders that are visible from the current class loader. If snappy-java
is loaded in a parent class loader, its child class loader uses
snappy-java loaded in the parent, so UnsatisfiedLinkError will not be
thrown.
A possible workaround would be accessing the native code through JNI
and if encountered UnsatisfiedLinkError, trying to load a native code.
I am not sure whether this approach works properly or not.
And also, note that libsnapyjava.so uses statically linked snappy. I guess
function name collision between libsnappy.so and libsnappyjava.so is
not a real problem.
Is their any possibility that your code uses snappy-java from
different class loaders in the same JVM?
I guess Hadoop might use different class loaders to run map tasks, and
if you embed snappy-java.jar and your map function classes into a
single jar file for running MapReduce task in a Hadoop, that is a
problem. I often see similar problems when using JNI-based library
with Tomcat, which also forks several class loaders in a JVM.
If it is the case, adding snappy-java to the classpath of hadoop node
might solve your problem, not in the jars of your map-reduce programs.
Bests,
--
Taro L. Saito
<l...@xerial.org>
University of Tokyo
http://www.xerial.org/leo
Tel. +81-47-136-4065 (64065)
I would like to confirm where you put snappy-java-(version).jar ?
in HADOOP_HOME/lib or within another jar file passed to Hadoop?
If snappy-java is in HADOOP_HOME/lib and task tracker node is configured to load
snappy-java in HADOO_HOME/lib, UnsatisfiedLinkError problem is probably a bug
in snappy-java (failed to find a proper native library, or something
else, e.g., function symbol collision, etc.)
If snappy-java is in somewhere else, first call to Snappy will
succeed, but subsequent
calls will fail.
This is my understandings.
--
Taro L. Saito
<l...@xerial.org>
University of Tokyo
http://www.xerial.org/leo
Tel. +81-47-136-4065 (64065)
Thank you for the information.
I checked the exported symbols in libsnappyjava.so using 'nm -C -D' and
found the original API of snappy is also exported in the static
library. Your are correct.
I hid the snappy API using -fvisibility=hidden option in gcc-4.x, and shipped
a new snapshot version:
http://maven.xerial.org/repository/snapshot/org/xerial/snappy/snappy-java/1.0.3-SNAPSHOT/snappy-java-1.0.3-20110604.005740-2.jar
The fix is as follows:
http://code.google.com/p/snappy-java/source/detail?r=60dd607e755e13d7e0378186a19ab1322cc1819c
--
Taro L. Saito
<l...@xerial.org>
University of Tokyo
http://www.xerial.org/leo
Tel. +81-47-136-4065 (64065)