Repository navigation
fix(arrow): wake equality-delete waiters with the notifier of the started load - #3697
Conversation
…rted load Co-authored-by: JeonDaehong <[email protected]>
JeonDaehong
left a comment
There was a problem hiding this comment.
Thanks @c-thiel for picking this up, and for the co-author credit! I checked that the new test catches the bug. With the old behavior put back in insert_equality_delete (a fresh Notify stored over the one from try_start_eq_del_load), the test times out after 5s. With the fix it passes, and so do the arrow:: tests on 3db15d4. The other case from #3275 (notified_owned() under the lock) is already on main, so this closes out both. LGTM.
| *entry.lock().unwrap() |= delete_vector; | ||
| } | ||
|
|
||
| /// Stores the equality delete predicate that `eq_del` delivers, and wakes the tasks |
There was a problem hiding this comment.
Since this no longer writes the Loading state itself, it now relies on try_start_eq_del_load having stored notify for this path. A caller that skips that step would leave no entry, and get_equality_delete_predicate_for_delete_file_path returns None for a missing entry, so the delete would be silently skipped rather than hang. Maybe say this in the doc comment, or add a debug_assert! that the entry is Loading(notify)?
There was a problem hiding this comment.
Hm, I think a missing entry wouldn't skip the delete silently, though: build_equality_delete_predicate turns the None into an Unexpected error ("Missing predicate for equality delete file …"). I think the case worth guarding is a different notifier, which would leave the waiters hanging again, as in the bug here. So I added a debug_assert! that the entry is Loading with this exact notifier, like the one in abandon_pos_del_load. Every test that loads equality deletes through the loader now checks it. 5139400
Makes sense?
|
|
||
| let mut waiter = Box::pin(filter.get_equality_delete_predicate_for_delete_file_path(path)); | ||
| // Registers the waiter on the notifier that `try_start_eq_del_load` stored. | ||
| assert!(futures::poll!(&mut waiter).is_pending()); |
There was a problem hiding this comment.
Polling once here makes the window deterministic without a multi-thread runtime or a sleep. My repro on #3275 needed both, so this is a much better test.
laskoviymishka
left a comment
There was a problem hiding this comment.
Thanks @c-thiel for sending the #3275 fix now rather than waiting on the PR limit. As I read it, waiters register notified_owned() on the same Notify that try_start_eq_del_load stored, and tokio guarantees a created Notified gets notify_waiters() even before its first poll (notify.rs), so nobody is left on a stale notifier.
Which issue does this PR close?
No issue yet. A scan can hang forever when two data files share an equality delete file: a task can wait on a notifier that is never woken.
@JeonDaehong found this race and proposed this fix on #3275, planned as a follow-up once the open PR limit allows. This PR sends that fix now, with @JeonDaehong as co-author of the commit. The reviews of #2873 and #3268 also raised it.
What changes are included in this PR?
CachingDeleteFileLoadermarks an equality delete file as loading withtry_start_eq_del_load, which stores a notifier. It then callsinsert_equality_delete, which replaced that state with a second notifier and woke only the second one when the predicate arrived. A task that read the state between the two calls waited on the first notifier forever, so the record batch stream fromArrowReader::readnever finished. This needs a multi-thread runtime and a pause between the two calls, so it is rare, but the hang is permanent.insert_equality_deletenow takes the notifier fromtry_start_eq_del_loadand keeps the loading state that it set. A failed load is a separate case (#3274, #3275).Are these changes tested?
Yes, in
arrow::delete_filter:test_eq_del_waiter_registered_before_insert_is_wokenregisters a waiter between the two calls and checks that it gets the predicate. Without the fix it times out.test_build_equality_delete_predicate_case_sensitivenow starts the load first, as the loader does.AI Disclosure
Supported by Claude Code. Reviewed and checked by me.