From 5cce9361bceb8435ca75145e6a4f4225b53e2e18 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 5 Apr 2021 08:52:28 -0700 Subject: [PATCH] fix: avoid an extra rename when there is no dataDir (#11964) also perform globalSync() in defer when enabled for RenameData(), to ensure all calls are flushed to disk. --- cmd/xl-storage.go | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/cmd/xl-storage.go b/cmd/xl-storage.go index aff52c74b..5168e39ba 100644 --- a/cmd/xl-storage.go +++ b/cmd/xl-storage.go @@ -1143,6 +1143,7 @@ func (s *xlStorage) readAllData(volumeDir string, filePath string, requireDirect if err != nil { err = osErrToFileErr(err) } + return buf, err } @@ -1811,6 +1812,14 @@ func (s *xlStorage) Delete(ctx context.Context, volume string, path string, recu // RenameData - rename source path to destination path atomically, metadata and data directory. func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath, dataDir, dstVolume, dstPath string) (err error) { + defer func() { + if err == nil { + if s.globalSync { + globalSync() + } + } + }() + srcVolumeDir, err := s.getVolDir(srcVolume) if err != nil { return err @@ -1984,11 +1993,6 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath, dataDir, return osErrToFileErr(err) } - if s.globalSync { - // Sync all the previous directory operations. - globalSync() - } - for _, entry := range entries { // Skip xl.meta renames further, also ignore any directories such as `legacyDataDir` if entry == xlStorageFormatFile || strings.HasSuffix(entry, slashSeparator) { @@ -1999,11 +2003,6 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath, dataDir, return osErrToFileErr(err) } } - - // Sync all the metadata operations once renames are done. - if s.globalSync { - globalSync() - } } var oldDstDataPath string @@ -2032,13 +2031,12 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath, dataDir, return err } - if oldDstDataPath != "" { - renameAll(oldDstDataPath, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, mustGetUUID())) - } - renameAll(dstDataPath, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, mustGetUUID())) - // renameAll only for objects that have xl.meta not saved inline. if len(fi.Data) == 0 && fi.Size > 0 { + if oldDstDataPath != "" { + renameAll(oldDstDataPath, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, mustGetUUID())) + } + renameAll(dstDataPath, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, mustGetUUID())) if err = renameAll(srcDataPath, dstDataPath); err != nil { logger.LogIf(ctx, err) return osErrToFileErr(err)