Improve restoring of access entities' dependencies #2#69563
Improve restoring of access entities' dependencies #2#69563alexey-milovidov merged 14 commits intoClickHouse:masterfrom
Conversation
|
This is an automated comment for commit 8a7a411 with description of existing statuses. It's updated for the latest CI running ✅ Click here to open a full report in a separate page Successful checks
|
1bb4e16 to
5732a7d
Compare
5bae8f5 to
4d5859e
Compare
|
CI all green |
|
I'd like to merge #69346 first. |
eb5c7b1 to
e44e2c9
Compare
…_access_dependencies = true".
e44e2c9 to
9e35eb6
Compare
…updating dependents of restored access entities.
use "access-<UUID>.txt" instead of "access01.txt", "access02.txt", ...
… setting "write_access_entities_dependents".
9e35eb6 to
443ff06
Compare
…p_unresolved_access_dependencies".
443ff06 to
8a7a411
Compare
|
@pufit Please review |
| std::vector<UUID> findAll() const { return findAll(EntityClassT::TYPE); } | ||
| /// Returns the identifiers of all the entities in the storage. | ||
| template <typename EntityClassT = IAccessEntity> | ||
| std::vector<UUID> findAll() const; |
There was a problem hiding this comment.
When we're making a backup:
- first it collects all the access entities with BackupEntriesCollector::getAllAccessEntities(); then
- IAccessStorage::backup() finds UUIDs of all entities of the required type (users/roles/etc); and finally
- makeBackupEntryForAccessEntities() produces backup entities for the backup.
| if (!entities_ids_set.contains(id) && possible_dependent->hasDependencies(entities_ids_set)) | ||
| { | ||
| auto dependent = possible_dependent->clone(); | ||
| dependent->clearAllExceptDependencies(); |
There was a problem hiding this comment.
What does it do exactly? Why do we need to remove everything here?
There was a problem hiding this comment.
This is to store dependent access entities. For example, if we store roles:
BACKUP TABLE system.roles ...
then after this PR we'll have additional DEPENDENTS section in the backup with information about which users use those roles. This information must not contain the credentials of these users.
For example, if a role was granted to a user and if we backup system.roles then file /data/system/roles/access-<UUID>.txt inside the backup will look like this:
fb4c9f55-3c15-32b3-4c5b-ea6de397c48e ROLE role1
ATTACH ROLE role1 SETTINGS custom_x = 'x';
DEPENDENTS
7647694e-1f79-5d14-dd2c-29d976450ba1 USER user1
ATTACH USER user1 DEFAULT ROLE ID('fb4c9f55-3c15-32b3-4c5b-ea6de397c48e');
ATTACH GRANT ID('fb4c9f55-3c15-32b3-4c5b-ea6de397c48e') TO user1;
So this information is to restore role role1 and grant it to existing user user1, and not to restore user1 - so we don't have to store the credentials of user1 here.
| struct FilePathsAndHost | ||
| { | ||
| std::unordered_set<String> file_paths; | ||
| std::set<String> file_paths; |
There was a problem hiding this comment.
Because in BackupCoordinationReplicatedAccess::getFilePaths() we get the first file_path in this list and we want it to be the same on each host. This list of file paths contains the same elements on each host and if the list is sorted then we can be sure that the first element will be also the same on each host.
|
|
||
| if (found) | ||
| { | ||
| for (const auto & role_id : src.roles_with_admin_option) |
|
|
||
| if (found) | ||
| { | ||
| for (auto it = roles_with_admin_option.begin(); it != roles_with_admin_option.end();) |
|
I'm not sure about backport though - this PR has quite a bunch of changes, it adds new behavior and it even changes the format of some files stored inside a backup a little (in a backward-compatible manner). |
|
Yes, let's close backports. |
Changelog category:
Changelog entry:
Follow-up to #69346
Point 4 described there will work now as well:
For example if before making a backup a role was granted to a user:
then during
RESTOREthe following cases are possible:u1and roler1both don't exist. ThenRESTOREwill recreate them both and that grant too.u1and roler1both exist. ThenRESTORE(with default settings) will skip them both and that grant too.u1doesn't exist and roler1exist. ThenRESTORE(with default settings) will recreate useru1, and that grant too.u1exists and roler1doesn't exist. ThenRESTORE(with default settings) will recreate roler1, and (after this PR) that grant too.