From dfbbeb45c6a6f10a02e0217b7941bbe29e827d33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Fri, 9 Aug 2024 09:26:57 +0200 Subject: [PATCH] Rely on the assimilation to update the tree sizes for us --- pkg/storage/fs/posix/tree/assimilation.go | 11 +------- pkg/storage/fs/posix/tree/tree.go | 31 +++-------------------- 2 files changed, 5 insertions(+), 37 deletions(-) diff --git a/pkg/storage/fs/posix/tree/assimilation.go b/pkg/storage/fs/posix/tree/assimilation.go index eeb4288f1e..8aba27a540 100644 --- a/pkg/storage/fs/posix/tree/assimilation.go +++ b/pkg/storage/fs/posix/tree/assimilation.go @@ -488,7 +488,6 @@ assimilate: attributes[prefixes.ChecksumPrefix+"adler32"] = adler32h.Sum(nil) } - sizeDiff := int64(0) if fi.IsDir() { attributes.SetInt64(prefixes.TypeAttr, int64(provider.ResourceType_RESOURCE_TYPE_CONTAINER)) attributes.SetInt64(prefixes.TreesizeAttr, 0) @@ -501,19 +500,11 @@ assimilate: attributes.SetString(prefixes.BlobIDAttr, id) attributes.SetInt64(prefixes.BlobsizeAttr, fi.Size()) - // propagate the size change - sizeDiff = fi.Size() - if previousAttribs != nil && previousAttribs[prefixes.BlobsizeAttr] != nil { - oldSize, err := attributes.Int64(prefixes.BlobsizeAttr) - if err == nil { - sizeDiff -= oldSize - } - } } n := node.New(spaceID, id, parentID, filepath.Base(path), fi.Size(), "", provider.ResourceType_RESOURCE_TYPE_FILE, nil, t.lookup) n.SpaceRoot = &node.Node{SpaceID: spaceID, ID: spaceID} - err = t.Propagate(context.Background(), n, sizeDiff) + err = t.Propagate(context.Background(), n, 0) if err != nil { return nil, errors.Wrap(err, "failed to propagate") } diff --git a/pkg/storage/fs/posix/tree/tree.go b/pkg/storage/fs/posix/tree/tree.go index 7e4e20cc2f..498e274513 100644 --- a/pkg/storage/fs/posix/tree/tree.go +++ b/pkg/storage/fs/posix/tree/tree.go @@ -302,18 +302,6 @@ func (t *Tree) Move(ctx context.Context, oldNode *node.Node, newNode *node.Node) return errors.Wrap(err, "Decomposedfs: could not update old node attributes") } - // the size diff is the current treesize or blobsize of the old/source node - var sizeDiff int64 - if oldNode.IsDir(ctx) { - treeSize, err := oldNode.GetTreeSize(ctx) - if err != nil { - return err - } - sizeDiff = int64(treeSize) - } else { - sizeDiff = oldNode.Blobsize - } - // rename node err = os.Rename( filepath.Join(oldNode.ParentPath(), oldNode.Name), @@ -339,7 +327,7 @@ func (t *Tree) Move(ctx context.Context, oldNode *node.Node, newNode *node.Node) newNode.ID = oldNode.ID } _ = t.lookup.(*lookup.Lookup).CacheID(ctx, newNode.SpaceID, newNode.ID, filepath.Join(newNode.ParentPath(), newNode.Name)) - // update id cache for the moved subtree + // update id cache for the moved subtree. if oldNode.IsDir(ctx) { err = t.WarmupIDCache(filepath.Join(newNode.ParentPath(), newNode.Name), false) if err != nil { @@ -347,18 +335,6 @@ func (t *Tree) Move(ctx context.Context, oldNode *node.Node, newNode *node.Node) } } - // TODO inefficient because we might update several nodes twice, only propagate unchanged nodes? - // collect in a list, then only stat each node once - // also do this in a go routine ... webdav should check the etag async - - err = t.Propagate(ctx, oldNode, -sizeDiff) - if err != nil { - return errors.Wrap(err, "Decomposedfs: Move: could not propagate old node") - } - err = t.Propagate(ctx, newNode, sizeDiff) - if err != nil { - return errors.Wrap(err, "Decomposedfs: Move: could not propagate new node") - } return nil } @@ -713,8 +689,9 @@ func (t *Tree) removeNode(ctx context.Context, path string, n *node.Node) error } // Propagate propagates changes to the root of the tree -func (t *Tree) Propagate(ctx context.Context, n *node.Node, sizeDiff int64) (err error) { - return t.propagator.Propagate(ctx, n, sizeDiff) +func (t *Tree) Propagate(ctx context.Context, n *node.Node, _ int64) (err error) { + // We do not propagate size diffs here but rely on the assimilation to take care of the tree sizes instead + return t.propagator.Propagate(ctx, n, 0) } // WriteBlob writes a blob to the blobstore