Skip to content

Commit

Permalink
Merge pull request #3571 from kobergj/AsyncUploadFixes
Browse files Browse the repository at this point in the history
More Async Upload Fixes
  • Loading branch information
micbar authored Dec 29, 2022
2 parents 9d1998e + 8ea0228 commit f7d3b57
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 37 deletions.
5 changes: 4 additions & 1 deletion changelog/unreleased/async-uploads-improvements.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Enhancement: Async Upload Improvements

Collection of smaller fixes and quality of life improvements for async postprocessing, especially the upload part.
Contains unit tests, 0 byte uploads, adjusted endpoint responses and more
Contains unit tests, 0 byte uploads, adjusted endpoint responses and more. Adjust mtime when requested from upload.
Add etag to upload info.

https://github.com/cs3org/reva/pull/3556

https://github.com/cs3org/reva/pull/3571
14 changes: 14 additions & 0 deletions pkg/storage/utils/decomposedfs/upload/processing.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,20 @@ func CreateNodeForUpload(upload *Upload, initAttrs map[string]string) (*node.Nod
return nil, errors.Wrap(err, "Decomposedfs: could not write metadata")
}

// overwrite mtime if requested
if upload.Info.MetaData["mtime"] != "" {
if err := n.SetMtimeString(upload.Info.MetaData["mtime"]); err != nil {
return nil, err
}
}

// add etag to metadata
nfi, err := os.Stat(n.InternalPath())
if err != nil {
return nil, err
}
upload.Info.MetaData["etag"], _ = node.CalculateEtag(n.ID, nfi.ModTime())

// update nodeid for later
upload.Info.Storage["NodeId"] = n.ID
if err := upload.writeInfo(); err != nil {
Expand Down
43 changes: 7 additions & 36 deletions pkg/storage/utils/decomposedfs/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,13 @@ func (upload *Upload) FinishUpload(_ context.Context) error {
}
}

if upload.async {
// handle postprocessing asynchronously but inform there is something in progress
return upload.tp.Propagate(upload.Ctx, n, upload.sizeDiff)
}

err = upload.Finalize()
Cleanup(upload, err != nil, false)
if err != nil {
return err
if !upload.async {
// handle postprocessing synchronously
err = upload.Finalize()
Cleanup(upload, err != nil, false)
if err != nil {
return err
}
}

return upload.tp.Propagate(upload.Ctx, n, upload.sizeDiff)
Expand Down Expand Up @@ -347,33 +345,6 @@ func (upload *Upload) Finalize() (err error) {
return errors.Wrap(err, "failed to upload file to blostore")
}

if upload.async {
return nil
}

sublog := appctx.GetLogger(upload.Ctx).
With().
Interface("info", upload.Info).
Str("binPath", upload.binPath).
Str("targetPath", n.InternalPath()).
Str("spaceID", upload.Info.Storage["SpaceRoot"]).
Logger()

// tests sometimes set the mtime
if upload.Info.MetaData["mtime"] != "" {
if err := n.SetMtimeString(upload.Info.MetaData["mtime"]); err != nil {
sublog.Err(err).Interface("info", upload.Info).Msg("Decomposedfs: could not set mtime metadata")
return err
}
}

// some clients need the etag in the upload metadata
fi, err := os.Stat(n.InternalPath())
if err != nil {
sublog.Err(err).Interface("info", upload.Info).Str("path", n.InternalPath()).Msg("Decomposedfs: could not stat file")
return err
}
upload.Info.MetaData["etag"], _ = node.CalculateEtag(n.ID, fi.ModTime())
return nil
}

Expand Down

0 comments on commit f7d3b57

Please sign in to comment.