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

This commit is contained in:
Anis Elleuch 2016-09-13 19:01:10 +01:00 committed by Harshavardhana
parent 241c56e6d7
commit 51e337228e
2 changed files with 43 additions and 4 deletions

View file

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

View file

@ -17,6 +17,7 @@
package cmd
import (
"bytes"
"os"
"path/filepath"
"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)
}