mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
1.优化服务配置检查
2.废弃SetGoRoutineNum接口 3.释放Module优化
This commit is contained in:
@@ -417,13 +417,12 @@ func (cls *Cluster) readLocalService(localNodeId string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cls *Cluster) parseLocalCfg() {
|
func (cls *Cluster) parseLocalCfg() error{
|
||||||
rpcInfo := NodeRpcInfo{}
|
rpcInfo := NodeRpcInfo{}
|
||||||
rpcInfo.nodeInfo = cls.localNodeInfo
|
rpcInfo.nodeInfo = cls.localNodeInfo
|
||||||
rpcInfo.client = rpc.NewLClient(rpcInfo.nodeInfo.NodeId, &cls.callSet)
|
rpcInfo.client = rpc.NewLClient(rpcInfo.nodeInfo.NodeId, &cls.callSet)
|
||||||
|
|
||||||
cls.mapRpc[cls.localNodeInfo.NodeId] = &rpcInfo
|
cls.mapRpc[cls.localNodeInfo.NodeId] = &rpcInfo
|
||||||
|
|
||||||
for _, serviceName := range cls.localNodeInfo.ServiceList {
|
for _, serviceName := range cls.localNodeInfo.ServiceList {
|
||||||
splitServiceName := strings.Split(serviceName, ":")
|
splitServiceName := strings.Split(serviceName, ":")
|
||||||
if len(splitServiceName) == 2 {
|
if len(splitServiceName) == 2 {
|
||||||
@@ -440,8 +439,13 @@ func (cls *Cluster) parseLocalCfg() {
|
|||||||
cls.mapServiceNode[serviceName] = make(map[string]struct{})
|
cls.mapServiceNode[serviceName] = make(map[string]struct{})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _,ok:=cls.mapServiceNode[serviceName][cls.localNodeInfo.NodeId];ok {
|
||||||
|
return fmt.Errorf("duplicate service %s is configured in node %s", serviceName, cls.localNodeInfo.NodeId)
|
||||||
|
}
|
||||||
cls.mapServiceNode[serviceName][cls.localNodeInfo.NodeId] = struct{}{}
|
cls.mapServiceNode[serviceName][cls.localNodeInfo.NodeId] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cls *Cluster) IsNatsMode() bool {
|
func (cls *Cluster) IsNatsMode() bool {
|
||||||
@@ -474,8 +478,7 @@ func (cls *Cluster) InitCfg(localNodeId string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//本地配置服务加到全局map信息中
|
//本地配置服务加到全局map信息中
|
||||||
cls.parseLocalCfg()
|
return cls.parseLocalCfg()
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cls *Cluster) IsConfigService(serviceName string) bool {
|
func (cls *Cluster) IsConfigService(serviceName string) bool {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/duanhf2012/origin/v2/log"
|
"github.com/duanhf2012/origin/v2/log"
|
||||||
rpcHandle "github.com/duanhf2012/origin/v2/rpc"
|
rpcHandle "github.com/duanhf2012/origin/v2/rpc"
|
||||||
"github.com/duanhf2012/origin/v2/util/timer"
|
"github.com/duanhf2012/origin/v2/util/timer"
|
||||||
|
"slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
const InitModuleId = 1e9
|
const InitModuleId = 1e9
|
||||||
@@ -46,7 +47,7 @@ type Module struct {
|
|||||||
moduleName string //模块名称
|
moduleName string //模块名称
|
||||||
parent IModule //父亲
|
parent IModule //父亲
|
||||||
self IModule //自己
|
self IModule //自己
|
||||||
child map[uint32]IModule //孩子们
|
child []IModule //孩子们
|
||||||
mapActiveTimer map[timer.ITimer]struct{}
|
mapActiveTimer map[timer.ITimer]struct{}
|
||||||
mapActiveIdTimer map[uint64]timer.ITimer
|
mapActiveIdTimer map[uint64]timer.ITimer
|
||||||
dispatcher *timer.Dispatcher //timer
|
dispatcher *timer.Dispatcher //timer
|
||||||
@@ -93,10 +94,7 @@ func (m *Module) AddModule(module IModule) (uint32, error) {
|
|||||||
pAddModule.moduleId = m.NewModuleId()
|
pAddModule.moduleId = m.NewModuleId()
|
||||||
}
|
}
|
||||||
|
|
||||||
if m.child == nil {
|
_,ok := m.ancestor.getBaseModule().(*Module).descendants[module.GetModuleId()]
|
||||||
m.child = map[uint32]IModule{}
|
|
||||||
}
|
|
||||||
_, ok := m.child[module.GetModuleId()]
|
|
||||||
if ok == true {
|
if ok == true {
|
||||||
return 0, fmt.Errorf("exists module id %d", module.GetModuleId())
|
return 0, fmt.Errorf("exists module id %d", module.GetModuleId())
|
||||||
}
|
}
|
||||||
@@ -109,24 +107,27 @@ func (m *Module) AddModule(module IModule) (uint32, error) {
|
|||||||
pAddModule.eventHandler = event.NewEventHandler()
|
pAddModule.eventHandler = event.NewEventHandler()
|
||||||
pAddModule.eventHandler.Init(m.eventHandler.GetEventProcessor())
|
pAddModule.eventHandler.Init(m.eventHandler.GetEventProcessor())
|
||||||
pAddModule.IConcurrent = m.IConcurrent
|
pAddModule.IConcurrent = m.IConcurrent
|
||||||
|
|
||||||
|
m.child = append(m.child,module)
|
||||||
|
m.ancestor.getBaseModule().(*Module).descendants[module.GetModuleId()] = module
|
||||||
|
|
||||||
err := module.OnInit()
|
err := module.OnInit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
delete(m.ancestor.getBaseModule().(*Module).descendants, module.GetModuleId())
|
||||||
|
m.child = m.child[:len(m.child)-1]
|
||||||
|
log.Error("module OnInit error",log.String("ModuleName",module.GetModuleName()),log.ErrorField("err",err))
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
m.child[module.GetModuleId()] = module
|
|
||||||
m.ancestor.getBaseModule().(*Module).descendants[module.GetModuleId()] = module
|
|
||||||
|
|
||||||
log.Debug("Add module " + module.GetModuleName() + " completed")
|
log.Debug("Add module " + module.GetModuleName() + " completed")
|
||||||
return module.GetModuleId(), nil
|
return module.GetModuleId(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Module) ReleaseModule(moduleId uint32) {
|
func (m *Module) ReleaseModule(moduleId uint32) {
|
||||||
pModule := m.GetModule(moduleId).getBaseModule().(*Module)
|
pModule := m.GetModule(moduleId).getBaseModule().(*Module)
|
||||||
|
|
||||||
//释放子孙
|
//释放子孙
|
||||||
for id := range pModule.child {
|
for i:=len(pModule.child)-1; i>=0; i-- {
|
||||||
m.ReleaseModule(id)
|
m.ReleaseModule(pModule.child[i].GetModuleId())
|
||||||
}
|
}
|
||||||
|
|
||||||
pModule.self.OnRelease()
|
pModule.self.OnRelease()
|
||||||
@@ -140,7 +141,10 @@ func (m *Module) ReleaseModule(moduleId uint32) {
|
|||||||
t.Cancel()
|
t.Cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(m.child, moduleId)
|
m.child = slices.DeleteFunc(m.child, func(module IModule) bool {
|
||||||
|
return module.GetModuleId() == moduleId
|
||||||
|
})
|
||||||
|
|
||||||
delete(m.ancestor.getBaseModule().(*Module).descendants, moduleId)
|
delete(m.ancestor.getBaseModule().(*Module).descendants, moduleId)
|
||||||
|
|
||||||
//清理被删除的Module
|
//清理被删除的Module
|
||||||
|
|||||||
@@ -264,10 +264,13 @@ func (s *Service) Release() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
for i:=len(s.child)-1; i>=0; i-- {
|
||||||
|
s.ReleaseModule(s.child[i].GetModuleId())
|
||||||
|
}
|
||||||
|
|
||||||
if atomic.AddInt32(&s.isRelease, -1) == -1 {
|
if atomic.AddInt32(&s.isRelease, -1) == -1 {
|
||||||
s.self.OnRelease()
|
s.self.OnRelease()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) OnRelease() {
|
func (s *Service) OnRelease() {
|
||||||
@@ -432,6 +435,7 @@ func (s *Service) SetEventChannelNum(num int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecated: replace it with the OpenConcurrent function
|
||||||
func (s *Service) SetGoRoutineNum(goroutineNum int32) bool {
|
func (s *Service) SetGoRoutineNum(goroutineNum int32) bool {
|
||||||
//已经开始状态不允许修改协程数量,打开性能分析器不允许开多线程
|
//已经开始状态不允许修改协程数量,打开性能分析器不允许开多线程
|
||||||
if s.startStatus == true || s.profiler != nil {
|
if s.startStatus == true || s.profiler != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user