mirror of
https://github.com/pgsty/minio.git
synced 2026-10-06 17:55:59 +03:00
fix: startup load time by reusing storageDisks (#9210)
This commit is contained in:
+10
-6
@@ -424,7 +424,8 @@ func (s *posix) getVolDir(volume string) (string, error) {
|
||||
return volumeDir, nil
|
||||
}
|
||||
|
||||
func (s *posix) getDiskID() (string, error) {
|
||||
// GetDiskID - returns the cached disk uuid
|
||||
func (s *posix) GetDiskID() (string, error) {
|
||||
s.RLock()
|
||||
diskID := s.diskID
|
||||
fileInfo := s.formatFileInfo
|
||||
@@ -440,7 +441,7 @@ func (s *posix) getDiskID() (string, error) {
|
||||
defer s.Unlock()
|
||||
|
||||
// If somebody else updated the disk ID and changed the time, return what they got.
|
||||
if !s.formatLastCheck.Equal(lastCheck) {
|
||||
if !lastCheck.IsZero() && !s.formatLastCheck.Equal(lastCheck) && diskID != "" {
|
||||
// Somebody else got the lock first.
|
||||
return diskID, nil
|
||||
}
|
||||
@@ -448,10 +449,13 @@ func (s *posix) getDiskID() (string, error) {
|
||||
fi, err := os.Stat(formatFile)
|
||||
if err != nil {
|
||||
// If the disk is still not initialized.
|
||||
return "", err
|
||||
if os.IsNotExist(err) {
|
||||
return "", errUnformattedDisk
|
||||
}
|
||||
return "", errCorruptedFormat
|
||||
}
|
||||
|
||||
if xioutil.SameFile(fi, fileInfo) {
|
||||
if xioutil.SameFile(fi, fileInfo) && diskID != "" {
|
||||
// If the file has not changed, just return the cached diskID information.
|
||||
s.formatLastCheck = time.Now()
|
||||
return diskID, nil
|
||||
@@ -459,12 +463,12 @@ func (s *posix) getDiskID() (string, error) {
|
||||
|
||||
b, err := ioutil.ReadFile(formatFile)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", errCorruptedFormat
|
||||
}
|
||||
format := &formatXLV3{}
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
if err = json.Unmarshal(b, &format); err != nil {
|
||||
return "", err
|
||||
return "", errCorruptedFormat
|
||||
}
|
||||
s.diskID = format.XL.This
|
||||
s.formatFileInfo = fi
|
||||
|
||||
Reference in New Issue
Block a user