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

allow passing reader to read metadata #3886

Merged
merged 1 commit into from
May 12, 2023
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/fix-deadlock-by-passing-reader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: decomposedfs no longer deadlocks when cache is disabled

We now pass a Reader for the locked file to lower level functions so metadata can be read without aquiring a new file lock.

https://github.com/cs3org/reva/pull/3886
12 changes: 10 additions & 2 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ func (n *Node) Child(ctx context.Context, name string) (*Node, error) {
return c, nil
}

// Parent returns the parent node
func (n *Node) Parent() (p *Node, err error) {
// ParentWithReader returns the parent node
func (n *Node) ParentWithReader(r io.Reader) (p *Node, err error) {
if n.ParentID == "" {
return nil, fmt.Errorf("decomposedfs: root has no parent")
}
Expand All @@ -417,6 +417,9 @@ func (n *Node) Parent() (p *Node, err error) {
SpaceRoot: n.SpaceRoot,
}

// fill metadata cache using the reader
_, _ = p.XattrsWithReader(r)

// lookup name and parent id in extended attributes
p.ParentID, _ = p.XattrString(prefixes.ParentidAttr)
p.Name, _ = p.XattrString(prefixes.NameAttr)
Expand All @@ -428,6 +431,11 @@ func (n *Node) Parent() (p *Node, err error) {
return
}

// Parent returns the parent node
func (n *Node) Parent() (p *Node, err error) {
return n.ParentWithReader(nil)
}

// Owner returns the space owner
func (n *Node) Owner() *userpb.UserId {
return n.SpaceRoot.owner
Expand Down
20 changes: 17 additions & 3 deletions pkg/storage/utils/decomposedfs/node/xattrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package node

import (
"io"
"strconv"

"github.com/pkg/xattr"
Expand Down Expand Up @@ -84,21 +85,34 @@ func (n *Node) RemoveXattr(key string) error {
return n.lu.MetadataBackend().Remove(n.InternalPath(), key)
}

// Xattrs returns the extended attributes of the node. If the attributes have already
// XattrsWithReader returns the extended attributes of the node. If the attributes have already
// been cached they are not read from disk again.
func (n *Node) Xattrs() (Attributes, error) {
func (n *Node) XattrsWithReader(r io.Reader) (Attributes, error) {
if n.xattrsCache != nil {
return n.xattrsCache, nil
}

attrs, err := n.lu.MetadataBackend().All(n.InternalPath())
var attrs Attributes
var err error
if r != nil {
attrs, err = n.lu.MetadataBackend().AllWithLockedSource(n.InternalPath(), r)
} else {
attrs, err = n.lu.MetadataBackend().All(n.InternalPath())
}
if err != nil {
return nil, err
}

n.xattrsCache = attrs
return n.xattrsCache, nil
}

// Xattrs returns the extended attributes of the node. If the attributes have already
// been cached they are not read from disk again.
func (n *Node) Xattrs() (Attributes, error) {
return n.XattrsWithReader(nil)
}

// Xattr returns an extended attribute of the node. If the attributes have already
// been cached it is not read from disk again.
func (n *Node) Xattr(key string) ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ func (t *Tree) Propagate(ctx context.Context, n *node.Node, sizeDiff int64) (err
}
}()

if n, err = n.Parent(); err != nil {
if n, err = n.ParentWithReader(f); err != nil {
return err
}

Expand Down