mzcompose.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. """
  10. Basic Backup & Restore test with a table
  11. """
  12. from textwrap import dedent
  13. from materialize.mzcompose.composition import Composition
  14. from materialize.mzcompose.services.cockroach import Cockroach
  15. from materialize.mzcompose.services.materialized import Materialized
  16. from materialize.mzcompose.services.minio import Mc, Minio
  17. from materialize.mzcompose.services.persistcli import Persistcli
  18. from materialize.mzcompose.services.testdrive import Testdrive
  19. SERVICES = [
  20. Cockroach(setup_materialize=True),
  21. Minio(setup_materialize=True),
  22. Mc(),
  23. Materialized(
  24. external_blob_store=True,
  25. external_metadata_store=True,
  26. sanity_restart=False,
  27. metadata_store="cockroach",
  28. ),
  29. Testdrive(no_reset=True, metadata_store="cockroach"),
  30. Persistcli(),
  31. ]
  32. def workflow_default(c: Composition) -> None:
  33. # TODO: extract common substrings
  34. # Enable versioning for the Persist bucket
  35. c.enable_minio_versioning()
  36. # Start Materialize, and set up some basic state in it
  37. c.up("materialized", {"name": "testdrive", "persistent": True})
  38. c.testdrive(
  39. dedent(
  40. """
  41. > DROP TABLE IF EXISTS numbers;
  42. > CREATE TABLE IF NOT EXISTS numbers (id BIGINT);
  43. > INSERT INTO numbers SELECT * from generate_series(1, 1);
  44. > INSERT INTO numbers SELECT * from generate_series(1, 10);
  45. > INSERT INTO numbers SELECT * from generate_series(1, 100);
  46. """
  47. )
  48. )
  49. c.backup_cockroach()
  50. # Make further updates to Materialize's state
  51. for i in range(0, 100):
  52. # TODO: This seems to be enough to produce interesting shard state;
  53. # ie. if we remove the restore-blob step we can see the restore fail.
  54. # Is there any cheaper or more obvious way to do that?
  55. c.testdrive(
  56. dedent(
  57. """
  58. > INSERT INTO numbers SELECT * from generate_series(1, 1);
  59. > INSERT INTO numbers SELECT * from generate_series(1, 10);
  60. > INSERT INTO numbers SELECT * from generate_series(1, 100);
  61. """
  62. )
  63. )
  64. # Restore CRDB from backup, run persistcli restore-blob and restart Mz
  65. c.restore_cockroach()
  66. # Confirm that the database is readable / has shard data
  67. c.exec(
  68. "cockroach",
  69. "cockroach",
  70. "sql",
  71. "--insecure",
  72. "-e",
  73. "SELECT shard, min(sequence_number), max(sequence_number) "
  74. "FROM consensus.consensus GROUP BY 1 ORDER BY 2 DESC, 3 DESC, 1 ASC LIMIT 32;",
  75. )
  76. # Check that the cluster is up and that it answers queries as of the old state
  77. c.testdrive(
  78. dedent(
  79. """
  80. > SELECT count(*) FROM numbers;
  81. 111
  82. """
  83. )
  84. )