Skip to content

Commit

Permalink
Parallelize stat calls to providers
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Mar 25, 2021
1 parent 219de7b commit 99fbe7c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ linters:
- gocritic
- prealloc
#- gosec

65 changes: 43 additions & 22 deletions internal/grpc/services/gateway/storageprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1166,31 +1166,24 @@ func (s *svc) stat(ctx context.Context, req *provider.StatRequest) (*provider.St
return c.Stat(ctx, req)
}

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)
}
wg.Wait()

var totalSize uint64
infos := []*provider.ResourceInfo{}
for _, p := range providers {
c, err := s.getStorageProviderClient(ctx, p)
if err != nil {
for i := range providers {
if errors[i] != nil {
return &provider.StatResponse{
Status: status.NewInternal(ctx, err, "error connecting to storage provider="+p.Address),
Status: status.NewStatusFromErrType(ctx, "stat ref: "+req.Ref.String(), errors[i]),
}, nil
}

if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) {
req = &provider.StatRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{
Path: p.ProviderPath,
},
},
}
}
res, err := c.Stat(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "gateway: error calling ListContainer")
}
totalSize += res.Info.Size
infos = append(infos, res.Info)
totalSize += infoFromProviders[i].Size
}

// TODO(ishank011): aggregrate other properties for references spread across storage providers, eg. /eos
Expand All @@ -1202,13 +1195,41 @@ func (s *svc) stat(ctx context.Context, req *provider.StatRequest) (*provider.St
OpaqueId: uuid.New().String(),
},
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
Etag: etag.GenerateEtagFromResources(nil, infos),
Etag: etag.GenerateEtagFromResources(nil, infoFromProviders),
Path: resPath,
Size: totalSize,
},
}, 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()
c, err := s.getStorageProviderClient(ctx, p)
if err != nil {
*e = errors.Wrap(err, "error connecting to storage provider="+p.Address)
return
}

resPath := path.Clean(req.Ref.GetPath())
newPath := req.Ref.GetPath()
if resPath != "" && !strings.HasPrefix(resPath, p.ProviderPath) {
newPath = p.ProviderPath
}
r, err := c.Stat(ctx, &provider.StatRequest{
Ref: &provider.Reference{
Spec: &provider.Reference_Path{
Path: newPath,
},
},
})
if err != nil {
*e = errors.Wrap(err, "gateway: error calling ListContainer")
return
}
res = &provider.ResourceInfo{}
*res = *r.Info
}

func (s *svc) Stat(ctx context.Context, req *provider.StatRequest) (*provider.StatResponse, error) {
p, st := s.getPath(ctx, req.Ref, req.ArbitraryMetadataKeys...)
if st.Code != rpc.Code_CODE_OK {
Expand Down

0 comments on commit 99fbe7c

Please sign in to comment.