Uh oh!
There was an error while loading. Please reload this page.
[SPARK-14930][SPARK-13693] Fix race condition in CheckpointWriter.stop() - #12712
[SPARK-14930][SPARK-13693] Fix race condition in CheckpointWriter.stop()#12712JoshRosen wants to merge 1 commit into
Conversation
SparkQA
commented
Apr 26, 2016
Test build #57030 has finished for PR 12712 at commit
|
JoshRosen
commented
Apr 26, 2016
Jenkins, retest this please. |
SparkQA
commented
Apr 26, 2016
Test build #57040 has finished for PR 12712 at commit
|
marmbrus
commented
Apr 27, 2016
LGTM, thanks for fixing this! |
| private var stopped = false | ||
| private var _fs: FileSystem = _ | ||
| @volatile private[this] var fs: FileSystem = null |
There was a problem hiding this comment.
Does this even need to be a member? it looks like it's used entirely in one method.
There was a problem hiding this comment.
It's actually referenced by inner classes. I think the idea here is that we'll avoid calling .getFileSystem too much by caching the result, but will have the ability to clear the cache in case the cached FileSystem seems to be in a bad state.
There was a problem hiding this comment.
minor: fs and latestCheckpointTime don't need to be volatile as we use Executors.newFixedThreadPool(1) here. We should also give the thread a name for better debugging.
tdas
commented
Apr 27, 2016
LGTM. Merging to master |
CheckpointWriter.stop() is prone to a race condition: if one thread calls
stop()right as a checkpoint write task begins to execute, that write task may become blocked when trying to accessfs, the shared Hadoop FileSystem, since both thefsgetter andstopmethod synchronize on the same lock. Here's a thread-dump excerpt which illustrates the problem:We can fix this problem by having
stopandfsbe synchronized on different locks: the synchronization onstoponly needs to guard against multiple threads callingstopat the same time, whereas the synchronization onfsis only necessary for cross-thread visibility. There's only ever a single active checkpoint writer thread at a time, so we don't need to guard against concurrent access tofs. Thus,fscan simply become a@volatilevar, similar tolastCheckpointTime.This change should fix SPARK-13693, a flaky
MapWithStateSuitetest suite which has recently been failing several times per day. It also results in a huge test speedup: prior to this patch,MapWithStateSuitetook about 80 seconds to run, whereas it now runs in less than 10 seconds. For thestreamingproject's tests as a whole, they now run in ~220 seconds vs. ~354 before./cc @zsxwing and @tdas for review.