Resolve "Replace sync traversal_ids locking mechanism"
What does this MR do?
Replace traversal_ids lock mechanism.
- Lock on root ancestor instead of the results of the CTE which does not work as expected. Discussion at !57318 (comment 543437858)
- When moving a namespace to another hierarchy, lock the root ancestors of the original hierarchy and the new hierarchy. Discussion at !57318 (comment 553006573)
SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 2 LIMIT 1 FOR UPDATE
SELECT
"namespaces"."id"
FROM
"namespaces"
WHERE
"namespaces"."id" IN (
SELECT
"namespaces"."id"
FROM
(
SELECT
"namespaces".*
FROM
"namespaces"
INNER JOIN (
SELECT
"id",
"depth"
FROM
(
WITH RECURSIVE "base_and_ancestors" AS (
(
SELECT
"namespaces".*
FROM
"namespaces"
WHERE
"namespaces"."id" IN (1, 3)
)
UNION
(
SELECT
"namespaces".*
FROM
"namespaces",
"base_and_ancestors"
WHERE
"namespaces"."id" = "base_and_ancestors"."parent_id"
)
)
SELECT
DISTINCT "namespaces".*,
ROW_NUMBER() OVER () as depth
FROM
"base_and_ancestors" AS "namespaces"
) AS "namespaces"
) namespaces_join_table on namespaces_join_table.id = namespaces.id
ORDER BY
"namespaces_join_table"."depth" ASC
) AS "namespaces"
WHERE
"namespaces"."parent_id" IS NULL
)
ORDER BY
"namespaces"."id" ASC FOR
UPDATE
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?-
I have included a changelog entry. -
I have not included a changelog entry because developer facing refactor.
-
-
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Related to #326785 (closed)
Edited by Alex Pooley