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

Adds support for CHANGE REPLICATION SOURCE TO statement #636

Conversation

dennisurtubia
Copy link
Contributor

SUMMARY

Adds new mode for community.mysql.mysql_replication module.

This new mode adds support for MySQL CHANGE SOURCE REPLICATION TO statement.

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

mysql_replication

ADDITIONAL INFORMATION

MySQL CHANGE MASTER TO statement was deprecated. Doc

I didn´t found a respective statement for MariaDB that replaces CHANGE MASTER TO. List of MariaDB commands

Resolves #635

@dennisurtubia
Copy link
Contributor Author

@Andersson007 CHANGE REPLICATION SOURCE TO doesn't uses PRIMARY nomenclature in the statement variables, instead it, uses SOURCE doc.

I kept the nomenclature so as not to significantly increase the list of parameters.

elif mode == 'changereplication':
chm = []
result = {}
if primary_host is not None:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like this similar repetition with changeprimary mode. I can refactor if this make sense.

@dennisurtubia dennisurtubia force-pushed the feat/change-replication-statement branch from a8b7337 to b210084 Compare May 17, 2024 04:02
@Andersson007
Copy link
Collaborator

@dennisurtubia hello, thanks for the PR! Could you please add a changelog fragment and ping us when it's ready for review after the CI is green, thanks!

@Andersson007
Copy link
Collaborator

@dennisurtubia yep, any meaningful refactoring is welcome but it'd be better to do it in a dedicated PR. And also feel free to add yourself to the authors: field in DOCUMENTATION if you're not already there.

@dennisurtubia dennisurtubia marked this pull request as draft May 17, 2024 12:20
@dennisurtubia dennisurtubia force-pushed the feat/change-replication-statement branch 2 times, most recently from f311e68 to 6405ddc Compare May 17, 2024 14:27
Copy link

codecov bot commented May 17, 2024

Codecov Report

Attention: Patch coverage is 49.09091% with 28 lines in your changes are missing coverage. Please review.

Project coverage is 75.34%. Comparing base (47710cf) to head (6405ddc).
Report is 1 commits behind head on main.

Current head 6405ddc differs from pull request most recent head 9028d2c

Please upload reports for the commit 9028d2c to get more accurate results.

Files Patch % Lines
plugins/modules/mysql_replication.py 49.09% 13 Missing and 15 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #636      +/-   ##
==========================================
- Coverage   76.38%   75.34%   -1.04%     
==========================================
  Files          19       18       -1     
  Lines        2456     2507      +51     
  Branches      618      640      +22     
==========================================
+ Hits         1876     1889      +13     
- Misses        403      420      +17     
- Partials      177      198      +21     
Flag Coverage Δ
integration 74.63% <49.09%> (-0.54%) ⬇️
sanity ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Andersson007
Copy link
Collaborator

@dennisurtubia LGTM, one small formatting thing ^

@dennisurtubia dennisurtubia marked this pull request as ready for review May 20, 2024 11:22
@dennisurtubia dennisurtubia force-pushed the feat/change-replication-statement branch 2 times, most recently from 086f1b3 to 6fc2d85 Compare May 20, 2024 11:24
@Andersson007
Copy link
Collaborator

@dennisurtubia thanks, LGTM

@laurent-indermuehle any thoughts?

@laurent-indermuehle
Copy link
Collaborator

I'm grumpy. First we had to rename master to primary and slave to replica. Almost done but there is still a lot of 'master' and 'slave' in many commands.
Then Oracle decide that primary is not good enough and switch to 'source'. Nice job. I'm not exhausted /s. Thanks.

Anyway, my only request about this PR is that the option is more clearly labeled "only for MySQL" please.

@dennisurtubia dennisurtubia force-pushed the feat/change-replication-statement branch from 6fc2d85 to 9028d2c Compare May 20, 2024 12:28
@dennisurtubia
Copy link
Contributor Author

I'm grumpy. First we had to rename master to primary and slave to replica. Almost done but there is still a lot of 'master' and 'slave' in many commands. Then Oracle decide that primary is not good enough and switch to 'source'. Nice job. I'm not exhausted /s. Thanks.

Anyway, my only request about this PR is that the option is more clearly labeled "only for MySQL" please.

Hello, @laurent-indermuehle. I just updated the changereplication mode description, including "only supported in MySQL 8.0.23 and later"

@Andersson007
Copy link
Collaborator

@laurent-indermuehle can we merge the PR now?

@laurent-indermuehle
Copy link
Collaborator

Yes, Thanks @dennisurtubia having made the change I requested. I merge now! Thanks for your contribution!

@laurent-indermuehle laurent-indermuehle merged commit a80b805 into ansible-collections:main May 21, 2024
43 checks passed
@dennisurtubia dennisurtubia deleted the feat/change-replication-statement branch May 30, 2024 15:18
@betanummeric
Copy link
Member

Hi @dennisurtubia, thanks for the PR.
But variables should be put into SQL by the mysql driver, not by string replacement.
cursor.execute("select %(value)s", dict(value=1)) is safe,
whereas cursor.execute("select %(value)s" % dict(value=1)) allows SQL injection attacks.
Please fix this in a new PR to make the module safer.

@laurent-indermuehle
Copy link
Collaborator

@betanummeric Ho good catch, thanks for the advice.
What about this, is it unsafe too?

query = 'START %s %s' % (term, ','.join(chm))
cursor.execute(query)

@betanummeric
Copy link
Member

@laurent-indermuehle Yes, this is unsafe as well. The cursor.execute function adds safety, the other is just concatenating strings without checking anything.

@Andersson007
Copy link
Collaborator

@dennisurtubia could you fix this? if no time, can someone else do it?

@laurent-indermuehle
Copy link
Collaborator

@betanummeric Then this whole file is unsafe: https://github.com/eryx12o45/community.mysql/blob/main/plugins/modules/mysql_replication.py

Because we keep track of the executed queries in a list, how to make the cursor.execute safe?
Do you think we need to open an issue for this?

@dennisurtubia
Copy link
Contributor Author

@dennisurtubia could you fix this? if no time, can someone else do it?

Hey @Andersson007. Yes, I will fix it this week

@dennisurtubia
Copy link
Contributor Author

@betanummeric Then this whole file is unsafe: https://github.com/eryx12o45/community.mysql/blob/main/plugins/modules/mysql_replication.py

Because we keep track of the executed queries in a list, how to make the cursor.execute safe? Do you think we need to open an issue for this?

@laurent-indermuehle I noticed it too. I used some existing code in mysql_replication module to write this function.

I think it would be necessary to create an issue to resolve all issues.

@Andersson007
Copy link
Collaborator

@dennisurtubia I've created the issue, please take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mysql_replication: CHANGE REPLICATION SOURCE TO statement support
4 participants