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

Fix statcache usage #3814

Merged
merged 2 commits into from
Apr 25, 2023
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
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-statcache-usage.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down