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

Skip get user call in eosfs in case previous ones also failed #2237

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions changelog/unreleased/eos-skip-get-user-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Skip get user call in eosfs in case previous ones also failed

https://github.com/cs3org/reva/pull/2237
21 changes: 19 additions & 2 deletions pkg/storage/utils/eosfs/eosfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/cs3org/reva/pkg/eosclient/eosgrpc"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/mime"
"github.com/cs3org/reva/pkg/rgrpc/status"
"github.com/cs3org/reva/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/pkg/sharedconf"
"github.com/cs3org/reva/pkg/storage"
Expand Down Expand Up @@ -1796,6 +1797,12 @@ func (fs *eosfs) extractUIDAndGID(u *userpb.User) (eosclient.Authorization, erro
}

func (fs *eosfs) getUIDGateway(ctx context.Context, u *userpb.UserId) (eosclient.Authorization, error) {
log := appctx.GetLogger(ctx)
if userIDInterface, err := fs.userIDCache.Get(u.OpaqueId); err == nil {
log.Debug().Msg("eosfs: found cached user " + u.OpaqueId)
return fs.extractUIDAndGID(userIDInterface.(*userpb.User))
}

client, err := pool.GetGatewayServiceClient(fs.conf.GatewaySvc)
if err != nil {
return eosclient.Authorization{}, errors.Wrap(err, "eosfs: error getting gateway grpc client")
Expand All @@ -1804,11 +1811,15 @@ func (fs *eosfs) getUIDGateway(ctx context.Context, u *userpb.UserId) (eosclient
UserId: u,
})
if err != nil {
_ = fs.userIDCache.SetWithExpire(u.OpaqueId, &userpb.User{}, 12*time.Hour)
return eosclient.Authorization{}, errors.Wrap(err, "eosfs: error getting user")
}
if getUserResp.Status.Code != rpc.Code_CODE_OK {
return eosclient.Authorization{}, errors.Wrap(err, "eosfs: grpc get user failed")
_ = fs.userIDCache.SetWithExpire(u.OpaqueId, &userpb.User{}, 12*time.Hour)
return eosclient.Authorization{}, status.NewErrorFromCode(getUserResp.Status.Code, "eosfs")
}

_ = fs.userIDCache.Set(u.OpaqueId, getUserResp.User)
return fs.extractUIDAndGID(getUserResp.User)
}

Expand All @@ -1834,10 +1845,16 @@ func (fs *eosfs) getUserIDGateway(ctx context.Context, uid string) (*userpb.User
Value: uid,
})
if err != nil {
// Insert an empty object in the cache so that we don't make another call
// for a specific amount of time
_ = fs.userIDCache.SetWithExpire(uid, &userpb.UserId{}, 12*time.Hour)
return nil, errors.Wrap(err, "eosfs: error getting user")
}
if getUserResp.Status.Code != rpc.Code_CODE_OK {
return nil, errors.Wrap(err, "eosfs: grpc get user failed")
// Insert an empty object in the cache so that we don't make another call
// for a specific amount of time
_ = fs.userIDCache.SetWithExpire(uid, &userpb.UserId{}, 12*time.Hour)
return nil, status.NewErrorFromCode(getUserResp.Status.Code, "eosfs")
}

_ = fs.userIDCache.Set(uid, getUserResp.User.Id)
Expand Down