Skip to content

Fix write with append with plain_rewritable/plain metadata types - #83695

Merged
azat merged 1 commit into
ClickHouse:masterfrom
tuanpach:disallow-write-file-with-append-for-plain-object-storage-transaction
Jul 28, 2025
Merged

azat merged 1 commit into
ClickHouse:masterfrom
tuanpach:disallow-write-file-with-append-for-plain-object-storage-transaction

Conversation

@tuanpach

@tuanpach tuanpach commented Jul 14, 2025 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix write with append (in MergeTree used for experimental transactions) with plain_rewritable/plain metadata types, previously they were simply ignored

  1. Remove noop addBlobToMetadata in MetadataStorageFromPlainObjectStorageTransaction
  2. Add supportAddingBlobToMetadata to MetadataStorageFromDiskTransaction indicating if addBlobToMetadata is supported
  3. Handle DiskObjectStorageTransaction::writeFile and CopyFileObjectStorageOperation with supportAddingBlobToMetadata

Internal explanation:

  • In MetadataStorageFromDisk, we store mapping: local_path -> DiskObjectStorageMetadata
    In DiskObjectStorageMetadata, it has a list of blobs stored in ObjectKeysWithMetadata keys_with_meta;
    It is a 1-to-n mapping from a local_path to multiple blobs. Each object_key in keys_with_meta points to the blob stored in the object storage.
    When writing with append, it simply adds a new blob to keys_with_meta in DiskObjectStorageMetadata. The buffer will point to the newly created object in the object storage.

  • In MetadataStorageFromPlainObjectStorage, things are different.
    It uses object_storage->generateObjectKeyForPath to generate the remote_path from the local_path. In other words, it is a 1-to-1 mapping from local_path to remote_path.

  • In MetadataStorageFromPlainRewritableObjectStorage, it inherits from MetadataStorageFromPlainObjectStorage, which has std::shared_ptr<InMemoryDirectoryPathMap> path_map.
    In the object storage, we store in _meta a mapping from remote_directory_path to local_directory_path.
    Under remote_directory_path, there are files which belong to local_directory_path.
    The directory paths and files are loaded into path_map during initialization or refresh.
    It is also a 1-to-1 mapping

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c2c96e2]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan, distributed plan, sequential) failure
00002_log_and_exception_messages_formatting FAIL
Stateless tests (amd_binary, old analyzer, s3 storage, DatabaseReplicated, parallel) failure
03300_merge_parts_metric FAIL
Integration tests (release, 4/6) failure
test_backup_restore_on_cluster/test.py::test_shutdown_waits_for_backup FAIL

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 14, 2025
@tuanpach
tuanpach requested a review from jkartseva July 14, 2025 08:46
@tuanpach tuanpach added the can be tested Allows running workflows for external contributors label Jul 14, 2025
@tuanpach
tuanpach force-pushed the disallow-write-file-with-append-for-plain-object-storage-transaction branch 3 times, most recently from dffb0ef to d3182c3 Compare July 14, 2025 10:33
@jkartseva jkartseva self-assigned this Jul 15, 2025
@tuanpach
tuanpach force-pushed the disallow-write-file-with-append-for-plain-object-storage-transaction branch from d3182c3 to ce6dab9 Compare July 23, 2025 06:54
@tuanpach
tuanpach force-pushed the disallow-write-file-with-append-for-plain-object-storage-transaction branch from a7565e5 to 66d4888 Compare July 24, 2025 05:47
@tuanpach
tuanpach requested review from azat and jkartseva July 24, 2025 08:45

@jkartseva jkartseva left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@jkartseva

Copy link
Copy Markdown
Member

PTAL at the test in private.

@tuanpach
tuanpach force-pushed the disallow-write-file-with-append-for-plain-object-storage-transaction branch from 66d4888 to f2d45da Compare July 25, 2025 08:01
@tuanpach

Copy link
Copy Markdown
Member Author

