diff --git a/endpoints/registry.py b/endpoints/registry.py index 3d681679a..7d04b6409 100644 --- a/endpoints/registry.py +++ b/endpoints/registry.py @@ -42,22 +42,10 @@ def image_is_uploading(repo_image): if repo_image is None: return False - if repo_image.storage.uploading is not None: - return repo_image.storage.uploading - - logger.warning('Checking legacy upload flag') - mark_path = store.image_mark_path(repo_image.storage.uuid) - return store.exists(mark_path) + return repo_image.storage.uploading def set_uploading_flag(repo_image, is_image_uploading): - if repo_image.storage.uploading is None and not is_image_uploading: - logger.warning('Removing legacy upload flag') - uuid = repo_image.storage.uuid - mark_path = store.image_mark_path(uuid) - if store.exists(mark_path): - store.remove(mark_path) - repo_image.storage.uploading = is_image_uploading repo_image.storage.save() @@ -191,14 +179,14 @@ def put_image_layer(namespace, repository, image_id): logger.debug('put_image_layer: Error when computing tarsum ' '{0}'.format(e)) - try: - checksum = store.get_content(store.image_checksum_path(uuid)) - except IOError: + if repo_image.storage.checksum is None: # We don't have a checksum stored yet, that's fine skipping the check. # Not removing the mark though, image is not downloadable yet. session['checksum'] = csums return make_response('true', 200) + checksum = repo_image.storage.checksum + # We check if the checksums provided matches one the one we computed if checksum not in csums: logger.warning('put_image_layer: Wrong checksum') @@ -357,10 +345,6 @@ def store_checksum(image_storage, checksum): return 'Invalid checksum format' # We store the checksum - checksum_path = store.image_checksum_path(image_storage.uuid) - store.put_content(checksum_path, checksum) - - # And store it in the db image_storage.checksum = checksum image_storage.save() @@ -425,10 +409,8 @@ def put_image_json(namespace, repository, image_id): # We cleanup any old checksum in case it's a retry after a fail profile.debug('Cleanup old checksum') - try: - store.remove(store.image_checksum_path(uuid)) - except Exception: - pass + repo_image.storage.checksum = None + repo_image.storage.save() # If we reach that point, it means that this is a new image or a retry # on a failed push diff --git a/storage/basestorage.py b/storage/basestorage.py index 93b2b64e8..9b43cb1ae 100644 --- a/storage/basestorage.py +++ b/storage/basestorage.py @@ -36,14 +36,6 @@ class BaseStorage(object): base_path = self.image_path(storage_uuid) return '{0}json'.format(base_path) - def image_mark_path(self, storage_uuid): - base_path = self.image_path(storage_uuid) - return '{0}_inprogress'.format(base_path) - - def image_checksum_path(self, storage_uuid): - base_path = self.image_path(storage_uuid) - return '{0}_checksum'.format(base_path) - def image_layer_path(self, storage_uuid): base_path = self.image_path(storage_uuid) return '{0}layer'.format(base_path) diff --git a/tools/backfilluploadingflag.py b/tools/backfilluploadingflag.py deleted file mode 100644 index 6107d1081..000000000 --- a/tools/backfilluploadingflag.py +++ /dev/null @@ -1,21 +0,0 @@ -import logging - -logging.basicConfig(level=logging.DEBUG) -logger = logging.getLogger(__name__) -logging.getLogger('boto').setLevel(logging.CRITICAL) - -from data.database import ImageStorage -from app import storage - -for image_storage in ImageStorage.select().where(ImageStorage.uploading == None): - mark_path = storage.image_mark_path(None, None, None, image_storage.uuid) - json_path = storage.image_json_path(None, None, None, image_storage.uuid) - - logger.info('Mark path: %s Json path: %s', mark_path, json_path) - - if storage.exists(json_path): - image_storage.uploading = storage.exists(mark_path) - logger.info('Image existed and was currently uploading: %s', image_storage.uploading) - image_storage.save() - else: - logger.warning('Image does not exist.') diff --git a/tools/fiximages.py b/tools/fiximages.py deleted file mode 100644 index 9c13ebc5a..000000000 --- a/tools/fiximages.py +++ /dev/null @@ -1,52 +0,0 @@ -import logging - -logging.basicConfig(level=logging.DEBUG) - -from data.database import Image, ImageStorage -from app import storage - -logger = logging.getLogger(__name__) -logging.getLogger('boto').setLevel(logging.CRITICAL) - - -def migrate_checksum(image_storage): - checksum_path = storage.image_checksum_path(image_storage.uuid) - try: - checksum = storage.get_content(checksum_path) - image_storage.checksum = checksum - logger.debug('Backfilled checksum for image: %s as: %s', image_storage.uuid, checksum) - return True - except IOError: - pass - - return False - - -def fix_images(image_storage_query): - for image_storage in image_storage_query: - dirty = False - if image_storage.checksum is None: - dirty = migrate_checksum(image_storage) - - if image_storage.uploading is None: - dirty = True - mark_path = storage.image_mark_path(image_storage.uuid) - if storage.exists(mark_path): - image_storage.uploading = True - else: - image_storage.uploading = image_storage.checksum is None - - logger.debug('Set uploading flag to %s for image: %s', image_storage.uploading, - image_storage.uuid) - - if dirty: - image_storage.save() - - -storage_to_fix = (ImageStorage.select() - .where((ImageStorage.checksum >> None) & - ((ImageStorage.uploading >> None) | (ImageStorage.uploading == False)))) - -logger.debug('Fixing %s images', storage_to_fix.count()) - -fix_images(storage_to_fix)