Fix: deadlock and sync issue in node pool
This commit is contained in:
parent
1f06ee3af6
commit
5db476634a
5 changed files with 35 additions and 8 deletions
|
@ -48,6 +48,9 @@ func migration() {
|
|||
// 创建初始管理员账户
|
||||
addDefaultUser()
|
||||
|
||||
// 创建初始节点
|
||||
addDefaultNode()
|
||||
|
||||
// 向设置数据表添加初始设置
|
||||
addDefaultSettings()
|
||||
|
||||
|
@ -268,3 +271,22 @@ func addDefaultUser() {
|
|||
util.Log().Info("初始管理员密码:" + c.Sprint(password))
|
||||
}
|
||||
}
|
||||
|
||||
func addDefaultNode() {
|
||||
_, err := GetNodeByID(1)
|
||||
|
||||
if gorm.IsRecordNotFoundError(err) {
|
||||
defaultAdminGroup := Node{
|
||||
Name: "主机(本机)",
|
||||
Status: NodeActive,
|
||||
Type: MasterNodeType,
|
||||
Aria2OptionsSerialized: Aria2Option{
|
||||
Interval: 10,
|
||||
Timeout: 10,
|
||||
},
|
||||
}
|
||||
if err := DB.Create(&defaultAdminGroup).Error; err != nil {
|
||||
util.Log().Panic("无法创建初始节点记录, %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ func (pool *NodePool) Add(node *model.Node) {
|
|||
old, ok = pool.inactive[node.ID]
|
||||
}
|
||||
if old != nil {
|
||||
old.Init(node)
|
||||
go old.Init(node)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ type slaveCaller struct {
|
|||
// Init 初始化节点
|
||||
func (node *SlaveNode) Init(nodeModel *model.Node) {
|
||||
node.lock.Lock()
|
||||
defer node.lock.Unlock()
|
||||
node.Model = nodeModel
|
||||
|
||||
// Init http request client
|
||||
|
@ -54,12 +53,15 @@ func (node *SlaveNode) Init(nodeModel *model.Node) {
|
|||
)
|
||||
|
||||
node.caller.parent = node
|
||||
node.Active = true
|
||||
if node.close != nil {
|
||||
node.lock.Unlock()
|
||||
node.close <- true
|
||||
go node.StartPingLoop()
|
||||
} else {
|
||||
node.Active = true
|
||||
node.lock.Unlock()
|
||||
go node.StartPingLoop()
|
||||
}
|
||||
|
||||
go node.StartPingLoop()
|
||||
}
|
||||
|
||||
// IsFeatureEnabled 查询节点的某项功能是否启用
|
||||
|
@ -84,6 +86,9 @@ func (node *SlaveNode) SubscribeStatusChange(callback func(bool, uint)) {
|
|||
|
||||
// Ping 从机节点,返回从机负载
|
||||
func (node *SlaveNode) Ping(req *serializer.NodePingReq) (*serializer.NodePingResp, error) {
|
||||
node.lock.RLock()
|
||||
defer node.lock.RUnlock()
|
||||
|
||||
reqBodyEncoded, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -4,7 +4,7 @@ package conf
|
|||
var BackendVersion = "3.3.2"
|
||||
|
||||
// RequiredDBVersion 与当前版本匹配的数据库版本
|
||||
var RequiredDBVersion = "3.3.2"
|
||||
var RequiredDBVersion = "3.4.0-beta"
|
||||
|
||||
// RequiredStaticVersion 与当前版本匹配的静态资源版本
|
||||
var RequiredStaticVersion = "3.3.2"
|
||||
|
|
|
@ -15,9 +15,9 @@ import (
|
|||
|
||||
// Aria2TestService aria2连接测试服务
|
||||
type Aria2TestService struct {
|
||||
Server string `json:"server" binding:"required"`
|
||||
Server string `json:"server"`
|
||||
RPC string `json:"rpc" binding:"required"`
|
||||
Secret string `json:"secret" binding:"required"`
|
||||
Secret string `json:"secret"`
|
||||
Token string `json:"token"`
|
||||
Type model.ModelType `json:"type"`
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue