From 52155a23abb541bfdb744e850ed93a5e88f925b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 4 Apr 2024 17:04:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=86=E7=BE=A4=E8=AE=BE=E7=BD=AE=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=87=AA=E5=8A=A8=E7=A1=AC=E7=9B=98TRIM=E9=80=89?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/configs/db.template.yaml | 2 +- internal/db/models/node_cluster_dao.go | 8 +++++--- internal/db/models/node_cluster_model.go | 3 +++ internal/db/models/node_dao.go | 3 ++- internal/rpc/services/service_node_cluster.go | 5 +++-- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/build/configs/db.template.yaml b/build/configs/db.template.yaml index 2140af8e..5466c621 100644 --- a/build/configs/db.template.yaml +++ b/build/configs/db.template.yaml @@ -12,5 +12,5 @@ dbs: fields: - bool: [ "uamIsOn", "followPort", "requestHostExcludingPort", "autoRemoteStart", "autoInstallNftables", "enableIPLists", "detectAgents", "checkingPorts", "enableRecordHealthCheck", "offlineIsNotified", "http2Enabled", "http3Enabled", "enableHTTP2", "retry50X", "retry40X", "autoSystemTuning", "disableDefaultDB" ] + bool: [ "uamIsOn", "followPort", "requestHostExcludingPort", "autoRemoteStart", "autoInstallNftables", "enableIPLists", "detectAgents", "checkingPorts", "enableRecordHealthCheck", "offlineIsNotified", "http2Enabled", "http3Enabled", "enableHTTP2", "retry50X", "retry40X", "autoSystemTuning", "disableDefaultDB", "autoTrimDisks" ] diff --git a/internal/db/models/node_cluster_dao.go b/internal/db/models/node_cluster_dao.go index 47326e5e..94b216df 100644 --- a/internal/db/models/node_cluster_dao.go +++ b/internal/db/models/node_cluster_dao.go @@ -126,7 +126,7 @@ func (this *NodeClusterDAO) FindAllEnableClusterIds(tx *dbs.Tx) (result []int64, } // CreateCluster 创建集群 -func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string, grantId int64, installDir string, dnsDomainId int64, dnsName string, dnsTTL int32, cachePolicyId int64, httpFirewallPolicyId int64, systemServices map[string]maps.Map, globalServerConfig *serverconfigs.GlobalServerConfig, autoInstallNftables bool, autoSystemTuning bool) (clusterId int64, err error) { +func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string, grantId int64, installDir string, dnsDomainId int64, dnsName string, dnsTTL int32, cachePolicyId int64, httpFirewallPolicyId int64, systemServices map[string]maps.Map, globalServerConfig *serverconfigs.GlobalServerConfig, autoInstallNftables bool, autoSystemTuning bool, autoTrimDisks bool) (clusterId int64, err error) { uniqueId, err := this.GenUniqueId(tx) if err != nil { return 0, err @@ -190,6 +190,7 @@ func (this *NodeClusterDAO) CreateCluster(tx *dbs.Tx, adminId int64, name string op.Secret = secret op.AutoInstallNftables = autoInstallNftables op.AutoSystemTuning = autoSystemTuning + op.AutoTrimDisks = autoTrimDisks op.State = NodeClusterStateEnabled err = this.Save(tx, op) if err != nil { @@ -200,7 +201,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, nodeMaxThreads int32, autoOpenPorts bool, clockConfig *nodeconfigs.ClockConfig, autoRemoteStart bool, autoInstallTables bool, sshParams *nodeconfigs.SSHParams, autoSystemTuning bool) error { +func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name string, grantId int64, installDir string, timezone string, nodeMaxThreads int32, autoOpenPorts bool, clockConfig *nodeconfigs.ClockConfig, autoRemoteStart bool, autoInstallTables bool, sshParams *nodeconfigs.SSHParams, autoSystemTuning bool, autoTrimDisks bool) error { if clusterId <= 0 { return errors.New("invalid clusterId") } @@ -228,6 +229,7 @@ func (this *NodeClusterDAO) UpdateCluster(tx *dbs.Tx, clusterId int64, name stri op.AutoRemoteStart = autoRemoteStart op.AutoInstallNftables = autoInstallTables op.AutoSystemTuning = autoSystemTuning + op.AutoTrimDisks = autoTrimDisks if sshParams != nil { sshParamsJSON, err := json.Marshal(sshParams) @@ -1028,7 +1030,7 @@ func (this *NodeClusterDAO) FindClusterBasicInfo(tx *dbs.Tx, clusterId int64, ca cluster, err := this.Query(tx). Pk(clusterId). State(NodeClusterStateEnabled). - Result("id", "name", "timeZone", "nodeMaxThreads", "cachePolicyId", "httpFirewallPolicyId", "autoOpenPorts", "webp", "uam", "cc", "httpPages", "http3", "isOn", "ddosProtection", "clock", "globalServerConfig", "autoInstallNftables", "autoSystemTuning", "networkSecurity"). + Result("id", "name", "timeZone", "nodeMaxThreads", "cachePolicyId", "httpFirewallPolicyId", "autoOpenPorts", "webp", "uam", "cc", "httpPages", "http3", "isOn", "ddosProtection", "clock", "globalServerConfig", "autoInstallNftables", "autoSystemTuning", "networkSecurity", "autoTrimDisks"). Find() if err != nil || cluster == nil { return nil, err diff --git a/internal/db/models/node_cluster_model.go b/internal/db/models/node_cluster_model.go index 498519b6..c5b66b90 100644 --- a/internal/db/models/node_cluster_model.go +++ b/internal/db/models/node_cluster_model.go @@ -45,6 +45,7 @@ const ( NodeClusterField_Http3 dbs.FieldName = "http3" // HTTP3设置 NodeClusterField_AutoSystemTuning dbs.FieldName = "autoSystemTuning" // 是否自动调整系统参数 NodeClusterField_NetworkSecurity dbs.FieldName = "networkSecurity" // 网络安全策略 + NodeClusterField_AutoTrimDisks dbs.FieldName = "autoTrimDisks" // 是否自动执行TRIM ) // NodeCluster 节点集群 @@ -91,6 +92,7 @@ type NodeCluster struct { Http3 dbs.JSON `field:"http3"` // HTTP3设置 AutoSystemTuning bool `field:"autoSystemTuning"` // 是否自动调整系统参数 NetworkSecurity dbs.JSON `field:"networkSecurity"` // 网络安全策略 + AutoTrimDisks bool `field:"autoTrimDisks"` // 是否自动执行TRIM } type NodeClusterOperator struct { @@ -136,6 +138,7 @@ type NodeClusterOperator struct { Http3 any // HTTP3设置 AutoSystemTuning any // 是否自动调整系统参数 NetworkSecurity any // 网络安全策略 + AutoTrimDisks any // 是否自动执行TRIM } func NewNodeClusterOperator() *NodeClusterOperator { diff --git a/internal/db/models/node_dao.go b/internal/db/models/node_dao.go index 8ea41727..e2814e6e 100644 --- a/internal/db/models/node_dao.go +++ b/internal/db/models/node_dao.go @@ -1244,10 +1244,11 @@ func (this *NodeDAO) ComposeNodeConfig(tx *dbs.Tx, nodeId int64, dataMap *shared } } - // 自动安装nftables + // 自动安装nftables等集群配置 if clusterIndex == 0 { config.AutoInstallNftables = nodeCluster.AutoInstallNftables config.AutoSystemTuning = nodeCluster.AutoSystemTuning + config.AutoTrimDisks = nodeCluster.AutoTrimDisks } // 安全设置 diff --git a/internal/rpc/services/service_node_cluster.go b/internal/rpc/services/service_node_cluster.go index 1a6d98fa..a73b176e 100644 --- a/internal/rpc/services/service_node_cluster.go +++ b/internal/rpc/services/service_node_cluster.go @@ -80,7 +80,7 @@ func (this *NodeClusterService) CreateNodeCluster(ctx context.Context, req *pb.C req.DnsTTL = 0 } - clusterId, err = models.SharedNodeClusterDAO.CreateCluster(tx, adminId, req.Name, req.NodeGrantId, req.InstallDir, req.DnsDomainId, req.DnsName, req.DnsTTL, req.HttpCachePolicyId, req.HttpFirewallPolicyId, systemServices, serverGlobalConfig, req.AutoInstallNftables, req.AutoSystemTuning) + clusterId, err = models.SharedNodeClusterDAO.CreateCluster(tx, adminId, req.Name, req.NodeGrantId, req.InstallDir, req.DnsDomainId, req.DnsName, req.DnsTTL, req.HttpCachePolicyId, req.HttpFirewallPolicyId, systemServices, serverGlobalConfig, req.AutoInstallNftables, req.AutoSystemTuning, req.AutoTrimDisks) if err != nil { return err } @@ -127,7 +127,7 @@ func (this *NodeClusterService) UpdateNodeCluster(ctx context.Context, req *pb.U } } - err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone, req.NodeMaxThreads, req.AutoOpenPorts, clockConfig, req.AutoRemoteStart, req.AutoInstallNftables, sshParams, req.AutoSystemTuning) + err = models.SharedNodeClusterDAO.UpdateCluster(tx, req.NodeClusterId, req.Name, req.NodeGrantId, req.InstallDir, req.TimeZone, req.NodeMaxThreads, req.AutoOpenPorts, clockConfig, req.AutoRemoteStart, req.AutoInstallNftables, sshParams, req.AutoSystemTuning, req.AutoTrimDisks) if err != nil { return nil, err } @@ -234,6 +234,7 @@ func (this *NodeClusterService) FindEnabledNodeCluster(ctx context.Context, req AutoRemoteStart: cluster.AutoRemoteStart, AutoInstallNftables: cluster.AutoInstallNftables, AutoSystemTuning: cluster.AutoSystemTuning, + AutoTrimDisks: cluster.AutoTrimDisks, }}, nil }