From 528540f805525bbe0a3ebe188a139e0da4856549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Tue, 25 Apr 2023 11:31:35 +0200 Subject: [PATCH 1/2] Fix reading/writing from and to the stat cache --- .../handlers/apps/sharing/shares/shares.go | 20 +++++++++---------- .../ocs/handlers/apps/sharing/shares/user.go | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go index adeeb03dee..51666b7649 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/shares.go @@ -83,7 +83,7 @@ type Handler struct { skipUpdatingExistingSharesMountpoints bool additionalInfoTemplate *template.Template userIdentifierCache *ttlcache.Cache - resourceInfoCache cache.StatCache + statCache cache.StatCache deniable bool resharing bool @@ -130,7 +130,7 @@ func (h *Handler) Init(c *config.Config) { h.deniable = c.EnableDenials h.resharing = resharing(c) - h.resourceInfoCache = cache.GetStatCache(c.ResourceInfoCacheStore, c.ResourceInfoCacheNodes, c.ResourceInfoCacheDatabase, "stat", time.Duration(c.ResourceInfoCacheTTL)*time.Second, c.ResourceInfoCacheSize) + h.statCache = cache.GetStatCache(c.ResourceInfoCacheStore, c.ResourceInfoCacheNodes, c.ResourceInfoCacheDatabase, "stat", time.Duration(c.ResourceInfoCacheTTL)*time.Second, c.ResourceInfoCacheSize) if c.CacheWarmupDriver != "" { cwm, err := getCacheWarmupManager(c) if err == nil { @@ -153,8 +153,8 @@ func (h *Handler) startCacheWarmup(c sharecache.Warmup) { return } for _, r := range infos { - key := h.resourceInfoCache.GetKey(r.Owner, &provider.Reference{ResourceId: r.Id}, []string{}, []string{}) - _ = h.resourceInfoCache.PushToCache(key, r) + key := h.statCache.GetKey(r.Owner, &provider.Reference{ResourceId: r.Id}, []string{}, []string{}) + _ = h.statCache.PushToCache(key, r) } } @@ -769,7 +769,7 @@ func (h *Handler) updateShare(w http.ResponseWriter, r *http.Request, shareID st } if currentUser, ok := ctxpkg.ContextGetUser(ctx); ok { - h.resourceInfoCache.RemoveStat(currentUser.Id, shareR.Share.ResourceId) + h.statCache.RemoveStat(currentUser.Id, shareR.Share.ResourceId) } share, err := conversions.CS3Share2ShareData(ctx, uRes.Share) @@ -1354,10 +1354,10 @@ func (h *Handler) getResourceInfo(ctx context.Context, client gateway.GatewayAPI logger := appctx.GetLogger(ctx) key := "" if currentUser, ok := ctxpkg.ContextGetUser(ctx); ok { - key = h.resourceInfoCache.GetKey(currentUser.Id, ref, []string{}, []string{}) - pinfo := &provider.ResourceInfo{} - if err := h.resourceInfoCache.PullFromCache(key, pinfo); err == nil { - return pinfo, &rpc.Status{Code: rpc.Code_CODE_OK}, nil + key = h.statCache.GetKey(currentUser.Id, ref, []string{}, []string{}) + s := &provider.StatResponse{} + if err := h.statCache.PullFromCache(key, s); err == nil { + return s.Info, &rpc.Status{Code: rpc.Code_CODE_OK}, nil } } @@ -1376,7 +1376,7 @@ func (h *Handler) getResourceInfo(ctx context.Context, client gateway.GatewayAPI } if key != "" { - _ = h.resourceInfoCache.PushToCache(key, *statRes.Info) + _ = h.statCache.PushToCache(key, statRes) } return statRes.Info, statRes.Status, nil diff --git a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go index a435252881..e6089ce1c3 100644 --- a/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go +++ b/internal/http/services/owncloud/ocs/handlers/apps/sharing/shares/user.go @@ -207,7 +207,7 @@ func (h *Handler) removeUserShare(w http.ResponseWriter, r *http.Request, shareI return } if currentUser, ok := ctxpkg.ContextGetUser(ctx); ok { - h.resourceInfoCache.RemoveStat(currentUser.Id, getShareResp.Share.ResourceId) + h.statCache.RemoveStat(currentUser.Id, getShareResp.Share.ResourceId) } response.WriteOCSSuccess(w, r, data) } From 756bd7b10e9476f1486fe1482cd455f579ced372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Duffeck?= Date: Tue, 25 Apr 2023 11:33:07 +0200 Subject: [PATCH 2/2] Add changelog --- changelog/unreleased/fix-statcache-usage.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/unreleased/fix-statcache-usage.md diff --git a/changelog/unreleased/fix-statcache-usage.md b/changelog/unreleased/fix-statcache-usage.md new file mode 100644 index 0000000000..eae9da594d --- /dev/null +++ b/changelog/unreleased/fix-statcache-usage.md @@ -0,0 +1,5 @@ +Bugfix: Fix stat cache access + +We fixed a problem where wrong data was written to and expected from the stat cache. + +https://github.com/cs3org/reva/pull/3814