Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrently stat shares in OCS service #2941

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Concurrently stat user shares
  • Loading branch information
ishank011 committed Jun 9, 2022
commit 406f602c0e320b6cc060791b868aa062998f5e88
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
package shares

import (
"context"
"net/http"
"sync"

gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
Expand Down Expand Up @@ -175,45 +178,66 @@ func (h *Handler) listUserShares(r *http.Request, filters []*collaboration.Filte
}

ocsDataPayload := make([]*conversions.ShareData, 0)
if h.gatewayAddr != "" {
// get a connection to the users share provider
client, err := pool.GetGatewayServiceClient(pool.Endpoint(h.gatewayAddr))
if err != nil {
return ocsDataPayload, nil, err
}
client, err := pool.GetGatewayServiceClient(pool.Endpoint(h.gatewayAddr))
if err != nil {
return ocsDataPayload, nil, err
}

// do list shares request. filtered
lsUserSharesResponse, err := client.ListShares(ctx, &lsUserSharesRequest)
if err != nil {
return ocsDataPayload, nil, err
}
if lsUserSharesResponse.Status.Code != rpc.Code_CODE_OK {
return ocsDataPayload, lsUserSharesResponse.Status, nil
}
// do list shares request. filtered
lsUserSharesResponse, err := client.ListShares(ctx, &lsUserSharesRequest)
if err != nil {
return ocsDataPayload, nil, err
}
if lsUserSharesResponse.Status.Code != rpc.Code_CODE_OK {
return ocsDataPayload, lsUserSharesResponse.Status, nil
}

// build OCS response payload
for _, s := range lsUserSharesResponse.Shares {
data, err := conversions.CS3Share2ShareData(ctx, s)
if err != nil {
log.Debug().Interface("share", s).Interface("shareData", data).Err(err).Msg("could not CS3Share2ShareData, skipping")
continue
var wg sync.WaitGroup
workers := 50
input := make(chan *collaboration.Share, len(lsUserSharesResponse.Shares))
output := make(chan *conversions.ShareData, len(lsUserSharesResponse.Shares))

for i := 0; i < workers; i++ {
wg.Add(1)
go func(ctx context.Context, client gateway.GatewayAPIClient, input chan *collaboration.Share, output chan *conversions.ShareData, wg *sync.WaitGroup) {
defer wg.Done()

// build OCS response payload
for s := range input {
data, err := conversions.CS3Share2ShareData(ctx, s)
if err != nil {
log.Debug().Interface("share", s.GetId()).Err(err).Msg("CS3Share2ShareData call failed, skipping")
return
}

info, status, err := h.getResourceInfoByID(ctx, client, s.ResourceId)
if err != nil || status.Code != rpc.Code_CODE_OK {
log.Debug().Interface("share", s.GetId()).Interface("status", status).Interface("shareData", data).Err(err).Msg("could not stat share, skipping")
return
}

if err := h.addFileInfo(ctx, data, info); err != nil {
log.Debug().Interface("share", s.GetId()).Interface("shareData", data).Err(err).Msg("could not add file info, skipping")
return
}
h.mapUserIds(ctx, client, data)

log.Debug().Interface("share", s.GetId()).Interface("shareData", data).Msg("mapped")
output <- data
}
}(ctx, client, input, output, &wg)
}

info, status, err := h.getResourceInfoByID(ctx, client, s.ResourceId)
if err != nil || status.Code != rpc.Code_CODE_OK {
log.Debug().Interface("share", s).Interface("status", status).Interface("shareData", data).Err(err).Msg("could not stat share, skipping")
continue
}
for _, share := range lsUserSharesResponse.Shares {
input <- share
}

if err := h.addFileInfo(ctx, data, info); err != nil {
log.Debug().Interface("share", s).Interface("info", info).Interface("shareData", data).Err(err).Msg("could not add file info, skipping")
continue
}
h.mapUserIds(ctx, client, data)
close(input)
wg.Wait()
close(output)

log.Debug().Interface("share", s).Interface("info", info).Interface("shareData", data).Msg("mapped")
ocsDataPayload = append(ocsDataPayload, data)
}
for s := range output {
ocsDataPayload = append(ocsDataPayload, s)
}

return ocsDataPayload, nil, nil
Expand Down