Skip to content

Commit e7a7ac3

Browse files
Fix race condition in Parquet reader accessing next_subgroup_for_step
There was a data race between: - Thread A assigning a new vector to `row_group.next_subgroup_for_step` in `intersectColumnIndexResultsAndInitSubgroups` - Thread B reading `row_group.next_subgroup_for_step.empty()` in the `is_privileged_task` lambda in `scheduleTasksIfNeeded` The fix adds a stage check before accessing the vector. Since `next_subgroup_for_step` is assigned during `OffsetIndex` processing and the stage advances to `ColumnData` only after the assignment, checking `stage >= ColumnData` with acquire ordering ensures proper synchronization. Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent d8c4564 commit e7a7ac3

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎src/Processors/Formats/Impl/Parquet/ReadManager.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,11 @@ void ReadManager::scheduleTasksIfNeeded(ReadStage stage_idx)
626626
if (row_group_idx != i)
627627
return false;
628628
const RowGroup & row_group = reader.row_groups[row_group_idx];
629+
/// Must check stage first to ensure `next_subgroup_for_step` is fully initialized.
630+
/// It's assigned during `OffsetIndex` processing, before stage advances to `ColumnData`.
631+
/// Using acquire ordering to synchronize with the release (seq_cst) store in `finishRowGroupStage`.
632+
if (row_group.stage.load(std::memory_order_acquire) < ReadStage::ColumnData)
633+
return false;
629634
if (row_group.next_subgroup_for_step.empty())
630635
return false;
631636
return row_group.next_subgroup_for_step[0].load() == row_group.delivery_ptr.load();

0 commit comments

Comments
 (0)