@azat azat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though note, that this is still not enough to fix transactions for MergeTree on plain_rewriteable (since there the exception will be thrown from noexcept scope and will lead to std::terminate), but I will rebase #84084 on top of this PR once it will be merged

Also can you please adjust the PR title and description to something more user-friendly? Since right now it is pretty internal.

@tuanpach
tuanpach force-pushed the disallow-write-file-with-append-for-plain-object-storage-transaction branch from f2d45da to d63ea7a Compare July 28, 2025 02:09
…rageTransaction

2) Add supportAddingBlobToMetadata to MetadataStorageFromDiskTransaction indicating if addBlobToMetadata is supported
3) Handle DiskObjectStorageTransaction::writeFile and  CopyFileObjectStorageOperation with supportAddingBlobToMetadata
@tuanpach
tuanpach force-pushed the disallow-write-file-with-append-for-plain-object-storage-transaction branch from d63ea7a to c2c96e2 Compare July 28, 2025 06:00
@tuanpach

Copy link
Copy Markdown
Member Author

LGTM, though note, that this is still not enough to fix transactions for MergeTree on plain_rewriteable (since there the exception will be thrown from noexcept scope and will lead to std::terminate), but I will rebase #84084 on top of this PR once it will be merged

Also can you please adjust the PR title and description to something more user-friendly? Since right now it is pretty internal.

I updated the title and description.

@tuanpach tuanpach changed the title Disallow DiskObjectStorageTransaction::writeFile with WriteMode::Append if metadata transaction is MetadataStorageFromPlainObjectStorageTransaction Fix logic related to adding blob to metadata: DiskObjectStorageTransaction::writeFile and CopyFileObjectStorageOperation Jul 28, 2025
@azat azat changed the title Fix logic related to adding blob to metadata: DiskObjectStorageTransaction::writeFile and CopyFileObjectStorageOperation Fix logic related to writing files with append with plain_rewritable/plain metadata types Jul 28, 2025
@azat

azat commented Jul 28, 2025 •

Copy link
Copy Markdown
Member

I updated the title and description.

I've adjusted it one more time to avoid using internal class names (since this is the bug fix and it will be visible in changelog and users may struggle to understand what this mean), hope you are OK with it

file_name_non_existing_target="file_non_existing_target_03578_$(random_str 10).txt"

printf "%s" "abc" | clickhouse-disks -C "$config" --disk "$disk_name" --save-logs --query "write $file_name_src"
printf "%s" "123" | clickhouse-disks -C "$config" --disk "$disk_name" --save-logs --query "write --mode append $file_name_src" 2>/dev/null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(minor) I would prefer to print exception message in this case, but we can improve it later.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that we need to make sure that it fails, not simply ignored, for instance this test likely will pass with previous implementation, since the add to blob was simply noop

Hm, also, are you sure that this will use copy? It looks like a plain write to me...

@tuanpach tuanpach Jul 28, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I will update it in another PR to use copy.

Oh, I want to append it so that it will create multiple blobs if the disk metadata is local.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will tidy up the tests in a separate PR.

@azat
azat enabled auto-merge July 28, 2025 11:43
@azat azat changed the title Fix logic related to writing files with append with plain_rewritable/plain metadata types Fix write with append with plain_rewritable/plain metadata types Jul 28, 2025
@azat
azat added this pull request to the merge queue Jul 28, 2025
@azat

azat commented Jul 28, 2025

Copy link
Copy Markdown
Member

@tuanpach I will merge it, since I want to rebase #84084 on top

Merged via the queue into ClickHouse:master with commit 6954573 Jul 28, 2025
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 28, 2025
@tuanpach

Copy link
Copy Markdown
Member Author

I updated the title and description.

I've adjusted it one more time to avoid using internal class names (since this is the bug fix and it will be visible in changelog and users may struggle to understand what this mean), hope you are OK with it

Got it. Thanks for helping.

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 pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants