边缘节点支持设置多个缓存目录

This commit is contained in:
刘祥超
2022-11-15 20:35:59 +08:00
parent 181a4d05b0
commit feb1068441
4 changed files with 43 additions and 5 deletions

View File

@@ -1146,6 +1146,7 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils
}
config.CacheDiskDir = node.CacheDiskDir
config.CacheDiskSubDirs = node.DecodeCacheDiskSubDirs()
// TOA
toaConfig, err := SharedNodeClusterDAO.FindClusterTOAConfig(tx, primaryClusterId, cacheMap)
@@ -1621,7 +1622,7 @@ func (this *NodeDAO) UpdateNodeSystem(tx *dbs.Tx, nodeId int64, maxCPU int32) er
}
// UpdateNodeCache 设置缓存相关
func (this *NodeDAO) UpdateNodeCache(tx *dbs.Tx, nodeId int64, maxCacheDiskCapacityJSON []byte, maxCacheMemoryCapacityJSON []byte, cacheDiskDir string) error {
func (this *NodeDAO) UpdateNodeCache(tx *dbs.Tx, nodeId int64, maxCacheDiskCapacityJSON []byte, maxCacheMemoryCapacityJSON []byte, cacheDiskDir string, cacheDiskSubDirs []*serverconfigs.CacheDir) error {
if nodeId <= 0 {
return errors.New("invalid nodeId")
}
@@ -1634,7 +1635,17 @@ func (this *NodeDAO) UpdateNodeCache(tx *dbs.Tx, nodeId int64, maxCacheDiskCapac
op.MaxCacheMemoryCapacity = maxCacheMemoryCapacityJSON
}
op.CacheDiskDir = cacheDiskDir
err := this.Save(tx, op)
if cacheDiskSubDirs == nil {
cacheDiskSubDirs = []*serverconfigs.CacheDir{}
}
cacheDiskSubDirsJSON, err := json.Marshal(cacheDiskSubDirs)
if err != nil {
return err
}
op.CacheDiskSubDirs = cacheDiskSubDirsJSON
err = this.Save(tx, op)
if err != nil {
return err
}

View File

@@ -38,7 +38,8 @@ type Node struct {
DnsRoutes dbs.JSON `field:"dnsRoutes"` // DNS线路设置
MaxCacheDiskCapacity dbs.JSON `field:"maxCacheDiskCapacity"` // 硬盘缓存容量
MaxCacheMemoryCapacity dbs.JSON `field:"maxCacheMemoryCapacity"` // 内存缓存容量
CacheDiskDir string `field:"cacheDiskDir"` // 缓存目录
CacheDiskDir string `field:"cacheDiskDir"` // 缓存目录
CacheDiskSubDirs dbs.JSON `field:"cacheDiskSubDirs"` // 其他缓存目录
DnsResolver dbs.JSON `field:"dnsResolver"` // DNS解析器
EnableIPLists bool `field:"enableIPLists"` // 启用IP名单
}
@@ -78,7 +79,8 @@ type NodeOperator struct {
DnsRoutes any // DNS线路设置
MaxCacheDiskCapacity any // 硬盘缓存容量
MaxCacheMemoryCapacity any // 内存缓存容量
CacheDiskDir any // 缓存目录
CacheDiskDir any // 缓存目录
CacheDiskSubDirs any // 其他缓存目录
DnsResolver any // DNS解析器
EnableIPLists any // 启用IP名单
}

View File

@@ -2,7 +2,9 @@ package models
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/ddosconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"sort"
@@ -181,3 +183,16 @@ func (this *Node) DecodeLnAddrs() []string {
}
return result
}
func (this *Node) DecodeCacheDiskSubDirs() []*serverconfigs.CacheDir {
if IsNull(this.CacheDiskSubDirs) {
return nil
}
var result = []*serverconfigs.CacheDir{}
err := json.Unmarshal(this.CacheDiskSubDirs, &result)
if err != nil {
remotelogs.Error("Node.DecodeCacheDiskSubDirs", err.Error())
}
return result
}

View File

@@ -673,6 +673,7 @@ func (this *NodeService) FindEnabledNode(ctx context.Context, req *pb.FindEnable
MaxCacheDiskCapacity: pbMaxCacheDiskCapacity,
MaxCacheMemoryCapacity: pbMaxCacheMemoryCapacity,
CacheDiskDir: node.CacheDiskDir,
CacheDiskSubDirsJSON: node.CacheDiskSubDirs,
Level: int32(node.Level),
LnAddrs: node.DecodeLnAddrs(),
DnsRoutes: pbRoutes,
@@ -1708,7 +1709,16 @@ func (this *NodeService) UpdateNodeCache(ctx context.Context, req *pb.UpdateNode
}
}
err = models.SharedNodeDAO.UpdateNodeCache(tx, req.NodeId, maxCacheDiskCapacityJSON, maxCacheMemoryCapacityJSON, req.CacheDiskDir)
// cache sub dirs
var cacheSubDirs = []*serverconfigs.CacheDir{}
if len(req.CacheDiskSubDirsJSON) > 0 {
err = json.Unmarshal(req.CacheDiskSubDirsJSON, &cacheSubDirs)
if err != nil {
return nil, errors.New("decode 'cacheDiskSubDirsJSON' failed: " + err.Error())
}
}
err = models.SharedNodeDAO.UpdateNodeCache(tx, req.NodeId, maxCacheDiskCapacityJSON, maxCacheMemoryCapacityJSON, req.CacheDiskDir, cacheSubDirs)
if err != nil {
return nil, err
}