-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[fix](iceberg) Harden external-write lifecycle, OCC, memory, and file ownership #66348
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
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
5839584
[fix](iceberg) Harden write lifecycle and cleanup
Gabriel39 f299232
[fix](iceberg) Address write safety review findings
Gabriel39 08b5ac7
[fix](iceberg) Preserve Azure data and deduplicate orphan scans
Gabriel39 065e5df
[fix](iceberg) Address follow-up write safety review
Gabriel39 87b3235
[fix](iceberg) Address multipart and snapshot review feedback
Gabriel39 25f5e23
[fix](iceberg) Address remaining write safety feedback
Gabriel39 febfd1a
[fix](iceberg) Match object store hash layout
Gabriel39 5f8b26f
[fix](azure) Keep multipart block IDs rolling-compatible
Gabriel39 82a09e1
[test](azure) Seed legacy residual block ID
Gabriel39 2771934
[fix](azure) Fence multipart writers with blob leases
Gabriel39 b6f4f01
[fix](iceberg) Close async and rolling boundaries
Gabriel39 630af93
[test](iceberg) Isolate async admission policy
Gabriel39 40f328b
[fix](iceberg) Close remaining write safety gaps
Gabriel39 d002553
[chore](be) Fix clang formatting
Gabriel39 3f1b475
[fix](iceberg) Close final write ownership gaps
Gabriel39 d01bebc
[fix](iceberg) Gate standalone deletes on report ACK
Gabriel39 6799e4e
[fix](iceberg) Preserve external write ownership until final report
Gabriel39 403b77a
[fix](iceberg) Avoid writer test suite collision
Gabriel39 025bd21
[test](be) Cover deferred upload report lifecycle
Gabriel39 44cb06d
[fix](be) Declare external report Thrift parameter
Gabriel39 7dbfd96
[fix](iceberg) Bound partition sorter memory admission
Gabriel39 78a36ec
[fix](regression) Isolate MTMV job lookup
Gabriel39 c5f07d4
[fix](test) Model Iceberg report ACK in merge sink UT
Gabriel39 35a48c0
[fix](test) Preserve rebase safety invariants
Gabriel39 190ebe5
[fix](iceberg) Close external write review gaps
Gabriel39 b02a3ff
[fix](fe) Fix Checkstyle import ordering
Gabriel39 8314c90
[fix](iceberg) Keep scan test compatible with catalog properties
Gabriel39 71abd40
[fix](azure) Isolate multipart blocks with upload UUIDs
Gabriel39 64eba05
[fix](iceberg) Preserve EOS memory reservation through close
Gabriel39 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <algorithm> | ||
| #include <limits> | ||
| #include <vector> | ||
|
|
||
| namespace doris { | ||
|
|
||
| class Block; | ||
|
|
||
| struct IcebergSorterReserveMemory { | ||
| size_t retained_growth = 0; | ||
| size_t retained_growth_trigger_bytes = 0; | ||
| size_t transient_workspace = 0; | ||
| }; | ||
|
|
||
| inline size_t iceberg_saturating_add(size_t lhs, size_t rhs) { | ||
| return std::min(std::numeric_limits<size_t>::max() - lhs, rhs) + lhs; | ||
| } | ||
|
|
||
| inline size_t bounded_iceberg_reserve_size( | ||
| const std::vector<IcebergSorterReserveMemory>& per_partition_reservations, | ||
| size_t incoming_rows = std::numeric_limits<size_t>::max(), | ||
| size_t incoming_bytes = std::numeric_limits<size_t>::max()) { | ||
| size_t transient_workspace = 0; | ||
| for (const auto& reservation : per_partition_reservations) { | ||
| transient_workspace = std::max(transient_workspace, reservation.transient_workspace); | ||
| } | ||
|
|
||
| std::vector<const IcebergSorterReserveMemory*> growth_candidates; | ||
| growth_candidates.reserve(per_partition_reservations.size()); | ||
| for (const auto& reservation : per_partition_reservations) { | ||
| if (reservation.retained_growth > 0) { | ||
| growth_candidates.push_back(&reservation); | ||
| } | ||
| } | ||
|
|
||
| std::sort(growth_candidates.begin(), growth_candidates.end(), | ||
| [](const auto* lhs, const auto* rhs) { | ||
| return lhs->retained_growth > rhs->retained_growth; | ||
| }); | ||
| size_t row_bound = 0; | ||
| for (size_t i = 0; i < std::min(incoming_rows, growth_candidates.size()); ++i) { | ||
| row_bound = iceberg_saturating_add(row_bound, growth_candidates[i]->retained_growth); | ||
| } | ||
|
|
||
| size_t byte_bound = 0; | ||
| std::vector<const IcebergSorterReserveMemory*> positive_trigger_candidates; | ||
| positive_trigger_candidates.reserve(growth_candidates.size()); | ||
| for (const auto* reservation : growth_candidates) { | ||
| if (reservation->retained_growth_trigger_bytes == 0) { | ||
| byte_bound = iceberg_saturating_add(byte_bound, reservation->retained_growth); | ||
| } else { | ||
| positive_trigger_candidates.push_back(reservation); | ||
| } | ||
| } | ||
| std::sort(positive_trigger_candidates.begin(), positive_trigger_candidates.end(), | ||
| [](const auto* lhs, const auto* rhs) { | ||
| return static_cast<unsigned __int128>(lhs->retained_growth) * | ||
| rhs->retained_growth_trigger_bytes > | ||
| static_cast<unsigned __int128>(rhs->retained_growth) * | ||
| lhs->retained_growth_trigger_bytes; | ||
| }); | ||
| size_t remaining_bytes = incoming_bytes; | ||
| for (const auto* reservation : positive_trigger_candidates) { | ||
| if (reservation->retained_growth_trigger_bytes <= remaining_bytes) { | ||
| byte_bound = iceberg_saturating_add(byte_bound, reservation->retained_growth); | ||
| remaining_bytes -= reservation->retained_growth_trigger_bytes; | ||
| continue; | ||
| } | ||
| const auto numerator = | ||
| static_cast<unsigned __int128>(reservation->retained_growth) * remaining_bytes + | ||
| reservation->retained_growth_trigger_bytes - 1; | ||
| const auto fractional_growth = | ||
| std::min<unsigned __int128>(numerator / reservation->retained_growth_trigger_bytes, | ||
| std::numeric_limits<size_t>::max()); | ||
| byte_bound = iceberg_saturating_add(byte_bound, static_cast<size_t>(fractional_growth)); | ||
| break; | ||
| } | ||
|
|
||
| // A block's rows and bytes are divided across partition sorters. The two fractional-relaxation | ||
| // bounds avoid charging the complete input block to every active partition while remaining safe. | ||
| const size_t retained_growth = std::min(row_bound, byte_bound); | ||
| return iceberg_saturating_add(retained_growth, transient_workspace); | ||
| } | ||
|
|
||
| inline size_t iceberg_reserve_size( | ||
| const std::vector<IcebergSorterReserveMemory>& per_partition_reservations, | ||
| size_t incoming_block_reserve, size_t incoming_rows = std::numeric_limits<size_t>::max(), | ||
| size_t incoming_bytes = std::numeric_limits<size_t>::max()) { | ||
| size_t sorter_reserve = | ||
| bounded_iceberg_reserve_size(per_partition_reservations, incoming_rows, incoming_bytes); | ||
| // The incoming block creates cold partition writers before they can appear in the published snapshot. | ||
| return iceberg_saturating_add(sorter_reserve, incoming_block_reserve); | ||
| } | ||
|
|
||
| size_t iceberg_cold_writer_reserve_size(const Block& block, size_t writer_workspace_bytes); | ||
|
|
||
| inline size_t iceberg_spill_merge_workspace(size_t spill_file_count, size_t spill_buffer_bytes, | ||
| size_t merge_limit_bytes) { | ||
| if (spill_file_count == 0 || spill_buffer_bytes == 0) { | ||
| return 0; | ||
| } | ||
| const size_t max_fan_in = std::max<size_t>(2, merge_limit_bytes / spill_buffer_bytes); | ||
| const size_t input_count = std::min(spill_file_count, max_fan_in); | ||
| const size_t max_size = std::numeric_limits<size_t>::max(); | ||
| const size_t input_bytes = input_count > max_size / spill_buffer_bytes | ||
| ? max_size | ||
| : input_count * spill_buffer_bytes; | ||
| // VSortedRunMerger materializes one block per input cursor plus the block being emitted. | ||
| return input_bytes > max_size - spill_buffer_bytes ? max_size | ||
| : input_bytes + spill_buffer_bytes; | ||
| } | ||
|
|
||
| } // namespace doris |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.