fetch-select-during-ingest.td 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. FORMAT AVRO USING SCHEMA '${int}'
  23. ENVELOPE NONE
  24. WITH (TIMESTAMP INTERVAL '100ms')
  25. $ kafka-ingest format=avro topic=tail-fetch-during-ingest schema=${int} timestamp=1
  26. {"f1": 123}
  27. > SELECT * FROM fetch_during_ingest;
  28. 123
  29. > BEGIN
  30. > DECLARE c CURSOR FOR SELECT * FROM fetch_during_ingest;
  31. > FETCH 1 c WITH (timeout='60s');
  32. 123
  33. $ kafka-ingest format=avro topic=tail-fetch-during-ingest schema=${int} timestamp=2
  34. {"f1": 234}
  35. # Sleep here to make sure the entire machinery has run. Since we are in a transaction,
  36. # we have no way of knowing that the source has progressed to '234' outside of the transaction
  37. # NOTE(benesch): grumble. This is not a particularly robust way to write this
  38. # test. It is, however, better than what was previously here, which used
  39. # `SELECT mz_unsafe.mz_sleep(2)`, which had the extremely suboptimal property
  40. # of wedging up the coordinator for 2s, instead of just pausing the test for 2s.
  41. $ sleep-is-probably-flaky-i-have-justified-my-need-with-a-comment duration=2s
  42. # This will return an empty result - nothing else available for fetching in the current transaction
  43. > FETCH 1 c WITH (timeout='2s');
  44. > COMMIT;
  45. #
  46. # The '234' row can now be fetched
  47. #
  48. > BEGIN
  49. > DECLARE c CURSOR FOR SELECT * FROM fetch_during_ingest;
  50. > FETCH 2 c WITH (timeout='60s');
  51. 123
  52. 234