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

Commit

Permalink
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 Aug 4, 2021
1 parent 7c8932d commit 058d8f7
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,13 +1163,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 @@ -1197,12 +1196,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
}

resPath := path.Clean(req.Ref.GetPath())
Expand All @@ -1212,13 +1210,10 @@ func (s *svc) statOnProvider(ctx context.Context, req *provider.StatRequest, res
}
r, err := c.Stat(ctx, &provider.StatRequest{Ref: &provider.Reference{Path: newPath}})
if err != nil {
*e = errors.Wrap(err, fmt.Sprintf("gateway: error calling Stat %s on %+v", newPath, p))
return
}
if res == nil {
res = &provider.ResourceInfo{}
e := errors.Wrap(err, fmt.Sprintf("gateway: error calling Stat %s: %+v", newPath, 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 @@ -1431,13 +1426,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 @@ -1481,8 +1473,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 058d8f7

Please sign in to comment.