2015-01-28 07:27:46 +00:00
|
|
|
package notifications
|
|
|
|
|
|
|
|
import (
|
2023-08-13 11:44:21 +00:00
|
|
|
"bytes"
|
2015-01-28 07:27:46 +00:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2020-08-24 11:18:39 +00:00
|
|
|
"github.com/distribution/distribution/v3"
|
2023-08-13 11:44:21 +00:00
|
|
|
dcontext "github.com/distribution/distribution/v3/context"
|
|
|
|
"github.com/distribution/distribution/v3/manifest/schema2"
|
2020-08-24 11:18:39 +00:00
|
|
|
"github.com/distribution/distribution/v3/registry/storage"
|
|
|
|
"github.com/distribution/distribution/v3/registry/storage/cache/memory"
|
|
|
|
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
|
|
|
|
"github.com/distribution/distribution/v3/testutil"
|
2023-08-30 15:50:56 +00:00
|
|
|
"github.com/distribution/reference"
|
2016-12-17 00:28:34 +00:00
|
|
|
"github.com/opencontainers/go-digest"
|
2015-01-28 07:27:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestListener(t *testing.T) {
|
2023-08-13 11:44:21 +00:00
|
|
|
ctx := dcontext.Background()
|
2016-04-07 00:01:30 +00:00
|
|
|
|
2023-08-13 11:44:21 +00:00
|
|
|
registry, err := storage.NewRegistry(ctx, inmemory.New(),
|
|
|
|
storage.BlobDescriptorCacheProvider(memory.NewInMemoryBlobDescriptorCacheProvider(memory.UnlimitedSize)),
|
|
|
|
storage.EnableDelete, storage.EnableRedirect)
|
2015-08-18 17:56:27 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating registry: %v", err)
|
|
|
|
}
|
2015-01-28 07:27:46 +00:00
|
|
|
tl := &testListener{
|
|
|
|
ops: make(map[string]int),
|
|
|
|
}
|
2015-04-27 22:58:58 +00:00
|
|
|
|
2017-01-14 01:06:03 +00:00
|
|
|
repoRef, _ := reference.WithName("foo/bar")
|
2015-12-15 22:35:23 +00:00
|
|
|
repository, err := registry.Repository(ctx, repoRef)
|
2015-02-13 21:59:50 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting repo: %v", err)
|
|
|
|
}
|
2018-08-03 05:58:52 +00:00
|
|
|
|
|
|
|
remover, ok := registry.(distribution.RepositoryRemover)
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("registry does not implement RepositoryRemover")
|
|
|
|
}
|
|
|
|
repository, remover = Listen(repository, remover, tl)
|
2015-01-28 07:27:46 +00:00
|
|
|
|
|
|
|
// Now take the registry through a number of operations
|
2023-08-13 11:44:21 +00:00
|
|
|
checkTestRepository(t, repository, remover)
|
2015-01-28 07:27:46 +00:00
|
|
|
|
|
|
|
expectedOps := map[string]int{
|
2016-01-28 17:56:37 +00:00
|
|
|
"manifest:push": 1,
|
|
|
|
"manifest:pull": 1,
|
|
|
|
"manifest:delete": 1,
|
2023-08-13 11:44:21 +00:00
|
|
|
"layer:push": 3,
|
|
|
|
"layer:pull": 3,
|
|
|
|
"layer:delete": 3,
|
2018-07-18 18:25:59 +00:00
|
|
|
"tag:delete": 1,
|
2018-08-03 05:58:52 +00:00
|
|
|
"repo:delete": 1,
|
2015-01-28 07:27:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(tl.ops, expectedOps) {
|
|
|
|
t.Fatalf("counts do not match:\n%v\n !=\n%v", tl.ops, expectedOps)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type testListener struct {
|
|
|
|
ops map[string]int
|
|
|
|
}
|
|
|
|
|
2016-03-18 22:30:47 +00:00
|
|
|
func (tl *testListener) ManifestPushed(repo reference.Named, m distribution.Manifest, options ...distribution.ManifestServiceOption) error {
|
2015-01-28 07:27:46 +00:00
|
|
|
tl.ops["manifest:push"]++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-18 22:30:47 +00:00
|
|
|
func (tl *testListener) ManifestPulled(repo reference.Named, m distribution.Manifest, options ...distribution.ManifestServiceOption) error {
|
2015-01-28 07:27:46 +00:00
|
|
|
tl.ops["manifest:pull"]++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-28 17:56:37 +00:00
|
|
|
func (tl *testListener) ManifestDeleted(repo reference.Named, d digest.Digest) error {
|
2015-01-28 07:27:46 +00:00
|
|
|
tl.ops["manifest:delete"]++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
func (tl *testListener) BlobPushed(repo reference.Named, desc distribution.Descriptor) error {
|
2015-01-28 07:27:46 +00:00
|
|
|
tl.ops["layer:push"]++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
func (tl *testListener) BlobPulled(repo reference.Named, desc distribution.Descriptor) error {
|
2015-01-28 07:27:46 +00:00
|
|
|
tl.ops["layer:pull"]++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
func (tl *testListener) BlobMounted(repo reference.Named, desc distribution.Descriptor, fromRepo reference.Named) error {
|
2016-01-06 23:57:35 +00:00
|
|
|
tl.ops["layer:mount"]++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-28 17:56:37 +00:00
|
|
|
func (tl *testListener) BlobDeleted(repo reference.Named, d digest.Digest) error {
|
2015-01-28 07:27:46 +00:00
|
|
|
tl.ops["layer:delete"]++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-07-18 18:25:59 +00:00
|
|
|
func (tl *testListener) TagDeleted(repo reference.Named, tag string) error {
|
|
|
|
tl.ops["tag:delete"]++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-03 05:58:52 +00:00
|
|
|
func (tl *testListener) RepoDeleted(repo reference.Named) error {
|
|
|
|
tl.ops["repo:delete"]++
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-08-13 11:44:21 +00:00
|
|
|
// checkTestRepository takes the registry through all of its operations,
|
2015-01-28 07:27:46 +00:00
|
|
|
// carrying out generic checks.
|
2023-08-13 11:44:21 +00:00
|
|
|
func checkTestRepository(t *testing.T, repository distribution.Repository, remover distribution.RepositoryRemover) {
|
2015-01-28 07:27:46 +00:00
|
|
|
// TODO(stevvooe): This would be a nice testutil function. Basically, it
|
|
|
|
// takes the registry through a common set of operations. This could be
|
|
|
|
// used to make cross-cutting updates by changing internals that affect
|
|
|
|
// update counts. Basically, it would make writing tests a lot easier.
|
2023-08-13 11:44:21 +00:00
|
|
|
// TODO: change this to use Builder
|
2015-08-21 04:50:15 +00:00
|
|
|
|
2023-08-13 11:44:21 +00:00
|
|
|
ctx := dcontext.Background()
|
2015-01-28 07:27:46 +00:00
|
|
|
tag := "thetag"
|
2015-08-21 04:50:15 +00:00
|
|
|
|
2023-08-13 11:44:21 +00:00
|
|
|
config := []byte(`{"name": "foo"}`)
|
|
|
|
configDgst := digest.FromBytes(config)
|
|
|
|
configReader := bytes.NewReader(config)
|
2015-01-28 07:27:46 +00:00
|
|
|
|
2016-01-28 17:56:37 +00:00
|
|
|
var blobDigests []digest.Digest
|
2023-08-13 11:44:21 +00:00
|
|
|
blobDigests = append(blobDigests, configDgst)
|
|
|
|
|
Refactor Blob Service API
This PR refactors the blob service API to be oriented around blob descriptors.
Identified by digests, blobs become an abstract entity that can be read and
written using a descriptor as a handle. This allows blobs to take many forms,
such as a ReadSeekCloser or a simple byte buffer, allowing blob oriented
operations to better integrate with blob agnostic APIs (such as the `io`
package). The error definitions are now better organized to reflect conditions
that can only be seen when interacting with the blob API.
The main benefit of this is to separate the much smaller metadata from large
file storage. Many benefits also follow from this. Reading and writing has
been separated into discrete services. Backend implementation is also
simplified, by reducing the amount of metadata that needs to be picked up to
simply serve a read. This also improves cacheability.
"Opening" a blob simply consists of an access check (Stat) and a path
calculation. Caching is greatly simplified and we've made the mapping of
provisional to canonical hashes a first-class concept. BlobDescriptorService
and BlobProvider can be combined in different ways to achieve varying effects.
Recommend Review Approach
-------------------------
This is a very large patch. While apologies are in order, we are getting a
considerable amount of refactoring. Most changes follow from the changes to
the root package (distribution), so start there. From there, the main changes
are in storage. Looking at (*repository).Blobs will help to understand the how
the linkedBlobStore is wired. One can explore the internals within and also
branch out into understanding the changes to the caching layer. Following the
descriptions below will also help to guide you.
To reduce the chances for regressions, it was critical that major changes to
unit tests were avoided. Where possible, they are left untouched and where
not, the spirit is hopefully captured. Pay particular attention to where
behavior may have changed.
Storage
-------
The primary changes to the `storage` package, other than the interface
updates, were to merge the layerstore and blobstore. Blob access is now
layered even further. The first layer, blobStore, exposes a global
`BlobStatter` and `BlobProvider`. Operations here provide a fast path for most
read operations that don't take access control into account. The
`linkedBlobStore` layers on top of the `blobStore`, providing repository-
scoped blob link management in the backend. The `linkedBlobStore` implements
the full `BlobStore` suite, providing access-controlled, repository-local blob
writers. The abstraction between the two is slightly broken in that
`linkedBlobStore` is the only channel under which one can write into the global
blob store. The `linkedBlobStore` also provides flexibility in that it can act
over different link sets depending on configuration. This allows us to use the
same code for signature links, manifest links and blob links. Eventually, we
will fully consolidate this storage.
The improved cache flow comes from the `linkedBlobStatter` component
of `linkedBlobStore`. Using a `cachedBlobStatter`, these combine together to
provide a simple cache hierarchy that should streamline access checks on read
and write operations, or at least provide a single path to optimize. The
metrics have been changed in a slightly incompatible way since the former
operations, Fetch and Exists, are no longer relevant.
The fileWriter and fileReader have been slightly modified to support the rest
of the changes. The most interesting is the removal of the `Stat` call from
`newFileReader`. This was the source of unnecessary round trips that were only
present to look up the size of the resulting reader. Now, one must simply pass
in the size, requiring the caller to decide whether or not the `Stat` call is
appropriate. In several cases, it turned out the caller already had the size
already. The `WriterAt` implementation has been removed from `fileWriter`,
since it is no longer required for `BlobWriter`, reducing the number of paths
which writes may take.
Cache
-----
Unfortunately, the `cache` package required a near full rewrite. It was pretty
mechanical in that the cache is oriented around the `BlobDescriptorService`
slightly modified to include the ability to set the values for individual
digests. While the implementation is oriented towards caching, it can act as a
primary store. Provisions are in place to have repository local metadata, in
addition to global metadata. Fallback is implemented as a part of the storage
package to maintain this flexibility.
One unfortunate side-effect is that caching is now repository-scoped, rather
than global. This should have little effect on performance but may increase
memory usage.
Handlers
--------
The `handlers` package has been updated to leverage the new API. For the most
part, the changes are superficial or mechanical based on the API changes. This
did expose a bug in the handling of provisional vs canonical digests that was
fixed in the unit tests.
Configuration
-------------
One user-facing change has been made to the configuration and is updated in
the associated documentation. The `layerinfo` cache parameter has been
deprecated by the `blobdescriptor` cache parameter. Both are equivalent and
configuration files should be backward compatible.
Notifications
-------------
Changes the `notification` package are simply to support the interface
changes.
Context
-------
A small change has been made to the tracing log-level. Traces have been moved
from "info" to "debug" level to reduce output when not needed.
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-05-12 07:10:29 +00:00
|
|
|
blobs := repository.Blobs(ctx)
|
2023-08-13 11:44:21 +00:00
|
|
|
|
|
|
|
// push config blob
|
|
|
|
if err := testutil.PushBlob(ctx, repository, configReader, configDgst); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then fetch the config blob
|
|
|
|
if rc, err := blobs.Open(ctx, configDgst); err != nil {
|
|
|
|
t.Fatalf("error fetching config: %v", err)
|
|
|
|
} else {
|
|
|
|
defer rc.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
m := schema2.Manifest{
|
|
|
|
Versioned: schema2.SchemaVersion,
|
|
|
|
Config: distribution.Descriptor{
|
|
|
|
MediaType: "foo/bar",
|
|
|
|
Digest: configDgst,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-01-28 07:27:46 +00:00
|
|
|
for i := 0; i < 2; i++ {
|
2019-02-05 00:01:04 +00:00
|
|
|
rs, dgst, err := testutil.CreateRandomTarFile()
|
2015-01-28 07:27:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating test layer: %v", err)
|
|
|
|
}
|
2016-01-28 17:56:37 +00:00
|
|
|
blobDigests = append(blobDigests, dgst)
|
Refactor Blob Service API
This PR refactors the blob service API to be oriented around blob descriptors.
Identified by digests, blobs become an abstract entity that can be read and
written using a descriptor as a handle. This allows blobs to take many forms,
such as a ReadSeekCloser or a simple byte buffer, allowing blob oriented
operations to better integrate with blob agnostic APIs (such as the `io`
package). The error definitions are now better organized to reflect conditions
that can only be seen when interacting with the blob API.
The main benefit of this is to separate the much smaller metadata from large
file storage. Many benefits also follow from this. Reading and writing has
been separated into discrete services. Backend implementation is also
simplified, by reducing the amount of metadata that needs to be picked up to
simply serve a read. This also improves cacheability.
"Opening" a blob simply consists of an access check (Stat) and a path
calculation. Caching is greatly simplified and we've made the mapping of
provisional to canonical hashes a first-class concept. BlobDescriptorService
and BlobProvider can be combined in different ways to achieve varying effects.
Recommend Review Approach
-------------------------
This is a very large patch. While apologies are in order, we are getting a
considerable amount of refactoring. Most changes follow from the changes to
the root package (distribution), so start there. From there, the main changes
are in storage. Looking at (*repository).Blobs will help to understand the how
the linkedBlobStore is wired. One can explore the internals within and also
branch out into understanding the changes to the caching layer. Following the
descriptions below will also help to guide you.
To reduce the chances for regressions, it was critical that major changes to
unit tests were avoided. Where possible, they are left untouched and where
not, the spirit is hopefully captured. Pay particular attention to where
behavior may have changed.
Storage
-------
The primary changes to the `storage` package, other than the interface
updates, were to merge the layerstore and blobstore. Blob access is now
layered even further. The first layer, blobStore, exposes a global
`BlobStatter` and `BlobProvider`. Operations here provide a fast path for most
read operations that don't take access control into account. The
`linkedBlobStore` layers on top of the `blobStore`, providing repository-
scoped blob link management in the backend. The `linkedBlobStore` implements
the full `BlobStore` suite, providing access-controlled, repository-local blob
writers. The abstraction between the two is slightly broken in that
`linkedBlobStore` is the only channel under which one can write into the global
blob store. The `linkedBlobStore` also provides flexibility in that it can act
over different link sets depending on configuration. This allows us to use the
same code for signature links, manifest links and blob links. Eventually, we
will fully consolidate this storage.
The improved cache flow comes from the `linkedBlobStatter` component
of `linkedBlobStore`. Using a `cachedBlobStatter`, these combine together to
provide a simple cache hierarchy that should streamline access checks on read
and write operations, or at least provide a single path to optimize. The
metrics have been changed in a slightly incompatible way since the former
operations, Fetch and Exists, are no longer relevant.
The fileWriter and fileReader have been slightly modified to support the rest
of the changes. The most interesting is the removal of the `Stat` call from
`newFileReader`. This was the source of unnecessary round trips that were only
present to look up the size of the resulting reader. Now, one must simply pass
in the size, requiring the caller to decide whether or not the `Stat` call is
appropriate. In several cases, it turned out the caller already had the size
already. The `WriterAt` implementation has been removed from `fileWriter`,
since it is no longer required for `BlobWriter`, reducing the number of paths
which writes may take.
Cache
-----
Unfortunately, the `cache` package required a near full rewrite. It was pretty
mechanical in that the cache is oriented around the `BlobDescriptorService`
slightly modified to include the ability to set the values for individual
digests. While the implementation is oriented towards caching, it can act as a
primary store. Provisions are in place to have repository local metadata, in
addition to global metadata. Fallback is implemented as a part of the storage
package to maintain this flexibility.
One unfortunate side-effect is that caching is now repository-scoped, rather
than global. This should have little effect on performance but may increase
memory usage.
Handlers
--------
The `handlers` package has been updated to leverage the new API. For the most
part, the changes are superficial or mechanical based on the API changes. This
did expose a bug in the handling of provisional vs canonical digests that was
fixed in the unit tests.
Configuration
-------------
One user-facing change has been made to the configuration and is updated in
the associated documentation. The `layerinfo` cache parameter has been
deprecated by the `blobdescriptor` cache parameter. Both are equivalent and
configuration files should be backward compatible.
Notifications
-------------
Changes the `notification` package are simply to support the interface
changes.
Context
-------
A small change has been made to the tracing log-level. Traces have been moved
from "info" to "debug" level to reduce output when not needed.
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-05-12 07:10:29 +00:00
|
|
|
|
2023-08-13 11:44:21 +00:00
|
|
|
if err := testutil.PushBlob(ctx, repository, rs, dgst); err != nil {
|
|
|
|
t.Fatal(err)
|
2015-01-28 07:27:46 +00:00
|
|
|
}
|
|
|
|
|
2023-08-13 11:44:21 +00:00
|
|
|
m.Layers = append(m.Layers, distribution.Descriptor{
|
|
|
|
MediaType: "application/octet-stream",
|
|
|
|
Digest: dgst,
|
2015-11-03 19:03:17 +00:00
|
|
|
})
|
2015-01-28 07:27:46 +00:00
|
|
|
|
Refactor Blob Service API
This PR refactors the blob service API to be oriented around blob descriptors.
Identified by digests, blobs become an abstract entity that can be read and
written using a descriptor as a handle. This allows blobs to take many forms,
such as a ReadSeekCloser or a simple byte buffer, allowing blob oriented
operations to better integrate with blob agnostic APIs (such as the `io`
package). The error definitions are now better organized to reflect conditions
that can only be seen when interacting with the blob API.
The main benefit of this is to separate the much smaller metadata from large
file storage. Many benefits also follow from this. Reading and writing has
been separated into discrete services. Backend implementation is also
simplified, by reducing the amount of metadata that needs to be picked up to
simply serve a read. This also improves cacheability.
"Opening" a blob simply consists of an access check (Stat) and a path
calculation. Caching is greatly simplified and we've made the mapping of
provisional to canonical hashes a first-class concept. BlobDescriptorService
and BlobProvider can be combined in different ways to achieve varying effects.
Recommend Review Approach
-------------------------
This is a very large patch. While apologies are in order, we are getting a
considerable amount of refactoring. Most changes follow from the changes to
the root package (distribution), so start there. From there, the main changes
are in storage. Looking at (*repository).Blobs will help to understand the how
the linkedBlobStore is wired. One can explore the internals within and also
branch out into understanding the changes to the caching layer. Following the
descriptions below will also help to guide you.
To reduce the chances for regressions, it was critical that major changes to
unit tests were avoided. Where possible, they are left untouched and where
not, the spirit is hopefully captured. Pay particular attention to where
behavior may have changed.
Storage
-------
The primary changes to the `storage` package, other than the interface
updates, were to merge the layerstore and blobstore. Blob access is now
layered even further. The first layer, blobStore, exposes a global
`BlobStatter` and `BlobProvider`. Operations here provide a fast path for most
read operations that don't take access control into account. The
`linkedBlobStore` layers on top of the `blobStore`, providing repository-
scoped blob link management in the backend. The `linkedBlobStore` implements
the full `BlobStore` suite, providing access-controlled, repository-local blob
writers. The abstraction between the two is slightly broken in that
`linkedBlobStore` is the only channel under which one can write into the global
blob store. The `linkedBlobStore` also provides flexibility in that it can act
over different link sets depending on configuration. This allows us to use the
same code for signature links, manifest links and blob links. Eventually, we
will fully consolidate this storage.
The improved cache flow comes from the `linkedBlobStatter` component
of `linkedBlobStore`. Using a `cachedBlobStatter`, these combine together to
provide a simple cache hierarchy that should streamline access checks on read
and write operations, or at least provide a single path to optimize. The
metrics have been changed in a slightly incompatible way since the former
operations, Fetch and Exists, are no longer relevant.
The fileWriter and fileReader have been slightly modified to support the rest
of the changes. The most interesting is the removal of the `Stat` call from
`newFileReader`. This was the source of unnecessary round trips that were only
present to look up the size of the resulting reader. Now, one must simply pass
in the size, requiring the caller to decide whether or not the `Stat` call is
appropriate. In several cases, it turned out the caller already had the size
already. The `WriterAt` implementation has been removed from `fileWriter`,
since it is no longer required for `BlobWriter`, reducing the number of paths
which writes may take.
Cache
-----
Unfortunately, the `cache` package required a near full rewrite. It was pretty
mechanical in that the cache is oriented around the `BlobDescriptorService`
slightly modified to include the ability to set the values for individual
digests. While the implementation is oriented towards caching, it can act as a
primary store. Provisions are in place to have repository local metadata, in
addition to global metadata. Fallback is implemented as a part of the storage
package to maintain this flexibility.
One unfortunate side-effect is that caching is now repository-scoped, rather
than global. This should have little effect on performance but may increase
memory usage.
Handlers
--------
The `handlers` package has been updated to leverage the new API. For the most
part, the changes are superficial or mechanical based on the API changes. This
did expose a bug in the handling of provisional vs canonical digests that was
fixed in the unit tests.
Configuration
-------------
One user-facing change has been made to the configuration and is updated in
the associated documentation. The `layerinfo` cache parameter has been
deprecated by the `blobdescriptor` cache parameter. Both are equivalent and
configuration files should be backward compatible.
Notifications
-------------
Changes the `notification` package are simply to support the interface
changes.
Context
-------
A small change has been made to the tracing log-level. Traces have been moved
from "info" to "debug" level to reduce output when not needed.
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-05-12 07:10:29 +00:00
|
|
|
// Then fetch the blobs
|
|
|
|
if rc, err := blobs.Open(ctx, dgst); err != nil {
|
2015-01-28 07:27:46 +00:00
|
|
|
t.Fatalf("error fetching layer: %v", err)
|
Refactor Blob Service API
This PR refactors the blob service API to be oriented around blob descriptors.
Identified by digests, blobs become an abstract entity that can be read and
written using a descriptor as a handle. This allows blobs to take many forms,
such as a ReadSeekCloser or a simple byte buffer, allowing blob oriented
operations to better integrate with blob agnostic APIs (such as the `io`
package). The error definitions are now better organized to reflect conditions
that can only be seen when interacting with the blob API.
The main benefit of this is to separate the much smaller metadata from large
file storage. Many benefits also follow from this. Reading and writing has
been separated into discrete services. Backend implementation is also
simplified, by reducing the amount of metadata that needs to be picked up to
simply serve a read. This also improves cacheability.
"Opening" a blob simply consists of an access check (Stat) and a path
calculation. Caching is greatly simplified and we've made the mapping of
provisional to canonical hashes a first-class concept. BlobDescriptorService
and BlobProvider can be combined in different ways to achieve varying effects.
Recommend Review Approach
-------------------------
This is a very large patch. While apologies are in order, we are getting a
considerable amount of refactoring. Most changes follow from the changes to
the root package (distribution), so start there. From there, the main changes
are in storage. Looking at (*repository).Blobs will help to understand the how
the linkedBlobStore is wired. One can explore the internals within and also
branch out into understanding the changes to the caching layer. Following the
descriptions below will also help to guide you.
To reduce the chances for regressions, it was critical that major changes to
unit tests were avoided. Where possible, they are left untouched and where
not, the spirit is hopefully captured. Pay particular attention to where
behavior may have changed.
Storage
-------
The primary changes to the `storage` package, other than the interface
updates, were to merge the layerstore and blobstore. Blob access is now
layered even further. The first layer, blobStore, exposes a global
`BlobStatter` and `BlobProvider`. Operations here provide a fast path for most
read operations that don't take access control into account. The
`linkedBlobStore` layers on top of the `blobStore`, providing repository-
scoped blob link management in the backend. The `linkedBlobStore` implements
the full `BlobStore` suite, providing access-controlled, repository-local blob
writers. The abstraction between the two is slightly broken in that
`linkedBlobStore` is the only channel under which one can write into the global
blob store. The `linkedBlobStore` also provides flexibility in that it can act
over different link sets depending on configuration. This allows us to use the
same code for signature links, manifest links and blob links. Eventually, we
will fully consolidate this storage.
The improved cache flow comes from the `linkedBlobStatter` component
of `linkedBlobStore`. Using a `cachedBlobStatter`, these combine together to
provide a simple cache hierarchy that should streamline access checks on read
and write operations, or at least provide a single path to optimize. The
metrics have been changed in a slightly incompatible way since the former
operations, Fetch and Exists, are no longer relevant.
The fileWriter and fileReader have been slightly modified to support the rest
of the changes. The most interesting is the removal of the `Stat` call from
`newFileReader`. This was the source of unnecessary round trips that were only
present to look up the size of the resulting reader. Now, one must simply pass
in the size, requiring the caller to decide whether or not the `Stat` call is
appropriate. In several cases, it turned out the caller already had the size
already. The `WriterAt` implementation has been removed from `fileWriter`,
since it is no longer required for `BlobWriter`, reducing the number of paths
which writes may take.
Cache
-----
Unfortunately, the `cache` package required a near full rewrite. It was pretty
mechanical in that the cache is oriented around the `BlobDescriptorService`
slightly modified to include the ability to set the values for individual
digests. While the implementation is oriented towards caching, it can act as a
primary store. Provisions are in place to have repository local metadata, in
addition to global metadata. Fallback is implemented as a part of the storage
package to maintain this flexibility.
One unfortunate side-effect is that caching is now repository-scoped, rather
than global. This should have little effect on performance but may increase
memory usage.
Handlers
--------
The `handlers` package has been updated to leverage the new API. For the most
part, the changes are superficial or mechanical based on the API changes. This
did expose a bug in the handling of provisional vs canonical digests that was
fixed in the unit tests.
Configuration
-------------
One user-facing change has been made to the configuration and is updated in
the associated documentation. The `layerinfo` cache parameter has been
deprecated by the `blobdescriptor` cache parameter. Both are equivalent and
configuration files should be backward compatible.
Notifications
-------------
Changes the `notification` package are simply to support the interface
changes.
Context
-------
A small change has been made to the tracing log-level. Traces have been moved
from "info" to "debug" level to reduce output when not needed.
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-05-12 07:10:29 +00:00
|
|
|
} else {
|
|
|
|
defer rc.Close()
|
2015-01-28 07:27:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-13 11:44:21 +00:00
|
|
|
sm, err := schema2.FromStruct(m)
|
2015-01-28 07:27:46 +00:00
|
|
|
if err != nil {
|
2023-08-13 11:44:21 +00:00
|
|
|
t.Fatal(err.Error())
|
2015-01-28 07:27:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 17:39:34 +00:00
|
|
|
manifests, err := repository.Manifests(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
2015-01-28 07:27:46 +00:00
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
var digestPut digest.Digest
|
|
|
|
if digestPut, err = manifests.Put(ctx, sm); err != nil {
|
2015-01-28 07:27:46 +00:00
|
|
|
t.Fatalf("unexpected error putting the manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
2023-08-13 11:44:21 +00:00
|
|
|
_, canonical, err := sm.Payload()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
dgst := digest.FromBytes(canonical)
|
2015-08-21 04:50:15 +00:00
|
|
|
if dgst != digestPut {
|
|
|
|
t.Fatalf("mismatching digest from payload and put")
|
2015-02-26 23:47:04 +00:00
|
|
|
}
|
|
|
|
|
2021-05-27 22:51:55 +00:00
|
|
|
if err := repository.Tags(ctx).Tag(ctx, tag, distribution.Descriptor{Digest: dgst}); err != nil {
|
|
|
|
t.Fatalf("unexpected error tagging manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
_, err = manifests.Get(ctx, dgst)
|
2015-01-28 07:27:46 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error fetching manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
2023-08-13 11:44:21 +00:00
|
|
|
err = repository.Tags(ctx).Untag(ctx, tag)
|
2021-05-27 22:51:55 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error deleting tag: %v", err)
|
|
|
|
}
|
|
|
|
|
2016-01-28 17:56:37 +00:00
|
|
|
err = manifests.Delete(ctx, dgst)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error deleting blob: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, d := range blobDigests {
|
|
|
|
err = blobs.Delete(ctx, d)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error deleting blob: %v", err)
|
|
|
|
}
|
2018-07-18 18:25:59 +00:00
|
|
|
}
|
2016-01-28 17:56:37 +00:00
|
|
|
|
2018-08-03 05:58:52 +00:00
|
|
|
err = remover.Remove(ctx, repository.Named())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error deleting repo: %v", err)
|
|
|
|
}
|
2015-01-28 07:27:46 +00:00
|
|
|
}
|