From 08b9c4b0d41aed9e455f8bd384a047d354270f8b Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 19 Apr 2017 16:50:51 -0400 Subject: [PATCH] Fill backfill script for recent changes We forgot that we need to lookup by user *object* and we need to lookup locations on their own --- util/backfillreplication.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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)