Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop unneeded session locks #4985

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/drop-unneeded-locks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: drop unneeded session locks

We no longer lock session metadada files, as they are already written atomically.

https://github.com/cs3org/reva/pull/4985
14 changes: 0 additions & 14 deletions pkg/storage/utils/decomposedfs/upload/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"time"

"github.com/google/renameio/v2"
"github.com/rogpeppe/go-internal/lockedfile"
tusd "github.com/tus/tusd/v2/pkg/handler"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
Expand Down Expand Up @@ -84,14 +83,6 @@ func (s *OcisSession) Purge(ctx context.Context) error {
_, span := tracer.Start(ctx, "Purge")
defer span.End()
sessionPath := sessionPath(s.store.root, s.info.ID)
f, err := lockedfile.OpenFile(sessionPath+".lock", os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0600)
if err != nil {
return err
}
defer func() {
f.Close()
os.Remove(sessionPath + ".lock")
}()
if err := os.Remove(sessionPath); err != nil {
return err
}
Expand Down Expand Up @@ -127,11 +118,6 @@ func (s *OcisSession) Persist(ctx context.Context) error {
if err != nil {
return err
}
f, err := lockedfile.OpenFile(sessionPath+".lock", os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0600)
if err != nil {
return err
}
defer f.Close()
return renameio.WriteFile(sessionPath, d, 0600)
}

Expand Down
14 changes: 5 additions & 9 deletions pkg/storage/utils/decomposedfs/upload/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"regexp"
"strconv"
"strings"
"syscall"
"time"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand Down Expand Up @@ -129,24 +130,19 @@ func (store OcisStore) Get(ctx context.Context, id string) (*OcisSession, error)
store: store,
info: tusd.FileInfo{},
}
lock, err := lockedfile.Open(sessionPath + ".lock")
data, err := os.ReadFile(sessionPath)
if err != nil {
if errors.Is(err, iofs.ErrNotExist) {
// Interpret os.ErrNotExist as 404 Not Found
// handle stale NFS file handles that can occur when the file is deleted betwenn the ATTR and FOPEN call of os.ReadFile
if pathErr, ok := err.(*os.PathError); ok && pathErr.Err == syscall.ESTALE {
appctx.GetLogger(ctx).Info().Str("session", id).Err(err).Msg("treating stale file handle as not found")
err = tusd.ErrNotFound
}
return nil, err
}
defer lock.Close()
data, err := os.ReadFile(sessionPath)
if err != nil {
if errors.Is(err, iofs.ErrNotExist) {
// Interpret os.ErrNotExist as 404 Not Found
err = tusd.ErrNotFound
}
return nil, err
}
lock.Close() // release lock asap

if err := json.Unmarshal(data, &session.info); err != nil {
return nil, err
Expand Down
Loading