Skip to content

Fix a lost wakeup in the Delta Lake data file iterator - #129547

Merged
alexey-milovidov merged 3 commits into
masterfrom
delta-lake-scan-fixes
Nov 7, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
delta-lake-scan-fixes

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

A query reading a Delta Lake table could hang forever when the data file scanning thread failed, e.g. with PATH_ACCESS_DENIED for a data file referred to by a path outside of the table directory.

TableSnapshot::Iterator::setScanException set scan_exception and shutdown without holding next_mutex and then notified data_files_cv. If the notification came after next had checked the condition of its wait but before it started waiting, the wakeup was lost. The destructor set shutdown the same way before notifying the scanning thread, which waits on schedule_next_batch_cv with the same kind of condition, so it could hang in join. Both are set under the mutex now, which also makes next read scan_exception after it is written.

It was found by 05526_delta_lake_kernel_golden_errors of #129093, which reads the canonicalized-paths-* golden tables of delta-kernel-rs: it hung with TSan in two jobs, with the main thread waiting on a condition variable (report). The race does not reproduce in a release build (200 parallel runs with and without the fix), so there is no separate test. #129093 has been merged first, and 05526_delta_lake_kernel_golden_errors now times out on master the same way (report); this PR fixes it.

Related: #129093

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a rare hang of a query reading a Delta Lake table when listing its data files fails.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/129547]

Version info

  • Merged into: 26.11.1.1596-master (included in 26.11 and later)

`TableSnapshot::Iterator::setScanException` set `scan_exception` and `shutdown` without holding `next_mutex`
and then notified `data_files_cv`. If the notification came after `next` checked the condition of the wait
but before it started waiting, `next` waited forever, and the query hung. This happens when the scanning
thread fails, e.g. with `PATH_ACCESS_DENIED` for a data file outside of the table directory, and it was seen
with TSan. The destructor set `shutdown` in the same way before notifying the scanning thread, which waits
on `schedule_next_batch_cv` with the same condition, so it could hang in `join` as well. Set them under the
mutex. This also makes `next` read `scan_exception` after it is written.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129093&sha=23927a29eeb17c626ca415713a6eae693f2d74c9&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20targeted%29
Related: #129093

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ae7bb14]

Summary: ✅


AI Review

Summary

The PR protects iterator shutdown and scan-exception publication with next_mutex, preventing lost wakeups when Delta Lake scanning fails or the iterator is destroyed. Reviewed the full modified file, its callers and callback paths, and all prior PR discussion at head ae7bb14754e37ff5c8e48c02658d02b8c6c641e1; the local file matches that head. No source-level correctness defect found. One Major remains: the known reproducer has no verified passing TSan run with the fix.

Findings

⚠️ Majors

Tests
  • ⚠️ Select the existing 05526_delta_lake_kernel_golden_errors for repeated TSan runs with the patched iterator and attach the result; no new test is required. The current head workflow is still running and its targeted TSan job is pending, so it supplies no replacement evidence yet. No local build or tests were run.
Final Verdict

Status: ⚠️ Request changes. Provide passing focused TSan validation of the existing reproducer. No implementation change is requested based on the code review. Posted one Major inline comment in a single batched review.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 5, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Nov 5, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ae7bb1475 with master 1e4565847 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 25a55661d; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels Nov 6, 2026
/// checking the condition and starting to wait, and reads `scan_exception` after it is set.
void setScanException()
{
std::lock_guard lock(next_mutex);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major] Please validate the known lost-wakeup reproducer with the patched iterator under TSan. 05526_delta_lake_kernel_golden_errors times out on master, but it is absent from the completed targeted TSan run at 85b72dfd, despite that job reporting 880 passes. The current head's targeted TSan job is still pending. The described release runs cannot establish that the observed TSan-only hang is fixed, since they also passed without the fix. No additional test is needed: select the existing reproducer for repeated TSan runs and attach the result showing that the scan errors propagate without a timeout.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 7, 2026
Merged via the queue into master with commit ac23198 Nov 7, 2026
188 checks passed
@alexey-milovidov
alexey-milovidov deleted the delta-lake-scan-fixes branch November 7, 2026 13:39
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 7, 2026
@clickhouse-gh clickhouse-gh Bot added comp-delta-lake Delta Lake tables: reading Delta metadata through delta-kernel-rs (table snapshots, schema and ty... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-delta-lake Delta Lake tables: reading Delta metadata through delta-kernel-rs (table snapshots, schema and ty... pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants