-
Notifications
You must be signed in to change notification settings - Fork 932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: event driven chain cache #976
Changes from 48 commits
49b71c0
a707429
353391f
b3eff92
72e3dff
e958d69
f84b8fc
f7073cf
1518966
e7a0e1c
7d0f479
2831e35
ae8b2ae
e2d57e7
0b7206b
7438599
daa66ea
7dfa6be
ac7acc7
8e92b2d
f466966
c822cfa
c1cc113
482f9dc
c634ab2
4bce431
f5030fe
c5532cb
b812794
5fe6029
b6022bb
a856678
b5784d2
e5bee95
84bfb9d
a15546a
d305b67
5919b11
ed0b174
be89b70
3dc2f17
833c829
add1618
4f3d161
30e36d0
2c2c35f
569bacd
25c1e44
e5d53ca
edd99f5
93094ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,38 +121,45 @@ func (invoker *baseClusterInvoker) doSelect(lb cluster.LoadBalance, invocation p | |
|
||
func (invoker *baseClusterInvoker) doSelectInvoker(lb cluster.LoadBalance, invocation protocol.Invocation, invokers []protocol.Invoker, invoked []protocol.Invoker) protocol.Invoker { | ||
if len(invokers) == 0 { | ||
logger.Errorf("the invokers of %s is nil. ", invocation.Invoker().GetUrl().ServiceKey()) | ||
return nil | ||
} | ||
go protocol.TryRefreshBlackList() | ||
if len(invokers) == 1 { | ||
return invokers[0] | ||
if invokers[0].IsAvailable() { | ||
return invokers[0] | ||
} | ||
protocol.SetInvokerUnhealthyStatus(invokers[0]) | ||
logger.Errorf("the invokers of %s is nil. ", invokers[0].GetUrl().ServiceKey()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个错误日志看起来跟上下文无关,或者是否应该放在 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里位置主要是针对invokers列表因为健康检查导致为空时,打印出对应失败的key。 |
||
return nil | ||
} | ||
|
||
selectedInvoker := lb.Select(invokers, invocation) | ||
|
||
//judge to if the selectedInvoker is invoked | ||
|
||
//judge if the selected Invoker is invoked and available | ||
if (!selectedInvoker.IsAvailable() && invoker.availablecheck) || isInvoked(selectedInvoker, invoked) { | ||
protocol.SetInvokerUnhealthyStatus(selectedInvoker) | ||
otherInvokers := getOtherInvokers(invokers, selectedInvoker) | ||
// do reselect | ||
var reslectInvokers []protocol.Invoker | ||
|
||
for _, invoker := range invokers { | ||
if !invoker.IsAvailable() { | ||
for i := 0; i < 3; i++ { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 当整个循环次数超过 3 次,最后还是会返回最开始不可用的 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you r right, I've fixed it. |
||
if len(otherInvokers) == 0 { | ||
// no other ivk to reselect, return to fallback | ||
logger.Errorf("all %d invokers is unavailable for %s.", len(invokers), selectedInvoker.GetUrl().String()) | ||
return nil | ||
} | ||
reselectedInvoker := lb.Select(otherInvokers, invocation) | ||
if isInvoked(reselectedInvoker, invoked) { | ||
otherInvokers = getOtherInvokers(otherInvokers, reselectedInvoker) | ||
continue | ||
} | ||
if !reselectedInvoker.IsAvailable() { | ||
logger.Infof("the invoker of %s is not available, maybe some network error happened or the server is shutdown.", | ||
invoker.GetUrl().Ip) | ||
protocol.SetInvokerUnhealthyStatus(reselectedInvoker) | ||
otherInvokers = getOtherInvokers(otherInvokers, reselectedInvoker) | ||
continue | ||
} | ||
|
||
if !isInvoked(invoker, invoked) { | ||
reslectInvokers = append(reslectInvokers, invoker) | ||
} | ||
} | ||
|
||
if len(reslectInvokers) > 0 { | ||
selectedInvoker = lb.Select(reslectInvokers, invocation) | ||
} else { | ||
logger.Errorf("all %d invokers is unavailable for %s.", len(invokers), selectedInvoker.GetUrl().String()) | ||
return nil | ||
selectedInvoker = reselectedInvoker | ||
break | ||
} | ||
} | ||
return selectedInvoker | ||
|
@@ -194,3 +201,13 @@ func getLoadBalance(invoker protocol.Invoker, invocation protocol.Invocation) cl | |
} | ||
return extension.GetLoadbalance(lb) | ||
} | ||
|
||
func getOtherInvokers(invokers []protocol.Invoker, invoker protocol.Invoker) []protocol.Invoker { | ||
otherInvokers := make([]protocol.Invoker, 0) | ||
for _, i := range invokers { | ||
if i != invoker { | ||
otherInvokers = append(otherInvokers, i) | ||
} | ||
} | ||
return otherInvokers | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,7 +148,13 @@ conditions: | |
url := getConditionRouteUrl(applicationKey) | ||
assert.NotNil(t, url) | ||
factory := extension.GetRouterFactory(url.Protocol) | ||
r, err := factory.NewPriorityRouter(url) | ||
notify := make(chan struct{}) | ||
go func() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed~ |
||
for { | ||
<-notify | ||
} | ||
}() | ||
r, err := factory.NewPriorityRouter(url, notify) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, r) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if need warn log ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个地方比较有意思,是改了个已有的坑。
invocation.Invoker()是个nil,所以一走到这一行就会panic。
后来发现这里不会被执行到。不存在invokers列表为空的情况。所以决定删掉这行日志了。