Skip to content

Commit

Permalink
Fix locations that reference thd.net to use thd.net_ptr
Browse files Browse the repository at this point in the history
Summary: Use thd.net_ptr so that that both detached sessions and regular sessions update the correct NET.  This affects LOAD DATA INFILE as well as the query cache

Reviewed By: abal147

Differential Revision: D14312882

fbshipit-source-id: b2961fa1782
  • Loading branch information
jkedgar authored and facebook-github-bot committed Apr 23, 2019
1 parent 307760a commit 205e06a
Show file tree
Hide file tree
Showing 28 changed files with 258 additions and 190 deletions.
2 changes: 1 addition & 1 deletion client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2899,7 +2899,7 @@ static void try_setup_rpc_role(st_connection *con) {
// Only the root user has proxy privileges for other users so only
// do this automatically for root.
if (con->rpc_id[0] == '\0' && !con->rpc_role_set &&
(std::string(mysql->user) == std::string("root"))) {
mysql->user && (std::string(mysql->user) == std::string("root"))) {
DBUG_PRINT("info",
("Converting query to com_rpc conn_id: %lu, role: %s, db: %s",
mysql->thread_id, mysql->user, mysql->db));
Expand Down
6 changes: 3 additions & 3 deletions libmysqld/lib_sql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ void *create_embedded_thd(int client_flag)
thd->cur_data= 0;
thd->first_data= 0;
thd->data_tail= &thd->first_data;
memset(&thd->net, 0, sizeof(thd->net));
memset(thd->get_net(), 0, sizeof(*thd->get_net()));

mutex_lock_shard(SHARDED(&LOCK_thread_count), thd);
add_global_thread(thd);
Expand Down Expand Up @@ -874,8 +874,8 @@ int check_embedded_connection(MYSQL *mysql, const char *db)

end= (char *) send_client_connect_attrs(mysql, (uchar *) end);

/* acl_authenticate() takes the data from thd->net->read_pos */
thd->net.read_pos= (uchar*)buf;
/* acl_authenticate() takes the data from thd->get_net()->read_pos */
thd->get_net()->read_pos= (uchar*)buf;

if (acl_authenticate(thd, 0, end - buf))
{
Expand Down
2 changes: 1 addition & 1 deletion plugin/semisync/semisync_master_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ int repl_semi_after_send_event(Binlog_transmit_param *param,
else
{
THD *thd= current_thd;
int err= repl_semisync.readSlaveReply(&thd->net,
int err= repl_semisync.readSlaveReply(thd->get_net(),
param->server_id,
event_buf);
/*
Expand Down
24 changes: 14 additions & 10 deletions sql/event_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ void
deinit_event_thread(THD *thd)
{
thd->proc_info= "Clearing";
DBUG_ASSERT(thd->net.buff != 0);
net_end(&thd->net);
NET* net = thd->get_net();
DBUG_ASSERT(net->buff != 0);
net_end(net);
DBUG_PRINT("exit", ("Event thread finishing"));

dec_thread_running();
Expand All @@ -176,7 +177,7 @@ deinit_event_thread(THD *thd)
NOTES
1. The host of the thead is my_localhost
2. thd->net is initted with NULL - no communication.
2. thd->get_net() is initted with NULL - no communication.
*/

void
Expand All @@ -187,9 +188,10 @@ pre_init_event_thread(THD* thd)
thd->security_ctx->master_access= 0;
thd->security_ctx->db_access= 0;
thd->security_ctx->host_or_ip= (char*)my_localhost;
my_net_init(&thd->net, NULL);
NET* net = thd->get_net();
my_net_init(net, NULL);
thd->security_ctx->set_user((char*)"event_scheduler");
thd->net.read_timeout = timeout_from_seconds(slave_net_timeout);
net->read_timeout = timeout_from_seconds(slave_net_timeout);
thd->slave_thread= 0;
thd->variables.option_bits|= OPTION_AUTO_IS_NULL;
thd->client_capabilities|= CLIENT_MULTI_RESULTS;
Expand Down Expand Up @@ -242,7 +244,7 @@ event_scheduler_thread(void *arg)
else
{
thd->proc_info= "Clearing";
net_end(&thd->net);
net_end(thd->get_net());
delete thd;
}

Expand Down Expand Up @@ -447,8 +449,9 @@ Event_scheduler::start(int *err_no)
*err_no);

new_thd->proc_info= "Clearing";
DBUG_ASSERT(new_thd->net.buff != 0);
net_end(&new_thd->net);
NET* net = new_thd->get_net();
DBUG_ASSERT(net->buff != 0);
net_end(net);

state= INITIALIZED;
scheduler_thd= NULL;
Expand Down Expand Up @@ -579,8 +582,9 @@ Event_scheduler::execute_top(Event_queue_element_for_exec *event_name)
" thread (errno=%d). Stopping event scheduler", res);

new_thd->proc_info= "Clearing";
DBUG_ASSERT(new_thd->net.buff != 0);
net_end(&new_thd->net);
NET* net = new_thd->get_net();
DBUG_ASSERT(net->buff != 0);
net_end(net);

goto error;
}
Expand Down
4 changes: 2 additions & 2 deletions sql/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,7 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
(ulong) thd->get_sent_row_count(),
(ulong) thd->get_examined_row_count(),
(ulong) thd->thread_id(),
(ulong) thd->net.last_errno,
(ulong) thd->get_net()->last_errno,
(ulong) thd->killed,
(ulong) (thd->status_var.bytes_received -
query_start->bytes_received),
Expand Down Expand Up @@ -2324,7 +2324,7 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
(ulong) thd->get_sent_row_count(),
(ulong) thd->get_examined_row_count(),
(ulong) thd->thread_id(),
(ulong) thd->net.last_errno,
(ulong) thd->get_net()->last_errno,
(ulong) thd->killed,
(ulong) thd->status_var.bytes_received,
(ulong) thd->status_var.bytes_sent,
Expand Down
10 changes: 5 additions & 5 deletions sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7377,10 +7377,10 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli,
thd->variables.pseudo_thread_id= thread_id;
if (net)
{
// mysql_load will use thd->net to read the file
thd->net.vio = net->vio;
// mysql_load will use thd->get_net() to read the file
thd->get_net()->vio = net->vio;
// Make sure the client does not get confused about the packet sequence
thd->net.pkt_nr = net->pkt_nr;
thd->get_net()->pkt_nr = net->pkt_nr;
}
/*
It is safe to use tmp_list twice because we are not going to
Expand All @@ -7404,7 +7404,7 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli,
print_slave_db_safe(thd->db));
}
if (net)
net->pkt_nr= thd->net.pkt_nr;
net->pkt_nr= thd->get_net()->pkt_nr;
}
}
else
Expand All @@ -7419,7 +7419,7 @@ int Load_log_event::do_apply_event(NET* net, Relay_log_info const *rli,
}

error:
thd->net.vio = 0;
thd->get_net()->vio = 0;
const char *remember_db= thd->db;
thd->catalog= 0;
thd->set_db(NULL, 0); /* will free the current database */
Expand Down
26 changes: 15 additions & 11 deletions sql/log_event_old.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1534,10 +1534,11 @@ int Old_rows_log_event::do_apply_event(Relay_log_info const *rli)
Error reporting borrowed from Query_log_event with many excessive
simplifications (we don't honour --slave-skip-errors)
*/
uint actual_error= thd->net.last_errno;
const NET* net = thd->get_net();
uint actual_error= net->last_errno;
rli->report(ERROR_LEVEL, actual_error,
"Error '%s' in %s event: when locking tables",
(actual_error ? thd->net.last_error :
(actual_error ? net->last_error :
"unexpected success or fatal error"),
get_type_str());
thd->is_fatal_error= 1;
Expand Down Expand Up @@ -1711,10 +1712,11 @@ int Old_rows_log_event::do_apply_event(Relay_log_info const *rli)
break;

default:
rli->report(ERROR_LEVEL, thd->net.last_errno,
const NET* net = thd->get_net();
rli->report(ERROR_LEVEL, net->last_errno,
"Error in %s event: row application failed. %s",
get_type_str(),
thd->net.last_error);
net->last_error);
thd->is_slave_error= 1;
break;
}
Expand Down Expand Up @@ -1749,12 +1751,13 @@ int Old_rows_log_event::do_apply_event(Relay_log_info const *rli)

if (error)
{ /* error has occured during the transaction */
rli->report(ERROR_LEVEL, thd->net.last_errno,
const NET* net = thd->get_net();
rli->report(ERROR_LEVEL, net->last_errno,
"Error in %s event: error during transaction execution "
"on table %s.%s. %s",
get_type_str(), table->s->db.str,
table->s->table_name.str,
thd->net.last_error);
net->last_error);

/*
If one day we honour --skip-slave-errors in row-based replication, and
Expand Down Expand Up @@ -1889,9 +1892,9 @@ Old_rows_log_event::do_update_pos(Relay_log_info *rli)
*/
rli->stmt_done(log_pos);
/*
Clear any errors in thd->net.last_err*. It is not known if this is
Clear any errors in thd->get_net()->last_err*. It is not known if this is
needed or not. It is believed that any errors that may exist in
thd->net.last_err* are allowed. Examples of errors are "key not
thd->get_net()->last_err* are allowed. Examples of errors are "key not
found", which is produced in the test case rpl_row_conflicts.test
*/
thd->clear_error();
Expand Down Expand Up @@ -2631,9 +2634,10 @@ Write_rows_log_event_old::do_exec_row(const Relay_log_info *const rli)
{
DBUG_ASSERT(m_table != NULL);
int error= write_row(rli, TRUE /* overwrite */);

if (error && !thd->net.last_errno)
thd->net.last_errno= error;

NET* net = thd->get_net();
if (error && !net->last_errno)
net->last_errno= error;

return error;
}
Expand Down
2 changes: 1 addition & 1 deletion sql/mf_iocache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int _my_b_net_read(register IO_CACHE *info, uchar *Buffer,
size_t Count MY_ATTRIBUTE((unused)))
{
ulong read_length;
NET *net= &(current_thd)->net;
NET *net= current_thd->get_net();
DBUG_ENTER("_my_b_net_read");

if (!info->end_of_file)
Expand Down
Loading

0 comments on commit 205e06a

Please sign in to comment.