diff --git a/util/backfillreplication.py b/util/backfillreplication.py index e63cd45fe..a60a6ef89 100644 --- a/util/backfillreplication.py +++ b/util/backfillreplication.py @@ -1,7 +1,9 @@ import logging import features +from app import storage, image_replication_queue from data.database import Image, ImageStorage, Repository, User +from data import model from util.registry.replication import queue_storage_replication def backfill_replication(): @@ -17,9 +19,16 @@ def backfill_replication(): if image.storage.uuid in encountered: continue - print "Enqueueing image storage %s to be replicated" % (image.storage.uuid) - encountered.add(image.storage.uuid) - queue_storage_replication(image.repository.namespace_user.username, image.storage) + namespace = image.repository.namespace_user.username + locations = model.user.get_region_locations(namespace) + locations_required = locations | set(storage.default_locations) + locations_missing = locations_required - set(image.storage.locations) + if locations_missing: + print "Enqueueing image storage %s to be replicated" % (image.storage.uuid) + encountered.add(image.storage.uuid) + + if not image_replication_queue.alive([image.storage.uuid]): + queue_storage_replication(image.repository.namespace_user.username, image.storage) if __name__ == '__main__':