Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update async replication example and add semisync replication example #547

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MARIADB_ROOT_PASSWORD=secret
MARIADB_REPLICATION_USER=repl
MARIADB_REPLICATION_PASSWORD=replicationpass
PRIMARY_name='mariadb-primary'
REPLICATION_name_1='mariadb-replica-1'
REPLICATION_name_2='mariadb-replica-2'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The REPLICATION_* are only used once. Can we just omit them and get the default configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are here giving the exact name of replicas, I personally prefer to specify the name of replicas.

60 changes: 60 additions & 0 deletions examples/compose-replication-semisync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
version: "3"
x-common-variables: &common-variables
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
MARIADB_REPLICATION_USER: ${MARIADB_REPLICATION_USER}
MARIADB_REPLICATION_PASSWORD: ${MARIADB_REPLICATION_PASSWORD}

x-common-attributes: &common-attributes
env_file:
- .env
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in preparation for non-replication based examples here, recommend explicit naming about env_replication as a env_file.

What's the gain on having it as an env file? It it just showcasing the hiding of passwords out of the main compose file as best practices?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gain as you said for password and having it in place and not repeating the variables for different containers.
Note this is docker-compose file and it has to be used env_file with specifiyng .env.

image: mariadb:lts
environment: *common-variables
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
start_period: 10s
interval: 10s
timeout: 5s
retries: 3

x-common-replication: &common-replication
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--replication_io", "--replication_sql", "--replication_seconds_behind_master=1", "--replication"]
interval: 10s
timeout: 5s
retries: 3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is start_period worth including and works correctly?10s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it works, have added, thanks. There is also start_interval, but I wouldn't added it here.

depends_on:
master:
condition: service_healthy

services:
master:
<<: *common-attributes
container_name: ${PRIMARY_name}
command: --log-bin --log-basename=mariadb --rpl_semi_sync_master_enabled
environment:
- MARIADB_USER=testuser
- MARIADB_PASSWORD=password
- MARIADB_DATABASE=testdb

replica1:
<<:
- *common-attributes
- *common-replication
container_name: ${REPLICATION_name_1}
command: --server-id=2 --log-basename=mariadb --rpl_semi_sync_slave_enabled
environment:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can environment and depends_on go into common-replication? (in the hope that environment is additive)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we can not move environment but we can do depends_onand that I have added. Only thing that could work is that we specify MARIADB_MASTER_HOST=${PRIMARY_name} and MARIADB_HEALTHCHECK_GRANTS=REPLICA MONITOR in .env but I think this way is more readable.

- MARIADB_MASTER_HOST=${PRIMARY_name}
- MARIADB_HEALTHCHECK_GRANTS=REPLICA MONITOR

replica2:
<<:
- *common-attributes
- *common-replication
container_name: ${REPLICATION_name_2}
command: --server-id=3 --log-basename=mariadb --rpl_semi_sync_slave_enabled
environment:
- MARIADB_MASTER_HOST=${PRIMARY_name}
- MARIADB_HEALTHCHECK_GRANTS=REPLICA MONITOR

networks:
backend:
72 changes: 49 additions & 23 deletions examples/compose-replication.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,60 @@
version: "3"
x-common-variables: &common-variables
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
MARIADB_REPLICATION_USER: ${MARIADB_REPLICATION_USER}
MARIADB_REPLICATION_PASSWORD: ${MARIADB_REPLICATION_PASSWORD}

x-common-attributes: &common-attributes
env_file:
- .env
image: mariadb:lts
environment: *common-variables
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
start_period: 10s
interval: 10s
timeout: 5s
retries: 3

x-common-replication: &common-replication
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--replication_io", "--replication_sql", "--replication_seconds_behind_master=1", "--replication"]
interval: 10s
timeout: 5s
retries: 3
depends_on:
master:
condition: service_healthy

services:
master:
image: mariadb:latest
<<: *common-attributes
container_name: ${PRIMARY_name}
command: --log-bin --log-basename=mariadb
environment:
- MARIADB_ROOT_PASSWORD=password
- MARIADB_USER=testuser
- MARIADB_PASSWORD=password
- MARIADB_DATABASE=testdb
- MARIADB_REPLICATION_USER=repl
- MARIADB_REPLICATION_PASSWORD=replicationpass
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 3
replica:
image: mariadb:latest

replica1:
<<:
- *common-attributes
- *common-replication
container_name: ${REPLICATION_name_1}
command: --server-id=2 --log-basename=mariadb
environment:
- MARIADB_ROOT_PASSWORD=password
- MARIADB_MASTER_HOST=master
- MARIADB_REPLICATION_USER=repl
- MARIADB_REPLICATION_PASSWORD=replicationpass
- MARIADB_MASTER_HOST=${PRIMARY_name}
- MARIADB_HEALTHCHECK_GRANTS=REPLICA MONITOR
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--replication_io", "--replication_sql", "--replication_seconds_behind_master=1", "--replication"]
interval: 10s
timeout: 5s
retries: 3
depends_on:
master:
condition: service_healthy

replica2:
<<:
- *common-attributes
- *common-replication
container_name: ${REPLICATION_name_2}
command: --server-id=3 --log-basename=mariadb
environment:
- MARIADB_MASTER_HOST=${PRIMARY_name}
- MARIADB_HEALTHCHECK_GRANTS=REPLICA MONITOR

networks:
backend: