Skip to content

Clickhouse TTL misleading #47462

@safaci2000

Description

@safaci2000

Component(s)

exporter/clickhouse

Is your feature request related to a problem? Please describe.

Please correct me if any of this is incorrect.

Currently the TTL only applies if you use create_schema: true, otherwise it's essentially ignored. Also, if the value is changed, then it won't be reflected on the DB.

Describe the solution you'd like

I would like to suggest either we:

  1. Update the code to run an ALTER TABLE ... ON CLUSTER .... when the collector comes up against the cluster to ensure the TTL is respected.
  2. Update the config to reflect the fact that the ttl is a bootstrap setting.

If a user looks at the config they would assume that all those settings would carry over rather than being silently ignored.

Describe alternatives you've considered

No response

Additional context

A few more notes, according to the docs The query is executed locally on the host and then the query is written by the host to ZK. I believe this should be fairly safe but you might run into the same SQL being executed multiple times. Alternatively you could run something like:

Disclaimer, AI assisted and needs further validation.

-- Step 1: Suppress full rewrite during the ALTER
ALTER TABLE my_table ON CLUSTER my_cluster
  MODIFY SETTING materialize_ttl_recalculate_only = 1;

-- Step 2: Apply the TTL change (lightweight, only updates ttl.txt)
ALTER TABLE my_table ON CLUSTER my_cluster
  MODIFY TTL event_time + INTERVAL 90 DAY;

-- Step 3: Reset the setting back to default
ALTER TABLE my_table ON CLUSTER my_cluster
  RESET SETTING materialize_ttl_recalculate_only;
--OR
-- Step 3:
ALTER TABLE my_table ON CLUSTER my_cluster
  MODIFY SETTING materialize_ttl_recalculate_only = 0;

-- Step 4: NOW actually apply TTL to existing data
ALTER TABLE my_table ON CLUSTER my_cluster
  MATERIALIZE TTL;

Where existing data is not updated (heavy operation) and only the meta data is updated which is a very easy and light operation.

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions