From c2cdc9895c51c85811ad52fdfc9867d44b7d3f08 Mon Sep 17 00:00:00 2001 From: JIN XiaoFeng Date: Fri, 14 Jun 2024 14:36:15 +0800 Subject: [PATCH] [Controller] debug sync by orgid --- cli/ctl/trisolaris_check.go | 1 + .../trisolaris/services/grpc/synchronize/vtap.go | 10 ++++++++-- server/controller/trisolaris/trisolaris.go | 16 ++++++++++------ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/cli/ctl/trisolaris_check.go b/cli/ctl/trisolaris_check.go index 7e3d6650404..4ec3f3e9451 100644 --- a/cli/ctl/trisolaris_check.go +++ b/cli/ctl/trisolaris_check.go @@ -268,6 +268,7 @@ func initCmd(cmd *cobra.Command, cmds []CmdExecute) { groupID = paramData.GroupID clusterID = paramData.ClusterID teamID = paramData.TeamID + orgID = paramData.OrgID case "analyzer": name = paramData.Type orgID = paramData.OrgID diff --git a/server/controller/trisolaris/services/grpc/synchronize/vtap.go b/server/controller/trisolaris/services/grpc/synchronize/vtap.go index 2ceb613edab..effa76fa19f 100644 --- a/server/controller/trisolaris/services/grpc/synchronize/vtap.go +++ b/server/controller/trisolaris/services/grpc/synchronize/vtap.go @@ -319,8 +319,14 @@ func (e *VTapEvent) Sync(ctx context.Context, in *api.SyncRequest) (*api.SyncRes orgID, teamIDInt := trisolaris.GetOrgInfoByTeamID(teamIDStr) gVTapInfo := trisolaris.GetORGVTapInfo(orgID) if gVTapInfo == nil { - log.Errorf("ORGID-%d: ctrlIp is %s, ctrlMac is %s, team_id is (str=%s,int=%d) not found vtapInfo", orgID, ctrlIP, ctrlMac, teamIDStr, teamIDInt) - return e.GetFailedResponse(in, gVTapInfo), nil + if rOrgID := int(in.GetOrgId()); rOrgID != 0 { + orgID = rOrgID + gVTapInfo = trisolaris.GetORGVTapInfo(rOrgID) + } + if gVTapInfo == nil { + log.Errorf("ORGID-%d: ctrlIp is %s, ctrlMac is %s, team_id is (str=%s,int=%d) not found vtapInfo", orgID, ctrlIP, ctrlMac, teamIDStr, teamIDInt) + return e.GetFailedResponse(in, gVTapInfo), nil + } } vtapCacheKey := ctrlIP + "-" + ctrlMac vtapCache, err := e.getVTapCache(in, orgID) diff --git a/server/controller/trisolaris/trisolaris.go b/server/controller/trisolaris/trisolaris.go index 11e014e40a2..36a40c7ffab 100644 --- a/server/controller/trisolaris/trisolaris.go +++ b/server/controller/trisolaris/trisolaris.go @@ -357,7 +357,6 @@ func NewTrisolarisManager(cfg *config.Config, db *gorm.DB) *TrisolarisManager { } func (m *TrisolarisManager) Start() error { - go m.TimedCheckORG() go m.refreshOP.TimedRefreshIPs() m.startTime = getStartTime() orgIDs, err := mysql.GetORGIDs() @@ -367,9 +366,11 @@ func (m *TrisolarisManager) Start() error { } log.Infof("get orgIDs : %v", orgIDs) trisolaris := NewTrisolaris(m.config, mysql.DefaultDB, m.ctx, m.startTime) - trisolaris.Start() m.orgToTrisolaris[DEFAULT_ORG_ID] = trisolaris - for _, orgID := range orgIDs { + go trisolaris.Start() + orgIDsUint32 := make([]uint32, len(orgIDs), len(orgIDs)) + for index, orgID := range orgIDs { + orgIDsUint32[index] = uint32(orgID) if utils.CheckOrgID(orgID) == false || orgID == DEFAULT_ORG_ID { continue } @@ -379,10 +380,13 @@ func (m *TrisolarisManager) Start() error { continue } trisolaris := NewTrisolaris(m.config, orgDB, m.ctx, m.startTime) - trisolaris.Start() m.orgToTrisolaris[orgID] = trisolaris + go trisolaris.Start() } - + m.orgIDData = &trident.OrgIDsResponse{ + OrgIds: orgIDsUint32, + } + go m.TimedCheckORG() m.getTeamData(orgIDs) log.Infof("finish orgdata init %v", orgIDs) return nil @@ -496,8 +500,8 @@ func (m *TrisolarisManager) checkORG() { continue } trisolaris := NewTrisolaris(m.config, orgDB, m.ctx, m.startTime) - trisolaris.Start() m.orgToTrisolaris[orgID] = trisolaris + go trisolaris.Start() } } }