Repository navigation
Fix an error reading an Iceberg table whose current-snapshot-id is JSON null - #121460
tiandiwonder wants to merge 4 commits into
Conversation
…t-id` is JSON null" This reverts commit cc06a47.
This is why the first attempt was reverted (#121443): on a cloud build `IcebergMetadata::optimize` is gated on `IcebergCompactionMetadataGenerator`, which the background scheduler creates lazily, and both tests re-attach the table right before calling `OPTIMIZE` - so the generator did not exist yet and the command raised `Logical error: Background compaction is not initialized. This is a bug`. The tests themselves passed, because their cloud branch classified that outcome as acceptable, but the harness reads `Logical error` out of the *server log* (`ci/jobs/scripts/log_parser.py`) and reports it against whatever job shares that server, which is the "havoc in the private CI" the revert describes. Excusing the outcome was the wrong shape. The command is now not issued at all on a cloud build: the paths these tests cover (`getHistory`, and the compaction guard behind it) exist only in the open-source branch, and the surrounding assertions - the table still reads as empty, the row counts around the rewrite - hold on both builds and are the only things printed. A successful `OPTIMIZE` now prints nothing, so the reference no longer carries a line that a cloud build produces without having run anything. Measured on this branch: forcing the cloud branch issues **0** `OPTIMIZE` queries (both tests still match their references), against 3 on the open-source path, so the log line that caused the revert cannot be produced. The three tests pass on an open-source build. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [1fe18e8] Summary: ✅
AI ReviewSummaryThis PR teaches the Iceberg paths that read Findings
Final VerdictNeeds changes before merge: the LLVM Coverage ReportMeasured on commit 1fe18e8.
Changed lines: Changed C/C++ lines covered: 36/38 (94.74%) · Uncovered code |
|
|
||
| if (!metadata->has(Iceberg::f_current_snapshot_id)) | ||
| /// `has` is true for a JSON null, and `getValue<Int64>` throws on one; null means "no current snapshot". | ||
| if (!metadata->has(Iceberg::f_current_snapshot_id) || metadata->isNull(Iceberg::f_current_snapshot_id)) |
There was a problem hiding this comment.
expire_snapshots already derives protected snapshots from refs (applyRetentionPolicy / partitionSnapshotsByIds below), so returning here on JSON null is only correct if the metadata is actually snapshotless. The new fixtures do not put it in that state: they null only current-snapshot-id, while refs.main.snapshot-id still points at the live snapshot. All of our in-tree snapshotless metadata either clears refs or sets refs.main.snapshot-id = -1 (for example tests/queries/0_stateless/data_minio/simple_usage_test/v0.metadata.json and tests/queries/0_stateless/data_minio/issue87414/test/t0/metadata/v1.metadata.json).
With the PR as written, expire_snapshots now becomes a silent no-op on metadata that still advertises a live main branch, instead of just avoiding the getValue<Int64> conversion error. Please either normalize refs.main in the fixture too, or keep walking refs here and short-circuit only when both carriers say there is no current snapshot.
current-snapshot-id is JSON null (re-land)current-snapshot-id is JSON null
…it printed The sibling `04846_iceberg_optimize_snapshotless_position_delete` already does this; this test was left deciding on "stderr is non-empty", which is not the same question. The harness sets `CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL` to `warning` and injects `--send_logs_level`, so any unrelated server-log line the client prints would have been reported as `FAIL: OPTIMIZE failed: ...`, failing the test for something that is not a failure. The exit status answers the question the test is actually asking, and `--send_logs_level=fatal` keeps a real exception's report to three lines. The conversion-error check stays text-based: `Can not convert empty value` is the signature of the regression this test exists for, and the client still prints the exception with logs at `fatal`. Verified on this branch: the test passes; with `allow_experimental_iceberg_compaction` dropped so `OPTIMIZE` genuinely fails, it reports `FAIL: OPTIMIZE failed: ... Code: 36 ... (BAD_ARGUMENTS)` and mismatches, so the assertion still catches a broken `OPTIMIZE`; and with the cloud branch forced it issues no `OPTIMIZE` at all. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Related: #114465
Related: #121443
Re-lands #114465, which was reverted by #121443. The fix itself is unchanged; only the two tests
that call
OPTIMIZEare.Why it was reverted
On a cloud build
IcebergMetadata::optimizeis gated onIcebergCompactionMetadataGenerator, whichthe background scheduler creates lazily. Both
OPTIMIZEtests re-attach the table immediatelybefore calling the command — to pick up the hand-edited
current-snapshot-id— so on a cloud buildthe generator did not exist yet and
OPTIMIZEraisedLogical error: Background compaction is not initialized. This is a bug.The tests passed: their cloud branch classified that exception as acceptable. But the harness does
not only read test output —
ci/jobs/scripts/log_parser.pyextractsLogical error.*from theserver log and the functional-test results report it against whatever job shares that server.
Hence the "absolute havoc in the private CI" the revert describes. The public CI has no cloud build,
so nothing showed there.
What changed
The command is no longer issued on a cloud build at all, instead of being issued and then excused:
getHistoryand the compaction guard behind it) exist only inthe open-source branch, so there is nothing for them to assert on cloud;
around the rewrite — and a successful
OPTIMIZEnow prints nothing, so the reference no longercontains a line a cloud build can produce without having run anything.
Measured on this branch: with the cloud branch forced, 0
OPTIMIZEqueries reach the server andboth tests still match their references; the open-source path issues 3. The three tests pass on an
open-source build.
The sibling
04846_iceberg_null_current_snapshot_idis untouched: it exercises the readers thatbehave the same on both builds and never calls
OPTIMIZE.Follow-up, not fixed here
OPTIMIZEon a freshly attached Iceberg table raising aLOGICAL_ERRORthat says "This is a bug"is a real defect of the cloud path — a user-reachable window, not a test artifact. It is being fixed
separately on the cloud side; these tests simply stop walking into it.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an error when reading an Iceberg table whose
current-snapshot-idis JSON null, which some writers emit for a table with no current snapshot.Workflow [PR]
Sync PR [sync-upstream/pr/121460]