Closed qxzzxq closed 2 years ago
It's Spark 3.0.1, isn't it? Could this be somehow related to https://github.com/apache/spark/commit/9236fc407fe11db13063129d6a2494e573891766? Looks suspiciously similar. I'd check out 3.0.2 to see if things got any better.
Hi @jaceklaskowski thank you for your reply. The version of Spark we used is 3.0.1.
I tried to run with Spark 3.0.2 and 3.0.0, I still got the same problem.
seems like the problem still exists in delta 1.0.0 with a different message
java.lang.IllegalStateException: SparkContext has been shutdown
Can you post the app (to reproduce the issue) to delta forum?
The snippet in the initial message of @qxzzxq reproduce it, I will post it in the forum
the forum link https://groups.google.com/g/delta-users/c/K3_7kmKbmI4
@qxzzxq Thanks for reporting this. Which version doesn't have this issue? I tried 0.6.0 and 0.70 and saw NullPointerException as well. One simple fix would be ignoring exceptions at this line since we don't care about the uncache failure: https://github.com/delta-io/delta/blob/v1.0.0/core/src/main/scala/org/apache/spark/sql/delta/util/StateCache.scala#L107
Feel free to open a PR to fix it if anyone has free time :)
I'm also seeing this bug with Delta 1.0.0 and Spark 3.1.2. It seems like Delta is storing some state about a cached snapshot that persists even when the underlying SparkSession has been closed. It probably needs to either detect when the SparkSession has changed or been deleted and invalidate the cache, or tolerate exceptions in the uncaching as @zsxwing suggested.
This is happening in my unit tests as with @qxzzxq. Are there any suggested workarounds? I'm not sure that persisting a single SparkSession across tests is a good idea, but I'm not sure if there are any other options. There would have to be some way to access the snapshot in question and unpersist it prior to shutting down the first SparkSession. I'm not entirely sure what objects Delta is creating that are spanning SparkSessions and tests.
We are currently reviewing this issue and will follow up shortly.
Hi, when can we expect a fix for this issue. And in the mean time is there a temporary workaround to avoid this issue?
I submitted #881 to fix this. You can call org.apache.spark.sql.delta.DeltaLog.clearCache()
after stopping Spark as a workaround.
Description
Our unit tests worked well before Delta 0.7.0. After upgrading Delta from 0.7.0 to 0.8.0, we noticed that our unit tests failed due to some
java.lang.NullPointerException
that was thrown during the write of Dataset (https://github.com/SETL-Framework/setl/pull/183).The test framework we used is ScalaTest 3.2.1. In our tests, we stop the active
SparkSession
at the beginning of each test and re-create a new one with a differentSparkConf
.We found that if we shut down the active SparkSession and create a new one, then Datasets/DataFrames could no longer be written. However, if we use the existing one, no
NullPointerException
will be thrown in this situation. Unfortunately, this is not a suitable solution as we need to modify the configuration for each test.For other formats, like csv, we don't have any error. I don't know if this is a designed feature of Delta or there is indeed a bug.
Error Reproduction
Run the following piece of code to reproduce the error.
NullPointerException will be thrown with Delta 0.7.0 and 0.8.0 (the code does throw a NullPointerException with Delta 0.7.0 but I don't understand why our unit tests could still pass :p )
Environment
Java 1.8 Scala 2.12.10 Spark 3.0.1 Delta 0.8.0 ScalaTest 3.2.1