Repository navigation
Support real hard links for plain_rewritable metadata. - #110939
alexey-milovidov merged 19 commits into
Conversation
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.
|
|
Thanks for the question. Before this PR, The existing
|
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.
|
Workflow [PR], commit [1486fb0] Summary: ✅
AI ReviewSummaryThis PR adds real hard-link support to Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block
LLVM Coverage ReportMeasured on commit 1486fb0.
Changed lines: Changed C/C++ lines covered: 1209/1267 (95.42%) · Uncovered code |
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
🕵 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.
There was a problem hiding this comment.
🕵 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.
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]>
…plicit-prefix-path
`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]>
…e-explicit-prefix-path
Fix clang-tidy readability-duplicate-include failure introduced when merging upstream changes that added DataTypeArray.h alongside an already present DataTypeLowCardinality.h include.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes24 object files changed (+355.99 KiB total), 2 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units77 translation units recompiled, 635 s compile time in total, 75 of them have a recent master baseline. |
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.
|
🕵 Addressed the review - the four blockers and the major, one commit each, with a regression test for every one of them.
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. The two failing stateless tests, |
| } | ||
|
|
||
| /// 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) |
There was a problem hiding this comment.
❌ 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) |
There was a problem hiding this comment.
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.
|
@ylw510 @alexey-milovidov — title/description suggestions: Description (currently
Ignore if intentional. |
|
This is causing issues in the stress tests: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=3b3489bfd27660683f874666359fc92f58ca46b8&name_0=MasterCI&name_1=Stress%20test%20%28amd_debug%29&name_1=Stress%20test%20%28amd_debug%29 Reverting. Please investigate and reintroduce |
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]>
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)).
…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]>
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]>
Closes: #91611
Related: #93882
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Disks with the
plain_rewritablemetadata (s3_plain_rewritable, andazure/localobject storages withmetadata_type = plain_rewritable) support hard links if configured with the newenable_hard_linkssetting, which enablesALTERoperations and mutations onMergeTreetables 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.pathobject 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:prefix.path, then delete the blob), as described in the issue.HEADrequests. 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::supportsHardLinksnow asks the metadata storage, which is where the distinction between the metadata types belongs. It is false for the write-once (plain) metadata, and forplain_rewritableit follows theenable_hard_linkssetting of the disk.table_disk = 1,DROP TABLEnow also removes themutation_*.txtfiles, 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 previousInMemoryDirectoryTree, which was removed from master).Compatibility
A server older than 26.9 reads the whole
prefix.pathobject 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_linkssetting of the disk. With the setting off,createHardLinkcopies 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 forFREEZEand 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]