Skip to content

Add author column to system.mutations - #103395

Open
EilRoviSoft wants to merge 65 commits into
ClickHouse:masterfrom
EilRoviSoft:dev/mdb-43837
Open

EilRoviSoft wants to merge 65 commits into
ClickHouse:masterfrom
EilRoviSoft:dev/mdb-43837

Conversation

@EilRoviSoft

@EilRoviSoft EilRoviSoft commented Apr 22, 2026 •

Copy link
Copy Markdown

Adds an author column to the system.mutations table. It records the user who initiated each mutation, which is useful for auditing — for example, finding out who started a long-running or problematic mutation.

The author is taken from the user that issued the ALTER TABLE ... UPDATE/DELETE query (initial_user, falling back to current_user), and is persisted alongside the mutation entry: in the on-disk entry for MergeTree and in the ClickHouse Keeper entry for ReplicatedMergeTree.

Persisting the author is gated behind a new MergeTree setting persist_mutation_author (default false). When it is disabled, the serialized mutation entry stays byte-for-byte identical to the current format, so mixed-version clusters and downgrades are unaffected. When it is enabled, the entry is written with format version: 2 carrying the author field, so servers that do not know this format fail with an explicit UNKNOWN_FORMAT_VERSION error instead of a confusing parse failure. Reading is backward compatible — entries of both versions are parsed correctly, and the column is empty for mutations created without the setting.

For ALTER ... ON CLUSTER, the recorded author is the user executing the query on each host; the initiating user is recorded only when the distributed_ddl_use_initial_user_and_roles server setting is enabled. This is documented in the system.mutations docs.

Changelog category (leave one):

  • New Feature

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

Added an author column to the system.mutations table, showing the user who initiated each mutation. It is populated for mutations created while the new MergeTree setting persist_mutation_author is enabled (disabled by default, because persisting the author extends the mutation entry format that older servers cannot read).


Workflow [PR]
Sync PR [sync-upstream/pr/103395]

@alexey-milovidov alexey-milovidov added the close in a month if not active This will be closed in case of no information label Apr 23, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

Please edit the title and use the description template.

@alexey-milovidov

Copy link
Copy Markdown
Member

Needs a test.

@EilRoviSoft EilRoviSoft changed the title Dev/mdb 43837 Adding author field into system.mutations Apr 27, 2026
@EilRoviSoft
EilRoviSoft marked this pull request as ready for review April 27, 2026 15:45
@EilRoviSoft
EilRoviSoft requested a review from aalexfvk May 12, 2026 00:25
@alexey-milovidov alexey-milovidov changed the title Adding author field into system.mutations Add author column to system.mutations Jun 29, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aaa5f8f]

Summary: ❌

job_name test_name status info comment
Stress test (arm_asan_ubsan, s3) FAIL
UndefinedBehaviorSanitizer: undefined behavior (STID: 0993-9a84) FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL

AI Review

Summary

Adds optional mutation-author persistence and the system.mutations.author column for MergeTree and ReplicatedMergeTree. Two blockers remain: truncated transaction metadata can become a nontransactional mutation during recovery, and exceptions inside replicated settings publication can bypass rollback. Review covered local mutation loading and CSN rewriting, Keeper entry parsing and replication queues, and system-table status mapping.

Findings

❌ Blockers

  • MergeTreeMutationEntry.cpp:200: checkString consumes partial matches. A mutation file ending immediately after tid: is accepted with Tx::NonTransactionalTID and Tx::NonTransactionalCSN; EOF validation succeeds. StorageMergeTree::loadMutations then bypasses transaction-commit validation, allowing an uncommitted mutation to execute after restart. This also affects version-1 files with the new setting disabled. Reject incomplete markers, for example with checkStringByFirstCharacterAndAssertTheRest, throughout the trailer parser.
  • StorageReplicatedMergeTree.cpp:7222, also line 7292: changeSettings runs outside the rollback handlers. It publishes storage_settings before allocating/cloning metadata and starting any newly required background mover. An exception in that tail leaves persist_mutation_author enabled after a failed enabling query, so later mutations can write incompatible version-2 Keeper entries. Protect the whole settings operation or make publication exception-safe. This is the remaining failure path in the previous rollback finding.
