Repository navigation
Cherry pick #107040 to 26.5: Fix crash moving an empty part to a plain_rewritable disk - #110793
Merged
Merged
Conversation
ALTER TABLE ... MOVE PARTITION ... TO DISK 'plain_rewritable_disk' aborted the
server when the moved part was empty (0 rows, e.g. an empty part kept by
remove_empty_parts = 0 after DROP PARTITION).
An empty part contains 0-byte files. A local-metadata disk
(supportsEmptyFilesWithoutBlobs() == true) stores such a file with zero stored
objects, so DiskObjectStorageTransaction::copyFileImpl builds an empty
blobs_to_create vector and calls createMetadataFile(path, {}). The
plain_rewritable implementation of createMetadataFile took objects.front()
unconditionally, which aborts on an empty vector (libc++ hardening:
"front() called on an empty vector").
The createMetadataFile(path, objects) contract allows an empty objects list:
the local metadata storage creates an empty file and the non-rewritable plain
storage is a no-op. plain_rewritable was the only implementation that crashed.
Fix: when objects is empty, record a 0-byte file. The write operation only uses
StoredObject::bytes_size, so a size-0 object is sufficient and matches how the
source 0-byte file is represented.
This regressed in 25.12 when the plain_rewritable metadata storage was split
from the unified plain implementation (the front() call has been unconditional
since then).
Closes #106960
Co-Authored-By: Claude Opus 4.8 <[email protected]>
The previous fix recorded a 0-byte file for plain_rewritable only in the in-memory directory tree (fs_tree->recordFile), without writing a backing object. plain_rewritable returns supportsEmptyFilesWithoutBlobs() == false and rebuilds its metadata from the object listing, so: - after a metadata reload (SYSTEM DROP DISK METADATA CACHE / restart) the empty file's entry disappears, because load() lists actual objects under the directory and the 0-byte object was never written; - a later MOVE/copy from this disk gets a synthesized object key from getStorageObjectsIfExist() and copyObjectToAnotherObjectStorage() fails trying to read an object that does not exist. Fix: when createMetadataFile() is called with an empty objects list (a 0-byte file with no copied blob, which only happens when moving an empty part onto plain_rewritable), generate the destination object key and materialize a real 0-byte object there. This matches the normal write path, which always writes a blob for empty files on plain_rewritable (create_blob_if_empty == true), and keeps the file consistent across reload and subsequent copy/move. The regression test is extended to move the empty part to plain_rewritable, reload the disk metadata cache, and move the part back, so it cannot pass with only transient in-memory metadata. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The test uses SYSTEM DROP DISK METADATA CACHE, which affects server-wide disk metadata cache state, so the style checker requires the no-parallel tag (ci/jobs/scripts/check_style/various_checks.sh). Co-Authored-By: Claude Opus 4.8 <[email protected]>
The previous fixup materialized a real 0-byte object for a blobless empty file on plain_rewritable, but set the cleanup flag (object_written) only after writeObject(...)->finalize() returned. If the remote write created the object and a later step in the same transaction threw, the rollback called undo() with the flag still false, so the generated object was left behind. Because plain_rewritable rebuilds its metadata from the object listing, the next load()/dropCache() would list that orphan and make a file visible even though the metadata transaction never committed. Mark the write as attempted before issuing the remote write (renaming the flag to object_write_attempted) so undo() removes the generated object on any failure once the write begins. removeObjectIfExists keeps undo safe when the object was never actually created. The normal non-empty copy path is unaffected: its blob is written by copyObjectToAnotherObjectStorage before createMetadataFile, so create_empty_object stays false there. Add a deterministic regression test (gtest EmptyFileObjectWriteUndo) that injects a fault right after the empty file object is materialized via the new plain_object_storage_write_fail_after_empty_file_object failpoint, and asserts no orphan object survives the rolled-back transaction nor a reload from the object listing. The test fails without this change. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ty-part-plain-rewritable
Relocate the fix for copying an empty file to a plain_rewritable disk from
the metadata storage layer into DiskObjectStorageTransaction::copyFileImpl,
as requested in review.
plain_rewritable correctly advertises supportsEmptyFilesWithoutBlobs() == false,
so the metadata layer is not where the bug belongs. The real defect is that
copyFileImpl issued createMetadataFile(to, {}) for an empty source file without
checking the destination metadata storage's feature flag, hitting front() on an
empty StoredObjects vector. Now, when there are no blobs to copy and the
destination does not support blobless empty files, copyFileImpl materializes a
real 0-byte object through the regular write path (mirrors createFile()).
This reverts the earlier metadata-storage changes (createMetadataFile empty
branch, the create_empty_object/object_write_attempted plumbing, the
plain_object_storage_write_fail_after_empty_file_object failpoint) and removes
the SQL test in favor of a minimal unit test.
The write path uses shared_from_this(), which exposed a latent bug:
MultipleDisksObjectStorageTransaction inherited enable_shared_from_this twice
(once via DiskObjectStorageTransaction, once directly), so shared_from_this()
threw bad_weak_ptr on the cross-disk move path. Removed the redundant base.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
All src/gtest*.cpp files link into the single unit_tests_dbms process. Both DiskObjectStorageTest::SetUpTestSuite and MetadataPlainRewritableDiskTest::SetUp call getIOThreadPool().initialize(), and StaticThreadPool::initialize throws LOGICAL_ERROR if the pool is already initialized, so whichever suite runs second aborts. Switch both to initializeWithDefaultSettingsIfNotInitialized() (guarded by std::call_once) so the pool is initialized exactly once regardless of suite order. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The empty-source branch went through writeFile with getWriteSettings(), which reads the current query/global context rather than the per-call WriteSettings passed into copyFile. That bypasses backup/restore throttlers, cache settings, and the object_storage_write_if_none_match / object_storage_write_if_match conditional writes that still govern whether the 0-byte destination object may be created or overwritten. Thread the caller's write_settings through, mirroring the non-empty path that uses them via copyObjectToAnotherObjectStorage; writeFile applies the IO scheduling enrichment. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…lain-rewritable Fix crash moving an empty part to a plain_rewritable disk
This branch was successfully deployed
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 #107040
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