From ebc3627c73a591dbf74d70d7a00ac91cea5d4a78 Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Mon, 24 Jan 2022 17:09:12 -0800 Subject: [PATCH] further improvements to newXLStorage (#14166) - create internal erasure volumes only if the disk is unformatted - return a copy of format data in xlStorage.ReadAll - parse env vars only once, to be re-used by xl-storage --- cmd/common-main.go | 11 +++++++++++ cmd/globals.go | 4 ++++ cmd/xl-storage.go | 47 ++++++++++++++++++++-------------------------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/cmd/common-main.go b/cmd/common-main.go index 11bb3af6c..1967bbb37 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -40,6 +40,7 @@ import ( "syscall" "time" + "github.com/dustin/go-humanize" fcolor "github.com/fatih/color" "github.com/go-openapi/loads" "github.com/inconshreveable/mousetrap" @@ -652,6 +653,16 @@ func handleCommonEnvVars() { logger.Fatal(config.ErrInvalidFSOSyncValue(err), "Invalid MINIO_FS_OSYNC value in environment variable") } + if rootDiskSize := env.Get(config.EnvRootDiskThresholdSize, ""); rootDiskSize != "" { + size, err := humanize.ParseBytes(rootDiskSize) + if err != nil { + logger.Fatal(err, fmt.Sprintf("Invalid %s value in environment variable", config.EnvRootDiskThresholdSize)) + } + globalRootDiskThreshold = size + } + + globalIsCICD = env.Get("MINIO_CI_CD", "") != "" + domains := env.Get(config.EnvDomain, "") if len(domains) != 0 { for _, domainName := range strings.Split(domains, config.ValueSeparator) { diff --git a/cmd/globals.go b/cmd/globals.go index fc14298fa..b5bc8a0cb 100644 --- a/cmd/globals.go +++ b/cmd/globals.go @@ -341,6 +341,10 @@ var ( // List of local drives to this node, this is only set during server startup. globalLocalDrives []StorageAPI + // Is MINIO_CI_CD set? + globalIsCICD bool + + globalRootDiskThreshold uint64 // Add new variable global values here. ) diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index e7439152b..f06beef76 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -41,12 +41,10 @@ import ( jsoniter "github.com/json-iterator/go" "github.com/minio/minio/internal/bucket/lifecycle" "github.com/minio/minio/internal/color" - "github.com/minio/minio/internal/config" "github.com/minio/minio/internal/disk" xioutil "github.com/minio/minio/internal/ioutil" "github.com/minio/minio/internal/logger" "github.com/minio/pkg/console" - "github.com/minio/pkg/env" "github.com/yargevad/filepathx" ) @@ -215,38 +213,32 @@ func newXLStorage(ep Endpoint) (s *xlStorage, err error) { } var rootDisk bool - if env.Get("MINIO_CI_CD", "") != "" { + if globalIsCICD { rootDisk = true } else { rootDisk, err = disk.IsRootDisk(path, SlashSeparator) if err != nil { return nil, err } - if !rootDisk { - // If for some reason we couldn't detect the - // root disk use - MINIO_ROOTDISK_THRESHOLD_SIZE - // to figure out if the disk is root disk or not. - if rootDiskSize := env.Get(config.EnvRootDiskThresholdSize, ""); rootDiskSize != "" { - info, err := disk.GetInfo(path) - if err != nil { - return nil, err - } - size, err := humanize.ParseBytes(rootDiskSize) - if err != nil { - return nil, err - } - // size of the disk is less than the threshold or - // equal to the size of the disk at path, treat - // such disks as rootDisks and reject them. - rootDisk = info.Total <= size + if !rootDisk && globalRootDiskThreshold > 0 { + // If for some reason we couldn't detect the root disk + // use - MINIO_ROOTDISK_THRESHOLD_SIZE to figure out if + // this disk is a root disk. + info, err := disk.GetInfo(path) + if err != nil { + return nil, err } + + // treat those disks with size less than or equal to the + // threshold as rootDisks. + rootDisk = info.Total <= globalRootDiskThreshold } } s = &xlStorage{ diskPath: path, endpoint: ep, - globalSync: env.Get(config.EnvFSOSync, config.EnableOff) == config.EnableOn, + globalSync: globalFSOSync, rootDisk: rootDisk, poolIndex: -1, setIndex: -1, @@ -285,6 +277,11 @@ func newXLStorage(ep Endpoint) (s *xlStorage, err error) { return s, err } Remove(filePath) + + // Create all necessary bucket folders if possible. + if err = makeFormatErasureMetaVolumes(s); err != nil { + return nil, err + } } else { format := &formatErasureV3{} json := jsoniter.ConfigCompatibleWithStandardLibrary @@ -296,11 +293,6 @@ func newXLStorage(ep Endpoint) (s *xlStorage, err error) { s.formatLegacy = format.Erasure.DistributionAlgo == formatErasureVersionV2DistributionAlgoV1 } - // Create all necessary bucket folders if possible. - if err = makeFormatErasureMetaVolumes(s); err != nil { - return nil, err - } - // Success. return s, nil } @@ -1423,7 +1415,8 @@ func (s *xlStorage) ReadAll(ctx context.Context, volume string, path string) (bu // in-case the caller is a network operation. if volume == minioMetaBucket && path == formatConfigFile { s.RLock() - formatData := s.formatData + formatData := make([]byte, len(s.formatData)) + copy(formatData, s.formatData) s.RUnlock() if len(formatData) > 0 { return formatData, nil