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
b8150706
Commit
b8150706
authored
5 years ago
by
xg.gao
Browse files
Options
Downloads
Patches
Plain Diff
code clean
parent
ff9eec75
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
remoting/zookeeper/client.go
+16
-31
16 additions, 31 deletions
remoting/zookeeper/client.go
with
16 additions
and
31 deletions
remoting/zookeeper/client.go
+
16
−
31
View file @
b8150706
...
...
@@ -42,7 +42,7 @@ const (
)
var
(
errNilZkClientConn
=
perrors
.
New
(
"zookeeperclient{conn} is nil"
)
errNilZkClientConn
=
perrors
.
New
(
"zookeeper
client{conn} is nil"
)
errNilChildren
=
perrors
.
Errorf
(
"has none children"
)
errNilNode
=
perrors
.
Errorf
(
"node does not exist"
)
)
...
...
@@ -114,12 +114,11 @@ func ValidateZookeeperClient(container zkClientFacade, opts ...Option) error {
var
(
err
error
)
opions
:=
&
Options
{}
op
t
ions
:=
&
Options
{}
for
_
,
opt
:=
range
opts
{
opt
(
opions
)
opt
(
op
t
ions
)
}
connected
:=
false
err
=
nil
lock
:=
container
.
ZkClientLock
()
url
:=
container
.
GetUrl
()
...
...
@@ -128,7 +127,7 @@ func ValidateZookeeperClient(container zkClientFacade, opts ...Option) error {
defer
lock
.
Unlock
()
if
container
.
ZkClient
()
==
nil
{
//in dubbo
,every registry only connect one node
,so this is []string{r.Address}
//
in dubbo,
every registry only connect one node,
so this is []string{r.Address}
timeout
,
err
:=
time
.
ParseDuration
(
url
.
GetParam
(
constant
.
REGISTRY_TIMEOUT_KEY
,
constant
.
DEFAULT_REG_TIMEOUT
))
if
err
!=
nil
{
logger
.
Errorf
(
"timeout config %v is invalid ,err is %v"
,
...
...
@@ -136,10 +135,10 @@ func ValidateZookeeperClient(container zkClientFacade, opts ...Option) error {
return
perrors
.
WithMessagef
(
err
,
"newZookeeperClient(address:%+v)"
,
url
.
Location
)
}
zkAddresses
:=
strings
.
Split
(
url
.
Location
,
","
)
newClient
,
err
:=
newZookeeperClient
(
opions
.
zkName
,
zkAddresses
,
timeout
)
newClient
,
err
:=
newZookeeperClient
(
op
t
ions
.
zkName
,
zkAddresses
,
timeout
)
if
err
!=
nil
{
logger
.
Warnf
(
"newZookeeperClient(name{%s}, zk address{%v}, timeout{%d}) = error{%v}"
,
opions
.
zkName
,
url
.
Location
,
timeout
.
String
(),
err
)
op
t
ions
.
zkName
,
url
.
Location
,
timeout
.
String
(),
err
)
return
perrors
.
WithMessagef
(
err
,
"newZookeeperClient(address:%+v)"
,
url
.
Location
)
}
container
.
SetZkClient
(
newClient
)
...
...
@@ -157,8 +156,8 @@ func ValidateZookeeperClient(container zkClientFacade, opts ...Option) error {
}
if
connected
{
logger
.
Info
(
"Connect to zookeeper successfully, name{%s}, zk address{%v}"
,
opions
.
zkName
,
url
.
Location
)
container
.
WaitGroup
()
.
Add
(
1
)
//zk client start successful, then registry wg +1
logger
.
Info
(
"Connect to zookeeper successfully, name{%s}, zk address{%v}"
,
op
t
ions
.
zkName
,
url
.
Location
)
container
.
WaitGroup
()
.
Add
(
1
)
//
zk client start successful, then registry wg +1
}
return
perrors
.
WithMessagef
(
err
,
"newZookeeperClient(address:%+v)"
,
url
.
PrimitiveURL
)
...
...
@@ -214,14 +213,14 @@ func NewMockZookeeperClient(name string, timeout time.Duration, opts ...Option)
eventRegistry
:
make
(
map
[
string
][]
*
chan
struct
{}),
}
opions
:=
&
Options
{}
op
t
ions
:=
&
Options
{}
for
_
,
opt
:=
range
opts
{
opt
(
opions
)
opt
(
op
t
ions
)
}
// connect to zookeeper
if
opions
.
ts
!=
nil
{
ts
=
opions
.
ts
if
op
t
ions
.
ts
!=
nil
{
ts
=
op
t
ions
.
ts
}
else
{
ts
,
err
=
zk
.
StartTestCluster
(
1
,
nil
,
nil
)
if
err
!=
nil
{
...
...
@@ -229,16 +228,10 @@ func NewMockZookeeperClient(name string, timeout time.Duration, opts ...Option)
}
}
//callbackChan := make(chan zk.Event)
//f := func(event zk.Event) {
// callbackChan <- event
//}
z
.
Conn
,
event
,
err
=
ts
.
ConnectWithOptions
(
timeout
)
if
err
!=
nil
{
return
nil
,
nil
,
nil
,
perrors
.
WithMessagef
(
err
,
"zk.Connect"
)
}
//z.wait.Add(1)
return
ts
,
z
,
event
,
nil
}
...
...
@@ -255,11 +248,10 @@ func (z *ZookeeperClient) HandleZkEvent(session <-chan zk.Event) {
logger
.
Infof
(
"zk{path:%v, name:%s} connection goroutine game over."
,
z
.
ZkAddrs
,
z
.
name
)
}()
LOOP
:
for
{
select
{
case
<-
z
.
exit
:
b
re
ak
LOOP
re
turn
case
event
=
<-
session
:
logger
.
Warnf
(
"client{%s} get a zookeeper event{type:%s, server:%s, path:%s, state:%d-%s, err:%v}"
,
z
.
name
,
event
.
Type
,
event
.
Server
,
event
.
Path
,
event
.
State
,
StateToString
(
event
.
State
),
event
.
Err
)
...
...
@@ -274,8 +266,7 @@ LOOP:
if
conn
!=
nil
{
conn
.
Close
()
}
break
LOOP
return
case
(
int
)(
zk
.
EventNodeDataChanged
),
(
int
)(
zk
.
EventNodeChildrenChanged
)
:
logger
.
Infof
(
"zkClient{%s} get zk node changed event{path:%s}"
,
z
.
name
,
event
.
Path
)
z
.
RLock
()
...
...
@@ -441,11 +432,7 @@ func (z *ZookeeperClient) CreateWithValue(basePath string, value []byte) error {
// Delete ...
func
(
z
*
ZookeeperClient
)
Delete
(
basePath
string
)
error
{
var
(
err
error
)
err
=
errNilZkClientConn
err
:=
errNilZkClientConn
conn
:=
z
.
getConn
()
if
conn
!=
nil
{
err
=
conn
.
Delete
(
basePath
,
-
1
)
...
...
@@ -464,14 +451,12 @@ func (z *ZookeeperClient) RegisterTemp(basePath string, node string) (string, er
)
err
=
errNilZkClientConn
data
=
[]
byte
(
""
)
zkPath
=
path
.
Join
(
basePath
)
+
"/"
+
node
conn
:=
z
.
getConn
()
if
conn
!=
nil
{
tmpPath
,
err
=
conn
.
Create
(
zkPath
,
data
,
zk
.
FlagEphemeral
,
zk
.
WorldACL
(
zk
.
PermAll
))
tmpPath
,
err
=
conn
.
Create
(
zkPath
,
[]
byte
(
""
)
,
zk
.
FlagEphemeral
,
zk
.
WorldACL
(
zk
.
PermAll
))
}
//if err != nil && err != zk.ErrNodeExists {
if
err
!=
nil
{
logger
.
Warnf
(
"conn.Create(
\"
%s
\"
, zk.FlagEphemeral) = error(%v)
\n
"
,
zkPath
,
perrors
.
WithStack
(
err
))
return
zkPath
,
perrors
.
WithStack
(
err
)
...
...
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