Skip to content

Commit

Permalink
Merge pull request #15126 from ywk253100/210610_art_2.2
Browse files Browse the repository at this point in the history
Fix the concurrent pushing the same image issue
  • Loading branch information
ywk253100 authored Jun 15, 2021
2 parents b94de65 + 5373139 commit 722579b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
20 changes: 10 additions & 10 deletions src/controller/artifact/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions src/controller/repository/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 722579b

Please sign in to comment.