Skip to content

Commit 11d5404

Browse files
committed
fix CreateWorker bugs.
1 parent 119ea9f commit 11d5404

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

cache/cache.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,17 @@ func (cacheRepository *CacheRepository) CreateWorker(key string, node *gzkwrappe
493493

494494
worker := cacheRepository.nodeStore.GetWorker(key)
495495
if worker != nil {
496-
logger.WARN("[#cache#] %s create worker %s is already, %s(%s).", node.Location, node.HostName, node.IpAddr)
496+
logger.WARN("[#cache#] %s create worker %s key is already, %s(%s).", node.Location, node.HostName, node.IpAddr)
497497
return
498498
}
499499

500-
ret := cacheRepository.localStorage.ContainsLocationServer(node.Location, node.IpAddr, node.HostName)
500+
ret := cacheRepository.nodeStore.ContainsLocationWorker(node.Location, node.IpAddr, node.HostName)
501+
if ret {
502+
logger.WARN("[#cache#] %s create worker %s ip or host is already, %s(%s).", node.Location, node.HostName, node.IpAddr)
503+
return
504+
}
505+
506+
ret = cacheRepository.localStorage.ContainsLocationServer(node.Location, node.IpAddr, node.HostName)
501507
if ret {
502508
server := models.CreateServer(key, node, 1)
503509
attach := models.AttachDecode(node.Attach)
@@ -511,7 +517,7 @@ func (cacheRepository *CacheRepository) ChangeWorker(key string, node *gzkwrappe
511517

512518
worker := cacheRepository.nodeStore.GetWorker(key)
513519
if worker == nil {
514-
logger.WARN("[#cache#] %s change worker %s not found, %s(%s).", node.Location, node.HostName, node.IpAddr)
520+
logger.WARN("[#cache#] %s change worker %s key is not found, %s(%s).", node.Location, node.HostName, node.IpAddr)
515521
return
516522
}
517523

cache/nodes.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,28 @@ func (store *NodeStore) GetWorker(key string) *Worker {
7575
return nil
7676
}
7777

78+
//ContainsLocationWorker is exported
79+
func (store *NodeStore) ContainsLocationWorker(location string, ipaddr string, hostname string) bool {
80+
81+
store.RLock()
82+
defer store.RUnlock()
83+
if workers, ret := store.nodesData[location]; ret {
84+
for _, worker := range workers {
85+
if itIPAddr := strings.TrimSpace(worker.IPAddr); itIPAddr != "" {
86+
if itIPAddr == ipaddr {
87+
return true
88+
}
89+
}
90+
if itHostName := strings.TrimSpace(worker.Name); itHostName != "" {
91+
if strings.ToUpper(itHostName) == strings.ToUpper(hostname) {
92+
return true
93+
}
94+
}
95+
}
96+
}
97+
return false
98+
}
99+
78100
//GetWorkers is exported
79101
func (store *NodeStore) GetWorkers(location string) []*Worker {
80102

0 commit comments

Comments
 (0)