From 60690a7e1da743fcab8ddb2a54f856c561eb5884 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 13 Nov 2019 21:18:23 +0100 Subject: [PATCH] fs: Fix setting new deployment ID in format when not present (#8517) The code does not properly set a new deployemnt ID when not present in format.json: it loops twice without releasing write lock on format.json causing an infinite locking error on the same file. This commit fixes and simplifies a little the code. --- cmd/format-fs.go | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/cmd/format-fs.go b/cmd/format-fs.go index b426019fc..a75370116 100644 --- a/cmd/format-fs.go +++ b/cmd/format-fs.go @@ -350,27 +350,24 @@ func formatFSFixDeploymentID(fsFormatPath string) error { 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 { - break - } - - if err = jsonLoad(wlk, format); err != nil { - break - } - - // Check if format needs to be updated - if format.ID != "" { - err = nil - break - } - - format.ID = mustGetUUID() - if err = jsonSave(wlk, format); err != nil { - break - } + break } - if wlk != nil { - wlk.Close() + if err != nil { + return err } - return err + + defer wlk.Close() + + if err = jsonLoad(wlk, format); err != nil { + return err + } + + // Check if format needs to be updated + if format.ID != "" { + return nil + } + + // Set new UUID to the format and save it + format.ID = mustGetUUID() + return jsonSave(wlk, format) }