Draft: Use CI mirror tables for data isolation on CI database
What does this MR do and why?
This MR makes the data isolation scoping work for tables on the ci database.
The scoping rewrote queries on CI tables into subqueries on the projects and namespaces tables, which do not exist on the ci database. Now the gitlab-database-data_isolation gem passes the table name to current_sharding_key_value, so the initializer can scope gitlab_ci tables through ci_project_mirrors and ci_namespace_mirrors instead:
-- before (broken on a decomposed ci database):
WHERE "p_ci_builds"."project_id" IN (SELECT "projects"."id" FROM "projects" WHERE ...)
-- after:
WHERE "p_ci_builds"."project_id" IN (SELECT "ci_project_mirrors"."project_id" FROM "ci_project_mirrors" WHERE "ci_project_mirrors"."organization_id" = ...)There is no recursion when the subquery table is itself in the sharding key map, because the gem builds sharding key value subqueries inside Context.without_data_isolation.
This MR is part 4 of a series:
- !253978 (merged) - add the
organization_idcolumns - !254205 (merged) - sync
organization_idon changes - !254209 (merged) - backfill
organization_idfor existing rows - This MR - use the mirror tables in the data isolation logic
References
- Related to #627588
How to set up and validate locally
- Make sure the mirror tables are populated (see the earlier MRs in the series).
- Enable isolation for an organization and set it as the current organization.
- In a Rails console,
Ci::Pipeline.all.to_sql(or any CI model sharded byproject_id/namespace_id) should show anIN (SELECT ... FROM ci_project_mirrors ...)condition instead of a subquery onprojects.
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.