Skip to content

Refactor Blob Service API - #519

Merged
stevvooe merged 1 commit into
distribution:masterfrom
stevvooe:blob-service-refactor
May 16, 2015
Merged

stevvooe merged 1 commit into
distribution:masterfrom
stevvooe:blob-service-refactor

Conversation

@stevvooe

Copy link
Copy Markdown
Collaborator

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 errors 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 BlobReadService 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 BlobDescriptorService and BlobReadService. 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 a repository- scoped blob link management in the backend. The linkedBlobStore implements the full BlobService 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 linkedBlobDescriptorStore component of linkedBlobStore. Using a cachedBlobDescriptorStore, 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.

@stevvooe stevvooe added this to the Registry/2.1 milestone May 12, 2015
@stevvooe
stevvooe force-pushed the blob-service-refactor branch 2 times, most recently from 5370095 to fb80672 Compare May 12, 2015 23:11
@stevvooe
stevvooe force-pushed the blob-service-refactor branch from fb80672 to 38308ed Compare May 12, 2015 23:19
Comment thread notifications/listener.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be bsl.BlobService.Get

@stevvooe
stevvooe force-pushed the blob-service-refactor branch 3 times, most recently from 6e25dd6 to 406f4c5 Compare May 13, 2015 01:53
@dmp42

dmp42 commented May 13, 2015

Copy link
Copy Markdown
Contributor

This is solid work.

Indeed a big changeset - calling @noxiouz @ahmetalpbalkan @ncdc @RichardScothern to the rescue for additional reviews - we should merge this ASAP and avoid it to linger for too long so additional work can move forward on top of this.

@ncdc

ncdc commented May 13, 2015

Copy link
Copy Markdown

I'm out of the office and can take a look next week. Cc @vbatts
On Wed, May 13, 2015 at 1:38 AM Olivier Gambier [email protected]
wrote:

This is solid work.

Indeed a big changeset - calling @noxiouz https://github.com/noxiouz
@ahmetalpbalkan https://github.com/ahmetalpbalkan @ncdc
https://github.com/ncdc @RichardScothern
https://github.com/RichardScothern to the rescue for additional reviews

  • we should merge this ASAP and avoid it to linger for too long so
    additional work can move forward on top of this.

—
Reply to this email directly or view it on GitHub
#519 (comment).

@noxiouz

noxiouz commented May 13, 2015

Copy link
Copy Markdown
Contributor

@dmp42 thank you for calling me. I'm going to look at it a couple hours later.

@stevvooe stevvooe mentioned this pull request May 13, 2015
6 of 7 tasks
Comment thread registry/handlers/blobupload.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think return is missing there.

Comment thread blobs.go Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to Reader()?
it closer describes what the function does, and has symmetry with (BlobWriteService).Writer()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document why we are using descriptors instead of digest here. There is a fantastic reason.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RichardScothern I think we are going to change Writer to something else.

@dmcgowan

Copy link
Copy Markdown
Collaborator

The changes look good and someone has to be first to drop it, but let me preface...

Having to pass along such a powerful interface such as a repository to every object is an unfortunate pattern that this changes makes steps to breaking. repository.Name() occurs many times and often only the name is needed. There were a few cases were it was confusing whether repository.ctx or .ctx should be used directly. These mixups will always occur when direct access is allowed to a powerful parent object. This change is progress though!

Also a few nits to address, but...

LGTM

@tiborvass

Copy link
Copy Markdown
Contributor

Apart from name bikesheddings and splitting BlobReadService into BlobReadService and BlobServer, the interface looks solid and super well thought-out. Like I told @stevvooe, it would be super helpful to have in a later document somewhere, detailed explanations on why this design was chosen, mentioning different scenarios as well as how/where optimizations can happen.

Design LGTM (didn't read implementation)

Comment thread blobs.go Outdated

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider not using Descriptor here, rather than digest. We do get an optimization here by passing in the length and mediatype, but at the same time, this could be set by the caller.

@stevvooe

Copy link
Copy Markdown
Collaborator Author

@dmcgowan I agree about the issue with having to pass Repository around. Really, it should represent the data structure Repository throughout the application, but it does carry baggage. Part of this comes from the original intent of the code, which avoided using the repository name as a string field. The other half comes from the lack of type safety we have for repository names.

I'll see if I can simplify this aspect slightly.

@stevvooe
stevvooe force-pushed the blob-service-refactor branch from 406f4c5 to 9e7bbed Compare May 15, 2015 09:44
@stevvooe

Copy link
Copy Markdown
Collaborator Author

Updates:

  • Using errors.New where it makes sense
  • Writer is now Create and Rollback is now Cancel. The bikeshed is now painted.
  • Made blob oriented service definitions more granular. We now have BlobServer, BlobService and BlobStore.
  • Clarified godocs in blobs.go.
  • Removed descriptors from Open and ServeBlob by leveraging better separation with BlobStatter.
  • Cache control max-age moved to a constant and increased to one year

@stevvooe
stevvooe force-pushed the blob-service-refactor branch from 9e7bbed to 67e856b Compare May 15, 2015 09:46
Comment thread registry/storage/signaturestore.go Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong context, I would expect to use s.ctx

@stevvooe
stevvooe force-pushed the blob-service-refactor branch from 67e856b to fee9ca5 Compare May 15, 2015 23:57
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 <[email protected]>
@dmcgowan

Copy link
Copy Markdown
Collaborator

LGTM

stevvooe added a commit that referenced this pull request May 16, 2015
@stevvooe
stevvooe merged commit ace71ea into distribution:master May 16, 2015
@stevvooe
stevvooe deleted the blob-service-refactor branch May 16, 2015 00:52
thaJeztah pushed a commit to thaJeztah/distribution that referenced this pull request Apr 22, 2021
thaJeztah pushed a commit to thaJeztah/distribution that referenced this pull request Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants