Skip to content

Support real hard links for plain_rewritable metadata. - #110939

Merged
alexey-milovidov merged 19 commits into
ClickHouse:masterfrom
ylw510:plain-rewritable-explicit-prefix-path
Sep 9, 2026
Merged

alexey-milovidov merged 19 commits into
ClickHouse:masterfrom
ylw510:plain-rewritable-explicit-prefix-path

Conversation

@ylw510

@ylw510 ylw510 commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #91611
Related: #93882

Changelog category (leave one):

  • New Feature

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

Disks with the plain_rewritable metadata (s3_plain_rewritable, and azure/local object storages with metadata_type = plain_rewritable) support hard links if configured with the new enable_hard_links setting, which enables ALTER operations and mutations on MergeTree tables stored on them. Mutations and partition operations share the unchanged blobs between parts instead of copying them. The setting is off by default, because a disk that has hard links cannot be read by older servers.

Details

Implements the design from the issue: the prefix.path object of a directory may be in the implicit form (just the logical path, as before) or in the explicit form, where the logical path is followed by the list of files with the keys of their blobs, so a file can point to a blob stored under the prefix of another directory:

/hello/world/
files: 2
hello.json	gfkoqxvyhaasroiodbeurnftnwieiihy/hello.json	1234
upyachka.bin	aaealinyzgdzycgcnpgaapdssrjirnnr/upyachka.bin	567
  • A hard link switches the target directory to the explicit form. Removing a file whose blob is still linked from elsewhere switches its directory to the explicit form too (the blob stays, unlisted). Moving a file between directories is a metadata-only operation once either directory is explicit or the blob is shared.
  • The number of links to every blob is kept in memory (only for blobs with more than one link) and recalculated on load; a blob is removed together with its last link. Deletion of the last link is the only non-atomic step (rewrite prefix.path, then delete the blob), as described in the issue.
  • New blobs of a directory in the explicit form get random names, so a new file cannot clobber the blob of a removed file that is still linked from another directory. The same applies to rewriting a file whose blob is shared, including the case when the file is created, hard-linked and rewritten by the same transaction: the created files are replayed on the uncommitted state of the transaction, because the choice of the key of the next blob depends on them.
  • The explicit form also stores the sizes of the files, so loading a directory in this form needs no listing and no HEAD requests. Directories that never had hard links keep the implicit form byte-for-byte, so a disk without hard links has the same layout as before and stays readable by older servers.
  • DiskObjectStorage::supportsHardLinks now asks the metadata storage, which is where the distinction between the metadata types belongs. It is false for the write-once (plain) metadata, and for plain_rewritable it follows the enable_hard_links setting of the disk.
  • With table_disk = 1, DROP TABLE now also removes the mutation_*.txt files, because the root of the disk cannot be removed recursively.

The implementation is on top of the current FsSnapshot-based metadata (the original commit of this PR targeted the previous InMemoryDirectoryTree, which was removed from master).

Compatibility

A server older than 26.9 reads the whole prefix.path object as the logical path of the directory, so it cannot read a directory in the explicit form: the directory ends up under a bogus path. A disk that has such directories is therefore not readable after a downgrade and cannot be shared with older servers, and this is not a property that can be added to the servers that are already released.

For that reason the creation of hard links is off by default and has to be enabled by the enable_hard_links setting of the disk. With the setting off, createHardLink copies the blob, as it did before, and no directory ever switches to the explicit form, so the layout of the disk is byte-for-byte the same as before this change - including for FREEZE and backups, which create hard links without asking whether the disk supports them. The explicit form is always read, so a disk written with hard links enabled stays usable after the setting is turned off again.

Not done here: garbage collection of orphan blobs at startup (possible after a crash between the two steps of the last-link deletion). It would need a full listing of the bucket at startup, and the metadata storage cannot tell a read-only replica from the writer, so it is better done as a separate tool or a follow-up. This is documented as a caveat of enable_hard_links, and it is one of the reasons the setting is off by default.


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

Enable shared-blob hard links via explicit prefix.path mappings and refcounts so
MergeTree ALTER/mutations on plain_rewritable disks no longer rely on copyObject,
and update related tests and docs.
@Michicosun Michicosun self-assigned this Jul 18, 2026
@Michicosun

Michicosun commented Jul 18, 2026 •

Copy link
Copy Markdown
Member

plain-rewritable disks support hardlinks, why is this pr needed? There was an attempt to enable them in disk object storage #93882

@ylw510

ylw510 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

plain-rewritable disks support hardlinks, why is this pr needed? There was an attempt to enable them in disk object storage #93882

Thanks for the question.

Before this PR, plain_rewritable did not really support hard links for MergeTree:

The existing createHardLink path was a fake hard link: it called copyObject and duplicated the blob. That is enough to make the API compile/run, but it is not a shared-blob hard link, and it is expensive for mutations.

operations.addOperation(std::make_unique<MetadataStorageFromPlainObjectStorageCopyFileOperation>(

object_storage->copyObject(StoredObject(remote_path_from), StoredObject(remote_path_to), getReadSettings(), getWriteSettings());

DiskObjectStorage::supportsHardLinks() returned false for plain_rewritable, so MergeTree rejected ALTER/mutations with SUPPORT_IS_DISABLED.

@clickhouse-gh clickhouse-gh Bot added the comp-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... label Sep 4, 2026
@alexey-milovidov
alexey-milovidov marked this pull request as ready for review September 6, 2026 14:36
The plain-rewritable metadata storage was rewritten on master (immutable FsSnapshot
trees replaced InMemoryDirectoryTree), so the hard link implementation is taken
from master here and reimplemented on top of the new structure in the next commits.
… in prefix.path

A hard link makes the target directory list its files explicitly in prefix.path,
together with the keys and sizes of their blobs, so a file can point to the blob
of another directory. Link counts are kept in memory and rebuilt on load; a blob
is removed together with its last link. Directories without hard links keep the
implicit form and the layout unchanged.
The count is only kept for referenced blobs; a new blob may be created later under
the same key, and it must start with a single link.
… test

- WriteFileOperation: a file may be written to its default blob location inside a
  directory that has (or gets) the explicit file list; add it to prefix.path instead
  of throwing. This is the normal mutation path (unchanged columns hard-linked, then
  the changed column written), which the guard rejected.
- 05104: make the reader compare only materialized columns, drop the fragile
  system.remote_data_paths introspection; generated reference.
- 03008_s3: give the MOVE PARTITION destination the same projection as the source.
FsMetadata::applySnapshot adds the snapshot's blob-link deltas to the committed
counts, but the same snapshot becomes the committed one and getHardlinkCount reads
through it, so the deltas were counted twice (a blob with two links reported three).
Reset the deltas on the snapshot once they are applied.
It exercised recreating a file under the same name in an implicit directory within a
single transaction, which the design does not support (random blob names protect only
explicit directories) and which does not happen in MergeTree. The supported recreate
case with hard links is covered by ExplicitDirectoryUsesRandomBlobNames.
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Sep 6, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1486fb0]

Summary: ✅


AI Review

Summary

This PR adds real hard-link support to plain_rewritable metadata behind enable_hard_links, switches affected directories to an explicit prefix.path file-list format, and cleans up table_disk root metadata left behind by mutations. The transaction-state fixes and the non-root empty-prefix.path recovery look correct, but the root-directory loader still mis-recovers an explicit root if __meta/__root/prefix.path becomes a visible zero-byte object, so this is not ready to merge yet.

Findings

❌ Blockers

  • [src/Disks/DiskObjectStorage/MetadataStorages/PlainRewritable/MetadataStorageFromPlainRewritableObjectStorage.cpp:169-197,291-303] The root-directory recovery still falls back to implicit-root loading when __meta/__root/prefix.path is visible as a zero-byte object. CreateHardLinkRootFiles proves the problematic layout: after the root switches to the explicit form, /f2 exists only in __meta/__root/prefix.path while the only physical blob under __root/ is f1. If LocalObjectStorage exposes a zero-byte prefix.path during rewrite, load() clears local_path because the remote path is __root, leaves has_explicit_file_list = false, and then rebuilds the root from the raw __root/ listing. That silently drops /f2 on restart, and the same load() path is used by refresh(). The invariant for an explicit root has to be "the file list is authoritative", not "fall back to whatever is under __root/".
    Suggested fix: do not accept a zero-byte __root/prefix.path as an implicit-root mapping. Either keep the previous root view until the metadata object becomes readable again, or fail the load/refresh instead of rebuilding from the __root/ listing. Add the focused restart regression by truncating __meta/__root/prefix.path after CreateHardLinkRootFiles.
Tests
  • ⚠️ HardLinksDisabled still only covers the "disabled from the start" path. The PR also promises that explicit directories remain readable after enable_hard_links is turned off again (MetadataStorageFromPlainRewritableObjectStorage.h:58-59), so please add a focused restart regression that creates a real hard link with the setting enabled, restarts with it disabled, and verifies the explicit directory still loads.
Final Verdict

Status: ❌ Block

  • Fix the zero-byte __root/prefix.path recovery so explicit-root files cannot disappear on restart or refresh().
  • Add focused regression coverage for the root-empty case and for restarting with enable_hard_links turned off after explicit directories already exist.

LLVM Coverage Report

Measured on commit 1486fb0.

Metric Baseline Current Δ
Lines 88.90% 88.90% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.30% 81.30% +0.00%

Changed lines: Changed C/C++ lines covered: 1209/1267 (95.42%) · Uncovered code

Full report · Diff report

Fix cpp cidb style check failure that disallows tab characters in source files.
/// Load the list of files inside the directory.
for (auto dir_iterator = object_storage->iterate(layout->constructFilesDirectoryKey(remote_path.value()), 0, /*with_tags=*/ false, std::nullopt); dir_iterator->isValid(); dir_iterator->next())
/// In the implicit form, the files of the directory are the blobs stored under its prefix.
if (!has_explicit_file_list)

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.

⚠️ Major: once a directory switches to the explicit form, restart stops listing the blobs under its prefix here and trusts only prefix.path. The unlink/remove paths now commit "drop the file from prefix.path" before finalize() deletes the last blob, so a kill in that window leaves an orphaned object that the loader will ignore forever after restart. The PR description calls the missing GC out, but with hard links enabled for mutations and partition moves this becomes a normal crash/restart leak path. I think the feature needs a recovery mechanism in the same rollout (startup sweep or a supported external tool) rather than shipping a format that can strand arbitrary blob data permanently.

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.

🕵 Right, and this is why hard links are now off by default: enable_hard_links (0 unless the disk asks for it) is what admits both this and the downgrade problem, and the caveat is spelled out next to the setting in storing-data.mdx - an object whose last link is dropped is deleted after the metadata rewrite, so a kill in that window leaves an object that nothing references and that has to be deleted manually.

A recovery pass is deliberately not in this change. To find such an object it has to list the whole bucket, because the orphan may sit under the prefix of a directory that has since been removed, and the metadata storage cannot tell a read-only replica from the writer, so a startup sweep on a shared endpoint could delete the objects of another server's in-flight transaction. That makes it a separate tool (or an explicitly invoked operation), not something to bolt onto load.

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.

🕵 This one stands as answered above: the recovery pass needs a full listing of the bucket (the orphan can sit under the prefix of a directory that has since been removed) and the metadata storage cannot tell a read-only replica from the writer, so a sweep in load on a shared endpoint could delete the objects of an in-flight transaction of another server. That makes it a separate tool, and it is one of the reasons enable_hard_links is off by default.

For contrast, the crash windows that can be recovered from load are handled that way - see #118465, where the temporary name gets a reserved prefix the loader recognises. A blob whose last link was just dropped has no such handle: its key is indistinguishable from a live blob without the full set of file lists.

alexey-milovidov and others added 4 commits September 7, 2026 19:11
A hard link switches the `prefix.path` object of the target directory to the
explicit form, which servers older than 26.9 cannot read: they read the whole
object as the logical path of the directory, so the directory ends up under a
bogus path. Enabling `supportsHardLinks` for every `plain_rewritable` disk
therefore made the first `ALTER`, mutation or `FREEZE` break downgrades and
mixed-version setups for an already supported disk type, without any way to keep
the previous layout.

Add the `enable_hard_links` setting of the disk (`0` by default). With it off,
`createHardLink` copies the blob, as it did before, and no directory ever
switches to the explicit form, so the layout is byte-for-byte the same as
before this feature. The explicit form is always *read*, so a disk written with
hard links enabled stays usable after they are disabled again; a copy into a
directory that is already in the explicit form is added to its file list.

`DiskObjectStorage::supportsHardLinks` now asks the metadata storage, which is
also where the distinction between the metadata types belongs.

The `03008_*_plain_rewritable` tests go back to checking that `ALTER` and
mutations are rejected, which is what a disk without `enable_hard_links` does;
the coverage of the enabled feature is in
`05104_s3_plain_rewritable_hard_links`. This also fixes the flaky check timeout
of `03008_s3_plain_rewritable`, which was running mutations of 10000 rows over
10 partitions on every repetition:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=110939&sha=08253f9ab019412aa01b05f88590bfab08704930&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20flaky%20check%29
ClickHouse#110939

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`createHardLink` marked the source blob as shared only when the source file was
visible in `UncommittedState`, but file creations were not replayed there. So
for a transaction that creates a file, hard-links it and then rewrites it -
`createMetadataFile("A/f1")`, `createHardLink("A/f1", "B/f1")`,
`createMetadataFile("A/f1")` - `generateObjectKeyForPath` reused the default key
of `A/f1` for the rewrite instead of picking a fresh blob, and the rewrite
overwrote the very blob that `B/f1` was supposed to keep. The link then saw the
new contents.

Replay the created files, together with the keys of their blobs, on the
uncommitted state, which is exactly the fact that the choice of the key of the
next blob depends on. `UncommittedState::recordCreatedFile` mirrors what
`MetadataStorageFromPlainObjectStorageWriteFileOperation` does on the commit
snapshot: a rewrite drops the link to the previous blob of the file.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`MetadataStorageFromCacheObjectStorage` forwards `createHardLink`, `isPlain`
and `isWriteOnce` to the metadata storage it wraps, so it has to forward
`supportsHardLinks` as well. Otherwise the default implementation answers for
the wrapper and disagrees with the storage that actually performs the
operation - for a cached `plain_rewritable` disk with `enable_hard_links` it
would keep saying that hard links are not supported.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread src/Storages/StorageMergeTree.cpp Resolved
Fix clang-tidy readability-duplicate-include failure introduced when merging
upstream changes that added DataTypeArray.h alongside an already present
DataTypeLowCardinality.h include.
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 1486fb059 with master 602ce8d11 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

24 object files changed (+355.99 KiB total), 2 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Disks/DiskObjectStorage/MetadataStorages/PlainRewritable/MetadataStorageFro… 351.87 KiB 460.66 KiB +108.79 KiB (+30.92%)
src/CMakeFiles/dbms.dir/Disks/DiskObjectStorage/MetadataStorages/PlainRewritable/Metadata/PrefixPat… new 88.61 KiB +88.61 KiB
src/CMakeFiles/dbms.dir/Disks/DiskObjectStorage/MetadataStorages/PlainRewritable/Metadata/BlobLinkC… new 47.65 KiB +47.65 KiB
src/CMakeFiles/dbms.dir/Disks/DiskObjectStorage/MetadataStorages/PlainRewritable/MetadataStorageFro… 406.14 KiB 439.47 KiB +33.33 KiB (+8.21%)
src/CMakeFiles/dbms.dir/Disks/DiskObjectStorage/MetadataStorages/PlainRewritable/Metadata/FsSnapsho… 175.04 KiB 200.02 KiB +24.98 KiB (+14.27%)
src/CMakeFiles/dbms.dir/Disks/DiskObjectStorage/MetadataStorages/PlainRewritable/Metadata/FsMetadat… 24.19 KiB 42.22 KiB +18.03 KiB (+74.55%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

77 translation units recompiled, 635 s compile time in total, 75 of them have a recent master baseline.

Job report

Only the reserved metadata object of the root maps to the empty logical path. A
metadata object of any other directory whose logical path is empty does not
describe a directory at all: `LocalObjectStorage` writes to the final key
directly, so an interrupted write leaves the object empty and visible. The
loader used to map such an object to the logical root, which hides the files of
the root and sends the lookups under it to the prefix of that directory.
The object key of the next blob of a directory depends on the files the
transaction is going to create, so the uncommitted state has to see them. Two
facts were missing:

- `recordCreatedFile` did not record that a file written to a blob outside of
  the default location switches its directory to the explicit file list at
  commit, so a second rewrite of the same file fell back to the default
  location - the blob that a hard link to it is keeping alive.
- `planFileMove` recorded only that the two directories become explicit, not
  the moved file itself, so a `createHardLink` from the new path did not mark
  its blob shared, and the rewrite that followed clobbered the contents the
  link preserves. The same held for `replaceFile`.

Hard links are replayed as well (`recordHardLink`), for the same reason.
…on `DROP`

`dropAllData` turns `removeRecursive` into a no-op for the root of a disk, so a
table that occupies the whole disk has to remove what it keeps there itself.
`deduplication_logs/` survived the drop, and the next table created on the same
disk loaded the block numbers of the previous one and silently skipped its
inserts as duplicates.
`FREEZE` and backups call `createHardLink` too, so a disk can become unreadable
by older servers without a mutation or an `ALTER` ever running. Also move the
subsection below the `plain_rewritable` paragraph: it had been inserted between
the configuration example and its `is equal to` continuation.
@alexey-milovidov

alexey-milovidov commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

🕵 Addressed the review - the four blockers and the major, one commit each, with a regression test for every one of them.

Finding Commit Test
A prefix.path object without a logical path was loaded as the logical root 4ed06168901 EmptyDirectoryMetadataIsNotLoadedAsRoot
recordCreatedFile did not mark the directory explicit for a non-default blob key 080511755a8 CreateHardLinkAndRewriteTwiceInSameTransaction
planFileMove / replaceFile did not replay the move on the transaction view 080511755a8 MoveFileThenHardLinkAndRewriteInSameTransaction, ReplaceFileThenHardLinkAndRewriteInSameTransaction
table_disk DROP left deduplication_logs/ in the root of the disk f021b9697af 05137_table_disk_drop_deduplication_log
The downgrade caveat named ALTER and mutations only 7826e1f8d11 -

The three transaction findings are one defect: the uncommitted state has to see every file the transaction is going to create, because the object key of the next blob of a directory depends on them. It may over-count the links of a blob - that only makes the choice of the key more conservative - but it must never under-count them. createHardLink was replayed too (recordHardLink) to close the same hole on the target of a hard link.

The two failing stateless tests, 04648_distributed_plan_task_error_propagation and 04340_distributed_plan_status_reenqueue_fault, are unrelated: both have been failing on master itself and across dozens of unrelated pull requests since 2026-09-06, and are tracked by #118831 and #118832. Both are closed by #118417, which is already open: 04648 loses a race in ReadFromDistributedPlanSource::tryGenerate, and 04340 is collateral damage - 04648 stops before its SYSTEM DISABLE FAILPOINT and leaves the server-wide fail point armed for the rest of the job.

}

/// The root directory has a metadata object only in the explicit form, and it is stored under the reserved remote path.
if (remote_path.value() == PlainRewritableLayout::ROOT_DIRECTORY_TOKEN)

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: the root-directory recovery still loses files if __meta/__root/prefix.path becomes a visible zero-byte object during a rewrite on LocalObjectStorage.

CreateHardLinkRootFiles already shows the problematic layout: after createHardLink("/f1", "/f2"), the root has switched to the explicit form, but there is still only one physical blob under __root/ (__root/f1) and the second name lives only in the explicit file list. If __meta/__root/prefix.path is truncated to zero bytes before restart, the size_bytes == 0 branch above leaves has_explicit_file_list = false, this block still accepts the object as /, and the fallback at lines 291-303 rebuilds the root from the __root/ listing with only f1. f2 disappears after restart.

For non-root directories an empty prefix.path is now ignored, but for __root that silent fallback is not safe once the root has ever become explicit. Please treat an empty __root/prefix.path as corrupt / in-progress instead of reverting to implicit-root loading, and add a focused restart regression test by truncating the root metadata object after CreateHardLinkRootFiles.

`ReplaceFileThenHardLinkAndRewriteInSameTransaction` passed without the fix. A
move that copies the blob gives the target the default location of its own path,
which is also the key a file already sitting at that path has in a directory
with the implicit file list, so a pre-existing target hides the stale
transaction view instead of exposing it. Replace onto a path that does not exist
yet instead - that call is legal for `replaceFile`, and it does fail without the
fix, as the other three regression tests do.
EXPECT_EQ(readObject(object_storage, metadata->getStorageObjects("A/f1").front().remote_path), "data");
}

TEST_F(MetadataPlainRewritableDiskTest, HardLinksDisabled)

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.

⚠️ Major: this test only covers enable_hard_links = 0 from the start, but the PR's compatibility contract is stronger. MetadataStorageFromPlainRewritableObjectStorage.h and storing-data.mdx both say that once a disk has already switched some directories to the explicit prefix.path form, turning enable_hard_links off again still leaves those directories readable. That rollback path is exactly where a regression would strand existing data, so it needs a focused restart test of its own: create a real hard link with enable_hard_links = 1, restart with it set to 0, and verify the explicit directory still loads.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 9, 2026
Merged via the queue into ClickHouse:master with commit 7e2e045 Sep 9, 2026
175 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 9, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@ylw510 @alexey-milovidov — title/description suggestions:

Description (currently incomplete):

  • Why: The body (and the docs the PR adds) imply FREEZE is one of the operations that starts creating hard links, but ALTER TABLE ... FREEZE is rejected for plain_rewritable disks independently of enable_hard_links: the partition-command allowlist at MergeTreeData.cpp:8583-8594 admits only DROP_PARTITION / DROP_DETACHED_PARTITION / ATTACH_PARTITION / MOVE_PARTITION / REPLACE_PARTITION, so FREEZE hits the SUPPORT_IS_DISABLED throw at MergeTreeData.cpp:8613. Verified on a local plain_rewritable disk with enable_hard_links = 1: Partition operation ALTER TABLE FREEZE ALL is not supported for disk.

  • Suggested addition:

    Worth stating which operations the setting does and does not unlock. enable_hard_links flips the two gates keyed on supportsHardLinks() (MergeTreeData::checkAlterIsPossible, MergeTreeData::checkMutationIsPossible), so mutations and column ALTERs work. Partition-level commands stay governed by the type-keyed allowlist in MergeTreeData::checkAlterPartitionIsPossible (MergeTreeData.cpp:8583-8594), which does not list FREEZE - so ALTER TABLE ... FREEZE [PARTITION] is still rejected. Either drop FREEZE from the docs sentence 'a mutation, an ALTER, a FREEZE or a backup' in storing-data.mdx, or extend that allowlist. (BACKUP does create hard links, but only for tables outside an Atomic database: MergeTreeData.cpp:9077-9082 sets make_temporary_hard_links = false when the table has a UUID.)

Ignore if intentional.

@Algunenano

Copy link
Copy Markdown
Member

CheSema added a commit that referenced this pull request Sep 11, 2026
Master reverted "Support real hard links for plain_rewritable metadata"
(#110939) in 79745e1, so the operations this branch touches lost their
explicit file lists. The reversal work is re-applied on the simpler code:

- `MetadataStorageFromPlainObjectStorageHardLinkOperation` is gone, because
  `createHardLink` copies the blob again, which the copy operation covers.
- `MetadataStorageFromPlainObjectStorageWriteFileOperation` no longer writes to
  object storage, so it has nothing to reverse and does not take `UndoRetries`.
- The move of a file has a single form again, so its reversal no longer has a
  branch for a move that only rewrites file lists.
- `prefix.path` holds a logical path again, so the tests read it directly.

Everything the branch claims is unchanged: every stage of an `undo` repeats
until object storage accepts it, each stage converges on the state recorded
before the first write rather than on what `execute` saw succeed, and a blob
that exists under neither its own key nor its temporary key is reported as a
logical error.

When #119304 restores the hard links, the reversals of the hard link operation,
of `WriteFileOperation` and of the file move that only rewrites file lists need
the same treatment again.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
alexey-milovidov added a commit that referenced this pull request Sep 13, 2026
Edited by hand following .claude/skills/edit-changelog/SKILL.md, consolidating
the nine raw blocks generated between 2026-09-06 and 2026-09-13. The
NightlyChangelog job rejected its own edits every night in that period: the
verifier did not know that #116566 (reverted by #116586) had itself reverted
#109710, so it demanded that no trace of #116586 remain while the rules put
its link on the CatBoost entry. Fixed in the job by
#119866; this edit passes the
patched verifier, and the trailers below give the ledger the missing chain.

Failed runs: https://github.com/ClickHouse/ClickHouse/actions/runs/34006912773
through https://github.com/ClickHouse/ClickHouse/actions/runs/34668133756

Changelog-revert: 116566 109710 Revert "Remove CatBoost integration"
Changelog-revert: 116586 116566 Revert "Revert "Remove CatBoost integration""
Changelog-revert: 117629 117295 Revert "Skip Darwin fast test in PRs unless labeled ci-macos"
Changelog-revert: 118525 118218 Revert "Do not wait for the remote drain when cancelling a remote query"
Changelog-revert: 119043 117866 Revert "Add `ci-coverage` label to force LLVM coverage jobs on tests-only PRs"
Changelog-revert: 119269 118239 Revert "Require agents to run the style check locally before pushing"
Changelog-revert: 119270 115343 Revert "Resume a NATS JetStream subscription after a reconnect"
Changelog-revert: 119274 118919 Revert "Carry the mutation version onto a rewritten lightweight `DELETE`"
Changelog-revert: 119275 114817 Revert "Convert OUTER join to INNER join by null-rejecting join conditions"
Changelog-revert: 119276 110939 Revert "Support real hard links for plain_rewritable metadata."
Changelog-revert: 119279 117449 Revert "Print file offsets in the bare fatal stack traces and build the release binary as PIE"
Changelog-revert: 119281 116629 Revert "Check access rights in the TimeSeries table functions"
Changelog-revert: 119298 118606 Revert "Proper partition pruning with dates"
Changelog-revert: 119323 117768 Revert "Docs: Skip private sync for documentation-only pull requests"
Changelog-revert: 119334 117356 Revert "Unify the spill trigger for hash joins"
Changelog-revert: 119429 114562 Revert "Fix NO_SUCH_COLUMN_IN_TABLE naming a column absent from the table when a part's columns were all renamed or all dropped"
Changelog-deleted-entry: 110939 [New Feature] [raw] * Disks with the `plain_rewritable` metadata (`s3_plain_rewritable`, and `azure`/`local` object storages with `metadata_type = plain_rewritable`) support hard links if configured with the new `enable_hard_links` setting, which enables `ALTER` operations and mutations on `MergeTree` tables stored on them. Mutations and partition operations share the unchanged blobs between parts instead of copying them. The setting is off by default, because a disk that has hard links cannot be read by older servers. [#110939](#110939) ([yanglongwei](https://github.com/ylw510)).
Changelog-deleted-entry: 114562 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed `NO_SUCH_COLUMN_IN_TABLE` naming a column that is not in the table, when reading or merging a part whose columns had all been renamed or all dropped by a mutation that was not applied yet. The merge kept being retried, so the table stopped compacting. Also fixed the columns of a `MergeTree` part produced by such a merge reading as their default values until the mutation was applied. [#114562](#114562) ([Shaohua Wang](https://github.com/tiandiwonder)).
Changelog-deleted-entry: 114817 [Performance Improvement] [raw] * Convert `OUTER JOIN` to `INNER JOIN` when a later JOIN condition filters out its NULL-extended rows, and filter NULL join keys directly at the table scan when column statistics show it is selective. Only conditions of the form `expr1` OP `expr2` are considered, where OP is one of `=`, `<`, `<=`, `>`, `>=`. Each side can be a column or an expression that propagates NULLs. Controlled by the new settings `query_plan_derive_not_null_filters_from_joins` (enabled by default), `query_plan_allow_derived_not_null_filters_execution` (enabled by default) and `query_plan_max_selectivity_for_not_null_filters_execution` (0.7 by default). [#114817](#114817) ([Hechem Selmi](https://github.com/m-selmi)).
Changelog-deleted-entry: 115343 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed a `NATS` engine table reading from a JetStream stream (`nats_stream`) silently stopping to consume messages after the NATS server restarted or the connection was re-established. [#115343](#115343) ([Alexey Milovidov](https://github.com/alexey-milovidov)).
Changelog-deleted-entry: 116629 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * The table functions reading a `TimeSeries` table (`timeSeriesSamples`, `timeSeriesTags`, `timeSeriesMetrics`, `timeSeriesSelector`, `prometheusQuery`, `prometheusQueryRange`) checked no privilege on it: a user holding only `CREATE TEMPORARY TABLE` could read its target tables' column definitions and rows, and write into them. Each now requires the corresponding privilege on the `TimeSeries` table and on the target table, following an `Alias` target through to the table it points at. `timeSeriesSamples`, `timeSeriesTags` and `timeSeriesMetrics` check the target at table level, since they return it whole and cannot restrict the columns, so a column-scoped grant on the target is not enough; the other three run ordinary target queries, which the planner still checks per column. An external target is authorized before it is looked up, so its existence is not disclosed either. A read fails with `ACCESS_DENIED` when the user's effective `SELECT` row-policy filter on the `TimeSeries` table is not always true, since such a policy cannot be enforced on the target's rows, and the three target functions can no longer back a `CREATE TABLE ... AS` (`BAD_ARGUMENTS`). PromQL over the Prometheus HTTP and remote-read endpoints reaches `timeSeriesSelector` whenever it selects series, so those requests now need these privileges for the user the endpoint authenticated. [#116629](#116629) ([Groene AI](https://github.com/groeneai)).
Changelog-deleted-entry: 117356 [Backward Incompatible Change] [raw] * `max_bytes_before_external_join` and `max_bytes_ratio_before_external_join` are now the spill threshold for every hash-based `join_algorithm`, including `grace_hash`, which previously ignored them and spilled on `max_rows_in_join` / `max_bytes_in_join` instead. Those two are a hard cap again for every algorithm: they no longer cause spilling, and a join that spills no longer exceeds them. All join algorithms remain available; `join_algorithm = 'grace_hash'` now needs a non-zero spill threshold, and is skipped in favour of the next algorithm in the list when it has none. Set `legacy_join_size_limits_trigger_spilling = 1` (or `compatibility` to 26.8 or older) to restore the previous behavior. [#117356](#117356) ([Yarik Briukhovetskyi](https://github.com/yariks5s)).
Changelog-deleted-entry: 117449 [Build/Testing/Packaging Improvement] [raw] * ClickHouse is now built as a position independent executable on Linux amd64 and aarch64 with glibc, including the release builds, so the text segment is subject to ASLR. Addresses in the bare stack trace of a fatal log are now file offsets relative to the object that contains them, annotated with that object for frames outside the main executable, so they can be resolved with `addr2line -e <object> <hex>` regardless of where the binary was loaded. For the same reason `system.errors.last_error_trace`, `system.error_log.last_error_trace` and `system.crash_log.trace` now store a frame of the main executable as its file offset, keeping runtime addresses for frames in other objects. [#117449](#117449) ([Groene AI](https://github.com/groeneai)).
Changelog-deleted-entry: 117768 [NOT FOR CHANGELOG / INSIGNIFICANT] [raw] * Not applicable. [#117768](#117768) ([Dominic Tran](https://github.com/dhtclk)).
Changelog-deleted-entry: 118218 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed cancelling a distributed, `s3Cluster` or parallel-replicas `SELECT` taking up to `receive_timeout` (300 s by default) to take effect, and never reaching some of the remote sources, when one of them was draining the packets left over after a `LIMIT` was satisfied. [#118218](#118218) ([Groene AI](https://github.com/groeneai)).
Changelog-deleted-entry: 118239 [NOT FOR CHANGELOG / INSIGNIFICANT] [raw] * Require agents to run the style check locally before pushing. [#118239](#118239) ([Nikita Fomichev](https://github.com/fm4v)).
Changelog-deleted-entry: 118606 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Proper partition pruning with dates. Closes [#103433](#103433). [#118606](#118606) ([Konstantin Vedernikov](https://github.com/scanhex12)).
Changelog-deleted-entry: 118919 [Bug Fix (user-visible misbehavior in an official stable release)] [raw] * Fixed a pending lightweight `DELETE` read with `apply_mutations_on_fly = 1` evaluating its predicate over patch parts created after it, which made rows disappear from the result and reappear after the mutation materialized. [#118919](#118919) ([Alexey Milovidov](https://github.com/alexey-milovidov)).
alexey-milovidov added a commit that referenced this pull request Sep 18, 2026
…while a readonly table loaded

A readonly `MergeTree` table over the directory of a live table (`table_disk`
on the same `plain_rewritable` endpoint) does not own the `mutation_*.txt`
entries there: the live table removes one at any moment (`KILL MUTATION`,
`clearOldMutations`), also between the listing and the read in
`loadMutations`. The read then failed with a raw `S3_ERROR` (`The specified
key does not exist`), which is what reverted #110939: the stress test kills
random mutations and treats every such error as a bug, see
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=3b3489bfd27660683f874666359fc92f58ca46b8&name_0=MasterCI&name_1=Stress%20test%20%28amd_debug%29

The table still cannot load without the entry - a part below its version
would miss the commands, and no reader-side rule can tell a killed mutation
from a finished one (see the analysis in #119154) - so the load still fails,
but with `FILE_DOESNT_EXIST` and the reason: the entry was removed
concurrently, and the attach can be retried after `SYSTEM DROP DISK METADATA
CACHE` reloads the metadata of the readonly disk, which still lists the entry.
The check probes the backend, because the cached metadata of the disk is
exactly what is stale. Only a readonly disk takes this path.

Related: #119154

Co-Authored-By: Claude Fable 5.1 <[email protected]>
zghong pushed a commit to zghong/ClickHouse that referenced this pull request Oct 21, 2026
The `enable_hard_links` setting of disks with the `plain_rewritable` metadata,
added in ClickHouse#110939, is now `1` by
default, so `ALTER` operations and mutations work on such disks out of the box.
The setting can still be turned off to keep a disk readable by servers older
than 26.9.

The tests that check the behavior without hard links now set
`enable_hard_links = 0` explicitly, and `03008_local_plain_rewritable` checks
that the mutations succeed on a disk from the config.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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-object-storage-disks Object-storage disk layer: DiskObjectStorage, metadata storage adapters, transaction support for ... pr-feature Pull request with new product feature 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.

Support hard links in the disks with plain_rewritable metadata

6 participants