Repository navigation
Reject an array whose elements were not read outside the MergeTree readers - #115528
Conversation
…aders
`SerializationArray::deserializeBinaryBulkWithMultipleStreams` accepted an empty
elements column with a non-zero last offset for the sizes encoding. The resulting
`ColumnArray` reports rows whose elements are not there, so every consumer indexes
the elements column out of bounds - `ColumnArray::sizeAt` tripped the `PODArray`
assertion while `sortBlock` permuted a `Map(Map(Enum8, Date), Int32)` column read
from a `Log` table:
Logical error: '(n >= (static_cast<ssize_t>(pad_left_) ? -1 : 0)) && (n <= static_cast<ssize_t>(this->size()))'
DB::ColumnArray::sizeAt(long) const
DB::ColumnArray::indexImpl<unsigned long>(...) const
DB::ColumnMap::index(DB::IColumn const&, unsigned long) const
DB::ColumnTuple::index(DB::IColumn const&, unsigned long) const
DB::ColumnArray::indexImpl<unsigned long>(...) const
DB::ColumnMap::permute(...) const
DB::sortBlock(...)
That state is legitimate in one place only: a column of a `Nested` type that was
added by `ALTER` reads from the parts written before that `ALTER` with its shared
sizes stream present and its elements stream missing. The MergeTree readers mark
such a column in `partially_read_columns`, throw it away and fill it with defaults
in `IMergeTreeReader::fillMissingColumns`, so nothing else ever sees it. Everyone
else - `Log`, `TinyLog` - hands the column straight to the query pipeline.
Deserialization now rejects it with `INCORRECT_DATA` unless the caller sets the new
`partially_read_columns_are_refilled` flag, which the two MergeTree readers do. The
`Log` engine reported plausible garbage before the fix (a `Map` read back as
`{'':0,'':0}`) and now names the column and the path it could not read.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8d087c3c23fb6c25532270957bdb5eddb1947872&name_0=MasterCI&name_1=BuzzHouse%20%28arm_asan_ubsan%29
Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [21b3e47] Summary: ✅
AI ReviewSummaryThis PR tightens Final Verdict✅ No new findings. LLVM Coverage ReportMeasured on commit 21b3e47.
Changed lines: Changed C/C++ lines covered: 20/20 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units3044 translation units recompiled, 15811 s compile time in total, 3044 of them have a recent master baseline. |
tiandiwonder
left a comment
There was a problem hiding this comment.
Shorten the comments.
`MergeTreeReaderWide` and `MergeTreeReaderCompact` set `partially_read_columns_are_refilled` for every column they read, while `IMergeTreeReader::fillMissingColumns` only replaces the columns recorded in `partially_read_columns`. A column whose elements file is present but holds no data is not recorded there, so its `ColumnArray` with offsets past the end of its elements still reached the query pipeline. Each reader now sets the flag only for the columns it will actually refill. The gtest for the accepted case is replaced by `05024_mergetree_array_missing_elements`, which drives the real MergeTree readers: a `Nested` column added by `ALTER` still reads as defaults from the older parts, while an emptied elements file is now reported as `INCORRECT_DATA`. Keeping it as a unit test also broke `Bugfix validation (unit tests)`, whose before-binary is compiled with the fix reverted and therefore without the new flag. Add the `log-engine` tag to `05023_log_array_missing_elements`, which otherwise breaks under `--replace-log-memory-with-mergetree`, and trim the comments that repeated the flag's declaration.
…ments-outside-mergetree
…ments-outside-mergetree
…es are missing Both tests located the files to corrupt with an unguarded `find | head -n 1`: when `find` matched nothing, `dirname ''` collapsed to `.` and the tests passed vacuously without corrupting anything, which is how `05024_mergetree_array_missing_elements` failed on `Fast test (arm_darwin)` - the part has no `a.bin` there for a reason not yet known. `05024` now asks `system.parts` for the active part path instead of searching, and exits with a listing of the parts and files when `a.bin` is not where it must be, so the next darwin run shows the actual part layout. `05023` requires exactly the three element files of the `Log` table and the `sizes.json` next to them. #115528
…e test, to satisfy the style check
…ments-outside-mergetree
…ments-outside-mergetree
…tive filesystem
`Fast test (arm_darwin)` failed on this test because on a case-insensitive
filesystem every stream file of a MergeTree part is stored under the hash of
its name (`replaceFileNameToHashIfNeeded`), so there is no `a.bin` to
truncate - the diagnostics added earlier showed the part holding
`1fa2c35cbbcd93388960cb3c765e3171.bin`, which is
`lower(hex(reverse(sipHash128('a'))))`. The test now resolves the elements
file by trying both the plain and the hashed name, and still exits with an
error listing the part layout when neither is there.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115528&sha=46bd9a99cf4bfdd9a62211d2dda98a20a919f501&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29
Co-Authored-By: Claude Fable 5 <[email protected]>
tiandiwonder
left a comment
There was a problem hiding this comment.
Approving. All six findings from rounds 1-3 are closed, and this round closed the last open question too.
The arm_darwin failure turned out not to be the fix at all — it was the test looking for a.bin where MergeTree stores every stream under sipHash128 of its name on a case-insensitive filesystem, independently of replace_long_file_name_to_hash. I checked the new formula against real on-disk names rather than reading it: forcing the same layout with replace_long_file_name_to_hash = 1, max_file_name_length = 0 gives 1fa2c35cbbcd93388960cb3c765e3171.bin, exactly what lower(hex(reverse(sipHash128('a')))) returns, and sipHash128('k') is a different one of the three files so the probe can't land on the key column. Deriving the digest from the server instead of hard-coding it is the right call — it can't rot. 05024 no longer appears in the arm_darwin failures.
Two jobs are still red and neither is this PR: Fast test (arm_darwin) fails only on 01599_multiline_input_and_singleline_comments (an expect test killed at 60 s with Operation not permitted while sending SIGKILL — macOS runner permissions), and Stateless tests (arm_binary, parallel) only on 05047_distributed_plan_finished_stages_drain with NO_SUCH_DATA_PART on a distributed read. Neither 05023 nor 05024 fails anywhere on this head.
I've replied on @clickhouse-gh's compact-coverage thread — short version, the existing compact arm already pins that reader, and the test it asks for isn't constructible. Resolving my own threads; this approval also supersedes my stale CHANGES_REQUESTED from Aug 20, whose findings are all resolved.
…ments-outside-mergetree
`MergeTreeReaderCompact::readData` gained the same `partially_read_columns.contains(name)` gate as the wide reader, while `05024_mergetree_array_missing_elements` only corrupted a wide part, so a regression in the compact reader would have kept the test green. Every column of a compact part lives in `data.bin`, and the sizes and the elements of an array share one compressed block unless their codecs differ, so the corrupted table gives its elements a codec of their own (`Delta`). Cutting `data.bin` at the mark of the elements substream - read from `mergeTreeIndex(..., with_marks = 1)` - then leaves the sizes of `a` in place and takes its elements away, and reading the column reports `INCORRECT_DATA`.
…ompact part is missing If `mergeTreeIndex` returns no mark for the elements substream of `a`, `truncate -s ""` only writes to stderr and the compact arm of the test reports a bare `0`. Print the marks and exit instead, as the wide arm already does when it cannot find the elements file.
…ments-outside-mergetree
|
🕵 @groeneai, investigate the failures on this head — none of them touch this PR (it only changes
I have merged |
|
Investigated all three on
Three open PRs, any one of which clears both rows:
None is merged, so
That descriptor has no fixing PR yet: a fix task owns it and I will post the link here when it opens. Since it may recur on the fresh head, the rate: 33 rows in 30 days, at most 2 on any day before 09-03 and 4 to 7 per day since, almost all |
…ments-outside-mergetree
|
🕵 Thank you for the analysis — the failpoint-leak cascade explains both rows, and it matches what the head shows. On the overlap: let's land #118417 as the fix for this red. It is two files, and it removes both halves at once — the rethrow ordering in #118390 should not land the same 439-to-1000 substitution a second time. Please reduce it to the part #118417 does not touch — the exchange-source reporting path itself ( #105942 is the one I want independently of the above: resetting enabled failpoints after each no-parallel test fixes the class, not this instance, and the nine other files that can leak a On This branch has now been merged with |
|
Agreed on landing #118417 as the fix for this red. On reducing #118390: there is no overlapping code to remove. #118417 is So the question is not what to strip, but whether that reporting path still changes anything once your ordering is in. By the reasoning in your #105942: nothing from me, and I will not touch it.
|
…ments-outside-mergetree
|
🕵 Merged On the two reds of
No unresolved review threads; the AI Review reports no remaining inline findings, and the description and changelog entry still match the diff exactly ( |
|
🕵 Status on The sync status reads
Neither path touches this diff: the PR only changes Everything else is settled on this head: all public checks green, 0 unresolved review threads, AI Review |
|
@alexey-milovidov @tiandiwonder — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
Reading a
Logtable whose array sizes stream is there while its array elements stream is not returned aColumnArraythat reports rows whose elements are not present. Every consumer then indexes the elements column out of bounds. On theBuzzHouse (arm_asan_ubsan)master run below,SELECT * FROM d0.t37 LIMIT 100over aMap(Map(Enum8, Date), Int32)column tripped thePODArrayassertion inColumnArray::sizeAtwhilesortBlockwas permuting that column; in a release build the same read silently returns garbage (theMapreads back as{'':0,'':0}).SerializationArray::deserializeBinaryBulkWithMultipleStreamsallowed that state for the sizes encoding. It is legitimate in one place only: a column of aNestedtype that was added byALTERreads from the parts written before thatALTERwith its shared sizes stream present and its elements stream missing. The MergeTree readers record such a column inpartially_read_columns, discard it and fill it with defaults inIMergeTreeReader::fillMissingColumns, so nothing downstream ever sees it.LogandTinyLoghave no such step and hand the column straight to the query pipeline.Deserialization now rejects an empty elements column with a non-zero last offset with
INCORRECT_DATA, naming the column and the path, unless the caller sets the newpartially_read_columns_are_refilledflag - which onlyMergeTreeReaderWideandMergeTreeReaderCompactdo.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8d087c3c23fb6c25532270957bdb5eddb1947872&name_0=MasterCI&name_1=BuzzHouse%20%28arm_asan_ubsan%29
Related: #109212
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix reading a
LogorTinyLogtable whose array or map elements are missing while their sizes are present: such a table returned rows with elements that are not there and made the server read out of bounds. It is now reported asINCORRECT_DATA.Workflow [PR]
Sync PR [sync-upstream/pr/115528]