Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
412a54e3
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
412a54e3
编写于
9月 30, 2020
作者:
A
alexey-milovidov
提交者:
GitHub
9月 30, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14693 from hustnn/zk_exist_fix2
Fix potential memory leak caused by zookeeper exist calling
上级
b6bccfc4
a7024134
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
42 addition
and
6 deletion
+42
-6
src/Common/ZooKeeper/ZooKeeper.cpp
src/Common/ZooKeeper/ZooKeeper.cpp
+4
-3
src/Common/ZooKeeper/ZooKeeperImpl.cpp
src/Common/ZooKeeper/ZooKeeperImpl.cpp
+36
-2
src/Storages/MergeTree/LeaderElection.h
src/Storages/MergeTree/LeaderElection.h
+2
-1
未找到文件。
src/Common/ZooKeeper/ZooKeeper.cpp
浏览文件 @
412a54e3
...
...
@@ -663,7 +663,7 @@ bool ZooKeeper::waitForDisappear(const std::string & path, const WaitCondition &
{
WaitForDisappearStatePtr
state
=
std
::
make_shared
<
WaitForDisappearState
>
();
auto
callback
=
[
state
](
const
Coordination
::
Exists
Response
&
response
)
auto
callback
=
[
state
](
const
Coordination
::
Get
Response
&
response
)
{
state
->
code
=
int32_t
(
response
.
error
);
if
(
state
->
code
)
...
...
@@ -683,8 +683,9 @@ bool ZooKeeper::waitForDisappear(const std::string & path, const WaitCondition &
while
(
!
condition
||
!
condition
())
{
/// NOTE: if the node doesn't exist, the watch will leak.
impl
->
exists
(
path
,
callback
,
watch
);
/// Use getData insteand of exists to avoid watch leak.
impl
->
get
(
path
,
callback
,
watch
);
if
(
!
condition
)
state
->
event
.
wait
();
else
if
(
!
state
->
event
.
tryWait
(
1000
))
...
...
src/Common/ZooKeeper/ZooKeeperImpl.cpp
浏览文件 @
412a54e3
...
...
@@ -422,6 +422,18 @@ void ZooKeeperRequest::write(WriteBuffer & out) const
}
static
void
removeRootPath
(
String
&
path
,
const
String
&
root_path
)
{
if
(
root_path
.
empty
())
return
;
if
(
path
.
size
()
<=
root_path
.
size
())
throw
Exception
(
"Received path is not longer than root_path"
,
Error
::
ZDATAINCONSISTENCY
);
path
=
path
.
substr
(
root_path
.
size
());
}
struct
ZooKeeperResponse
:
virtual
Response
{
virtual
~
ZooKeeperResponse
()
override
=
default
;
...
...
@@ -1092,8 +1104,6 @@ void ZooKeeper::sendThread()
{
info
.
request
->
has_watch
=
true
;
CurrentMetrics
::
add
(
CurrentMetrics
::
ZooKeeperWatch
);
std
::
lock_guard
lock
(
watches_mutex
);
watches
[
info
.
request
->
getPath
()].
emplace_back
(
std
::
move
(
info
.
watch
));
}
if
(
expired
)
...
...
@@ -1278,6 +1288,30 @@ void ZooKeeper::receiveEvent()
response
->
removeRootPath
(
root_path
);
}
/// Instead of setting the watch in sendEvent, set it in receiveEvent becuase need to check the response.
/// The watch shouldn't be set if the node does not exist and it will never exist like sequential ephemeral nodes.
/// By using getData() instead of exists(), a watch won't be set if the node doesn't exist.
if
(
request_info
.
watch
)
{
bool
add_watch
=
false
;
/// 3 indicates the ZooKeeperExistsRequest.
// For exists, we set the watch on both node exist and nonexist case.
// For other case like getData, we only set the watch when node exists.
if
(
request_info
.
request
->
getOpNum
()
==
3
)
add_watch
=
(
response
->
error
==
Error
::
ZOK
||
response
->
error
==
Error
::
ZNONODE
);
else
add_watch
=
response
->
error
==
Error
::
ZOK
;
if
(
add_watch
)
{
/// The key of wathces should exclude the root_path
String
req_path
=
request_info
.
request
->
getPath
();
removeRootPath
(
req_path
,
root_path
);
std
::
lock_guard
lock
(
watches_mutex
);
watches
[
req_path
].
emplace_back
(
std
::
move
(
request_info
.
watch
));
}
}
int32_t
actual_length
=
in
->
count
()
-
count_before_event
;
if
(
length
!=
actual_length
)
throw
Exception
(
"Response length doesn't match. Expected: "
+
toString
(
length
)
+
", actual: "
+
toString
(
actual_length
),
Error
::
ZMARSHALLINGERROR
);
...
...
src/Storages/MergeTree/LeaderElection.h
浏览文件 @
412a54e3
...
...
@@ -124,7 +124,8 @@ private:
/// Watch for the node in front of us.
--
my_node_it
;
if
(
!
zookeeper
.
existsWatch
(
path
+
"/"
+
*
my_node_it
,
nullptr
,
task
->
getWatchCallback
()))
std
::
string
get_path_value
;
if
(
!
zookeeper
.
tryGetWatch
(
path
+
"/"
+
*
my_node_it
,
get_path_value
,
nullptr
,
task
->
getWatchCallback
()))
task
->
schedule
();
success
=
true
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录