Log grants on archived projects in permission refreshes
What does this MR do and why?
Permission refreshes write project_authorizations rows for archived projects at the same priority as for active projects. Archived projects are read-only, so a grant there (new access or an access level increase) could wait for the safety-net refresh. Defer authorization grants on archived projects... (!266553) makes that change. Today the share of refresh writes that are such grants can only be estimated from logs.
This MR logs how many of a refresh's grants are on projects archived themselves or under an archived group, as authorized_projects_refresh.archived_grants_count next to rows_added_count. It applies per user, when the new log_archived_project_authorization_grants flag is on. What the refresh writes is unchanged.
- The count is what the refresh requested, like the
rows_*_slicefields.rows_added_countis what it applied, so in rare races the count can be higher. - Access level decreases and duplicate-row cleanup on archived projects rewrite rows but are not grants, so they are not counted.
Database
One new query, run only for refreshes that find grants for a user the flag is on for, in slices of 1,000 project IDs. No query runs when a refresh has no grants.
Query, plans and timings
SELECT "projects"."id" FROM "projects"
LEFT OUTER JOIN "namespaces" ON "namespaces"."type" = 'Group' AND "namespaces"."id" = "projects"."namespace_id" AND "namespaces"."type" = 'Group'
WHERE "projects"."id" IN (<up to 1,000 project IDs>)
AND ("projects"."archived" = TRUE OR EXISTS (SELECT 1 FROM "namespace_settings" WHERE "namespace_settings"."namespace_id" = ANY (namespaces.traversal_ids) AND "namespace_settings"."archived" = TRUE))
LIMIT <number of project IDs>The IDs were 1,000 real project IDs from each user's own project_authorizations rows, picked by a subquery. The linked plans on gitlab-production-main include that subquery. The times below leave it out.
| Input | Archived | Warm | Cold |
|---|---|---|---|
| Group access token bot in the namespace with the most rows added | 511 of 1,000 | 7 ms | 2.6 s |
| Member of a 52k-project hierarchy | 999 of 1,000 | 3 ms | 0.9 s |
The cold runs are first reads of projects and namespaces pages on a fresh clone, about 1,900 and 1,000 shared buffer reads. The same refresh has just read these projects to compute fresh access, so production should be closer to the warm times.
References
- https://gitlab.com/gitlab-org/gitlab/-/work_items/637273+
- Defer authorization grants on archived projects... (!266553), stacked on this MR.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.