Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
c1cc1138
Commit
c1cc1138
authored
4 years ago
by
李志信
Browse files
Options
Downloads
Patches
Plain Diff
fix: add router change refresh cache logic
parent
c822cfab
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cluster/router/chain/chain.go
+14
-9
14 additions, 9 deletions
cluster/router/chain/chain.go
protocol/rpc_status.go
+10
-6
10 additions, 6 deletions
protocol/rpc_status.go
with
24 additions
and
15 deletions
cluster/router/chain/chain.go
+
14
−
9
View file @
c1cc1138
...
...
@@ -20,12 +20,12 @@ package chain
import
(
"sort"
"sync"
"sync/atomic"
"time"
)
import
(
perrors
"github.com/pkg/errors"
"go.uber.org/atomic"
)
import
(
...
...
@@ -38,9 +38,7 @@ import (
)
const
(
timeInterval
=
5
*
time
.
Second
timeThreshold
=
2
*
time
.
Second
countThreshold
=
5
timeInterval
=
5
*
time
.
Second
)
// RouterChain Router chain
...
...
@@ -65,6 +63,8 @@ type RouterChain struct {
notify
chan
struct
{}
// Address cache
cache
atomic
.
Value
// routerNeedsUpdate
routerNeedsUpdate
atomic
.
Bool
}
// Route Loop routers in RouterChain and call Route method to determine the target invokers list.
...
...
@@ -102,6 +102,7 @@ func (c *RouterChain) AddRouters(routers []router.PriorityRouter) {
c
.
mutex
.
Lock
()
defer
c
.
mutex
.
Unlock
()
c
.
routers
=
newRouters
c
.
routerNeedsUpdate
.
Store
(
true
)
}
// SetInvokers receives updated invokers from registry center. If the times of notification exceeds countThreshold and
...
...
@@ -123,8 +124,9 @@ func (c *RouterChain) loop() {
for
{
select
{
case
<-
ticker
.
C
:
if
protocol
.
GetAndRefreshState
()
{
if
protocol
.
GetAndRefreshState
()
||
c
.
routerNeedsUpdate
.
Load
()
{
c
.
buildCache
()
c
.
routerNeedsUpdate
.
Store
(
false
)
}
case
<-
c
.
notify
:
c
.
buildCache
()
...
...
@@ -237,11 +239,14 @@ func NewRouterChain(url *common.URL) (*RouterChain, error) {
sortRouter
(
newRouters
)
routerNeedsUpdateInit
:=
atomic
.
Bool
{}
routerNeedsUpdateInit
.
Store
(
false
)
chain
:=
&
RouterChain
{
builtinRouters
:
routers
,
routers
:
newRouters
,
last
:
time
.
Now
(),
notify
:
make
(
chan
struct
{}),
builtinRouters
:
routers
,
routers
:
newRouters
,
last
:
time
.
Now
(),
notify
:
make
(
chan
struct
{}),
routerNeedsUpdate
:
routerNeedsUpdateInit
,
}
if
url
!=
nil
{
chain
.
url
=
url
...
...
This diff is collapsed.
Click to expand it.
protocol/rpc_status.go
+
10
−
6
View file @
c1cc1138
...
...
@@ -23,6 +23,10 @@ import (
"time"
)
import
(
uberAtomic
"go.uber.org/atomic"
)
import
(
"github.com/apache/dubbo-go/common"
"github.com/apache/dubbo-go/common/constant"
...
...
@@ -30,11 +34,11 @@ import (
)
var
(
methodStatistics
sync
.
Map
// url -> { methodName : RPCStatus}
serviceStatistic
sync
.
Map
// url -> RPCStatus
invokerBlackList
sync
.
Map
// store unhealthy url blackList
blackListCacheDirty
a
tomic
.
Value
// store if the cache in chain is not refreshed by blacklist
blackListRefreshing
int32
// store if the refresing method is processing
methodStatistics
sync
.
Map
// url -> { methodName : RPCStatus}
serviceStatistic
sync
.
Map
// url -> RPCStatus
invokerBlackList
sync
.
Map
// store unhealthy url blackList
blackListCacheDirty
uberA
tomic
.
Bool
// store if the cache in chain is not refreshed by blacklist
blackListRefreshing
int32
// store if the refresing method is processing
)
func
init
()
{
...
...
@@ -237,7 +241,7 @@ func RemoveUrlKeyUnhealthyStatus(key string) {
func
GetAndRefreshState
()
bool
{
state
:=
blackListCacheDirty
.
Load
()
blackListCacheDirty
.
Store
(
false
)
return
state
.
(
bool
)
return
state
}
// TryRefreshBlackList start 3 gr to check at most block=16 invokers in black list
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment