[full-ci] More cache cleanup (#6134)
* Make env var names consistent with the others * Remove unused OCS cache * Use the same cache database for shared caches * Bump reva
This commit is contained in:
Generated
Vendored
+10
-10
@@ -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
|
||||
|
||||
Generated
Vendored
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
+107
-41
@@ -1,15 +1,24 @@
|
||||
// Package redis is a redis backed store implementation
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
log "go-micro.dev/v4/logger"
|
||||
"go-micro.dev/v4/logger"
|
||||
"go-micro.dev/v4/store"
|
||||
"go-micro.dev/v4/util/cmd"
|
||||
)
|
||||
|
||||
// DefaultDatabase is the namespace that the store
|
||||
// will use if no namespace is provided.
|
||||
var (
|
||||
DefaultDatabase = "micro"
|
||||
DefaultTable = "micro"
|
||||
)
|
||||
|
||||
type rkv struct {
|
||||
ctx context.Context
|
||||
options store.Options
|
||||
@@ -33,8 +42,9 @@ func (r *rkv) Close() error {
|
||||
}
|
||||
|
||||
func (r *rkv) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) {
|
||||
options := store.ReadOptions{}
|
||||
options.Table = r.options.Table
|
||||
options := store.ReadOptions{
|
||||
Table: r.options.Table,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
@@ -42,40 +52,57 @@ func (r *rkv) Read(key string, opts ...store.ReadOption) ([]*store.Record, error
|
||||
|
||||
var keys []string
|
||||
|
||||
rkey := fmt.Sprintf("%s%s", options.Table, key)
|
||||
// Handle Prefix
|
||||
// TODO suffix
|
||||
if options.Prefix {
|
||||
prefixKey := fmt.Sprintf("%s*", rkey)
|
||||
fkeys, err := r.Client.Keys(r.ctx, prefixKey).Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// TODO Limit Offset
|
||||
var rkey string
|
||||
|
||||
keys = append(keys, fkeys...)
|
||||
} else {
|
||||
keys = []string{rkey}
|
||||
switch {
|
||||
case options.Prefix:
|
||||
rkey = fmt.Sprintf("%s%s*", options.Table, key)
|
||||
case options.Suffix:
|
||||
rkey = fmt.Sprintf("%s*%s", options.Table, key)
|
||||
default:
|
||||
keys = []string{fmt.Sprintf("%s%s", options.Table, key)}
|
||||
}
|
||||
|
||||
if len(keys) == 0 {
|
||||
cursor := uint64(options.Offset)
|
||||
count := int64(options.Limit)
|
||||
|
||||
for {
|
||||
var err error
|
||||
|
||||
var ks []string
|
||||
|
||||
ks, cursor, err = r.Client.Scan(r.ctx, cursor, rkey, count).Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
keys = append(keys, ks...)
|
||||
|
||||
if cursor == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
records := make([]*store.Record, 0, len(keys))
|
||||
|
||||
// read all keys, continue on error
|
||||
var val []byte
|
||||
|
||||
var d time.Duration
|
||||
|
||||
var err error
|
||||
|
||||
for _, rkey = range keys {
|
||||
val, err := r.Client.Get(r.ctx, rkey).Bytes()
|
||||
|
||||
if err != nil && err == redis.Nil {
|
||||
return nil, store.ErrNotFound
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
val, err = r.Client.Get(r.ctx, rkey).Bytes()
|
||||
if err != nil || val == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if val == nil {
|
||||
return nil, store.ErrNotFound
|
||||
}
|
||||
|
||||
d, err := r.Client.TTL(r.ctx, rkey).Result()
|
||||
d, err = r.Client.TTL(r.ctx, rkey).Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
continue
|
||||
}
|
||||
|
||||
records = append(records, &store.Record{
|
||||
@@ -85,47 +112,77 @@ func (r *rkv) Read(key string, opts ...store.ReadOption) ([]*store.Record, error
|
||||
})
|
||||
}
|
||||
|
||||
if len(keys) == 1 {
|
||||
return records, err
|
||||
}
|
||||
|
||||
// keys might have vanished since we scanned them, ignore errors
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func (r *rkv) Delete(key string, opts ...store.DeleteOption) error {
|
||||
options := store.DeleteOptions{}
|
||||
options.Table = r.options.Table
|
||||
options := store.DeleteOptions{
|
||||
Table: r.options.Table,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
rkey := fmt.Sprintf("%s%s", options.Table, key)
|
||||
|
||||
return r.Client.Del(r.ctx, rkey).Err()
|
||||
}
|
||||
|
||||
func (r *rkv) Write(record *store.Record, opts ...store.WriteOption) error {
|
||||
options := store.WriteOptions{}
|
||||
options.Table = r.options.Table
|
||||
options := store.WriteOptions{
|
||||
Table: r.options.Table,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
rkey := fmt.Sprintf("%s%s", options.Table, record.Key)
|
||||
|
||||
return r.Client.Set(r.ctx, rkey, record.Value, record.Expiry).Err()
|
||||
}
|
||||
|
||||
func (r *rkv) List(opts ...store.ListOption) ([]string, error) {
|
||||
options := store.ListOptions{}
|
||||
options.Table = r.options.Table
|
||||
options := store.ListOptions{
|
||||
Table: r.options.Table,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
keys, err := r.Client.Keys(r.ctx, "*").Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
key := fmt.Sprintf("%s%s*%s", options.Table, options.Prefix, options.Suffix)
|
||||
|
||||
cursor := uint64(options.Offset)
|
||||
|
||||
count := int64(options.Limit)
|
||||
|
||||
var allKeys []string
|
||||
|
||||
var keys []string
|
||||
|
||||
var err error
|
||||
|
||||
for {
|
||||
keys, cursor, err = r.Client.Scan(r.ctx, cursor, key, count).Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
allKeys = append(allKeys, keys...)
|
||||
|
||||
if cursor == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return keys, nil
|
||||
return allKeys, nil
|
||||
}
|
||||
|
||||
func (r *rkv) Options() store.Options {
|
||||
@@ -136,8 +193,14 @@ func (r *rkv) String() string {
|
||||
return "redis"
|
||||
}
|
||||
|
||||
// NewStore returns a redis store.
|
||||
func NewStore(opts ...store.Option) store.Store {
|
||||
var options store.Options
|
||||
options := store.Options{
|
||||
Database: DefaultDatabase,
|
||||
Table: DefaultTable,
|
||||
Logger: logger.DefaultLogger,
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
@@ -148,7 +211,7 @@ func NewStore(opts ...store.Option) store.Store {
|
||||
}
|
||||
|
||||
if err := s.configure(); err != nil {
|
||||
log.Fatal(err)
|
||||
s.options.Logger.Log(logger.ErrorLevel, "Error configuring store ", err)
|
||||
}
|
||||
|
||||
return s
|
||||
@@ -156,8 +219,11 @@ func NewStore(opts ...store.Option) store.Store {
|
||||
|
||||
func (r *rkv) configure() error {
|
||||
if r.Client != nil {
|
||||
r.Client.Close()
|
||||
if err := r.Client.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
r.Client = newUniversalClient(r.options)
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user