Handle GC constraint failures in a nicer way

Fixes #1739
This commit is contained in:
Joseph Schorr 2016-08-17 15:09:19 -04:00
parent 0b50928900
commit aeddc6af06

View file

@ -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)