Skip to content

Do not build an empty aggregate function state in 05211_backup_log_zero_byte_data_file - #120048

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/05211-zero-byte-fixture-empty-array
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/05211-zero-byte-fixture-empty-array

Conversation

@groeneai

@groeneai groeneai commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #119727
Related: #119722
Related: #119728
Related: #119858 (comment)

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Test-only. 05211_backup_log_zero_byte_data_file no longer builds an aggregate function state that serializes to zero bytes, so it stops leaving behind a table whose reads fail with Invalid number of columns in chunk pushed to OutputPort.

Description

05211_backup_log_zero_byte_data_file builds its zero-byte-data-file fixture from a column of countResample(10, 5, 1) states. The range is empty, so every state serializes to nothing and the column reads back as zero rows while __marks.mrk records 100. LogSource::readData drops the empty column, a short chunk reaches a two-column output port, and any reader of the table it leaves behind aborts with Invalid number of columns in chunk pushed to OutputPort. Expected 2, found 1 (#119727). 05211 itself reports OK, so the abort lands on whatever ran next, which is why it reds master and unrelated pull requests.

This split was asked for on #119858 so master goes quiet while #119728 finishes review; no source change here. The carrier becomes an all-empty Array(UInt64) column: its element stream receives nothing, so s.bin is 0 bytes beside a populated s.size0.bin, the same on-disk condition without the broken read path. No query can observe a file's size, so the fixture asserts it from data_paths[1]. #119728 carries the same rewrite and can take master's version once this merges.

The swap costs one of 05211's two carriers: reverting BackupImpl::copyFileToDisk still reds every restored arm, reverting StorageLog::hasNothingToBackUp no longer does, because an array column's first data file is its always-populated sizes stream. Only an empty aggregate state can put a zero-byte data file first while rows exist, so 05212_backup_log_zero_byte_first_data_file covers that predicate directly, fabricating the recorded size under a private clickhouse-local path as 05099_log_array_missing_elements does. Four arms: Log and TinyLog each kept by a later data file, Log kept by its marks, and TinyLog with neither, whose data the backup must omit. Reverting both StorageLog files reds the first three and leaves 05211 green; narrowing the predicate to require marks reds the fourth.

Validated on a master build with no source change: 50 randomized runs of both pass.


Workflow [PR]
Sync PR [sync-upstream/pr/120048]

…ro_byte_data_file

The fixture built its zero-byte data file from a column of
countResample(10, 5, 1) states. That parameterisation covers an empty range,
so every state serializes to nothing: the column deserializes to zero rows
while __marks.mrk still records 100, LogSource::readData drops the empty
column, and a chunk with fewer columns than its output port header reaches
ISource::prepare(). Any read of the table this test leaves behind then aborts
with "Invalid number of columns in chunk pushed to OutputPort. Expected 2,
found 1" (issue ClickHouse#119727). The test reports OK itself, so the abort is
attributed to whatever ran next, which is why it reds master and unrelated
pull requests rather than 05211.

Build the same on-disk condition from an all-empty Array(UInt64) column
instead. Its element stream receives nothing, so s.bin holds 0 bytes beside a
populated s.size0.bin, and reading it back does not go through the broken
path: the array consistency check compares nested size against the last
offset, and both are 0.

This costs one of the two carriers the test covered. With an array column
data_files[0] is the always-populated sizes stream, so reverting
StorageLog::hasNothingToBackUp no longer reddens the test, while reverting
BackupImpl::copyFileToDisk still does, on all three restored arms. Only an
empty aggregate state can occupy zero bytes at index 0 while rows exist, and
that is the construct being removed, so the new test 05212 rebuilds the
predicate's branches from a private clickhouse-local path instead, in the
form 05099 already uses. Both directions were measured rather than argued.

05212_backup_log_zero_byte_first_data_file truncates a data file and records
it as empty in sizes.json, which is what the predicate reads, and covers its
branches separately. A Log table whose first data file records no bytes
while a later one still does needs the loop over the recorded sizes to keep
it. A Log table where no data file records bytes at all, while __marks.mrk
still records 100 rows, needs the marks fallback. A TinyLog table in that
first shape keeps no marks for anything to fall back on, so the loop is the
only thing that can keep it, which is the mirrored case the countResample
column used to reach at index 0 directly. Restoring both
src/Storages/StorageLog files to 98afba8~1 reddens all three arms and
leaves 05211 green. Its tables describe rows in files that do not hold them,
so every statement runs in clickhouse-local against a private path and
nothing is fabricated under a shared server.

ClickHouse#119728 carries the same rewrite, so once this merges it can take master's
version of these two files.

The zero-byte data file is the subject of the test but is invisible to any
query, so s.bin's size is asserted from data_paths[1] on the source and on
the restored table.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 7 findings over four rounds, all
adjudicated; the final round returned zero findings).

# Sev Finding Verdict Evidence / action
1 ❌ The rewrite leaves StorageLog::hasNothingToBackUp without regression coverage: reverting that half of the merged fix keeps the test green AGREE, fixed Conceded and measured. My first-round verdict on it was wrong: I declined the remedy because it needs on-disk fabrication, but 05099_log_array_missing_elements.sh truncates a Log data file and rewrites sizes.json inside a private clickhouse-local path (git blame -> ea5cf4d7ebc4f, 2026-08-20), and 05180_memory_table_backup_cwd_tmp_sizes_json.sh shows BACKUP works from clickhouse-local against a File destination. Once the aggregate carrier is gone the condition is no longer SQL-constructible (Array and Map put a populated sizes stream first, Nullable a populated null map, String a length varint per row, LowCardinality both streams, FixedString(0) is rejected at type creation), so 05212_backup_log_zero_byte_first_data_file rebuilds it by fabrication instead
2 ❌ Neither of the first two arms isolates the loop over the recorded data-file sizes: both are ENGINE = Log, so the marks fallback keeps them either way AGREE, fixed Right, and it names the arm the rewrite dropped. use_marks_file is engine_name == "Log", so a TinyLog table has nothing to fall back on and only the loop can keep its data; a third arm covers that. Under a mutation that narrows the size check to the first data file and leaves the marks fallback intact, that arm is the only thing in the tree that reds. Restoring both StorageLog files to 98afba8773cc~1 reds all three arms on their oracle lines and leaves 05211 green
3 ⚠️ The test never checks that s.bin is present with size zero, so it can pass without exercising the zero-size restore branch AGREE, fixed The subject of the test is physical and none of its assertions were: row counts and array lengths cannot see a file size. The fixture now reads data_paths[1] and asserts s.bin's exact byte count on the source table and on the restored one, in the idiom 02047_log_family_data_file_sizes.sh already uses. A negative control extracts the shipped helper out of the test file and runs it against a one-element array column, which prints 50 bytes against the all-empty column's 0, so the assertion tracks reality in both directions
4 ⚠️ The fabrication helper's comment reversed FileChecker::repair() AGREE, fixed repair() never re-derives a record from disk: it forces every file to its recorded size, throwing UNEXPECTED_END_OF_FILE when the file is shorter and truncating it when it is longer. The comment now says that, which is also why the truncation and the recorded size have to change together
5 ⚠️ "Neither state is reachable through SQL" is false on master today, by the very carrier this PR removes AGREE, fixed Addressed to the one reader guaranteed to hold the counterexample. The file header and the commit message now name the empty aggregate state as the SQL-reachable carrier and say it is the construct being removed
6 💡 The changelog entry described the leftover table's reads as aborting the server AGREE, fixed Build-dependent: Exception::handleErrorCode aborts on LOGICAL_ERROR only in debug and sanitizer builds or when abort_on_logical_error is set, so a release build raises a catchable exception. The entry now names the error instead of its effect
7 💡 The marks arm hardcoded the physical backup layout AGREE, fixed Replaced by a manifest lookup that accepts any directory prefix, so moving the layout no longer reads as a dropped backup. It still discriminates: that line goes 1 -> 0 under the revert

Also noted, not blocking: the restore target sum(k) before line would assert its precondition better
as count(); the TinyLog arm asserts manifest membership where the first arm asserts a
restore-and-read; table_dir's guard string says "Log table" on a path that holds a TinyLog one.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by a fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-10:20260914-173037

