|
| 1 | +-- Durable, source-authoritative CEX user-stream health snapshots. |
| 2 | +-- NO TTL: quiet, disconnected, and failed states are replay evidence. |
| 3 | + |
| 4 | +CREATE DATABASE IF NOT EXISTS broker_stream_health; |
| 5 | + |
| 6 | +CREATE TABLE IF NOT EXISTS broker_stream_health.snapshots |
| 7 | +( |
| 8 | + schema_version LowCardinality(String), |
| 9 | + source LowCardinality(String), |
| 10 | + deployment_id LowCardinality(String), |
| 11 | + producer_id LowCardinality(String), |
| 12 | + producer_epoch UInt64, |
| 13 | + run_id UUID, |
| 14 | + batch_id FixedString(64), |
| 15 | + batch_sequence UInt64, |
| 16 | + batch_snapshot_count UInt32, |
| 17 | + batch_active_stream_count UInt32, |
| 18 | + registry_revision FixedString(64), |
| 19 | + registry_status Enum8('active' = 1, 'retired' = 2), |
| 20 | + retired_at Nullable(DateTime64(3, 'UTC')), |
| 21 | + snapshot_id FixedString(64), |
| 22 | + stream_key String, |
| 23 | + exchange LowCardinality(String), |
| 24 | + account_selector LowCardinality(String), |
| 25 | + account_role LowCardinality(Nullable(String)), |
| 26 | + stream_kind LowCardinality(String), |
| 27 | + account_scope LowCardinality(String), |
| 28 | + sequence UInt64, |
| 29 | + state Enum8('connecting' = 1, 'connected' = 2, 'disconnected' = 3, 'error' = 4), |
| 30 | + state_changed_at DateTime64(3, 'UTC'), |
| 31 | + last_connected_at Nullable(DateTime64(3, 'UTC')), |
| 32 | + last_authenticated_at Nullable(DateTime64(3, 'UTC')), |
| 33 | + last_received_at Nullable(DateTime64(3, 'UTC')), |
| 34 | + heartbeat_at DateTime64(3, 'UTC'), |
| 35 | + connect_attempt_count UInt64, |
| 36 | + reconnect_count UInt64, |
| 37 | + error_count UInt64, |
| 38 | + last_failure_kind Enum8( |
| 39 | + 'none' = 0, |
| 40 | + 'auth_failed' = 1, |
| 41 | + 'transport_error' = 2, |
| 42 | + 'remote_closed' = 3, |
| 43 | + 'protocol_error' = 4, |
| 44 | + 'backpressure' = 5, |
| 45 | + 'unsupported_connector' = 6, |
| 46 | + 'shutdown' = 7 |
| 47 | + ), |
| 48 | + last_failure_reason String, |
| 49 | + traffic_mode Enum8('event_driven' = 1, 'continuous' = 2, 'unknown' = 3), |
| 50 | + source_watermark Nullable(String), |
| 51 | + payload_sha256 FixedString(64), |
| 52 | + payload_json String, |
| 53 | + ingested_at DateTime64(3, 'UTC') DEFAULT now64(3) |
| 54 | +) |
| 55 | +ENGINE = MergeTree |
| 56 | +PARTITION BY toYYYYMM(heartbeat_at) |
| 57 | +ORDER BY (producer_id, producer_epoch, run_id, stream_key, sequence, snapshot_id); |
| 58 | + |
| 59 | +-- A collision is never reconciled by a reader. The forwarder records the |
| 60 | +-- evidence separately and fails the whole candidate batch closed. |
| 61 | +CREATE TABLE IF NOT EXISTS broker_stream_health.replay_conflicts |
| 62 | +( |
| 63 | + detected_at DateTime64(3, 'UTC') DEFAULT now64(3), |
| 64 | + batch_id FixedString(64), |
| 65 | + snapshot_id FixedString(64), |
| 66 | + conflict_kind Enum8( |
| 67 | + 'payload_mismatch' = 1, |
| 68 | + 'partial_batch' = 2, |
| 69 | + 'multiple_existing_hashes' = 3 |
| 70 | + ), |
| 71 | + existing_payload_sha256 String, |
| 72 | + incoming_payload_sha256 FixedString(64), |
| 73 | + existing_payload_json String, |
| 74 | + incoming_payload_json String |
| 75 | +) |
| 76 | +ENGINE = MergeTree |
| 77 | +PARTITION BY toYYYYMM(detected_at) |
| 78 | +ORDER BY (snapshot_id, detected_at); |
0 commit comments