Add storage layer contexts (#10321)

Add context to all (non-trivial) calls to the storage layer. 

Contexts are propagated through the REST client.

- `context.TODO()` is left in place for the places where it needs to be added to the caller.
- `endWalkCh` could probably be removed from the walkers, but no changes so far.

The "dangerous" part is that now a caller disconnecting *will* propagate down,  so a 
"delete" operation will now be interrupted. In some cases we might want to disconnect 
this functionality so the operation completes if it has started, leaving the system in a cleaner state.
This commit is contained in:
Klaus Post
2020-09-04 09:45:06 -07:00
committed by GitHub
parent 0037951b6e
commit 2d58a8d861
36 changed files with 466 additions and 467 deletions
+5 -4
View File
@@ -19,6 +19,7 @@
package cmd
import (
"context"
"io/ioutil"
"os"
"path"
@@ -56,7 +57,7 @@ func TestIsValidUmaskVol(t *testing.T) {
// Attempt to create a volume to verify the permissions later.
// MakeVol creates 0777.
if err = disk.MakeVol(testCase.volName); err != nil {
if err = disk.MakeVol(context.Background(), testCase.volName); err != nil {
t.Fatalf("Creating a volume failed with %s expected to pass.", err)
}
defer os.RemoveAll(tmpPath)
@@ -98,7 +99,7 @@ func TestIsValidUmaskFile(t *testing.T) {
// Attempt to create a volume to verify the permissions later.
// MakeVol creates directory with 0777 perms.
if err = disk.MakeVol(testCase.volName); err != nil {
if err = disk.MakeVol(context.Background(), testCase.volName); err != nil {
t.Fatalf("Creating a volume failed with %s expected to pass.", err)
}
@@ -106,12 +107,12 @@ func TestIsValidUmaskFile(t *testing.T) {
// Attempt to create a file to verify the permissions later.
// AppendFile creates file with 0666 perms.
if err = disk.AppendFile(testCase.volName, pathJoin("hello-world.txt", xlStorageFormatFile), []byte("Hello World")); err != nil {
if err = disk.AppendFile(context.Background(), testCase.volName, pathJoin("hello-world.txt", xlStorageFormatFile), []byte("Hello World")); err != nil {
t.Fatalf("Create a file `test` failed with %s expected to pass.", err)
}
// CheckFile - stat the file.
if err := disk.CheckFile(testCase.volName, "hello-world.txt"); err != nil {
if err := disk.CheckFile(context.Background(), testCase.volName, "hello-world.txt"); err != nil {
t.Fatalf("Stat failed with %s expected to pass.", err)
}
}