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

Cache resolved links #3801

Merged
merged 2 commits into from
Apr 20, 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/cache-node-ids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Cache node ids

decomposedfs now keeps an in-memory cache for node ids, sparing a lot of ReadLink calls.

https://github.com/cs3org/reva/pull/3801
25 changes: 21 additions & 4 deletions pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"strings"
"time"

"github.com/bluele/gcache"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/v2/pkg/appctx"
"github.com/cs3org/reva/v2/pkg/errtypes"
Expand Down Expand Up @@ -78,6 +79,8 @@ type Tree struct {
blobstore Blobstore

options *options.Options

idCache gcache.Cache
}

// PermissionCheckFunc defined a function used to check resource permissions
Expand All @@ -89,6 +92,7 @@ func New(lu PathLookup, bs Blobstore, o *options.Options) *Tree {
lookup: lu,
blobstore: bs,
options: o,
idCache: gcache.New(1_000_000).LRU().Build(),
}
}

Expand Down Expand Up @@ -271,6 +275,7 @@ func (t *Tree) Move(ctx context.Context, oldNode *node.Node, newNode *node.Node)
if err != nil {
return errors.Wrap(err, "Decomposedfs: could not move child")
}
t.idCache.Remove(filepath.Join(oldNode.ParentPath(), oldNode.Name))

// update target parentid and name
attribs := node.Attributes{}
Expand Down Expand Up @@ -360,9 +365,19 @@ func (t *Tree) ListFolder(ctx context.Context, n *node.Node) ([]*node.Node, erro
for i := 0; i < numWorkers; i++ {
g.Go(func() error {
for name := range work {
nodeID, err := readChildNodeFromLink(filepath.Join(dir, name))
if err != nil {
return err
nodeID := ""
path := filepath.Join(dir, name)
if val, err := t.idCache.Get(path); err == nil {
nodeID = val.(string)
} else {
nodeID, err = readChildNodeFromLink(path)
if err != nil {
return err
}
err = t.idCache.Set(path, nodeID)
if err != nil {
return err
}
}

child, err := node.ReadNode(ctx, t.lookup, n.SpaceID, nodeID, false, n, true)
Expand Down Expand Up @@ -481,7 +496,9 @@ func (t *Tree) Delete(ctx context.Context, n *node.Node) (err error) {
_ = os.Remove(n.LockFilePath())

// finally remove the entry from the parent dir
err = os.Remove(filepath.Join(n.ParentPath(), n.Name))
path := filepath.Join(n.ParentPath(), n.Name)
err = os.Remove(path)
t.idCache.Remove(path)
if err != nil {
// To roll back changes
// TODO revert the rename
Expand Down