From e4fb9375d274ffb1604e8b52740908d8c156b1aa Mon Sep 17 00:00:00 2001 From: Aditya R Date: Wed, 6 Apr 2022 20:24:32 +0530 Subject: [PATCH 1/2] storage: use race-free AddNames instead of SetNames Commits from parallel builds using `SetNames` removes `names` from storage for other builds. Use race-free atomic `AddNames` to prevent breaking of parallel builds. Signed-off-by: Aditya R --- storage/storage_image.go | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/storage/storage_image.go b/storage/storage_image.go index 5340690bc..78fcd3265 100644 --- a/storage/storage_image.go +++ b/storage/storage_image.go @@ -802,24 +802,13 @@ func (s *storageImageDestination) Commit(ctx context.Context, unparsedToplevel t return errors.Wrapf(err, "error saving big data %q for image %q", blob.String(), img.ID) } } - // Set the reference's name on the image. We don't need to worry about avoiding duplicate - // values because SetNames() will deduplicate the list that we pass to it. - if name := s.imageRef.DockerReference(); len(oldNames) > 0 || name != nil { - names := []string{} - if name != nil { - names = append(names, name.String()) + // Adds the reference's name on the image. We don't need to worry about avoiding duplicate + // values because AddNames() will deduplicate the list that we pass to it. + if name := s.imageRef.DockerReference(); name != nil { + if err := s.imageRef.transport.store.AddNames(img.ID, []string{name.String()}); err != nil { + return errors.Wrapf(err, "adding names %v to image %q", name, img.ID) } - if len(oldNames) > 0 { - names = append(names, oldNames...) - } - if err := s.imageRef.transport.store.SetNames(img.ID, names); err != nil { - if _, err2 := s.imageRef.transport.store.DeleteImage(img.ID, true); err2 != nil { - logrus.Debugf("error deleting incomplete image %q: %v", img.ID, err2) - } - logrus.Debugf("error setting names %v on image %q: %v", names, img.ID, err) - return errors.Wrapf(err, "error setting names %v on image %q", names, img.ID) - } - logrus.Debugf("set names of image %q to %v", img.ID, names) + logrus.Debugf("added name %q to image %q", name, img.ID) } // Save the unparsedToplevel's manifest. if len(toplevelManifest) != 0 { From 4c686c4a35141bb9f6b29f40f7f9c6d21b1fd1c7 Mon Sep 17 00:00:00 2001 From: Aditya R Date: Wed, 6 Apr 2022 20:27:08 +0530 Subject: [PATCH 2/2] vendor: bump c/storage to race-free release Signed-off-by: Aditya R --- go.mod | 4 +++- go.sum | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index b4d91cbf9..bf08b1b73 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/pquerna/ffjson v0.0.0-20190813045741-dac163c6c0a9 // indirect github.com/sirupsen/logrus v1.7.0 github.com/stretchr/testify v1.7.0 - github.com/ulikunitz/xz v0.5.9 + github.com/ulikunitz/xz v0.5.10 github.com/vbatts/tar-split v0.11.1 github.com/vbauerster/mpb/v5 v5.4.0 github.com/xeipuuv/gojsonpointer v0.0.0-20190809123943-df4f5c81cb3b // indirect @@ -44,3 +44,5 @@ require ( golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect ) + +replace github.com/containers/storage => github.com/flouthoc/storage v1.24.9-0.20220406143351-b050a8141d8d diff --git a/go.sum b/go.sum index ed1fdc8e2..1416eda3e 100644 --- a/go.sum +++ b/go.sum @@ -68,6 +68,8 @@ github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 h1:UhxFibDNY/bfvqU5CAUmr9zpesgbU6SWc8/B4mflAE4= github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE= +github.com/flouthoc/storage v1.24.9-0.20220406143351-b050a8141d8d h1:vAlqUKp756AAI0Ns/EK1aOUlpRkY7yPaGpFe63PfqiU= +github.com/flouthoc/storage v1.24.9-0.20220406143351-b050a8141d8d/go.mod h1:5Gjxx8EqRRuTC6J2dbQ/5SMs43SHhe3Ky+BzyeNVPZM= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -228,6 +230,7 @@ github.com/tchap/go-patricia v2.3.0+incompatible h1:GkY4dP3cEfEASBPPkWd+AmjYxhmD github.com/tchap/go-patricia v2.3.0+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ23RP/odRBOTVjwp2cDyi6I= github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I= github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= +github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vbatts/tar-split v0.11.1 h1:0Odu65rhcZ3JZaPHxl7tCI3V/C/Q9Zf82UFravl02dE=