Geo: Add models to prepare for project repo replication v2
What does this MR do and why?
This code change adds support a new verification system for project repositories in GitLab's Geo feature.
It adds the models ProjectRepository and ProjectRepositoryState in the EE module and factories and tests for them.
References
Geo: Enumerate project_repositories instead of ... (#546175)
Test setup
Use the following script to enable needed feature flags and setup data on the primary node.
Test Setup script
Feature.enable_percentage_of_time(:allow_organization_creation, 100)
Feature.enable_percentage_of_time(:organization_switching, 100)
Feature.enable_percentage_of_time(:ui_for_organizations, 100)
Feature.enable(:org_mover_extend_selective_sync_to_primary_checksumming)
Feature.enable(:geo_selective_sync_by_organizations)
# Create first organization with owner
org1 = Organizations::Organization.create!(name: 'Test Org 1', path: 'test-org-1', visibility_level: Organizations::Organization::PUBLIC)
Organizations::OrganizationUser.create_organization_record_for(User.first.id, org1.id)
# Create second organization with owner
org2 = Organizations::Organization.create!(name: 'Test Org 2', path: 'test-org-2', visibility_level: Organizations::Organization::PUBLIC)
Organizations::OrganizationUser.create_organization_record_for(User.first.id, org2.id)
# Create projects in first organization
group1 = Group.create!(name: 'Group 1', path: 'group-1', organization: org1)
group1.add_owner(User.first)
# Create 3 projects in first organization
3.times do |i|
Projects::CreateService.new(User.first, {
name: "Project #{i+1}",
path: "project-#{i+1}",
description: "Test project #{i+1}",
namespace_id: group1.id,
organization_id: org1.id,
visibility_level: Gitlab::VisibilityLevel.level_value('private'),
initialize_with_readme: true
}).execute
end
# Create projects in second organization
group2 = Group.create!(name: 'Group 2', path: 'group-2', organization: org2)
group2.add_owner(User.first)
# Create 3 projects in second organization
3.times do |i|
Projects::CreateService.new(User.first, {
name: "Project #{i+4}",
path: "project-#{i+4}",
description: "Test project #{i+4}",
namespace_id: group2.id,
organization_id: org2.id,
visibility_level: Gitlab::VisibilityLevel.level_value('private'),
initialize_with_readme: true
}).execute
end
::Gitlab::Geo.secondary_nodes.first.update!(selective_sync_type: 'organizations', organizations: [org1, org2])
puts 'Created 2 organizations with 3 projects each'
Database queries
ProjectRepository.selective_sync_scope(
node,
replicables: ProjectRepository.where(id: 1..10000))
SQL
-- ProjectRepository Load for Geo selective sync by organizations
SELECT
"project_repositories".*
FROM
"project_repositories"
WHERE
"project_repositories"."id" BETWEEN 1 AND 10000
AND "project_repositories"."project_id" IN (
SELECT
"projects"."id"
FROM
"projects"
WHERE
"projects"."namespace_id" IN (
SELECT
"namespaces"."id"
FROM
"namespaces"
WHERE
"namespaces"."organization_id" IN (
SELECT
"geo_node_organization_links"."organization_id"
FROM
"geo_node_organization_links"
WHERE
"geo_node_organization_links"."geo_node_id" = 2)))
ProjectRepository.pluck_verifiable_ids_in_range(1..10000)
Raw SQL
-- ProjectRepository Ids (12.7ms)
SELECT
"project_repositories"."id"
FROM
"project_repositories"
WHERE
"project_repositories"."id" BETWEEN 1 AND 10000
AND "project_repositories"."project_id" IN (
SELECT
"projects"."id"
FROM
"projects"
WHERE
"projects"."namespace_id" IN (
SELECT
"namespaces"."id"
FROM
"namespaces"
WHERE
"namespaces"."organization_id" IN (
SELECT
"geo_node_organization_links"."organization_id"
FROM
"geo_node_organization_links"
WHERE
"geo_node_organization_links"."geo_node_id" = 2)))
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. oup::geo
Edited by Aakriti Gupta