storage/filestore: Monitor when we open files in trash

Change-Id: I817bf8349c2e1ba55e1490f06162af1099bebdb0
This commit is contained in:
Isaac Hess 2019-11-26 11:54:30 -07:00
parent 756b9b9e2b
commit a6235d3962
3 changed files with 27 additions and 4 deletions

View File

@ -61,6 +61,7 @@ storj.io/storj/satellite/repair/checker."remote_segments_lost" IntVal
storj.io/storj/satellite/repair/checker."remote_segments_needing_repair" IntVal
storj.io/storj/satellite/satellitedb."audit_reputation_alpha" FloatVal
storj.io/storj/satellite/satellitedb."audit_reputation_beta" FloatVal
storj.io/storj/storage/filestore."open_file_in_trash" Meter
storj.io/storj/storagenode/contact."satellite_contact_request" Meter
storj.io/storj/storagenode/gracefulexit."satellite_gracefulexit_request" Meter
storj.io/storj/storagenode/monitor."allocated_bandwidth" IntVal

View File

@ -121,6 +121,18 @@ func (dir *Dir) refToDirPath(ref storage.BlobRef, subDir string) (string, error)
return filepath.Join(subDir, namespace, key[:2], key[2:]), nil
}
// fileConfirmedInTrash returns true if it is able to confirm the file is in
// the trash. On errors, or if the file is not in the trash, it returns false.
func (dir *Dir) fileConfirmedInTrash(ctx context.Context, ref storage.BlobRef, formatVer storage.FormatVersion) bool {
trashBasePath, err := dir.refToDirPath(ref, dir.trashdir())
if err != nil {
return false
}
trashVerPath := blobPathForFormatVersion(trashBasePath, formatVer)
_, err = os.Stat(trashVerPath)
return err == nil
}
// blobPathForFormatVersion adjusts a bare blob path (as might have been generated by a call to
// blobToBasePath()) to what it should be for the given storage format version.
func blobPathForFormatVersion(path string, formatVersion storage.FormatVersion) string {
@ -199,7 +211,12 @@ func (dir *Dir) Open(ctx context.Context, ref storage.BlobRef) (_ *os.File, _ st
if err == nil {
return file, formatVer, nil
}
if !os.IsNotExist(err) {
if os.IsNotExist(err) {
// Check and monitor if the file is in the trash
if dir.fileConfirmedInTrash(ctx, ref, formatVer) {
monFileInTrash.Mark(1)
}
} else {
return nil, FormatV0, Error.New("unable to open %q: %v", vPath, err)
}
}
@ -208,9 +225,9 @@ func (dir *Dir) Open(ctx context.Context, ref storage.BlobRef) (_ *os.File, _ st
// OpenWithStorageFormat opens an already-located blob file with a known storage format version,
// which avoids the potential need to search through multiple storage formats to find the blob.
func (dir *Dir) OpenWithStorageFormat(ctx context.Context, blobRef storage.BlobRef, formatVer storage.FormatVersion) (_ *os.File, err error) {
func (dir *Dir) OpenWithStorageFormat(ctx context.Context, ref storage.BlobRef, formatVer storage.FormatVersion) (_ *os.File, err error) {
defer mon.Task()(&ctx)(&err)
path, err := dir.blobToBasePath(blobRef)
path, err := dir.blobToBasePath(ref)
if err != nil {
return nil, err
}
@ -220,6 +237,10 @@ func (dir *Dir) OpenWithStorageFormat(ctx context.Context, blobRef storage.BlobR
return file, nil
}
if os.IsNotExist(err) {
// Check and monitor if the file is in the trash
if dir.fileConfirmedInTrash(ctx, ref, formatVer) {
monFileInTrash.Mark(1)
}
return nil, err
}
return nil, Error.New("unable to open %q: %v", vPath, err)

View File

@ -19,7 +19,8 @@ var (
// Error is the default filestore error class
Error = errs.Class("filestore error")
mon = monkit.Package()
mon = monkit.Package()
monFileInTrash = mon.Meter("open_file_in_trash") //locked
_ storage.Blobs = (*blobStore)(nil)
)