Make Storage Driver API calls context aware.
- Change driver interface to take a context as its first argument - Make newFileReader take a context as its first argument - Make newFileWriter take a context as its first argument - Make blobstore exists and delete take a context as a first argument - Pass the layerreader's context to the storage layer - Pass the app's context to purgeuploads - Store the app's context into the blobstore (was previously null) - Pass the trace'd context to the storage drivers Signed-off-by: Richard Scothern <richard.scothern@gmail.com>
This commit is contained in:
parent
c0d297c011
commit
5d9105bd25
30 changed files with 383 additions and 343 deletions
|
@ -7,6 +7,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
|
||||
"github.com/docker/distribution/context"
|
||||
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
||||
)
|
||||
|
||||
|
@ -18,6 +19,8 @@ const (
|
|||
type fileWriter struct {
|
||||
driver storagedriver.StorageDriver
|
||||
|
||||
ctx context.Context
|
||||
|
||||
// identifying fields
|
||||
path string
|
||||
|
||||
|
@ -45,13 +48,14 @@ var _ fileWriterInterface = &fileWriter{}
|
|||
|
||||
// newFileWriter returns a prepared fileWriter for the driver and path. This
|
||||
// could be considered similar to an "open" call on a regular filesystem.
|
||||
func newFileWriter(driver storagedriver.StorageDriver, path string) (*bufferedFileWriter, error) {
|
||||
func newFileWriter(ctx context.Context, driver storagedriver.StorageDriver, path string) (*bufferedFileWriter, error) {
|
||||
fw := fileWriter{
|
||||
driver: driver,
|
||||
path: path,
|
||||
ctx: ctx,
|
||||
}
|
||||
|
||||
if fi, err := driver.Stat(path); err != nil {
|
||||
if fi, err := driver.Stat(ctx, path); err != nil {
|
||||
switch err := err.(type) {
|
||||
case storagedriver.PathNotFoundError:
|
||||
// ignore, offset is zero
|
||||
|
@ -179,7 +183,7 @@ func (fw *fileWriter) readFromAt(r io.Reader, offset int64) (n int64, err error)
|
|||
updateOffset = true
|
||||
}
|
||||
|
||||
nn, err := fw.driver.WriteStream(fw.path, offset, r)
|
||||
nn, err := fw.driver.WriteStream(fw.ctx, fw.path, offset, r)
|
||||
|
||||
if updateOffset {
|
||||
// We should forward the offset, whether or not there was an error.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue