2016-06-14 10:12:15 +02:00
|
|
|
/*
|
2019-04-09 20:39:42 +02:00
|
|
|
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
2016-06-14 10:12:15 +02: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-19 01:23:42 +02:00
|
|
|
package cmd
|
2016-06-14 10:12:15 +02:00
|
|
|
|
2016-07-29 01:49:59 +02:00
|
|
|
import (
|
2018-02-16 02:45:57 +01:00
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
2017-06-13 02:40:28 +02:00
|
|
|
"os"
|
2018-03-19 17:13:00 +01:00
|
|
|
"reflect"
|
2016-07-29 01:49:59 +02:00
|
|
|
"testing"
|
|
|
|
)
|
2016-06-14 10:12:15 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// Test get offline/online uuids.
|
|
|
|
func TestGetUUIDs(t *testing.T) {
|
2018-03-15 21:55:23 +01:00
|
|
|
fmtV2 := newFormatXLV3(4, 16)
|
|
|
|
formats := make([]*formatXLV3, 64)
|
2016-06-14 10:12:15 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
for i := 0; i < 4; i++ {
|
|
|
|
for j := 0; j < 16; j++ {
|
|
|
|
newFormat := *fmtV2
|
|
|
|
newFormat.XL.This = fmtV2.XL.Sets[i][j]
|
|
|
|
formats[i*16+j] = &newFormat
|
|
|
|
}
|
|
|
|
}
|
2016-08-12 17:36:43 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
gotCount := len(getOnlineUUIDs(fmtV2, formats))
|
|
|
|
if gotCount != 64 {
|
|
|
|
t.Errorf("Expected online count '64', got '%d'", gotCount)
|
2016-08-12 17:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
for i := 0; i < 4; i++ {
|
|
|
|
for j := 0; j < 16; j++ {
|
|
|
|
if j < 4 {
|
|
|
|
formats[i*16+j] = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-12 17:36:43 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
gotCount = len(getOnlineUUIDs(fmtV2, formats))
|
|
|
|
if gotCount != 48 {
|
|
|
|
t.Errorf("Expected online count '48', got '%d'", gotCount)
|
2016-08-12 17:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
gotCount = len(getOfflineUUIDs(fmtV2, formats))
|
|
|
|
if gotCount != 16 {
|
|
|
|
t.Errorf("Expected offline count '16', got '%d'", gotCount)
|
2017-10-22 07:30:34 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
markUUIDsOffline(fmtV2, formats)
|
|
|
|
gotCount = 0
|
|
|
|
for i := range fmtV2.XL.Sets {
|
|
|
|
for j := range fmtV2.XL.Sets[i] {
|
|
|
|
if fmtV2.XL.Sets[i][j] == offlineDiskUUID {
|
|
|
|
gotCount++
|
|
|
|
}
|
2016-08-12 17:36:43 +02:00
|
|
|
}
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
if gotCount != 16 {
|
|
|
|
t.Errorf("Expected offline count '16', got '%d'", gotCount)
|
|
|
|
}
|
2016-09-09 21:53:09 +02:00
|
|
|
}
|
|
|
|
|
2018-03-19 17:13:00 +01:00
|
|
|
// tests fixFormatXLV3 - fix format.json on all disks.
|
|
|
|
func TestFixFormatV3(t *testing.T) {
|
|
|
|
xlDirs, err := getRandomDisks(8)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
for _, xlDir := range xlDirs {
|
|
|
|
defer os.RemoveAll(xlDir)
|
|
|
|
}
|
2019-11-20 02:42:27 +01:00
|
|
|
endpoints := mustGetNewEndpoints(xlDirs...)
|
2018-03-19 17:13:00 +01:00
|
|
|
|
2019-09-28 01:47:12 +02:00
|
|
|
storageDisks, errs := initStorageDisksWithErrors(endpoints)
|
|
|
|
for _, err := range errs {
|
|
|
|
if err != nil && err != errDiskNotFound {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-04-04 06:58:48 +02:00
|
|
|
}
|
|
|
|
|
2018-03-19 17:13:00 +01:00
|
|
|
format := newFormatXLV3(1, 8)
|
|
|
|
formats := make([]*formatXLV3, 8)
|
|
|
|
|
|
|
|
for j := 0; j < 8; j++ {
|
2019-11-21 13:24:51 +01:00
|
|
|
newFormat := format.Clone()
|
2018-03-19 17:13:00 +01:00
|
|
|
newFormat.XL.This = format.XL.Sets[0][j]
|
2019-11-21 13:24:51 +01:00
|
|
|
formats[j] = newFormat
|
2018-03-19 17:13:00 +01:00
|
|
|
}
|
|
|
|
|
2018-04-04 06:58:48 +02:00
|
|
|
if err = initFormatXLMetaVolume(storageDisks, formats); err != nil {
|
2018-03-19 17:13:00 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
formats[1] = nil
|
|
|
|
expThis := formats[2].XL.This
|
|
|
|
formats[2].XL.This = ""
|
2018-04-04 06:58:48 +02:00
|
|
|
if err := fixFormatXLV3(storageDisks, endpoints, formats); err != nil {
|
2018-03-19 17:13:00 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-04-04 06:58:48 +02:00
|
|
|
|
|
|
|
newFormats, errs := loadFormatXLAll(storageDisks)
|
2018-03-19 17:13:00 +01:00
|
|
|
for _, err := range errs {
|
2018-04-10 18:36:37 +02:00
|
|
|
if err != nil && err != errUnformattedDisk {
|
2018-03-19 17:13:00 +01:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gotThis := newFormats[2].XL.This
|
|
|
|
if expThis != gotThis {
|
|
|
|
t.Fatalf("expected uuid %s, got %s", expThis, gotThis)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// tests formatXLV3ThisEmpty conditions.
|
|
|
|
func TestFormatXLEmpty(t *testing.T) {
|
|
|
|
format := newFormatXLV3(1, 16)
|
|
|
|
formats := make([]*formatXLV3, 16)
|
|
|
|
|
|
|
|
for j := 0; j < 16; j++ {
|
2019-11-21 13:24:51 +01:00
|
|
|
newFormat := format.Clone()
|
2018-03-19 17:13:00 +01:00
|
|
|
newFormat.XL.This = format.XL.Sets[0][j]
|
2019-11-21 13:24:51 +01:00
|
|
|
formats[j] = newFormat
|
2018-03-19 17:13:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// empty format to indicate disk not found, but this
|
|
|
|
// empty should return false.
|
|
|
|
formats[0] = nil
|
|
|
|
|
|
|
|
if ok := formatXLV3ThisEmpty(formats); ok {
|
|
|
|
t.Fatalf("expected value false, got %t", ok)
|
|
|
|
}
|
|
|
|
|
|
|
|
formats[2].XL.This = ""
|
|
|
|
if ok := formatXLV3ThisEmpty(formats); !ok {
|
|
|
|
t.Fatalf("expected value true, got %t", ok)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// Tests format xl get version.
|
|
|
|
func TestFormatXLGetVersion(t *testing.T) {
|
|
|
|
// Get test root.
|
|
|
|
rootPath, err := getTestRoot()
|
2016-09-10 00:32:08 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
defer os.RemoveAll(rootPath)
|
2016-09-09 21:53:09 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
v := &formatXLVersionDetect{}
|
|
|
|
v.XL.Version = "1"
|
|
|
|
b, err := json.Marshal(v)
|
2016-09-09 21:53:09 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
if err = ioutil.WriteFile(pathJoin(rootPath, formatConfigFile), b, os.FileMode(0644)); err != nil {
|
|
|
|
t.Fatal(err)
|
2016-08-12 17:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
_, err = formatXLGetVersion("not-found")
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected to fail but found success")
|
2016-08-12 17:36:43 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
vstr, err := formatXLGetVersion(pathJoin(rootPath, formatConfigFile))
|
2016-07-29 01:49:59 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
if vstr != "1" {
|
|
|
|
t.Fatalf("Expected version '1', got '%s'", vstr)
|
|
|
|
}
|
|
|
|
}
|
2016-07-29 01:49:59 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// Tests format get backend format.
|
|
|
|
func TestFormatMetaGetFormatBackendXL(t *testing.T) {
|
|
|
|
// Get test root.
|
|
|
|
rootPath, err := getTestRoot()
|
2016-07-29 01:49:59 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
defer os.RemoveAll(rootPath)
|
2016-07-29 01:49:59 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
m := &formatMetaV1{
|
|
|
|
Format: "fs",
|
|
|
|
Version: formatMetaVersionV1,
|
|
|
|
}
|
2016-07-29 01:49:59 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
b, err := json.Marshal(m)
|
2016-07-29 01:49:59 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
if err = ioutil.WriteFile(pathJoin(rootPath, formatConfigFile), b, os.FileMode(0644)); err != nil {
|
2016-07-29 01:49:59 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
|
|
|
|
_, err = formatMetaGetFormatBackendXL("not-found")
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected to fail but found success")
|
2016-07-29 01:49:59 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
format, err := formatMetaGetFormatBackendXL(pathJoin(rootPath, formatConfigFile))
|
|
|
|
if err != nil {
|
2016-07-29 01:49:59 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
if format != m.Format {
|
|
|
|
t.Fatalf("Expected format value %s, got %s", m.Format, format)
|
2016-07-29 01:49:59 +02:00
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
|
|
|
|
m = &formatMetaV1{
|
|
|
|
Format: "xl",
|
|
|
|
Version: "2",
|
2016-07-29 01:49:59 +02:00
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
|
|
|
|
b, err = json.Marshal(m)
|
|
|
|
if err != nil {
|
2016-07-29 01:49:59 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
|
|
|
|
if err = ioutil.WriteFile(pathJoin(rootPath, formatConfigFile), b, os.FileMode(0644)); err != nil {
|
2016-07-29 01:49:59 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
_, err = formatMetaGetFormatBackendXL(pathJoin(rootPath, formatConfigFile))
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Expected to fail with incompatible meta version")
|
2016-07-29 01:49:59 +02:00
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
}
|
2016-07-29 01:49:59 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// Tests xl format migration.
|
|
|
|
func TestFormatXLMigrate(t *testing.T) {
|
|
|
|
// Get test root.
|
|
|
|
rootPath, err := getTestRoot()
|
2016-07-29 01:49:59 +02:00
|
|
|
if err != nil {
|
2018-02-16 02:45:57 +01:00
|
|
|
t.Fatal(err)
|
2016-07-29 01:49:59 +02:00
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
defer os.RemoveAll(rootPath)
|
2016-07-29 01:49:59 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
m := &formatXLV1{}
|
|
|
|
m.Format = formatBackendXL
|
|
|
|
m.Version = formatMetaVersionV1
|
|
|
|
m.XL.Version = formatXLVersionV1
|
|
|
|
m.XL.Disk = mustGetUUID()
|
|
|
|
m.XL.JBOD = []string{m.XL.Disk, mustGetUUID(), mustGetUUID(), mustGetUUID()}
|
2016-07-29 01:49:59 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
b, err := json.Marshal(m)
|
2016-07-29 01:49:59 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
if err = os.MkdirAll(pathJoin(rootPath, minioMetaBucket), os.FileMode(0755)); err != nil {
|
2016-07-29 01:49:59 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
if err = ioutil.WriteFile(pathJoin(rootPath, minioMetaBucket, formatConfigFile), b, os.FileMode(0644)); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-07-29 01:49:59 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
if err = formatXLMigrate(rootPath); err != nil {
|
2016-07-29 01:49:59 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-03-15 21:55:23 +01:00
|
|
|
migratedVersion, err := formatXLGetVersion(pathJoin(rootPath, minioMetaBucket, formatConfigFile))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if migratedVersion != formatXLVersionV3 {
|
2018-03-19 17:13:00 +01:00
|
|
|
t.Fatalf("expected version: %s, got: %s", formatXLVersionV3, migratedVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
b, err = ioutil.ReadFile(pathJoin(rootPath, minioMetaBucket, formatConfigFile))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
formatV3 := &formatXLV3{}
|
|
|
|
if err = json.Unmarshal(b, formatV3); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if formatV3.XL.This != m.XL.Disk {
|
|
|
|
t.Fatalf("expected disk uuid: %s, got: %s", m.XL.Disk, formatV3.XL.This)
|
|
|
|
}
|
|
|
|
if len(formatV3.XL.Sets) != 1 {
|
|
|
|
t.Fatalf("expected single set after migrating from v1 to v3, but found %d", len(formatV3.XL.Sets))
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(formatV3.XL.Sets[0], m.XL.JBOD) {
|
|
|
|
t.Fatalf("expected disk uuid: %v, got: %v", m.XL.JBOD, formatV3.XL.Sets[0])
|
2018-03-15 21:55:23 +01:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
m = &formatXLV1{}
|
|
|
|
m.Format = "unknown"
|
|
|
|
m.Version = formatMetaVersionV1
|
|
|
|
m.XL.Version = formatXLVersionV1
|
|
|
|
m.XL.Disk = mustGetUUID()
|
|
|
|
m.XL.JBOD = []string{m.XL.Disk, mustGetUUID(), mustGetUUID(), mustGetUUID()}
|
|
|
|
|
|
|
|
b, err = json.Marshal(m)
|
|
|
|
if err != nil {
|
2016-07-29 01:49:59 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
|
|
|
|
if err = ioutil.WriteFile(pathJoin(rootPath, minioMetaBucket, formatConfigFile), b, os.FileMode(0644)); err != nil {
|
2016-07-29 01:49:59 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
if err = formatXLMigrate(rootPath); err == nil {
|
|
|
|
t.Fatal("Expected to fail with unexpected backend format")
|
|
|
|
}
|
2016-07-29 01:49:59 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
m = &formatXLV1{}
|
|
|
|
m.Format = formatBackendXL
|
|
|
|
m.Version = formatMetaVersionV1
|
2018-03-15 21:55:23 +01:00
|
|
|
m.XL.Version = "30"
|
2018-02-16 02:45:57 +01:00
|
|
|
m.XL.Disk = mustGetUUID()
|
|
|
|
m.XL.JBOD = []string{m.XL.Disk, mustGetUUID(), mustGetUUID(), mustGetUUID()}
|
2016-07-29 01:49:59 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
b, err = json.Marshal(m)
|
2016-07-29 01:49:59 +02:00
|
|
|
if err != nil {
|
2018-02-16 02:45:57 +01:00
|
|
|
t.Fatal(err)
|
2016-07-29 01:49:59 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
if err = ioutil.WriteFile(pathJoin(rootPath, minioMetaBucket, formatConfigFile), b, os.FileMode(0644)); err != nil {
|
|
|
|
t.Fatal(err)
|
2016-07-29 01:49:59 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
if err = formatXLMigrate(rootPath); err == nil {
|
|
|
|
t.Fatal("Expected to fail with unexpected backend format version number")
|
2016-07-29 01:49:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// Tests check format xl value.
|
|
|
|
func TestCheckFormatXLValue(t *testing.T) {
|
2016-06-14 10:12:15 +02:00
|
|
|
testCases := []struct {
|
2018-03-15 21:55:23 +01:00
|
|
|
format *formatXLV3
|
2018-02-16 02:45:57 +01:00
|
|
|
success bool
|
2016-06-14 10:12:15 +02:00
|
|
|
}{
|
2018-02-16 02:45:57 +01:00
|
|
|
// Invalid XL format version "2".
|
2016-06-14 10:12:15 +02:00
|
|
|
{
|
2018-03-15 21:55:23 +01:00
|
|
|
&formatXLV3{
|
2018-07-17 05:26:42 +02:00
|
|
|
formatMetaV1: formatMetaV1{
|
|
|
|
Version: "2",
|
|
|
|
Format: "XL",
|
|
|
|
},
|
2018-02-16 02:45:57 +01:00
|
|
|
XL: struct {
|
|
|
|
Version string `json:"version"`
|
|
|
|
This string `json:"this"`
|
|
|
|
Sets [][]string `json:"sets"`
|
|
|
|
DistributionAlgo string `json:"distributionAlgo"`
|
|
|
|
}{
|
|
|
|
Version: "2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
2016-06-14 10:12:15 +02:00
|
|
|
},
|
2018-02-16 02:45:57 +01:00
|
|
|
// Invalid XL format "Unknown".
|
2016-06-14 10:12:15 +02:00
|
|
|
{
|
2018-03-15 21:55:23 +01:00
|
|
|
&formatXLV3{
|
2018-07-17 05:26:42 +02:00
|
|
|
formatMetaV1: formatMetaV1{
|
|
|
|
Version: "1",
|
|
|
|
Format: "Unknown",
|
|
|
|
},
|
2018-02-16 02:45:57 +01:00
|
|
|
XL: struct {
|
|
|
|
Version string `json:"version"`
|
|
|
|
This string `json:"this"`
|
|
|
|
Sets [][]string `json:"sets"`
|
|
|
|
DistributionAlgo string `json:"distributionAlgo"`
|
|
|
|
}{
|
|
|
|
Version: "2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
2016-06-14 10:12:15 +02:00
|
|
|
},
|
2018-02-16 02:45:57 +01:00
|
|
|
// Invalid XL format version "0".
|
2016-06-14 10:12:15 +02:00
|
|
|
{
|
2018-03-15 21:55:23 +01:00
|
|
|
&formatXLV3{
|
2018-07-17 05:26:42 +02:00
|
|
|
formatMetaV1: formatMetaV1{
|
|
|
|
Version: "1",
|
|
|
|
Format: "XL",
|
|
|
|
},
|
2018-02-16 02:45:57 +01:00
|
|
|
XL: struct {
|
|
|
|
Version string `json:"version"`
|
|
|
|
This string `json:"this"`
|
|
|
|
Sets [][]string `json:"sets"`
|
|
|
|
DistributionAlgo string `json:"distributionAlgo"`
|
|
|
|
}{
|
|
|
|
Version: "0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
false,
|
2016-09-09 21:53:09 +02:00
|
|
|
},
|
2016-06-14 10:12:15 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// Valid all test cases.
|
2016-06-14 10:12:15 +02:00
|
|
|
for i, testCase := range testCases {
|
2018-02-16 02:45:57 +01:00
|
|
|
if err := checkFormatXLValue(testCase.format); err != nil && testCase.success {
|
|
|
|
t.Errorf("Test %d: Expected failure %s", i+1, err)
|
2016-06-14 10:12:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-09 21:53:09 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// Tests getFormatXLInQuorum()
|
|
|
|
func TestGetFormatXLInQuorumCheck(t *testing.T) {
|
|
|
|
setCount := 2
|
2019-11-21 13:24:51 +01:00
|
|
|
drivesPerSet := 16
|
2016-09-09 21:53:09 +02:00
|
|
|
|
2019-11-21 13:24:51 +01:00
|
|
|
format := newFormatXLV3(setCount, drivesPerSet)
|
2018-03-15 21:55:23 +01:00
|
|
|
formats := make([]*formatXLV3, 32)
|
2017-08-03 13:37:02 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
for i := 0; i < setCount; i++ {
|
2019-11-21 13:24:51 +01:00
|
|
|
for j := 0; j < drivesPerSet; j++ {
|
|
|
|
newFormat := format.Clone()
|
2018-02-16 02:45:57 +01:00
|
|
|
newFormat.XL.This = format.XL.Sets[i][j]
|
2019-11-21 13:24:51 +01:00
|
|
|
formats[i*drivesPerSet+j] = newFormat
|
2017-08-03 13:37:02 +02:00
|
|
|
}
|
2016-09-09 21:53:09 +02:00
|
|
|
}
|
2016-09-10 18:54:22 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// Return a format from list of formats in quorum.
|
|
|
|
quorumFormat, err := getFormatXLInQuorum(formats)
|
2016-09-11 04:32:18 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// Check if the reference format and input formats are same.
|
2018-03-15 21:55:23 +01:00
|
|
|
if err = formatXLV3Check(quorumFormat, formats[0]); err != nil {
|
2016-09-10 18:54:22 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// QuorumFormat has .This field empty on purpose, expect a failure.
|
2018-03-15 21:55:23 +01:00
|
|
|
if err = formatXLV3Check(formats[0], quorumFormat); err == nil {
|
2018-02-16 02:45:57 +01:00
|
|
|
t.Fatal("Unexpected success")
|
2016-09-10 18:54:22 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
formats[0] = nil
|
|
|
|
quorumFormat, err = getFormatXLInQuorum(formats)
|
2016-09-11 04:32:18 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
badFormat := *quorumFormat
|
|
|
|
badFormat.XL.Sets = nil
|
2018-03-15 21:55:23 +01:00
|
|
|
if err = formatXLV3Check(quorumFormat, &badFormat); err == nil {
|
2018-02-16 02:45:57 +01:00
|
|
|
t.Fatal("Unexpected success")
|
2016-09-10 18:54:22 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
badFormatUUID := *quorumFormat
|
|
|
|
badFormatUUID.XL.Sets[0][0] = "bad-uuid"
|
2018-03-15 21:55:23 +01:00
|
|
|
if err = formatXLV3Check(quorumFormat, &badFormatUUID); err == nil {
|
2018-02-16 02:45:57 +01:00
|
|
|
t.Fatal("Unexpected success")
|
2016-09-10 18:54:22 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
badFormatSetSize := *quorumFormat
|
|
|
|
badFormatSetSize.XL.Sets[0] = nil
|
2018-03-15 21:55:23 +01:00
|
|
|
if err = formatXLV3Check(quorumFormat, &badFormatSetSize); err == nil {
|
2018-02-16 02:45:57 +01:00
|
|
|
t.Fatal("Unexpected success")
|
2016-09-11 04:32:18 +02:00
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
for i := range formats {
|
|
|
|
if i < 17 {
|
|
|
|
formats[i] = nil
|
2016-09-10 18:54:22 +02:00
|
|
|
}
|
|
|
|
}
|
2018-02-16 02:45:57 +01:00
|
|
|
if _, err = getFormatXLInQuorum(formats); err == nil {
|
|
|
|
t.Fatal("Unexpected success")
|
2016-09-10 18:54:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-19 05:17:35 +02:00
|
|
|
// Tests formatXLGetDeploymentID()
|
|
|
|
func TestGetXLID(t *testing.T) {
|
|
|
|
setCount := 2
|
2019-11-21 13:24:51 +01:00
|
|
|
drivesPerSet := 8
|
2018-07-19 05:17:35 +02:00
|
|
|
|
2019-11-21 13:24:51 +01:00
|
|
|
format := newFormatXLV3(setCount, drivesPerSet)
|
2018-07-19 05:17:35 +02:00
|
|
|
formats := make([]*formatXLV3, 16)
|
|
|
|
|
|
|
|
for i := 0; i < setCount; i++ {
|
2019-11-21 13:24:51 +01:00
|
|
|
for j := 0; j < drivesPerSet; j++ {
|
|
|
|
newFormat := format.Clone()
|
2018-07-19 05:17:35 +02:00
|
|
|
newFormat.XL.This = format.XL.Sets[i][j]
|
2019-11-21 13:24:51 +01:00
|
|
|
formats[i*drivesPerSet+j] = newFormat
|
2018-07-19 05:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return a format from list of formats in quorum.
|
|
|
|
quorumFormat, err := getFormatXLInQuorum(formats)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the reference format and input formats are same.
|
|
|
|
var id string
|
|
|
|
if id, err = formatXLGetDeploymentID(quorumFormat, formats); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if id == "" {
|
|
|
|
t.Fatal("ID cannot be empty.")
|
|
|
|
}
|
|
|
|
|
|
|
|
formats[0] = nil
|
|
|
|
if id, err = formatXLGetDeploymentID(quorumFormat, formats); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if id == "" {
|
|
|
|
t.Fatal("ID cannot be empty.")
|
|
|
|
}
|
|
|
|
|
|
|
|
formats[1].XL.Sets[0][0] = "bad-uuid"
|
|
|
|
if id, err = formatXLGetDeploymentID(quorumFormat, formats); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if id == "" {
|
|
|
|
t.Fatal("ID cannot be empty.")
|
|
|
|
}
|
|
|
|
|
|
|
|
formats[2].ID = "bad-id"
|
2019-02-13 13:59:36 +01:00
|
|
|
if _, err = formatXLGetDeploymentID(quorumFormat, formats); err != errCorruptedFormat {
|
2018-07-19 05:17:35 +02:00
|
|
|
t.Fatal("Unexpected Success")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// Initialize new format sets.
|
|
|
|
func TestNewFormatSets(t *testing.T) {
|
|
|
|
setCount := 2
|
2019-11-21 13:24:51 +01:00
|
|
|
drivesPerSet := 16
|
2016-09-10 18:54:22 +02:00
|
|
|
|
2019-11-21 13:24:51 +01:00
|
|
|
format := newFormatXLV3(setCount, drivesPerSet)
|
2018-03-15 21:55:23 +01:00
|
|
|
formats := make([]*formatXLV3, 32)
|
2018-02-16 02:45:57 +01:00
|
|
|
errs := make([]error, 32)
|
2016-09-11 04:32:18 +02:00
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
for i := 0; i < setCount; i++ {
|
2019-11-21 13:24:51 +01:00
|
|
|
for j := 0; j < drivesPerSet; j++ {
|
|
|
|
newFormat := format.Clone()
|
2018-02-16 02:45:57 +01:00
|
|
|
newFormat.XL.This = format.XL.Sets[i][j]
|
2019-11-21 13:24:51 +01:00
|
|
|
formats[i*drivesPerSet+j] = newFormat
|
2016-09-10 18:54:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
quorumFormat, err := getFormatXLInQuorum(formats)
|
2016-11-17 01:42:23 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2018-02-16 02:45:57 +01:00
|
|
|
// 16th disk is unformatted.
|
|
|
|
errs[15] = errUnformattedDisk
|
2016-09-11 04:32:18 +02:00
|
|
|
|
2019-11-21 13:24:51 +01:00
|
|
|
newFormats := newHealFormatSets(quorumFormat, setCount, drivesPerSet, formats, errs)
|
2018-02-16 02:45:57 +01:00
|
|
|
if newFormats == nil {
|
|
|
|
t.Fatal("Unexpected failure")
|
2016-09-10 18:54:22 +02:00
|
|
|
}
|
2019-01-23 03:32:06 +01:00
|
|
|
|
|
|
|
// Check if deployment IDs are preserved.
|
|
|
|
for i := range newFormats {
|
|
|
|
for j := range newFormats[i] {
|
|
|
|
if newFormats[i][j].ID != quorumFormat.ID {
|
|
|
|
t.Fatal("Deployment id in the new format is lost")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-10 18:54:22 +02:00
|
|
|
}
|
2019-09-28 01:47:12 +02:00
|
|
|
|
|
|
|
func BenchmarkInitStorageDisks256(b *testing.B) {
|
|
|
|
benchmarkInitStorageDisksN(b, 256)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkInitStorageDisks1024(b *testing.B) {
|
|
|
|
benchmarkInitStorageDisksN(b, 1024)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkInitStorageDisks2048(b *testing.B) {
|
|
|
|
benchmarkInitStorageDisksN(b, 2048)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkInitStorageDisksMax(b *testing.B) {
|
|
|
|
benchmarkInitStorageDisksN(b, 32*204)
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchmarkInitStorageDisksN(b *testing.B, nDisks int) {
|
|
|
|
b.ResetTimer()
|
|
|
|
b.ReportAllocs()
|
|
|
|
|
|
|
|
fsDirs, err := getRandomDisks(nDisks)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
2019-11-20 02:42:27 +01:00
|
|
|
endpoints := mustGetNewEndpoints(fsDirs...)
|
2019-09-28 01:47:12 +02:00
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
endpoints := endpoints
|
|
|
|
for pb.Next() {
|
|
|
|
initStorageDisksWithErrors(endpoints)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|