Skip to content

Commit 7115341

Browse files
committed
Fixed warnings and errors found by buildbot
field.cc - Fixed warning about overlapping memory copy (backport from 10.0) Item_subselect.cc - Fixed core dump in main.view - Problem was that thd->lex->current_select->master_unit()->item was not set, which caused crash in maxr_as_dependent sql/mysqld.cc - Got error on shutdown as we where freeing mutex before all THD objects was freed (~THD uses some mutex). Fixed by during shutdown freeing THD inside mutex. sql/log.cc - log_space_lock and LOCK_log where locked in inconsistenly. Fixed by not having a log_space_lock around purge_logs. sql/slave.cc - Remove unnecessary log_space_lock - Move cond_broadcast inside lock to ensure we don't miss the signal
1 parent 7a96702 commit 7115341

File tree

5 files changed

+40
-30
lines changed

5 files changed

+40
-30
lines changed

sql/field.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7612,7 +7612,8 @@ int Field_geom::store(const char *from, uint length, CHARSET_INFO *cs)
76127612
}
76137613

76147614
Field_blob::store_length(length);
7615-
if (table->copy_blobs || length <= MAX_FIELD_WIDTH)
7615+
if ((table->copy_blobs || length <= MAX_FIELD_WIDTH) &&
7616+
from != value.ptr())
76167617
{ // Must make a copy
76177618
value.copy(from, length, cs);
76187619
from= value.ptr();

sql/item_subselect.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,10 +2018,21 @@ Item_in_subselect::create_single_in_to_exists_cond(JOIN *join,
20182018
*/
20192019
if (expr && !expr->fixed)
20202020
{
2021+
bool tmp;
20212022
SELECT_LEX *save_current_select= thd->lex->current_select;
2023+
Item_subselect *save_item;
2024+
20222025
thd->lex->current_select= thd->lex->current_select->outer_select();
2023-
bool tmp;
2026+
/*
2027+
For st_select_lex::mark_as_dependent, who needs to mark
2028+
this sub query as correlated.
2029+
*/
2030+
save_item= thd->lex->current_select->master_unit()->item;
2031+
thd->lex->current_select->master_unit()->item= this;
2032+
20242033
tmp= expr->fix_fields(thd, 0);
2034+
2035+
thd->lex->current_select->master_unit()->item= save_item;
20252036
thd->lex->current_select= save_current_select;
20262037
if (tmp)
20272038
DBUG_RETURN(true);

sql/log.cc

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3676,6 +3676,7 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
36763676
{
36773677
int error;
36783678
char *to_purge_if_included= NULL;
3679+
ulonglong log_space_reclaimed= 0;
36793680
DBUG_ENTER("purge_first_log");
36803681

36813682
DBUG_ASSERT(is_open());
@@ -3724,17 +3725,13 @@ int MYSQL_BIN_LOG::purge_first_log(Relay_log_info* rli, bool included)
37243725

37253726
DBUG_EXECUTE_IF("crash_before_purge_logs", DBUG_SUICIDE(););
37263727

3727-
mysql_mutex_lock(&rli->log_space_lock);
37283728
rli->relay_log.purge_logs(to_purge_if_included, included,
3729-
0, 0, &rli->log_space_total);
3730-
mysql_mutex_unlock(&rli->log_space_lock);
3729+
0, 0, &log_space_reclaimed);
37313730

3732-
/*
3733-
Ok to broadcast after the critical region as there is no risk of
3734-
the mutex being destroyed by this thread later - this helps save
3735-
context switches
3736-
*/
3731+
mysql_mutex_lock(&rli->log_space_lock);
3732+
rli->log_space_total-= log_space_reclaimed;
37373733
mysql_cond_broadcast(&rli->log_space_cond);
3734+
mysql_mutex_unlock(&rli->log_space_lock);
37383735

37393736
/*
37403737
* Need to update the log pos because purge logs has been called
@@ -3783,8 +3780,8 @@ int MYSQL_BIN_LOG::update_log_index(LOG_INFO* log_info, bool need_update_threads
37833780
@param need_mutex
37843781
@param need_update_threads If we want to update the log coordinates of
37853782
all threads. False for relay logs, true otherwise.
3786-
@param freed_log_space If not null, decrement this variable of
3787-
the amount of log space freed
3783+
@param reclaimeed_log_space If not null, increment this variable to
3784+
the amount of log space freed
37883785
37893786
@note
37903787
If any of the logs before the deleted one is in use,
@@ -3800,10 +3797,10 @@ int MYSQL_BIN_LOG::update_log_index(LOG_INFO* log_info, bool need_update_threads
38003797
*/
38013798

38023799
int MYSQL_BIN_LOG::purge_logs(const char *to_log,
3803-
bool included,
3804-
bool need_mutex,
3805-
bool need_update_threads,
3806-
ulonglong *decrease_log_space)
3800+
bool included,
3801+
bool need_mutex,
3802+
bool need_update_threads,
3803+
ulonglong *reclaimed_space)
38073804
{
38083805
int error= 0;
38093806
bool exit_loop= 0;
@@ -3868,7 +3865,7 @@ int MYSQL_BIN_LOG::purge_logs(const char *to_log,
38683865
err:
38693866
/* Read each entry from purge_index_file and delete the file. */
38703867
if (is_inited_purge_index_file() &&
3871-
(error= purge_index_entry(thd, decrease_log_space, FALSE)))
3868+
(error= purge_index_entry(thd, reclaimed_space, FALSE)))
38723869
sql_print_error("MSYQL_BIN_LOG::purge_logs failed to process registered files"
38733870
" that would be purged.");
38743871
close_purge_index_file();
@@ -3973,7 +3970,7 @@ int MYSQL_BIN_LOG::register_create_index_entry(const char *entry)
39733970
DBUG_RETURN(register_purge_index_entry(entry));
39743971
}
39753972

3976-
int MYSQL_BIN_LOG::purge_index_entry(THD *thd, ulonglong *decrease_log_space,
3973+
int MYSQL_BIN_LOG::purge_index_entry(THD *thd, ulonglong *reclaimed_space,
39773974
bool need_mutex)
39783975
{
39793976
DBUG_ENTER("MYSQL_BIN_LOG:purge_index_entry");
@@ -4093,8 +4090,8 @@ int MYSQL_BIN_LOG::purge_index_entry(THD *thd, ulonglong *decrease_log_space,
40934090
DBUG_PRINT("info",("purging %s",log_info.log_file_name));
40944091
if (!my_delete(log_info.log_file_name, MYF(0)))
40954092
{
4096-
if (decrease_log_space)
4097-
*decrease_log_space-= s.st_size;
4093+
if (reclaimed_space)
4094+
*reclaimed_space+= s.st_size;
40984095
}
40994096
else
41004097
{

sql/mysqld.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2488,14 +2488,23 @@ void unlink_thd(THD *thd)
24882488
thd->add_status_to_global();
24892489

24902490
mysql_mutex_lock(&LOCK_thread_count);
2491-
thread_count--;
24922491
thd->unlink();
24932492
/*
24942493
Used by binlog_reset_master. It would be cleaner to use
24952494
DEBUG_SYNC here, but that's not possible because the THD's debug
24962495
sync feature has been shut down at this point.
24972496
*/
24982497
DBUG_EXECUTE_IF("sleep_after_lock_thread_count_before_delete_thd", sleep(5););
2498+
if (unlikely(abort_loop))
2499+
{
2500+
/*
2501+
During shutdown, we have to delete thd inside the mutex
2502+
to not refer to mutexes that may be deleted during shutdown
2503+
*/
2504+
delete thd;
2505+
thd= 0;
2506+
}
2507+
thread_count--;
24992508
mysql_mutex_unlock(&LOCK_thread_count);
25002509

25012510
delete thd;

sql/slave.cc

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,9 +3556,7 @@ pthread_handler_t handle_slave_sql(void *arg)
35563556
rli->clear_error();
35573557

35583558
//tell the I/O thread to take relay_log_space_limit into account from now on
3559-
mysql_mutex_lock(&rli->log_space_lock);
35603559
rli->ignore_log_space_limit= 0;
3561-
mysql_mutex_unlock(&rli->log_space_lock);
35623560
rli->trans_retries= 0; // start from "no error"
35633561
DBUG_PRINT("info", ("rli->trans_retries: %lu", rli->trans_retries));
35643562

@@ -5228,14 +5226,8 @@ static Log_event* next_event(Relay_log_info* rli)
52285226
rli->ignore_log_space_limit= true;
52295227
}
52305228

5231-
/*
5232-
If the I/O thread is blocked, unblock it. Ok to broadcast
5233-
after unlock, because the mutex is only destroyed in
5234-
~Relay_log_info(), i.e. when rli is destroyed, and rli will
5235-
not be destroyed before we exit the present function.
5236-
*/
5237-
mysql_mutex_unlock(&rli->log_space_lock);
52385229
mysql_cond_broadcast(&rli->log_space_cond);
5230+
mysql_mutex_unlock(&rli->log_space_lock);
52395231
// Note that wait_for_update_relay_log unlocks lock_log !
52405232
rli->relay_log.wait_for_update_relay_log(rli->sql_thd);
52415233
// re-acquire data lock since we released it earlier

0 commit comments

Comments
 (0)