fix: startup load time by reusing storageDisks (#9210)

This commit is contained in:
Harshavardhana
2020-03-27 14:48:30 -07:00
committed by GitHub
parent 0c80bf45d0
commit 6f992134a2
18 changed files with 287 additions and 194 deletions
+10 -6
View File
@@ -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