-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[bug](iceberg) fix iceberg sink writer with spill report error #62899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,7 @@ | |
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <limits> | ||
| #include <mutex> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing |
||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
|
|
@@ -101,12 +101,12 @@ class VIcebergSortWriter : public IPartitionWriterBase { | |
|
|
||
| inline size_t written_len() const override { return _iceberg_partition_writer->written_len(); } | ||
|
|
||
| // Returns a raw pointer to the FullSorter, used by SpillIcebergTableSinkLocalState | ||
| // to query memory usage (data_size, get_reserve_mem_size) | ||
| auto sorter() const { return _sorter.get(); } | ||
| size_t data_size() const; | ||
|
|
||
| size_t get_reserve_mem_size(RuntimeState* state, bool eos) const; | ||
|
|
||
| // Called by the memory management system to trigger spilling data to disk | ||
| Status trigger_spill() { return _do_spill(); } | ||
| Status trigger_spill(); | ||
|
|
||
| private: | ||
| // Calculate average row size from the first non-empty block to determine | ||
|
|
@@ -129,6 +129,8 @@ class VIcebergSortWriter : public IPartitionWriterBase { | |
| // Explicitly calls do_sort() before prepare_for_read() to guarantee sorted output. | ||
| Status _do_spill(); | ||
|
|
||
| Status _close_locked(const Status& status); | ||
|
|
||
| // Merge all spilled streams and output final sorted data to Parquet/ORC files. | ||
| // Handles file splitting when output exceeds target file size. | ||
| Status _combine_files_output(); | ||
|
|
@@ -168,6 +170,17 @@ class VIcebergSortWriter : public IPartitionWriterBase { | |
| std::unique_ptr<FullSorter> _sorter; | ||
| std::unique_ptr<VSortedRunMerger> _merger; | ||
|
|
||
| // Serialize all accesses to _sorter because async writes and revoke spills run on | ||
| // different thread pools but touch the same FullSorter instance. | ||
| mutable std::mutex _sorter_mutex; | ||
|
|
||
| // Set to true once close() has finished tearing down the sorter / underlying writer. | ||
| // Late-arriving revoke spills (which run on a different thread than the async writer) | ||
| // must become no-ops after close, otherwise they would write to a fresh spill stream | ||
| // whose data never gets merged out (close has already produced the final output and | ||
| // cleaned up spill files). | ||
| bool _closed = false; | ||
|
|
||
| // Queue of spill files waiting to be merged (FIFO order) | ||
| std::deque<SpillFileSPtr> _sorted_spill_files; | ||
| // Files currently being consumed by the merger | ||
|
|
@@ -185,4 +198,4 @@ class VIcebergSortWriter : public IPartitionWriterBase { | |
| RuntimeProfile::Counter* _do_spill_count_counter = nullptr; | ||
| }; | ||
|
|
||
| } // namespace doris | ||
| } // namespace doris | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still reads
_writer->current_writer()without synchronization before the newVIcebergSortWritermutex can help.current_writer()returns a reference to_current_writer, while the async writer thread assigns_current_writer = writerinVIcebergTableWriter::_write_prepared_block()after each write. Workload memory revocation can enter this path concurrently with that assignment, so theshared_ptrobject itself is read and written at the same time, which is undefined behavior and can still cause the spill-time crash this PR is trying to fix. Please protect_current_writerwith the same synchronization boundary (or return a synchronized copy / atomic shared_ptr) before doing thedynamic_cast.