Skip to content

Commit

Permalink
Add Mutex to MCI related infos
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-github-robot authored Oct 25, 2024
2 parents e9b68ca + e03f33f commit 679efa7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/cloudspec.csv
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ NCP,JPN,SPSVRSSD00000016,,,,,,,,,,,,default,default,,,,,,vm
NCP,DEN,SPSVRSSD00000005,,,,,,,,,,,,default,default,,,,,,vm
NCP,DEN,SPSVRSSD00000007,,,,,,,,,,,,default,default,,,,,,vm
NCP,DEN,SPSVRSSD00000016,,,,,,,,,,,,default,default,,,,,,vm
NCPVPC,all,SPSVRSSD00000002,0.0748,,,,,,,,,,,default,default,,,,,,vm
NCPVPC,all,SVR.VSVR.HICPU.C004.M008.NET.SSD.B050.G002,0.14,,,,,,,,,,,default,default,,,,,,vm
NCPVPC,all,SVR.VSVR.HICPU.C008.M016.NET.SSD.B050.G002,0.28,,,,,,,,,,,default,default,,,,,,vm
NCPVPC,all,SVR.VSVR.HICPU.C016.M032.NET.SSD.B050.G002,0.57,,,,,,,,,,,default,default,,,,,,vm
Expand Down
8 changes: 8 additions & 0 deletions src/core/infra/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
"github.com/rs/zerolog/log"
)

var mciInfoMutex sync.Mutex

// [MCI and VM object information managemenet]

// ListMciId is func to list MCI ID
Expand Down Expand Up @@ -415,6 +417,7 @@ func GetMciAccessInfo(nsId string, mciId string, option string) (*model.MciAcces
wg.Add(1)
go func(nsId string, mciId string, vmId string, option string, chanResults chan model.MciVmAccessInfo) {
defer wg.Done()
common.RandomSleep(0, len(vmList)/2)
vmInfo, err := GetVmCurrentPublicIp(nsId, mciId, vmId)
vmAccessInfo := model.MciVmAccessInfo{}
if err != nil {
Expand Down Expand Up @@ -1327,6 +1330,8 @@ func GetMciVmStatus(nsId string, mciId string, vmId string) (*model.TbVmStatusIn

// UpdateMciInfo is func to update MCI Info (without VM info in MCI)
func UpdateMciInfo(nsId string, mciInfoData model.TbMciInfo) {
mciInfoMutex.Lock()
defer mciInfoMutex.Unlock()

mciInfoData.Vm = nil

Expand All @@ -1352,6 +1357,9 @@ func UpdateMciInfo(nsId string, mciInfoData model.TbMciInfo) {

// UpdateVmInfo is func to update VM Info
func UpdateVmInfo(nsId string, mciId string, vmInfoData model.TbVmInfo) {
mciInfoMutex.Lock()
defer mciInfoMutex.Unlock()

key := common.GenMciKey(nsId, mciId, vmInfoData.Id)

// Check existence of the key. If no key, no update.
Expand Down

0 comments on commit 679efa7

Please sign in to comment.