Hash v1 uploads for torrent chunks
This commit is contained in:
parent
44fcc7e44b
commit
8f80d7064b
6 changed files with 98 additions and 69 deletions
|
@ -2,10 +2,12 @@ import logging
|
|||
|
||||
from peewee import JOIN_LEFT_OUTER, fn, SQL
|
||||
|
||||
from data.model import config, db_transaction, InvalidImageException, TorrentInfoDoesNotExist
|
||||
from data.database import (ImageStorage, Image, DerivedStorageForImage, ImageStoragePlacement,
|
||||
ImageStorageLocation, ImageStorageTransformation, ImageStorageSignature,
|
||||
ImageStorageSignatureKind, Repository, Namespace, TorrentInfo)
|
||||
from data.model import (config, db_transaction, InvalidImageException, TorrentInfoDoesNotExist,
|
||||
DataModelException, _basequery)
|
||||
from data.database import (ImageStorage, Image, ImageStoragePlacement, ImageStorageLocation,
|
||||
ImageStorageTransformation, ImageStorageSignature,
|
||||
ImageStorageSignatureKind, Repository, Namespace, TorrentInfo,
|
||||
db_for_update)
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -203,6 +205,40 @@ def _reduce_as_tree(queries_to_reduce):
|
|||
return to_reduce_left.union_all(to_reduce_right)
|
||||
|
||||
|
||||
def set_image_storage_metadata(docker_image_id, namespace_name, repository_name, image_size,
|
||||
uncompressed_size):
|
||||
""" Sets metadata that is specific to the binary storage of the data, irrespective of how it
|
||||
is used in the layer tree.
|
||||
"""
|
||||
if image_size is None:
|
||||
raise DataModelException('Empty image size field')
|
||||
|
||||
query = (Image
|
||||
.select(Image, ImageStorage)
|
||||
.join(Repository)
|
||||
.join(Namespace, on=(Repository.namespace_user == Namespace.id))
|
||||
.switch(Image)
|
||||
.join(ImageStorage, JOIN_LEFT_OUTER)
|
||||
.where(Repository.name == repository_name, Namespace.username == namespace_name,
|
||||
Image.docker_image_id == docker_image_id))
|
||||
|
||||
try:
|
||||
image = db_for_update(query).get()
|
||||
except ImageStorage.DoesNotExist:
|
||||
raise InvalidImageException('No image with specified id and repository')
|
||||
|
||||
# We MUST do this here, it can't be done in the corresponding image call because the storage
|
||||
# has not yet been pushed
|
||||
image.aggregate_size = _basequery.calculate_image_aggregate_size(image.ancestors, image_size,
|
||||
image.parent)
|
||||
image.save()
|
||||
|
||||
image.storage.image_size = image_size
|
||||
image.storage.uncompressed_size = uncompressed_size
|
||||
image.storage.save()
|
||||
return image.storage
|
||||
|
||||
|
||||
def get_storage_locations(uuid):
|
||||
query = (ImageStoragePlacement
|
||||
.select()
|
||||
|
|
Reference in a new issue