Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only] Upload post processing #2963

Merged
merged 12 commits into from
Jul 1, 2022
7 changes: 7 additions & 0 deletions changelog/unreleased/upload-postprocessing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Allow async postprocessing of uploads

The server is now able to return immediately after it has stored all bytes.
Postprocessing can be configured so that the server behaves exactly like now,
therefore it is no breaking change

https://github.com/cs3org/reva/pull/2963
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ require (
github.com/sethvargo/go-password v0.2.0
github.com/stretchr/testify v1.7.1
github.com/studio-b12/gowebdav v0.0.0-20211109083228-3f8721cd4b6f
github.com/test-go/testify v1.1.4
github.com/thanhpk/randstr v1.0.4
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tus/tusd v1.8.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,8 @@ github.com/studio-b12/gowebdav v0.0.0-20211109083228-3f8721cd4b6f h1:L2NE7BXnSlS
github.com/studio-b12/gowebdav v0.0.0-20211109083228-3f8721cd4b6f/go.mod h1:bHA7t77X/QFExdeAnDzK6vKM34kEZAcE1OX4MfiwjkE=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE=
github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU=
github.com/thanhpk/randstr v1.0.4 h1:IN78qu/bR+My+gHCvMEXhR/i5oriVHcTB/BJJIRTsNo=
github.com/thanhpk/randstr v1.0.4/go.mod h1:M/H2P1eNLZzlDwAzpkkkUvoyNNMbzRGhESZuEQk3r0U=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
Expand Down
8 changes: 8 additions & 0 deletions internal/http/services/owncloud/ocdav/propfind/propfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,14 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
}
}

if status := utils.ReadPlainFromOpaque(md.Opaque, "status"); status == "processing" {
response.Propstat = append(response.Propstat, PropstatXML{
Status: "HTTP/1.1 425 TOO EARLY", // TODO: use proper status code
Prop: propstatOK.Prop,
})
return &response, nil
}

if len(propstatOK.Prop) > 0 {
response.Propstat = append(response.Propstat, propstatOK)
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/storage/utils/decomposedfs/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ const (

// RootID defines the root node's ID
RootID = "root"

// ProcessingStatus is the name of the status when processing a file
ProcessingStatus = "processing"
)

// Node represents a node in the tree and provides methods to get a Parent or Child instance
Expand Down Expand Up @@ -641,6 +644,10 @@ func (n *Node) AsResourceInfo(ctx context.Context, rp *provider.ResourcePermissi
ParentId: parentID,
}

if n.IsProcessing() {
ri.Opaque = utils.AppendPlainToOpaque(ri.Opaque, "status", "processing")
kobergj marked this conversation as resolved.
Show resolved Hide resolved
}

if nodeType == provider.ResourceType_RESOURCE_TYPE_CONTAINER {
ts, err := n.GetTreeSize()
if err == nil {
Expand Down Expand Up @@ -1124,6 +1131,22 @@ func (n *Node) FindStorageSpaceRoot() error {
return nil
}

// MarkProcessing marks the node as being processed
func (n *Node) MarkProcessing() error {
return n.SetMetadata(xattrs.StatusPrefix, ProcessingStatus)
}

// UnmarkProcessing removes the processing flag from the node
func (n *Node) UnmarkProcessing() error {
return n.RemoveMetadata(xattrs.StatusPrefix)
}

// IsProcessing returns true if the node is currently being processed
func (n *Node) IsProcessing() bool {
v, err := n.GetMetadata(xattrs.StatusPrefix)
return err == nil && v == ProcessingStatus
}

// IsSpaceRoot checks if the node is a space root
func IsSpaceRoot(r *Node) bool {
path := r.InternalPath()
Expand Down
10 changes: 10 additions & 0 deletions pkg/storage/utils/decomposedfs/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package options
import (
"path/filepath"
"strings"
"time"

"github.com/mitchellh/mapstructure"
"github.com/pkg/errors"
Expand Down Expand Up @@ -51,6 +52,15 @@ type Options struct {

PersonalSpaceAliasTemplate string `mapstructure:"personalspacealias_template"`
GeneralSpaceAliasTemplate string `mapstructure:"generalspacealias_template"`

Postprocessing PostprocessingOptions `mapstructure:"postprocessing"`
}

// PostprocessingOptions defines the available options for postprocessing
type PostprocessingOptions struct {
AsyncFileUploads bool `mapstructure:"asyncfileuploads"`

DelayProcessing time.Duration `mapstructure:"delayprocessing"` // for testing purposes, or if you want to annoy your users
}

// New returns a new Options instance for the given configuration
Expand Down
Loading