From ffb0a564c4d657cd67730505a04aaf0caeaac111 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Thu, 4 Nov 2021 12:12:06 +0100 Subject: [PATCH] Skip get user call in eosfs in case previous ones also failed --- .../unreleased/eos-skip-get-user-call.md | 3 +++ pkg/storage/utils/eosfs/eosfs.go | 21 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/eos-skip-get-user-call.md diff --git a/changelog/unreleased/eos-skip-get-user-call.md b/changelog/unreleased/eos-skip-get-user-call.md new file mode 100644 index 0000000000..7a7e7cfd70 --- /dev/null +++ b/changelog/unreleased/eos-skip-get-user-call.md @@ -0,0 +1,3 @@ +Enhancement: Skip get user call in eosfs in case previous ones also failed + +https://github.com/cs3org/reva/pull/2237 \ No newline at end of file diff --git a/pkg/storage/utils/eosfs/eosfs.go b/pkg/storage/utils/eosfs/eosfs.go index 17542f76a2..14db47a15e 100644 --- a/pkg/storage/utils/eosfs/eosfs.go +++ b/pkg/storage/utils/eosfs/eosfs.go @@ -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" @@ -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") @@ -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) } @@ -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)