Skip to content

Commit 7864d95

Browse files
author
Jan Lindström
committed
Fixed regression on SST tests. We incorrectly used my_thread_end(), which
sets mysys_var pointer to NULL, so the next THD::THD will crash. Removed my_thread_init()/end() pairs and because Wsrep_allowlist_service::allowlist_cb is not always called from a new thread added a thread to do so. Fix co-authored by Sergei Golubchik <serg@mariadb.org> and mkaruza <mario.karuza@galeracluster.com> Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
1 parent 15783d7 commit 7864d95

File tree

2 files changed

+54
-27
lines changed

2 files changed

+54
-27
lines changed

sql/wsrep_allowlist_service.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ bool Wsrep_allowlist_service::allowlist_cb (
3636
WSREP_NOEXCEPT
3737
{
3838
std::string string_value(value.data());
39-
return (wsrep_schema->allowlist_check(key, string_value));
39+
bool res= wsrep_schema->allowlist_check(key, string_value);
40+
return res;
4041
}
4142

4243
std::unique_ptr<wsrep::allowlist_service> entrypoint;

sql/wsrep_schema.cc

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ void Wsrep_schema::clear_allowlist()
15261526
WSREP_ERROR("Unable to get thd");
15271527
return;
15281528
}
1529-
my_thread_init();
1529+
15301530
thd->thread_stack= (char*)&thd;
15311531
wsrep_init_thd_for_schema(thd);
15321532
TABLE* allowlist_table= 0;
@@ -1562,7 +1562,6 @@ void Wsrep_schema::clear_allowlist()
15621562
Wsrep_schema_impl::finish_stmt(thd);
15631563
out:
15641564
delete thd;
1565-
my_thread_end();
15661565
}
15671566

15681567
void Wsrep_schema::store_allowlist(std::vector<std::string>& ip_allowlist)
@@ -1573,7 +1572,7 @@ void Wsrep_schema::store_allowlist(std::vector<std::string>& ip_allowlist)
15731572
WSREP_ERROR("Unable to get thd");
15741573
return;
15751574
}
1576-
my_thread_init();
1575+
15771576
thd->thread_stack= (char*)&thd;
15781577
wsrep_init_thd_for_schema(thd);
15791578
TABLE* allowlist_table= 0;
@@ -1604,38 +1603,41 @@ void Wsrep_schema::store_allowlist(std::vector<std::string>& ip_allowlist)
16041603
Wsrep_schema_impl::finish_stmt(thd);
16051604
out:
16061605
delete thd;
1607-
my_thread_end();
16081606
}
16091607

1610-
bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
1611-
const std::string& value)
1608+
typedef struct Allowlist_check_arg
16121609
{
1613-
// We don't have wsrep schema initialized at this point
1614-
if (wsrep_schema_ready == false)
1610+
Allowlist_check_arg(const std::string& value)
1611+
: value(value)
1612+
, response(false)
16151613
{
1616-
return true;
1617-
}
1618-
THD *thd = new THD(next_thread_id());
1619-
if (!thd)
1620-
{
1621-
WSREP_ERROR("Unable to get thd");
1622-
return false;
16231614
}
1615+
std::string value;
1616+
bool response;
1617+
} Allowlist_check_arg;
1618+
1619+
static void *allowlist_check_thread(void *param)
1620+
{
1621+
Allowlist_check_arg *arg= (Allowlist_check_arg *) param;
1622+
16241623
my_thread_init();
1625-
thd->thread_stack= (char*)&thd;
1624+
THD thd(0);
1625+
thd.thread_stack= (char *) &thd;
1626+
wsrep_init_thd_for_schema(&thd);
1627+
16261628
int error;
16271629
TABLE *allowlist_table= 0;
16281630
bool match_found_or_empty= false;
16291631
bool table_have_rows= false;
1630-
char row[64]= { 0, };
1631-
wsrep_init_thd_for_schema(thd);
1632+
char row[64]= {
1633+
0,
1634+
};
16321635

16331636
/*
16341637
* Read allowlist table
16351638
*/
1636-
Wsrep_schema_impl::init_stmt(thd);
1637-
if (Wsrep_schema_impl::open_for_read(thd,
1638-
allowlist_table_str.c_str(),
1639+
Wsrep_schema_impl::init_stmt(&thd);
1640+
if (Wsrep_schema_impl::open_for_read(&thd, allowlist_table_str.c_str(),
16391641
&allowlist_table) ||
16401642
Wsrep_schema_impl::init_for_scan(allowlist_table))
16411643
{
@@ -1650,7 +1652,7 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
16501652
goto out;
16511653
}
16521654
table_have_rows= true;
1653-
if (!value.compare(row))
1655+
if (!arg->value.compare(row))
16541656
{
16551657
match_found_or_empty= true;
16561658
break;
@@ -1675,10 +1677,34 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
16751677
{
16761678
goto out;
16771679
}
1678-
Wsrep_schema_impl::finish_stmt(thd);
1679-
(void)trans_commit(thd);
1680+
Wsrep_schema_impl::finish_stmt(&thd);
1681+
(void) trans_commit(&thd);
16801682
out:
1681-
delete thd;
16821683
my_thread_end();
1683-
return match_found_or_empty;
1684+
arg->response = match_found_or_empty;
1685+
return 0;
1686+
}
1687+
1688+
bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
1689+
const std::string &value)
1690+
{
1691+
// We don't have wsrep schema initialized at this point
1692+
if (wsrep_schema_ready == false)
1693+
{
1694+
return true;
1695+
}
1696+
pthread_t allowlist_check_thd;
1697+
int ret;
1698+
Allowlist_check_arg arg(value);
1699+
ret= mysql_thread_create(0, /* Not instrumented */
1700+
&allowlist_check_thd, NULL,
1701+
allowlist_check_thread, &arg);
1702+
if (ret)
1703+
{
1704+
WSREP_ERROR("allowlist_check(): mysql_thread_create() failed: %d (%s)",
1705+
ret, strerror(ret));
1706+
return false;
1707+
}
1708+
pthread_join(allowlist_check_thd, NULL);
1709+
return arg.response;
16841710
}

0 commit comments

Comments
 (0)