Skip to content

Commit 3088d52

Browse files
author
Nirbhay Choubey
committed
bzr merge -r3933..3945 codership/5.5 (Non-InnoDB changes only).
1 parent 3c0b3ba commit 3088d52

File tree

13 files changed

+91
-97
lines changed

13 files changed

+91
-97
lines changed

include/thr_lock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern "C" {
2222
#endif
2323
#ifdef WITH_WSREP
2424
#include <my_sys.h>
25-
typedef int (* wsrep_thd_is_brute_force_fun)(void *);
25+
typedef my_bool (* wsrep_thd_is_brute_force_fun)(void *, my_bool);
2626
typedef int (* wsrep_abort_thd_fun)(void *, void *, my_bool);
2727
typedef int (* wsrep_on_fun)(void *);
2828
void wsrep_thr_lock_init(

mysys/thr_lock.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ wsrep_break_lock(
690690
{
691691
if (wsrep_on(data->owner->mysql_thd) &&
692692
wsrep_thd_is_brute_force &&
693-
wsrep_thd_is_brute_force(data->owner->mysql_thd))
693+
wsrep_thd_is_brute_force(data->owner->mysql_thd, TRUE))
694694
{
695695
THR_LOCK_DATA *holder;
696696

@@ -715,7 +715,7 @@ wsrep_break_lock(
715715
holder;
716716
holder=holder->next)
717717
{
718-
if (!wsrep_thd_is_brute_force(holder->owner->mysql_thd))
718+
if (!wsrep_thd_is_brute_force(holder->owner->mysql_thd, TRUE))
719719
{
720720
wsrep_abort_thd(data->owner->mysql_thd,
721721
holder->owner->mysql_thd, FALSE);
@@ -731,7 +731,7 @@ wsrep_break_lock(
731731
holder;
732732
holder=holder->next)
733733
{
734-
if (!wsrep_thd_is_brute_force(holder->owner->mysql_thd))
734+
if (!wsrep_thd_is_brute_force(holder->owner->mysql_thd, TRUE))
735735
{
736736
wsrep_abort_thd(data->owner->mysql_thd,
737737
holder->owner->mysql_thd, FALSE);

sql/log.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,11 @@ void thd_binlog_trx_reset(THD * thd)
567567
{
568568
binlog_cache_mngr *const cache_mngr=
569569
(binlog_cache_mngr*) thd_get_ha_data(thd, binlog_hton);
570-
if (cache_mngr) cache_mngr->reset(false, true);
571-
}
570+
if (cache_mngr)
571+
{
572+
cache_mngr->reset_cache(&cache_mngr->stmt_cache);
573+
cache_mngr->reset_cache(&cache_mngr->trx_cache);
574+
}
572575
thd->clear_binlog_table_maps();
573576
}
574577

sql/mdl.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ void MDL_lock::Ticket_list::add_ticket(MDL_ticket *ticket)
14821482
DBUG_ASSERT(ticket->get_lock());
14831483
#ifdef WITH_WSREP
14841484
if ((this == &(ticket->get_lock()->m_waiting)) &&
1485-
wsrep_thd_is_brute_force((void *)(ticket->get_ctx()->wsrep_get_thd())))
1485+
wsrep_thd_is_BF((void *)(ticket->get_ctx()->get_thd()), false))
14861486
{
14871487
Ticket_iterator itw(ticket->get_lock()->m_waiting);
14881488
Ticket_iterator itg(ticket->get_lock()->m_granted);
@@ -1493,7 +1493,7 @@ void MDL_lock::Ticket_list::add_ticket(MDL_ticket *ticket)
14931493

14941494
while ((waiting= itw++) && !added)
14951495
{
1496-
if (!wsrep_thd_is_brute_force((void *)(waiting->get_ctx()->wsrep_get_thd())))
1496+
if (!wsrep_thd_is_BF((void *)(waiting->get_ctx()->get_thd()), true))
14971497
{
14981498
WSREP_DEBUG("MDL add_ticket inserted before: %lu %s",
14991499
wsrep_thd_thread_id(waiting->get_ctx()->wsrep_get_thd()),
@@ -1894,7 +1894,7 @@ MDL_lock::can_grant_lock(enum_mdl_type type_arg,
18941894
ticket->is_incompatible_when_granted(type_arg))
18951895
#ifdef WITH_WSREP
18961896
{
1897-
if (wsrep_thd_is_brute_force((void *)(requestor_ctx->wsrep_get_thd())) &&
1897+
if (wsrep_thd_is_BF((void *)(requestor_ctx->get_thd()), false) &&
18981898
key.mdl_namespace() == MDL_key::GLOBAL)
18991899
{
19001900
WSREP_DEBUG("global lock granted for BF: %lu %s",
@@ -1935,7 +1935,7 @@ MDL_lock::can_grant_lock(enum_mdl_type type_arg,
19351935
#ifdef WITH_WSREP
19361936
else
19371937
{
1938-
if (wsrep_thd_is_brute_force((void *)(requestor_ctx->wsrep_get_thd())) &&
1938+
if (wsrep_thd_is_BF((void *)(requestor_ctx->get_thd()), false) &&
19391939
key.mdl_namespace() == MDL_key::GLOBAL)
19401940
{
19411941
WSREP_DEBUG("global lock granted for BF (waiting queue): %lu %s",

sql/mysqld.cc

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,11 +2735,7 @@ static void network_init(void)
27352735
@note
27362736
For the connection that is doing shutdown, this is called twice
27372737
*/
2738-
#ifdef WITH_WSREP
2739-
void close_connection(THD *thd, uint sql_errno, bool lock)
2740-
#else
27412738
void close_connection(THD *thd, uint sql_errno)
2742-
#endif
27432739
{
27442740
DBUG_ENTER("close_connection");
27452741

@@ -2972,7 +2968,11 @@ bool one_thread_per_connection_end(THD *thd, bool put_in_cache)
29722968
unlink_thd(thd);
29732969
/* Mark that current_thd is not valid anymore */
29742970
set_current_thd(0);
2971+
#ifdef WITH_WSREP
2972+
if (put_in_cache && cache_thread() && !thd->wsrep_applier)
2973+
#else
29752974
if (put_in_cache && cache_thread())
2975+
#endif /* WITH_WSREP */
29762976
DBUG_RETURN(0); // Thread is reused
29772977

29782978
/*
@@ -5248,7 +5248,7 @@ pthread_handler_t start_wsrep_THD(void *arg)
52485248
thd->thr_create_utime= microsecond_interval_timer();
52495249
if (MYSQL_CALLBACK_ELSE(thread_scheduler, init_new_connection_thread, (), 0))
52505250
{
5251-
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
5251+
close_connection(thd, ER_OUT_OF_RESOURCES);
52525252
statistic_increment(aborted_connects,&LOCK_status);
52535253
MYSQL_CALLBACK(thread_scheduler, end_thread, (thd, 0));
52545254

@@ -5271,7 +5271,7 @@ pthread_handler_t start_wsrep_THD(void *arg)
52715271
thd->thread_stack= (char*) &thd;
52725272
if (thd->store_globals())
52735273
{
5274-
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
5274+
close_connection(thd, ER_OUT_OF_RESOURCES);
52755275
statistic_increment(aborted_connects,&LOCK_status);
52765276
MYSQL_CALLBACK(thread_scheduler, end_thread, (thd, 0));
52775277
delete thd;
@@ -5300,10 +5300,11 @@ pthread_handler_t start_wsrep_THD(void *arg)
53005300

53015301
processor(thd);
53025302

5303-
close_connection(thd, 0, 1);
5303+
close_connection(thd, 0);
53045304

53055305
mysql_mutex_lock(&LOCK_thread_count);
53065306
wsrep_running_threads--;
5307+
WSREP_DEBUG("wsrep running threads now: %lu", wsrep_running_threads);
53075308
mysql_cond_signal(&COND_thread_count);
53085309
mysql_mutex_unlock(&LOCK_thread_count);
53095310

@@ -5323,6 +5324,7 @@ pthread_handler_t start_wsrep_THD(void *arg)
53235324
// at server shutdown
53245325
}
53255326

5327+
my_thread_end();
53265328
if (thread_handling > SCHEDULER_ONE_THREAD_PER_CONNECTION)
53275329
{
53285330
mysql_mutex_lock(&LOCK_thread_count);
@@ -5409,23 +5411,6 @@ static bool have_client_connections()
54095411
return false;
54105412
}
54115413

5412-
/*
5413-
returns the number of wsrep appliers running.
5414-
However, the caller (thd parameter) is not taken in account
5415-
*/
5416-
static int have_wsrep_appliers(THD *thd)
5417-
{
5418-
int ret= 0;
5419-
THD *tmp;
5420-
5421-
I_List_iterator<THD> it(threads);
5422-
while ((tmp=it++))
5423-
{
5424-
ret+= (tmp != thd && tmp->wsrep_applier);
5425-
}
5426-
return ret;
5427-
}
5428-
54295414
static void wsrep_close_thread(THD *thd)
54305415
{
54315416
thd->killed= KILL_CONNECTION;
@@ -5536,7 +5521,7 @@ void wsrep_close_client_connections(my_bool wait_to_end)
55365521
!is_replaying_connection(tmp))
55375522
{
55385523
WSREP_INFO("killing local connection: %ld",tmp->thread_id);
5539-
close_connection(tmp,0,0);
5524+
close_connection(tmp,0);
55405525
}
55415526
#endif
55425527
}
@@ -5611,7 +5596,7 @@ void wsrep_wait_appliers_close(THD *thd)
56115596
{
56125597
/* Wait for wsrep appliers to gracefully exit */
56135598
mysql_mutex_lock(&LOCK_thread_count);
5614-
while (have_wsrep_appliers(thd) > 1)
5599+
while (wsrep_running_threads > 1)
56155600
// 1 is for rollbacker thread which needs to be killed explicitly.
56165601
// This gotta be fixed in a more elegant manner if we gonna have arbitrary
56175602
// number of non-applier wsrep threads.
@@ -5631,7 +5616,7 @@ void wsrep_wait_appliers_close(THD *thd)
56315616
wsrep_close_threads (thd);
56325617
/* and wait for them to die */
56335618
mysql_mutex_lock(&LOCK_thread_count);
5634-
while (have_wsrep_appliers(thd) > 0)
5619+
while (wsrep_running_threads > 0)
56355620
{
56365621
if (thread_handling > SCHEDULER_ONE_THREAD_PER_CONNECTION)
56375622
{
@@ -6630,11 +6615,7 @@ void create_thread_to_handle_connection(THD *thd)
66306615
my_snprintf(error_message_buff, sizeof(error_message_buff),
66316616
ER_THD(thd, ER_CANT_CREATE_THREAD), error);
66326617
net_send_error(thd, ER_CANT_CREATE_THREAD, error_message_buff, NULL);
6633-
#ifdef WITH_WSREP
6634-
close_connection(thd, ER_OUT_OF_RESOURCES ,0);
6635-
#else
66366618
close_connection(thd, ER_OUT_OF_RESOURCES);
6637-
#endif /* WITH_WSREP */
66386619

66396620
mysql_mutex_lock(&LOCK_thread_count);
66406621
thd->unlink();
@@ -6680,11 +6661,7 @@ static void create_new_thread(THD *thd)
66806661
mysql_mutex_unlock(&LOCK_connection_count);
66816662

66826663
DBUG_PRINT("error",("Too many connections"));
6683-
#ifdef WITH_WSREP
6684-
close_connection(thd, ER_CON_COUNT_ERROR, 1);
6685-
#else
66866664
close_connection(thd, ER_CON_COUNT_ERROR);
6687-
#endif /* WITH_WSREP */
66886665
statistic_increment(denied_connections, &LOCK_status);
66896666
delete thd;
66906667
statistic_increment(connection_errors_max_connection, &LOCK_status);
@@ -7095,11 +7072,7 @@ pthread_handler_t handle_connections_namedpipes(void *arg)
70957072
if (!(thd->net.vio= vio_new_win32pipe(hConnectedPipe)) ||
70967073
my_net_init(&thd->net, thd->net.vio, MYF(MY_THREAD_SPECIFIC)))
70977074
{
7098-
#ifdef WITH_WSREP
7099-
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
7100-
#else
71017075
close_connection(thd, ER_OUT_OF_RESOURCES);
7102-
#endif
71037076
delete thd;
71047077
set_current_thd(0);
71057078
continue;
@@ -7297,11 +7270,7 @@ pthread_handler_t handle_connections_shared_memory(void *arg)
72977270
event_conn_closed)) ||
72987271
my_net_init(&thd->net, thd->net.vio, MYF(MY_THREAD_SPECIFIC)))
72997272
{
7300-
#ifdef WITH_WSREP
7301-
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
7302-
#else
73037273
close_connection(thd, ER_OUT_OF_RESOURCES);
7304-
#endif
73057274
errmsg= 0;
73067275
goto errorconn;
73077276
}

sql/mysqld.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
5555
some places */
5656
/* Function prototypes */
5757
void kill_mysql(void);
58-
#ifdef WITH_WSREP
59-
void close_connection(THD *thd, uint sql_errno= 0, bool lock=1);
60-
#else
6158
void close_connection(THD *thd, uint sql_errno= 0);
62-
#endif /* WITH_WSREP */
6359
void handle_connection_in_main_thread(THD *thd);
6460
void create_thread_to_handle_connection(THD *thd);
6561
void delete_running_thd(THD *thd);

sql/sql_base.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8830,7 +8830,7 @@ bool mysql_notify_thread_having_shared_lock(THD *thd, THD *in_use,
88308830
#ifdef WITH_WSREP
88318831
{
88328832
signalled|= mysql_lock_abort_for_thread(thd, thd_table);
8833-
if (thd && WSREP(thd) && wsrep_thd_is_brute_force((void *)thd))
8833+
if (thd && WSREP(thd) && wsrep_thd_is_BF((void *)thd, true))
88348834
{
88358835
WSREP_DEBUG("remove_table_from_cache: %llu",
88368836
(unsigned long long) thd->real_id);

sql/sql_connect.cc

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,11 +1102,7 @@ bool setup_connection_thread_globals(THD *thd)
11021102
{
11031103
if (thd->store_globals())
11041104
{
1105-
#ifdef WITH_WSREP
1106-
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
1107-
#else
11081105
close_connection(thd, ER_OUT_OF_RESOURCES);
1109-
#endif
11101106
statistic_increment(aborted_connects,&LOCK_status);
11111107
MYSQL_CALLBACK(thd->scheduler, end_thread, (thd, 0));
11121108
return 1; // Error
@@ -1351,11 +1347,7 @@ void do_handle_one_connection(THD *thd_arg)
13511347

13521348
if (MYSQL_CALLBACK_ELSE(thd->scheduler, init_new_connection_thread, (), 0))
13531349
{
1354-
#ifdef WITH_WSREP
1355-
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
1356-
#else
13571350
close_connection(thd, ER_OUT_OF_RESOURCES);
1358-
#endif
13591351
statistic_increment(aborted_connects,&LOCK_status);
13601352
MYSQL_CALLBACK(thd->scheduler, end_thread, (thd, 0));
13611353
return;
@@ -1413,13 +1405,9 @@ void do_handle_one_connection(THD *thd_arg)
14131405
thd->wsrep_query_state= QUERY_EXITING;
14141406
mysql_mutex_unlock(&thd->LOCK_wsrep_thd);
14151407
}
1416-
#endif
1408+
#endif
14171409
end_thread:
1418-
#ifdef WITH_WSREP
1419-
close_connection(thd, 0, 1);
1420-
#else
14211410
close_connection(thd);
1422-
#endif
14231411

14241412
if (thd->userstat_running)
14251413
update_global_user_stats(thd, create_user, time(NULL));

sql/sql_parse.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -808,11 +808,7 @@ void do_handle_bootstrap(THD *thd)
808808
if (my_thread_init() || thd->store_globals())
809809
{
810810
#ifndef EMBEDDED_LIBRARY
811-
#ifdef WITH_WSREP
812-
close_connection(thd, ER_OUT_OF_RESOURCES, 1);
813-
#else
814811
close_connection(thd, ER_OUT_OF_RESOURCES);
815-
#endif /* WITH_WSREP */
816812
#endif
817813
thd->fatal_error();
818814
goto end;
@@ -7884,7 +7880,7 @@ kill_one_thread(THD *thd, longlong id, killed_state kill_signal, killed_type typ
78847880
#ifdef WITH_WSREP
78857881
if (((thd->security_ctx->master_access & SUPER_ACL) ||
78867882
thd->security_ctx->user_matches(tmp->security_ctx)) &&
7887-
!wsrep_thd_is_brute_force((void *)tmp))
7883+
!wsrep_thd_is_BF((void *)tmp, true))
78887884
#else
78897885
if ((thd->security_ctx->master_access & SUPER_ACL) ||
78907886
thd->security_ctx->user_matches(tmp->security_ctx))

sql/wsrep_mysqld.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ void wsrep_init_startup (bool first)
663663
{
664664
if (wsrep_init()) unireg_abort(1);
665665

666-
wsrep_thr_lock_init(wsrep_thd_is_brute_force, wsrep_abort_thd,
666+
wsrep_thr_lock_init(wsrep_thd_is_BF, wsrep_abort_thd,
667667
wsrep_debug, wsrep_convert_LOCK_to_trx, wsrep_on);
668668

669669
/* Skip replication start if no cluster address */
@@ -1370,6 +1370,13 @@ int wsrep_to_isolation_begin(THD *thd, char *db_, char *table_,
13701370
DBUG_ASSERT(thd->wsrep_exec_mode == LOCAL_STATE);
13711371
DBUG_ASSERT(thd->wsrep_trx_meta.gtid.seqno == WSREP_SEQNO_UNDEFINED);
13721372

1373+
if (thd->global_read_lock.can_acquire_protection())
1374+
{
1375+
WSREP_DEBUG("Aborting TOI: Global Read-Lock (FTWRL) in place: %s %lu",
1376+
thd->query(), thd->thread_id);
1377+
return -1;
1378+
}
1379+
13731380
if (wsrep_debug && thd->mdl_context.has_locks())
13741381
{
13751382
WSREP_DEBUG("thread holds MDL locks at TI begin: %s %lu",

0 commit comments

Comments
 (0)