2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-06-21 18:48:27 -04:00
|
|
|
|
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"
|
2021-01-07 22:27:31 -05:00
|
|
|
crand "crypto/rand"
|
2020-11-23 12:12:17 -05:00
|
|
|
"errors"
|
2021-01-07 22:27:31 -05:00
|
|
|
"io"
|
2016-07-21 16:15:54 -04:00
|
|
|
"io/ioutil"
|
2016-10-08 20:08:17 -04:00
|
|
|
"os"
|
2021-03-29 20:00:55 -04:00
|
|
|
"strconv"
|
2016-06-21 18:48:27 -04:00
|
|
|
"testing"
|
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"
|
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-06-12 23:04:01 -04:00
|
|
|
objLayer, disks, err = prepareErasure16(ctx)
|
2016-06-21 18:48:27 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleaning up of temporary test directories
|
2020-09-10 12:18:19 -04:00
|
|
|
defer objLayer.Shutdown(context.Background())
|
2016-06-21 18:48:27 -04:00
|
|
|
defer removeRoots(disks)
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
err = objLayer.MakeBucketWithLocation(ctx, "bucket1", BucketOptions{})
|
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
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func TestErasureDeleteObjectBasic(t *testing.T) {
|
2016-07-21 16:15:54 -04:00
|
|
|
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-06-12 23:04:01 -04:00
|
|
|
xl, fsDirs, err := prepareErasure16(ctx)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2020-09-10 12:18:19 -04:00
|
|
|
defer xl.Shutdown(context.Background())
|
2016-07-21 16:15:54 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
err = xl.MakeBucketWithLocation(ctx, "bucket", BucketOptions{})
|
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 {
|
2020-06-12 23:04:01 -04:00
|
|
|
t.Fatalf("Erasure Object upload failed: <ERROR> %s", err)
|
2016-08-12 03:26:30 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
for _, test := range testCases {
|
|
|
|
test := test
|
|
|
|
t.Run("", func(t *testing.T) {
|
2021-03-29 20:00:55 -04:00
|
|
|
_, err := xl.GetObjectInfo(ctx, "bucket", "dir/obj", ObjectOptions{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("dir/obj not found before last test")
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
_, actualErr := xl.DeleteObject(ctx, test.bucket, test.object, ObjectOptions{})
|
|
|
|
if test.expectedErr != nil && actualErr != test.expectedErr {
|
|
|
|
t.Errorf("Expected to fail with %s, but failed with %s", test.expectedErr, actualErr)
|
|
|
|
}
|
|
|
|
if test.expectedErr == nil && actualErr != nil {
|
|
|
|
t.Errorf("Expected to pass, but failed with %s", actualErr)
|
|
|
|
}
|
|
|
|
})
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
|
|
|
// Cleanup backend directories
|
|
|
|
removeRoots(fsDirs)
|
|
|
|
}
|
2019-05-13 15:25:49 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func TestErasureDeleteObjectsErasureSet(t *testing.T) {
|
2020-04-14 20:52:38 -04:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2020-06-12 23:04:01 -04:00
|
|
|
var objs []*erasureObjects
|
2019-05-13 15:25:49 -04:00
|
|
|
for i := 0; i < 32; i++ {
|
2020-06-12 23:04:01 -04:00
|
|
|
obj, fsDirs, err := prepareErasure(ctx, 16)
|
2019-05-13 15:25:49 -04:00
|
|
|
if err != nil {
|
2020-06-12 23:04:01 -04:00
|
|
|
t.Fatal("Unable to initialize 'Erasure' object layer.", err)
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
// Remove all dirs.
|
|
|
|
for _, dir := range fsDirs {
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
}
|
2020-12-01 16:50:33 -05:00
|
|
|
z := obj.(*erasureServerPools)
|
|
|
|
xl := z.serverPools[0].sets[0]
|
2019-11-19 20:42:27 -05:00
|
|
|
objs = append(objs, xl)
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureSets := &erasureSets{sets: objs, distributionAlgo: "CRCMOD"}
|
2019-05-13 15:25:49 -04:00
|
|
|
|
|
|
|
type testCaseType struct {
|
|
|
|
bucket string
|
|
|
|
object string
|
|
|
|
}
|
|
|
|
|
|
|
|
bucketName := "bucket"
|
|
|
|
testCases := []testCaseType{
|
|
|
|
{bucketName, "dir/obj1"},
|
|
|
|
{bucketName, "dir/obj2"},
|
|
|
|
{bucketName, "obj3"},
|
|
|
|
{bucketName, "obj_4"},
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
err := erasureSets.MakeBucketWithLocation(ctx, bucketName, BucketOptions{})
|
2019-05-13 15:25:49 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testCase := range testCases {
|
2020-06-12 23:04:01 -04:00
|
|
|
_, err = erasureSets.PutObject(ctx, 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 {
|
2020-06-12 23:04:01 -04:00
|
|
|
t.Fatalf("Erasure Object upload failed: <ERROR> %s", err)
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
toObjectNames := func(testCases []testCaseType) []ObjectToDelete {
|
|
|
|
names := make([]ObjectToDelete, len(testCases))
|
2019-05-13 15:25:49 -04:00
|
|
|
for i := range testCases {
|
2020-06-12 23:04:01 -04:00
|
|
|
names[i] = ObjectToDelete{ObjectName: testCases[i].object}
|
2019-05-13 15:25:49 -04:00
|
|
|
}
|
|
|
|
return names
|
|
|
|
}
|
|
|
|
|
|
|
|
objectNames := toObjectNames(testCases)
|
2020-06-12 23:04:01 -04:00
|
|
|
_, delErrs := erasureSets.DeleteObjects(ctx, bucketName, objectNames, ObjectOptions{})
|
2019-05-13 15:25:49 -04:00
|
|
|
|
|
|
|
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-06-12 23:04:01 -04:00
|
|
|
_, statErr := erasureSets.GetObjectInfo(ctx, 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
func TestErasureDeleteObjectDiskNotFound(t *testing.T) {
|
2021-01-16 15:08:02 -05:00
|
|
|
restoreGlobalStorageClass := globalStorageClass
|
|
|
|
defer func() {
|
|
|
|
globalStorageClass = restoreGlobalStorageClass
|
|
|
|
}()
|
|
|
|
|
|
|
|
globalStorageClass = storageclass.Config{}
|
|
|
|
|
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-06-12 23:04:01 -04:00
|
|
|
obj, fsDirs, err := prepareErasure16(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
|
2020-09-10 12:18:19 -04:00
|
|
|
defer obj.Shutdown(context.Background())
|
2019-11-19 20:42:27 -05:00
|
|
|
defer removeRoots(fsDirs)
|
2016-07-21 16:15:54 -04:00
|
|
|
|
2020-12-01 16:50:33 -05:00
|
|
|
z := obj.(*erasureServerPools)
|
|
|
|
xl := z.serverPools[0].sets[0]
|
2016-07-21 16:15:54 -04:00
|
|
|
|
|
|
|
// Create "bucket"
|
2020-06-12 23:04:01 -04:00
|
|
|
err = obj.MakeBucketWithLocation(ctx, "bucket", BucketOptions{})
|
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.
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks := xl.getDisks()
|
2020-12-01 16:50:33 -05:00
|
|
|
z.serverPools[0].erasureDisksMu.Lock()
|
2019-11-19 20:42:27 -05:00
|
|
|
xl.getDisks = func() []StorageAPI {
|
2021-01-16 15:08:02 -05:00
|
|
|
for i := range erasureDisks[:4] {
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks[i] = newNaughtyDisk(erasureDisks[i], nil, errFaultyDisk)
|
2019-11-19 20:42:27 -05:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
return erasureDisks
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
|
2020-12-01 16:50:33 -05:00
|
|
|
z.serverPools[0].erasureDisksMu.Unlock()
|
2020-06-12 23:04:01 -04:00
|
|
|
_, err = obj.DeleteObject(ctx, bucket, object, ObjectOptions{})
|
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.
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks = xl.getDisks()
|
2020-12-01 16:50:33 -05:00
|
|
|
z.serverPools[0].erasureDisksMu.Lock()
|
2019-11-19 20:42:27 -05:00
|
|
|
xl.getDisks = func() []StorageAPI {
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks[7] = nil
|
|
|
|
erasureDisks[8] = nil
|
|
|
|
return erasureDisks
|
2019-11-19 20:42:27 -05:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
|
2020-12-01 16:50:33 -05:00
|
|
|
z.serverPools[0].erasureDisksMu.Unlock()
|
2020-06-12 23:04:01 -04:00
|
|
|
_, err = obj.DeleteObject(ctx, bucket, object, ObjectOptions{})
|
|
|
|
// since majority of disks are not available, metaquorum is not achieved and hence errErasureWriteQuorum error
|
2020-11-23 12:12:17 -05:00
|
|
|
if !errors.Is(err, errErasureWriteQuorum) {
|
2020-06-12 23:04:01 -04:00
|
|
|
t.Errorf("Expected deleteObject to fail with %v, but failed with %v", toObjectErr(errErasureWriteQuorum, 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-06-12 23:04:01 -04:00
|
|
|
obj, fsDirs, err := prepareErasure16(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.
|
2020-09-10 12:18:19 -04:00
|
|
|
defer obj.Shutdown(context.Background())
|
2019-11-19 20:42:27 -05:00
|
|
|
defer removeRoots(fsDirs)
|
2016-07-21 16:15:54 -04:00
|
|
|
|
2020-12-01 16:50:33 -05:00
|
|
|
z := obj.(*erasureServerPools)
|
|
|
|
xl := z.serverPools[0].sets[0]
|
2016-07-21 16:15:54 -04:00
|
|
|
|
|
|
|
// Create "bucket"
|
2020-06-12 23:04:01 -04:00
|
|
|
err = obj.MakeBucketWithLocation(ctx, "bucket", BucketOptions{})
|
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{}
|
2021-03-31 12:19:14 -04:00
|
|
|
buf := make([]byte, smallFileThreshold*16)
|
2021-01-07 22:27:31 -05:00
|
|
|
if _, err = io.ReadFull(crand.Reader, buf); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2021-01-02 13:35:57 -05:00
|
|
|
|
|
|
|
// Test use case 1: All disks are online, xl.meta are present, but data are missing
|
2021-01-07 22:27:31 -05:00
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader(buf), int64(len(buf)), "", ""), opts)
|
2016-07-21 16:15:54 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-02-02 13:17:13 -05:00
|
|
|
|
2021-01-02 13:35:57 -05:00
|
|
|
for _, disk := range xl.getDisks() {
|
|
|
|
files, _ := disk.ListDir(ctx, bucket, object, -1)
|
|
|
|
for _, file := range files {
|
|
|
|
if file != "xl.meta" {
|
|
|
|
disk.Delete(ctx, bucket, pathJoin(object, file), true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
err = xl.GetObject(ctx, bucket, object, 0, int64(len(buf)), ioutil.Discard, "", opts)
|
2021-01-02 13:35:57 -05:00
|
|
|
if err != toObjectErr(errFileNotFound, bucket, object) {
|
|
|
|
t.Errorf("Expected GetObject to fail with %v, but failed with %v", toObjectErr(errErasureWriteQuorum, bucket, object), err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test use case 2: Make 9 disks offline, which leaves less than quorum number of disks
|
2020-06-12 23:04:01 -04:00
|
|
|
// in a 16 disk Erasure 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)
|
2021-01-02 13:35:57 -05:00
|
|
|
|
|
|
|
// Create "object" under "bucket".
|
2021-01-07 22:27:31 -05:00
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader(buf), int64(len(buf)), "", ""), opts)
|
2021-01-02 13:35:57 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-07-21 16:15:54 -04:00
|
|
|
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
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks := xl.getDisks()
|
|
|
|
for i := range erasureDisks[:9] {
|
|
|
|
switch diskType := erasureDisks[i].(type) {
|
2016-09-09 15:53:09 -04:00
|
|
|
case *naughtyDisk:
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks[i] = newNaughtyDisk(diskType.disk, diskErrors, errFaultyDisk)
|
2018-02-15 20:45:57 -05:00
|
|
|
default:
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks[i] = newNaughtyDisk(erasureDisks[i], diskErrors, errFaultyDisk)
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
|
|
|
}
|
2020-12-01 16:50:33 -05:00
|
|
|
z.serverPools[0].erasureDisksMu.Lock()
|
2019-11-19 20:42:27 -05:00
|
|
|
xl.getDisks = func() []StorageAPI {
|
2020-06-12 23:04:01 -04:00
|
|
|
return erasureDisks
|
2019-11-19 20:42:27 -05:00
|
|
|
}
|
2020-12-01 16:50:33 -05:00
|
|
|
z.serverPools[0].erasureDisksMu.Unlock()
|
2021-01-04 21:51:52 -05:00
|
|
|
// Fetch object from store.
|
|
|
|
err = xl.GetObject(ctx, bucket, object, 0, int64(len("abcd")), ioutil.Discard, "", opts)
|
|
|
|
if err != toObjectErr(errErasureReadQuorum, bucket, object) {
|
|
|
|
t.Errorf("Expected GetObject to fail with %v, but failed with %v", toObjectErr(errErasureWriteQuorum, bucket, object), err)
|
2021-01-02 13:35:57 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestHeadObjectNoQuorum(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
// Create an instance of xl backend.
|
|
|
|
obj, fsDirs, err := prepareErasure16(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// Cleanup backend directories.
|
|
|
|
defer obj.Shutdown(context.Background())
|
|
|
|
defer removeRoots(fsDirs)
|
|
|
|
|
|
|
|
z := obj.(*erasureServerPools)
|
|
|
|
xl := z.serverPools[0].sets[0]
|
|
|
|
|
|
|
|
// Create "bucket"
|
|
|
|
err = obj.MakeBucketWithLocation(ctx, "bucket", BucketOptions{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bucket := "bucket"
|
|
|
|
object := "object"
|
|
|
|
opts := ObjectOptions{}
|
|
|
|
|
|
|
|
// Test use case 1: All disks are online, xl.meta are present, but data are missing
|
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
for _, disk := range xl.getDisks() {
|
|
|
|
files, _ := disk.ListDir(ctx, bucket, object, -1)
|
|
|
|
for _, file := range files {
|
|
|
|
if file != "xl.meta" {
|
|
|
|
disk.Delete(ctx, bucket, pathJoin(object, file), true)
|
|
|
|
}
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
|
|
|
}
|
2021-01-02 13:35:57 -05:00
|
|
|
|
|
|
|
_, err = xl.GetObjectInfo(ctx, bucket, object, opts)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Expected StatObject to succeed if data dir are not found, but failed with %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test use case 2: Make 9 disks offline, which leaves less than quorum number of disks
|
|
|
|
// in a 16 disk Erasure setup. The original disks are 'replaced' with
|
|
|
|
// naughtyDisks that fail after 'f' successful StorageAPI method
|
|
|
|
// invocations, where f - [0,2)
|
|
|
|
|
|
|
|
// Create "object" under "bucket".
|
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
erasureDisks := xl.getDisks()
|
|
|
|
for i := range erasureDisks[:10] {
|
|
|
|
erasureDisks[i] = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
z.serverPools[0].erasureDisksMu.Lock()
|
|
|
|
xl.getDisks = func() []StorageAPI {
|
|
|
|
return erasureDisks
|
|
|
|
}
|
|
|
|
z.serverPools[0].erasureDisksMu.Unlock()
|
|
|
|
|
|
|
|
// Fetch object from store.
|
|
|
|
_, err = xl.GetObjectInfo(ctx, bucket, object, opts)
|
|
|
|
if err != toObjectErr(errErasureReadQuorum, bucket, object) {
|
|
|
|
t.Errorf("Expected getObjectInfo to fail with %v, but failed with %v", toObjectErr(errErasureWriteQuorum, bucket, object), err)
|
|
|
|
}
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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-06-12 23:04:01 -04:00
|
|
|
obj, fsDirs, err := prepareErasure16(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.
|
2020-09-10 12:18:19 -04:00
|
|
|
defer obj.Shutdown(context.Background())
|
2019-11-19 20:42:27 -05:00
|
|
|
defer removeRoots(fsDirs)
|
|
|
|
|
2020-12-01 16:50:33 -05:00
|
|
|
z := obj.(*erasureServerPools)
|
|
|
|
xl := z.serverPools[0].sets[0]
|
2016-07-21 16:15:54 -04:00
|
|
|
|
|
|
|
// Create "bucket"
|
2020-06-12 23:04:01 -04:00
|
|
|
err = obj.MakeBucketWithLocation(ctx, "bucket", BucketOptions{})
|
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".
|
2021-03-31 12:19:14 -04:00
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader(bytes.Repeat([]byte{'a'}, smallFileThreshold*16)), smallFileThreshold*16, "", ""), 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
|
2020-06-12 23:04:01 -04:00
|
|
|
// in a 16 disk Erasure setup. The original disks are 'replaced' with
|
2016-09-09 15:53:09 -04:00
|
|
|
// naughtyDisks that fail after 'f' successful StorageAPI method
|
2021-03-29 20:00:55 -04:00
|
|
|
// invocations, where f - [0,4)
|
2021-04-20 13:44:39 -04:00
|
|
|
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
|
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks := xl.getDisks()
|
|
|
|
for i := range erasureDisks[:9] {
|
|
|
|
switch diskType := erasureDisks[i].(type) {
|
2016-09-09 15:53:09 -04:00
|
|
|
case *naughtyDisk:
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks[i] = newNaughtyDisk(diskType.disk, diskErrors, errFaultyDisk)
|
2018-02-15 20:45:57 -05:00
|
|
|
default:
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks[i] = newNaughtyDisk(erasureDisks[i], diskErrors, errFaultyDisk)
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
|
|
|
}
|
2020-12-01 16:50:33 -05:00
|
|
|
z.serverPools[0].erasureDisksMu.Lock()
|
2019-11-19 20:42:27 -05:00
|
|
|
xl.getDisks = func() []StorageAPI {
|
2020-06-12 23:04:01 -04:00
|
|
|
return erasureDisks
|
2019-11-19 20:42:27 -05:00
|
|
|
}
|
2020-12-01 16:50:33 -05:00
|
|
|
z.serverPools[0].erasureDisksMu.Unlock()
|
2016-07-21 16:15:54 -04:00
|
|
|
// Upload new content to same object "object"
|
2021-03-31 12:19:14 -04:00
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader(bytes.Repeat([]byte{byte(f)}, smallFileThreshold*16)), smallFileThreshold*16, "", ""), opts)
|
2020-11-23 12:12:17 -05:00
|
|
|
if !errors.Is(err, errErasureWriteQuorum) {
|
2020-06-12 23:04:01 -04:00
|
|
|
t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errErasureWriteQuorum, bucket, object), err)
|
2016-07-21 16:15:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 20:08:17 -04:00
|
|
|
|
2021-03-29 20:00:55 -04:00
|
|
|
func TestPutObjectNoQuorumSmall(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
// Create an instance of xl backend.
|
|
|
|
obj, fsDirs, err := prepareErasure16(ctx)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup backend directories.
|
|
|
|
defer obj.Shutdown(context.Background())
|
|
|
|
defer removeRoots(fsDirs)
|
|
|
|
|
|
|
|
z := obj.(*erasureServerPools)
|
|
|
|
xl := z.serverPools[0].sets[0]
|
|
|
|
|
|
|
|
// Create "bucket"
|
|
|
|
err = obj.MakeBucketWithLocation(ctx, "bucket", BucketOptions{})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
bucket := "bucket"
|
|
|
|
object := "object"
|
|
|
|
opts := ObjectOptions{}
|
|
|
|
// Create "object" under "bucket".
|
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader(bytes.Repeat([]byte{'a'}, smallFileThreshold/2)), smallFileThreshold/2, "", ""), opts)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make 9 disks offline, which leaves less than quorum number of disks
|
|
|
|
// in a 16 disk Erasure setup. The original disks are 'replaced' with
|
|
|
|
// naughtyDisks that fail after 'f' successful StorageAPI method
|
|
|
|
// invocations, where f - [0,2)
|
|
|
|
for f := 0; f < 2; f++ {
|
|
|
|
t.Run("exec-"+strconv.Itoa(f), func(t *testing.T) {
|
|
|
|
diskErrors := make(map[int]error)
|
|
|
|
for i := 0; i <= f; i++ {
|
|
|
|
diskErrors[i] = nil
|
|
|
|
}
|
|
|
|
erasureDisks := xl.getDisks()
|
|
|
|
for i := range erasureDisks[:9] {
|
|
|
|
switch diskType := erasureDisks[i].(type) {
|
|
|
|
case *naughtyDisk:
|
|
|
|
erasureDisks[i] = newNaughtyDisk(diskType.disk, diskErrors, errFaultyDisk)
|
|
|
|
default:
|
|
|
|
erasureDisks[i] = newNaughtyDisk(erasureDisks[i], diskErrors, errFaultyDisk)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
z.serverPools[0].erasureDisksMu.Lock()
|
|
|
|
xl.getDisks = func() []StorageAPI {
|
|
|
|
return erasureDisks
|
|
|
|
}
|
|
|
|
z.serverPools[0].erasureDisksMu.Unlock()
|
|
|
|
// Upload new content to same object "object"
|
|
|
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader(bytes.Repeat([]byte{byte(f)}, smallFileThreshold/2)), smallFileThreshold/2, "", ""), opts)
|
|
|
|
if !errors.Is(err, errErasureWriteQuorum) {
|
|
|
|
t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errErasureWriteQuorum, bucket, object), err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-06-12 23:04:01 -04:00
|
|
|
restoreGlobalStorageClass := globalStorageClass
|
|
|
|
defer func() {
|
|
|
|
globalStorageClass = restoreGlobalStorageClass
|
|
|
|
}()
|
|
|
|
|
2021-01-16 15:08:02 -05:00
|
|
|
globalStorageClass = storageclass.Config{}
|
|
|
|
|
2019-10-07 01:50:24 -04:00
|
|
|
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)
|
|
|
|
|
2020-12-01 16:50:33 -05:00
|
|
|
z := obj.(*erasureServerPools)
|
|
|
|
xl := z.serverPools[0].sets[0]
|
2020-06-12 23:04:01 -04:00
|
|
|
erasureDisks := xl.getDisks()
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(GlobalContext)
|
|
|
|
defer cancel()
|
2019-10-07 01:50:24 -04:00
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
err := obj.MakeBucketWithLocation(ctx, bucket, BucketOptions{})
|
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-06-12 23:04:01 -04:00
|
|
|
_, err = obj.PutObject(ctx, 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)
|
|
|
|
}
|
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
parts1, errs1 := readAllFileInfo(ctx, erasureDisks, bucket, object1, "", false)
|
2020-08-03 15:15:08 -04:00
|
|
|
parts1SC := globalStorageClass
|
|
|
|
|
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-06-12 23:04:01 -04:00
|
|
|
_, err = obj.PutObject(ctx, 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)
|
|
|
|
}
|
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
parts2, errs2 := readAllFileInfo(ctx, erasureDisks, bucket, object2, "", false)
|
2020-08-03 15:15:08 -04:00
|
|
|
parts2SC := globalStorageClass
|
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-06-12 23:04:01 -04:00
|
|
|
_, err = obj.PutObject(ctx, 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)
|
|
|
|
}
|
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
parts3, errs3 := readAllFileInfo(ctx, erasureDisks, bucket, object3, "", false)
|
2020-08-03 15:15:08 -04:00
|
|
|
parts3SC := globalStorageClass
|
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-06-12 23:04:01 -04:00
|
|
|
_, err = obj.PutObject(ctx, 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)
|
|
|
|
}
|
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
parts4, errs4 := readAllFileInfo(ctx, erasureDisks, bucket, object4, "", false)
|
2020-08-03 15:15:08 -04:00
|
|
|
parts4SC := storageclass.Config{
|
|
|
|
Standard: storageclass.StorageClass{
|
|
|
|
Parity: 6,
|
|
|
|
},
|
|
|
|
}
|
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-06-12 23:04:01 -04:00
|
|
|
_, err = obj.PutObject(ctx, 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)
|
|
|
|
}
|
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
parts5, errs5 := readAllFileInfo(ctx, erasureDisks, bucket, object5, "", false)
|
2020-08-03 15:15:08 -04:00
|
|
|
parts5SC := storageclass.Config{
|
|
|
|
RRS: storageclass.StorageClass{
|
|
|
|
Parity: 2,
|
|
|
|
},
|
|
|
|
}
|
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-06-12 23:04:01 -04:00
|
|
|
_, err = obj.PutObject(ctx, 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)
|
|
|
|
}
|
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
parts6, errs6 := readAllFileInfo(ctx, erasureDisks, bucket, object6, "", false)
|
2020-08-03 15:15:08 -04:00
|
|
|
parts6SC := storageclass.Config{
|
|
|
|
RRS: storageclass.StorageClass{
|
|
|
|
Parity: 2,
|
|
|
|
},
|
|
|
|
}
|
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)
|
2021-01-16 15:08:02 -05:00
|
|
|
metadata7["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: 5,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-06-12 23:04:01 -04:00
|
|
|
_, err = obj.PutObject(ctx, 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)
|
|
|
|
}
|
|
|
|
|
2021-01-07 22:27:31 -05:00
|
|
|
parts7, errs7 := readAllFileInfo(ctx, erasureDisks, bucket, object7, "", false)
|
2020-08-03 15:15:08 -04:00
|
|
|
parts7SC := storageclass.Config{
|
|
|
|
Standard: storageclass.StorageClass{
|
|
|
|
Parity: 5,
|
|
|
|
},
|
|
|
|
}
|
2019-10-07 01:50:24 -04:00
|
|
|
|
|
|
|
tests := []struct {
|
2020-06-12 23:04:01 -04:00
|
|
|
parts []FileInfo
|
2019-10-07 01:50:24 -04:00
|
|
|
errs []error
|
|
|
|
expectedReadQuorum int
|
|
|
|
expectedWriteQuorum int
|
2020-08-03 15:15:08 -04:00
|
|
|
storageClassCfg storageclass.Config
|
2019-10-07 01:50:24 -04:00
|
|
|
expectedError error
|
|
|
|
}{
|
2021-01-16 15:08:02 -05:00
|
|
|
{parts1, errs1, 12, 12, parts1SC, nil},
|
2020-08-03 15:15:08 -04:00
|
|
|
{parts2, errs2, 14, 14, parts2SC, nil},
|
2021-01-16 15:08:02 -05:00
|
|
|
{parts3, errs3, 12, 12, parts3SC, nil},
|
2020-08-03 15:15:08 -04:00
|
|
|
{parts4, errs4, 10, 10, parts4SC, nil},
|
|
|
|
{parts5, errs5, 14, 14, parts5SC, nil},
|
2021-01-16 15:08:02 -05:00
|
|
|
{parts6, errs6, 12, 12, parts6SC, nil},
|
|
|
|
{parts7, errs7, 11, 11, parts7SC, nil},
|
2019-10-07 01:50:24 -04:00
|
|
|
}
|
2020-06-12 23:04:01 -04:00
|
|
|
for _, tt := range tests {
|
|
|
|
tt := tt
|
|
|
|
t.(*testing.T).Run("", func(t *testing.T) {
|
2020-08-03 15:15:08 -04:00
|
|
|
globalStorageClass = tt.storageClassCfg
|
2021-01-16 15:08:02 -05:00
|
|
|
actualReadQuorum, actualWriteQuorum, err := objectQuorumFromMeta(ctx, tt.parts, tt.errs, getDefaultParityBlocks(len(erasureDisks)))
|
2020-06-12 23:04:01 -04:00
|
|
|
if tt.expectedError != nil && err == nil {
|
|
|
|
t.Errorf("Expected %s, got %s", tt.expectedError, err)
|
|
|
|
}
|
|
|
|
if tt.expectedError == nil && err != nil {
|
|
|
|
t.Errorf("Expected %s, got %s", tt.expectedError, err)
|
|
|
|
}
|
|
|
|
if tt.expectedReadQuorum != actualReadQuorum {
|
|
|
|
t.Errorf("Expected Read Quorum %d, got %d", tt.expectedReadQuorum, actualReadQuorum)
|
|
|
|
}
|
|
|
|
if tt.expectedWriteQuorum != actualWriteQuorum {
|
|
|
|
t.Errorf("Expected Write Quorum %d, got %d", tt.expectedWriteQuorum, actualWriteQuorum)
|
|
|
|
}
|
|
|
|
})
|
2019-10-07 01:50:24 -04:00
|
|
|
}
|
|
|
|
}
|