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:
Richard 2015-04-27 15:58:58 -07:00
parent c0d297c011
commit 5d9105bd25
30 changed files with 383 additions and 343 deletions

View file

@ -7,6 +7,7 @@ import (
"os"
"testing"
"github.com/docker/distribution/context"
"github.com/docker/distribution/digest"
storagedriver "github.com/docker/distribution/registry/storage/driver"
"github.com/docker/distribution/registry/storage/driver/inmemory"
@ -32,8 +33,9 @@ func TestSimpleWrite(t *testing.T) {
driver := inmemory.New()
path := "/random"
ctx := context.Background()
fw, err := newFileWriter(driver, path)
fw, err := newFileWriter(ctx, driver, path)
if err != nil {
t.Fatalf("unexpected error creating fileWriter: %v", err)
}
@ -49,7 +51,7 @@ func TestSimpleWrite(t *testing.T) {
t.Fatalf("unexpected write length: %d != %d", n, len(content))
}
fr, err := newFileReader(driver, path)
fr, err := newFileReader(ctx, driver, path)
if err != nil {
t.Fatalf("unexpected error creating fileReader: %v", err)
}
@ -92,7 +94,7 @@ func TestSimpleWrite(t *testing.T) {
t.Fatalf("writeat was short: %d != %d", n, len(content))
}
fr, err = newFileReader(driver, path)
fr, err = newFileReader(ctx, driver, path)
if err != nil {
t.Fatalf("unexpected error creating fileReader: %v", err)
}
@ -122,13 +124,13 @@ func TestSimpleWrite(t *testing.T) {
// Now, we copy from one path to another, running the data through the
// fileReader to fileWriter, rather than the driver.Move command to ensure
// everything is working correctly.
fr, err = newFileReader(driver, path)
fr, err = newFileReader(ctx, driver, path)
if err != nil {
t.Fatalf("unexpected error creating fileReader: %v", err)
}
defer fr.Close()
fw, err = newFileWriter(driver, "/copied")
fw, err = newFileWriter(ctx, driver, "/copied")
if err != nil {
t.Fatalf("unexpected error creating fileWriter: %v", err)
}
@ -143,7 +145,7 @@ func TestSimpleWrite(t *testing.T) {
t.Fatalf("unexpected copy length: %d != %d", nn, len(doubled))
}
fr, err = newFileReader(driver, "/copied")
fr, err = newFileReader(ctx, driver, "/copied")
if err != nil {
t.Fatalf("unexpected error creating fileReader: %v", err)
}
@ -162,7 +164,8 @@ func TestSimpleWrite(t *testing.T) {
}
func TestBufferedFileWriter(t *testing.T) {
writer, err := newFileWriter(inmemory.New(), "/random")
ctx := context.Background()
writer, err := newFileWriter(ctx, inmemory.New(), "/random")
if err != nil {
t.Fatalf("Failed to initialize bufferedFileWriter: %v", err.Error())
@ -203,8 +206,8 @@ func BenchmarkFileWriter(b *testing.B) {
driver: inmemory.New(),
path: "/random",
}
if fi, err := fw.driver.Stat(fw.path); err != nil {
ctx := context.Background()
if fi, err := fw.driver.Stat(ctx, fw.path); err != nil {
switch err := err.(type) {
case storagedriver.PathNotFoundError:
// ignore, offset is zero
@ -236,8 +239,9 @@ func BenchmarkFileWriter(b *testing.B) {
func BenchmarkBufferedFileWriter(b *testing.B) {
b.StopTimer() // not sure how long setup above will take
ctx := context.Background()
for i := 0; i < b.N; i++ {
bfw, err := newFileWriter(inmemory.New(), "/random")
bfw, err := newFileWriter(ctx, inmemory.New(), "/random")
if err != nil {
b.Fatalf("Failed to initialize bufferedFileWriter: %v", err.Error())