Skip to content

Fix MergeTree transactions on disks with plain_rewritable metadata by avoiding append mode - #84084

Closed
azat wants to merge 4 commits into
ClickHouse:masterfrom
azat:txn-no-append
Closed

azat wants to merge 4 commits into
ClickHouse:masterfrom
azat:txn-no-append

Conversation

@azat

@azat azat commented Jul 20, 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 MergeTree transactions on disks with plain_rewritable metadata by avoiding append mode

Fixes: #50666
Fixes: #83988

@azat
azat requested review from jkartseva and tavplubix July 20, 2025 20:51
@clickhouse-gh

clickhouse-gh Bot commented Jul 20, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [26de9b4]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan, distributed plan, parallel, 1/2) failure
02421_truncate_isolation_no_merges FAIL
Stateless tests (amd_binary, ParallelReplicas, s3 storage, parallel) failure
03207_json_read_subcolumns_2_memory FAIL
Exception in test runner FAIL
Killed by signal (in clickhouse-server.log or clickhouse-server.err.log) FAIL
Fatal messages (in clickhouse-server.log or clickhouse-server.err.log) FAIL
Stateless tests (amd_tsan, s3 storage, parallel) failure
02443_detach_attach_partition FAIL
Stress test (amd_tsan) failure
Server died FAIL
Hung check failed, possible deadlock found (see hung_check.log) FAIL
Sanitizer assert (in stderr.log) FAIL
Fatal message in clickhouse-server.log (see fatal_messages.txt) FAIL
Found signal in gdb.log FAIL

@azat azat Jul 20, 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.

This ignores the WriteMode::Append writes, which sounds very bad, since it is used in a few places in MergeTree code (at least), for example for txn_version.txt

Refs: 91cf0ff

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jul 20, 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.

Here to avoid introducing extra complexity for experimental feature the append writes had been replaced with rewriting file from scratch via rename

Refs: a27e4fc

@tuanpach

Copy link
Copy Markdown
Member
  • I created a PR #83695 that disallowed DiskObjectStorageTransaction::writeFile with WriteMode::Append if metadata transaction is MetadataStorageFromPlainObjectStorageTransaction.
  • There is another PR #83349 which will rewrite the whole txn metadata file if append CSN is not supported. Sasha suggested that we can just disable transactions for tables using disks which do not support Append.

I think we try to solve the same problem. Please take a look.

@azat

azat commented Jul 23, 2025

Copy link
Copy Markdown
Member Author

@tuanpach thanks for coming by!

Yes, we do solve the same problem:

@tuanpach what do you think?

@alexey-milovidov

Copy link
Copy Markdown
Member

Can we always avoid appends?

@tuanpach

tuanpach commented Jul 25, 2025 •

Copy link
Copy Markdown
Member

There is one case when the transaction is rolled back:

part->appendRemovalTIDToVersionMetadata(/* clear */ true);
part->version.unlockRemovalTID(tid, TransactionInfoContext{part->storage.getStorageID(), part->name});

When calling part->appendRemovalTIDToVersionMetadata(/* clear */ true);, in the current logic, it will append Tx::EmptyTID into the metadata file.

void VersionMetadata::writeRemovalTID(WriteBuffer & buf, bool clear) const
{
writeCString("\n" REMOVAL_TID_STR, buf);
if (clear)
TransactionID::write(Tx::EmptyTID, buf);
else
TransactionID::write(removal_tid, buf);
}

Then, it calls part->version.unlockRemovalTID to set remove_tid to Tx::EmptyTID

However, in this PR, we call writeVersionMetadata(version, /*fsync=*/ fsync); in appendRemovalTIDToVersionMetadata, the remove_tid has not been updated to Tx::EmptyTID yet.

@tavplubix

Copy link
Copy Markdown
Member

MergeTree transactions on disks with plain_rewritable metadata

Do we need MergeTree transactions with this disk? Can we just disallow it?

azat added 4 commits August 6, 2025 15:16
Note that for i.e. remote storages it is not optimal, since it will add
one more blob, while for local disks it does make sense to write with
append and we can have a separate path for local disks, but,
transactions are experimental, let's not introduce code that will not be
tested.

Also I've tried couple of other ideas, but the interface became more
complex, and I am not sure that it worth it for experimental
functionality.

v2: fix rollback (thanks to Tuan)
@azat
azat marked this pull request as draft August 6, 2025 14:00
@azat

azat commented Aug 15, 2025

Copy link
Copy Markdown
Member Author

Do we need MergeTree transactions with this disk? Can we just disallow it?

Sure we can, but I was thinking that if it was required only in this place (actually also for deduplication log) it will be easier to remove it, but I'm ok with both approaches. Do you have strong feeling about this?

@alexey-milovidov

Copy link
Copy Markdown
Member

That's cool, removing appends is a much cleaner approach!

@tuanpach

Copy link
Copy Markdown
Member

There is a refactoring PR for VersionMetadata: #87125

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

Labels

pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed assert assertHasValidVersionMetadata() Logical error: Tasks in BackgroundSchedulePool cannot throw

5 participants