mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-15 20:22:01 +01:00
Merge pull request #15104 from ywk253100/210609_art
Fix the concurrent pushing the same image issue
This commit is contained in:
commit
22d833460d
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user