Tests
  • ⚠️ Add a focused mutation-loader regression for a transaction marker truncated at each nonempty prefix; loading must throw rather than produce a nontransactional entry.
  • ⚠️ Cover failure inside changeSettings after settings publication, for both the pure settings and settings/comment branches. The existing failpoints run after this call returns. A compatible storage-policy change that starts background moves can exercise the existing mt_background_jobs_assignee_throw_after_task_created failpoint; verify a subsequent mutation retains the old format.
Missing context / blind spots
  • ⚠️ No ClickHouse binary is available in this review job, so the findings are established by source traces. The head CI report has a passing Fast test; the broader build/test pipeline is still pending. Focused regression results would close the runtime-verification gap.
Final Verdict

Status: ❌ Block

Reject truncated transaction markers and include settings publication in rollback protection, with focused regression coverage.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jul 9, 2026
Comment thread src/Storages/StorageMergeTree.cpp Resolved
…or` field

Both the on-disk `MergeTree` mutation file and the `ReplicatedMergeTree`
mutation znode now advertise `format version: 2` when the `author` field is
written, and the readers accept both versions, so a binary that does not know
about `author` fails with an explicit `UNKNOWN_FORMAT_VERSION` error instead
of a confusing parse error.
…USTER` caveat

For `ALTER ... ON CLUSTER` queries the recorded author is the user under which
the query was executed on each host, which is the local default user unless the
server setting `distributed_ddl_use_initial_user_and_roles` is enabled.
In a `Replicated` database an `ALTER` is executed by the DDL worker, whose
query context does not carry the initiating user (unless
`distributed_ddl_use_initial_user_and_roles` is enabled), so no author is
recorded. Tag the tests that check the recorded author with
`no-replicated-database`.

`04825_replicated_persist_mutation_author_no_mix`: a `Replicated` database
rejects mixing replicated and non-replicated `ALTER` commands earlier with
`QUERY_IS_PROHIBITED`, so accept it as well.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=103395&sha=latest&name_0=PR
PR: ClickHouse#103395

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=103395&sha=latest&name_0=PR&name_1=Integration%20tests%20(arm_binary%2C%201%2F4) (test_storage_iceberg_concurrent/test_concurrent_reads.py::test_concurrent_reads, FILE_DOESNT_EXIST for the Iceberg metadata file; it has been failing in dozens of PRs and on master since 2026-10-12) and provide a fix in a separate PR. If the fix is already in progress, link it here.

The other failures (author tests under DBReplicated) were caused by this PR and are fixed in ffe4692.

@groeneai

Copy link
Copy Markdown
Collaborator

This is fixed by #125448 (mine), merged 2026-10-13 01:47 UTC. The failed run tested ff3996e merged into master e83d574 (2026-10-12 20:58 UTC), which does not contain the fix.

It matches the #125448 mechanism. Since #120519 (2026-10-12), test_storage_delta/test_writes_interop.py shares this job, and its Spark JVM is reused by test_concurrent_reads with a stale cached s3a:// filesystem. Here both ran on xdist worker gw0, and the retry in a fresh pytest session passed.

Since the merge, master has 103 passing runs of this test and 1 failure, on 3ab409c, which predates the fix. The 7 PR failures since 05:00 UTC, this one included, all tested a master without it. The run for ffe4692 merges into 2ca8bd9, which includes the fix.

alexey-milovidov and others added 4 commits October 21, 2026 15:58
# Conflicts:
#	src/Storages/System/StorageSystemMutations.cpp
Master is now `26.11`, and the setting has not been released yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l settings or comment change

In `StorageReplicatedMergeTree::alter`, `getMutationAuthor` could throw
`TOO_LARGE_STRING_SIZE` only after a mixed `MODIFY COMMENT` / `MODIFY SETTING`
had already been committed locally, leaving the local change without the
replicated `ALTER` and its mutation. Compute the mutation commands and the
author before that commit and reuse the author when filling the entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An `UPDATE` in the same query runs as a separate `mutate` segment after
`alter`, so it does not go through the fixed path. A column type change
creates the mutation inside the replicated `ALTER` entry, which is the
case that used to leave the local comment change committed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master and pushed b110acc.

  • Resolved a conflict in StorageSystemMutations.cpp. master now fills columns through columns_mask, and author is inserted after create_time in that scheme.
  • Moved the persist_mutation_author settings-history record to 26.11, because master is now 26.11.
  • Review fix: StorageReplicatedMergeTree::alter now validates the mutation author before committing a local MODIFY SETTING / MODIFY COMMENT. A new test, 05441_replicated_mutation_author_long_user_name_keeps_comment, covers it.

@groeneai, thanks for confirming that the Iceberg failure was fixed by #125448. This merge includes that fix.

Comment thread src/Storages/StorageMergeTree.cpp Resolved
alexey-milovidov and others added 2 commits October 28, 2026 22:35
…ntil the mutation entry is created

The lock was declared in the `if` initializer and released right after the
check, so a settings `ALTER` could publish a transient
`persist_mutation_author` value in memory before `startMutation` read it.
A failed enabling `ALTER` could then leave a `format version: 2` mutation
file behind. Keep the lock through `startMutation`, as the replicated path
does, and cover the interleaving where the mutation passes the lock check
before the settings `ALTER` starts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=103395&sha=b110acc068fadfb76c1fb21c07dbb28bde1fda52&name_0=PR&name_1=Stress%20test%20%28amd_msan%29 (Logical error: Context has expired in FunctionTimeSeriesStoreTags::executeImpl, not related to this PR) and provide a fix in a separate PR. It looks like #126492 already covers it; please confirm.

@groeneai

Copy link
Copy Markdown
Collaborator

Confirmed, this is the bug #126492 fixes. The stack is WithContextImpl::getContext() <- FunctionTimeSeriesStoreTags::executeImpl (timeSeriesStoreTags.cpp:117), the exact call #126492 removes: it captures the tags collector in the constructor instead of reading it through the weakly held creation context at execution time, which can already be gone (same change for timeSeriesTagsToGroup). Its head is green and mergeable, so no separate PR is needed.

Not caused by this PR: the same abort hit the Stress tests of 12 other PRs in the last 30 days.

@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
alexey-milovidov and others added 3 commits November 5, 2026 07:42
…ring the mutation

The previous commit held the lock through all of `startMutation`, including the
in-memory registration. `05331_mutation_not_skipped_before_registration` (new on
`master`) pauses a mutation right before registration and expects a concurrent
`ALTER TABLE ... DROP COLUMN` to proceed; with the lock held it timed out with
`DEADLOCK_AVOIDED`.

