From 7d52b439422e1d53e7c9a418e1d13b95dbb7b235 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 01/30] Format schema.sql the way ClickHouse prints it Run every statement through clickhouse-format (24.8), the layout SHOW CREATE and production's DDL use, so the per-table commits that follow show only real changes. Comments are kept. No statement changes: formatting the old and new files gives identical output. --- scripts/cluster-migration/schema.sql | 307 +++++++++++++-------------- 1 file changed, 146 insertions(+), 161 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 0421dde7..a87f5954 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -1,142 +1,120 @@ -CREATE TABLE - ooni.jsonl ON CLUSTER oonidata_cluster ( - `report_id` String, - `input` String, - `s3path` String, - `linenum` Int32, - `measurement_uid` String, - `date` Date, - `source` String, - `update_time` DateTime64 (3) MATERIALIZED now64 () - ) ENGINE = ReplicatedReplacingMergeTree ( - '/clickhouse/{cluster}/tables/ooni/jsonl/{shard}', - '{replica}', - update_time - ) -ORDER BY - (report_id, input, measurement_uid) SETTINGS index_granularity = 8192; +CREATE TABLE ooni.jsonl ON CLUSTER oonidata_cluster +( + `report_id` String, + `input` String, + `s3path` String, + `linenum` Int32, + `measurement_uid` String, + `date` Date, + `source` String, + `update_time` DateTime64(3) MATERIALIZED now64() +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/jsonl/{shard}', '{replica}', update_time) +ORDER BY (report_id, input, measurement_uid) +SETTINGS index_granularity = 8192; -CREATE TABLE - ooni.fastpath ON CLUSTER oonidata_cluster ( - `measurement_uid` String, - `report_id` String, - `input` String, - `probe_cc` LowCardinality (String), - `probe_asn` Int32, - `test_name` LowCardinality (String), - `test_start_time` DateTime, - `measurement_start_time` DateTime, - `filename` String, - `scores` String, - `platform` String, - `anomaly` String, - `confirmed` String, - `msm_failure` String, - `domain` String, - `software_name` String, - `software_version` String, - `control_failure` String, - `blocking_general` Float32, - `is_ssl_expected` Int8, - `page_len` Int32, - `page_len_ratio` Float32, - `server_cc` String, - `server_asn` Int8, - `server_as_name` String, - `update_time` DateTime64 (3) MATERIALIZED now64 (), - `test_version` String, - `architecture` String, - `engine_name` LowCardinality (String), - `engine_version` String, - `test_runtime` Float32, - `blocking_type` String, - `test_helper_address` LowCardinality (String), - `test_helper_type` LowCardinality (String), - `ooni_run_link_id` Nullable (UInt64), - INDEX fastpath_rid_idx report_id TYPE minmax GRANULARITY 1, - INDEX measurement_uid_idx measurement_uid TYPE minmax GRANULARITY 8 - ) ENGINE = ReplicatedReplacingMergeTree ( - '/clickhouse/{cluster}/tables/ooni/fastpath/{shard}', - '{replica}', - update_time - ) -ORDER BY - ( - measurement_start_time, - report_id, - input, - measurement_uid - ) SETTINGS index_granularity = 8192; +CREATE TABLE ooni.fastpath ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `report_id` String, + `input` String, + `probe_cc` LowCardinality(String), + `probe_asn` Int32, + `test_name` LowCardinality(String), + `test_start_time` DateTime, + `measurement_start_time` DateTime, + `filename` String, + `scores` String, + `platform` String, + `anomaly` String, + `confirmed` String, + `msm_failure` String, + `domain` String, + `software_name` String, + `software_version` String, + `control_failure` String, + `blocking_general` Float32, + `is_ssl_expected` Int8, + `page_len` Int32, + `page_len_ratio` Float32, + `server_cc` String, + `server_asn` Int8, + `server_as_name` String, + `update_time` DateTime64(3) MATERIALIZED now64(), + `test_version` String, + `architecture` String, + `engine_name` LowCardinality(String), + `engine_version` String, + `test_runtime` Float32, + `blocking_type` String, + `test_helper_address` LowCardinality(String), + `test_helper_type` LowCardinality(String), + `ooni_run_link_id` Nullable(UInt64), + INDEX fastpath_rid_idx report_id TYPE minmax GRANULARITY 1, + INDEX measurement_uid_idx measurement_uid TYPE minmax GRANULARITY 8 +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/fastpath/{shard}', '{replica}', update_time) +ORDER BY (measurement_start_time, report_id, input, measurement_uid) +SETTINGS index_granularity = 8192; -CREATE TABLE - ooni.citizenlab ON CLUSTER oonidata_cluster ( - `domain` String, - `url` String, - `cc` FixedString (32), - `category_code` String - ) ENGINE = ReplicatedReplacingMergeTree ( - '/clickhouse/{cluster}/tables/ooni/citizenlab/{shard}', - '{replica}' - ) -ORDER BY - (domain, url, cc, category_code) SETTINGS index_granularity = 4; +CREATE TABLE ooni.citizenlab ON CLUSTER oonidata_cluster +( + `domain` String, + `url` String, + `cc` FixedString(32), + `category_code` String +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizenlab/{shard}', '{replica}') +ORDER BY (domain, url, cc, category_code) +SETTINGS index_granularity = 4; -CREATE TABLE - ooni.citizenlab_flip ON CLUSTER oonidata_cluster ( - `domain` String, - `url` String, - `cc` FixedString (32), - `category_code` String - ) ENGINE = ReplicatedReplacingMergeTree ( - '/clickhouse/{cluster}/tables/ooni/citizenlab_flip/{shard}', - '{replica}' - ) -ORDER BY - (domain, url, cc, category_code) SETTINGS index_granularity = 4; +CREATE TABLE ooni.citizenlab_flip ON CLUSTER oonidata_cluster +( + `domain` String, + `url` String, + `cc` FixedString(32), + `category_code` String +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizenlab_flip/{shard}', '{replica}') +ORDER BY (domain, url, cc, category_code) +SETTINGS index_granularity = 4; -CREATE TABLE - analysis_web_measurement ON CLUSTER oonidata_cluster ( - `domain` String, - `input` String, - `test_name` String, - `probe_asn` UInt32, - `probe_as_org_name` String, - `probe_cc` String, - `resolver_asn` UInt32, - `resolver_as_cc` String, - `network_type` String, - `measurement_start_time` DateTime64 (3, 'UTC'), - `measurement_uid` String, - `ooni_run_link_id` String, - `top_probe_analysis` Nullable (String), - `top_dns_failure` Nullable (String), - `top_tcp_failure` Nullable (String), - `top_tls_failure` Nullable (String), - `dns_blocked` Float32, - `dns_down` Float32, - `dns_ok` Float32, - `tcp_blocked` Float32, - `tcp_down` Float32, - `tcp_ok` Float32, - `tls_blocked` Float32, - `tls_down` Float32, - `tls_ok` Float32 - ) ENGINE = ReplicatedReplacingMergeTree ( - '/clickhouse/{cluster}/tables/ooni/analysis_web_measurement/{shard}', - '{replica}' - ) -PARTITION BY - substring(measurement_uid, 1, 6) PRIMARY KEY measurement_uid -ORDER BY - ( - measurement_uid, - measurement_start_time, - probe_cc, - probe_asn, - domain - ) SETTINGS index_granularity = 8192; +CREATE TABLE analysis_web_measurement ON CLUSTER oonidata_cluster +( + `domain` String, + `input` String, + `test_name` String, + `probe_asn` UInt32, + `probe_as_org_name` String, + `probe_cc` String, + `resolver_asn` UInt32, + `resolver_as_cc` String, + `network_type` String, + `measurement_start_time` DateTime64(3, 'UTC'), + `measurement_uid` String, + `ooni_run_link_id` String, + `top_probe_analysis` Nullable(String), + `top_dns_failure` Nullable(String), + `top_tcp_failure` Nullable(String), + `top_tls_failure` Nullable(String), + `dns_blocked` Float32, + `dns_down` Float32, + `dns_ok` Float32, + `tcp_blocked` Float32, + `tcp_down` Float32, + `tcp_ok` Float32, + `tls_blocked` Float32, + `tls_down` Float32, + `tls_ok` Float32 +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/analysis_web_measurement/{shard}', '{replica}') +PARTITION BY substring(measurement_uid, 1, 6) +PRIMARY KEY measurement_uid +ORDER BY (measurement_uid, measurement_start_time, probe_cc, probe_asn, domain) +SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS event_detector_changepoints ON CLUSTER oonidata_cluster( +CREATE TABLE IF NOT EXISTS event_detector_changepoints ON CLUSTER oonidata_cluster +( `probe_asn` UInt32, `probe_cc` String, `domain` String, @@ -170,11 +148,8 @@ CREATE TABLE IF NOT EXISTS event_detector_changepoints ON CLUSTER oonidata_clust `s_neg` Nullable(float), `current_mean` Nullable(float), `h` Nullable(float) - ) -ENGINE = ReplicatedReplacingMergeTree ( - '/clickhouse/{cluster}/tables/ooni/event_detector_changepoints/{shard}', - '{replica}' - ) +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/event_detector_changepoints/{shard}', '{replica}') PARTITION BY toYYYYMM(ts) ORDER BY (probe_asn, probe_cc, ts, domain) SETTINGS index_granularity = 8192; @@ -189,31 +164,26 @@ CREATE TABLE IF NOT EXISTS event_detector_cusums ON CLUSTER oonidata_cluster `dns_isp_blocked_w_sum` Nullable(Float64), `dns_isp_blocked_s_pos` Nullable(Float64), `dns_isp_blocked_s_neg` Nullable(Float64), - `dns_other_blocked_obs_w_sum` Nullable(Float64), `dns_other_blocked_w_sum` Nullable(Float64), `dns_other_blocked_s_pos` Nullable(Float64), `dns_other_blocked_s_neg` Nullable(Float64), - `tcp_blocked_obs_w_sum` Nullable(Float64), `tcp_blocked_w_sum` Nullable(Float64), `tcp_blocked_s_pos` Nullable(Float64), `tcp_blocked_s_neg` Nullable(Float64), - `tls_blocked_obs_w_sum` Nullable(Float64), `tls_blocked_w_sum` Nullable(Float64), `tls_blocked_s_pos` Nullable(Float64), `tls_blocked_s_neg` Nullable(Float64) ) -ENGINE = ReplicatedReplacingMergeTree ( - '/clickhouse/{cluster}/tables/ooni/event_detector_cusums/{shard}', - '{replica}' -) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/event_detector_cusums/{shard}', '{replica}') PARTITION BY toYYYYMM(ts) ORDER BY (probe_asn, probe_cc, domain) SETTINGS index_granularity = 8192; -ALTER TABLE event_detector_changepoints ON CLUSTER oonidata_cluster ADD COLUMN `block_type` String; +ALTER TABLE event_detector_changepoints ON CLUSTER oonidata_cluster + ADD COLUMN `block_type` String; -- faulty measurements CREATE TABLE IF NOT EXISTS faulty_measurements ON CLUSTER oonidata_cluster @@ -227,24 +197,39 @@ CREATE TABLE IF NOT EXISTS faulty_measurements ON CLUSTER oonidata_cluster -- JSON-encoded details about the anomaly `details` String ) -ENGINE = ReplicatedReplacingMergeTree ( - '/clickhouse/{cluster}/tables/ooni/faulty_measurements/{shard}', - '{replica}' -) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/faulty_measurements/{shard}', '{replica}') ORDER BY (ts, type, probe_cc, probe_asn, uid); -- Anonymous Credentials fields -ALTER TABLE ooni.fastpath ADD COLUMN IF NOT EXISTS `is_verified` Int8; -ALTER TABLE ooni.fastpath ADD COLUMN IF NOT EXISTS `nym` Nullable(String); -ALTER TABLE ooni.fastpath ADD COLUMN IF NOT EXISTS `zkp_request` Nullable(String); -ALTER TABLE ooni.fastpath ADD COLUMN IF NOT EXISTS `age_range` Nullable(String); -ALTER TABLE ooni.fastpath ADD COLUMN IF NOT EXISTS `msm_range` Nullable(String); +ALTER TABLE ooni.fastpath + ADD COLUMN IF NOT EXISTS `is_verified` Int8; + +ALTER TABLE ooni.fastpath + ADD COLUMN IF NOT EXISTS `nym` Nullable(String); + +ALTER TABLE ooni.fastpath + ADD COLUMN IF NOT EXISTS `zkp_request` Nullable(String); + +ALTER TABLE ooni.fastpath + ADD COLUMN IF NOT EXISTS `age_range` Nullable(String); + +ALTER TABLE ooni.fastpath + ADD COLUMN IF NOT EXISTS `msm_range` Nullable(String); + +ALTER TABLE ooni.fastpath + DROP COLUMN IF EXISTS nym; + +ALTER TABLE ooni.fastpath + DROP COLUMN IF EXISTS zkp_request; + +ALTER TABLE ooni.fastpath + DROP COLUMN IF EXISTS age_range; + +ALTER TABLE ooni.fastpath + DROP COLUMN IF EXISTS msm_range; -ALTER TABLE ooni.fastpath DROP COLUMN IF EXISTS `nym`; -ALTER TABLE ooni.fastpath DROP COLUMN IF EXISTS `zkp_request`; -ALTER TABLE ooni.fastpath DROP COLUMN IF EXISTS `age_range`; -ALTER TABLE ooni.fastpath DROP COLUMN IF EXISTS `msm_range`; -ALTER TABLE ooni.fastpath MODIFY COLUMN `is_verified` LowCardinality(String) DEFAULT 'u'; +ALTER TABLE ooni.fastpath + MODIFY COLUMN `is_verified` LowCardinality(String) DEFAULT 'u'; -- Changepoints CREATE TABLE IF NOT EXISTS event_detector_v2_changepoints ON CLUSTER oonidata_cluster From 9b0853c1690a7b2fb65157255846d5f83e5e03c4 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 02/30] Sort schema.sql by table name Move each statement next to the others of its table, tables by name, ALTERs after their CREATE. Only the order changes. --- scripts/cluster-migration/schema.sql | 258 +++++++++++++-------------- 1 file changed, 129 insertions(+), 129 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index a87f5954..5cae2096 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -1,84 +1,3 @@ -CREATE TABLE ooni.jsonl ON CLUSTER oonidata_cluster -( - `report_id` String, - `input` String, - `s3path` String, - `linenum` Int32, - `measurement_uid` String, - `date` Date, - `source` String, - `update_time` DateTime64(3) MATERIALIZED now64() -) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/jsonl/{shard}', '{replica}', update_time) -ORDER BY (report_id, input, measurement_uid) -SETTINGS index_granularity = 8192; - -CREATE TABLE ooni.fastpath ON CLUSTER oonidata_cluster -( - `measurement_uid` String, - `report_id` String, - `input` String, - `probe_cc` LowCardinality(String), - `probe_asn` Int32, - `test_name` LowCardinality(String), - `test_start_time` DateTime, - `measurement_start_time` DateTime, - `filename` String, - `scores` String, - `platform` String, - `anomaly` String, - `confirmed` String, - `msm_failure` String, - `domain` String, - `software_name` String, - `software_version` String, - `control_failure` String, - `blocking_general` Float32, - `is_ssl_expected` Int8, - `page_len` Int32, - `page_len_ratio` Float32, - `server_cc` String, - `server_asn` Int8, - `server_as_name` String, - `update_time` DateTime64(3) MATERIALIZED now64(), - `test_version` String, - `architecture` String, - `engine_name` LowCardinality(String), - `engine_version` String, - `test_runtime` Float32, - `blocking_type` String, - `test_helper_address` LowCardinality(String), - `test_helper_type` LowCardinality(String), - `ooni_run_link_id` Nullable(UInt64), - INDEX fastpath_rid_idx report_id TYPE minmax GRANULARITY 1, - INDEX measurement_uid_idx measurement_uid TYPE minmax GRANULARITY 8 -) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/fastpath/{shard}', '{replica}', update_time) -ORDER BY (measurement_start_time, report_id, input, measurement_uid) -SETTINGS index_granularity = 8192; - -CREATE TABLE ooni.citizenlab ON CLUSTER oonidata_cluster -( - `domain` String, - `url` String, - `cc` FixedString(32), - `category_code` String -) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizenlab/{shard}', '{replica}') -ORDER BY (domain, url, cc, category_code) -SETTINGS index_granularity = 4; - -CREATE TABLE ooni.citizenlab_flip ON CLUSTER oonidata_cluster -( - `domain` String, - `url` String, - `cc` FixedString(32), - `category_code` String -) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizenlab_flip/{shard}', '{replica}') -ORDER BY (domain, url, cc, category_code) -SETTINGS index_granularity = 4; - CREATE TABLE analysis_web_measurement ON CLUSTER oonidata_cluster ( `domain` String, @@ -113,6 +32,50 @@ PRIMARY KEY measurement_uid ORDER BY (measurement_uid, measurement_start_time, probe_cc, probe_asn, domain) SETTINGS index_granularity = 8192; +CREATE TABLE IF NOT EXISTS changepoint_label ON CLUSTER oonidata_cluster +( + -- Ground truth, set by a person. Represents the network state for + -- the (probe_cc, probe_asn, resolver_asn, domain) series of the + -- changepoint it labels + `id` UUID, + -- UUID in event_detector_v2_changepoints (foreign key) + `changepoint_id` UUID, + `created_at` DateTime64(3, 'UTC') DEFAULT now64(), + `author` String, + -- blocked, ok or undecided + `verdict` LowCardinality(String), + -- Additional context the author might share + `notes` String, + `last_ok_time` Nullable(DateTime64(3, 'UTC')), + `first_block_time` Nullable(DateTime64(3, 'UTC')), + `last_block_time` Nullable(DateTime64(3, 'UTC')), + `first_ok_time` Nullable(DateTime64(3, 'UTC')) +) +ENGINE = MergeTree +ORDER BY (changepoint_id, created_at, id); + +CREATE TABLE ooni.citizenlab ON CLUSTER oonidata_cluster +( + `domain` String, + `url` String, + `cc` FixedString(32), + `category_code` String +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizenlab/{shard}', '{replica}') +ORDER BY (domain, url, cc, category_code) +SETTINGS index_granularity = 4; + +CREATE TABLE ooni.citizenlab_flip ON CLUSTER oonidata_cluster +( + `domain` String, + `url` String, + `cc` FixedString(32), + `category_code` String +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizenlab_flip/{shard}', '{replica}') +ORDER BY (domain, url, cc, category_code) +SETTINGS index_granularity = 4; + CREATE TABLE IF NOT EXISTS event_detector_changepoints ON CLUSTER oonidata_cluster ( `probe_asn` UInt32, @@ -154,6 +117,9 @@ PARTITION BY toYYYYMM(ts) ORDER BY (probe_asn, probe_cc, ts, domain) SETTINGS index_granularity = 8192; +ALTER TABLE event_detector_changepoints ON CLUSTER oonidata_cluster + ADD COLUMN `block_type` String; + CREATE TABLE IF NOT EXISTS event_detector_cusums ON CLUSTER oonidata_cluster ( `probe_asn` UInt32, @@ -182,23 +148,70 @@ PARTITION BY toYYYYMM(ts) ORDER BY (probe_asn, probe_cc, domain) SETTINGS index_granularity = 8192; -ALTER TABLE event_detector_changepoints ON CLUSTER oonidata_cluster - ADD COLUMN `block_type` String; - --- faulty measurements -CREATE TABLE IF NOT EXISTS faulty_measurements ON CLUSTER oonidata_cluster +-- Changepoints +CREATE TABLE IF NOT EXISTS event_detector_v2_changepoints ON CLUSTER oonidata_cluster ( - `ts` DateTime64(3, 'UTC') DEFAULT now64(), - `type` String, - `uid` UUID DEFAULT generateUUIDv4(), - -- geoip lookup result for the probe IP + `uuid` UUID, + `domain` String, `probe_cc` String, `probe_asn` UInt32, - -- JSON-encoded details about the anomaly - `details` String + `resolver_asn` UInt32, + `layer` LowCardinality(String), + `ts_hour` DateTime64(3, 'UTC'), + `s_neg` Float64, + `s_pos` Float64, + `h` Float64, + `state` LowCardinality(String), + -- JSON-encoded parameters the detector was run with + `run_parameters` String, + `created_at` DateTime64(3, 'UTC') DEFAULT now64() ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/faulty_measurements/{shard}', '{replica}') -ORDER BY (ts, type, probe_cc, probe_asn, uid); +ENGINE = MergeTree +ORDER BY (ts_hour, domain, layer, probe_cc, probe_asn, resolver_asn, state, uuid); + +CREATE TABLE ooni.fastpath ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `report_id` String, + `input` String, + `probe_cc` LowCardinality(String), + `probe_asn` Int32, + `test_name` LowCardinality(String), + `test_start_time` DateTime, + `measurement_start_time` DateTime, + `filename` String, + `scores` String, + `platform` String, + `anomaly` String, + `confirmed` String, + `msm_failure` String, + `domain` String, + `software_name` String, + `software_version` String, + `control_failure` String, + `blocking_general` Float32, + `is_ssl_expected` Int8, + `page_len` Int32, + `page_len_ratio` Float32, + `server_cc` String, + `server_asn` Int8, + `server_as_name` String, + `update_time` DateTime64(3) MATERIALIZED now64(), + `test_version` String, + `architecture` String, + `engine_name` LowCardinality(String), + `engine_version` String, + `test_runtime` Float32, + `blocking_type` String, + `test_helper_address` LowCardinality(String), + `test_helper_type` LowCardinality(String), + `ooni_run_link_id` Nullable(UInt64), + INDEX fastpath_rid_idx report_id TYPE minmax GRANULARITY 1, + INDEX measurement_uid_idx measurement_uid TYPE minmax GRANULARITY 8 +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/fastpath/{shard}', '{replica}', update_time) +ORDER BY (measurement_start_time, report_id, input, measurement_uid) +SETTINGS index_granularity = 8192; -- Anonymous Credentials fields ALTER TABLE ooni.fastpath @@ -231,45 +244,32 @@ ALTER TABLE ooni.fastpath ALTER TABLE ooni.fastpath MODIFY COLUMN `is_verified` LowCardinality(String) DEFAULT 'u'; --- Changepoints -CREATE TABLE IF NOT EXISTS event_detector_v2_changepoints ON CLUSTER oonidata_cluster +-- faulty measurements +CREATE TABLE IF NOT EXISTS faulty_measurements ON CLUSTER oonidata_cluster ( - `uuid` UUID, - `domain` String, + `ts` DateTime64(3, 'UTC') DEFAULT now64(), + `type` String, + `uid` UUID DEFAULT generateUUIDv4(), + -- geoip lookup result for the probe IP `probe_cc` String, `probe_asn` UInt32, - `resolver_asn` UInt32, - `layer` LowCardinality(String), - `ts_hour` DateTime64(3, 'UTC'), - `s_neg` Float64, - `s_pos` Float64, - `h` Float64, - `state` LowCardinality(String), - -- JSON-encoded parameters the detector was run with - `run_parameters` String, - `created_at` DateTime64(3, 'UTC') DEFAULT now64() + -- JSON-encoded details about the anomaly + `details` String ) -ENGINE = MergeTree -ORDER BY (ts_hour, domain, layer, probe_cc, probe_asn, resolver_asn, state, uuid); +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/faulty_measurements/{shard}', '{replica}') +ORDER BY (ts, type, probe_cc, probe_asn, uid); -CREATE TABLE IF NOT EXISTS changepoint_label ON CLUSTER oonidata_cluster +CREATE TABLE ooni.jsonl ON CLUSTER oonidata_cluster ( - -- Ground truth, set by a person. Represents the network state for - -- the (probe_cc, probe_asn, resolver_asn, domain) series of the - -- changepoint it labels - `id` UUID, - -- UUID in event_detector_v2_changepoints (foreign key) - `changepoint_id` UUID, - `created_at` DateTime64(3, 'UTC') DEFAULT now64(), - `author` String, - -- blocked, ok or undecided - `verdict` LowCardinality(String), - -- Additional context the author might share - `notes` String, - `last_ok_time` Nullable(DateTime64(3, 'UTC')), - `first_block_time` Nullable(DateTime64(3, 'UTC')), - `last_block_time` Nullable(DateTime64(3, 'UTC')), - `first_ok_time` Nullable(DateTime64(3, 'UTC')) + `report_id` String, + `input` String, + `s3path` String, + `linenum` Int32, + `measurement_uid` String, + `date` Date, + `source` String, + `update_time` DateTime64(3) MATERIALIZED now64() ) -ENGINE = MergeTree -ORDER BY (changepoint_id, created_at, id); +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/jsonl/{shard}', '{replica}', update_time) +ORDER BY (report_id, input, measurement_uid) +SETTINGS index_granularity = 8192; From 7880f9435d83ceeeba7db44b9f9e1dad5f5c688b Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 03/30] schema.sql: analysis_web_measurement as in production Add the columns production has: top_{dns,tcp,tls}_rule_id, probe_id and analysis_rules_version, and its minmax indexes on measurement_start_time, probe_cc and probe_asn. Like every table from here on, it's now created as ooni. with IF NOT EXISTS, as production reports it. --- scripts/cluster-migration/schema.sql | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 5cae2096..1b943d4f 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -1,4 +1,4 @@ -CREATE TABLE analysis_web_measurement ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS ooni.analysis_web_measurement ON CLUSTER oonidata_cluster ( `domain` String, `input` String, @@ -24,7 +24,15 @@ CREATE TABLE analysis_web_measurement ON CLUSTER oonidata_cluster `tcp_ok` Float32, `tls_blocked` Float32, `tls_down` Float32, - `tls_ok` Float32 + `tls_ok` Float32, + `top_dns_rule_id` LowCardinality(String), + `top_tcp_rule_id` LowCardinality(String), + `top_tls_rule_id` LowCardinality(String), + `probe_id` FixedString(64), + `analysis_rules_version` UInt16, + INDEX measurement_start_time_idx measurement_start_time TYPE minmax GRANULARITY 2, + INDEX probe_cc_idx probe_cc TYPE minmax GRANULARITY 1, + INDEX probe_asn_idx probe_asn TYPE minmax GRANULARITY 1 ) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/analysis_web_measurement/{shard}', '{replica}') PARTITION BY substring(measurement_uid, 1, 6) From b6526fe63aa64ebb0fc63a2628abedaec92c8561 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 04/30] schema.sql: add asnmeta Replicated at /clickhouse/{cluster}/tables/ooni/asnmeta on every replica, as ooni/data#190 made it (and OOPRIV-181 restored on data1). --- scripts/cluster-migration/schema.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 1b943d4f..b3a2eaf0 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -40,6 +40,19 @@ PRIMARY KEY measurement_uid ORDER BY (measurement_uid, measurement_start_time, probe_cc, probe_asn, domain) SETTINGS index_granularity = 8192; +CREATE TABLE IF NOT EXISTS ooni.asnmeta ON CLUSTER oonidata_cluster +( + `asn` UInt32, + `org_name` String, + `cc` String, + `changed` Date, + `aut_name` String, + `source` String +) +ENGINE = ReplicatedMergeTree('/clickhouse/{cluster}/tables/ooni/asnmeta', '{replica}') +ORDER BY (asn, changed) +SETTINGS index_granularity = 8192; + CREATE TABLE IF NOT EXISTS changepoint_label ON CLUSTER oonidata_cluster ( -- Ground truth, set by a person. Represents the network state for From 8e8197ac46940fca531ffeaeba619cd7f0e1f8db Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 05/30] schema.sql: changepoint_label as in production No change but the explicit index_granularity production reports. --- scripts/cluster-migration/schema.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index b3a2eaf0..db8a5cc5 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -53,7 +53,7 @@ ENGINE = ReplicatedMergeTree('/clickhouse/{cluster}/tables/ooni/asnmeta', '{repl ORDER BY (asn, changed) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS changepoint_label ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS ooni.changepoint_label ON CLUSTER oonidata_cluster ( -- Ground truth, set by a person. Represents the network state for -- the (probe_cc, probe_asn, resolver_asn, domain) series of the @@ -73,7 +73,8 @@ CREATE TABLE IF NOT EXISTS changepoint_label ON CLUSTER oonidata_cluster `first_ok_time` Nullable(DateTime64(3, 'UTC')) ) ENGINE = MergeTree -ORDER BY (changepoint_id, created_at, id); +ORDER BY (changepoint_id, created_at, id) +SETTINGS index_granularity = 8192; CREATE TABLE ooni.citizenlab ON CLUSTER oonidata_cluster ( From 8e89a4e06f0a926cfe92a5851bb0e1335f62b918 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 06/30] schema.sql: citizenlab's Keeper path as in production Production's path has no /{shard} suffix. A replica created with the old path wouldn't join production's table. --- scripts/cluster-migration/schema.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index db8a5cc5..795994cc 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -76,14 +76,14 @@ ENGINE = MergeTree ORDER BY (changepoint_id, created_at, id) SETTINGS index_granularity = 8192; -CREATE TABLE ooni.citizenlab ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS ooni.citizenlab ON CLUSTER oonidata_cluster ( `domain` String, `url` String, `cc` FixedString(32), `category_code` String ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizenlab/{shard}', '{replica}') +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizenlab', '{replica}') ORDER BY (domain, url, cc, category_code) SETTINGS index_granularity = 4; From 61374653c23171f49a8e7f0a5b694e3ea012c577 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 07/30] schema.sql: drop citizenlab_flip Production doesn't have it. Only the legacy citizenlab updater used it, and ooni/data's updater (ooni/data#190) swaps citizenlab without it. --- scripts/cluster-migration/schema.sql | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 795994cc..1d64d5d9 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -87,17 +87,6 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizen ORDER BY (domain, url, cc, category_code) SETTINGS index_granularity = 4; -CREATE TABLE ooni.citizenlab_flip ON CLUSTER oonidata_cluster -( - `domain` String, - `url` String, - `cc` FixedString(32), - `category_code` String -) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizenlab_flip/{shard}', '{replica}') -ORDER BY (domain, url, cc, category_code) -SETTINGS index_granularity = 4; - CREATE TABLE IF NOT EXISTS event_detector_changepoints ON CLUSTER oonidata_cluster ( `probe_asn` UInt32, From 95b5c5a8ca2ef76e412906a9c7e2d6821361bbae Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 08/30] schema.sql: event_detector_changepoints as in production Production has none of the 17 *_obs_w_sum, *_w_sum, *_s_pos, *_s_neg, last_ts and current_mean columns, and no partitioning. It has current_state, and block_type in the CREATE instead of a later ALTER. float is now spelled Float32, the same type. --- scripts/cluster-migration/schema.sql | 40 +++++++--------------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 1d64d5d9..8d51c9cf 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -87,7 +87,7 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizen ORDER BY (domain, url, cc, category_code) SETTINGS index_granularity = 4; -CREATE TABLE IF NOT EXISTS event_detector_changepoints ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS ooni.event_detector_changepoints ON CLUSTER oonidata_cluster ( `probe_asn` UInt32, `probe_cc` String, @@ -96,41 +96,21 @@ CREATE TABLE IF NOT EXISTS event_detector_changepoints ON CLUSTER oonidata_clust `count_isp_resolver` Nullable(UInt32), `count_other_resolver` Nullable(UInt32), `count` Nullable(UInt32), - `dns_isp_blocked` Nullable(float), - `dns_other_blocked` Nullable(float), - `tcp_blocked` Nullable(float), - `tls_blocked` Nullable(float), - `last_ts` DateTime64(3, 'UTC'), - `dns_isp_blocked_obs_w_sum` Nullable(float), - `dns_isp_blocked_w_sum` Nullable(float), - `dns_isp_blocked_s_pos` Nullable(float), - `dns_isp_blocked_s_neg` Nullable(float), - `dns_other_blocked_obs_w_sum` Nullable(float), - `dns_other_blocked_w_sum` Nullable(float), - `dns_other_blocked_s_pos` Nullable(float), - `dns_other_blocked_s_neg` Nullable(float), - `tcp_blocked_obs_w_sum` Nullable(float), - `tcp_blocked_w_sum` Nullable(float), - `tcp_blocked_s_pos` Nullable(float), - `tcp_blocked_s_neg` Nullable(float), - `tls_blocked_obs_w_sum` Nullable(float), - `tls_blocked_w_sum` Nullable(float), - `tls_blocked_s_pos` Nullable(float), - `tls_blocked_s_neg` Nullable(float), + `dns_isp_blocked` Nullable(Float32), + `dns_other_blocked` Nullable(Float32), + `tcp_blocked` Nullable(Float32), + `tls_blocked` Nullable(Float32), `change_dir` Nullable(Int8), - `s_pos` Nullable(float), - `s_neg` Nullable(float), - `current_mean` Nullable(float), - `h` Nullable(float) + `s_pos` Nullable(Float32), + `s_neg` Nullable(Float32), + `current_state` String, + `h` Nullable(Float32), + `block_type` String ) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/event_detector_changepoints/{shard}', '{replica}') -PARTITION BY toYYYYMM(ts) ORDER BY (probe_asn, probe_cc, ts, domain) SETTINGS index_granularity = 8192; -ALTER TABLE event_detector_changepoints ON CLUSTER oonidata_cluster - ADD COLUMN `block_type` String; - CREATE TABLE IF NOT EXISTS event_detector_cusums ON CLUSTER oonidata_cluster ( `probe_asn` UInt32, From 4d1f61679b412dd3fe7b38afe6ee24e7fbae9c58 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 09/30] schema.sql: event_detector_cusums as in production Production's table is a plain ReplacingMergeTree(ts), not replicated or partitioned, with *_current_state instead of *_obs_w_sum and *_w_sum. The *_last_change and *_last_ts columns are data1's, the only replica with rows. --- scripts/cluster-migration/schema.sql | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 8d51c9cf..cda3e956 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -111,31 +111,34 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/event_d ORDER BY (probe_asn, probe_cc, ts, domain) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS event_detector_cusums ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS ooni.event_detector_cusums ON CLUSTER oonidata_cluster ( `probe_asn` UInt32, `probe_cc` String, `domain` String, `ts` DateTime64(3, 'UTC'), - `dns_isp_blocked_obs_w_sum` Nullable(Float64), - `dns_isp_blocked_w_sum` Nullable(Float64), + `dns_isp_blocked_current_state` String DEFAULT 'ok', `dns_isp_blocked_s_pos` Nullable(Float64), `dns_isp_blocked_s_neg` Nullable(Float64), - `dns_other_blocked_obs_w_sum` Nullable(Float64), - `dns_other_blocked_w_sum` Nullable(Float64), + `dns_other_blocked_current_state` String DEFAULT 'ok', `dns_other_blocked_s_pos` Nullable(Float64), `dns_other_blocked_s_neg` Nullable(Float64), - `tcp_blocked_obs_w_sum` Nullable(Float64), - `tcp_blocked_w_sum` Nullable(Float64), + `tcp_blocked_current_state` String DEFAULT 'ok', `tcp_blocked_s_pos` Nullable(Float64), `tcp_blocked_s_neg` Nullable(Float64), - `tls_blocked_obs_w_sum` Nullable(Float64), - `tls_blocked_w_sum` Nullable(Float64), + `tls_blocked_current_state` String DEFAULT 'ok', `tls_blocked_s_pos` Nullable(Float64), - `tls_blocked_s_neg` Nullable(Float64) + `tls_blocked_s_neg` Nullable(Float64), + `dns_isp_blocked_last_change` Int8 DEFAULT 0, + `dns_isp_blocked_last_ts` Nullable(DateTime64(3, 'UTC')), + `dns_other_blocked_last_change` Int8 DEFAULT 0, + `dns_other_blocked_last_ts` Nullable(DateTime64(3, 'UTC')), + `tcp_blocked_last_change` Int8 DEFAULT 0, + `tcp_blocked_last_ts` Nullable(DateTime64(3, 'UTC')), + `tls_blocked_last_change` Int8 DEFAULT 0, + `tls_blocked_last_ts` Nullable(DateTime64(3, 'UTC')) ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/event_detector_cusums/{shard}', '{replica}') -PARTITION BY toYYYYMM(ts) +ENGINE = ReplacingMergeTree(ts) ORDER BY (probe_asn, probe_cc, domain) SETTINGS index_granularity = 8192; From 3ccfcb629404895fc3ab9fa542d30539ab771083 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 10/30] schema.sql: event_detector_v2_changepoints as in production No change but the explicit index_granularity production reports. --- scripts/cluster-migration/schema.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index cda3e956..07ac4cc8 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -142,8 +142,7 @@ ENGINE = ReplacingMergeTree(ts) ORDER BY (probe_asn, probe_cc, domain) SETTINGS index_granularity = 8192; --- Changepoints -CREATE TABLE IF NOT EXISTS event_detector_v2_changepoints ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS ooni.event_detector_v2_changepoints ON CLUSTER oonidata_cluster ( `uuid` UUID, `domain` String, @@ -161,7 +160,8 @@ CREATE TABLE IF NOT EXISTS event_detector_v2_changepoints ON CLUSTER oonidata_cl `created_at` DateTime64(3, 'UTC') DEFAULT now64() ) ENGINE = MergeTree -ORDER BY (ts_hour, domain, layer, probe_cc, probe_asn, resolver_asn, state, uuid); +ORDER BY (ts_hour, domain, layer, probe_cc, probe_asn, resolver_asn, state, uuid) +SETTINGS index_granularity = 8192; CREATE TABLE ooni.fastpath ON CLUSTER oonidata_cluster ( From e658f3084b8d6442a578927d7875f97e72234277 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 11/30] schema.sql: fastpath as in production anomaly, confirmed and msm_failure are LowCardinality(String) (ooni/backend#1279), input has a bloom filter index (ooni/backend#1292), and is_verified is in the CREATE. The ALTERs that added and then dropped nym, zkp_request, age_range and msm_range are gone. data1 and data3's definition: data2 alone also has deduplicate_merge_projection_mode = 'rebuild'. --- scripts/cluster-migration/schema.sql | 43 +++++----------------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 07ac4cc8..ed50342f 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -163,7 +163,7 @@ ENGINE = MergeTree ORDER BY (ts_hour, domain, layer, probe_cc, probe_asn, resolver_asn, state, uuid) SETTINGS index_granularity = 8192; -CREATE TABLE ooni.fastpath ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS ooni.fastpath ON CLUSTER oonidata_cluster ( `measurement_uid` String, `report_id` String, @@ -176,9 +176,9 @@ CREATE TABLE ooni.fastpath ON CLUSTER oonidata_cluster `filename` String, `scores` String, `platform` String, - `anomaly` String, - `confirmed` String, - `msm_failure` String, + `anomaly` LowCardinality(String), + `confirmed` LowCardinality(String), + `msm_failure` LowCardinality(String), `domain` String, `software_name` String, `software_version` String, @@ -200,44 +200,15 @@ CREATE TABLE ooni.fastpath ON CLUSTER oonidata_cluster `test_helper_address` LowCardinality(String), `test_helper_type` LowCardinality(String), `ooni_run_link_id` Nullable(UInt64), + `is_verified` LowCardinality(String) DEFAULT 'u', INDEX fastpath_rid_idx report_id TYPE minmax GRANULARITY 1, - INDEX measurement_uid_idx measurement_uid TYPE minmax GRANULARITY 8 + INDEX measurement_uid_idx measurement_uid TYPE minmax GRANULARITY 8, + INDEX input_bloom_idx input TYPE bloom_filter(0.01) GRANULARITY 1 ) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/fastpath/{shard}', '{replica}', update_time) ORDER BY (measurement_start_time, report_id, input, measurement_uid) SETTINGS index_granularity = 8192; --- Anonymous Credentials fields -ALTER TABLE ooni.fastpath - ADD COLUMN IF NOT EXISTS `is_verified` Int8; - -ALTER TABLE ooni.fastpath - ADD COLUMN IF NOT EXISTS `nym` Nullable(String); - -ALTER TABLE ooni.fastpath - ADD COLUMN IF NOT EXISTS `zkp_request` Nullable(String); - -ALTER TABLE ooni.fastpath - ADD COLUMN IF NOT EXISTS `age_range` Nullable(String); - -ALTER TABLE ooni.fastpath - ADD COLUMN IF NOT EXISTS `msm_range` Nullable(String); - -ALTER TABLE ooni.fastpath - DROP COLUMN IF EXISTS nym; - -ALTER TABLE ooni.fastpath - DROP COLUMN IF EXISTS zkp_request; - -ALTER TABLE ooni.fastpath - DROP COLUMN IF EXISTS age_range; - -ALTER TABLE ooni.fastpath - DROP COLUMN IF EXISTS msm_range; - -ALTER TABLE ooni.fastpath - MODIFY COLUMN `is_verified` LowCardinality(String) DEFAULT 'u'; - -- faulty measurements CREATE TABLE IF NOT EXISTS faulty_measurements ON CLUSTER oonidata_cluster ( From dc8fb718572e9d040f8d5e84a7a9dc9a169ba466 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 12/30] schema.sql: faulty_measurements as in production No change but the explicit index_granularity production reports. --- scripts/cluster-migration/schema.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index ed50342f..ce717c31 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -209,8 +209,7 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/fastpat ORDER BY (measurement_start_time, report_id, input, measurement_uid) SETTINGS index_granularity = 8192; --- faulty measurements -CREATE TABLE IF NOT EXISTS faulty_measurements ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS ooni.faulty_measurements ON CLUSTER oonidata_cluster ( `ts` DateTime64(3, 'UTC') DEFAULT now64(), `type` String, @@ -222,7 +221,8 @@ CREATE TABLE IF NOT EXISTS faulty_measurements ON CLUSTER oonidata_cluster `details` String ) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/faulty_measurements/{shard}', '{replica}') -ORDER BY (ts, type, probe_cc, probe_asn, uid); +ORDER BY (ts, type, probe_cc, probe_asn, uid) +SETTINGS index_granularity = 8192; CREATE TABLE ooni.jsonl ON CLUSTER oonidata_cluster ( From 5552cc13566245f2ff28dd7c6f11b31c76fa25e9 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 13/30] schema.sql: add fingerprints_dns An EmbeddedRocksDB table, so it isn't replicated: production has it on data1 and data2 only, and ON CLUSTER creates it, empty, on every node. --- scripts/cluster-migration/schema.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index ce717c31..62bfdcdc 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -224,6 +224,23 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/faulty_ ORDER BY (ts, type, probe_cc, probe_asn, uid) SETTINGS index_granularity = 8192; +CREATE TABLE IF NOT EXISTS ooni.fingerprints_dns ON CLUSTER oonidata_cluster +( + `name` String, + `scope` Enum8('nat' = 1, 'isp' = 2, 'prod' = 3, 'inst' = 4, 'vbw' = 5, 'fp' = 6), + `other_names` String, + `location_found` String, + `pattern_type` Enum8('full' = 1, 'prefix' = 2, 'contains' = 3, 'regexp' = 4), + `pattern` String, + `confidence_no_fp` UInt8, + `expected_countries` String, + `source` String, + `exp_url` String, + `notes` String +) +ENGINE = EmbeddedRocksDB +PRIMARY KEY name; + CREATE TABLE ooni.jsonl ON CLUSTER oonidata_cluster ( `report_id` String, From 0768d6b5d3c2af7d958c02797050e6eca145cacf Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 14/30] schema.sql: add fingerprints_http An EmbeddedRocksDB table, not replicated, like fingerprints_dns. --- scripts/cluster-migration/schema.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 62bfdcdc..170a6f1e 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -241,6 +241,23 @@ CREATE TABLE IF NOT EXISTS ooni.fingerprints_dns ON CLUSTER oonidata_cluster ENGINE = EmbeddedRocksDB PRIMARY KEY name; +CREATE TABLE IF NOT EXISTS ooni.fingerprints_http ON CLUSTER oonidata_cluster +( + `name` String, + `scope` Enum8('nat' = 1, 'isp' = 2, 'prod' = 3, 'inst' = 4, 'vbw' = 5, 'fp' = 6, 'injb' = 7, 'prov' = 8), + `other_names` String, + `location_found` String, + `pattern_type` Enum8('full' = 1, 'prefix' = 2, 'contains' = 3, 'regexp' = 4), + `pattern` String, + `confidence_no_fp` UInt8, + `expected_countries` String, + `source` String, + `exp_url` String, + `notes` String +) +ENGINE = EmbeddedRocksDB +PRIMARY KEY name; + CREATE TABLE ooni.jsonl ON CLUSTER oonidata_cluster ( `report_id` String, From 1048e6c73b09d19d1b630a7b4e0a045533b955a7 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 15/30] schema.sql: jsonl as in production No change but IF NOT EXISTS. --- scripts/cluster-migration/schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 170a6f1e..8152d557 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -258,7 +258,7 @@ CREATE TABLE IF NOT EXISTS ooni.fingerprints_http ON CLUSTER oonidata_cluster ENGINE = EmbeddedRocksDB PRIMARY KEY name; -CREATE TABLE ooni.jsonl ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS ooni.jsonl ON CLUSTER oonidata_cluster ( `report_id` String, `input` String, From 534449ccedfb251947792c7b11d09387546994be Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 16/30] schema.sql: add labeling_frames A local MergeTree. data1's definition, the only replica with rows and with failed_fastpath. --- scripts/cluster-migration/schema.sql | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 8152d557..36bbc73e 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -272,3 +272,19 @@ CREATE TABLE IF NOT EXISTS ooni.jsonl ON CLUSTER oonidata_cluster ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/jsonl/{shard}', '{replica}', update_time) ORDER BY (report_id, input, measurement_uid) SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS ooni.labeling_frames ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `blocked_fastpath` Bool, + `blocked_analysis` Bool, + `stratum` LowCardinality(String), + `test_name` LowCardinality(String), + `day` DateTime('UTC'), + `fastpath_query` LowCardinality(String), + `analysis_query` LowCardinality(String), + `failed_fastpath` Bool +) +ENGINE = MergeTree +ORDER BY (stratum, measurement_uid) +SETTINGS index_granularity = 8192; From 473d7fb08f94ef8296248cacfe81df943faeecbc Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 17/30] schema.sql: add msmt_feedback Replicated at production's path, msmt_feedback_new. --- scripts/cluster-migration/schema.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 36bbc73e..678103aa 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -288,3 +288,15 @@ CREATE TABLE IF NOT EXISTS ooni.labeling_frames ON CLUSTER oonidata_cluster ENGINE = MergeTree ORDER BY (stratum, measurement_uid) SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS ooni.msmt_feedback ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `account_id` String, + `status` String, + `update_time` DateTime64(3) DEFAULT now64(), + `comment` String +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/msmt_feedback_new/{shard}', '{replica}') +ORDER BY (measurement_uid, account_id, update_time) +SETTINGS index_granularity = 4; From 49360bbb7c3ea026253921a6f8277b9a43fa88df Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 18/30] schema.sql: add obs_http_middlebox --- scripts/cluster-migration/schema.sql | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 678103aa..fd75fc86 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -300,3 +300,59 @@ CREATE TABLE IF NOT EXISTS ooni.msmt_feedback ON CLUSTER oonidata_cluster ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/msmt_feedback_new/{shard}', '{replica}') ORDER BY (measurement_uid, account_id, update_time) SETTINGS index_granularity = 4; + +CREATE TABLE IF NOT EXISTS ooni.obs_http_middlebox ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `observation_idx` UInt16, + `input` Nullable(String), + `report_id` String, + `ooni_run_link_id` String DEFAULT '', + `measurement_start_time` DateTime64(3, 'UTC'), + `software_name` String, + `software_version` String, + `test_name` String, + `test_version` String, + `bucket_date` String, + `probe_asn` UInt32, + `probe_cc` String, + `probe_as_org_name` String, + `probe_as_cc` String, + `probe_as_name` String, + `network_type` String, + `platform` String, + `origin` String, + `engine_name` String, + `engine_version` String, + `architecture` String, + `resolver_ip` String, + `resolver_asn` UInt32, + `resolver_cc` String, + `resolver_as_org_name` String, + `resolver_as_cc` String, + `resolver_is_scrubbed` UInt8, + `resolver_asn_probe` UInt32, + `resolver_as_org_name_probe` String, + `created_at` Nullable(DateTime64(3, 'UTC')), + `hirl_sent_0` Nullable(String), + `hirl_sent_1` Nullable(String), + `hirl_sent_2` Nullable(String), + `hirl_sent_3` Nullable(String), + `hirl_sent_4` Nullable(String), + `hirl_received_0` Nullable(String), + `hirl_received_1` Nullable(String), + `hirl_received_2` Nullable(String), + `hirl_received_3` Nullable(String), + `hirl_received_4` Nullable(String), + `hirl_failure` Nullable(String), + `hirl_success` Nullable(UInt8), + `hfm_diff` Nullable(String), + `hfm_failure` Nullable(String), + `hfm_success` Nullable(UInt8), + `probe_id` FixedString(64) +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/obs_http_middlebox/{shard}', '{replica}') +PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) +PRIMARY KEY (measurement_uid, observation_idx) +ORDER BY (measurement_uid, observation_idx, measurement_start_time) +SETTINGS index_granularity = 8192; From b435644a2d654ae2c1baf94a048dd0b3bc4047b7 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 19/30] schema.sql: add obs_openvpn --- scripts/cluster-migration/schema.sql | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index fd75fc86..e133d226 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -356,3 +356,42 @@ PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) PRIMARY KEY (measurement_uid, observation_idx) ORDER BY (measurement_uid, observation_idx, measurement_start_time) SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS ooni.obs_openvpn ON CLUSTER oonidata_cluster +( + `anomaly` Int8, + `bootstrap_time` Float32, + `confirmed` Int8, + `error` String, + `failure` String, + `input` String, + `last_handshake_transaction_id` Int32, + `measurement_start_time` DateTime, + `measurement_uid` String, + `minivpn_version` String, + `obfs4_version` String, + `obfuscation` String, + `platform` String, + `probe_asn` Int32, + `probe_cc` String, + `probe_network_name` String, + `provider` String, + `remote` String, + `report_id` String, + `resolver_asn` Int32, + `resolver_ip` String, + `resolver_network_name` String, + `software_name` String, + `software_version` String, + `success` Int8, + `success_handshake` Int8, + `success_icmp` Int8, + `success_urlgrab` Int8, + `tcp_connect_status_success` Int8, + `test_runtime` Float32, + `test_start_time` DateTime, + `transport` String +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/obs_openvpn/{shard}', '{replica}') +ORDER BY (measurement_start_time, report_id, input) +SETTINGS index_granularity = 8; From 014b4e23f6ab522e7eadd78af870c3927ddb826c Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 20/30] schema.sql: add obs_web Replicated at production's path, obs_web_repl. --- scripts/cluster-migration/schema.sql | 107 +++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index e133d226..bf427e50 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -395,3 +395,110 @@ CREATE TABLE IF NOT EXISTS ooni.obs_openvpn ON CLUSTER oonidata_cluster ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/obs_openvpn/{shard}', '{replica}') ORDER BY (measurement_start_time, report_id, input) SETTINGS index_granularity = 8; + +CREATE TABLE IF NOT EXISTS ooni.obs_web ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `observation_idx` UInt16, + `input` Nullable(String), + `report_id` String, + `ooni_run_link_id` String DEFAULT '', + `measurement_start_time` DateTime64(3, 'UTC'), + `software_name` String, + `software_version` String, + `test_name` String, + `test_version` String, + `bucket_date` String, + `probe_asn` UInt32, + `probe_cc` String, + `probe_as_org_name` String, + `probe_as_cc` String, + `probe_as_name` String, + `network_type` String, + `platform` String, + `origin` String, + `engine_name` String, + `engine_version` String, + `architecture` String, + `resolver_ip` String, + `resolver_asn` UInt32, + `resolver_cc` String, + `resolver_as_org_name` String, + `resolver_as_cc` String, + `resolver_is_scrubbed` UInt8, + `resolver_asn_probe` UInt32, + `resolver_as_org_name_probe` String, + `created_at` Nullable(DateTime('UTC')), + `target_id` Nullable(String), + `hostname` Nullable(String), + `transaction_id` Nullable(UInt16), + `ip` Nullable(String), + `port` Nullable(UInt16), + `ip_asn` Nullable(UInt32), + `ip_as_org_name` Nullable(String), + `ip_as_cc` Nullable(String), + `ip_cc` Nullable(String), + `ip_is_bogon` Nullable(UInt8), + `dns_query_type` Nullable(String), + `dns_failure` Nullable(String), + `dns_engine` Nullable(String), + `dns_engine_resolver_address` Nullable(String), + `dns_answer_type` Nullable(String), + `dns_answer` Nullable(String), + `dns_answer_asn` Nullable(UInt32), + `dns_answer_as_org_name` Nullable(String), + `dns_t` Nullable(Float64), + `tcp_failure` Nullable(String), + `tcp_success` Nullable(UInt8), + `tcp_t` Nullable(Float64), + `tls_failure` Nullable(String), + `tls_server_name` Nullable(String), + `tls_outer_server_name` Nullable(String), + `tls_echconfig` Nullable(String), + `tls_version` Nullable(String), + `tls_cipher_suite` Nullable(String), + `tls_is_certificate_valid` Nullable(UInt8), + `tls_end_entity_certificate_fingerprint` Nullable(String), + `tls_end_entity_certificate_subject` Nullable(String), + `tls_end_entity_certificate_subject_common_name` Nullable(String), + `tls_end_entity_certificate_issuer` Nullable(String), + `tls_end_entity_certificate_issuer_common_name` Nullable(String), + `tls_end_entity_certificate_san_list` Array(String), + `tls_end_entity_certificate_not_valid_after` Nullable(DateTime64(3, 'UTC')), + `tls_end_entity_certificate_not_valid_before` Nullable(DateTime64(3, 'UTC')), + `tls_certificate_chain_length` Nullable(UInt16), + `tls_certificate_chain_fingerprints` Array(String), + `tls_handshake_read_count` Nullable(UInt16), + `tls_handshake_write_count` Nullable(UInt16), + `tls_handshake_read_bytes` Nullable(UInt32), + `tls_handshake_write_bytes` Nullable(UInt32), + `tls_handshake_last_operation` Nullable(String), + `tls_handshake_time` Nullable(Float64), + `tls_t` Nullable(Float64), + `http_request_url` Nullable(String), + `http_network` Nullable(String), + `http_alpn` Nullable(String), + `http_failure` Nullable(String), + `http_request_body_length` Nullable(UInt32), + `http_request_method` Nullable(String), + `http_runtime` Nullable(Float64), + `http_response_body_length` Nullable(Int32), + `http_response_body_is_truncated` Nullable(UInt8), + `http_response_body_sha1` Nullable(String), + `http_response_status_code` Nullable(UInt16), + `http_response_header_location` Nullable(String), + `http_response_header_server` Nullable(String), + `http_request_redirect_from` Nullable(String), + `http_request_body_is_truncated` Nullable(UInt8), + `http_t` Nullable(Float64), + `probe_analysis` Nullable(String), + `probe_id` FixedString(64), + INDEX measurement_start_time_idx measurement_start_time TYPE minmax GRANULARITY 2, + INDEX probe_cc_idx probe_cc TYPE minmax GRANULARITY 1, + INDEX probe_asn_idx probe_asn TYPE minmax GRANULARITY 1 +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/obs_web_repl/{shard}', '{replica}') +PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) +PRIMARY KEY (measurement_uid, observation_idx) +ORDER BY (measurement_uid, observation_idx, measurement_start_time, probe_cc, probe_asn) +SETTINGS index_granularity = 8192; From 46a1f809bdc6e05e1927549456e7daed3b269f19 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 21/30] schema.sql: add obs_web_ctrl --- scripts/cluster-migration/schema.sql | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index bf427e50..2ebeef7c 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -502,3 +502,44 @@ PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) PRIMARY KEY (measurement_uid, observation_idx) ORDER BY (measurement_uid, observation_idx, measurement_start_time, probe_cc, probe_asn) SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS ooni.obs_web_ctrl ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `observation_idx` UInt16, + `input` Nullable(String), + `report_id` String, + `ooni_run_link_id` String DEFAULT '', + `measurement_start_time` DateTime64(3, 'UTC'), + `software_name` String, + `software_version` String, + `test_name` String, + `test_version` String, + `bucket_date` String, + `hostname` String, + `created_at` Nullable(DateTime64(3, 'UTC')), + `ip` String, + `port` Nullable(UInt16), + `ip_asn` Nullable(UInt32), + `ip_as_org_name` Nullable(String), + `ip_as_cc` Nullable(String), + `ip_cc` Nullable(String), + `ip_is_bogon` Nullable(UInt8), + `dns_failure` Nullable(String), + `dns_success` Nullable(UInt8), + `tcp_failure` Nullable(String), + `tcp_success` Nullable(UInt8), + `tls_failure` Nullable(String), + `tls_success` Nullable(UInt8), + `tls_server_name` Nullable(String), + `http_request_url` Nullable(String), + `http_failure` Nullable(String), + `http_success` Nullable(UInt8), + `http_response_body_length` Nullable(Int32), + INDEX measurement_start_time_idx measurement_start_time TYPE minmax GRANULARITY 2 +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/obs_web_ctrl/{shard}', '{replica}') +PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) +PRIMARY KEY (measurement_uid, observation_idx) +ORDER BY (measurement_uid, observation_idx, measurement_start_time, hostname) +SETTINGS index_granularity = 8192; From 53a6e664d7c1baeaac565094a8f61b822ea13973 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 22/30] schema.sql: add test_groups A Join table, local to each node. --- scripts/cluster-migration/schema.sql | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 2ebeef7c..79b53964 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -543,3 +543,10 @@ PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) PRIMARY KEY (measurement_uid, observation_idx) ORDER BY (measurement_uid, observation_idx, measurement_start_time, hostname) SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS ooni.test_groups ON CLUSTER oonidata_cluster +( + `test_name` String, + `test_group` String +) +ENGINE = Join(ANY, LEFT, test_name); From edfd3acd8d2711ea0a896f8a74f6855c1bbcc2f6 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 23/30] schema.sql: add url_priorities --- scripts/cluster-migration/schema.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 79b53964..cb1f9d0b 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -550,3 +550,16 @@ CREATE TABLE IF NOT EXISTS ooni.test_groups ON CLUSTER oonidata_cluster `test_group` String ) ENGINE = Join(ANY, LEFT, test_name); + +CREATE TABLE IF NOT EXISTS ooni.url_priorities ON CLUSTER oonidata_cluster +( + `sign` Int8, + `category_code` String, + `cc` String, + `domain` String, + `url` String, + `priority` Int32 +) +ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/{cluster}/tables/ooni/url_priorities/{shard}', '{replica}', sign) +ORDER BY (category_code, cc, domain, url, priority) +SETTINGS index_granularity = 1024; From b6c37ade80633e784a67e287e5e8374df574d039 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 24/30] schema.sql: add the counters_asn_test_list view Its inner table keeps production's Keeper path, so a new replica joins the existing one. Production has the view on data1 and data3. --- scripts/cluster-migration/schema.sql | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index cb1f9d0b..72026ff2 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -563,3 +563,29 @@ CREATE TABLE IF NOT EXISTS ooni.url_priorities ON CLUSTER oonidata_cluster ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/{cluster}/tables/ooni/url_priorities/{shard}', '{replica}', sign) ORDER BY (category_code, cc, domain, url, priority) SETTINGS index_granularity = 1024; + +CREATE MATERIALIZED VIEW IF NOT EXISTS ooni.counters_asn_test_list ON CLUSTER oonidata_cluster +( + `week` DateTime, + `probe_cc` String, + `probe_asn` UInt64, + `input` String, + `msmt_cnt` UInt64 +) +ENGINE = ReplicatedSummingMergeTree('/clickhouse/{cluster}/tables/ooni/.inner_id.6a72ceec-7e0e-4b65-a3ab-da2809202114/{shard}', '{replica}') +ORDER BY (probe_cc, probe_asn, input) +SETTINGS index_granularity = 8192 +AS SELECT + toStartOfWeek(measurement_start_time) AS week, + probe_cc, + probe_asn, + input, + count() AS msmt_cnt +FROM ooni.fastpath +INNER JOIN ooni.citizenlab ON fastpath.input = citizenlab.url +WHERE (measurement_start_time < now()) AND (measurement_start_time > (now() - toIntervalDay(8))) AND (test_name = 'web_connectivity') +GROUP BY + week, + probe_cc, + probe_asn, + input; From 8a77a38765791c13dd77adee86a2a05de1a98d1b Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 08:39:41 +0000 Subject: [PATCH 25/30] schema.sql: say where the definitions come from A header with the dump date, which replica's definition is used where they differ, and what's left out: the updaters' *_tmp tables, msmt_feedback_old, session_expunge (unused since ooni/backend#972) and the leftover inner table of the dropped counters_test_list view. Also CREATE DATABASE, which the ooni. names need on a new cluster. --- scripts/cluster-migration/schema.sql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 72026ff2..9e1d76e0 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -1,3 +1,17 @@ +-- The tables and views of the ooni database, as production has them (dumped from every replica on +-- 2026-10-20 after asnmeta was made replicated again on data1, OOPRIV-181). Run on a new cluster with +-- clickhouse-client --multiquery < schema.sql +-- Where the replicas differ, this is the definition of the replica that holds the data: +-- event_detector_cusums, labeling_frames: data1 (the only replica with rows, and with their newer columns) +-- fastpath: data1 and data3 (data2 alone has deduplicate_merge_projection_mode = 'rebuild') +-- event_detector_cusums, event_detector_v2_changepoints, labeling_frames and changepoint_label are not +-- replicated: ON CLUSTER creates an empty local table on each node, as production has them. +-- Not included: the updaters' *_tmp tables (recreated on every run), msmt_feedback_old (superseded by +-- msmt_feedback), session_expunge (unused since backend #972) and the leftover inner table of the dropped +-- counters_test_list view. + +CREATE DATABASE IF NOT EXISTS ooni ON CLUSTER oonidata_cluster; + CREATE TABLE IF NOT EXISTS ooni.analysis_web_measurement ON CLUSTER oonidata_cluster ( `domain` String, From 8b1ae6c08c7daf59cac7c9d77d87569310901e24 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 09:39:09 +0000 Subject: [PATCH 26/30] schema.sql: {database} in the Keeper paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ClickHouse fills in {database} when it creates a table, so in production the paths are unchanged: /clickhouse/{cluster}/tables/ooni/
/{shard}. A second database on the same cluster, e.g. a scratch or CI one, now gets paths of its own instead of joining production's replicas. counters_asn_test_list's path keeps production's name for its hidden table, .inner_id.6a72ceec-…, with a comment saying why: a replica added later joins production's table whatever UUID its view gets. With {table} there, it would start a separate, empty path unless its CREATE copied the view's UUID. --- scripts/cluster-migration/schema.sql | 30 +++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 9e1d76e0..826c8115 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -48,7 +48,7 @@ CREATE TABLE IF NOT EXISTS ooni.analysis_web_measurement ON CLUSTER oonidata_clu INDEX probe_cc_idx probe_cc TYPE minmax GRANULARITY 1, INDEX probe_asn_idx probe_asn TYPE minmax GRANULARITY 1 ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/analysis_web_measurement/{shard}', '{replica}') +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/analysis_web_measurement/{shard}', '{replica}') PARTITION BY substring(measurement_uid, 1, 6) PRIMARY KEY measurement_uid ORDER BY (measurement_uid, measurement_start_time, probe_cc, probe_asn, domain) @@ -63,7 +63,7 @@ CREATE TABLE IF NOT EXISTS ooni.asnmeta ON CLUSTER oonidata_cluster `aut_name` String, `source` String ) -ENGINE = ReplicatedMergeTree('/clickhouse/{cluster}/tables/ooni/asnmeta', '{replica}') +ENGINE = ReplicatedMergeTree('/clickhouse/{cluster}/tables/{database}/asnmeta', '{replica}') ORDER BY (asn, changed) SETTINGS index_granularity = 8192; @@ -97,7 +97,7 @@ CREATE TABLE IF NOT EXISTS ooni.citizenlab ON CLUSTER oonidata_cluster `cc` FixedString(32), `category_code` String ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/citizenlab', '{replica}') +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/citizenlab', '{replica}') ORDER BY (domain, url, cc, category_code) SETTINGS index_granularity = 4; @@ -121,7 +121,7 @@ CREATE TABLE IF NOT EXISTS ooni.event_detector_changepoints ON CLUSTER oonidata_ `h` Nullable(Float32), `block_type` String ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/event_detector_changepoints/{shard}', '{replica}') +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/event_detector_changepoints/{shard}', '{replica}') ORDER BY (probe_asn, probe_cc, ts, domain) SETTINGS index_granularity = 8192; @@ -219,7 +219,7 @@ CREATE TABLE IF NOT EXISTS ooni.fastpath ON CLUSTER oonidata_cluster INDEX measurement_uid_idx measurement_uid TYPE minmax GRANULARITY 8, INDEX input_bloom_idx input TYPE bloom_filter(0.01) GRANULARITY 1 ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/fastpath/{shard}', '{replica}', update_time) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/fastpath/{shard}', '{replica}', update_time) ORDER BY (measurement_start_time, report_id, input, measurement_uid) SETTINGS index_granularity = 8192; @@ -234,7 +234,7 @@ CREATE TABLE IF NOT EXISTS ooni.faulty_measurements ON CLUSTER oonidata_cluster -- JSON-encoded details about the anomaly `details` String ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/faulty_measurements/{shard}', '{replica}') +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/faulty_measurements/{shard}', '{replica}') ORDER BY (ts, type, probe_cc, probe_asn, uid) SETTINGS index_granularity = 8192; @@ -283,7 +283,7 @@ CREATE TABLE IF NOT EXISTS ooni.jsonl ON CLUSTER oonidata_cluster `source` String, `update_time` DateTime64(3) MATERIALIZED now64() ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/jsonl/{shard}', '{replica}', update_time) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/jsonl/{shard}', '{replica}', update_time) ORDER BY (report_id, input, measurement_uid) SETTINGS index_granularity = 8192; @@ -311,7 +311,7 @@ CREATE TABLE IF NOT EXISTS ooni.msmt_feedback ON CLUSTER oonidata_cluster `update_time` DateTime64(3) DEFAULT now64(), `comment` String ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/msmt_feedback_new/{shard}', '{replica}') +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/msmt_feedback_new/{shard}', '{replica}') ORDER BY (measurement_uid, account_id, update_time) SETTINGS index_granularity = 4; @@ -365,7 +365,7 @@ CREATE TABLE IF NOT EXISTS ooni.obs_http_middlebox ON CLUSTER oonidata_cluster `hfm_success` Nullable(UInt8), `probe_id` FixedString(64) ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/obs_http_middlebox/{shard}', '{replica}') +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/obs_http_middlebox/{shard}', '{replica}') PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) PRIMARY KEY (measurement_uid, observation_idx) ORDER BY (measurement_uid, observation_idx, measurement_start_time) @@ -406,7 +406,7 @@ CREATE TABLE IF NOT EXISTS ooni.obs_openvpn ON CLUSTER oonidata_cluster `test_start_time` DateTime, `transport` String ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/obs_openvpn/{shard}', '{replica}') +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/obs_openvpn/{shard}', '{replica}') ORDER BY (measurement_start_time, report_id, input) SETTINGS index_granularity = 8; @@ -511,7 +511,7 @@ CREATE TABLE IF NOT EXISTS ooni.obs_web ON CLUSTER oonidata_cluster INDEX probe_cc_idx probe_cc TYPE minmax GRANULARITY 1, INDEX probe_asn_idx probe_asn TYPE minmax GRANULARITY 1 ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/obs_web_repl/{shard}', '{replica}') +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/obs_web_repl/{shard}', '{replica}') PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) PRIMARY KEY (measurement_uid, observation_idx) ORDER BY (measurement_uid, observation_idx, measurement_start_time, probe_cc, probe_asn) @@ -552,7 +552,7 @@ CREATE TABLE IF NOT EXISTS ooni.obs_web_ctrl ON CLUSTER oonidata_cluster `http_response_body_length` Nullable(Int32), INDEX measurement_start_time_idx measurement_start_time TYPE minmax GRANULARITY 2 ) -ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/ooni/obs_web_ctrl/{shard}', '{replica}') +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/obs_web_ctrl/{shard}', '{replica}') PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) PRIMARY KEY (measurement_uid, observation_idx) ORDER BY (measurement_uid, observation_idx, measurement_start_time, hostname) @@ -574,10 +574,12 @@ CREATE TABLE IF NOT EXISTS ooni.url_priorities ON CLUSTER oonidata_cluster `url` String, `priority` Int32 ) -ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/{cluster}/tables/ooni/url_priorities/{shard}', '{replica}', sign) +ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/{cluster}/tables/{database}/url_priorities/{shard}', '{replica}', sign) ORDER BY (category_code, cc, domain, url, priority) SETTINGS index_granularity = 1024; +-- Its rows are in a hidden table, .inner_id.. The Keeper path keeps production's name +-- for it, so a replica added later joins production's table whatever UUID its view gets. CREATE MATERIALIZED VIEW IF NOT EXISTS ooni.counters_asn_test_list ON CLUSTER oonidata_cluster ( `week` DateTime, @@ -586,7 +588,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS ooni.counters_asn_test_list ON CLUSTER oo `input` String, `msmt_cnt` UInt64 ) -ENGINE = ReplicatedSummingMergeTree('/clickhouse/{cluster}/tables/ooni/.inner_id.6a72ceec-7e0e-4b65-a3ab-da2809202114/{shard}', '{replica}') +ENGINE = ReplicatedSummingMergeTree('/clickhouse/{cluster}/tables/{database}/.inner_id.6a72ceec-7e0e-4b65-a3ab-da2809202114/{shard}', '{replica}') ORDER BY (probe_cc, probe_asn, input) SETTINGS index_granularity = 8192 AS SELECT From 850676239bd51c17f54d70065d117f67f520ca2f Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 09:39:09 +0000 Subject: [PATCH 27/30] schema.sql: leave the database to the client Table names are unqualified, so clickhouse-client --database decides where the file loads, and CREATE DATABASE moves to the header's instructions: it has to exist on every node first, or the nodes without it fail with UNKNOWN_DATABASE while the others create the table. Tested on a two-node 24.8.6.70 cluster with Keeper. The node that receives an ON CLUSTER query qualifies its names with the client's database before passing it on, so every node uses that database, not its own default. Loaded into ooni, this file gives exactly the definitions and Keeper paths of the previous commit's file on both nodes; loaded again into ooni_test on the same cluster, it shares no path with ooni, and its view reads ooni_test's tables. --- scripts/cluster-migration/schema.sql | 57 +++++++++++++++------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 826c8115..48cdf331 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -1,6 +1,11 @@ -- The tables and views of the ooni database, as production has them (dumped from every replica on --- 2026-10-20 after asnmeta was made replicated again on data1, OOPRIV-181). Run on a new cluster with --- clickhouse-client --multiquery < schema.sql +-- 2026-10-20 after asnmeta was made replicated again on data1, OOPRIV-181). Create the database on every +-- node, then load this file into it: +-- clickhouse-client -q "CREATE DATABASE IF NOT EXISTS ooni ON CLUSTER oonidata_cluster" +-- clickhouse-client --database ooni --multiquery < schema.sql +-- Any database name works, e.g. for CI: ON CLUSTER creates each table in the client's database on every +-- node, and the Keeper paths include {database}, so a second database on the same cluster doesn't share +-- production's replicas. -- Where the replicas differ, this is the definition of the replica that holds the data: -- event_detector_cusums, labeling_frames: data1 (the only replica with rows, and with their newer columns) -- fastpath: data1 and data3 (data2 alone has deduplicate_merge_projection_mode = 'rebuild') @@ -10,9 +15,7 @@ -- msmt_feedback), session_expunge (unused since backend #972) and the leftover inner table of the dropped -- counters_test_list view. -CREATE DATABASE IF NOT EXISTS ooni ON CLUSTER oonidata_cluster; - -CREATE TABLE IF NOT EXISTS ooni.analysis_web_measurement ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS analysis_web_measurement ON CLUSTER oonidata_cluster ( `domain` String, `input` String, @@ -54,7 +57,7 @@ PRIMARY KEY measurement_uid ORDER BY (measurement_uid, measurement_start_time, probe_cc, probe_asn, domain) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.asnmeta ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS asnmeta ON CLUSTER oonidata_cluster ( `asn` UInt32, `org_name` String, @@ -67,7 +70,7 @@ ENGINE = ReplicatedMergeTree('/clickhouse/{cluster}/tables/{database}/asnmeta', ORDER BY (asn, changed) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.changepoint_label ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS changepoint_label ON CLUSTER oonidata_cluster ( -- Ground truth, set by a person. Represents the network state for -- the (probe_cc, probe_asn, resolver_asn, domain) series of the @@ -90,7 +93,7 @@ ENGINE = MergeTree ORDER BY (changepoint_id, created_at, id) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.citizenlab ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS citizenlab ON CLUSTER oonidata_cluster ( `domain` String, `url` String, @@ -101,7 +104,7 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/c ORDER BY (domain, url, cc, category_code) SETTINGS index_granularity = 4; -CREATE TABLE IF NOT EXISTS ooni.event_detector_changepoints ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS event_detector_changepoints ON CLUSTER oonidata_cluster ( `probe_asn` UInt32, `probe_cc` String, @@ -125,7 +128,7 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/e ORDER BY (probe_asn, probe_cc, ts, domain) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.event_detector_cusums ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS event_detector_cusums ON CLUSTER oonidata_cluster ( `probe_asn` UInt32, `probe_cc` String, @@ -156,7 +159,7 @@ ENGINE = ReplacingMergeTree(ts) ORDER BY (probe_asn, probe_cc, domain) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.event_detector_v2_changepoints ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS event_detector_v2_changepoints ON CLUSTER oonidata_cluster ( `uuid` UUID, `domain` String, @@ -177,7 +180,7 @@ ENGINE = MergeTree ORDER BY (ts_hour, domain, layer, probe_cc, probe_asn, resolver_asn, state, uuid) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.fastpath ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS fastpath ON CLUSTER oonidata_cluster ( `measurement_uid` String, `report_id` String, @@ -223,7 +226,7 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/f ORDER BY (measurement_start_time, report_id, input, measurement_uid) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.faulty_measurements ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS faulty_measurements ON CLUSTER oonidata_cluster ( `ts` DateTime64(3, 'UTC') DEFAULT now64(), `type` String, @@ -238,7 +241,7 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/f ORDER BY (ts, type, probe_cc, probe_asn, uid) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.fingerprints_dns ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS fingerprints_dns ON CLUSTER oonidata_cluster ( `name` String, `scope` Enum8('nat' = 1, 'isp' = 2, 'prod' = 3, 'inst' = 4, 'vbw' = 5, 'fp' = 6), @@ -255,7 +258,7 @@ CREATE TABLE IF NOT EXISTS ooni.fingerprints_dns ON CLUSTER oonidata_cluster ENGINE = EmbeddedRocksDB PRIMARY KEY name; -CREATE TABLE IF NOT EXISTS ooni.fingerprints_http ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS fingerprints_http ON CLUSTER oonidata_cluster ( `name` String, `scope` Enum8('nat' = 1, 'isp' = 2, 'prod' = 3, 'inst' = 4, 'vbw' = 5, 'fp' = 6, 'injb' = 7, 'prov' = 8), @@ -272,7 +275,7 @@ CREATE TABLE IF NOT EXISTS ooni.fingerprints_http ON CLUSTER oonidata_cluster ENGINE = EmbeddedRocksDB PRIMARY KEY name; -CREATE TABLE IF NOT EXISTS ooni.jsonl ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS jsonl ON CLUSTER oonidata_cluster ( `report_id` String, `input` String, @@ -287,7 +290,7 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/j ORDER BY (report_id, input, measurement_uid) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.labeling_frames ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS labeling_frames ON CLUSTER oonidata_cluster ( `measurement_uid` String, `blocked_fastpath` Bool, @@ -303,7 +306,7 @@ ENGINE = MergeTree ORDER BY (stratum, measurement_uid) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.msmt_feedback ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS msmt_feedback ON CLUSTER oonidata_cluster ( `measurement_uid` String, `account_id` String, @@ -315,7 +318,7 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/m ORDER BY (measurement_uid, account_id, update_time) SETTINGS index_granularity = 4; -CREATE TABLE IF NOT EXISTS ooni.obs_http_middlebox ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS obs_http_middlebox ON CLUSTER oonidata_cluster ( `measurement_uid` String, `observation_idx` UInt16, @@ -371,7 +374,7 @@ PRIMARY KEY (measurement_uid, observation_idx) ORDER BY (measurement_uid, observation_idx, measurement_start_time) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.obs_openvpn ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS obs_openvpn ON CLUSTER oonidata_cluster ( `anomaly` Int8, `bootstrap_time` Float32, @@ -410,7 +413,7 @@ ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/o ORDER BY (measurement_start_time, report_id, input) SETTINGS index_granularity = 8; -CREATE TABLE IF NOT EXISTS ooni.obs_web ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS obs_web ON CLUSTER oonidata_cluster ( `measurement_uid` String, `observation_idx` UInt16, @@ -517,7 +520,7 @@ PRIMARY KEY (measurement_uid, observation_idx) ORDER BY (measurement_uid, observation_idx, measurement_start_time, probe_cc, probe_asn) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.obs_web_ctrl ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS obs_web_ctrl ON CLUSTER oonidata_cluster ( `measurement_uid` String, `observation_idx` UInt16, @@ -558,14 +561,14 @@ PRIMARY KEY (measurement_uid, observation_idx) ORDER BY (measurement_uid, observation_idx, measurement_start_time, hostname) SETTINGS index_granularity = 8192; -CREATE TABLE IF NOT EXISTS ooni.test_groups ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS test_groups ON CLUSTER oonidata_cluster ( `test_name` String, `test_group` String ) ENGINE = Join(ANY, LEFT, test_name); -CREATE TABLE IF NOT EXISTS ooni.url_priorities ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS url_priorities ON CLUSTER oonidata_cluster ( `sign` Int8, `category_code` String, @@ -580,7 +583,7 @@ SETTINGS index_granularity = 1024; -- Its rows are in a hidden table, .inner_id.. The Keeper path keeps production's name -- for it, so a replica added later joins production's table whatever UUID its view gets. -CREATE MATERIALIZED VIEW IF NOT EXISTS ooni.counters_asn_test_list ON CLUSTER oonidata_cluster +CREATE MATERIALIZED VIEW IF NOT EXISTS counters_asn_test_list ON CLUSTER oonidata_cluster ( `week` DateTime, `probe_cc` String, @@ -597,8 +600,8 @@ AS SELECT probe_asn, input, count() AS msmt_cnt -FROM ooni.fastpath -INNER JOIN ooni.citizenlab ON fastpath.input = citizenlab.url +FROM fastpath +INNER JOIN citizenlab ON fastpath.input = citizenlab.url WHERE (measurement_start_time < now()) AND (measurement_start_time > (now() - toIntervalDay(8))) AND (test_name = 'web_connectivity') GROUP BY week, From 45f1940f2600e0be5048409d3940caf8c22817b4 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 09:54:03 +0000 Subject: [PATCH 28/30] Add a migrations directory, with schema.sql as its baseline schema.sql stays the schema as it is now. A change to an existing cluster goes in a numbered file in migrations/, applied once, in order, on one node. 000_baseline.sql is schema.sql as of this PR and is never edited; the README says how to run, document and record a migration. schema.sql's header points to it. --- .../migrations/000_baseline.sql | 610 ++++++++++++++++++ .../cluster-migration/migrations/README.md | 15 + scripts/cluster-migration/schema.sql | 2 +- 3 files changed, 626 insertions(+), 1 deletion(-) create mode 100644 scripts/cluster-migration/migrations/000_baseline.sql create mode 100644 scripts/cluster-migration/migrations/README.md diff --git a/scripts/cluster-migration/migrations/000_baseline.sql b/scripts/cluster-migration/migrations/000_baseline.sql new file mode 100644 index 00000000..48cdf331 --- /dev/null +++ b/scripts/cluster-migration/migrations/000_baseline.sql @@ -0,0 +1,610 @@ +-- The tables and views of the ooni database, as production has them (dumped from every replica on +-- 2026-10-20 after asnmeta was made replicated again on data1, OOPRIV-181). Create the database on every +-- node, then load this file into it: +-- clickhouse-client -q "CREATE DATABASE IF NOT EXISTS ooni ON CLUSTER oonidata_cluster" +-- clickhouse-client --database ooni --multiquery < schema.sql +-- Any database name works, e.g. for CI: ON CLUSTER creates each table in the client's database on every +-- node, and the Keeper paths include {database}, so a second database on the same cluster doesn't share +-- production's replicas. +-- Where the replicas differ, this is the definition of the replica that holds the data: +-- event_detector_cusums, labeling_frames: data1 (the only replica with rows, and with their newer columns) +-- fastpath: data1 and data3 (data2 alone has deduplicate_merge_projection_mode = 'rebuild') +-- event_detector_cusums, event_detector_v2_changepoints, labeling_frames and changepoint_label are not +-- replicated: ON CLUSTER creates an empty local table on each node, as production has them. +-- Not included: the updaters' *_tmp tables (recreated on every run), msmt_feedback_old (superseded by +-- msmt_feedback), session_expunge (unused since backend #972) and the leftover inner table of the dropped +-- counters_test_list view. + +CREATE TABLE IF NOT EXISTS analysis_web_measurement ON CLUSTER oonidata_cluster +( + `domain` String, + `input` String, + `test_name` String, + `probe_asn` UInt32, + `probe_as_org_name` String, + `probe_cc` String, + `resolver_asn` UInt32, + `resolver_as_cc` String, + `network_type` String, + `measurement_start_time` DateTime64(3, 'UTC'), + `measurement_uid` String, + `ooni_run_link_id` String, + `top_probe_analysis` Nullable(String), + `top_dns_failure` Nullable(String), + `top_tcp_failure` Nullable(String), + `top_tls_failure` Nullable(String), + `dns_blocked` Float32, + `dns_down` Float32, + `dns_ok` Float32, + `tcp_blocked` Float32, + `tcp_down` Float32, + `tcp_ok` Float32, + `tls_blocked` Float32, + `tls_down` Float32, + `tls_ok` Float32, + `top_dns_rule_id` LowCardinality(String), + `top_tcp_rule_id` LowCardinality(String), + `top_tls_rule_id` LowCardinality(String), + `probe_id` FixedString(64), + `analysis_rules_version` UInt16, + INDEX measurement_start_time_idx measurement_start_time TYPE minmax GRANULARITY 2, + INDEX probe_cc_idx probe_cc TYPE minmax GRANULARITY 1, + INDEX probe_asn_idx probe_asn TYPE minmax GRANULARITY 1 +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/analysis_web_measurement/{shard}', '{replica}') +PARTITION BY substring(measurement_uid, 1, 6) +PRIMARY KEY measurement_uid +ORDER BY (measurement_uid, measurement_start_time, probe_cc, probe_asn, domain) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS asnmeta ON CLUSTER oonidata_cluster +( + `asn` UInt32, + `org_name` String, + `cc` String, + `changed` Date, + `aut_name` String, + `source` String +) +ENGINE = ReplicatedMergeTree('/clickhouse/{cluster}/tables/{database}/asnmeta', '{replica}') +ORDER BY (asn, changed) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS changepoint_label ON CLUSTER oonidata_cluster +( + -- Ground truth, set by a person. Represents the network state for + -- the (probe_cc, probe_asn, resolver_asn, domain) series of the + -- changepoint it labels + `id` UUID, + -- UUID in event_detector_v2_changepoints (foreign key) + `changepoint_id` UUID, + `created_at` DateTime64(3, 'UTC') DEFAULT now64(), + `author` String, + -- blocked, ok or undecided + `verdict` LowCardinality(String), + -- Additional context the author might share + `notes` String, + `last_ok_time` Nullable(DateTime64(3, 'UTC')), + `first_block_time` Nullable(DateTime64(3, 'UTC')), + `last_block_time` Nullable(DateTime64(3, 'UTC')), + `first_ok_time` Nullable(DateTime64(3, 'UTC')) +) +ENGINE = MergeTree +ORDER BY (changepoint_id, created_at, id) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS citizenlab ON CLUSTER oonidata_cluster +( + `domain` String, + `url` String, + `cc` FixedString(32), + `category_code` String +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/citizenlab', '{replica}') +ORDER BY (domain, url, cc, category_code) +SETTINGS index_granularity = 4; + +CREATE TABLE IF NOT EXISTS event_detector_changepoints ON CLUSTER oonidata_cluster +( + `probe_asn` UInt32, + `probe_cc` String, + `domain` String, + `ts` DateTime64(3, 'UTC'), + `count_isp_resolver` Nullable(UInt32), + `count_other_resolver` Nullable(UInt32), + `count` Nullable(UInt32), + `dns_isp_blocked` Nullable(Float32), + `dns_other_blocked` Nullable(Float32), + `tcp_blocked` Nullable(Float32), + `tls_blocked` Nullable(Float32), + `change_dir` Nullable(Int8), + `s_pos` Nullable(Float32), + `s_neg` Nullable(Float32), + `current_state` String, + `h` Nullable(Float32), + `block_type` String +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/event_detector_changepoints/{shard}', '{replica}') +ORDER BY (probe_asn, probe_cc, ts, domain) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS event_detector_cusums ON CLUSTER oonidata_cluster +( + `probe_asn` UInt32, + `probe_cc` String, + `domain` String, + `ts` DateTime64(3, 'UTC'), + `dns_isp_blocked_current_state` String DEFAULT 'ok', + `dns_isp_blocked_s_pos` Nullable(Float64), + `dns_isp_blocked_s_neg` Nullable(Float64), + `dns_other_blocked_current_state` String DEFAULT 'ok', + `dns_other_blocked_s_pos` Nullable(Float64), + `dns_other_blocked_s_neg` Nullable(Float64), + `tcp_blocked_current_state` String DEFAULT 'ok', + `tcp_blocked_s_pos` Nullable(Float64), + `tcp_blocked_s_neg` Nullable(Float64), + `tls_blocked_current_state` String DEFAULT 'ok', + `tls_blocked_s_pos` Nullable(Float64), + `tls_blocked_s_neg` Nullable(Float64), + `dns_isp_blocked_last_change` Int8 DEFAULT 0, + `dns_isp_blocked_last_ts` Nullable(DateTime64(3, 'UTC')), + `dns_other_blocked_last_change` Int8 DEFAULT 0, + `dns_other_blocked_last_ts` Nullable(DateTime64(3, 'UTC')), + `tcp_blocked_last_change` Int8 DEFAULT 0, + `tcp_blocked_last_ts` Nullable(DateTime64(3, 'UTC')), + `tls_blocked_last_change` Int8 DEFAULT 0, + `tls_blocked_last_ts` Nullable(DateTime64(3, 'UTC')) +) +ENGINE = ReplacingMergeTree(ts) +ORDER BY (probe_asn, probe_cc, domain) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS event_detector_v2_changepoints ON CLUSTER oonidata_cluster +( + `uuid` UUID, + `domain` String, + `probe_cc` String, + `probe_asn` UInt32, + `resolver_asn` UInt32, + `layer` LowCardinality(String), + `ts_hour` DateTime64(3, 'UTC'), + `s_neg` Float64, + `s_pos` Float64, + `h` Float64, + `state` LowCardinality(String), + -- JSON-encoded parameters the detector was run with + `run_parameters` String, + `created_at` DateTime64(3, 'UTC') DEFAULT now64() +) +ENGINE = MergeTree +ORDER BY (ts_hour, domain, layer, probe_cc, probe_asn, resolver_asn, state, uuid) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS fastpath ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `report_id` String, + `input` String, + `probe_cc` LowCardinality(String), + `probe_asn` Int32, + `test_name` LowCardinality(String), + `test_start_time` DateTime, + `measurement_start_time` DateTime, + `filename` String, + `scores` String, + `platform` String, + `anomaly` LowCardinality(String), + `confirmed` LowCardinality(String), + `msm_failure` LowCardinality(String), + `domain` String, + `software_name` String, + `software_version` String, + `control_failure` String, + `blocking_general` Float32, + `is_ssl_expected` Int8, + `page_len` Int32, + `page_len_ratio` Float32, + `server_cc` String, + `server_asn` Int8, + `server_as_name` String, + `update_time` DateTime64(3) MATERIALIZED now64(), + `test_version` String, + `architecture` String, + `engine_name` LowCardinality(String), + `engine_version` String, + `test_runtime` Float32, + `blocking_type` String, + `test_helper_address` LowCardinality(String), + `test_helper_type` LowCardinality(String), + `ooni_run_link_id` Nullable(UInt64), + `is_verified` LowCardinality(String) DEFAULT 'u', + INDEX fastpath_rid_idx report_id TYPE minmax GRANULARITY 1, + INDEX measurement_uid_idx measurement_uid TYPE minmax GRANULARITY 8, + INDEX input_bloom_idx input TYPE bloom_filter(0.01) GRANULARITY 1 +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/fastpath/{shard}', '{replica}', update_time) +ORDER BY (measurement_start_time, report_id, input, measurement_uid) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS faulty_measurements ON CLUSTER oonidata_cluster +( + `ts` DateTime64(3, 'UTC') DEFAULT now64(), + `type` String, + `uid` UUID DEFAULT generateUUIDv4(), + -- geoip lookup result for the probe IP + `probe_cc` String, + `probe_asn` UInt32, + -- JSON-encoded details about the anomaly + `details` String +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/faulty_measurements/{shard}', '{replica}') +ORDER BY (ts, type, probe_cc, probe_asn, uid) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS fingerprints_dns ON CLUSTER oonidata_cluster +( + `name` String, + `scope` Enum8('nat' = 1, 'isp' = 2, 'prod' = 3, 'inst' = 4, 'vbw' = 5, 'fp' = 6), + `other_names` String, + `location_found` String, + `pattern_type` Enum8('full' = 1, 'prefix' = 2, 'contains' = 3, 'regexp' = 4), + `pattern` String, + `confidence_no_fp` UInt8, + `expected_countries` String, + `source` String, + `exp_url` String, + `notes` String +) +ENGINE = EmbeddedRocksDB +PRIMARY KEY name; + +CREATE TABLE IF NOT EXISTS fingerprints_http ON CLUSTER oonidata_cluster +( + `name` String, + `scope` Enum8('nat' = 1, 'isp' = 2, 'prod' = 3, 'inst' = 4, 'vbw' = 5, 'fp' = 6, 'injb' = 7, 'prov' = 8), + `other_names` String, + `location_found` String, + `pattern_type` Enum8('full' = 1, 'prefix' = 2, 'contains' = 3, 'regexp' = 4), + `pattern` String, + `confidence_no_fp` UInt8, + `expected_countries` String, + `source` String, + `exp_url` String, + `notes` String +) +ENGINE = EmbeddedRocksDB +PRIMARY KEY name; + +CREATE TABLE IF NOT EXISTS jsonl ON CLUSTER oonidata_cluster +( + `report_id` String, + `input` String, + `s3path` String, + `linenum` Int32, + `measurement_uid` String, + `date` Date, + `source` String, + `update_time` DateTime64(3) MATERIALIZED now64() +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/jsonl/{shard}', '{replica}', update_time) +ORDER BY (report_id, input, measurement_uid) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS labeling_frames ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `blocked_fastpath` Bool, + `blocked_analysis` Bool, + `stratum` LowCardinality(String), + `test_name` LowCardinality(String), + `day` DateTime('UTC'), + `fastpath_query` LowCardinality(String), + `analysis_query` LowCardinality(String), + `failed_fastpath` Bool +) +ENGINE = MergeTree +ORDER BY (stratum, measurement_uid) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS msmt_feedback ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `account_id` String, + `status` String, + `update_time` DateTime64(3) DEFAULT now64(), + `comment` String +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/msmt_feedback_new/{shard}', '{replica}') +ORDER BY (measurement_uid, account_id, update_time) +SETTINGS index_granularity = 4; + +CREATE TABLE IF NOT EXISTS obs_http_middlebox ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `observation_idx` UInt16, + `input` Nullable(String), + `report_id` String, + `ooni_run_link_id` String DEFAULT '', + `measurement_start_time` DateTime64(3, 'UTC'), + `software_name` String, + `software_version` String, + `test_name` String, + `test_version` String, + `bucket_date` String, + `probe_asn` UInt32, + `probe_cc` String, + `probe_as_org_name` String, + `probe_as_cc` String, + `probe_as_name` String, + `network_type` String, + `platform` String, + `origin` String, + `engine_name` String, + `engine_version` String, + `architecture` String, + `resolver_ip` String, + `resolver_asn` UInt32, + `resolver_cc` String, + `resolver_as_org_name` String, + `resolver_as_cc` String, + `resolver_is_scrubbed` UInt8, + `resolver_asn_probe` UInt32, + `resolver_as_org_name_probe` String, + `created_at` Nullable(DateTime64(3, 'UTC')), + `hirl_sent_0` Nullable(String), + `hirl_sent_1` Nullable(String), + `hirl_sent_2` Nullable(String), + `hirl_sent_3` Nullable(String), + `hirl_sent_4` Nullable(String), + `hirl_received_0` Nullable(String), + `hirl_received_1` Nullable(String), + `hirl_received_2` Nullable(String), + `hirl_received_3` Nullable(String), + `hirl_received_4` Nullable(String), + `hirl_failure` Nullable(String), + `hirl_success` Nullable(UInt8), + `hfm_diff` Nullable(String), + `hfm_failure` Nullable(String), + `hfm_success` Nullable(UInt8), + `probe_id` FixedString(64) +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/obs_http_middlebox/{shard}', '{replica}') +PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) +PRIMARY KEY (measurement_uid, observation_idx) +ORDER BY (measurement_uid, observation_idx, measurement_start_time) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS obs_openvpn ON CLUSTER oonidata_cluster +( + `anomaly` Int8, + `bootstrap_time` Float32, + `confirmed` Int8, + `error` String, + `failure` String, + `input` String, + `last_handshake_transaction_id` Int32, + `measurement_start_time` DateTime, + `measurement_uid` String, + `minivpn_version` String, + `obfs4_version` String, + `obfuscation` String, + `platform` String, + `probe_asn` Int32, + `probe_cc` String, + `probe_network_name` String, + `provider` String, + `remote` String, + `report_id` String, + `resolver_asn` Int32, + `resolver_ip` String, + `resolver_network_name` String, + `software_name` String, + `software_version` String, + `success` Int8, + `success_handshake` Int8, + `success_icmp` Int8, + `success_urlgrab` Int8, + `tcp_connect_status_success` Int8, + `test_runtime` Float32, + `test_start_time` DateTime, + `transport` String +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/obs_openvpn/{shard}', '{replica}') +ORDER BY (measurement_start_time, report_id, input) +SETTINGS index_granularity = 8; + +CREATE TABLE IF NOT EXISTS obs_web ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `observation_idx` UInt16, + `input` Nullable(String), + `report_id` String, + `ooni_run_link_id` String DEFAULT '', + `measurement_start_time` DateTime64(3, 'UTC'), + `software_name` String, + `software_version` String, + `test_name` String, + `test_version` String, + `bucket_date` String, + `probe_asn` UInt32, + `probe_cc` String, + `probe_as_org_name` String, + `probe_as_cc` String, + `probe_as_name` String, + `network_type` String, + `platform` String, + `origin` String, + `engine_name` String, + `engine_version` String, + `architecture` String, + `resolver_ip` String, + `resolver_asn` UInt32, + `resolver_cc` String, + `resolver_as_org_name` String, + `resolver_as_cc` String, + `resolver_is_scrubbed` UInt8, + `resolver_asn_probe` UInt32, + `resolver_as_org_name_probe` String, + `created_at` Nullable(DateTime('UTC')), + `target_id` Nullable(String), + `hostname` Nullable(String), + `transaction_id` Nullable(UInt16), + `ip` Nullable(String), + `port` Nullable(UInt16), + `ip_asn` Nullable(UInt32), + `ip_as_org_name` Nullable(String), + `ip_as_cc` Nullable(String), + `ip_cc` Nullable(String), + `ip_is_bogon` Nullable(UInt8), + `dns_query_type` Nullable(String), + `dns_failure` Nullable(String), + `dns_engine` Nullable(String), + `dns_engine_resolver_address` Nullable(String), + `dns_answer_type` Nullable(String), + `dns_answer` Nullable(String), + `dns_answer_asn` Nullable(UInt32), + `dns_answer_as_org_name` Nullable(String), + `dns_t` Nullable(Float64), + `tcp_failure` Nullable(String), + `tcp_success` Nullable(UInt8), + `tcp_t` Nullable(Float64), + `tls_failure` Nullable(String), + `tls_server_name` Nullable(String), + `tls_outer_server_name` Nullable(String), + `tls_echconfig` Nullable(String), + `tls_version` Nullable(String), + `tls_cipher_suite` Nullable(String), + `tls_is_certificate_valid` Nullable(UInt8), + `tls_end_entity_certificate_fingerprint` Nullable(String), + `tls_end_entity_certificate_subject` Nullable(String), + `tls_end_entity_certificate_subject_common_name` Nullable(String), + `tls_end_entity_certificate_issuer` Nullable(String), + `tls_end_entity_certificate_issuer_common_name` Nullable(String), + `tls_end_entity_certificate_san_list` Array(String), + `tls_end_entity_certificate_not_valid_after` Nullable(DateTime64(3, 'UTC')), + `tls_end_entity_certificate_not_valid_before` Nullable(DateTime64(3, 'UTC')), + `tls_certificate_chain_length` Nullable(UInt16), + `tls_certificate_chain_fingerprints` Array(String), + `tls_handshake_read_count` Nullable(UInt16), + `tls_handshake_write_count` Nullable(UInt16), + `tls_handshake_read_bytes` Nullable(UInt32), + `tls_handshake_write_bytes` Nullable(UInt32), + `tls_handshake_last_operation` Nullable(String), + `tls_handshake_time` Nullable(Float64), + `tls_t` Nullable(Float64), + `http_request_url` Nullable(String), + `http_network` Nullable(String), + `http_alpn` Nullable(String), + `http_failure` Nullable(String), + `http_request_body_length` Nullable(UInt32), + `http_request_method` Nullable(String), + `http_runtime` Nullable(Float64), + `http_response_body_length` Nullable(Int32), + `http_response_body_is_truncated` Nullable(UInt8), + `http_response_body_sha1` Nullable(String), + `http_response_status_code` Nullable(UInt16), + `http_response_header_location` Nullable(String), + `http_response_header_server` Nullable(String), + `http_request_redirect_from` Nullable(String), + `http_request_body_is_truncated` Nullable(UInt8), + `http_t` Nullable(Float64), + `probe_analysis` Nullable(String), + `probe_id` FixedString(64), + INDEX measurement_start_time_idx measurement_start_time TYPE minmax GRANULARITY 2, + INDEX probe_cc_idx probe_cc TYPE minmax GRANULARITY 1, + INDEX probe_asn_idx probe_asn TYPE minmax GRANULARITY 1 +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/obs_web_repl/{shard}', '{replica}') +PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) +PRIMARY KEY (measurement_uid, observation_idx) +ORDER BY (measurement_uid, observation_idx, measurement_start_time, probe_cc, probe_asn) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS obs_web_ctrl ON CLUSTER oonidata_cluster +( + `measurement_uid` String, + `observation_idx` UInt16, + `input` Nullable(String), + `report_id` String, + `ooni_run_link_id` String DEFAULT '', + `measurement_start_time` DateTime64(3, 'UTC'), + `software_name` String, + `software_version` String, + `test_name` String, + `test_version` String, + `bucket_date` String, + `hostname` String, + `created_at` Nullable(DateTime64(3, 'UTC')), + `ip` String, + `port` Nullable(UInt16), + `ip_asn` Nullable(UInt32), + `ip_as_org_name` Nullable(String), + `ip_as_cc` Nullable(String), + `ip_cc` Nullable(String), + `ip_is_bogon` Nullable(UInt8), + `dns_failure` Nullable(String), + `dns_success` Nullable(UInt8), + `tcp_failure` Nullable(String), + `tcp_success` Nullable(UInt8), + `tls_failure` Nullable(String), + `tls_success` Nullable(UInt8), + `tls_server_name` Nullable(String), + `http_request_url` Nullable(String), + `http_failure` Nullable(String), + `http_success` Nullable(UInt8), + `http_response_body_length` Nullable(Int32), + INDEX measurement_start_time_idx measurement_start_time TYPE minmax GRANULARITY 2 +) +ENGINE = ReplicatedReplacingMergeTree('/clickhouse/{cluster}/tables/{database}/obs_web_ctrl/{shard}', '{replica}') +PARTITION BY concat(substring(bucket_date, 1, 4), substring(bucket_date, 6, 2)) +PRIMARY KEY (measurement_uid, observation_idx) +ORDER BY (measurement_uid, observation_idx, measurement_start_time, hostname) +SETTINGS index_granularity = 8192; + +CREATE TABLE IF NOT EXISTS test_groups ON CLUSTER oonidata_cluster +( + `test_name` String, + `test_group` String +) +ENGINE = Join(ANY, LEFT, test_name); + +CREATE TABLE IF NOT EXISTS url_priorities ON CLUSTER oonidata_cluster +( + `sign` Int8, + `category_code` String, + `cc` String, + `domain` String, + `url` String, + `priority` Int32 +) +ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/{cluster}/tables/{database}/url_priorities/{shard}', '{replica}', sign) +ORDER BY (category_code, cc, domain, url, priority) +SETTINGS index_granularity = 1024; + +-- Its rows are in a hidden table, .inner_id.. The Keeper path keeps production's name +-- for it, so a replica added later joins production's table whatever UUID its view gets. +CREATE MATERIALIZED VIEW IF NOT EXISTS counters_asn_test_list ON CLUSTER oonidata_cluster +( + `week` DateTime, + `probe_cc` String, + `probe_asn` UInt64, + `input` String, + `msmt_cnt` UInt64 +) +ENGINE = ReplicatedSummingMergeTree('/clickhouse/{cluster}/tables/{database}/.inner_id.6a72ceec-7e0e-4b65-a3ab-da2809202114/{shard}', '{replica}') +ORDER BY (probe_cc, probe_asn, input) +SETTINGS index_granularity = 8192 +AS SELECT + toStartOfWeek(measurement_start_time) AS week, + probe_cc, + probe_asn, + input, + count() AS msmt_cnt +FROM fastpath +INNER JOIN citizenlab ON fastpath.input = citizenlab.url +WHERE (measurement_start_time < now()) AND (measurement_start_time > (now() - toIntervalDay(8))) AND (test_name = 'web_connectivity') +GROUP BY + week, + probe_cc, + probe_asn, + input; diff --git a/scripts/cluster-migration/migrations/README.md b/scripts/cluster-migration/migrations/README.md new file mode 100644 index 00000000..da3a671c --- /dev/null +++ b/scripts/cluster-migration/migrations/README.md @@ -0,0 +1,15 @@ +# ClickHouse schema migrations + +`../schema.sql` is the schema as it is now: read it to see a table, and load it to build a new +cluster. A change to an existing cluster's schema goes in a numbered file here, applied once, in +order, on one node (its DDL uses `ON CLUSTER`): + + clickhouse-client --database ooni --multiquery < migrations/NNN_description.sql + +- Every schema change updates `schema.sql` and adds a migration. `../test/check.sh`, which CI runs, + fails unless `schema.sql` gives the same tables as all the migrations in order. +- `000_baseline.sql` is `schema.sql` as of ooni/devops#521. Don't edit it, or a migration that has + been applied: fix forward with a new one. +- Start each file with what it does to production: whether it rewrites data (a mutation, e.g. + `MODIFY COLUMN` or `MATERIALIZE`), how long it took on a copy, and what readers see meanwhile. +- Say in the PR when it was applied to production. diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 48cdf331..30ee6a85 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -5,7 +5,7 @@ -- clickhouse-client --database ooni --multiquery < schema.sql -- Any database name works, e.g. for CI: ON CLUSTER creates each table in the client's database on every -- node, and the Keeper paths include {database}, so a second database on the same cluster doesn't share --- production's replicas. +-- production's replicas. A change to an existing cluster also goes in migrations/: see its README. -- Where the replicas differ, this is the definition of the replica that holds the data: -- event_detector_cusums, labeling_frames: data1 (the only replica with rows, and with their newer columns) -- fastpath: data1 and data3 (data2 alone has deduplicate_merge_projection_mode = 'rebuild') From c9df565564c1bad95dcf64ebb799bcdf31923f93 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 09:54:03 +0000 Subject: [PATCH 29/30] Check that schema.sql equals its migrations test/check.sh starts a one-node oonidata_cluster with Keeper at production's version (24.8.6.70), loads schema.sql into one database and every migration, in order, into another, and compares each table's definition and Keeper path with the database name and UUIDs blanked. It takes about 10 seconds. CI runs it when schema.sql, the migrations, the test or the workflow change. It fails when a migration is missing, and when schema.sql changes without one: both checked by hand before this commit. --- .github/workflows/check_cluster_schema.yml | 16 +++++++ scripts/cluster-migration/test/check.sh | 46 +++++++++++++++++++ scripts/cluster-migration/test/clickhouse.xml | 22 +++++++++ scripts/cluster-migration/test/compose.yml | 11 +++++ 4 files changed, 95 insertions(+) create mode 100644 .github/workflows/check_cluster_schema.yml create mode 100755 scripts/cluster-migration/test/check.sh create mode 100644 scripts/cluster-migration/test/clickhouse.xml create mode 100644 scripts/cluster-migration/test/compose.yml diff --git a/.github/workflows/check_cluster_schema.yml b/.github/workflows/check_cluster_schema.yml new file mode 100644 index 00000000..17c6ac96 --- /dev/null +++ b/.github/workflows/check_cluster_schema.yml @@ -0,0 +1,16 @@ +# Checks that scripts/cluster-migration/schema.sql and its migrations give the same tables +on: + pull_request: + paths: + - "scripts/cluster-migration/schema.sql" + - "scripts/cluster-migration/migrations/**" + - "scripts/cluster-migration/test/**" + - ".github/workflows/check_cluster_schema.yml" + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Compare schema.sql with the migrations + run: scripts/cluster-migration/test/check.sh diff --git a/scripts/cluster-migration/test/check.sh b/scripts/cluster-migration/test/check.sh new file mode 100755 index 00000000..2b0ab45b --- /dev/null +++ b/scripts/cluster-migration/test/check.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# Checks that schema.sql and the migrations agree: loads schema.sql into one database and every +# migrations/NNN_*.sql, in order, into another, then compares each table's definition and Keeper path. +# Needs docker compose; set COMPOSE="podman compose" to use podman. +set -euo pipefail +cd "$(dirname "$0")" +compose=${COMPOSE:-docker compose} +q() { $compose exec -T clickhouse clickhouse-client -u admin --password admin "$@"; } +work=$(mktemp -d) +trap '$compose down -v >/dev/null 2>&1; rm -rf "$work"' EXIT + +$compose up -d +for _ in $(seq 60); do + q -q "SELECT 1 FROM system.zookeeper WHERE path = '/'" /dev/null 2>&1 && break + sleep 1 +done + +for db in from_schema from_migrations; do + q -q "CREATE DATABASE $db ON CLUSTER oonidata_cluster FORMAT Null" /dev/null +for f in ../migrations/[0-9][0-9][0-9]_*.sql; do + echo "applying $(basename "$f")" + q --database from_migrations --multiquery <"$f" >/dev/null +done + +# each table's definition and Keeper path, with the database name and UUIDs blanked +snapshot() { + q -q " + SELECT t.name, + replaceAll(replaceAll(replaceRegexpAll(t.create_table_query, '[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}', ''), + '$1.', '.'), '/$1/', '//'), + replaceAll(r.zookeeper_path, '/$1/', '//') + FROM system.tables AS t + LEFT JOIN system.replicas AS r ON r.database = t.database AND r.table = t.name + WHERE t.database = '$1' + ORDER BY t.name + FORMAT TSV" "$work/schema.tsv" +snapshot from_migrations >"$work/migrations.tsv" +if ! diff -u "$work/schema.tsv" "$work/migrations.tsv"; then + echo "schema.sql and the migrations disagree: the diff above is schema.sql (-) against the migrations (+)" + exit 1 +fi +echo "schema.sql and the migrations agree on all $(wc -l <"$work/schema.tsv") tables" diff --git a/scripts/cluster-migration/test/clickhouse.xml b/scripts/cluster-migration/test/clickhouse.xml new file mode 100644 index 00000000..f393db4b --- /dev/null +++ b/scripts/cluster-migration/test/clickhouse.xml @@ -0,0 +1,22 @@ + + + + + + + + + clickhouse9000adminadmin + + + + oonidata_cluster01clickhouse + + 9181 + 1 + /var/lib/clickhouse/coordination/log + /var/lib/clickhouse/coordination/snapshots + 1clickhouse9234 + + clickhouse9181 + diff --git a/scripts/cluster-migration/test/compose.yml b/scripts/cluster-migration/test/compose.yml new file mode 100644 index 00000000..5ebd8d0f --- /dev/null +++ b/scripts/cluster-migration/test/compose.yml @@ -0,0 +1,11 @@ +# A one-node oonidata_cluster with Keeper, at production's ClickHouse version, for check.sh +name: cluster-schema-check +services: + clickhouse: + image: docker.io/clickhouse/clickhouse-server:24.8.6.70 + hostname: clickhouse + environment: {CLICKHOUSE_USER: admin, CLICKHOUSE_PASSWORD: admin} + volumes: + - ./clickhouse.xml:/etc/clickhouse-server/config.d/cluster.xml:ro,z + ulimits: {nofile: 262144} + mem_limit: 2g From 01fa0846eaf45ab7ecec8622ba8d2eafe3b7ee36 Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Fri, 23 Oct 2026 09:54:03 +0000 Subject: [PATCH 30/30] Give counters_asn_test_list a target table, with week in its key The view kept its rows in a hidden table, .inner_id., sorted by (probe_cc, probe_asn, input). It's a SummingMergeTree, so merges add up the weeks of each key and keep one arbitrary week. Its reader, ooniprobe's test-list/urls (common/prio.py), sums the current and previous week, so it misses every count whose merged row says an older week, which in production is most of them. Tested on 24.8: 2 rows from last week and 5 from this one merge into one row of 7 that says last week. The view now writes TO counters_asn_test_list_data, sorted by (probe_cc, probe_asn, input, week), with a plain {database} Keeper path. It keeps its name and column types, so the reader's query doesn't change. The table is backed up and restored by name, like any other table, by the clickhouse_backup role's "*" job; the view's backup holds only its definition. Restore the table before the view: a view restored without its table makes every insert into fastpath fail. Migration 001 does it in production. The old rows are wrong, so it doesn't copy them: it counts the two weeks the reader uses again from fastpath, from the rows inserted before the new view existed (fastpath's update_time), and the new view counts the rest. That also counts uploads that came more than 8 days late, which the view leaves out. It isn't a mutation. Queries on the view fail between the DROP and the RENAME, for about a second; from then on test-list/urls gets the corrected counts. Tested on a two-node 24.8.6.70 cluster set up like production (the view on one node, its rows already merged): the weeks come out right, a late upload is counted once, later inserts are counted once on both nodes, and test/check.sh passes. --- .../001_counters_asn_test_list_target.sql | 73 +++++++++++++++++++ .../cluster-migration/migrations/README.md | 18 +++++ scripts/cluster-migration/schema.sql | 19 +++-- 3 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 scripts/cluster-migration/migrations/001_counters_asn_test_list_target.sql diff --git a/scripts/cluster-migration/migrations/001_counters_asn_test_list_target.sql b/scripts/cluster-migration/migrations/001_counters_asn_test_list_target.sql new file mode 100644 index 00000000..57f8a487 --- /dev/null +++ b/scripts/cluster-migration/migrations/001_counters_asn_test_list_target.sql @@ -0,0 +1,73 @@ +-- Give counters_asn_test_list an explicit target table, counters_asn_test_list_data, instead of the +-- hidden .inner_id. table it made itself, and add week to its sorting key. The hidden table is +-- sorted by (probe_cc, probe_asn, input) only, so merges add up the weeks of each key and keep one +-- arbitrary week: the reader, ooniprobe's test-list/urls (common/prio.py), sums the current and previous +-- week and misses every count whose merged row says an older week. The new table keeps one row per +-- week, can be backed up and restored by name, and lets the view be dropped or changed without losing +-- its rows. +-- In production: not a mutation. The old rows are wrong, so they aren't copied: the two weeks the +-- reader uses are counted again from fastpath, from rows inserted before the new view existed (the +-- view counts the rest). Unlike the view, this also counts uploads that came more than 8 days after +-- their measurement. Queries on counters_asn_test_list fail between the DROP and the RENAME, for about +-- a second; test-list/urls returns the corrected counts from then on. + +CREATE TABLE IF NOT EXISTS counters_asn_test_list_data ON CLUSTER oonidata_cluster +( + `week` DateTime, + `probe_cc` String, + `probe_asn` UInt64, + `input` String, + `msmt_cnt` UInt64 +) +ENGINE = ReplicatedSummingMergeTree('/clickhouse/{cluster}/tables/{database}/counters_asn_test_list_data/{shard}', '{replica}') +ORDER BY (probe_cc, probe_asn, input, week) +SETTINGS index_granularity = 8192; + +-- Count fastpath's new rows from now on, alongside the old view +CREATE MATERIALIZED VIEW IF NOT EXISTS counters_asn_test_list_new ON CLUSTER oonidata_cluster TO counters_asn_test_list_data +( + `week` DateTime, + `probe_cc` String, + `probe_asn` UInt64, + `input` String, + `msmt_cnt` UInt64 +) +AS SELECT + toStartOfWeek(measurement_start_time) AS week, + probe_cc, + probe_asn, + input, + count() AS msmt_cnt +FROM fastpath +INNER JOIN citizenlab ON fastpath.input = citizenlab.url +WHERE (measurement_start_time < now()) AND (measurement_start_time > (now() - toIntervalDay(8))) AND (test_name = 'web_connectivity') +GROUP BY + week, + probe_cc, + probe_asn, + input; + +-- Count the two weeks the reader sums, from the rows the new view didn't see +INSERT INTO counters_asn_test_list_data SELECT + toStartOfWeek(measurement_start_time) AS week, + probe_cc, + probe_asn, + input, + count() AS msmt_cnt +FROM fastpath +INNER JOIN citizenlab ON fastpath.input = citizenlab.url +WHERE (measurement_start_time >= toStartOfWeek(now() - toIntervalWeek(1))) AND (test_name = 'web_connectivity') AND (update_time < ( + SELECT metadata_modification_time + FROM system.tables + WHERE (database = currentDatabase()) AND (name = 'counters_asn_test_list_new') +)) +GROUP BY + week, + probe_cc, + probe_asn, + input; + +-- The old view and its hidden table. They exist only on data1 and data3, hence IF EXISTS. +DROP TABLE IF EXISTS counters_asn_test_list ON CLUSTER oonidata_cluster SYNC; + +RENAME TABLE counters_asn_test_list_new TO counters_asn_test_list ON CLUSTER oonidata_cluster; diff --git a/scripts/cluster-migration/migrations/README.md b/scripts/cluster-migration/migrations/README.md index da3a671c..c0093add 100644 --- a/scripts/cluster-migration/migrations/README.md +++ b/scripts/cluster-migration/migrations/README.md @@ -13,3 +13,21 @@ order, on one node (its DDL uses `ON CLUSTER`): - Start each file with what it does to production: whether it rewrites data (a mutation, e.g. `MODIFY COLUMN` or `MATERIALIZE`), how long it took on a copy, and what readers see meanwhile. - Say in the PR when it was applied to production. + +## Rebuilding counters_asn_test_list + +Nothing rebuilds the view's counts by itself: it only counts new fastpath inserts. Restore +`counters_asn_test_list_data` from a backup before the view (a view without its table makes every +fastpath insert fail). If the table is lost with no backup, recreate it from `schema.sql` and count the +two weeks that test-list/urls reads again from fastpath, from the rows inserted before the table +existed (the view counts the rest): + +```sql +INSERT INTO ooni.counters_asn_test_list_data +SELECT toStartOfWeek(measurement_start_time) AS week, probe_cc, probe_asn, input, count() AS msmt_cnt +FROM ooni.fastpath INNER JOIN ooni.citizenlab ON fastpath.input = citizenlab.url +WHERE measurement_start_time >= toStartOfWeek(now() - INTERVAL 1 WEEK) AND test_name = 'web_connectivity' + AND update_time < (SELECT metadata_modification_time FROM system.tables + WHERE database = 'ooni' AND name = 'counters_asn_test_list_data') +GROUP BY week, probe_cc, probe_asn, input +``` diff --git a/scripts/cluster-migration/schema.sql b/scripts/cluster-migration/schema.sql index 30ee6a85..402a0dbc 100644 --- a/scripts/cluster-migration/schema.sql +++ b/scripts/cluster-migration/schema.sql @@ -581,9 +581,19 @@ ENGINE = ReplicatedCollapsingMergeTree('/clickhouse/{cluster}/tables/{database}/ ORDER BY (category_code, cc, domain, url, priority) SETTINGS index_granularity = 1024; --- Its rows are in a hidden table, .inner_id.. The Keeper path keeps production's name --- for it, so a replica added later joins production's table whatever UUID its view gets. -CREATE MATERIALIZED VIEW IF NOT EXISTS counters_asn_test_list ON CLUSTER oonidata_cluster +CREATE TABLE IF NOT EXISTS counters_asn_test_list_data ON CLUSTER oonidata_cluster +( + `week` DateTime, + `probe_cc` String, + `probe_asn` UInt64, + `input` String, + `msmt_cnt` UInt64 +) +ENGINE = ReplicatedSummingMergeTree('/clickhouse/{cluster}/tables/{database}/counters_asn_test_list_data/{shard}', '{replica}') +ORDER BY (probe_cc, probe_asn, input, week) +SETTINGS index_granularity = 8192; + +CREATE MATERIALIZED VIEW IF NOT EXISTS counters_asn_test_list ON CLUSTER oonidata_cluster TO counters_asn_test_list_data ( `week` DateTime, `probe_cc` String, @@ -591,9 +601,6 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS counters_asn_test_list ON CLUSTER oonidat `input` String, `msmt_cnt` UInt64 ) -ENGINE = ReplicatedSummingMergeTree('/clickhouse/{cluster}/tables/{database}/.inner_id.6a72ceec-7e0e-4b65-a3ab-da2809202114/{shard}', '{replica}') -ORDER BY (probe_cc, probe_asn, input) -SETTINGS index_granularity = 8192 AS SELECT toStartOfWeek(measurement_start_time) AS week, probe_cc,