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
9ae184fe
Commit
9ae184fe
authored
4 years ago
by
邹毅贤
Browse files
Options
Downloads
Patches
Plain Diff
extract method for get zookeeper connection
parent
1d1bbe08
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
remoting/zookeeper/client.go
+20
-25
20 additions, 25 deletions
remoting/zookeeper/client.go
with
20 additions
and
25 deletions
remoting/zookeeper/client.go
+
20
−
25
View file @
9ae184fe
...
...
@@ -416,15 +416,15 @@ func (z *ZookeeperClient) CreateWithValue(basePath string, value []byte) error {
)
logger
.
Debugf
(
"zookeeperClient.Create(basePath{%s})"
,
basePath
)
conn
:=
z
.
getConn
()
err
=
errNilZkClientConn
if
conn
==
nil
{
return
perrors
.
WithMessagef
(
err
,
"zk.Create(path:%s)"
,
basePath
)
}
for
_
,
str
:=
range
strings
.
Split
(
basePath
,
"/"
)[
1
:
]
{
tmpPath
=
path
.
Join
(
tmpPath
,
"/"
,
str
)
err
=
errNilZkClientConn
z
.
RLock
()
conn
:=
z
.
Conn
z
.
RUnlock
()
if
conn
!=
nil
{
_
,
err
=
conn
.
Create
(
tmpPath
,
value
,
0
,
zk
.
WorldACL
(
zk
.
PermAll
))
}
_
,
err
=
conn
.
Create
(
tmpPath
,
value
,
0
,
zk
.
WorldACL
(
zk
.
PermAll
))
if
err
!=
nil
{
if
err
==
zk
.
ErrNodeExists
{
...
...
@@ -446,9 +446,7 @@ func (z *ZookeeperClient) Delete(basePath string) error {
)
err
=
errNilZkClientConn
z
.
RLock
()
conn
:=
z
.
Conn
z
.
RUnlock
()
conn
:=
z
.
getConn
()
if
conn
!=
nil
{
err
=
conn
.
Delete
(
basePath
,
-
1
)
}
...
...
@@ -468,9 +466,7 @@ func (z *ZookeeperClient) RegisterTemp(basePath string, node string) (string, er
err
=
errNilZkClientConn
data
=
[]
byte
(
""
)
zkPath
=
path
.
Join
(
basePath
)
+
"/"
+
node
z
.
RLock
()
conn
:=
z
.
Conn
z
.
RUnlock
()
conn
:=
z
.
getConn
()
if
conn
!=
nil
{
tmpPath
,
err
=
conn
.
Create
(
zkPath
,
data
,
zk
.
FlagEphemeral
,
zk
.
WorldACL
(
zk
.
PermAll
))
}
...
...
@@ -493,9 +489,7 @@ func (z *ZookeeperClient) RegisterTempSeq(basePath string, data []byte) (string,
)
err
=
errNilZkClientConn
z
.
RLock
()
conn
:=
z
.
Conn
z
.
RUnlock
()
conn
:=
z
.
getConn
()
if
conn
!=
nil
{
tmpPath
,
err
=
conn
.
Create
(
path
.
Join
(
basePath
)
+
"/"
,
...
...
@@ -526,9 +520,7 @@ func (z *ZookeeperClient) GetChildrenW(path string) ([]string, <-chan zk.Event,
)
err
=
errNilZkClientConn
z
.
RLock
()
conn
:=
z
.
Conn
z
.
RUnlock
()
conn
:=
z
.
getConn
()
if
conn
!=
nil
{
children
,
stat
,
watcher
,
err
=
conn
.
ChildrenW
(
path
)
}
...
...
@@ -562,9 +554,7 @@ func (z *ZookeeperClient) GetChildren(path string) ([]string, error) {
)
err
=
errNilZkClientConn
z
.
RLock
()
conn
:=
z
.
Conn
z
.
RUnlock
()
conn
:=
z
.
getConn
()
if
conn
!=
nil
{
children
,
stat
,
err
=
conn
.
Children
(
path
)
}
...
...
@@ -595,9 +585,7 @@ func (z *ZookeeperClient) ExistW(zkPath string) (<-chan zk.Event, error) {
)
err
=
errNilZkClientConn
z
.
RLock
()
conn
:=
z
.
Conn
z
.
RUnlock
()
conn
:=
z
.
getConn
()
if
conn
!=
nil
{
exist
,
_
,
watcher
,
err
=
conn
.
ExistsW
(
zkPath
)
}
...
...
@@ -618,3 +606,10 @@ func (z *ZookeeperClient) ExistW(zkPath string) (<-chan zk.Event, error) {
func
(
z
*
ZookeeperClient
)
GetContent
(
zkPath
string
)
([]
byte
,
*
zk
.
Stat
,
error
)
{
return
z
.
Conn
.
Get
(
zkPath
)
}
// getConn gets zookeeper connection safely
func
(
z
*
ZookeeperClient
)
getConn
()
*
zk
.
Conn
{
z
.
RLock
()
defer
z
.
RUnlock
()
return
z
.
Conn
}
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