Repository navigation
Sync private - #104518
Sync private#104518scanhex12 merged 17 commits into
Conversation
Move five helpers that wrap `IPartsCollector` and the merge selector
out of the anonymous namespace in `MergeTreeDataMergerMutator.cpp` and
declare them in the header so other table engines can reuse them
without going through `MergeTreeDataMergerMutator`:
- `canMergeAllParts`
- `getBestPartitionToOptimizeEntire`
- `grabAllPossibleRanges` (returns just `PartsRanges` for callers
that don't need the per-partition statistics)
- `chooseMergesFrom`
- `grabAllPartsInsidePartition`
Add `calculateStatisticsForPartitions` for callers that obtain ranges
from a source other than `IPartsCollector` (which fills statistics
itself).
The internal callers in `MergeTreeDataMergerMutator` keep using the
full-fat `CollectedPartsRanges` flavour, which is renamed to
`collectAllPossibleRanges` to free up the public name.
Also let the per-storage backoff bias propagate into
`BackgroundJobsAssignee::postpone` via the existing virtual
`IBackgroundOperation::getBiasBackoffSeconds` (defaults to 0, so this
is a no-op for current `MergeTreeData` users).
No behaviour change for `MergeTree` family.
Make `StorageObjectStorage` an `IBackgroundOperation` so engines backed by object storage can opt into the same scheduling infrastructure that `MergeTree` uses. The wiring is opt-in: by default `StorageObjectStorageConfiguration::isBackgroundExecutable` returns false, `startup` / `shutdown` skip the assignee, and any attempt to schedule a job through a configuration that hasn't overridden `scheduleDataProcessingJob` fails with `NOT_IMPLEMENTED`. Existing `StorageS3`, `StorageAzure`, `StorageHDFS`, etc. observe no behaviour change. Subclasses opt in by overriding: - `isBackgroundExecutable` (return true) - `scheduleDataProcessingJob` - optionally `finishAllBackgroundJobs` and `getBiasBackoffSeconds` `scheduleDataMovingJob` is a hard `NOT_IMPLEMENTED` override; object storage doesn't have parts to move between disks. Also expose `getObjectStorage` / `getObjectStorageConfiguration` on `StorageObjectStorage` so configuration-side background workers can reach the underlying storage and configuration without friend declarations.
|
Workflow [PR], commit [df93162] Summary: ❌
AI ReviewSummaryThis PR extracts Findings❌ Blockers
ClickHouse Rules
Performance & Safety
Final Verdict
|
|
|
||
| std::shared_ptr<DataLake::ICatalog> catalog; | ||
| StorageID storage_id; | ||
| BackgroundJobsAssignee background_operations_assignee; |
There was a problem hiding this comment.
BackgroundJobsAssignee caches StorageID and uses it in finish to remove queued tasks by storage id. With this new assignee on StorageObjectStorage, table rename now needs the same renameInMemory handling as MergeTreeData (background_operations_assignee.updateStorageID(new_table_id)).
Without it, after RENAME TABLE the assignee keeps the old id and shutdown/destruction may fail to remove queued tasks for the renamed table.
Please add a renameInMemory override in StorageObjectStorage that calls IStorage::renameInMemory(new_table_id) and then updates background_operations_assignee.
There was a problem hiding this comment.
This is still reproducible on the current HEAD (78fa1bc9).
StorageObjectStorage now owns background_operations_assignee, but the class still has no renameInMemory override. BackgroundJobsAssignee caches StorageID from construction and uses it in finish for removeTasksCorrespondingToStorage(...).
After RENAME TABLE, IStorage::renameInMemory updates only the base IStorage id, so the assignee keeps the old id and shutdown can leave queued background tasks behind. Please add StorageObjectStorage::renameInMemory that calls IStorage::renameInMemory(new_table_id) and background_operations_assignee.updateStorageID(new_table_id) (and keep storage_id member consistent as well, since it is used in this class).
There was a problem hiding this comment.
This still looks unresolved on the current head.
StorageObjectStorage now owns background_operations_assignee, but there is still no renameInMemory override in either StorageObjectStorage.h or StorageObjectStorage.cpp. BackgroundJobsAssignee caches StorageID and uses it in finish for removeTasksCorrespondingToStorage(...), so after RENAME TABLE it can keep removing tasks for the old id.
Please add StorageObjectStorage::renameInMemory that calls IStorage::renameInMemory(new_table_id), background_operations_assignee.updateStorageID(new_table_id), and updates the class storage_id member too (it is used in this class, e.g. in executeCommand/alter paths).
There was a problem hiding this comment.
I re-checked this on the current PR head and it is still unresolved: StorageObjectStorage has background_operations_assignee and storage_id, but there is still no renameInMemory override.
After RENAME TABLE, IStorage::renameInMemory updates only the base StorageID; the assignee still keeps the old id used by BackgroundJobsAssignee::finish (removeTasksCorrespondingToStorage(...)). That can leave queued background tasks tied to the old table id.
Please add StorageObjectStorage::renameInMemory that calls IStorage::renameInMemory(new_table_id) and then updates both background_operations_assignee (updateStorageID(new_table_id)) and the class storage_id member.
There was a problem hiding this comment.
Re-checking current HEAD: this is still unresolved.
StorageObjectStorage owns background_operations_assignee, but there is still no renameInMemory override updating the cached storage id (background_operations_assignee.updateStorageID(new_table_id)). After RENAME TABLE, finish can still look up jobs by the old id and miss waiting/cleanup for the new id.
There was a problem hiding this comment.
Still live on current HEAD (7e8c5200). StorageObjectStorage now owns background_operations_assignee, but there is still no StorageObjectStorage::renameInMemory override that forwards the new id into BackgroundJobsAssignee::updateStorageID.
BackgroundJobsAssignee::finish removes queued tasks by its cached storage_id, so after RENAME TABLE we can leave stale tasks under the old id.
There was a problem hiding this comment.
Still unresolved on current HEAD (e774411f).
StorageObjectStorage still has no renameInMemory override, so background_operations_assignee keeps the old StorageID after RENAME TABLE.
BackgroundJobsAssignee::finish removes queued jobs by its cached storage_id, so cleanup can miss jobs that are now associated with the renamed table id. Please add StorageObjectStorage::renameInMemory and update both background_operations_assignee (updateStorageID) and the class storage_id member.
There was a problem hiding this comment.
Re-checking current code: this is still unresolved.
StorageObjectStorage still has no renameInMemory override, so after RENAME TABLE the cached id inside background_operations_assignee is not synchronized. BackgroundJobsAssignee::finish removes tasks by cached storage id, so cleanup/wait can target the old id.
Please add StorageObjectStorage::renameInMemory that calls IStorage::renameInMemory(new_table_id), then updates both background_operations_assignee via updateStorageID(new_table_id) and the class member storage_id.
There was a problem hiding this comment.
This is still a real correctness issue on the current head.
StorageObjectStorage now owns background_operations_assignee and a cached storage_id, but the class still does not override renameInMemory. After RENAME TABLE, background_operations_assignee keeps the old StorageID, so BackgroundJobsAssignee::finish removes tasks for the old name and can leave tasks for the renamed table behind.
Please add StorageObjectStorage::renameInMemory and propagate the new ID to both cached fields, e.g. update storage_id and call background_operations_assignee.updateStorageID(new_table_id).
There was a problem hiding this comment.
Re-checking current HEAD (df93162a): this is still unresolved.
StorageObjectStorage has background_operations_assignee and cached storage_id, but there is still no renameInMemory override to propagate table renames to those cached IDs. After RENAME TABLE, IStorage::renameInMemory updates only the base StorageID, while BackgroundJobsAssignee::finish still removes tasks by its cached storage_id.
Please add StorageObjectStorage::renameInMemory that calls IStorage::renameInMemory(new_table_id), then updates both:
background_operations_assignee.updateStorageID(new_table_id)storage_id = new_table_id
|
|
||
| std::shared_ptr<DataLake::ICatalog> catalog; | ||
| StorageID storage_id; | ||
| BackgroundJobsAssignee background_operations_assignee; |
There was a problem hiding this comment.
BackgroundJobsAssignee caches StorageID and uses it in finish to remove queued tasks by storage id. With this new assignee on StorageObjectStorage, table rename now needs the same renameInMemory handling as MergeTreeData (background_operations_assignee.updateStorageID(new_table_id)).
Without it, after RENAME TABLE the assignee keeps the old id and shutdown/destruction may fail to remove queued tasks for the renamed table.
Please add a renameInMemory override in StorageObjectStorage that calls IStorage::renameInMemory(new_table_id) and then updates background_operations_assignee.
There was a problem hiding this comment.
This still looks unresolved on the current head.
StorageObjectStorage now owns background_operations_assignee, but there is still no renameInMemory override in either StorageObjectStorage.h or StorageObjectStorage.cpp. BackgroundJobsAssignee caches StorageID and uses it in finish for removeTasksCorrespondingToStorage(...), so after RENAME TABLE it can keep removing tasks for the old id.
Please add StorageObjectStorage::renameInMemory that calls IStorage::renameInMemory(new_table_id), background_operations_assignee.updateStorageID(new_table_id), and updates the class storage_id member too (it is used in this class, e.g. in executeCommand/alter paths).
There was a problem hiding this comment.
Still unresolved on current code.
The BackgroundJobsAssignee path added in this PR still lacks the renameInMemory synchronization that MergeTree has. StorageObjectStorage needs to update assignee storage id on rename to keep finish/job lookup consistent after RENAME TABLE.
There was a problem hiding this comment.
Still live on current HEAD.
StorageObjectStorage gained BackgroundJobsAssignee, but rename synchronization is still missing: there is no renameInMemory override that updates the assignee's cached id.
Please mirror the MergeTree pattern (IStorage::renameInMemory(new_table_id) + background_operations_assignee.updateStorageID(new_table_id) + updating local storage_id).
There was a problem hiding this comment.
Re-checking current HEAD: this is still live for the same reason — no StorageObjectStorage::renameInMemory override updates background_operations_assignee/storage_id on rename. The assignee keeps a stale storage id after RENAME TABLE.
There was a problem hiding this comment.
Re-checking current code: this is still unresolved for the same reason. StorageObjectStorage has background scheduling hooks, but no renameInMemory synchronization with BackgroundJobsAssignee::updateStorageID.
Please add StorageObjectStorage::renameInMemory to keep the assignee storage id in sync after rename.
There was a problem hiding this comment.
Re-checking current code: this is still live for the same reason.
StorageObjectStorage gained background scheduling hooks but still does not synchronize rename state with BackgroundJobsAssignee (updateStorageID) in renameInMemory. The cached id can diverge after RENAME TABLE.
There was a problem hiding this comment.
Still live on current code for the same reason: StorageObjectStorage gained background job scheduling but does not override renameInMemory to propagate the new StorageID into BackgroundJobsAssignee.
Without this sync, finish may keep operating on stale table id after RENAME TABLE.
There was a problem hiding this comment.
Re-checking current head: this thread is still live for the same reason.
StorageObjectStorage has no renameInMemory override, so rename does not propagate the new StorageID to background_operations_assignee (or to the class-local storage_id). That leaves background-task cleanup keyed by stale id after RENAME TABLE.
|
Ubuntu seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
| Int32 total_rows; | ||
| Int32 total_bytes; | ||
| Int64 total_rows; | ||
| Int64 total_bytes; |
There was a problem hiding this comment.
DeleteFileWriteResult::total_bytes is now Int64, but the write paths still assign through static_cast<Int32> (delete_data_result[...].total_bytes and update_data_result[...].total_bytes).
That still truncates file sizes above 2 GiB and records incorrect Iceberg snapshot statistics. Please remove the narrowing cast and store full-size values in both assignments.
There was a problem hiding this comment.
This is still live in current HEAD: both write paths still assign total_bytes through static_cast<Int32>:
delete_data_result[...].total_bytes = static_cast<Int32>(delete_bytes);update_data_result[...].total_bytes = static_cast<Int32>(update_bytes);
DeleteFileWriteResult::total_bytes is now Int64, so these casts still truncate values above 2 GiB.
There was a problem hiding this comment.
Re-checked on current HEAD: both narrowing assignments are still present:
delete_data_result[partition_key].total_bytes = static_cast<Int32>(delete_bytes);update_data_result[partition_key].total_bytes = static_cast<Int32>(update_bytes);
DeleteFileWriteResult::total_bytes is Int64, so values above 2 GiB are still truncated in metadata accounting.
There was a problem hiding this comment.
Still unresolved. Both assignments in Mutations.cpp still narrow to Int32:
delete_data_result[partition_key].total_bytes = static_cast<Int32>(delete_bytes);update_data_result[partition_key].total_bytes = static_cast<Int32>(update_bytes);
DeleteFileWriteResult::total_bytes is Int64, so sizes above 2 GiB are still truncated in metadata accounting.
There was a problem hiding this comment.
Still unresolved on current HEAD: DeleteFileWriteResult::total_bytes is Int64, but both write paths still narrow through static_cast<Int32>:
delete_data_result[partition_key].total_bytes = static_cast<Int32>(delete_bytes);update_data_result[partition_key].total_bytes = static_cast<Int32>(update_bytes);
This truncates values above 2^31-1 and can emit incorrect Iceberg metadata. These assignments should keep Int64 end-to-end.
There was a problem hiding this comment.
Still unresolved on current HEAD (e774411f): both assignments still narrow Int64 sizes to Int32.
delete_data_result[partition_key].total_bytes = static_cast<Int32>(delete_bytes);update_data_result[partition_key].total_bytes = static_cast<Int32>(update_bytes);
DeleteFileWriteResult::total_bytes is Int64, so values above 2^31 - 1 are still truncated in Iceberg metadata accounting. These should be assigned without narrowing.
There was a problem hiding this comment.
Still unresolved on current code.
DeleteFileWriteResult::total_bytes is Int64, but both assignments in Mutations.cpp still narrow via static_cast<Int32>:
delete_data_result[partition_key].total_bytes = static_cast<Int32>(delete_bytes);update_data_result[partition_key].total_bytes = static_cast<Int32>(update_bytes);
This truncates sizes above 2^31 - 1 in Iceberg metadata accounting. Please assign delete_bytes / update_bytes directly as Int64.
There was a problem hiding this comment.
This is still live on current code: both write paths narrow byte counts to Int32 even though DeleteFileWriteResult::total_bytes is Int64.
delete_data_result[partition_key].total_bytes = static_cast<Int32>(delete_bytes);update_data_result[partition_key].total_bytes = static_cast<Int32>(update_bytes);
For files larger than 2 GiB, this truncates/overflows metadata and produces incorrect total_bytes. Assign delete_bytes / update_bytes directly (or cast to Int64) instead of Int32.
There was a problem hiding this comment.
Re-checking current HEAD (df93162a): still unresolved.
Both paths still narrow Int64 byte counters to Int32:
delete_data_result[partition_key].total_bytes = static_cast<Int32>(delete_bytes);update_data_result[partition_key].total_bytes = static_cast<Int32>(update_bytes);
DeleteFileWriteResult::total_bytes is Int64, so files above 2 GiB still truncate/overflow metadata accounting. Please assign as Int64 end-to-end (direct assignment or static_cast<Int64>).
|
|
||
| size_t occupied = CurrentMetrics::values[CurrentMetrics::BackgroundMergesAndMutationsPoolTask].load(std::memory_order_relaxed); | ||
| size_t max_tasks_count = context->getMergeMutateExecutor()->getMaxTasksCount(); | ||
| if (occupied > 1 && max_tasks_count - occupied < (*settings)[MergeTreeSetting::number_of_free_entries_in_pool_to_execute_optimize_entire_partition]) |
There was a problem hiding this comment.
occupied/max_tasks_count were changed from signed to size_t, and this expression can now underflow:
max_tasks_count - occupiedWhen occupied > max_tasks_count (possible with transient metric skew), subtraction wraps to a huge unsigned value and the guard is bypassed exactly when the pool is already overloaded.
Please keep these as signed integers (as before), or guard the subtraction explicitly (occupied >= max_tasks_count first).
There was a problem hiding this comment.
Still unresolved on current code: occupied/max_tasks_count are size_t, and the condition still subtracts unsigned values:
max_tasks_count - occupiedWhen occupied >= max_tasks_count, this wraps and can bypass the "not enough idle threads" guard exactly in overload conditions. Please add an explicit occupied >= max_tasks_count check before subtraction (or use signed arithmetic as before).
There was a problem hiding this comment.
Still unresolved. In getBestPartitionToOptimizeEntire, both occupied and max_tasks_count are size_t, and the guard still does unsigned subtraction:
max_tasks_count - occupied < number_of_free_entries_in_pool_to_execute_optimize_entire_partition
If occupied >= max_tasks_count, subtraction wraps and can bypass the overload guard. Please add an explicit occupied >= max_tasks_count check (or use signed arithmetic as before) before subtracting.
There was a problem hiding this comment.
Still live: both occupied and max_tasks_count are size_t, and the guard still uses max_tasks_count - occupied.
When occupied > max_tasks_count (possible with races or dynamic pool-size changes), unsigned subtraction underflows and the condition becomes false, so optimize-entire-partition can run even with no free worker slots. Please compute free slots in a non-underflowing way (for example, clamp to zero before comparing).
There was a problem hiding this comment.
Still live on current HEAD (e774411f).
In getBestPartitionToOptimizeEntire, both occupied and max_tasks_count are size_t, but the guard still computes max_tasks_count - occupied.
When occupied >= max_tasks_count, unsigned subtraction underflows and the "not enough idle threads" check can be bypassed. Please compute free slots in a non-underflowing way (for example, explicit occupied >= max_tasks_count check before subtraction).
There was a problem hiding this comment.
Still unresolved on current code.
In getBestPartitionToOptimizeEntire, occupied and max_tasks_count are size_t, and the guard still computes max_tasks_count - occupied.
When occupied >= max_tasks_count, unsigned subtraction underflows and can bypass the idle-thread check exactly in overload conditions. Please guard explicitly (occupied >= max_tasks_count) before subtraction, or compute free slots with saturation to zero.
There was a problem hiding this comment.
This guard is still unsafe after switching to size_t:
max_tasks_count - occupied < number_of_free_entries_in_pool_to_execute_optimize_entire_partition
If occupied >= max_tasks_count (possible during transient races or after pool-size reconfiguration), unsigned subtraction underflows and the condition becomes false, so the code may continue as if free slots exist.
Please avoid subtraction on unsigned values here, for example by checking occupied >= max_tasks_count first, or by comparing as occupied + required_free_entries > max_tasks_count with overflow-safe logic.
There was a problem hiding this comment.
Re-checking current HEAD (df93162a): this guard is still unsafe.
occupied and max_tasks_count are size_t, and the condition still computes:
max_tasks_count - occupied < number_of_free_entries_in_pool_to_execute_optimize_entire_partition
If occupied >= max_tasks_count, unsigned subtraction underflows and the overload guard can be bypassed. Please avoid subtracting unsigned values here (for example, explicit occupied >= max_tasks_count check before subtraction, or compute free slots with saturation to zero).
…objstorage-bg-hooks
LLVM Coverage Report
Changed lines: 69.90% (267/382) | lost baseline coverage: 4 line(s) · Uncovered code |
1a7ea50
| return ranges_by_partitions; | ||
| } | ||
|
|
||
| String getBestPartitionToOptimizeEntire( |
There was a problem hiding this comment.
I remember here #94104 we discussed and concluded that changes to the merge mutator were not needed, at least from the MergeTree side. What changed?
Changelog category (leave one):
Version info
26.5.1.548