Add concurrency support for Git repository backups

Merged James Fargher requested to merge concurrent_repo_backup into master

What does this MR do?

#222488 (closed)

  • Breaks down dumping repositories for backup into n-threads per gitaly shard via GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY and restricts total concurrency via GITLAB_BACKUP_MAX_CONCURRENCY
  • Maintains original behaviour by default

DB

The main query for projects is split over one thread per storage, looks like this:

SELECT "projects".* FROM "projects" WHERE "projects"."repository_storage" = 'default' ORDER BY "projects"."id" ASC LIMIT 100

Explain:

 Limit  (cost=199.81..200.06 rows=100 width=721) (actual time=340.480..340.512 rows=100 loops=1)
   Buffers: shared hit=3 read=150
   I/O Timings: read=338.220
   ->  Sort  (cost=199.81..200.18 rows=146 width=721) (actual time=340.479..340.496 rows=100 loops=1)
         Sort Key: projects.id
         Sort Method: quicksort  Memory: 88kB
         Buffers: shared hit=3 read=150
         I/O Timings: read=338.220
         ->  Index Scan using index_projects_on_repository_storage on public.projects  (cost=0.56..194.56 rows=146 width=721) (actual time=9.225..339.741 rows=148 loops=1)
               Index Cond: ((projects.repository_storage)::text = 'default'::text)
               Buffers: shared read=150
               I/O Timings: read=338.220

Screenshots

An example running in GDK with only a single storage:

