Repository navigation
Fix manifest compaction delete all - #111241
Conversation
|
Workflow [PR], commit [52c641c] Summary: ✅
AI ReviewSummaryThis PR makes Missing context / blind spots
Final Verdict✅ No blocking issues found in the current diff. LLVM Coverage ReportMeasured on commit 52c641c.
Changed lines: Changed C/C++ lines covered: 27/34 (79.41%) · Uncovered code |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 1/4 (25.00%) · Uncovered code |
| if (partitions_map.size() >= num_data_manifests) | ||
| /// Nothing to consolidate: either no live data files remain (empty table; writing an empty manifest list would also crash the Avro writer), | ||
| /// or the data manifests are already optimally consolidated (at most one per partition) so a rewrite cannot reduce the count. | ||
| if (partitions_map.empty() || partitions_map.size() >= num_data_manifests) |
There was a problem hiding this comment.
if partitions_map.empty() means that table is unpartitioned, I think there could be manifests to compact. It means that the early exit is wrong, isn't it?
There was a problem hiding this comment.
🕵 An empty partitions_map does not mean "the table is unpartitioned" - the group key always starts with the source partition-spec id and schema id:
String partition_key = std::to_string(source_partition_spec_id) + "|" + std::to_string(source_schema_id) + "|";
FieldVisitorDump dump_visitor;
for (const auto & val : data_file->parsed_entry->partition_key_value)
partition_key += applyVisitor(dump_visitor, val) + "|";An unpartitioned table has an empty partition_key_value, so all of its live files land in one group keyed "0|0|": partitions_map.size() == 1, not 0. With N data manifests that makes partitions_map.size() >= num_data_manifests false for any N > 1, so such a table is consolidated exactly as before. The map is empty only when not a single live data file was collected from any DATA manifest of the current snapshot.
To make that impossible to misread I replaced the condition with the equivalent total_data_files == 0 and split it into its own branch with its own log message (6b482a4 - every group is created by the same code path that increments total_data_files, so the two conditions always hold together).
And because the argument should not live only in a comment, test_optimize_manifest_files_all_deleted now has a second phase (0368e1e): it refills the same unpartitioned table so the current snapshot lists several DATA manifests again, runs OPTIMIZE TABLE ... MANIFEST, and asserts they are consolidated into exactly one manifest with every live data-file entry preserved. test_optimize_manifest_files is the same shape (unpartitioned, seven inserts) and also still compacts.
|
Dear @scanhex12, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
`partitions_map` is keyed by `"<spec-id>|<schema-id>|"` followed by the partition values, so it is never empty for an unpartitioned table that still has live data files: such a table forms a single group keyed `"0|0|"`. The map is empty only when not a single live data file was collected from the current snapshot's `DATA` manifests, which the equivalent `total_data_files == 0` states outright. Review feedback read `partitions_map.empty()` as "the table is unpartitioned", so express the condition the unambiguous way, split it off into its own branch, and give the two cases separate log messages. There is no behaviour change: every group is created by the same code path that increments `total_data_files`, so `partitions_map.empty()` and `total_data_files == 0` always hold together. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…a again Extend `test_optimize_manifest_files_all_deleted` with a second phase: refill the (unpartitioned) table so the current snapshot references several `DATA` manifests again, run `OPTIMIZE TABLE ... MANIFEST`, and assert that they are consolidated into exactly one manifest with every live data-file entry preserved. This pins down that the early exit for a table with no live data files does not swallow a table that genuinely needs compaction - previously that could only be argued from the code. The manifest-list walk used by the precondition checks is factored into `current_snapshot_data_manifests` so both phases share it, and it now also reports how many `DATA` manifests the current snapshot lists. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`test_optimize_manifest_files_all_deleted` asserted that the post-`OPTIMIZE` snapshot lists a single `DATA` manifest and saw four instead. The compaction itself was correct - the server log shows `Creating manifest file for partition '0|0|' (4 data files)`, `Creating manifest list with 1 partition manifest(s)` and `Committing metadata file: .../v11.metadata.json` - but the test was looking at the wrong snapshot. `default_upload_directory` uses `LocalUploader`, which copies Spark's table *into* the instance's container with `copy_file_to_container`. The host-side `/var/lib/clickhouse/user_files` and the container's are therefore different file systems that only share a path prefix: the host holds what Spark wrote, while `OPTIMIZE TABLE ... MANIFEST` commits its metadata inside the container. So the host-side `get_last_snapshot` can never see a ClickHouse-side commit and kept returning Spark's snapshot, whose manifest list still had the four appended manifests. Resolve the current snapshot inside the instance instead, the way ClickHouse itself resolves it: from the `v<N>.metadata.json` with the highest version. This also removes the host/container mixing from the pre-`OPTIMIZE` precondition checks, which happened to agree only because nothing had been committed on the ClickHouse side yet. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 17 s compile time in total, 7 of them have a recent master baseline. |
…ppens The rejection of Iceberg tables with per-file `key_metadata` protects a *rewrite*: a manifest-only rewrite cannot round-trip the data-file encryption keys, so dropping them would make the table unreadable. It was checked while collecting the current snapshot's manifests, i.e. before either "nothing to consolidate" early return was reachable. That contradicts the contract this pull request establishes. An emptied table - whose `DATA` manifests hold only deleted entries and are never read again - got `NOT_IMPLEMENTED` instead of the no-op it is now supposed to get, and the same held for a table whose manifests were already optimally consolidated. In both cases every manifest is left exactly as it is, so there is no encryption metadata to lose and no reason to turn reporting success into a hard error. Move the check past both early returns, onto the path that actually writes new manifests. The data manifests are collected into `data_manifest_paths` during the pass that was already walking them, which also removes the separate `num_data_manifests` counter that had to be kept in sync with them. Addresses the AI review finding on `Compaction.cpp:642-654`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
OPTIMIZE TABLE ... MANIFESTcrashed the server with aSIGSEGVwhen the current snapshot of an Iceberg table had no live data files — for example after a copy-on-writeDELETEthat removed every row. EveryDATAmanifest still listed by that snapshot yields zero live files, so the rewrite collected nothing and then asked the Avro writer toclosea manifest list it had never written to, dereferencing a null stream.Such a snapshot now takes the same "nothing to consolidate" path as an already optimally consolidated one, so the table is left alone and
OPTIMIZEreports success. The condition is expressed astotal_data_files == 0, which is what the check really means: an unpartitioned table is not affected, because the grouping key always carries the source partition-spec id and schema id and so still forms one group as soon as the table holds live files.Closes: #111216
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes a crash when running
OPTIMIZE TABLE ... MANIFESTon an experimental Iceberg table whose rows had all been deleted.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/111241]
Version info
26.9.1.1412(included in26.9and later)