Skip to content

Commit

Permalink
pipeline cache deletes
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic authored and 2403905 committed May 19, 2023
1 parent fc40054 commit 3cf5e1e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/pipeline-cache-delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Pipeline cache deletes

The gateway now pipelines deleting keys from the stat and provider cache

https://github.com/cs3org/reva/pull/3817
https://github.com/cs3org/reva/pull/3809
19 changes: 11 additions & 8 deletions pkg/storage/cache/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
package cache

import (
"strings"
"sync"
"time"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"go-micro.dev/v4/store"
)

// ProviderCache can invalidate all provider related cache entries
Expand All @@ -47,20 +48,22 @@ func (c providerCache) RemoveListStorageProviders(res *provider.ResourceId) {
if res == nil {
return
}
sid := res.SpaceId

keys, err := c.List()
keys, err := c.List(store.ListSuffix(res.SpaceId), store.ListLimit(100))
if err != nil {
// FIXME log error
return
}
// FIXME add context option to List, Read and Write to upstream

wg := sync.WaitGroup{}
for _, key := range keys {
if strings.Contains(key, sid) {
_ = c.Delete(key)
continue
}
wg.Add(1)
go func(k string) {
defer wg.Done()
_ = c.Delete(k)
}(key)
}
wg.Wait()
}

func (c providerCache) GetKey(userID *userpb.UserId, spaceID string) string {
Expand Down
40 changes: 21 additions & 19 deletions pkg/storage/cache/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ package cache

import (
"strings"
"sync"
"time"

userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"go-micro.dev/v4/store"
)

// NewStatCache creates a new StatCache
Expand All @@ -50,27 +52,27 @@ func (c statCache) RemoveStat(userID *userpb.UserId, res *provider.ResourceId) {
oid = "oid:" + res.OpaqueId
}

keys, err := c.List()
if err != nil {
// FIXME handle error
return
}
for _, key := range keys {
if strings.Contains(key, uid) {
_ = c.Delete(key)
continue
}

if sid != "" && strings.Contains(key, sid) {
_ = c.Delete(key)
continue
}
// TODO currently, invalidating the stat cache is inefficient and should be disabled. Storage providers / drivers can more selectively invalidate stat cache entries.
// This shotgun invalidation wipes all cache entries for the user, space, and nodeid of a changed resource, which means the stat cache is mostly empty, anyway.
prefixes := []string{uid, "*" + sid, "*" + oid}

if oid != "" && strings.Contains(key, oid) {
_ = c.Delete(key)
continue
}
wg := sync.WaitGroup{}
for _, prefix := range prefixes {
wg.Add(1)
go func(p string) {
defer wg.Done()
keys, _ := c.List(store.ListPrefix(p), store.ListLimit(100))
for _, key := range keys {
wg.Add(1)
go func(k string) {
defer wg.Done()
_ = c.Delete(k)
}(key)
}
}(prefix)
}

wg.Wait()
}

// generates a user specific key pointing to ref - used for statcache
Expand Down

0 comments on commit 3cf5e1e

Please sign in to comment.