Repository navigation
Cherry pick #112839 to 26.5: Fix segfault and silent data corruption when appending a non-appendable format to a file - #112924
Merged
Conversation
…geFileSink A format that registers markFormatHasNoAppendSupport cannot be appended to, and StorageFile::write enforces that. The check lives inside if (!paths.empty()), so two routes into StorageFileSink never reach it: a write through a file descriptor never populates paths, and a partitioned write returns its sink before the check. Both then let StorageFileSink::initialize suppress the format prefix for a target that already has bytes. With rows that appends a second Avro header after the existing data, so the query succeeds with no diagnostic and the resulting file no longer reads back. With zero rows nothing calls DataFileWriterBase::syncIfNeeded, which is the only thing that binds the encoder to a stream; DataFileWriterBase::sync then flushes the encoder as its first statement and binds the stream one line later, so StreamWriter::out_ is still the default nullptr and the server dies with SIGSEGV. The second one is the failure reported on #111164. Ask the format's own append-support checker in StorageFileSink::initialize, where the authoritative per-sink size is computed and one statement before the prefix is suppressed. That covers both symptoms and both uncovered routes, and it also closes the window between the query-start stat in StorageFile::write and the per-sink fstat. Adding syncIfNeeded to AvroRowOutputFormat::finalizeImpl was tried first and rejected on measurement: it stops the fault but still writes an unreadable file, so it trades a loud failure for silent corruption. On these two routes an INSERT into a non-empty file now fails for Arrow, ArrowStream, JSON, Npy, ORC and Parquet where it previously returned success. Measuring all thirteen always-non-appendable formats there shows none of them ever appended: five read back only the original row and silently discard the appended one, Parquet fails a column read, and the rest already errored. The File engine documentation is qualified accordingly in the same commit.
…ed checker Review round 1 on the StorageFileSink no-append guard. The documentation sentence added with the guard advised the `engine_file_truncate_on_insert` and `engine_file_allow_create_multiple_files` settings unconditionally, but neither setting applies on the file-descriptor route: `StorageFileSink::initialize` builds a `WriteBufferFromFileDescriptor` without consulting `flags`, and the multiple-files branch rewrites `paths`, which is empty there. The guard's own error message already omits that advice for this reason, so the two artifacts contradicted each other about the behaviour this change introduces. The sentence is now scoped to a plain file path and states why the descriptor route is different. The settings-dependent-checker test cell only drove the checker's appendable branch, where a guard keyed on a hardcoded format list and no guard at all both succeed, so the cell could not distinguish them; removing the guard left it green. It now also asserts the non-appendable configuration is rejected, which fails under both bypasses and proves the per-statement setting reaches the checker through `getFormatSettings`. The test number moved from 04660 to 04668: 04660 was free on master when the test was written but is now claimed by other unpublished work and by an open pull request. Co-Authored-By: Claude Fable 5 <[email protected]>
Fix segfault and silent data corruption when appending a non-appendable format to a file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #112839
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job