Skip to content

Commit

Permalink
Skip get user call in eosfs in case previous ones also failed (#2237)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Nov 8, 2021
1 parent c35c530 commit bb40f54
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit bb40f54

Please sign in to comment.