Eradicate the s3 versions of the checksum and the uploading flag.
This commit is contained in:
parent
af9b0904d9
commit
fb465fd66f
4 changed files with 6 additions and 105 deletions
|
@ -42,22 +42,10 @@ def image_is_uploading(repo_image):
|
||||||
if repo_image is None:
|
if repo_image is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if repo_image.storage.uploading is not None:
|
|
||||||
return repo_image.storage.uploading
|
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)
|
|
||||||
|
|
||||||
|
|
||||||
def set_uploading_flag(repo_image, is_image_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.uploading = is_image_uploading
|
||||||
repo_image.storage.save()
|
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 '
|
logger.debug('put_image_layer: Error when computing tarsum '
|
||||||
'{0}'.format(e))
|
'{0}'.format(e))
|
||||||
|
|
||||||
try:
|
if repo_image.storage.checksum is None:
|
||||||
checksum = store.get_content(store.image_checksum_path(uuid))
|
|
||||||
except IOError:
|
|
||||||
# We don't have a checksum stored yet, that's fine skipping the check.
|
# We don't have a checksum stored yet, that's fine skipping the check.
|
||||||
# Not removing the mark though, image is not downloadable yet.
|
# Not removing the mark though, image is not downloadable yet.
|
||||||
session['checksum'] = csums
|
session['checksum'] = csums
|
||||||
return make_response('true', 200)
|
return make_response('true', 200)
|
||||||
|
|
||||||
|
checksum = repo_image.storage.checksum
|
||||||
|
|
||||||
# We check if the checksums provided matches one the one we computed
|
# We check if the checksums provided matches one the one we computed
|
||||||
if checksum not in csums:
|
if checksum not in csums:
|
||||||
logger.warning('put_image_layer: Wrong checksum')
|
logger.warning('put_image_layer: Wrong checksum')
|
||||||
|
@ -357,10 +345,6 @@ def store_checksum(image_storage, checksum):
|
||||||
return 'Invalid checksum format'
|
return 'Invalid checksum format'
|
||||||
|
|
||||||
# We store the checksum
|
# 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.checksum = checksum
|
||||||
image_storage.save()
|
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
|
# We cleanup any old checksum in case it's a retry after a fail
|
||||||
profile.debug('Cleanup old checksum')
|
profile.debug('Cleanup old checksum')
|
||||||
try:
|
repo_image.storage.checksum = None
|
||||||
store.remove(store.image_checksum_path(uuid))
|
repo_image.storage.save()
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# If we reach that point, it means that this is a new image or a retry
|
# If we reach that point, it means that this is a new image or a retry
|
||||||
# on a failed push
|
# on a failed push
|
||||||
|
|
|
@ -36,14 +36,6 @@ class BaseStorage(object):
|
||||||
base_path = self.image_path(storage_uuid)
|
base_path = self.image_path(storage_uuid)
|
||||||
return '{0}json'.format(base_path)
|
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):
|
def image_layer_path(self, storage_uuid):
|
||||||
base_path = self.image_path(storage_uuid)
|
base_path = self.image_path(storage_uuid)
|
||||||
return '{0}layer'.format(base_path)
|
return '{0}layer'.format(base_path)
|
||||||
|
|
|
@ -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.')
|
|
|
@ -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)
|
|
Reference in a new issue