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-03-31 16:26:25 +0300
commite48fc858e8fb390336face9ed577d54ea66b1826 (patch)
tree3d359d42ef549102ef6d76ea500e80f27475c63a
parentc64f411324206466cab9770fdf6bf3e07e771451 (diff)
downloadmariadb-git-bb-10.9-MDEV-27246-galera-allowlist.tar.gz
MDEV-27263 Cluster bootstrap node shows duplicate wsrep allowlist IP warning messages on each restart.bb-10.9-MDEV-27246-galera-allowlist
We should clear `wsrep_allowlist` table on bootstrap before writing to it. Reviewed-by: Jan Lindström <jan.lindstrom@mariadb.com>
-rw-r--r--mysql-test/suite/galera/r/galera_defaults.result6
-rw-r--r--mysql-test/suite/galera/t/galera_defaults.test2
-rw-r--r--sql/wsrep_mysqld.cc3
-rw-r--r--sql/wsrep_schema.cc54
-rw-r--r--sql/wsrep_schema.h6
5 files changed, 62 insertions, 9 deletions
diff --git a/mysql-test/suite/galera/r/galera_defaults.result b/mysql-test/suite/galera/r/galera_defaults.result
index e32557f578e..ebcae5827c8 100644
--- a/mysql-test/suite/galera/r/galera_defaults.result
+++ b/mysql-test/suite/galera/r/galera_defaults.result
@@ -1,9 +1,9 @@
connection node_2;
connection node_1;
# Correct Galera library found
-SELECT COUNT(*) `expect 50` FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME LIKE 'wsrep_%';
-expect 50
-50
+SELECT COUNT(*) `expect 51` FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME LIKE 'wsrep_%';
+expect 51
+51
SELECT VARIABLE_NAME, VARIABLE_VALUE
FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
WHERE VARIABLE_NAME LIKE 'wsrep_%'
diff --git a/mysql-test/suite/galera/t/galera_defaults.test b/mysql-test/suite/galera/t/galera_defaults.test
index ff08151327a..6cb0cc1c634 100644
--- a/mysql-test/suite/galera/t/galera_defaults.test
+++ b/mysql-test/suite/galera/t/galera_defaults.test
@@ -16,6 +16,8 @@
--let $galera_version=26.4.11
source ../wsrep/include/check_galera_version.inc;
+SELECT COUNT(*) `expect 51` FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME LIKE 'wsrep_%';
+
# Global Variables
SELECT VARIABLE_NAME, VARIABLE_VALUE
diff --git a/sql/wsrep_mysqld.cc b/sql/wsrep_mysqld.cc
index d41229bad2b..5fd14e566a6 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 fbf33a4ca66..765832a48b7 100644
--- a/sql/wsrep_schema.cc
+++ b/sql/wsrep_schema.cc
@@ -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,15 +1518,61 @@ out:
DBUG_RETURN(ret);
}
-void Wsrep_schema::store_allowlist(std::vector<std::string>& ip_allowlist)
+void Wsrep_schema::clear_allowlist()
{
+ my_thread_init();
THD* thd= new THD(next_thread_id());
if (!thd)
{
WSREP_ERROR("Unable to get thd");
return;
}
+ 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;
+}
+
+void Wsrep_schema::store_allowlist(std::vector<std::string>& ip_allowlist)
+{
my_thread_init();
+ THD* thd= new THD(next_thread_id());
+ if (!thd)
+ {
+ WSREP_ERROR("Unable to get thd");
+ return;
+ }
thd->thread_stack= (char*)&thd;
wsrep_init_thd_for_schema(thd);
TABLE* allowlist_table= 0;
@@ -1557,7 +1603,6 @@ 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,
@@ -1568,13 +1613,13 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
{
return true;
}
+ my_thread_init();
THD *thd = new THD(next_thread_id());
if (!thd)
{
WSREP_ERROR("Unable to get thd");
return false;
}
- my_thread_init();
thd->thread_stack= (char*)&thd;
int error;
TABLE *allowlist_table= 0;
@@ -1632,6 +1677,5 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
(void)trans_commit(thd);
out:
delete thd;
- my_thread_end();
return match_found_or_empty;
}
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
*/