replica-targeting.td 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. # Tests for replica-targeted queries (SELECT and SUBSCRIBE).
  10. #
  11. # These tests rely on testdrive's retry feature, as they query introspection
  12. # sources whose data might not be immediately available.
  13. $ set-regex match=\d{13} replacement=<TIMESTAMP>
  14. # Test that replica-targeted queries return results from the target replica.
  15. #
  16. # This test works by querying introspection sources, which are the only compute
  17. # collections that can have different contents between replicas. Specifically,
  18. # we look at the distinct `worker_id`s present in `mz_compute_frontiers_per_worker`
  19. # for replicas with different worker counts. We know that
  20. # `mz_compute_frontiers_per_worker` always contains entries, because it tracks the
  21. # frontiers of introspection sources as well.
  22. > CREATE CLUSTER test REPLICAS (
  23. r1 (SIZE '1'),
  24. r2 (SIZE '2'),
  25. r4 (SIZE '4')
  26. )
  27. > SET cluster = test
  28. > SET cluster_replica = r1
  29. > SELECT DISTINCT worker_id FROM mz_introspection.mz_compute_frontiers_per_worker ORDER BY worker_id
  30. 0
  31. > BEGIN
  32. > DECLARE c CURSOR FOR SUBSCRIBE (
  33. SELECT count(DISTINCT worker_id) FROM mz_introspection.mz_compute_frontiers_per_worker
  34. )
  35. > FETCH c
  36. <TIMESTAMP> 1 1
  37. > COMMIT
  38. > SET cluster_replica = r2
  39. > SELECT DISTINCT worker_id FROM mz_introspection.mz_compute_frontiers_per_worker ORDER BY worker_id
  40. 0
  41. 1
  42. > BEGIN
  43. > DECLARE c CURSOR FOR SUBSCRIBE (
  44. SELECT count(DISTINCT worker_id) FROM mz_introspection.mz_compute_frontiers_per_worker
  45. )
  46. > FETCH c
  47. <TIMESTAMP> 1 2
  48. > COMMIT
  49. > SET cluster_replica = r4
  50. > SELECT DISTINCT worker_id FROM mz_introspection.mz_compute_frontiers_per_worker ORDER BY worker_id
  51. 0
  52. 1
  53. 2
  54. 3
  55. > BEGIN
  56. > DECLARE c CURSOR FOR SUBSCRIBE (
  57. SELECT count(DISTINCT worker_id) FROM mz_introspection.mz_compute_frontiers_per_worker
  58. )
  59. > FETCH c
  60. <TIMESTAMP> 1 4
  61. > COMMIT
  62. # Test that replica-targeted subscribes work when the subscribed collection
  63. # advances to the empty frontier. Regression test for database-issues#7457.
  64. > DROP CLUSTER test CASCADE
  65. > CREATE CLUSTER test SIZE '4-4', REPLICATION FACTOR 4
  66. > SET cluster_replica = r1
  67. > CREATE MATERIALIZED VIEW mv AS SELECT 1
  68. > BEGIN
  69. > DECLARE c CURSOR FOR SUBSCRIBE mv
  70. > FETCH c
  71. <TIMESTAMP> 1 1
  72. > COMMIT
  73. # We want to provoke the case where a non-targeted replica returns a response
  74. # first, so try multiple times to be sure.
  75. > BEGIN
  76. > DECLARE c CURSOR FOR SUBSCRIBE mv
  77. > FETCH c
  78. <TIMESTAMP> 1 1
  79. > COMMIT
  80. > BEGIN
  81. > DECLARE c CURSOR FOR SUBSCRIBE mv
  82. > FETCH c
  83. <TIMESTAMP> 1 1
  84. > COMMIT