Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
冷面1992
TDengine
提交
d70ca0b1
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,发现更多精彩内容 >>
提交
d70ca0b1
编写于
12月 11, 2020
作者:
H
Hui Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-2292]
上级
02b50447
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
205 addition
and
98 deletion
+205
-98
src/kit/taosdump/taosdump.c
src/kit/taosdump/taosdump.c
+205
-98
未找到文件。
src/kit/taosdump/taosdump.c
浏览文件 @
d70ca0b1
...
...
@@ -14,6 +14,9 @@
*/
#include <iconv.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include "os.h"
#include "taos.h"
#include "taosdef.h"
...
...
@@ -366,6 +369,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
static
struct
argp
argp
=
{
options
,
parse_opt
,
args_doc
,
doc
};
static
resultStatistics
g_resultStatistics
=
{
0
};
static
FILE
*
g_fpOfResult
=
NULL
;
static
int
g_numOfCores
=
1
;
int
taosDumpOut
(
struct
arguments
*
arguments
);
int
taosDumpIn
(
struct
arguments
*
arguments
);
...
...
@@ -378,7 +382,7 @@ int32_t taosDumpTable(char *table, char *metric, struct arguments *arguments, FI
int
taosDumpTableData
(
FILE
*
fp
,
char
*
tbname
,
struct
arguments
*
arguments
,
TAOS
*
taosCon
,
char
*
dbName
);
int
taosCheckParam
(
struct
arguments
*
arguments
);
void
taosFreeDbInfos
();
static
void
taosStartDumpOutWorkThreads
(
struct
arguments
*
args
,
int32_t
numOfThread
,
char
*
dbName
);
static
void
taosStartDumpOutWorkThreads
(
void
*
taosCon
,
struct
arguments
*
args
,
int32_t
numOfThread
,
char
*
dbName
);
struct
arguments
tsArguments
=
{
// connection option
...
...
@@ -540,6 +544,8 @@ int main(int argc, char *argv[]) {
}
}
g_numOfCores
=
(
int32_t
)
sysconf
(
_SC_NPROCESSORS_ONLN
);
time_t
tTime
=
time
(
NULL
);
struct
tm
tm
=
*
localtime
(
&
tTime
);
...
...
@@ -692,64 +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
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
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
;
}
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
>=
arguments
->
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
;
}
...
...
@@ -946,7 +985,7 @@ int taosDumpOut(struct arguments *arguments) {
}
// start multi threads to dumpout
taosStartDumpOutWorkThreads
(
arguments
,
totalNumOfThread
,
dbInfos
[
0
]
->
name
);
taosStartDumpOutWorkThreads
(
taos
,
arguments
,
totalNumOfThread
,
dbInfos
[
0
]
->
name
);
char
tmpFileName
[
TSDB_FILENAME_LEN
+
1
];
_clean_tmp_file:
...
...
@@ -1181,34 +1220,34 @@ void* taosDumpOutWorkThreadFp(void *arg)
STableRecord
tableRecord
;
int
fd
;
char
tmp
FileName
[
TSDB_FILENAME_LEN
*
4
]
=
{
0
};
sprintf
(
tmp
FileName
,
".tables.tmp.%d"
,
pThread
->
threadIndex
);
fd
=
open
(
tmp
FileName
,
O_RDWR
|
O_CREAT
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
char
tmp
Buf
[
TSDB_FILENAME_LEN
*
4
]
=
{
0
};
sprintf
(
tmp
Buf
,
".tables.tmp.%d"
,
pThread
->
threadIndex
);
fd
=
open
(
tmp
Buf
,
O_RDWR
|
O_CREAT
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
if
(
fd
==
-
1
)
{
fprintf
(
stderr
,
"taosDumpTableFp() failed to open temp file: %s
\n
"
,
tmp
FileName
);
fprintf
(
stderr
,
"taosDumpTableFp() failed to open temp file: %s
\n
"
,
tmp
Buf
);
return
NULL
;
}
FILE
*
fp
=
NULL
;
memset
(
tmp
FileName
,
0
,
TSDB_FILENAME_LEN
+
128
);
memset
(
tmp
Buf
,
0
,
TSDB_FILENAME_LEN
+
128
);
if
(
tsArguments
.
outpath
[
0
]
!=
0
)
{
sprintf
(
tmp
FileName
,
"%s/%s.tables.%d.sql"
,
tsArguments
.
outpath
,
pThread
->
dbName
,
pThread
->
threadIndex
);
sprintf
(
tmp
Buf
,
"%s/%s.tables.%d.sql"
,
tsArguments
.
outpath
,
pThread
->
dbName
,
pThread
->
threadIndex
);
}
else
{
sprintf
(
tmp
FileName
,
"%s.tables.%d.sql"
,
pThread
->
dbName
,
pThread
->
threadIndex
);
sprintf
(
tmp
Buf
,
"%s.tables.%d.sql"
,
pThread
->
dbName
,
pThread
->
threadIndex
);
}
fp
=
fopen
(
tmp
FileName
,
"w"
);
fp
=
fopen
(
tmp
Buf
,
"w"
);
if
(
fp
==
NULL
)
{
fprintf
(
stderr
,
"failed to open file %s
\n
"
,
tmp
FileName
);
fprintf
(
stderr
,
"failed to open file %s
\n
"
,
tmp
Buf
);
close
(
fd
);
return
NULL
;
}
memset
(
tmp
FileName
,
0
,
TSDB_FILENAME_LEN
);
sprintf
(
tmp
FileName
,
"use %s"
,
pThread
->
dbName
);
memset
(
tmp
Buf
,
0
,
TSDB_FILENAME_LEN
);
sprintf
(
tmp
Buf
,
"use %s"
,
pThread
->
dbName
);
TAOS_RES
*
tmpResult
=
taos_query
(
pThread
->
taosCon
,
tmp
FileName
);
TAOS_RES
*
tmpResult
=
taos_query
(
pThread
->
taosCon
,
tmp
Buf
);
int32_t
code
=
taos_errno
(
tmpResult
);
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"invalid database %s
\n
"
,
pThread
->
dbName
);
...
...
@@ -1218,6 +1257,9 @@ void* taosDumpOutWorkThreadFp(void *arg)
return
NULL
;
}
int
fileNameIndex
=
1
;
int
tablesInOneFile
=
0
;
int64_t
lastRowsPrint
=
5000000
;
fprintf
(
fp
,
"USE %s;
\n\n
"
,
pThread
->
dbName
);
while
(
1
)
{
ssize_t
readLen
=
read
(
fd
,
&
tableRecord
,
sizeof
(
STableRecord
));
...
...
@@ -1228,6 +1270,33 @@ void* taosDumpOutWorkThreadFp(void *arg)
// TODO: sum table count and table rows by self
pThread
->
tablesOfDumpOut
++
;
pThread
->
rowsOfDumpOut
+=
ret
;
if
(
pThread
->
rowsOfDumpOut
>=
lastRowsPrint
)
{
printf
(
" %"
PRId64
" rows already be dumpout from database %s
\n
"
,
pThread
->
rowsOfDumpOut
,
pThread
->
dbName
);
lastRowsPrint
+=
5000000
;
}
tablesInOneFile
++
;
if
(
tablesInOneFile
>=
tsArguments
.
table_batch
)
{
fclose
(
fp
);
tablesInOneFile
=
0
;
memset
(
tmpBuf
,
0
,
TSDB_FILENAME_LEN
+
128
);
if
(
tsArguments
.
outpath
[
0
]
!=
0
)
{
sprintf
(
tmpBuf
,
"%s/%s.tables.%d-%d.sql"
,
tsArguments
.
outpath
,
pThread
->
dbName
,
pThread
->
threadIndex
,
fileNameIndex
);
}
else
{
sprintf
(
tmpBuf
,
"%s.tables.%d-%d.sql"
,
pThread
->
dbName
,
pThread
->
threadIndex
,
fileNameIndex
);
}
fileNameIndex
++
;
fp
=
fopen
(
tmpBuf
,
"w"
);
if
(
fp
==
NULL
)
{
fprintf
(
stderr
,
"failed to open file %s
\n
"
,
tmpBuf
);
close
(
fd
);
taos_free_result
(
tmpResult
);
return
NULL
;
}
}
}
}
...
...
@@ -1238,7 +1307,7 @@ void* taosDumpOutWorkThreadFp(void *arg)
return
NULL
;
}
static
void
taosStartDumpOutWorkThreads
(
struct
arguments
*
args
,
int32_t
numOfThread
,
char
*
dbName
)
static
void
taosStartDumpOutWorkThreads
(
void
*
taosCon
,
struct
arguments
*
args
,
int32_t
numOfThread
,
char
*
dbName
)
{
pthread_attr_t
thattr
;
SThreadParaObj
*
threadObj
=
(
SThreadParaObj
*
)
calloc
(
numOfThread
,
sizeof
(
SThreadParaObj
));
...
...
@@ -1249,12 +1318,7 @@ static void taosStartDumpOutWorkThreads(struct arguments* args, int32_t numOfTh
pThread
->
threadIndex
=
t
;
pThread
->
totalThreads
=
numOfThread
;
tstrncpy
(
pThread
->
dbName
,
dbName
,
TSDB_TABLE_NAME_LEN
);
pThread
->
taosCon
=
taos_connect
(
args
->
host
,
args
->
user
,
args
->
password
,
NULL
,
args
->
port
);
if
(
pThread
->
taosCon
==
NULL
)
{
fprintf
(
stderr
,
"ERROR: thread:%d failed connect to TDengine, reason:%s
\n
"
,
pThread
->
threadIndex
,
taos_errstr
(
NULL
));
exit
(
0
);
}
pThread
->
taosCon
=
taosCon
;
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
...
...
@@ -1273,7 +1337,6 @@ static void taosStartDumpOutWorkThreads(struct arguments* args, int32_t numOfTh
int64_t
totalRowsOfDumpOut
=
0
;
int64_t
totalChildTblsOfDumpOut
=
0
;
for
(
int32_t
t
=
0
;
t
<
numOfThread
;
++
t
)
{
taos_close
(
threadObj
[
t
].
taosCon
);
totalChildTblsOfDumpOut
+=
threadObj
[
t
].
tablesOfDumpOut
;
totalRowsOfDumpOut
+=
threadObj
[
t
].
rowsOfDumpOut
;
}
...
...
@@ -1398,44 +1461,81 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
return
-
1
;
}
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
res
);
int32_t
numOfTable
=
0
;
int32_t
numOfThread
=
0
;
char
tmpFileName
[
TSDB_FILENAME_LEN
+
1
];
while
((
row
=
taos_fetch_row
(
res
))
!=
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
(
res
);
for
(
int32_t
loopCnt
=
0
;
loopCnt
<
numOfThread
;
loopCnt
++
)
{
sprintf
(
tmpFileName
,
".tables.tmp.%d"
,
loopCnt
);
(
void
)
remove
(
tmpFileName
);
}
return
-
1
;
}
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
;
}
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
[
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
);
if
(
numOfTable
>=
arguments
->
table_batch
)
{
numOfTable
=
0
;
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
;
}
}
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
;
...
...
@@ -1444,10 +1544,10 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
taos_free_result
(
res
);
// start multi threads to dumpout
taosStartDumpOutWorkThreads
(
arguments
,
numOfThread
,
dbInfo
->
name
);
taosStartDumpOutWorkThreads
(
taosCon
,
arguments
,
numOfThread
,
dbInfo
->
name
);
for
(
int
loopCnt
=
0
;
loopCnt
<
numOfThread
;
loopCnt
++
)
{
sprintf
(
tmp
FileName
,
".tables.tmp.%d"
,
loopCnt
);
(
void
)
remove
(
tmp
FileName
);
sprintf
(
tmp
Buf
,
".tables.tmp.%d"
,
loopCnt
);
(
void
)
remove
(
tmp
Buf
);
}
return
0
;
...
...
@@ -1552,8 +1652,8 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols
}
int
taosDumpTableData
(
FILE
*
fp
,
char
*
tbname
,
struct
arguments
*
arguments
,
TAOS
*
taosCon
,
char
*
dbName
)
{
/* char temp[MAX_COMMAND_SIZE] = "\0"; */
int64_t
totalRows
=
0
;
int64_t
lastRowsPrint
=
5000000
;
int64_t
totalRows
=
0
;
int
count
=
0
;
char
*
pstr
=
NULL
;
TAOS_ROW
row
=
NULL
;
...
...
@@ -1680,9 +1780,14 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
curr_sqlstr_len
+=
sprintf
(
pstr
+
curr_sqlstr_len
,
") "
);
totalRows
++
;
totalRows
++
;
count
++
;
fprintf
(
fp
,
"%s"
,
tmpBuffer
);
if
(
totalRows
>=
lastRowsPrint
)
{
printf
(
" %"
PRId64
" rows already be dumpout from %s.%s
\n
"
,
totalRows
,
dbName
,
tbname
);
lastRowsPrint
+=
5000000
;
}
total_sqlstr_len
+=
curr_sqlstr_len
;
...
...
@@ -2048,6 +2153,7 @@ int taosDumpInOneFile(TAOS * taos, FILE* fp, char* fcharset, char* encode, c
return
-
1
;
}
int
lastRowsPrint
=
5000000
;
int
lineNo
=
0
;
while
((
read_len
=
getline
(
&
line
,
&
line_len
,
fp
))
!=
-
1
)
{
++
lineNo
;
...
...
@@ -2074,7 +2180,12 @@ int taosDumpInOneFile(TAOS * taos, FILE* fp, char* fcharset, char* encode, c
}
memset
(
cmd
,
0
,
TSDB_MAX_ALLOWED_SQL_LEN
);
cmd_len
=
0
;
cmd_len
=
0
;
if
(
lineNo
>=
lastRowsPrint
)
{
printf
(
" %d lines already be executed from file %s
\n
"
,
lineNo
,
fileName
);
lastRowsPrint
+=
5000000
;
}
}
tfree
(
cmd
);
...
...
@@ -2101,7 +2212,7 @@ void* taosDumpInWorkThreadFp(void *arg)
return
NULL
;
}
static
void
taosStartDumpInWorkThreads
(
struct
arguments
*
args
)
static
void
taosStartDumpInWorkThreads
(
void
*
taosCon
,
struct
arguments
*
args
)
{
pthread_attr_t
thattr
;
SThreadParaObj
*
pThread
;
...
...
@@ -2116,11 +2227,7 @@ static void taosStartDumpInWorkThreads(struct arguments *args)
pThread
=
threadObj
+
t
;
pThread
->
threadIndex
=
t
;
pThread
->
totalThreads
=
totalThreads
;
pThread
->
taosCon
=
taos_connect
(
args
->
host
,
args
->
user
,
args
->
password
,
NULL
,
args
->
port
);
if
(
pThread
->
taosCon
==
NULL
)
{
fprintf
(
stderr
,
"ERROR: thread:%d failed connect to TDengine, reason:%s
\n
"
,
pThread
->
threadIndex
,
taos_errstr
(
NULL
));
exit
(
0
);
}
pThread
->
taosCon
=
taosCon
;
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
...
...
@@ -2169,7 +2276,7 @@ int taosDumpIn(struct arguments *arguments) {
taosDumpInOneFile
(
taos
,
fp
,
tsfCharset
,
arguments
->
encode
,
tsDbSqlFile
);
}
taosStartDumpInWorkThreads
(
arguments
);
taosStartDumpInWorkThreads
(
taos
,
arguments
);
taos_close
(
taos
);
taosFreeSQLFiles
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录