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
a2eea0b7
Commit
a2eea0b7
authored
4 years ago
by
cvictory
Browse files
Options
Downloads
Patches
Plain Diff
fix review issue: add constraint of Action value of ServiceEvent in NotifyAll func
parent
35ccd359
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
registry/directory/directory.go
+36
-23
36 additions, 23 deletions
registry/directory/directory.go
registry/registry.go
+2
-2
2 additions, 2 deletions
registry/registry.go
with
38 additions
and
25 deletions
registry/directory/directory.go
+
36
−
23
View file @
a2eea0b7
...
@@ -67,6 +67,7 @@ type RegistryDirectory struct {
...
@@ -67,6 +67,7 @@ type RegistryDirectory struct {
referenceConfigurationListener
*
referenceConfigurationListener
referenceConfigurationListener
*
referenceConfigurationListener
serviceKey
string
serviceKey
string
forbidden
atomic
.
Bool
forbidden
atomic
.
Bool
registerLock
sync
.
Mutex
// this lock if for register
}
}
// NewRegistryDirectory will create a new RegistryDirectory
// NewRegistryDirectory will create a new RegistryDirectory
...
@@ -111,6 +112,7 @@ func (dir *RegistryDirectory) Notify(event *registry.ServiceEvent) {
...
@@ -111,6 +112,7 @@ func (dir *RegistryDirectory) Notify(event *registry.ServiceEvent) {
go
dir
.
refreshInvokers
(
event
)
go
dir
.
refreshInvokers
(
event
)
}
}
// NotifyAll notify the events that are complete Service Event List.
func
(
dir
*
RegistryDirectory
)
NotifyAll
(
events
[]
*
registry
.
ServiceEvent
)
{
func
(
dir
*
RegistryDirectory
)
NotifyAll
(
events
[]
*
registry
.
ServiceEvent
)
{
go
dir
.
refreshAllInvokers
(
events
)
go
dir
.
refreshAllInvokers
(
events
)
}
}
...
@@ -129,38 +131,49 @@ func (dir *RegistryDirectory) refreshInvokers(event *registry.ServiceEvent) {
...
@@ -129,38 +131,49 @@ func (dir *RegistryDirectory) refreshInvokers(event *registry.ServiceEvent) {
}
}
// refreshAllInvokers the argument is the complete list of the service events, we can safely assume any cached invoker
// refreshAllInvokers the argument is the complete list of the service events, we can safely assume any cached invoker
// not in the incoming list can be removed.
It will ignor
e Action of serviceEvent.
// not in the incoming list can be removed.
Th
e Action of serviceEvent
should be EventTypeUpdate
.
func
(
dir
*
RegistryDirectory
)
refreshAllInvokers
(
events
[]
*
registry
.
ServiceEvent
)
{
func
(
dir
*
RegistryDirectory
)
refreshAllInvokers
(
events
[]
*
registry
.
ServiceEvent
)
{
var
(
var
(
oldInvokers
[]
protocol
.
Invoker
oldInvokers
[]
protocol
.
Invoker
addEvents
[]
*
registry
.
ServiceEvent
addEvents
[]
*
registry
.
ServiceEvent
)
)
// loop the events to check the Action should be EventTypeUpdate.
// get need clear invokers from original invoker list
dir
.
cacheInvokersMap
.
Range
(
func
(
k
,
v
interface
{})
bool
{
if
!
dir
.
eventMatched
(
k
.
(
string
),
events
)
{
// delete unused invoker from cache
if
invoker
:=
dir
.
uncacheInvokerWithKey
(
k
.
(
string
));
invoker
!=
nil
{
oldInvokers
=
append
(
oldInvokers
,
invoker
)
}
}
return
true
})
// get need add invokers from events
for
_
,
event
:=
range
events
{
for
_
,
event
:=
range
events
{
// Is the key (url.Key()) of cacheInvokersMap the best way?
if
event
.
Action
!=
remoting
.
EventTypeUpdate
{
if
_
,
ok
:=
dir
.
cacheInvokersMap
.
Load
(
event
.
Service
.
Key
());
!
ok
{
panic
(
"Your implements of register center is wrong, "
+
event
.
Action
=
remoting
.
EventType
Add
"please check the Action of ServiceEvent should be
EventType
Update"
)
addEvents
=
append
(
addEvents
,
event
)
return
}
}
}
}
// loop the addEvents
func
()
{
for
_
,
event
:=
range
addEvents
{
// this lock is work at batch update of InvokeCache
logger
.
Debugf
(
"registry update, result{%s}"
,
event
)
dir
.
registerLock
.
Lock
()
if
oldInvoker
,
_
:=
dir
.
cacheInvokerByEvent
(
event
);
oldInvoker
!=
nil
{
defer
dir
.
registerLock
.
Unlock
()
oldInvokers
=
append
(
oldInvokers
,
oldInvoker
)
// get need clear invokers from original invoker list
dir
.
cacheInvokersMap
.
Range
(
func
(
k
,
v
interface
{})
bool
{
if
!
dir
.
eventMatched
(
k
.
(
string
),
events
)
{
// delete unused invoker from cache
if
invoker
:=
dir
.
uncacheInvokerWithKey
(
k
.
(
string
));
invoker
!=
nil
{
oldInvokers
=
append
(
oldInvokers
,
invoker
)
}
}
return
true
})
// get need add invokers from events
for
_
,
event
:=
range
events
{
// Is the key (url.Key()) of cacheInvokersMap the best way?
if
_
,
ok
:=
dir
.
cacheInvokersMap
.
Load
(
event
.
Service
.
Key
());
!
ok
{
addEvents
=
append
(
addEvents
,
event
)
}
}
}
}
// loop the updateEvents
for
_
,
event
:=
range
addEvents
{
logger
.
Debugf
(
"registry update, result{%s}"
,
event
)
if
oldInvoker
,
_
:=
dir
.
cacheInvokerByEvent
(
event
);
oldInvoker
!=
nil
{
oldInvokers
=
append
(
oldInvokers
,
oldInvoker
)
}
}
}()
dir
.
setNewInvokers
()
dir
.
setNewInvokers
()
// destroy unused invokers
// destroy unused invokers
for
_
,
invoker
:=
range
oldInvokers
{
for
_
,
invoker
:=
range
oldInvokers
{
...
...
This diff is collapsed.
Click to expand it.
registry/registry.go
+
2
−
2
View file @
a2eea0b7
...
@@ -73,8 +73,8 @@ type NotifyListener interface {
...
@@ -73,8 +73,8 @@ type NotifyListener interface {
// passed in, then it's a incremental event. Pls. note when a list (instead of single event) comes,
// passed in, then it's a incremental event. Pls. note when a list (instead of single event) comes,
// the impl of NotifyListener may abandon the accumulated result from previous notifications.
// the impl of NotifyListener may abandon the accumulated result from previous notifications.
Notify
(
*
ServiceEvent
)
Notify
(
*
ServiceEvent
)
// Notify the events are complete Service Event List.
// Notify
All
the events are complete Service Event List.
// The argument of events []*ServiceEvent is equal to urls []*URL,
becaus
e Action of
S
erviceEvent
will be ignored
.
// The argument of events []*ServiceEvent is equal to urls []*URL,
Th
e Action of
s
erviceEvent
should be EventTypeUpdate
.
// If your registry center can only get all urls but can't get individual event, you should use this one.
// If your registry center can only get all urls but can't get individual event, you should use this one.
NotifyAll
([]
*
ServiceEvent
)
NotifyAll
([]
*
ServiceEvent
)
}
}
...
...
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