From c7397132f361d2fe3edc297422f1c8a08d822a05 Mon Sep 17 00:00:00 2001 From: kobergj Date: Thu, 13 Jan 2022 16:59:33 +0100 Subject: [PATCH] fix statcache logic (#2440) Signed-off-by: jkoberg --- changelog/unreleased/improve_statcache.md | 5 +++++ .../grpc/services/gateway/storageprovidercache.go | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 changelog/unreleased/improve_statcache.md diff --git a/changelog/unreleased/improve_statcache.md b/changelog/unreleased/improve_statcache.md new file mode 100644 index 00000000000..fc4750b35c4 --- /dev/null +++ b/changelog/unreleased/improve_statcache.md @@ -0,0 +1,5 @@ +Bugfix: Add ArbitraryMetadataKeys to statcache key + +Otherwise stating with and without them would return the same result (because it is cached) + +https://github.com/cs3org/reva/pull/2440 diff --git a/internal/grpc/services/gateway/storageprovidercache.go b/internal/grpc/services/gateway/storageprovidercache.go index 535ae7b9d7b..3100f126317 100644 --- a/internal/grpc/services/gateway/storageprovidercache.go +++ b/internal/grpc/services/gateway/storageprovidercache.go @@ -211,19 +211,24 @@ type cachedAPIClient struct { // generates a user specific key pointing to ref - used for statcache // a key looks like: uid:1234-1233!sid:5678-5677!oid:9923-9934!path:/path/to/source // as you see it adds "uid:"/"sid:"/"oid:" prefixes to the uuids so they can be differentiated -func statKey(user *userpb.User, ref *provider.Reference) string { +func statKey(user *userpb.User, ref *provider.Reference, metaDataKeys []string) string { if ref == nil || ref.ResourceId == nil || ref.ResourceId.StorageId == "" { return "" } - return "uid" + user.Id.OpaqueId + "!sid:" + ref.ResourceId.StorageId + "!oid:" + ref.ResourceId.OpaqueId + "!path:" + ref.Path + key := "uid" + user.Id.OpaqueId + "!sid:" + ref.ResourceId.StorageId + "!oid:" + ref.ResourceId.OpaqueId + "!path:" + ref.Path + for _, k := range metaDataKeys { + key += "!mdk:" + k + } + + return key } // Stat looks in cache first before forwarding to storage provider func (c *cachedAPIClient) Stat(ctx context.Context, in *provider.StatRequest, opts ...grpc.CallOption) (*provider.StatResponse, error) { cache := c.caches[stat] - key := statKey(ctxpkg.ContextMustGetUser(ctx), in.Ref) + key := statKey(ctxpkg.ContextMustGetUser(ctx), in.Ref, in.ArbitraryMetadataKeys) if key != "" { s := &provider.StatResponse{} if err := pullFromCache(cache, key, s); err == nil {