diff --git a/internal/db/models/node_cluster_dao.go b/internal/db/models/node_cluster_dao.go index f6d998e0..96c17d51 100644 --- a/internal/db/models/node_cluster_dao.go +++ b/internal/db/models/node_cluster_dao.go @@ -178,7 +178,7 @@ func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string } // UpdateCluster 修改集群 -func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string, timezone string) error { +func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string, timezone string, nodeMaxThreads int32, nodeTCPMaxConnections int32) error { if clusterId <= 0 { return errors.New("invalid clusterId") } @@ -188,6 +188,17 @@ func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name stri op.GrantId = grantId op.InstallDir = installDir op.TimeZone = timezone + + if nodeMaxThreads < 0 { + nodeMaxThreads = 0 + } + op.NodeMaxThreads = nodeMaxThreads + + if nodeTCPMaxConnections < 0 { + nodeTCPMaxConnections = 0 + } + op.NodeTCPMaxConnections = nodeTCPMaxConnections + err := this.Save(tx, op) if err != nil { return err @@ -864,27 +875,27 @@ func (this *NodeClusterDAO) ExistsEnabledCluster(tx *dbs.Tx, clusterId int64) (b Exist() } -// FindClusterTimezone 查找时区 -func (this *NodeClusterDAO) FindClusterTimezone(tx *dbs.Tx, clusterId int64, cacheMap *utils.CacheMap) (string, error) { - var cacheKey = this.Table + ":FindEnabledTimeZone:" + types.String(clusterId) +// FindClusterBasicInfo 查找集群基础信息 +func (this *NodeClusterDAO) FindClusterBasicInfo(tx *dbs.Tx, clusterId int64, cacheMap *utils.CacheMap) (*NodeCluster, error) { + var cacheKey = this.Table + ":FindClusterBasicInfo:" + types.String(clusterId) if cacheMap != nil { cache, ok := cacheMap.Get(cacheKey) if ok { - return cache.(string), nil + return cache.(*NodeCluster), nil } } - timeZone, err := this.Query(tx). + cluster, err := this.Query(tx). Pk(clusterId). - Result("timeZone"). - FindStringCol("") - if err != nil { - return "", err + Result("timeZone", "nodeMaxThreads", "nodeTCPMaxConnections", "cachePolicyId", "httpFirewallPolicyId"). + Find() + if err != nil || cluster == nil { + return nil, err } if cacheMap != nil { - cacheMap.Put(cacheKey, timeZone) + cacheMap.Put(cacheKey, cluster) } - return timeZone, nil + return cluster.(*NodeCluster), nil } // NotifyUpdate 通知更新 diff --git a/internal/db/models/node_cluster_model.go b/internal/db/models/node_cluster_model.go index 4d9d79cf..a22c5aa7 100644 --- a/internal/db/models/node_cluster_model.go +++ b/internal/db/models/node_cluster_model.go @@ -2,59 +2,63 @@ package models // NodeCluster 节点集群 type NodeCluster struct { - Id uint32 `field:"id"` // ID - AdminId uint32 `field:"adminId"` // 管理员ID - UserId uint32 `field:"userId"` // 用户ID - IsOn uint8 `field:"isOn"` // 是否启用 - Name string `field:"name"` // 名称 - UseAllAPINodes uint8 `field:"useAllAPINodes"` // 是否使用所有API节点 - ApiNodes string `field:"apiNodes"` // 使用的API节点 - InstallDir string `field:"installDir"` // 安装目录 - Order uint32 `field:"order"` // 排序 - CreatedAt uint64 `field:"createdAt"` // 创建时间 - GrantId uint32 `field:"grantId"` // 默认认证方式 - State uint8 `field:"state"` // 状态 - AutoRegister uint8 `field:"autoRegister"` // 是否开启自动注册 - UniqueId string `field:"uniqueId"` // 唯一ID - Secret string `field:"secret"` // 密钥 - HealthCheck string `field:"healthCheck"` // 健康检查 - DnsName string `field:"dnsName"` // DNS名称 - DnsDomainId uint32 `field:"dnsDomainId"` // 域名ID - Dns string `field:"dns"` // DNS配置 - Toa string `field:"toa"` // TOA配置 - CachePolicyId uint32 `field:"cachePolicyId"` // 缓存策略ID - HttpFirewallPolicyId uint32 `field:"httpFirewallPolicyId"` // WAF策略ID - AccessLog string `field:"accessLog"` // 访问日志设置 - SystemServices string `field:"systemServices"` // 系统服务设置 - TimeZone string `field:"timeZone"` // 时区 + Id uint32 `field:"id"` // ID + AdminId uint32 `field:"adminId"` // 管理员ID + UserId uint32 `field:"userId"` // 用户ID + IsOn uint8 `field:"isOn"` // 是否启用 + Name string `field:"name"` // 名称 + UseAllAPINodes uint8 `field:"useAllAPINodes"` // 是否使用所有API节点 + ApiNodes string `field:"apiNodes"` // 使用的API节点 + InstallDir string `field:"installDir"` // 安装目录 + Order uint32 `field:"order"` // 排序 + CreatedAt uint64 `field:"createdAt"` // 创建时间 + GrantId uint32 `field:"grantId"` // 默认认证方式 + State uint8 `field:"state"` // 状态 + AutoRegister uint8 `field:"autoRegister"` // 是否开启自动注册 + UniqueId string `field:"uniqueId"` // 唯一ID + Secret string `field:"secret"` // 密钥 + HealthCheck string `field:"healthCheck"` // 健康检查 + DnsName string `field:"dnsName"` // DNS名称 + DnsDomainId uint32 `field:"dnsDomainId"` // 域名ID + Dns string `field:"dns"` // DNS配置 + Toa string `field:"toa"` // TOA配置 + CachePolicyId uint32 `field:"cachePolicyId"` // 缓存策略ID + HttpFirewallPolicyId uint32 `field:"httpFirewallPolicyId"` // WAF策略ID + AccessLog string `field:"accessLog"` // 访问日志设置 + SystemServices string `field:"systemServices"` // 系统服务设置 + TimeZone string `field:"timeZone"` // 时区 + NodeMaxThreads uint32 `field:"nodeMaxThreads"` // 节点最大线程数 + NodeTCPMaxConnections uint32 `field:"nodeTCPMaxConnections"` // TCP最大连接数 } type NodeClusterOperator struct { - Id interface{} // ID - AdminId interface{} // 管理员ID - UserId interface{} // 用户ID - IsOn interface{} // 是否启用 - Name interface{} // 名称 - UseAllAPINodes interface{} // 是否使用所有API节点 - ApiNodes interface{} // 使用的API节点 - InstallDir interface{} // 安装目录 - Order interface{} // 排序 - CreatedAt interface{} // 创建时间 - GrantId interface{} // 默认认证方式 - State interface{} // 状态 - AutoRegister interface{} // 是否开启自动注册 - UniqueId interface{} // 唯一ID - Secret interface{} // 密钥 - HealthCheck interface{} // 健康检查 - DnsName interface{} // DNS名称 - DnsDomainId interface{} // 域名ID - Dns interface{} // DNS配置 - Toa interface{} // TOA配置 - CachePolicyId interface{} // 缓存策略ID - HttpFirewallPolicyId interface{} // WAF策略ID - AccessLog interface{} // 访问日志设置 - SystemServices interface{} // 系统服务设置 - TimeZone interface{} // 时区 + Id interface{} // ID + AdminId interface{} // 管理员ID + UserId interface{} // 用户ID + IsOn interface{} // 是否启用 + Name interface{} // 名称 + UseAllAPINodes interface{} // 是否使用所有API节点 + ApiNodes interface{} // 使用的API节点 + InstallDir interface{} // 安装目录 + Order interface{} // 排序 + CreatedAt interface{} // 创建时间 + GrantId interface{} // 默认认证方式 + State interface{} // 状态 + AutoRegister interface{} // 是否开启自动注册 + UniqueId interface{} // 唯一ID + Secret interface{} // 密钥 + HealthCheck interface{} // 健康检查 + DnsName interface{} // DNS名称 + DnsDomainId interface{} // 域名ID + Dns interface{} // DNS配置 + Toa interface{} // TOA配置 + CachePolicyId interface{} // 缓存策略ID + HttpFirewallPolicyId interface{} // WAF策略ID + AccessLog interface{} // 访问日志设置 + SystemServices interface{} // 系统服务设置 + TimeZone interface{} // 时区 + NodeMaxThreads interface{} // 节点最大线程数 + NodeTCPMaxConnections interface{} // TCP最大连接数 } func NewNodeClusterOperator() *NodeClusterOperator { diff --git a/internal/db/models/node_dao.go b/internal/db/models/node_dao.go index 7b4da25d..94f6c230 100644 --- a/internal/db/models/node_dao.go +++ b/internal/db/models/node_dao.go @@ -782,11 +782,17 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils var primaryClusterId = int64(node.ClusterId) var clusterIds = []int64{primaryClusterId} clusterIds = append(clusterIds, node.DecodeSecondaryClusterIds()...) + var clusterIndex = 0 for _, clusterId := range clusterIds { - httpFirewallPolicyId, err := SharedNodeClusterDAO.FindClusterHTTPFirewallPolicyId(tx, clusterId, cacheMap) + nodeCluster, err := SharedNodeClusterDAO.FindClusterBasicInfo(tx, clusterId, cacheMap) if err != nil { return nil, err } + if nodeCluster == nil { + continue + } + + var httpFirewallPolicyId = int64(nodeCluster.HttpFirewallPolicyId) if httpFirewallPolicyId > 0 { firewallPolicy, err := SharedHTTPFirewallPolicyDAO.ComposeFirewallPolicy(tx, httpFirewallPolicyId, cacheMap) if err != nil { @@ -798,10 +804,7 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils } // 缓存策略 - httpCachePolicyId, err := SharedNodeClusterDAO.FindClusterHTTPCachePolicyId(tx, clusterId, cacheMap) - if err != nil { - return nil, err - } + var httpCachePolicyId = int64(nodeCluster.CachePolicyId) if httpCachePolicyId > 0 { cachePolicy, err := SharedHTTPCachePolicyDAO.ComposeCachePolicy(tx, httpCachePolicyId, cacheMap) if err != nil { @@ -813,13 +816,20 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, cacheMap *utils } // 时区 - timeZone, err := SharedNodeClusterDAO.FindClusterTimezone(tx, clusterId, cacheMap) - if err != nil { - return nil, err + if len(config.TimeZone) == 0 { + var timeZone = nodeCluster.TimeZone + if len(timeZone) > 0 { + config.TimeZone = timeZone + } } - if len(timeZone) > 0 { - config.TimeZone = timeZone + + // 最大线程数、TCP连接数 + if clusterIndex == 0 { + config.MaxThreads = int(nodeCluster.NodeMaxThreads) + config.TCPMaxConnections = int(nodeCluster.NodeTCPMaxConnections) } + + clusterIndex++ } // 缓存最大容量设置 diff --git a/internal/rpc/services/service_node_cluster.go b/internal/rpc/services/service_node_cluster.go index 91116e15..77306c11 100644 --- a/internal/rpc/services/service_node_cluster.go +++ b/internal/rpc/services/service_node_cluster.go @@ -83,7 +83,7 @@ func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.U tx := this.NullTx() - err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone) + err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone, req.NodeMaxThreads, req.NodeTCPMaxConnections) if err != nil { return nil, err } @@ -148,19 +148,21 @@ func (this *NodeClusterService) FindEnabledNodeCluster(ctx context.Context, req } return &pb.FindEnabledNodeClusterResponse{NodeCluster: &pb.NodeCluster{ - Id: int64(cluster.Id), - Name: cluster.Name, - CreatedAt: int64(cluster.CreatedAt), - InstallDir: cluster.InstallDir, - NodeGrantId: int64(cluster.GrantId), - UniqueId: cluster.UniqueId, - Secret: cluster.Secret, - HttpCachePolicyId: int64(cluster.CachePolicyId), - HttpFirewallPolicyId: int64(cluster.HttpFirewallPolicyId), - DnsName: cluster.DnsName, - DnsDomainId: int64(cluster.DnsDomainId), - IsOn: cluster.IsOn == 1, - TimeZone: cluster.TimeZone, + Id: int64(cluster.Id), + Name: cluster.Name, + CreatedAt: int64(cluster.CreatedAt), + InstallDir: cluster.InstallDir, + NodeGrantId: int64(cluster.GrantId), + UniqueId: cluster.UniqueId, + Secret: cluster.Secret, + HttpCachePolicyId: int64(cluster.CachePolicyId), + HttpFirewallPolicyId: int64(cluster.HttpFirewallPolicyId), + DnsName: cluster.DnsName, + DnsDomainId: int64(cluster.DnsDomainId), + IsOn: cluster.IsOn == 1, + TimeZone: cluster.TimeZone, + NodeMaxThreads: int32(cluster.NodeMaxThreads), + NodeTCPMaxConnections: int32(cluster.NodeTCPMaxConnections), }}, nil }