Mount blobs between repositories in Geo container sync

What does this MR do and why?

Geo sync uploads every blob a repository lacks, even when the secondary registry already holds it for another repository.

Behind the geo_container_registry_blob_mount beta flag, sync first asks the primary whether this repository holds the blob. If it does, sync mounts the blob from that other repository, and falls back to the upload on any other answer or error.

flowchart TD
  F{"Flag on?"} -- "no" --> U["Pull from primary<br/>and upload, as before"]
  F -- "yes" --> K{"Another repository<br/>known to hold the blob?"}
  K -- "no" --> U
  K -- "yes" --> H{"Primary holds the blob<br/>in this repository?"}
  H -- "no, or an error" --> U
  H -- "yes" --> M{"Registry mount"}
  M -- "linked" --> D["Done, no transfer"]
  M -- "upload session" --> C["Pull from primary,<br/>send to that session"]
  M -- "any error" --> U

Measured on a two-site Geo pair, for a later repository that shares 4 blobs with one already synced:

Check Flag Result
Shared blobs off 4 uploads, 16 _uploads/ keys
Shared blobs on 0 uploads, 0 keys, 4 mounts answered 201
Shared blobs, filesystem metadata mode on 0 uploads after the first repository
Stale record of the source on mount answered 202, blob sent to that upload session, synced
Mount refused with 401 (token without pull on the source) on falls back to the upload, synced
Records cleared on plain upload, records rebuilt
Two syncs at once on 2 uploads per repository instead of 4, because neither had recorded the blobs yet, both synced
Pull from primary fails after a 202 on upload session cancelled, sync fails as unpatched does
Registry refuses that cancel on Blob upload session not cancelled logged with the digest
Patched code off same uploads, POST and PUT counts as unpatched
Primary does not hold the blob in this repository on no mount; the pull from the primary answers 404 and the tag fails, as unpatched
Primary holds the blob in this repository, secondary does not on mount answered 201

The last two rows ran with the check against the primary, which costs one HEAD per blob it could mount. The rows above predate the check, which the specs cover.

References

Screenshots or screen recordings

No UI change.

How to set up and validate locally

On a self-managed Geo pair:

  1. On the primary, in a Rails console, run Feature.enable(:geo_container_registry_blob_mount).
  2. On the primary, push two container repositories that share image layers.
  3. Let the secondary sync both.
  4. In the secondary registry request log, the second repository's blobs show a POST .../blobs/uploads/ with a mount= parameter answered 201 and no PUT.
  5. On the primary, run Feature.disable(:geo_container_registry_blob_mount) and repeat with two new repositories to see the uploads return.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

An AI coding assistant wrote this change. The assistant also checked each claim against the source at 48ad40d6, ran the touched specs and RuboCop on the touched files on a test VM, and ran a ported copy of the change on a two-site Geo test pair.

Edited by Andrew Dunn

Merge request reports

Loading
Loading