-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PS-9148: Add caching of dictionary table for component_masking_functions (Old) #5275
base: 8.0
Are you sure you want to change the base?
Changes from all commits
bc9d38a
15cfaae
58517cf
d505232
bc4179b
6fd4883
4cf7652
848a99e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* Copyright (c) 2024 Percona LLC and/or its affiliates. All rights reserved. | ||
|
||
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 | ||
the Free Software Foundation; version 2 of the License. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software Foundation, | ||
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ | ||
|
||
#ifndef MASKING_FUNCTIONS_BOOKSHELF_HPP | ||
#define MASKING_FUNCTIONS_BOOKSHELF_HPP | ||
|
||
#include "masking_functions/bookshelf_fwd.hpp" | ||
|
||
#include <string> | ||
#include <string_view> | ||
#include <unordered_map> | ||
|
||
#include "masking_functions/dictionary_fwd.hpp" | ||
|
||
namespace masking_functions { | ||
|
||
class bookshelf { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
public: | ||
bookshelf(); | ||
bookshelf(const dictionary &) = delete; | ||
bookshelf(bookshelf &&) = delete; | ||
bookshelf &operator=(const bookshelf &) = delete; | ||
bookshelf &operator=(bookshelf &&) = delete; | ||
~bookshelf(); | ||
|
||
bool contains(const std::string &dictionary_name, | ||
const std::string &term) const noexcept; | ||
// returns empty std::string_view if no such dictionary exist | ||
std::string_view get_random( | ||
const std::string &dictionary_name) const noexcept; | ||
bool remove(const std::string &dictionary_name) noexcept; | ||
bool remove(const std::string &dictionary_name, | ||
const std::string &term) noexcept; | ||
bool insert(const std::string &dictionary_name, const std::string &term); | ||
|
||
private: | ||
// TODO: in c++20 change to method signatures to accept std::string_view | ||
// and container to std::unordered_map<std::string, dictionary_ptr, | ||
// transparent_string_like_hash, std::equal_to<>>. | ||
using dictionary_container = std::unordered_map<std::string, dictionary_ptr>; | ||
dictionary_container dictionaries_; | ||
}; | ||
|
||
} // namespace masking_functions | ||
|
||
#endif // MASKING_FUNCTIONS_BOOKSHELF_HPP |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* Copyright (c) 2024 Percona LLC and/or its affiliates. All rights reserved. | ||
|
||
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 | ||
the Free Software Foundation; version 2 of the License. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software Foundation, | ||
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ | ||
|
||
#ifndef MASKING_FUNCTIONS_BOOKSHELF_FWD_HPP | ||
#define MASKING_FUNCTIONS_BOOKSHELF_FWD_HPP | ||
|
||
#include <memory> | ||
|
||
namespace masking_functions { | ||
|
||
class bookshelf; | ||
|
||
using bookshelf_ptr = std::unique_ptr<bookshelf>; | ||
|
||
} // namespace masking_functions | ||
|
||
#endif // MASKING_FUNCTIONS_BOOKSHELF_HPP |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* Copyright (c) 2023 Percona LLC and/or its affiliates. All rights reserved. | ||
|
||
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 | ||
the Free Software Foundation; version 2 of the License. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software Foundation, | ||
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ | ||
|
||
#ifndef MASKING_FUNCTIONS_COMPONENT_SYS_VARIABLE_SERVICE_TUPLE_HPP | ||
#define MASKING_FUNCTIONS_COMPONENT_SYS_VARIABLE_SERVICE_TUPLE_HPP | ||
|
||
#include <mysql/components/service.h> | ||
|
||
#include <mysql/components/services/component_sys_var_service.h> | ||
|
||
#include "masking_functions/component_sys_variable_service_tuple_fwd.hpp" | ||
|
||
namespace masking_functions { | ||
|
||
// A set of MySQL query services required to perform system variable | ||
// registration / unregistration. | ||
// It is recommended to be used in a combination with the | ||
// 'primitive_singleton' class template. | ||
// | ||
// primitive_singleton<component_sys_variable_service_tuple>::instance() = | ||
// component_sys_variable_service_tuple{ | ||
// component_sys_variable_register, | ||
// component_sys_variable_unregister | ||
// }; | ||
// ... | ||
// sql_context | ||
// ctx{primitive_singleton<component_sys_variable_service_tuple>::instance()}; | ||
struct component_sys_variable_service_tuple { | ||
SERVICE_TYPE(component_sys_variable_register) * registrator; | ||
SERVICE_TYPE(component_sys_variable_unregister) * unregistrator; | ||
}; | ||
|
||
} // namespace masking_functions | ||
|
||
#endif // MASKING_FUNCTIONS_COMPONENT_SYS_VARIABLE_SERVICE_TUPLE_HPP |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* Copyright (c) 2023 Percona LLC and/or its affiliates. All rights reserved. | ||
|
||
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 | ||
the Free Software Foundation; version 2 of the License. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software Foundation, | ||
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ | ||
|
||
#ifndef MASKING_FUNCTIONS_COMPONENT_SYS_VARIABLE_SERVICE_TUPLE_FWD_HPP | ||
#define MASKING_FUNCTIONS_COMPONENT_SYS_VARIABLE_SERVICE_TUPLE_FWD_HPP | ||
|
||
namespace masking_functions { | ||
|
||
struct component_sys_variable_service_tuple; | ||
|
||
} // namespace masking_functions | ||
|
||
#endif // MASKING_FUNCTIONS_COMPONENT_SYS_VARIABLE_SERVICE_TUPLE_FWD_HPP |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* Copyright (c) 2024 Percona LLC and/or its affiliates. All rights reserved. | ||
|
||
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 | ||
the Free Software Foundation; version 2 of the License. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software Foundation, | ||
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ | ||
|
||
#ifndef MASKING_FUNCTIONS_DICTIONARY_HPP | ||
#define MASKING_FUNCTIONS_DICTIONARY_HPP | ||
|
||
#include "masking_functions/dictionary_fwd.hpp" | ||
|
||
#include <string> | ||
#include <string_view> | ||
#include <unordered_set> | ||
|
||
namespace masking_functions { | ||
|
||
class dictionary { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
public: | ||
// a convenience constructor that creates a dictionary with one term | ||
explicit dictionary(const std::string &term); | ||
|
||
dictionary(const dictionary &) = delete; | ||
dictionary(dictionary &&) = delete; | ||
dictionary &operator=(const dictionary &) = delete; | ||
dictionary &operator=(dictionary &&) = delete; | ||
|
||
~dictionary() = default; | ||
|
||
bool is_empty() const noexcept { return terms_.empty(); } | ||
|
||
bool contains(const std::string &term) const noexcept; | ||
// returns empty std::string_view if the dictionary is empty | ||
std::string_view get_random() const noexcept; | ||
bool insert(const std::string &term); | ||
bool remove(const std::string &term) noexcept; | ||
|
||
private: | ||
// TODO: in c++20 change to method signatures to accept std::string_view | ||
// and container to std::unordered_set<std::string, | ||
// transparent_string_like_hash, std::equal_to<>>. | ||
using term_container = std::unordered_set<std::string>; | ||
term_container terms_; | ||
}; | ||
|
||
} // namespace masking_functions | ||
|
||
#endif // MASKING_FUNCTIONS_DICTIONARY_HPP |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* Copyright (c) 2024 Percona LLC and/or its affiliates. All rights reserved. | ||
|
||
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 | ||
the Free Software Foundation; version 2 of the License. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software Foundation, | ||
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ | ||
|
||
#ifndef MASKING_FUNCTIONS_DICTIONARY_FWD_HPP | ||
#define MASKING_FUNCTIONS_DICTIONARY_FWD_HPP | ||
|
||
#include <memory> | ||
|
||
namespace masking_functions { | ||
|
||
class dictionary; | ||
|
||
using dictionary_ptr = std::unique_ptr<dictionary>; | ||
|
||
} // namespace masking_functions | ||
|
||
#endif // MASKING_FUNCTIONS_DICTIONARY_FWD_HPP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class
bookshelf
defines a copy assignment operator, a move constructor and a move assignment operator but does not define a destructor or a copy constructor