mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
fix: fork os.MkdirAll to optimize cases where parent exists (#15379)
a/b/c/d/ where `a/b/c/` exists results in additional syscalls such as an Lstat() call to verify if the `a/b/c/` exists and its a directory. We do not need to do this on MinIO since the parent prefixes if exist, we can simply return success without spending additional syscalls. Also this implementation attempts to simply use Access() calls to avoid os.Stat() calls since the latter does memory allocation for things we do not need to use. Access() is simpler since we have a predictable structure on the backend and we know exactly how our path structures are.
This commit is contained in:
@@ -35,6 +35,7 @@ type osMetric uint8
|
||||
const (
|
||||
osMetricRemoveAll osMetric = iota
|
||||
osMetricMkdirAll
|
||||
osMetricMkdir
|
||||
osMetricRename
|
||||
osMetricOpenFile
|
||||
osMetricOpen
|
||||
@@ -114,10 +115,16 @@ func RemoveAll(dirPath string) error {
|
||||
return os.RemoveAll(dirPath)
|
||||
}
|
||||
|
||||
// Mkdir captures time taken to call os.Mkdir
|
||||
func Mkdir(dirPath string, mode os.FileMode) error {
|
||||
defer updateOSMetrics(osMetricMkdir, dirPath)()
|
||||
return os.Mkdir(dirPath, mode)
|
||||
}
|
||||
|
||||
// MkdirAll captures time taken to call os.MkdirAll
|
||||
func MkdirAll(dirPath string, mode os.FileMode) error {
|
||||
defer updateOSMetrics(osMetricMkdirAll, dirPath)()
|
||||
return os.MkdirAll(dirPath, mode)
|
||||
return osMkdirAll(dirPath, mode)
|
||||
}
|
||||
|
||||
// Rename captures time taken to call os.Rename
|
||||
|
||||
Reference in New Issue
Block a user