statistics.td 5.3 KB

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