Skip to content

Commit 00ed736

Browse files
committed
Bug#32861777 USE HA_ACL_NOTIFY IN STANDARD SERVER - STEP 2/2
The handler ha_acl_notify method have only been used in MySQL Cluster server and is one of the remaining differences between standard MySQL server and MySQL Cluster server. One reason it has not already been integrated in standard server is that in preparation to the call of ha_acl_notify lists of users are copied which potentially could be an issue for big lists. And the copy did always occur even if no handler have implemented ha_acl_notify. This patch keeps original lists but introduces automatic conversion from LEX_CSTRING and LEX_USER to avoid explicit usage of these types in ndbcluster plugin when accessing the data stored in Acl_change_notification object. And now also calls ha_acl_notify from standard server, removing one differences with MySQL Cluster server. Change-Id: I2499af3e78094f216f0fd4dcd443b70337d50d3a
1 parent 39a1e38 commit 00ed736

File tree

3 files changed

+35
-53
lines changed

3 files changed

+35
-53
lines changed

sql/auth/acl_change_notification.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,46 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2424
#ifndef ACL_CHANGE_NOTIFICATION_INCLUDED
2525
#define ACL_CHANGE_NOTIFICATION_INCLUDED
2626

27-
#include "my_sqlcommand.h" // enum_sql_command
28-
#include "sql/table.h" // LEX_USER, LEX_CSTRING, List
29-
30-
class Rewrite_params; // forward declaration
27+
#include "my_sqlcommand.h" // enum_sql_command
28+
#include "sql/sql_rewrite.h" // User_params
29+
#include "sql/table.h" // LEX_USER, LEX_CSTRING, List
3130

3231
class Acl_change_notification {
3332
public:
33+
struct Priv : public std::string {
34+
Priv(const LEX_CSTRING &lex_priv)
35+
: std::string{lex_priv.str, lex_priv.length} {}
36+
};
3437
struct User {
3538
std::string name;
3639
std::string host;
3740
User(const LEX_USER &lex_user)
3841
: name(lex_user.user.str, lex_user.user.length),
3942
host(lex_user.host.str, lex_user.host.length) {}
4043
};
41-
42-
Acl_change_notification(class THD *thd, enum_sql_command op,
44+
Acl_change_notification(THD *thd, enum_sql_command op,
4345
const List<LEX_USER> *users,
44-
Rewrite_params *rewrite_params,
46+
std::set<LEX_USER *> *rewrite_params,
4547
const List<LEX_CSTRING> *dynamic_privs);
4648

4749
private:
48-
enum_sql_command operation;
49-
std::string db;
50-
std::vector<User> user_list;
51-
std::vector<std::string> dynamic_privilege_list;
52-
Rewrite_params *rewrite_params;
50+
const std::string db;
51+
const enum_sql_command operation;
52+
const List<LEX_USER> empty_users;
53+
const List<LEX_USER> &users;
54+
const User_params rewrite_user_params;
55+
const List<LEX_CSTRING> empty_dynamic_privs;
56+
const List<LEX_CSTRING> &dynamic_privs;
5357

5458
public:
5559
enum_sql_command get_operation() const { return operation; }
5660
const std::string &get_db() const { return db; }
57-
const std::vector<User> &get_user_list() const { return user_list; }
58-
const std::vector<std::string> &get_dynamic_privilege_list() const {
59-
return dynamic_privilege_list;
61+
auto &get_user_list() const { return users; }
62+
auto &get_dynamic_privilege_list() const { return dynamic_privs; }
63+
const User_params *get_rewrite_params() const {
64+
if (rewrite_user_params.users == nullptr) return nullptr;
65+
return &rewrite_user_params;
6066
}
61-
Rewrite_params *get_rewrite_params() const { return rewrite_params; }
6267
};
6368

6469
#endif

sql/auth/sql_user_table.cc

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -574,45 +574,22 @@ ulong get_access(TABLE *form, uint fieldnr, uint *next_field) {
574574
*/
575575
Acl_change_notification::Acl_change_notification(
576576
THD *thd, enum_sql_command op, const List<LEX_USER> *users,
577-
Rewrite_params *rewrite, const List<LEX_CSTRING> *dynamic_privs)
578-
: operation(op),
579-
db(thd->db().str, thd->db().length),
580-
rewrite_params(rewrite) {
581-
if (users) {
582-
/* Copy data out of List<LEX_USER> */
583-
user_list.reserve(users->size());
584-
for (const LEX_USER &lex_user : *users) {
585-
user_list.emplace_back(lex_user);
586-
}
587-
}
588-
if (dynamic_privs) {
589-
/* Copy data from dynamic_privs to dynamic_privilege_list */
590-
dynamic_privilege_list.reserve(dynamic_privs->elements);
591-
for (const LEX_CSTRING &priv : *dynamic_privs) {
592-
dynamic_privilege_list.emplace_back(priv.str, priv.length);
593-
}
594-
}
595-
}
596-
597-
void acl_notify_htons(
598-
THD *thd MY_ATTRIBUTE((unused)),
599-
enum_sql_command operation MY_ATTRIBUTE((unused)),
600-
const List<LEX_USER> *users MY_ATTRIBUTE((unused)),
601-
std::set<LEX_USER *> *rewrite_users MY_ATTRIBUTE((unused)),
602-
const List<LEX_CSTRING> *dynamic_privs MY_ATTRIBUTE((unused))) {
577+
std::set<LEX_USER *> *rewrite_users, const List<LEX_CSTRING> *dynamic_privs)
578+
: db{thd->db().str, thd->db().length},
579+
operation(op),
580+
users(users ? *users : empty_users),
581+
rewrite_user_params(rewrite_users),
582+
dynamic_privs(dynamic_privs ? *dynamic_privs : empty_dynamic_privs) {}
583+
584+
void acl_notify_htons(THD *thd, enum_sql_command operation,
585+
const List<LEX_USER> *users,
586+
std::set<LEX_USER *> *rewrite_users,
587+
const List<LEX_CSTRING> *dynamic_privs) {
603588
DBUG_TRACE;
604589
DBUG_PRINT("enter", ("db: %s query: '%s'", thd->db().str, thd->query().str));
605-
#ifdef WITH_NDBCLUSTER_STORAGE_ENGINE
606-
/*
607-
The Acl_change_notification is used only by the ndbcluster SE.
608-
So, instantiate it and send a notification only if the Server is
609-
built with ndbcluster SE.
610-
*/
611-
User_params rewrite_user_params(rewrite_users);
612-
User_params *rewrite = rewrite_users ? &rewrite_user_params : nullptr;
613-
Acl_change_notification notice(thd, operation, users, rewrite, dynamic_privs);
590+
Acl_change_notification notice(thd, operation, users, rewrite_users,
591+
dynamic_privs);
614592
ha_acl_notify(thd, &notice);
615-
#endif
616593
}
617594

618595
/**

storage/ndb/plugin/ndb_stored_grants.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static std::mutex local_granted_users_mutex;
5757
/* Utility functions */
5858

5959
bool op_grants_or_revokes_ndb_storage(ChangeNotice *notice) {
60-
for (const std::string &priv : notice->get_dynamic_privilege_list())
60+
for (const ChangeNotice::Priv priv : notice->get_dynamic_privilege_list())
6161
if (!native_strncasecmp(priv.c_str(), "NDB_STORED_USER", priv.length()))
6262
return true;
6363
return false;

0 commit comments

Comments
 (0)