JaneliaSciComp / BigStitcher-Spark

Running compute-intense parts of BigStitcher distributed
BSD 2-Clause "Simplified" License
18 stars 10 forks source link

NoSuchMethodError for Gson library #11

Closed trautmane closed 1 year ago

trautmane commented 1 year ago

Hi @kgabor,

You mentioned that after adding zarr export support to AffineFusion, you ran into the following error when running a distributed spark instance:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.gson.reflect.TypeToken.getParameterized(Ljava/lang/reflect/Type;[Ljava/lang/reflect/Type;)Lcom/google/gson/reflect/TypeToken;
        at org.janelia.saalfeldlab.n5.zarr.N5ZarrReader.getZArraryAttributes(N5ZarrReader.java:259)
        ...

I think this problem occurs because the Hadoop libraries used by Spark pull in an ancient version of Gson (likely 2.2.4 or similar) and the n5 zarr library (currently) relies upon Gson 2.8.6. Even though Gson 2.8.6 is bundled in the big-stitcher fat jar, the Hadoop stuff is higher in the classpath when running a Spark cluster - so you end up running with ancient Gson. This post describes the issue very nicely.

As the post mentions, the best way to fix this issue is to force Spark to use a newer Gson library by specifying additional --conf arguments when launching spark-submit like this:

/misc/local/spark-3.0.1/bin/spark-submit 
  --deploy-mode client 
  --master spark://... 
  --conf spark.driver.extraClassPath=/groups/scicompsoft/home/trautmane/bigstitcher/gabor/gson-2.8.6.jar
  --conf spark.executor.extraClassPath=/groups/scicompsoft/home/trautmane/bigstitcher/gabor/gson-2.8.6.jar
  ...

You'll need to:

Give this a shot and let me know if it solves the errors you were getting. I ran a small test case at Janelia and was able to successfully produce a zarr result - so, I'm hopeful this will work for you.

Finally while debugging this problem, I made a few minor tweaks to your commits here that mean you will need to specify -s ZARR (capitalized) instead of your original lower case version if you pull and run with the latest code.

Let me know how it goes, Eric

kgabor commented 1 year ago

Works perfectly, thanks!

trautmane commented 1 year ago

Glad to hear it worked!