Skip to content

Commit

Permalink
manifests
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Zheng <zhengliang0901@gmail.com>
  • Loading branch information
microyahoo committed May 8, 2024
1 parent 26067e5 commit 7e99e9e
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cmd/registry/config-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ storage:
accesskey: testy
secretkey: testy
region: us-west-1
regionendpoint: http://10.9.8.73:80
regionendpoint: http://10.9.8.95:80
# forcepathstyle: true
# accelerate: false
bucket: test2
bucket: test
# encrypt: true
# chunksize: 5242880
multipartcopychunksize: 33554432
Expand Down
11 changes: 9 additions & 2 deletions registry/handlers/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"strings"
"sync"
"time"

"github.com/distribution/distribution/v3"
"github.com/distribution/distribution/v3/internal/dcontext"
Expand Down Expand Up @@ -126,7 +127,7 @@ func (imh *manifestHandler) GetManifest(w http.ResponseWriter, r *http.Request)
}
return
}
imh.Digest = desc.Digest
imh.Digest = desc.Digest // 设置 digst
}

if etagMatch(r, imh.Digest.String()) {
Expand Down Expand Up @@ -458,7 +459,9 @@ func (imh *manifestHandler) DeleteManifest(w http.ResponseWriter, r *http.Reques
return
}

err = manifests.Delete(imh, imh.Digest)
now := time.Now()
err = manifests.Delete(imh, imh.Digest) // 删除 <root>/v2/repositories/<name>/_manifests/revisions/<algorithm>/<hex digest>/link
dcontext.GetLogger(imh).Infof("DeleteImageTag with digest %s with time: %s", imh.Digest, time.Since(now))
if err != nil {
switch err {
case digest.ErrDigestUnsupported:
Expand All @@ -478,7 +481,9 @@ func (imh *manifestHandler) DeleteManifest(w http.ResponseWriter, r *http.Reques
}

tagService := imh.Repository.Tags(imh)
now = time.Now()
referencedTags, err := tagService.Lookup(imh, distribution.Descriptor{Digest: imh.Digest})
dcontext.GetLogger(imh).Infof("DeleteImageTag with lookup digest %s with time: %s", imh.Digest, time.Since(now))
if err != nil {
imh.Errors = append(imh.Errors, err)
return
Expand All @@ -490,6 +495,7 @@ func (imh *manifestHandler) DeleteManifest(w http.ResponseWriter, r *http.Reques
)
g := errgroup.Group{}
g.SetLimit(storage.DefaultConcurrencyLimit)
now = time.Now()
for _, tag := range referencedTags {
tag := tag

Expand All @@ -504,6 +510,7 @@ func (imh *manifestHandler) DeleteManifest(w http.ResponseWriter, r *http.Reques
}
_ = g.Wait() // imh will record all errors, so ignore the error of Wait()
imh.Errors = errs
dcontext.GetLogger(imh).Infof("DeleteImageTag with untag digest %s with time: %s", imh.Digest, time.Since(now))

w.WriteHeader(http.StatusAccepted)
}
2 changes: 1 addition & 1 deletion registry/storage/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (reg *registry) Repositories(ctx context.Context, repos []string, last stri

// Enumerate applies ingester to each repository
func (reg *registry) Enumerate(ctx context.Context, ingester func(string) error) error {
root, err := pathFor(repositoriesRootPathSpec{})
root, err := pathFor(repositoriesRootPathSpec{}) // <root>/v2/repositories
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion registry/storage/garbagecollect.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func MarkAndSweep(ctx context.Context, storageDriver driver.StorageDriver, regis
return fmt.Errorf("failed to construct repository: %v", err)
}

manifestService, err := repository.Manifests(ctx)
manifestService, err := repository.Manifests(ctx) // registry/storage/registry.go
if err != nil {
return fmt.Errorf("failed to construct manifest service: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions registry/storage/linkedblobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ func (lbs *linkedBlobStore) Delete(ctx context.Context, dgst digest.Digest) erro
return nil
}

func (lbs *linkedBlobStore) Enumerate(ctx context.Context, ingestor func(digest.Digest) error) error {
rootPath, err := pathFor(lbs.linkDirectoryPathSpec)
func (lbs *linkedBlobStore) Enumerate(ctx context.Context, ingestor func(digest.Digest) error) error { // registry/storage/registry.go
rootPath, err := pathFor(lbs.linkDirectoryPathSpec) // <root>/v2/repositories/<name>/_manifests/revisions/ or <root>/v2/repositories/<name>/_manifests/tags/<tag>/index/
if err != nil {
return err
}
Expand Down Expand Up @@ -366,7 +366,7 @@ type linkedBlobStatter struct {
var _ distribution.BlobDescriptorService = &linkedBlobStatter{}

func (lbs *linkedBlobStatter) Stat(ctx context.Context, dgst digest.Digest) (distribution.Descriptor, error) {
blobLinkPath, err := lbs.linkPath(lbs.repository.Named().Name(), dgst)
blobLinkPath, err := lbs.linkPath(lbs.repository.Named().Name(), dgst) // <root>/v2/repositories/<name>/_manifests/revisions/<algorithm>/<hex digest>/link
if err != nil {
return distribution.Descriptor{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion registry/storage/purgeuploads.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func getOutstandingUploads(ctx context.Context, driver storageDriver.StorageDriv
uploads := make(map[string]uploadData)

inUploadDir := false
root, err := pathFor(repositoriesRootPathSpec{})
root, err := pathFor(repositoriesRootPathSpec{}) // <root>/v2/repositories
if err != nil {
return uploads, append(errors, err)
}
Expand Down
6 changes: 3 additions & 3 deletions registry/storage/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (repo *repository) Tags(ctx context.Context) distribution.TagService {
// may be context sensitive in the future. The instance should be used similar
// to a request local.
func (repo *repository) Manifests(ctx context.Context, options ...distribution.ManifestServiceOption) (distribution.ManifestService, error) {
manifestDirectoryPathSpec := manifestRevisionsPathSpec{name: repo.name.Name()}
manifestDirectoryPathSpec := manifestRevisionsPathSpec{name: repo.name.Name()} // <root>/v2/repositories/<name>/_manifests/revisions/

var statter distribution.BlobDescriptorService = &linkedBlobStatter{
blobStore: repo.blobStore,
Expand All @@ -235,8 +235,8 @@ func (repo *repository) Manifests(ctx context.Context, options ...distribution.M

// TODO(stevvooe): linkPath limits this blob store to only
// manifests. This instance cannot be used for blob checks.
linkPath: manifestRevisionLinkPath, // <root>/v2/repositories/<name>/_manifests/revisions/<algorithm>/<hex digest>/link
linkDirectoryPathSpec: manifestDirectoryPathSpec,
linkPath: manifestRevisionLinkPath, // <root>/v2/repositories/<name>/_manifests/revisions/<algorithm>/<hex digest>/link
linkDirectoryPathSpec: manifestDirectoryPathSpec, // <root>/v2/repositories/<name>/_manifests/revisions/
}

manifestListHandler := &manifestListHandler{
Expand Down
16 changes: 8 additions & 8 deletions registry/storage/tagstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ type tagStore struct {

// All returns all tags
func (ts *tagStore) All(ctx context.Context) ([]string, error) {
pathSpec, err := pathFor(manifestTagsPathSpec{
pathSpec, err := pathFor(manifestTagsPathSpec{ // <root>/v2/repositories/<name>/_manifests/tags/
name: ts.repository.Named().Name(),
})
if err != nil {
return nil, err
}

entries, err := ts.blobStore.driver.List(ctx, pathSpec)
entries, err := ts.blobStore.driver.List(ctx, pathSpec) // 以 s3 为例,列出 <root>/v2/repositories/<name>/_manifests/tags/ 目录下的所有 entries
if err != nil {
switch err := err.(type) {
case storagedriver.PathNotFoundError:
Expand Down Expand Up @@ -82,15 +82,15 @@ func (ts *tagStore) Tag(ctx context.Context, tag string, desc distribution.Descr

// resolve the current revision for name and tag.
func (ts *tagStore) Get(ctx context.Context, tag string) (distribution.Descriptor, error) {
currentPath, err := pathFor(manifestTagCurrentPathSpec{
currentPath, err := pathFor(manifestTagCurrentPathSpec{ // <root>/v2/repositories/<name>/_manifests/tags/<tag>/current/link
name: ts.repository.Named().Name(),
tag: tag,
})
if err != nil {
return distribution.Descriptor{}, err
}

revision, err := ts.blobStore.readlink(ctx, currentPath)
revision, err := ts.blobStore.readlink(ctx, currentPath) // 从 link 文件或对象中读取对应的 revision
if err != nil {
switch err.(type) {
case storagedriver.PathNotFoundError:
Expand All @@ -105,7 +105,7 @@ func (ts *tagStore) Get(ctx context.Context, tag string) (distribution.Descripto

// Untag removes the tag association
func (ts *tagStore) Untag(ctx context.Context, tag string) error {
tagPath, err := pathFor(manifestTagPathSpec{
tagPath, err := pathFor(manifestTagPathSpec{ // <root>/v2/repositories/<name>/_manifests/tags/<tag>/
name: ts.repository.Named().Name(),
tag: tag,
})
Expand Down Expand Up @@ -168,7 +168,7 @@ func (ts *tagStore) Lookup(ctx context.Context, desc distribution.Descriptor) ([
tag: tag,
}

tagLinkPath, _ := pathFor(tagLinkPathSpec)
tagLinkPath, _ := pathFor(tagLinkPathSpec) // <root>/v2/repositories/<name>/_manifests/tags/<tag>/current/link
tagDigest, err := ts.blobStore.readlink(ctx, tagLinkPath)
if err != nil {
switch err.(type) {
Expand Down Expand Up @@ -198,7 +198,7 @@ func (ts *tagStore) Lookup(ctx context.Context, desc distribution.Descriptor) ([

func (ts *tagStore) ManifestDigests(ctx context.Context, tag string) ([]digest.Digest, error) {
tagLinkPath := func(name string, dgst digest.Digest) (string, error) {
return pathFor(manifestTagIndexEntryLinkPathSpec{
return pathFor(manifestTagIndexEntryLinkPathSpec{ // <root>/v2/repositories/<name>/_manifests/tags/<tag>/index/<algorithm>/<hex digest>/link
name: name,
tag: tag,
revision: dgst,
Expand All @@ -214,7 +214,7 @@ func (ts *tagStore) ManifestDigests(ctx context.Context, tag string) ([]digest.D
repository: ts.repository,
ctx: ctx,
linkPath: tagLinkPath,
linkDirectoryPathSpec: manifestTagIndexPathSpec{
linkDirectoryPathSpec: manifestTagIndexPathSpec{ // <root>/v2/repositories/<name>/_manifests/tags/<tag>/index/
name: ts.repository.Named().Name(),
tag: tag,
},
Expand Down
4 changes: 2 additions & 2 deletions registry/storage/vacuum.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (v Vacuum) RemoveManifest(name string, dgst digest.Digest, tags []string) e
// remove a tag manifest reference, in case of not found continue to next one
for _, tag := range tags {

tagsPath, err := pathFor(manifestTagIndexEntryPathSpec{name: name, revision: dgst, tag: tag})
tagsPath, err := pathFor(manifestTagIndexEntryPathSpec{name: name, revision: dgst, tag: tag}) // <root>/v2/repositories/<name>/_manifests/tags/<tag>/index/<algorithm>/<hex digest>/
if err != nil {
return err
}
Expand All @@ -76,7 +76,7 @@ func (v Vacuum) RemoveManifest(name string, dgst digest.Digest, tags []string) e
}
}

manifestPath, err := pathFor(manifestRevisionPathSpec{name: name, revision: dgst})
manifestPath, err := pathFor(manifestRevisionPathSpec{name: name, revision: dgst}) // <root>/v2/repositories/<name>/_manifests/revisions/<algorithm>/<hex digest>/
if err != nil {
return err
}
Expand Down

0 comments on commit 7e99e9e

Please sign in to comment.