Have storage replication backfill tool only backfill missing storages

Prevents overload of the queue
This commit is contained in:
Joseph Schorr 2017-03-22 11:30:49 -04:00
parent b05ebbf2c0
commit 6ab5b8be45

View file

@ -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__':