From 17b3166adc91fdc611e6c9386422c9e7df4403b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Thu, 9 Mar 2023 09:53:50 +0100 Subject: [PATCH] WIP: debug missing parent id --- pkg/storage/utils/decomposedfs/node/node.go | 6 +++++- pkg/storage/utils/decomposedfs/spaces.go | 2 +- pkg/storage/utils/decomposedfs/tree/tree.go | 10 ++++++---- pkg/storage/utils/decomposedfs/upload/processing.go | 1 + 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/storage/utils/decomposedfs/node/node.go b/pkg/storage/utils/decomposedfs/node/node.go index 23f671eb12b..31479132ec7 100644 --- a/pkg/storage/utils/decomposedfs/node/node.go +++ b/pkg/storage/utils/decomposedfs/node/node.go @@ -184,7 +184,7 @@ func (n *Node) ChangeOwner(new *userpb.UserId) (err error) { } // WriteAllNodeMetadata writes the Node metadata to disk -func (n *Node) WriteAllNodeMetadata() (err error) { +func (n *Node) WriteAllNodeMetadata(ctx context.Context) (err error) { attribs := make(map[string]string) attribs[prefixes.TypeAttr] = strconv.FormatInt(int64(n.Type()), 10) @@ -193,6 +193,7 @@ func (n *Node) WriteAllNodeMetadata() (err error) { attribs[prefixes.BlobIDAttr] = n.BlobID attribs[prefixes.BlobsizeAttr] = strconv.FormatInt(n.Blobsize, 10) + appctx.GetLogger(ctx).Error().Str("nodeid", n.ID).Str("parentid", n.ParentID).Msg("Setting parent id") return n.SetXattrs(attribs, true) } @@ -315,6 +316,9 @@ func ReadNode(ctx context.Context, lu PathLookup, spaceID, nodeID string, canLis n.Name = attrs[prefixes.NameAttr] n.ParentID = attrs[prefixes.ParentidAttr] if n.ParentID == "" { + appctx.GetLogger(ctx).Error().Str("nodeid", n.ID).Str("parentid", n.ParentID).Interface("n", n).Msg("missing parent id") + d, _ := os.ReadFile(n.InternalPath() + ".ini") + appctx.GetLogger(ctx).Error().Str("ini", string(d)) return nil, errtypes.InternalError("Missing parent ID on node") } // TODO why do we stat the parent? to determine if the current node is in the trash we would need to traverse all parents... diff --git a/pkg/storage/utils/decomposedfs/spaces.go b/pkg/storage/utils/decomposedfs/spaces.go index 3a872b2fcd3..6534d73ad4e 100644 --- a/pkg/storage/utils/decomposedfs/spaces.go +++ b/pkg/storage/utils/decomposedfs/spaces.go @@ -102,7 +102,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr return nil, errors.Wrap(err, "Decomposedfs: error creating node") } - if err := root.WriteAllNodeMetadata(); err != nil { + if err := root.WriteAllNodeMetadata(ctx); err != nil { return nil, err } var owner *userv1beta1.UserId diff --git a/pkg/storage/utils/decomposedfs/tree/tree.go b/pkg/storage/utils/decomposedfs/tree/tree.go index 48c6a79f786..0220d3eb0de 100644 --- a/pkg/storage/utils/decomposedfs/tree/tree.go +++ b/pkg/storage/utils/decomposedfs/tree/tree.go @@ -264,7 +264,7 @@ func (t *Tree) TouchFile(ctx context.Context, n *node.Node) error { return errors.Wrap(err, "Decomposedfs: error creating node") } - err = n.WriteAllNodeMetadata() + err = n.WriteAllNodeMetadata(ctx) if err != nil { return err } @@ -300,7 +300,7 @@ func (t *Tree) CreateDir(ctx context.Context, n *node.Node) (err error) { n.ID = uuid.New().String() } - err = t.createDirNode(n) + err = t.createDirNode(ctx, n) if err != nil { return } @@ -386,6 +386,7 @@ func (t *Tree) Move(ctx context.Context, oldNode *node.Node, newNode *node.Node) } // update target parentid and name + appctx.GetLogger(ctx).Error().Str("nodeid", oldNode.ID).Str("parentid", newNode.ParentID).Msg("Setting parent id11111") if err := oldNode.SetXattr(prefixes.ParentidAttr, newNode.ParentID); err != nil { return errors.Wrap(err, "Decomposedfs: could not set parentid attribute") } @@ -623,6 +624,7 @@ func (t *Tree) RestoreRecycleItemFunc(ctx context.Context, spaceid, key, trashPa // set ParentidAttr to restorePath's node parent id if trashPath != "" { + appctx.GetLogger(ctx).Error().Str("nodeid", recycleNode.ID).Str("parentid", targetNode.ParentID).Msg("Setting parent id22222222") if err := recycleNode.SetXattr(prefixes.ParentidAttr, targetNode.ParentID); err != nil { return errors.Wrap(err, "Decomposedfs: could not set name attribute") } @@ -942,14 +944,14 @@ func (t *Tree) DeleteBlob(node *node.Node) error { } // TODO check if node exists? -func (t *Tree) createDirNode(n *node.Node) (err error) { +func (t *Tree) createDirNode(ctx context.Context, n *node.Node) (err error) { // create a directory node nodePath := n.InternalPath() if err := os.MkdirAll(nodePath, 0700); err != nil { return errors.Wrap(err, "Decomposedfs: error creating node") } - return n.WriteAllNodeMetadata() + return n.WriteAllNodeMetadata(ctx) } var nodeIDRegep = regexp.MustCompile(`.*/nodes/([^.]*).*`) diff --git a/pkg/storage/utils/decomposedfs/upload/processing.go b/pkg/storage/utils/decomposedfs/upload/processing.go index b9195c7817c..fd017cb9706 100644 --- a/pkg/storage/utils/decomposedfs/upload/processing.go +++ b/pkg/storage/utils/decomposedfs/upload/processing.go @@ -288,6 +288,7 @@ func CreateNodeForUpload(upload *Upload, initAttrs map[string]string) (*node.Nod initAttrs[prefixes.StatusPrefix] = node.ProcessingStatus + upload.Info.ID // update node metadata with new blobid etc + appctx.GetLogger(upload.Ctx).Error().Str("nodeid", n.ID).Str("parentid", n.ParentID).Msg("Setting parent id") err = n.SetXattrs(initAttrs, false) if err != nil { return nil, errors.Wrap(err, "Decomposedfs: could not write metadata")