Repository navigation
Fix Iceberg OPTIMIZE deleting version-hint - #122833
Conversation
|
Workflow [PR], commit [18bd573] Summary: ✅
AI ReviewSummaryThis PR fixes the happy path for OSS Iceberg Findings
Tests
Final Verdict
LLVM Coverage ReportMeasured on commit 18bd573.
Changed lines: Changed C/C++ lines covered: 88/94 (93.62%) · Uncovered code |
3949eee to
b57bb12
Compare
Build profile diff (arm_release)Commit See the job log for details. |
3c294a3 to
9f3168f
Compare
9f3168f to
0e6d533
Compare
| DB::ContextPtr context, | ||
| bool try_write_version_hint); | ||
| bool try_write_version_hint, | ||
| bool * version_hint_confirmed = nullptr); |
There was a problem hiding this comment.
Let's remove this flag and logical error related to it
There was a problem hiding this comment.
You're right 100% - I've missed that spaghetti logic. The general problem is that for regular updates it's okay to succeed writing metadata, but to fail updating the hint file. For optimize operations, this is more complicated. I made it explicit, as well as the contract for optimize in general.
| { | ||
| const auto sample_block = std::make_shared<const Block>(metadata_snapshot->getSampleBlock()); | ||
| auto snapshots_info = getHistory(context); | ||
| auto snapshots_info = getHistory(context, /* ignore_metadata_pointer_overrides */ true); |
There was a problem hiding this comment.
absolute slop, used to cover the gap in ambiguous logic. I removed this one and the change in getHistory as well.
| /// writer that does not have the setting enabled advances the table. | ||
| size_t i = 0; | ||
| while (i < MAX_TRANSACTION_RETRIES) | ||
| for (size_t attempt=0; attempt < MAX_TRANSACTION_RETRIES; ++attempt) |
| return true; | ||
| } | ||
|
|
||
| bool tryWriteVersionHintFile( |
There was a problem hiding this comment.
I think that when an INSERT and a compaction (OPTIMIZE) run concurrently, they can corrupt the metadata.json file. In this case, both operations write metadata.json at the same time, and we only detect the conflict later, at the step where we write the version hint file.
I think OPTIMIZE should fail correctly (without breaking metadata of insert operation) in this case.
We can fix it in the following PR, but we need to keep it in mind
|
📊 Cloud Performance Report
This PR only changes how Iceberg compaction and metadata writes handle the version-hint file, plus one new stateless test. Neither ClickBench nor TPC-H runs that code. No query has a directional verdict. ClickBench Q31 (-13.9%) is inside master's normal range with almost no change in CPU time, so leaving it as no change fits the diff. ClickBench Q34 (-11.2%) shows a matching CPU drop, but master's history for this query shifted mid-window, so the old numbers don't give a reliable comparison. The diff also cannot explain the drop, so not_sure is the right call. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
866b862 to
0d5d8fd
Compare
| json_representation, | ||
| object_storage, | ||
| context)) | ||
| throw Exception(ErrorCodes::FILE_ALREADY_EXISTS, "Metadata file {} already exists", generated_metadata_info.path.serialize()); |
There was a problem hiding this comment.
writeMetadataFile does not mean only “the path already exists”: it also returns false for retryable storage failures after logging them (see the new helper in Utils.cpp). Mapping every false to FILE_ALREADY_EXISTS here turns a transient metadata-write failure into a bogus version-conflict, which is what the user will see from OPTIMIZE.
Can we preserve the original failure here (or at least distinguish “already exists” from “write was not confirmed”) instead of always throwing FILE_ALREADY_EXISTS?
| if (writeMetadataFiles(plan, persistent_table_components.path_resolver, object_storage_, context_, sample_block_, write_format, persistent_table_components.table_path)) | ||
| clearOldFiles(object_storage_, old_files); | ||
| else | ||
| LOG_WARNING(getLogger("IcebergCompaction"), "Compacted metadata was written but its version hint was not confirmed; old files were retained"); |
There was a problem hiding this comment.
If writeMetadataFiles returns false, the rewritten data files / manifests / vN.metadata.json have already been created, but the compaction was not published through version-hint.text. This branch only logs a warning and still lets OPTIMIZE return success, so a transient hint-update failure or a writer race leaves the whole rewritten snapshot tree orphaned while the command appears to have worked.
I think this needs to surface a retryable commit-conflict/failure (or clean up the just-written files) rather than quietly succeeding.
0d5d8fd to
18bd573
Compare
A task of a distributed plan runs a deserialized plan, and plan headers carry names and types only, so a receive step's header has a full column where the producing stage emits a `ColumnConst`. The Persisted and Streaming exchanges write through `NativeWriter`, which materializes constants, but `SinkFromInMemoryExchange` (used by `distributed_plan_execute_locally`) forwarded the chunk unchanged. With a constant `ORDER BY` key, `PartialSortingTransform` kept its LIMIT threshold as a `ColumnConst`, and the next zero-row scheduling tick of `SourceFromInMemoryExchange`, built from the header, made `ColumnVector<UInt8>::compareColumn` read the `ColumnConst` threshold as a `ColumnVector`, which aborted debug and sanitizer builds with the `PODArray` bounds assertion (STID 2508-1e49). Materialize constants in `SinkFromInMemoryExchange::consume`, the only caller of `InMemoryExchange::appendChunk`, so all in-memory exchanges deliver what the serialized ones do. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122833&sha=866b862fc9f521847ee9acac63978be11ba19e3c&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 PR: ClickHouse#122833 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
OPTIMIZE TABLEon OSS Iceberg tables could deletemetadata/version-hint.text, leaving hint-based readers unable to open the table.Changes
Advance compaction metadata output to the next metadata version instead of rewriting
v0.metadata.json.Publish compacted metadata via the existing metadata-and-version-hint helper so
version-hint.textstays in sync.Restrict old metadata cleanup to
.metadata.jsonfiles soversion-hint.textis not treated as obsolete metadata.Add a stateless regression test covering
OPTIMIZE TABLEon an Iceberg table withiceberg_use_version_hint = 1.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
OPTIMIZE TABLEfor OSS Iceberg tables so compaction no longer removesversion-hint.textand breaks hint-based reads.Closes: #120164
Workflow [PR]
Sync PR [sync-upstream/pr/122833]
Version info
26.10.1.1912-master(included in26.10and later)