Skip to content

Commit a2d59ec

Browse files
committed
Merge branch 'main' of https://github.com/ClickHouse/clickhouse-docs into update_links_other_functions
2 parents 1836b91 + bcffa27 commit a2d59ec

File tree

37 files changed

+653
-527
lines changed

37 files changed

+653
-527
lines changed

docs/cloud/features/04_infrastructure/automatic_scaling.md renamed to docs/cloud/features/04_infrastructure/automatic_scaling/01_auto_scaling.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ For Enterprise tier services scaling works as follows:
3838
- Custom profiles (`highMemory` and `highCPU`) do not support vertical autoscaling or manual vertical scaling. However, these services can be scaled vertically by contacting support.
3939

4040
:::note
41-
Scaling in ClickHouse Cloud happens in what we call "Make Before Break" (MBB) approach. This adds one or more replicas of the new size before removing the old replicas, preventing any loss of capacity during scaling operations. By eliminating the gap between removing existing replicas and adding new ones, MBB creates a more seamless and less disruptive scaling process. It is especially beneficial in scale-up scenarios, where high resource utilization triggers the need for additional capacity, since removing replicas prematurely would only exacerbate the resource constraints. As part of this approach we wait up to an hour to let any existing queries complete on the older replicas before we will remove them. This balances the need for existing queries to complete, while at the same time ensuring that older replicas do not linger around for too long.
41+
Scaling in ClickHouse Cloud happens in what we call a ["Make Before Break" (MBB)](/cloud/features/mbb) approach.
42+
This adds one or more replicas of the new size before removing the old replicas, preventing any loss of capacity during scaling operations.
43+
By eliminating the gap between removing existing replicas and adding new ones, MBB creates a more seamless and less disruptive scaling process.
44+
It is especially beneficial in scale-up scenarios, where high resource utilization triggers the need for additional capacity, since removing replicas prematurely would only exacerbate the resource constraints.
45+
As part of this approach, we wait up to an hour to let any existing queries complete on the older replicas before removing them.
46+
This balances the need for existing queries to complete, while at the same time ensuring that older replicas do not linger around for too long.
4247

4348
Please note that as part of this change:
44-
1. Historical system table data will be retained for up to a maximum of 30 days as part of scaling events. In addition, any system table data older than December 19, 2024, for services on AWS or GCP and older than January 14, 2025, for services on Azure will not be retained as part of the migration to the new organization tiers.
49+
1. Historical system table data is retained for up to a maximum of 30 days as part of scaling events. In addition, any system table data older than December 19, 2024, for services on AWS or GCP and older than January 14, 2025, for services on Azure will not be retained as part of the migration to the new organization tiers.
4550
2. For services utilizing TDE (Transparent Data Encryption) system table data is currently not maintained after MBB operations. We are working on removing this limitation.
4651
:::
4752

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
sidebar_position: 1
3+
sidebar_label: 'Make Before Break (MBB)'
4+
slug: /cloud/features/mbb
5+
description: 'Page describing Make Before Break (MBB) operations in ClickHouse Cloud'
6+
keywords: ['Make Before Break', 'MBB', 'Scaling', 'ClickHouse Cloud']
7+
title: 'Make Before Break (MBB) operations in ClickHouse Cloud'
8+
doc_type: 'guide'
9+
---
10+
11+
import Image from '@theme/IdealImage';
12+
import mbb_diagram from '@site/static/images/cloud/features/mbb/vertical_scaling.png';
13+
14+
ClickHouse Cloud performs cluster upgrades and cluster scaling utilizing a **Make Before Break** (MBB) approach.
15+
In this approach, new replicas are added to the cluster before removing old replicas from it.
16+
This is as opposed to the break-first approach, where old replicas would first be removed, before adding new ones.
17+
18+
The MBB approach has several benefits:
19+
* Since capacity is added to the cluster before removal, the **overall cluster capacity does not go down** unlike with the break-first approach. Of course, unplanned events such as node or disk failures etc. can still happen in a cloud environment.
20+
* This approach is especially useful in situations where the cluster is under heavy load as it **prevents existing replicas from being overloaded** as would happen with a break-first approach.
21+
* Because replicas can be added quickly without having to wait to remove replicas first, this approach leads to a **faster, more responsive** scaling experience.
22+
23+
The image below shows how this might happen for a cluster with 3 replicas where the service is scaled vertically:
24+
25+
<Image img={mbb_diagram} size="lg" alt="Example diagram for a cluster with 3 replicas which gets vertically scaled" />
26+
27+
Overall, MBB leads to a seamless, less disruptive scaling and upgrade experience compared to the break-first approach previously utilized.
28+
29+
With MBB, there are some key behaviors that users need to be aware of:
30+
31+
1. MBB operations wait for existing workloads to finish on the current replicas before being terminated.
32+
This period is currently set to 1 hour, which means that scaling or upgrades can wait up to one hour for a long-running query on a replica before the replica is removed.
33+
Additionally, if a backup process is running on a replica, it is left to complete before the replica is terminated.
34+
2. Due to the fact that there is a waiting time before a replica is terminated, there can be situations where a cluster might have more than the maximum number of replicas set for the cluster.
35+
For example, you might have a service with 6 total replicas, but with an MBB operation in progress, 3 additional replicas may get added to the cluster leading to a total of 9 replicas, while the older replicas are still serving queries.
36+
This means that for a period of time, the cluster will have more than the desired number of replicas.
37+
Additionally, multiple MBB operations themselves can overlap, leading to replica accumulation. This can happen, for instance, in scenarios where several vertical scaling requests are sent to the cluster via the API.
38+
ClickHouse Cloud has checks in place to restrict the number of replicas that a cluster might accumulate.
39+
3. With MBB operations, system table data is kept for 30 days. This means every time an MBB operation happens on a cluster, 30 days worth of system table data is replicated from the old replicas to the new ones.
40+
41+
If you are interested in learning more about the mechanics of MBB operations, please look at this [blog post](https://clickhouse.com/blog/make-before-break-faster-scaling-mechanics-for-clickhouse-cloud) from the ClickHouse engineering team.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"label": "Automatic Scaling",
3+
"collapsible": true,
4+
"collapsed": true,
5+
}

