Skip to content

Commit

Permalink
Merge branch 'edge' into RestoringSpaces
Browse files Browse the repository at this point in the history
  • Loading branch information
kobergj committed Feb 3, 2022
2 parents 7076d96 + 48c06f9 commit ed8b15b
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 3,295 deletions.
10 changes: 10 additions & 0 deletions changelog/unreleased/change-remove-owncloud-storage-driver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Change: remove the ownCloud storage driver

We've removed the ownCloud storage driver because it was no longer
maintained after the ownCloud SQL storage driver was added.

If you have been using the ownCloud storage driver, please switch
to the ownCloud SQL storage driver which brings you more features and
is under active maintenance.

https://github.com/cs3org/reva/pull/2495
5 changes: 5 additions & 0 deletions changelog/unreleased/invalidate-listproviders-cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Invalidate listproviders cache

We now invalidate the related listproviders cache entries when updating or deleting a storage space.

https://github.com/cs3org/reva/pull/2500
6 changes: 6 additions & 0 deletions changelog/unreleased/spaces-stat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Fix spaces stat

When stating a space e.g. the Share Jail and that space contains another space, in this case a share
then the stat would sometimes get the sub space instead of the Share Jail itself.

https://github.com/cs3org/reva/pull/2501
44 changes: 0 additions & 44 deletions examples/oc-phoenix/storage-home.toml

This file was deleted.

34 changes: 0 additions & 34 deletions examples/oc-phoenix/storage-oc.toml

This file was deleted.

70 changes: 67 additions & 3 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ func (s *svc) UpdateStorageSpace(ctx context.Context, req *provider.UpdateStorag
}

if res.Status.Code == rpc.Code_CODE_OK {
s.cache.RemoveStat(ctxpkg.ContextMustGetUser(ctx), res.StorageSpace.Root)
id := res.StorageSpace.Root
s.cache.RemoveStat(ctxpkg.ContextMustGetUser(ctx), id)
s.cache.RemoveListStorageProviders(id)
}
return res, nil
}
Expand Down Expand Up @@ -325,7 +327,9 @@ func (s *svc) DeleteStorageSpace(ctx context.Context, req *provider.DeleteStorag
}, nil
}

s.cache.RemoveStat(ctxpkg.ContextMustGetUser(ctx), &provider.ResourceId{OpaqueId: req.Id.OpaqueId})
id := &provider.ResourceId{OpaqueId: req.Id.OpaqueId}
s.cache.RemoveStat(ctxpkg.ContextMustGetUser(ctx), id)
s.cache.RemoveListStorageProviders(id)

