fix: intrument os.OpenFile differently for Reads and Writes (#15449)

allows us to trace latency for READs or WRITEs
This commit is contained in:
Harshavardhana 2022-08-01 13:22:43 -07:00 committed by GitHub
parent aad9cb208a
commit 043aaa792d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 36 deletions

View File

@ -535,7 +535,7 @@ func parsEnvEntry(envEntry string) (envKV, error) {
// the environment values from a file, in the form "key, value". // the environment values from a file, in the form "key, value".
// in a structured form. // in a structured form.
func minioEnvironFromFile(envConfigFile string) ([]envKV, error) { func minioEnvironFromFile(envConfigFile string) ([]envKV, error) {
f, err := os.Open(envConfigFile) f, err := Open(envConfigFile)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -916,7 +916,7 @@ func getTLSConfig() (x509Certs []*x509.Certificate, manager *certs.Manager, secu
// Therefore, we read all filenames in the cert directory and check // Therefore, we read all filenames in the cert directory and check
// for each directory whether it contains a public.crt and private.key. // for each directory whether it contains a public.crt and private.key.
// If so, we try to add it to certificate manager. // If so, we try to add it to certificate manager.
root, err := os.Open(globalCertsDir.Get()) root, err := Open(globalCertsDir.Get())
if err != nil { if err != nil {
return nil, nil, false, err return nil, nil, false, err
} }
@ -935,7 +935,7 @@ func getTLSConfig() (x509Certs []*x509.Certificate, manager *certs.Manager, secu
continue continue
} }
if file.Mode()&os.ModeSymlink == os.ModeSymlink { if file.Mode()&os.ModeSymlink == os.ModeSymlink {
file, err = os.Stat(filepath.Join(root.Name(), file.Name())) file, err = Stat(filepath.Join(root.Name(), file.Name()))
if err != nil { if err != nil {
// not accessible ignore // not accessible ignore
continue continue

View File

@ -227,7 +227,7 @@ func (d *dataUpdateTracker) load(ctx context.Context, drives ...string) {
for _, drive := range drives { for _, drive := range drives {
cacheFormatPath := pathJoin(drive, dataUpdateTrackerFilename) cacheFormatPath := pathJoin(drive, dataUpdateTrackerFilename)
f, err := os.Open(cacheFormatPath) f, err := OpenFile(cacheFormatPath, readMode, 0o666)
if err != nil { if err != nil {
if osIsNotExist(err) { if osIsNotExist(err) {
continue continue

View File

@ -624,7 +624,7 @@ func (c *diskCache) saveMetadata(ctx context.Context, bucket, object string, met
if err := os.MkdirAll(cachedPath, 0o777); err != nil { if err := os.MkdirAll(cachedPath, 0o777); err != nil {
return err return err
} }
f, err := os.OpenFile(metaPath, os.O_RDWR|os.O_CREATE, 0o666) f, err := OpenFile(metaPath, os.O_RDWR|os.O_CREATE|writeMode, 0o666)
if err != nil { if err != nil {
return err return err
} }
@ -687,7 +687,7 @@ func (c *diskCache) updateMetadata(ctx context.Context, bucket, object, etag str
if err := os.MkdirAll(cachedPath, 0o777); err != nil { if err := os.MkdirAll(cachedPath, 0o777); err != nil {
return err return err
} }
f, err := os.OpenFile(metaPath, os.O_RDWR, 0o666) f, err := OpenFile(metaPath, os.O_RDWR|writeMode, 0o666)
if err != nil { if err != nil {
return err return err
} }
@ -1275,12 +1275,12 @@ func (c *diskCache) NewMultipartUpload(ctx context.Context, bucket, object, uID
cachePath := getMultipartCacheSHADir(c.dir, bucket, object) cachePath := getMultipartCacheSHADir(c.dir, bucket, object)
uploadIDDir := path.Join(cachePath, uploadID) uploadIDDir := path.Join(cachePath, uploadID)
if err := os.MkdirAll(uploadIDDir, 0o777); err != nil { if err := mkdirAll(uploadIDDir, 0o777); err != nil {
return uploadID, err return uploadID, err
} }
metaPath := pathJoin(uploadIDDir, cacheMetaJSONFile) metaPath := pathJoin(uploadIDDir, cacheMetaJSONFile)
f, err := os.OpenFile(metaPath, os.O_RDWR|os.O_CREATE, 0o666) f, err := OpenFile(metaPath, os.O_RDWR|os.O_CREATE|writeMode, 0o666)
if err != nil { if err != nil {
return uploadID, err return uploadID, err
} }
@ -1386,7 +1386,7 @@ func (c *diskCache) SavePartMetadata(ctx context.Context, bucket, object, upload
defer uploadLock.Unlock(ulkctx.Cancel) defer uploadLock.Unlock(ulkctx.Cancel)
metaPath := pathJoin(uploadDir, cacheMetaJSONFile) metaPath := pathJoin(uploadDir, cacheMetaJSONFile)
f, err := os.OpenFile(metaPath, os.O_RDWR, 0o666) f, err := OpenFile(metaPath, os.O_RDWR|writeMode, 0o666)
if err != nil { if err != nil {
return err return err
} }
@ -1465,7 +1465,7 @@ func newCachePartEncryptReader(ctx context.Context, bucket, object string, partI
func (c *diskCache) uploadIDExists(bucket, object, uploadID string) (err error) { func (c *diskCache) uploadIDExists(bucket, object, uploadID string) (err error) {
mpartCachePath := getMultipartCacheSHADir(c.dir, bucket, object) mpartCachePath := getMultipartCacheSHADir(c.dir, bucket, object)
uploadIDDir := path.Join(mpartCachePath, uploadID) uploadIDDir := path.Join(mpartCachePath, uploadID)
if _, err := os.Stat(uploadIDDir); err != nil { if _, err := Stat(uploadIDDir); err != nil {
return err return err
} }
return nil return nil
@ -1564,7 +1564,7 @@ func (c *diskCache) CompleteMultipartUpload(ctx context.Context, bucket, object,
uploadMeta.Hits++ uploadMeta.Hits++
metaPath := pathJoin(uploadIDDir, cacheMetaJSONFile) metaPath := pathJoin(uploadIDDir, cacheMetaJSONFile)
f, err := os.OpenFile(metaPath, os.O_RDWR|os.O_CREATE, 0o666) f, err := OpenFile(metaPath, os.O_RDWR|os.O_CREATE|writeMode, 0o666)
if err != nil { if err != nil {
return oi, err return oi, err
} }
@ -1634,7 +1634,7 @@ func (c *diskCache) cleanupStaleUploads(ctx context.Context) {
readDirFn(pathJoin(c.dir, minioMetaBucket, cacheMultipartDir), func(shaDir string, typ os.FileMode) error { readDirFn(pathJoin(c.dir, minioMetaBucket, cacheMultipartDir), func(shaDir string, typ os.FileMode) error {
return readDirFn(pathJoin(c.dir, minioMetaBucket, cacheMultipartDir, shaDir), func(uploadIDDir string, typ os.FileMode) error { return readDirFn(pathJoin(c.dir, minioMetaBucket, cacheMultipartDir, shaDir), func(uploadIDDir string, typ os.FileMode) error {
uploadIDPath := pathJoin(c.dir, minioMetaBucket, cacheMultipartDir, shaDir, uploadIDDir) uploadIDPath := pathJoin(c.dir, minioMetaBucket, cacheMultipartDir, shaDir, uploadIDDir)
fi, err := os.Stat(uploadIDPath) fi, err := Stat(uploadIDPath)
if err != nil { if err != nil {
return nil return nil
} }
@ -1649,8 +1649,8 @@ func (c *diskCache) cleanupStaleUploads(ctx context.Context) {
readDirFn(pathJoin(c.dir, minioMetaBucket, cacheWritebackDir), func(shaDir string, typ os.FileMode) error { readDirFn(pathJoin(c.dir, minioMetaBucket, cacheWritebackDir), func(shaDir string, typ os.FileMode) error {
wbdir := pathJoin(c.dir, minioMetaBucket, cacheWritebackDir, shaDir) wbdir := pathJoin(c.dir, minioMetaBucket, cacheWritebackDir, shaDir)
cachedir := pathJoin(c.dir, shaDir) cachedir := pathJoin(c.dir, shaDir)
if _, err := os.Stat(cachedir); os.IsNotExist(err) { if _, err := Stat(cachedir); os.IsNotExist(err) {
fi, err := os.Stat(wbdir) fi, err := Stat(wbdir)
if err != nil { if err != nil {
return nil return nil
} }

View File

@ -37,7 +37,8 @@ const (
osMetricMkdirAll osMetricMkdirAll
osMetricMkdir osMetricMkdir
osMetricRename osMetricRename
osMetricOpenFile osMetricOpenFileW
osMetricOpenFileR
osMetricOpen osMetricOpen
osMetricOpenFileDirectIO osMetricOpenFileDirectIO
osMetricLstat osMetricLstat
@ -135,7 +136,12 @@ func Rename(src, dst string) error {
// OpenFile captures time taken to call os.OpenFile // OpenFile captures time taken to call os.OpenFile
func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) { func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error) {
defer updateOSMetrics(osMetricOpenFile, name)() switch flag & writeMode {
case writeMode:
defer updateOSMetrics(osMetricOpenFileW, name)()
default:
defer updateOSMetrics(osMetricOpenFileR, name)()
}
return os.OpenFile(name, flag, perm) return os.OpenFile(name, flag, perm)
} }

View File

@ -12,23 +12,24 @@ func _() {
_ = x[osMetricMkdirAll-1] _ = x[osMetricMkdirAll-1]
_ = x[osMetricMkdir-2] _ = x[osMetricMkdir-2]
_ = x[osMetricRename-3] _ = x[osMetricRename-3]
_ = x[osMetricOpenFile-4] _ = x[osMetricOpenFileW-4]
_ = x[osMetricOpen-5] _ = x[osMetricOpenFileR-5]
_ = x[osMetricOpenFileDirectIO-6] _ = x[osMetricOpen-6]
_ = x[osMetricLstat-7] _ = x[osMetricOpenFileDirectIO-7]
_ = x[osMetricRemove-8] _ = x[osMetricLstat-8]
_ = x[osMetricStat-9] _ = x[osMetricRemove-9]
_ = x[osMetricAccess-10] _ = x[osMetricStat-10]
_ = x[osMetricCreate-11] _ = x[osMetricAccess-11]
_ = x[osMetricReadDirent-12] _ = x[osMetricCreate-12]
_ = x[osMetricFdatasync-13] _ = x[osMetricReadDirent-13]
_ = x[osMetricSync-14] _ = x[osMetricFdatasync-14]
_ = x[osMetricLast-15] _ = x[osMetricSync-15]
_ = x[osMetricLast-16]
} }
const _osMetric_name = "RemoveAllMkdirAllMkdirRenameOpenFileOpenOpenFileDirectIOLstatRemoveStatAccessCreateReadDirentFdatasyncSyncLast" const _osMetric_name = "RemoveAllMkdirAllMkdirRenameOpenFileWOpenFileROpenOpenFileDirectIOLstatRemoveStatAccessCreateReadDirentFdatasyncSyncLast"
var _osMetric_index = [...]uint8{0, 9, 17, 22, 28, 36, 40, 56, 61, 67, 71, 77, 83, 93, 102, 106, 110} var _osMetric_index = [...]uint8{0, 9, 17, 22, 28, 37, 46, 50, 66, 71, 77, 81, 87, 93, 103, 112, 116, 120}
func (i osMetric) String() string { func (i osMetric) String() string {
if i >= osMetric(len(_osMetric_index)-1) { if i >= osMetric(len(_osMetric_index)-1) {

View File

@ -237,7 +237,7 @@ func (jd *tierDiskJournal) Open() error {
} }
var err error var err error
jd.file, err = os.OpenFile(jd.JournalPath(), os.O_APPEND|os.O_CREATE|os.O_WRONLY|writeMode, 0o666) jd.file, err = OpenFile(jd.JournalPath(), os.O_APPEND|os.O_CREATE|os.O_WRONLY|writeMode, 0o666)
if err != nil { if err != nil {
return err return err
} }
@ -259,7 +259,7 @@ func (jd *tierDiskJournal) Open() error {
} }
func (jd *tierDiskJournal) OpenRO() (io.ReadCloser, error) { func (jd *tierDiskJournal) OpenRO() (io.ReadCloser, error) {
file, err := os.Open(jd.ReadOnlyPath()) file, err := Open(jd.ReadOnlyPath())
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -181,7 +181,7 @@ func IsBOSH() bool {
// Check if this is Helm package installation and report helm chart version // Check if this is Helm package installation and report helm chart version
func getHelmVersion(helmInfoFilePath string) string { func getHelmVersion(helmInfoFilePath string) string {
// Read the file exists. // Read the file exists.
helmInfoFile, err := os.Open(helmInfoFilePath) helmInfoFile, err := Open(helmInfoFilePath)
if err != nil { if err != nil {
// Log errors and return "" as MinIO can be deployed // Log errors and return "" as MinIO can be deployed
// without Helm charts as well. // without Helm charts as well.

View File

@ -394,7 +394,7 @@ func (s *xlStorage) readMetadataWithDMTime(ctx context.Context, itemPath string)
return nil, time.Time{}, err return nil, time.Time{}, err
} }
f, err := OpenFile(itemPath, readMode, 0) f, err := OpenFile(itemPath, readMode, 0o666)
if err != nil { if err != nil {
return nil, time.Time{}, err return nil, time.Time{}, err
} }
@ -1547,7 +1547,7 @@ func (s *xlStorage) ReadFile(ctx context.Context, volume string, path string, of
} }
// Open the file for reading. // Open the file for reading.
file, err := Open(filePath) file, err := OpenFile(filePath, readMode, 0o666)
if err != nil { if err != nil {
switch { switch {
case osIsNotExist(err): case osIsNotExist(err):
@ -2515,7 +2515,7 @@ func (s *xlStorage) RenameFile(ctx context.Context, srcVolume, srcPath, dstVolum
func (s *xlStorage) bitrotVerify(ctx context.Context, partPath string, partSize int64, algo BitrotAlgorithm, sum []byte, shardSize int64) error { func (s *xlStorage) bitrotVerify(ctx context.Context, partPath string, partSize int64, algo BitrotAlgorithm, sum []byte, shardSize int64) error {
// Open the file for reading. // Open the file for reading.
file, err := Open(partPath) file, err := OpenFile(partPath, readMode, 0o666)
if err != nil { if err != nil {
return osErrToFileErr(err) return osErrToFileErr(err)
} }