Skip to content

Commit

Permalink
spans for tree ListFolder
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Jun 28, 2023
1 parent 8ec6fde commit 93525dd
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,9 @@ func (t *Tree) Move(ctx context.Context, oldNode *node.Node, newNode *node.Node)
return nil
}

func readChildNodeFromLink(path string) (string, error) {
func readChildNodeFromLink(ctx context.Context, path string) (string, error) {
_, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "readChildNodeFromLink")
defer span.End()
link, err := os.Readlink(path)
if err != nil {
return "", err
Expand All @@ -336,8 +338,13 @@ func readChildNodeFromLink(path string) (string, error) {

// ListFolder lists the content of a folder node
func (t *Tree) ListFolder(ctx context.Context, n *node.Node) ([]*node.Node, error) {
ctx, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "ListFolder")
defer span.End()
dir := n.InternalPath()

_, subspan := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "os.Open")
f, err := os.Open(dir)
subspan.End()
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return nil, errtypes.NotFound(dir)
Expand All @@ -346,7 +353,9 @@ func (t *Tree) ListFolder(ctx context.Context, n *node.Node) ([]*node.Node, erro
}
defer f.Close()

_, subspan = appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "f.Readdirnames")
names, err := f.Readdirnames(0)
subspan.End()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -378,13 +387,13 @@ func (t *Tree) ListFolder(ctx context.Context, n *node.Node) ([]*node.Node, erro
g.Go(func() error {
for name := range work {
path := filepath.Join(dir, name)
nodeID := getNodeIDFromCache(path, t.idCache)
nodeID := getNodeIDFromCache(ctx, path, t.idCache)
if nodeID == "" {
nodeID, err = readChildNodeFromLink(path)
nodeID, err = readChildNodeFromLink(ctx, path)
if err != nil {
return err
}
err = storeNodeIDInCache(path, nodeID, t.idCache)
err = storeNodeIDInCache(ctx, path, nodeID, t.idCache)
if err != nil {
return err
}
Expand Down Expand Up @@ -1031,15 +1040,19 @@ func (t *Tree) readRecycleItem(ctx context.Context, spaceID, key, path string) (
return
}

func getNodeIDFromCache(path string, cache store.Store) string {
func getNodeIDFromCache(ctx context.Context, path string, cache store.Store) string {
_, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "getNodeIDFromCache")
defer span.End()
recs, err := cache.Read(path)
if err == nil && len(recs) > 0 {
return string(recs[0].Value)
}
return ""
}

func storeNodeIDInCache(path string, nodeID string, cache store.Store) error {
func storeNodeIDInCache(ctx context.Context, path string, nodeID string, cache store.Store) error {
_, span := appctx.GetTracerProvider(ctx).Tracer(tracerName).Start(ctx, "storeNodeIDInCache")
defer span.End()
return cache.Write(&store.Record{
Key: path,
Value: []byte(nodeID),
Expand Down

0 comments on commit 93525dd

Please sign in to comment.