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

feat: 禁用缓存持久化时不自动创建目录;提供禁用配置中心的API #198

Merged
merged 2 commits into from
Jul 19, 2024
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
2 changes: 2 additions & 0 deletions pkg/config/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type ConfigFileConfig interface {
BaseConfig
// IsEnable 是否启用配置中心
IsEnable() bool
// SetEnable 设置是否启用配置中心能力
SetEnable(bool)
// GetConfigConnectorConfig 配置文件连接器
GetConfigConnectorConfig() ConfigConnectorConfig
// GetConfigFilterConfig 配置文件加密器
Expand Down
8 changes: 5 additions & 3 deletions plugin/localregistry/common/cache_persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (

// CachePersistHandler 持久化工具类
type CachePersistHandler struct {
persistEnable bool
persistDir string
maxWriteRetry int
maxReadRetry int
Expand All @@ -61,9 +62,10 @@ type CacheFileInfo struct {
}

// NewCachePersistHandler create persistence handler
func NewCachePersistHandler(persistDir string, maxWriteRetry int,
func NewCachePersistHandler(persistEnable bool, persistDir string, maxWriteRetry int,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接添加新的参数,这样不兼容以前的版本,可以改进兼容呢?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个只是插件,不对外暴露,没啥影响

maxReadRetry int, retryInterval time.Duration) (*CachePersistHandler, error) {
handler := &CachePersistHandler{}
handler.persistEnable = persistEnable
handler.persistDir = persistDir
handler.maxReadRetry = maxReadRetry
handler.maxWriteRetry = maxWriteRetry
Expand All @@ -79,8 +81,8 @@ func (cph *CachePersistHandler) init() error {
if nil == cph.marshaler {
cph.marshaler = &jsonpb.Marshaler{}
}
if err := model.EnsureAndVerifyDir(cph.persistDir); err != nil {
return err
if cph.persistEnable {
return model.EnsureAndVerifyDir(cph.persistDir)
}
return nil
}
Expand Down
3 changes: 2 additions & 1 deletion plugin/localregistry/inmemory/inmemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,13 @@ func (g *LocalCache) Init(ctx *plugin.InitContext) error {
g.eventToCacheHandlers[model.EventFaultDetect] = g.newFaultDetectCacheHandler()
// 批量服务
g.eventToCacheHandlers[model.EventServices] = g.newServicesHandler()
g.cacheFromPersistAvailableInterval = ctx.Config.GetConsumer().GetLocalCache().GetPersistAvailableInterval()
g.cachePersistHandler, err = lrplug.NewCachePersistHandler(
g.persistEnable,
g.persistDir,
ctx.Config.GetConsumer().GetLocalCache().GetPersistMaxWriteRetry(),
ctx.Config.GetConsumer().GetLocalCache().GetPersistMaxReadRetry(),
ctx.Config.GetConsumer().GetLocalCache().GetPersistRetryInterval())
g.cacheFromPersistAvailableInterval = ctx.Config.GetConsumer().GetLocalCache().GetPersistAvailableInterval()
if err != nil {
return err
}
Expand Down
Loading