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
This commit is contained in:
Krishnan Parthasarathi 2022-01-24 17:09:12 -08:00 committed by GitHub
parent 295730408b
commit ebc3627c73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 27 deletions

View File

@ -40,6 +40,7 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/dustin/go-humanize"
fcolor "github.com/fatih/color" fcolor "github.com/fatih/color"
"github.com/go-openapi/loads" "github.com/go-openapi/loads"
"github.com/inconshreveable/mousetrap" "github.com/inconshreveable/mousetrap"
@ -652,6 +653,16 @@ func handleCommonEnvVars() {
logger.Fatal(config.ErrInvalidFSOSyncValue(err), "Invalid MINIO_FS_OSYNC value in environment variable") 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, "") domains := env.Get(config.EnvDomain, "")
if len(domains) != 0 { if len(domains) != 0 {
for _, domainName := range strings.Split(domains, config.ValueSeparator) { for _, domainName := range strings.Split(domains, config.ValueSeparator) {

View File

@ -341,6 +341,10 @@ var (
// List of local drives to this node, this is only set during server startup. // List of local drives to this node, this is only set during server startup.
globalLocalDrives []StorageAPI globalLocalDrives []StorageAPI
// Is MINIO_CI_CD set?
globalIsCICD bool
globalRootDiskThreshold uint64
// Add new variable global values here. // Add new variable global values here.
) )

View File

@ -41,12 +41,10 @@ import (
jsoniter "github.com/json-iterator/go" jsoniter "github.com/json-iterator/go"
"github.com/minio/minio/internal/bucket/lifecycle" "github.com/minio/minio/internal/bucket/lifecycle"
"github.com/minio/minio/internal/color" "github.com/minio/minio/internal/color"
"github.com/minio/minio/internal/config"
"github.com/minio/minio/internal/disk" "github.com/minio/minio/internal/disk"
xioutil "github.com/minio/minio/internal/ioutil" xioutil "github.com/minio/minio/internal/ioutil"
"github.com/minio/minio/internal/logger" "github.com/minio/minio/internal/logger"
"github.com/minio/pkg/console" "github.com/minio/pkg/console"
"github.com/minio/pkg/env"
"github.com/yargevad/filepathx" "github.com/yargevad/filepathx"
) )
@ -215,38 +213,32 @@ func newXLStorage(ep Endpoint) (s *xlStorage, err error) {
} }
var rootDisk bool var rootDisk bool
if env.Get("MINIO_CI_CD", "") != "" { if globalIsCICD {
rootDisk = true rootDisk = true
} else { } else {
rootDisk, err = disk.IsRootDisk(path, SlashSeparator) rootDisk, err = disk.IsRootDisk(path, SlashSeparator)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if !rootDisk { if !rootDisk && globalRootDiskThreshold > 0 {
// If for some reason we couldn't detect the // If for some reason we couldn't detect the root disk
// root disk use - MINIO_ROOTDISK_THRESHOLD_SIZE // use - MINIO_ROOTDISK_THRESHOLD_SIZE to figure out if
// to figure out if the disk is root disk or not. // this disk is a root disk.
if rootDiskSize := env.Get(config.EnvRootDiskThresholdSize, ""); rootDiskSize != "" { info, err := disk.GetInfo(path)
info, err := disk.GetInfo(path) if err != nil {
if err != nil { return nil, err
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
} }
// treat those disks with size less than or equal to the
// threshold as rootDisks.
rootDisk = info.Total <= globalRootDiskThreshold
} }
} }
s = &xlStorage{ s = &xlStorage{
diskPath: path, diskPath: path,
endpoint: ep, endpoint: ep,
globalSync: env.Get(config.EnvFSOSync, config.EnableOff) == config.EnableOn, globalSync: globalFSOSync,
rootDisk: rootDisk, rootDisk: rootDisk,
poolIndex: -1, poolIndex: -1,
setIndex: -1, setIndex: -1,
@ -285,6 +277,11 @@ func newXLStorage(ep Endpoint) (s *xlStorage, err error) {
return s, err return s, err
} }
Remove(filePath) Remove(filePath)
// Create all necessary bucket folders if possible.
if err = makeFormatErasureMetaVolumes(s); err != nil {
return nil, err
}
} else { } else {
format := &formatErasureV3{} format := &formatErasureV3{}
json := jsoniter.ConfigCompatibleWithStandardLibrary json := jsoniter.ConfigCompatibleWithStandardLibrary
@ -296,11 +293,6 @@ func newXLStorage(ep Endpoint) (s *xlStorage, err error) {
s.formatLegacy = format.Erasure.DistributionAlgo == formatErasureVersionV2DistributionAlgoV1 s.formatLegacy = format.Erasure.DistributionAlgo == formatErasureVersionV2DistributionAlgoV1
} }
// Create all necessary bucket folders if possible.
if err = makeFormatErasureMetaVolumes(s); err != nil {
return nil, err
}
// Success. // Success.
return s, nil 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. // in-case the caller is a network operation.
if volume == minioMetaBucket && path == formatConfigFile { if volume == minioMetaBucket && path == formatConfigFile {
s.RLock() s.RLock()
formatData := s.formatData formatData := make([]byte, len(s.formatData))
copy(formatData, s.formatData)
s.RUnlock() s.RUnlock()
if len(formatData) > 0 { if len(formatData) > 0 {
return formatData, nil return formatData, nil