1
- /* Copyright (C) 2015-2021 Codership Oy <info@codership.com>
1
+ /* Copyright (C) 2015-2022 Codership Oy <info@codership.com>
2
2
3
3
This program is free software; you can redistribute it and/or modify
4
4
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=
95
95
static const std::string create_allowlist_table_str=
96
96
" CREATE TABLE IF NOT EXISTS " + wsrep_schema_str + " ." + allowlist_table_str +
97
97
" ("
98
- " ip CHAR(64) NOT NULL,"
98
+ " ip CHAR(64) NOT NULL,"
99
99
" PRIMARY KEY (ip)"
100
100
" ) ENGINE=InnoDB STATS_PERSISTENT=0" ;
101
101
@@ -1518,14 +1518,62 @@ int Wsrep_schema::recover_sr_transactions(THD *orig_thd)
1518
1518
DBUG_RETURN (ret);
1519
1519
}
1520
1520
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
+
1521
1568
void Wsrep_schema::store_allowlist (std::vector<std::string>& ip_allowlist)
1522
1569
{
1523
1570
THD* thd= new THD (next_thread_id ());
1524
- if (!thd)
1571
+ if (!thd)
1525
1572
{
1526
1573
WSREP_ERROR (" Unable to get thd" );
1527
1574
return ;
1528
1575
}
1576
+ my_thread_init ();
1529
1577
thd->thread_stack = (char *)&thd;
1530
1578
wsrep_init_thd_for_schema (thd);
1531
1579
TABLE* allowlist_table= 0 ;
@@ -1541,7 +1589,7 @@ void Wsrep_schema::store_allowlist(std::vector<std::string>& ip_allowlist)
1541
1589
{
1542
1590
Wsrep_schema_impl::store (allowlist_table, 0 , ip_allowlist[i]);
1543
1591
if ((error= Wsrep_schema_impl::insert (allowlist_table)))
1544
- {
1592
+ {
1545
1593
if (error == HA_ERR_FOUND_DUPP_KEY)
1546
1594
{
1547
1595
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)
1556
1604
Wsrep_schema_impl::finish_stmt (thd);
1557
1605
out:
1558
1606
delete thd;
1607
+ my_thread_end ();
1559
1608
}
1560
1609
1561
1610
bool Wsrep_schema::allowlist_check (Wsrep_allowlist_key key,
@@ -1566,14 +1615,13 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
1566
1615
{
1567
1616
return true ;
1568
1617
}
1569
- my_thread_init ();
1570
1618
THD *thd = new THD (next_thread_id ());
1571
- if (!thd)
1619
+ if (!thd)
1572
1620
{
1573
- my_thread_end ();
1574
1621
WSREP_ERROR (" Unable to get thd" );
1575
1622
return false ;
1576
1623
}
1624
+ my_thread_init ();
1577
1625
thd->thread_stack = (char *)&thd;
1578
1626
int error;
1579
1627
TABLE *allowlist_table= 0 ;
@@ -1586,19 +1634,18 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
1586
1634
* Read allowlist table
1587
1635
*/
1588
1636
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 (),
1591
1639
&allowlist_table) ||
1592
- Wsrep_schema_impl::init_for_scan (allowlist_table))
1593
-
1640
+ Wsrep_schema_impl::init_for_scan (allowlist_table))
1594
1641
{
1595
1642
goto out;
1596
1643
}
1597
- while (true )
1644
+ while (true )
1598
1645
{
1599
- if ((error= Wsrep_schema_impl::next_record (allowlist_table)) == 0 )
1646
+ if ((error= Wsrep_schema_impl::next_record (allowlist_table)) == 0 )
1600
1647
{
1601
- if (Wsrep_schema_impl::scan (allowlist_table, 0 , row, sizeof (row)))
1648
+ if (Wsrep_schema_impl::scan (allowlist_table, 0 , row, sizeof (row)))
1602
1649
{
1603
1650
goto out;
1604
1651
}
@@ -1609,7 +1656,7 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
1609
1656
break ;
1610
1657
}
1611
1658
}
1612
- else if (error == HA_ERR_END_OF_FILE)
1659
+ else if (error == HA_ERR_END_OF_FILE)
1613
1660
{
1614
1661
if (!table_have_rows)
1615
1662
{
@@ -1619,12 +1666,12 @@ bool Wsrep_schema::allowlist_check(Wsrep_allowlist_key key,
1619
1666
}
1620
1667
break ;
1621
1668
}
1622
- else
1669
+ else
1623
1670
{
1624
1671
goto out;
1625
1672
}
1626
1673
}
1627
- if (Wsrep_schema_impl::end_scan (allowlist_table))
1674
+ if (Wsrep_schema_impl::end_scan (allowlist_table))
1628
1675
{
1629
1676
goto out;
1630
1677
}
0 commit comments