Skip to content

Commit

Permalink
🐛 Fix gc artifact for multi-arch manifest (#336)
Browse files Browse the repository at this point in the history
gc the multi-arch manifest need twice gc, first delete the manifest index,
second delete the reference manifest
  • Loading branch information
tosone authored Mar 11, 2024
1 parent 211d46e commit e28bf37
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
15 changes: 9 additions & 6 deletions pkg/daemon/gc/gc_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,15 @@ func (g gcArtifact) deleteArtifactCheck() {
continue
}
// 3. check manifest index associate with this artifact
err = artifactService.IsArtifactAssociatedWithArtifact(g.ctx, task.Artifact.ID)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
log.Error().Err(err).Int64("repositoryID", task.Artifact.RepositoryID).Int64("artifactID", task.Artifact.ID).Msg("Get manifest associated with manifest index failed")
}
if err == nil {
continue
if !(task.Artifact.ContentType == "application/vnd.docker.distribution.manifest.list.v2+json" ||
task.Artifact.ContentType == "application/vnd.oci.image.index.v1+json") { // skip this check if artifact is manifest index
err = artifactService.IsArtifactAssociatedWithArtifact(g.ctx, task.Artifact.ID)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
log.Error().Err(err).Int64("repositoryID", task.Artifact.RepositoryID).Int64("artifactID", task.Artifact.ID).Msg("Get manifest associated with manifest index failed")
}
if err == nil {
continue
}
}
// 4. delete the artifact that referrer to this artifact
delArtifacts, err := artifactService.GetReferrers(g.ctx, task.Artifact.RepositoryID, task.Artifact.Digest, nil)
Expand Down
4 changes: 2 additions & 2 deletions pkg/dal/dao/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ func (s *artifactService) Create(ctx context.Context, artifact *models.Artifact)
// FindWithLastPull ...
func (s *artifactService) FindWithLastPull(ctx context.Context, repositoryID int64, before int64, limit, last int64) ([]*models.Artifact, error) {
return s.tx.Artifact.WithContext(ctx).
Where(s.tx.Artifact.ID.Gt(last), s.tx.Artifact.RepositoryID.Eq(repositoryID)).
Where(s.tx.Artifact.LastPull.Lt(before)).
Or(s.tx.Artifact.LastPull.IsNull(), s.tx.Artifact.UpdatedAt.Lt(before)).
Where(s.tx.Artifact.ID.Gt(last), s.tx.Artifact.RepositoryID.Eq(repositoryID)).
Limit(int(limit)).Find()
Limit(int(limit)).Order(s.tx.Artifact.ID).Find()
}

// FindAssociateWithTag ...
Expand Down
2 changes: 1 addition & 1 deletion pkg/dal/dao/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *blobService) FindWithLastPull(ctx context.Context, before int64, last,
Where(s.tx.Blob.ID.Gt(last)).
Where(s.tx.Blob.LastPull.Lt(before)).
Or(s.tx.Blob.LastPull.IsNull(), s.tx.Blob.UpdatedAt.Lt(before)).
Find()
Order(s.tx.Blob.ID).Find()
}

// FindAssociateWithArtifact ...
Expand Down
2 changes: 1 addition & 1 deletion pkg/dal/models/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type ArtifactSizeByNamespaceOrRepository interface {

// ArtifactAssociated ...
type ArtifactAssociated interface {
// SELECT COUNT(artifact_id) as count FROM artifact_artifacts LEFT JOIN artifacts ON artifacts.id = artifact_artifacts.artifact_index_id WHERE artifacts.deleted_at = 0 AND artifact_index_id=@artifactID
// SELECT COUNT(artifact_id) as count FROM artifact_artifacts LEFT JOIN artifacts ON artifacts.id = artifact_artifacts.artifact_id WHERE artifacts.deleted_at = 0 AND artifact_index_id=@artifactID
ArtifactAssociated(artifactID int64) (gen.M, error)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/dal/query/artifacts.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e28bf37

Please sign in to comment.