Refactor: move slave pkg inside of cluster

Test: middleware for node communication
This commit is contained in:
HFO4
2021-11-08 19:54:26 +08:00
parent eaa0f6be91
commit e41ec9defa
16 changed files with 135 additions and 43 deletions

View File

@@ -39,14 +39,22 @@ type NodePool struct {
// Init 初始化从机节点池
func Init() {
Default = &NodePool{
featureMap: make(map[string][]Node),
}
Default = &NodePool{}
Default.Init()
if err := Default.initFromDB(); err != nil {
util.Log().Warning("节点池初始化失败, %s", err)
}
}
func (pool *NodePool) Init() {
pool.lock.Lock()
defer pool.lock.Unlock()
pool.featureMap = make(map[string][]Node)
pool.active = make(map[uint]Node)
pool.inactive = make(map[uint]Node)
}
func (pool *NodePool) buildIndexMap() {
pool.lock.Lock()
for _, feature := range featureGroup {
@@ -98,8 +106,6 @@ func (pool *NodePool) initFromDB() error {
}
pool.lock.Lock()
pool.active = make(map[uint]Node)
pool.inactive = make(map[uint]Node)
for i := 0; i < len(nodes); i++ {
pool.add(&nodes[i])
}