@ -24,6 +24,7 @@ import (
"path"
"path"
"time"
"time"
"github.com/minio/minio/cmd/logger"
"github.com/minio/minio/pkg/lock"
"github.com/minio/minio/pkg/lock"
)
)
@ -332,29 +333,43 @@ func formatFSFixDeploymentID(fsFormatPath string) error {
return nil
return nil
}
}
formatStartTime := time . Now ( ) . Round ( time . Second )
getElapsedTime := func ( ) string {
return time . Now ( ) . Round ( time . Second ) . Sub ( formatStartTime ) . String ( )
}
doneCh := make ( chan struct { } )
defer close ( doneCh )
retryTimerCh := newRetryTimerSimple ( doneCh )
for {
for {
wlk , err := lock . TryLockedOpenFile ( fsFormatPath , os . O_RDWR , 0 )
select {
if err == lock . ErrAlreadyLocked {
case <- retryTimerCh :
// Lock already present, sleep and attempt again.
time . Sleep ( 100 * time . Millisecond )
continue
}
if err != nil {
return err
}
defer wlk . Close ( )
err = jsonLoad ( wlk , format )
wlk , err := lock . TryLockedOpenFile ( fsFormatPath , os . O_RDWR , 0 )
if err != nil {
if err == lock . ErrAlreadyLocked {
return err
// Lock already present, sleep and attempt again
}
// Check if it needs to be updated
logger . Info ( "Another minio process(es) might be holding a lock to the file %s. Please kill that minio process(es) (elapsed %s)\n" , fsFormatPath , getElapsedTime ( ) )
if format . ID != "" {
continue
return nil
}
if err != nil {
return err
}
defer wlk . Close ( )
err = jsonLoad ( wlk , format )
if err != nil {
return err
}
// Check if it needs to be updated
if format . ID != "" {
return nil
}
format . ID = mustGetUUID ( )
return jsonSave ( wlk , format )
}
}
format . ID = mustGetUUID ( )
return jsonSave ( wlk , format )
}
}
}
}