Skip to content

Commit 1259050

Browse files
authored
1. MotanCluster on refresh add: shuffle endpoints list avoid to call to determine server nodes when the list is not change. 2.MotanEndpoint ensure trigger keepalive in recordErrAndKeepalive. (#243)
* add request x-forwarded-for (#241) * 1. MotanCluster on refresh add: shuffle endpoints list avoid to call to determine server nodes when the list is not change. 2.MotanEndpoint ensure trigger keepalive and optimise to call keepalive in recordErrAndKeepalive. * 1. MotanCluster on refresh add: shuffle endpoints list avoid to call to determine server nodes when the list is not change. 2.MotanEndpoint ensure trigger keepalive in recordErrAndKeepalive.
1 parent d55c49f commit 1259050

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cluster/motanCluster.go

+7
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,16 @@ func (m *MotanCluster) refresh() {
122122
newRefers = append(newRefers, e)
123123
}
124124
}
125+
// shuffle endpoints list avoid to call to determine server nodes when the list is not change.
126+
newRefers = m.ShuffleEndpoints(newRefers)
125127
m.Refers = newRefers
126128
m.LoadBalance.OnRefresh(newRefers)
127129
}
130+
func (m *MotanCluster) ShuffleEndpoints(endpoints []motan.EndPoint) []motan.EndPoint {
131+
rand.Seed(time.Now().UnixNano())
132+
rand.Shuffle(len(endpoints), func(i, j int) { endpoints[i], endpoints[j] = endpoints[j], endpoints[i] })
133+
return endpoints
134+
}
128135
func (m *MotanCluster) AddRegistry(registry motan.Registry) {
129136
m.Registries = append(m.Registries, registry)
130137
}

endpoint/motanEndpoint.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ func (m *MotanEndpoint) Call(request motan.Request) motan.Response {
219219

220220
func (m *MotanEndpoint) recordErrAndKeepalive() {
221221
errCount := atomic.AddUint32(&m.errorCount, 1)
222-
if errCount == uint32(m.errorCountThreshold) {
222+
// ensure trigger keepalive
223+
if errCount >= uint32(m.errorCountThreshold) {
223224
m.setAvailable(false)
224225
vlog.Infoln("Referer disable:" + m.url.GetIdentity())
225226
go m.keepalive()

0 commit comments

Comments
 (0)