replica_targeting.slt 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 (SELECTs and SUBSCRIBEs).
  10. mode cockroach
  11. statement ok
  12. CREATE TABLE test (a TEXT, b TEXT)
  13. statement ok
  14. INSERT INTO test VALUES('a', 'b')
  15. statement ok
  16. CREATE CLUSTER test
  17. REPLICAS (
  18. replica_a (SIZE '1', INTROSPECTION INTERVAL '50 milliseconds'),
  19. replica_b (SIZE '2', INTROSPECTION INTERVAL '50 milliseconds')
  20. )
  21. statement ok
  22. SET cluster = test
  23. statement ok
  24. SET cluster_replica = replica_a
  25. # Verify that simple queries work.
  26. query TT
  27. SELECT * FROM test
  28. ----
  29. a b
  30. simple
  31. DECLARE s CURSOR FOR SUBSCRIBE test;
  32. FETCH 0 s;
  33. ----
  34. COMPLETE 0
  35. COMPLETE 0
  36. # Verify that queries on introspection sources work.
  37. statement ok
  38. SELECT * FROM mz_introspection.mz_compute_exports
  39. simple
  40. DECLARE s CURSOR FOR SUBSCRIBE mz_introspection.mz_compute_exports;
  41. FETCH 0 s;
  42. ----
  43. COMPLETE 0
  44. COMPLETE 0
  45. # Verify that targeting an unknown replica fails.
  46. statement ok
  47. SET cluster_replica = unknown
  48. query error cluster replica 'test.unknown' does not exist
  49. SELECT * FROM test
  50. # Verify that untargeted introspection queries are disallowed.
  51. statement ok
  52. RESET cluster_replica
  53. query error log source reads must target a replica
  54. SELECT * FROM mz_introspection.mz_compute_exports
  55. statement error log source reads must target a replica
  56. SUBSCRIBE mz_introspection.mz_compute_exports
  57. # Verify that untargeted introspection queries on unreplicated clusters are
  58. # allowed.
  59. statement ok
  60. DROP CLUSTER REPLICA test.replica_b;
  61. statement ok
  62. SELECT * FROM mz_introspection.mz_compute_exports
  63. simple
  64. DECLARE s CURSOR FOR SUBSCRIBE mz_introspection.mz_compute_exports;
  65. FETCH 0 s;
  66. ----
  67. COMPLETE 0
  68. COMPLETE 0
  69. # Verify that querying introspection data is disallowed on replicas with
  70. # introspection disabled, but allowed on introspection-enabled replicas
  71. # in the same cluster.
  72. statement ok
  73. DROP CLUSTER test CASCADE
  74. statement ok
  75. CREATE CLUSTER test
  76. REPLICAS (
  77. replica_a (SIZE '1', INTROSPECTION INTERVAL 0),
  78. replica_b (SIZE '1', INTROSPECTION INTERVAL 1)
  79. )
  80. statement ok
  81. SET cluster_replica = replica_a
  82. query error cannot read log sources of replica with disabled introspection
  83. SELECT * FROM mz_introspection.mz_compute_exports
  84. statement error cannot read log sources of replica with disabled introspection
  85. SUBSCRIBE mz_introspection.mz_compute_exports
  86. statement ok
  87. SET cluster_replica = replica_b
  88. statement ok
  89. SELECT * FROM mz_introspection.mz_compute_exports
  90. simple
  91. DECLARE s CURSOR FOR SUBSCRIBE mz_introspection.mz_compute_exports;
  92. FETCH 0 s;
  93. ----
  94. COMPLETE 0
  95. COMPLETE 0
  96. # A query that has introspection views in its time domain but does not
  97. # specifically reference those introspection views should work even on a replica
  98. # with introspection disabled. This query would crash in v0.27.0-alpha.24.
  99. query I
  100. SELECT 1 FROM mz_sources LIMIT 1
  101. ----
  102. 1
  103. # Clean up.
  104. statement ok
  105. DROP CLUSTER test CASCADE