From e68724370fbcd9dfa7bcd41f0f4d2afd0d897fb3 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Fri, 4 Jun 2021 11:32:40 +0200 Subject: [PATCH] [cbox-commit-3] Make stat and list calls sequential for virtual views --- .../grpc/services/gateway/storageprovider.go | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/internal/grpc/services/gateway/storageprovider.go b/internal/grpc/services/gateway/storageprovider.go index 1a751742ef..4694ac8589 100644 --- a/internal/grpc/services/gateway/storageprovider.go +++ b/internal/grpc/services/gateway/storageprovider.go @@ -30,6 +30,7 @@ import ( rtrace "github.com/cs3org/reva/pkg/trace" "google.golang.org/protobuf/types/known/fieldmaskpb" + "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" @@ -1207,13 +1208,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 { @@ -1241,12 +1241,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) { @@ -1260,10 +1259,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) { @@ -1481,13 +1480,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) @@ -1532,8 +1528,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)