-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MDEV-37602: Phase 1 & 2 - Session-scoped rgi and Master_info registration in index #5159
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
bodyhedia44
wants to merge
1
commit into
MariaDB:main
Choose a base branch
from
bodyhedia44:MDEV-37602-binlog-replay-rework
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.
+74
−46
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 |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| #include "rpl_mi.h" | ||
| #include "slave.h" | ||
| #include "log_event.h" | ||
| #include <cstdio> | ||
|
|
||
|
|
||
| /** | ||
|
|
@@ -163,14 +164,7 @@ int save_restore_context_apply_event(Log_event *ev, rpl_group_info *rgi) | |
|
|
||
| THD *thd= rgi->thd; | ||
| Relay_log_info *rli= thd->rli_fake; | ||
| DBUG_ASSERT(!rli->mi); | ||
| LEX_CSTRING connection_name= { STRING_WITH_LEN("BINLOG_BASE64_EVENT") }; | ||
|
|
||
| if (!(rli->mi= new Master_info(&connection_name, false))) | ||
| { | ||
| my_error(ER_OUT_OF_RESOURCES, MYF(0)); | ||
| return -1; | ||
| } | ||
| DBUG_ASSERT(rli->mi); | ||
|
|
||
| sql_digest_state *m_digest= thd->m_digest; | ||
| PSI_statement_locker *m_statement_psi= thd->m_statement_psi;; | ||
|
|
@@ -189,8 +183,6 @@ int save_restore_context_apply_event(Log_event *ev, rpl_group_info *rgi) | |
| thd->m_statement_psi= m_statement_psi; | ||
| thd->variables.pseudo_thread_id= m_thread_id; | ||
| thd->reset_db(&save_db); | ||
| delete rli->mi; | ||
| rli->mi= NULL; | ||
|
|
||
| return err; | ||
| } | ||
|
|
@@ -234,28 +226,55 @@ void mysql_client_binlog_statement(THD* thd) | |
|
|
||
| int err; | ||
| Relay_log_info *rli; | ||
| rpl_group_info *rgi; | ||
| rpl_group_info *rgi= thd->rgi_fake; | ||
| uchar *buf= NULL; | ||
| size_t coded_len= 0, decoded_len= 0; | ||
|
|
||
| rli= thd->rli_fake; | ||
| if (!rli && (rli= thd->rli_fake= new Relay_log_info(FALSE, "BINLOG_BASE64_EVENT"))) | ||
| rli->sql_driver_thd= thd; | ||
| if (!(rgi= thd->rgi_fake)) | ||
| rgi= thd->rgi_fake= new rpl_group_info(rli); | ||
| rgi->thd= thd; | ||
| const char *error= 0; | ||
| Log_event *ev = 0; | ||
| Log_event *ev= 0; | ||
| my_bool is_fragmented= FALSE; | ||
| my_bool keep_rgi= false; | ||
| /* | ||
| Out of memory check | ||
| */ | ||
| if (!(rli)) | ||
|
|
||
| rli= thd->rli_fake; | ||
| if (!rli) | ||
| { | ||
| my_error(ER_OUTOFMEMORY, MYF(ME_FATAL), 1); /* needed 1 bytes */ | ||
| goto end; | ||
| /* | ||
| Create a session-scoped Master_info. Its embedded Relay_log_info | ||
| serves as rli_fake for the connection, eliminating throwaway | ||
| Master_info creation per Query event in save_restore_context_apply_event(). | ||
| Register it in master_info_index for visibility in SHOW SLAVE STATUS. | ||
| */ | ||
| char conn_name_buf[64]; | ||
| int len= snprintf(conn_name_buf, sizeof(conn_name_buf), | ||
| "binlog_replay_%llu", | ||
| (unsigned long long)thd->thread_id); | ||
| LEX_CSTRING connection_name= { conn_name_buf, (size_t)len }; | ||
|
|
||
| Master_info *mi= new Master_info(&connection_name, false); | ||
| if (!mi || mi->error()) | ||
| { | ||
| delete mi; | ||
| my_error(ER_OUTOFMEMORY, MYF(ME_FATAL), 1); | ||
| goto end; | ||
| } | ||
| mi->rli.mi= mi; | ||
| mi->rli.sql_driver_thd= thd; | ||
|
|
||
| /* | ||
| Register in master_info_index so it appears in monitoring queries. | ||
| Pass write_to_file=FALSE since binlog_replay connections are ephemeral. | ||
| */ | ||
| if (master_info_index->add_master_info(mi, FALSE)) | ||
| { | ||
| delete mi; | ||
| my_error(ER_OUTOFMEMORY, MYF(ME_FATAL), 1); | ||
| goto end; | ||
| } | ||
|
|
||
| thd->mi_fake= mi; | ||
| thd->rli_fake= rli= &mi->rli; | ||
| } | ||
| if (!rgi) | ||
| rgi= thd->rgi_fake= new rpl_group_info(rli); | ||
| rgi->thd= thd; | ||
|
Comment on lines
+275
to
+277
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. If if (!rgi)
{
if (!(rgi= thd->rgi_fake= new rpl_group_info(rli)))
{
my_error(ER_OUTOFMEMORY, MYF(ME_FATAL), 1);
goto end;
}
}
rgi->thd= thd; |
||
|
|
||
| DBUG_ASSERT(rli->belongs_to_client()); | ||
|
|
||
|
|
@@ -412,16 +431,6 @@ void mysql_client_binlog_statement(THD* thd) | |
| */ | ||
| LEX *backup_lex; | ||
|
|
||
| /* | ||
| If we are re-assembling a Rows_log_event from a group of | ||
| Partial_rows_log_events, the rgi houses the assembler, so we need | ||
| it around while we are re-constructing the event. | ||
| */ | ||
| if (ev->get_type_code() == PARTIAL_ROW_DATA_EVENT && | ||
| (((Partial_rows_log_event *) ev)->seq_no < | ||
| ((Partial_rows_log_event *) ev)->total_fragments)) | ||
| keep_rgi= true; | ||
|
|
||
| thd->backup_and_reset_current_lex(&backup_lex); | ||
| err= save_restore_context_apply_event(ev, rgi); | ||
| thd->restore_current_lex(backup_lex); | ||
|
|
@@ -462,13 +471,8 @@ void mysql_client_binlog_statement(THD* thd) | |
| if (unlikely(is_fragmented)) | ||
| my_free(const_cast<char*>(thd->lex->comment.str)); | ||
| thd->variables.option_bits= thd_options; | ||
| rgi->slave_close_thread_tables(thd); | ||
| if (rgi) | ||
| rgi->slave_close_thread_tables(thd); | ||
| my_free(buf); | ||
|
|
||
| if (!keep_rgi) | ||
| { | ||
| delete rgi; | ||
| rgi= thd->rgi_fake= NULL; | ||
| } | ||
| DBUG_VOID_RETURN; | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global
master_info_indexcan beNULLon standalone servers where replication is not initialized or disabled. Dereferencing it directly will cause a server crash when executingBINLOGstatements. Additionally, modifyingmaster_info_indexrequires holding theLOCK_active_mimutex to prevent race conditions with other threads (e.g., concurrentSHOW STATUSor administrative commands).Please add a
NULLcheck formaster_info_indexand wrap the registration inLOCK_active_mi.