Avoid hiding disk errors in some cases in FS Shutdown (#2668)

master
Anis Elleuch 8 years ago committed by Harshavardhana
parent 241c56e6d7
commit 51e337228e
  1. 10
      cmd/fs-v1.go
  2. 37
      cmd/fs-v1_test.go

@ -117,14 +117,16 @@ func (fs fsObjects) Shutdown() error {
// List if there are any multipart entries. // List if there are any multipart entries.
_, err := fs.storage.ListDir(minioMetaBucket, mpartMetaPrefix) _, err := fs.storage.ListDir(minioMetaBucket, mpartMetaPrefix)
if err != errFileNotFound { if err != errFileNotFound {
// Multipart directory is not empty hence do not remove '.minio.sys' volume. // A nil err means that multipart directory is not empty hence do not remove '.minio.sys' volume.
return nil // A non nil err means that an unexpected error occured
return err
} }
// List if there are any bucket configuration entries. // List if there are any bucket configuration entries.
_, err = fs.storage.ListDir(minioMetaBucket, bucketConfigPrefix) _, err = fs.storage.ListDir(minioMetaBucket, bucketConfigPrefix)
if err != errFileNotFound { if err != errFileNotFound {
// Bucket config directory is not empty hence do not remove '.minio.sys' volume. // A nil err means that bucket config directory is not empty hence do not remove '.minio.sys' volume.
return nil // A non nil err means that an unexpected error occured
return err
} }
// Cleanup everything else. // Cleanup everything else.
prefix := "" prefix := ""

@ -17,6 +17,7 @@
package cmd package cmd
import ( import (
"bytes"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -59,3 +60,39 @@ func TestNewFS(t *testing.T) {
} }
} }
} }
// TestFSShutdown - initialize a new FS object layer then calls Shutdown
// to check returned results
func TestFSShutdown(t *testing.T) {
// Create an FS object and shutdown it. No errors expected
disk := filepath.Join(os.TempDir(), "minio-"+nextSuffix())
obj, err := newFSObjects(disk)
if err != nil {
t.Fatal("Cannot create a new FS object: ", err)
}
fs := obj.(fsObjects)
fsStorage := fs.storage.(*posix)
bucketName := "testbucket"
objectName := "object"
objectContent := "12345"
obj.MakeBucket(bucketName)
obj.PutObject(bucketName, objectName, int64(len(objectContent)), bytes.NewReader([]byte(objectContent)), nil)
if err := fs.Shutdown(); err != nil {
t.Fatal("Cannot shutdown the FS object: ", err)
}
// Create an FS and program errors with disks when shutdown is called
for i := 1; i <= 5; i++ {
naughty := newNaughtyDisk(fsStorage, map[int]error{i: errFaultyDisk}, nil)
fs.storage = naughty
if err := fs.Shutdown(); err != errFaultyDisk {
t.Fatal(i, ", Got unexpected fs shutdown error: ", err)
}
}
removeAll(disk)
}

Loading…
Cancel
Save