Skip to content

Fix create on ClickHouse 26.2+ for tables with a cache disk over a plain_rewritable disk - #1701

Open
kolsys wants to merge 1 commit into
Altinity:masterfrom
kolsys:fix/cache-disk-name-in-system-parts
Open

kolsys wants to merge 1 commit into
Altinity:masterfrom
kolsys:fix/cache-disk-name-in-system-parts

Conversation

@kolsys

@kolsys kolsys commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Symptom

create / create_remote fails on ClickHouse 26.8 for every table whose storage policy has a volume on a cache
disk which wraps a plain_rewritable disk. The same clickhouse-backup 2.8.3 with the same config works on 25.8.
One such table fails the backup of the whole server, and skip_disks doesn't help: the error is raised before the
disk is skipped.

backup failed error: one of createBackupLocal go-routine return error: b.AddTableToLocalBackup:
`db`.`t` have parts on plain disks and on disk plain_cache which is not a local disk of system.disks
(a cache disk over object storage is listed under the underlying disk name), only local disks are
supported next to plain disks in one storage policy

Cause

ClickHouse changed the disk name it reports for a part behind a cache disk. Same data volume, same storage
configuration, a volume declared on plain_cache (type = cache, disk = plain):

ClickHouse system.parts.disk_name system.storage_policies.disks
25.8.28.1 plain (the wrapped disk) ['plain']
26.1.12.23 plain (the wrapped disk) ['plain']
26.2.19.43 plain_cache (the cache disk) ['plain_cache']
26.8.44.3 plain_cache (the cache disk) ['plain_cache']

system.disks lists both names with the same path on both versions, cache_path is non-empty only for the
cache disk.

