From a7d407fa4231640b1d804e57057ccd6a33515a6f Mon Sep 17 00:00:00 2001 From: kannappanr <30541348+kannappanr@users.noreply.github.com> Date: Wed, 9 Jan 2019 10:13:04 -0800 Subject: [PATCH] Display message on failure to get lock on format.json in fs mode on startup (#6538) Retry to see if the lock is free. Retry time will increase binomially. --- cmd/format-fs.go | 53 +++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/cmd/format-fs.go b/cmd/format-fs.go index e07e14b35..00f0bfdb8 100644 --- a/cmd/format-fs.go +++ b/cmd/format-fs.go @@ -24,6 +24,7 @@ import ( "path" "time" + "github.com/minio/minio/cmd/logger" "github.com/minio/minio/pkg/lock" ) @@ -332,29 +333,43 @@ func formatFSFixDeploymentID(fsFormatPath string) error { 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 { - wlk, err := lock.TryLockedOpenFile(fsFormatPath, os.O_RDWR, 0) - if err == lock.ErrAlreadyLocked { - // Lock already present, sleep and attempt again. - time.Sleep(100 * time.Millisecond) - continue - } - if err != nil { - return err - } - defer wlk.Close() + select { + case <-retryTimerCh: - err = jsonLoad(wlk, format) - if err != nil { - return err - } + wlk, err := lock.TryLockedOpenFile(fsFormatPath, os.O_RDWR, 0) + if err == lock.ErrAlreadyLocked { + // Lock already present, sleep and attempt again - // Check if it needs to be updated - if format.ID != "" { - return nil + 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()) + continue + } + 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) } }