Skip to content

Commit

Permalink
mo-service: fix default cache configs (#18690)
Browse files Browse the repository at this point in the history
fileservice: do not set default memory and disk config in setDefaults

Approved by: @zhangxu19830126, @sukki37
  • Loading branch information
reusee authored Sep 10, 2024
1 parent 2737645 commit f01f07a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 47 deletions.
44 changes: 38 additions & 6 deletions cmd/mo-service/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ func dumpCommonConfig(cfg Config) (map[string]*logservicepb.ConfigItem, error) {
}

func (c *Config) setFileserviceDefaultValues() {

for i := 0; i < len(c.FileServices); i++ {
config := &c.FileServices[i]

Expand All @@ -605,12 +606,6 @@ func (c *Config) setFileserviceDefaultValues() {
}
}

// set default disk cache dir
if config.Cache.DiskPath == nil {
path := config.DataDir + "-cache"
config.Cache.DiskPath = &path
}

}

// default LOCAL fs
Expand Down Expand Up @@ -664,4 +659,41 @@ func (c *Config) setFileserviceDefaultValues() {
})
}

for i := 0; i < len(c.FileServices); i++ {
config := &c.FileServices[i]

// cache configs
switch config.Name {

case defines.LocalFileServiceName:
// memory
if config.Cache.MemoryCapacity == nil {
capacity := tomlutil.ByteSize(512 * (1 << 20))
config.Cache.MemoryCapacity = &capacity
}
// no disk

case defines.SharedFileServiceName:
// memory
if config.Cache.MemoryCapacity == nil {
capacity := tomlutil.ByteSize(512 * (1 << 20))
config.Cache.MemoryCapacity = &capacity
}
// disk
if config.Cache.DiskPath == nil {
path := config.DataDir + "-cache"
config.Cache.DiskPath = &path
}
if config.Cache.DiskCapacity == nil {
capacity := tomlutil.ByteSize(8 * (1 << 30))
config.Cache.DiskCapacity = &capacity
}

case defines.ETLFileServiceName:
// no caches

}

}

}
17 changes: 0 additions & 17 deletions pkg/fileservice/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,6 @@ type CacheCallbacks struct {
type CacheCallbackFunc = func(fscache.CacheKey, fscache.Data)

func (c *CacheConfig) setDefaults() {
if c.MemoryCapacity == nil {
size := toml.ByteSize(512 << 20)
c.MemoryCapacity = &size
}
if c.DiskCapacity == nil {
size := toml.ByteSize(8 << 30)
c.DiskCapacity = &size
}
if c.DiskMinEvictInterval == nil {
c.DiskMinEvictInterval = &toml.Duration{
Duration: time.Minute * 7,
}
}
if c.DiskEvictTarget == nil {
target := 0.8
c.DiskEvictTarget = &target
}
c.RPC.Adjust()
}

Expand Down
45 changes: 25 additions & 20 deletions pkg/fileservice/local_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (l *LocalFS) AllocateCacheData(size int) fscache.Data {
func (l *LocalFS) initCaches(ctx context.Context, config CacheConfig) error {
config.setDefaults()

// remote
if config.RemoteCacheEnabled {
if config.QueryClient == nil {
return moerr.NewInternalError(ctx, "query client is nil")
Expand All @@ -131,7 +132,9 @@ func (l *LocalFS) initCaches(ctx context.Context, config CacheConfig) error {
)
}

if *config.MemoryCapacity > DisableCacheCapacity { // 1 means disable
// memory
if config.MemoryCapacity != nil &&
*config.MemoryCapacity > DisableCacheCapacity { // 1 means disable
l.memCache = NewMemCache(
fscache.ConstCapacity(int64(*config.MemoryCapacity)),
&config.CacheCallbacks,
Expand All @@ -144,26 +147,28 @@ func (l *LocalFS) initCaches(ctx context.Context, config CacheConfig) error {
)
}

if config.enableDiskCacheForLocalFS {
if *config.DiskCapacity > DisableCacheCapacity && config.DiskPath != nil {
var err error
l.diskCache, err = NewDiskCache(
ctx,
*config.DiskPath,
fscache.ConstCapacity(int64(*config.DiskCapacity)),
l.perfCounterSets,
true,
l.name,
l,
)
if err != nil {
return err
}
logutil.Info("fileservice: disk cache initialized",
zap.Any("fs-name", l.name),
zap.Any("config", config),
)
// disk
if config.enableDiskCacheForLocalFS &&
config.DiskCapacity != nil &&
*config.DiskCapacity > DisableCacheCapacity &&
config.DiskPath != nil {
var err error
l.diskCache, err = NewDiskCache(
ctx,
*config.DiskPath,
fscache.ConstCapacity(int64(*config.DiskCapacity)),
l.perfCounterSets,
true,
l.name,
l,
)
if err != nil {
return err
}
logutil.Info("fileservice: disk cache initialized",
zap.Any("fs-name", l.name),
zap.Any("config", config),
)
}

return nil
Expand Down
4 changes: 3 additions & 1 deletion pkg/fileservice/remote_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/pb/query"
"github.com/matrixorigin/matrixone/pkg/queryservice"
"github.com/matrixorigin/matrixone/pkg/queryservice/client"
"github.com/matrixorigin/matrixone/pkg/util/toml"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -121,7 +122,8 @@ func runTestWithTwoFileServices(t *testing.T, fn func(sf1 *cacheFs, sf2 *cacheFs
KeyRouterFactory: func() client.KeyRouter[query.CacheKey] {
return keyRouter
},
QueryClient: qt,
QueryClient: qt,
MemoryCapacity: ptrTo[toml.ByteSize](1 << 30),
}
cacheCfg.setDefaults()
cacheCfg.SetRemoteCacheCallback()
Expand Down
7 changes: 5 additions & 2 deletions pkg/fileservice/s3_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ func (s *S3FS) initCaches(ctx context.Context, config CacheConfig) error {
}

// memory cache
if *config.MemoryCapacity > DisableCacheCapacity {
if config.MemoryCapacity != nil &&
*config.MemoryCapacity > DisableCacheCapacity {
s.memCache = NewMemCache(
fscache.ConstCapacity(int64(*config.MemoryCapacity)),
&config.CacheCallbacks,
Expand All @@ -164,7 +165,9 @@ func (s *S3FS) initCaches(ctx context.Context, config CacheConfig) error {
}

// disk cache
if *config.DiskCapacity > DisableCacheCapacity && config.DiskPath != nil {
if config.DiskCapacity != nil &&
*config.DiskCapacity > DisableCacheCapacity &&
config.DiskPath != nil {
var err error
s.diskCache, err = NewDiskCache(
ctx,
Expand Down
3 changes: 2 additions & 1 deletion pkg/fileservice/s3_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,8 @@ func TestS3PrefetchFile(t *testing.T) {
RoleARN: config.RoleARN,
},
CacheConfig{
DiskPath: ptrTo(cacheDir),
DiskCapacity: ptrTo[toml.ByteSize](1 << 30),
DiskPath: ptrTo(cacheDir),
},
nil,
false,
Expand Down

0 comments on commit f01f07a

Please sign in to comment.