10-replica-connection.td 2.2 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. > CREATE SECRET mysqlpass AS '${arg.mysql-root-password}'
  10. $ mysql-connect name=mysql url=mysql://root@mysql password=${arg.mysql-root-password}
  11. $ mysql-connect name=mysql-replica url=mysql://root@mysql-replica password=${arg.mysql-root-password}
  12. #
  13. # Create some data on the primary
  14. # and use RESET ... to clear any previous state
  15. # from the binlogs that may slow down the replication
  16. # process on the replica and cause us to be in an unknown
  17. # state when we create our source.
  18. #
  19. $ mysql-execute name=mysql
  20. DROP DATABASE IF EXISTS public;
  21. RESET BINARY LOGS AND GTIDS;
  22. CREATE DATABASE public;
  23. USE public;
  24. CREATE TABLE t1 (f1 INTEGER);
  25. INSERT INTO t1 VALUES (1);
  26. #
  27. # Create a connection from MZ to the replica
  28. #
  29. > CREATE CONNECTION mysq_replica TO MYSQL (
  30. HOST 'mysql-replica',
  31. USER root,
  32. PASSWORD SECRET mysqlpass
  33. )
  34. #
  35. # Turn off the required 'replica_preserve_commit_order' setting for this replica
  36. # and start replication on the replica
  37. #
  38. $ mysql-execute name=mysql-replica
  39. STOP REPLICA;
  40. SET GLOBAL replica_preserve_commit_order=OFF;
  41. CHANGE REPLICATION SOURCE TO SOURCE_HOST='mysql', SOURCE_PORT=3306, SOURCE_USER='root', SOURCE_PASSWORD='${arg.mysql-root-password}', SOURCE_AUTO_POSITION=1;
  42. START REPLICA;
  43. #
  44. # Now try creating a source for this replica, and we should hit an error
  45. #
  46. ! CREATE SOURCE replica_source FROM MYSQL CONNECTION mysq_replica;
  47. contains:Invalid MySQL system replication settings
  48. #
  49. # Now fix the setting on the mysql replica
  50. #
  51. $ mysql-execute name=mysql-replica
  52. STOP REPLICA;
  53. SET GLOBAL replica_preserve_commit_order=ON;
  54. START REPLICA;
  55. #
  56. # Let the replica catch up to the primary
  57. #
  58. > SELECT mz_unsafe.mz_sleep(3)
  59. <null>
  60. #
  61. # Validate we can now create a source to this replica
  62. #
  63. > CREATE SOURCE replica_source FROM MYSQL CONNECTION mysq_replica;
  64. > CREATE TABLE t1 FROM SOURCE replica_source (REFERENCE public.t1);