From c0adb52213965941969dbdc6e2e3dac0a2b90f10 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 11 Jul 2020 09:37:34 -0700 Subject: [PATCH] sync to disk only upon successful legacy metadata rename (#10018) --- cmd/xl-storage.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index 87efcfd68..de89a18b6 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -1232,7 +1232,12 @@ func (s *xlStorage) renameLegacyMetadata(volume, path string) error { dstFilePath := pathJoin(filePath, xlStorageFormatFile) // Renaming xl.json to xl.meta should be fully synced to disk. - defer globalSync() + defer func() { + if err == nil { + // Sync to disk only upon success. + globalSync() + } + }() if err = os.Rename(srcFilePath, dstFilePath); err != nil { switch { @@ -2111,7 +2116,7 @@ func (s *xlStorage) RenameData(srcVolume, srcPath, dataDir, dstVolume, dstPath s return osErrToFileErr(err) } - // Sync all the directory operations. + // Sync all the previous directory operations. globalSync() for _, entry := range entries {