force delete should just use rename() (#13417)

use rename() instead of forced blocking
delete call, faster for large namespaces.
This commit is contained in:
Harshavardhana 2021-10-12 09:24:00 -07:00 committed by GitHub
parent f5a55c44d4
commit f8c5c24159
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -743,13 +743,15 @@ func (s *xlStorage) DeleteVol(ctx context.Context, volume string, forceDelete bo
} }
if forceDelete { if forceDelete {
err = renameAll(volumeDir, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, mustGetUUID())) err = s.moveToTrash(volumeDir, true)
} else { } else {
err = Remove(volumeDir) err = Remove(volumeDir)
} }
if err != nil { if err != nil {
switch { switch {
case errors.Is(err, errFileNotFound):
return errVolumeNotFound
case osIsNotExist(err): case osIsNotExist(err):
return errVolumeNotFound return errVolumeNotFound
case isSysErrNotEmpty(err): case isSysErrNotEmpty(err):
@ -814,6 +816,14 @@ func (s *xlStorage) DeleteVersions(ctx context.Context, volume string, versions
return errs return errs
} }
func (s *xlStorage) moveToTrash(filePath string, recursive bool) error {
pathUUID := mustGetUUID()
if recursive {
return renameAll(filePath, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, pathUUID))
}
return Rename(filePath, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, pathUUID))
}
// DeleteVersion - deletes FileInfo metadata for path at `xl.meta`. forceDelMarker // DeleteVersion - deletes FileInfo metadata for path at `xl.meta`. forceDelMarker
// will force creating a new `xl.meta` to create a new delete marker // will force creating a new `xl.meta` to create a new delete marker
func (s *xlStorage) DeleteVersion(ctx context.Context, volume, path string, fi FileInfo, forceDelMarker bool) error { func (s *xlStorage) DeleteVersion(ctx context.Context, volume, path string, fi FileInfo, forceDelMarker bool) error {
@ -879,7 +889,7 @@ func (s *xlStorage) DeleteVersion(ctx context.Context, volume, path string, fi F
if err = checkPathLength(filePath); err != nil { if err = checkPathLength(filePath); err != nil {
return err return err
} }
if err = renameAll(filePath, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, mustGetUUID())); err != nil { if err = s.moveToTrash(filePath, true); err != nil {
if err != errFileNotFound { if err != errFileNotFound {
return err return err
} }
@ -902,7 +912,7 @@ func (s *xlStorage) DeleteVersion(ctx context.Context, volume, path string, fi F
return err return err
} }
err = Rename(filePath, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, mustGetUUID())) err = s.moveToTrash(filePath, false)
if err == nil || err == errFileNotFound { if err == nil || err == errFileNotFound {
s.deleteFile(volumeDir, pathJoin(volumeDir, path), false) s.deleteFile(volumeDir, pathJoin(volumeDir, path), false)
} }
@ -1722,7 +1732,7 @@ func (s *xlStorage) deleteFile(basePath, deletePath string, recursive bool) erro
var err error var err error
if recursive { if recursive {
err = renameAll(deletePath, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, mustGetUUID())) err = s.moveToTrash(deletePath, true)
} else { } else {
err = Remove(deletePath) err = Remove(deletePath)
} }
@ -1740,6 +1750,8 @@ func (s *xlStorage) deleteFile(basePath, deletePath string, recursive bool) erro
return nil return nil
case osIsNotExist(err): case osIsNotExist(err):
return nil return nil
case errors.Is(err, errFileNotFound):
return nil
case osIsPermission(err): case osIsPermission(err):
return errFileAccessDenied return errFileAccessDenied
case isSysErrIO(err): case isSysErrIO(err):
@ -2017,7 +2029,7 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath string, f
// renameAll only for objects that have xl.meta not saved inline. // renameAll only for objects that have xl.meta not saved inline.
if len(fi.Data) == 0 && fi.Size > 0 { if len(fi.Data) == 0 && fi.Size > 0 {
renameAll(dstDataPath, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, mustGetUUID())) s.moveToTrash(dstDataPath, true)
if err = renameAll(srcDataPath, dstDataPath); err != nil { if err = renameAll(srcDataPath, dstDataPath); err != nil {
if legacyPreserved { if legacyPreserved {
// Any failed rename calls un-roll previous transaction. // Any failed rename calls un-roll previous transaction.
@ -2046,7 +2058,7 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath string, f
// movement, this is to ensure that previous data references can co-exist for // movement, this is to ensure that previous data references can co-exist for
// any recoverability. // any recoverability.
if oldDstDataPath != "" { if oldDstDataPath != "" {
renameAll(oldDstDataPath, pathutil.Join(s.diskPath, minioMetaTmpDeletedBucket, mustGetUUID())) s.moveToTrash(oldDstDataPath, true)
} }
} else { } else {
// Write meta-file directly, no data // Write meta-file directly, no data