MDEV-8235: Expose check_slave_start_position as SQL function GTID_CHECK_POS()#4956
MDEV-8235: Expose check_slave_start_position as SQL function GTID_CHECK_POS()#4956ayush-jha123 wants to merge 5 commits into
Conversation
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for your contribution! This is a preliminary review.
First, the formalities:
- please keep a single commit, with a commit message in it.
- please make sure all of the buildbot hosts compile and run successfully
Below are some of my thoughts on the functionality and its implementation and test coverage. You can ignore all of the below and take it with the final reviewer. Or address it and have a faster final review with these fixed.
81aa4a1 to
c4377de
Compare
This commit implements the GTID_CHECK_POS() SQL function, which allows validating if a given GTID position is reachable within the current set of binary logs. This is useful for external tools or orchestration layers to verify if a node is viable for replication start without actually initiating a slave connection. Features: - Returns 1 if all GTIDs in the requested state are reachable. - Returns 0 if any GTID in the requested state has been purged. - Propagates parsing errors for malformed GTID strings. - Derived from Item_bool_func to ensure native boolean handling. - Protected by HAVE_REPLICATION for safe embedded builds. Implemented via a thin wrapper over the engine-internal gtid_find_binlog_pos() logic.
c4377de to
bd30bf6
Compare
gkodinov
left a comment
There was a problem hiding this comment.
It's looking much better. Please make sure to address the comments below. This is my last batch of preliminary review comments.
Thanks for your efforts.
fb66443 to
beeba7c
Compare
beeba7c to
ebb7195
Compare
|
Hi @gkodinov, I've just pushed the updated commit addressing your latest feedback: Compilaton: Added #include "sql_repl.h" to sql/item_func.cc to fix the scope error you observed on Buildbot. Thanks for the review, let me know if there's anything else! |
ca84483 to
75568df
Compare
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for working on this. Some of the test results do not make a lot of sense it seems.
It'd be good to have even more test coverage: more edge cases, more positive and negative outcomes, scenarios producing all the possible return values and/or errors etc.
And also a better design definition of what the SQL function does is going to help a lot: e.g. possible return values, when are they returned, formal description or parameters, what determines the return value (just the parameter values or some other state, etc.
| if ((null_value= args[0]->null_value)) | ||
| return 0; | ||
|
|
||
| #ifndef HAVE_REPLICATION |
There was a problem hiding this comment.
I'd reverse the condition for readability. But that's optional.
75568df to
cf68c81
Compare
gkodinov
left a comment
There was a problem hiding this comment.
It is looking much better now! Thanks for the updated tests. This makes it look good. Some final remarks below.
| SELECT GTID_CHECK_POS('NEW_GTID_POS'); | ||
| GTID_CHECK_POS('NEW_GTID_POS') | ||
| 1 | ||
| # The old position (now in a purged log) returns 0 |
There was a problem hiding this comment.
this one fails on buildbot:
main.gtid_check_pos w7 [ fail ]
Test ended at 2026-06-03 19:55:16
CURRENT_TEST: main.gtid_check_pos
--- C:/a/server/server/mysql-test/main/gtid_check_pos.result 2026-06-03 19:12:08.051490800 +0000
+++ C:\a\server\server\mysql-test\main\gtid_check_pos.reject 2026-06-03 19:55:13.752902600 +0000
@@ -30,7 +30,7 @@
# The old position (now in a purged log) returns 0
SELECT GTID_CHECK_POS('OLD_GTID_POS');
GTID_CHECK_POS('OLD_GTID_POS')
-0
+1
| @@ -37,6 +37,7 @@ | |||
| #include "sql_acl.h" // EXECUTE_ACL | |||
| #include "mysqld.h" // LOCK_short_uuid_generator | |||
| #include "rpl_mi.h" | |||
|
|
|||
There was a problem hiding this comment.
no white-space only changes please.
| and verifies if they exist and are reachable (viable) within the current | ||
| set of binary logs. | ||
|
|
||
| @param gtid_str A string representation of GTIDs (e.g. '0-1-1,0-1-2'). |
There was a problem hiding this comment.
This will make doxygen return an error if one day it was run on these files. This is a method documentation block. And yet, you're talking about the SQL function itself. I'd move this particular block towards the class definition (?), reformat it a bit so that there's no @return or @param directives and then add a real one here explaining the return value and what the function does in specific.
|
|
||
| @param gtid_str A string representation of GTIDs (e.g. '0-1-1,0-1-2'). | ||
|
|
||
| @return |
There was a problem hiding this comment.
fwiw, use @RetVal if you want to do good doxygen. Or don't do doxygen.
| @@ -5838,4 +5839,113 @@ int compare_log_name(const char *log_1, const char *log_2) { | |||
| return res; | |||
| } | |||
|
|
|||
| /** | |||
There was a problem hiding this comment.
that's what good doxygen looks like! Nice! I'd consider doing some @sa too towards the bigger picture/subsystem. But this is optional.
|
Thnks again for the review, I pushed an update addressing your final remarks:
|
I’ve been diving deep into the replication source code for the last two weeks,
investigating MDEV-8235. I noticed this task has been open for a while and realized
how useful it would be for DBAs to have a simple way to check GTID availability
directly from the SQL layer.
After studying how check_slave_start_position() works internally, I’ve implemented
a user-facing version called GTID_CHECK_POS().
What this PR does:
in sql_repl.cc to avoid code duplication.
which makes it robust for automation scripts.
I’m really excited to contribute this to MariaDB and would appreciate feedback
on the implementation.