The change is ClickHouse#96444 "Use cache layer as disk
name", merged into 26.2.1.521 and labelled pr-not-for-changelog, so it is not in the changelog.
ClickHouse#98665 describes the same change from the
TTL ... TO DISK side ("there was a bug in the previous version where the name of the cache disk was copied from
the wrapped disk") and names ClickHouse#96070, which is in 26.2 as well.

clickhouse-backup is not ready for the new name:

  • getDisksFromSystemDisks groups system.disks by d.path and takes argMin(d.name, d.cache_path != ''), so
    the cache disk and the wrapped disk are one Disk named as the wrapped disk. The comment there says
    system.parts always reports the wrapped disk name.
  • filterPlainPolicyParts and linkLocalPartsToShadow look the disk of a part up with
    findDiskByName(diskList, part.DiskName), get nil for the cache disk name and return the error above.

How to reproduce

ClickHouse 26.2+. The error was reproduced on 26.8.44.3: with an Azure disk on Azurite (below) and with the S3
disk of the new integration test.

<storage_configuration>
  <disks>
    <plain>
      <type>object_storage</type>
      <object_storage_type>azure_blob_storage</object_storage_type>
      <metadata_type>plain_rewritable</metadata_type>
      <storage_account_url>http://azurite:10000/devstoreaccount1</storage_account_url>
      <container_name>plain-disk</container_name>
      <account_name>devstoreaccount1</account_name>
      <account_key>...</account_key>
    </plain>
    <plain_cache>
      <type>cache</type>
      <disk>plain</disk>
      <path>/var/lib/clickhouse/filesystem_caches/plain_cache/</path>
      <max_size>1Gi</max_size>
    </plain_cache>
  </disks>
  <policies>
    <hybrid>
      <volumes>
        <hot><disk>default</disk></hot>
        <cold><disk>plain_cache</disk></cold>
      </volumes>
    </hybrid>
  </policies>
</storage_configuration>
CREATE TABLE db.t (id UInt64, payload String) ENGINE = MergeTree PARTITION BY id % 4 ORDER BY id
SETTINGS storage_policy = 'hybrid';
INSERT INTO db.t SELECT number, repeat('x', 128) FROM numbers(1000);
ALTER TABLE db.t MOVE PARTITION ID '0' TO VOLUME 'cold';
SELECT DISTINCT disk_name FROM system.parts WHERE database = 'db' AND table = 't' AND active;
-- 25.8: default, plain          26.8: default, plain_cache
clickhouse-backup create_remote --tables='db.*' test_backup                      # fails on 26.8
CLICKHOUSE_SKIP_DISKS=plain,plain_cache clickhouse-backup create_remote ...      # fails the same way

A table with all its parts behind the cache disk (a policy with the cold volume only) fails the same way.

Fix

Disk gets Aliases: the names of the cache wrappers collapsed into its system.disks row
(groupUniqArrayIf(d.name, d.cache_path != '')). Disk.HasName and clickhouse.FindDiskByName match a disk by
its name or by an alias, the name of a disk wins over an alias of another disk.

The disk keeps the wrapped disk name, as before. It is the name stored in metadata.json, in
shadow/<db>/<table>/<disk>_<part>.tar and in <object_disk_path>/<backup>/<disk>/, so nothing changes in
existing backups, and an increment made after the server upgrade reuses the parts of a backup made before it.

Places where a disk name reported by the server is matched to the disk list:

  • filterPlainPolicyParts: the disk of a part is found by either name and DiskName of the part is rewritten to
    the name of the Disk, so linkLocalPartsToShadow and uploadPlainDiskParts work unchanged. An object disk
    with local metadata behind a cache disk next to plain disks is still rejected, the error names both disks.
  • shouldSkipByDiskNameOrType: skip_disks skips the pair by either name. Before, only the wrapped disk name
    worked.
  • rebalance (getLiveParts), the dry-run estimate of create and the hardlink of existing parts in download
    (findHardlinkablePartsByHash, hardlinkFromLiveParts) resolve system.parts.disk_name the same way.
  • findDiskByName is alias-aware, which also covers the system.storage_policies lookup of custom disks in
    resolveCustomDiskAliases (it used to fall back to matching by path).

No new grants and no new server settings are needed.

Not affected: the regular FREEZE path doesn't use system.parts.disk_name to find a disk
(fetchHashOfAllFiles doesn't filter by disk). An object disk with local metadata behind a cache disk is backed
up on 26.8.44.3 by unpatched 2.8.3, checked.

Tests

Unit:

  • TestFilterPlainPolicyParts: parts behind a cache disk reported under the wrapped name (25.8) and under the
    cache name (26.8) resolve to the same disk, the returned parts carry the wrapped disk name; an object disk
    behind a cache disk and a disk absent in system.disks are rejected.
  • TestSkipDisksMatchCacheAndWrappedDiskNames: skip_disks with the wrapped name, the cache name, both, and
    skip_disk_types.
  • TestDiskAliases, TestFindDiskByName.

Integration:

  • TestPlainRewritableCacheHybridS3 (new): the hybrid scenario of TestPlainRewritableHybridS3 with the cold
    volume on a cache disk over disk_s3_plain_rewritable, three runs: skip_disks by the cache disk name, by the
    wrapped disk name, and without skip_disks (with restore on 25.11+). The cache disk and the
    s3_plain_rewritable_cache_hybrid policy are added to dynamic_settings.sh for 25.4+.
  • TestCacheDiskBackup: additionally checks that the table metadata lists the parts behind the cache under
    s3_disk and never under s3_cache.

Run locally (arm64): TestPlainRewritableCacheHybridS3, TestPlainRewritableHybridS3 and TestCacheDiskBackup
pass on 26.8.44.3 and on 25.8.28.1. With the 2.8.3 binary TestPlainRewritableCacheHybridS3 fails on 26.8.44.3
with the error above. The rest of the integration suite was not run locally.

Manual, one data volume upgraded from 25.8.28.1 to 26.8.44.3, Azure plain_rewritable disk on Azurite behind a
cache disk, both disk names in skip_disks, three tables: local only, hybrid (parts on both volumes), all parts
behind the cache disk:

  1. 25.8.28.1, 2.8.3: create_remote full passes.
  2. 26.8.44.3, 2.8.3: create_remote --diff-from-remote fails with the error above.
  3. 26.8.44.3, this branch: the increment from the full of step 1 passes, required_backup points to it, the
    parts unchanged since the full are required under the same disk name, only new parts are uploaded.
  4. rebase of the next increment passes, the backup becomes full.
  5. restore_remote of the chain and of the rebased backup into another database: the local and the hybrid table
    come back with the row counts of their local parts (the checksum of the hybrid table matches too), the table
    behind the cache disk comes back as schema only, as it does with skip_disks on 25.8.

Also: the same create_remote by this branch on 25.8.28.1 gives the same parts, disks and remote files as 2.8.3;
skip_disks with the cache disk name only, on both versions; without skip_disks the parts behind the cache are
copied under the wrapped disk name on both versions, an increment on 26.8 reuses the plain disk parts of a full
made on 25.8, and a full backup with plain disk parts restores on 26.8. With the same patch on top of v2.8.3,
watch with a schedule, full_type=rebase and delete_previous_cycle continues the chain after the failed tick
of 2.8.3.

A cache disk shares system.disks.path with the disk it wraps, so GetDisks
lists the pair once, under the wrapped disk name. For a part behind the
cache system.parts.disk_name is the wrapped disk on ClickHouse 25.8 and
the cache disk on 26.8, system.storage_policies changed the same way. On
26.8 create failed for every table with a plain_rewritable disk behind a
cache disk in its storage policy, even with the disk in skip_disks:

  `db`.`t` have parts on plain disks and on disk <cache disk> which is
  not a local disk of system.disks

GetDisks now keeps the names of the cache wrappers collapsed into a disk
in Disk.Aliases and a disk is found by any of its names. The disk keeps
the wrapped disk name, so backup metadata, shadow/<db>/<table>/<disk>_*
archives and object_disk_path/<backup>/<disk>/ prefixes don't change and
an increment made on 26.8 reuses the parts of a backup made on 25.8.

- the parts of a table backed up without FREEZE are attributed to the
  GetDisks entry, whichever name system.parts reports
- skip_disks skips a cache disk and the disk it wraps by either name
- rebalance, the dry-run estimate of create and the hardlink of existing
  parts in download match system.parts.disk_name the same way

The FREEZE path doesn't use system.parts.disk_name and was not affected:
an object disk with local metadata behind a cache disk is backed up on
26.8 by 2.8.3 as well.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Slach Slach added this to the 2.8.4 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants