Skip to content

Commit 7fdc993

Browse files
mkaruzaJan Lindström
authored andcommitted
MDEV-27263 Cluster bootstrap node shows duplicate wsrep allowlist IP warning messages on each restart.
We should clear `wsrep_allowlist` table on bootstrap before writing to it. Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
1 parent 9743d00 commit 7fdc993

File tree

3 files changed

+72
-18
lines changed

3 files changed

+72
-18
lines changed

sql/wsrep_mysqld.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,10 @@ void wsrep_init_schema()
456456
unireg_abort(1);
457457
}
458458
// If we are bootstraping new cluster we should
459-
// populate allowlist from variable
459+
// clear allowlist table and populate it from variable
460460
if (wsrep_new_cluster)
461461
{
462+
wsrep_schema->clear_allowlist();
462463
std::vector<std::string> ip_allowlist;
463464
if (wsrep_split_allowlist(ip_allowlist))
464465
{

sql/wsrep_schema.cc

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2015-2021 Codership Oy <info@codership.com>
1+
/* Copyright (C) 2015-2022 Codership Oy <info@codership.com>
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -95,7 +95,7 @@ static const std::string create_frag_table_str=
9595
static const std::string create_allowlist_table_str=
9696
"CREATE TABLE IF NOT EXISTS " + wsrep_schema_str + "." + allowlist_table_str +
9797
"("
98-
"ip CHAR(64) NOT NULL,"
98+
"ip CHAR(64) NOT NULL,"
9999
"PRIMARY KEY (ip)"
100100
") ENGINE=InnoDB STATS_PERSISTENT=0";
101101

@@ -1518,14 +1518,62 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd)
15181518
DBUG_RETURN(ret);
15191519
}
15201520

1521+
void Wsrep_schema::clear_allowlist()
1522+
{
1523+
THD* thd= new THD(next_thread_id());
1524+
if (!thd)
1525+
{
1526+
WSREP_ERROR("Unable to get thd");
1527+
return;
1528+
}
1529+
my_thread_init();
1530+
thd->thread_stack= (char*)&thd;
1531+
wsrep_init_thd_for_schema(thd);
1532+
TABLE* allowlist_table= 0;
1533+
int error= 0;
1534+
1535+
Wsrep_schema_impl::init_stmt(thd);
1536+
1537+
if (Wsrep_schema_impl::open_for_write(thd, allowlist_table_str.c_str(),
1538+
&allowlist_table) ||
1539+
Wsrep_schema_impl::init_for_scan(allowlist_table))
1540+
{
1541+
WSREP_ERROR("Failed to open mysql.wsrep_allowlist table");
1542+
goto out;
1543+
}
1544+
1545+
while (0 == error)
1546+
{
1547+
if ((error= Wsrep_schema_impl::next_record(allowlist_table)) == 0)
1548+
{
1549+
Wsrep_schema_impl::delete_row(allowlist_table);
1550+
}
1551+
else if (error == HA_ERR_END_OF_FILE)
1552+
{
1553+
continue;
1554+
}
1555+
else
1556+
{
1557+
WSREP_ERROR("Allowlist table scan returned error %d", error);
1558+
}
1559+
}
1560+
1561+
Wsrep_schema_impl::end_scan(allowlist_table);
1562+
Wsrep_schema_impl::finish_stmt(thd);
1563+
out:
1564+
delete thd;
1565+
my_thread_end();
1566+
}
1567+
15211568
void Wsrep_schema::store_allowlist(std::vector<std::string>& ip_allowlist)
15221569
{
15231570
THD* thd= new THD(next_thread_id());
1524-
if (!thd)
1571+
if (!thd)
15251572
{
15261573
WSREP_ERROR("Unable to get thd");
15271574
return;
15281575
}
1576+
my_thread_init();
15291577
thd->thread_stack= (char*)&thd;
15301578
wsrep_init_thd_for_schema(thd);
15311579
TABLE* allowlist_table= 0;
@@ -1541,7 +1589,7 @@ void Wsrep_schema::store_allowlist(std::vector<std::string>& ip_allowlist)
15411589
{
15421590
Wsrep_schema_impl::store(allowlist_table, 0, ip_allowlist[i]);
15431591
if ((error= Wsrep_schema_impl::insert(allowlist_table)))
1544-
{
1592+
{
15451593
if (error == HA_ERR_FOUND_DUPP_KEY)
15461594
{
15471595
WSREP_WARN("Duplicate entry (%s) found in `wsrep_allowlist` list", ip_allowlist[i].c_str());
@@ -1556,6 +1604,7 @@ void Wsrep_schema::store_allowlist(std::vector<std::string>& ip_allowlist)
15561604
Wsrep_schema_impl::finish_stmt(thd);
15571605
out:
15581606
delete thd;
1607+
my_thread_end();
15591608
}
15601609

15611610
bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
@@ -1566,14 +1615,13 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
15661615
{
15671616
return true;
15681617
}
1569-
my_thread_init();
15701618
THD *thd = new THD(next_thread_id());
1571-
if (!thd)
1619+
if (!thd)
15721620
{
1573-
my_thread_end();
15741621
WSREP_ERROR("Unable to get thd");
15751622
return false;
15761623
}
1624+
my_thread_init();
15771625
thd->thread_stack= (char*)&thd;
15781626
int error;
15791627
TABLE *allowlist_table= 0;
@@ -1586,19 +1634,18 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
15861634
* Read allowlist table
15871635
*/
15881636
Wsrep_schema_impl::init_stmt(thd);
1589-
if (Wsrep_schema_impl::open_for_read(thd,
1590-
allowlist_table_str.c_str(),
1637+
if (Wsrep_schema_impl::open_for_read(thd,
1638+
allowlist_table_str.c_str(),
15911639
&allowlist_table) ||
1592-
Wsrep_schema_impl::init_for_scan(allowlist_table))
1593-
1640+
Wsrep_schema_impl::init_for_scan(allowlist_table))
15941641
{
15951642
goto out;
15961643
}
1597-
while (true)
1644+
while (true)
15981645
{
1599-
if ((error= Wsrep_schema_impl::next_record(allowlist_table)) == 0)
1646+
if ((error= Wsrep_schema_impl::next_record(allowlist_table)) == 0)
16001647
{
1601-
if (Wsrep_schema_impl::scan(allowlist_table, 0, row, sizeof(row)))
1648+
if (Wsrep_schema_impl::scan(allowlist_table, 0, row, sizeof(row)))
16021649
{
16031650
goto out;
16041651
}
@@ -1609,7 +1656,7 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
16091656
break;
16101657
}
16111658
}
1612-
else if (error == HA_ERR_END_OF_FILE)
1659+
else if (error == HA_ERR_END_OF_FILE)
16131660
{
16141661
if (!table_have_rows)
16151662
{
@@ -1619,12 +1666,12 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
16191666
}
16201667
break;
16211668
}
1622-
else
1669+
else
16231670
{
16241671
goto out;
16251672
}
16261673
}
1627-
if (Wsrep_schema_impl::end_scan(allowlist_table))
1674+
if (Wsrep_schema_impl::end_scan(allowlist_table))
16281675
{
16291676
goto out;
16301677
}

sql/wsrep_schema.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ class Wsrep_schema
133133
*/
134134
int recover_sr_transactions(THD* orig_thd);
135135

136+
137+
/**
138+
Delete all rows on bootstrap from `wsrep_allowlist` variable
139+
*/
140+
void clear_allowlist();
141+
136142
/**
137143
Store allowlist ip on bootstrap from `wsrep_allowlist` variable
138144
*/

0 commit comments

Comments
 (0)