Skip to content

Commit

Permalink
WIP: debug missing parent id
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Mar 9, 2023
1 parent 7a7fe11 commit 8e9b8b3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
6 changes: 5 additions & 1 deletion pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down Expand Up @@ -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)).Msg("missing parent id")
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...
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions pkg/storage/utils/decomposedfs/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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/([^.]*).*`)
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/utils/decomposedfs/upload/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 8e9b8b3

Please sign in to comment.