Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冷面1992
TDengine
提交
297ec49a
TDengine
项目概览
冷面1992
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
297ec49a
编写于
12月 11, 2020
作者:
H
huili
提交者:
GitHub
12月 11, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4543 from taosdata/hotfix/test
Hotfix/test
上级
070d3aa8
2f5967d5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
126 addition
and
85 deletion
+126
-85
src/kit/taosdump/taosdump.c
src/kit/taosdump/taosdump.c
+126
-85
未找到文件。
src/kit/taosdump/taosdump.c
浏览文件 @
297ec49a
...
...
@@ -698,79 +698,97 @@ int32_t taosSaveTableOfMetricToTempFile(TAOS *taosCon, char* metric, struct argu
sprintf
(
tmpCommand
,
"select tbname from %s"
,
metric
);
TAOS_RES
*
res
ult
=
taos_query
(
taosCon
,
tmpCommand
);
int32_t
code
=
taos_errno
(
res
ult
);
TAOS_RES
*
res
=
taos_query
(
taosCon
,
tmpCommand
);
int32_t
code
=
taos_errno
(
res
);
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"failed to run command %s
\n
"
,
tmpCommand
);
free
(
tmpCommand
);
taos_free_result
(
res
ult
);
taos_free_result
(
res
);
return
-
1
;
}
free
(
tmpCommand
);
int
table_batch
=
arguments
->
table_batch
;
int
affectdRows
=
taos_affected_rows
(
result
);
if
(
affectdRows
<=
0
)
{
free
(
tmpCommand
);
taos_free_result
(
result
);
char
tmpBuf
[
TSDB_FILENAME_LEN
+
1
];
memset
(
tmpBuf
,
0
,
TSDB_FILENAME_LEN
);
sprintf
(
tmpBuf
,
".select-tbname.tmp"
);
fd
=
open
(
tmpBuf
,
O_RDWR
|
O_CREAT
|
O_TRUNC
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
if
(
fd
==
-
1
)
{
fprintf
(
stderr
,
"failed to open temp file: %s
\n
"
,
tmpBuf
);
taos_free_result
(
res
);
return
-
1
;
}
int
maxNumOfThread
=
affectdRows
/
table_batch
+
1
;
if
(
maxNumOfThread
>
2
*
g_numOfCores
)
{
maxNumOfThread
=
2
*
g_numOfCores
;
}
table_batch
=
affectdRows
/
maxNumOfThread
+
1
;
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
result
);
int32_t
numOfTable
=
0
;
int32_t
numOfThread
=
*
totalNumOfThread
;
char
tmpFileName
[
TSDB_FILENAME_LEN
+
1
];
while
((
row
=
taos_fetch_row
(
result
))
!=
NULL
)
{
if
(
0
==
numOfTable
)
{
memset
(
tmpFileName
,
0
,
TSDB_FILENAME_LEN
);
sprintf
(
tmpFileName
,
".tables.tmp.%d"
,
numOfThread
);
fd
=
open
(
tmpFileName
,
O_RDWR
|
O_CREAT
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
if
(
fd
==
-
1
)
{
fprintf
(
stderr
,
"failed to open temp file: %s
\n
"
,
tmpFileName
);
taos_free_result
(
result
);
for
(
int32_t
loopCnt
=
0
;
loopCnt
<
numOfThread
;
loopCnt
++
)
{
sprintf
(
tmpFileName
,
".tables.tmp.%d"
,
loopCnt
);
(
void
)
remove
(
tmpFileName
);
}
free
(
tmpCommand
);
return
-
1
;
}
numOfThread
++
;
}
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
res
);
int32_t
numOfTable
=
0
;
while
((
row
=
taos_fetch_row
(
res
))
!=
NULL
)
{
memset
(
&
tableRecord
,
0
,
sizeof
(
STableRecord
));
tstrncpy
(
tableRecord
.
name
,
(
char
*
)
row
[
0
],
fields
[
0
].
bytes
);
tstrncpy
(
tableRecord
.
metric
,
metric
,
TSDB_TABLE_NAME_LEN
);
taosWrite
(
fd
,
&
tableRecord
,
sizeof
(
STableRecord
));
taosWrite
(
fd
,
&
tableRecord
,
sizeof
(
STableRecord
));
numOfTable
++
;
}
taos_free_result
(
res
);
lseek
(
fd
,
0
,
SEEK_SET
);
int
maxThreads
=
arguments
->
thread_num
;
int
tableOfPerFile
;
if
(
numOfTable
<=
arguments
->
thread_num
)
{
tableOfPerFile
=
1
;
maxThreads
=
numOfTable
;
}
else
{
tableOfPerFile
=
numOfTable
/
arguments
->
thread_num
;
if
(
0
!=
numOfTable
%
arguments
->
thread_num
)
{
tableOfPerFile
+=
1
;
}
}
if
(
numOfTable
>=
table_batch
)
{
numOfTable
=
0
;
char
*
tblBuf
=
(
char
*
)
calloc
(
1
,
tableOfPerFile
*
sizeof
(
STableRecord
));
if
(
NULL
==
tblBuf
){
fprintf
(
stderr
,
"failed to calloc %"
PRIzu
"
\n
"
,
tableOfPerFile
*
sizeof
(
STableRecord
));
close
(
fd
);
return
-
1
;
}
int32_t
numOfThread
=
*
totalNumOfThread
;
int
subFd
=
-
1
;
for
(;
numOfThread
<
maxThreads
;
numOfThread
++
)
{
memset
(
tmpBuf
,
0
,
TSDB_FILENAME_LEN
);
sprintf
(
tmpBuf
,
".tables.tmp.%d"
,
numOfThread
);
subFd
=
open
(
tmpBuf
,
O_RDWR
|
O_CREAT
|
O_TRUNC
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
if
(
subFd
==
-
1
)
{
fprintf
(
stderr
,
"failed to open temp file: %s
\n
"
,
tmpBuf
);
for
(
int32_t
loopCnt
=
0
;
loopCnt
<
numOfThread
;
loopCnt
++
)
{
sprintf
(
tmpBuf
,
".tables.tmp.%d"
,
loopCnt
);
(
void
)
remove
(
tmpBuf
);
}
sprintf
(
tmpBuf
,
".select-tbname.tmp"
);
(
void
)
remove
(
tmpBuf
);
close
(
fd
);
fd
=
-
1
;
return
-
1
;
}
// read tableOfPerFile for fd, write to subFd
ssize_t
readLen
=
read
(
fd
,
tblBuf
,
tableOfPerFile
*
sizeof
(
STableRecord
));
if
(
readLen
<=
0
)
{
close
(
subFd
);
break
;
}
taosWrite
(
subFd
,
tblBuf
,
readLen
);
close
(
subFd
);
}
sprintf
(
tmpBuf
,
".select-tbname.tmp"
);
(
void
)
remove
(
tmpBuf
);
if
(
fd
>=
0
)
{
close
(
fd
);
fd
=
-
1
;
}
taos_free_result
(
result
);
}
*
totalNumOfThread
=
numOfThread
;
free
(
tmpCommand
);
return
0
;
}
...
...
@@ -1443,58 +1461,81 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
return
-
1
;
}
int
table_batch
=
arguments
->
table_batch
;
int
affectdRows
=
taos_affected_rows
(
res
);
if
(
affectdRows
<=
0
)
{
char
tmpBuf
[
TSDB_FILENAME_LEN
+
1
];
memset
(
tmpBuf
,
0
,
TSDB_FILENAME_LEN
);
sprintf
(
tmpBuf
,
".show-tables.tmp"
);
fd
=
open
(
tmpBuf
,
O_RDWR
|
O_CREAT
|
O_TRUNC
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
if
(
fd
==
-
1
)
{
fprintf
(
stderr
,
"failed to open temp file: %s
\n
"
,
tmpBuf
);
taos_free_result
(
res
);
return
-
1
;
}
int
maxNumOfThread
=
affectdRows
/
table_batch
+
1
;
if
(
maxNumOfThread
>
2
*
g_numOfCores
)
{
maxNumOfThread
=
2
*
g_numOfCores
;
}
table_batch
=
affectdRows
/
maxNumOfThread
+
1
;
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
res
);
int32_t
numOfTable
=
0
;
int32_t
numOfThread
=
0
;
char
tmpBuf
[
TSDB_FILENAME_LEN
+
1
];
while
((
row
=
taos_fetch_row
(
res
))
!=
NULL
)
{
if
(
0
==
numOfTable
)
{
memset
(
tmpBuf
,
0
,
TSDB_FILENAME_LEN
);
sprintf
(
tmpBuf
,
".tables.tmp.%d"
,
numOfThread
);
fd
=
open
(
tmpBuf
,
O_RDWR
|
O_CREAT
|
O_TRUNC
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
if
(
fd
==
-
1
)
{
fprintf
(
stderr
,
"failed to open temp file: %s
\n
"
,
tmpBuf
);
taos_free_result
(
res
);
for
(
int32_t
loopCnt
=
0
;
loopCnt
<
numOfThread
;
loopCnt
++
)
{
sprintf
(
tmpBuf
,
".tables.tmp.%d"
,
loopCnt
);
(
void
)
remove
(
tmpBuf
);
}
return
-
1
;
}
numOfThread
++
;
}
int32_t
numOfTable
=
0
;
while
((
row
=
taos_fetch_row
(
res
))
!=
NULL
)
{
memset
(
&
tableRecord
,
0
,
sizeof
(
STableRecord
));
tstrncpy
(
tableRecord
.
name
,
(
char
*
)
row
[
TSDB_SHOW_TABLES_NAME_INDEX
],
fields
[
TSDB_SHOW_TABLES_NAME_INDEX
].
bytes
);
tstrncpy
(
tableRecord
.
metric
,
(
char
*
)
row
[
TSDB_SHOW_TABLES_METRIC_INDEX
],
fields
[
TSDB_SHOW_TABLES_METRIC_INDEX
].
bytes
);
taosWrite
(
fd
,
&
tableRecord
,
sizeof
(
STableRecord
));
numOfTable
++
;
}
taos_free_result
(
res
);
lseek
(
fd
,
0
,
SEEK_SET
);
int
maxThreads
=
tsArguments
.
thread_num
;
int
tableOfPerFile
;
if
(
numOfTable
<=
tsArguments
.
thread_num
)
{
tableOfPerFile
=
1
;
maxThreads
=
numOfTable
;
}
else
{
tableOfPerFile
=
numOfTable
/
tsArguments
.
thread_num
;
if
(
0
!=
numOfTable
%
tsArguments
.
thread_num
)
{
tableOfPerFile
+=
1
;
}
}
if
(
numOfTable
>=
table_batch
)
{
numOfTable
=
0
;
char
*
tblBuf
=
(
char
*
)
calloc
(
1
,
tableOfPerFile
*
sizeof
(
STableRecord
));
if
(
NULL
==
tblBuf
){
fprintf
(
stderr
,
"failed to calloc %"
PRIzu
"
\n
"
,
tableOfPerFile
*
sizeof
(
STableRecord
));
close
(
fd
);
return
-
1
;
}
int32_t
numOfThread
=
0
;
int
subFd
=
-
1
;
for
(
numOfThread
=
0
;
numOfThread
<
maxThreads
;
numOfThread
++
)
{
memset
(
tmpBuf
,
0
,
TSDB_FILENAME_LEN
);
sprintf
(
tmpBuf
,
".tables.tmp.%d"
,
numOfThread
);
subFd
=
open
(
tmpBuf
,
O_RDWR
|
O_CREAT
|
O_TRUNC
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
if
(
subFd
==
-
1
)
{
fprintf
(
stderr
,
"failed to open temp file: %s
\n
"
,
tmpBuf
);
for
(
int32_t
loopCnt
=
0
;
loopCnt
<
numOfThread
;
loopCnt
++
)
{
sprintf
(
tmpBuf
,
".tables.tmp.%d"
,
loopCnt
);
(
void
)
remove
(
tmpBuf
);
}
sprintf
(
tmpBuf
,
".show-tables.tmp"
);
(
void
)
remove
(
tmpBuf
);
close
(
fd
);
fd
=
-
1
;
return
-
1
;
}
// read tableOfPerFile for fd, write to subFd
ssize_t
readLen
=
read
(
fd
,
tblBuf
,
tableOfPerFile
*
sizeof
(
STableRecord
));
if
(
readLen
<=
0
)
{
close
(
subFd
);
break
;
}
taosWrite
(
subFd
,
tblBuf
,
readLen
);
close
(
subFd
);
}
sprintf
(
tmpBuf
,
".show-tables.tmp"
);
(
void
)
remove
(
tmpBuf
);
if
(
fd
>=
0
)
{
close
(
fd
);
fd
=
-
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录