From aeddc6af0612179cd5c765a9a934ef38668167d3 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 17 Aug 2016 15:09:19 -0400 Subject: [PATCH] Handle GC constraint failures in a nicer way Fixes #1739 --- data/model/repository.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/data/model/repository.py b/data/model/repository.py index cd37aa0a6..ca4ff15a9 100644 --- a/data/model/repository.py +++ b/data/model/repository.py @@ -2,7 +2,7 @@ import logging import random from datetime import timedelta, datetime -from peewee import JOIN_LEFT_OUTER, fn, SQL +from peewee import JOIN_LEFT_OUTER, fn, SQL, IntegrityError from cachetools import ttl_cache from data.model import (DataModelException, tag, db_transaction, storage, permission, @@ -175,10 +175,20 @@ def garbage_collect_repo(repo): # Delete any derived images and the images themselves. if has_derived: - DerivedStorageForImage.delete().where( - DerivedStorageForImage.source_image << to_remove).execute() + try: + (DerivedStorageForImage + .delete() + .where(DerivedStorageForImage.source_image << to_remove) + .execute()) + except IntegrityError: + logger.info('Could not GC derived images %s; will try again soon', to_remove) + return - Image.delete().where(Image.id << to_remove).execute() + try: + Image.delete().where(Image.id << to_remove).execute() + except IntegrityError: + logger.info('Could not GC images %s; will try again soon', to_remove) + return if len(to_remove) > 0: logger.info('Garbage collecting storage for images: %s', to_remove)