Resolve lost wakeup in SpillPoolReader with multiple concurrent SpillPoolWriters#23522
Open
pepijnve wants to merge 1 commit into
Open
Resolve lost wakeup in SpillPoolReader with multiple concurrent SpillPoolWriters#23522pepijnve wants to merge 1 commit into
pepijnve wants to merge 1 commit into
Conversation
Member
That is interesting because I constantly facing the "Too many open files" when there is a heavy spill. I did not know it is a problem and I was thinking it is OK, just used |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
When multiple
SpillPoolWriterclones concurrently push batches to the same channel, more than one non-finishedSpillFilecan be in flight. This happens because eachSpillPoolWriterclone takes thecurrent_write_fileat the start ofpush_batchand puts it back when it's done. When multiplepush_batchcalls happen concurrently, only the first one will be able to take thecurrent_write_fileand the others will all create their own new spill file. Which one gets put back for subsequent use is a race condition.If this occurred and the writers are all dropped before rotation happens in, multiple files in the
filesdeque will be havewriter_finished == false. The last writer drop logic inSpillPoolWriter::droponly finishes whatever file is thecurrent_write_fileas finished.This can lead to a stalled situation when
SpillPoolFile::poll_nextcatches up with the writer and returnsPendingbecausewriter_finished == false. A waker for the file is registered, but since the last writer drop logic only finishes and wakes whatever happens to becurrent_write_file, which may not be the current read file, the waker may end up never being notified.There is a secondary waker that is registered on the spill pool itself, but due to fine grained locking, it is possible for the wake call in the last writer drop logic to be called before the waker registration.
What changes are included in this PR?
writer_droppedfield which was an unnecessary denormalisation ofactive_writer_count == 0An additional benefit of tracking all unfinished write files is that excessive creation of tiny spill files is avoided when many writers are pushing batches concurrently.
Are these changes tested?
Reproduction case from linked issue was used to confirm fix
Are there any user-facing changes?
No