Merge pull request #15104 from ywk253100/210609_art

Fix the concurrent pushing the same image issue
This commit is contained in:
Wenkai Yin(尹文开) 2021-06-10 22:20:22 +08:00 committed by GitHub
commit 22d833460d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 22 deletions

View File

@ -199,21 +199,21 @@ func (c *controller) ensureArtifact(ctx context.Context, repository, digest stri
if err = orm.WithTransaction(func(ctx context.Context) error {
id, err := c.artMgr.Create(ctx, artifact)
if err != nil {
// if got conflict error, try to get the artifact again
if errors.IsConflictErr(err) {
var e error
artifact, e = c.artMgr.GetByDigest(ctx, repository, digest)
if e != nil {
err = e
}
}
return err
}
created = true
artifact.ID = id
return nil
})(ctx); err != nil && !errors.IsConflictErr(err) {
return false, nil, err
})(ctx); err != nil {
// got error that isn't conflict error, return directly
if !errors.IsConflictErr(err) {
return false, nil, err
}
// if got conflict error, try to get the artifact again
artifact, err = c.artMgr.GetByDigest(ctx, repository, digest)
if err != nil {
return false, nil, err
}
}
return created, artifact, nil

View File

@ -104,22 +104,21 @@ func (c *controller) Ensure(ctx context.Context, name string) (bool, int64, erro
Name: name,
})
if err != nil {
// if got conflict error, try to get again
if errors.IsConflictErr(err) {
var e error
repository, e = c.repoMgr.GetByName(ctx, name)
if e != nil {
err = e
} else {
id = repository.RepositoryID
}
}
return err
}
created = true
return nil
})(ctx); err != nil && !errors.IsConflictErr(err) {
return false, 0, err
})(ctx); err != nil {
// isn't conflict error, return directly
if !errors.IsConflictErr(err) {
return false, 0, err
}
// if got conflict error, try to get again
repository, err = c.repoMgr.GetByName(ctx, name)
if err != nil {
return false, 0, err
}
id = repository.RepositoryID
}
return created, id, nil