MySQL 9.5.0
Source Code Documentation
accounts_cleaner.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2025, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef _ROUTER_ACCOUNTS_CLEANER_H_
27#define _ROUTER_ACCOUNTS_CLEANER_H_
28
32
33namespace mysqlrouter {
34
36 public:
37 MySQLAccountsCleaner(std::ostream &err_stream) : err_stream_(err_stream) {}
38
39 ~MySQLAccountsCleaner() { undo_create_user_for_new_accounts(); }
40
42 enum { kNotSet = 1, kAllAccounts, kNewAccounts } type = kNotSet;
43 std::string accounts;
44
45 void clear() {
46 type = kNotSet;
47 accounts = "";
48 }
49 };
50
51 std::string make_account_list(const std::string username,
52 const std::set<std::string> &hostnames);
53
54 void set_session(MySQLSession *session) { session_ = session; }
55
57 const UndoCreateAccountList &account_list) {
58 tmp_undo_create_account_list_ = account_list;
59 }
60
62 tmp_undo_create_account_list_.clear();
63 undo_create_account_list_.push_back(account_list);
64 }
65
66 void clear() {
67 tmp_undo_create_account_list_.clear();
68 undo_create_account_list_.clear();
69 }
70
71 /** @brief Deletes Router accounts just created
72 *
73 * This method runs as a cleanup after something goes wrong. Its purpose is
74 * to undo CREATE USER [IF NOT EXISTS] for accounts that got created during
75 * bootstrap. Note that it will drop only those accounts which did not exist
76 * prior to bootstrap (it may be a subset of account names passed to
77 * CREATE USER [IF NOT EXISTS]). If it is not able to determine what this
78 * (sub)set is, it will not drop anything - instead it will advise user on
79 * how to clean those up manually.
80 */
81 void undo_create_user_for_new_accounts() noexcept;
82
83 private:
84 MySQLSession *session_{nullptr};
85 std::ostream &err_stream_;
87 std::vector<UndoCreateAccountList> undo_create_account_list_;
88};
89
90} // namespace mysqlrouter
91
92#endif
Definition: accounts_cleaner.h:35
std::vector< UndoCreateAccountList > undo_create_account_list_
Definition: accounts_cleaner.h:87
UndoCreateAccountList tmp_undo_create_account_list_
Definition: accounts_cleaner.h:86
void clear()
Definition: accounts_cleaner.h:66
void register_tmp_undo_account_list(const UndoCreateAccountList &account_list)
Definition: accounts_cleaner.h:56
void set_session(MySQLSession *session)
Definition: accounts_cleaner.h:54
std::ostream & err_stream_
Definition: accounts_cleaner.h:85
MySQLAccountsCleaner(std::ostream &err_stream)
Definition: accounts_cleaner.h:37
~MySQLAccountsCleaner()
Definition: accounts_cleaner.h:39
void register_undo_account_list(const UndoCreateAccountList &account_list)
Definition: accounts_cleaner.h:61
Definition: mysql_session.h:157
Definition: base64.h:43
required string type
Definition: replication_group_member_actions.proto:34
#define ROUTER_MYSQL_EXPORT
Definition: router_mysql_export.h:15
@ kAllAccounts
Definition: accounts_cleaner.h:42
std::string accounts
Definition: accounts_cleaner.h:43
void clear()
Definition: accounts_cleaner.h:45