Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
51490bdb
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看板
未验证
提交
51490bdb
编写于
12月 18, 2021
作者:
S
Shengliang Guan
提交者:
GitHub
12月 18, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9182 from taosdata/feature/dnode3
make script/sh available
上级
4658a963
aace32e6
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
171 addition
and
411 deletion
+171
-411
CMakeLists.txt
CMakeLists.txt
+2
-1
include/util/tdef.h
include/util/tdef.h
+1
-0
source/dnode/mgmt/daemon/src/daemon.c
source/dnode/mgmt/daemon/src/daemon.c
+1
-0
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+1
-1
source/dnode/mnode/impl/src/mndDb.c
source/dnode/mnode/impl/src/mndDb.c
+12
-11
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+4
-23
tests/CMakeLists.txt
tests/CMakeLists.txt
+3
-14
tests/script/general/user/basic1.sim
tests/script/general/user/basic1.sim
+5
-5
tests/script/sh/deploy.sh
tests/script/sh/deploy.sh
+6
-3
tests/script/sh/exec.sh
tests/script/sh/exec.sh
+7
-4
tests/script/test.sh
tests/script/test.sh
+5
-21
tests/tsim/CMakeLists.txt
tests/tsim/CMakeLists.txt
+14
-9
tests/tsim/inc/sim.h
tests/tsim/inc/sim.h
+30
-31
tests/tsim/inc/simParse.h
tests/tsim/inc/simParse.h
+7
-7
tests/tsim/src/simExe.c
tests/tsim/src/simExe.c
+43
-250
tests/tsim/src/simMain.c
tests/tsim/src/simMain.c
+3
-7
tests/tsim/src/simParse.c
tests/tsim/src/simParse.c
+15
-15
tests/tsim/src/simSystem.c
tests/tsim/src/simSystem.c
+8
-7
tools/shell/inc/shellCommand.h
tools/shell/inc/shellCommand.h
+2
-2
tools/shell/src/shellLinux.c
tools/shell/src/shellLinux.c
+2
-0
未找到文件。
CMakeLists.txt
浏览文件 @
51490bdb
...
...
@@ -26,8 +26,9 @@ if(${BUILD_TEST})
endif
(
${
BUILD_TEST
}
)
add_subdirectory
(
source
)
add_subdirectory
(
tools
)
add_subdirectory
(
tests
)
# docs
add_subdirectory
(
docs
)
# tests (TODO)
\ No newline at end of file
# tests (TODO)
include/util/tdef.h
浏览文件 @
51490bdb
...
...
@@ -235,6 +235,7 @@ do { \
#define TSDB_MAX_VNODES 512
#define TSDB_MIN_VNODES_PER_DB 1
#define TSDB_MAX_VNODES_PER_DB 4096
#define TSDB_DEFAULT_VN_PER_DB 2
#define TSDB_DNODE_ROLE_ANY 0
#define TSDB_DNODE_ROLE_MGMT 1
...
...
source/dnode/mgmt/daemon/src/daemon.c
浏览文件 @
51490bdb
...
...
@@ -92,6 +92,7 @@ void dmnPrintVersion() {
}
int
dmnReadConfig
(
const
char
*
path
)
{
tstrncpy
(
configDir
,
global
.
configDir
,
PATH_MAX
);
taosInitGlobalCfg
();
taosReadGlobalLogCfg
();
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
51490bdb
...
...
@@ -182,6 +182,7 @@ typedef struct {
}
SUserObj
;
typedef
struct
{
int32_t
numOfVgroups
;
int32_t
cacheBlockSize
;
int32_t
totalBlocks
;
int32_t
daysPerFile
;
...
...
@@ -209,7 +210,6 @@ typedef struct {
int64_t
uid
;
int32_t
cfgVersion
;
int32_t
vgVersion
;
int32_t
numOfVgroups
;
int8_t
hashMethod
;
// default is 1
SDbCfg
cfg
;
}
SDbObj
;
...
...
source/dnode/mnode/impl/src/mndDb.c
浏览文件 @
51490bdb
...
...
@@ -77,8 +77,8 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
SDB_SET_INT64
(
pRaw
,
dataPos
,
pDb
->
uid
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfgVersion
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
vgVersion
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
numOfVgroups
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pDb
->
hashMethod
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
numOfVgroups
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
cacheBlockSize
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
totalBlocks
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pDb
->
cfg
.
daysPerFile
)
...
...
@@ -124,8 +124,8 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
uid
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfgVersion
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
vgVersion
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
numOfVgroups
)
SDB_GET_INT8
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
hashMethod
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
numOfVgroups
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
cacheBlockSize
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
totalBlocks
)
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pDb
->
cfg
.
daysPerFile
)
...
...
@@ -163,7 +163,6 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) {
pOldDb
->
updateTime
=
pNewDb
->
createdTime
;
pOldDb
->
cfgVersion
=
pNewDb
->
cfgVersion
;
pOldDb
->
vgVersion
=
pNewDb
->
vgVersion
;
pOldDb
->
numOfVgroups
=
pNewDb
->
numOfVgroups
;
memcpy
(
&
pOldDb
->
cfg
,
&
pNewDb
->
cfg
,
sizeof
(
SDbCfg
));
return
0
;
}
...
...
@@ -195,6 +194,7 @@ static int32_t mndCheckDbName(char *dbName, SUserObj *pUser) {
}
static
int32_t
mndCheckDbCfg
(
SMnode
*
pMnode
,
SDbCfg
*
pCfg
)
{
if
(
pCfg
->
numOfVgroups
<
TSDB_MIN_VNODES_PER_DB
||
pCfg
->
numOfVgroups
>
TSDB_MAX_VNODES_PER_DB
)
return
-
1
;
if
(
pCfg
->
cacheBlockSize
<
TSDB_MIN_CACHE_BLOCK_SIZE
||
pCfg
->
cacheBlockSize
>
TSDB_MAX_CACHE_BLOCK_SIZE
)
return
-
1
;
if
(
pCfg
->
totalBlocks
<
TSDB_MIN_TOTAL_BLOCKS
||
pCfg
->
totalBlocks
>
TSDB_MAX_TOTAL_BLOCKS
)
return
-
1
;
if
(
pCfg
->
daysPerFile
<
TSDB_MIN_DAYS_PER_FILE
||
pCfg
->
daysPerFile
>
TSDB_MAX_DAYS_PER_FILE
)
return
-
1
;
...
...
@@ -222,6 +222,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
}
static
void
mndSetDefaultDbCfg
(
SDbCfg
*
pCfg
)
{
if
(
pCfg
->
numOfVgroups
<
0
)
pCfg
->
numOfVgroups
=
TSDB_DEFAULT_VN_PER_DB
;
if
(
pCfg
->
cacheBlockSize
<
0
)
pCfg
->
cacheBlockSize
=
TSDB_DEFAULT_CACHE_BLOCK_SIZE
;
if
(
pCfg
->
totalBlocks
<
0
)
pCfg
->
totalBlocks
=
TSDB_DEFAULT_TOTAL_BLOCKS
;
if
(
pCfg
->
daysPerFile
<
0
)
pCfg
->
daysPerFile
=
TSDB_DEFAULT_DAYS_PER_FILE
;
...
...
@@ -246,7 +247,7 @@ static int32_t mndSetRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb
if
(
pDbRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pDbRaw
)
!=
0
)
return
-
1
;
sdbSetRawStatus
(
pDbRaw
,
SDB_STATUS_CREATING
);
for
(
int
v
=
0
;
v
<
pDb
->
numOfVgroups
;
++
v
)
{
for
(
int
v
=
0
;
v
<
pDb
->
cfg
.
numOfVgroups
;
++
v
)
{
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
pVgroups
+
v
);
if
(
pVgRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pVgRaw
)
!=
0
)
return
-
1
;
sdbSetRawStatus
(
pVgRaw
,
SDB_STATUS_CREATING
);
...
...
@@ -260,7 +261,7 @@ static int32_t mndSetUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb
if
(
pDbRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pDbRaw
)
!=
0
)
return
-
1
;
sdbSetRawStatus
(
pDbRaw
,
SDB_STATUS_DROPPED
);
for
(
int
v
=
0
;
v
<
pDb
->
numOfVgroups
;
++
v
)
{
for
(
int
v
=
0
;
v
<
pDb
->
cfg
.
numOfVgroups
;
++
v
)
{
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
pVgroups
+
v
);
if
(
pVgRaw
==
NULL
||
mndTransAppendUndolog
(
pTrans
,
pVgRaw
)
!=
0
)
return
-
1
;
sdbSetRawStatus
(
pVgRaw
,
SDB_STATUS_DROPPED
);
...
...
@@ -274,7 +275,7 @@ static int32_t mndSetCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVg
if
(
pDbRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pDbRaw
)
!=
0
)
return
-
1
;
sdbSetRawStatus
(
pDbRaw
,
SDB_STATUS_READY
);
for
(
int
v
=
0
;
v
<
pDb
->
numOfVgroups
;
++
v
)
{
for
(
int
v
=
0
;
v
<
pDb
->
cfg
.
numOfVgroups
;
++
v
)
{
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
pVgroups
+
v
);
if
(
pVgRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pVgRaw
)
!=
0
)
return
-
1
;
sdbSetRawStatus
(
pVgRaw
,
SDB_STATUS_READY
);
...
...
@@ -298,11 +299,11 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat
dbObj
.
createdTime
=
taosGetTimestampMs
();
dbObj
.
updateTime
=
dbObj
.
createdTime
;
dbObj
.
uid
=
mndGenerateUid
(
dbObj
.
name
,
TSDB_FULL_DB_NAME_LEN
);
dbObj
.
numOfVgroups
=
pCreate
->
numOfVgroups
;
dbObj
.
hashMethod
=
1
;
dbObj
.
cfgVersion
=
1
;
dbObj
.
vgVersion
=
1
;
dbObj
.
cfg
=
(
SDbCfg
){.
cacheBlockSize
=
pCreate
->
cacheBlockSize
,
dbObj
.
cfg
=
(
SDbCfg
){.
numOfVgroups
=
pCreate
->
numOfVgroups
,
.
cacheBlockSize
=
pCreate
->
cacheBlockSize
,
.
totalBlocks
=
pCreate
->
totalBlocks
,
.
daysPerFile
=
pCreate
->
daysPerFile
,
.
daysToKeep0
=
pCreate
->
daysToKeep0
,
...
...
@@ -643,7 +644,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) {
return
-
1
;
}
int32_t
contLen
=
sizeof
(
SUseDbRsp
)
+
pDb
->
numOfVgroups
*
sizeof
(
SVgroupInfo
);
int32_t
contLen
=
sizeof
(
SUseDbRsp
)
+
pDb
->
cfg
.
numOfVgroups
*
sizeof
(
SVgroupInfo
);
SUseDbRsp
*
pRsp
=
rpcMallocCont
(
contLen
);
if
(
pRsp
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -654,7 +655,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) {
if
(
pUse
->
vgVersion
<
pDb
->
vgVersion
)
{
void
*
pIter
=
NULL
;
while
(
vindex
<
pDb
->
numOfVgroups
)
{
while
(
vindex
<
pDb
->
cfg
.
numOfVgroups
)
{
SVgObj
*
pVgroup
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_VGROUP
,
pIter
,
(
void
**
)
&
pVgroup
);
if
(
pIter
==
NULL
)
break
;
...
...
@@ -888,7 +889,7 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int16_t
*
)
pWrite
=
pDb
->
numOfVgroups
;
*
(
int16_t
*
)
pWrite
=
pDb
->
cfg
.
numOfVgroups
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
51490bdb
...
...
@@ -156,11 +156,6 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) {
sdbRelease
(
pSdb
,
pVgroup
);
}
static
int32_t
mndGetDefaultVgroupSize
(
SMnode
*
pMnode
)
{
// todo
return
2
;
}
static
int32_t
mndGetAvailableDnode
(
SMnode
*
pMnode
,
SVgObj
*
pVgroup
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
allocedVnodes
=
0
;
...
...
@@ -193,21 +188,7 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) {
}
int32_t
mndAllocVgroup
(
SMnode
*
pMnode
,
SDbObj
*
pDb
,
SVgObj
**
ppVgroups
)
{
if
(
pDb
->
numOfVgroups
!=
-
1
&&
(
pDb
->
numOfVgroups
<
TSDB_MIN_VNODES_PER_DB
||
pDb
->
numOfVgroups
>
TSDB_MAX_VNODES_PER_DB
))
{
terrno
=
TSDB_CODE_MND_INVALID_DB_OPTION
;
return
-
1
;
}
if
(
pDb
->
numOfVgroups
==
-
1
)
{
pDb
->
numOfVgroups
=
mndGetDefaultVgroupSize
(
pMnode
);
if
(
pDb
->
numOfVgroups
<
0
)
{
terrno
=
TSDB_CODE_MND_NO_ENOUGH_DNODES
;
return
-
1
;
}
}
SVgObj
*
pVgroups
=
calloc
(
pDb
->
numOfVgroups
,
sizeof
(
SVgObj
));
SVgObj
*
pVgroups
=
calloc
(
pDb
->
cfg
.
numOfVgroups
,
sizeof
(
SVgObj
));
if
(
pVgroups
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
...
...
@@ -217,9 +198,9 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
int32_t
maxVgId
=
sdbGetMaxId
(
pMnode
->
pSdb
,
SDB_VGROUP
);
uint32_t
hashMin
=
0
;
uint32_t
hashMax
=
UINT32_MAX
;
uint32_t
hashInterval
=
(
hashMax
-
hashMin
)
/
pDb
->
numOfVgroups
;
uint32_t
hashInterval
=
(
hashMax
-
hashMin
)
/
pDb
->
cfg
.
numOfVgroups
;
for
(
uint32_t
v
=
0
;
v
<
pDb
->
numOfVgroups
;
v
++
)
{
for
(
uint32_t
v
=
0
;
v
<
pDb
->
cfg
.
numOfVgroups
;
v
++
)
{
SVgObj
*
pVgroup
=
&
pVgroups
[
v
];
pVgroup
->
vgId
=
maxVgId
++
;
pVgroup
->
createdTime
=
taosGetTimestampMs
();
...
...
@@ -227,7 +208,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
pVgroup
->
version
=
1
;
pVgroup
->
dbUid
=
pDb
->
uid
;
pVgroup
->
hashBegin
=
hashMin
+
hashInterval
*
v
;
if
(
v
==
pDb
->
numOfVgroups
-
1
)
{
if
(
v
==
pDb
->
cfg
.
numOfVgroups
-
1
)
{
pVgroup
->
hashEnd
=
hashMax
;
}
else
{
pVgroup
->
hashEnd
=
hashMin
+
hashInterval
*
(
v
+
1
)
-
1
;
...
...
tests/CMakeLists.txt
浏览文件 @
51490bdb
# generate debug version:
# mkdir debug; cd debug; cmake -DCMAKE_BUILD_TYPE=Debug ..
# generate release version:
# mkdir release; cd release; cmake -DCMAKE_BUILD_TYPE=Release ..
CMAKE_MINIMUM_REQUIRED
(
VERSION 2.8...3.20
)
PROJECT
(
TDengine
)
SET
(
CMAKE_C_STANDARD 11
)
SET
(
CMAKE_VERBOSE_MAKEFILE ON
)
ADD_SUBDIRECTORY
(
examples/c
)
#ADD_SUBDIRECTORY(examples/c)
ADD_SUBDIRECTORY
(
tsim
)
ADD_SUBDIRECTORY
(
test/c
)
ADD_SUBDIRECTORY
(
comparisonTest/tdengine
)
#
ADD_SUBDIRECTORY(test/c)
#
ADD_SUBDIRECTORY(comparisonTest/tdengine)
tests/script/general/user/basic1.sim
浏览文件 @
51490bdb
...
...
@@ -5,7 +5,7 @@ sql connect
print =============== show users
sql show users
if $rows !=
3
then
if $rows !=
1
then
return -1
endi
...
...
@@ -21,7 +21,7 @@ sql_error drop account root
print =============== create user1
sql create user user1 PASS 'user1'
sql show users
if $rows !=
4
then
if $rows !=
2
then
return -1
endi
...
...
@@ -33,7 +33,7 @@ print $data30 $data31 $data32
print =============== create user2
sql create user user2 PASS 'user2'
sql show users
if $rows !=
5
then
if $rows !=
3
then
return -1
endi
...
...
@@ -46,7 +46,7 @@ print $data40 $data41 $data42
print =============== drop user1
sql drop user user1
sql show users
if $rows !=
4
then
if $rows !=
2
then
return -1
endi
...
...
@@ -62,7 +62,7 @@ system sh/exec.sh -n dnode1 -s start
print =============== show users
sql show users
if $rows !=
4
then
if $rows !=
2
then
return -1
endi
...
...
tests/script/sh/deploy.sh
浏览文件 @
51490bdb
#!/bin/bash
set
+e
#set -x
echo
"Executing deploy.sh"
if
[
$#
!=
4
]
;
then
...
...
@@ -50,12 +53,12 @@ else
fi
if
[[
"
$TAOSD_DIR
"
==
*
"
$IN_TDINTERNAL
"
*
]]
;
then
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
bin
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2,3
`
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
source
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2,3
`
else
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
bin
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2
`
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
source
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2
`
fi
BUILD_DIR
=
$TAOS_DIR
/
$BIN_DIR
/build
BUILD_DIR
=
$TAOS_DIR
/
$BIN_DIR
SIM_DIR
=
$TAOS_DIR
/sim
...
...
tests/script/sh/exec.sh
浏览文件 @
51490bdb
...
...
@@ -8,6 +8,9 @@
# exit 1
# fi
set
+e
#set -x
UNAME_BIN
=
`
which
uname
`
OS_TYPE
=
`
$UNAME_BIN
`
...
...
@@ -62,16 +65,16 @@ else
fi
if
[[
"
$TAOSD_DIR
"
==
*
"
$IN_TDINTERNAL
"
*
]]
;
then
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
bin
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2,3
`
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
source
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2,3
`
else
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
bin
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2
`
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
source
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2
`
fi
BUILD_DIR
=
$TAOS_DIR
/
$BIN_DIR
/build
BUILD_DIR
=
$TAOS_DIR
/
$BIN_DIR
SIM_DIR
=
$TAOS_DIR
/sim
NODE_DIR
=
$SIM_DIR
/
$NODE_NAME
EXE_DIR
=
$BUILD_DIR
/
bi
n
EXE_DIR
=
$BUILD_DIR
/
source/dnode/mgmt/daemo
n
CFG_DIR
=
$NODE_DIR
/cfg
LOG_DIR
=
$NODE_DIR
/log
DATA_DIR
=
$NODE_DIR
/data
...
...
tests/script/test.sh
浏览文件 @
51490bdb
...
...
@@ -22,9 +22,6 @@ do
f
)
FILE_NAME
=
$OPTARG
;;
a
)
ASYNC
=
1
;;
v
)
VALGRIND
=
1
;;
...
...
@@ -60,32 +57,22 @@ else
fi
if
[[
"
$TAOSD_DIR
"
==
*
"
$IN_TDINTERNAL
"
*
]]
;
then
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
bin
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2,3
`
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
source
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2,3
`
else
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
bin
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2
`
BIN_DIR
=
`
find
.
-name
"taosd"
|grep
source
|head
-n1
|cut
-d
'/'
${
cut_opt
}
2
`
fi
BUILD_DIR
=
$TOP_DIR
/
$BIN_DIR
/build
BUILD_DIR
=
$TOP_DIR
/
$BIN_DIR
SIM_DIR
=
$TOP_DIR
/sim
if
[
$ASYNC
-eq
0
]
;
then
PROGRAM
=
$BUILD_DIR
/bin/tsim
else
PROGRAM
=
"
$BUILD_DIR
/bin/tsim -a"
fi
PROGRAM
=
$BUILD_DIR
/tests/tsim/tsim
PRG_DIR
=
$SIM_DIR
/tsim
CFG_DIR
=
$PRG_DIR
/cfg
LOG_DIR
=
$PRG_DIR
/log
DATA_DIR
=
$PRG_DIR
/data
ARBITRATOR_PRG_DIR
=
$SIM_DIR
/arbitrator
ARBITRATOR_LOG_DIR
=
$ARBITRATOR_PRG_DIR
/log
chmod
-R
777
$PRG_DIR
echo
"------------------------------------------------------------------------"
echo
"Start TDengine Testing Case ..."
...
...
@@ -96,12 +83,10 @@ echo "CFG_DIR : $CFG_DIR"
rm
-rf
$LOG_DIR
rm
-rf
$CFG_DIR
rm
-rf
$ARBITRATOR_LOG_DIR
mkdir
-p
$PRG_DIR
mkdir
-p
$LOG_DIR
mkdir
-p
$CFG_DIR
mkdir
-p
$ARBITRATOR_LOG_DIR
TAOS_CFG
=
$PRG_DIR
/cfg/taos.cfg
touch
-f
$TAOS_CFG
...
...
@@ -115,7 +100,7 @@ echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG
echo
"serverPort 7100"
>>
$TAOS_CFG
echo
"dataDir
$DATA_DIR
"
>>
$TAOS_CFG
echo
"logDir
$LOG_DIR
"
>>
$TAOS_CFG
echo
"scriptDir
${
CODE_DIR
}
/../script"
>>
$TAOS_CFG
echo
"scriptDir
${
CODE_DIR
}
"
>>
$TAOS_CFG
echo
"numOfLogLines 100000000"
>>
$TAOS_CFG
echo
"rpcDebugFlag 143"
>>
$TAOS_CFG
echo
"tmrDebugFlag 131"
>>
$TAOS_CFG
...
...
@@ -141,7 +126,6 @@ if [ -n "$FILE_NAME" ]; then
else
echo
"ExcuteCmd:"
$PROGRAM
-c
$CFG_DIR
-f
$FILE_NAME
$PROGRAM
-c
$CFG_DIR
-f
$FILE_NAME
# valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME
fi
else
echo
"ExcuteCmd:"
$PROGRAM
-c
$CFG_DIR
-f
basicSuite.sim
...
...
tests/tsim/CMakeLists.txt
浏览文件 @
51490bdb
PROJECT
(
TDengine
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/src/client/inc
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/deps/cJson/inc
)
INCLUDE_DIRECTORIES
(
inc
)
AUX_SOURCE_DIRECTORY
(
src SRC
)
ADD_EXECUTABLE
(
tsim
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
tsim taos_static trpc tutil pthread cJson
)
aux_source_directory
(
src TSIM_SRC
)
add_executable
(
tsim
${
TSIM_SRC
}
)
target_link_libraries
(
tsim
PUBLIC taos
PUBLIC util
PUBLIC common
PUBLIC os
PUBLIC cjson
)
target_include_directories
(
tsim
PRIVATE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
tests/tsim/inc/sim.h
浏览文件 @
51490bdb
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _
_SIM_H_
_
#define _
_SIM_H_
_
#ifndef _
TD_SIM_H
_
#define _
TD_SIM_H
_
#include <semaphore.h>
#include <stdbool.h>
...
...
@@ -102,18 +102,18 @@ typedef struct _cmd_t {
int16_t
cmdno
;
int16_t
nlen
;
char
name
[
MAX_SIM_CMD_NAME_LEN
];
bool
(
*
parseCmd
)(
char
*
,
struct
_cmd_t
*
,
int32_t
);
bool
(
*
executeCmd
)(
struct
_script_t
*
script
,
char
*
option
);
bool
(
*
parseCmd
)(
char
*
,
struct
_cmd_t
*
,
int32_t
);
bool
(
*
executeCmd
)(
struct
_script_t
*
script
,
char
*
option
);
struct
_cmd_t
*
next
;
}
SCommand
;
typedef
struct
{
int16_t
cmdno
;
int16_t
jump
;
// jump position
int16_t
errorJump
;
// sql jump flag, while '-x' exist in sql cmd, this flag
// will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */
int16_t
lineNum
;
// correspodning line number in original file
int32_t
optionOffset
;
// relative option offset
int16_t
jump
;
// jump position
int16_t
errorJump
;
// sql jump flag, while '-x' exist in sql cmd, this flag
// will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */
int16_t
lineNum
;
// correspodning line number in original file
int32_t
optionOffset
;
// relative option offset
}
SCmdLine
;
typedef
struct
_var_t
{
...
...
@@ -123,24 +123,24 @@ typedef struct _var_t {
}
SVariable
;
typedef
struct
_script_t
{
int32_t
type
;
bool
killed
;
void
*
taos
;
char
rows
[
12
];
// number of rows data retrieved
char
data
[
MAX_QUERY_ROW_NUM
][
MAX_QUERY_COL_NUM
][
MAX_QUERY_VALUE_LEN
];
// query results
char
system_exit_code
[
12
];
char
system_ret_content
[
MAX_SYSTEM_RESULT_LEN
];
int32_t
varLen
;
int32_t
linePos
;
// current cmd position
int32_t
numOfLines
;
// number of lines in the script
int32_t
bgScriptLen
;
char
fileName
[
MAX_FILE_NAME_LEN
];
// script file name
char
error
[
MAX_ERROR_LEN
];
char
*
optionBuffer
;
SCmdLine
*
lines
;
// command list
SVariable
variables
[
MAX_VAR_LEN
];
pthread_t
bgPid
;
char
auth
[
128
];
int32_t
type
;
bool
killed
;
void
*
taos
;
char
rows
[
12
];
// number of rows data retrieved
char
data
[
MAX_QUERY_ROW_NUM
][
MAX_QUERY_COL_NUM
][
MAX_QUERY_VALUE_LEN
];
// query results
char
system_exit_code
[
12
];
char
system_ret_content
[
MAX_SYSTEM_RESULT_LEN
];
int32_t
varLen
;
int32_t
linePos
;
// current cmd position
int32_t
numOfLines
;
// number of lines in the script
int32_t
bgScriptLen
;
char
fileName
[
MAX_FILE_NAME_LEN
];
// script file name
char
error
[
MAX_ERROR_LEN
];
char
*
optionBuffer
;
SCmdLine
*
lines
;
// command list
SVariable
variables
[
MAX_VAR_LEN
];
pthread_t
bgPid
;
char
auth
[
128
];
struct
_script_t
*
bgScripts
[
MAX_BACKGROUND_SCRIPT_NUM
];
}
SScript
;
...
...
@@ -150,16 +150,15 @@ extern int32_t simScriptPos;
extern
int32_t
simScriptSucced
;
extern
int32_t
simDebugFlag
;
extern
char
tsScriptDir
[];
extern
bool
simAsyncQuery
;
extern
bool
abortExecution
;
SScript
*
simParseScript
(
char
*
fileName
);
SScript
*
simProcessCallOver
(
SScript
*
script
);
void
*
simExecuteScript
(
void
*
script
);
void
*
simExecuteScript
(
void
*
script
);
void
simInitsimCmdList
();
bool
simSystemInit
();
void
simSystemCleanUp
();
char
*
simGetVariable
(
SScript
*
script
,
char
*
varName
,
int32_t
varLen
);
char
*
simGetVariable
(
SScript
*
script
,
char
*
varName
,
int32_t
varLen
);
bool
simExecuteExpCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteTestCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteGotoCmd
(
SScript
*
script
,
char
*
option
);
...
...
@@ -178,4 +177,4 @@ bool simExecuteLineInsertCmd(SScript *script, char *option);
bool
simExecuteLineInsertErrorCmd
(
SScript
*
script
,
char
*
option
);
void
simVisuallizeOption
(
SScript
*
script
,
char
*
src
,
char
*
dst
);
#endif
\ No newline at end of file
#endif
/*_TD_SIM_H_*/
\ No newline at end of file
tests/tsim/inc/simParse.h
浏览文件 @
51490bdb
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _
_SIM_PARSE_H_
_
#define _
_SIM_PARSE_H_
_
#ifndef _
TD_SIM_PARSE_H
_
#define _
TD_SIM_PARSE_H
_
#define MAX_NUM_CMD 64
#define MAX_NUM_LABLES 100
...
...
@@ -40,10 +40,10 @@ typedef struct {
/* block definition */
typedef
struct
{
char
top
;
/* the number of blocks stacked */
char
type
[
MAX_NUM_BLOCK
];
/* the block type */
int16_t
*
pos
[
MAX_NUM_BLOCK
];
/* position of the jump for if/elif/case */
int16_t
back
[
MAX_NUM_BLOCK
];
/* go back, endw and continue */
char
top
;
/* the number of blocks stacked */
char
type
[
MAX_NUM_BLOCK
];
/* the block type */
int16_t
*
pos
[
MAX_NUM_BLOCK
];
/* position of the jump for if/elif/case */
int16_t
back
[
MAX_NUM_BLOCK
];
/* go back, endw and continue */
char
numJump
[
MAX_NUM_BLOCK
];
int16_t
*
jump
[
MAX_NUM_BLOCK
][
MAX_NUM_JUMP
];
/* break or elif */
char
sexp
[
MAX_NUM_BLOCK
][
40
];
/*switch expression */
...
...
@@ -52,4 +52,4 @@ typedef struct {
bool
simParseExpression
(
char
*
token
,
int32_t
lineNum
);
#endif
\ No newline at end of file
#endif
/*_TD_SIM_PARSE_H_*/
\ No newline at end of file
tests/tsim/src/simExe.c
浏览文件 @
51490bdb
...
...
@@ -14,18 +14,18 @@
*/
#define _DEFAULT_SOURCE
#include "../../../include/client/taos.h"
#include "cJSON.h"
#include "os.h"
#include "sim.h"
#include "taos.h"
#include "taoserror.h"
#include "tglobal.h"
#include "ttypes.h"
#include "tutil.h"
#undef TAOS_MEM_CHECK
void
simLogSql
(
char
*
sql
,
bool
useSharp
)
{
static
FILE
*
fp
=
NULL
;
char
filename
[
256
];
char
filename
[
256
];
sprintf
(
filename
,
"%s/sim.sql"
,
tsScriptDir
);
if
(
fp
==
NULL
)
{
fp
=
fopen
(
filename
,
"w"
);
...
...
@@ -74,7 +74,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return
"null"
;
}
char
*
keyName
;
char
*
keyName
;
int32_t
keyLen
;
paGetToken
(
varName
+
6
,
&
keyName
,
&
keyLen
);
...
...
@@ -91,7 +91,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return
"null"
;
}
char
*
keyName
;
char
*
keyName
;
int32_t
keyLen
;
paGetToken
(
varName
+
7
,
&
keyName
,
&
keyLen
);
...
...
@@ -144,7 +144,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
}
int32_t
simExecuteExpression
(
SScript
*
script
,
char
*
exp
)
{
char
*
op1
,
*
op2
,
*
var1
,
*
var2
,
*
var3
,
*
rest
;
char
*
op1
,
*
op2
,
*
var1
,
*
var2
,
*
var3
,
*
rest
;
int32_t
op1Len
,
op2Len
,
var1Len
,
var2Len
,
var3Len
,
val0
,
val1
;
char
t0
[
1024
],
t1
[
1024
],
t2
[
1024
],
t3
[
2048
];
int32_t
result
;
...
...
@@ -302,10 +302,10 @@ bool simExecuteRunBackCmd(SScript *script, char *option) {
}
void
simReplaceShToBat
(
char
*
dst
)
{
char
*
sh
=
strstr
(
dst
,
".sh"
);
char
*
sh
=
strstr
(
dst
,
".sh"
);
if
(
sh
!=
NULL
)
{
int32_t
dstLen
=
(
int32_t
)
strlen
(
dst
);
char
*
end
=
dst
+
dstLen
;
char
*
end
=
dst
+
dstLen
;
*
(
end
+
1
)
=
0
;
for
(
char
*
p
=
end
;
p
>=
sh
;
p
--
)
{
...
...
@@ -436,7 +436,7 @@ bool simExecuteReturnCmd(SScript *script, char *option) {
}
void
simVisuallizeOption
(
SScript
*
script
,
char
*
src
,
char
*
dst
)
{
char
*
var
,
*
token
,
*
value
;
char
*
var
,
*
token
,
*
value
;
int32_t
dstLen
,
srcLen
,
tokenLen
;
dst
[
0
]
=
0
,
dstLen
=
0
;
...
...
@@ -466,10 +466,6 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
strcpy
(
dst
+
dstLen
,
src
);
}
void
simCloseRestFulConnect
(
SScript
*
script
)
{
memset
(
script
->
auth
,
0
,
sizeof
(
script
->
auth
));
}
void
simCloseNativeConnect
(
SScript
*
script
)
{
if
(
script
->
taos
==
NULL
)
return
;
...
...
@@ -479,168 +475,7 @@ void simCloseNativeConnect(SScript *script) {
script
->
taos
=
NULL
;
}
void
simCloseTaosdConnect
(
SScript
*
script
)
{
if
(
simAsyncQuery
)
{
simCloseRestFulConnect
(
script
);
}
else
{
simCloseNativeConnect
(
script
);
}
}
// {"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}
// {"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}
// {"status":"succ","head":["ts","i"],"data":[["2017-12-25 21:28:41.022",1],["2017-12-25 21:28:42.022",2],["2017-12-25 21:28:43.022",3],["2017-12-25 21:28:44.022",4],["2017-12-25 21:28:45.022",5],["2017-12-25 21:28:46.022",6],["2017-12-25 21:28:47.022",7],["2017-12-25 21:28:48.022",8],["2017-12-25 21:28:49.022",9],["2017-12-25 21:28:50.022",10]],"rows":10}
int32_t
simParseHttpCommandResult
(
SScript
*
script
,
char
*
command
)
{
cJSON
*
root
=
cJSON_Parse
(
command
);
if
(
root
==
NULL
)
{
simError
(
"script:%s, failed to parse json, response:%s"
,
script
->
fileName
,
command
);
return
-
1
;
}
cJSON
*
status
=
cJSON_GetObjectItem
(
root
,
"status"
);
if
(
status
==
NULL
)
{
simError
(
"script:%s, failed to parse json, status is null, response:%s"
,
script
->
fileName
,
command
);
cJSON_Delete
(
root
);
return
-
1
;
}
if
(
status
->
valuestring
==
NULL
||
strlen
(
status
->
valuestring
)
==
0
)
{
simError
(
"script:%s, failed to parse json, status value is null, response:%s"
,
script
->
fileName
,
command
);
cJSON_Delete
(
root
);
return
-
1
;
}
if
(
strcmp
(
status
->
valuestring
,
"succ"
)
!=
0
)
{
cJSON
*
code
=
cJSON_GetObjectItem
(
root
,
"code"
);
if
(
code
==
NULL
)
{
simError
(
"script:%s, failed to parse json, code is null, response:%s"
,
script
->
fileName
,
command
);
cJSON_Delete
(
root
);
return
-
1
;
}
int32_t
retcode
=
(
int32_t
)
code
->
valueint
;
if
(
retcode
!=
1017
)
{
simError
(
"script:%s, json:status:%s not equal to succ, response:%s"
,
script
->
fileName
,
status
->
valuestring
,
command
);
cJSON_Delete
(
root
);
return
retcode
;
}
else
{
simDebug
(
"script:%s, json:status:%s not equal to succ, but code is %d, response:%s"
,
script
->
fileName
,
status
->
valuestring
,
retcode
,
command
);
cJSON_Delete
(
root
);
return
0
;
}
}
cJSON
*
desc
=
cJSON_GetObjectItem
(
root
,
"desc"
);
if
(
desc
!=
NULL
)
{
if
(
desc
->
valuestring
==
NULL
||
strlen
(
desc
->
valuestring
)
==
0
)
{
simError
(
"script:%s, failed to parse json, desc value is null, response:%s"
,
script
->
fileName
,
command
);
cJSON_Delete
(
root
);
return
-
1
;
}
strcpy
(
script
->
auth
,
desc
->
valuestring
);
cJSON_Delete
(
root
);
return
0
;
}
cJSON
*
data
=
cJSON_GetObjectItem
(
root
,
"data"
);
if
(
data
==
NULL
)
{
simError
(
"script:%s, failed to parse json, data is null, response:%s"
,
script
->
fileName
,
command
);
cJSON_Delete
(
root
);
return
-
1
;
}
int32_t
rowsize
=
cJSON_GetArraySize
(
data
);
if
(
rowsize
<
0
)
{
simError
(
"script:%s, failed to parse json:data, data size %d, response:%s"
,
script
->
fileName
,
rowsize
,
command
);
cJSON_Delete
(
root
);
return
-
1
;
}
int32_t
rowIndex
=
0
;
sprintf
(
script
->
rows
,
"%d"
,
rowsize
);
for
(
int32_t
r
=
0
;
r
<
rowsize
;
++
r
)
{
cJSON
*
row
=
cJSON_GetArrayItem
(
data
,
r
);
if
(
row
==
NULL
)
continue
;
if
(
rowIndex
++
>=
10
)
break
;
int32_t
colsize
=
cJSON_GetArraySize
(
row
);
if
(
colsize
<
0
)
{
break
;
}
colsize
=
MIN
(
10
,
colsize
);
for
(
int32_t
c
=
0
;
c
<
colsize
;
++
c
)
{
cJSON
*
col
=
cJSON_GetArrayItem
(
row
,
c
);
if
(
col
->
valuestring
!=
NULL
)
{
strcpy
(
script
->
data
[
r
][
c
],
col
->
valuestring
);
}
else
{
if
(
col
->
numberstring
[
0
]
==
0
)
{
strcpy
(
script
->
data
[
r
][
c
],
"null"
);
}
else
{
strcpy
(
script
->
data
[
r
][
c
],
col
->
numberstring
);
}
}
}
}
return
0
;
}
int32_t
simExecuteRestFulCommand
(
SScript
*
script
,
char
*
command
)
{
char
buf
[
5000
]
=
{
0
};
sprintf
(
buf
,
"%s 2>/dev/null"
,
command
);
FILE
*
fp
=
popen
(
buf
,
"r"
);
if
(
fp
==
NULL
)
{
simError
(
"failed to execute %s"
,
buf
);
return
-
1
;
}
int32_t
mallocSize
=
2000
;
int32_t
alreadyReadSize
=
0
;
char
*
content
=
malloc
(
mallocSize
);
while
(
!
feof
(
fp
))
{
int32_t
availSize
=
mallocSize
-
alreadyReadSize
;
int32_t
len
=
(
int32_t
)
fread
(
content
+
alreadyReadSize
,
1
,
availSize
,
fp
);
if
(
len
>=
availSize
)
{
alreadyReadSize
+=
len
;
mallocSize
*=
2
;
content
=
realloc
(
content
,
mallocSize
);
}
}
pclose
(
fp
);
return
simParseHttpCommandResult
(
script
,
content
);
}
bool
simCreateRestFulConnect
(
SScript
*
script
,
char
*
user
,
char
*
pass
)
{
char
command
[
4096
];
sprintf
(
command
,
"curl 127.0.0.1:6041/rest/login/%s/%s"
,
user
,
pass
);
bool
success
=
false
;
for
(
int32_t
attempt
=
0
;
attempt
<
10
;
++
attempt
)
{
success
=
simExecuteRestFulCommand
(
script
,
command
)
==
0
;
if
(
!
success
)
{
simDebug
(
"script:%s, user:%s connect taosd failed:%s, attempt:%d"
,
script
->
fileName
,
user
,
taos_errstr
(
NULL
),
attempt
);
taosMsleep
(
1000
);
}
else
{
simDebug
(
"script:%s, user:%s connect taosd successed, attempt:%d"
,
script
->
fileName
,
user
,
attempt
);
break
;
}
}
if
(
!
success
)
{
sprintf
(
script
->
error
,
"lineNum:%d. connect taosd failed:%s"
,
script
->
lines
[
script
->
linePos
].
lineNum
,
taos_errstr
(
NULL
));
return
false
;
}
simDebug
(
"script:%s, connect taosd successed, auth:%p"
,
script
->
fileName
,
script
->
auth
);
return
true
;
}
void
simCloseTaosdConnect
(
SScript
*
script
)
{
simCloseNativeConnect
(
script
);
}
bool
simCreateNativeConnect
(
SScript
*
script
,
char
*
user
,
char
*
pass
)
{
simCloseTaosdConnect
(
script
);
...
...
@@ -651,7 +486,7 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
return
false
;
}
taos
=
taos_connect
(
NULL
,
user
,
pass
,
NULL
,
tsDnodeShellPort
);
taos
=
taos_connect
(
NULL
,
user
,
pass
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
simDebug
(
"script:%s, user:%s connect taosd failed:%s, attempt:%d"
,
script
->
fileName
,
user
,
taos_errstr
(
NULL
),
attempt
);
...
...
@@ -675,8 +510,8 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
}
bool
simCreateTaosdConnect
(
SScript
*
script
,
char
*
rest
)
{
char
*
user
=
TSDB_DEFAULT_USER
;
char
*
token
;
char
*
user
=
TSDB_DEFAULT_USER
;
char
*
token
;
int32_t
tokenLen
;
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
...
...
@@ -684,18 +519,14 @@ bool simCreateTaosdConnect(SScript *script, char *rest) {
user
=
token
;
}
if
(
simAsyncQuery
)
{
return
simCreateRestFulConnect
(
script
,
user
,
TSDB_DEFAULT_PASS
);
}
else
{
return
simCreateNativeConnect
(
script
,
user
,
TSDB_DEFAULT_PASS
);
}
return
simCreateNativeConnect
(
script
,
user
,
TSDB_DEFAULT_PASS
);
}
bool
simExecuteNativeSqlCommand
(
SScript
*
script
,
char
*
rest
,
bool
isSlow
)
{
char
timeStr
[
30
]
=
{
0
};
time_t
tt
;
struct
tm
*
tp
;
SCmdLine
*
line
=
&
script
->
lines
[
script
->
linePos
];
SCmdLine
*
line
=
&
script
->
lines
[
script
->
linePos
];
int32_t
ret
=
-
1
;
TAOS_RES
*
pSql
=
NULL
;
...
...
@@ -710,7 +541,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
pSql
=
taos_query
(
script
->
taos
,
rest
);
ret
=
taos_errno
(
pSql
);
if
(
ret
==
TSDB_CODE_MND_
TABLE
_ALREADY_EXIST
||
ret
==
TSDB_CODE_MND_DB_ALREADY_EXIST
)
{
if
(
ret
==
TSDB_CODE_MND_
STB
_ALREADY_EXIST
||
ret
==
TSDB_CODE_MND_DB_ALREADY_EXIST
)
{
simDebug
(
"script:%s, taos:%p, %s success, ret:%d:%s"
,
script
->
fileName
,
script
->
taos
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
ret
=
0
;
...
...
@@ -756,7 +587,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
while
((
row
=
taos_fetch_row
(
pSql
)))
{
if
(
numOfRows
<
MAX_QUERY_ROW_NUM
)
{
TAOS_FIELD
*
fields
=
taos_fetch_fields
(
pSql
);
int32_t
*
length
=
taos_fetch_lengths
(
pSql
);
int32_t
*
length
=
taos_fetch_lengths
(
pSql
);
for
(
int32_t
i
=
0
;
i
<
num_fields
;
i
++
)
{
char
*
value
=
NULL
;
...
...
@@ -780,7 +611,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
sprintf
(
value
,
"%d"
,
*
((
int8_t
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
sprintf
(
value
,
"%u"
,
*
((
uint8_t
*
)
row
[
i
]));
sprintf
(
value
,
"%u"
,
*
((
uint8_t
*
)
row
[
i
]));
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
sprintf
(
value
,
"%d"
,
*
((
int16_t
*
)
row
[
i
]));
...
...
@@ -846,7 +677,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
}
else
if
(
precision
==
TSDB_TIME_PRECISION_MICRO
)
{
sprintf
(
value
,
"%s.%06d"
,
timeStr
,
(
int32_t
)(
*
((
int64_t
*
)
row
[
i
])
%
1000000
));
}
else
{
sprintf
(
value
,
"%s.%09d"
,
timeStr
,
(
int32_t
)(
*
((
int64_t
*
)
row
[
i
])
%
1000000000
));
sprintf
(
value
,
"%s.%09d"
,
timeStr
,
(
int32_t
)(
*
((
int64_t
*
)
row
[
i
])
%
1000000000
));
}
break
;
...
...
@@ -877,43 +708,8 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
return
true
;
}
bool
simExecuteRestFulSqlCommand
(
SScript
*
script
,
char
*
rest
)
{
SCmdLine
*
line
=
&
script
->
lines
[
script
->
linePos
];
char
command
[
4096
];
sprintf
(
command
,
"curl -H 'Authorization: Taosd %s' -d
\"
%s
\"
127.0.0.1:6041/rest/sql"
,
script
->
auth
,
rest
);
int32_t
ret
=
-
1
;
for
(
int32_t
attempt
=
0
;
attempt
<
10
;
++
attempt
)
{
ret
=
simExecuteRestFulCommand
(
script
,
command
);
if
(
ret
==
TSDB_CODE_MND_TABLE_ALREADY_EXIST
||
ret
==
TSDB_CODE_MND_DB_ALREADY_EXIST
)
{
simDebug
(
"script:%s, taos:%p, %s success, ret:%d:%s"
,
script
->
fileName
,
script
->
taos
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
ret
=
0
;
break
;
}
else
if
(
ret
!=
0
)
{
simDebug
(
"script:%s, taos:%p, %s failed, ret:%d"
,
script
->
fileName
,
script
->
taos
,
rest
,
ret
);
if
(
line
->
errorJump
==
SQL_JUMP_TRUE
)
{
script
->
linePos
=
line
->
jump
;
return
true
;
}
taosMsleep
(
1000
);
}
else
{
break
;
}
}
if
(
ret
)
{
sprintf
(
script
->
error
,
"lineNum:%d. sql:%s failed, ret:%d"
,
line
->
lineNum
,
rest
,
ret
);
return
false
;
}
script
->
linePos
++
;
return
true
;
}
bool
simExecuteSqlImpCmd
(
SScript
*
script
,
char
*
rest
,
bool
isSlow
)
{
char
buf
[
3000
];
char
buf
[
3000
];
SCmdLine
*
line
=
&
script
->
lines
[
script
->
linePos
];
simVisuallizeOption
(
script
,
rest
,
buf
);
...
...
@@ -935,7 +731,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
return
true
;
}
if
(
(
!
simAsyncQuery
&&
script
->
taos
==
NULL
)
||
(
simAsyncQuery
&&
script
->
auth
[
0
]
==
0
)
)
{
if
(
script
->
taos
==
NULL
)
{
if
(
!
simCreateTaosdConnect
(
script
,
"connect root"
))
{
if
(
line
->
errorJump
==
SQL_JUMP_TRUE
)
{
script
->
linePos
=
line
->
jump
;
...
...
@@ -951,11 +747,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
return
true
;
}
if
(
simAsyncQuery
)
{
return
simExecuteRestFulSqlCommand
(
script
,
rest
);
}
else
{
return
simExecuteNativeSqlCommand
(
script
,
rest
,
isSlow
);
}
return
simExecuteNativeSqlCommand
(
script
,
rest
,
isSlow
);
}
bool
simExecuteSqlCmd
(
SScript
*
script
,
char
*
rest
)
{
...
...
@@ -1010,7 +802,7 @@ bool simExecuteRestfulCmd(SScript *script, char *rest) {
}
bool
simExecuteSqlErrorCmd
(
SScript
*
script
,
char
*
rest
)
{
char
buf
[
3000
];
char
buf
[
3000
];
SCmdLine
*
line
=
&
script
->
lines
[
script
->
linePos
];
simVisuallizeOption
(
script
,
rest
,
buf
);
...
...
@@ -1032,7 +824,7 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return
true
;
}
if
(
(
!
simAsyncQuery
&&
script
->
taos
==
NULL
)
||
(
simAsyncQuery
&&
script
->
auth
[
0
]
==
0
)
)
{
if
(
script
->
taos
==
NULL
)
{
if
(
!
simCreateTaosdConnect
(
script
,
"connect root"
))
{
if
(
line
->
errorJump
==
SQL_JUMP_TRUE
)
{
script
->
linePos
=
line
->
jump
;
...
...
@@ -1048,17 +840,9 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return
true
;
}
int32_t
ret
;
TAOS_RES
*
pSql
=
NULL
;
if
(
simAsyncQuery
)
{
char
command
[
4096
];
sprintf
(
command
,
"curl -H 'Authorization: Taosd %s' -d '%s' 127.0.0.1:6041/rest/sql"
,
script
->
auth
,
rest
);
ret
=
simExecuteRestFulCommand
(
script
,
command
);
}
else
{
pSql
=
taos_query
(
script
->
taos
,
rest
);
ret
=
taos_errno
(
pSql
);
taos_free_result
(
pSql
);
}
TAOS_RES
*
pSql
=
pSql
=
taos_query
(
script
->
taos
,
rest
);
int32_t
ret
=
taos_errno
(
pSql
);
taos_free_result
(
pSql
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
simDebug
(
"script:%s, taos:%p, %s execute, expect failed, so success, ret:%d:%s"
,
script
->
fileName
,
script
->
taos
,
...
...
@@ -1083,15 +867,19 @@ bool simExecuteLineInsertCmd(SScript *script, char *rest) {
simInfo
(
"script:%s, %s"
,
script
->
fileName
,
rest
);
simLogSql
(
buf
,
true
);
char
*
lines
[]
=
{
rest
};
char
*
lines
[]
=
{
rest
};
#if 0
int32_t ret = taos_insert_lines(script->taos, lines, 1);
#else
int32_t
ret
=
0
;
#endif
if
(
ret
==
TSDB_CODE_SUCCESS
)
{
simDebug
(
"script:%s, taos:%p, %s executed. success."
,
script
->
fileName
,
script
->
taos
,
rest
);
script
->
linePos
++
;
return
true
;
}
else
{
sprintf
(
script
->
error
,
"lineNum: %d. line: %s failed, ret:%d:%s"
,
line
->
lineNum
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
sprintf
(
script
->
error
,
"lineNum: %d. line: %s failed, ret:%d:%s"
,
line
->
lineNum
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
return
false
;
}
}
...
...
@@ -1106,15 +894,20 @@ bool simExecuteLineInsertErrorCmd(SScript *script, char *rest) {
simInfo
(
"script:%s, %s"
,
script
->
fileName
,
rest
);
simLogSql
(
buf
,
true
);
char
*
lines
[]
=
{
rest
};
char
*
lines
[]
=
{
rest
};
#if 0
int32_t ret = taos_insert_lines(script->taos, lines, 1);
#else
int32_t
ret
=
0
;
#endif
if
(
ret
==
TSDB_CODE_SUCCESS
)
{
sprintf
(
script
->
error
,
"script:%s, taos:%p, %s executed. expect failed, but success."
,
script
->
fileName
,
script
->
taos
,
rest
);
sprintf
(
script
->
error
,
"script:%s, taos:%p, %s executed. expect failed, but success."
,
script
->
fileName
,
script
->
taos
,
rest
);
script
->
linePos
++
;
return
false
;
}
else
{
simDebug
(
"lineNum: %d. line: %s failed, ret:%d:%s. Expect failed, so success"
,
line
->
lineNum
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
simDebug
(
"lineNum: %d. line: %s failed, ret:%d:%s. Expect failed, so success"
,
line
->
lineNum
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
return
true
;
}
}
tests/tsim/src/simMain.c
浏览文件 @
51490bdb
...
...
@@ -15,19 +15,17 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "tglobal.h"
#include "sim.h"
#
undef TAOS_MEM_CHECK
#
include "tglobal.h"
bool
simAsyncQuery
=
false
;
bool
simExecSuccess
=
false
;
bool
abortExecution
=
false
;
void
simHandleSignal
(
int32_t
signo
,
void
*
sigInfo
,
void
*
context
)
{
simSystemCleanUp
();
abortExecution
=
true
;
// runningScript->killed = true;
// exit(1);
// runningScript->killed = true;
// exit(1);
}
int32_t
main
(
int32_t
argc
,
char
*
argv
[])
{
...
...
@@ -38,8 +36,6 @@ int32_t main(int32_t argc, char *argv[]) {
tstrncpy
(
configDir
,
argv
[
++
i
],
128
);
}
else
if
(
strcmp
(
argv
[
i
],
"-f"
)
==
0
&&
i
<
argc
-
1
)
{
strcpy
(
scriptFile
,
argv
[
++
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-a"
)
==
0
)
{
simAsyncQuery
=
true
;
}
else
{
printf
(
"usage: %s [options]
\n
"
,
argv
[
0
]);
printf
(
" [-c config]: config directory, default is: %s
\n
"
,
configDir
);
...
...
tests/tsim/src/simParse.c
浏览文件 @
51490bdb
...
...
@@ -60,9 +60,9 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "sim.h"
#include "simParse.h"
#include "tutil.h"
#undef TAOS_MEM_CHECK
#include "simParse.h"
static
SCommand
*
cmdHashList
[
MAX_NUM_CMD
];
static
SCmdLine
cmdLine
[
MAX_CMD_LINES
];
...
...
@@ -177,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) {
}
SScript
*
simParseScript
(
char
*
fileName
)
{
FILE
*
fd
;
FILE
*
fd
;
int32_t
tokenLen
,
lineNum
=
0
;
char
buffer
[
MAX_LINE_LEN
],
name
[
128
],
*
token
,
*
rest
;
SCommand
*
pCmd
;
SScript
*
script
;
SScript
*
script
;
if
((
fileName
[
0
]
==
'.'
)
||
(
fileName
[
0
]
==
'/'
))
{
strcpy
(
name
,
fileName
);
...
...
@@ -252,7 +252,7 @@ SScript *simParseScript(char *fileName) {
}
int32_t
simCheckExpression
(
char
*
exp
)
{
char
*
op1
,
*
op2
,
*
op
,
*
rest
;
char
*
op1
,
*
op2
,
*
op
,
*
rest
;
int32_t
op1Len
,
op2Len
,
opLen
;
rest
=
paGetToken
(
exp
,
&
op1
,
&
op1Len
);
...
...
@@ -336,7 +336,7 @@ bool simParseExpression(char *token, int32_t lineNum) {
}
bool
simParseIfCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
char
*
ret
;
char
*
ret
;
int32_t
expLen
;
expLen
=
simCheckExpression
(
rest
);
...
...
@@ -502,7 +502,7 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool
simParseSwitchCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
char
*
token
;
char
*
token
;
int32_t
tokenLen
;
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
...
...
@@ -525,7 +525,7 @@ bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool
simParseCaseCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
char
*
token
;
char
*
token
;
int32_t
tokenLen
;
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
...
...
@@ -666,7 +666,7 @@ bool simParsePrintCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
void
simCheckSqlOption
(
char
*
rest
)
{
int32_t
valueLen
;
char
*
value
,
*
xpos
;
char
*
value
,
*
xpos
;
xpos
=
strstr
(
rest
,
" -x"
);
// need a blank
if
(
xpos
)
{
...
...
@@ -750,7 +750,7 @@ bool simParseSystemContentCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool
simParseSleepCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
char
*
token
;
char
*
token
;
int32_t
tokenLen
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_SLEEP
;
...
...
@@ -769,7 +769,7 @@ bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool
simParseReturnCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
char
*
token
;
char
*
token
;
int32_t
tokenLen
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_RETURN
;
...
...
@@ -788,7 +788,7 @@ bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool
simParseGotoCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
char
*
token
;
char
*
token
;
int32_t
tokenLen
;
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
...
...
@@ -811,7 +811,7 @@ bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
}
bool
simParseRunCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
char
*
token
;
char
*
token
;
int32_t
tokenLen
;
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
...
...
@@ -838,7 +838,7 @@ bool simParseRunBackCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
return
true
;
}
bool
simParseLineInsertCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
bool
simParseLineInsertCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
int32_t
expLen
;
rest
++
;
...
...
@@ -854,7 +854,7 @@ bool simParseLineInsertCmd(char* rest, SCommand* pCmd, int32_t lineNum) {
return
true
;
}
bool
simParseLineInsertErrorCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
bool
simParseLineInsertErrorCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int32_t
lineNum
)
{
int32_t
expLen
;
rest
++
;
...
...
tests/tsim/src/simSystem.c
浏览文件 @
51490bdb
...
...
@@ -14,15 +14,15 @@
*/
#define _DEFAULT_SOURCE
#include "../../../include/client/taos.h"
#include "os.h"
#include "sim.h"
#include "taos.h"
#include "taoserror.h"
#include "tglobal.h"
#include "tsocket.h"
#include "ttimer.h"
#include "tutil.h"
#undef TAOS_MEM_CHECK
#include "tglobal.h"
#include "tconfig.h"
SScript
*
simScriptList
[
MAX_MAIN_SCRIPT_NUM
];
SCommand
simCmdList
[
SIM_CMD_END
];
...
...
@@ -81,10 +81,11 @@ char *simParseHostName(char *varName) {
}
bool
simSystemInit
()
{
if
(
taos_init
())
{
return
false
;
}
taosGetFqdn
(
simHostName
);
taosInitGlobalCfg
();
taosReadCfgFromFile
();
simInitsimCmdList
();
memset
(
simScriptList
,
0
,
sizeof
(
SScript
*
)
*
MAX_MAIN_SCRIPT_NUM
);
return
true
;
...
...
@@ -171,7 +172,7 @@ void *simExecuteScript(void *inputScript) {
}
}
else
{
SCmdLine
*
line
=
&
script
->
lines
[
script
->
linePos
];
char
*
option
=
script
->
optionBuffer
+
line
->
optionOffset
;
char
*
option
=
script
->
optionBuffer
+
line
->
optionOffset
;
simDebug
(
"script:%s, line:%d with option
\"
%s
\"
"
,
script
->
fileName
,
line
->
lineNum
,
option
);
SCommand
*
cmd
=
&
simCmdList
[
line
->
cmdno
];
...
...
tools/shell/inc/shellCommand.h
浏览文件 @
51490bdb
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _
_COMMAND_STRUCT_
_
#define _
_COMMAND_STRUCT_
_
#ifndef _
TD_SHELL_COMMAND_H
_
#define _
TD_SHELL_COMMAND_H
_
#include "shell.h"
...
...
tools/shell/src/shellLinux.c
浏览文件 @
51490bdb
...
...
@@ -219,7 +219,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
argp_parse
(
&
argp
,
argc
,
argv
,
0
,
0
,
arguments
);
if
(
arguments
->
abort
)
{
#ifndef _ALPINE
#if 0
error(10, 0, "ABORTED");
#endif
#else
abort
();
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录