-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-8235: Expose check_slave_start_position as SQL function GTID_CHECK_POS() #4956
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
Open
ayush-jha123
wants to merge
2
commits into
MariaDB:main
Choose a base branch
from
ayush-jha123:mdev-8235-gtid-pos
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # | ||
| # MDEV-8235 Expose check_slave_start_position as SQL function | ||
| # | ||
| # 1. Set up some basic GTID history | ||
| CREATE TABLE t1 (a INT); | ||
| INSERT INTO t1 VALUES (1); | ||
| INSERT INTO t1 VALUES (2); | ||
| # Get the current GTID position manually and verify it exists | ||
| SELECT GTID_CHECK_POS('GTID_POS'); | ||
| GTID_CHECK_POS('GTID_POS') | ||
| 1 | ||
| # 2. Verify invalid inputs | ||
| SELECT GTID_CHECK_POS('invalid-format'); | ||
| ERROR HY000: Could not parse GTID list | ||
| SELECT GTID_CHECK_POS(NULL); | ||
| GTID_CHECK_POS(NULL) | ||
| NULL | ||
| # 3. Check for a very old purged GTID | ||
| # (Simulate purging all logs) | ||
| FLUSH LOGS; | ||
| PURGE BINARY LOGS BEFORE NOW(); | ||
| # Depending on when it is executed, '0-1-1' might still be | ||
| # reachable if we haven't actually purged the very first file | ||
| # but purge binary logs before now() should remove everything | ||
| # except the active one. | ||
| # Since we want a deterministic test, let's check | ||
| # a completely fake server_id / seq_no that shouldn't exist | ||
| SELECT GTID_CHECK_POS('99-99-9999999'); | ||
| GTID_CHECK_POS('99-99-9999999') | ||
| 1 | ||
| # 4. Check for an otherwise valid GTID (right domain and server) | ||
| # that is absent (sequence number is in the future). | ||
| SELECT GTID_CHECK_POS('ABSENT_GTID'); | ||
| GTID_CHECK_POS('ABSENT_GTID') | ||
| 1 | ||
| # Cleanup | ||
| DROP TABLE t1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --source include/have_log_bin.inc | ||
|
|
||
| --echo # | ||
| --echo # MDEV-8235 Expose check_slave_start_position as SQL function | ||
| --echo # | ||
|
|
||
| --echo # 1. Set up some basic GTID history | ||
| CREATE TABLE t1 (a INT); | ||
| INSERT INTO t1 VALUES (1); | ||
| INSERT INTO t1 VALUES (2); | ||
|
|
||
| --echo # Get the current GTID position manually and verify it exists | ||
| let $pos= `SELECT @@GLOBAL.gtid_binlog_pos`; | ||
| --replace_result $pos GTID_POS | ||
| eval SELECT GTID_CHECK_POS('$pos'); | ||
|
gkodinov marked this conversation as resolved.
|
||
|
|
||
| --echo # 2. Verify invalid inputs | ||
| --error ER_INCORRECT_GTID_STATE | ||
| SELECT GTID_CHECK_POS('invalid-format'); | ||
| SELECT GTID_CHECK_POS(NULL); | ||
|
|
||
| --echo # 3. Check for a very old purged GTID | ||
| --echo # (Simulate purging all logs) | ||
| FLUSH LOGS; | ||
| PURGE BINARY LOGS BEFORE NOW(); | ||
|
|
||
| --echo # Depending on when it is executed, '0-1-1' might still be | ||
| --echo # reachable if we haven't actually purged the very first file | ||
| --echo # but purge binary logs before now() should remove everything | ||
| --echo # except the active one. | ||
|
|
||
| --echo # Since we want a deterministic test, let's check | ||
| --echo # a completely fake server_id / seq_no that shouldn't exist | ||
| SELECT GTID_CHECK_POS('99-99-9999999'); | ||
|
|
||
| --echo # 4. Check for an otherwise valid GTID (right domain and server) | ||
| --echo # that is absent (sequence number is in the future). | ||
| let $server_id= `SELECT @@GLOBAL.server_id`; | ||
| let $absent_gtid= 0-$server_id-99999999; | ||
| --replace_result $absent_gtid ABSENT_GTID | ||
| eval SELECT GTID_CHECK_POS('$absent_gtid'); | ||
|
|
||
| --echo # Cleanup | ||
| DROP TABLE t1; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ | |
| #include "sql_acl.h" // EXECUTE_ACL | ||
| #include "mysqld.h" // LOCK_short_uuid_generator | ||
| #include "rpl_mi.h" | ||
|
|
||
| #include "sql_time.h" | ||
| #include <m_ctype.h> | ||
| #include <hash.h> | ||
|
|
@@ -53,6 +54,7 @@ | |
| #include "sql_cte.h" | ||
| #ifdef WITH_WSREP | ||
| #include "mysql/service_wsrep.h" | ||
| #include "sql_repl.h" | ||
| #endif /* WITH_WSREP */ | ||
|
|
||
| #ifdef NO_EMBEDDED_ACCESS_CHECKS | ||
|
|
@@ -824,6 +826,30 @@ String *Item_int_func::val_str(String *str) | |
| } | ||
|
|
||
|
|
||
| bool Item_func_gtid_check_pos::val_bool() | ||
| { | ||
| DBUG_ASSERT(fixed()); | ||
| String *gtid_str= args[0]->val_str(&tmp_value); | ||
| if ((null_value= args[0]->null_value)) | ||
| return 0; | ||
|
|
||
| #ifndef HAVE_REPLICATION | ||
| my_error(ER_NOT_SUPPORTED_YET, MYF(0), "GTID_CHECK_POS"); | ||
| null_value= 1; | ||
| return 0; | ||
| #else | ||
| bool is_reachable= false; | ||
| if (rpl_gtid_pos_check_reachable(gtid_str, &is_reachable)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails to compile on buildbot (I'm assuming for the unit tests) as follows: Please have a look. |
||
| { | ||
| null_value= 1; | ||
| return 0; | ||
| } | ||
| null_value= 0; | ||
| return is_reachable; | ||
| #endif | ||
| } | ||
|
|
||
|
|
||
| bool Item_func_connection_id::fix_length_and_dec(THD *thd) | ||
| { | ||
| if (Item_long_func::fix_length_and_dec(thd)) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
| #include "semisync_slave.h" | ||
| #include "mysys_err.h" | ||
| #include "gtid_index.h" | ||
| #include "item_cmpfunc.h" | ||
|
|
||
|
|
||
| enum enum_gtid_until_state { | ||
|
|
@@ -2122,6 +2123,9 @@ gtid_state_from_binlog_pos(const char *in_name, uint32 pos, String *out_str) | |
| } | ||
|
|
||
|
|
||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no space only changes please. |
||
|
|
||
|
|
||
| static bool | ||
| is_until_reached(binlog_send_info *info, ulong *ev_offset, | ||
| Log_event_type event_type, const char **errmsg, | ||
|
|
@@ -5838,4 +5842,60 @@ int compare_log_name(const char *log_1, const char *log_2) { | |
| return res; | ||
| } | ||
|
|
||
| bool rpl_gtid_pos_check_reachable(String *gtid_str, bool *is_reachable) | ||
| { | ||
|
|
||
| slave_connection_state state; | ||
| char buf[FN_REFLEN] = {0}; | ||
| const char *errormsg; | ||
|
|
||
| if (!mysql_bin_log.is_open()) | ||
| { | ||
| my_error(ER_NO_BINARY_LOGGING, MYF(0)); | ||
| return true; | ||
| } | ||
|
|
||
| if (state.load(gtid_str->ptr(), gtid_str->length())) | ||
| { | ||
| /* | ||
| We purposefully do not swallow the error here. If the user passes an | ||
| ill-formed string, state.load throws ER_INCORRECT_GTID_STATE which | ||
| will correctly abort the statement and notify the user. | ||
| */ | ||
| return true; | ||
| } | ||
|
|
||
| /* | ||
| gtid_find_binlog_pos will natively iterate over the entire `state` hash, | ||
| evaluating every GTID provided in the comma-separated list. | ||
|
|
||
| If ANY of the requested GTIDs are found to be purged from the binary logs, | ||
| it returns a non-null error message pinpointing the purged GTID. | ||
|
|
||
| If ALL GTIDs within the requested state natively resolve (meaning they exist | ||
| in our index/binlogs, or are safely in the future), it returns a null errormsg. | ||
|
|
||
| We disregard `found_in_index` and `out_start_seek` counts since we are only doing | ||
| boolean viability checking of the provided GTIDs, not actually initializing a dump thread. | ||
| */ | ||
| bool found_in_index= false; | ||
| uint32 out_start_seek= 0; | ||
| rpl_binlog_state until_binlog_state; | ||
| until_binlog_state.init(); | ||
| slave_connection_state until_gtid_state; | ||
|
|
||
| errormsg= gtid_find_binlog_pos(&state, buf, &until_gtid_state, &until_binlog_state, &found_in_index, &out_start_seek); | ||
|
|
||
| until_binlog_state.free(); | ||
|
|
||
| if (errormsg) | ||
| { | ||
| *is_reachable= false; | ||
| return false; // At least one requested GTID has been purged. | ||
| } | ||
|
|
||
| *is_reachable= true; | ||
| return false; // All requested GTIDs are currently viable/reachable. | ||
| } | ||
|
|
||
| #endif /* HAVE_REPLICATION */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.