Skip to content

Resolve "Replace sync traversal_ids locking mechanism"

What does this MR do?

Replace traversal_ids lock mechanism.

  1. Lock on root ancestor instead of the results of the CTE which does not work as expected. Discussion at !57318 (comment 543437858)
  2. When moving a namespace to another hierarchy, lock the root ancestors of the original hierarchy and the new hierarchy. Discussion at !57318 (comment 553006573)
Lock on root ancestor
SELECT "namespaces".* FROM "namespaces" WHERE "namespaces"."type" = 'Group' AND "namespaces"."id" = 2 LIMIT 1 FOR UPDATE
Lock root ancestor of both the original and new hierarchy.
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

Availability and Testing

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

Merge request reports