Skip to content

Commit

Permalink
Merge pull request #4081 from kobergj/PropagateSizeDiffAfterPP
Browse files Browse the repository at this point in the history
Propagate sizeDiff after failed postprocessing
  • Loading branch information
kobergj authored Jul 26, 2023
2 parents 4498035 + 9454d3e commit 08de0da
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/propagate-sizediff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Propagate sizeDiff

When postprocessing failed the sizeDiff would not be propagated correctly. This is fixed

https://github.com/cs3org/reva/pull/4081
20 changes: 16 additions & 4 deletions pkg/storage/utils/decomposedfs/decomposedfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,23 @@ func (fs *Decomposedfs) Postprocessing(ch <-chan events.Event) {
failed = true
}

getParent := func() *node.Node {
p, err := up.Node.Parent(ctx)
if err != nil {
log.Error().Err(err).Str("uploadID", ev.UploadID).Msg("could not read parent")
return nil
}
return p
}

now := time.Now()
if p, err := node.ReadNode(ctx, fs.lu, up.Info.Storage["SpaceRoot"], n.ParentID, false, nil, true); err != nil {
log.Error().Err(err).Str("uploadID", ev.UploadID).Msg("could not read parent")
} else {
// update parent tmtime to propagate etag change
if failed {
// propagate sizeDiff after failed postprocessing
if err := fs.tp.Propagate(ctx, up.Node, -up.SizeDiff); err != nil {
log.Error().Err(err).Str("uploadID", ev.UploadID).Msg("could not propagate tree size change")
}
} else if p := getParent(); p != nil {
// update parent tmtime to propagate etag change after successful postprocessing
_ = p.SetTMTime(ctx, &now)
if err := fs.tp.Propagate(ctx, p, 0); err != nil {
log.Error().Err(err).Str("uploadID", ev.UploadID).Msg("could not propagate etag change")
Expand Down
10 changes: 5 additions & 5 deletions pkg/storage/utils/decomposedfs/upload/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func Get(ctx context.Context, id string, lu *lookup.Lookup, tp Tree, fsRoot stri

up := buildUpload(ctx, info, info.Storage["BinPath"], infoPath, lu, tp, pub, async, tknopts)
up.versionsPath = info.MetaData["versionsPath"]
up.sizeDiff, _ = strconv.ParseInt(info.MetaData["sizeDiff"], 10, 64)
up.SizeDiff, _ = strconv.ParseInt(info.MetaData["sizeDiff"], 10, 64)
return up, nil
}

Expand Down Expand Up @@ -364,8 +364,8 @@ func initNewNode(upload *Upload, n *node.Node, fsize uint64) (*lockedfile.File,
}

// on a new file the sizeDiff is the fileSize
upload.sizeDiff = int64(fsize)
upload.Info.MetaData["sizeDiff"] = strconv.Itoa(int(upload.sizeDiff))
upload.SizeDiff = int64(fsize)
upload.Info.MetaData["sizeDiff"] = strconv.Itoa(int(upload.SizeDiff))
return f, nil
}

Expand Down Expand Up @@ -393,9 +393,9 @@ func updateExistingNode(upload *Upload, n *node.Node, spaceID string, fsize uint
}

upload.versionsPath = upload.lu.InternalPath(spaceID, n.ID+node.RevisionIDDelimiter+tmtime.UTC().Format(time.RFC3339Nano))
upload.sizeDiff = int64(fsize) - old.Blobsize
upload.SizeDiff = int64(fsize) - old.Blobsize
upload.Info.MetaData["versionsPath"] = upload.versionsPath
upload.Info.MetaData["sizeDiff"] = strconv.Itoa(int(upload.sizeDiff))
upload.Info.MetaData["sizeDiff"] = strconv.Itoa(int(upload.SizeDiff))

targetPath := n.InternalPath()

Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/utils/decomposedfs/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ type Upload struct {
Info tusd.FileInfo
// node for easy access
Node *node.Node
// SizeDiff size difference between new and old file version
SizeDiff int64
// infoPath is the path to the .info file
infoPath string
// binPath is the path to the binary file (which has no extension)
Expand All @@ -100,8 +102,6 @@ type Upload struct {
tp Tree
// versionsPath will be empty if there was no file before
versionsPath string
// sizeDiff size difference between new and old file version
sizeDiff int64
// and a logger as well
log zerolog.Logger
// publisher used to publish events
Expand Down Expand Up @@ -296,7 +296,7 @@ func (upload *Upload) FinishUpload(_ context.Context) error {
}
}

return upload.tp.Propagate(upload.Ctx, n, upload.sizeDiff)
return upload.tp.Propagate(upload.Ctx, n, upload.SizeDiff)
}

// Terminate terminates the upload
Expand Down

0 comments on commit 08de0da

Please sign in to comment.