Skip to content

Commit

Permalink
Rely on the assimilation to update the tree sizes for us
Browse files Browse the repository at this point in the history
  • Loading branch information
aduffeck committed Aug 9, 2024
1 parent 99645d2 commit 35d40e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
11 changes: 1 addition & 10 deletions pkg/storage/fs/posix/tree/assimilation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
}
Expand Down
27 changes: 6 additions & 21 deletions pkg/storage/fs/posix/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -339,23 +327,19 @@ 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 {
return err
}
}

// 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)
err = t.Propagate(ctx, oldNode, 0)
if err != nil {
return errors.Wrap(err, "Decomposedfs: Move: could not propagate old node")
}
err = t.Propagate(ctx, newNode, sizeDiff)
err = t.Propagate(ctx, newNode, 0)
if err != nil {
return errors.Wrap(err, "Decomposedfs: Move: could not propagate new node")
}
Expand Down Expand Up @@ -713,8 +697,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
Expand Down

0 comments on commit 35d40e5

Please sign in to comment.