hydration-status.td 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. # Test reporting of dataflow hydration status through
  10. # `mz_internal.mz_compute_hydration_statuses`,
  11. # `mz_internal.mz_hydration_statuses`, and
  12. # `mz_internal.mz_compute_operator_hydration_statuses`.
  13. #
  14. # Note that all of the below tests only assert that the `hydrated` flag
  15. # eventually becomes `true`, not that it starts off as `false`. That's because
  16. # we have no control about the hydration timing of dataflows or the update
  17. # cadence of the hydration introspection relations, so we have no reliable way
  18. # of ensuring that a query arrives before a dataflow has hydrated.
  19. #
  20. # These tests rely on testdrive's retry feature, as dataflows can take an
  21. # unknown (but hopefully small) time to hydrate. Furthermore, the queried
  22. # introspection relations are asynchronously updated, so DDL commands are not
  23. # immediately reflected there.
  24. > CREATE CLUSTER test REPLICAS (hydrated_test_1 (SIZE '1'))
  25. > SET cluster = test
  26. # Test that on an empty cluster only the introspection indexes show up.
  27. # Introspection subscribes do not show up because the hydration introspection
  28. # relations exclude transient dataflow.
  29. > SELECT DISTINCT left(h.object_id, 2), h.hydrated
  30. FROM mz_internal.mz_compute_hydration_statuses h
  31. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  32. WHERE r.name LIKE 'hydrated_test%';
  33. si true
  34. > SELECT DISTINCT left(h.object_id, 2), h.hydrated
  35. FROM mz_internal.mz_hydration_statuses h
  36. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  37. WHERE r.name LIKE 'hydrated_test%';
  38. si true
  39. # No operator-level hydration status logging for introspection dataflows.
  40. > SELECT DISTINCT left(h.object_id, 1), h.hydrated
  41. FROM mz_internal.mz_compute_operator_hydration_statuses h
  42. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  43. WHERE r.name LIKE 'hydrated_test%';
  44. # Test adding new compute dataflows.
  45. > CREATE TABLE t (a int)
  46. > CREATE INDEX idx ON t (a)
  47. > CREATE MATERIALIZED VIEW mv AS SELECT * FROM t
  48. > CREATE MATERIALIZED VIEW mv_const AS SELECT 1
  49. > SELECT o.name, r.name, h.hydrated, h.hydration_time IS NOT NULL
  50. FROM mz_internal.mz_compute_hydration_statuses h
  51. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  52. JOIN mz_objects o ON (o.id = h.object_id)
  53. WHERE
  54. r.name LIKE 'hydrated_test%' AND
  55. o.id NOT LIKE 's%';
  56. idx hydrated_test_1 true true
  57. mv hydrated_test_1 true true
  58. mv_const hydrated_test_1 true false
  59. > SELECT o.name, r.name, h.hydrated
  60. FROM mz_internal.mz_hydration_statuses h
  61. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  62. JOIN mz_objects o ON (o.id = h.object_id)
  63. WHERE
  64. r.name LIKE 'hydrated_test%' AND
  65. o.id NOT LIKE 's%';
  66. idx hydrated_test_1 true
  67. mv hydrated_test_1 true
  68. mv_const hydrated_test_1 true
  69. > SELECT o.name, r.name, bool_and(h.hydrated)
  70. FROM mz_internal.mz_compute_operator_hydration_statuses h
  71. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  72. JOIN mz_objects o ON (o.id = h.object_id)
  73. WHERE
  74. r.name LIKE 'hydrated_test%' AND
  75. o.id NOT LIKE 's%'
  76. GROUP BY o.name, r.name;
  77. idx hydrated_test_1 true
  78. mv hydrated_test_1 true
  79. mv_const hydrated_test_1 true
  80. # Test adding new replicas.
  81. > CREATE CLUSTER REPLICA test.hydrated_test_2 SIZE '1'
  82. > SELECT o.name, r.name, h.hydrated, h.hydration_time IS NOT NULL
  83. FROM mz_internal.mz_compute_hydration_statuses h
  84. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  85. JOIN mz_objects o ON (o.id = h.object_id)
  86. WHERE
  87. r.name LIKE 'hydrated_test%' AND
  88. o.id NOT LIKE 's%';
  89. idx hydrated_test_1 true true
  90. idx hydrated_test_2 true true
  91. mv hydrated_test_1 true true
  92. mv hydrated_test_2 true true
  93. mv_const hydrated_test_1 true false
  94. mv_const hydrated_test_2 true false
  95. > SELECT o.name, r.name, h.hydrated
  96. FROM mz_internal.mz_hydration_statuses h
  97. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  98. JOIN mz_objects o ON (o.id = h.object_id)
  99. WHERE
  100. r.name LIKE 'hydrated_test%' AND
  101. o.id NOT LIKE 's%';
  102. idx hydrated_test_1 true
  103. idx hydrated_test_2 true
  104. mv hydrated_test_1 true
  105. mv hydrated_test_2 true
  106. mv_const hydrated_test_1 true
  107. mv_const hydrated_test_2 true
  108. # `mv_const` doesn't show up for the second replica because its output was
  109. # already fully computed so it wasn't installed on the replica and no operators
  110. # exist.
  111. > SELECT o.name, r.name, bool_and(h.hydrated)
  112. FROM mz_internal.mz_compute_operator_hydration_statuses h
  113. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  114. JOIN mz_objects o ON (o.id = h.object_id)
  115. WHERE
  116. r.name LIKE 'hydrated_test%' AND
  117. o.id NOT LIKE 's%'
  118. GROUP BY o.name, r.name;
  119. idx hydrated_test_1 true
  120. idx hydrated_test_2 true
  121. mv hydrated_test_1 true
  122. mv hydrated_test_2 true
  123. mv_const hydrated_test_1 true
  124. # Test dropping replicas.
  125. > DROP CLUSTER REPLICA test.hydrated_test_1
  126. > SELECT o.name, r.name, h.hydrated, h.hydration_time IS NOT NULL
  127. FROM mz_internal.mz_compute_hydration_statuses h
  128. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  129. JOIN mz_objects o ON (o.id = h.object_id)
  130. WHERE
  131. r.name LIKE 'hydrated_test%' AND
  132. o.id NOT LIKE 's%';
  133. idx hydrated_test_2 true true
  134. mv hydrated_test_2 true true
  135. mv_const hydrated_test_2 true false
  136. > SELECT o.name, r.name, h.hydrated
  137. FROM mz_internal.mz_hydration_statuses h
  138. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  139. JOIN mz_objects o ON (o.id = h.object_id)
  140. WHERE
  141. r.name LIKE 'hydrated_test%' AND
  142. o.id NOT LIKE 's%';
  143. idx hydrated_test_2 true
  144. mv hydrated_test_2 true
  145. mv_const hydrated_test_2 true
  146. > SELECT o.name, r.name, bool_and(h.hydrated)
  147. FROM mz_internal.mz_compute_operator_hydration_statuses h
  148. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  149. JOIN mz_objects o ON (o.id = h.object_id)
  150. WHERE
  151. r.name LIKE 'hydrated_test%' AND
  152. o.id NOT LIKE 's%'
  153. GROUP BY o.name, r.name;
  154. idx hydrated_test_2 true
  155. mv hydrated_test_2 true
  156. > DROP CLUSTER REPLICA test.hydrated_test_2
  157. > SELECT o.name, r.name, h.hydrated, h.hydration_time IS NOT NULL
  158. FROM mz_internal.mz_compute_hydration_statuses h
  159. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  160. JOIN mz_objects o ON (o.id = h.object_id)
  161. WHERE
  162. r.name LIKE 'hydrated_test%' AND
  163. o.id NOT LIKE 's%';
  164. > SELECT o.name, r.name, h.hydrated
  165. FROM mz_internal.mz_hydration_statuses h
  166. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  167. JOIN mz_objects o ON (o.id = h.object_id)
  168. WHERE
  169. r.name LIKE 'hydrated_test%' AND
  170. o.id NOT LIKE 's%';
  171. > SELECT o.name, r.name, bool_and(h.hydrated)
  172. FROM mz_internal.mz_compute_operator_hydration_statuses h
  173. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  174. JOIN mz_objects o ON (o.id = h.object_id)
  175. WHERE
  176. r.name LIKE 'hydrated_test%' AND
  177. o.id NOT LIKE 's%'
  178. GROUP BY o.name, r.name;
  179. # Test dropping dataflows.
  180. > CREATE CLUSTER REPLICA test.hydrated_test_3 SIZE '1'
  181. > SELECT o.name, r.name, h.hydrated, h.hydration_time IS NOT NULL
  182. FROM mz_internal.mz_compute_hydration_statuses h
  183. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  184. JOIN mz_objects o ON (o.id = h.object_id)
  185. WHERE
  186. r.name LIKE 'hydrated_test%' AND
  187. o.id NOT LIKE 's%';
  188. idx hydrated_test_3 true true
  189. mv hydrated_test_3 true true
  190. mv_const hydrated_test_3 true false
  191. > SELECT o.name, r.name, h.hydrated
  192. FROM mz_internal.mz_hydration_statuses h
  193. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  194. JOIN mz_objects o ON (o.id = h.object_id)
  195. WHERE
  196. r.name LIKE 'hydrated_test%' AND
  197. o.id NOT LIKE 's%';
  198. idx hydrated_test_3 true
  199. mv hydrated_test_3 true
  200. mv_const hydrated_test_3 true
  201. > SELECT o.name, r.name, bool_and(h.hydrated)
  202. FROM mz_internal.mz_compute_operator_hydration_statuses h
  203. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  204. JOIN mz_objects o ON (o.id = h.object_id)
  205. WHERE
  206. r.name LIKE 'hydrated_test%' AND
  207. o.id NOT LIKE 's%'
  208. GROUP BY o.name, r.name;
  209. idx hydrated_test_3 true
  210. mv hydrated_test_3 true
  211. > DROP INDEX idx;
  212. > DROP MATERIALIZED VIEW mv_const;
  213. > SELECT o.name, r.name, h.hydrated, h.hydration_time IS NOT NULL
  214. FROM mz_internal.mz_compute_hydration_statuses h
  215. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  216. JOIN mz_objects o ON (o.id = h.object_id)
  217. WHERE
  218. r.name LIKE 'hydrated_test%' AND
  219. o.id NOT LIKE 's%';
  220. mv hydrated_test_3 true true
  221. > SELECT o.name, r.name, h.hydrated
  222. FROM mz_internal.mz_hydration_statuses h
  223. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  224. JOIN mz_objects o ON (o.id = h.object_id)
  225. WHERE
  226. r.name LIKE 'hydrated_test%' AND
  227. o.id NOT LIKE 's%';
  228. mv hydrated_test_3 true
  229. > SELECT o.name, r.name, bool_and(h.hydrated)
  230. FROM mz_internal.mz_compute_operator_hydration_statuses h
  231. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  232. JOIN mz_objects o ON (o.id = h.object_id)
  233. WHERE
  234. r.name LIKE 'hydrated_test%' AND
  235. o.id NOT LIKE 's%'
  236. GROUP BY o.name, r.name;
  237. mv hydrated_test_3 true
  238. # Test adding new storage dataflows.
  239. > CREATE SOURCE src
  240. IN CLUSTER test
  241. FROM LOAD GENERATOR auction (UP TO 100);
  242. > CREATE TABLE accounts FROM SOURCE src (REFERENCE accounts);
  243. > CREATE TABLE auctions FROM SOURCE src (REFERENCE auctions);
  244. > CREATE TABLE bids FROM SOURCE src (REFERENCE bids);
  245. > CREATE TABLE organizations FROM SOURCE src (REFERENCE organizations);
  246. > CREATE TABLE users FROM SOURCE src (REFERENCE users);
  247. > CREATE CONNECTION kafka_conn
  248. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT)
  249. > CREATE CONNECTION csr_conn
  250. TO CONFLUENT SCHEMA REGISTRY (URL '${testdrive.schema-registry-url}')
  251. > CREATE SINK snk
  252. IN CLUSTER test
  253. FROM mv
  254. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-sink1-${testdrive.seed}')
  255. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  256. ENVELOPE DEBEZIUM
  257. # Webhook sources are not backed by dataflows, so they have no concept of
  258. # hydration and shouldn't show up in mz_hydration_statuses.
  259. > CREATE SOURCE web IN CLUSTER test FROM WEBHOOK BODY FORMAT JSON
  260. > SELECT o.name, r.name, h.hydrated
  261. FROM mz_internal.mz_hydration_statuses h
  262. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  263. JOIN mz_objects o ON (o.id = h.object_id)
  264. WHERE
  265. r.name LIKE 'hydrated_test%' AND
  266. o.id NOT LIKE 's%';
  267. mv hydrated_test_3 true
  268. src hydrated_test_3 true
  269. snk hydrated_test_3 true
  270. # Test dropping replicas.
  271. > DROP CLUSTER REPLICA test.hydrated_test_3
  272. > SELECT o.name, r.name, h.hydrated
  273. FROM mz_internal.mz_hydration_statuses h
  274. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  275. JOIN mz_objects o ON (o.id = h.object_id)
  276. WHERE
  277. r.name LIKE 'hydrated_test%' AND
  278. o.id NOT LIKE 's%';
  279. # Test adding new replicas.
  280. > CREATE CLUSTER REPLICA test.hydrated_test_4 SIZE '1'
  281. > SELECT o.name, r.name, h.hydrated
  282. FROM mz_internal.mz_hydration_statuses h
  283. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  284. JOIN mz_objects o ON (o.id = h.object_id)
  285. WHERE
  286. r.name LIKE 'hydrated_test%' AND
  287. o.id NOT LIKE 's%';
  288. mv hydrated_test_4 true
  289. src hydrated_test_4 true
  290. snk hydrated_test_4 true
  291. # Test dropping dataflows.
  292. > DROP SINK snk
  293. > DROP SOURCE src CASCADE
  294. > DROP MATERIALIZED VIEW mv
  295. > SELECT o.name, r.name, h.hydrated
  296. FROM mz_internal.mz_hydration_statuses h
  297. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  298. JOIN mz_objects o ON (o.id = h.object_id)
  299. WHERE
  300. r.name LIKE 'hydrated_test%' AND
  301. o.id NOT LIKE 's%';
  302. # Test hydration status reporting with WMR dataflows.
  303. > CREATE MATERIALIZED VIEW mv_wmr AS
  304. WITH MUTUALLY RECURSIVE
  305. x (a int) AS (
  306. SELECT * FROM t
  307. UNION ALL
  308. SELECT a + 1 FROM x WHERE a < 10
  309. )
  310. SELECT * FROM x;
  311. > CREATE MATERIALIZED VIEW mv_wmr_const AS
  312. WITH MUTUALLY RECURSIVE
  313. x (a int) AS (
  314. VALUES (1)
  315. UNION ALL
  316. SELECT a + 1 FROM x WHERE a < 10
  317. )
  318. SELECT * FROM x;
  319. > CREATE MATERIALIZED VIEW mv_wmr_stuck AS
  320. WITH MUTUALLY RECURSIVE
  321. x (a int) AS (
  322. VALUES (1)
  323. UNION ALL
  324. SELECT a + 1 FROM x
  325. )
  326. SELECT * FROM x;
  327. > SELECT o.name, r.name, h.hydrated, h.hydration_time IS NOT NULL
  328. FROM mz_internal.mz_compute_hydration_statuses h
  329. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  330. JOIN mz_objects o ON (o.id = h.object_id)
  331. WHERE
  332. r.name LIKE 'hydrated_test%' AND
  333. o.id NOT LIKE 's%';
  334. mv_wmr hydrated_test_4 true true
  335. mv_wmr_const hydrated_test_4 true false
  336. mv_wmr_stuck hydrated_test_4 false false
  337. > SELECT o.name, r.name, h.hydrated
  338. FROM mz_internal.mz_hydration_statuses h
  339. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  340. JOIN mz_objects o ON (o.id = h.object_id)
  341. WHERE
  342. r.name LIKE 'hydrated_test%' AND
  343. o.id NOT LIKE 's%';
  344. mv_wmr hydrated_test_4 true
  345. mv_wmr_const hydrated_test_4 true
  346. mv_wmr_stuck hydrated_test_4 false
  347. > SELECT o.name, r.name, bool_and(h.hydrated)
  348. FROM mz_internal.mz_compute_operator_hydration_statuses h
  349. JOIN mz_cluster_replicas r ON (r.id = h.replica_id)
  350. JOIN mz_objects o ON (o.id = h.object_id)
  351. WHERE
  352. r.name LIKE 'hydrated_test%' AND
  353. o.id NOT LIKE 's%'
  354. GROUP BY o.name, r.name;
  355. mv_wmr hydrated_test_4 true
  356. mv_wmr_const hydrated_test_4 true
  357. mv_wmr_stuck hydrated_test_4 false
  358. > DROP MATERIALIZED VIEW mv_wmr
  359. > DROP MATERIALIZED VIEW mv_wmr_const
  360. > DROP MATERIALIZED VIEW mv_wmr_stuck
  361. # Test that incorrectly configured sinks do _not_ show as hydrated.
  362. > CREATE TABLE schema1 (a int)
  363. > CREATE TABLE schema2 (a text)
  364. > CREATE SINK snk_schema1
  365. IN CLUSTER test
  366. FROM schema1
  367. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-snk_schema1-${testdrive.seed}')
  368. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  369. ENVELOPE DEBEZIUM
  370. > SELECT s.name, h.hydrated
  371. FROM mz_sinks s
  372. JOIN mz_internal.mz_hydration_statuses h ON (h.object_id = s.id)
  373. snk_schema1 true
  374. > CREATE SINK snk_schema2
  375. IN CLUSTER test
  376. FROM schema2
  377. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-snk_schema1-${testdrive.seed}')
  378. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  379. ENVELOPE DEBEZIUM
  380. # If we have a bug, the sink's hydration status might toggle between `false`
  381. # and `true`, rather than always being `true`. Using retries might therefore
  382. # cause this test to pass even if it shouldn't. We instead disable retries and
  383. # manually check the hydration status a couple times.
  384. $ set-max-tries max-tries=1
  385. > SELECT s.name, h.hydrated
  386. FROM mz_sinks s
  387. JOIN mz_internal.mz_hydration_statuses h ON (h.object_id = s.id)
  388. snk_schema1 true
  389. snk_schema2 false
  390. > SELECT s.name, h.hydrated
  391. FROM mz_sinks s
  392. JOIN mz_internal.mz_hydration_statuses h ON (h.object_id = s.id)
  393. snk_schema1 true
  394. snk_schema2 false
  395. > SELECT s.name, h.hydrated
  396. FROM mz_sinks s
  397. JOIN mz_internal.mz_hydration_statuses h ON (h.object_id = s.id)
  398. snk_schema1 true
  399. snk_schema2 false
  400. > SELECT s.name, h.hydrated
  401. FROM mz_sinks s
  402. JOIN mz_internal.mz_hydration_statuses h ON (h.object_id = s.id)
  403. snk_schema1 true
  404. snk_schema2 false
  405. > SELECT s.name, h.hydrated
  406. FROM mz_sinks s
  407. JOIN mz_internal.mz_hydration_statuses h ON (h.object_id = s.id)
  408. snk_schema1 true
  409. snk_schema2 false