$ bundle exec rake gitlab:backup:create GITLAB_BACKUP_MAX_STORAGE_CONCURRENCY=2
...
2020-07-31 15:45:05 +1200 -- Dumping repositories ...
 * gitlab-org/gitlab-test (@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b) ... 
 * gitlab-org/gitlab-shell (@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35) ... 
 * gitlab-org/gitlab-shell (@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35) ... [DONE]
 * gitlab-org/gitlab-shell (@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35) ... [SKIPPED] Wiki
 * gnuwget/wget2 (@hashed/4e/07/4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce) ... 
 * gitlab-org/gitlab-test (@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b) ... [DONE]
 * gitlab-org/gitlab-test (@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b) ... [SKIPPED] Wiki
 * Commit451/lab-coat (@hashed/4b/22/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a) ... 
 * Commit451/lab-coat (@hashed/4b/22/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a) ... [DONE]
 * Commit451/lab-coat (@hashed/4b/22/4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a) ... [SKIPPED] Wiki
 * jashkenas/underscore (@hashed/ef/2d/ef2d127de37b942baad06145e54b0c619a1f22327b2ebbcfbec78f5564afe39d) ... 
 * gnuwget/wget2 (@hashed/4e/07/4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce) ... [DONE]
 * gnuwget/wget2 (@hashed/4e/07/4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce) ... [SKIPPED] Wiki
 * flightjs/flight (@hashed/e7/f6/e7f6c011776e8db7cd330b54174fd76f7d0216b612387a5ffcfb81e6f0919683) ... 
 * jashkenas/underscore (@hashed/ef/2d/ef2d127de37b942baad06145e54b0c619a1f22327b2ebbcfbec78f5564afe39d) ... [DONE]
 * jashkenas/underscore (@hashed/ef/2d/ef2d127de37b942baad06145e54b0c619a1f22327b2ebbcfbec78f5564afe39d) ... [SKIPPED] Wiki
 * twitter/typeahead-js (@hashed/79/02/7902699be42c8a8e46fbbb4501726517e86b22c56a189f7625a6da49081b2451) ... 
 * flightjs/flight (@hashed/e7/f6/e7f6c011776e8db7cd330b54174fd76f7d0216b612387a5ffcfb81e6f0919683) ... [DONE]
 * flightjs/flight (@hashed/e7/f6/e7f6c011776e8db7cd330b54174fd76f7d0216b612387a5ffcfb81e6f0919683) ... [SKIPPED] Wiki
 * h5bp/html5-boilerplate (@hashed/2c/62/2c624232cdd221771294dfbb310aca000a0df6ac8b66b696d90ef06fdefb64a3) ... 
 * twitter/typeahead-js (@hashed/79/02/7902699be42c8a8e46fbbb4501726517e86b22c56a189f7625a6da49081b2451) ... [DONE]
 * twitter/typeahead-js (@hashed/79/02/7902699be42c8a8e46fbbb4501726517e86b22c56a189f7625a6da49081b2451) ... [SKIPPED] Wiki
 * lakenya/gitlab-shell (@hashed/19/58/19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7) ... 
 * lakenya/gitlab-shell (@hashed/19/58/19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7) ... [SKIPPED]
 * lakenya/gitlab-shell (@hashed/19/58/19581e27de7ced00ff1ce50b2047e7a567c76b1cbaebabe5ef03f7c3017bb5b7) ... [SKIPPED] Wiki
 * reported_user_6/gitlab-shell (@hashed/4a/44/4a44dc15364204a80fe80e9039455cc1608281820fe2b24f1e5233ade6af1dd5) ... 
 * reported_user_6/gitlab-shell (@hashed/4a/44/4a44dc15364204a80fe80e9039455cc1608281820fe2b24f1e5233ade6af1dd5) ... [SKIPPED]
 * reported_user_6/gitlab-shell (@hashed/4a/44/4a44dc15364204a80fe80e9039455cc1608281820fe2b24f1e5233ade6af1dd5) ... [SKIPPED] Wiki
 * melvin_botsford/flight (@hashed/4f/c8/4fc82b26aecb47d2868c4efbe3581732a3e7cbcc6c2efb32062c08170a05eeb8) ... 
 * melvin_botsford/flight (@hashed/4f/c8/4fc82b26aecb47d2868c4efbe3581732a3e7cbcc6c2efb32062c08170a05eeb8) ... [SKIPPED]
 * melvin_botsford/flight (@hashed/4f/c8/4fc82b26aecb47d2868c4efbe3581732a3e7cbcc6c2efb32062c08170a05eeb8) ... [SKIPPED] Wiki
 * darrel.schinner/gitlab-shell (@hashed/6b/51/6b51d431df5d7f141cbececcf79edf3dd861c3b4069f0b11661a3eefacbba918) ... 
 * darrel.schinner/gitlab-shell (@hashed/6b/51/6b51d431df5d7f141cbececcf79edf3dd861c3b4069f0b11661a3eefacbba918) ... [SKIPPED]
 * h5bp/html5-boilerplate (@hashed/2c/62/2c624232cdd221771294dfbb310aca000a0df6ac8b66b696d90ef06fdefb64a3) ... [DONE]
 * darrel.schinner/gitlab-shell (@hashed/6b/51/6b51d431df5d7f141cbececcf79edf3dd861c3b4069f0b11661a3eefacbba918) ... [SKIPPED] Wiki
 * shelley_walker/underscore (@hashed/3f/db/3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278) ... 
 * h5bp/html5-boilerplate (@hashed/2c/62/2c624232cdd221771294dfbb310aca000a0df6ac8b66b696d90ef06fdefb64a3) ... [SKIPPED] Wiki
 * jesusa/gitlab-shell (@hashed/85/27/8527a891e224136950ff32ca212b45bc93f69fbb801c3b1ebedac52775f99e61) ... 
 * shelley_walker/underscore (@hashed/3f/db/3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278) ... [SKIPPED]
 * jesusa/gitlab-shell (@hashed/85/27/8527a891e224136950ff32ca212b45bc93f69fbb801c3b1ebedac52775f99e61) ... [SKIPPED]
 * shelley_walker/underscore (@hashed/3f/db/3fdba35f04dc8c462986c992bcf875546257113072a909c162f7e470e581e278) ... [SKIPPED] Wiki
 * jannet/underscore (@hashed/e6/29/e629fa6598d732768f7c726b4b621285f9c3b85303900aa912017db7617d8bdb) ... 
 * jesusa/gitlab-shell (@hashed/85/27/8527a891e224136950ff32ca212b45bc93f69fbb801c3b1ebedac52775f99e61) ... [SKIPPED] Wiki
 * reported_user_18/underscore (@hashed/b1/7e/b17ef6d19c7a5b1ee83b907c595526dcb1eb06db8227d650d5dda0a9f4ce8cd9) ... 
 * jannet/underscore (@hashed/e6/29/e629fa6598d732768f7c726b4b621285f9c3b85303900aa912017db7617d8bdb) ... [SKIPPED]
 * reported_user_18/underscore (@hashed/b1/7e/b17ef6d19c7a5b1ee83b907c595526dcb1eb06db8227d650d5dda0a9f4ce8cd9) ... [SKIPPED]
 * jannet/underscore (@hashed/e6/29/e629fa6598d732768f7c726b4b621285f9c3b85303900aa912017db7617d8bdb) ... [SKIPPED] Wiki
 * reported_user_3/gitlab-shell (@hashed/45/23/4523540f1504cd17100c4835e85b7eefd49911580f8efff0599a8f283be6b9e3) ... 
 * reported_user_18/underscore (@hashed/b1/7e/b17ef6d19c7a5b1ee83b907c595526dcb1eb06db8227d650d5dda0a9f4ce8cd9) ... [SKIPPED] Wiki
 * reported_user_19/underscore (@hashed/4e/c9/4ec9599fc203d176a301536c2e091a19bc852759b255bd6818810a42c5fed14a) ... 
 * reported_user_3/gitlab-shell (@hashed/45/23/4523540f1504cd17100c4835e85b7eefd49911580f8efff0599a8f283be6b9e3) ... [SKIPPED]
 * reported_user_19/underscore (@hashed/4e/c9/4ec9599fc203d176a301536c2e091a19bc852759b255bd6818810a42c5fed14a) ... [SKIPPED]
 * reported_user_3/gitlab-shell (@hashed/45/23/4523540f1504cd17100c4835e85b7eefd49911580f8efff0599a8f283be6b9e3) ... [SKIPPED] Wiki
 * root/gitaly (@hashed/94/00/9400f1b21cb527d7fa3d3eabba93557a18ebe7a2ca4e471cfe5e4c5b4ca7f767) ... 
 * reported_user_19/underscore (@hashed/4e/c9/4ec9599fc203d176a301536c2e091a19bc852759b255bd6818810a42c5fed14a) ... [SKIPPED] Wiki
 * root/gitaly (@hashed/94/00/9400f1b21cb527d7fa3d3eabba93557a18ebe7a2ca4e471cfe5e4c5b4ca7f767) ... [DONE]
 * root/gitaly (@hashed/94/00/9400f1b21cb527d7fa3d3eabba93557a18ebe7a2ca4e471cfe5e4c5b4ca7f767) ... [SKIPPED] Wiki
2020-07-31 15:45:07 +1200 -- done
...

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
Edited by James Fargher