diff --git a/util/backfillreplication.py b/util/backfillreplication.py index a60a6ef89..f08ad4749 100644 --- a/util/backfillreplication.py +++ b/util/backfillreplication.py @@ -2,7 +2,8 @@ import logging import features from app import storage, image_replication_queue -from data.database import Image, ImageStorage, Repository, User +from data.database import (Image, ImageStorage, Repository, User, ImageStoragePlacement, + ImageStorageLocation) from data import model from util.registry.replication import queue_storage_replication @@ -19,10 +20,17 @@ def backfill_replication(): if image.storage.uuid in encountered: continue - namespace = image.repository.namespace_user.username + namespace = image.repository.namespace_user locations = model.user.get_region_locations(namespace) locations_required = locations | set(storage.default_locations) - locations_missing = locations_required - set(image.storage.locations) + + query = (ImageStoragePlacement + .select(ImageStoragePlacement, ImageStorageLocation) + .where(ImageStoragePlacement.storage == image.storage) + .join(ImageStorageLocation)) + + existing_locations = set([p.location.name for p in query]) + locations_missing = locations_required - existing_locations if locations_missing: print "Enqueueing image storage %s to be replicated" % (image.storage.uuid) encountered.add(image.storage.uuid)