Split `startMutation` into `prepareMutationEntry`, which decides the entry format
(`persist_mutation_author`) and writes `mutation_*.txt`, and `registerMutation`.
Only the preparation runs under the `ALTER` lock, so a settings `ALTER` still
cannot change the format between the check and the write, while the registration
no longer blocks `ALTER` queries, as on `master`.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=103395&sha=4b25adc960a1467eb4e56d4a8a9ba980467423c4&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20sequential%29
PR: ClickHouse#103395

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion_commands`

`master` now computes `maybe_mutation_commands` in `StorageReplicatedMergeTree::alter`
before the settings/comment change, to check for non-deterministic virtual columns.
The PR computed it at the same point for `getMutationAuthor`; keep a single definition.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

alexey-milovidov commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

🕵 Pushed 9b82da7:

  • 05331_mutation_not_skipped_before_registration, which is new on master, failed in every sequential stateless job with DEADLOCK_AVOIDED. The cause was the previous commit 4b25adc in this PR, which held the ALTER lock through all of startMutation. The test parks a mutation just before it is registered and expects a concurrent DROP COLUMN to go through. Fix (e6a124e): StorageMergeTree::mutate now holds the lock only around prepareMutationEntry, which chooses the entry format (persist_mutation_author) and writes mutation_*.txt. The lock is released before registerMutation (the former second half of startMutation). The format guarantee that 05457_mutation_holds_alter_lock_against_settings_alter checks still holds.
  • Merged master. That brings in Skip 05397_clickhouse_local_locked_path_untouched on macOS #128088, which fixes the 05397_clickhouse_local_locked_path_untouched failure on Fast test (arm_darwin). It is unrelated to this PR. Also removed a duplicate maybe_mutation_commands definition in StorageReplicatedMergeTree::alter, a semantic conflict with master.
  • @groeneai, thanks for confirming the timeSeriesStoreTags stress failure. Capture the tags collector when creating timeSeriesStoreTags and timeSeriesTagsToGroup #126492 is still open, so that fix is not on master yet.

Locally, with embedded Keeper, the 9 author tests and 05331 pass.

@CLAassistant

CLAassistant commented Nov 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@groeneai

Copy link
Copy Markdown
Collaborator

Follow-up on the 02369 CHECKSUM_DOESNT_MATCH in Upgrade check (amd_release): the statistics author ruled in #130674 that statistics.packed differing between releases is expected while replica versions differ (as docs/guides/oss/update.mdx documents), so the fix is in the check: #130760 makes the upgrade log scan ignore that message when the hash of uncompressed files is the sole mismatch. The compressed-file mismatch those runs also had has not recurred since #121249 kept the default codec stable across the restart (0 of about 12,000 Upgrade check runs since 2026-10-03).

alexey-milovidov pushed a commit to pugachevdmitry/ClickHouse that referenced this pull request Nov 12, 2026
…part files after the upgrade

After the restart, the upgraded server executes a MERGE_PARTS or MUTATE_PART
entry whose result the other replica already committed under the previous
release. checkPartChecksumsAndCommit compares the new part with the ZooKeeper
part header written by the old release. Releases change the byte format of
uncompressed part files: statistics.packed is registered with file_hash only,
so it lands in the "hash of uncompressed files" bucket, and its content changed
in 26.7 (auto_statistics_types default) and in 26.11 (ClickHouse#123950 adds the sum to
basic statistics). The task then logs CHECKSUM_DOESNT_MATCH at error level,
removes the local part and fetches the replica's part. The upgrade guide
(docs/guides/oss/update.mdx) documents this message as expected while replica
versions differ, and the statistics author confirmed it on ClickHouse#130674, but the
post-upgrade log scan treated it as a failure.

Filter the line only when "hash of uncompressed files doesn't match" is the
sole clause. Divergent column data ("uncompressed hash of compressed files"),
both clauses together, a different number of files and the KILL MUTATION
"different columns hash" case still fail the job. The Upgrade check is the only
CI job that reports these lines (the stress tests scan only
"<Error>.*Application"), so a broader filter on "is not byte-identical to data
on another replicas" would remove the only CI detector of divergent column data
after replicated merges and mutations.

Validated by running the extracted scan on the Upgrade check log of ClickHouse#130547
(1 line -> 0) and on 7 control lines (7 -> 5, every other shape kept), with
GNU grep 3.11 locally and inside clickhouse/stress-test. Changing "Code: 40" to
"Code: 41" in the new pattern restores both results.

Related: ClickHouse#103395
Related: ClickHouse#130674

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 2 commits November 20, 2026 16:28
Conflict resolutions:
- `FailPoint.cpp`: keep both sides' fail point declarations.
- `MergeTreeMutationEntry.cpp`: `master` moved the serialization into `writeRecord`, which
  `writeCSN` now also uses to rewrite the whole record. The `author` field and the
  `format version: 2` choice moved into `writeRecord`, so the author survives a CSN rewrite.
- `StorageMergeTree.cpp`, `StorageReplicatedMergeTree.cpp`: keep the PR's rollback with
  `run_sanity_checks = false`, adapted to `StorageInMemoryMetadata::getSettingsChanges`.
`master` is now `26.12`, and `26.11` has already been released without this setting.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged the latest master (b0626a8) and pushed f9ecaae. The only red check on 9b82da7 was CH Inc sync, which was blocked by the conflicts.

  • MergeTreeMutationEntry.cpp: master moved the serialization of the mutation file into writeRecord, and writeCSN now uses it to rewrite the whole file through a temporary one instead of appending the csn: line. The author field and the choice between format version: 1 and format version: 2 moved into writeRecord too, so a transactional mutation keeps its author when its CSN is written. The loader already accepts author: and csn: in either order.
  • StorageMergeTree.cpp / StorageReplicatedMergeTree.cpp: kept this PR's rollback, which calls changeSettings(..., /*run_sanity_checks=*/false), and adapted it to StorageInMemoryMetadata::getSettingsChanges.
  • FailPoint.cpp: kept the fail points from both sides.
  • Moved the persist_mutation_author settings-history record to 26.12, because master is now 26.12.

The changed translation units compile without warnings. I could not link and run the tests locally because the build host was overloaded, so CI will run them.

@groeneai, thanks for following up on the 02369 Upgrade check. #130760 covers it, and nothing is needed here.

Conflicts in `StorageMergeTree` and `StorageReplicatedMergeTree`: both sides changed how a mutation entry
is created. Kept the mutation `author` and the alter lock from this branch together with
`resolvePartitionIdsOfScopedCommands` from master, and adopted the name `startMutation` from master
instead of `registerMutation`. In `StorageReplicatedMergeTree::mutate` the partitions are resolved before
the alter lock is taken, so user SQL in a partition expression is not evaluated under the lock.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged the latest master (7692306) and pushed aaa5f8f to resolve the conflicts.

  • StorageMergeTree: master now resolves the partitions of scoped commands in prepareMutationEntry (resolvePartitionIdsOfScopedCommands) and names the registration step startMutation. Kept both that and the mutation author; registerMutation from this branch is now startMutation. The ALTER lock is still released before the registration.
  • StorageReplicatedMergeTree: kept the author field and the ALTER lock together with the partition resolution from master. In mutate the partitions are resolved before the lock is taken, so a partition expression with user SQL is not evaluated under it.

Built locally; the nine tests of this PR plus 02441_alter_delete_and_drop_column and 01451_replicated_detach_drop_and_quorum_long pass on the merged tree. No unresolved review threads.

*buf >> "\n";

if (buf->eof())
if (checkString("tid: ", *buf))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[Blocker] Reject a partially read transaction marker instead of treating it as absent

checkString consumes the matching prefix even when it returns false (src/IO/ReadHelpers.cpp:166). If an existing mutation file is truncated immediately after tid: (without the following space/value), this call consumes the entire suffix and returns false. The constructor then assigns Tx::NonTransactionalTID / Tx::NonTransactionalCSN, skips the loop at EOF, and passes assertEOF. The old reader rejected this file.

This changes recovery semantics: StorageMergeTree::loadMutations skips its transaction-commit check for the resulting entry, so an uncommitted mutation can be replayed as an ordinary mutation after restart. This also affects version-1 files with persist_mutation_author disabled. Use a discriminator that throws once a marker has started, such as checkStringByFirstCharacterAndAssertTheRest, and apply the same strict handling to the trailer markers. Please cover partial transaction markers with a focused loader regression.

This branch has not been deployed

No deployments
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 comp-mutations ALTER UPDATE/DELETE and mutation execution over parts (including lightweight updates/deletes). external Author is not a member of the ClickHouse organization manual approve Manual approve required to run CI pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants