Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
494f7a95
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,体验更适合开发者的 AI 搜索 >>
提交
494f7a95
编写于
6月 08, 2016
作者:
P
Pavel Kartavyy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
zookeeper-dump-tree: print tree size
上级
2416f1bd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
7 deletion
+30
-7
utils/zookeeper-dump-tree/main.cpp
utils/zookeeper-dump-tree/main.cpp
+30
-7
未找到文件。
utils/zookeeper-dump-tree/main.cpp
浏览文件 @
494f7a95
...
...
@@ -12,6 +12,8 @@ struct CallbackState
{
std
::
string
path
;
std
::
list
<
CallbackState
>::
const_iterator
it
;
std
::
list
<
std
::
list
<
CallbackState
>::
const_iterator
>
children
;
int64_t
dataLength
=
0
;
};
using
CallbackStates
=
std
::
list
<
CallbackState
>
;
...
...
@@ -19,10 +21,11 @@ CallbackStates states;
zkutil
::
ZooKeeper
*
zookeeper
;
int
running_count
=
0
;
Poco
::
Event
completed
;
void
process
(
const
CallbackState
&
state
);
void
process
(
CallbackState
&
state
);
void
callback
(
int
rc
,
...
...
@@ -30,13 +33,16 @@ void callback(
const
Stat
*
stat
,
const
void
*
data
)
{
const
CallbackState
*
state
=
reinterpret_cast
<
const
CallbackState
*>
(
data
);
CallbackState
*
state
=
reinterpret_cast
<
CallbackState
*>
(
const_cast
<
void
*>
(
data
)
);
if
(
rc
!=
ZOK
&&
rc
!=
ZNONODE
)
{
std
::
cerr
<<
zerror
(
rc
)
<<
", path: "
<<
state
->
path
<<
"
\n
"
;
}
if
(
stat
!=
nullptr
)
state
->
dataLength
=
stat
->
dataLength
;
if
(
rc
==
ZOK
&&
strings
)
{
for
(
int32_t
i
=
0
;
i
<
strings
->
count
;
++
i
)
...
...
@@ -44,23 +50,38 @@ void callback(
states
.
emplace_back
();
states
.
back
().
path
=
state
->
path
+
(
state
->
path
==
"/"
?
""
:
"/"
)
+
strings
->
data
[
i
];
states
.
back
().
it
=
--
states
.
end
();
state
->
children
.
push_back
(
states
.
back
().
it
);
std
::
cout
<<
states
.
back
().
path
<<
'\n'
;
process
(
states
.
back
());
}
}
states
.
erase
(
state
->
it
);
if
(
states
.
empty
())
--
running_count
;
if
(
running_count
==
0
)
completed
.
set
();
}
void
process
(
const
CallbackState
&
state
)
void
process
(
CallbackState
&
state
)
{
++
running_count
;
zoo_awget_children2
(
zookeeper
->
getHandle
(),
state
.
path
.
data
(),
nullptr
,
nullptr
,
callback
,
&
state
);
}
typedef
std
::
pair
<
int64_t
,
int64_t
>
NodesBytes
;
NodesBytes
printTree
(
const
CallbackState
&
state
)
{
int64_t
nodes
=
1
;
int64_t
bytes
=
state
.
dataLength
;
for
(
auto
child
:
state
.
children
)
{
NodesBytes
nodesBytes
=
printTree
(
*
child
);
nodes
+=
nodesBytes
.
first
;
bytes
+=
nodesBytes
.
second
;
}
std
::
cout
<<
state
.
path
<<
'\t'
<<
nodes
<<
'\t'
<<
bytes
<<
'\n'
;
return
NodesBytes
(
nodes
,
bytes
);
}
int
main
(
int
argc
,
char
**
argv
)
try
...
...
@@ -95,6 +116,8 @@ try
process
(
states
.
back
());
completed
.
wait
();
printTree
(
*
states
.
begin
());
}
catch
(...)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录