2016-06-21 18:48:27 -04:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2016 MinIO, Inc.
|
2016-06-21 18:48:27 -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-21 18:48:27 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2020-04-14 20:52:38 -04:00
|
|
|
"context"
|
2016-07-21 16:15:54 -04:00
|
|
|
"io/ioutil"
|
2016-10-08 20:08:17 -04:00
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"reflect"
|
2016-06-21 18:48:27 -04:00
|
|
|
"testing"
|
2016-10-08 20:08:17 -04:00
|
|
|
"time"
|
2016-11-22 21:18:22 -05:00
|
|
|
|
|
|
|
humanize "github.com/dustin/go-humanize"
|
2019-10-07 01:50:24 -04:00
|
|
|
"github.com/minio/minio/cmd/config/storageclass"
|
2019-03-14 16:08:51 -04:00
|
|
|
"github.com/minio/minio/pkg/madmin"
|
2016-06-21 18:48:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepeatPutObjectPart(t *testing.T) {
|
2020-04-14 20:52:38 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2016-06-21 18:48:27 -04:00
|
|
|
var objLayer ObjectLayer
|
|
|
|
var disks []string
|
|
|
|
var err error
|
2018-09-10 12:42:43 -04:00
|
|
|
var opts ObjectOptions
|
2016-06-21 18:48:27 -04:00
|
|
|
|
2020-04-14 20:52:38 -04:00
|
|
|
objLayer, disks, err = prepareXL16(ctx)
|
2016-06-21 18:48:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleaning up of temporary test directories
|
|
|
|
defer removeRoots(disks)
|
|
|
|
|
2020-05-08 16:44:44 -04:00
|
|
|
err = objLayer.MakeBucketWithLocation(ctx, "bucket1", "", false)
|
2016-06-21 18:48:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-04-14 20:52:38 -04:00
|
|
|
uploadID, err := objLayer.NewMultipartUpload(ctx, "bucket1", "mpartObj1", opts)
|
2016-06-21 18:48:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-11-22 21:18:22 -05:00
|
|
|
fiveMBBytes := bytes.Repeat([]byte("a"), 5*humanize.MiByte)
|
2016-11-21 16:51:05 -05:00
|
|
|
md5Hex := getMD5Hash(fiveMBBytes)
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = objLayer.PutObjectPart(ctx, "bucket1", "mpartObj1", uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(fiveMBBytes), 5*humanize.MiByte, md5Hex, ""), opts)
|
2016-06-21 18:48:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// PutObjectPart should succeed even if part already exists. ref: https://github.com/minio/minio/issues/1930
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = objLayer.PutObjectPart(ctx, "bucket1", "mpartObj1", uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(fiveMBBytes), 5*humanize.MiByte, md5Hex, ""), opts)
|
2016-06-21 18:48:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2016-07-21 16:15:54 -04:00
|
|
|
|
|
|
|
func TestXLDeleteObjectBasic(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
bucket string
|
|
|
|
object string
|
|
|
|
expectedErr error
|
|
|
|
}{
|
2018-08-31 16:16:35 -04:00
|
|
|
{".test", "dir/obj", BucketNameInvalid{Bucket: ".test"}},
|
|
|
|
{"----", "dir/obj", BucketNameInvalid{Bucket: "----"}},
|
2016-07-21 16:15:54 -04:00
|
|
|
{"bucket", "", ObjectNameInvalid{Bucket: "bucket", Object: ""}},
|
|
|
|
{"bucket", "doesnotexist", ObjectNotFound{Bucket: "bucket", Object: "doesnotexist"}},
|
2018-08-31 16:16:35 -04:00
|
|
|
{"bucket", "dir/doesnotexist", ObjectNotFound{Bucket: "bucket", Object: "dir/doesnotexist"}},
|
|
|
|
{"bucket", "dir", ObjectNotFound{Bucket: "bucket", Object: "dir"}},
|
|
|
|
{"bucket", "dir/", ObjectNotFound{Bucket: "bucket", Object: "dir/"}},
|
|
|
|
{"bucket", "dir/obj", nil},
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
|
|
|
|
2020-04-14 20:52:38 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2016-07-21 16:15:54 -04:00
|
|
|
// Create an instance of xl backend
|
2020-04-14 20:52:38 -04:00
|
|
|
xl, fsDirs, err := prepareXL16(ctx)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-05-08 16:44:44 -04:00
|
|
|
err = xl.MakeBucketWithLocation(ctx, "bucket", "", false)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-08-31 16:16:35 -04:00
|
|
|
// Create object "dir/obj" under bucket "bucket" for Test 7 to pass
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = xl.PutObject(ctx, "bucket", "dir/obj", mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{})
|
2016-08-12 03:26:30 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("XL Object upload failed: <ERROR> %s", err)
|
|
|
|
}
|
2016-07-21 16:15:54 -04:00
|
|
|
for i, test := range testCases {
|
2020-04-14 20:52:38 -04:00
|
|
|
actualErr := xl.DeleteObject(ctx, test.bucket, test.object)
|
2016-07-21 16:15:54 -04:00
|
|
|
if test.expectedErr != nil && actualErr != test.expectedErr {
|
|
|
|
t.Errorf("Test %d: Expected to fail with %s, but failed with %s", i+1, test.expectedErr, actualErr)
|
|
|
|
}
|
|
|
|
if test.expectedErr == nil && actualErr != nil {
|
|
|
|
t.Errorf("Test %d: Expected to pass, but failed with %s", i+1, actualErr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Cleanup backend directories
|
|
|
|
removeRoots(fsDirs)
|
|
|
|
}
|
2019-05-13 15:25:49 -04:00
|
|
|
|
|
|
|
func TestXLDeleteObjectsXLSet(t *testing.T) {
|
2020-04-14 20:52:38 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2019-05-13 15:25:49 -04:00
|
|
|
var objs []*xlObjects
|
|
|
|
for i := 0; i < 32; i++ {
|
2020-04-14 20:52:38 -04:00
|
|
|
obj, fsDirs, err := prepareXL(ctx, 16)
|
2019-05-13 15:25:49 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Unable to initialize 'XL' object layer.", err)
|
|
|
|
}
|
|
|
|
// Remove all dirs.
|
|
|
|
for _, dir := range fsDirs {
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
}
|
2019-11-19 20:42:27 -05:00
|
|
|
z := obj.(*xlZones)
|
|
|
|
xl := z.zones[0].sets[0]
|
|
|
|
objs = append(objs, xl)
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
xlSets := &xlSets{sets: objs, distributionAlgo: "CRCMOD"}
|
|
|
|
|
|
|
|
type testCaseType struct {
|
|
|
|
bucket string
|
|
|
|
object string
|
|
|
|
}
|
|
|
|
|
|
|
|
bucketName := "bucket"
|
|
|
|
testCases := []testCaseType{
|
|
|
|
{bucketName, "dir/obj1"},
|
|
|
|
{bucketName, "dir/obj2"},
|
|
|
|
{bucketName, "obj3"},
|
|
|
|
{bucketName, "obj_4"},
|
|
|
|
}
|
|
|
|
|
2020-05-08 16:44:44 -04:00
|
|
|
err := xlSets.MakeBucketWithLocation(GlobalContext, bucketName, "", false)
|
2019-05-13 15:25:49 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = xlSets.PutObject(GlobalContext, testCase.bucket, testCase.object,
|
2019-05-13 15:25:49 -04:00
|
|
|
mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("XL Object upload failed: <ERROR> %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toObjectNames := func(testCases []testCaseType) []string {
|
|
|
|
names := make([]string, len(testCases))
|
|
|
|
for i := range testCases {
|
|
|
|
names[i] = testCases[i].object
|
|
|
|
}
|
|
|
|
return names
|
|
|
|
}
|
|
|
|
|
|
|
|
objectNames := toObjectNames(testCases)
|
2020-04-09 12:30:02 -04:00
|
|
|
delErrs, err := xlSets.DeleteObjects(GlobalContext, bucketName, objectNames)
|
2019-05-13 15:25:49 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Failed to call DeleteObjects with the error: `%v`", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range delErrs {
|
|
|
|
if delErrs[i] != nil {
|
|
|
|
t.Errorf("Failed to remove object `%v` with the error: `%v`", objectNames[i], delErrs[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range testCases {
|
2020-04-09 12:30:02 -04:00
|
|
|
_, statErr := xlSets.GetObjectInfo(GlobalContext, test.bucket, test.object, ObjectOptions{})
|
2019-05-13 15:25:49 -04:00
|
|
|
switch statErr.(type) {
|
|
|
|
case ObjectNotFound:
|
|
|
|
default:
|
2019-08-06 15:08:58 -04:00
|
|
|
t.Fatalf("Object %s is not removed", test.bucket+SlashSeparator+test.object)
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:15:54 -04:00
|
|
|
func TestXLDeleteObjectDiskNotFound(t *testing.T) {
|
2020-04-14 20:52:38 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2016-07-21 16:15:54 -04:00
|
|
|
// Create an instance of xl backend.
|
2020-04-14 20:52:38 -04:00
|
|
|
obj, fsDirs, err := prepareXL16(ctx)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-11-19 20:42:27 -05:00
|
|
|
// Cleanup backend directories
|
|
|
|
defer removeRoots(fsDirs)
|
2016-07-21 16:15:54 -04:00
|
|
|
|
2019-11-19 20:42:27 -05:00
|
|
|
z := obj.(*xlZones)
|
|
|
|
xl := z.zones[0].sets[0]
|
2016-07-21 16:15:54 -04:00
|
|
|
|
|
|
|
// Create "bucket"
|
2020-05-08 16:44:44 -04:00
|
|
|
err = obj.MakeBucketWithLocation(ctx, "bucket", "", false)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bucket := "bucket"
|
|
|
|
object := "object"
|
2018-09-10 12:42:43 -04:00
|
|
|
opts := ObjectOptions{}
|
2016-07-21 16:15:54 -04:00
|
|
|
// Create object "obj" under bucket "bucket".
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
2016-09-02 02:10:50 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-07-21 16:15:54 -04:00
|
|
|
// for a 16 disk setup, quorum is 9. To simulate disks not found yet
|
|
|
|
// quorum is available, we remove disks leaving quorum disks behind.
|
2019-11-19 20:42:27 -05:00
|
|
|
xlDisks := xl.getDisks()
|
2020-01-23 14:50:09 -05:00
|
|
|
z.zones[0].xlDisksMu.Lock()
|
2019-11-19 20:42:27 -05:00
|
|
|
xl.getDisks = func() []StorageAPI {
|
|
|
|
for i := range xlDisks[:7] {
|
|
|
|
xlDisks[i] = newNaughtyDisk(xlDisks[i], nil, errFaultyDisk)
|
|
|
|
}
|
|
|
|
return xlDisks
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
2020-01-23 14:50:09 -05:00
|
|
|
z.zones[0].xlDisksMu.Unlock()
|
2020-04-14 20:52:38 -04:00
|
|
|
err = obj.DeleteObject(ctx, bucket, object)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create "obj" under "bucket".
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove one more disk to 'lose' quorum, by setting it to nil.
|
2019-11-19 20:42:27 -05:00
|
|
|
xlDisks = xl.getDisks()
|
2020-01-23 14:50:09 -05:00
|
|
|
z.zones[0].xlDisksMu.Lock()
|
2019-11-19 20:42:27 -05:00
|
|
|
xl.getDisks = func() []StorageAPI {
|
|
|
|
xlDisks[7] = nil
|
|
|
|
xlDisks[8] = nil
|
|
|
|
return xlDisks
|
|
|
|
}
|
2020-01-23 14:50:09 -05:00
|
|
|
z.zones[0].xlDisksMu.Unlock()
|
2020-04-14 20:52:38 -04:00
|
|
|
err = obj.DeleteObject(ctx, bucket, object)
|
2017-12-22 06:28:13 -05:00
|
|
|
// since majority of disks are not available, metaquorum is not achieved and hence errXLReadQuorum error
|
|
|
|
if err != toObjectErr(errXLReadQuorum, bucket, object) {
|
|
|
|
t.Errorf("Expected deleteObject to fail with %v, but failed with %v", toObjectErr(errXLReadQuorum, bucket, object), err)
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetObjectNoQuorum(t *testing.T) {
|
2020-04-14 20:52:38 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2016-07-21 16:15:54 -04:00
|
|
|
// Create an instance of xl backend.
|
2020-04-14 20:52:38 -04:00
|
|
|
obj, fsDirs, err := prepareXL16(ctx)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-11-19 20:42:27 -05:00
|
|
|
// Cleanup backend directories.
|
|
|
|
defer removeRoots(fsDirs)
|
2016-07-21 16:15:54 -04:00
|
|
|
|
2019-11-19 20:42:27 -05:00
|
|
|
z := obj.(*xlZones)
|
|
|
|
xl := z.zones[0].sets[0]
|
2016-07-21 16:15:54 -04:00
|
|
|
|
|
|
|
// Create "bucket"
|
2020-05-08 16:44:44 -04:00
|
|
|
err = obj.MakeBucketWithLocation(ctx, "bucket", "", false)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bucket := "bucket"
|
|
|
|
object := "object"
|
2018-09-10 12:42:43 -04:00
|
|
|
opts := ObjectOptions{}
|
2016-07-21 16:15:54 -04:00
|
|
|
// Create "object" under "bucket".
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-02-02 13:17:13 -05:00
|
|
|
|
2016-07-21 16:15:54 -04:00
|
|
|
// Make 9 disks offline, which leaves less than quorum number of disks
|
|
|
|
// in a 16 disk XL setup. The original disks are 'replaced' with
|
2016-09-09 15:53:09 -04:00
|
|
|
// naughtyDisks that fail after 'f' successful StorageAPI method
|
2016-07-21 16:15:54 -04:00
|
|
|
// invocations, where f - [0,2)
|
|
|
|
for f := 0; f < 2; f++ {
|
2016-09-09 15:53:09 -04:00
|
|
|
diskErrors := make(map[int]error)
|
|
|
|
for i := 0; i <= f; i++ {
|
|
|
|
diskErrors[i] = nil
|
|
|
|
}
|
2019-11-19 20:42:27 -05:00
|
|
|
xlDisks := xl.getDisks()
|
|
|
|
for i := range xlDisks[:9] {
|
|
|
|
switch diskType := xlDisks[i].(type) {
|
2016-09-09 15:53:09 -04:00
|
|
|
case *naughtyDisk:
|
2019-11-19 20:42:27 -05:00
|
|
|
xlDisks[i] = newNaughtyDisk(diskType.disk, diskErrors, errFaultyDisk)
|
2018-02-15 20:45:57 -05:00
|
|
|
default:
|
2019-11-19 20:42:27 -05:00
|
|
|
xlDisks[i] = newNaughtyDisk(xlDisks[i], diskErrors, errFaultyDisk)
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
|
|
|
}
|
2020-01-23 14:50:09 -05:00
|
|
|
z.zones[0].xlDisksMu.Lock()
|
2019-11-19 20:42:27 -05:00
|
|
|
xl.getDisks = func() []StorageAPI {
|
|
|
|
return xlDisks
|
|
|
|
}
|
2020-01-23 14:50:09 -05:00
|
|
|
z.zones[0].xlDisksMu.Unlock()
|
2016-07-21 16:15:54 -04:00
|
|
|
// Fetch object from store.
|
2020-04-14 20:52:38 -04:00
|
|
|
err = xl.GetObject(ctx, bucket, object, 0, int64(len("abcd")), ioutil.Discard, "", opts)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != toObjectErr(errXLReadQuorum, bucket, object) {
|
|
|
|
t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errXLWriteQuorum, bucket, object), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPutObjectNoQuorum(t *testing.T) {
|
2020-04-14 20:52:38 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
2016-07-21 16:15:54 -04:00
|
|
|
// Create an instance of xl backend.
|
2020-04-14 20:52:38 -04:00
|
|
|
obj, fsDirs, err := prepareXL16(ctx)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-11-19 20:42:27 -05:00
|
|
|
// Cleanup backend directories.
|
|
|
|
defer removeRoots(fsDirs)
|
|
|
|
|
|
|
|
z := obj.(*xlZones)
|
|
|
|
xl := z.zones[0].sets[0]
|
2016-07-21 16:15:54 -04:00
|
|
|
|
|
|
|
// Create "bucket"
|
2020-05-08 16:44:44 -04:00
|
|
|
err = obj.MakeBucketWithLocation(ctx, "bucket", "", false)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bucket := "bucket"
|
|
|
|
object := "object"
|
2018-09-10 12:42:43 -04:00
|
|
|
opts := ObjectOptions{}
|
2016-07-21 16:15:54 -04:00
|
|
|
// Create "object" under "bucket".
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make 9 disks offline, which leaves less than quorum number of disks
|
|
|
|
// in a 16 disk XL setup. The original disks are 'replaced' with
|
2016-09-09 15:53:09 -04:00
|
|
|
// naughtyDisks that fail after 'f' successful StorageAPI method
|
2016-07-21 16:15:54 -04:00
|
|
|
// invocations, where f - [0,3)
|
|
|
|
for f := 0; f < 3; f++ {
|
2016-09-09 15:53:09 -04:00
|
|
|
diskErrors := make(map[int]error)
|
|
|
|
for i := 0; i <= f; i++ {
|
|
|
|
diskErrors[i] = nil
|
|
|
|
}
|
2019-11-19 20:42:27 -05:00
|
|
|
xlDisks := xl.getDisks()
|
|
|
|
for i := range xlDisks[:9] {
|
|
|
|
switch diskType := xlDisks[i].(type) {
|
2016-09-09 15:53:09 -04:00
|
|
|
case *naughtyDisk:
|
2019-11-19 20:42:27 -05:00
|
|
|
xlDisks[i] = newNaughtyDisk(diskType.disk, diskErrors, errFaultyDisk)
|
2018-02-15 20:45:57 -05:00
|
|
|
default:
|
2019-11-19 20:42:27 -05:00
|
|
|
xlDisks[i] = newNaughtyDisk(xlDisks[i], diskErrors, errFaultyDisk)
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
|
|
|
}
|
2020-01-23 14:50:09 -05:00
|
|
|
z.zones[0].xlDisksMu.Lock()
|
2019-11-19 20:42:27 -05:00
|
|
|
xl.getDisks = func() []StorageAPI {
|
|
|
|
return xlDisks
|
|
|
|
}
|
2020-01-23 14:50:09 -05:00
|
|
|
z.zones[0].xlDisksMu.Unlock()
|
2016-07-21 16:15:54 -04:00
|
|
|
// Upload new content to same object "object"
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != toObjectErr(errXLWriteQuorum, bucket, object) {
|
|
|
|
t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errXLWriteQuorum, bucket, object), err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 20:08:17 -04:00
|
|
|
|
2016-10-14 22:57:40 -04:00
|
|
|
// Tests both object and bucket healing.
|
|
|
|
func TestHealing(t *testing.T) {
|
2020-04-14 20:52:38 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
obj, fsDirs, err := prepareXL16(ctx)
|
2016-10-08 20:08:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer removeRoots(fsDirs)
|
2019-11-19 20:42:27 -05:00
|
|
|
|
|
|
|
z := obj.(*xlZones)
|
|
|
|
xl := z.zones[0].sets[0]
|
2016-10-08 20:08:17 -04:00
|
|
|
|
|
|
|
// Create "bucket"
|
2020-05-08 16:44:44 -04:00
|
|
|
err = obj.MakeBucketWithLocation(ctx, "bucket", "", false)
|
2016-10-08 20:08:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bucket := "bucket"
|
|
|
|
object := "object"
|
|
|
|
|
2016-11-22 21:18:22 -05:00
|
|
|
data := make([]byte, 1*humanize.MiByte)
|
2016-10-08 20:08:17 -04:00
|
|
|
length := int64(len(data))
|
|
|
|
_, err = rand.Read(data)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader(data), length, "", ""), ObjectOptions{})
|
2016-10-08 20:08:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-11-19 20:42:27 -05:00
|
|
|
disk := xl.getDisks()[0]
|
2020-04-14 20:52:38 -04:00
|
|
|
xlMetaPreHeal, err := readXLMeta(ctx, disk, bucket, object)
|
2016-10-08 20:08:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the object - to simulate the case where the disk was down when the object
|
|
|
|
// was created.
|
|
|
|
err = os.RemoveAll(path.Join(fsDirs[0], bucket, object))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = xl.HealObject(ctx, bucket, object, madmin.HealOpts{ScanMode: madmin.HealNormalScan})
|
2016-10-08 20:08:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-04-14 20:52:38 -04:00
|
|
|
xlMetaPostHeal, err := readXLMeta(ctx, disk, bucket, object)
|
2016-10-08 20:08:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// After heal the meta file should be as expected.
|
|
|
|
if !reflect.DeepEqual(xlMetaPreHeal, xlMetaPostHeal) {
|
|
|
|
t.Fatal("HealObject failed")
|
|
|
|
}
|
|
|
|
|
2019-02-01 22:01:06 -05:00
|
|
|
err = os.RemoveAll(path.Join(fsDirs[0], bucket, object, "xl.json"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-10-08 20:08:17 -04:00
|
|
|
// Write xl.json with different modtime to simulate the case where a disk had
|
|
|
|
// gone down when an object was replaced by a new object.
|
|
|
|
xlMetaOutDated := xlMetaPreHeal
|
|
|
|
xlMetaOutDated.Stat.ModTime = time.Now()
|
2020-04-14 20:52:38 -04:00
|
|
|
err = writeXLMetadata(ctx, disk, bucket, object, xlMetaOutDated)
|
2016-10-08 20:08:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = xl.HealObject(ctx, bucket, object, madmin.HealOpts{ScanMode: madmin.HealDeepScan})
|
2016-10-08 20:08:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-04-14 20:52:38 -04:00
|
|
|
xlMetaPostHeal, err = readXLMeta(ctx, disk, bucket, object)
|
2016-10-08 20:08:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// After heal the meta file should be as expected.
|
|
|
|
if !reflect.DeepEqual(xlMetaPreHeal, xlMetaPostHeal) {
|
|
|
|
t.Fatal("HealObject failed")
|
|
|
|
}
|
2016-10-14 14:12:17 -04:00
|
|
|
|
2016-10-14 22:57:40 -04:00
|
|
|
// Remove the bucket - to simulate the case where bucket was
|
|
|
|
// created when the disk was down.
|
2016-10-14 14:12:17 -04:00
|
|
|
err = os.RemoveAll(path.Join(fsDirs[0], bucket))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// This would create the bucket.
|
2020-04-14 20:52:38 -04:00
|
|
|
_, err = xl.HealBucket(ctx, bucket, false, false)
|
2016-10-14 14:12:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// Stat the bucket to make sure that it was created.
|
2019-11-19 20:42:27 -05:00
|
|
|
_, err = xl.getDisks()[0].StatVol(bucket)
|
2016-10-14 14:12:17 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-10-08 20:08:17 -04:00
|
|
|
}
|
2019-10-07 01:50:24 -04:00
|
|
|
|
|
|
|
func TestObjectQuorumFromMeta(t *testing.T) {
|
|
|
|
ExecObjectLayerTestWithDirs(t, testObjectQuorumFromMeta)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testObjectQuorumFromMeta(obj ObjectLayer, instanceType string, dirs []string, t TestErrHandler) {
|
|
|
|
bucket := getRandomBucketName()
|
|
|
|
|
|
|
|
var opts ObjectOptions
|
|
|
|
// make data with more than one part
|
|
|
|
partCount := 3
|
2019-11-19 20:42:27 -05:00
|
|
|
data := bytes.Repeat([]byte("a"), 6*1024*1024*partCount)
|
|
|
|
|
|
|
|
z := obj.(*xlZones)
|
|
|
|
xl := z.zones[0].sets[0]
|
|
|
|
xlDisks := xl.getDisks()
|
2019-10-07 01:50:24 -04:00
|
|
|
|
2020-05-08 16:44:44 -04:00
|
|
|
err := obj.MakeBucketWithLocation(GlobalContext, bucket, globalMinioDefaultRegion, false)
|
2019-10-07 01:50:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to make a bucket %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Object for test case 1 - No StorageClass defined, no MetaData in PutObject
|
|
|
|
object1 := "object1"
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucket, object1, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), opts)
|
2019-10-07 01:50:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to putObject %v", err)
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
parts1, errs1 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object1)
|
2019-10-07 01:50:24 -04:00
|
|
|
|
|
|
|
// Object for test case 2 - No StorageClass defined, MetaData in PutObject requesting RRS Class
|
|
|
|
object2 := "object2"
|
|
|
|
metadata2 := make(map[string]string)
|
|
|
|
metadata2["x-amz-storage-class"] = storageclass.RRS
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucket, object2, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata2})
|
2019-10-07 01:50:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to putObject %v", err)
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
parts2, errs2 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object2)
|
2019-10-07 01:50:24 -04:00
|
|
|
|
|
|
|
// Object for test case 3 - No StorageClass defined, MetaData in PutObject requesting Standard Storage Class
|
|
|
|
object3 := "object3"
|
|
|
|
metadata3 := make(map[string]string)
|
|
|
|
metadata3["x-amz-storage-class"] = storageclass.STANDARD
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucket, object3, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata3})
|
2019-10-07 01:50:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to putObject %v", err)
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
parts3, errs3 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object3)
|
2019-10-07 01:50:24 -04:00
|
|
|
|
|
|
|
// Object for test case 4 - Standard StorageClass defined as Parity 6, MetaData in PutObject requesting Standard Storage Class
|
|
|
|
object4 := "object4"
|
|
|
|
metadata4 := make(map[string]string)
|
|
|
|
metadata4["x-amz-storage-class"] = storageclass.STANDARD
|
2019-10-23 01:59:13 -04:00
|
|
|
globalStorageClass = storageclass.Config{
|
2019-10-07 01:50:24 -04:00
|
|
|
Standard: storageclass.StorageClass{
|
|
|
|
Parity: 6,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucket, object4, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata4})
|
2019-10-07 01:50:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to putObject %v", err)
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
parts4, errs4 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object4)
|
2019-10-07 01:50:24 -04:00
|
|
|
|
|
|
|
// Object for test case 5 - RRS StorageClass defined as Parity 2, MetaData in PutObject requesting RRS Class
|
|
|
|
// Reset global storage class flags
|
|
|
|
object5 := "object5"
|
|
|
|
metadata5 := make(map[string]string)
|
|
|
|
metadata5["x-amz-storage-class"] = storageclass.RRS
|
2019-10-23 01:59:13 -04:00
|
|
|
globalStorageClass = storageclass.Config{
|
2019-10-07 01:50:24 -04:00
|
|
|
RRS: storageclass.StorageClass{
|
|
|
|
Parity: 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucket, object5, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata5})
|
2019-10-07 01:50:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to putObject %v", err)
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
parts5, errs5 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object5)
|
2019-10-07 01:50:24 -04:00
|
|
|
|
|
|
|
// Object for test case 6 - RRS StorageClass defined as Parity 2, MetaData in PutObject requesting Standard Storage Class
|
|
|
|
object6 := "object6"
|
|
|
|
metadata6 := make(map[string]string)
|
|
|
|
metadata6["x-amz-storage-class"] = storageclass.STANDARD
|
2019-10-23 01:59:13 -04:00
|
|
|
globalStorageClass = storageclass.Config{
|
2019-10-07 01:50:24 -04:00
|
|
|
RRS: storageclass.StorageClass{
|
|
|
|
Parity: 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucket, object6, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata6})
|
2019-10-07 01:50:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to putObject %v", err)
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
parts6, errs6 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object6)
|
2019-10-07 01:50:24 -04:00
|
|
|
|
|
|
|
// Object for test case 7 - Standard StorageClass defined as Parity 5, MetaData in PutObject requesting RRS Class
|
|
|
|
// Reset global storage class flags
|
|
|
|
object7 := "object7"
|
|
|
|
metadata7 := make(map[string]string)
|
|
|
|
metadata7["x-amz-storage-class"] = storageclass.RRS
|
2019-10-23 01:59:13 -04:00
|
|
|
globalStorageClass = storageclass.Config{
|
2019-10-07 01:50:24 -04:00
|
|
|
Standard: storageclass.StorageClass{
|
|
|
|
Parity: 5,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
_, err = obj.PutObject(GlobalContext, bucket, object7, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata7})
|
2019-10-07 01:50:24 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to putObject %v", err)
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:30:02 -04:00
|
|
|
parts7, errs7 := readAllXLMetadata(GlobalContext, xlDisks, bucket, object7)
|
2019-10-07 01:50:24 -04:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
parts []xlMetaV1
|
|
|
|
errs []error
|
|
|
|
expectedReadQuorum int
|
|
|
|
expectedWriteQuorum int
|
|
|
|
expectedError error
|
|
|
|
}{
|
|
|
|
{parts1, errs1, 8, 9, nil},
|
|
|
|
{parts2, errs2, 14, 15, nil},
|
|
|
|
{parts3, errs3, 8, 9, nil},
|
|
|
|
{parts4, errs4, 10, 11, nil},
|
|
|
|
{parts5, errs5, 14, 15, nil},
|
|
|
|
{parts6, errs6, 8, 9, nil},
|
|
|
|
{parts7, errs7, 14, 15, nil},
|
|
|
|
}
|
|
|
|
for i, tt := range tests {
|
2020-04-09 12:30:02 -04:00
|
|
|
actualReadQuorum, actualWriteQuorum, err := objectQuorumFromMeta(GlobalContext, *xl, tt.parts, tt.errs)
|
2019-10-07 01:50:24 -04:00
|
|
|
if tt.expectedError != nil && err == nil {
|
|
|
|
t.Errorf("Test %d, Expected %s, got %s", i+1, tt.expectedError, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if tt.expectedError == nil && err != nil {
|
|
|
|
t.Errorf("Test %d, Expected %s, got %s", i+1, tt.expectedError, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if tt.expectedReadQuorum != actualReadQuorum {
|
|
|
|
t.Errorf("Test %d, Expected Read Quorum %d, got %d", i+1, tt.expectedReadQuorum, actualReadQuorum)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if tt.expectedWriteQuorum != actualWriteQuorum {
|
|
|
|
t.Errorf("Test %d, Expected Write Quorum %d, got %d", i+1, tt.expectedWriteQuorum, actualWriteQuorum)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|