statistics.td 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. $ set-sql-timeout duration=60s
  10. #
  11. # Test progress statistics
  12. #
  13. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  14. ALTER SYSTEM SET storage_statistics_collection_interval = 1000
  15. ALTER SYSTEM SET storage_statistics_interval = 2000
  16. > CREATE SECRET mysqlpass AS '${arg.mysql-root-password}'
  17. > CREATE CONNECTION mysqc TO MYSQL (
  18. HOST mysql,
  19. USER root,
  20. PASSWORD SECRET mysqlpass
  21. )
  22. $ mysql-connect name=mysql url=mysql://root@mysql password=${arg.mysql-root-password}
  23. $ mysql-execute name=mysql
  24. DROP DATABASE IF EXISTS public;
  25. CREATE DATABASE public;
  26. USE public;
  27. CREATE TABLE t1 (f1 TEXT);
  28. INSERT INTO t1 VALUES ('one');
  29. > CREATE CLUSTER stats_cluster SIZE '${arg.default-replica-size}'
  30. > CREATE SOURCE mz_source IN CLUSTER stats_cluster FROM MYSQL CONNECTION mysqc FOR TABLES (public.t1);
  31. > SELECT COUNT(*) > 0 FROM t1;
  32. true
  33. # NOTE: we make sure that we have stats for a replica, otherwise the
  34. # set-from-sql below might fail because it doesn't do retries when a row is
  35. # missing.
  36. $ set-regex match=u\d+ replacement="<REPLICAID>"
  37. > SELECT cr.id
  38. FROM
  39. mz_clusters c,
  40. mz_cluster_replicas cr,
  41. mz_internal.mz_source_statistics_raw u,
  42. mz_sources s
  43. WHERE
  44. c.name = 'stats_cluster' AND c.id = cr.cluster_id AND cr.id = u.replica_id
  45. AND s.name IN ('mz_source') AND u.id = s.id
  46. ORDER BY cr.id
  47. LIMIT 1
  48. <REPLICAID>
  49. # Find the replica that is running the source, so that the stats query can be
  50. # very specific and not be confused by querying stats from multiple or older
  51. # replicas.
  52. $ set-from-sql var=replica_id
  53. SELECT cr.id
  54. FROM
  55. mz_clusters c,
  56. mz_cluster_replicas cr,
  57. mz_internal.mz_source_statistics_raw u,
  58. mz_sources s
  59. WHERE
  60. c.name = 'stats_cluster' AND c.id = cr.cluster_id AND cr.id = u.replica_id
  61. AND s.name IN ('mz_source') AND u.id = s.id
  62. ORDER BY cr.id
  63. LIMIT 1
  64. > SELECT
  65. s.name,
  66. u.offset_committed > 0,
  67. u.offset_known >= u.offset_committed,
  68. u.snapshot_records_known,
  69. u.snapshot_records_staged
  70. FROM mz_sources s
  71. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  72. WHERE s.name IN ('mz_source') AND u.replica_id = '${replica_id}'
  73. mz_source true true 1 1
  74. $ set-from-sql var=previous-offset-committed
  75. SELECT
  76. (u.offset_committed)::text
  77. FROM mz_sources s
  78. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  79. WHERE s.name IN ('mz_source') AND u.replica_id = '${replica_id}'
  80. $ mysql-execute name=mysql
  81. INSERT INTO t1 VALUES ('two');
  82. > SELECT
  83. s.name,
  84. u.offset_committed > ${previous-offset-committed},
  85. u.offset_known >= u.offset_committed,
  86. u.snapshot_records_known,
  87. u.snapshot_records_staged
  88. FROM mz_sources s
  89. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  90. WHERE s.name IN ('mz_source') AND u.replica_id = '${replica_id}'
  91. mz_source true true 1 1
  92. $ set-from-sql var=pre-restart-offset-committed
  93. SELECT
  94. (u.offset_committed)::text
  95. FROM mz_sources s
  96. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  97. WHERE s.name IN ('mz_source') AND u.replica_id = '${replica_id}'
  98. > ALTER CLUSTER stats_cluster SET (REPLICATION FACTOR 0)
  99. $ mysql-execute name=mysql
  100. INSERT INTO t1 VALUES ('three');
  101. > ALTER CLUSTER stats_cluster SET (REPLICATION FACTOR 1)
  102. # Ensure the snapshot stats stay there for the old replica, and don't change.
  103. > SELECT
  104. s.name,
  105. u.offset_committed >= ${pre-restart-offset-committed},
  106. u.offset_known >= u.offset_committed,
  107. u.snapshot_records_known,
  108. u.snapshot_records_staged
  109. FROM mz_sources s
  110. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  111. WHERE s.name IN ('mz_source') AND u.replica_id = '${replica_id}'
  112. mz_source true true 1 1
  113. $ set-regex match=u\d+ replacement="<REPLICAID>"
  114. > SELECT cr.id
  115. FROM
  116. mz_clusters c,
  117. mz_cluster_replicas cr,
  118. mz_internal.mz_source_statistics_raw u,
  119. mz_sources s
  120. WHERE
  121. c.name = 'stats_cluster' AND c.id = cr.cluster_id AND cr.id = u.replica_id
  122. AND s.name IN ('mz_source') AND u.id = s.id
  123. ORDER BY cr.id
  124. LIMIT 1
  125. <REPLICAID>
  126. $ set-from-sql var=replica_id
  127. SELECT cr.id
  128. FROM
  129. mz_clusters c,
  130. mz_cluster_replicas cr,
  131. mz_internal.mz_source_statistics_raw u,
  132. mz_sources s
  133. WHERE
  134. c.name = 'stats_cluster' AND c.id = cr.cluster_id AND cr.id = u.replica_id
  135. AND s.name IN ('mz_source') AND u.id = s.id
  136. ORDER BY cr.id
  137. LIMIT 1
  138. # The new replica will have different stats, because it never did a snapshot
  139. # and didn't read messages.
  140. > SELECT
  141. s.name,
  142. u.offset_committed > ${pre-restart-offset-committed},
  143. u.offset_known >= u.offset_committed,
  144. u.snapshot_records_known,
  145. u.snapshot_records_staged
  146. FROM mz_sources s
  147. JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id
  148. WHERE s.name IN ('mz_source') AND u.replica_id = '${replica_id}'
  149. mz_source true true <null> <null>
  150. # TODO(guswynn/roshan): test snapshot stats when alter cluster add table is supported by mysql
  151. > DROP CLUSTER stats_cluster CASCADE