Merge pull request #862 from GLYASAI/startup-sequence

bug fix: circular dependency
This commit is contained in:
黄润豪 2020-10-16 17:15:43 +08:00 committed by GitHub
commit 45b6db9819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 3 deletions

View File

@ -312,18 +312,19 @@ func (s *ServiceDependency) buildLinkListByHead(l *list.List) []*list.List {
if !ok {
copy := list.New()
copy.PushBackList(l)
return []*list.List{l}
return []*list.List{copy}
}
var result []*list.List
for _, depsid := range depsids {
// child node is already in the linked list
if alreadyInLinkedList(l, depsid) {
if alreadyInLinkedList(l, depsid) || s.childInLinkedList(l, depsid) {
copy := list.New()
copy.PushBackList(l)
result = append(result, copy)
continue
}
newl := list.New()
newl.PushBackList(l)
newl.PushBack(depsid)
@ -341,6 +342,21 @@ func (s *ServiceDependency) buildLinkListByHead(l *list.List) []*list.List {
return result
}
func (s *ServiceDependency) childInLinkedList(l *list.List, sid string) bool {
depsids, ok := s.sid2depsids[sid]
if !ok {
return false
}
for _, depsid := range depsids {
if alreadyInLinkedList(l, depsid) {
return true
}
}
return false
}
func alreadyInLinkedList(l *list.List, depsid string) bool {
pre := l.Back()
for pre != nil {

View File

@ -167,6 +167,32 @@ func TestBuildLinkListByHead(t *testing.T) {
return []*list.List{l}
}(),
},
{
name: "spring cloud pig",
l: func() *list.List {
l := list.New()
l.PushBack("banana")
return l
}(),
sid2depsids: map[string][]string{
"apple": []string{"banana"},
"banana": []string{"apple", "cat", "dog"},
},
want: func() []*list.List {
l1 := list.New()
l1.PushBack("banana")
l2 := list.New()
l2.PushBack("banana")
l2.PushBack("cat")
l3 := list.New()
l3.PushBack("banana")
l3.PushBack("dog")
return []*list.List{l1, l2, l3}
}(),
},
}
for idx := range tests {

View File

@ -22,7 +22,7 @@ func CheckTenantResource(tenant *dbmodel.Tenants, needMemory int) error {
}
clusterInfo, err := GetTenantManager().GetAllocatableResources()
if err != nil {
logrus.Errorf("get cluster resources failure for check tenant resource.", err.Error())
logrus.Errorf("get cluster resources failure for check tenant resource: %v", err.Error())
}
if clusterInfo != nil {
clusterAvailMemory := clusterInfo.AllMemory - clusterInfo.RequestMemory