@fjall/components-infrastructure 39.1.0 → 39.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/patterns/aws/clickhouseDatabase.d.ts +20 -4
- package/dist/lib/patterns/aws/clickhouseDatabase.js +16 -7
- package/dist/lib/patterns/aws/database.d.ts +2 -2
- package/dist/lib/resources/aws/database/clickhouseConstants.d.ts +6 -4
- package/dist/lib/resources/aws/database/clickhouseConstants.js +6 -4
- package/dist/lib/resources/aws/database/clickhouseOptimiseScript.d.ts +47 -7
- package/dist/lib/resources/aws/database/clickhouseOptimiseScript.js +41 -14
- package/package.json +3 -3
|
@@ -4,6 +4,7 @@ import { type IBucket } from "aws-cdk-lib/aws-s3";
|
|
|
4
4
|
import { Construct } from "constructs";
|
|
5
5
|
import { Secret, type SecretImport } from "../../resources/aws/secrets/secret.js";
|
|
6
6
|
import { type BackupTier } from "../../utils/backupTierMapping.js";
|
|
7
|
+
import { type ClickHouseOptimiseTables } from "../../resources/aws/database/clickhouseOptimiseScript.js";
|
|
7
8
|
import { type ClickHouseAlarmThresholds } from "../../resources/aws/monitoring/index.js";
|
|
8
9
|
import { type ClickHouseSchemaAdmin, type ProfileSpec } from "../../resources/aws/database/clickhouseSchemas.js";
|
|
9
10
|
import { type ISecret } from "aws-cdk-lib/aws-secretsmanager";
|
|
@@ -152,11 +153,22 @@ export interface ClickHouseDatabaseProps {
|
|
|
152
153
|
/** Tier 4 escape hatch (D16): bring-your-own cold-tier bucket. */
|
|
153
154
|
coldTierBucket?: IBucket;
|
|
154
155
|
/**
|
|
155
|
-
*
|
|
156
|
-
* `Schedule.expression(...)`
|
|
156
|
+
* When the optimise sidecar runs (D19), while `optimiseTables` names a
|
|
157
|
+
* table. CDK's `Schedule.expression(...)` reads the string at synth only
|
|
158
|
+
* while the sidecar exists. `false` disables the sidecar.
|
|
157
159
|
* Default: `OPTIMISE_FINAL_SCHEDULE` from `clickhouseConstants.ts`.
|
|
158
160
|
*/
|
|
159
161
|
optimiseSchedule?: string | false;
|
|
162
|
+
/**
|
|
163
|
+
* The tables the optimise sidecar merges (FJL-2911). Left out, the sidecar
|
|
164
|
+
* merges the Fjall web app's own tables, `REPLACING_MERGE_TREE_TABLES` and
|
|
165
|
+
* `OPTIMISE_MV_TABLES`, and a database without them fails, and pages, on
|
|
166
|
+
* every run. Set, it names the only tables merged, and a list it leaves out
|
|
167
|
+
* is empty. A value that names no table, such as `{}`, removes the sidecar,
|
|
168
|
+
* its task log group and its maintenance filters. 40.0.0 names none by
|
|
169
|
+
* default.
|
|
170
|
+
*/
|
|
171
|
+
optimiseTables?: ClickHouseOptimiseTables;
|
|
160
172
|
/**
|
|
161
173
|
* BACKUP DATABASE TO S3 schedule (D19). Schedule string validated by CDK
|
|
162
174
|
* `Schedule.expression(...)` at synth time. `false` disables the sidecar
|
|
@@ -309,12 +321,16 @@ export interface ClickHouseDatabaseProps {
|
|
|
309
321
|
* `alarms:` from the patterns layer (same convention as `ServiceLogAlarm`).
|
|
310
322
|
*/
|
|
311
323
|
export type { ClickHouseAlarmThresholds };
|
|
324
|
+
/** Public re-export of the optimise sidecar's table lists, so factory
|
|
325
|
+
* consumers can type `optimiseTables:` from the patterns layer. */
|
|
326
|
+
export type { ClickHouseOptimiseTables };
|
|
312
327
|
/**
|
|
313
328
|
* ClickHouse analytics database wrapper implementing IClickHouseDatabase.
|
|
314
329
|
*
|
|
315
330
|
* Composes `EcsCompute` directly per Phase 5e D7 — one EC2-pinned service
|
|
316
|
-
* (single-instance, AWS_VPC mode, Cloud Map registered) plus
|
|
317
|
-
*
|
|
331
|
+
* (single-instance, AWS_VPC mode, Cloud Map registered) plus a scheduled
|
|
332
|
+
* backup task, and a scheduled optimise task while `optimiseTables` names a
|
|
333
|
+
* table. Per-role secrets, dual S3 buckets, and 10
|
|
318
334
|
* CfnOutputs are owned by `ClickHouseDatabase` itself; every taggable
|
|
319
335
|
* resource routes through its Fjall wrapper (AC45d-g).
|
|
320
336
|
*/
|
|
@@ -18,7 +18,7 @@ import { LogGroup } from "../../resources/aws/logging/logGroup.js";
|
|
|
18
18
|
import { StackEncryptionKey } from "../../resources/aws/secrets/stackEncryptionKey.js";
|
|
19
19
|
import { createClickHouseSecurityGroup } from "../../resources/aws/database/clickhouseSecurityGroup.js";
|
|
20
20
|
import { buildMaintenancePreamble } from "../../resources/aws/database/clickhouseMaintenanceScript.js";
|
|
21
|
-
import { buildClickHouseOptimiseScript } from "../../resources/aws/database/clickhouseOptimiseScript.js";
|
|
21
|
+
import { buildClickHouseOptimiseScript, refuseOffShapeOptimiseTables } from "../../resources/aws/database/clickhouseOptimiseScript.js";
|
|
22
22
|
import { buildClickHouseEntrypointWrapper, buildClickHouseUserData, generateUsersConfigXml } from "../../resources/aws/database/clickhouseUserData.js";
|
|
23
23
|
import { toPascalCase } from "../../utils/capitaliseString.js";
|
|
24
24
|
import { resolveAlertsTopic } from "../../utils/resolveAlertsTopic.js";
|
|
@@ -187,8 +187,9 @@ function createClickHouseUserSecret(scope, name) {
|
|
|
187
187
|
* ClickHouse analytics database wrapper implementing IClickHouseDatabase.
|
|
188
188
|
*
|
|
189
189
|
* Composes `EcsCompute` directly per Phase 5e D7 — one EC2-pinned service
|
|
190
|
-
* (single-instance, AWS_VPC mode, Cloud Map registered) plus
|
|
191
|
-
*
|
|
190
|
+
* (single-instance, AWS_VPC mode, Cloud Map registered) plus a scheduled
|
|
191
|
+
* backup task, and a scheduled optimise task while `optimiseTables` names a
|
|
192
|
+
* table. Per-role secrets, dual S3 buckets, and 10
|
|
192
193
|
* CfnOutputs are owned by `ClickHouseDatabase` itself; every taggable
|
|
193
194
|
* resource routes through its Fjall wrapper (AC45d-g).
|
|
194
195
|
*/
|
|
@@ -289,7 +290,15 @@ export class ClickHouseDatabase extends Construct {
|
|
|
289
290
|
...managedPasswords
|
|
290
291
|
];
|
|
291
292
|
const desiredCount = resolveClickHouseDesiredCount(this.node.tryGetContext("clickhouseDesiredCount"), props.desiredCount);
|
|
292
|
-
|
|
293
|
+
refuseOffShapeOptimiseTables(id, props.optimiseTables ?? {});
|
|
294
|
+
const optimiseTables = props.optimiseTables ?? {
|
|
295
|
+
replacingMergeTree: REPLACING_MERGE_TREE_TABLES,
|
|
296
|
+
compact: OPTIMISE_MV_TABLES
|
|
297
|
+
};
|
|
298
|
+
const optimiseReplacingTables = optimiseTables.replacingMergeTree ?? [];
|
|
299
|
+
const optimiseCompactTables = optimiseTables.compact ?? [];
|
|
300
|
+
const optimiseEnabled = props.optimiseSchedule !== false &&
|
|
301
|
+
optimiseReplacingTables.length + optimiseCompactTables.length > 0;
|
|
293
302
|
const backupEnabled = props.backupSchedule !== false;
|
|
294
303
|
const backupVerifyEnabled = props.backupVerify !== false;
|
|
295
304
|
const optimiseSchedule = typeof props.optimiseSchedule === "string"
|
|
@@ -482,7 +491,7 @@ export class ClickHouseDatabase extends Construct {
|
|
|
482
491
|
: {};
|
|
483
492
|
// One clickhouse-client invocation per statement: a single multi-statement
|
|
484
493
|
// --query aborts on the first failure, so one missing table (a migration
|
|
485
|
-
// deploy-order window, or a dropped table
|
|
494
|
+
// deploy-order window, or a dropped table still named in optimiseTables)
|
|
486
495
|
// would permanently skip every optimise after it. Each failure emits its
|
|
487
496
|
// own status marker and the task still exits non-zero so they stay
|
|
488
497
|
// visible in the task history. Both scheduled tasks authenticate as the
|
|
@@ -495,8 +504,8 @@ export class ClickHouseDatabase extends Construct {
|
|
|
495
504
|
const backupClient = `${clickHouseClient} --receive_timeout=${clickHouseBackupVerifyTimeoutSeconds(storageGb)}`;
|
|
496
505
|
const optimiseScript = buildClickHouseOptimiseScript({
|
|
497
506
|
databaseName: CLICKHOUSE_DATABASE_NAME,
|
|
498
|
-
replacingTables:
|
|
499
|
-
mvTables:
|
|
507
|
+
replacingTables: optimiseReplacingTables,
|
|
508
|
+
mvTables: optimiseCompactTables
|
|
500
509
|
});
|
|
501
510
|
const optimisePreamble = buildMaintenancePreamble({
|
|
502
511
|
client: optimiseClient,
|
|
@@ -4,7 +4,7 @@ import type { ITopic } from "aws-cdk-lib/aws-sns";
|
|
|
4
4
|
import type { RdsAlarmThresholds } from "../../resources/aws/monitoring/index.js";
|
|
5
5
|
import type App from "../../app.js";
|
|
6
6
|
import { type DynamoDBKeySchema, type DynamoDBGlobalSecondaryIndex } from "../../resources/aws/database/dynamodb.js";
|
|
7
|
-
import { ClickHouseDatabase, type ClickHouseDatabaseProps, type ClickHouseAlarmThresholds } from "./clickhouseDatabase.js";
|
|
7
|
+
import { ClickHouseDatabase, type ClickHouseDatabaseProps, type ClickHouseAlarmThresholds, type ClickHouseOptimiseTables } from "./clickhouseDatabase.js";
|
|
8
8
|
import { type BackupTier } from "../../utils/backupTierMapping.js";
|
|
9
9
|
import { type Connections, type IConnectable, type IVpc } from "aws-cdk-lib/aws-ec2";
|
|
10
10
|
import { type ITable } from "aws-cdk-lib/aws-dynamodb";
|
|
@@ -350,7 +350,7 @@ export declare class RelationalDatabase extends Construct implements IRelational
|
|
|
350
350
|
*/
|
|
351
351
|
grantIamConnect(grantee: IGrantable, dbUsername: string): Grant;
|
|
352
352
|
}
|
|
353
|
-
export { ClickHouseDatabase, type ClickHouseDatabaseProps, type ClickHouseAlarmThresholds };
|
|
353
|
+
export { ClickHouseDatabase, type ClickHouseDatabaseProps, type ClickHouseAlarmThresholds, type ClickHouseOptimiseTables };
|
|
354
354
|
export { ClickHouseDefaultProfiles, ClickHouseSchemaAdminSchema, ManagedPasswordNameSchema, ProfileSpecSchema, SettingConstraintSchema, type ClickHouseSchemaAdmin, type FrozenProfileSpec, type ManagedPasswordName, type ProfileSpec, type SettingConstraint } from "../../resources/aws/database/clickhouseSchemas.js";
|
|
355
355
|
export { renderUsersXml } from "../../resources/aws/database/clickhouseXmlRenderer.js";
|
|
356
356
|
export type { RenderUsersXmlOptions } from "../../resources/aws/database/clickhouseXmlRenderer.js";
|
|
@@ -282,7 +282,8 @@ export declare const CLICKHOUSE_DEFAULT_DISK_NAME = "default";
|
|
|
282
282
|
* about five times the worst observed. */
|
|
283
283
|
export declare const OPTIMISE_STATEMENT_RECEIVE_TIMEOUT_SECONDS = 1200;
|
|
284
284
|
/** ReplacingMergeTree tables the optimise task settles, partition by
|
|
285
|
-
* partition (`buildClickHouseOptimiseScript`)
|
|
285
|
+
* partition (`buildClickHouseOptimiseScript`), for a database that leaves
|
|
286
|
+
* `optimiseTables` out.
|
|
286
287
|
*
|
|
287
288
|
* Coupled with the webapp, whose tenant table manifest marks the same tables
|
|
288
289
|
* `replacingMergeTree`; a webapp test compares the two lists, reading this
|
|
@@ -315,9 +316,10 @@ export declare const CLICKHOUSE_SERVICE_NAME = "ClickHouseService";
|
|
|
315
316
|
* These are not ReplacingMergeTree (no dedup needed) but un-merged parts force
|
|
316
317
|
* read-time aggregation which degrades query performance.
|
|
317
318
|
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
319
|
+
* They are the `compact` list for a database that leaves `optimiseTables`
|
|
320
|
+
* out, so every name here must exist in such a database's live schema. A
|
|
321
|
+
* database that names its own lists can drop a table without a fjall release
|
|
322
|
+
* (FJL-2911). */
|
|
321
323
|
export declare const OPTIMISE_MV_TABLES: readonly ["metrics_hourly_mv", "metrics_daily_mv", "response_time_quantiles_hourly_mv", "deployment_duration_quantiles_daily_mv", "compliance_score_daily_mv", "ai_usage_daily_mv", "finding_daily_aggregate", "insight_pattern_dismissals"];
|
|
322
324
|
/** Resource allocation for the lightweight optimise task. */
|
|
323
325
|
export declare const OPTIMISE_TASK_MEMORY_MIB = 256;
|
|
@@ -308,7 +308,8 @@ export const CLICKHOUSE_DEFAULT_DISK_NAME = "default";
|
|
|
308
308
|
* about five times the worst observed. */
|
|
309
309
|
export const OPTIMISE_STATEMENT_RECEIVE_TIMEOUT_SECONDS = 1200;
|
|
310
310
|
/** ReplacingMergeTree tables the optimise task settles, partition by
|
|
311
|
-
* partition (`buildClickHouseOptimiseScript`)
|
|
311
|
+
* partition (`buildClickHouseOptimiseScript`), for a database that leaves
|
|
312
|
+
* `optimiseTables` out.
|
|
312
313
|
*
|
|
313
314
|
* Coupled with the webapp, whose tenant table manifest marks the same tables
|
|
314
315
|
* `replacingMergeTree`; a webapp test compares the two lists, reading this
|
|
@@ -348,9 +349,10 @@ export const CLICKHOUSE_SERVICE_NAME = "ClickHouseService";
|
|
|
348
349
|
* These are not ReplacingMergeTree (no dedup needed) but un-merged parts force
|
|
349
350
|
* read-time aggregation which degrades query performance.
|
|
350
351
|
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
352
|
+
* They are the `compact` list for a database that leaves `optimiseTables`
|
|
353
|
+
* out, so every name here must exist in such a database's live schema. A
|
|
354
|
+
* database that names its own lists can drop a table without a fjall release
|
|
355
|
+
* (FJL-2911). */
|
|
354
356
|
export const OPTIMISE_MV_TABLES = [
|
|
355
357
|
"metrics_hourly_mv",
|
|
356
358
|
"metrics_daily_mv",
|
|
@@ -41,8 +41,9 @@
|
|
|
41
41
|
* - `skip_projections`: the parts carry different projection sets, which the
|
|
42
42
|
* engine refuses to merge together (Code 388). The job says so rather than
|
|
43
43
|
* issuing a statement that could only report a no-op as success.
|
|
44
|
-
* - `skip_partition_id`: the partition id
|
|
45
|
-
*
|
|
44
|
+
* - `skip_partition_id`: the partition id holds a character other than a
|
|
45
|
+
* digit, a letter, `_` or `-` (`PARTITION_ID_CHARACTERS`), so the job will
|
|
46
|
+
* not place it inside a statement.
|
|
46
47
|
*
|
|
47
48
|
* A partition the job skips is logged every run as a
|
|
48
49
|
* `fjall:maintenance:skipped` line. It is never a status marker: it neither
|
|
@@ -51,8 +52,8 @@
|
|
|
51
52
|
* A listed ReplacingMergeTree table that does not exist fails the job with
|
|
52
53
|
* `cause=missing_table`, naming the table. The enumeration alone would read a
|
|
53
54
|
* missing table as one with nothing to settle, and a dropped table left in
|
|
54
|
-
*
|
|
55
|
-
* raised `UNKNOWN_TABLE`. A missing materialised view still fails through its
|
|
55
|
+
* `optimiseTables` must stay as visible as it was when the whole-table
|
|
56
|
+
* statement raised `UNKNOWN_TABLE`. A missing materialised view still fails through its
|
|
56
57
|
* own statement, as `reason=optimise_<view>`.
|
|
57
58
|
*
|
|
58
59
|
* `sh` only (the image's `/bin/sh` is dash), and nothing relies on `set -e`:
|
|
@@ -79,6 +80,44 @@ export declare const OPTIMISE_PARTITION_ACTION: {
|
|
|
79
80
|
readonly skipProjections: "skip_projections";
|
|
80
81
|
readonly skipPartitionId: "skip_partition_id";
|
|
81
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* The characters a partition id may hold for the sweep to place it inside a
|
|
85
|
+
* statement. It is the body of a bracket expression that the enumeration's
|
|
86
|
+
* RE2 class (`[^…]`) and the shell's `case` pattern (`[!…]`) read the same
|
|
87
|
+
* way, since a trailing `-` is literal in both. On clickhouse-server
|
|
88
|
+
* 26.3.17.56 a date or integer key gives digits, a tuple of them joins its
|
|
89
|
+
* values with `-` (`202611-3`, `202611--5`), a negative integer starts with
|
|
90
|
+
* `-`, and a key holding a string is hashed to hex (FJL-2919).
|
|
91
|
+
*/
|
|
92
|
+
export declare const PARTITION_ID_CHARACTERS = "0-9A-Za-z_-";
|
|
93
|
+
/**
|
|
94
|
+
* The tables a ClickHouse database's optimise task merges, by how it merges
|
|
95
|
+
* them. Each name is a table or view in the database the construct creates
|
|
96
|
+
* (`CLICKHOUSE_DATABASE_NAME`), and matches `^[a-z][a-z0-9_]*$`.
|
|
97
|
+
*/
|
|
98
|
+
export interface ClickHouseOptimiseTables {
|
|
99
|
+
/**
|
|
100
|
+
* ReplacingMergeTree tables. The task settles each partition that holds
|
|
101
|
+
* more than one part, or rows a lightweight delete has masked, with
|
|
102
|
+
* `OPTIMIZE TABLE … PARTITION ID … FINAL`, so rows that share a sorting key
|
|
103
|
+
* collapse into one. It leaves to the engine, and logs, a partition whose id
|
|
104
|
+
* holds a character other than a digit, a letter, `_` or `-`, one whose
|
|
105
|
+
* parts carry different projections, and one with a part off the local disk
|
|
106
|
+
* unless a lightweight delete has masked rows in it.
|
|
107
|
+
*/
|
|
108
|
+
readonly replacingMergeTree?: readonly string[];
|
|
109
|
+
/**
|
|
110
|
+
* Materialised views and any other table whose parts should be merged. The
|
|
111
|
+
* task merges each with a plain `OPTIMIZE TABLE`, without `FINAL`.
|
|
112
|
+
*/
|
|
113
|
+
readonly compact?: readonly string[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Refuses an `optimiseTables` name outside `^[a-z][a-z0-9_]*$`, naming the
|
|
117
|
+
* list and the database it came from. The name itself is withheld, because
|
|
118
|
+
* one that fails the shape could be anything.
|
|
119
|
+
*/
|
|
120
|
+
export declare function refuseOffShapeOptimiseTables(databaseId: string, tables: ClickHouseOptimiseTables): void;
|
|
82
121
|
export interface ClickHouseOptimiseScriptParams {
|
|
83
122
|
/** Database the listed tables live in. */
|
|
84
123
|
readonly databaseName: string;
|
|
@@ -89,8 +128,9 @@ export interface ClickHouseOptimiseScriptParams {
|
|
|
89
128
|
}
|
|
90
129
|
/**
|
|
91
130
|
* The optimise job body, to follow `buildMaintenancePreamble`. Globbing is
|
|
92
|
-
* switched off because the sweep word
|
|
93
|
-
* word is already `
|
|
94
|
-
* `status=ok` only when every table and view settled
|
|
131
|
+
* switched off because the sweep word splits the enumeration's output. Every
|
|
132
|
+
* word is already digits, letters, `_`, `-` and `:`, so this is defence in
|
|
133
|
+
* depth. Exits 0 with `status=ok` only when every table and view settled
|
|
134
|
+
* without a failure.
|
|
95
135
|
*/
|
|
96
136
|
export declare function buildClickHouseOptimiseScript(params: ClickHouseOptimiseScriptParams): string;
|
|
@@ -41,8 +41,9 @@
|
|
|
41
41
|
* - `skip_projections`: the parts carry different projection sets, which the
|
|
42
42
|
* engine refuses to merge together (Code 388). The job says so rather than
|
|
43
43
|
* issuing a statement that could only report a no-op as success.
|
|
44
|
-
* - `skip_partition_id`: the partition id
|
|
45
|
-
*
|
|
44
|
+
* - `skip_partition_id`: the partition id holds a character other than a
|
|
45
|
+
* digit, a letter, `_` or `-` (`PARTITION_ID_CHARACTERS`), so the job will
|
|
46
|
+
* not place it inside a statement.
|
|
46
47
|
*
|
|
47
48
|
* A partition the job skips is logged every run as a
|
|
48
49
|
* `fjall:maintenance:skipped` line. It is never a status marker: it neither
|
|
@@ -51,8 +52,8 @@
|
|
|
51
52
|
* A listed ReplacingMergeTree table that does not exist fails the job with
|
|
52
53
|
* `cause=missing_table`, naming the table. The enumeration alone would read a
|
|
53
54
|
* missing table as one with nothing to settle, and a dropped table left in
|
|
54
|
-
*
|
|
55
|
-
* raised `UNKNOWN_TABLE`. A missing materialised view still fails through its
|
|
55
|
+
* `optimiseTables` must stay as visible as it was when the whole-table
|
|
56
|
+
* statement raised `UNKNOWN_TABLE`. A missing materialised view still fails through its
|
|
56
57
|
* own statement, as `reason=optimise_<view>`.
|
|
57
58
|
*
|
|
58
59
|
* `sh` only (the image's `/bin/sh` is dash), and nothing relies on `set -e`:
|
|
@@ -82,7 +83,32 @@ export const OPTIMISE_PARTITION_ACTION = {
|
|
|
82
83
|
skipProjections: "skip_projections",
|
|
83
84
|
skipPartitionId: "skip_partition_id"
|
|
84
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* The characters a partition id may hold for the sweep to place it inside a
|
|
88
|
+
* statement. It is the body of a bracket expression that the enumeration's
|
|
89
|
+
* RE2 class (`[^…]`) and the shell's `case` pattern (`[!…]`) read the same
|
|
90
|
+
* way, since a trailing `-` is literal in both. On clickhouse-server
|
|
91
|
+
* 26.3.17.56 a date or integer key gives digits, a tuple of them joins its
|
|
92
|
+
* values with `-` (`202611-3`, `202611--5`), a negative integer starts with
|
|
93
|
+
* `-`, and a key holding a string is hashed to hex (FJL-2919).
|
|
94
|
+
*/
|
|
95
|
+
export const PARTITION_ID_CHARACTERS = "0-9A-Za-z_-";
|
|
85
96
|
const IDENTIFIER_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
97
|
+
const OPTIMISE_TABLE_LIST_PRESENCE = { replacingMergeTree: true, compact: true };
|
|
98
|
+
const OPTIMISE_TABLE_LISTS = Object.keys(OPTIMISE_TABLE_LIST_PRESENCE);
|
|
99
|
+
/**
|
|
100
|
+
* Refuses an `optimiseTables` name outside `^[a-z][a-z0-9_]*$`, naming the
|
|
101
|
+
* list and the database it came from. The name itself is withheld, because
|
|
102
|
+
* one that fails the shape could be anything.
|
|
103
|
+
*/
|
|
104
|
+
export function refuseOffShapeOptimiseTables(databaseId, tables) {
|
|
105
|
+
for (const list of OPTIMISE_TABLE_LISTS) {
|
|
106
|
+
const names = tables[list] ?? [];
|
|
107
|
+
if (names.some((name) => !IDENTIFIER_PATTERN.test(name))) {
|
|
108
|
+
throw new Error(`ClickHouse database ${databaseId}: every name in optimiseTables.${list} must match ${IDENTIFIER_PATTERN}. The name that does not is withheld.`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
86
112
|
function assertIdentifier(kind, value) {
|
|
87
113
|
if (!IDENTIFIER_PATTERN.test(value)) {
|
|
88
114
|
throw new Error(`ClickHouse optimise ${kind} must match ${IDENTIFIER_PATTERN}.`);
|
|
@@ -91,14 +117,14 @@ function assertIdentifier(kind, value) {
|
|
|
91
117
|
/**
|
|
92
118
|
* One row per partition that needs attention, as `<id>:<verdict>`.
|
|
93
119
|
*
|
|
94
|
-
* A partition id
|
|
95
|
-
* itself
|
|
96
|
-
* nothing but an id the statement can quote
|
|
97
|
-
*
|
|
98
|
-
*
|
|
120
|
+
* A partition id holding a character outside `PARTITION_ID_CHARACTERS` is
|
|
121
|
+
* never returned as itself. It comes back hex encoded with the
|
|
122
|
+
* `skip_partition_id` verdict, so nothing but an id the statement can quote
|
|
123
|
+
* safely ever reaches the shell. None of the key shapes measured on
|
|
124
|
+
* clickhouse-server 26.3.17.56 gives such an id.
|
|
99
125
|
*/
|
|
100
126
|
function enumerationQuery(databaseName, table) {
|
|
101
|
-
const safeId =
|
|
127
|
+
const safeId = `length(partition_id) > 0 AND NOT match(partition_id, '[^${PARTITION_ID_CHARACTERS}]')`;
|
|
102
128
|
const verdict = `multiIf(NOT (${safeId}), '${OPTIMISE_PARTITION_ACTION.skipPartitionId}',` +
|
|
103
129
|
` uniqExact(arrayStringConcat(arraySort(projections), ',')) > 1, '${OPTIMISE_PARTITION_ACTION.skipProjections}',` +
|
|
104
130
|
` max(has_lightweight_delete) = 1, '${OPTIMISE_PARTITION_ACTION.purge}',` +
|
|
@@ -123,7 +149,7 @@ function sweepFunction(databaseName) {
|
|
|
123
149
|
` FJALL_SWEEP_PARTS=$(${MAINTENANCE_RUN_FN} "enumerate_$FJALL_SWEEP_TABLE" "${enumeration}") || return 1`,
|
|
124
150
|
` for FJALL_SWEEP_ENTRY in $FJALL_SWEEP_PARTS; do`,
|
|
125
151
|
` FJALL_SWEEP_ID=\${FJALL_SWEEP_ENTRY%%:*}; FJALL_SWEEP_ACTION=\${FJALL_SWEEP_ENTRY#*:}`,
|
|
126
|
-
` case "$FJALL_SWEEP_ID" in ''|*[
|
|
152
|
+
` case "$FJALL_SWEEP_ID" in ''|*[!${PARTITION_ID_CHARACTERS}]*) FJALL_SWEEP_ID=unreadable; FJALL_SWEEP_ACTION=${skipPartitionId} ;; esac`,
|
|
127
153
|
` case "$FJALL_SWEEP_ACTION" in`,
|
|
128
154
|
` ${merge}|${purge})`,
|
|
129
155
|
` echo "${OPTIMISE_PARTITION_LOG_TOKEN} table=$FJALL_SWEEP_TABLE partition=$FJALL_SWEEP_ID action=$FJALL_SWEEP_ACTION job=$FJALL_JOB" >&2`,
|
|
@@ -138,9 +164,10 @@ function sweepFunction(databaseName) {
|
|
|
138
164
|
}
|
|
139
165
|
/**
|
|
140
166
|
* The optimise job body, to follow `buildMaintenancePreamble`. Globbing is
|
|
141
|
-
* switched off because the sweep word
|
|
142
|
-
* word is already `
|
|
143
|
-
* `status=ok` only when every table and view settled
|
|
167
|
+
* switched off because the sweep word splits the enumeration's output. Every
|
|
168
|
+
* word is already digits, letters, `_`, `-` and `:`, so this is defence in
|
|
169
|
+
* depth. Exits 0 with `status=ok` only when every table and view settled
|
|
170
|
+
* without a failure.
|
|
144
171
|
*/
|
|
145
172
|
export function buildClickHouseOptimiseScript(params) {
|
|
146
173
|
const { databaseName, replacingTables, mvTables } = params;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fjall/components-infrastructure",
|
|
3
|
-
"version": "39.1
|
|
3
|
+
"version": "39.2.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/fjall-tech/fjall.git",
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
},
|
|
88
88
|
"dependencies": {
|
|
89
89
|
"@aws-sdk/client-organizations": "^3.1098.0",
|
|
90
|
-
"@fjall/generator": "^39.1
|
|
91
|
-
"@fjall/util": "^39.1
|
|
90
|
+
"@fjall/generator": "^39.2.1",
|
|
91
|
+
"@fjall/util": "^39.2.1",
|
|
92
92
|
"constructs": "^10.7.2",
|
|
93
93
|
"zod": "^4.4.3"
|
|
94
94
|
},
|