Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
[cbox-commit-3] Make stat and list calls sequential for virtual views
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Oct 4, 2021
1 parent 891f44c commit 31153b6
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"time"

rtrace "github.com/cs3org/reva/pkg/trace"
"github.com/cs3org/reva/pkg/utils"

collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
Expand Down Expand Up @@ -1214,13 +1215,12 @@ func (s *svc) statAcrossProviders(ctx context.Context, req *provider.StatRequest

infoFromProviders := make([]*provider.ResourceInfo, len(providers))
errors := make([]error, len(providers))
var wg sync.WaitGroup

for i, p := range providers {
wg.Add(1)
go s.statOnProvider(ctx, req, &infoFromProviders[i], p, &errors[i], &wg)
r, e := s.statOnProvider(ctx, req, p)
infoFromProviders[i] = r
errors[i] = e
}
wg.Wait()

var totalSize uint64
for i := range providers {
Expand Down Expand Up @@ -1248,12 +1248,11 @@ func (s *svc) statAcrossProviders(ctx context.Context, req *provider.StatRequest
}, nil
}

func (s *svc) statOnProvider(ctx context.Context, req *provider.StatRequest, res **provider.ResourceInfo, p *registry.ProviderInfo, e *error, wg *sync.WaitGroup) {
defer wg.Done()
func (s *svc) statOnProvider(ctx context.Context, req *provider.StatRequest, p *registry.ProviderInfo) (*provider.ResourceInfo, error) {
c, err := s.getStorageProviderClient(ctx, p)
if err != nil {
*e = errors.Wrap(err, "error connecting to storage provider="+p.Address)
return
e := errors.Wrap(err, "error connecting to storage provider="+p.Address)
return nil, e
}

if utils.IsAbsoluteReference(req.Ref) {
Expand All @@ -1267,10 +1266,10 @@ func (s *svc) statOnProvider(ctx context.Context, req *provider.StatRequest, res

r, err := c.Stat(ctx, req)
if err != nil {
*e = errors.Wrap(err, fmt.Sprintf("gateway: error calling Stat %s on %+v", req.Ref, p))
return
e := errors.Wrap(err, fmt.Sprintf("gateway: error calling Stat %s: %+v", req.Ref.String(), p))
return nil, e
}
*res = r.Info
return r.Info, nil
}

func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.StatResponse, error) {
Expand Down Expand Up @@ -1488,13 +1487,10 @@ func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequ
infoFromProviders := make([][]*provider.ResourceInfo, len(providers))
errors := make([]error, len(providers))
indirects := make([]bool, len(providers))
var wg sync.WaitGroup

for i, p := range providers {
wg.Add(1)
go s.listContainerOnProvider(ctx, req, &infoFromProviders[i], p, &indirects[i], &errors[i], &wg)
s.listContainerOnProvider(ctx, req, &infoFromProviders[i], p, &indirects[i], &errors[i])
}
wg.Wait()

infos := []*provider.ResourceInfo{}
nestedInfos := make(map[string][]*provider.ResourceInfo)
Expand Down Expand Up @@ -1539,8 +1535,7 @@ func (s *svc) listContainer(ctx context.Context, req *provider.ListContainerRequ
}, nil
}

func (s *svc) listContainerOnProvider(ctx context.Context, req *provider.ListContainerRequest, res *[]*provider.ResourceInfo, p *registry.ProviderInfo, ind *bool, e *error, wg *sync.WaitGroup) {
defer wg.Done()
func (s *svc) listContainerOnProvider(ctx context.Context, req *provider.ListContainerRequest, res *[]*provider.ResourceInfo, p *registry.ProviderInfo, ind *bool, e *error) {
c, err := s.getStorageProviderClient(ctx, p)
if err != nil {
*e = errors.Wrap(err, "error connecting to storage provider="+p.Address)
Expand Down

0 comments on commit 31153b6

Please sign in to comment.