divergent-dataflow-cancellation.td 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. # This test checks whether divergent WMR dataflows are correctly dropped after
  10. # they have been cancelled by the user.
  11. #
  12. # We check whether the dataflow was dropped by inspecting the introspection
  13. # sources. This also serves to verify that logging is correctly cleaned up under
  14. # active dataflow cancellation.
  15. # Introspection subscribes add noise to the introspection sources, so disable them.
  16. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  17. ALTER SYSTEM SET enable_introspection_subscribes = false
  18. > CREATE CLUSTER test SIZE '1';
  19. > SET cluster = test;
  20. > CREATE VIEW divergent AS
  21. WITH MUTUALLY RECURSIVE
  22. flip(x int) AS (VALUES(1) EXCEPT ALL SELECT * FROM flip)
  23. SELECT * FROM flip
  24. > CREATE INDEX divergent_index ON divergent (x)
  25. > CREATE MATERIALIZED VIEW divergent_materialized AS
  26. WITH MUTUALLY RECURSIVE
  27. flip(x int) AS (VALUES(1) EXCEPT ALL SELECT * FROM flip)
  28. SELECT * FROM flip
  29. # Ensure the dataflow was successfully installed.
  30. > SELECT count(*)
  31. FROM mz_introspection.mz_dataflows
  32. WHERE name LIKE '%divergent%'
  33. 2
  34. # Drop the installed dataflows
  35. > DROP INDEX divergent_index
  36. > DROP MATERIALIZED VIEW divergent_materialized
  37. # Force a statement timeout
  38. > CREATE TABLE divergent_insert_select (f1 INTEGER);
  39. > SET statement_timeout = '5s'
  40. ! INSERT INTO divergent_insert_select
  41. WITH MUTUALLY RECURSIVE flip(x int) AS (VALUES(1) EXCEPT ALL SELECT * FROM flip)
  42. SELECT * FROM flip;
  43. contains: canceling statement due to statement timeout
  44. # Force a cursor to close
  45. > BEGIN
  46. > DECLARE c CURSOR FOR SUBSCRIBE (
  47. WITH MUTUALLY RECURSIVE flip(x int) AS (VALUES(1) EXCEPT ALL SELECT * FROM flip)
  48. SELECT * FROM flip
  49. )
  50. > FETCH ALL c WITH (timeout = '2s');
  51. > COMMIT
  52. # Confirm that all dataflows are now cancelled
  53. > SELECT count(*) FROM mz_introspection.mz_active_peeks_per_worker
  54. 0
  55. > SELECT count(*) FROM mz_introspection.mz_arrangement_batches_raw
  56. 0
  57. > SELECT count(*) FROM mz_introspection.mz_arrangement_records_raw
  58. 0
  59. > SELECT count(*) FROM mz_introspection.mz_arrangement_sharing_raw
  60. 0
  61. > SELECT count(*) FROM mz_introspection.mz_compute_error_counts_raw
  62. 0
  63. # One export for each introspection arrangement.
  64. > SELECT count(*)
  65. FROM mz_introspection.mz_compute_exports_per_worker
  66. WHERE worker_id = 0
  67. 31
  68. # One frontier for each introspection arrangement.
  69. > SELECT count(*)
  70. FROM mz_introspection.mz_compute_frontiers_per_worker
  71. WHERE worker_id = 0
  72. 31
  73. > SELECT count(*) FROM mz_introspection.mz_compute_import_frontiers_per_worker
  74. 0
  75. > SELECT count(*) FROM mz_introspection.mz_compute_operator_durations_histogram_raw
  76. 0
  77. > SELECT count(*) FROM mz_introspection.mz_dataflow_addresses_per_worker
  78. 0
  79. > SELECT count(*) FROM mz_introspection.mz_dataflow_channels_per_worker
  80. 0
  81. > SELECT count(*) FROM mz_introspection.mz_dataflow_operator_reachability_raw
  82. 0
  83. > SELECT count(*) FROM mz_introspection.mz_dataflow_operators_per_worker
  84. 0
  85. # This source never sees retractions.
  86. > SELECT count(*) > 0 FROM mz_introspection.mz_dataflow_shutdown_durations_histogram_raw
  87. true
  88. > SELECT count(*) FROM mz_introspection.mz_message_counts_received_raw
  89. 0
  90. > SELECT count(*) FROM mz_introspection.mz_message_counts_sent_raw
  91. 0
  92. # This source never sees retractions.
  93. > SELECT count(*) > 0 FROM mz_introspection.mz_peek_durations_histogram_raw
  94. true
  95. > SELECT count(*) FROM mz_introspection.mz_scheduling_elapsed_raw
  96. 0
  97. # This source never sees retractions.
  98. > SELECT count(*) > 0 FROM mz_introspection.mz_scheduling_parks_histogram_raw
  99. true
  100. # Cleanup.
  101. > DROP CLUSTER test CASCADE