summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormkaruza <mario.karuza@galeracluster.com>2021-12-16 09:39:26 +0100
committerJan Lindström <jan.lindstrom@mariadb.com>2022-08-02 17:24:28 +0300
commit7fdc993ec6bb39a99b3b9af604e38a253ae76c96 (patch)
tree9154292af7149888d30de7d1c29ffca8a1926547
parent9743d0043e8fc248043e2d98e7fa4197557ac59d (diff)
downloadmariadb-git-7fdc993ec6bb39a99b3b9af604e38a253ae76c96.tar.gz
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>
-rw-r--r--sql/wsrep_mysqld.cc3
-rw-r--r--sql/wsrep_schema.cc81
-rw-r--r--sql/wsrep_schema.h6
3 files changed, 72 insertions, 18 deletions
diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc
index af41e150256..caea02c38f3 100644
--- a/sql/wsrep_mysqld.cc
+++ b/sql/wsrep_mysqld.cc
@@ -456,9 +456,10 @@ void wsrep_init_schema()
unireg_abort(1);
}
// If we are bootstraping new cluster we should
- // populate allowlist from variable
+ // clear allowlist table and populate it from variable
if (wsrep_new_cluster)
{
+ wsrep_schema->clear_allowlist();
std::vector<std::string> ip_allowlist;
if (wsrep_split_allowlist(ip_allowlist))
{
diff --git a/sql/wsrep_schema.cc b/sql/wsrep_schema.cc
index e62fbd788f4..0f32f5994c0 100644
--- a/sql/wsrep_schema.cc
+++ b/sql/wsrep_schema.cc
@@ -1,4 +1,4 @@
-/* Copyright (C) 2015-2021 Codership Oy <info@codership.com>
+/* Copyright (C) 2015-2022 Codership Oy <info@codership.com>
This program is free software; you can redistribute it and/or modify
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=
static const std::string create_allowlist_table_str=
"CREATE TABLE IF NOT EXISTS " + wsrep_schema_str + "." + allowlist_table_str +
"("
- "ip CHAR(64) NOT NULL,"
+ "ip CHAR(64) NOT NULL,"
"PRIMARY KEY (ip)"
") ENGINE=InnoDB STATS_PERSISTENT=0";
@@ -1518,14 +1518,62 @@ out:
DBUG_RETURN(ret);
}
+void Wsrep_schema::clear_allowlist()
+{
+ THD* thd= new THD(next_thread_id());
+ if (!thd)
+ {
+ WSREP_ERROR("Unable to get thd");
+ return;
+ }
+ my_thread_init();
+ thd->thread_stack= (char*)&thd;
+ wsrep_init_thd_for_schema(thd);
+ TABLE* allowlist_table= 0;
+ int error= 0;
+
+ Wsrep_schema_impl::init_stmt(thd);
+
+ if (Wsrep_schema_impl::open_for_write(thd, allowlist_table_str.c_str(),
+ &allowlist_table) ||
+ Wsrep_schema_impl::init_for_scan(allowlist_table))
+ {
+ WSREP_ERROR("Failed to open mysql.wsrep_allowlist table");
+ goto out;
+ }
+
+ while (0 == error)
+ {
+ if ((error= Wsrep_schema_impl::next_record(allowlist_table)) == 0)
+ {
+ Wsrep_schema_impl::delete_row(allowlist_table);
+ }
+ else if (error == HA_ERR_END_OF_FILE)
+ {
+ continue;
+ }
+ else
+ {
+ WSREP_ERROR("Allowlist table scan returned error %d", error);
+ }
+ }
+
+ Wsrep_schema_impl::end_scan(allowlist_table);
+ Wsrep_schema_impl::finish_stmt(thd);
+out:
+ delete thd;
+ my_thread_end();
+}
+
void Wsrep_schema::store_allowlist(std::vector<std::string>& ip_allowlist)
{
THD* thd= new THD(next_thread_id());
- if (!thd)
+ if (!thd)
{
WSREP_ERROR("Unable to get thd");
return;
}
+ my_thread_init();
thd->thread_stack= (char*)&thd;
wsrep_init_thd_for_schema(thd);
TABLE* allowlist_table= 0;
@@ -1541,7 +1589,7 @@ void Wsrep_schema::store_allowlist(std::vector<std::string>& ip_allowlist)
{
Wsrep_schema_impl::store(allowlist_table, 0, ip_allowlist[i]);
if ((error= Wsrep_schema_impl::insert(allowlist_table)))
- {
+ {
if (error == HA_ERR_FOUND_DUPP_KEY)
{
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)
Wsrep_schema_impl::finish_stmt(thd);
out:
delete thd;
+ my_thread_end();
}
bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
@@ -1566,14 +1615,13 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
{
return true;
}
- my_thread_init();
THD *thd = new THD(next_thread_id());
- if (!thd)
+ if (!thd)
{
- my_thread_end();
WSREP_ERROR("Unable to get thd");
return false;
}
+ my_thread_init();
thd->thread_stack= (char*)&thd;
int error;
TABLE *allowlist_table= 0;
@@ -1586,19 +1634,18 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
* Read allowlist table
*/
Wsrep_schema_impl::init_stmt(thd);
- if (Wsrep_schema_impl::open_for_read(thd,
- allowlist_table_str.c_str(),
+ if (Wsrep_schema_impl::open_for_read(thd,
+ allowlist_table_str.c_str(),
&allowlist_table) ||
- Wsrep_schema_impl::init_for_scan(allowlist_table))
-
+ Wsrep_schema_impl::init_for_scan(allowlist_table))
{
goto out;
}
- while (true)
+ while (true)
{
- if ((error= Wsrep_schema_impl::next_record(allowlist_table)) == 0)
+ if ((error= Wsrep_schema_impl::next_record(allowlist_table)) == 0)
{
- if (Wsrep_schema_impl::scan(allowlist_table, 0, row, sizeof(row)))
+ if (Wsrep_schema_impl::scan(allowlist_table, 0, row, sizeof(row)))
{
goto out;
}
@@ -1609,7 +1656,7 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
break;
}
}
- else if (error == HA_ERR_END_OF_FILE)
+ else if (error == HA_ERR_END_OF_FILE)
{
if (!table_have_rows)
{
@@ -1619,12 +1666,12 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
}
break;
}
- else
+ else
{
goto out;
}
}
- if (Wsrep_schema_impl::end_scan(allowlist_table))
+ if (Wsrep_schema_impl::end_scan(allowlist_table))
{
goto out;
}
diff --git a/sql/wsrep_schema.h b/sql/wsrep_schema.h
index 943fe8759c0..05522e77089 100644
--- a/sql/wsrep_schema.h
+++ b/sql/wsrep_schema.h
@@ -133,6 +133,12 @@ class Wsrep_schema
*/
int recover_sr_transactions(THD* orig_thd);
+
+ /**
+ Delete all rows on bootstrap from `wsrep_allowlist` variable
+ */
+ void clear_allowlist();
+
/**
Store allowlist ip on bootstrap from `wsrep_allowlist` variable
*/