docs/cloud/features/08_backups/overview.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ After you have successfully inserted the data into your original service, make s
154154

155155
## Undeleting or undropping tables {#undeleting-or-undropping-tables}
156156

157-
<CloudNotSupportedBadge/>
158-
159-
The `UNDROP` command is not supported in ClickHouse Cloud. If you accidentally `DROP` a table, the best course of action is to restore your last backup and recreate the table from the backup.
157+
The `UNDROP` command is supported in ClickHouse Cloud through [Shared Catalog](https://clickhouse.com/docs/cloud/reference/shared-catalog).
160158

161159
To prevent users from accidentally dropping tables, you can use [`GRANT` statements](/sql-reference/statements/grant) to revoke permissions for the [`DROP TABLE` command](/sql-reference/statements/drop#drop-table) for a specific user or role.
162160

docs/cloud/reference/02_architecture.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ description: 'This page describes the architecture of ClickHouse Cloud'
66
doc_type: 'reference'
77
---
88

9-
import Architecture from '@site/static/images/cloud/reference/architecture.svg';
9+
import Image from '@theme/IdealImage';
10+
import Architecture from '@site/static/images/cloud/reference/architecture.png';
1011

1112
# ClickHouse Cloud architecture
1213

13-
<Architecture alt='ClickHouse Cloud architecture' class='image' />
14+
<Image img={Architecture} size='lg' alt='Cloud architecture'/>
1415

1516
## Storage backed by object store {#storage-backed-by-object-store}
1617
- Virtually unlimited storage

docs/integrations/data-ingestion/etl-tools/dbt/features-and-configurations.md

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,41 @@ dbt relies on a read-after-insert consistency model. This is not compatible with
144144
| settings | A map/dictionary of "TABLE" settings to be used to DDL statements like 'CREATE TABLE' with this model | |
145145
| query_settings | A map/dictionary of ClickHouse user level settings to be used with `INSERT` or `DELETE` statements in conjunction with this model | |
146146
| ttl | A TTL expression to be used with the table. The TTL expression is a string that can be used to specify the TTL for the table. | |
147-
| indexes | A list of indexes to create, available only for `table` materialization. For examples look at ([#397](https://github.com/ClickHouse/dbt-clickhouse/pull/397)) | |
148-
| sql_security | Allow you to specify which ClickHouse user to use when executing the view's underlying query. [`SQL SECURITY`](https://clickhouse.com/docs/sql-reference/statements/create/view#sql_security) has two legal values`definer` `invoker`. | |
147+
| indexes | A list of [data skipping indexes to create](/optimize/skipping-indexes). Check below for more information. | |
148+
| sql_security | Allow you to specify which ClickHouse user to use when executing the view's underlying query. `SQL SECURITY` [has two legal values](/sql-reference/statements/create/view#sql_security)`definer` `invoker`. | |
149149
| definer | If `sql_security` was set to `definer`, you have to specify any existing user or `CURRENT_USER` in the `definer` clause. | |
150+
| projections | A list of [projections](/data-modeling/projections) to be created. Check [About projections](#projections) for details. | |
151+
152+
#### About data skipping indexes {#data-skipping-indexes}
153+
154+
Data skipping indexes are only available for the `table` materialization. To add a list of data skipping indexes to a table, use the `indexes` configuration:
155+
156+
```sql
157+
{{ config(
158+
materialized='table',
159+
indexes=[{
160+
'name': 'your_index_name',
161+
'definition': 'your_column TYPE minmax GRANULARITY 2'
162+
}]
163+
) }}
164+
```
165+
166+
#### About projections {#projections}
167+
168+
You can add [projections](/data-modeling/projections) to `table` and `distributed_table` materializations using the `projections` configuration:
169+
170+
```sql
171+
{{ config(
172+
materialized='table',
173+
projections=[
174+
{
175+
'name': 'your_projection_name',
176+
'query': 'SELECT department, avg(age) AS avg_age GROUP BY department'
177+
}
178+
]
179+
) }}
180+
```
181+
**Note**: For distributed tables, the projection is applied to the `_local` tables, not to the distributed proxy table.
150182

151183
### Supported table engines {#supported-table-engines}
152184

@@ -191,7 +223,7 @@ should be carefully researched and tested.
191223
| codec | A string consisting of arguments passed to `CODEC()` in the column's DDL. For example: `codec: "Delta, ZSTD"` will be compiled as `CODEC(Delta, ZSTD)`. |
192224
| ttl | A string consisting of a [TTL (time-to-live) expression](https://clickhouse.com/docs/guides/developer/ttl) that defines a TTL rule in the column's DDL. For example: `ttl: ts + INTERVAL 1 DAY` will be compiled as `TTL ts + INTERVAL 1 DAY`. |
193225

194-
#### Example {#example}
226+
#### Example of schema configuration {#example-of-schema-configuration}
195227

196228
```yaml
197229
models:
@@ -209,6 +241,30 @@ models:
209241
ttl: ts + INTERVAL 1 DAY
210242
```
211243
244+
#### Adding complex types {#adding-complex-types}
245+
246+
dbt automatically determines the data type of each column by analyzing the SQL used to create the model. However, in some cases this process may not accurately determine the data type, leading to conflicts with the types specified in the contract `data_type` property. To address this, we recommend using the `CAST()` function in the model SQL to explicitly define the desired type. For example:
247+
248+
```sql
249+
{{
250+
config(
251+
materialized="materialized_view",
252+
engine="AggregatingMergeTree",
253+
order_by=["event_type"],
254+
)
255+
}}
256+
257+
select
258+
-- event_type may be infered as a String but we may prefer LowCardinality(String):
259+
CAST(event_type, 'LowCardinality(String)') as event_type,
260+
-- countState() may be infered as `AggregateFunction(count)` but we may prefer to change the type of the argument used:
261+
CAST(countState(), 'AggregateFunction(count, UInt32)') as response_count,
262+
-- maxSimpleState() may be infered as `SimpleAggregateFunction(max, String)` but we may prefer to also change the type of the argument used:
263+
CAST(maxSimpleState(event_type), 'SimpleAggregateFunction(max, LowCardinality(String))') as max_event_type
264+
from {{ ref('user_events') }}
265+
group by event_type
266+
```
267+
212268
## Features {#features}
213269

214270
### Materialization: view {#materialization-view}

docs/integrations/data-ingestion/etl-tools/dbt/index.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ List of supported features:
4141
- [x] Distributed table materialization (experimental)
4242
- [x] Distributed incremental materialization (experimental)
4343
- [x] Contracts
44+
- [x] ClickHouse-specific column configurations (Codec, TTL...)
45+
- [x] ClickHouse-specific table settings (indexes, projections...)
4446

4547
All features up to dbt-core 1.9 are supported. We will soon add the features added in dbt-core 1.10.
4648

@@ -125,7 +127,36 @@ Execute `dbt debug` with the CLI tool to confirm whether dbt is able to connect
125127

126128
Go to the [guides page](/integrations/dbt/guides) to learn more about how to use dbt with ClickHouse.
127129

128-
## Troubleshooting Connections {#troubleshooting-connections}
130+
### Testing and Deploying your models (CI/CD) {#testing-and-deploying-your-models-ci-cd}
131+
132+
There are many ways to test and deploy your dbt project. dbt has some suggestions for [best practice workflows](https://docs.getdbt.com/best-practices/best-practice-workflows#pro-tips-for-workflows) and [CI jobs](https://docs.getdbt.com/docs/deploy/ci-jobs). We are going to discuss several strategies, but keep in mind that these strategies may need to be deeply adjusted to fit your specific use case.
133+
134+
#### CI/CD with simple data tests and unit tests {#ci-with-simple-data-tests-and-unit-tests}
135+
136+
One simple way to kick-start your CI pipeline is to run a ClickHouse cluster inside your job and then run your models against it. You can insert demo data into this cluster before running your models. You can just use a [seed](https://docs.getdbt.com/reference/commands/seed) to populate the staging environment with a subset of your production data.
137+
138+
Once the data is inserted, you can then run your [data tests](https://docs.getdbt.com/docs/build/data-tests) and your [unit tests](https://docs.getdbt.com/docs/build/unit-tests).
139+
140+
Your CD step can be as simple as running `dbt build` against your production ClickHouse cluster.
141+
142+
#### More complete CI/CD stage: Use recent data, only test affected models {#more-complete-ci-stage}
143+
144+
One common strategy is to use [Slim CI](https://docs.getdbt.com/best-practices/best-practice-workflows#run-only-modified-models-to-test-changes-slim-ci) jobs, where only the modified models (and their up- and downstream dependencies) are re-deployed. This approach uses artifacts from your production runs (i.e., the [dbt manifest](https://docs.getdbt.com/reference/artifacts/manifest-json)) to reduce the run time of your project and ensure there is no schema drift across environments.
145+
146+
To keep your development environments in sync and avoid running your models against stale deployments, you can use [clone](https://docs.getdbt.com/reference/commands/clone) or even [defer](https://docs.getdbt.com/reference/node-selection/defer).
147+
148+
We recommend using a dedicated ClickHouse cluster or service for the testing environment (i.e., a staging environment) to avoid impacting the operation of your production environment. To ensure the testing environment is representative, it's important that you use a subset of your production data, as well as run dbt in a way that prevents schema drift between environments.
149+
150+
- If you don't need fresh data to test against, you can restore a backup of your production data into the staging environment.
151+
- If you need fresh data to test against, you can use a combination of the [`remoteSecure()` table function](/sql-reference/table-functions/remote) and refreshable materialized views to insert at the desired frequency. Another option is to use object storage as an intermediate and periodically write data from your production service, then import it into the staging environment using the object storage table functions or ClickPipes (for continuous ingestion).
152+
153+
Using a dedicated environment for CI testing also allows you to perform manual testing without impacting your production environment. For example, you may want to point a BI tool to this environment for testing.
154+
155+
For deployment (i.e., the CD step), we recommend using the artifacts from your production deployments to only update the models that have changed. This requires setting up object storage (e.g., S3) as intermediate storage for your dbt artifacts. Once that is set up, you can run a command like `dbt build --select state:modified+ --state path/to/last/deploy/state.json` to selectively rebuild the minimum amount of models needed based on what changed since the last run in production.
156+
157+
## Troubleshooting common issues {#troubleshooting-common-issues}
158+
159+
### Connections {#troubleshooting-connections}
129160

130161
If you encounter issues connecting to ClickHouse from dbt, make sure the following criteria are met:
131162

@@ -134,6 +165,10 @@ If you encounter issues connecting to ClickHouse from dbt, make sure the followi
134165
- If you're not using the default table engine for the database, you must specify a table engine in your model
135166
configuration.
136167

168+
### Understanding long-running operations {#understanding-long-running-operations}
169+
170+
Some operations may take longer than expected due to specific ClickHouse queries. To gain more insight into which queries are taking longer, increase the [log level](https://docs.getdbt.com/reference/global-configs/logs#log-level) to `debug` — this will print the time used by each query. For example, this can be achieved by appending `--log-level debug` to dbt commands.
171+
137172
## Limitations {#limitations}
138173

139174
The current ClickHouse adapter for dbt has several limitations users should be aware of:

0 commit comments

Comments
 (0)