Skip to content

Commit

Permalink
HEAD check for container blobs deletes blob if content store cannot find
Browse files Browse the repository at this point in the history
blob nil on repeat

logging for blob insert

Upload blob recovery during push

console cleanup
  • Loading branch information
ABastionOfSanity committed Nov 18, 2022
1 parent 3c07ed0 commit 00f3f3a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
14 changes: 12 additions & 2 deletions routers/api/packages/container/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// The uploaded blob gets stored in a special upload version to link them to the package/image
func saveAsPackageBlob(hsr packages_module.HashedSizeReader, pi *packages_service.PackageInfo) (*packages_model.PackageBlob, error) {
pb := packages_service.NewPackageBlob(hsr)

fmt.Println("saveAsPackageBlob: ", pb.HashSHA256)
exists := false

contentStore := packages_module.NewContentStore()
Expand All @@ -45,7 +45,7 @@ func saveAsPackageBlob(hsr packages_module.HashedSizeReader, pi *packages_servic
return err
}
}

fmt.Println("CREATED!!!")
if created {
if _, err := packages_model.InsertProperty(ctx, packages_model.PropertyTypePackage, p.ID, container_module.PropertyRepository, strings.ToLower(pi.Owner.LowerName+"/"+pi.Name)); err != nil {
log.Error("Error setting package property: %v", err)
Expand Down Expand Up @@ -73,6 +73,16 @@ func saveAsPackageBlob(hsr packages_module.HashedSizeReader, pi *packages_servic
log.Error("Error inserting package blob: %v", err)
return err
}
if exists {
_, err := contentStore.Get(packages_module.BlobHash256Key(pb.HashSHA256))
if err != nil {
log.Info("BLOB MODEL and ERR in ContentStore. Resaving Blob to content store ", err.Error())
if err := contentStore.Save(packages_module.BlobHash256Key(pb.HashSHA256), hsr, hsr.Size()); err != nil {
log.Error("Error saving package blob in content store during FIXITUP: %v", err)
return err
}
}
}
if !exists {
if err := contentStore.Save(packages_module.BlobHash256Key(pb.HashSHA256), hsr, hsr.Size()); err != nil {
log.Error("Error saving package blob in content store: %v", err)
Expand Down
16 changes: 16 additions & 0 deletions routers/api/packages/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,23 @@ func HeadBlob(ctx *context.Context) {
}
return
}
//check if actually in ContentStore
//if not, delete Blob and return 404
//content_store.Get()
cStore := packages_module.NewContentStore()
configReader, err := cStore.Get(packages_module.BlobHash256Key(blob.Blob.HashSHA256))
if err != nil {
log.Warn("ContentStore Get Error while HEAD for Blob: ", blob.Blob.HashSHA256, err.Error())

digest := ctx.Params("digest")

if err := deleteBlob(ctx.Package.Owner.ID, ctx.Params("image"), digest); err != nil {
log.Warn("Error while deleteBlob in HEAD: ", err.Error())
}
apiErrorDefined(ctx, errBlobUnknown)
return
}
defer configReader.Close()
setResponseHeaders(ctx.Resp, &containerHeaders{
ContentDigest: blob.Properties.GetByName(container_module.PropertyDigest),
ContentLength: blob.Blob.Size,
Expand Down
1 change: 0 additions & 1 deletion services/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ func NewPackageBlob(hsr packages_module.HashedSizeReader) *packages_model.Packag

func addFileToPackageVersion(ctx context.Context, pv *packages_model.PackageVersion, pfci *PackageFileCreationInfo) (*packages_model.PackageFile, *packages_model.PackageBlob, bool, error) {
log.Trace("Adding package file: %v, %s", pv.ID, pfci.Filename)

pb, exists, err := packages_model.GetOrInsertBlob(ctx, NewPackageBlob(pfci.Data))
if err != nil {
log.Error("Error inserting package blob: %v", err)
Expand Down

0 comments on commit 00f3f3a

Please sign in to comment.