fetch-select-during-ingest.td 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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-arg-default single-replica-cluster=quickstart
  10. #
  11. # Make sure that data that was ingested during the lifetime of a SELECT cursor is *NOT* FETCH-ed
  12. #
  13. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  14. ALTER SYSTEM SET min_timestamp_interval = '100ms'
  15. $ set int={"type": "record", "name": "field_int", "fields": [ {"name": "f1", "type": "int"} ] }
  16. $ kafka-create-topic topic=tail-fetch-during-ingest
  17. > CREATE CONNECTION kafka_conn
  18. TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  19. > CREATE SOURCE fetch_during_ingest
  20. IN CLUSTER ${arg.single-replica-cluster}
  21. FROM KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-tail-fetch-during-ingest-${testdrive.seed}')
  22. WITH (TIMESTAMP INTERVAL '100ms')
  23. > CREATE TABLE fetch_during_ingest_tbl FROM SOURCE fetch_during_ingest (REFERENCE "testdrive-tail-fetch-during-ingest-${testdrive.seed}")
  24. FORMAT AVRO USING SCHEMA '${int}'
  25. ENVELOPE NONE
  26. $ kafka-ingest format=avro topic=tail-fetch-during-ingest schema=${int} timestamp=1
  27. {"f1": 123}
  28. > SELECT * FROM fetch_during_ingest_tbl;
  29. 123
  30. > BEGIN
  31. > DECLARE c CURSOR FOR SELECT * FROM fetch_during_ingest_tbl;
  32. > FETCH 1 c WITH (timeout='60s');
  33. 123
  34. $ kafka-ingest format=avro topic=tail-fetch-during-ingest schema=${int} timestamp=2
  35. {"f1": 234}
  36. # Sleep here to make sure the entire machinery has run. Since we are in a transaction,
  37. # we have no way of knowing that the source has progressed to '234' outside of the transaction
  38. # NOTE(benesch): grumble. This is not a particularly robust way to write this
  39. # test. It is, however, better than what was previously here, which used
  40. # `SELECT mz_unsafe.mz_sleep(2)`, which had the extremely suboptimal property
  41. # of wedging up the coordinator for 2s, instead of just pausing the test for 2s.
  42. $ sleep-is-probably-flaky-i-have-justified-my-need-with-a-comment duration=2s
  43. # This will return an empty result - nothing else available for fetching in the current transaction
  44. > FETCH 1 c WITH (timeout='2s');
  45. > COMMIT;
  46. #
  47. # The '234' row can now be fetched
  48. #
  49. > BEGIN
  50. > DECLARE c CURSOR FOR SELECT * FROM fetch_during_ingest_tbl;
  51. > FETCH 2 c WITH (timeout='60s');
  52. 123
  53. 234