v1.5.1 增强程序稳定性
This commit is contained in:
@@ -49,11 +49,17 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
var sharedNodeConfig *nodeconfigs.NodeConfig
|
||||
var sharedNodeConfig atomic.Pointer[nodeconfigs.NodeConfig]
|
||||
|
||||
// nodeConfig 返回当前节点配置(并发安全)
|
||||
func nodeConfig() *nodeconfigs.NodeConfig {
|
||||
return sharedNodeConfig.Load()
|
||||
}
|
||||
var nodeTaskNotify = make(chan bool, 8)
|
||||
var nodeConfigChangedNotify = make(chan bool, 8)
|
||||
var nodeConfigUpdatedAt int64
|
||||
@@ -63,7 +69,7 @@ var nodeInstance *Node
|
||||
|
||||
// Node 节点
|
||||
type Node struct {
|
||||
isLoaded bool
|
||||
isLoaded atomic.Bool
|
||||
sock *gosock.Sock
|
||||
locker sync.Mutex
|
||||
|
||||
@@ -200,11 +206,13 @@ func (this *Node) Start() {
|
||||
remotelogs.ServerError(serverErr.Id, "NODE", serverErr.Message, nodeconfigs.NodeLogTypeServerConfigInitFailed, maps.Map{})
|
||||
}
|
||||
}
|
||||
sharedNodeConfig = nodeConfig
|
||||
sharedNodeConfig.Store(nodeConfig)
|
||||
this.onReload(nodeConfig, true)
|
||||
|
||||
// 调整系统参数
|
||||
go this.tuneSystemParameters()
|
||||
goman.New(func() {
|
||||
this.tuneSystemParameters()
|
||||
})
|
||||
|
||||
// 发送事件
|
||||
events.Notify(events.EventLoaded)
|
||||
@@ -406,7 +414,7 @@ func (this *Node) syncConfig(taskVersion int64) error {
|
||||
}
|
||||
|
||||
// 刷新配置
|
||||
if this.isLoaded {
|
||||
if this.isLoaded.Load() {
|
||||
remotelogs.Println("NODE", "reloading node config ...")
|
||||
} else {
|
||||
remotelogs.Println("NODE", "loading node config ...")
|
||||
@@ -417,11 +425,11 @@ func (this *Node) syncConfig(taskVersion int64) error {
|
||||
// 发送事件
|
||||
events.Notify(events.EventReload)
|
||||
|
||||
if this.isLoaded {
|
||||
if this.isLoaded.Load() {
|
||||
return sharedListenerManager.Start(nodeConfig)
|
||||
}
|
||||
|
||||
this.isLoaded = true
|
||||
this.isLoaded.Store(true)
|
||||
|
||||
// 预创建本地日志目录与空文件,便于 Fluent Bit 立即 tail,无需等首条访问日志
|
||||
_ = accesslogs.SharedFileWriter().EnsureInit()
|
||||
@@ -885,7 +893,7 @@ func (this *Node) listenSock() error {
|
||||
// 重载配置调用
|
||||
func (this *Node) onReload(config *nodeconfigs.NodeConfig, reloadAll bool) {
|
||||
nodeconfigs.ResetNodeConfig(config)
|
||||
sharedNodeConfig = config
|
||||
sharedNodeConfig.Store(config)
|
||||
|
||||
var accessLogFilePath string
|
||||
if config != nil && config.GlobalServerConfig != nil {
|
||||
@@ -1069,7 +1077,7 @@ func (this *Node) reloadServer() {
|
||||
if countUpdatingServers > 0 {
|
||||
var updatingServerMap = this.updatingServerMap
|
||||
this.updatingServerMap = map[int64]*serverconfigs.ServerConfig{}
|
||||
newNodeConfig, err := nodeconfigs.CloneNodeConfig(sharedNodeConfig)
|
||||
newNodeConfig, err := nodeconfigs.CloneNodeConfig(nodeConfig())
|
||||
if err != nil {
|
||||
remotelogs.Error("NODE", "apply server config error: "+err.Error())
|
||||
return
|
||||
@@ -1121,7 +1129,7 @@ func (this *Node) tuneSystemParameters() {
|
||||
return
|
||||
}
|
||||
|
||||
if sharedNodeConfig == nil || !sharedNodeConfig.AutoSystemTuning {
|
||||
if nodeConfig() == nil || !nodeConfig().AutoSystemTuning {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user