Merge pull request #7793 from kobergj/FixNatsjsCache
[full-ci] Use nats-js cache
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
Enhancement: Bump reva
|
||||
|
||||
Bumps reva version
|
||||
|
||||
https://github.com/owncloud/ocis/pull/7793
|
||||
@@ -0,0 +1,5 @@
|
||||
Bugfix: Fix natsjs cache
|
||||
|
||||
The nats-js cache was not working. It paniced and wrote a lot of error logs. Both is fixed now.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/7790
|
||||
@@ -35,7 +35,7 @@ require (
|
||||
github.com/go-micro/plugins/v4/registry/nats v1.2.2-0.20230723205323-1ada01245674
|
||||
github.com/go-micro/plugins/v4/server/grpc v1.2.0
|
||||
github.com/go-micro/plugins/v4/server/http v1.2.2
|
||||
github.com/go-micro/plugins/v4/store/nats-js v1.2.1-0.20230807070816-bc05fb076ce7
|
||||
github.com/go-micro/plugins/v4/store/nats-js v1.2.1-0.20231129143103-d72facc652f0
|
||||
github.com/go-micro/plugins/v4/wrapper/breaker/gobreaker v1.2.0
|
||||
github.com/go-micro/plugins/v4/wrapper/monitoring/prometheus v1.2.0
|
||||
github.com/go-micro/plugins/v4/wrapper/trace/opentelemetry v1.2.0
|
||||
@@ -347,6 +347,4 @@ require (
|
||||
sigs.k8s.io/yaml v1.4.0 // indirect
|
||||
)
|
||||
|
||||
replace github.com/go-micro/plugins/v4/store/nats-js => github.com/kobergj/plugins/v4/store/nats-js v1.2.1-0.20231020092801-9463c820c19a
|
||||
|
||||
replace github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348
|
||||
|
||||
@@ -1213,6 +1213,8 @@ github.com/go-micro/plugins/v4/server/grpc v1.2.0 h1:lXfM+/0oE/u1g0hVBYsvbP4lYOY
|
||||
github.com/go-micro/plugins/v4/server/grpc v1.2.0/go.mod h1:+Ah9Pf/vMSXxBM3fup/hc3N+zN2as3nIpcRaR4sBjnY=
|
||||
github.com/go-micro/plugins/v4/server/http v1.2.2 h1:UK2/09AU0zV3wHELuR72TZzVU2vTUhbx9qrRGrQSIWg=
|
||||
github.com/go-micro/plugins/v4/server/http v1.2.2/go.mod h1:YuAjaSPxcn3LI8j2FUsqx0Rxunrj4YwDV41Ax76rLl0=
|
||||
github.com/go-micro/plugins/v4/store/nats-js v1.2.1-0.20231129143103-d72facc652f0 h1:Qa1EBQ9UyCGecFAJQovl/MHGnvbcvDaM3qUoAG5Lnvk=
|
||||
github.com/go-micro/plugins/v4/store/nats-js v1.2.1-0.20231129143103-d72facc652f0/go.mod h1:aCRl8JQmqIaonOl88nFPY/BOQnHPVHY9ngStzLkXnYk=
|
||||
github.com/go-micro/plugins/v4/store/redis v1.2.1-0.20230510195111-07cd57e1bc9d h1:HQoDDVyMfdkrgXNo03ZY4vzhoOXMDZVZ4SnpBDVID6E=
|
||||
github.com/go-micro/plugins/v4/store/redis v1.2.1-0.20230510195111-07cd57e1bc9d/go.mod h1:MbCG0YiyPqETTtm7uHFmxQNCaW1o9hBoYtFwhbVjLUg=
|
||||
github.com/go-micro/plugins/v4/transport/grpc v1.1.0 h1:mXfDYfFQLnVDzjGY3o84oe4prfux9h8txsnA19dKsj8=
|
||||
@@ -1593,8 +1595,6 @@ github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.1.0 h1:eyi1Ad2aNJMW95zcSbmGg7Cg6cq3ADwLpMAP96d8rF0=
|
||||
github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
||||
github.com/kobergj/plugins/v4/store/nats-js v1.2.1-0.20231020092801-9463c820c19a h1:W+itvdTLFGLuFh+E5IzW08n2BS02cHK91qnMo7SUxbA=
|
||||
github.com/kobergj/plugins/v4/store/nats-js v1.2.1-0.20231020092801-9463c820c19a/go.mod h1:wt51O2yNmgF/F7E00IYIH0awseRGqtnmjZGn6RjbZSk=
|
||||
github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348 h1:Czv6AW9Suj6npWd5BLZjobdD78c2RdzBeKBgkq3jYZk=
|
||||
github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348/go.mod h1:Goi4eJ9SrKkxE6NsAVqBVNxfQFbwb7UbyII6743ldgM=
|
||||
github.com/kolo/xmlrpc v0.0.0-20200310150728-e0350524596b/go.mod h1:o03bZfuBwAXHetKXuInt4S7omeXUu62/A845kiycsSQ=
|
||||
|
||||
@@ -64,6 +64,8 @@ import (
|
||||
var (
|
||||
// runset keeps track of which services to start supervised.
|
||||
runset map[string]struct{}
|
||||
// time to wait after starting the preliminary services
|
||||
_preliminaryDelay = 6 * time.Second
|
||||
// time to wait between starting service groups (preliminary, main, delayed)
|
||||
_startDelay = 2 * time.Second
|
||||
)
|
||||
@@ -413,8 +415,8 @@ func Start(o ...Option) error {
|
||||
// trap will block on halt channel for interruptions.
|
||||
go trap(s, halt)
|
||||
|
||||
// grace period for supervisor to get up
|
||||
time.Sleep(_startDelay)
|
||||
// grace period for preliminary services to get up
|
||||
time.Sleep(_preliminaryDelay)
|
||||
|
||||
// schedule services that we are sure don't have interdependencies.
|
||||
scheduleServiceTokens(s, s.ServicesRegistry)
|
||||
|
||||
@@ -111,8 +111,9 @@ func DefaultConfig() *config.Config {
|
||||
SharePrefix: "/Shares",
|
||||
HomeNamespace: "/users/{{.Id.OpaqueId}}",
|
||||
AdditionalInfoAttribute: "{{.Mail}}",
|
||||
StatCacheType: "noop",
|
||||
StatCacheDatabase: "ocis",
|
||||
StatCacheType: "memory",
|
||||
StatCacheNodes: []string{"127.0.0.1:9233"},
|
||||
StatCacheDatabase: "cache-stat",
|
||||
StatCacheTTL: 300 * time.Second,
|
||||
ListOCMShares: true,
|
||||
PublicShareMustHavePassword: true,
|
||||
|
||||
@@ -85,7 +85,7 @@ type StorageRegistry struct {
|
||||
|
||||
// Cache holds cache config
|
||||
type Cache struct {
|
||||
StatCacheStore string `yaml:"stat_cache_store" env:"OCIS_CACHE_STORE;GATEWAY_STAT_CACHE_STORE" desc:"The type of the cache store. Supported values are: 'memory', 'ocmem', 'etcd', 'redis', 'redis-sentinel', 'nats-js', 'noop'. See the text description for details."`
|
||||
StatCacheStore string // NOTE: The stat cache is not working atm. Hence we block configuring it
|
||||
StatCacheNodes []string `yaml:"stat_cache_nodes" env:"OCIS_CACHE_STORE_NODES;GATEWAY_STAT_CACHE_STORE_NODES" desc:"A list of nodes to access the configured store. This has no effect when 'memory' or 'ocmem' stores are configured. Note that the behaviour how nodes are used is dependent on the library of the configured store. See the Environment Variable Types description for more details."`
|
||||
StatCacheDatabase string `yaml:"stat_cache_database" env:"OCIS_CACHE_DATABASE" desc:"The database name the configured store should use."`
|
||||
StatCacheTTL time.Duration `yaml:"stat_cache_ttl" env:"OCIS_CACHE_TTL;GATEWAY_STAT_CACHE_TTL" desc:"Default time to live for user info in the cache. Only applied when access tokens has no expiration. See the Environment Variable Types description for more details."`
|
||||
|
||||
@@ -39,14 +39,17 @@ func DefaultConfig() *config.Config {
|
||||
DisableHomeCreationOnLogin: true,
|
||||
TransferExpires: 24 * 60 * 60,
|
||||
Cache: config.Cache{
|
||||
StatCacheStore: "noop",
|
||||
StatCacheStore: "noop", // NOTE: stat cache not working
|
||||
StatCacheDatabase: "ocis",
|
||||
StatCacheNodes: []string{"127.0.0.1:9233"},
|
||||
StatCacheTTL: 300 * time.Second,
|
||||
ProviderCacheStore: "noop",
|
||||
ProviderCacheDatabase: "ocis",
|
||||
ProviderCacheNodes: []string{"127.0.0.1:9233"},
|
||||
ProviderCacheDatabase: "cache-providers",
|
||||
ProviderCacheTTL: 300 * time.Second,
|
||||
CreateHomeCacheStore: "noop",
|
||||
CreateHomeCacheDatabase: "ocis",
|
||||
CreateHomeCacheStore: "memory",
|
||||
CreateHomeCacheNodes: []string{"127.0.0.1:9233"},
|
||||
CreateHomeCacheDatabase: "cache-createhome",
|
||||
CreateHomeCacheTTL: 300 * time.Second,
|
||||
},
|
||||
|
||||
|
||||
@@ -97,8 +97,8 @@ func DefaultConfig() *config.Config {
|
||||
},
|
||||
Cache: &config.Cache{
|
||||
Store: "memory",
|
||||
Database: "ocis",
|
||||
Table: "roles",
|
||||
Nodes: []string{"127.0.0.1:9233"},
|
||||
Database: "cache-roles",
|
||||
TTL: time.Hour * 336,
|
||||
},
|
||||
Events: config.Events{
|
||||
|
||||
@@ -44,8 +44,8 @@ func DefaultConfig() *config.Config {
|
||||
SkipUserInfo: false,
|
||||
UserinfoCache: &config.Cache{
|
||||
Store: "memory",
|
||||
Database: "ocis",
|
||||
Table: "userinfo",
|
||||
Nodes: []string{"127.0.0.1:9233"},
|
||||
Database: "cache-userinfo",
|
||||
TTL: time.Second * 10,
|
||||
},
|
||||
JWKS: config.JWKS{
|
||||
|
||||
@@ -58,7 +58,8 @@ func DefaultConfig() *config.Config {
|
||||
SystemUserIDP: "internal",
|
||||
Cache: &config.Cache{
|
||||
Store: "memory",
|
||||
Database: "ocis",
|
||||
Nodes: []string{"127.0.0.1:9233"},
|
||||
Database: "settings-cache",
|
||||
FileTable: "settings_files",
|
||||
DirectoryTable: "settings_dirs",
|
||||
TTL: time.Minute * 10,
|
||||
|
||||
@@ -53,7 +53,8 @@ func DefaultConfig() *config.Config {
|
||||
},
|
||||
FileMetadataCache: config.Cache{
|
||||
Store: "memory",
|
||||
Database: "ocis",
|
||||
Nodes: []string{"127.0.0.1:9233"},
|
||||
Database: "storage-system",
|
||||
TTL: 24 * 60 * time.Second,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -94,13 +94,21 @@ func DefaultConfig() *config.Config {
|
||||
EnableTLS: false,
|
||||
},
|
||||
StatCache: config.StatCache{
|
||||
Store: "noop",
|
||||
Store: "memory",
|
||||
Nodes: []string{"127.0.0.1:9233"},
|
||||
Database: "ocis",
|
||||
TTL: 300 * time.Second,
|
||||
},
|
||||
FilemetadataCache: config.FilemetadataCache{
|
||||
Store: "memory",
|
||||
Database: "ocis",
|
||||
Nodes: []string{"127.0.0.1:9233"},
|
||||
Database: "storage-users",
|
||||
TTL: 24 * 60 * time.Second,
|
||||
},
|
||||
IDCache: config.IDCache{
|
||||
Store: "memory",
|
||||
Nodes: []string{"127.0.0.1:9233"},
|
||||
Database: "ids-storage-users",
|
||||
TTL: 24 * 60 * time.Second,
|
||||
},
|
||||
Tasks: config.Tasks{
|
||||
|
||||
@@ -128,7 +128,7 @@ func WaitForConnection() bool {
|
||||
Transport: transport,
|
||||
}
|
||||
|
||||
req, _ := http.NewRequest("GET", config.Get("url")+"/graph/v1.0/users/"+config.Get("adminUsername"), nil)
|
||||
req, _ := http.NewRequest("GET", config.Get("url")+"/graph/v1.0/me/drives", nil)
|
||||
req.SetBasicAuth(config.Get("adminUsername"), config.Get("adminPassword"))
|
||||
|
||||
timeout := time.After(timeoutValue)
|
||||
|
||||
+14
-16
@@ -9,6 +9,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cornelk/hashmap"
|
||||
"github.com/nats-io/nats.go"
|
||||
"github.com/pkg/errors"
|
||||
"go-micro.dev/v4/store"
|
||||
@@ -34,7 +35,7 @@ type natsStore struct {
|
||||
|
||||
conn *nats.Conn
|
||||
js nats.JetStreamContext
|
||||
buckets *sync.Map
|
||||
buckets *hashmap.Map[string, nats.ObjectStore]
|
||||
}
|
||||
|
||||
func init() {
|
||||
@@ -55,7 +56,7 @@ func NewStore(opts ...store.Option) store.Store {
|
||||
opts: options,
|
||||
jsopts: []nats.JSOpt{},
|
||||
objStoreConfigs: []*nats.ObjectStoreConfig{},
|
||||
buckets: &sync.Map{},
|
||||
buckets: hashmap.New[string, nats.ObjectStore](),
|
||||
storageType: nats.FileStorage,
|
||||
}
|
||||
|
||||
@@ -103,7 +104,7 @@ func (n *natsStore) Init(opts ...store.Option) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Failed to create bucket (%s)", cfg.Bucket)
|
||||
}
|
||||
n.buckets.Store(cfg.Bucket, store)
|
||||
n.buckets.Set(cfg.Bucket, store)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -178,11 +179,10 @@ func (n *natsStore) Read(key string, opts ...store.ReadOption) ([]*store.Record,
|
||||
opt.Table = n.opts.Table
|
||||
}
|
||||
|
||||
b, ok := n.buckets.Load(opt.Database)
|
||||
bucket, ok := n.buckets.Get(opt.Database)
|
||||
if !ok {
|
||||
return nil, ErrBucketNotFound
|
||||
}
|
||||
bucket := b.(nats.ObjectStore)
|
||||
|
||||
var keys []string
|
||||
|
||||
@@ -292,8 +292,7 @@ func (n *natsStore) Write(r *store.Record, opts ...store.WriteOption) error {
|
||||
opt.Table = n.opts.Table
|
||||
}
|
||||
|
||||
s, ok := n.buckets.Load(opt.Database)
|
||||
store, _ := s.(nats.ObjectStore)
|
||||
store, ok := n.buckets.Get(opt.Database)
|
||||
// Create new bucket if not exists
|
||||
if !ok {
|
||||
var err error
|
||||
@@ -345,19 +344,18 @@ func (n *natsStore) Delete(key string, opts ...store.DeleteOption) error {
|
||||
}
|
||||
|
||||
if opt.Table == "DELETE_BUCKET" {
|
||||
n.buckets.Delete(key)
|
||||
n.buckets.Del(key)
|
||||
if err := n.js.DeleteObjectStore(key); err != nil {
|
||||
return errors.Wrap(err, "Failed to delete bucket")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
s, ok := n.buckets.Load(opt.Database)
|
||||
store, ok := n.buckets.Get(opt.Database)
|
||||
if !ok {
|
||||
return ErrBucketNotFound
|
||||
}
|
||||
|
||||
store := s.(nats.ObjectStore)
|
||||
if err := store.Delete(getKey(key, opt.Table)); err != nil {
|
||||
return errors.Wrap(err, "Failed to delete data")
|
||||
}
|
||||
@@ -383,11 +381,10 @@ func (n *natsStore) List(opts ...store.ListOption) ([]string, error) {
|
||||
opt.Table = n.opts.Table
|
||||
}
|
||||
|
||||
s, ok := n.buckets.Load(opt.Database)
|
||||
store, ok := n.buckets.Get(opt.Database)
|
||||
if !ok {
|
||||
return nil, ErrBucketNotFound
|
||||
}
|
||||
store := s.(nats.ObjectStore)
|
||||
|
||||
objects, err := store.List()
|
||||
if err != nil {
|
||||
@@ -405,13 +402,14 @@ func (n *natsStore) List(opts ...store.ListOption) ([]string, error) {
|
||||
if !strings.HasSuffix(key, opt.Suffix) {
|
||||
continue
|
||||
}
|
||||
keys = append(keys, key)
|
||||
|
||||
keys = append(keys, strings.TrimPrefix(key, getKey(opt.Prefix, opt.Table)))
|
||||
}
|
||||
|
||||
if opt.Limit > 0 {
|
||||
if opt.Limit > 0 && int(opt.Offset+opt.Limit) < len(keys) {
|
||||
return keys[opt.Offset : opt.Offset+opt.Limit], nil
|
||||
}
|
||||
if opt.Offset > 0 {
|
||||
if opt.Offset > 0 && int(opt.Offset) < len(keys) {
|
||||
return keys[opt.Offset:], nil
|
||||
}
|
||||
return keys, nil
|
||||
@@ -448,7 +446,7 @@ func (n *natsStore) createNewBucket(name string) (nats.ObjectStore, error) {
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "Failed to create new bucket (%s)", name)
|
||||
}
|
||||
n.buckets.Store(name, store)
|
||||
n.buckets.Set(name, store)
|
||||
return store, err
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-3
@@ -937,8 +937,8 @@ github.com/go-micro/plugins/v4/server/grpc
|
||||
# github.com/go-micro/plugins/v4/server/http v1.2.2
|
||||
## explicit; go 1.17
|
||||
github.com/go-micro/plugins/v4/server/http
|
||||
# github.com/go-micro/plugins/v4/store/nats-js v1.2.1-0.20230807070816-bc05fb076ce7 => github.com/kobergj/plugins/v4/store/nats-js v1.2.1-0.20231020092801-9463c820c19a
|
||||
## explicit; go 1.17
|
||||
# github.com/go-micro/plugins/v4/store/nats-js v1.2.1-0.20231129143103-d72facc652f0
|
||||
## explicit; go 1.21
|
||||
github.com/go-micro/plugins/v4/store/nats-js
|
||||
# github.com/go-micro/plugins/v4/store/nats-js-kv v0.0.0-00010101000000-000000000000 => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348
|
||||
## explicit; go 1.21
|
||||
@@ -2297,5 +2297,4 @@ stash.kopano.io/kgol/oidc-go
|
||||
# stash.kopano.io/kgol/rndm v1.1.2
|
||||
## explicit; go 1.13
|
||||
stash.kopano.io/kgol/rndm
|
||||
# github.com/go-micro/plugins/v4/store/nats-js => github.com/kobergj/plugins/v4/store/nats-js v1.2.1-0.20231020092801-9463c820c19a
|
||||
# github.com/go-micro/plugins/v4/store/nats-js-kv => github.com/kobergj/plugins/v4/store/nats-js-kv v0.0.0-20231207143248-4d424e3ae348
|
||||
|
||||
Reference in New Issue
Block a user