@clickhouse-gh clickhouse-gh Bot closed this Sep 14, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d6bdabc]

Summary: ✅


AI Review

Summary

This PR rewrites 05211_backup_log_zero_byte_data_file so it no longer leaves behind an unreadable fixture, and moves the lost StorageLog::hasNothingToBackUp coverage into 05212_backup_log_zero_byte_first_data_file using isolated clickhouse-local fabrication. I checked the current head against the underlying StorageLog/backup logic, read the prior discussion, and the added db_d arm closes the earlier TinyLog/no-marks gap; with CI green, I do not see any remaining correctness or coverage issues in the patch.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 14, 2026
@groeneai
groeneai requested a review from pamarcos September 14, 2026 18:03
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 14, 2026
…rst_data_file

All three arms ended at one of StorageLog::hasNothingToBackUp's "keep the data"
outcomes: two are kept by a data file that records bytes, one by its marks. None
reached the outcome where a table has nothing to preserve because no data file
records bytes and the engine keeps no marks, so a change that started backing up
such a table passed the file.

Add that arm, as the second arm's fabrication on TinyLog: the engine is the only
difference between the two, which is what makes the marks visibly the whole
reason one table keeps its data and the other does not. Measured with the size
check narrowed to require marks, the new arm is the only line in either test
that reddens, and 05211 stays green. Dropping just the !use_marks_file disjunct
changes nothing anywhere: loadMarks returns before loading anything when the
engine keeps no marks, so marks.empty() already covers that case.

The arm reads the backup manifest for the same file name twice, once while it
still records bytes, so a zero cannot come from a name that never matches.

Co-Authored-By: Claude Opus 5 <[email protected]>
@PedroTadim

Copy link
Copy Markdown
Member

@groeneai is this fixing a CI failure?

@groeneai

Copy link
Copy Markdown
Collaborator Author

Yes. It stops the Invalid number of columns in chunk pushed to OutputPort. Expected 2, found 1 failure that has been hitting master and unrelated pull requests since 2026-09-13 20:20Z, on a countResample(10, 5, 1) state header: 40 occurrences in the last 7 days over 11 check flavours (39 of them Stress test), 36 distinct pull requests and three runs of master itself (73c372c6e5de, 7f4f875596fb, 360a086963ab), against nothing in the preceding 90 days. The most recent hit is today at 06:12Z.

The carrier is 05211_backup_log_zero_byte_data_file, added in 98afba8773cc. It leaves behind a Log table whose aggregate state column serializes to zero bytes, so the column reads back as zero rows while the marks file records 100, and the next reader of that table aborts. 05211 itself reports OK, which is why the failure surfaces under whatever test ran next.

This PR only removes that carrier, so that master goes quiet while the server-side fix is still in review; the split was asked for in #119858 (comment). The actual defect stays with #119728 and issue #119727.

@PedroTadim

Copy link
Copy Markdown
Member

We should go with #119728 instead

@PedroTadim PedroTadim closed this Sep 17, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Understood, and I will not reopen this one.

On the master noise: #119728 already carries the same 05211 fixture rewrite (faf29df2f9fd), so that route does stop it. Its head 381822043 is green (0 failed checks) and merge-clean, but it still shows changes-requested from the 2026-09-13 18:34Z review, which predates the redesign I pushed in 880ef882: the parameterisation is now rejected at creation and all three chassert(!serialized.empty()) sites are byte-identical to master again. A re-review is all it is waiting on.

Two things live only here, both added after the split and both wanted per #119858 (comment): the on-disk s.bin size assertion in 05211, and the new 05212_backup_log_zero_byte_first_data_file covering the TinyLog first-data-file case. I can fold those two into #119728 if you want them there; otherwise I leave that PR untouched.

The signature is still firing meanwhile: 77 rows in the last 7 days over 65 pull requests, 9 of them true-master, most recently 2026-09-17 12:24:48Z on master itself (Stress test (amd_tsan), fda9f2fe). I will link #119728 as the fixing PR when it shows up on other pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-backup Backup/restore infrastructure and backup formats. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants