Skip to content

Commit d09a9a9

Browse files
authored
PS-9181 [DOCS] - document background dictionary cache reload functionality in the Masking Functions component 8.0 (#440)
modified: docs/data-masking-function-list.md modified: docs/data-masking-overview.md
1 parent e36e32b commit d09a9a9

File tree

2 files changed

+127
-11
lines changed

2 files changed

+127
-11
lines changed

docs/data-masking-function-list.md

+96-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-
# Data masking component functions
1+
# Data masking component functions and variables
22

33
The feature is in [tech preview](glossary.md#tech-preview).
44

5-
| **Name** | **Usage** |
5+
## Permissions
6+
7+
In Percona Server for MySQL 8.0.41, dictionary-related functions no longer run internal queries as the root user without a password. Following MySQL best practices, many admins disable the `root` user, which previously caused these functions to stop working. The server now uses the built-in `mysql.session` user to execute dictionary queries.
8+
9+
However, for this to work, you need to grant the mysql.session user `SELECT`, `INSERT`, `UPDATE`, and `DELETE` privileges on the `masking_dictionaries` table.
10+
11+
```{.bash data-prompt="mysql>"}
12+
mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON mysql.masking_dictionaries TO 'mysql.session'@'localhost';
13+
```
14+
15+
If you change the value of the `masking_functions.masking_database` system variable to something other than `mysql`, make sure to update the `GRANT` query to match the new value.
16+
17+
```{.bash data-prompt="mysql>"}
18+
mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON <masking_functions.masking_database>.masking_dictionaries TO 'mysql.session'@'localhost';
19+
```
20+
21+
## Data masking component functions
22+
23+
| **Name** | **Details** |
624
|---------------------------------------------------|-------------------------------------------------------|
725
| [`gen_blocklist(str, from_dictionary_name, to_dictionary_name)`](#gen_blockliststr-from_dictionary_name-to_dictionary_name) | Replace a term from a dictionary |
826
| [`gen_dictionary(dictionary_name)`](#gen_dictionarydictionary_name) | Returns a random term from a dictionary |
@@ -24,14 +42,20 @@ The feature is in [tech preview](glossary.md#tech-preview).
2442
| [`mask_ssn(str [,mask_char])`](#mask_ssnstr-mask_char) | Masks the US Social Security number |
2543
| [`mask_uk_nin(str [,mask_char])`](#mask_uk_ninstr-mask_char) | Masks the United Kingdom National Insurance number |
2644
| [`mask_uuid(str [,mask_char])`](#mask_uuidstr-mask_char) | Masks the Universally Unique Identifier |
45+
| [`masking_dictionaries_flush()`](#masking_dictionaries_flush) | Resyncs the internal dictionary term cache |
2746
| [`masking_dictionary_remove(dictionary_name)`](#masking_dictionary_removedictionary_name) | Removes the dictionary |
2847
| [`masking_dictionary_term_add(dictionary_name, term_name)`](#masking_dictionary_term_adddictionary_name-term_name) | Adds a term to the masking dictionary |
2948
| [`masking_dictionary_term_remove(dictionary_name, term_name)`](#masking_dictionary_term_removedictionary_name-term_name) | Removes a term from the masking dictionary |
3049

50+
3151
## gen_blocklist(str, from_dictionary_name, to_dictionary_name)
3252

3353
Replaces a term from one dictionary with a randomly selected term in another dictionary.
3454

55+
### Version update
56+
57+
Percona Server for MySQL 8.0.41 introduces an internal term cache. The server now uses in-memory data structures for lookups instead of querying the `<masking_functions.masking_database>.masking_dictionaries` table every time. This improvement boosts performance, especially when handling multiple rows.
58+
3559
### Parameters
3660

3761
| Parameter | Optional | Description | Type |
@@ -66,6 +90,10 @@ mysql> SELECT gen_blocklist('apple', 'fruit', 'nut');
6690

6791
Returns a term from a dictionary selected at random.
6892

93+
### Version update
94+
95+
Percona Server for MySQL 8.0.41 introduces an internal term cache. The server now uses in-memory data structures for lookups instead of querying the `<masking_functions.masking_database>.masking_dictionaries` table every time. This improvement boosts performance, especially when handling multiple rows.
96+
6997
### Parameters
7098

7199
| Parameter | Optional | Description | Type |
@@ -760,6 +788,34 @@ mysql> SELECT mask_uuid('9a3b642c-06c6-11ee-be56-0242ac120002');
760788
+-------------------------------------------------------+
761789
```
762790

791+
792+
## masking_dictionaries_flush()
793+
794+
Resyncs the internal dictionary term cache.
795+
796+
### Parameters
797+
798+
None
799+
800+
### Returns
801+
802+
Returns an integer value of `1` (one) when successful.
803+
804+
### Example
805+
806+
```{.bash data-prompt="mysql>"}
807+
mysql> SELECT masking_dictionaries_flush();
808+
```
809+
??? example "Expected output"
810+
811+
```{.text .no-copy}
812+
+------------------------------+
813+
| masking_dictionaries_flush() |
814+
+------------------------------+
815+
| 1 |
816+
+---------------------------- +
817+
```
818+
763819
## masking_dictionary_remove(dictionary_name)
764820

765821
Removes all of the terms and then removes the dictionary.
@@ -775,7 +831,7 @@ Requires the `MASKING_DICTIONARIES_ADMIN` privilege.
775831

776832
### Returns
777833

778-
Returns a string value of `1` (one) in the `utf8mb4` character set if the operation is successful or `NULL` if the operation could not find the `dictionary_name`.
834+
Returns a integer value of `1` (one) if the operation is successful. Returns the integer value of `0` (zero) for a failure.
779835

780836
### Example
781837

@@ -807,9 +863,7 @@ Adds a term to the dictionary and requires the `MASKING_DICTIONARIES_ADMIN` priv
807863

808864
### Returns
809865

810-
Returns a string value of `1` (one) in the `utf8mb4` character set if the operation is successful. If the `dictionary_name` does not exist, the operation creates the dictionary.
811-
812-
Returns `NULL` if the operation fails. An operation can fail if the `term_name` is already available in the dictionary specified by `dictionary_name`.
866+
Returns a integer value of `1` (one) if the operation is successful. Returns the integer value of `0` (zero) for a failure. If the `dictionary_name` does not exist, the operation creates the dictionary.
813867

814868
The operation uses `INSERT IGNORE` and can have the following outcomes:
815869

@@ -872,7 +926,7 @@ Requires the `MASKING_DICTIONARIES_ADMIN` privilege.
872926

873927
### Returns
874928

875-
Returns a string value of `1` (one) in the `utf8mb4` character set if the operation is successful.
929+
Returns a integer value of `1` (one) if the operation is successful. Returns the integer value of `0` (zero) for a failure.
876930

877931
Returns `NULL` if the operation fails. An operation can fail if the following occurs:
878932

@@ -902,3 +956,38 @@ mysql> SELECT masking_dictionary_term_remove('trees','pine');
902956
| 1 |
903957
+-------------------------------------------------------+
904958
```
959+
960+
## System variables
961+
962+
963+
| **Name** | **Details** |
964+
|---------------------------------------------------|-------------------------------------------------------|
965+
| [`dictionaries_flush_interval_seconds (integer, unsigned)`](#dictionaries_flush_interval_secondsinteger-unsigned) | The number of seconds between updates to the internal dictionary cache to match changes in the dictionaries table.|
966+
| [`masking_database(str)`](#masking_databasestr) | Set a different database name to use for the dictionaries table. |
967+
968+
### dictionaries_flush_interval_seconds(integer, unsigned)
969+
970+
| Option | Description |
971+
|--------------|------------------|
972+
| command-line | Yes |
973+
| scope | Global |
974+
| data type | unsigned integer |
975+
| default | 10000 |
976+
977+
978+
Percona Server for MySQL 8.0.41 adds this variable. The number of seconds between a synchronization between the dictionaries table and the internal dictionary cache. The default value is 10,000 seconds (2 hours and 46 minutes). The minimum value is 1 second. The maximum value is 31,536,000 seconds (1 year).
979+
980+
### masking_database(string)
981+
982+
| Option | Description |
983+
| -------------- | ------------------ |
984+
| Scope: | Global |
985+
| Read, Write, or Read-Only: | Read-Only |
986+
| Data type | String |
987+
| Default value | "mysql" |
988+
989+
Specify the name of the database that holds the `masking_dictionaries` table. By default, it uses the `mysql` database.
990+
991+
### Returns
992+
993+
Returns a string value of `1` (one) when successful.

docs/data-masking-overview.md

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Data masking overview
22

3-
Data masking protects sensitive information by blocking unauthorized users from accessing the real data. This process creates altered versions of data for specific uses, like presentations, sales demonstrations, or software testing. The masked data keeps the same format as the original but contains changed values that cannot be reversed to reveal the true information. By making the data worthless to outsiders, masking helps organizations reduce their risk of data breaches or misuse. Companies can safely use masked data in various scenarios without exposing confidential details to unauthorized parties.
3+
Data masking protects sensitive information by restricting data access to authorized users only. When you need to present, demonstrate, or test software without revealing actual data, masking creates safe versions of your data. The masking process changes values while keeping the same data format, making the original values impossible to recover. This security approach reduces organizational risk because any exposed data becomes worthless to unauthorized parties.
44

55
Data masking in Percona Server for MySQL is an essential tool for protecting sensitive information in various scenarios:
66

@@ -14,16 +14,43 @@ Data masking in Percona Server for MySQL is an essential tool for protecting sen
1414

1515
These examples underscore how data masking serves as a crucial safeguard for sensitive information, allowing organizations to leverage their data effectively across diverse functions.
1616

17-
Data masking helps to limit the exposure of sensitive data by preventing access to non-authorized users. Masking provides a way to create a version of the data in situations, such as a presentation, sales demo, or software testing, when the real data should not be used. Data masking changes the data values while using the same format and cannot be reverse engineered. Masking reduces an organization's risk by making the data useless to an outside party.
17+
18+
## Version updates
19+
20+
Percona Server for MySQL 8.0.41 introduces performance improvements for data masking through an internal term cache. The cache affects the following functions in the [data masking component](data-masking-function-list.md):
21+
22+
* [gen_blocklist()](data-masking-function-list.md#gen_blockliststr-from_dictionary_name-to_dictionary_name)
23+
24+
* [gen_dictionary()](data-masking-function-list.md#gen_dictionarydictionary_name)
25+
26+
The new cache stores dictionary data in memory, making lookups faster than the previous method of querying the `<masking_functions.masking_database>.masking_dictionaries` table each time. This speed boost is especially noticeable when you're working with many rows of data.
27+
28+
However, the cache brings some new considerations. If you change the dictionary table directly (instead of using the proper dictionary management functions), your cache and table data can become different.
29+
30+
The dictionary manipulation functions are the following:
31+
32+
* [`masking_dictionary_term_add()`](data-masking-function-list.md#masking_dictionary_term_adddictionary_name-term_name)
33+
34+
* [`masking_dictionary_term_remove()`](data-masking-function-list.md#masking_dictionary_term_removedictionary_name-term_name)
35+
36+
* [`masking_dictionary_remove()`](data-masking-function-list.md#masking_dictionary_removedictionary_name)
37+
38+
To fix this, you can use the new [`masking_dictionaries_flush()`](data-masking-function-list.md#masking_dictionaries_flush) function to sync them back up. This function returns `1` when successful.
39+
40+
The changes also affect how row-based replication works. When dictionary changes happen on the source server, they travel through the binary log to the replica server. While the replica applies these changes to its table correctly, the dictionary term cache doesn't update right away.
41+
42+
To handle this, there's a new system setting called [`component_masking_functions.dictionaries_flush_interval_seconds()`](data-masking-function-list.html#dictionaries_flush_interval_secondsinteger-unsigned)
43+
44+
By default, it's set to 0. When you set it higher, the system starts a background process that refreshes the cache at your specified interval. This helps replicas stay in sync after receiving binary log updates. The value specifies the number of seconds between each sync.
1845

1946
## Data masking techniques
2047

2148
The common data masking techniques are the following:
2249

2350
| Technique | Description |
2451
| --- | --- |
25-
| Custom string | Replaces sensitive data with a specific string, such as a phone number with XXX-XXX-XXXX |
26-
| Data substitution | Replaces sensitive data with realistic alternative values, such as city name with another name from a dictionary |
52+
| Character substitution | Replaces sensitive data with a matching symbol (X,*). For example, a phone number becomes XXX-XXX-XXXX. |
53+
| Value generation | Replaces sensitive data with realistic-looking alternative values. For example, for testing purposes, you can generate a realistic alternative United States Social Security Number. |
2754

2855
## Additional resources
2956

0 commit comments

Comments
 (0)