if dsRes.Status.Code != rpc.Code_CODE_OK {
return dsRes, nil
Expand Down Expand Up @@ -805,7 +809,7 @@ func (s *svc) Unlock(ctx context.Context, req *provider.UnlockRequest) (*provide
// Stat returns the Resoure info for a given resource by forwarding the request to the responsible provider.
// TODO cache info
func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.StatResponse, error) {
c, _, ref, err := s.findAndUnwrap(ctx, req.Ref)
c, _, ref, err := s.findAndUnwrapUnique(ctx, req.Ref)
if err != nil {
return &provider.StatResponse{
Status: status.NewNotFound(ctx, fmt.Sprintf("gateway could not find space for ref=%+v", req.Ref)),
Expand Down Expand Up @@ -994,6 +998,16 @@ func (s *svc) find(ctx context.Context, ref *provider.Reference) (provider.Provi
return client, p[0], err
}

func (s *svc) findUnique(ctx context.Context, ref *provider.Reference) (provider.ProviderAPIClient, *registry.ProviderInfo, error) {
p, err := s.findSingleSpace(ctx, ref)
if err != nil {
return nil, nil, err
}

client, err := s.getStorageProviderClient(ctx, p[0])
return client, p[0], err
}

// FIXME findAndUnwrap currently just returns the first provider ... which may not be what is needed.
// for the ListRecycle call we need an exact match, for Stat and List we need to query all related providers
func (s *svc) findAndUnwrap(ctx context.Context, ref *provider.Reference) (provider.ProviderAPIClient, *registry.ProviderInfo, *provider.Reference, error) {
Expand All @@ -1017,6 +1031,27 @@ func (s *svc) findAndUnwrap(ctx context.Context, ref *provider.Reference) (provi
return c, p, relativeReference, nil
}

func (s *svc) findAndUnwrapUnique(ctx context.Context, ref *provider.Reference) (provider.ProviderAPIClient, *registry.ProviderInfo, *provider.Reference, error) {
c, p, err := s.findUnique(ctx, ref)
if err != nil {
return nil, nil, nil, err
}

var (
root *provider.ResourceId
mountPath string
)
for _, space := range decodeSpaces(p) {
mountPath = decodePath(space)
root = space.Root
break // TODO can there be more than one space for a path?
}

relativeReference := unwrap(ref, mountPath, root)

return c, p, relativeReference, nil
}

func (s *svc) getStorageProviderClient(_ context.Context, p *registry.ProviderInfo) (provider.ProviderAPIClient, error) {
c, err := pool.GetStorageProviderServiceClient(p.Address)
if err != nil {
Expand Down Expand Up @@ -1064,6 +1099,35 @@ func (s *svc) findSpaces(ctx context.Context, ref *provider.Reference) ([]*regis
return s.findProvider(ctx, listReq)
}

func (s *svc) findSingleSpace(ctx context.Context, ref *provider.Reference) ([]*registry.ProviderInfo, error) {
switch {
case ref == nil:
return nil, errtypes.BadRequest("missing reference")
case ref.ResourceId != nil:
// no action needed in that case
case ref.Path != "": // TODO implement a mount path cache in the registry?
// nothing to do here either
default:
return nil, errtypes.BadRequest("invalid reference, at least path or id must be set")
}

filters := map[string]string{
"path": ref.Path,
"unique": "true",
}
if ref.ResourceId != nil {
filters["storage_id"] = ref.ResourceId.StorageId
filters["opaque_id"] = ref.ResourceId.OpaqueId
}

listReq := &registry.ListStorageProvidersRequest{
Opaque: &typesv1beta1.Opaque{},
}
sdk.EncodeOpaqueMap(listReq.Opaque, filters)

return s.findProvider(ctx, listReq)
}

func (s *svc) findProvider(ctx context.Context, listReq *registry.ListStorageProvidersRequest) ([]*registry.ProviderInfo, error) {
// lookup
c, err := pool.GetStorageRegistryClient(s.c.StorageRegistryEndpoint)
Expand Down
16 changes: 16 additions & 0 deletions internal/grpc/services/gateway/storageprovidercache.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ func (c Caches) RemoveStat(user *userpb.User, res *provider.ResourceId) {
}
}

// RemoveListStorageProviders removes a reference from the listproviders cache
func (c Caches) RemoveListStorageProviders(res *provider.ResourceId) {
if res == nil {
return
}
sid := res.StorageId

cache := c[listproviders]
for _, key := range cache.GetKeys() {
if strings.Contains(key, sid) {
_ = cache.Remove(key)
continue
}
}
}

func initCache(ttlSeconds int) *ttlcache.Cache {
cache := ttlcache.NewCache()
_ = cache.SetTTL(time.Duration(ttlSeconds) * time.Second)
Expand Down
1 change: 0 additions & 1 deletion pkg/storage/fs/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
_ "github.com/cs3org/reva/pkg/storage/fs/localhome"
_ "github.com/cs3org/reva/pkg/storage/fs/nextcloud"
_ "github.com/cs3org/reva/pkg/storage/fs/ocis"
_ "github.com/cs3org/reva/pkg/storage/fs/owncloud"
_ "github.com/cs3org/reva/pkg/storage/fs/owncloudsql"
_ "github.com/cs3org/reva/pkg/storage/fs/s3"
_ "github.com/cs3org/reva/pkg/storage/fs/s3ng"
Expand Down
Loading

0 comments on commit ed8b15b

Please sign in to comment.