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:
Harshavardhana
2022-07-24 00:43:11 -07:00
committed by GitHub
parent b2f4948bbe
commit 7725425e05
8 changed files with 93 additions and 18 deletions

View File

@@ -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