Skip to content

restore_schema_on_cluster: LIVE VIEW and WINDOW VIEW restored without ON CLUSTER #1423

Description

@wangyelei

Summary

When restore_schema_on_cluster is configured, some view types (LIVE VIEW, WINDOW VIEW) are restored without ON CLUSTER, causing them to only be created on the current node and failing subsequent data restore.

Environment

  • ClickHouse: 25.4.4
  • clickhouse-backup: 2.7.0
  • Config: restore_schema_on_cluster: 'default'

Restore log (schema phase)

10 DDL statements logged. 8 have ON CLUSTER 'default' — but 2 are missing it:

Missing ON CLUSTER — LINE 1:

ATTACH LIVE VIEW test.daily_sales_live UUID '8190d585-7a31-4920-808a-be163dc164d8' (`event_date` UInt32, `sku_id` String, `total_sales` Decimal(38, 2)) AS SELECT ...

Missing ON CLUSTER — LINE 5:

ATTACH WINDOW VIEW test.wv UUID '6b87827c-f223-40d6-9cff-252a7f41655f' (`total` Decimal(38, 2), `w_start` DateTime) ENGINE = MergeTree ORDER BY total SETTINGS index_granularity = 8192 AS SELECT ...

All other types (MATERIALIZED VIEW ... TO, CREATE VIEW, CREATE DICTIONARY, CREATE TABLE) correctly got ON CLUSTER 'default'.

Fatal error during data restore

Because LIVE VIEW and WINDOW VIEW were only created on the local node, data restore fails:

FTL RestoreData: 'test.daily_sales_live', 'test.wv' is not created. Restore schema first or create missing tables manually

Root cause

enrichQueryWithOnCluster() in pkg/clickhouse/clickhouse.go uses regexes createViewRe / attachViewRe whose first capture group [^(]+ stops at the ( in UUID-quoted values and column definitions. The ( causes the regex to fail to reach AS SELECT, so ON CLUSTER is never injected.

Fix

PR: #1422

Change [^(]+ to .+? (lazy match) in createViewRe and attachViewRe, allowing the regex to skip past UUID and parenthesized column definitions to find AS SELECT.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions