Merge pull request #1744 from coreos-inc/gc-constraint
Handle GC constraint failures in a nicer way
This commit is contained in:
commit
987bd53c2d
1 changed files with 14 additions and 4 deletions
|
@ -2,7 +2,7 @@ import logging
|
||||||
import random
|
import random
|
||||||
|
|
||||||
from datetime import timedelta, datetime
|
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 cachetools import ttl_cache
|
||||||
|
|
||||||
from data.model import (DataModelException, tag, db_transaction, storage, permission,
|
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.
|
# Delete any derived images and the images themselves.
|
||||||
if has_derived:
|
if has_derived:
|
||||||
DerivedStorageForImage.delete().where(
|
try:
|
||||||
DerivedStorageForImage.source_image << to_remove).execute()
|
(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
|
||||||
|
|
||||||
|
try:
|
||||||
Image.delete().where(Image.id << to_remove).execute()
|
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:
|
if len(to_remove) > 0:
|
||||||
logger.info('Garbage collecting storage for images: %s', to_remove)
|
logger.info('Garbage collecting storage for images: %s', to_remove)
|
||||||
|
|
Reference in a new issue