Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3adbf1a7
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3adbf1a7
编写于
12月 09, 2020
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/develop' into feature/wal
上级
e7201c63
bba3cf88
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
398 addition
and
424 deletion
+398
-424
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+3
-0
src/client/src/tscProfile.c
src/client/src/tscProfile.c
+5
-0
src/client/src/tscStream.c
src/client/src/tscStream.c
+4
-0
src/cq/src/cqMain.c
src/cq/src/cqMain.c
+9
-4
src/cq/test/cqtest.c
src/cq/test/cqtest.c
+1
-1
src/inc/taosmsg.h
src/inc/taosmsg.h
+1
-0
src/inc/tcq.h
src/inc/tcq.h
+1
-1
src/inc/tsdb.h
src/inc/tsdb.h
+1
-1
src/kit/taosdump/taosdump.c
src/kit/taosdump/taosdump.c
+306
-409
src/mnode/src/mnodeProfile.c
src/mnode/src/mnodeProfile.c
+10
-0
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+1
-1
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+1
-1
tests/pytest/fulltest.sh
tests/pytest/fulltest.sh
+7
-3
tests/pytest/pytest_1.sh
tests/pytest/pytest_1.sh
+7
-3
tests/pytest/table/createTableFromAnotherDb.py
tests/pytest/table/createTableFromAnotherDb.py
+41
-0
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
3adbf1a7
...
@@ -382,6 +382,7 @@ typedef struct SSqlObj {
...
@@ -382,6 +382,7 @@ typedef struct SSqlObj {
typedef
struct
SSqlStream
{
typedef
struct
SSqlStream
{
SSqlObj
*
pSql
;
SSqlObj
*
pSql
;
const
char
*
dstTable
;
uint32_t
streamId
;
uint32_t
streamId
;
char
listed
;
char
listed
;
bool
isProject
;
bool
isProject
;
...
@@ -408,6 +409,8 @@ typedef struct SSqlStream {
...
@@ -408,6 +409,8 @@ typedef struct SSqlStream {
struct
SSqlStream
*
prev
,
*
next
;
struct
SSqlStream
*
prev
,
*
next
;
}
SSqlStream
;
}
SSqlStream
;
void
tscSetStreamDestTable
(
SSqlStream
*
pStream
,
const
char
*
dstTable
);
int32_t
tscInitRpc
(
const
char
*
user
,
const
char
*
secret
,
void
**
pDnodeConn
);
int32_t
tscInitRpc
(
const
char
*
user
,
const
char
*
secret
,
void
**
pDnodeConn
);
void
tscInitMsgsFp
();
void
tscInitMsgsFp
();
...
...
src/client/src/tscProfile.c
浏览文件 @
3adbf1a7
...
@@ -262,6 +262,11 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) {
...
@@ -262,6 +262,11 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) {
SSqlStream
*
pStream
=
pObj
->
streamList
;
SSqlStream
*
pStream
=
pObj
->
streamList
;
while
(
pStream
)
{
while
(
pStream
)
{
tstrncpy
(
pSdesc
->
sql
,
pStream
->
pSql
->
sqlstr
,
sizeof
(
pSdesc
->
sql
));
tstrncpy
(
pSdesc
->
sql
,
pStream
->
pSql
->
sqlstr
,
sizeof
(
pSdesc
->
sql
));
if
(
pStream
->
dstTable
==
NULL
)
{
pSdesc
->
dstTable
[
0
]
=
0
;
}
else
{
tstrncpy
(
pSdesc
->
dstTable
,
pStream
->
dstTable
,
sizeof
(
pSdesc
->
dstTable
));
}
pSdesc
->
streamId
=
htonl
(
pStream
->
streamId
);
pSdesc
->
streamId
=
htonl
(
pStream
->
streamId
);
pSdesc
->
num
=
htobe64
(
pStream
->
num
);
pSdesc
->
num
=
htobe64
(
pStream
->
num
);
...
...
src/client/src/tscStream.c
浏览文件 @
3adbf1a7
...
@@ -535,6 +535,10 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) {
...
@@ -535,6 +535,10 @@ static void tscCreateStream(void *param, TAOS_RES *res, int code) {
pStream
,
pTableMetaInfo
->
name
,
pStream
->
interval
.
interval
,
pStream
->
interval
.
sliding
,
starttime
,
pSql
->
sqlstr
);
pStream
,
pTableMetaInfo
->
name
,
pStream
->
interval
.
interval
,
pStream
->
interval
.
sliding
,
starttime
,
pSql
->
sqlstr
);
}
}
void
tscSetStreamDestTable
(
SSqlStream
*
pStream
,
const
char
*
dstTable
)
{
pStream
->
dstTable
=
dstTable
;
}
TAOS_STREAM
*
taos_open_stream
(
TAOS
*
taos
,
const
char
*
sqlstr
,
void
(
*
fp
)(
void
*
param
,
TAOS_RES
*
,
TAOS_ROW
row
),
TAOS_STREAM
*
taos_open_stream
(
TAOS
*
taos
,
const
char
*
sqlstr
,
void
(
*
fp
)(
void
*
param
,
TAOS_RES
*
,
TAOS_ROW
row
),
int64_t
stime
,
void
*
param
,
void
(
*
callback
)(
void
*
))
{
int64_t
stime
,
void
*
param
,
void
(
*
callback
)(
void
*
))
{
STscObj
*
pObj
=
(
STscObj
*
)
taos
;
STscObj
*
pObj
=
(
STscObj
*
)
taos
;
...
...
src/cq/src/cqMain.c
浏览文件 @
3adbf1a7
...
@@ -57,6 +57,7 @@ typedef struct SCqObj {
...
@@ -57,6 +57,7 @@ typedef struct SCqObj {
uint64_t
uid
;
uint64_t
uid
;
int32_t
tid
;
// table ID
int32_t
tid
;
// table ID
int32_t
rowSize
;
// bytes of a row
int32_t
rowSize
;
// bytes of a row
char
*
dstTable
;
char
*
sqlStr
;
// SQL string
char
*
sqlStr
;
// SQL string
STSchema
*
pSchema
;
// pointer to schema array
STSchema
*
pSchema
;
// pointer to schema array
void
*
pStream
;
void
*
pStream
;
...
@@ -185,7 +186,7 @@ void cqStop(void *handle) {
...
@@ -185,7 +186,7 @@ void cqStop(void *handle) {
pthread_mutex_unlock
(
&
pContext
->
mutex
);
pthread_mutex_unlock
(
&
pContext
->
mutex
);
}
}
void
*
cqCreate
(
void
*
handle
,
uint64_t
uid
,
int32_t
tid
,
char
*
sqlStr
,
STSchema
*
pSchema
)
{
void
*
cqCreate
(
void
*
handle
,
uint64_t
uid
,
int32_t
sid
,
const
char
*
dstTable
,
char
*
sqlStr
,
STSchema
*
pSchema
)
{
if
(
tsEnableStream
==
0
)
{
if
(
tsEnableStream
==
0
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -195,9 +196,11 @@ void *cqCreate(void *handle, uint64_t uid, int32_t tid, char *sqlStr, STSchema *
...
@@ -195,9 +196,11 @@ void *cqCreate(void *handle, uint64_t uid, int32_t tid, char *sqlStr, STSchema *
if
(
pObj
==
NULL
)
return
NULL
;
if
(
pObj
==
NULL
)
return
NULL
;
pObj
->
uid
=
uid
;
pObj
->
uid
=
uid
;
pObj
->
tid
=
tid
;
pObj
->
tid
=
sid
;
pObj
->
sqlStr
=
malloc
(
strlen
(
sqlStr
)
+
1
);
if
(
dstTable
!=
NULL
)
{
strcpy
(
pObj
->
sqlStr
,
sqlStr
);
pObj
->
dstTable
=
strdup
(
dstTable
);
}
pObj
->
sqlStr
=
strdup
(
sqlStr
);
pObj
->
pSchema
=
tdDupSchema
(
pSchema
);
pObj
->
pSchema
=
tdDupSchema
(
pSchema
);
pObj
->
rowSize
=
schemaTLen
(
pSchema
);
pObj
->
rowSize
=
schemaTLen
(
pSchema
);
...
@@ -247,6 +250,7 @@ void cqDrop(void *handle) {
...
@@ -247,6 +250,7 @@ void cqDrop(void *handle) {
cInfo
(
"vgId:%d, id:%d CQ:%s is dropped"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
cInfo
(
"vgId:%d, id:%d CQ:%s is dropped"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
tdFreeSchema
(
pObj
->
pSchema
);
tdFreeSchema
(
pObj
->
pSchema
);
free
(
pObj
->
dstTable
);
free
(
pObj
->
sqlStr
);
free
(
pObj
->
sqlStr
);
free
(
pObj
);
free
(
pObj
);
...
@@ -292,6 +296,7 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) {
...
@@ -292,6 +296,7 @@ static void cqCreateStream(SCqContext *pContext, SCqObj *pObj) {
if
(
pObj
->
pStream
==
NULL
)
{
if
(
pObj
->
pStream
==
NULL
)
{
pObj
->
pStream
=
taos_open_stream
(
pContext
->
dbConn
,
pObj
->
sqlStr
,
cqProcessStreamRes
,
0
,
pObj
,
NULL
);
pObj
->
pStream
=
taos_open_stream
(
pContext
->
dbConn
,
pObj
->
sqlStr
,
cqProcessStreamRes
,
0
,
pObj
,
NULL
);
if
(
pObj
->
pStream
)
{
if
(
pObj
->
pStream
)
{
tscSetStreamDestTable
(
pObj
->
pStream
,
pObj
->
dstTable
);
pContext
->
num
++
;
pContext
->
num
++
;
cInfo
(
"vgId:%d, id:%d CQ:%s is openned"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
cInfo
(
"vgId:%d, id:%d CQ:%s is openned"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
}
else
{
}
else
{
...
...
src/cq/test/cqtest.c
浏览文件 @
3adbf1a7
...
@@ -70,7 +70,7 @@ int main(int argc, char *argv[]) {
...
@@ -70,7 +70,7 @@ int main(int argc, char *argv[]) {
tdDestroyTSchemaBuilder
(
&
schemaBuilder
);
tdDestroyTSchemaBuilder
(
&
schemaBuilder
);
for
(
int
sid
=
1
;
sid
<
10
;
++
sid
)
{
for
(
int
sid
=
1
;
sid
<
10
;
++
sid
)
{
cqCreate
(
pCq
,
sid
,
sid
,
"select avg(speed) from demo.t1 sliding(1s) interval(5s)"
,
pSchema
);
cqCreate
(
pCq
,
sid
,
sid
,
NULL
,
"select avg(speed) from demo.t1 sliding(1s) interval(5s)"
,
pSchema
);
}
}
tdFreeSchema
(
pSchema
);
tdFreeSchema
(
pSchema
);
...
...
src/inc/taosmsg.h
浏览文件 @
3adbf1a7
...
@@ -787,6 +787,7 @@ typedef struct {
...
@@ -787,6 +787,7 @@ typedef struct {
typedef
struct
{
typedef
struct
{
char
sql
[
TSDB_SHOW_SQL_LEN
];
char
sql
[
TSDB_SHOW_SQL_LEN
];
char
dstTable
[
TSDB_TABLE_NAME_LEN
];
uint32_t
streamId
;
uint32_t
streamId
;
int64_t
num
;
// number of computing/cycles
int64_t
num
;
// number of computing/cycles
int64_t
useconds
;
int64_t
useconds
;
...
...
src/inc/tcq.h
浏览文件 @
3adbf1a7
...
@@ -42,7 +42,7 @@ void cqStart(void *handle);
...
@@ -42,7 +42,7 @@ void cqStart(void *handle);
void
cqStop
(
void
*
handle
);
void
cqStop
(
void
*
handle
);
// cqCreate is called by TSDB to start an instance of CQ
// cqCreate is called by TSDB to start an instance of CQ
void
*
cqCreate
(
void
*
handle
,
uint64_t
uid
,
int32_t
sid
,
char
*
sqlStr
,
STSchema
*
pSchema
);
void
*
cqCreate
(
void
*
handle
,
uint64_t
uid
,
int32_t
sid
,
c
onst
char
*
dstTable
,
c
har
*
sqlStr
,
STSchema
*
pSchema
);
// cqDrop is called by TSDB to stop an instance of CQ, handle is the return value of cqCreate
// cqDrop is called by TSDB to stop an instance of CQ, handle is the return value of cqCreate
void
cqDrop
(
void
*
handle
);
void
cqDrop
(
void
*
handle
);
...
...
src/inc/tsdb.h
浏览文件 @
3adbf1a7
...
@@ -48,7 +48,7 @@ typedef struct {
...
@@ -48,7 +48,7 @@ typedef struct {
void
*
cqH
;
void
*
cqH
;
int
(
*
notifyStatus
)(
void
*
,
int
status
,
int
eno
);
int
(
*
notifyStatus
)(
void
*
,
int
status
,
int
eno
);
int
(
*
eventCallBack
)(
void
*
);
int
(
*
eventCallBack
)(
void
*
);
void
*
(
*
cqCreateFunc
)(
void
*
handle
,
uint64_t
uid
,
int
sid
,
char
*
sqlStr
,
STSchema
*
pSchema
);
void
*
(
*
cqCreateFunc
)(
void
*
handle
,
uint64_t
uid
,
int
32_t
sid
,
const
char
*
dstTable
,
char
*
sqlStr
,
STSchema
*
pSchema
);
void
(
*
cqDropFunc
)(
void
*
handle
);
void
(
*
cqDropFunc
)(
void
*
handle
);
}
STsdbAppH
;
}
STsdbAppH
;
...
...
src/kit/taosdump/taosdump.c
浏览文件 @
3adbf1a7
...
@@ -65,6 +65,9 @@ enum _show_tables_index {
...
@@ -65,6 +65,9 @@ enum _show_tables_index {
TSDB_SHOW_TABLES_CREATED_TIME_INDEX
,
TSDB_SHOW_TABLES_CREATED_TIME_INDEX
,
TSDB_SHOW_TABLES_COLUMNS_INDEX
,
TSDB_SHOW_TABLES_COLUMNS_INDEX
,
TSDB_SHOW_TABLES_METRIC_INDEX
,
TSDB_SHOW_TABLES_METRIC_INDEX
,
TSDB_SHOW_TABLES_UID_INDEX
,
TSDB_SHOW_TABLES_TID_INDEX
,
TSDB_SHOW_TABLES_VGID_INDEX
,
TSDB_MAX_SHOW_TABLES
TSDB_MAX_SHOW_TABLES
};
};
...
@@ -93,23 +96,26 @@ extern char version[];
...
@@ -93,23 +96,26 @@ extern char version[];
typedef
struct
{
typedef
struct
{
char
name
[
TSDB_DB_NAME_LEN
+
1
];
char
name
[
TSDB_DB_NAME_LEN
+
1
];
int32_t
tables
;
char
create_time
[
32
];
int32_t
ntables
;
int32_t
vgroups
;
int32_t
vgroups
;
int16_t
replica
tions
;
int16_t
replica
;
int16_t
quorum
;
int16_t
quorum
;
int16_t
daysPerFile
;
int16_t
days
;
int16_t
daysToKeep
;
char
keeplist
[
32
];
int16_t
daysToKeep1
;
//int16_t daysToKeep;
int16_t
daysToKeep2
;
//int16_t daysToKeep1;
int32_t
cacheBlockSize
;
//MB
//int16_t daysToKeep2;
int32_t
totalBlocks
;
int32_t
cache
;
//MB
int32_t
minRowsPerFileBlock
;
int32_t
blocks
;
int32_t
maxRowsPerFileBlock
;
int32_t
minrows
;
int8_t
walLevel
;
int32_t
maxrows
;
int32_t
fsyncPeriod
;
int8_t
wallevel
;
int8_t
compression
;
int32_t
fsync
;
int8_t
precision
;
// time resolution
int8_t
comp
;
char
precision
[
8
];
// time resolution
int8_t
update
;
int8_t
update
;
char
status
[
16
];
}
SDbInfo
;
}
SDbInfo
;
typedef
struct
{
typedef
struct
{
...
@@ -128,8 +134,17 @@ typedef struct {
...
@@ -128,8 +134,17 @@ typedef struct {
int32_t
totalThreads
;
int32_t
totalThreads
;
char
dbName
[
TSDB_TABLE_NAME_LEN
+
1
];
char
dbName
[
TSDB_TABLE_NAME_LEN
+
1
];
void
*
taosCon
;
void
*
taosCon
;
int64_t
rowsOfDumpOut
;
int64_t
tablesOfDumpOut
;
}
SThreadParaObj
;
}
SThreadParaObj
;
typedef
struct
{
int64_t
totalRowsOfDumpOut
;
int64_t
totalChildTblsOfDumpOut
;
int32_t
totalSuperTblsOfDumpOut
;
int32_t
totalDatabasesOfDumpOut
;
}
resultStatistics
;
static
int64_t
totalDumpOutRows
=
0
;
static
int64_t
totalDumpOutRows
=
0
;
SDbInfo
**
dbInfos
=
NULL
;
SDbInfo
**
dbInfos
=
NULL
;
...
@@ -167,6 +182,7 @@ static struct argp_option options[] = {
...
@@ -167,6 +182,7 @@ static struct argp_option options[] = {
// input/output file
// input/output file
{
"outpath"
,
'o'
,
"OUTPATH"
,
0
,
"Output file path."
,
1
},
{
"outpath"
,
'o'
,
"OUTPATH"
,
0
,
"Output file path."
,
1
},
{
"inpath"
,
'i'
,
"INPATH"
,
0
,
"Input file path."
,
1
},
{
"inpath"
,
'i'
,
"INPATH"
,
0
,
"Input file path."
,
1
},
{
"resultFile"
,
'r'
,
"RESULTFILE"
,
0
,
"DumpOut/In Result file path and name."
,
1
},
#ifdef _TD_POWER_
#ifdef _TD_POWER_
{
"config"
,
'c'
,
"CONFIG_DIR"
,
0
,
"Configure directory. Default is /etc/power/taos.cfg."
,
1
},
{
"config"
,
'c'
,
"CONFIG_DIR"
,
0
,
"Configure directory. Default is /etc/power/taos.cfg."
,
1
},
#else
#else
...
@@ -200,6 +216,8 @@ struct arguments {
...
@@ -200,6 +216,8 @@ struct arguments {
// output file
// output file
char
outpath
[
TSDB_FILENAME_LEN
+
1
];
char
outpath
[
TSDB_FILENAME_LEN
+
1
];
char
inpath
[
TSDB_FILENAME_LEN
+
1
];
char
inpath
[
TSDB_FILENAME_LEN
+
1
];
// result file
char
*
resultFile
;
char
*
encode
;
char
*
encode
;
// dump unit option
// dump unit option
bool
all_databases
;
bool
all_databases
;
...
@@ -274,6 +292,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
...
@@ -274,6 +292,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
tstrncpy
(
arguments
->
inpath
,
full_path
.
we_wordv
[
0
],
TSDB_FILENAME_LEN
);
tstrncpy
(
arguments
->
inpath
,
full_path
.
we_wordv
[
0
],
TSDB_FILENAME_LEN
);
wordfree
(
&
full_path
);
wordfree
(
&
full_path
);
break
;
break
;
case
'r'
:
arguments
->
resultFile
=
arg
;
break
;
case
'c'
:
case
'c'
:
if
(
wordexp
(
arg
,
&
full_path
,
0
)
!=
0
)
{
if
(
wordexp
(
arg
,
&
full_path
,
0
)
!=
0
)
{
fprintf
(
stderr
,
"Invalid path %s
\n
"
,
arg
);
fprintf
(
stderr
,
"Invalid path %s
\n
"
,
arg
);
...
@@ -343,16 +364,18 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
...
@@ -343,16 +364,18 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
/* Our argp parser. */
/* Our argp parser. */
static
struct
argp
argp
=
{
options
,
parse_opt
,
args_doc
,
doc
};
static
struct
argp
argp
=
{
options
,
parse_opt
,
args_doc
,
doc
};
static
resultStatistics
g_resultStatistics
=
{
0
};
static
FILE
*
g_fpOfResult
=
NULL
;
int
taosDumpOut
(
struct
arguments
*
arguments
);
int
taosDumpOut
(
struct
arguments
*
arguments
);
int
taosDumpIn
(
struct
arguments
*
arguments
);
int
taosDumpIn
(
struct
arguments
*
arguments
);
void
taosDumpCreateDbClause
(
SDbInfo
*
dbInfo
,
bool
isDumpProperty
,
FILE
*
fp
);
void
taosDumpCreateDbClause
(
SDbInfo
*
dbInfo
,
bool
isDumpProperty
,
FILE
*
fp
);
int
taosDumpDb
(
SDbInfo
*
dbInfo
,
struct
arguments
*
arguments
,
FILE
*
fp
,
TAOS
*
taosCon
);
int
taosDumpDb
(
SDbInfo
*
dbInfo
,
struct
arguments
*
arguments
,
FILE
*
fp
,
TAOS
*
taosCon
);
int32_t
taosDumpStable
(
char
*
table
,
FILE
*
fp
,
TAOS
*
taosCon
);
int32_t
taosDumpStable
(
char
*
table
,
FILE
*
fp
,
TAOS
*
taosCon
,
char
*
dbName
);
void
taosDumpCreateTableClause
(
STableDef
*
tableDes
,
int
numOfCols
,
FILE
*
fp
);
void
taosDumpCreateTableClause
(
STableDef
*
tableDes
,
int
numOfCols
,
FILE
*
fp
,
char
*
dbName
);
void
taosDumpCreateMTableClause
(
STableDef
*
tableDes
,
char
*
metric
,
int
numOfCols
,
FILE
*
fp
);
void
taosDumpCreateMTableClause
(
STableDef
*
tableDes
,
char
*
metric
,
int
numOfCols
,
FILE
*
fp
,
char
*
dbName
);
int32_t
taosDumpTable
(
char
*
table
,
char
*
metric
,
struct
arguments
*
arguments
,
FILE
*
fp
,
TAOS
*
taosCon
);
int32_t
taosDumpTable
(
char
*
table
,
char
*
metric
,
struct
arguments
*
arguments
,
FILE
*
fp
,
TAOS
*
taosCon
,
char
*
dbName
);
int
taosDumpTableData
(
FILE
*
fp
,
char
*
tbname
,
struct
arguments
*
arguments
,
TAOS
*
taosCon
);
int
taosDumpTableData
(
FILE
*
fp
,
char
*
tbname
,
struct
arguments
*
arguments
,
TAOS
*
taosCon
,
char
*
dbName
);
int
taosCheckParam
(
struct
arguments
*
arguments
);
int
taosCheckParam
(
struct
arguments
*
arguments
);
void
taosFreeDbInfos
();
void
taosFreeDbInfos
();
static
void
taosStartDumpOutWorkThreads
(
struct
arguments
*
args
,
int32_t
numOfThread
,
char
*
dbName
);
static
void
taosStartDumpOutWorkThreads
(
struct
arguments
*
args
,
int32_t
numOfThread
,
char
*
dbName
);
...
@@ -372,6 +395,7 @@ struct arguments tsArguments = {
...
@@ -372,6 +395,7 @@ struct arguments tsArguments = {
// outpath and inpath
// outpath and inpath
""
,
""
,
""
,
""
,
"./dump_result.txt"
,
NULL
,
NULL
,
// dump unit option
// dump unit option
false
,
false
,
...
@@ -393,17 +417,33 @@ struct arguments tsArguments = {
...
@@ -393,17 +417,33 @@ struct arguments tsArguments = {
false
false
};
};
int
queryDB
(
TAOS
*
taos
,
char
*
command
)
{
static
int
queryDbImpl
(
TAOS
*
taos
,
char
*
command
)
{
TAOS_RES
*
pSql
=
NULL
;
int
i
;
TAOS_RES
*
res
=
NULL
;
int32_t
code
=
-
1
;
int32_t
code
=
-
1
;
pSql
=
taos_query
(
taos
,
command
);
for
(
i
=
0
;
i
<
5
;
i
++
)
{
code
=
taos_errno
(
pSql
);
if
(
NULL
!=
res
)
{
if
(
code
)
{
taos_free_result
(
res
);
fprintf
(
stderr
,
"sql error: %s, reason:%s
\n
"
,
command
,
taos_errstr
(
pSql
));
res
=
NULL
;
}
res
=
taos_query
(
taos
,
command
);
code
=
taos_errno
(
res
);
if
(
0
==
code
)
{
break
;
}
}
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"Failed to run <%s>, reason: %s
\n
"
,
command
,
taos_errstr
(
res
));
taos_free_result
(
res
);
//taos_close(taos);
return
-
1
;
}
}
taos_free_result
(
pSql
);
return
code
;
taos_free_result
(
res
);
return
0
;
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
...
@@ -430,6 +470,7 @@ int main(int argc, char *argv[]) {
...
@@ -430,6 +470,7 @@ int main(int argc, char *argv[]) {
printf
(
"mysqlFlag: %d
\n
"
,
tsArguments
.
mysqlFlag
);
printf
(
"mysqlFlag: %d
\n
"
,
tsArguments
.
mysqlFlag
);
printf
(
"outpath: %s
\n
"
,
tsArguments
.
outpath
);
printf
(
"outpath: %s
\n
"
,
tsArguments
.
outpath
);
printf
(
"inpath: %s
\n
"
,
tsArguments
.
inpath
);
printf
(
"inpath: %s
\n
"
,
tsArguments
.
inpath
);
printf
(
"resultFile: %s
\n
"
,
tsArguments
.
resultFile
);
printf
(
"encode: %s
\n
"
,
tsArguments
.
encode
);
printf
(
"encode: %s
\n
"
,
tsArguments
.
encode
);
printf
(
"all_databases: %d
\n
"
,
tsArguments
.
all_databases
);
printf
(
"all_databases: %d
\n
"
,
tsArguments
.
all_databases
);
printf
(
"databases: %d
\n
"
,
tsArguments
.
databases
);
printf
(
"databases: %d
\n
"
,
tsArguments
.
databases
);
...
@@ -460,12 +501,77 @@ int main(int argc, char *argv[]) {
...
@@ -460,12 +501,77 @@ int main(int argc, char *argv[]) {
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
g_fpOfResult
=
fopen
(
tsArguments
.
resultFile
,
"a"
);
if
(
NULL
==
g_fpOfResult
)
{
fprintf
(
stderr
,
"Failed to open %s for save result
\n
"
,
tsArguments
.
resultFile
);
return
1
;
};
fprintf
(
g_fpOfResult
,
"#############################################################################
\n
"
);
fprintf
(
g_fpOfResult
,
"============================== arguments config =============================
\n
"
);
{
fprintf
(
g_fpOfResult
,
"host: %s
\n
"
,
tsArguments
.
host
);
fprintf
(
g_fpOfResult
,
"user: %s
\n
"
,
tsArguments
.
user
);
fprintf
(
g_fpOfResult
,
"password: %s
\n
"
,
tsArguments
.
password
);
fprintf
(
g_fpOfResult
,
"port: %u
\n
"
,
tsArguments
.
port
);
fprintf
(
g_fpOfResult
,
"cversion: %s
\n
"
,
tsArguments
.
cversion
);
fprintf
(
g_fpOfResult
,
"mysqlFlag: %d
\n
"
,
tsArguments
.
mysqlFlag
);
fprintf
(
g_fpOfResult
,
"outpath: %s
\n
"
,
tsArguments
.
outpath
);
fprintf
(
g_fpOfResult
,
"inpath: %s
\n
"
,
tsArguments
.
inpath
);
fprintf
(
g_fpOfResult
,
"resultFile: %s
\n
"
,
tsArguments
.
resultFile
);
fprintf
(
g_fpOfResult
,
"encode: %s
\n
"
,
tsArguments
.
encode
);
fprintf
(
g_fpOfResult
,
"all_databases: %d
\n
"
,
tsArguments
.
all_databases
);
fprintf
(
g_fpOfResult
,
"databases: %d
\n
"
,
tsArguments
.
databases
);
fprintf
(
g_fpOfResult
,
"schemaonly: %d
\n
"
,
tsArguments
.
schemaonly
);
fprintf
(
g_fpOfResult
,
"with_property: %d
\n
"
,
tsArguments
.
with_property
);
fprintf
(
g_fpOfResult
,
"start_time: %"
PRId64
"
\n
"
,
tsArguments
.
start_time
);
fprintf
(
g_fpOfResult
,
"end_time: %"
PRId64
"
\n
"
,
tsArguments
.
end_time
);
fprintf
(
g_fpOfResult
,
"data_batch: %d
\n
"
,
tsArguments
.
data_batch
);
fprintf
(
g_fpOfResult
,
"max_sql_len: %d
\n
"
,
tsArguments
.
max_sql_len
);
fprintf
(
g_fpOfResult
,
"table_batch: %d
\n
"
,
tsArguments
.
table_batch
);
fprintf
(
g_fpOfResult
,
"thread_num: %d
\n
"
,
tsArguments
.
thread_num
);
fprintf
(
g_fpOfResult
,
"allow_sys: %d
\n
"
,
tsArguments
.
allow_sys
);
fprintf
(
g_fpOfResult
,
"abort: %d
\n
"
,
tsArguments
.
abort
);
fprintf
(
g_fpOfResult
,
"isDumpIn: %d
\n
"
,
tsArguments
.
isDumpIn
);
fprintf
(
g_fpOfResult
,
"arg_list_len: %d
\n
"
,
tsArguments
.
arg_list_len
);
for
(
int32_t
i
=
0
;
i
<
tsArguments
.
arg_list_len
;
i
++
)
{
fprintf
(
g_fpOfResult
,
"arg_list[%d]: %s
\n
"
,
i
,
tsArguments
.
arg_list
[
i
]);
}
}
time_t
tTime
=
time
(
NULL
);
struct
tm
tm
=
*
localtime
(
&
tTime
);
if
(
tsArguments
.
isDumpIn
)
{
if
(
tsArguments
.
isDumpIn
)
{
if
(
taosDumpIn
(
&
tsArguments
)
<
0
)
return
-
1
;
fprintf
(
g_fpOfResult
,
"============================== DUMP IN ==============================
\n
"
);
fprintf
(
g_fpOfResult
,
"# DumpIn start time: %d-%02d-%02d %02d:%02d:%02d
\n
"
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
);
if
(
taosDumpIn
(
&
tsArguments
)
<
0
)
{
fprintf
(
g_fpOfResult
,
"
\n
"
);
fclose
(
g_fpOfResult
);
return
-
1
;
}
}
else
{
}
else
{
if
(
taosDumpOut
(
&
tsArguments
)
<
0
)
return
-
1
;
fprintf
(
g_fpOfResult
,
"============================== DUMP OUT ==============================
\n
"
);
fprintf
(
g_fpOfResult
,
"# DumpOut start time: %d-%02d-%02d %02d:%02d:%02d
\n
"
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
);
if
(
taosDumpOut
(
&
tsArguments
)
<
0
)
{
fprintf
(
g_fpOfResult
,
"
\n
"
);
fclose
(
g_fpOfResult
);
return
-
1
;
}
}
fprintf
(
g_fpOfResult
,
"
\n
============================== TOTAL STATISTICS ==============================
\n
"
);
fprintf
(
g_fpOfResult
,
"# total database count: %d
\n
"
,
g_resultStatistics
.
totalDatabasesOfDumpOut
);
fprintf
(
g_fpOfResult
,
"# total super table count: %d
\n
"
,
g_resultStatistics
.
totalSuperTblsOfDumpOut
);
fprintf
(
g_fpOfResult
,
"# total child table count: %"
PRId64
"
\n
"
,
g_resultStatistics
.
totalChildTblsOfDumpOut
);
fprintf
(
g_fpOfResult
,
"# total row count: %"
PRId64
"
\n
"
,
g_resultStatistics
.
totalRowsOfDumpOut
);
}
fprintf
(
g_fpOfResult
,
"
\n
"
);
fclose
(
g_fpOfResult
);
return
0
;
return
0
;
}
}
...
@@ -700,7 +806,7 @@ int taosDumpOut(struct arguments *arguments) {
...
@@ -700,7 +806,7 @@ int taosDumpOut(struct arguments *arguments) {
int32_t
code
=
taos_errno
(
result
);
int32_t
code
=
taos_errno
(
result
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"failed to run command: %s, reason: %s
\n
"
,
command
,
taos_errstr
(
taos
));
fprintf
(
stderr
,
"failed to run command: %s, reason: %s
\n
"
,
command
,
taos_errstr
(
result
));
goto
_exit_failure
;
goto
_exit_failure
;
}
}
...
@@ -736,27 +842,29 @@ int taosDumpOut(struct arguments *arguments) {
...
@@ -736,27 +842,29 @@ int taosDumpOut(struct arguments *arguments) {
}
}
strncpy
(
dbInfos
[
count
]
->
name
,
(
char
*
)
row
[
TSDB_SHOW_DB_NAME_INDEX
],
fields
[
TSDB_SHOW_DB_NAME_INDEX
].
bytes
);
strncpy
(
dbInfos
[
count
]
->
name
,
(
char
*
)
row
[
TSDB_SHOW_DB_NAME_INDEX
],
fields
[
TSDB_SHOW_DB_NAME_INDEX
].
bytes
);
#if 0
if
(
arguments
->
with_property
)
{
if
(
arguments
->
with_property
)
{
dbInfos[count]->tables = *((int32_t *)row[TSDB_SHOW_DB_NTABLES_INDEX]);
dbInfos
[
count
]
->
n
tables
=
*
((
int32_t
*
)
row
[
TSDB_SHOW_DB_NTABLES_INDEX
]);
dbInfos
[
count
]
->
vgroups
=
*
((
int32_t
*
)
row
[
TSDB_SHOW_DB_VGROUPS_INDEX
]);
dbInfos
[
count
]
->
vgroups
=
*
((
int32_t
*
)
row
[
TSDB_SHOW_DB_VGROUPS_INDEX
]);
dbInfos[count]->replica
tions
= *((int16_t *)row[TSDB_SHOW_DB_REPLICA_INDEX]);
dbInfos
[
count
]
->
replica
=
*
((
int16_t
*
)
row
[
TSDB_SHOW_DB_REPLICA_INDEX
]);
dbInfos
[
count
]
->
quorum
=
*
((
int16_t
*
)
row
[
TSDB_SHOW_DB_QUORUM_INDEX
]);
dbInfos
[
count
]
->
quorum
=
*
((
int16_t
*
)
row
[
TSDB_SHOW_DB_QUORUM_INDEX
]);
dbInfos[count]->daysPerFile = *((int16_t *)row[TSDB_SHOW_DB_DAYS_INDEX]);
dbInfos
[
count
]
->
days
=
*
((
int16_t
*
)
row
[
TSDB_SHOW_DB_DAYS_INDEX
]);
dbInfos[count]->daysToKeep = *((int16_t *)row[TSDB_SHOW_DB_KEEP_INDEX]);
dbInfos[count]->daysToKeep1;
strncpy
(
dbInfos
[
count
]
->
keeplist
,
(
char
*
)
row
[
TSDB_SHOW_DB_KEEP_INDEX
],
fields
[
TSDB_SHOW_DB_KEEP_INDEX
].
bytes
);
dbInfos[count]->daysToKeep2;
//dbInfos[count]->daysToKeep = *((int16_t *)row[TSDB_SHOW_DB_KEEP_INDEX]);
dbInfos[count]->cacheBlockSize = *((int32_t *)row[TSDB_SHOW_DB_CACHE_INDEX]);
//dbInfos[count]->daysToKeep1;
dbInfos[count]->totalBlocks = *((int32_t *)row[TSDB_SHOW_DB_BLOCKS_INDEX]);
//dbInfos[count]->daysToKeep2;
dbInfos[count]->minRowsPerFileBlock = *((int32_t *)row[TSDB_SHOW_DB_MINROWS_INDEX]);
dbInfos
[
count
]
->
cache
=
*
((
int32_t
*
)
row
[
TSDB_SHOW_DB_CACHE_INDEX
]);
dbInfos[count]->maxRowsPerFileBlock = *((int32_t *)row[TSDB_SHOW_DB_MAXROWS_INDEX]);
dbInfos
[
count
]
->
blocks
=
*
((
int32_t
*
)
row
[
TSDB_SHOW_DB_BLOCKS_INDEX
]);
dbInfos[count]->walLevel = *((int8_t *)row[TSDB_SHOW_DB_WALLEVEL_INDEX]);
dbInfos
[
count
]
->
minrows
=
*
((
int32_t
*
)
row
[
TSDB_SHOW_DB_MINROWS_INDEX
]);
dbInfos[count]->fsyncPeriod = *((int32_t *)row[TSDB_SHOW_DB_FSYNC_INDEX]);
dbInfos
[
count
]
->
maxrows
=
*
((
int32_t
*
)
row
[
TSDB_SHOW_DB_MAXROWS_INDEX
]);
dbInfos[count]->compression = (int8_t)(*((int8_t *)row[TSDB_SHOW_DB_COMP_INDEX]));
dbInfos
[
count
]
->
wallevel
=
*
((
int8_t
*
)
row
[
TSDB_SHOW_DB_WALLEVEL_INDEX
]);
dbInfos[count]->precision = *((int8_t *)row[TSDB_SHOW_DB_PRECISION_INDEX]);
dbInfos
[
count
]
->
fsync
=
*
((
int32_t
*
)
row
[
TSDB_SHOW_DB_FSYNC_INDEX
]);
dbInfos
[
count
]
->
comp
=
(
int8_t
)(
*
((
int8_t
*
)
row
[
TSDB_SHOW_DB_COMP_INDEX
]));
strncpy
(
dbInfos
[
count
]
->
precision
,
(
char
*
)
row
[
TSDB_SHOW_DB_PRECISION_INDEX
],
fields
[
TSDB_SHOW_DB_PRECISION_INDEX
].
bytes
);
//dbInfos[count]->precision = *((int8_t *)row[TSDB_SHOW_DB_PRECISION_INDEX]);
dbInfos
[
count
]
->
update
=
*
((
int8_t
*
)
row
[
TSDB_SHOW_DB_UPDATE_INDEX
]);
dbInfos
[
count
]
->
update
=
*
((
int8_t
*
)
row
[
TSDB_SHOW_DB_UPDATE_INDEX
]);
}
}
#endif
count
++
;
count
++
;
if
(
arguments
->
databases
)
{
if
(
arguments
->
databases
)
{
...
@@ -781,6 +889,8 @@ int taosDumpOut(struct arguments *arguments) {
...
@@ -781,6 +889,8 @@ int taosDumpOut(struct arguments *arguments) {
taosDumpDb
(
dbInfos
[
0
],
arguments
,
fp
,
taos
);
taosDumpDb
(
dbInfos
[
0
],
arguments
,
fp
,
taos
);
}
else
{
// case: taosdump <db> tablex tabley ...
}
else
{
// case: taosdump <db> tablex tabley ...
taosDumpCreateDbClause
(
dbInfos
[
0
],
arguments
->
with_property
,
fp
);
taosDumpCreateDbClause
(
dbInfos
[
0
],
arguments
->
with_property
,
fp
);
fprintf
(
g_fpOfResult
,
"
\n
#### database: %s
\n
"
,
dbInfos
[
0
]
->
name
);
g_resultStatistics
.
totalDatabasesOfDumpOut
++
;
sprintf
(
command
,
"use %s"
,
dbInfos
[
0
]
->
name
);
sprintf
(
command
,
"use %s"
,
dbInfos
[
0
]
->
name
);
...
@@ -796,6 +906,7 @@ int taosDumpOut(struct arguments *arguments) {
...
@@ -796,6 +906,7 @@ int taosDumpOut(struct arguments *arguments) {
int32_t
totalNumOfThread
=
1
;
// 0: all normal talbe into .tables.tmp.0
int32_t
totalNumOfThread
=
1
;
// 0: all normal talbe into .tables.tmp.0
int
normalTblFd
=
-
1
;
int
normalTblFd
=
-
1
;
int32_t
retCode
;
int32_t
retCode
;
int
superTblCnt
=
0
;
for
(
int
i
=
1
;
arguments
->
arg_list
[
i
];
i
++
)
{
for
(
int
i
=
1
;
arguments
->
arg_list
[
i
];
i
++
)
{
if
(
taosGetTableRecordInfo
(
arguments
->
arg_list
[
i
],
&
tableRecordInfo
,
taos
)
<
0
)
{
if
(
taosGetTableRecordInfo
(
arguments
->
arg_list
[
i
],
&
tableRecordInfo
,
taos
)
<
0
)
{
fprintf
(
stderr
,
"input the invalide table %s
\n
"
,
arguments
->
arg_list
[
i
]);
fprintf
(
stderr
,
"input the invalide table %s
\n
"
,
arguments
->
arg_list
[
i
]);
...
@@ -803,11 +914,17 @@ int taosDumpOut(struct arguments *arguments) {
...
@@ -803,11 +914,17 @@ int taosDumpOut(struct arguments *arguments) {
}
}
if
(
tableRecordInfo
.
isMetric
)
{
// dump all table of this metric
if
(
tableRecordInfo
.
isMetric
)
{
// dump all table of this metric
(
void
)
taosDumpStable
(
tableRecordInfo
.
tableRecord
.
metric
,
fp
,
taos
);
int
ret
=
taosDumpStable
(
tableRecordInfo
.
tableRecord
.
metric
,
fp
,
taos
,
dbInfos
[
0
]
->
name
);
if
(
0
==
ret
)
{
superTblCnt
++
;
}
retCode
=
taosSaveTableOfMetricToTempFile
(
taos
,
tableRecordInfo
.
tableRecord
.
metric
,
arguments
,
&
totalNumOfThread
);
retCode
=
taosSaveTableOfMetricToTempFile
(
taos
,
tableRecordInfo
.
tableRecord
.
metric
,
arguments
,
&
totalNumOfThread
);
}
else
{
}
else
{
if
(
tableRecordInfo
.
tableRecord
.
metric
[
0
]
!=
'\0'
)
{
// dump this sub table and it's metric
if
(
tableRecordInfo
.
tableRecord
.
metric
[
0
]
!=
'\0'
)
{
// dump this sub table and it's metric
(
void
)
taosDumpStable
(
tableRecordInfo
.
tableRecord
.
metric
,
fp
,
taos
);
int
ret
=
taosDumpStable
(
tableRecordInfo
.
tableRecord
.
metric
,
fp
,
taos
,
dbInfos
[
0
]
->
name
);
if
(
0
==
ret
)
{
superTblCnt
++
;
}
}
}
retCode
=
taosSaveAllNormalTableToTempFile
(
taos
,
tableRecordInfo
.
tableRecord
.
name
,
tableRecordInfo
.
tableRecord
.
metric
,
&
normalTblFd
);
retCode
=
taosSaveAllNormalTableToTempFile
(
taos
,
tableRecordInfo
.
tableRecord
.
name
,
tableRecordInfo
.
tableRecord
.
metric
,
&
normalTblFd
);
}
}
...
@@ -820,6 +937,10 @@ int taosDumpOut(struct arguments *arguments) {
...
@@ -820,6 +937,10 @@ int taosDumpOut(struct arguments *arguments) {
}
}
}
}
// TODO: save dump super table <superTblCnt> into result_output.txt
fprintf
(
g_fpOfResult
,
"# super table counter: %d
\n
"
,
superTblCnt
);
g_resultStatistics
.
totalSuperTblsOfDumpOut
+=
superTblCnt
;
if
(
-
1
!=
normalTblFd
){
if
(
-
1
!=
normalTblFd
){
taosClose
(
normalTblFd
);
taosClose
(
normalTblFd
);
}
}
...
@@ -855,41 +976,27 @@ _exit_failure:
...
@@ -855,41 +976,27 @@ _exit_failure:
return
-
1
;
return
-
1
;
}
}
int
taosGetTableDes
(
char
*
table
,
STableDef
*
tableDes
,
TAOS
*
taosCon
,
bool
isSuperTable
)
{
int
taosGetTableDes
(
char
*
dbName
,
char
*
table
,
STableDef
*
tableDes
,
TAOS
*
taosCon
,
bool
isSuperTable
)
{
TAOS_ROW
row
=
NULL
;
TAOS_ROW
row
=
NULL
;
TAOS_RES
*
tmpResult
=
NULL
;
TAOS_RES
*
res
=
NULL
;
int
count
=
0
;
int
count
=
0
;
char
*
tempCommand
=
(
char
*
)
malloc
(
COMMAND_SIZE
);
char
sqlstr
[
COMMAND_SIZE
];
if
(
tempCommand
==
NULL
)
{
sprintf
(
sqlstr
,
"describe %s.%s;"
,
dbName
,
table
);
fprintf
(
stderr
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
char
*
tbuf
=
(
char
*
)
malloc
(
COMMAND_SIZE
);
if
(
tbuf
==
NULL
)
{
fprintf
(
stderr
,
"failed to allocate memory
\n
"
);
free
(
tempCommand
);
return
-
1
;
}
sprintf
(
tempCommand
,
"describe %s"
,
table
);
tmpResult
=
taos_query
(
taosCon
,
tempCommand
);
res
=
taos_query
(
taosCon
,
sqlstr
);
int32_t
code
=
taos_errno
(
tmpResult
);
int32_t
code
=
taos_errno
(
res
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"failed to run command %s
\n
"
,
tempCommand
);
fprintf
(
stderr
,
"failed to run command <%s>, reason:%s
\n
"
,
sqlstr
,
taos_errstr
(
res
));
free
(
tempCommand
);
taos_free_result
(
res
);
free
(
tbuf
);
taos_free_result
(
tmpResult
);
return
-
1
;
return
-
1
;
}
}
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
tmpResult
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
res
);
tstrncpy
(
tableDes
->
name
,
table
,
TSDB_COL_NAME_LEN
);
tstrncpy
(
tableDes
->
name
,
table
,
TSDB_COL_NAME_LEN
);
while
((
row
=
taos_fetch_row
(
tmpResult
))
!=
NULL
)
{
while
((
row
=
taos_fetch_row
(
res
))
!=
NULL
)
{
strncpy
(
tableDes
->
cols
[
count
].
field
,
(
char
*
)
row
[
TSDB_DESCRIBE_METRIC_FIELD_INDEX
],
strncpy
(
tableDes
->
cols
[
count
].
field
,
(
char
*
)
row
[
TSDB_DESCRIBE_METRIC_FIELD_INDEX
],
fields
[
TSDB_DESCRIBE_METRIC_FIELD_INDEX
].
bytes
);
fields
[
TSDB_DESCRIBE_METRIC_FIELD_INDEX
].
bytes
);
strncpy
(
tableDes
->
cols
[
count
].
type
,
(
char
*
)
row
[
TSDB_DESCRIBE_METRIC_TYPE_INDEX
],
strncpy
(
tableDes
->
cols
[
count
].
type
,
(
char
*
)
row
[
TSDB_DESCRIBE_METRIC_TYPE_INDEX
],
...
@@ -901,12 +1008,10 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon, bool isSupe
...
@@ -901,12 +1008,10 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon, bool isSupe
count
++
;
count
++
;
}
}
taos_free_result
(
tmpResult
);
taos_free_result
(
res
);
tmpResult
=
NULL
;
res
=
NULL
;
if
(
isSuperTable
)
{
if
(
isSuperTable
)
{
free
(
tempCommand
);
free
(
tbuf
);
return
count
;
return
count
;
}
}
...
@@ -915,37 +1020,33 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon, bool isSupe
...
@@ -915,37 +1020,33 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon, bool isSupe
if
(
strcmp
(
tableDes
->
cols
[
i
].
note
,
"TAG"
)
!=
0
)
continue
;
if
(
strcmp
(
tableDes
->
cols
[
i
].
note
,
"TAG"
)
!=
0
)
continue
;
sprintf
(
tempCommand
,
"select %s from %s"
,
tableDes
->
cols
[
i
].
field
,
table
);
sprintf
(
sqlstr
,
"select %s from %s.%s"
,
tableDes
->
cols
[
i
].
field
,
dbName
,
table
);
tmpResult
=
taos_query
(
taosCon
,
tempCommand
);
res
=
taos_query
(
taosCon
,
sqlstr
);
code
=
taos_errno
(
tmpResult
);
code
=
taos_errno
(
res
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"failed to run command %s
\n
"
,
tempCommand
);
fprintf
(
stderr
,
"failed to run command <%s>, reason:%s
\n
"
,
sqlstr
,
taos_errstr
(
res
));
free
(
tempCommand
);
taos_free_result
(
res
);
free
(
tbuf
);
taos_free_result
(
tmpResult
);
return
-
1
;
return
-
1
;
}
}
fields
=
taos_fetch_fields
(
tmpResult
);
fields
=
taos_fetch_fields
(
res
);
row
=
taos_fetch_row
(
tmpResult
);
row
=
taos_fetch_row
(
res
);
if
(
NULL
==
row
)
{
if
(
NULL
==
row
)
{
fprintf
(
stderr
,
" fetch failed to run command %s
\n
"
,
tempCommand
);
fprintf
(
stderr
,
" fetch failed to run command <%s>, reason:%s
\n
"
,
sqlstr
,
taos_errstr
(
res
));
free
(
tempCommand
);
taos_free_result
(
res
);
free
(
tbuf
);
taos_free_result
(
tmpResult
);
return
-
1
;
return
-
1
;
}
}
if
(
row
[
0
]
==
NULL
)
{
if
(
row
[
0
]
==
NULL
)
{
sprintf
(
tableDes
->
cols
[
i
].
note
,
"%s"
,
"NULL"
);
sprintf
(
tableDes
->
cols
[
i
].
note
,
"%s"
,
"NULL"
);
taos_free_result
(
tmpResult
);
taos_free_result
(
res
);
tmpResult
=
NULL
;
res
=
NULL
;
continue
;
continue
;
}
}
int32_t
*
length
=
taos_fetch_lengths
(
tmpResult
);
int32_t
*
length
=
taos_fetch_lengths
(
res
);
//int32_t* length = taos_fetch_lengths(tmpResult);
//int32_t* length = taos_fetch_lengths(tmpResult);
switch
(
fields
[
0
].
type
)
{
switch
(
fields
[
0
].
type
)
{
...
@@ -970,18 +1071,22 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon, bool isSupe
...
@@ -970,18 +1071,22 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon, bool isSupe
case
TSDB_DATA_TYPE_DOUBLE
:
case
TSDB_DATA_TYPE_DOUBLE
:
sprintf
(
tableDes
->
cols
[
i
].
note
,
"%f"
,
GET_DOUBLE_VAL
(
row
[
0
]));
sprintf
(
tableDes
->
cols
[
i
].
note
,
"%f"
,
GET_DOUBLE_VAL
(
row
[
0
]));
break
;
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_BINARY
:
{
memset
(
tableDes
->
cols
[
i
].
note
,
0
,
sizeof
(
tableDes
->
cols
[
i
].
note
));
memset
(
tableDes
->
cols
[
i
].
note
,
0
,
sizeof
(
tableDes
->
cols
[
i
].
note
));
tableDes
->
cols
[
i
].
note
[
0
]
=
'\''
;
tableDes
->
cols
[
i
].
note
[
0
]
=
'\''
;
char
tbuf
[
COMMAND_SIZE
];
converStringToReadable
((
char
*
)
row
[
0
],
length
[
0
],
tbuf
,
COMMAND_SIZE
);
converStringToReadable
((
char
*
)
row
[
0
],
length
[
0
],
tbuf
,
COMMAND_SIZE
);
char
*
pstr
=
stpcpy
(
&
(
tableDes
->
cols
[
i
].
note
[
1
]),
tbuf
);
char
*
pstr
=
stpcpy
(
&
(
tableDes
->
cols
[
i
].
note
[
1
]),
tbuf
);
*
(
pstr
++
)
=
'\''
;
*
(
pstr
++
)
=
'\''
;
break
;
break
;
case
TSDB_DATA_TYPE_NCHAR
:
}
case
TSDB_DATA_TYPE_NCHAR
:
{
memset
(
tableDes
->
cols
[
i
].
note
,
0
,
sizeof
(
tableDes
->
cols
[
i
].
note
));
memset
(
tableDes
->
cols
[
i
].
note
,
0
,
sizeof
(
tableDes
->
cols
[
i
].
note
));
char
tbuf
[
COMMAND_SIZE
];
convertNCharToReadable
((
char
*
)
row
[
0
],
length
[
0
],
tbuf
,
COMMAND_SIZE
);
convertNCharToReadable
((
char
*
)
row
[
0
],
length
[
0
],
tbuf
,
COMMAND_SIZE
);
sprintf
(
tableDes
->
cols
[
i
].
note
,
"
\'
%s
\'
"
,
tbuf
);
sprintf
(
tableDes
->
cols
[
i
].
note
,
"
\'
%s
\'
"
,
tbuf
);
break
;
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
sprintf
(
tableDes
->
cols
[
i
].
note
,
"%"
PRId64
""
,
*
(
int64_t
*
)
row
[
0
]);
sprintf
(
tableDes
->
cols
[
i
].
note
,
"%"
PRId64
""
,
*
(
int64_t
*
)
row
[
0
]);
#if 0
#if 0
...
@@ -1001,17 +1106,14 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon, bool isSupe
...
@@ -1001,17 +1106,14 @@ int taosGetTableDes(char *table, STableDef *tableDes, TAOS* taosCon, bool isSupe
break
;
break
;
}
}
taos_free_result
(
tmpResult
);
taos_free_result
(
res
);
tmpResult
=
NULL
;
res
=
NULL
;
}
}
free
(
tempCommand
);
free
(
tbuf
);
return
count
;
return
count
;
}
}
int32_t
taosDumpTable
(
char
*
table
,
char
*
metric
,
struct
arguments
*
arguments
,
FILE
*
fp
,
TAOS
*
taosCon
)
{
int32_t
taosDumpTable
(
char
*
table
,
char
*
metric
,
struct
arguments
*
arguments
,
FILE
*
fp
,
TAOS
*
taosCon
,
char
*
dbName
)
{
int
count
=
0
;
int
count
=
0
;
STableDef
*
tableDes
=
(
STableDef
*
)
calloc
(
1
,
sizeof
(
STableDef
)
+
sizeof
(
SColDes
)
*
TSDB_MAX_COLUMNS
);
STableDef
*
tableDes
=
(
STableDef
*
)
calloc
(
1
,
sizeof
(
STableDef
)
+
sizeof
(
SColDes
)
*
TSDB_MAX_COLUMNS
);
...
@@ -1030,7 +1132,7 @@ int32_t taosDumpTable(char *table, char *metric, struct arguments *arguments, FI
...
@@ -1030,7 +1132,7 @@ int32_t taosDumpTable(char *table, char *metric, struct arguments *arguments, FI
memset(tableDes, 0, sizeof(STableDef) + sizeof(SColDes) * TSDB_MAX_COLUMNS);
memset(tableDes, 0, sizeof(STableDef) + sizeof(SColDes) * TSDB_MAX_COLUMNS);
*/
*/
count
=
taosGetTableDes
(
table
,
tableDes
,
taosCon
,
false
);
count
=
taosGetTableDes
(
dbName
,
table
,
tableDes
,
taosCon
,
false
);
if
(
count
<
0
)
{
if
(
count
<
0
)
{
free
(
tableDes
);
free
(
tableDes
);
...
@@ -1038,10 +1140,10 @@ int32_t taosDumpTable(char *table, char *metric, struct arguments *arguments, FI
...
@@ -1038,10 +1140,10 @@ int32_t taosDumpTable(char *table, char *metric, struct arguments *arguments, FI
}
}
// create child-table using super-table
// create child-table using super-table
taosDumpCreateMTableClause
(
tableDes
,
metric
,
count
,
fp
);
taosDumpCreateMTableClause
(
tableDes
,
metric
,
count
,
fp
,
dbName
);
}
else
{
// dump table definition
}
else
{
// dump table definition
count
=
taosGetTableDes
(
table
,
tableDes
,
taosCon
,
false
);
count
=
taosGetTableDes
(
dbName
,
table
,
tableDes
,
taosCon
,
false
);
if
(
count
<
0
)
{
if
(
count
<
0
)
{
free
(
tableDes
);
free
(
tableDes
);
...
@@ -1049,39 +1151,28 @@ int32_t taosDumpTable(char *table, char *metric, struct arguments *arguments, FI
...
@@ -1049,39 +1151,28 @@ int32_t taosDumpTable(char *table, char *metric, struct arguments *arguments, FI
}
}
// create normal-table or super-table
// create normal-table or super-table
taosDumpCreateTableClause
(
tableDes
,
count
,
fp
);
taosDumpCreateTableClause
(
tableDes
,
count
,
fp
,
dbName
);
}
}
free
(
tableDes
);
free
(
tableDes
);
return
taosDumpTableData
(
fp
,
table
,
arguments
,
taosCon
);
return
taosDumpTableData
(
fp
,
table
,
arguments
,
taosCon
,
dbName
);
}
}
void
taosDumpCreateDbClause
(
SDbInfo
*
dbInfo
,
bool
isDumpProperty
,
FILE
*
fp
)
{
void
taosDumpCreateDbClause
(
SDbInfo
*
dbInfo
,
bool
isDumpProperty
,
FILE
*
fp
)
{
char
sqlstr
[
TSDB_MAX_SQL_LEN
]
=
{
0
};
char
*
tmpCommand
=
(
char
*
)
malloc
(
COMMAND_SIZE
);
char
*
pstr
=
sqlstr
;
if
(
tmpCommand
==
NULL
)
{
pstr
+=
sprintf
(
pstr
,
"CREATE DATABASE IF NOT EXISTS %s "
,
dbInfo
->
name
);
fprintf
(
stderr
,
"failed to allocate memory
\n
"
);
return
;
}
char
*
pstr
=
tmpCommand
;
pstr
+=
sprintf
(
pstr
,
"CREATE DATABASE IF NOT EXISTS %s"
,
dbInfo
->
name
);
if
(
isDumpProperty
)
{
if
(
isDumpProperty
)
{
#if 0
pstr
+=
sprintf
(
pstr
,
pstr
+=
sprintf
(
pstr
,
"TABLES %d vgroups %d REPLICA %d quorum %d DAYS %d KEEP %d CACHE %d BLOCKS %d MINROWS %d MAXROWS %d WALLEVEL %d FYNC %d COMP %d PRECISION %s UPDATE %d",
"TABLES %d VGROUPS %d REPLICA %d QUORUM %d DAYS %d KEEP %s CACHE %d BLOCKS %d MINROWS %d MAXROWS %d WALLEVEL %d FYNC %d COMP %d PRECISION '%s' UPDATE %d"
,
dbInfo->tables, dbInfo->vgroups, dbInfo->replications, dbInfo->quorum, dbInfo->daysPerFile, dbInfo->daysToKeep, dbInfo->cacheBlockSize,
dbInfo
->
ntables
,
dbInfo
->
vgroups
,
dbInfo
->
replica
,
dbInfo
->
quorum
,
dbInfo
->
days
,
dbInfo
->
keeplist
,
dbInfo
->
cache
,
dbInfo->totalBlocks, dbInfo->minRowsPerFileBlock, dbInfo->maxRowsPerFileBlock, dbInfo->walLevel, dbInfo->fsyncPeriod, dbInfo->compression,
dbInfo
->
blocks
,
dbInfo
->
minrows
,
dbInfo
->
maxrows
,
dbInfo
->
wallevel
,
dbInfo
->
fsync
,
dbInfo
->
comp
,
dbInfo
->
precision
,
dbInfo
->
update
);
dbInfo->precision, dbInfo->update);
#endif
}
}
pstr
+=
sprintf
(
pstr
,
";"
);
pstr
+=
sprintf
(
pstr
,
";"
);
fprintf
(
fp
,
"%s
\n\n
"
,
sqlstr
);
fprintf
(
fp
,
"%s
\n\n
"
,
tmpCommand
);
free
(
tmpCommand
);
}
}
void
*
taosDumpOutWorkThreadFp
(
void
*
arg
)
void
*
taosDumpOutWorkThreadFp
(
void
*
arg
)
...
@@ -1131,7 +1222,13 @@ void* taosDumpOutWorkThreadFp(void *arg)
...
@@ -1131,7 +1222,13 @@ void* taosDumpOutWorkThreadFp(void *arg)
while
(
1
)
{
while
(
1
)
{
ssize_t
readLen
=
read
(
fd
,
&
tableRecord
,
sizeof
(
STableRecord
));
ssize_t
readLen
=
read
(
fd
,
&
tableRecord
,
sizeof
(
STableRecord
));
if
(
readLen
<=
0
)
break
;
if
(
readLen
<=
0
)
break
;
taosDumpTable
(
tableRecord
.
name
,
tableRecord
.
metric
,
&
tsArguments
,
fp
,
pThread
->
taosCon
);
int
ret
=
taosDumpTable
(
tableRecord
.
name
,
tableRecord
.
metric
,
&
tsArguments
,
fp
,
pThread
->
taosCon
,
pThread
->
dbName
);
if
(
ret
>=
0
)
{
// TODO: sum table count and table rows by self
pThread
->
tablesOfDumpOut
++
;
pThread
->
rowsOfDumpOut
+=
ret
;
}
}
}
taos_free_result
(
tmpResult
);
taos_free_result
(
tmpResult
);
...
@@ -1147,13 +1244,15 @@ static void taosStartDumpOutWorkThreads(struct arguments* args, int32_t numOfTh
...
@@ -1147,13 +1244,15 @@ static void taosStartDumpOutWorkThreads(struct arguments* args, int32_t numOfTh
SThreadParaObj
*
threadObj
=
(
SThreadParaObj
*
)
calloc
(
numOfThread
,
sizeof
(
SThreadParaObj
));
SThreadParaObj
*
threadObj
=
(
SThreadParaObj
*
)
calloc
(
numOfThread
,
sizeof
(
SThreadParaObj
));
for
(
int
t
=
0
;
t
<
numOfThread
;
++
t
)
{
for
(
int
t
=
0
;
t
<
numOfThread
;
++
t
)
{
SThreadParaObj
*
pThread
=
threadObj
+
t
;
SThreadParaObj
*
pThread
=
threadObj
+
t
;
pThread
->
rowsOfDumpOut
=
0
;
pThread
->
tablesOfDumpOut
=
0
;
pThread
->
threadIndex
=
t
;
pThread
->
threadIndex
=
t
;
pThread
->
totalThreads
=
numOfThread
;
pThread
->
totalThreads
=
numOfThread
;
tstrncpy
(
pThread
->
dbName
,
dbName
,
TSDB_TABLE_NAME_LEN
);
tstrncpy
(
pThread
->
dbName
,
dbName
,
TSDB_TABLE_NAME_LEN
);
pThread
->
taosCon
=
taos_connect
(
args
->
host
,
args
->
user
,
args
->
password
,
NULL
,
args
->
port
);
pThread
->
taosCon
=
taos_connect
(
args
->
host
,
args
->
user
,
args
->
password
,
NULL
,
args
->
port
);
if
(
pThread
->
taosCon
==
NULL
)
{
if
(
pThread
->
taosCon
==
NULL
)
{
fprintf
(
stderr
,
"ERROR: thread:%d failed connect to TDengine,
error:%s
\n
"
,
pThread
->
threadIndex
,
taos_errstr
(
pThread
->
taosCon
));
fprintf
(
stderr
,
"ERROR: thread:%d failed connect to TDengine,
reason:%s
\n
"
,
pThread
->
threadIndex
,
taos_errstr
(
NULL
));
exit
(
0
);
exit
(
0
);
}
}
...
@@ -1170,15 +1269,25 @@ static void taosStartDumpOutWorkThreads(struct arguments* args, int32_t numOfTh
...
@@ -1170,15 +1269,25 @@ static void taosStartDumpOutWorkThreads(struct arguments* args, int32_t numOfTh
pthread_join
(
threadObj
[
t
].
threadID
,
NULL
);
pthread_join
(
threadObj
[
t
].
threadID
,
NULL
);
}
}
// TODO: sum all thread dump table count and rows of per table, then save into result_output.txt
int64_t
totalRowsOfDumpOut
=
0
;
int64_t
totalChildTblsOfDumpOut
=
0
;
for
(
int32_t
t
=
0
;
t
<
numOfThread
;
++
t
)
{
for
(
int32_t
t
=
0
;
t
<
numOfThread
;
++
t
)
{
taos_close
(
threadObj
[
t
].
taosCon
);
taos_close
(
threadObj
[
t
].
taosCon
);
totalChildTblsOfDumpOut
+=
threadObj
[
t
].
tablesOfDumpOut
;
totalRowsOfDumpOut
+=
threadObj
[
t
].
rowsOfDumpOut
;
}
}
fprintf
(
g_fpOfResult
,
"# child table counter: %"
PRId64
"
\n
"
,
totalChildTblsOfDumpOut
);
fprintf
(
g_fpOfResult
,
"# row counter: %"
PRId64
"
\n
"
,
totalRowsOfDumpOut
);
g_resultStatistics
.
totalChildTblsOfDumpOut
+=
totalChildTblsOfDumpOut
;
g_resultStatistics
.
totalRowsOfDumpOut
+=
totalRowsOfDumpOut
;
free
(
threadObj
);
free
(
threadObj
);
}
}
int32_t
taosDumpStable
(
char
*
table
,
FILE
*
fp
,
TAOS
*
taosCon
)
{
int32_t
taosDumpStable
(
char
*
table
,
FILE
*
fp
,
TAOS
*
taosCon
,
char
*
dbName
)
{
int
count
=
0
;
int
count
=
0
;
STableDef
*
tableDes
=
(
STableDef
*
)
calloc
(
1
,
sizeof
(
STableDef
)
+
sizeof
(
SColDes
)
*
TSDB_MAX_COLUMNS
);
STableDef
*
tableDes
=
(
STableDef
*
)
calloc
(
1
,
sizeof
(
STableDef
)
+
sizeof
(
SColDes
)
*
TSDB_MAX_COLUMNS
);
...
@@ -1187,15 +1296,15 @@ int32_t taosDumpStable(char *table, FILE *fp, TAOS* taosCon) {
...
@@ -1187,15 +1296,15 @@ int32_t taosDumpStable(char *table, FILE *fp, TAOS* taosCon) {
exit
(
-
1
);
exit
(
-
1
);
}
}
count
=
taosGetTableDes
(
table
,
tableDes
,
taosCon
,
true
);
count
=
taosGetTableDes
(
dbName
,
table
,
tableDes
,
taosCon
,
true
);
if
(
count
<
0
)
{
if
(
count
<
0
)
{
free
(
tableDes
);
free
(
tableDes
);
fprintf
(
stderr
,
"failed to get stable
schema
\n
"
);
fprintf
(
stderr
,
"failed to get stable
[%s] schema
\n
"
,
table
);
exit
(
-
1
);
exit
(
-
1
);
}
}
taosDumpCreateTableClause
(
tableDes
,
count
,
fp
);
taosDumpCreateTableClause
(
tableDes
,
count
,
fp
,
dbName
);
free
(
tableDes
);
free
(
tableDes
);
return
0
;
return
0
;
...
@@ -1207,38 +1316,19 @@ int32_t taosDumpCreateSuperTableClause(TAOS* taosCon, char* dbName, FILE *fp)
...
@@ -1207,38 +1316,19 @@ int32_t taosDumpCreateSuperTableClause(TAOS* taosCon, char* dbName, FILE *fp)
TAOS_ROW
row
;
TAOS_ROW
row
;
int
fd
=
-
1
;
int
fd
=
-
1
;
STableRecord
tableRecord
;
STableRecord
tableRecord
;
char
sqlstr
[
TSDB_MAX_SQL_LEN
]
=
{
0
};
char
*
tmpCommand
=
(
char
*
)
malloc
(
COMMAND_SIZE
);
sprintf
(
sqlstr
,
"show %s.stables"
,
dbName
);
if
(
tmpCommand
==
NULL
)
{
fprintf
(
stderr
,
"failed to allocate memory
\n
"
);
exit
(
-
1
);
}
sprintf
(
tmpCommand
,
"use %s"
,
dbName
);
TAOS_RES
*
tmpResult
=
taos_query
(
taosCon
,
tmpCommand
);
TAOS_RES
*
res
=
taos_query
(
taosCon
,
sqlstr
);
int32_t
code
=
taos_errno
(
tmpResult
);
int32_t
code
=
taos_errno
(
res
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"invalid database %s, error: %s
\n
"
,
dbName
,
taos_errstr
(
taosCon
));
fprintf
(
stderr
,
"failed to run command <%s>, reason: %s
\n
"
,
sqlstr
,
taos_errstr
(
res
));
free
(
tmpCommand
);
taos_free_result
(
res
);
taos_free_result
(
tmpResult
);
exit
(
-
1
);
}
taos_free_result
(
tmpResult
);
sprintf
(
tmpCommand
,
"show stables"
);
tmpResult
=
taos_query
(
taosCon
,
tmpCommand
);
code
=
taos_errno
(
tmpResult
);
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"failed to run command %s, error: %s
\n
"
,
tmpCommand
,
taos_errstr
(
taosCon
));
free
(
tmpCommand
);
taos_free_result
(
tmpResult
);
exit
(
-
1
);
exit
(
-
1
);
}
}
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
tmpResult
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
res
);
char
tmpFileName
[
TSDB_FILENAME_LEN
+
1
];
char
tmpFileName
[
TSDB_FILENAME_LEN
+
1
];
memset
(
tmpFileName
,
0
,
TSDB_FILENAME_LEN
);
memset
(
tmpFileName
,
0
,
TSDB_FILENAME_LEN
);
...
@@ -1246,32 +1336,38 @@ int32_t taosDumpCreateSuperTableClause(TAOS* taosCon, char* dbName, FILE *fp)
...
@@ -1246,32 +1336,38 @@ int32_t taosDumpCreateSuperTableClause(TAOS* taosCon, char* dbName, FILE *fp)
fd
=
open
(
tmpFileName
,
O_RDWR
|
O_CREAT
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
fd
=
open
(
tmpFileName
,
O_RDWR
|
O_CREAT
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
fprintf
(
stderr
,
"failed to open temp file: %s
\n
"
,
tmpFileName
);
fprintf
(
stderr
,
"failed to open temp file: %s
\n
"
,
tmpFileName
);
taos_free_result
(
tmpResult
);
taos_free_result
(
res
);
free
(
tmpCommand
);
(
void
)
remove
(
".stables.tmp"
);
(
void
)
remove
(
".stables.tmp"
);
exit
(
-
1
);
exit
(
-
1
);
}
}
while
((
row
=
taos_fetch_row
(
tmpResult
))
!=
NULL
)
{
while
((
row
=
taos_fetch_row
(
res
))
!=
NULL
)
{
memset
(
&
tableRecord
,
0
,
sizeof
(
STableRecord
));
memset
(
&
tableRecord
,
0
,
sizeof
(
STableRecord
));
strncpy
(
tableRecord
.
name
,
(
char
*
)
row
[
TSDB_SHOW_TABLES_NAME_INDEX
],
fields
[
TSDB_SHOW_TABLES_NAME_INDEX
].
bytes
);
strncpy
(
tableRecord
.
name
,
(
char
*
)
row
[
TSDB_SHOW_TABLES_NAME_INDEX
],
fields
[
TSDB_SHOW_TABLES_NAME_INDEX
].
bytes
);
taosWrite
(
fd
,
&
tableRecord
,
sizeof
(
STableRecord
));
taosWrite
(
fd
,
&
tableRecord
,
sizeof
(
STableRecord
));
}
}
taos_free_result
(
tmpResult
);
taos_free_result
(
res
);
(
void
)
lseek
(
fd
,
0
,
SEEK_SET
);
(
void
)
lseek
(
fd
,
0
,
SEEK_SET
);
int
superTblCnt
=
0
;
while
(
1
)
{
while
(
1
)
{
ssize_t
readLen
=
read
(
fd
,
&
tableRecord
,
sizeof
(
STableRecord
));
ssize_t
readLen
=
read
(
fd
,
&
tableRecord
,
sizeof
(
STableRecord
));
if
(
readLen
<=
0
)
break
;
if
(
readLen
<=
0
)
break
;
(
void
)
taosDumpStable
(
tableRecord
.
name
,
fp
,
taosCon
);
int
ret
=
taosDumpStable
(
tableRecord
.
name
,
fp
,
taosCon
,
dbName
);
if
(
0
==
ret
)
{
superTblCnt
++
;
}
}
}
// TODO: save dump super table <superTblCnt> into result_output.txt
fprintf
(
g_fpOfResult
,
"# super table counter: %d
\n
"
,
superTblCnt
);
g_resultStatistics
.
totalSuperTblsOfDumpOut
+=
superTblCnt
;
close
(
fd
);
close
(
fd
);
(
void
)
remove
(
".stables.tmp"
);
(
void
)
remove
(
".stables.tmp"
);
free
(
tmpCommand
);
return
0
;
return
0
;
}
}
...
@@ -1283,57 +1379,42 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
...
@@ -1283,57 +1379,42 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
taosDumpCreateDbClause
(
dbInfo
,
arguments
->
with_property
,
fp
);
taosDumpCreateDbClause
(
dbInfo
,
arguments
->
with_property
,
fp
);
char
*
tmpCommand
=
(
char
*
)
malloc
(
COMMAND_SIZE
);
fprintf
(
g_fpOfResult
,
"
\n
#### database: %s
\n
"
,
dbInfo
->
name
);
if
(
tmpCommand
==
NULL
)
{
g_resultStatistics
.
totalDatabasesOfDumpOut
++
;
fprintf
(
stderr
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
sprintf
(
tmpCommand
,
"use %s"
,
dbInfo
->
name
);
char
sqlstr
[
TSDB_MAX_SQL_LEN
]
=
{
0
};
TAOS_RES
*
tmpResult
=
taos_query
(
taosCon
,
tmpCommand
);
int32_t
code
=
taos_errno
(
tmpResult
);
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"invalid database %s
\n
"
,
dbInfo
->
name
);
free
(
tmpCommand
);
taos_free_result
(
tmpResult
);
return
-
1
;
}
taos_free_result
(
tmpResult
);
fprintf
(
fp
,
"USE %s;
\n\n
"
,
dbInfo
->
name
);
fprintf
(
fp
,
"USE %s;
\n\n
"
,
dbInfo
->
name
);
(
void
)
taosDumpCreateSuperTableClause
(
taosCon
,
dbInfo
->
name
,
fp
);
(
void
)
taosDumpCreateSuperTableClause
(
taosCon
,
dbInfo
->
name
,
fp
);
sprintf
(
tmpCommand
,
"show tables"
);
sprintf
(
sqlstr
,
"show %s.tables"
,
dbInfo
->
name
);
tmpResult
=
taos_query
(
taosCon
,
tmpCommand
);
TAOS_RES
*
res
=
taos_query
(
taosCon
,
sqlstr
);
code
=
taos_errno
(
tmpResult
);
int
code
=
taos_errno
(
res
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"failed to run command %s
\n
"
,
tmpCommand
);
fprintf
(
stderr
,
"failed to run command <%s>, reason:%s
\n
"
,
sqlstr
,
taos_errstr
(
res
));
free
(
tmpCommand
);
taos_free_result
(
res
);
taos_free_result
(
tmpResult
);
return
-
1
;
return
-
1
;
}
}
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
tmpResult
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
res
);
int32_t
numOfTable
=
0
;
int32_t
numOfTable
=
0
;
int32_t
numOfThread
=
0
;
int32_t
numOfThread
=
0
;
char
tmpFileName
[
TSDB_FILENAME_LEN
+
1
];
char
tmpFileName
[
TSDB_FILENAME_LEN
+
1
];
while
((
row
=
taos_fetch_row
(
tmpResult
))
!=
NULL
)
{
while
((
row
=
taos_fetch_row
(
res
))
!=
NULL
)
{
if
(
0
==
numOfTable
)
{
if
(
0
==
numOfTable
)
{
memset
(
tmpFileName
,
0
,
TSDB_FILENAME_LEN
);
memset
(
tmpFileName
,
0
,
TSDB_FILENAME_LEN
);
sprintf
(
tmpFileName
,
".tables.tmp.%d"
,
numOfThread
);
sprintf
(
tmpFileName
,
".tables.tmp.%d"
,
numOfThread
);
fd
=
open
(
tmpFileName
,
O_RDWR
|
O_CREAT
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
fd
=
open
(
tmpFileName
,
O_RDWR
|
O_CREAT
,
S_IRWXU
|
S_IRGRP
|
S_IXGRP
|
S_IROTH
);
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
fprintf
(
stderr
,
"failed to open temp file: %s
\n
"
,
tmpFileName
);
fprintf
(
stderr
,
"failed to open temp file: %s
\n
"
,
tmpFileName
);
taos_free_result
(
tmpResult
);
taos_free_result
(
res
);
for
(
int32_t
loopCnt
=
0
;
loopCnt
<
numOfThread
;
loopCnt
++
)
{
for
(
int32_t
loopCnt
=
0
;
loopCnt
<
numOfThread
;
loopCnt
++
)
{
sprintf
(
tmpFileName
,
".tables.tmp.%d"
,
loopCnt
);
sprintf
(
tmpFileName
,
".tables.tmp.%d"
,
loopCnt
);
(
void
)
remove
(
tmpFileName
);
(
void
)
remove
(
tmpFileName
);
}
}
free
(
tmpCommand
);
return
-
1
;
return
-
1
;
}
}
...
@@ -1360,7 +1441,7 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
...
@@ -1360,7 +1441,7 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
fd
=
-
1
;
fd
=
-
1
;
}
}
taos_free_result
(
tmpResult
);
taos_free_result
(
res
);
// start multi threads to dumpout
// start multi threads to dumpout
taosStartDumpOutWorkThreads
(
arguments
,
numOfThread
,
dbInfo
->
name
);
taosStartDumpOutWorkThreads
(
arguments
,
numOfThread
,
dbInfo
->
name
);
...
@@ -1369,24 +1450,17 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
...
@@ -1369,24 +1450,17 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao
(
void
)
remove
(
tmpFileName
);
(
void
)
remove
(
tmpFileName
);
}
}
free
(
tmpCommand
);
return
0
;
return
0
;
}
}
void
taosDumpCreateTableClause
(
STableDef
*
tableDes
,
int
numOfCols
,
FILE
*
fp
)
{
void
taosDumpCreateTableClause
(
STableDef
*
tableDes
,
int
numOfCols
,
FILE
*
fp
,
char
*
dbName
)
{
int
counter
=
0
;
int
counter
=
0
;
int
count_temp
=
0
;
int
count_temp
=
0
;
char
sqlstr
[
COMMAND_SIZE
];
char
*
tmpBuf
=
(
char
*
)
malloc
(
COMMAND_SIZE
);
char
*
pstr
=
sqlstr
;
if
(
tmpBuf
==
NULL
)
{
fprintf
(
stderr
,
"failed to allocate memory
\n
"
);
return
;
}
char
*
pstr
=
tmpBuf
;
pstr
+=
sprintf
(
tmpBuf
,
"CREATE TABLE IF NOT EXISTS %s"
,
tableDes
->
name
);
pstr
+=
sprintf
(
sqlstr
,
"CREATE TABLE IF NOT EXISTS %s.%s"
,
dbName
,
tableDes
->
name
);
for
(;
counter
<
numOfCols
;
counter
++
)
{
for
(;
counter
<
numOfCols
;
counter
++
)
{
if
(
tableDes
->
cols
[
counter
].
note
[
0
]
!=
'\0'
)
break
;
if
(
tableDes
->
cols
[
counter
].
note
[
0
]
!=
'\0'
)
break
;
...
@@ -1420,12 +1494,10 @@ void taosDumpCreateTableClause(STableDef *tableDes, int numOfCols, FILE *fp) {
...
@@ -1420,12 +1494,10 @@ void taosDumpCreateTableClause(STableDef *tableDes, int numOfCols, FILE *fp) {
pstr
+=
sprintf
(
pstr
,
");"
);
pstr
+=
sprintf
(
pstr
,
");"
);
fprintf
(
fp
,
"%s
\n
"
,
tmpBuf
);
fprintf
(
fp
,
"%s
\n\n
"
,
sqlstr
);
free
(
tmpBuf
);
}
}
void
taosDumpCreateMTableClause
(
STableDef
*
tableDes
,
char
*
metric
,
int
numOfCols
,
FILE
*
fp
)
{
void
taosDumpCreateMTableClause
(
STableDef
*
tableDes
,
char
*
metric
,
int
numOfCols
,
FILE
*
fp
,
char
*
dbName
)
{
int
counter
=
0
;
int
counter
=
0
;
int
count_temp
=
0
;
int
count_temp
=
0
;
...
@@ -1438,7 +1510,7 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols
...
@@ -1438,7 +1510,7 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols
char
*
pstr
=
NULL
;
char
*
pstr
=
NULL
;
pstr
=
tmpBuf
;
pstr
=
tmpBuf
;
pstr
+=
sprintf
(
tmpBuf
,
"CREATE TABLE IF NOT EXISTS %s
USING %s TAGS ("
,
tableDes
->
n
ame
,
metric
);
pstr
+=
sprintf
(
tmpBuf
,
"CREATE TABLE IF NOT EXISTS %s
.%s USING %s.%s TAGS ("
,
dbName
,
tableDes
->
name
,
dbN
ame
,
metric
);
for
(;
counter
<
numOfCols
;
counter
++
)
{
for
(;
counter
<
numOfCols
;
counter
++
)
{
if
(
tableDes
->
cols
[
counter
].
note
[
0
]
!=
'\0'
)
break
;
if
(
tableDes
->
cols
[
counter
].
note
[
0
]
!=
'\0'
)
break
;
...
@@ -1479,48 +1551,36 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols
...
@@ -1479,48 +1551,36 @@ void taosDumpCreateMTableClause(STableDef *tableDes, char *metric, int numOfCols
free
(
tmpBuf
);
free
(
tmpBuf
);
}
}
int
taosDumpTableData
(
FILE
*
fp
,
char
*
tbname
,
struct
arguments
*
arguments
,
TAOS
*
taosCon
)
{
int
taosDumpTableData
(
FILE
*
fp
,
char
*
tbname
,
struct
arguments
*
arguments
,
TAOS
*
taosCon
,
char
*
dbName
)
{
/* char temp[MAX_COMMAND_SIZE] = "\0"; */
/* char temp[MAX_COMMAND_SIZE] = "\0"; */
int64_t
totalRows
=
0
;
int64_t
totalRows
=
0
;
int
count
=
0
;
int
count
=
0
;
char
*
pstr
=
NULL
;
char
*
pstr
=
NULL
;
TAOS_ROW
row
=
NULL
;
TAOS_ROW
row
=
NULL
;
int
numFields
=
0
;
int
numFields
=
0
;
char
*
tbuf
=
NULL
;
char
*
tmpCommand
=
(
char
*
)
calloc
(
1
,
COMMAND_SIZE
);
if
(
arguments
->
schemaonly
)
{
if
(
tmpCommand
==
NULL
)
{
return
0
;
fprintf
(
stderr
,
"failed to allocate memory
\n
"
);
return
-
1
;
}
}
int32_t
sql_buf_len
=
arguments
->
max_sql_len
;
int32_t
sql_buf_len
=
arguments
->
max_sql_len
;
char
*
tmpBuffer
=
(
char
*
)
calloc
(
1
,
sql_buf_len
+
128
);
char
*
tmpBuffer
=
(
char
*
)
calloc
(
1
,
sql_buf_len
+
128
);
if
(
tmpBuffer
==
NULL
)
{
if
(
tmpBuffer
==
NULL
)
{
fprintf
(
stderr
,
"failed to allocate memory
\n
"
);
fprintf
(
stderr
,
"failed to allocate memory
\n
"
);
free
(
tmpCommand
);
return
-
1
;
return
-
1
;
}
}
pstr
=
tmpBuffer
;
pstr
=
tmpBuffer
;
if
(
arguments
->
schemaonly
)
{
char
sqlstr
[
1024
]
=
{
0
};
free
(
tmpCommand
);
sprintf
(
sqlstr
,
free
(
tmpBuffer
);
"select * from %s.%s where _c0 >= %"
PRId64
" and _c0 <= %"
PRId64
" order by _c0 asc;"
,
return
0
;
dbName
,
tbname
,
arguments
->
start_time
,
arguments
->
end_time
);
}
sprintf
(
tmpCommand
,
"select * from %s where _c0 >= %"
PRId64
" and _c0 <= %"
PRId64
" order by _c0 asc"
,
tbname
,
arguments
->
start_time
,
arguments
->
end_time
);
TAOS_RES
*
tmpResult
=
taos_query
(
taosCon
,
tmpCommand
);
TAOS_RES
*
tmpResult
=
taos_query
(
taosCon
,
sqlstr
);
int32_t
code
=
taos_errno
(
tmpResult
);
int32_t
code
=
taos_errno
(
tmpResult
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
fprintf
(
stderr
,
"failed to run command %s, reason: %s
\n
"
,
tmpCommand
,
taos_errstr
(
taosCon
));
fprintf
(
stderr
,
"failed to run command %s, reason: %s
\n
"
,
sqlstr
,
taos_errstr
(
tmpResult
));
free
(
tmpCommand
);
free
(
tmpBuffer
);
free
(
tmpBuffer
);
taos_free_result
(
tmpResult
);
taos_free_result
(
tmpResult
);
return
-
1
;
return
-
1
;
...
@@ -1529,14 +1589,6 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
...
@@ -1529,14 +1589,6 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
numFields
=
taos_field_count
(
tmpResult
);
numFields
=
taos_field_count
(
tmpResult
);
assert
(
numFields
>
0
);
assert
(
numFields
>
0
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
tmpResult
);
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
tmpResult
);
tbuf
=
(
char
*
)
malloc
(
COMMAND_SIZE
);
if
(
tbuf
==
NULL
)
{
fprintf
(
stderr
,
"No enough memory
\n
"
);
free
(
tmpCommand
);
free
(
tmpBuffer
);
taos_free_result
(
tmpResult
);
return
-
1
;
}
int
rowFlag
=
0
;
int
rowFlag
=
0
;
int32_t
curr_sqlstr_len
=
0
;
int32_t
curr_sqlstr_len
=
0
;
...
@@ -1550,7 +1602,7 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
...
@@ -1550,7 +1602,7 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
if
(
count
==
0
)
{
if
(
count
==
0
)
{
total_sqlstr_len
=
0
;
total_sqlstr_len
=
0
;
curr_sqlstr_len
+=
sprintf
(
pstr
+
curr_sqlstr_len
,
"INSERT INTO %s
VALUES ("
,
tbname
);
curr_sqlstr_len
+=
sprintf
(
pstr
+
curr_sqlstr_len
,
"INSERT INTO %s
.%s VALUES ("
,
dbName
,
tbname
);
}
else
{
}
else
{
if
(
arguments
->
mysqlFlag
)
{
if
(
arguments
->
mysqlFlag
)
{
if
(
0
==
rowFlag
)
{
if
(
0
==
rowFlag
)
{
...
@@ -1594,17 +1646,21 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
...
@@ -1594,17 +1646,21 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
case
TSDB_DATA_TYPE_DOUBLE
:
case
TSDB_DATA_TYPE_DOUBLE
:
curr_sqlstr_len
+=
sprintf
(
pstr
+
curr_sqlstr_len
,
"%f"
,
GET_DOUBLE_VAL
(
row
[
col
]));
curr_sqlstr_len
+=
sprintf
(
pstr
+
curr_sqlstr_len
,
"%f"
,
GET_DOUBLE_VAL
(
row
[
col
]));
break
;
break
;
case
TSDB_DATA_TYPE_BINARY
:
case
TSDB_DATA_TYPE_BINARY
:
{
char
tbuf
[
COMMAND_SIZE
]
=
{
0
};
//*(pstr++) = '\'';
//*(pstr++) = '\'';
converStringToReadable
((
char
*
)
row
[
col
],
length
[
col
],
tbuf
,
COMMAND_SIZE
);
converStringToReadable
((
char
*
)
row
[
col
],
length
[
col
],
tbuf
,
COMMAND_SIZE
);
//pstr = stpcpy(pstr, tbuf);
//pstr = stpcpy(pstr, tbuf);
//*(pstr++) = '\'';
//*(pstr++) = '\'';
pstr
+=
sprintf
(
pstr
+
curr_sqlstr_len
,
"
\'
%s
\'
"
,
tbuf
);
pstr
+=
sprintf
(
pstr
+
curr_sqlstr_len
,
"
\'
%s
\'
"
,
tbuf
);
break
;
break
;
case
TSDB_DATA_TYPE_NCHAR
:
}
case
TSDB_DATA_TYPE_NCHAR
:
{
char
tbuf
[
COMMAND_SIZE
]
=
{
0
};
convertNCharToReadable
((
char
*
)
row
[
col
],
length
[
col
],
tbuf
,
COMMAND_SIZE
);
convertNCharToReadable
((
char
*
)
row
[
col
],
length
[
col
],
tbuf
,
COMMAND_SIZE
);
pstr
+=
sprintf
(
pstr
+
curr_sqlstr_len
,
"
\'
%s
\'
"
,
tbuf
);
pstr
+=
sprintf
(
pstr
+
curr_sqlstr_len
,
"
\'
%s
\'
"
,
tbuf
);
break
;
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
if
(
!
arguments
->
mysqlFlag
)
{
if
(
!
arguments
->
mysqlFlag
)
{
curr_sqlstr_len
+=
sprintf
(
pstr
+
curr_sqlstr_len
,
"%"
PRId64
""
,
*
(
int64_t
*
)
row
[
col
]);
curr_sqlstr_len
+=
sprintf
(
pstr
+
curr_sqlstr_len
,
"%"
PRId64
""
,
*
(
int64_t
*
)
row
[
col
]);
...
@@ -1638,19 +1694,12 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
...
@@ -1638,19 +1694,12 @@ int taosDumpTableData(FILE *fp, char *tbname, struct arguments *arguments, TAOS*
//}
//}
}
}
atomic_add_fetch_64
(
&
totalDumpOutRows
,
totalRows
);
fprintf
(
fp
,
"
\n
"
);
fprintf
(
fp
,
"
\n
"
);
atomic_add_fetch_64
(
&
totalDumpOutRows
,
totalRows
);
if
(
tbuf
)
{
free
(
tbuf
);
}
taos_free_result
(
tmpResult
);
taos_free_result
(
tmpResult
);
tmpResult
=
NULL
;
free
(
tmpCommand
);
free
(
tmpBuffer
);
free
(
tmpBuffer
);
return
0
;
return
totalRows
;
}
}
int
taosCheckParam
(
struct
arguments
*
arguments
)
{
int
taosCheckParam
(
struct
arguments
*
arguments
)
{
...
@@ -1986,159 +2035,6 @@ static FILE* taosOpenDumpInFile(char *fptr) {
...
@@ -1986,159 +2035,6 @@ static FILE* taosOpenDumpInFile(char *fptr) {
return
f
;
return
f
;
}
}
int
taosDumpInOneFile_old
(
TAOS
*
taos
,
FILE
*
fp
,
char
*
fcharset
,
char
*
encode
)
{
char
*
command
=
NULL
;
char
*
lcommand
=
NULL
;
int
tsize
=
0
;
char
*
line
=
NULL
;
_Bool
isRun
=
true
;
size_t
line_size
=
0
;
char
*
pstr
=
NULL
;
char
*
lstr
=
NULL
;
size_t
inbytesleft
=
0
;
size_t
outbytesleft
=
COMMAND_SIZE
;
char
*
tcommand
=
NULL
;
char
*
charsetOfFile
=
NULL
;
iconv_t
cd
=
(
iconv_t
)(
-
1
);
command
=
(
char
*
)
malloc
(
COMMAND_SIZE
);
lcommand
=
(
char
*
)
malloc
(
COMMAND_SIZE
);
if
(
command
==
NULL
||
lcommand
==
NULL
)
{
fprintf
(
stderr
,
"failed to connect to allocate memory
\n
"
);
goto
_dumpin_exit_failure
;
}
// Resolve locale
if
(
*
fcharset
!=
'\0'
)
{
charsetOfFile
=
fcharset
;
}
else
{
charsetOfFile
=
encode
;
}
if
(
charsetOfFile
!=
NULL
&&
strcasecmp
(
tsCharset
,
charsetOfFile
)
!=
0
)
{
cd
=
iconv_open
(
tsCharset
,
charsetOfFile
);
if
(
cd
==
((
iconv_t
)(
-
1
)))
{
fprintf
(
stderr
,
"Failed to open iconv handle
\n
"
);
goto
_dumpin_exit_failure
;
}
}
pstr
=
command
;
int64_t
linenu
=
0
;
while
(
1
)
{
ssize_t
size
=
getline
(
&
line
,
&
line_size
,
fp
);
linenu
++
;
if
(
size
<=
0
)
break
;
if
(
size
==
1
)
{
if
(
pstr
!=
command
)
{
inbytesleft
=
pstr
-
command
;
memset
(
lcommand
,
0
,
COMMAND_SIZE
);
pstr
=
command
;
lstr
=
lcommand
;
outbytesleft
=
COMMAND_SIZE
;
if
(
cd
!=
((
iconv_t
)(
-
1
)))
{
iconv
(
cd
,
&
pstr
,
&
inbytesleft
,
&
lstr
,
&
outbytesleft
);
tcommand
=
lcommand
;
}
else
{
tcommand
=
command
;
}
taosReplaceCtrlChar
(
tcommand
);
if
(
queryDB
(
taos
,
tcommand
)
!=
0
)
{
fprintf
(
stderr
,
"error sql: linenu: %"
PRId64
" failed
\n
"
,
linenu
);
exit
(
0
);
}
pstr
=
command
;
pstr
[
0
]
=
'\0'
;
tsize
=
0
;
isRun
=
true
;
}
continue
;
}
/* if (line[0] == '-' && line[1] == '-') continue; */
line
[
size
-
1
]
=
0
;
if
(
tsize
+
size
-
1
>
COMMAND_SIZE
)
{
fprintf
(
stderr
,
"command is too long
\n
"
);
goto
_dumpin_exit_failure
;
}
if
(
line
[
size
-
2
]
==
'\\'
)
{
line
[
size
-
2
]
=
' '
;
isRun
=
false
;
}
else
{
isRun
=
true
;
}
memcpy
(
pstr
,
line
,
size
-
1
);
pstr
+=
(
size
-
1
);
*
pstr
=
'\0'
;
if
(
!
isRun
)
continue
;
if
(
command
!=
pstr
&&
!
isEmptyCommand
(
command
))
{
inbytesleft
=
pstr
-
command
;
memset
(
lcommand
,
0
,
COMMAND_SIZE
);
pstr
=
command
;
lstr
=
lcommand
;
outbytesleft
=
COMMAND_SIZE
;
if
(
cd
!=
((
iconv_t
)(
-
1
)))
{
iconv
(
cd
,
&
pstr
,
&
inbytesleft
,
&
lstr
,
&
outbytesleft
);
tcommand
=
lcommand
;
}
else
{
tcommand
=
command
;
}
taosReplaceCtrlChar
(
tcommand
);
if
(
queryDB
(
taos
,
tcommand
)
!=
0
)
{
fprintf
(
stderr
,
"error sql: linenu:%"
PRId64
" failed
\n
"
,
linenu
);
exit
(
0
);
}
}
pstr
=
command
;
*
pstr
=
'\0'
;
tsize
=
0
;
}
if
(
pstr
!=
command
)
{
inbytesleft
=
pstr
-
command
;
memset
(
lcommand
,
0
,
COMMAND_SIZE
);
pstr
=
command
;
lstr
=
lcommand
;
outbytesleft
=
COMMAND_SIZE
;
if
(
cd
!=
((
iconv_t
)(
-
1
)))
{
iconv
(
cd
,
&
pstr
,
&
inbytesleft
,
&
lstr
,
&
outbytesleft
);
tcommand
=
lcommand
;
}
else
{
tcommand
=
command
;
}
taosReplaceCtrlChar
(
lcommand
);
if
(
queryDB
(
taos
,
tcommand
)
!=
0
)
fprintf
(
stderr
,
"error sql: linenu:%"
PRId64
" failed
\n
"
,
linenu
);
}
if
(
cd
!=
((
iconv_t
)(
-
1
)))
iconv_close
(
cd
);
tfree
(
line
);
tfree
(
command
);
tfree
(
lcommand
);
taos_close
(
taos
);
fclose
(
fp
);
return
0
;
_dumpin_exit_failure:
if
(
cd
!=
((
iconv_t
)(
-
1
)))
iconv_close
(
cd
);
tfree
(
command
);
tfree
(
lcommand
);
taos_close
(
taos
);
fclose
(
fp
);
return
-
1
;
}
int
taosDumpInOneFile
(
TAOS
*
taos
,
FILE
*
fp
,
char
*
fcharset
,
char
*
encode
,
char
*
fileName
)
{
int
taosDumpInOneFile
(
TAOS
*
taos
,
FILE
*
fp
,
char
*
fcharset
,
char
*
encode
,
char
*
fileName
)
{
int
read_len
=
0
;
int
read_len
=
0
;
char
*
cmd
=
NULL
;
char
*
cmd
=
NULL
;
...
@@ -2172,8 +2068,9 @@ int taosDumpInOneFile(TAOS * taos, FILE* fp, char* fcharset, char* encode, c
...
@@ -2172,8 +2068,9 @@ int taosDumpInOneFile(TAOS * taos, FILE* fp, char* fcharset, char* encode, c
memcpy
(
cmd
+
cmd_len
,
line
,
read_len
);
memcpy
(
cmd
+
cmd_len
,
line
,
read_len
);
cmd
[
read_len
+
cmd_len
]
=
'\0'
;
cmd
[
read_len
+
cmd_len
]
=
'\0'
;
if
(
queryD
B
(
taos
,
cmd
))
{
if
(
queryD
bImpl
(
taos
,
cmd
))
{
fprintf
(
stderr
,
"error sql: linenu:%d, file:%s
\n
"
,
lineNo
,
fileName
);
fprintf
(
stderr
,
"error sql: linenu:%d, file:%s
\n
"
,
lineNo
,
fileName
);
fprintf
(
g_fpOfResult
,
"error sql: linenu:%d, file:%s
\n
"
,
lineNo
,
fileName
);
}
}
memset
(
cmd
,
0
,
TSDB_MAX_ALLOWED_SQL_LEN
);
memset
(
cmd
,
0
,
TSDB_MAX_ALLOWED_SQL_LEN
);
...
@@ -2221,7 +2118,7 @@ static void taosStartDumpInWorkThreads(struct arguments *args)
...
@@ -2221,7 +2118,7 @@ static void taosStartDumpInWorkThreads(struct arguments *args)
pThread
->
totalThreads
=
totalThreads
;
pThread
->
totalThreads
=
totalThreads
;
pThread
->
taosCon
=
taos_connect
(
args
->
host
,
args
->
user
,
args
->
password
,
NULL
,
args
->
port
);
pThread
->
taosCon
=
taos_connect
(
args
->
host
,
args
->
user
,
args
->
password
,
NULL
,
args
->
port
);
if
(
pThread
->
taosCon
==
NULL
)
{
if
(
pThread
->
taosCon
==
NULL
)
{
fprintf
(
stderr
,
"ERROR: thread:%d failed connect to TDengine,
error:%s
\n
"
,
pThread
->
threadIndex
,
taos_errstr
(
pThread
->
taosCon
));
fprintf
(
stderr
,
"ERROR: thread:%d failed connect to TDengine,
reason:%s
\n
"
,
pThread
->
threadIndex
,
taos_errstr
(
NULL
));
exit
(
0
);
exit
(
0
);
}
}
...
...
src/mnode/src/mnodeProfile.c
浏览文件 @
3adbf1a7
...
@@ -450,6 +450,12 @@ static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p
...
@@ -450,6 +450,12 @@ static int32_t mnodeGetStreamMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_TABLE_NAME_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"dest table"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_IPv4ADDR_LEN
+
6
+
VARSTR_HEADER_SIZE
;
pShow
->
bytes
[
cols
]
=
TSDB_IPv4ADDR_LEN
+
6
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"ip:port"
);
strcpy
(
pSchema
[
cols
].
name
,
"ip:port"
);
...
@@ -524,6 +530,10 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v
...
@@ -524,6 +530,10 @@ static int32_t mnodeRetrieveStreams(SShowObj *pShow, char *data, int32_t rows, v
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pConnObj
->
user
,
pShow
->
bytes
[
cols
]);
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pConnObj
->
user
,
pShow
->
bytes
[
cols
]);
cols
++
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pDesc
->
dstTable
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
snprintf
(
ipStr
,
sizeof
(
ipStr
),
"%s:%u"
,
taosIpStr
(
pConnObj
->
ip
),
pConnObj
->
port
);
snprintf
(
ipStr
,
sizeof
(
ipStr
),
"%s:%u"
,
taosIpStr
(
pConnObj
->
ip
),
pConnObj
->
port
);
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
ipStr
,
pShow
->
bytes
[
cols
]);
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
ipStr
,
pShow
->
bytes
[
cols
]);
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
3adbf1a7
...
@@ -872,7 +872,7 @@ static void tsdbStartStream(STsdbRepo *pRepo) {
...
@@ -872,7 +872,7 @@ static void tsdbStartStream(STsdbRepo *pRepo) {
for
(
int
i
=
0
;
i
<
pMeta
->
maxTables
;
i
++
)
{
for
(
int
i
=
0
;
i
<
pMeta
->
maxTables
;
i
++
)
{
STable
*
pTable
=
pMeta
->
tables
[
i
];
STable
*
pTable
=
pMeta
->
tables
[
i
];
if
(
pTable
&&
pTable
->
type
==
TSDB_STREAM_TABLE
)
{
if
(
pTable
&&
pTable
->
type
==
TSDB_STREAM_TABLE
)
{
pTable
->
cqhandle
=
(
*
pRepo
->
appH
.
cqCreateFunc
)(
pRepo
->
appH
.
cqH
,
TABLE_UID
(
pTable
),
TABLE_TID
(
pTable
),
pTable
->
sql
,
pTable
->
cqhandle
=
(
*
pRepo
->
appH
.
cqCreateFunc
)(
pRepo
->
appH
.
cqH
,
TABLE_UID
(
pTable
),
TABLE_TID
(
pTable
),
TABLE_NAME
(
pTable
)
->
data
,
pTable
->
sql
,
tsdbGetTableSchemaImpl
(
pTable
,
false
,
false
,
-
1
));
tsdbGetTableSchemaImpl
(
pTable
,
false
,
false
,
-
1
));
}
}
}
}
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
3adbf1a7
...
@@ -828,7 +828,7 @@ static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx, boo
...
@@ -828,7 +828,7 @@ static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx, boo
if
(
lock
&&
tsdbUnlockRepoMeta
(
pRepo
)
<
0
)
return
-
1
;
if
(
lock
&&
tsdbUnlockRepoMeta
(
pRepo
)
<
0
)
return
-
1
;
if
(
TABLE_TYPE
(
pTable
)
==
TSDB_STREAM_TABLE
&&
addIdx
)
{
if
(
TABLE_TYPE
(
pTable
)
==
TSDB_STREAM_TABLE
&&
addIdx
)
{
pTable
->
cqhandle
=
(
*
pRepo
->
appH
.
cqCreateFunc
)(
pRepo
->
appH
.
cqH
,
TABLE_UID
(
pTable
),
TABLE_TID
(
pTable
),
pTable
->
sql
,
pTable
->
cqhandle
=
(
*
pRepo
->
appH
.
cqCreateFunc
)(
pRepo
->
appH
.
cqH
,
TABLE_UID
(
pTable
),
TABLE_TID
(
pTable
),
TABLE_NAME
(
pTable
)
->
data
,
pTable
->
sql
,
tsdbGetTableSchemaImpl
(
pTable
,
false
,
false
,
-
1
));
tsdbGetTableSchemaImpl
(
pTable
,
false
,
false
,
-
1
));
}
}
...
...
tests/pytest/fulltest.sh
浏览文件 @
3adbf1a7
...
@@ -22,6 +22,7 @@ python3 ./test.py -f insert/insertIntoTwoTables.py
...
@@ -22,6 +22,7 @@ python3 ./test.py -f insert/insertIntoTwoTables.py
python3 ./test.py
-f
insert/before_1970.py
python3 ./test.py
-f
insert/before_1970.py
python3 bug2265.py
python3 bug2265.py
#table
python3 ./test.py
-f
table/alter_wal0.py
python3 ./test.py
-f
table/alter_wal0.py
python3 ./test.py
-f
table/column_name.py
python3 ./test.py
-f
table/column_name.py
python3 ./test.py
-f
table/column_num.py
python3 ./test.py
-f
table/column_num.py
...
@@ -29,6 +30,12 @@ python3 ./test.py -f table/db_table.py
...
@@ -29,6 +30,12 @@ python3 ./test.py -f table/db_table.py
python3 ./test.py
-f
table/create_sensitive.py
python3 ./test.py
-f
table/create_sensitive.py
#python3 ./test.py -f table/tablename-boundary.py
#python3 ./test.py -f table/tablename-boundary.py
python3 ./test.py
-f
table/max_table_length.py
python3 ./test.py
-f
table/max_table_length.py
python3 ./test.py
-f
table/alter_column.py
python3 ./test.py
-f
table/boundary.py
python3 ./test.py
-f
table/create-a-lot.py
python3 ./test.py
-f
table/create.py
python3 ./test.py
-f
table/del_stable.py
python3 ./test.py
-f
table/queryWithTaosdKilled.py
# tag
# tag
...
@@ -138,9 +145,6 @@ python3 ./test.py -f user/pass_len.py
...
@@ -138,9 +145,6 @@ python3 ./test.py -f user/pass_len.py
# stable
# stable
python3 ./test.py
-f
stable/query_after_reset.py
python3 ./test.py
-f
stable/query_after_reset.py
# table
python3 ./test.py
-f
table/del_stable.py
#query
#query
python3 ./test.py
-f
query/filter.py
python3 ./test.py
-f
query/filter.py
python3 ./test.py
-f
query/filterCombo.py
python3 ./test.py
-f
query/filterCombo.py
...
...
tests/pytest/pytest_1.sh
浏览文件 @
3adbf1a7
...
@@ -20,6 +20,7 @@ python3 insert/retentionpolicy.py
...
@@ -20,6 +20,7 @@ python3 insert/retentionpolicy.py
python3 ./test.py
-f
insert/alterTableAndInsert.py
python3 ./test.py
-f
insert/alterTableAndInsert.py
python3 ./test.py
-f
insert/insertIntoTwoTables.py
python3 ./test.py
-f
insert/insertIntoTwoTables.py
#table
python3 ./test.py
-f
table/alter_wal0.py
python3 ./test.py
-f
table/alter_wal0.py
python3 ./test.py
-f
table/column_name.py
python3 ./test.py
-f
table/column_name.py
python3 ./test.py
-f
table/column_num.py
python3 ./test.py
-f
table/column_num.py
...
@@ -27,6 +28,12 @@ python3 ./test.py -f table/db_table.py
...
@@ -27,6 +28,12 @@ python3 ./test.py -f table/db_table.py
python3 ./test.py
-f
table/create_sensitive.py
python3 ./test.py
-f
table/create_sensitive.py
#python3 ./test.py -f table/tablename-boundary.py
#python3 ./test.py -f table/tablename-boundary.py
python3 ./test.py
-f
table/max_table_length.py
python3 ./test.py
-f
table/max_table_length.py
python3 ./test.py
-f
table/alter_column.py
python3 ./test.py
-f
table/boundary.py
python3 ./test.py
-f
table/create-a-lot.py
python3 ./test.py
-f
table/create.py
python3 ./test.py
-f
table/del_stable.py
python3 ./test.py
-f
table/queryWithTaosdKilled.py
# tag
# tag
python3 ./test.py
-f
tag_lite/filter.py
python3 ./test.py
-f
tag_lite/filter.py
...
@@ -135,9 +142,6 @@ python3 ./test.py -f user/pass_len.py
...
@@ -135,9 +142,6 @@ python3 ./test.py -f user/pass_len.py
# stable
# stable
python3 ./test.py
-f
stable/query_after_reset.py
python3 ./test.py
-f
stable/query_after_reset.py
# table
python3 ./test.py
-f
table/del_stable.py
#query
#query
python3 ./test.py
-f
query/filter.py
python3 ./test.py
-f
query/filter.py
python3 ./test.py
-f
query/filterCombo.py
python3 ./test.py
-f
query/filterCombo.py
...
...
tests/pytest/table/createTableFromAnotherDb.py
0 → 100644
浏览文件 @
3adbf1a7
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
sys
import
taos
from
util.log
import
tdLog
from
util.cases
import
tdCases
from
util.sql
import
tdSql
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
(),
logSql
)
def
run
(
self
):
tdSql
.
prepare
()
print
(
"==============step1"
)
tdSql
.
execute
(
"create table db.cars(ts timestamp, c int) tags(id int);"
)
tdSql
.
execute
(
"create database db2"
)
tdSql
.
error
(
"create table db2.car1 using db.cars tags(1)"
)
tdSql
.
error
(
"insert into db2.car1 using db1.cars tags(1) values(now, 1);"
)
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录