2016-06-14 04:12:15 -04:00
|
|
|
/*
|
2017-01-18 15:24:34 -05:00
|
|
|
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
|
2016-06-14 04:12:15 -04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2016-08-18 19:23:42 -04:00
|
|
|
package cmd
|
2016-06-14 04:12:15 -04:00
|
|
|
|
2016-07-28 19:49:59 -04:00
|
|
|
import (
|
|
|
|
"bytes"
|
2017-06-12 20:40:28 -04:00
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-07-28 19:49:59 -04:00
|
|
|
"testing"
|
2017-06-12 20:40:28 -04:00
|
|
|
|
2017-11-25 14:58:29 -05:00
|
|
|
errors2 "github.com/minio/minio/pkg/errors"
|
2017-10-22 01:30:34 -04:00
|
|
|
"github.com/minio/minio/pkg/hash"
|
2017-06-12 20:40:28 -04:00
|
|
|
"github.com/minio/minio/pkg/lock"
|
2016-07-28 19:49:59 -04:00
|
|
|
)
|
2016-06-14 04:12:15 -04:00
|
|
|
|
|
|
|
// generates a valid format.json for XL backend.
|
|
|
|
func genFormatXLValid() []*formatConfigV1 {
|
|
|
|
jbod := make([]string, 8)
|
|
|
|
formatConfigs := make([]*formatConfigV1, 8)
|
|
|
|
for index := range jbod {
|
2016-11-22 19:52:37 -05:00
|
|
|
jbod[index] = mustGetUUID()
|
2016-06-14 04:12:15 -04:00
|
|
|
}
|
|
|
|
for index := range jbod {
|
|
|
|
formatConfigs[index] = &formatConfigV1{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendXL,
|
2016-06-14 04:12:15 -04:00
|
|
|
XL: &xlFormat{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: xlFormatBackendV1,
|
2016-06-14 04:12:15 -04:00
|
|
|
Disk: jbod[index],
|
|
|
|
JBOD: jbod,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return formatConfigs
|
|
|
|
}
|
|
|
|
|
|
|
|
// generates a invalid format.json version for XL backend.
|
|
|
|
func genFormatXLInvalidVersion() []*formatConfigV1 {
|
|
|
|
jbod := make([]string, 8)
|
|
|
|
formatConfigs := make([]*formatConfigV1, 8)
|
|
|
|
for index := range jbod {
|
2016-11-22 19:52:37 -05:00
|
|
|
jbod[index] = mustGetUUID()
|
2016-06-14 04:12:15 -04:00
|
|
|
}
|
|
|
|
for index := range jbod {
|
|
|
|
formatConfigs[index] = &formatConfigV1{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendXL,
|
2016-06-14 04:12:15 -04:00
|
|
|
XL: &xlFormat{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: xlFormatBackendV1,
|
2016-06-14 04:12:15 -04:00
|
|
|
Disk: jbod[index],
|
|
|
|
JBOD: jbod,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Corrupt version numbers.
|
|
|
|
formatConfigs[0].Version = "2"
|
|
|
|
formatConfigs[3].Version = "-1"
|
|
|
|
return formatConfigs
|
|
|
|
}
|
|
|
|
|
2016-09-09 15:53:09 -04:00
|
|
|
// generates a invalid format.json version for XL backend.
|
|
|
|
func genFormatXLInvalidFormat() []*formatConfigV1 {
|
|
|
|
jbod := make([]string, 8)
|
|
|
|
formatConfigs := make([]*formatConfigV1, 8)
|
|
|
|
for index := range jbod {
|
2016-11-22 19:52:37 -05:00
|
|
|
jbod[index] = mustGetUUID()
|
2016-09-09 15:53:09 -04:00
|
|
|
}
|
|
|
|
for index := range jbod {
|
|
|
|
formatConfigs[index] = &formatConfigV1{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendXL,
|
2016-09-09 15:53:09 -04:00
|
|
|
XL: &xlFormat{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: xlFormatBackendV1,
|
2016-09-09 15:53:09 -04:00
|
|
|
Disk: jbod[index],
|
|
|
|
JBOD: jbod,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Corrupt version numbers.
|
|
|
|
formatConfigs[0].Format = "lx"
|
|
|
|
formatConfigs[3].Format = "lx"
|
|
|
|
return formatConfigs
|
|
|
|
}
|
|
|
|
|
|
|
|
// generates a invalid format.json version for XL backend.
|
|
|
|
func genFormatXLInvalidXLVersion() []*formatConfigV1 {
|
|
|
|
jbod := make([]string, 8)
|
|
|
|
formatConfigs := make([]*formatConfigV1, 8)
|
|
|
|
for index := range jbod {
|
2016-11-22 19:52:37 -05:00
|
|
|
jbod[index] = mustGetUUID()
|
2016-09-09 15:53:09 -04:00
|
|
|
}
|
|
|
|
for index := range jbod {
|
|
|
|
formatConfigs[index] = &formatConfigV1{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendXL,
|
2016-09-09 15:53:09 -04:00
|
|
|
XL: &xlFormat{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: xlFormatBackendV1,
|
2016-09-09 15:53:09 -04:00
|
|
|
Disk: jbod[index],
|
|
|
|
JBOD: jbod,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Corrupt version numbers.
|
|
|
|
formatConfigs[0].XL.Version = "10"
|
|
|
|
formatConfigs[3].XL.Version = "-1"
|
|
|
|
return formatConfigs
|
|
|
|
}
|
|
|
|
|
2016-10-05 15:48:07 -04:00
|
|
|
func genFormatFS() *formatConfigV1 {
|
|
|
|
return &formatConfigV1{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendFS,
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 15:53:09 -04:00
|
|
|
// generates a invalid format.json version for XL backend.
|
|
|
|
func genFormatXLInvalidJBODCount() []*formatConfigV1 {
|
|
|
|
jbod := make([]string, 7)
|
|
|
|
formatConfigs := make([]*formatConfigV1, 8)
|
|
|
|
for index := range jbod {
|
2016-11-22 19:52:37 -05:00
|
|
|
jbod[index] = mustGetUUID()
|
2016-09-09 15:53:09 -04:00
|
|
|
}
|
|
|
|
for index := range jbod {
|
|
|
|
formatConfigs[index] = &formatConfigV1{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendXL,
|
2016-09-09 15:53:09 -04:00
|
|
|
XL: &xlFormat{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: xlFormatBackendV1,
|
2016-09-09 15:53:09 -04:00
|
|
|
Disk: jbod[index],
|
|
|
|
JBOD: jbod,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return formatConfigs
|
|
|
|
}
|
|
|
|
|
2016-06-14 04:12:15 -04:00
|
|
|
// generates a invalid format.json JBOD for XL backend.
|
|
|
|
func genFormatXLInvalidJBOD() []*formatConfigV1 {
|
|
|
|
jbod := make([]string, 8)
|
|
|
|
formatConfigs := make([]*formatConfigV1, 8)
|
|
|
|
for index := range jbod {
|
2016-11-22 19:52:37 -05:00
|
|
|
jbod[index] = mustGetUUID()
|
2016-06-14 04:12:15 -04:00
|
|
|
}
|
|
|
|
for index := range jbod {
|
|
|
|
formatConfigs[index] = &formatConfigV1{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendXL,
|
2016-06-14 04:12:15 -04:00
|
|
|
XL: &xlFormat{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: xlFormatBackendV1,
|
2016-06-14 04:12:15 -04:00
|
|
|
Disk: jbod[index],
|
|
|
|
JBOD: jbod,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for index := range jbod {
|
2016-11-22 19:52:37 -05:00
|
|
|
jbod[index] = mustGetUUID()
|
2016-06-14 04:12:15 -04:00
|
|
|
}
|
|
|
|
// Corrupt JBOD entries on disk 6 and disk 8.
|
|
|
|
formatConfigs[5].XL.JBOD = jbod
|
|
|
|
formatConfigs[7].XL.JBOD = jbod
|
|
|
|
return formatConfigs
|
|
|
|
}
|
|
|
|
|
|
|
|
// generates a invalid format.json Disk UUID for XL backend.
|
|
|
|
func genFormatXLInvalidDisks() []*formatConfigV1 {
|
|
|
|
jbod := make([]string, 8)
|
|
|
|
formatConfigs := make([]*formatConfigV1, 8)
|
|
|
|
for index := range jbod {
|
2016-11-22 19:52:37 -05:00
|
|
|
jbod[index] = mustGetUUID()
|
2016-06-14 04:12:15 -04:00
|
|
|
}
|
|
|
|
for index := range jbod {
|
|
|
|
formatConfigs[index] = &formatConfigV1{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendXL,
|
2016-06-14 04:12:15 -04:00
|
|
|
XL: &xlFormat{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: xlFormatBackendV1,
|
2016-06-14 04:12:15 -04:00
|
|
|
Disk: jbod[index],
|
|
|
|
JBOD: jbod,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Make disk 5 and disk 8 have inconsistent disk uuid's.
|
2016-11-22 19:52:37 -05:00
|
|
|
formatConfigs[4].XL.Disk = mustGetUUID()
|
|
|
|
formatConfigs[7].XL.Disk = mustGetUUID()
|
2016-06-14 04:12:15 -04:00
|
|
|
return formatConfigs
|
|
|
|
}
|
|
|
|
|
|
|
|
// generates a invalid format.json Disk UUID in wrong order for XL backend.
|
|
|
|
func genFormatXLInvalidDisksOrder() []*formatConfigV1 {
|
|
|
|
jbod := make([]string, 8)
|
|
|
|
formatConfigs := make([]*formatConfigV1, 8)
|
|
|
|
for index := range jbod {
|
2016-11-22 19:52:37 -05:00
|
|
|
jbod[index] = mustGetUUID()
|
2016-06-14 04:12:15 -04:00
|
|
|
}
|
|
|
|
for index := range jbod {
|
|
|
|
formatConfigs[index] = &formatConfigV1{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendXL,
|
2016-06-14 04:12:15 -04:00
|
|
|
XL: &xlFormat{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: xlFormatBackendV1,
|
2016-06-14 04:12:15 -04:00
|
|
|
Disk: jbod[index],
|
|
|
|
JBOD: jbod,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Re order jbod for failure case.
|
|
|
|
var jbod1 = make([]string, 8)
|
2017-03-08 13:00:47 -05:00
|
|
|
copy(jbod1, jbod)
|
2016-06-14 04:12:15 -04:00
|
|
|
jbod1[1], jbod1[2] = jbod[2], jbod[1]
|
|
|
|
formatConfigs[2].XL.JBOD = jbod1
|
|
|
|
return formatConfigs
|
|
|
|
}
|
|
|
|
|
2016-09-09 15:53:09 -04:00
|
|
|
func prepareFormatXLHealFreshDisks(obj ObjectLayer) ([]StorageAPI, error) {
|
|
|
|
var err error
|
2016-11-16 19:42:23 -05:00
|
|
|
xl := obj.(*xlObjects)
|
2016-08-12 11:36:43 -04:00
|
|
|
|
2017-06-01 12:43:20 -04:00
|
|
|
err = obj.MakeBucketWithLocation("bucket", "")
|
2016-08-12 11:36:43 -04:00
|
|
|
if err != nil {
|
2016-09-09 15:53:09 -04:00
|
|
|
return []StorageAPI{}, err
|
2016-08-12 11:36:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bucket := "bucket"
|
|
|
|
object := "object"
|
|
|
|
|
2017-10-22 01:30:34 -04:00
|
|
|
hashReader, err := hash.NewReader(bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", "")
|
2016-08-12 11:36:43 -04:00
|
|
|
if err != nil {
|
2016-09-09 15:53:09 -04:00
|
|
|
return []StorageAPI{}, err
|
2016-08-12 11:36:43 -04:00
|
|
|
}
|
|
|
|
|
2017-10-22 01:30:34 -04:00
|
|
|
if _, err = obj.PutObject(bucket, object, hashReader, nil); err != nil {
|
|
|
|
return []StorageAPI{}, err
|
|
|
|
}
|
|
|
|
|
2016-08-12 11:36:43 -04:00
|
|
|
// Remove the content of export dir 10 but preserve .minio.sys because it is automatically
|
|
|
|
// created when minio starts
|
|
|
|
for i := 3; i <= 5; i++ {
|
2017-06-12 20:40:28 -04:00
|
|
|
if err = xl.storageDisks[i].DeleteFile(minioMetaBucket, formatConfigFile); err != nil {
|
2016-09-09 15:53:09 -04:00
|
|
|
return []StorageAPI{}, err
|
2016-08-12 11:36:43 -04:00
|
|
|
}
|
2017-06-12 20:40:28 -04:00
|
|
|
if err = xl.storageDisks[i].DeleteFile(minioMetaBucket, "tmp"); err != nil {
|
2016-09-09 15:53:09 -04:00
|
|
|
return []StorageAPI{}, err
|
2016-08-12 11:36:43 -04:00
|
|
|
}
|
|
|
|
if err = xl.storageDisks[i].DeleteFile(bucket, object+"/xl.json"); err != nil {
|
2016-09-09 15:53:09 -04:00
|
|
|
return []StorageAPI{}, err
|
2016-08-12 11:36:43 -04:00
|
|
|
}
|
|
|
|
if err = xl.storageDisks[i].DeleteFile(bucket, object+"/part.1"); err != nil {
|
2016-09-09 15:53:09 -04:00
|
|
|
return []StorageAPI{}, err
|
2016-08-12 11:36:43 -04:00
|
|
|
}
|
|
|
|
if err = xl.storageDisks[i].DeleteVol(bucket); err != nil {
|
2016-09-09 15:53:09 -04:00
|
|
|
return []StorageAPI{}, err
|
2016-08-12 11:36:43 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
permutedStorageDisks := []StorageAPI{xl.storageDisks[1], xl.storageDisks[4],
|
|
|
|
xl.storageDisks[2], xl.storageDisks[8], xl.storageDisks[6], xl.storageDisks[7],
|
|
|
|
xl.storageDisks[0], xl.storageDisks[15], xl.storageDisks[13], xl.storageDisks[14],
|
|
|
|
xl.storageDisks[3], xl.storageDisks[10], xl.storageDisks[12], xl.storageDisks[9],
|
|
|
|
xl.storageDisks[5], xl.storageDisks[11]}
|
|
|
|
|
2016-09-09 15:53:09 -04:00
|
|
|
return permutedStorageDisks, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFormatXLHealFreshDisks(t *testing.T) {
|
2016-09-09 18:32:08 -04:00
|
|
|
nDisks := 16
|
|
|
|
fsDirs, err := getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-09-09 15:53:09 -04:00
|
|
|
// Create an instance of xl backend.
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err := initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-09 15:53:09 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
storageDisks, err := prepareFormatXLHealFreshDisks(obj)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-08-03 07:37:02 -04:00
|
|
|
|
|
|
|
// Attempt to load all `format.json`.
|
|
|
|
formatConfigs, _ := loadAllFormats(storageDisks)
|
|
|
|
|
2016-08-12 11:36:43 -04:00
|
|
|
// Start healing disks
|
2017-08-03 07:37:02 -04:00
|
|
|
err = healFormatXLFreshDisks(storageDisks, formatConfigs)
|
2016-08-12 11:36:43 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("healing corrupted disk failed: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load again XL format.json to validate it
|
2016-10-14 22:57:40 -04:00
|
|
|
_, err = loadFormatXL(storageDisks, 8)
|
2016-08-12 11:36:43 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("loading healed disk failed: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean all
|
|
|
|
removeRoots(fsDirs)
|
|
|
|
}
|
|
|
|
|
2016-07-28 19:49:59 -04:00
|
|
|
// Simulate XL disks creation, delete some format.json and remove the content of
|
|
|
|
// a given disk to test healing a corrupted disk
|
2016-08-12 11:36:43 -04:00
|
|
|
func TestFormatXLHealCorruptedDisks(t *testing.T) {
|
2016-07-28 19:49:59 -04:00
|
|
|
// Create an instance of xl backend.
|
2016-08-30 22:22:27 -04:00
|
|
|
obj, fsDirs, err := prepareXL()
|
2016-07-28 19:49:59 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-11-16 19:42:23 -05:00
|
|
|
xl := obj.(*xlObjects)
|
2016-07-28 19:49:59 -04:00
|
|
|
|
2017-06-01 12:43:20 -04:00
|
|
|
err = obj.MakeBucketWithLocation("bucket", "")
|
2016-07-28 19:49:59 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bucket := "bucket"
|
|
|
|
object := "object"
|
|
|
|
|
2017-10-22 01:30:34 -04:00
|
|
|
_, err = obj.PutObject(bucket, object, mustGetHashReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), nil)
|
2016-07-28 19:49:59 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now, remove two format files.. Load them and reorder
|
2017-06-12 20:40:28 -04:00
|
|
|
if err = xl.storageDisks[3].DeleteFile(minioMetaBucket, formatConfigFile); err != nil {
|
2016-07-28 19:49:59 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-06-12 20:40:28 -04:00
|
|
|
if err = xl.storageDisks[11].DeleteFile(minioMetaBucket, formatConfigFile); err != nil {
|
2016-07-28 19:49:59 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the content of export dir 10 but preserve .minio.sys because it is automatically
|
|
|
|
// created when minio starts
|
2017-06-12 20:40:28 -04:00
|
|
|
if err = xl.storageDisks[10].DeleteFile(minioMetaBucket, formatConfigFile); err != nil {
|
2016-07-28 19:49:59 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-06-12 20:40:28 -04:00
|
|
|
if err = xl.storageDisks[10].DeleteFile(minioMetaBucket, "tmp"); err != nil {
|
2016-07-28 19:49:59 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = xl.storageDisks[10].DeleteFile(bucket, object+"/xl.json"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = xl.storageDisks[10].DeleteFile(bucket, object+"/part.1"); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err = xl.storageDisks[10].DeleteVol(bucket); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
permutedStorageDisks := []StorageAPI{xl.storageDisks[1], xl.storageDisks[4],
|
|
|
|
xl.storageDisks[2], xl.storageDisks[8], xl.storageDisks[6], xl.storageDisks[7],
|
|
|
|
xl.storageDisks[0], xl.storageDisks[15], xl.storageDisks[13], xl.storageDisks[14],
|
|
|
|
xl.storageDisks[3], xl.storageDisks[10], xl.storageDisks[12], xl.storageDisks[9],
|
|
|
|
xl.storageDisks[5], xl.storageDisks[11]}
|
|
|
|
|
2017-08-03 07:37:02 -04:00
|
|
|
formatConfigs, _ := loadAllFormats(permutedStorageDisks)
|
|
|
|
|
2016-07-28 19:49:59 -04:00
|
|
|
// Start healing disks
|
2017-08-03 07:37:02 -04:00
|
|
|
err = healFormatXLCorruptedDisks(permutedStorageDisks, formatConfigs)
|
2016-07-28 19:49:59 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("healing corrupted disk failed: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load again XL format.json to validate it
|
2016-10-14 22:57:40 -04:00
|
|
|
_, err = loadFormatXL(permutedStorageDisks, 8)
|
2016-07-28 19:49:59 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("loading healed disk failed: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean all
|
|
|
|
removeRoots(fsDirs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test on ReorderByInspection by simulating creating disks and removing
|
|
|
|
// some of format.json
|
|
|
|
func TestFormatXLReorderByInspection(t *testing.T) {
|
|
|
|
// Create an instance of xl backend.
|
2016-08-30 22:22:27 -04:00
|
|
|
obj, fsDirs, err := prepareXL()
|
2016-07-28 19:49:59 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-11-16 19:42:23 -05:00
|
|
|
xl := obj.(*xlObjects)
|
2016-07-28 19:49:59 -04:00
|
|
|
|
2017-06-01 12:43:20 -04:00
|
|
|
err = obj.MakeBucketWithLocation("bucket", "")
|
2016-07-28 19:49:59 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bucket := "bucket"
|
|
|
|
object := "object"
|
|
|
|
|
2017-10-22 01:30:34 -04:00
|
|
|
_, err = obj.PutObject(bucket, object, mustGetHashReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), nil)
|
2016-07-28 19:49:59 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now, remove two format files.. Load them and reorder
|
2017-06-12 20:40:28 -04:00
|
|
|
if err = xl.storageDisks[3].DeleteFile(minioMetaBucket, formatConfigFile); err != nil {
|
2016-07-28 19:49:59 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-06-12 20:40:28 -04:00
|
|
|
if err = xl.storageDisks[5].DeleteFile(minioMetaBucket, formatConfigFile); err != nil {
|
2016-07-28 19:49:59 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
permutedStorageDisks := []StorageAPI{xl.storageDisks[1], xl.storageDisks[4],
|
|
|
|
xl.storageDisks[2], xl.storageDisks[8], xl.storageDisks[6], xl.storageDisks[7],
|
|
|
|
xl.storageDisks[0], xl.storageDisks[15], xl.storageDisks[13], xl.storageDisks[14],
|
|
|
|
xl.storageDisks[3], xl.storageDisks[10], xl.storageDisks[12], xl.storageDisks[9],
|
|
|
|
xl.storageDisks[5], xl.storageDisks[11]}
|
|
|
|
|
|
|
|
permutedFormatConfigs, _ := loadAllFormats(permutedStorageDisks)
|
|
|
|
|
2017-08-03 07:37:02 -04:00
|
|
|
_, orderedDisks, err := reorderDisks(permutedStorageDisks, permutedFormatConfigs, false)
|
2016-07-28 19:49:59 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("error reordering disks\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
orderedDisks, err = reorderDisksByInspection(orderedDisks, permutedStorageDisks, permutedFormatConfigs)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("failed to reorder disk by inspection")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check disks reordering
|
|
|
|
for i := 0; i <= 15; i++ {
|
|
|
|
if orderedDisks[i] == nil && i != 3 && i != 5 {
|
|
|
|
t.Fatal("should not be nil")
|
|
|
|
}
|
|
|
|
if orderedDisks[i] != nil && orderedDisks[i] != xl.storageDisks[i] {
|
2016-11-15 21:14:23 -05:00
|
|
|
t.Fatal("Disks were not ordered correctly")
|
2016-07-28 19:49:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
removeRoots(fsDirs)
|
|
|
|
}
|
|
|
|
|
2016-06-14 04:12:15 -04:00
|
|
|
// Wrapper for calling FormatXL tests - currently validates
|
|
|
|
// - valid format
|
|
|
|
// - unrecognized version number
|
2016-09-09 15:53:09 -04:00
|
|
|
// - unrecognized format tag
|
|
|
|
// - unrecognized xl version
|
|
|
|
// - wrong number of JBOD entries
|
2016-06-14 04:12:15 -04:00
|
|
|
// - invalid JBOD
|
|
|
|
// - invalid Disk uuid
|
|
|
|
func TestFormatXL(t *testing.T) {
|
|
|
|
formatInputCases := [][]*formatConfigV1{
|
|
|
|
genFormatXLValid(),
|
|
|
|
genFormatXLInvalidVersion(),
|
2016-09-09 15:53:09 -04:00
|
|
|
genFormatXLInvalidFormat(),
|
|
|
|
genFormatXLInvalidXLVersion(),
|
|
|
|
genFormatXLInvalidJBODCount(),
|
2016-06-14 04:12:15 -04:00
|
|
|
genFormatXLInvalidJBOD(),
|
|
|
|
genFormatXLInvalidDisks(),
|
|
|
|
genFormatXLInvalidDisksOrder(),
|
|
|
|
}
|
|
|
|
testCases := []struct {
|
|
|
|
formatConfigs []*formatConfigV1
|
|
|
|
shouldPass bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
formatConfigs: formatInputCases[0],
|
|
|
|
shouldPass: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
formatConfigs: formatInputCases[1],
|
|
|
|
shouldPass: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
formatConfigs: formatInputCases[2],
|
|
|
|
shouldPass: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
formatConfigs: formatInputCases[3],
|
|
|
|
shouldPass: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
formatConfigs: formatInputCases[4],
|
|
|
|
shouldPass: false,
|
|
|
|
},
|
2016-09-09 15:53:09 -04:00
|
|
|
{
|
|
|
|
formatConfigs: formatInputCases[5],
|
|
|
|
shouldPass: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
formatConfigs: formatInputCases[6],
|
|
|
|
shouldPass: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
formatConfigs: formatInputCases[7],
|
|
|
|
shouldPass: false,
|
|
|
|
},
|
2016-06-14 04:12:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for i, testCase := range testCases {
|
|
|
|
err := checkFormatXL(testCase.formatConfigs)
|
|
|
|
if err != nil && testCase.shouldPass {
|
|
|
|
t.Errorf("Test %d: Expected to pass but failed with %s", i+1, err)
|
|
|
|
}
|
|
|
|
if err == nil && !testCase.shouldPass {
|
|
|
|
t.Errorf("Test %d: Expected to fail but passed instead", i+1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests uuid order verification function.
|
|
|
|
func TestSavedUUIDOrder(t *testing.T) {
|
|
|
|
uuidTestCases := make([]struct {
|
|
|
|
uuid string
|
|
|
|
shouldPass bool
|
|
|
|
}, 8)
|
|
|
|
jbod := make([]string, 8)
|
|
|
|
formatConfigs := make([]*formatConfigV1, 8)
|
|
|
|
for index := range jbod {
|
2016-11-22 19:52:37 -05:00
|
|
|
jbod[index] = mustGetUUID()
|
2016-06-14 04:12:15 -04:00
|
|
|
uuidTestCases[index].uuid = jbod[index]
|
|
|
|
uuidTestCases[index].shouldPass = true
|
|
|
|
}
|
|
|
|
for index := range jbod {
|
|
|
|
formatConfigs[index] = &formatConfigV1{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendXL,
|
2016-06-14 04:12:15 -04:00
|
|
|
XL: &xlFormat{
|
2017-06-12 20:40:28 -04:00
|
|
|
Version: xlFormatBackendV1,
|
2016-06-14 04:12:15 -04:00
|
|
|
Disk: jbod[index],
|
|
|
|
JBOD: jbod,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Re order jbod for failure case.
|
|
|
|
var jbod1 = make([]string, 8)
|
2017-03-08 13:00:47 -05:00
|
|
|
copy(jbod1, jbod)
|
2016-06-14 04:12:15 -04:00
|
|
|
jbod1[1], jbod1[2] = jbod[2], jbod[1]
|
|
|
|
formatConfigs[2].XL.JBOD = jbod1
|
|
|
|
uuidTestCases[1].shouldPass = false
|
|
|
|
uuidTestCases[2].shouldPass = false
|
|
|
|
|
|
|
|
for i, testCase := range uuidTestCases {
|
|
|
|
// Is uuid present on all JBOD ?.
|
|
|
|
if testCase.shouldPass != isSavedUUIDInOrder(testCase.uuid, formatConfigs) {
|
|
|
|
t.Errorf("Test %d: Expected to pass but failed", i+1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-09 15:53:09 -04:00
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
// Test initFormatXL() when disks are expected to return errors
|
2016-09-09 15:53:09 -04:00
|
|
|
func TestInitFormatXLErrors(t *testing.T) {
|
2016-09-09 18:32:08 -04:00
|
|
|
nDisks := 16
|
|
|
|
fsDirs, err := getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
defer removeRoots(fsDirs)
|
2016-09-09 15:53:09 -04:00
|
|
|
// Create an instance of xl backend.
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err := initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-09 15:53:09 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-16 19:42:23 -05:00
|
|
|
xl := obj.(*xlObjects)
|
2016-09-09 15:53:09 -04:00
|
|
|
|
|
|
|
testStorageDisks := make([]StorageAPI, 16)
|
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
// All disks API return disk not found
|
2016-09-09 15:53:09 -04:00
|
|
|
for i := 0; i < 16; i++ {
|
2016-11-23 18:48:10 -05:00
|
|
|
d := xl.storageDisks[i].(*retryStorage)
|
2016-09-09 15:53:09 -04:00
|
|
|
testStorageDisks[i] = &naughtyDisk{disk: d, defaultErr: errDiskNotFound}
|
|
|
|
}
|
|
|
|
if err := initFormatXL(testStorageDisks); err != errDiskNotFound {
|
|
|
|
t.Fatal("Got a different error: ", err)
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
// All disks returns disk not found in the fourth call
|
2016-09-09 15:53:09 -04:00
|
|
|
for i := 0; i < 15; i++ {
|
2016-11-23 18:48:10 -05:00
|
|
|
d := xl.storageDisks[i].(*retryStorage)
|
2016-09-09 15:53:09 -04:00
|
|
|
testStorageDisks[i] = &naughtyDisk{disk: d, defaultErr: errDiskNotFound, errors: map[int]error{0: nil, 1: nil, 2: nil}}
|
|
|
|
}
|
|
|
|
if err := initFormatXL(testStorageDisks); err != errDiskNotFound {
|
|
|
|
t.Fatal("Got a different error: ", err)
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
// All disks are nil (disk not found)
|
2016-09-09 15:53:09 -04:00
|
|
|
for i := 0; i < 15; i++ {
|
|
|
|
testStorageDisks[i] = nil
|
|
|
|
}
|
|
|
|
if err := initFormatXL(testStorageDisks); err != errDiskNotFound {
|
|
|
|
t.Fatal("Got a different error: ", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 07:37:02 -04:00
|
|
|
// Test formatErrsSummary()
|
|
|
|
func TestFormatErrsSummary(t *testing.T) {
|
|
|
|
type errSummary struct {
|
|
|
|
fc, unfmt, ntfnd, crrptd, othr int
|
2016-09-09 15:53:09 -04:00
|
|
|
}
|
2017-08-03 07:37:02 -04:00
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
errs []error
|
|
|
|
expected errSummary
|
|
|
|
}{
|
|
|
|
{nil, errSummary{0, 0, 0, 0, 0}},
|
|
|
|
{[]error{errDiskNotFound, errUnformattedDisk, errCorruptedFormat, nil, errFaultyDisk},
|
|
|
|
errSummary{1, 1, 1, 1, 1}},
|
|
|
|
{[]error{errDiskNotFound, errDiskNotFound, errCorruptedFormat, nil, nil},
|
|
|
|
errSummary{2, 0, 2, 1, 0}},
|
2016-09-09 15:53:09 -04:00
|
|
|
}
|
2017-08-03 07:37:02 -04:00
|
|
|
for i, testCase := range testCases {
|
|
|
|
a, b, c, d, e := formatErrsSummary(testCase.errs)
|
|
|
|
got := errSummary{a, b, c, d, e}
|
|
|
|
if got != testCase.expected {
|
|
|
|
t.Errorf("Test %d: Got wrong results: %#v %#v", i+1,
|
|
|
|
got, testCase.expected)
|
|
|
|
}
|
2016-09-09 15:53:09 -04:00
|
|
|
}
|
|
|
|
}
|
2016-09-10 12:54:22 -04:00
|
|
|
|
2016-12-11 18:18:55 -05:00
|
|
|
// Tests for genericFormatCheckXL()
|
|
|
|
func TestGenericFormatCheckXL(t *testing.T) {
|
2016-09-10 12:54:22 -04:00
|
|
|
var errs []error
|
|
|
|
formatConfigs := genFormatXLInvalidJBOD()
|
|
|
|
|
|
|
|
// Some disks has corrupted formats, one faulty disk
|
|
|
|
errs = []error{nil, nil, errCorruptedFormat, errCorruptedFormat, errCorruptedFormat, errCorruptedFormat,
|
|
|
|
errCorruptedFormat, errFaultyDisk}
|
2016-12-11 18:18:55 -05:00
|
|
|
if err := genericFormatCheckXL(formatConfigs, errs); err != errCorruptedFormat {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Got unexpected err: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Many faulty disks
|
|
|
|
errs = []error{nil, nil, errFaultyDisk, errFaultyDisk, errFaultyDisk, errFaultyDisk,
|
|
|
|
errCorruptedFormat, errFaultyDisk}
|
2016-12-11 18:18:55 -05:00
|
|
|
if err := genericFormatCheckXL(formatConfigs, errs); err != errXLReadQuorum {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Got unexpected err: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// All formats successfully loaded
|
|
|
|
errs = []error{nil, nil, nil, nil, nil, nil, nil, nil}
|
2016-12-11 18:18:55 -05:00
|
|
|
if err := genericFormatCheckXL(formatConfigs, errs); err == nil {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatalf("Should fail here")
|
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
errs = []error{nil}
|
2016-12-11 18:18:55 -05:00
|
|
|
if err := genericFormatCheckXL([]*formatConfigV1{genFormatFS()}, errs); err == nil {
|
|
|
|
t.Fatalf("Should fail here")
|
2016-10-05 15:48:07 -04:00
|
|
|
}
|
|
|
|
errs = []error{errFaultyDisk}
|
2016-12-11 18:18:55 -05:00
|
|
|
if err := genericFormatCheckXL([]*formatConfigV1{genFormatFS()}, errs); err == nil {
|
2016-10-05 15:48:07 -04:00
|
|
|
t.Fatalf("Should fail here")
|
|
|
|
}
|
2016-09-10 12:54:22 -04:00
|
|
|
}
|
|
|
|
|
2017-06-12 20:40:28 -04:00
|
|
|
// TestFSCheckFormatFSErr - test loadFormatFS loading older format.
|
|
|
|
func TestFSCheckFormatFSErr(t *testing.T) {
|
|
|
|
// Prepare for testing
|
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(disk)
|
2017-06-12 20:40:28 -04:00
|
|
|
|
|
|
|
// Assign a new UUID.
|
|
|
|
uuid := mustGetUUID()
|
|
|
|
|
|
|
|
// Initialize meta volume, if volume already exists ignores it.
|
|
|
|
if err := initMetaVolumeFS(disk, uuid); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testCases := []struct {
|
|
|
|
format *formatConfigV1
|
|
|
|
formatWriteErr error
|
|
|
|
formatCheckErr error
|
|
|
|
shouldPass bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
format: &formatConfigV1{
|
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendFS,
|
|
|
|
FS: &fsFormat{
|
|
|
|
Version: fsFormatBackendV1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
formatCheckErr: nil,
|
|
|
|
shouldPass: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
format: &formatConfigV1{
|
|
|
|
Version: formatFileV1,
|
|
|
|
Format: formatBackendFS,
|
|
|
|
FS: &fsFormat{
|
|
|
|
Version: "10",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
formatCheckErr: errors.New("Unknown backend FS format version '10'"),
|
|
|
|
shouldPass: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
format: &formatConfigV1{
|
|
|
|
Version: formatFileV1,
|
|
|
|
Format: "garbage",
|
|
|
|
FS: &fsFormat{
|
|
|
|
Version: fsFormatBackendV1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
formatCheckErr: errors.New("FS backend format required. Found 'garbage'"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
format: &formatConfigV1{
|
|
|
|
Version: "-1",
|
|
|
|
Format: formatBackendFS,
|
|
|
|
FS: &fsFormat{
|
|
|
|
Version: fsFormatBackendV1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
formatCheckErr: errors.New("Unknown format file version '-1'"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fsFormatPath := pathJoin(disk, minioMetaBucket, formatConfigFile)
|
|
|
|
for i, testCase := range testCases {
|
2017-08-12 22:25:43 -04:00
|
|
|
lk, err := lock.LockedOpenFile((fsFormatPath), os.O_RDWR|os.O_CREATE, 0600)
|
2017-06-12 20:40:28 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
_, err = testCase.format.WriteTo(lk)
|
|
|
|
lk.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Test %d: Expected nil, got %s", i+1, err)
|
|
|
|
}
|
|
|
|
|
2017-08-12 22:25:43 -04:00
|
|
|
lk, err = lock.LockedOpenFile((fsFormatPath), os.O_RDWR|os.O_CREATE, 0600)
|
2017-06-12 20:40:28 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
formatCfg := &formatConfigV1{}
|
|
|
|
_, err = formatCfg.ReadFrom(lk)
|
|
|
|
lk.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
err = formatCfg.CheckFS()
|
|
|
|
if err != nil && testCase.shouldPass {
|
|
|
|
t.Errorf("Test %d: Should not fail with unexpected %s, expected nil", i+1, err)
|
|
|
|
}
|
|
|
|
if err == nil && !testCase.shouldPass {
|
|
|
|
t.Errorf("Test %d: Should fail with expected %s, got nil", i+1, testCase.formatCheckErr)
|
|
|
|
}
|
|
|
|
if err != nil && !testCase.shouldPass {
|
2017-11-25 14:58:29 -05:00
|
|
|
if errors2.Cause(err).Error() != testCase.formatCheckErr.Error() {
|
2017-06-12 20:40:28 -04:00
|
|
|
t.Errorf("Test %d: Should fail with expected %s, got %s", i+1, testCase.formatCheckErr, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestFSCheckFormatFS - test loadFormatFS with healty and faulty disks
|
|
|
|
func TestFSCheckFormatFS(t *testing.T) {
|
|
|
|
// Prepare for testing
|
|
|
|
disk := filepath.Join(globalTestTmpDir, "minio-"+nextSuffix())
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(disk)
|
2017-06-12 20:40:28 -04:00
|
|
|
|
|
|
|
// Assign a new UUID.
|
|
|
|
uuid := mustGetUUID()
|
|
|
|
|
|
|
|
// Initialize meta volume, if volume already exists ignores it.
|
|
|
|
if err := initMetaVolumeFS(disk, uuid); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fsFormatPath := pathJoin(disk, minioMetaBucket, formatConfigFile)
|
2017-08-12 22:25:43 -04:00
|
|
|
lk, err := lock.LockedOpenFile((fsFormatPath), os.O_RDWR|os.O_CREATE, 0600)
|
2017-06-12 20:40:28 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
format := newFSFormatV1()
|
|
|
|
_, err = format.WriteTo(lk)
|
|
|
|
lk.Close()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loading corrupted format file
|
2017-08-12 22:25:43 -04:00
|
|
|
file, err := os.OpenFile((fsFormatPath), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
|
2017-06-12 20:40:28 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Should not fail here", err)
|
|
|
|
}
|
|
|
|
file.Write([]byte{'b'})
|
|
|
|
file.Close()
|
|
|
|
|
2017-08-12 22:25:43 -04:00
|
|
|
lk, err = lock.LockedOpenFile((fsFormatPath), os.O_RDWR|os.O_CREATE, 0600)
|
2017-06-12 20:40:28 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
format = &formatConfigV1{}
|
|
|
|
_, err = format.ReadFrom(lk)
|
|
|
|
lk.Close()
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Should return an error here")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loading format file from disk not found.
|
2017-08-12 22:25:43 -04:00
|
|
|
os.RemoveAll(disk)
|
|
|
|
_, err = lock.LockedOpenFile((fsFormatPath), os.O_RDONLY, 0600)
|
2017-06-12 20:40:28 -04:00
|
|
|
if err != nil && !os.IsNotExist(err) {
|
|
|
|
t.Fatal("Should return 'format.json' does not exist, but got", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
func TestLoadFormatXLErrs(t *testing.T) {
|
2016-09-10 22:32:18 -04:00
|
|
|
nDisks := 16
|
|
|
|
fsDirs, err := getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
defer removeRoots(fsDirs)
|
2016-09-10 22:32:18 -04:00
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
// Create an instance of xl backend.
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err := initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-10 12:54:22 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-16 19:42:23 -05:00
|
|
|
xl := obj.(*xlObjects)
|
2016-09-10 12:54:22 -04:00
|
|
|
|
|
|
|
xl.storageDisks[11] = nil
|
|
|
|
|
|
|
|
// disk 12 returns faulty disk
|
2016-11-23 18:48:10 -05:00
|
|
|
posixDisk, ok := xl.storageDisks[12].(*retryStorage)
|
2016-09-10 12:54:22 -04:00
|
|
|
if !ok {
|
2016-11-23 18:48:10 -05:00
|
|
|
t.Fatal("storage disk is not *retryStorage type")
|
2016-09-10 12:54:22 -04:00
|
|
|
}
|
|
|
|
xl.storageDisks[10] = newNaughtyDisk(posixDisk, nil, errFaultyDisk)
|
2016-10-14 22:57:40 -04:00
|
|
|
if _, err = loadFormatXL(xl.storageDisks, 8); err != errFaultyDisk {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Got an unexpected error: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
removeRoots(fsDirs)
|
|
|
|
|
2016-09-10 22:32:18 -04:00
|
|
|
fsDirs, err = getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
defer removeRoots(fsDirs)
|
2016-09-10 22:32:18 -04:00
|
|
|
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err = initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-10 12:54:22 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-16 19:42:23 -05:00
|
|
|
xl = obj.(*xlObjects)
|
2016-09-10 12:54:22 -04:00
|
|
|
|
|
|
|
// disks 0..10 returns disk not found
|
|
|
|
for i := 0; i <= 10; i++ {
|
2016-11-23 18:48:10 -05:00
|
|
|
posixDisk, ok := xl.storageDisks[i].(*retryStorage)
|
2016-09-10 12:54:22 -04:00
|
|
|
if !ok {
|
2016-11-23 18:48:10 -05:00
|
|
|
t.Fatal("storage disk is not *retryStorage type")
|
2016-09-10 12:54:22 -04:00
|
|
|
}
|
|
|
|
xl.storageDisks[i] = newNaughtyDisk(posixDisk, nil, errDiskNotFound)
|
|
|
|
}
|
2016-10-14 22:57:40 -04:00
|
|
|
if _, err = loadFormatXL(xl.storageDisks, 8); err != errXLReadQuorum {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Got an unexpected error: ", err)
|
|
|
|
}
|
|
|
|
|
2016-09-10 22:32:18 -04:00
|
|
|
fsDirs, err = getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
defer removeRoots(fsDirs)
|
2016-09-10 22:32:18 -04:00
|
|
|
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err = initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-10 12:54:22 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-16 19:42:23 -05:00
|
|
|
xl = obj.(*xlObjects)
|
2016-09-10 12:54:22 -04:00
|
|
|
|
|
|
|
// disks 0..10 returns unformatted disk
|
|
|
|
for i := 0; i <= 10; i++ {
|
2017-06-12 20:40:28 -04:00
|
|
|
if err = xl.storageDisks[i].DeleteFile(minioMetaBucket, formatConfigFile); err != nil {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2016-10-14 22:57:40 -04:00
|
|
|
if _, err = loadFormatXL(xl.storageDisks, 8); err != errUnformattedDisk {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Got an unexpected error: ", err)
|
|
|
|
}
|
|
|
|
|
2016-09-10 22:32:18 -04:00
|
|
|
fsDirs, err = getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-10-05 15:48:07 -04:00
|
|
|
defer removeRoots(fsDirs)
|
2016-09-10 22:32:18 -04:00
|
|
|
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err = initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-10 12:54:22 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-16 19:42:23 -05:00
|
|
|
xl = obj.(*xlObjects)
|
2016-09-10 12:54:22 -04:00
|
|
|
|
|
|
|
// disks 0..15 returns is nil (disk not found)
|
|
|
|
for i := 0; i < 16; i++ {
|
|
|
|
xl.storageDisks[i] = nil
|
|
|
|
}
|
2016-10-14 22:57:40 -04:00
|
|
|
if _, err := loadFormatXL(xl.storageDisks, 8); err != errDiskNotFound {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Got an unexpected error: ", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for healFormatXLCorruptedDisks() with cases which lead to errors
|
|
|
|
func TestHealFormatXLCorruptedDisksErrs(t *testing.T) {
|
2017-01-18 15:24:34 -05:00
|
|
|
root, err := newTestConfig(globalMinioDefaultRegion)
|
2016-11-16 19:42:23 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(root)
|
2016-11-16 19:42:23 -05:00
|
|
|
|
2016-09-10 22:32:18 -04:00
|
|
|
nDisks := 16
|
|
|
|
fsDirs, err := getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
// Everything is fine, should return nil
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err := initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-10 12:54:22 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-08-03 07:37:02 -04:00
|
|
|
|
2016-11-16 19:42:23 -05:00
|
|
|
xl := obj.(*xlObjects)
|
2017-08-03 07:37:02 -04:00
|
|
|
formatConfigs, _ := loadAllFormats(xl.storageDisks)
|
|
|
|
if err = healFormatXLCorruptedDisks(xl.storageDisks, formatConfigs); err != nil {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Got an unexpected error: ", err)
|
|
|
|
}
|
2016-09-10 22:32:18 -04:00
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
removeRoots(fsDirs)
|
|
|
|
|
2016-09-10 22:32:18 -04:00
|
|
|
fsDirs, err = getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
// One disk returns Faulty Disk
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err = initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-10 12:54:22 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-16 19:42:23 -05:00
|
|
|
xl = obj.(*xlObjects)
|
2016-11-23 18:48:10 -05:00
|
|
|
posixDisk, ok := xl.storageDisks[0].(*retryStorage)
|
2016-09-10 12:54:22 -04:00
|
|
|
if !ok {
|
2016-11-23 18:48:10 -05:00
|
|
|
t.Fatal("storage disk is not *retryStorage type")
|
2016-09-10 12:54:22 -04:00
|
|
|
}
|
|
|
|
xl.storageDisks[0] = newNaughtyDisk(posixDisk, nil, errFaultyDisk)
|
2017-08-03 07:37:02 -04:00
|
|
|
formatConfigs, _ = loadAllFormats(xl.storageDisks)
|
|
|
|
if err = healFormatXLCorruptedDisks(xl.storageDisks, formatConfigs); err != errFaultyDisk {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Got an unexpected error: ", err)
|
|
|
|
}
|
|
|
|
removeRoots(fsDirs)
|
|
|
|
|
2016-09-10 22:32:18 -04:00
|
|
|
fsDirs, err = getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
// Corrupted format json in one disk
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err = initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-10 12:54:22 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-16 19:42:23 -05:00
|
|
|
xl = obj.(*xlObjects)
|
2016-09-10 12:54:22 -04:00
|
|
|
for i := 0; i <= 15; i++ {
|
2017-06-12 20:40:28 -04:00
|
|
|
if err = xl.storageDisks[i].AppendFile(minioMetaBucket, formatConfigFile, []byte("corrupted data")); err != nil {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2017-08-03 07:37:02 -04:00
|
|
|
formatConfigs, _ = loadAllFormats(xl.storageDisks)
|
|
|
|
if err = healFormatXLCorruptedDisks(xl.storageDisks, formatConfigs); err == nil {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Should get a json parsing error, ")
|
|
|
|
}
|
|
|
|
removeRoots(fsDirs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tests for healFormatXLFreshDisks() with cases which lead to errors
|
|
|
|
func TestHealFormatXLFreshDisksErrs(t *testing.T) {
|
2017-01-18 15:24:34 -05:00
|
|
|
root, err := newTestConfig(globalMinioDefaultRegion)
|
2016-11-16 19:42:23 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-08-12 22:25:43 -04:00
|
|
|
defer os.RemoveAll(root)
|
2016-11-16 19:42:23 -05:00
|
|
|
|
2016-09-10 22:32:18 -04:00
|
|
|
nDisks := 16
|
|
|
|
fsDirs, err := getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
// Everything is fine, should return nil
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err := initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-10 12:54:22 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-16 19:42:23 -05:00
|
|
|
xl := obj.(*xlObjects)
|
2017-08-03 07:37:02 -04:00
|
|
|
formatConfigs, _ := loadAllFormats(xl.storageDisks)
|
|
|
|
if err = healFormatXLFreshDisks(xl.storageDisks, formatConfigs); err != nil {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Got an unexpected error: ", err)
|
|
|
|
}
|
|
|
|
removeRoots(fsDirs)
|
|
|
|
|
2016-09-10 22:32:18 -04:00
|
|
|
fsDirs, err = getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
// One disk returns Faulty Disk
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err = initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-10 12:54:22 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-16 19:42:23 -05:00
|
|
|
xl = obj.(*xlObjects)
|
2016-11-23 18:48:10 -05:00
|
|
|
posixDisk, ok := xl.storageDisks[0].(*retryStorage)
|
2016-09-10 12:54:22 -04:00
|
|
|
if !ok {
|
2016-11-23 18:48:10 -05:00
|
|
|
t.Fatal("storage disk is not *retryStorage type")
|
2016-09-10 12:54:22 -04:00
|
|
|
}
|
|
|
|
xl.storageDisks[0] = newNaughtyDisk(posixDisk, nil, errFaultyDisk)
|
2017-08-03 07:37:02 -04:00
|
|
|
formatConfigs, _ = loadAllFormats(xl.storageDisks)
|
|
|
|
if err = healFormatXLFreshDisks(xl.storageDisks, formatConfigs); err != errFaultyDisk {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Got an unexpected error: ", err)
|
|
|
|
}
|
|
|
|
removeRoots(fsDirs)
|
|
|
|
|
2016-09-10 22:32:18 -04:00
|
|
|
fsDirs, err = getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-09-10 12:54:22 -04:00
|
|
|
// One disk is not found, heal corrupted disks should return nil
|
2017-04-11 18:44:27 -04:00
|
|
|
obj, _, err = initObjectLayer(mustGetNewEndpointList(fsDirs...))
|
2016-09-10 12:54:22 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-16 19:42:23 -05:00
|
|
|
xl = obj.(*xlObjects)
|
2016-09-10 12:54:22 -04:00
|
|
|
xl.storageDisks[0] = nil
|
2017-08-03 07:37:02 -04:00
|
|
|
formatConfigs, _ = loadAllFormats(xl.storageDisks)
|
|
|
|
if err = healFormatXLFreshDisks(xl.storageDisks, formatConfigs); err != nil {
|
2016-09-10 12:54:22 -04:00
|
|
|
t.Fatal("Got an unexpected error: ", err)
|
|
|
|
}
|
|
|
|
removeRoots(fsDirs)
|
|
|
|
}
|