optimize mkdir calls to avoid base-dir Mkdir attempts (#18021)

Currently we have IOPs of these patterns

```
[OS] os.Mkdir play.min.io:9000 /disk1 2.718µs
[OS] os.Mkdir play.min.io:9000 /disk1/data 2.406µs
[OS] os.Mkdir play.min.io:9000 /disk1/data/.minio.sys 4.068µs
[OS] os.Mkdir play.min.io:9000 /disk1/data/.minio.sys/tmp 2.843µs
[OS] os.Mkdir play.min.io:9000 /disk1/data/.minio.sys/tmp/d89c8ceb-f8d1-4cc6-b483-280f87c4719f 20.152µs
```

It can be seen that we can save quite Nx levels such as
if your drive is mounted at `/disk1/minio` you can simply
skip sending an `Mkdir /disk1/` and `Mkdir /disk1/minio`.

Since they are expected to exist already, this PR adds a way
for us to ignore all paths upto the mount or a directory which
ever has been provided to MinIO setup.
This commit is contained in:
Harshavardhana
2023-09-13 08:14:36 -07:00
committed by GitHub
parent 96fbf18201
commit 8b8be2695f
11 changed files with 60 additions and 50 deletions

View File

@@ -180,7 +180,7 @@ func getValidPath(path string) (string, error) {
}
if osIsNotExist(err) {
// Disk not found create it.
if err = mkdirAll(path, 0o777); err != nil {
if err = mkdirAll(path, 0o777, ""); err != nil {
return path, err
}
}
@@ -397,6 +397,11 @@ func (s *xlStorage) checkODirectDiskSupport() error {
// Check if backend is writable and supports O_DIRECT
uuid := mustGetUUID()
filePath := pathJoin(s.drivePath, minioMetaTmpDeletedBucket, ".writable-check-"+uuid+".tmp")
// Create top level directories if they don't exist.
// with mode 0o777 mkdir honors system umask.
mkdirAll(pathutil.Dir(filePath), 0o777, s.drivePath) // don't need to fail here
w, err := s.openFileDirect(filePath, os.O_CREATE|os.O_WRONLY|os.O_EXCL)
if err != nil {
return err
@@ -822,7 +827,7 @@ func (s *xlStorage) MakeVol(ctx context.Context, volume string) error {
// Volume does not exist we proceed to create.
if osIsNotExist(err) {
// Make a volume entry, with mode 0777 mkdir honors system umask.
err = mkdirAll(volumeDir, 0o777)
err = mkdirAll(volumeDir, 0o777, s.drivePath)
}
if osIsPermission(err) {
return errDiskAccessDenied
@@ -1089,16 +1094,16 @@ func (s *xlStorage) moveToTrash(filePath string, recursive, force bool) error {
pathUUID := mustGetUUID()
targetPath := pathutil.Join(s.drivePath, minioMetaTmpDeletedBucket, pathUUID)
var renameFn func(source, target string) error
if recursive {
renameFn = renameAll
if err := renameAll(filePath, targetPath, s.drivePath); err != nil {
return err
}
} else {
renameFn = Rename
if err := Rename(filePath, targetPath); err != nil {
return err
}
}
if err := renameFn(filePath, targetPath); err != nil {
return err
}
// immediately purge the target
if force {
removeAll(targetPath)
@@ -1717,10 +1722,6 @@ func (s *xlStorage) ReadFile(ctx context.Context, volume string, path string, of
}
func (s *xlStorage) openFileDirect(path string, mode int) (f *os.File, err error) {
// Create top level directories if they don't exist.
// with mode 0o777 mkdir honors system umask.
mkdirAll(pathutil.Dir(path), 0o777) // don't need to fail here
w, err := OpenFileDirectIO(path, mode, 0o666)
if err != nil {
switch {
@@ -1747,7 +1748,7 @@ func (s *xlStorage) openFileSync(filePath string, mode int) (f *os.File, err err
func (s *xlStorage) openFile(filePath string, mode int) (f *os.File, err error) {
// Create top level directories if they don't exist.
// with mode 0777 mkdir honors system umask.
if err = mkdirAll(pathutil.Dir(filePath), 0o777); err != nil {
if err = mkdirAll(pathutil.Dir(filePath), 0o777, s.drivePath); err != nil {
return nil, osErrToFileErr(err)
}
@@ -1925,7 +1926,7 @@ func (s *xlStorage) writeAllDirect(ctx context.Context, filePath string, fileSiz
// Create top level directories if they don't exist.
// with mode 0777 mkdir honors system umask.
parentFilePath := pathutil.Dir(filePath)
if err = mkdirAll(parentFilePath, 0o777); err != nil {
if err = mkdirAll(parentFilePath, 0o777, s.drivePath); err != nil {
return osErrToFileErr(err)
}
@@ -2388,7 +2389,7 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath string, f
}
// legacy data dir means its old content, honor system umask.
if err = mkdirAll(legacyDataPath, 0o777); err != nil {
if err = mkdirAll(legacyDataPath, 0o777, s.drivePath); err != nil {
// any failed mkdir-calls delete them.
s.deleteFile(dstVolumeDir, legacyDataPath, true, false)
return 0, osErrToFileErr(err)
@@ -2505,7 +2506,7 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath string, f
// on a versioned bucket.
s.moveToTrash(legacyDataPath, true, false)
}
if err = renameAll(srcDataPath, dstDataPath); err != nil {
if err = renameAll(srcDataPath, dstDataPath, s.drivePath); err != nil {
if legacyPreserved {
// Any failed rename calls un-roll previous transaction.
s.deleteFile(dstVolumeDir, legacyDataPath, true, false)
@@ -2516,7 +2517,7 @@ func (s *xlStorage) RenameData(ctx context.Context, srcVolume, srcPath string, f
}
// Commit meta-file
if err = renameAll(srcFilePath, dstFilePath); err != nil {
if err = renameAll(srcFilePath, dstFilePath, s.drivePath); err != nil {
if legacyPreserved {
// Any failed rename calls un-roll previous transaction.
s.deleteFile(dstVolumeDir, legacyDataPath, true, false)
@@ -2626,7 +2627,7 @@ func (s *xlStorage) RenameFile(ctx context.Context, srcVolume, srcPath, dstVolum
}
}
if err = renameAll(srcFilePath, dstFilePath); err != nil {
if err = renameAll(srcFilePath, dstFilePath, s.drivePath); err != nil {
if isSysErrNotEmpty(err) || isSysErrNotDir(err) {
return errFileAccessDenied
}