From 693e47e0634c4cf33f7c588f59c67088881dd2cf Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 20 Feb 2019 12:05:21 -0500 Subject: [PATCH] Add additional assertions and further checks in storage code --- data/model/blob.py | 5 +++++ data/model/image.py | 3 ++- data/model/storage.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/data/model/blob.py b/data/model/blob.py index cc90cea2f..fcd5caefa 100644 --- a/data/model/blob.py +++ b/data/model/blob.py @@ -15,6 +15,7 @@ logger = logging.getLogger(__name__) def get_repository_blob_by_digest(repository, blob_digest): """ Find the content-addressable blob linked to the specified repository. """ + assert blob_digest try: storage = (ImageStorage .select(ImageStorage.uuid) @@ -32,6 +33,7 @@ def get_repository_blob_by_digest(repository, blob_digest): def get_repo_blob_by_digest(namespace, repo_name, blob_digest): """ Find the content-addressable blob linked to the specified repository. """ + assert blob_digest try: storage = (ImageStorage .select(ImageStorage.uuid) @@ -81,6 +83,8 @@ def temp_link_blob(namespace, repo_name, blob_digest, link_expiration_s): """ Temporarily links to the blob record from the given namespace. If the blob record is not found, return None. """ + assert blob_digest + with db_transaction(): try: storage = ImageStorage.get(content_checksum=blob_digest) @@ -172,6 +176,7 @@ def get_shared_blob(digest): globally accessible, such as the special empty gzipped tar layer that Docker no longer pushes to us. """ + assert digest try: return ImageStorage.get(content_checksum=digest, uploading=False) except ImageStorage.DoesNotExist: diff --git a/data/model/image.py b/data/model/image.py index 70058c8c9..50362ca2a 100644 --- a/data/model/image.py +++ b/data/model/image.py @@ -489,7 +489,8 @@ def find_or_create_derived_storage(source_image, transformation_name, preferred_ transformation=trans, uniqueness_hash=uniqueness_hash) except IntegrityError: # Storage was created while this method executed. Just return the existing. - new_storage.delete_instance(recursive=True) + ImageStoragePlacement.delete().where(ImageStoragePlacement.storage == new_storage).execute() + new_storage.delete_instance() return find_derived_storage_for_image(source_image, transformation_name, varying_metadata) return derived diff --git a/data/model/storage.py b/data/model/storage.py index e1c9541d4..2fcd926b0 100644 --- a/data/model/storage.py +++ b/data/model/storage.py @@ -189,7 +189,7 @@ def garbage_collect_storage(storage_id_whitelist): def create_v1_storage(location_name): - storage = ImageStorage.create(cas_path=False) + storage = ImageStorage.create(cas_path=False, uploading=True) location = get_image_location_for_name(location_name) ImageStoragePlacement.create(location=location.id, storage=storage) storage.locations = {location_name}