优化节点配置生成速度

This commit is contained in:
刘祥超
2021-11-11 14:16:42 +08:00
parent 8afd21f2f4
commit 5b32343a2c
49 changed files with 527 additions and 198 deletions

View File

@@ -18,7 +18,9 @@ import (
"time"
)
// 命令请求相关
var primaryNodeId int64 = 0
// CommandRequest 命令请求相关
type CommandRequest struct {
Id int64
Code string
@@ -74,6 +76,26 @@ func (this *NodeService) NodeStream(server pb.NodeService_NodeStreamServer) erro
return err
}
// 选择一个作为主节点
if primaryNodeId == 0 {
primaryNodeId = nodeId
}
defer func() {
if primaryNodeId == nodeId {
primaryNodeId = 0
nodeLocker.Lock()
if len(nodeRequestChanMap) > 0 {
for anotherNodeId := range nodeRequestChanMap {
primaryNodeId = anotherNodeId
break
}
}
nodeLocker.Unlock()
}
}()
// 返回连接成功
{
apiConfig, err := configs.SharedAPIConfig()