Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
d583a4ca
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d583a4ca
编写于
11月 10, 2020
作者:
F
freemine
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'upstream/develop' into odbc-win
上级
9081fd67
a15f7c6f
变更
68
隐藏空白更改
内联
并排
Showing
68 changed file
with
1512 addition
and
981 deletion
+1512
-981
packaging/deb/makedeb.sh
packaging/deb/makedeb.sh
+1
-1
packaging/rpm/tdengine.spec
packaging/rpm/tdengine.spec
+2
-2
packaging/tools/makeclient.sh
packaging/tools/makeclient.sh
+2
-1
packaging/tools/makepkg.sh
packaging/tools/makepkg.sh
+2
-1
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+2
-1
src/client/src/tscServer.c
src/client/src/tscServer.c
+1
-2
src/common/src/tglobal.c
src/common/src/tglobal.c
+2
-0
src/connector/jdbc/deploy-pom.xml
src/connector/jdbc/deploy-pom.xml
+1
-1
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
...dbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+12
-12
src/cq/src/cqMain.c
src/cq/src/cqMain.c
+7
-7
src/dnode/inc/dnodeMPeer.h
src/dnode/inc/dnodeMPeer.h
+5
-5
src/dnode/inc/dnodeMRead.h
src/dnode/inc/dnodeMRead.h
+5
-5
src/dnode/inc/dnodeMWrite.h
src/dnode/inc/dnodeMWrite.h
+5
-5
src/dnode/src/dnodeMPeer.c
src/dnode/src/dnodeMPeer.c
+34
-35
src/dnode/src/dnodeMRead.c
src/dnode/src/dnodeMRead.c
+42
-43
src/dnode/src/dnodeMWrite.c
src/dnode/src/dnodeMWrite.c
+43
-45
src/dnode/src/dnodeMain.c
src/dnode/src/dnodeMain.c
+13
-13
src/dnode/src/dnodeMgmt.c
src/dnode/src/dnodeMgmt.c
+34
-22
src/dnode/src/dnodePeer.c
src/dnode/src/dnodePeer.c
+22
-21
src/dnode/src/dnodeShell.c
src/dnode/src/dnodeShell.c
+44
-44
src/dnode/src/dnodeVWrite.c
src/dnode/src/dnodeVWrite.c
+3
-3
src/inc/dnode.h
src/inc/dnode.h
+16
-16
src/inc/mnode.h
src/inc/mnode.h
+10
-9
src/inc/taosdef.h
src/inc/taosdef.h
+31
-28
src/inc/tcq.h
src/inc/tcq.h
+3
-3
src/inc/tsdb.h
src/inc/tsdb.h
+9
-3
src/inc/twal.h
src/inc/twal.h
+12
-7
src/kit/taosdemo/taosdemo.c
src/kit/taosdemo/taosdemo.c
+3
-3
src/mnode/inc/mnodeDef.h
src/mnode/inc/mnodeDef.h
+4
-4
src/mnode/inc/mnodeTable.h
src/mnode/inc/mnodeTable.h
+2
-2
src/mnode/inc/mnodeVgroup.h
src/mnode/inc/mnodeVgroup.h
+2
-2
src/mnode/src/mnodeInt.c
src/mnode/src/mnodeInt.c
+13
-4
src/mnode/src/mnodeMain.c
src/mnode/src/mnodeMain.c
+6
-6
src/mnode/src/mnodeSdb.c
src/mnode/src/mnodeSdb.c
+3
-3
src/mnode/src/mnodeTable.c
src/mnode/src/mnodeTable.c
+104
-102
src/mnode/src/mnodeVgroup.c
src/mnode/src/mnodeVgroup.c
+8
-8
src/plugins/http/src/httpQueue.c
src/plugins/http/src/httpQueue.c
+1
-1
src/plugins/monitor/src/monitorMain.c
src/plugins/monitor/src/monitorMain.c
+32
-32
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+0
-6
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+26
-12
src/sync/src/syncMain.c
src/sync/src/syncMain.c
+2
-2
src/sync/src/syncRestore.c
src/sync/src/syncRestore.c
+1
-1
src/sync/src/syncRetrieve.c
src/sync/src/syncRetrieve.c
+2
-2
src/sync/src/taosTcpPool.c
src/sync/src/taosTcpPool.c
+53
-50
src/tsdb/src/tsdbMemTable.c
src/tsdb/src/tsdbMemTable.c
+2
-0
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+36
-32
src/vnode/inc/vnodeInt.h
src/vnode/inc/vnodeInt.h
+2
-2
src/vnode/src/vnodeCfg.c
src/vnode/src/vnodeCfg.c
+1
-3
src/vnode/src/vnodeMain.c
src/vnode/src/vnodeMain.c
+19
-19
src/vnode/src/vnodeRead.c
src/vnode/src/vnodeRead.c
+32
-35
src/vnode/src/vnodeVersion.c
src/vnode/src/vnodeVersion.c
+4
-4
src/vnode/src/vnodeWrite.c
src/vnode/src/vnodeWrite.c
+10
-7
src/wal/src/walMgmt.c
src/wal/src/walMgmt.c
+1
-1
src/wal/src/walWrite.c
src/wal/src/walWrite.c
+10
-11
src/wal/test/waltest.c
src/wal/test/waltest.c
+0
-5
tests/perftest-scripts/perftest-query.sh
tests/perftest-scripts/perftest-query.sh
+92
-0
tests/pytest/crash_gen/crash_gen_main.py
tests/pytest/crash_gen/crash_gen_main.py
+1
-0
tests/pytest/fulltest.sh
tests/pytest/fulltest.sh
+3
-0
tests/pytest/insert/ningsiInsert.py
tests/pytest/insert/ningsiInsert.py
+88
-0
tests/pytest/query/query_performance.py
tests/pytest/query/query_performance.py
+219
-0
tests/pytest/wal/addOldWalTest.py
tests/pytest/wal/addOldWalTest.py
+70
-0
tests/test-all.sh
tests/test-all.sh
+6
-1
tests/tsim/inc/sim.h
tests/tsim/inc/sim.h
+43
-46
tests/tsim/inc/simParse.h
tests/tsim/inc/simParse.h
+1
-1
tests/tsim/src/simExe.c
tests/tsim/src/simExe.c
+114
-113
tests/tsim/src/simMain.c
tests/tsim/src/simMain.c
+5
-5
tests/tsim/src/simParse.c
tests/tsim/src/simParse.c
+102
-102
tests/tsim/src/simSystem.c
tests/tsim/src/simSystem.c
+26
-19
未找到文件。
packaging/deb/makedeb.sh
浏览文件 @
d583a4ca
...
...
@@ -48,7 +48,7 @@ cp ${compile_dir}/../packaging/deb/taosd ${pkg_dir}${install_home_pat
cp
${
compile_dir
}
/../packaging/tools/post.sh
${
pkg_dir
}${
install_home_path
}
/script
cp
${
compile_dir
}
/../packaging/tools/preun.sh
${
pkg_dir
}${
install_home_path
}
/script
cp
${
compile_dir
}
/build/bin/taosdemo
${
pkg_dir
}${
install_home_path
}
/bin
cp
${
compile_dir
}
/build/bin/taosdump
${
pkg_dir
}${
install_home_path
}
/bin
#
cp ${compile_dir}/build/bin/taosdump ${pkg_dir}${install_home_path}/bin
cp
${
compile_dir
}
/build/bin/taosd
${
pkg_dir
}${
install_home_path
}
/bin
cp
${
compile_dir
}
/build/bin/taos
${
pkg_dir
}${
install_home_path
}
/bin
cp
${
compile_dir
}
/build/lib/
${
libfile
}
${
pkg_dir
}${
install_home_path
}
/driver
...
...
packaging/rpm/tdengine.spec
浏览文件 @
d583a4ca
...
...
@@ -58,7 +58,7 @@ cp %{_compiledir}/../packaging/tools/preun.sh %{buildroot}%{homepath}/scri
cp %{_compiledir}/build/bin/taos %{buildroot}%{homepath}/bin
cp %{_compiledir}/build/bin/taosd %{buildroot}%{homepath}/bin
cp %{_compiledir}/build/bin/taosdemo %{buildroot}%{homepath}/bin
cp %{_compiledir}/build/bin/taosdump %{buildroot}%{homepath}/bin
#
cp %{_compiledir}/build/bin/taosdump %{buildroot}%{homepath}/bin
cp %{_compiledir}/build/lib/${libfile} %{buildroot}%{homepath}/driver
cp %{_compiledir}/../src/inc/taos.h %{buildroot}%{homepath}/include
cp %{_compiledir}/../src/inc/taoserror.h %{buildroot}%{homepath}/include
...
...
@@ -135,7 +135,7 @@ if [ $1 -eq 0 ];then
${csudo} rm -f ${bin_link_dir}/taos || :
${csudo} rm -f ${bin_link_dir}/taosd || :
${csudo} rm -f ${bin_link_dir}/taosdemo || :
${csudo} rm -f ${bin_link_dir}/taosdump || :
#
${csudo} rm -f ${bin_link_dir}/taosdump || :
${csudo} rm -f ${cfg_link_dir}/* || :
${csudo} rm -f ${inc_link_dir}/taos.h || :
${csudo} rm -f ${inc_link_dir}/taoserror.h || :
...
...
packaging/tools/makeclient.sh
浏览文件 @
d583a4ca
...
...
@@ -45,7 +45,8 @@ if [ "$osType" != "Darwin" ]; then
strip
${
build_dir
}
/bin/taos
bin_files
=
"
${
build_dir
}
/bin/taos
${
script_dir
}
/remove_client.sh"
else
bin_files
=
"
${
build_dir
}
/bin/taos
${
build_dir
}
/bin/taosdump
${
build_dir
}
/bin/taosdemo
${
script_dir
}
/remove_client.sh
${
script_dir
}
/set_core.sh"
#bin_files="${build_dir}/bin/taos ${build_dir}/bin/taosdump ${build_dir}/bin/taosdemo ${script_dir}/remove_client.sh ${script_dir}/set_core.sh"
bin_files
=
"
${
build_dir
}
/bin/taos
${
build_dir
}
/bin/taosdemo
${
script_dir
}
/remove_client.sh
${
script_dir
}
/set_core.sh"
fi
lib_files
=
"
${
build_dir
}
/lib/libtaos.so.
${
version
}
"
else
...
...
packaging/tools/makepkg.sh
浏览文件 @
d583a4ca
...
...
@@ -36,7 +36,8 @@ if [ "$pagMode" == "lite" ]; then
strip
${
build_dir
}
/bin/taos
bin_files
=
"
${
build_dir
}
/bin/taosd
${
build_dir
}
/bin/taos
${
script_dir
}
/remove.sh"
else
bin_files
=
"
${
build_dir
}
/bin/taosd
${
build_dir
}
/bin/taos
${
build_dir
}
/bin/taosdump
${
build_dir
}
/bin/taosdemo
${
build_dir
}
/bin/tarbitrator
${
script_dir
}
/remove.sh
${
script_dir
}
/set_core.sh"
#bin_files="${build_dir}/bin/taosd ${build_dir}/bin/taos ${build_dir}/bin/taosdump ${build_dir}/bin/taosdemo ${build_dir}/bin/tarbitrator ${script_dir}/remove.sh ${script_dir}/set_core.sh"
bin_files
=
"
${
build_dir
}
/bin/taosd
${
build_dir
}
/bin/taos
${
build_dir
}
/bin/taosdemo
${
build_dir
}
/bin/tarbitrator
${
script_dir
}
/remove.sh
${
script_dir
}
/set_core.sh"
fi
lib_files
=
"
${
build_dir
}
/lib/libtaos.so.
${
version
}
"
...
...
src/client/src/tscSQLParser.c
浏览文件 @
d583a4ca
...
...
@@ -16,6 +16,7 @@
#define _BSD_SOURCE
#define _XOPEN_SOURCE 500
#define _DEFAULT_SOURCE
#define _GNU_SOURCE
#include "os.h"
#include "qAst.h"
...
...
@@ -2037,7 +2038,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
SColumnIndex
index
=
{.
tableIndex
=
j
,
.
columnIndex
=
i
};
char
name
[
TSDB_COL_NAME_LEN
]
=
{
0
};
SStrToken
t
=
{.
z
=
pSchema
->
name
,
.
n
=
(
uint32_t
)
strnlen
(
pSchema
->
name
,
TSDB_COL_NAME_LEN
)};
SStrToken
t
=
{.
z
=
pSchema
[
i
].
name
,
.
n
=
(
uint32_t
)
strnlen
(
pSchema
[
i
].
name
,
TSDB_COL_NAME_LEN
)};
setResultColName
(
name
,
pItem
,
cvtFunc
.
originFuncId
,
&
t
);
if
(
setExprInfoForFunctions
(
pCmd
,
pQueryInfo
,
&
pSchema
[
index
.
columnIndex
],
cvtFunc
,
name
,
colIndex
,
&
index
,
finalResult
)
!=
0
)
{
...
...
src/client/src/tscServer.c
浏览文件 @
d583a4ca
...
...
@@ -1718,8 +1718,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
pTableMetaInfo
->
pTableMeta
=
(
STableMeta
*
)
taosCachePut
(
tscMetaCache
,
pTableMetaInfo
->
name
,
strlen
(
pTableMetaInfo
->
name
),
pTableMeta
,
size
,
tsTableMetaKeepTimer
*
1000
);
// todo handle out of memory case
if
(
pTableMetaInfo
->
pTableMeta
==
NULL
)
{
free
(
pTableMeta
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
...
...
src/common/src/tglobal.c
浏览文件 @
d583a4ca
...
...
@@ -218,6 +218,8 @@ int32_t (*monitorStartSystemFp)() = NULL;
void
(
*
monitorStopSystemFp
)()
=
NULL
;
void
(
*
monitorExecuteSQLFp
)(
char
*
sql
)
=
NULL
;
char
*
qtypeStr
[]
=
{
"rpc"
,
"fwd"
,
"wal"
,
"cq"
,
"query"
};
static
pthread_once_t
tsInitGlobalCfgOnce
=
PTHREAD_ONCE_INIT
;
void
taosSetAllDebugFlag
()
{
...
...
src/connector/jdbc/deploy-pom.xml
浏览文件 @
d583a4ca
...
...
@@ -5,7 +5,7 @@
<groupId>
com.taosdata.jdbc
</groupId>
<artifactId>
taos-jdbcdriver
</artifactId>
<version>
2.0.
6
</version>
<version>
2.0.
9
</version>
<packaging>
jar
</packaging>
<name>
JDBCDriver
</name>
...
...
src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
浏览文件 @
d583a4ca
...
...
@@ -111,8 +111,8 @@ public class TSDBJNIConnector {
* @throws SQLException
*/
public
long
executeQuery
(
String
sql
)
throws
SQLException
{
// close previous result set if the user forgets to invoke the
// free method to close previous result set.
// close previous result set if the user forgets to invoke the
// free method to close previous result set.
if
(!
this
.
isResultsetClosed
)
{
freeResultSet
(
taosResultSetPointer
);
}
...
...
@@ -122,23 +122,23 @@ public class TSDBJNIConnector {
pSql
=
this
.
executeQueryImp
(
sql
.
getBytes
(
TaosGlobalConfig
.
getCharset
()),
this
.
taos
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
this
.
freeResultSet
(
pSql
);
this
.
freeResultSet
Imp
(
this
.
taos
,
pSql
);
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
"Unsupported encoding"
));
}
int
code
=
this
.
getErrCode
(
pSql
);
if
(
code
!=
0
)
{
affectedRows
=
-
1
;
String
msg
=
this
.
getErrMsg
(
pSql
);
this
.
freeResultSet
(
pSql
);
this
.
freeResultSet
Imp
(
this
.
taos
,
pSql
);
throw
new
SQLException
(
TSDBConstants
.
WrapErrMsg
(
msg
),
""
,
code
);
}
// Try retrieving result set for the executed SQL using the current connection pointer.
taosResultSetPointer
=
this
.
getResultSetImp
(
this
.
taos
,
pSql
);
isResultsetClosed
=
(
taosResultSetPointer
==
TSDBConstants
.
JNI_NULL_POINTER
);
return
pSql
;
}
...
...
@@ -171,11 +171,11 @@ public class TSDBJNIConnector {
}
private
native
long
getResultSetImp
(
long
connection
,
long
pSql
);
public
boolean
isUpdateQuery
(
long
pSql
)
{
return
isUpdateQueryImp
(
this
.
taos
,
pSql
)
==
1
?
true
:
false
;
return
isUpdateQueryImp
(
this
.
taos
,
pSql
)
==
1
?
true
:
false
;
}
private
native
long
isUpdateQueryImp
(
long
connection
,
long
pSql
);
/**
...
...
@@ -191,7 +191,7 @@ public class TSDBJNIConnector {
res
=
this
.
freeResultSetImp
(
this
.
taos
,
result
);
taosResultSetPointer
=
TSDBConstants
.
JNI_NULL_POINTER
;
}
isResultsetClosed
=
true
;
return
res
;
}
...
...
@@ -274,7 +274,7 @@ public class TSDBJNIConnector {
* Consume a subscription
*/
long
consume
(
long
subscription
)
{
return
this
.
consumeImp
(
subscription
);
return
this
.
consumeImp
(
subscription
);
}
private
native
long
consumeImp
(
long
subscription
);
...
...
src/cq/src/cqMain.c
浏览文件 @
d583a4ca
...
...
@@ -39,16 +39,16 @@
#define cTrace(...) { if (cqDebugFlag & DEBUG_TRACE) { taosPrintLog("CQ ", cqDebugFlag, __VA_ARGS__); }}
typedef
struct
{
int
vgId
;
int
32_t
vgId
;
char
user
[
TSDB_USER_LEN
];
char
pass
[
TSDB_PASSWORD_LEN
];
char
db
[
TSDB_DB_NAME_LEN
];
FCqWrite
cqWrite
;
void
*
ahandle
;
int
num
;
// number of continuous streams
int
32_t
num
;
// number of continuous streams
struct
SCqObj
*
pHead
;
void
*
dbConn
;
int
master
;
int
32_t
master
;
void
*
tmrCtrl
;
pthread_mutex_t
mutex
;
}
SCqContext
;
...
...
@@ -57,7 +57,7 @@ typedef struct SCqObj {
tmr_h
tmrId
;
uint64_t
uid
;
int32_t
tid
;
// table ID
int
rowSize
;
// bytes of a row
int
32_t
rowSize
;
// bytes of a row
char
*
sqlStr
;
// SQL string
STSchema
*
pSchema
;
// pointer to schema array
void
*
pStream
;
...
...
@@ -175,7 +175,7 @@ void cqStop(void *handle) {
pthread_mutex_unlock
(
&
pContext
->
mutex
);
}
void
*
cqCreate
(
void
*
handle
,
uint64_t
uid
,
int
tid
,
char
*
sqlStr
,
STSchema
*
pSchema
)
{
void
*
cqCreate
(
void
*
handle
,
uint64_t
uid
,
int
32_t
tid
,
char
*
sqlStr
,
STSchema
*
pSchema
)
{
SCqContext
*
pContext
=
handle
;
SCqObj
*
pObj
=
calloc
(
sizeof
(
SCqObj
),
1
);
...
...
@@ -237,7 +237,7 @@ void cqDrop(void *handle) {
pthread_mutex_unlock
(
&
pContext
->
mutex
);
}
static
void
doCreateStream
(
void
*
param
,
TAOS_RES
*
result
,
int
code
)
{
static
void
doCreateStream
(
void
*
param
,
TAOS_RES
*
result
,
int
32_t
code
)
{
SCqObj
*
pObj
=
(
SCqObj
*
)
param
;
SCqContext
*
pContext
=
pObj
->
pContext
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
result
;
...
...
@@ -288,7 +288,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
cDebug
(
"vgId:%d, id:%d CQ:%s stream result is ready"
,
pContext
->
vgId
,
pObj
->
tid
,
pObj
->
sqlStr
);
int
size
=
sizeof
(
SWalHead
)
+
sizeof
(
SSubmitMsg
)
+
sizeof
(
SSubmitBlk
)
+
TD_DATA_ROW_HEAD_SIZE
+
pObj
->
rowSize
;
int
32_t
size
=
sizeof
(
SWalHead
)
+
sizeof
(
SSubmitMsg
)
+
sizeof
(
SSubmitBlk
)
+
TD_DATA_ROW_HEAD_SIZE
+
pObj
->
rowSize
;
char
*
buffer
=
calloc
(
size
,
1
);
SWalHead
*
pHead
=
(
SWalHead
*
)
buffer
;
...
...
src/dnode/inc/dnodeMPeer.h
浏览文件 @
d583a4ca
...
...
@@ -20,11 +20,11 @@
extern
"C"
{
#endif
int32_t
dnodeInitM
node
Peer
();
void
dnodeCleanupM
node
Peer
();
int32_t
dnodeAllocateM
nodePq
ueue
();
void
dnodeFreeM
nodePq
ueue
();
void
dnodeDispatchToM
node
PeerQueue
(
SRpcMsg
*
pMsg
);
int32_t
dnodeInitMPeer
();
void
dnodeCleanupMPeer
();
int32_t
dnodeAllocateM
PeerQ
ueue
();
void
dnodeFreeM
PeerQ
ueue
();
void
dnodeDispatchToMPeerQueue
(
SRpcMsg
*
pMsg
);
#ifdef __cplusplus
}
...
...
src/dnode/inc/dnodeMRead.h
浏览文件 @
d583a4ca
...
...
@@ -20,11 +20,11 @@
extern
"C"
{
#endif
int32_t
dnodeInitM
node
Read
();
void
dnodeCleanupM
node
Read
();
int32_t
dnodeAlloc
ateMnodeRq
ueue
();
void
dnodeFreeM
nodeRq
ueue
();
void
dnodeDispatchToM
node
ReadQueue
(
SRpcMsg
*
rpcMsg
);
int32_t
dnodeInitMRead
();
void
dnodeCleanupMRead
();
int32_t
dnodeAlloc
MReadQ
ueue
();
void
dnodeFreeM
ReadQ
ueue
();
void
dnodeDispatchToMReadQueue
(
SRpcMsg
*
rpcMsg
);
#ifdef __cplusplus
}
...
...
src/dnode/inc/dnodeMWrite.h
浏览文件 @
d583a4ca
...
...
@@ -20,11 +20,11 @@
extern
"C"
{
#endif
int32_t
dnodeInitM
node
Write
();
void
dnodeCleanupM
node
Write
();
int32_t
dnodeAlloc
ateMnodeW
queue
();
void
dnodeFreeM
nodeW
queue
();
void
dnodeDispatchToM
node
WriteQueue
(
SRpcMsg
*
pMsg
);
int32_t
dnodeInitMWrite
();
void
dnodeCleanupMWrite
();
int32_t
dnodeAlloc
MWrite
queue
();
void
dnodeFreeM
Write
queue
();
void
dnodeDispatchToMWriteQueue
(
SRpcMsg
*
pMsg
);
#ifdef __cplusplus
}
...
...
src/dnode/src/dnodeMPeer.c
浏览文件 @
d583a4ca
...
...
@@ -35,44 +35,44 @@ typedef struct {
typedef
struct
{
int32_t
curNum
;
int32_t
maxNum
;
SMPeerWorker
*
peerW
orker
;
SMPeerWorker
*
w
orker
;
}
SMPeerWorkerPool
;
static
SMPeerWorkerPool
tsMPeer
Pool
;
static
SMPeerWorkerPool
tsMPeer
WP
;
static
taos_qset
tsMPeerQset
;
static
taos_queue
tsMPeerQueue
;
static
void
*
dnodeProcessM
node
PeerQueue
(
void
*
param
);
static
void
*
dnodeProcessMPeerQueue
(
void
*
param
);
int32_t
dnodeInitM
node
Peer
()
{
int32_t
dnodeInitMPeer
()
{
tsMPeerQset
=
taosOpenQset
();
tsMPeer
Pool
.
maxNum
=
1
;
tsMPeer
Pool
.
curNum
=
0
;
tsMPeer
Pool
.
peerWorker
=
(
SMPeerWorker
*
)
calloc
(
sizeof
(
SMPeerWorker
),
tsMPeerPool
.
maxNum
);
tsMPeer
WP
.
maxNum
=
1
;
tsMPeer
WP
.
curNum
=
0
;
tsMPeer
WP
.
worker
=
(
SMPeerWorker
*
)
calloc
(
sizeof
(
SMPeerWorker
),
tsMPeerWP
.
maxNum
);
if
(
tsMPeer
Pool
.
peerW
orker
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
tsMPeer
Pool
.
maxNum
;
++
i
)
{
SMPeerWorker
*
pWorker
=
tsMPeer
Pool
.
peerW
orker
+
i
;
if
(
tsMPeer
WP
.
w
orker
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
tsMPeer
WP
.
maxNum
;
++
i
)
{
SMPeerWorker
*
pWorker
=
tsMPeer
WP
.
w
orker
+
i
;
pWorker
->
workerId
=
i
;
dDebug
(
"dnode mpeer worker:%d is created"
,
i
);
}
dDebug
(
"dnode mpeer is initialized, workers:%d qset:%p"
,
tsMPeer
Pool
.
maxNum
,
tsMPeerQset
);
dDebug
(
"dnode mpeer is initialized, workers:%d qset:%p"
,
tsMPeer
WP
.
maxNum
,
tsMPeerQset
);
return
0
;
}
void
dnodeCleanupM
node
Peer
()
{
for
(
int32_t
i
=
0
;
i
<
tsMPeer
Pool
.
maxNum
;
++
i
)
{
SMPeerWorker
*
pWorker
=
tsMPeer
Pool
.
peerW
orker
+
i
;
void
dnodeCleanupMPeer
()
{
for
(
int32_t
i
=
0
;
i
<
tsMPeer
WP
.
maxNum
;
++
i
)
{
SMPeerWorker
*
pWorker
=
tsMPeer
WP
.
w
orker
+
i
;
if
(
pWorker
->
thread
)
{
taosQsetThreadResume
(
tsMPeerQset
);
}
dDebug
(
"dnode mpeer worker:%d is closed"
,
i
);
}
for
(
int32_t
i
=
0
;
i
<
tsMPeer
Pool
.
maxNum
;
++
i
)
{
SMPeerWorker
*
pWorker
=
tsMPeer
Pool
.
peerW
orker
+
i
;
for
(
int32_t
i
=
0
;
i
<
tsMPeer
WP
.
maxNum
;
++
i
)
{
SMPeerWorker
*
pWorker
=
tsMPeer
WP
.
w
orker
+
i
;
dDebug
(
"dnode mpeer worker:%d start to join"
,
i
);
if
(
pWorker
->
thread
)
{
pthread_join
(
pWorker
->
thread
,
NULL
);
...
...
@@ -84,61 +84,60 @@ void dnodeCleanupMnodePeer() {
taosCloseQset
(
tsMPeerQset
);
tsMPeerQset
=
NULL
;
taosTFree
(
tsMPeer
Pool
.
peerW
orker
);
taosTFree
(
tsMPeer
WP
.
w
orker
);
}
int32_t
dnodeAllocateM
nodePq
ueue
()
{
int32_t
dnodeAllocateM
PeerQ
ueue
()
{
tsMPeerQueue
=
taosOpenQueue
();
if
(
tsMPeerQueue
==
NULL
)
return
TSDB_CODE_DND_OUT_OF_MEMORY
;
taosAddIntoQset
(
tsMPeerQset
,
tsMPeerQueue
,
NULL
);
for
(
int32_t
i
=
tsMPeer
Pool
.
curNum
;
i
<
tsMPeerPool
.
maxNum
;
++
i
)
{
SMPeerWorker
*
pWorker
=
tsMPeer
Pool
.
peerW
orker
+
i
;
for
(
int32_t
i
=
tsMPeer
WP
.
curNum
;
i
<
tsMPeerWP
.
maxNum
;
++
i
)
{
SMPeerWorker
*
pWorker
=
tsMPeer
WP
.
w
orker
+
i
;
pWorker
->
workerId
=
i
;
pthread_attr_t
thAttr
;
pthread_attr_init
(
&
thAttr
);
pthread_attr_setdetachstate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
pWorker
->
thread
,
&
thAttr
,
dnodeProcessM
node
PeerQueue
,
pWorker
)
!=
0
)
{
if
(
pthread_create
(
&
pWorker
->
thread
,
&
thAttr
,
dnodeProcessMPeerQueue
,
pWorker
)
!=
0
)
{
dError
(
"failed to create thread to process mpeer queue, reason:%s"
,
strerror
(
errno
));
}
pthread_attr_destroy
(
&
thAttr
);
tsMPeer
Pool
.
curNum
=
i
+
1
;
dDebug
(
"dnode mpeer worker:%d is launched, total:%d"
,
pWorker
->
workerId
,
tsMPeer
Pool
.
maxNum
);
tsMPeer
WP
.
curNum
=
i
+
1
;
dDebug
(
"dnode mpeer worker:%d is launched, total:%d"
,
pWorker
->
workerId
,
tsMPeer
WP
.
maxNum
);
}
dDebug
(
"dnode mpeer queue:%p is allocated"
,
tsMPeerQueue
);
return
TSDB_CODE_SUCCESS
;
}
void
dnodeFreeM
nodePq
ueue
()
{
void
dnodeFreeM
PeerQ
ueue
()
{
dDebug
(
"dnode mpeer queue:%p is freed"
,
tsMPeerQueue
);
taosCloseQueue
(
tsMPeerQueue
);
tsMPeerQueue
=
NULL
;
}
void
dnodeDispatchToM
node
PeerQueue
(
SRpcMsg
*
pMsg
)
{
void
dnodeDispatchToMPeerQueue
(
SRpcMsg
*
pMsg
)
{
if
(
!
mnodeIsRunning
()
||
tsMPeerQueue
==
NULL
)
{
dnodeSendRedirectMsg
(
pMsg
,
false
);
rpcFreeCont
(
pMsg
->
pCont
);
return
;
}
else
{
SMnodeMsg
*
pPeer
=
mnodeCreateMsg
(
pMsg
);
taosWriteQitem
(
tsMPeerQueue
,
TAOS_QTYPE_RPC
,
pPeer
);
}
SMnodeMsg
*
pPeer
=
(
SMnodeMsg
*
)
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
mnodeCreateMsg
(
pPeer
,
pMsg
);
taosWriteQitem
(
tsMPeerQueue
,
TAOS_QTYPE_RPC
,
pPeer
);
rpcFreeCont
(
pMsg
->
pCont
);
}
static
void
dnodeFreeM
node
PeerMsg
(
SMnodeMsg
*
pPeer
)
{
static
void
dnodeFreeMPeerMsg
(
SMnodeMsg
*
pPeer
)
{
mnodeCleanupMsg
(
pPeer
);
taosFreeQitem
(
pPeer
);
}
static
void
dnodeSendRpcM
node
PeerRsp
(
SMnodeMsg
*
pPeer
,
int32_t
code
)
{
static
void
dnodeSendRpcMPeerRsp
(
SMnodeMsg
*
pPeer
,
int32_t
code
)
{
if
(
code
==
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
return
;
SRpcMsg
rpcRsp
=
{
...
...
@@ -149,10 +148,10 @@ static void dnodeSendRpcMnodePeerRsp(SMnodeMsg *pPeer, int32_t code) {
};
rpcSendResponse
(
&
rpcRsp
);
dnodeFreeM
node
PeerMsg
(
pPeer
);
dnodeFreeMPeerMsg
(
pPeer
);
}
static
void
*
dnodeProcessM
node
PeerQueue
(
void
*
param
)
{
static
void
*
dnodeProcessMPeerQueue
(
void
*
param
)
{
SMnodeMsg
*
pPeerMsg
;
int32_t
type
;
void
*
unUsed
;
...
...
@@ -165,7 +164,7 @@ static void *dnodeProcessMnodePeerQueue(void *param) {
dDebug
(
"msg:%s will be processed in mpeer queue"
,
taosMsg
[
pPeerMsg
->
rpcMsg
.
msgType
]);
int32_t
code
=
mnodeProcessPeerReq
(
pPeerMsg
);
dnodeSendRpcM
node
PeerRsp
(
pPeerMsg
,
code
);
dnodeSendRpcMPeerRsp
(
pPeerMsg
,
code
);
}
return
NULL
;
...
...
src/dnode/src/dnodeMRead.c
浏览文件 @
d583a4ca
...
...
@@ -35,46 +35,46 @@ typedef struct {
typedef
struct
{
int32_t
curNum
;
int32_t
maxNum
;
SMReadWorker
*
readW
orker
;
SMReadWorker
*
w
orker
;
}
SMReadWorkerPool
;
static
SMReadWorkerPool
tsMRead
Pool
;
static
SMReadWorkerPool
tsMRead
WP
;
static
taos_qset
tsMReadQset
;
static
taos_queue
tsMReadQueue
;
static
void
*
dnodeProcessM
node
ReadQueue
(
void
*
param
);
static
void
*
dnodeProcessMReadQueue
(
void
*
param
);
int32_t
dnodeInitM
node
Read
()
{
int32_t
dnodeInitMRead
()
{
tsMReadQset
=
taosOpenQset
();
tsMRead
Pool
.
maxNum
=
tsNumOfCores
*
tsNumOfThreadsPerCore
/
2
;
tsMRead
Pool
.
maxNum
=
MAX
(
2
,
tsMReadPool
.
maxNum
);
tsMRead
Pool
.
maxNum
=
MIN
(
4
,
tsMReadPool
.
maxNum
);
tsMRead
Pool
.
curNum
=
0
;
tsMRead
Pool
.
readWorker
=
(
SMReadWorker
*
)
calloc
(
sizeof
(
SMReadWorker
),
tsMReadPool
.
maxNum
);
tsMRead
WP
.
maxNum
=
tsNumOfCores
*
tsNumOfThreadsPerCore
/
2
;
tsMRead
WP
.
maxNum
=
MAX
(
2
,
tsMReadWP
.
maxNum
);
tsMRead
WP
.
maxNum
=
MIN
(
4
,
tsMReadWP
.
maxNum
);
tsMRead
WP
.
curNum
=
0
;
tsMRead
WP
.
worker
=
(
SMReadWorker
*
)
calloc
(
sizeof
(
SMReadWorker
),
tsMReadWP
.
maxNum
);
if
(
tsMRead
Pool
.
readW
orker
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
tsMRead
Pool
.
maxNum
;
++
i
)
{
SMReadWorker
*
pWorker
=
tsMRead
Pool
.
readW
orker
+
i
;
if
(
tsMRead
WP
.
w
orker
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
tsMRead
WP
.
maxNum
;
++
i
)
{
SMReadWorker
*
pWorker
=
tsMRead
WP
.
w
orker
+
i
;
pWorker
->
workerId
=
i
;
dDebug
(
"dnode mread worker:%d is created"
,
i
);
}
dDebug
(
"dnode mread is initialized, workers:%d qset:%p"
,
tsMRead
Pool
.
maxNum
,
tsMReadQset
);
dDebug
(
"dnode mread is initialized, workers:%d qset:%p"
,
tsMRead
WP
.
maxNum
,
tsMReadQset
);
return
0
;
}
void
dnodeCleanupM
node
Read
()
{
for
(
int32_t
i
=
0
;
i
<
tsMRead
Pool
.
maxNum
;
++
i
)
{
SMReadWorker
*
pWorker
=
tsMRead
Pool
.
readW
orker
+
i
;
void
dnodeCleanupMRead
()
{
for
(
int32_t
i
=
0
;
i
<
tsMRead
WP
.
maxNum
;
++
i
)
{
SMReadWorker
*
pWorker
=
tsMRead
WP
.
w
orker
+
i
;
if
(
pWorker
->
thread
)
{
taosQsetThreadResume
(
tsMReadQset
);
}
dDebug
(
"dnode mread worker:%d is closed"
,
i
);
}
for
(
int32_t
i
=
0
;
i
<
tsMRead
Pool
.
maxNum
;
++
i
)
{
SMReadWorker
*
pWorker
=
tsMRead
Pool
.
readW
orker
+
i
;
for
(
int32_t
i
=
0
;
i
<
tsMRead
WP
.
maxNum
;
++
i
)
{
SMReadWorker
*
pWorker
=
tsMRead
WP
.
w
orker
+
i
;
dDebug
(
"dnode mread worker:%d start to join"
,
i
);
if
(
pWorker
->
thread
)
{
pthread_join
(
pWorker
->
thread
,
NULL
);
...
...
@@ -86,64 +86,63 @@ void dnodeCleanupMnodeRead() {
taosCloseQset
(
tsMReadQset
);
tsMReadQset
=
NULL
;
free
(
tsMRead
Pool
.
readW
orker
);
free
(
tsMRead
WP
.
w
orker
);
}
int32_t
dnodeAlloc
ateMnodeRq
ueue
()
{
int32_t
dnodeAlloc
MReadQ
ueue
()
{
tsMReadQueue
=
taosOpenQueue
();
if
(
tsMReadQueue
==
NULL
)
return
TSDB_CODE_DND_OUT_OF_MEMORY
;
taosAddIntoQset
(
tsMReadQset
,
tsMReadQueue
,
NULL
);
for
(
int32_t
i
=
tsMRead
Pool
.
curNum
;
i
<
tsMReadPool
.
maxNum
;
++
i
)
{
SMReadWorker
*
pWorker
=
tsMRead
Pool
.
readW
orker
+
i
;
for
(
int32_t
i
=
tsMRead
WP
.
curNum
;
i
<
tsMReadWP
.
maxNum
;
++
i
)
{
SMReadWorker
*
pWorker
=
tsMRead
WP
.
w
orker
+
i
;
pWorker
->
workerId
=
i
;
pthread_attr_t
thAttr
;
pthread_attr_init
(
&
thAttr
);
pthread_attr_setdetachstate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
pWorker
->
thread
,
&
thAttr
,
dnodeProcessM
node
ReadQueue
,
pWorker
)
!=
0
)
{
if
(
pthread_create
(
&
pWorker
->
thread
,
&
thAttr
,
dnodeProcessMReadQueue
,
pWorker
)
!=
0
)
{
dError
(
"failed to create thread to process mread queue, reason:%s"
,
strerror
(
errno
));
}
pthread_attr_destroy
(
&
thAttr
);
tsMRead
Pool
.
curNum
=
i
+
1
;
dDebug
(
"dnode mread worker:%d is launched, total:%d"
,
pWorker
->
workerId
,
tsMRead
Pool
.
maxNum
);
tsMRead
WP
.
curNum
=
i
+
1
;
dDebug
(
"dnode mread worker:%d is launched, total:%d"
,
pWorker
->
workerId
,
tsMRead
WP
.
maxNum
);
}
dDebug
(
"dnode mread queue:%p is allocated"
,
tsMReadQueue
);
return
TSDB_CODE_SUCCESS
;
}
void
dnodeFreeM
nodeRq
ueue
()
{
void
dnodeFreeM
ReadQ
ueue
()
{
dDebug
(
"dnode mread queue:%p is freed"
,
tsMReadQueue
);
taosCloseQueue
(
tsMReadQueue
);
tsMReadQueue
=
NULL
;
}
void
dnodeDispatchToM
node
ReadQueue
(
SRpcMsg
*
pMsg
)
{
void
dnodeDispatchToMReadQueue
(
SRpcMsg
*
pMsg
)
{
if
(
!
mnodeIsRunning
()
||
tsMReadQueue
==
NULL
)
{
dnodeSendRedirectMsg
(
pMsg
,
true
);
rpcFreeCont
(
pMsg
->
pCont
);
return
;
}
else
{
SMnodeMsg
*
pRead
=
mnodeCreateMsg
(
pMsg
);
taosWriteQitem
(
tsMReadQueue
,
TAOS_QTYPE_RPC
,
pRead
);
}
SMnodeMsg
*
pRead
=
(
SMnodeMsg
*
)
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
mnodeCreateMsg
(
pRead
,
pMsg
);
taosWriteQitem
(
tsMReadQueue
,
TAOS_QTYPE_RPC
,
pRead
);
rpcFreeCont
(
pMsg
->
pCont
);
}
static
void
dnodeFreeM
node
ReadMsg
(
SMnodeMsg
*
pRead
)
{
static
void
dnodeFreeMReadMsg
(
SMnodeMsg
*
pRead
)
{
mnodeCleanupMsg
(
pRead
);
taosFreeQitem
(
pRead
);
}
static
void
dnodeSendRpcM
node
ReadRsp
(
SMnodeMsg
*
pRead
,
int32_t
code
)
{
static
void
dnodeSendRpcMReadRsp
(
SMnodeMsg
*
pRead
,
int32_t
code
)
{
if
(
code
==
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
return
;
if
(
code
==
TSDB_CODE_MND_ACTION_NEED_REPROCESSED
)
{
// may be a auto create req, should put into write queue
dnodeReprocessM
node
WriteMsg
(
pRead
);
dnodeReprocessMWriteMsg
(
pRead
);
return
;
}
...
...
@@ -155,23 +154,23 @@ static void dnodeSendRpcMnodeReadRsp(SMnodeMsg *pRead, int32_t code) {
};
rpcSendResponse
(
&
rpcRsp
);
dnodeFreeM
node
ReadMsg
(
pRead
);
dnodeFreeMReadMsg
(
pRead
);
}
static
void
*
dnodeProcessM
node
ReadQueue
(
void
*
param
)
{
SMnodeMsg
*
pRead
Msg
;
static
void
*
dnodeProcessMReadQueue
(
void
*
param
)
{
SMnodeMsg
*
pRead
;
int32_t
type
;
void
*
unUsed
;
while
(
1
)
{
if
(
taosReadQitemFromQset
(
tsMReadQset
,
&
type
,
(
void
**
)
&
pRead
Msg
,
&
unUsed
)
==
0
)
{
if
(
taosReadQitemFromQset
(
tsMReadQset
,
&
type
,
(
void
**
)
&
pRead
,
&
unUsed
)
==
0
)
{
dDebug
(
"qset:%p, mnode read got no message from qset, exiting"
,
tsMReadQset
);
break
;
}
dDebug
(
"%p, msg:%s will be processed in mread queue"
,
pRead
Msg
->
rpcMsg
.
ahandle
,
taosMsg
[
pReadMsg
->
rpcMsg
.
msgType
]);
int32_t
code
=
mnodeProcessRead
(
pRead
Msg
);
dnodeSendRpcM
nodeReadRsp
(
pReadMsg
,
code
);
dDebug
(
"%p, msg:%s will be processed in mread queue"
,
pRead
->
rpcMsg
.
ahandle
,
taosMsg
[
pRead
->
rpcMsg
.
msgType
]);
int32_t
code
=
mnodeProcessRead
(
pRead
);
dnodeSendRpcM
ReadRsp
(
pRead
,
code
);
}
return
NULL
;
...
...
src/dnode/src/dnodeMWrite.c
浏览文件 @
d583a4ca
...
...
@@ -36,45 +36,45 @@ typedef struct {
typedef
struct
{
int32_t
curNum
;
int32_t
maxNum
;
SMWriteWorker
*
w
riteW
orker
;
SMWriteWorker
*
worker
;
}
SMWriteWorkerPool
;
static
SMWriteWorkerPool
tsMWrite
Pool
;
static
SMWriteWorkerPool
tsMWrite
WP
;
static
taos_qset
tsMWriteQset
;
static
taos_queue
tsMWriteQueue
;
extern
void
*
tsDnodeTmr
;
static
void
*
dnodeProcessM
node
WriteQueue
(
void
*
param
);
static
void
*
dnodeProcessMWriteQueue
(
void
*
param
);
int32_t
dnodeInitM
node
Write
()
{
int32_t
dnodeInitMWrite
()
{
tsMWriteQset
=
taosOpenQset
();
tsMWrite
Pool
.
maxNum
=
1
;
tsMWrite
Pool
.
curNum
=
0
;
tsMWrite
Pool
.
writeWorker
=
(
SMWriteWorker
*
)
calloc
(
sizeof
(
SMWriteWorker
),
tsMWritePool
.
maxNum
);
tsMWrite
WP
.
maxNum
=
1
;
tsMWrite
WP
.
curNum
=
0
;
tsMWrite
WP
.
worker
=
(
SMWriteWorker
*
)
calloc
(
sizeof
(
SMWriteWorker
),
tsMWriteWP
.
maxNum
);
if
(
tsMWrite
Pool
.
writeW
orker
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
tsMWrite
Pool
.
maxNum
;
++
i
)
{
SMWriteWorker
*
pWorker
=
tsMWrite
Pool
.
writeW
orker
+
i
;
if
(
tsMWrite
WP
.
w
orker
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
tsMWrite
WP
.
maxNum
;
++
i
)
{
SMWriteWorker
*
pWorker
=
tsMWrite
WP
.
w
orker
+
i
;
pWorker
->
workerId
=
i
;
dDebug
(
"dnode mwrite worker:%d is created"
,
i
);
}
dDebug
(
"dnode mwrite is initialized, workers:%d qset:%p"
,
tsMWrite
Pool
.
maxNum
,
tsMWriteQset
);
dDebug
(
"dnode mwrite is initialized, workers:%d qset:%p"
,
tsMWrite
WP
.
maxNum
,
tsMWriteQset
);
return
0
;
}
void
dnodeCleanupM
node
Write
()
{
for
(
int32_t
i
=
0
;
i
<
tsMWrite
Pool
.
maxNum
;
++
i
)
{
SMWriteWorker
*
pWorker
=
tsMWrite
Pool
.
writeW
orker
+
i
;
void
dnodeCleanupMWrite
()
{
for
(
int32_t
i
=
0
;
i
<
tsMWrite
WP
.
maxNum
;
++
i
)
{
SMWriteWorker
*
pWorker
=
tsMWrite
WP
.
w
orker
+
i
;
if
(
pWorker
->
thread
)
{
taosQsetThreadResume
(
tsMWriteQset
);
}
dDebug
(
"dnode mwrite worker:%d is closed"
,
i
);
}
for
(
int32_t
i
=
0
;
i
<
tsMWrite
Pool
.
maxNum
;
++
i
)
{
SMWriteWorker
*
pWorker
=
tsMWrite
Pool
.
writeW
orker
+
i
;
for
(
int32_t
i
=
0
;
i
<
tsMWrite
WP
.
maxNum
;
++
i
)
{
SMWriteWorker
*
pWorker
=
tsMWrite
WP
.
w
orker
+
i
;
dDebug
(
"dnode mwrite worker:%d start to join"
,
i
);
if
(
pWorker
->
thread
)
{
pthread_join
(
pWorker
->
thread
,
NULL
);
...
...
@@ -86,58 +86,56 @@ void dnodeCleanupMnodeWrite() {
taosCloseQset
(
tsMWriteQset
);
tsMWriteQset
=
NULL
;
taosTFree
(
tsMWrite
Pool
.
writeW
orker
);
taosTFree
(
tsMWrite
WP
.
w
orker
);
}
int32_t
dnodeAlloc
ateMnodeW
queue
()
{
int32_t
dnodeAlloc
MWrite
queue
()
{
tsMWriteQueue
=
taosOpenQueue
();
if
(
tsMWriteQueue
==
NULL
)
return
TSDB_CODE_DND_OUT_OF_MEMORY
;
taosAddIntoQset
(
tsMWriteQset
,
tsMWriteQueue
,
NULL
);
for
(
int32_t
i
=
tsMWrite
Pool
.
curNum
;
i
<
tsMWritePool
.
maxNum
;
++
i
)
{
SMWriteWorker
*
pWorker
=
tsMWrite
Pool
.
writeW
orker
+
i
;
for
(
int32_t
i
=
tsMWrite
WP
.
curNum
;
i
<
tsMWriteWP
.
maxNum
;
++
i
)
{
SMWriteWorker
*
pWorker
=
tsMWrite
WP
.
w
orker
+
i
;
pWorker
->
workerId
=
i
;
pthread_attr_t
thAttr
;
pthread_attr_init
(
&
thAttr
);
pthread_attr_setdetachstate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
pWorker
->
thread
,
&
thAttr
,
dnodeProcessM
node
WriteQueue
,
pWorker
)
!=
0
)
{
if
(
pthread_create
(
&
pWorker
->
thread
,
&
thAttr
,
dnodeProcessMWriteQueue
,
pWorker
)
!=
0
)
{
dError
(
"failed to create thread to process mwrite queue, reason:%s"
,
strerror
(
errno
));
}
pthread_attr_destroy
(
&
thAttr
);
tsMWrite
Pool
.
curNum
=
i
+
1
;
dDebug
(
"dnode mwrite worker:%d is launched, total:%d"
,
pWorker
->
workerId
,
tsMWrite
Pool
.
maxNum
);
tsMWrite
WP
.
curNum
=
i
+
1
;
dDebug
(
"dnode mwrite worker:%d is launched, total:%d"
,
pWorker
->
workerId
,
tsMWrite
WP
.
maxNum
);
}
dDebug
(
"dnode mwrite queue:%p is allocated"
,
tsMWriteQueue
);
return
TSDB_CODE_SUCCESS
;
}
void
dnodeFreeM
nodeW
queue
()
{
void
dnodeFreeM
Write
queue
()
{
dDebug
(
"dnode mwrite queue:%p is freed"
,
tsMWriteQueue
);
taosCloseQueue
(
tsMWriteQueue
);
tsMWriteQueue
=
NULL
;
}
void
dnodeDispatchToM
node
WriteQueue
(
SRpcMsg
*
pMsg
)
{
void
dnodeDispatchToMWriteQueue
(
SRpcMsg
*
pMsg
)
{
if
(
!
mnodeIsRunning
()
||
tsMWriteQueue
==
NULL
)
{
dnodeSendRedirectMsg
(
pMsg
,
true
);
rpcFreeCont
(
pMsg
->
pCont
);
return
;
}
else
{
SMnodeMsg
*
pWrite
=
mnodeCreateMsg
(
pMsg
);
dDebug
(
"app:%p:%p, msg:%s is put into mwrite queue:%p"
,
pWrite
->
rpcMsg
.
ahandle
,
pWrite
,
taosMsg
[
pWrite
->
rpcMsg
.
msgType
],
tsMWriteQueue
);
taosWriteQitem
(
tsMWriteQueue
,
TAOS_QTYPE_RPC
,
pWrite
);
}
SMnodeMsg
*
pWrite
=
(
SMnodeMsg
*
)
taosAllocateQitem
(
sizeof
(
SMnodeMsg
));
mnodeCreateMsg
(
pWrite
,
pMsg
);
dDebug
(
"app:%p:%p, msg:%s is put into mwrite queue:%p"
,
pWrite
->
rpcMsg
.
ahandle
,
pWrite
,
taosMsg
[
pWrite
->
rpcMsg
.
msgType
],
tsMWriteQueue
);
taosWriteQitem
(
tsMWriteQueue
,
TAOS_QTYPE_RPC
,
pWrite
);
rpcFreeCont
(
pMsg
->
pCont
);
}
static
void
dnodeFreeM
node
WriteMsg
(
SMnodeMsg
*
pWrite
)
{
static
void
dnodeFreeMWriteMsg
(
SMnodeMsg
*
pWrite
)
{
dDebug
(
"app:%p:%p, msg:%s is freed from mwrite queue:%p"
,
pWrite
->
rpcMsg
.
ahandle
,
pWrite
,
taosMsg
[
pWrite
->
rpcMsg
.
msgType
],
tsMWriteQueue
);
...
...
@@ -145,12 +143,12 @@ static void dnodeFreeMnodeWriteMsg(SMnodeMsg *pWrite) {
taosFreeQitem
(
pWrite
);
}
void
dnodeSendRpcM
node
WriteRsp
(
void
*
pMsg
,
int32_t
code
)
{
void
dnodeSendRpcMWriteRsp
(
void
*
pMsg
,
int32_t
code
)
{
SMnodeMsg
*
pWrite
=
pMsg
;
if
(
pWrite
==
NULL
)
return
;
if
(
code
==
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
return
;
if
(
code
==
TSDB_CODE_MND_ACTION_NEED_REPROCESSED
)
{
dnodeReprocessM
node
WriteMsg
(
pWrite
);
dnodeReprocessMWriteMsg
(
pWrite
);
return
;
}
...
...
@@ -162,10 +160,10 @@ void dnodeSendRpcMnodeWriteRsp(void *pMsg, int32_t code) {
};
rpcSendResponse
(
&
rpcRsp
);
dnodeFreeM
node
WriteMsg
(
pWrite
);
dnodeFreeMWriteMsg
(
pWrite
);
}
static
void
*
dnodeProcessM
node
WriteQueue
(
void
*
param
)
{
static
void
*
dnodeProcessMWriteQueue
(
void
*
param
)
{
SMnodeMsg
*
pWrite
;
int32_t
type
;
void
*
unUsed
;
...
...
@@ -180,13 +178,13 @@ static void *dnodeProcessMnodeWriteQueue(void *param) {
taosMsg
[
pWrite
->
rpcMsg
.
msgType
]);
int32_t
code
=
mnodeProcessWrite
(
pWrite
);
dnodeSendRpcM
node
WriteRsp
(
pWrite
,
code
);
dnodeSendRpcMWriteRsp
(
pWrite
,
code
);
}
return
NULL
;
}
void
dnodeReprocessM
node
WriteMsg
(
void
*
pMsg
)
{
void
dnodeReprocessMWriteMsg
(
void
*
pMsg
)
{
SMnodeMsg
*
pWrite
=
pMsg
;
if
(
!
mnodeIsRunning
()
||
tsMWriteQueue
==
NULL
)
{
...
...
@@ -194,7 +192,7 @@ void dnodeReprocessMnodeWriteMsg(void *pMsg) {
taosMsg
[
pWrite
->
rpcMsg
.
msgType
],
pWrite
->
retry
);
dnodeSendRedirectMsg
(
pMsg
,
true
);
dnodeFreeM
node
WriteMsg
(
pWrite
);
dnodeFreeMWriteMsg
(
pWrite
);
}
else
{
dDebug
(
"app:%p:%p, msg:%s is reput into mwrite queue:%p, retry times:%d"
,
pWrite
->
rpcMsg
.
ahandle
,
pWrite
,
taosMsg
[
pWrite
->
rpcMsg
.
msgType
],
tsMWriteQueue
,
pWrite
->
retry
);
...
...
@@ -203,12 +201,12 @@ void dnodeReprocessMnodeWriteMsg(void *pMsg) {
}
}
static
void
dnodeDoDelayReprocessM
node
WriteMsg
(
void
*
param
,
void
*
tmrId
)
{
dnodeReprocessM
node
WriteMsg
(
param
);
static
void
dnodeDoDelayReprocessMWriteMsg
(
void
*
param
,
void
*
tmrId
)
{
dnodeReprocessMWriteMsg
(
param
);
}
void
dnodeDelayReprocessM
node
WriteMsg
(
void
*
pMsg
)
{
void
dnodeDelayReprocessMWriteMsg
(
void
*
pMsg
)
{
SMnodeMsg
*
mnodeMsg
=
pMsg
;
void
*
unUsed
=
NULL
;
taosTmrReset
(
dnodeDoDelayReprocessM
node
WriteMsg
,
300
,
mnodeMsg
,
tsDnodeTmr
,
&
unUsed
);
taosTmrReset
(
dnodeDoDelayReprocessMWriteMsg
,
300
,
mnodeMsg
,
tsDnodeTmr
,
&
unUsed
);
}
src/dnode/src/dnodeMain.c
浏览文件 @
d583a4ca
...
...
@@ -37,11 +37,11 @@
#include "dnodeShell.h"
#include "dnodeTelemetry.h"
static
S
DnodeRunStatus
tsDnodeRunStatus
=
TSDB_DNODE
_RUN_STATUS_STOPPED
;
static
S
RunStatus
tsRunStatus
=
TSDB
_RUN_STATUS_STOPPED
;
static
int32_t
dnodeInitStorage
();
static
void
dnodeCleanupStorage
();
static
void
dnodeSetRunStatus
(
S
Dnode
RunStatus
status
);
static
void
dnodeSetRunStatus
(
SRunStatus
status
);
static
void
dnodeCheckDataDirOpenned
(
char
*
dir
);
static
int32_t
dnodeInitComponents
();
static
void
dnodeCleanupComponents
(
int32_t
stepId
);
...
...
@@ -63,9 +63,9 @@ static const SDnodeComponent tsDnodeComponents[] = {
{
"check"
,
dnodeInitCheck
,
dnodeCleanupCheck
},
// NOTES: dnodeInitCheck must be behind the dnodeinitStorage component !!!
{
"vread"
,
dnodeInitVRead
,
dnodeCleanupVRead
},
{
"vwrite"
,
dnodeInitVWrite
,
dnodeCleanupVWrite
},
{
"mread"
,
dnodeInitM
nodeRead
,
dnodeCleanupMnode
Read
},
{
"mwrite"
,
dnodeInitM
nodeWrite
,
dnodeCleanupMnode
Write
},
{
"mpeer"
,
dnodeInitM
nodePeer
,
dnodeCleanupMnode
Peer
},
{
"mread"
,
dnodeInitM
Read
,
dnodeCleanupM
Read
},
{
"mwrite"
,
dnodeInitM
Write
,
dnodeCleanupM
Write
},
{
"mpeer"
,
dnodeInitM
Peer
,
dnodeCleanupM
Peer
},
{
"client"
,
dnodeInitClient
,
dnodeCleanupClient
},
{
"server"
,
dnodeInitServer
,
dnodeCleanupServer
},
{
"mgmt"
,
dnodeInitMgmt
,
dnodeCleanupMgmt
},
...
...
@@ -104,7 +104,7 @@ static int32_t dnodeInitComponents() {
}
int32_t
dnodeInitSystem
()
{
dnodeSetRunStatus
(
TSDB_
DNODE_
RUN_STATUS_INITIALIZE
);
dnodeSetRunStatus
(
TSDB_RUN_STATUS_INITIALIZE
);
tscEmbedded
=
1
;
taosBlockSIGPIPE
();
taosResolveCRC
();
...
...
@@ -137,7 +137,7 @@ int32_t dnodeInitSystem() {
}
dnodeStartModules
();
dnodeSetRunStatus
(
TSDB_
DNODE_
RUN_STATUS_RUNING
);
dnodeSetRunStatus
(
TSDB_RUN_STATUS_RUNING
);
dInfo
(
"TDengine is initialized successfully"
);
...
...
@@ -145,20 +145,20 @@ int32_t dnodeInitSystem() {
}
void
dnodeCleanUpSystem
()
{
if
(
dnodeGetRunStatus
()
!=
TSDB_
DNODE_
RUN_STATUS_STOPPED
)
{
dnodeSetRunStatus
(
TSDB_
DNODE_
RUN_STATUS_STOPPED
);
if
(
dnodeGetRunStatus
()
!=
TSDB_RUN_STATUS_STOPPED
)
{
dnodeSetRunStatus
(
TSDB_RUN_STATUS_STOPPED
);
dnodeCleanupComponents
(
sizeof
(
tsDnodeComponents
)
/
sizeof
(
tsDnodeComponents
[
0
])
-
1
);
taos_cleanup
();
taosCloseLog
();
}
}
S
Dnode
RunStatus
dnodeGetRunStatus
()
{
return
ts
Dnode
RunStatus
;
SRunStatus
dnodeGetRunStatus
()
{
return
tsRunStatus
;
}
static
void
dnodeSetRunStatus
(
S
Dnode
RunStatus
status
)
{
ts
Dnode
RunStatus
=
status
;
static
void
dnodeSetRunStatus
(
SRunStatus
status
)
{
tsRunStatus
=
status
;
}
static
void
dnodeCheckDataDirOpenned
(
char
*
dir
)
{
...
...
src/dnode/src/dnodeMgmt.c
浏览文件 @
d583a4ca
...
...
@@ -47,6 +47,11 @@ typedef struct {
int32_t
*
vnodeList
;
}
SOpenVnodeThread
;
typedef
struct
{
SRpcMsg
rpcMsg
;
char
pCont
[];
}
SMgmtMsg
;
void
*
tsDnodeTmr
=
NULL
;
static
void
*
tsStatusTimer
=
NULL
;
static
uint32_t
tsRebootTime
;
...
...
@@ -172,38 +177,46 @@ void dnodeCleanupMgmt() {
vnodeCleanupResources
();
}
void
dnodeDispatchToMgmtQueue
(
SRpcMsg
*
pMsg
)
{
void
*
item
;
static
int32_t
dnodeWriteToMgmtQueue
(
SRpcMsg
*
pMsg
)
{
int32_t
size
=
sizeof
(
SMgmtMsg
)
+
pMsg
->
contLen
;
SMgmtMsg
*
pMgmt
=
taosAllocateQitem
(
size
);
if
(
pMgmt
==
NULL
)
{
return
TSDB_CODE_DND_OUT_OF_MEMORY
;
}
item
=
taosAllocateQitem
(
sizeof
(
SRpcMsg
));
if
(
item
)
{
memcpy
(
item
,
pMsg
,
sizeof
(
SRpcMsg
));
taosWriteQitem
(
tsMgmtQueue
,
1
,
item
);
}
else
{
SRpcMsg
rsp
=
{
.
handle
=
pMsg
->
handle
,
.
pCont
=
NULL
,
.
code
=
TSDB_CODE_DND_OUT_OF_MEMORY
};
pMgmt
->
rpcMsg
=
*
pMsg
;
pMgmt
->
rpcMsg
.
pCont
=
pMgmt
->
pCont
;
memcpy
(
pMgmt
->
pCont
,
pMsg
->
pCont
,
pMsg
->
contLen
);
taosWriteQitem
(
tsMgmtQueue
,
TAOS_QTYPE_RPC
,
pMgmt
);
return
TSDB_CODE_SUCCESS
;
}
void
dnodeDispatchToMgmtQueue
(
SRpcMsg
*
pMsg
)
{
int32_t
code
=
dnodeWriteToMgmtQueue
(
pMsg
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
SRpcMsg
rsp
=
{.
handle
=
pMsg
->
handle
,
.
code
=
code
};
rpcSendResponse
(
&
rsp
);
rpcFreeCont
(
pMsg
->
pCont
);
}
rpcFreeCont
(
pMsg
->
pCont
);
}
static
void
*
dnodeProcessMgmtQueue
(
void
*
param
)
{
SRpcMsg
*
pMsg
;
SRpcMsg
rsp
=
{
0
};
int
type
;
void
*
handle
;
SMgmtMsg
*
pMgmt
;
SRpcMsg
*
pMsg
;
SRpcMsg
rsp
=
{
0
};
int32_t
qtype
;
void
*
handle
;
while
(
1
)
{
if
(
taosReadQitemFromQset
(
tsMgmtQset
,
&
type
,
(
void
**
)
&
pMsg
,
&
handle
)
==
0
)
{
if
(
taosReadQitemFromQset
(
tsMgmtQset
,
&
qtype
,
(
void
**
)
&
pMgmt
,
&
handle
)
==
0
)
{
dDebug
(
"qset:%p, dnode mgmt got no message from qset, exit"
,
tsMgmtQset
);
break
;
}
dDebug
(
"%p, msg:%s will be processed"
,
pMsg
->
ahandle
,
taosMsg
[
pMsg
->
msgType
]);
pMsg
=
&
pMgmt
->
rpcMsg
;
dDebug
(
"%p, msg:%p:%s will be processed"
,
pMsg
->
ahandle
,
pMgmt
,
taosMsg
[
pMsg
->
msgType
]);
if
(
dnodeProcessMgmtMsgFp
[
pMsg
->
msgType
])
{
rsp
.
code
=
(
*
dnodeProcessMgmtMsgFp
[
pMsg
->
msgType
])(
pMsg
);
}
else
{
...
...
@@ -211,10 +224,9 @@ static void *dnodeProcessMgmtQueue(void *param) {
}
rsp
.
handle
=
pMsg
->
handle
;
rsp
.
pCont
=
NULL
;
rsp
.
pCont
=
NULL
;
rpcSendResponse
(
&
rsp
);
rpcFreeCont
(
pMsg
->
pCont
);
taosFreeQitem
(
pMsg
);
}
...
...
src/dnode/src/dnodePeer.c
浏览文件 @
d583a4ca
...
...
@@ -19,6 +19,7 @@
* to dnode. All theses messages are handled from here
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "taosmsg.h"
#include "tglobal.h"
...
...
@@ -34,8 +35,8 @@ static void (*dnodeProcessReqMsgFp[TSDB_MSG_TYPE_MAX])(SRpcMsg *);
static
void
dnodeProcessReqMsgFromDnode
(
SRpcMsg
*
pMsg
,
SRpcEpSet
*
);
static
void
(
*
dnodeProcessRspMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
rpcMsg
);
static
void
dnodeProcessRspFromDnode
(
SRpcMsg
*
pMsg
,
SRpcEpSet
*
pEpSet
);
static
void
*
ts
Dnode
ServerRpc
=
NULL
;
static
void
*
ts
Dnode
ClientRpc
=
NULL
;
static
void
*
tsServerRpc
=
NULL
;
static
void
*
tsClientRpc
=
NULL
;
int32_t
dnodeInitServer
()
{
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_MD_CREATE_TABLE
]
=
dnodeDispatchToVWriteQueue
;
...
...
@@ -50,11 +51,11 @@ int32_t dnodeInitServer() {
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_MD_CONFIG_DNODE
]
=
dnodeDispatchToMgmtQueue
;
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_MD_CREATE_MNODE
]
=
dnodeDispatchToMgmtQueue
;
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_DM_CONFIG_TABLE
]
=
dnodeDispatchToM
node
PeerQueue
;
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_DM_CONFIG_VNODE
]
=
dnodeDispatchToM
node
PeerQueue
;
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_DM_AUTH
]
=
dnodeDispatchToM
node
PeerQueue
;
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_DM_GRANT
]
=
dnodeDispatchToM
node
PeerQueue
;
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_DM_STATUS
]
=
dnodeDispatchToM
node
PeerQueue
;
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_DM_CONFIG_TABLE
]
=
dnodeDispatchToMPeerQueue
;
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_DM_CONFIG_VNODE
]
=
dnodeDispatchToMPeerQueue
;
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_DM_AUTH
]
=
dnodeDispatchToMPeerQueue
;
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_DM_GRANT
]
=
dnodeDispatchToMPeerQueue
;
dnodeProcessReqMsgFp
[
TSDB_MSG_TYPE_DM_STATUS
]
=
dnodeDispatchToMPeerQueue
;
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
...
...
@@ -66,8 +67,8 @@ int32_t dnodeInitServer() {
rpcInit
.
connType
=
TAOS_CONN_SERVER
;
rpcInit
.
idleTime
=
tsShellActivityTimer
*
1000
;
ts
Dnode
ServerRpc
=
rpcOpen
(
&
rpcInit
);
if
(
ts
Dnode
ServerRpc
==
NULL
)
{
tsServerRpc
=
rpcOpen
(
&
rpcInit
);
if
(
tsServerRpc
==
NULL
)
{
dError
(
"failed to init inter-dnodes RPC server"
);
return
-
1
;
}
...
...
@@ -77,9 +78,9 @@ int32_t dnodeInitServer() {
}
void
dnodeCleanupServer
()
{
if
(
ts
Dnode
ServerRpc
)
{
rpcClose
(
ts
Dnode
ServerRpc
);
ts
Dnode
ServerRpc
=
NULL
;
if
(
tsServerRpc
)
{
rpcClose
(
tsServerRpc
);
tsServerRpc
=
NULL
;
dInfo
(
"inter-dnodes RPC server is closed"
);
}
}
...
...
@@ -93,7 +94,7 @@ static void dnodeProcessReqMsgFromDnode(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
if
(
pMsg
->
pCont
==
NULL
)
return
;
if
(
dnodeGetRunStatus
()
!=
TSDB_
DNODE_
RUN_STATUS_RUNING
)
{
if
(
dnodeGetRunStatus
()
!=
TSDB_RUN_STATUS_RUNING
)
{
rspMsg
.
code
=
TSDB_CODE_APP_NOT_READY
;
rpcSendResponse
(
&
rspMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
...
...
@@ -131,8 +132,8 @@ int32_t dnodeInitClient() {
rpcInit
.
ckey
=
"key"
;
rpcInit
.
secret
=
secret
;
ts
Dnode
ClientRpc
=
rpcOpen
(
&
rpcInit
);
if
(
ts
Dnode
ClientRpc
==
NULL
)
{
tsClientRpc
=
rpcOpen
(
&
rpcInit
);
if
(
tsClientRpc
==
NULL
)
{
dError
(
"failed to init mnode rpc client"
);
return
-
1
;
}
...
...
@@ -142,9 +143,9 @@ int32_t dnodeInitClient() {
}
void
dnodeCleanupClient
()
{
if
(
ts
Dnode
ClientRpc
)
{
rpcClose
(
ts
Dnode
ClientRpc
);
ts
Dnode
ClientRpc
=
NULL
;
if
(
tsClientRpc
)
{
rpcClose
(
tsClientRpc
);
tsClientRpc
=
NULL
;
dInfo
(
"dnode inter-dnodes rpc client is closed"
);
}
}
...
...
@@ -168,15 +169,15 @@ void dnodeAddClientRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg)) {
}
void
dnodeSendMsgToDnode
(
SRpcEpSet
*
epSet
,
SRpcMsg
*
rpcMsg
)
{
rpcSendRequest
(
ts
Dnode
ClientRpc
,
epSet
,
rpcMsg
);
rpcSendRequest
(
tsClientRpc
,
epSet
,
rpcMsg
);
}
void
dnodeSendMsgToMnodeRecv
(
SRpcMsg
*
rpcMsg
,
SRpcMsg
*
rpcRsp
)
{
SRpcEpSet
epSet
=
{
0
};
dnodeGetEpSetForPeer
(
&
epSet
);
rpcSendRecv
(
ts
Dnode
ClientRpc
,
&
epSet
,
rpcMsg
,
rpcRsp
);
rpcSendRecv
(
tsClientRpc
,
&
epSet
,
rpcMsg
,
rpcRsp
);
}
void
dnodeSendMsgToDnodeRecv
(
SRpcMsg
*
rpcMsg
,
SRpcMsg
*
rpcRsp
,
SRpcEpSet
*
epSet
)
{
rpcSendRecv
(
ts
Dnode
ClientRpc
,
epSet
,
rpcMsg
,
rpcRsp
);
rpcSendRecv
(
tsClientRpc
,
epSet
,
rpcMsg
,
rpcRsp
);
}
\ No newline at end of file
src/dnode/src/dnodeShell.c
浏览文件 @
d583a4ca
...
...
@@ -33,9 +33,9 @@
static
void
(
*
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
);
static
void
dnodeProcessMsgFromShell
(
SRpcMsg
*
pMsg
,
SRpcEpSet
*
);
static
int
dnodeRetrieveUserAuthInfo
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
static
void
*
ts
Dnode
ShellRpc
=
NULL
;
static
int32_t
ts
Dnode
QueryReqNum
=
0
;
static
int32_t
ts
Dnode
SubmitReqNum
=
0
;
static
void
*
tsShellRpc
=
NULL
;
static
int32_t
tsQueryReqNum
=
0
;
static
int32_t
tsSubmitReqNum
=
0
;
int32_t
dnodeInitShell
()
{
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_SUBMIT
]
=
dnodeDispatchToVWriteQueue
;
...
...
@@ -44,35 +44,35 @@ int32_t dnodeInitShell() {
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_UPDATE_TAG_VAL
]
=
dnodeDispatchToVWriteQueue
;
// the following message shall be treated as mnode write
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_ACCT
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_ACCT
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_ACCT
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_USER
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_USER
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_USER
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_DNODE
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_DNODE
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_DB
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_DB
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_DB
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_TABLE
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_TABLE
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_TABLE
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_STREAM
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_KILL_QUERY
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_KILL_STREAM
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_KILL_CONN
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CONFIG_DNODE
]
=
dnodeDispatchToM
node
WriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_ACCT
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_ACCT
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_ACCT
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_USER
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_USER
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_USER
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_DNODE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_DNODE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_DB
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_DB
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_DB
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CREATE_TABLE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_DROP_TABLE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_TABLE
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_ALTER_STREAM
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_KILL_QUERY
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_KILL_STREAM
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_KILL_CONN
]
=
dnodeDispatchToMWriteQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CONFIG_DNODE
]
=
dnodeDispatchToMWriteQueue
;
// the following message shall be treated as mnode query
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_HEARTBEAT
]
=
dnodeDispatchToM
node
ReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CONNECT
]
=
dnodeDispatchToM
node
ReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_USE_DB
]
=
dnodeDispatchToM
node
ReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_TABLE_META
]
=
dnodeDispatchToM
node
ReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_STABLE_VGROUP
]
=
dnodeDispatchToM
node
ReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_TABLES_META
]
=
dnodeDispatchToM
node
ReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_SHOW
]
=
dnodeDispatchToM
node
ReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_RETRIEVE
]
=
dnodeDispatchToM
node
ReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_HEARTBEAT
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_CONNECT
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_USE_DB
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_TABLE_META
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_STABLE_VGROUP
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_TABLES_META
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_SHOW
]
=
dnodeDispatchToMReadQueue
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_CM_RETRIEVE
]
=
dnodeDispatchToMReadQueue
;
int32_t
numOfThreads
=
tsNumOfCores
*
tsNumOfThreadsPerCore
;
numOfThreads
=
(
int32_t
)
((
1
.
0
-
tsRatioOfQueryThreads
)
*
numOfThreads
/
2
.
0
);
...
...
@@ -91,8 +91,8 @@ int32_t dnodeInitShell() {
rpcInit
.
idleTime
=
tsShellActivityTimer
*
1000
;
rpcInit
.
afp
=
dnodeRetrieveUserAuthInfo
;
ts
Dnode
ShellRpc
=
rpcOpen
(
&
rpcInit
);
if
(
ts
Dnode
ShellRpc
==
NULL
)
{
tsShellRpc
=
rpcOpen
(
&
rpcInit
);
if
(
tsShellRpc
==
NULL
)
{
dError
(
"failed to init shell rpc server"
);
return
-
1
;
}
...
...
@@ -102,13 +102,13 @@ int32_t dnodeInitShell() {
}
void
dnodeCleanupShell
()
{
if
(
ts
Dnode
ShellRpc
)
{
rpcClose
(
ts
Dnode
ShellRpc
);
ts
Dnode
ShellRpc
=
NULL
;
if
(
tsShellRpc
)
{
rpcClose
(
tsShellRpc
);
tsShellRpc
=
NULL
;
}
}
void
dnodeProcessMsgFromShell
(
SRpcMsg
*
pMsg
,
SRpcEpSet
*
pEpSet
)
{
static
void
dnodeProcessMsgFromShell
(
SRpcMsg
*
pMsg
,
SRpcEpSet
*
pEpSet
)
{
SRpcMsg
rpcMsg
=
{
.
handle
=
pMsg
->
handle
,
.
pCont
=
NULL
,
...
...
@@ -117,7 +117,7 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
if
(
pMsg
->
pCont
==
NULL
)
return
;
if
(
dnodeGetRunStatus
()
!=
TSDB_
DNODE_
RUN_STATUS_RUNING
)
{
if
(
dnodeGetRunStatus
()
!=
TSDB_RUN_STATUS_RUNING
)
{
dError
(
"RPC %p, shell msg:%s is ignored since dnode not running"
,
pMsg
->
handle
,
taosMsg
[
pMsg
->
msgType
]);
rpcMsg
.
code
=
TSDB_CODE_APP_NOT_READY
;
rpcSendResponse
(
&
rpcMsg
);
...
...
@@ -126,9 +126,9 @@ void dnodeProcessMsgFromShell(SRpcMsg *pMsg, SRpcEpSet *pEpSet) {
}
if
(
pMsg
->
msgType
==
TSDB_MSG_TYPE_QUERY
)
{
atomic_fetch_add_32
(
&
ts
Dnode
QueryReqNum
,
1
);
atomic_fetch_add_32
(
&
tsQueryReqNum
,
1
);
}
else
if
(
pMsg
->
msgType
==
TSDB_MSG_TYPE_SUBMIT
)
{
atomic_fetch_add_32
(
&
ts
Dnode
SubmitReqNum
,
1
);
atomic_fetch_add_32
(
&
tsSubmitReqNum
,
1
);
}
else
{}
if
(
dnodeProcessShellMsgFp
[
pMsg
->
msgType
]
)
{
...
...
@@ -211,12 +211,12 @@ void *dnodeSendCfgTableToRecv(int32_t vgId, int32_t tid) {
}
}
S
Dnode
StatisInfo
dnodeGetStatisInfo
()
{
S
Dnode
StatisInfo
info
=
{
0
};
if
(
dnodeGetRunStatus
()
==
TSDB_
DNODE_
RUN_STATUS_RUNING
)
{
SStatisInfo
dnodeGetStatisInfo
()
{
SStatisInfo
info
=
{
0
};
if
(
dnodeGetRunStatus
()
==
TSDB_RUN_STATUS_RUNING
)
{
info
.
httpReqNum
=
httpGetReqCount
();
info
.
queryReqNum
=
atomic_exchange_32
(
&
ts
Dnode
QueryReqNum
,
0
);
info
.
submitReqNum
=
atomic_exchange_32
(
&
ts
Dnode
SubmitReqNum
,
0
);
info
.
queryReqNum
=
atomic_exchange_32
(
&
tsQueryReqNum
,
0
);
info
.
submitReqNum
=
atomic_exchange_32
(
&
tsSubmitReqNum
,
0
);
}
return
info
;
...
...
src/dnode/src/dnodeVWrite.c
浏览文件 @
d583a4ca
...
...
@@ -113,7 +113,7 @@ void dnodeDispatchToVWriteQueue(SRpcMsg *pRpcMsg) {
void
*
dnodeAllocVWriteQueue
(
void
*
pVnode
)
{
pthread_mutex_lock
(
&
tsVWriteWP
.
mutex
);
SVWriteWorker
*
pWorker
=
tsVWriteWP
.
worker
+
tsVWriteWP
.
nextId
;
void
*
queue
=
taosOpenQueue
();
taos_queue
*
queue
=
taosOpenQueue
();
if
(
queue
==
NULL
)
{
pthread_mutex_unlock
(
&
tsVWriteWP
.
mutex
);
return
NULL
;
...
...
@@ -207,8 +207,8 @@ static void *dnodeProcessVWriteQueue(void *param) {
bool
forceFsync
=
false
;
for
(
int32_t
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
taosGetQitem
(
pWorker
->
qall
,
&
qtype
,
(
void
**
)
&
pWrite
);
dTrace
(
"%p, msg:%p:%s will be processed in vwrite queue, qtype:%
d version
:%"
PRIu64
,
pWrite
->
rpcAhandle
,
pWrite
,
taosMsg
[
pWrite
->
pHead
->
msgType
],
qtype
,
pWrite
->
pHead
->
version
);
dTrace
(
"%p, msg:%p:%s will be processed in vwrite queue, qtype:%
s hver
:%"
PRIu64
,
pWrite
->
rpcAhandle
,
pWrite
,
taosMsg
[
pWrite
->
pHead
->
msgType
],
qtype
Str
[
qtype
]
,
pWrite
->
pHead
->
version
);
pWrite
->
code
=
vnodeProcessWrite
(
pVnode
,
pWrite
->
pHead
,
qtype
,
&
pWrite
->
rspRet
);
if
(
pWrite
->
code
<=
0
)
pWrite
->
processedCount
=
1
;
...
...
src/inc/dnode.h
浏览文件 @
d583a4ca
...
...
@@ -27,16 +27,16 @@ typedef struct {
int32_t
queryReqNum
;
int32_t
submitReqNum
;
int32_t
httpReqNum
;
}
S
Dnode
StatisInfo
;
}
SStatisInfo
;
typedef
enum
{
TSDB_
DNODE_
RUN_STATUS_INITIALIZE
,
TSDB_
DNODE_
RUN_STATUS_RUNING
,
TSDB_
DNODE_
RUN_STATUS_STOPPED
}
S
Dnode
RunStatus
;
TSDB_RUN_STATUS_INITIALIZE
,
TSDB_RUN_STATUS_RUNING
,
TSDB_RUN_STATUS_STOPPED
}
SRunStatus
;
S
DnodeRunStatus
dnodeGetRunStatus
();
S
Dnode
StatisInfo
dnodeGetStatisInfo
();
S
RunStatus
dnodeGetRunStatus
();
SStatisInfo
dnodeGetStatisInfo
();
bool
dnodeIsFirstDeploy
();
bool
dnodeIsMasterEp
(
char
*
ep
);
...
...
@@ -59,15 +59,15 @@ void dnodeSendRpcVWriteRsp(void *pVnode, void *param, int32_t code);
void
*
dnodeAllocVReadQueue
(
void
*
pVnode
);
void
dnodeFreeVReadQueue
(
void
*
rqueue
);
int32_t
dnodeAllocateM
nodePq
ueue
();
void
dnodeFreeM
nodePq
ueue
();
int32_t
dnodeAlloc
ateMnodeRq
ueue
();
void
dnodeFreeM
nodeRq
ueue
();
int32_t
dnodeAlloc
ateMnodeW
queue
();
void
dnodeFreeM
nodeW
queue
();
void
dnodeSendRpcM
node
WriteRsp
(
void
*
pMsg
,
int32_t
code
);
void
dnodeReprocessM
node
WriteMsg
(
void
*
pMsg
);
void
dnodeDelayReprocessM
node
WriteMsg
(
void
*
pMsg
);
int32_t
dnodeAllocateM
PeerQ
ueue
();
void
dnodeFreeM
PeerQ
ueue
();
int32_t
dnodeAlloc
MReadQ
ueue
();
void
dnodeFreeM
ReadQ
ueue
();
int32_t
dnodeAlloc
MWrite
queue
();
void
dnodeFreeM
Write
queue
();
void
dnodeSendRpcMWriteRsp
(
void
*
pMsg
,
int32_t
code
);
void
dnodeReprocessMWriteMsg
(
void
*
pMsg
);
void
dnodeDelayReprocessMWriteMsg
(
void
*
pMsg
);
void
dnodeSendStatusMsgToMnode
();
...
...
src/inc/mnode.h
浏览文件 @
d583a4ca
...
...
@@ -35,7 +35,13 @@ typedef struct {
}
SMnodeRsp
;
typedef
struct
SMnodeMsg
{
SRpcMsg
rpcMsg
;
struct
SAcctObj
*
pAcct
;
struct
SDnodeObj
*
pDnode
;
struct
SUserObj
*
pUser
;
struct
SDbObj
*
pDb
;
struct
SVgObj
*
pVgroup
;
struct
STableObj
*
pTable
;
struct
SSTableObj
*
pSTable
;
SMnodeRsp
rpcRsp
;
int8_t
received
;
int8_t
successed
;
...
...
@@ -43,16 +49,11 @@ typedef struct SMnodeMsg {
int8_t
retry
;
int32_t
code
;
void
*
pObj
;
struct
SAcctObj
*
pAcct
;
struct
SDnodeObj
*
pDnode
;
struct
SUserObj
*
pUser
;
struct
SDbObj
*
pDb
;
struct
SVgObj
*
pVgroup
;
struct
STableObj
*
pTable
;
struct
SSuperTableObj
*
pSTable
;
SRpcMsg
rpcMsg
;
char
pCont
[];
}
SMnodeMsg
;
void
mnodeCreateMsg
(
SMnodeMsg
*
pMsg
,
SRpcMsg
*
r
pcMsg
);
void
*
mnodeCreateMsg
(
SRpcMsg
*
pR
pcMsg
);
int32_t
mnodeInitMsg
(
SMnodeMsg
*
pMsg
);
void
mnodeCleanupMsg
(
SMnodeMsg
*
pMsg
);
...
...
src/inc/taosdef.h
浏览文件 @
d583a4ca
...
...
@@ -429,42 +429,45 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf
#define TSDB_PORT_DNODEDNODE 5
#define TSDB_PORT_SYNC 10
#define TSDB_PORT_HTTP 11
#define TSDB_PORT_ARBITRATOR 12
#define TSDB_PORT_ARBITRATOR 12
#define TAOS_QTYPE_RPC 0
#define TAOS_QTYPE_FWD 1
#define TAOS_QTYPE_WAL 2
#define TAOS_QTYPE_CQ 3
#define TAOS_QTYPE_QUERY 4
typedef
enum
{
TAOS_QTYPE_RPC
=
0
,
TAOS_QTYPE_FWD
=
1
,
TAOS_QTYPE_WAL
=
2
,
TAOS_QTYPE_CQ
=
3
,
TAOS_QTYPE_QUERY
=
4
}
EQType
;
typedef
enum
{
TSDB_SUPER_TABLE
=
0
,
// super table
TSDB_CHILD_TABLE
=
1
,
// table created from super table
TSDB_NORMAL_TABLE
=
2
,
// ordinary table
TSDB_STREAM_TABLE
=
3
,
// table created from stream computing
TSDB_TABLE_MAX
=
4
TSDB_SUPER_TABLE
=
0
,
// super table
TSDB_CHILD_TABLE
=
1
,
// table created from super table
TSDB_NORMAL_TABLE
=
2
,
// ordinary table
TSDB_STREAM_TABLE
=
3
,
// table created from stream computing
TSDB_TABLE_MAX
=
4
}
ETableType
;
typedef
enum
{
TSDB_MOD_MNODE
,
TSDB_MOD_HTTP
,
TSDB_MOD_MONITOR
,
TSDB_MOD_MQTT
,
TSDB_MOD_MAX
TSDB_MOD_MNODE
=
0
,
TSDB_MOD_HTTP
=
1
,
TSDB_MOD_MONITOR
=
2
,
TSDB_MOD_MQTT
=
3
,
TSDB_MOD_MAX
=
4
}
EModuleType
;
typedef
enum
{
TSDB_CHECK_ITEM_NETWORK
,
TSDB_CHECK_ITEM_MEM
,
TSDB_CHECK_ITEM_CPU
,
TSDB_CHECK_ITEM_DISK
,
TSDB_CHECK_ITEM_OS
,
TSDB_CHECK_ITEM_ACCESS
,
TSDB_CHECK_ITEM_VERSION
,
TSDB_CHECK_ITEM_DATAFILE
,
TSDB_CHECK_ITEM_MAX
}
ECheckItemType
;
typedef
enum
{
TSDB_CHECK_ITEM_NETWORK
,
TSDB_CHECK_ITEM_MEM
,
TSDB_CHECK_ITEM_CPU
,
TSDB_CHECK_ITEM_DISK
,
TSDB_CHECK_ITEM_OS
,
TSDB_CHECK_ITEM_ACCESS
,
TSDB_CHECK_ITEM_VERSION
,
TSDB_CHECK_ITEM_DATAFILE
,
TSDB_CHECK_ITEM_MAX
}
ECheckItemType
;
extern
char
*
qtypeStr
[];
#ifdef __cplusplus
}
...
...
src/inc/tcq.h
浏览文件 @
d583a4ca
...
...
@@ -24,7 +24,7 @@ extern "C" {
typedef
int32_t
(
*
FCqWrite
)(
void
*
ahandle
,
void
*
pHead
,
int32_t
qtype
,
void
*
pMsg
);
typedef
struct
{
int
vgId
;
int
32_t
vgId
;
char
user
[
TSDB_USER_LEN
];
char
pass
[
TSDB_PASSWORD_LEN
];
char
db
[
TSDB_DB_NAME_LEN
];
...
...
@@ -42,12 +42,12 @@ void cqStart(void *handle);
void
cqStop
(
void
*
handle
);
// cqCreate is called by TSDB to start an instance of CQ
void
*
cqCreate
(
void
*
handle
,
uint64_t
uid
,
int
sid
,
char
*
sqlStr
,
STSchema
*
pSchema
);
void
*
cqCreate
(
void
*
handle
,
uint64_t
uid
,
int
32_t
sid
,
char
*
sqlStr
,
STSchema
*
pSchema
);
// cqDrop is called by TSDB to stop an instance of CQ, handle is the return value of cqCreate
void
cqDrop
(
void
*
handle
);
extern
int
cqDebugFlag
;
extern
int
32_t
cqDebugFlag
;
#ifdef __cplusplus
...
...
src/inc/tsdb.h
浏览文件 @
d583a4ca
...
...
@@ -164,6 +164,12 @@ typedef struct STsdbQueryCond {
SColumnInfo
*
colList
;
}
STsdbQueryCond
;
typedef
struct
SMemRef
{
int32_t
ref
;
void
*
mem
;
void
*
imem
;
}
SMemRef
;
typedef
struct
SDataBlockInfo
{
STimeWindow
window
;
int32_t
rows
;
...
...
@@ -193,7 +199,7 @@ typedef struct {
* @param qinfo query info handle from query processor
* @return
*/
TsdbQueryHandleT
*
tsdbQueryTables
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
tableInfoGroup
,
void
*
qinfo
);
TsdbQueryHandleT
*
tsdbQueryTables
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
tableInfoGroup
,
void
*
qinfo
,
SMemRef
*
pRef
);
/**
* Get the last row of the given query time window for all the tables in STableGroupInfo object.
...
...
@@ -205,7 +211,7 @@ TsdbQueryHandleT *tsdbQueryTables(TSDB_REPO_T *tsdb, STsdbQueryCond *pCond, STab
* @param tableInfo table list.
* @return
*/
TsdbQueryHandleT
tsdbQueryLastRow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
tableInfo
,
void
*
qinfo
);
TsdbQueryHandleT
tsdbQueryLastRow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
tableInfo
,
void
*
qinfo
,
SMemRef
*
pRef
);
/**
* get the queried table object list
...
...
@@ -223,7 +229,7 @@ SArray* tsdbGetQueriedTableList(TsdbQueryHandleT *pHandle);
* @return
*/
TsdbQueryHandleT
tsdbQueryRowsInExternalWindow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
void
*
qinfo
);
void
*
qinfo
,
SMemRef
*
pRef
);
/**
* move to next block if exists
...
...
src/inc/twal.h
浏览文件 @
d583a4ca
...
...
@@ -25,9 +25,15 @@ typedef enum {
TAOS_WAL_FSYNC
=
2
}
EWalType
;
typedef
enum
{
TAOS_WAL_NOT_KEEP
=
0
,
TAOS_WAL_KEEP
=
1
}
EWalKeep
;
typedef
struct
{
int8_t
msgType
;
int8_t
reserved
[
3
];
int8_t
sver
;
int8_t
reserved
[
2
];
int32_t
len
;
uint64_t
version
;
uint32_t
signature
;
...
...
@@ -36,11 +42,10 @@ typedef struct {
}
SWalHead
;
typedef
struct
{
int32_t
vgId
;
int32_t
fsyncPeriod
;
// millisecond
int8_t
walLevel
;
// wal level
int8_t
wals
;
// number of WAL files;
int8_t
keep
;
// keep the wal file when closed
int32_t
vgId
;
int32_t
fsyncPeriod
;
// millisecond
EWalType
walLevel
;
// wal level
EWalKeep
keep
;
// keep the wal file when closed
}
SWalCfg
;
typedef
void
*
twalh
;
// WAL HANDLE
...
...
@@ -58,7 +63,7 @@ int32_t walWrite(twalh, SWalHead *);
void
walFsync
(
twalh
,
bool
forceFsync
);
int32_t
walRestore
(
twalh
,
void
*
pVnode
,
FWalWrite
writeFp
);
int32_t
walGetWalFile
(
twalh
,
char
*
fileName
,
int64_t
*
fileId
);
int64_t
walGetVersion
(
twalh
);
u
int64_t
walGetVersion
(
twalh
);
#ifdef __cplusplus
}
...
...
src/kit/taosdemo/taosdemo.c
浏览文件 @
d583a4ca
...
...
@@ -793,9 +793,9 @@ int main(int argc, char *argv[]) {
(
ntables
*
nrecords_per_table
)
/
(
t
*
nrecords_per_request
),
t
*
1000
);
printf
(
"Spent %.4f seconds to insert %d records with %d record(s) per request: %.2f records/second
\n
"
,
t
,
ntables
*
nrecords_per_table
,
nrecords_per_request
,
ntables
*
nrecords_per_table
/
t
);
printf
(
"Spent %.4f seconds to insert %
ll
d records with %d record(s) per request: %.2f records/second
\n
"
,
t
,
(
long
long
int
)
ntables
*
nrecords_per_table
,
nrecords_per_request
,
((
long
long
int
)
ntables
*
nrecords_per_table
)
/
t
);
for
(
int
i
=
0
;
i
<
threads
;
i
++
)
{
info
*
t_info
=
infos
+
i
;
...
...
src/mnode/inc/mnodeDef.h
浏览文件 @
d583a4ca
...
...
@@ -89,7 +89,7 @@ typedef struct STableObj {
int8_t
type
;
}
STableObj
;
typedef
struct
SS
uper
TableObj
{
typedef
struct
SSTableObj
{
STableObj
info
;
int8_t
reserved0
[
9
];
// for fill struct STableObj to 4byte align
int16_t
nextColId
;
...
...
@@ -104,7 +104,7 @@ typedef struct SSuperTableObj {
int32_t
numOfTables
;
SSchema
*
schema
;
void
*
vgHash
;
}
SS
uper
TableObj
;
}
SSTableObj
;
typedef
struct
{
STableObj
info
;
...
...
@@ -122,8 +122,8 @@ typedef struct {
int32_t
refCount
;
char
*
sql
;
//used by normal table
SSchema
*
schema
;
//used by normal table
SS
uperTableObj
*
superTable
;
}
SC
hild
TableObj
;
SS
TableObj
*
superTable
;
}
SCTableObj
;
typedef
struct
{
int32_t
dnodeId
;
...
...
src/mnode/inc/mnodeTable.h
浏览文件 @
d583a4ca
...
...
@@ -29,8 +29,8 @@ int64_t mnodeGetChildTableNum();
void
*
mnodeGetTable
(
char
*
tableId
);
void
mnodeIncTableRef
(
void
*
pTable
);
void
mnodeDecTableRef
(
void
*
pTable
);
void
*
mnodeGetNextChildTable
(
void
*
pIter
,
SC
hild
TableObj
**
pTable
);
void
*
mnodeGetNextSuperTable
(
void
*
pIter
,
SS
uper
TableObj
**
pTable
);
void
*
mnodeGetNextChildTable
(
void
*
pIter
,
SCTableObj
**
pTable
);
void
*
mnodeGetNextSuperTable
(
void
*
pIter
,
SSTableObj
**
pTable
);
void
mnodeDropAllChildTables
(
SDbObj
*
pDropDb
);
void
mnodeDropAllSuperTables
(
SDbObj
*
pDropDb
);
void
mnodeDropAllChildTablesInVgroups
(
SVgObj
*
pVgroup
);
...
...
src/mnode/inc/mnodeVgroup.h
浏览文件 @
d583a4ca
...
...
@@ -43,8 +43,8 @@ void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle);
void
mnodeAlterVgroup
(
SVgObj
*
pVgroup
,
void
*
ahandle
);
int32_t
mnodeGetAvailableVgroup
(
struct
SMnodeMsg
*
pMsg
,
SVgObj
**
pVgroup
,
int32_t
*
sid
);
void
mnodeAddTableIntoVgroup
(
SVgObj
*
pVgroup
,
SC
hild
TableObj
*
pTable
);
void
mnodeRemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
SC
hild
TableObj
*
pTable
);
void
mnodeAddTableIntoVgroup
(
SVgObj
*
pVgroup
,
SCTableObj
*
pTable
);
void
mnodeRemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
SCTableObj
*
pTable
);
void
mnodeSendDropVnodeMsg
(
int32_t
vgId
,
SRpcEpSet
*
epSet
,
void
*
ahandle
);
void
mnodeSendCreateVgroupMsg
(
SVgObj
*
pVgroup
,
void
*
ahandle
);
void
mnodeSendAlterVgroupMsg
(
SVgObj
*
pVgroup
);
...
...
src/mnode/src/mnodeInt.c
浏览文件 @
d583a4ca
...
...
@@ -18,7 +18,7 @@
#include "taosmsg.h"
#include "taoserror.h"
#include "trpc.h"
#include "t
cach
e.h"
#include "t
queu
e.h"
#include "mnode.h"
#include "dnode.h"
#include "mnodeDef.h"
...
...
@@ -34,8 +34,15 @@
#include "mnodeUser.h"
#include "mnodeVgroup.h"
void
mnodeCreateMsg
(
SMnodeMsg
*
pMsg
,
SRpcMsg
*
rpcMsg
)
{
pMsg
->
rpcMsg
=
*
rpcMsg
;
void
*
mnodeCreateMsg
(
SRpcMsg
*
pRpcMsg
)
{
int32_t
size
=
sizeof
(
SMnodeMsg
)
+
pRpcMsg
->
contLen
;
SMnodeMsg
*
pMsg
=
taosAllocateQitem
(
size
);
pMsg
->
rpcMsg
=
*
pRpcMsg
;
pMsg
->
rpcMsg
.
pCont
=
pMsg
->
pCont
;
memcpy
(
pMsg
->
pCont
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
return
pMsg
;
}
int32_t
mnodeInitMsg
(
SMnodeMsg
*
pMsg
)
{
...
...
@@ -54,7 +61,9 @@ int32_t mnodeInitMsg(SMnodeMsg *pMsg) {
void
mnodeCleanupMsg
(
SMnodeMsg
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
if
(
pMsg
->
rpcMsg
.
pCont
)
rpcFreeCont
(
pMsg
->
rpcMsg
.
pCont
);
if
(
pMsg
->
rpcMsg
.
pCont
!=
pMsg
->
pCont
)
{
tfree
(
pMsg
->
rpcMsg
.
pCont
);
}
if
(
pMsg
->
pUser
)
mnodeDecUserRef
(
pMsg
->
pUser
);
if
(
pMsg
->
pDb
)
mnodeDecDbRef
(
pMsg
->
pDb
);
if
(
pMsg
->
pVgroup
)
mnodeDecVgroupRef
(
pMsg
->
pVgroup
);
...
...
src/mnode/src/mnodeMain.c
浏览文件 @
d583a4ca
...
...
@@ -96,9 +96,9 @@ int32_t mnodeStartSystem() {
return
-
1
;
}
dnodeAlloc
ateMnodeW
queue
();
dnodeAlloc
ateMnodeRq
ueue
();
dnodeAllocateM
nodePq
ueue
();
dnodeAlloc
MWrite
queue
();
dnodeAlloc
MReadQ
ueue
();
dnodeAllocateM
PeerQ
ueue
();
if
(
mnodeInitComponents
()
!=
0
)
{
return
-
1
;
...
...
@@ -127,9 +127,9 @@ void mnodeCleanupSystem() {
mInfo
(
"starting to clean up mnode"
);
tsMgmtIsRunning
=
false
;
dnodeFreeM
nodeW
queue
();
dnodeFreeM
nodeRq
ueue
();
dnodeFreeM
nodePq
ueue
();
dnodeFreeM
Write
queue
();
dnodeFreeM
ReadQ
ueue
();
dnodeFreeM
PeerQ
ueue
();
mnodeCleanupTimer
();
mnodeCleanupComponents
(
sizeof
(
tsMnodeComponents
)
/
sizeof
(
tsMnodeComponents
[
0
])
-
1
);
...
...
src/mnode/src/mnodeSdb.c
浏览文件 @
d583a4ca
...
...
@@ -175,7 +175,7 @@ static void *sdbGetTableFromId(int32_t tableId) {
}
static
int32_t
sdbInitWal
()
{
SWalCfg
walCfg
=
{.
vgId
=
1
,
.
walLevel
=
2
,
.
wals
=
2
,
.
keep
=
1
,
.
fsyncPeriod
=
0
};
SWalCfg
walCfg
=
{.
vgId
=
1
,
.
walLevel
=
TAOS_WAL_FSYNC
,
.
keep
=
TAOS_WAL_KEEP
,
.
fsyncPeriod
=
0
};
char
temp
[
TSDB_FILENAME_LEN
];
sprintf
(
temp
,
"%s/wal"
,
tsMnodeDir
);
tsSdbObj
.
wal
=
walOpen
(
temp
,
&
walCfg
);
...
...
@@ -295,7 +295,7 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) {
if
(
pOper
->
writeCb
!=
NULL
)
{
pOper
->
retCode
=
(
*
pOper
->
writeCb
)(
pMsg
,
pOper
->
retCode
);
}
dnodeSendRpcM
node
WriteRsp
(
pMsg
,
pOper
->
retCode
);
dnodeSendRpcMWriteRsp
(
pMsg
,
pOper
->
retCode
);
// if ahandle, means this func is called by sdb write
if
(
ahandle
==
NULL
)
{
...
...
@@ -1043,7 +1043,7 @@ void sdbFreeWritequeue() {
int32_t
sdbWriteToQueue
(
void
*
param
,
void
*
data
,
int32_t
qtype
,
void
*
pMsg
)
{
SWalHead
*
pHead
=
data
;
int32_t
size
=
sizeof
(
SWalHead
)
+
pHead
->
len
;
SWalHead
*
pWal
=
(
SWalHead
*
)
taosAllocateQitem
(
size
);
SWalHead
*
pWal
=
taosAllocateQitem
(
size
);
memcpy
(
pWal
,
pHead
,
size
);
taosWriteQitem
(
tsSdbWriteQueue
,
qtype
,
pWal
);
...
...
src/mnode/src/mnodeTable.c
浏览文件 @
d583a4ca
...
...
@@ -52,9 +52,9 @@ static int32_t tsSuperTableUpdateSize;
static
void
*
mnodeGetChildTable
(
char
*
tableId
);
static
void
*
mnodeGetSuperTable
(
char
*
tableId
);
static
void
*
mnodeGetSuperTableByUid
(
uint64_t
uid
);
static
void
mnodeDropAllChildTablesInStable
(
SS
uper
TableObj
*
pStable
);
static
void
mnodeAddTableIntoStable
(
SS
uperTableObj
*
pStable
,
SChild
TableObj
*
pCtable
);
static
void
mnodeRemoveTableFromStable
(
SS
uperTableObj
*
pStable
,
SChild
TableObj
*
pCtable
);
static
void
mnodeDropAllChildTablesInStable
(
SSTableObj
*
pStable
);
static
void
mnodeAddTableIntoStable
(
SS
TableObj
*
pStable
,
SC
TableObj
*
pCtable
);
static
void
mnodeRemoveTableFromStable
(
SS
TableObj
*
pStable
,
SC
TableObj
*
pCtable
);
static
int32_t
mnodeGetShowTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeRetrieveShowTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
...
...
@@ -86,9 +86,9 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg);
static
int32_t
mnodeProcessAlterTableMsg
(
SMnodeMsg
*
pMsg
);
static
void
mnodeProcessAlterTableRsp
(
SRpcMsg
*
rpcMsg
);
static
int32_t
mnodeFindSuperTableColumnIndex
(
SS
uper
TableObj
*
pStable
,
char
*
colName
);
static
int32_t
mnodeFindSuperTableColumnIndex
(
SSTableObj
*
pStable
,
char
*
colName
);
static
void
mnodeDestroyChildTable
(
SC
hild
TableObj
*
pTable
)
{
static
void
mnodeDestroyChildTable
(
SCTableObj
*
pTable
)
{
taosTFree
(
pTable
->
info
.
tableId
);
taosTFree
(
pTable
->
schema
);
taosTFree
(
pTable
->
sql
);
...
...
@@ -101,7 +101,7 @@ static int32_t mnodeChildTableActionDestroy(SSdbOper *pOper) {
}
static
int32_t
mnodeChildTableActionInsert
(
SSdbOper
*
pOper
)
{
SC
hild
TableObj
*
pTable
=
pOper
->
pObj
;
SCTableObj
*
pTable
=
pOper
->
pObj
;
SVgObj
*
pVgroup
=
mnodeGetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
...
...
@@ -150,7 +150,7 @@ static int32_t mnodeChildTableActionInsert(SSdbOper *pOper) {
}
static
int32_t
mnodeChildTableActionDelete
(
SSdbOper
*
pOper
)
{
SC
hild
TableObj
*
pTable
=
pOper
->
pObj
;
SCTableObj
*
pTable
=
pOper
->
pObj
;
if
(
pTable
->
vgId
==
0
)
{
return
TSDB_CODE_MND_VGROUP_NOT_EXIST
;
}
...
...
@@ -186,8 +186,8 @@ static int32_t mnodeChildTableActionDelete(SSdbOper *pOper) {
}
static
int32_t
mnodeChildTableActionUpdate
(
SSdbOper
*
pOper
)
{
SC
hild
TableObj
*
pNew
=
pOper
->
pObj
;
SC
hild
TableObj
*
pTable
=
mnodeGetChildTable
(
pNew
->
info
.
tableId
);
SCTableObj
*
pNew
=
pOper
->
pObj
;
SCTableObj
*
pTable
=
mnodeGetChildTable
(
pNew
->
info
.
tableId
);
if
(
pTable
!=
pNew
)
{
void
*
oldTableId
=
pTable
->
info
.
tableId
;
void
*
oldSql
=
pTable
->
sql
;
...
...
@@ -195,7 +195,7 @@ static int32_t mnodeChildTableActionUpdate(SSdbOper *pOper) {
void
*
oldSTable
=
pTable
->
superTable
;
int32_t
oldRefCount
=
pTable
->
refCount
;
memcpy
(
pTable
,
pNew
,
sizeof
(
SC
hild
TableObj
));
memcpy
(
pTable
,
pNew
,
sizeof
(
SCTableObj
));
pTable
->
refCount
=
oldRefCount
;
pTable
->
sql
=
pNew
->
sql
;
...
...
@@ -213,7 +213,7 @@ static int32_t mnodeChildTableActionUpdate(SSdbOper *pOper) {
}
static
int32_t
mnodeChildTableActionEncode
(
SSdbOper
*
pOper
)
{
SC
hild
TableObj
*
pTable
=
pOper
->
pObj
;
SCTableObj
*
pTable
=
pOper
->
pObj
;
assert
(
pTable
!=
NULL
&&
pOper
->
rowData
!=
NULL
);
int32_t
len
=
strlen
(
pTable
->
info
.
tableId
);
...
...
@@ -244,7 +244,7 @@ static int32_t mnodeChildTableActionEncode(SSdbOper *pOper) {
static
int32_t
mnodeChildTableActionDecode
(
SSdbOper
*
pOper
)
{
assert
(
pOper
->
rowData
!=
NULL
);
SC
hildTableObj
*
pTable
=
calloc
(
1
,
sizeof
(
SChild
TableObj
));
SC
TableObj
*
pTable
=
calloc
(
1
,
sizeof
(
SC
TableObj
));
if
(
pTable
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
int32_t
len
=
strlen
(
pOper
->
rowData
);
...
...
@@ -284,7 +284,7 @@ static int32_t mnodeChildTableActionDecode(SSdbOper *pOper) {
static
int32_t
mnodeChildTableActionRestored
()
{
void
*
pIter
=
NULL
;
SC
hild
TableObj
*
pTable
=
NULL
;
SCTableObj
*
pTable
=
NULL
;
while
(
1
)
{
pIter
=
mnodeGetNextChildTable
(
pIter
,
&
pTable
);
...
...
@@ -323,7 +323,7 @@ static int32_t mnodeChildTableActionRestored() {
}
if
(
pTable
->
info
.
type
==
TSDB_CHILD_TABLE
)
{
SS
uper
TableObj
*
pSuperTable
=
mnodeGetSuperTableByUid
(
pTable
->
suid
);
SSTableObj
*
pSuperTable
=
mnodeGetSuperTableByUid
(
pTable
->
suid
);
if
(
pSuperTable
==
NULL
)
{
mError
(
"ctable:%s, stable:%"
PRIu64
" not exist"
,
pTable
->
info
.
tableId
,
pTable
->
suid
);
pTable
->
vgId
=
0
;
...
...
@@ -344,14 +344,14 @@ static int32_t mnodeChildTableActionRestored() {
}
static
int32_t
mnodeInitChildTables
()
{
SC
hild
TableObj
tObj
;
SCTableObj
tObj
;
tsChildTableUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
.
info
.
type
;
SSdbTableDesc
tableDesc
=
{
.
tableId
=
SDB_TABLE_CTABLE
,
.
tableName
=
"ctables"
,
.
hashSessions
=
TSDB_DEFAULT_CTABLES_HASH_SIZE
,
.
maxRowSize
=
sizeof
(
SC
hild
TableObj
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
)
+
TSDB_TABLE_FNAME_LEN
+
TSDB_CQ_SQL_SIZE
,
.
maxRowSize
=
sizeof
(
SCTableObj
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
)
+
TSDB_TABLE_FNAME_LEN
+
TSDB_CQ_SQL_SIZE
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_VAR_STRING
,
.
insertFp
=
mnodeChildTableActionInsert
,
...
...
@@ -386,7 +386,7 @@ int64_t mnodeGetChildTableNum() {
return
sdbGetNumOfRows
(
tsChildTableSdb
);
}
static
void
mnodeAddTableIntoStable
(
SS
uperTableObj
*
pStable
,
SChild
TableObj
*
pCtable
)
{
static
void
mnodeAddTableIntoStable
(
SS
TableObj
*
pStable
,
SC
TableObj
*
pCtable
)
{
atomic_add_fetch_32
(
&
pStable
->
numOfTables
,
1
);
if
(
pStable
->
vgHash
==
NULL
)
{
...
...
@@ -402,7 +402,7 @@ static void mnodeAddTableIntoStable(SSuperTableObj *pStable, SChildTableObj *pCt
}
}
static
void
mnodeRemoveTableFromStable
(
SS
uperTableObj
*
pStable
,
SChild
TableObj
*
pCtable
)
{
static
void
mnodeRemoveTableFromStable
(
SS
TableObj
*
pStable
,
SC
TableObj
*
pCtable
)
{
atomic_sub_fetch_32
(
&
pStable
->
numOfTables
,
1
);
if
(
pStable
->
vgHash
==
NULL
)
return
;
...
...
@@ -416,7 +416,7 @@ static void mnodeRemoveTableFromStable(SSuperTableObj *pStable, SChildTableObj *
mnodeDecVgroupRef
(
pVgroup
);
}
static
void
mnodeDestroySuperTable
(
SS
uper
TableObj
*
pStable
)
{
static
void
mnodeDestroySuperTable
(
SSTableObj
*
pStable
)
{
if
(
pStable
->
vgHash
!=
NULL
)
{
taosHashCleanup
(
pStable
->
vgHash
);
pStable
->
vgHash
=
NULL
;
...
...
@@ -432,7 +432,7 @@ static int32_t mnodeSuperTableActionDestroy(SSdbOper *pOper) {
}
static
int32_t
mnodeSuperTableActionInsert
(
SSdbOper
*
pOper
)
{
SS
uper
TableObj
*
pStable
=
pOper
->
pObj
;
SSTableObj
*
pStable
=
pOper
->
pObj
;
SDbObj
*
pDb
=
mnodeGetDbByTableId
(
pStable
->
info
.
tableId
);
if
(
pDb
!=
NULL
&&
pDb
->
status
==
TSDB_DB_STATUS_READY
)
{
mnodeAddSuperTableIntoDb
(
pDb
);
...
...
@@ -443,11 +443,11 @@ static int32_t mnodeSuperTableActionInsert(SSdbOper *pOper) {
}
static
int32_t
mnodeSuperTableActionDelete
(
SSdbOper
*
pOper
)
{
SS
uper
TableObj
*
pStable
=
pOper
->
pObj
;
SSTableObj
*
pStable
=
pOper
->
pObj
;
SDbObj
*
pDb
=
mnodeGetDbByTableId
(
pStable
->
info
.
tableId
);
if
(
pDb
!=
NULL
)
{
mnodeRemoveSuperTableFromDb
(
pDb
);
mnodeDropAllChildTablesInStable
((
SS
uper
TableObj
*
)
pStable
);
mnodeDropAllChildTablesInStable
((
SSTableObj
*
)
pStable
);
}
mnodeDecDbRef
(
pDb
);
...
...
@@ -455,8 +455,8 @@ static int32_t mnodeSuperTableActionDelete(SSdbOper *pOper) {
}
static
int32_t
mnodeSuperTableActionUpdate
(
SSdbOper
*
pOper
)
{
SS
uper
TableObj
*
pNew
=
pOper
->
pObj
;
SS
uper
TableObj
*
pTable
=
mnodeGetSuperTable
(
pNew
->
info
.
tableId
);
SSTableObj
*
pNew
=
pOper
->
pObj
;
SSTableObj
*
pTable
=
mnodeGetSuperTable
(
pNew
->
info
.
tableId
);
if
(
pTable
!=
NULL
&&
pTable
!=
pNew
)
{
void
*
oldTableId
=
pTable
->
info
.
tableId
;
void
*
oldSchema
=
pTable
->
schema
;
...
...
@@ -464,7 +464,7 @@ static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) {
int32_t
oldRefCount
=
pTable
->
refCount
;
int32_t
oldNumOfTables
=
pTable
->
numOfTables
;
memcpy
(
pTable
,
pNew
,
sizeof
(
SS
uper
TableObj
));
memcpy
(
pTable
,
pNew
,
sizeof
(
SSTableObj
));
pTable
->
vgHash
=
oldVgHash
;
pTable
->
refCount
=
oldRefCount
;
...
...
@@ -480,7 +480,7 @@ static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) {
}
static
int32_t
mnodeSuperTableActionEncode
(
SSdbOper
*
pOper
)
{
SS
uper
TableObj
*
pStable
=
pOper
->
pObj
;
SSTableObj
*
pStable
=
pOper
->
pObj
;
assert
(
pOper
->
pObj
!=
NULL
&&
pOper
->
rowData
!=
NULL
);
int32_t
len
=
strlen
(
pStable
->
info
.
tableId
);
...
...
@@ -504,7 +504,7 @@ static int32_t mnodeSuperTableActionEncode(SSdbOper *pOper) {
static
int32_t
mnodeSuperTableActionDecode
(
SSdbOper
*
pOper
)
{
assert
(
pOper
->
rowData
!=
NULL
);
SS
uperTableObj
*
pStable
=
(
SSuperTableObj
*
)
calloc
(
1
,
sizeof
(
SSuper
TableObj
));
SS
TableObj
*
pStable
=
(
SSTableObj
*
)
calloc
(
1
,
sizeof
(
SS
TableObj
));
if
(
pStable
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
int32_t
len
=
strlen
(
pOper
->
rowData
);
...
...
@@ -537,14 +537,14 @@ static int32_t mnodeSuperTableActionRestored() {
}
static
int32_t
mnodeInitSuperTables
()
{
SS
uper
TableObj
tObj
;
SSTableObj
tObj
;
tsSuperTableUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
.
info
.
type
;
SSdbTableDesc
tableDesc
=
{
.
tableId
=
SDB_TABLE_STABLE
,
.
tableName
=
"stables"
,
.
hashSessions
=
TSDB_DEFAULT_STABLES_HASH_SIZE
,
.
maxRowSize
=
sizeof
(
SS
uper
TableObj
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
)
+
TSDB_TABLE_FNAME_LEN
,
.
maxRowSize
=
sizeof
(
SSTableObj
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
)
+
TSDB_TABLE_FNAME_LEN
,
.
refCountPos
=
(
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
,
.
keyType
=
SDB_KEY_VAR_STRING
,
.
insertFp
=
mnodeSuperTableActionInsert
,
...
...
@@ -615,7 +615,7 @@ static void *mnodeGetSuperTable(char *tableId) {
}
static
void
*
mnodeGetSuperTableByUid
(
uint64_t
uid
)
{
SS
uper
TableObj
*
pStable
=
NULL
;
SSTableObj
*
pStable
=
NULL
;
void
*
pIter
=
NULL
;
while
(
1
)
{
...
...
@@ -647,11 +647,11 @@ void *mnodeGetTable(char *tableId) {
return
NULL
;
}
void
*
mnodeGetNextChildTable
(
void
*
pIter
,
SC
hild
TableObj
**
pTable
)
{
void
*
mnodeGetNextChildTable
(
void
*
pIter
,
SCTableObj
**
pTable
)
{
return
sdbFetchRow
(
tsChildTableSdb
,
pIter
,
(
void
**
)
pTable
);
}
void
*
mnodeGetNextSuperTable
(
void
*
pIter
,
SS
uper
TableObj
**
pTable
)
{
void
*
mnodeGetNextSuperTable
(
void
*
pIter
,
SSTableObj
**
pTable
)
{
return
sdbFetchRow
(
tsSuperTableSdb
,
pIter
,
(
void
**
)
pTable
);
}
...
...
@@ -765,12 +765,12 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) {
}
if
(
pMsg
->
pTable
->
type
==
TSDB_SUPER_TABLE
)
{
SS
uperTableObj
*
pSTable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pSTable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
mInfo
(
"app:%p:%p, table:%s, start to drop stable, uid:%"
PRIu64
", numOfChildTables:%d, sizeOfVgList:%d"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pDrop
->
tableId
,
pSTable
->
uid
,
pSTable
->
numOfTables
,
(
int32_t
)
taosHashGetSize
(
pSTable
->
vgHash
));
return
mnodeProcessDropSuperTableMsg
(
pMsg
);
}
else
{
SC
hildTableObj
*
pCTable
=
(
SChild
TableObj
*
)
pMsg
->
pTable
;
SC
TableObj
*
pCTable
=
(
SC
TableObj
*
)
pMsg
->
pTable
;
mInfo
(
"app:%p:%p, table:%s, start to drop ctable, vgId:%d tid:%d uid:%"
PRIu64
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pDrop
->
tableId
,
pCTable
->
vgId
,
pCTable
->
tid
,
pCTable
->
uid
);
return
mnodeProcessDropChildTableMsg
(
pMsg
);
...
...
@@ -816,7 +816,7 @@ static int32_t mnodeProcessTableMetaMsg(SMnodeMsg *pMsg) {
}
static
int32_t
mnodeCreateSuperTableCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
SS
uperTableObj
*
pTable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pTable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
assert
(
pTable
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
...
...
@@ -835,7 +835,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
if
(
pMsg
==
NULL
)
return
TSDB_CODE_MND_APP_ERROR
;
SCMCreateTableMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
SS
uperTableObj
*
pStable
=
calloc
(
1
,
sizeof
(
SSuper
TableObj
));
SS
TableObj
*
pStable
=
calloc
(
1
,
sizeof
(
SS
TableObj
));
if
(
pStable
==
NULL
)
{
mError
(
"app:%p:%p, table:%s, failed to create, no enough memory"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pCreate
->
tableId
);
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
...
...
@@ -878,7 +878,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsSuperTableSdb
,
.
pObj
=
pStable
,
.
rowSize
=
sizeof
(
SS
uper
TableObj
)
+
schemaSize
,
.
rowSize
=
sizeof
(
SSTableObj
)
+
schemaSize
,
.
pMsg
=
pMsg
,
.
writeCb
=
mnodeCreateSuperTableCb
};
...
...
@@ -894,7 +894,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) {
}
static
int32_t
mnodeDropSuperTableCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
SS
uperTableObj
*
pTable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pTable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"app:%p:%p, stable:%s, failed to drop, sdb error"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
);
}
else
{
...
...
@@ -907,7 +907,7 @@ static int32_t mnodeDropSuperTableCb(SMnodeMsg *pMsg, int32_t code) {
static
int32_t
mnodeProcessDropSuperTableMsg
(
SMnodeMsg
*
pMsg
)
{
if
(
pMsg
==
NULL
)
return
TSDB_CODE_MND_APP_ERROR
;
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
if
(
pStable
->
vgHash
!=
NULL
/*pStable->numOfTables != 0*/
)
{
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
pStable
->
vgHash
);
while
(
taosHashIterNext
(
pIter
))
{
...
...
@@ -950,7 +950,7 @@ static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg) {
return
code
;
}
static
int32_t
mnodeFindSuperTableTagIndex
(
SS
uper
TableObj
*
pStable
,
const
char
*
tagName
)
{
static
int32_t
mnodeFindSuperTableTagIndex
(
SSTableObj
*
pStable
,
const
char
*
tagName
)
{
SSchema
*
schema
=
(
SSchema
*
)
pStable
->
schema
;
for
(
int32_t
tag
=
0
;
tag
<
pStable
->
numOfTags
;
tag
++
)
{
if
(
strcasecmp
(
schema
[
pStable
->
numOfColumns
+
tag
].
name
,
tagName
)
==
0
)
{
...
...
@@ -962,7 +962,7 @@ static int32_t mnodeFindSuperTableTagIndex(SSuperTableObj *pStable, const char *
}
static
int32_t
mnodeAddSuperTableTagCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
mLInfo
(
"app:%p:%p, stable %s, add tag result:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
tstrerror
(
code
));
...
...
@@ -970,7 +970,7 @@ static int32_t mnodeAddSuperTableTagCb(SMnodeMsg *pMsg, int32_t code) {
}
static
int32_t
mnodeAddSuperTableTag
(
SMnodeMsg
*
pMsg
,
SSchema
schema
[],
int32_t
ntags
)
{
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
if
(
pStable
->
numOfTags
+
ntags
>
TSDB_MAX_TAGS
)
{
mError
(
"app:%p:%p, stable:%s, add tag, too many tags"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
);
return
TSDB_CODE_MND_TOO_MANY_TAGS
;
...
...
@@ -1018,14 +1018,14 @@ static int32_t mnodeAddSuperTableTag(SMnodeMsg *pMsg, SSchema schema[], int32_t
}
static
int32_t
mnodeDropSuperTableTagCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
mLInfo
(
"app:%p:%p, stable %s, drop tag result:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
tstrerror
(
code
));
return
code
;
}
static
int32_t
mnodeDropSuperTableTag
(
SMnodeMsg
*
pMsg
,
char
*
tagName
)
{
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
int32_t
col
=
mnodeFindSuperTableTagIndex
(
pStable
,
tagName
);
if
(
col
<
0
)
{
mError
(
"app:%p:%p, stable:%s, drop tag, tag:%s not exist"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
...
...
@@ -1052,14 +1052,14 @@ static int32_t mnodeDropSuperTableTag(SMnodeMsg *pMsg, char *tagName) {
}
static
int32_t
mnodeModifySuperTableTagNameCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
mLInfo
(
"app:%p:%p, stable %s, modify tag result:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
tstrerror
(
code
));
return
code
;
}
static
int32_t
mnodeModifySuperTableTagName
(
SMnodeMsg
*
pMsg
,
char
*
oldTagName
,
char
*
newTagName
)
{
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
int32_t
col
=
mnodeFindSuperTableTagIndex
(
pStable
,
oldTagName
);
if
(
col
<
0
)
{
mError
(
"app:%p:%p, stable:%s, failed to modify table tag, oldName: %s, newName: %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
...
...
@@ -1095,7 +1095,7 @@ static int32_t mnodeModifySuperTableTagName(SMnodeMsg *pMsg, char *oldTagName, c
return
sdbUpdateRow
(
&
oper
);
}
static
int32_t
mnodeFindSuperTableColumnIndex
(
SS
uper
TableObj
*
pStable
,
char
*
colName
)
{
static
int32_t
mnodeFindSuperTableColumnIndex
(
SSTableObj
*
pStable
,
char
*
colName
)
{
SSchema
*
schema
=
(
SSchema
*
)
pStable
->
schema
;
for
(
int32_t
col
=
0
;
col
<
pStable
->
numOfColumns
;
col
++
)
{
if
(
strcasecmp
(
schema
[
col
].
name
,
colName
)
==
0
)
{
...
...
@@ -1107,7 +1107,7 @@ static int32_t mnodeFindSuperTableColumnIndex(SSuperTableObj *pStable, char *col
}
static
int32_t
mnodeAddSuperTableColumnCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
mLInfo
(
"app:%p:%p, stable %s, add column result:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
tstrerror
(
code
));
return
code
;
...
...
@@ -1115,7 +1115,7 @@ static int32_t mnodeAddSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) {
static
int32_t
mnodeAddSuperTableColumn
(
SMnodeMsg
*
pMsg
,
SSchema
schema
[],
int32_t
ncols
)
{
SDbObj
*
pDb
=
pMsg
->
pDb
;
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
if
(
ncols
<=
0
)
{
mError
(
"app:%p:%p, stable:%s, add column, ncols:%d <= 0"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
ncols
);
return
TSDB_CODE_MND_APP_ERROR
;
...
...
@@ -1170,7 +1170,7 @@ static int32_t mnodeAddSuperTableColumn(SMnodeMsg *pMsg, SSchema schema[], int32
}
static
int32_t
mnodeDropSuperTableColumnCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
mLInfo
(
"app:%p:%p, stable %s, delete column result:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
tstrerror
(
code
));
return
code
;
...
...
@@ -1178,7 +1178,7 @@ static int32_t mnodeDropSuperTableColumnCb(SMnodeMsg *pMsg, int32_t code) {
static
int32_t
mnodeDropSuperTableColumn
(
SMnodeMsg
*
pMsg
,
char
*
colName
)
{
SDbObj
*
pDb
=
pMsg
->
pDb
;
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
int32_t
col
=
mnodeFindSuperTableColumnIndex
(
pStable
,
colName
);
if
(
col
<=
0
)
{
mError
(
"app:%p:%p, stable:%s, drop column, column:%s not exist"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
...
...
@@ -1215,14 +1215,14 @@ static int32_t mnodeDropSuperTableColumn(SMnodeMsg *pMsg, char *colName) {
}
static
int32_t
mnodeChangeSuperTableColumnCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
mLInfo
(
"app:%p:%p, stable %s, change column result:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pStable
->
info
.
tableId
,
tstrerror
(
code
));
return
code
;
}
static
int32_t
mnodeChangeSuperTableColumn
(
SMnodeMsg
*
pMsg
,
char
*
oldName
,
char
*
newName
)
{
SS
uperTableObj
*
pStable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pStable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
int32_t
col
=
mnodeFindSuperTableColumnIndex
(
pStable
,
oldName
);
if
(
col
<
0
)
{
mError
(
"app:%p:%p, stable:%s, change column, oldName: %s, newName: %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
...
...
@@ -1321,7 +1321,7 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows,
int32_t
numOfRows
=
0
;
char
*
pWrite
;
int32_t
cols
=
0
;
SS
uper
TableObj
*
pTable
=
NULL
;
SSTableObj
*
pTable
=
NULL
;
char
prefix
[
64
]
=
{
0
};
int32_t
prefixLen
;
...
...
@@ -1399,7 +1399,7 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows,
void
mnodeDropAllSuperTables
(
SDbObj
*
pDropDb
)
{
void
*
pIter
=
NULL
;
int32_t
numOfTables
=
0
;
SS
uper
TableObj
*
pTable
=
NULL
;
SSTableObj
*
pTable
=
NULL
;
char
prefix
[
64
]
=
{
0
};
tstrncpy
(
prefix
,
pDropDb
->
name
,
64
);
...
...
@@ -1430,7 +1430,7 @@ void mnodeDropAllSuperTables(SDbObj *pDropDb) {
mInfo
(
"db:%s, all super tables:%d is dropped from sdb"
,
pDropDb
->
name
,
numOfTables
);
}
static
int32_t
mnodeSetSchemaFromSuperTable
(
SSchema
*
pSchema
,
SS
uper
TableObj
*
pTable
)
{
static
int32_t
mnodeSetSchemaFromSuperTable
(
SSchema
*
pSchema
,
SSTableObj
*
pTable
)
{
int32_t
numOfCols
=
pTable
->
numOfColumns
+
pTable
->
numOfTags
;
assert
(
numOfCols
<=
TSDB_MAX_COLUMNS
);
...
...
@@ -1446,7 +1446,7 @@ static int32_t mnodeSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pT
}
static
int32_t
mnodeGetSuperTableMeta
(
SMnodeMsg
*
pMsg
)
{
SS
uperTableObj
*
pTable
=
(
SSuper
TableObj
*
)
pMsg
->
pTable
;
SS
TableObj
*
pTable
=
(
SS
TableObj
*
)
pMsg
->
pTable
;
STableMetaMsg
*
pMeta
=
rpcMallocCont
(
sizeof
(
STableMetaMsg
)
+
sizeof
(
SSchema
)
*
(
TSDB_MAX_TAGS
+
TSDB_MAX_COLUMNS
+
16
));
if
(
pMeta
==
NULL
)
{
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
...
...
@@ -1479,7 +1479,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
int32_t
contLen
=
sizeof
(
SSTableVgroupRspMsg
)
+
32
*
sizeof
(
SVgroupMsg
)
+
sizeof
(
SVgroupsMsg
);
for
(
int32_t
i
=
0
;
i
<
numOfTable
;
++
i
)
{
char
*
stableName
=
(
char
*
)
pInfo
+
sizeof
(
SSTableVgroupMsg
)
+
(
TSDB_TABLE_FNAME_LEN
)
*
i
;
SS
uper
TableObj
*
pTable
=
mnodeGetSuperTable
(
stableName
);
SSTableObj
*
pTable
=
mnodeGetSuperTable
(
stableName
);
if
(
pTable
!=
NULL
&&
pTable
->
vgHash
!=
NULL
)
{
contLen
+=
(
taosHashGetSize
(
pTable
->
vgHash
)
*
sizeof
(
SVgroupMsg
)
+
sizeof
(
SVgroupsMsg
));
}
...
...
@@ -1497,7 +1497,7 @@ static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *pMsg) {
for
(
int32_t
i
=
0
;
i
<
numOfTable
;
++
i
)
{
char
*
stableName
=
(
char
*
)
pInfo
+
sizeof
(
SSTableVgroupMsg
)
+
(
TSDB_TABLE_FNAME_LEN
)
*
i
;
SS
uper
TableObj
*
pTable
=
mnodeGetSuperTable
(
stableName
);
SSTableObj
*
pTable
=
mnodeGetSuperTable
(
stableName
);
if
(
pTable
==
NULL
)
{
mError
(
"app:%p:%p, stable:%s, not exist while get stable vgroup info"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
stableName
);
mnodeDecTableRef
(
pTable
);
...
...
@@ -1569,7 +1569,7 @@ static void mnodeProcessDropSuperTableRsp(SRpcMsg *rpcMsg) {
mInfo
(
"drop stable rsp received, result:%s"
,
tstrerror
(
rpcMsg
->
code
));
}
static
void
*
mnodeBuildCreateChildTableMsg
(
SCMCreateTableMsg
*
pMsg
,
SC
hild
TableObj
*
pTable
)
{
static
void
*
mnodeBuildCreateChildTableMsg
(
SCMCreateTableMsg
*
pMsg
,
SCTableObj
*
pTable
)
{
STagData
*
pTagData
=
NULL
;
int32_t
tagDataLen
=
0
;
int32_t
totalCols
=
0
;
...
...
@@ -1643,7 +1643,7 @@ static void *mnodeBuildCreateChildTableMsg(SCMCreateTableMsg *pMsg, SChildTableO
}
static
int32_t
mnodeDoCreateChildTableFp
(
SMnodeMsg
*
pMsg
)
{
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
pMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
pMsg
->
pTable
;
assert
(
pTable
);
mDebug
(
"app:%p:%p, table:%s, created in mnode, vgId:%d sid:%d, uid:%"
PRIu64
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
...
...
@@ -1669,7 +1669,7 @@ static int32_t mnodeDoCreateChildTableFp(SMnodeMsg *pMsg) {
}
static
int32_t
mnodeDoCreateChildTableCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
pMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
pMsg
->
pTable
;
SCMCreateTableMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
assert
(
pTable
);
...
...
@@ -1679,12 +1679,12 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
pTable
->
info
.
tableId
,
pMsg
->
rpcMsg
.
handle
);
pMsg
->
retry
=
0
;
dnodeReprocessM
node
WriteMsg
(
pMsg
);
dnodeReprocessMWriteMsg
(
pMsg
);
}
else
{
mDebug
(
"app:%p:%p, table:%s, created in dnode, thandle:%p"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
pMsg
->
rpcMsg
.
handle
);
dnodeSendRpcM
node
WriteRsp
(
pMsg
,
TSDB_CODE_SUCCESS
);
dnodeSendRpcMWriteRsp
(
pMsg
,
TSDB_CODE_SUCCESS
);
}
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
}
else
{
...
...
@@ -1699,7 +1699,7 @@ static int32_t mnodeDoCreateChildTableCb(SMnodeMsg *pMsg, int32_t code) {
static
int32_t
mnodeDoCreateChildTable
(
SMnodeMsg
*
pMsg
,
int32_t
tid
)
{
SVgObj
*
pVgroup
=
pMsg
->
pVgroup
;
SCMCreateTableMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
SC
hildTableObj
*
pTable
=
calloc
(
1
,
sizeof
(
SChild
TableObj
));
SC
TableObj
*
pTable
=
calloc
(
1
,
sizeof
(
SC
TableObj
));
if
(
pTable
==
NULL
)
{
mError
(
"app:%p:%p, table:%s, failed to alloc memory"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pCreate
->
tableId
);
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
...
...
@@ -1842,7 +1842,7 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) {
}
static
int32_t
mnodeSendDropChildTableMsg
(
SMnodeMsg
*
pMsg
,
bool
needReturn
)
{
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
pMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
pMsg
->
pTable
;
mLInfo
(
"app:%p:%p, ctable:%s, is dropped from sdb"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
);
SMDDropTableMsg
*
pDrop
=
rpcMallocCont
(
sizeof
(
SMDDropTableMsg
));
...
...
@@ -1880,7 +1880,7 @@ static int32_t mnodeSendDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) {
static
int32_t
mnodeDropChildTableCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
pMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
pMsg
->
pTable
;
mError
(
"app:%p:%p, ctable:%s, failed to drop, sdb error"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
);
return
code
;
}
...
...
@@ -1889,7 +1889,7 @@ static int32_t mnodeDropChildTableCb(SMnodeMsg *pMsg, int32_t code) {
}
static
int32_t
mnodeProcessDropChildTableMsg
(
SMnodeMsg
*
pMsg
)
{
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
pMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
pMsg
->
pTable
;
if
(
pMsg
->
pVgroup
==
NULL
)
pMsg
->
pVgroup
=
mnodeGetVgroup
(
pTable
->
vgId
);
if
(
pMsg
->
pVgroup
==
NULL
)
{
mError
(
"app:%p:%p, table:%s, failed to drop ctable, vgroup not exist"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
...
...
@@ -1914,7 +1914,7 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) {
return
code
;
}
static
int32_t
mnodeFindNormalTableColumnIndex
(
SC
hild
TableObj
*
pTable
,
char
*
colName
)
{
static
int32_t
mnodeFindNormalTableColumnIndex
(
SCTableObj
*
pTable
,
char
*
colName
)
{
SSchema
*
schema
=
(
SSchema
*
)
pTable
->
schema
;
for
(
int32_t
col
=
0
;
col
<
pTable
->
numOfColumns
;
col
++
)
{
if
(
strcasecmp
(
schema
[
col
].
name
,
colName
)
==
0
)
{
...
...
@@ -1926,7 +1926,7 @@ static int32_t mnodeFindNormalTableColumnIndex(SChildTableObj *pTable, char *col
}
static
int32_t
mnodeAlterNormalTableColumnCb
(
SMnodeMsg
*
pMsg
,
int32_t
code
)
{
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
pMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
pMsg
->
pTable
;
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"app:%p:%p, ctable %s, failed to alter column, reason:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
tstrerror
(
code
));
...
...
@@ -1965,7 +1965,7 @@ static int32_t mnodeAlterNormalTableColumnCb(SMnodeMsg *pMsg, int32_t code) {
}
static
int32_t
mnodeAddNormalTableColumn
(
SMnodeMsg
*
pMsg
,
SSchema
schema
[],
int32_t
ncols
)
{
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
pMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
pMsg
->
pTable
;
SDbObj
*
pDb
=
pMsg
->
pDb
;
if
(
ncols
<=
0
)
{
mError
(
"app:%p:%p, ctable:%s, add column, ncols:%d <= 0"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
ncols
);
...
...
@@ -2014,7 +2014,7 @@ static int32_t mnodeAddNormalTableColumn(SMnodeMsg *pMsg, SSchema schema[], int3
static
int32_t
mnodeDropNormalTableColumn
(
SMnodeMsg
*
pMsg
,
char
*
colName
)
{
SDbObj
*
pDb
=
pMsg
->
pDb
;
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
pMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
pMsg
->
pTable
;
int32_t
col
=
mnodeFindNormalTableColumnIndex
(
pTable
,
colName
);
if
(
col
<=
0
)
{
mError
(
"app:%p:%p, ctable:%s, drop column, column:%s not exist"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pTable
->
info
.
tableId
,
...
...
@@ -2046,7 +2046,7 @@ static int32_t mnodeDropNormalTableColumn(SMnodeMsg *pMsg, char *colName) {
}
static
int32_t
mnodeChangeNormalTableColumn
(
SMnodeMsg
*
pMsg
,
char
*
oldName
,
char
*
newName
)
{
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
pMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
pMsg
->
pTable
;
int32_t
col
=
mnodeFindNormalTableColumnIndex
(
pTable
,
oldName
);
if
(
col
<
0
)
{
mError
(
"app:%p:%p, ctable:%s, change column, oldName: %s, newName: %s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
...
...
@@ -2082,7 +2082,7 @@ static int32_t mnodeChangeNormalTableColumn(SMnodeMsg *pMsg, char *oldName, char
return
sdbUpdateRow
(
&
oper
);
}
static
int32_t
mnodeSetSchemaFromNormalTable
(
SSchema
*
pSchema
,
SC
hild
TableObj
*
pTable
)
{
static
int32_t
mnodeSetSchemaFromNormalTable
(
SSchema
*
pSchema
,
SCTableObj
*
pTable
)
{
int32_t
numOfCols
=
pTable
->
numOfColumns
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
strcpy
(
pSchema
->
name
,
pTable
->
schema
[
i
].
name
);
...
...
@@ -2097,7 +2097,7 @@ static int32_t mnodeSetSchemaFromNormalTable(SSchema *pSchema, SChildTableObj *p
static
int32_t
mnodeDoGetChildTableMeta
(
SMnodeMsg
*
pMsg
,
STableMetaMsg
*
pMeta
)
{
SDbObj
*
pDb
=
pMsg
->
pDb
;
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
pMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
pMsg
->
pTable
;
pMeta
->
uid
=
htobe64
(
pTable
->
uid
);
pMeta
->
tid
=
htonl
(
pTable
->
tid
);
...
...
@@ -2156,7 +2156,7 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
}
int32_t
contLen
=
sizeof
(
SCMCreateTableMsg
)
+
offsetof
(
STagData
,
data
)
+
tagLen
;
SCMCreateTableMsg
*
pCreateMsg
=
rpcMallocCont
(
contLen
);
SCMCreateTableMsg
*
pCreateMsg
=
calloc
(
1
,
contLen
);
if
(
pCreateMsg
==
NULL
)
{
mError
(
"app:%p:%p, table:%s, failed to create table while get meta info, no enough memory"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pInfo
->
tableId
);
...
...
@@ -2174,11 +2174,13 @@ static int32_t mnodeAutoCreateChildTable(SMnodeMsg *pMsg) {
mDebug
(
"app:%p:%p, table:%s, start to create on demand, tagLen:%d stable:%s"
,
pMsg
->
rpcMsg
.
ahandle
,
pMsg
,
pInfo
->
tableId
,
tagLen
,
pTags
->
name
);
rpcFreeCont
(
pMsg
->
rpcMsg
.
pCont
);
if
(
pMsg
->
rpcMsg
.
pCont
!=
pMsg
->
pCont
)
{
tfree
(
pMsg
->
rpcMsg
.
pCont
);
}
pMsg
->
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_CM_CREATE_TABLE
;
pMsg
->
rpcMsg
.
pCont
=
pCreateMsg
;
pMsg
->
rpcMsg
.
contLen
=
contLen
;
return
TSDB_CODE_MND_ACTION_NEED_REPROCESSED
;
}
...
...
@@ -2203,7 +2205,7 @@ static int32_t mnodeGetChildTableMeta(SMnodeMsg *pMsg) {
void
mnodeDropAllChildTablesInVgroups
(
SVgObj
*
pVgroup
)
{
void
*
pIter
=
NULL
;
int32_t
numOfTables
=
0
;
SC
hild
TableObj
*
pTable
=
NULL
;
SCTableObj
*
pTable
=
NULL
;
mInfo
(
"vgId:%d, all child tables will be dropped from sdb"
,
pVgroup
->
vgId
);
...
...
@@ -2231,7 +2233,7 @@ void mnodeDropAllChildTablesInVgroups(SVgObj *pVgroup) {
void
mnodeDropAllChildTables
(
SDbObj
*
pDropDb
)
{
void
*
pIter
=
NULL
;
int32_t
numOfTables
=
0
;
SC
hild
TableObj
*
pTable
=
NULL
;
SCTableObj
*
pTable
=
NULL
;
char
prefix
[
64
]
=
{
0
};
tstrncpy
(
prefix
,
pDropDb
->
name
,
64
);
...
...
@@ -2261,10 +2263,10 @@ void mnodeDropAllChildTables(SDbObj *pDropDb) {
mInfo
(
"db:%s, all child tables:%d is dropped from sdb"
,
pDropDb
->
name
,
numOfTables
);
}
static
void
mnodeDropAllChildTablesInStable
(
SS
uper
TableObj
*
pStable
)
{
static
void
mnodeDropAllChildTablesInStable
(
SSTableObj
*
pStable
)
{
void
*
pIter
=
NULL
;
int32_t
numOfTables
=
0
;
SC
hild
TableObj
*
pTable
=
NULL
;
SCTableObj
*
pTable
=
NULL
;
mInfo
(
"stable:%s uid:%"
PRIu64
", all child tables:%d will be dropped from sdb"
,
pStable
->
info
.
tableId
,
pStable
->
uid
,
pStable
->
numOfTables
);
...
...
@@ -2292,11 +2294,11 @@ static void mnodeDropAllChildTablesInStable(SSuperTableObj *pStable) {
}
#if 0
static SC
hild
TableObj* mnodeGetTableByPos(int32_t vnode, int32_t tid) {
static SCTableObj* mnodeGetTableByPos(int32_t vnode, int32_t tid) {
SVgObj *pVgroup = mnodeGetVgroup(vnode);
if (pVgroup == NULL) return NULL;
SC
hild
TableObj *pTable = pVgroup->tableList[tid - 1];
SCTableObj *pTable = pVgroup->tableList[tid - 1];
mnodeIncTableRef((STableObj *)pTable);
mnodeDecVgroupRef(pVgroup);
...
...
@@ -2314,7 +2316,7 @@ static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) {
mDebug("app:%p:%p, dnode:%d, vgId:%d sid:%d, receive table config msg", pMsg->rpcMsg.ahandle, pMsg, pCfg->dnodeId,
pCfg->vgId, pCfg->sid);
SC
hild
TableObj *pTable = mnodeGetTableByPos(pCfg->vgId, pCfg->sid);
SCTableObj *pTable = mnodeGetTableByPos(pCfg->vgId, pCfg->sid);
if (pTable == NULL) {
mError("app:%p:%p, dnode:%d, vgId:%d sid:%d, table not found", pMsg->rpcMsg.ahandle, pMsg, pCfg->dnodeId,
pCfg->vgId, pCfg->sid);
...
...
@@ -2322,7 +2324,7 @@ static int32_t mnodeProcessTableCfgMsg(SMnodeMsg *pMsg) {
}
SMDCreateTableMsg *pCreate = NULL;
pCreate = mnodeBuildCreateChildTableMsg(NULL, (SC
hild
TableObj *)pTable);
pCreate = mnodeBuildCreateChildTableMsg(NULL, (SCTableObj *)pTable);
mnodeDecTableRef(pTable);
if (pCreate == NULL) return terrno;
...
...
@@ -2340,7 +2342,7 @@ static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) {
SMnodeMsg
*
mnodeMsg
=
rpcMsg
->
ahandle
;
mnodeMsg
->
received
++
;
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
mnodeMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
mnodeMsg
->
pTable
;
assert
(
pTable
);
mInfo
(
"app:%p:%p, table:%s, drop table rsp received, vgId:%d sid:%d uid:%"
PRIu64
", thandle:%p result:%s"
,
...
...
@@ -2351,14 +2353,14 @@ static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) {
mError
(
"app:%p:%p, table:%s, failed to drop in dnode, vgId:%d sid:%d uid:%"
PRIu64
", reason:%s"
,
mnodeMsg
->
rpcMsg
.
ahandle
,
mnodeMsg
,
pTable
->
info
.
tableId
,
pTable
->
vgId
,
pTable
->
tid
,
pTable
->
uid
,
tstrerror
(
rpcMsg
->
code
));
dnodeSendRpcM
node
WriteRsp
(
mnodeMsg
,
rpcMsg
->
code
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
rpcMsg
->
code
);
return
;
}
if
(
mnodeMsg
->
pVgroup
==
NULL
)
mnodeMsg
->
pVgroup
=
mnodeGetVgroup
(
pTable
->
vgId
);
if
(
mnodeMsg
->
pVgroup
==
NULL
)
{
mError
(
"app:%p:%p, table:%s, failed to get vgroup"
,
mnodeMsg
->
rpcMsg
.
ahandle
,
mnodeMsg
,
pTable
->
info
.
tableId
);
dnodeSendRpcM
node
WriteRsp
(
mnodeMsg
,
TSDB_CODE_MND_VGROUP_NOT_EXIST
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
TSDB_CODE_MND_VGROUP_NOT_EXIST
);
return
;
}
...
...
@@ -2368,7 +2370,7 @@ static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) {
mnodeDropVgroup
(
mnodeMsg
->
pVgroup
,
NULL
);
}
dnodeSendRpcM
node
WriteRsp
(
mnodeMsg
,
TSDB_CODE_SUCCESS
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
TSDB_CODE_SUCCESS
);
}
/*
...
...
@@ -2381,7 +2383,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
SMnodeMsg
*
mnodeMsg
=
rpcMsg
->
ahandle
;
mnodeMsg
->
received
++
;
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
mnodeMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
mnodeMsg
->
pTable
;
assert
(
pTable
);
// If the table is deleted by another thread during creation, stop creating and send drop msg to vnode
...
...
@@ -2399,7 +2401,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
mnodeSendDropChildTableMsg
(
mnodeMsg
,
false
);
rpcMsg
->
code
=
TSDB_CODE_SUCCESS
;
dnodeSendRpcM
node
WriteRsp
(
mnodeMsg
,
rpcMsg
->
code
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
rpcMsg
->
code
);
return
;
}
...
...
@@ -2416,7 +2418,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mnodeMsg
->
pTable
=
NULL
;
mnodeDestroyChildTable
(
pTable
);
dnodeSendRpcM
node
WriteRsp
(
mnodeMsg
,
code
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
code
);
}
}
else
{
if
(
mnodeMsg
->
retry
++
<
10
)
{
...
...
@@ -2425,7 +2427,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
mnodeMsg
->
rpcMsg
.
ahandle
,
mnodeMsg
,
pTable
->
info
.
tableId
,
mnodeMsg
->
retry
,
pTable
->
vgId
,
pTable
->
tid
,
pTable
->
uid
,
tstrerror
(
rpcMsg
->
code
),
mnodeMsg
->
rpcMsg
.
handle
);
dnodeDelayReprocessM
node
WriteMsg
(
mnodeMsg
);
dnodeDelayReprocessMWriteMsg
(
mnodeMsg
);
}
else
{
mError
(
"app:%p:%p, table:%s, failed to create in dnode, vgId:%d sid:%d uid:%"
PRIu64
", result:%s thandle:%p"
,
mnodeMsg
->
rpcMsg
.
ahandle
,
mnodeMsg
,
pTable
->
info
.
tableId
,
pTable
->
vgId
,
pTable
->
tid
,
pTable
->
uid
,
...
...
@@ -2434,7 +2436,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) {
SSdbOper
oper
=
{.
type
=
SDB_OPER_GLOBAL
,
.
table
=
tsChildTableSdb
,
.
pObj
=
pTable
};
sdbDeleteRow
(
&
oper
);
dnodeSendRpcM
node
WriteRsp
(
mnodeMsg
,
rpcMsg
->
code
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
rpcMsg
->
code
);
}
}
}
...
...
@@ -2445,25 +2447,25 @@ static void mnodeProcessAlterTableRsp(SRpcMsg *rpcMsg) {
SMnodeMsg
*
mnodeMsg
=
rpcMsg
->
ahandle
;
mnodeMsg
->
received
++
;
SC
hildTableObj
*
pTable
=
(
SChild
TableObj
*
)
mnodeMsg
->
pTable
;
SC
TableObj
*
pTable
=
(
SC
TableObj
*
)
mnodeMsg
->
pTable
;
assert
(
pTable
);
if
(
rpcMsg
->
code
==
TSDB_CODE_SUCCESS
||
rpcMsg
->
code
==
TSDB_CODE_TDB_TABLE_ALREADY_EXIST
)
{
mDebug
(
"app:%p:%p, ctable:%s, altered in dnode, thandle:%p result:%s"
,
mnodeMsg
->
rpcMsg
.
ahandle
,
mnodeMsg
,
pTable
->
info
.
tableId
,
mnodeMsg
->
rpcMsg
.
handle
,
tstrerror
(
rpcMsg
->
code
));
dnodeSendRpcM
node
WriteRsp
(
mnodeMsg
,
TSDB_CODE_SUCCESS
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
TSDB_CODE_SUCCESS
);
}
else
{
if
(
mnodeMsg
->
retry
++
<
3
)
{
mDebug
(
"app:%p:%p, table:%s, alter table rsp received, need retry, times:%d result:%s thandle:%p"
,
mnodeMsg
->
rpcMsg
.
ahandle
,
mnodeMsg
,
pTable
->
info
.
tableId
,
mnodeMsg
->
retry
,
tstrerror
(
rpcMsg
->
code
),
mnodeMsg
->
rpcMsg
.
handle
);
dnodeDelayReprocessM
node
WriteMsg
(
mnodeMsg
);
dnodeDelayReprocessMWriteMsg
(
mnodeMsg
);
}
else
{
mError
(
"app:%p:%p, table:%s, failed to alter in dnode, result:%s thandle:%p"
,
mnodeMsg
->
rpcMsg
.
ahandle
,
mnodeMsg
,
pTable
->
info
.
tableId
,
tstrerror
(
rpcMsg
->
code
),
mnodeMsg
->
rpcMsg
.
handle
);
dnodeSendRpcM
node
WriteRsp
(
mnodeMsg
,
rpcMsg
->
code
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
rpcMsg
->
code
);
}
}
}
...
...
@@ -2483,7 +2485,7 @@ static int32_t mnodeProcessMultiTableMetaMsg(SMnodeMsg *pMsg) {
for
(
int32_t
t
=
0
;
t
<
pInfo
->
numOfTables
;
++
t
)
{
char
*
tableId
=
(
char
*
)(
pInfo
->
tableIds
+
t
*
TSDB_TABLE_FNAME_LEN
);
SC
hild
TableObj
*
pTable
=
mnodeGetChildTable
(
tableId
);
SCTableObj
*
pTable
=
mnodeGetChildTable
(
tableId
);
if
(
pTable
==
NULL
)
continue
;
if
(
pMsg
->
pDb
==
NULL
)
pMsg
->
pDb
=
mnodeGetDbByTableId
(
tableId
);
...
...
@@ -2607,7 +2609,7 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows
int32_t
cols
=
0
;
int32_t
numOfRows
=
0
;
SC
hild
TableObj
*
pTable
=
NULL
;
SCTableObj
*
pTable
=
NULL
;
SPatternCompareInfo
info
=
PATTERN_COMPARE_INFO_INITIALIZER
;
char
prefix
[
64
]
=
{
0
};
...
...
@@ -2843,7 +2845,7 @@ static int32_t mnodeRetrieveStreamTables(SShowObj *pShow, char *data, int32_t ro
}
int32_t
numOfRows
=
0
;
SC
hild
TableObj
*
pTable
=
NULL
;
SCTableObj
*
pTable
=
NULL
;
SPatternCompareInfo
info
=
PATTERN_COMPARE_INFO_INITIALIZER
;
char
prefix
[
64
]
=
{
0
};
...
...
src/mnode/src/mnodeVgroup.c
浏览文件 @
d583a4ca
...
...
@@ -529,7 +529,7 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) {
SSdbOper
desc
=
{.
type
=
SDB_OPER_GLOBAL
,
.
pObj
=
pVgroup
,
.
table
=
tsVgroupSdb
};
(
void
)
sdbUpdateRow
(
&
desc
);
dnodeReprocessM
node
WriteMsg
(
pMsg
);
dnodeReprocessMWriteMsg
(
pMsg
);
return
TSDB_CODE_MND_ACTION_IN_PROGRESS
;
// if (pVgroup->status == TAOS_VG_STATUS_CREATING || pVgroup->status == TAOS_VG_STATUS_READY) {
// mInfo("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId,
...
...
@@ -537,7 +537,7 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) {
// pVgroup->status = TAOS_VG_STATUS_READY;
// SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb};
// (void)sdbUpdateRow(&desc);
// dnodeReprocessM
node
WriteMsg(pMsg);
// dnodeReprocessMWriteMsg(pMsg);
// return TSDB_CODE_MND_ACTION_IN_PROGRESS;
// } else {
// mError("app:%p:%p, vgId:%d, is created in sdb, db:%s replica:%d, but vgroup is dropping", pMsg->rpcMsg.ahandle,
...
...
@@ -694,7 +694,7 @@ static bool mnodeFilterVgroups(SVgObj *pVgroup, STableObj *pTable) {
return
true
;
}
SC
hildTableObj
*
pCTable
=
(
SChild
TableObj
*
)
pTable
;
SC
TableObj
*
pCTable
=
(
SC
TableObj
*
)
pTable
;
if
(
pVgroup
->
vgId
==
pCTable
->
vgId
)
{
return
true
;
}
else
{
...
...
@@ -791,7 +791,7 @@ static int32_t mnodeRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, v
return
numOfRows
;
}
void
mnodeAddTableIntoVgroup
(
SVgObj
*
pVgroup
,
SC
hild
TableObj
*
pTable
)
{
void
mnodeAddTableIntoVgroup
(
SVgObj
*
pVgroup
,
SCTableObj
*
pTable
)
{
int32_t
idPoolSize
=
taosIdPoolMaxSize
(
pVgroup
->
idPool
);
if
(
pTable
->
tid
>
idPoolSize
)
{
mnodeAllocVgroupIdPool
(
pVgroup
);
...
...
@@ -807,7 +807,7 @@ void mnodeAddTableIntoVgroup(SVgObj *pVgroup, SChildTableObj *pTable) {
}
}
void
mnodeRemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
SC
hild
TableObj
*
pTable
)
{
void
mnodeRemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
SCTableObj
*
pTable
)
{
if
(
pTable
->
tid
>=
1
)
{
taosFreeId
(
pVgroup
->
idPool
,
pTable
->
tid
);
pVgroup
->
numOfTables
--
;
...
...
@@ -970,7 +970,7 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mnodeMsg
->
pVgroup
=
NULL
;
mnodeDestroyVgroup
(
pVgroup
);
dnodeSendRpcM
node
WriteRsp
(
mnodeMsg
,
code
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
code
);
}
}
else
{
SSdbOper
oper
=
{
...
...
@@ -979,7 +979,7 @@ static void mnodeProcessCreateVnodeRsp(SRpcMsg *rpcMsg) {
.
pObj
=
pVgroup
};
sdbDeleteRow
(
&
oper
);
dnodeSendRpcM
node
WriteRsp
(
mnodeMsg
,
mnodeMsg
->
code
);
dnodeSendRpcMWriteRsp
(
mnodeMsg
,
mnodeMsg
->
code
);
}
}
...
...
@@ -1041,7 +1041,7 @@ static void mnodeProcessDropVnodeRsp(SRpcMsg *rpcMsg) {
code
=
TSDB_CODE_MND_SDB_ERROR
;
}
dnodeReprocessM
node
WriteMsg
(
mnodeMsg
);
dnodeReprocessMWriteMsg
(
mnodeMsg
);
}
static
int32_t
mnodeProcessVnodeCfgMsg
(
SMnodeMsg
*
pMsg
)
{
...
...
src/plugins/http/src/httpQueue.c
浏览文件 @
d583a4ca
...
...
@@ -49,7 +49,7 @@ static taos_queue tsHttpQueue;
void
httpDispatchToResultQueue
(
void
*
param
,
TAOS_RES
*
result
,
int32_t
numOfRows
,
void
(
*
fp
)(
void
*
param
,
void
*
result
,
int32_t
numOfRows
))
{
if
(
tsHttpQueue
!=
NULL
)
{
SHttpResult
*
pMsg
=
(
SHttpResult
*
)
taosAllocateQitem
(
sizeof
(
SHttpResult
));
SHttpResult
*
pMsg
=
taosAllocateQitem
(
sizeof
(
SHttpResult
));
pMsg
->
param
=
param
;
pMsg
->
result
=
result
;
pMsg
->
numOfRows
=
numOfRows
;
...
...
src/plugins/monitor/src/monitorMain.c
浏览文件 @
d583a4ca
...
...
@@ -27,12 +27,12 @@
#include "monitor.h"
#include "taoserror.h"
#define m
onitor
Fatal(...) { if (monitorDebugFlag & DEBUG_FATAL) { taosPrintLog("MON FATAL ", 255, __VA_ARGS__); }}
#define m
onitor
Error(...) { if (monitorDebugFlag & DEBUG_ERROR) { taosPrintLog("MON ERROR ", 255, __VA_ARGS__); }}
#define m
onitor
Warn(...) { if (monitorDebugFlag & DEBUG_WARN) { taosPrintLog("MON WARN ", 255, __VA_ARGS__); }}
#define m
onitor
Info(...) { if (monitorDebugFlag & DEBUG_INFO) { taosPrintLog("MON ", 255, __VA_ARGS__); }}
#define m
onitor
Debug(...) { if (monitorDebugFlag & DEBUG_DEBUG) { taosPrintLog("MON ", monitorDebugFlag, __VA_ARGS__); }}
#define m
onitor
Trace(...) { if (monitorDebugFlag & DEBUG_TRACE) { taosPrintLog("MON ", monitorDebugFlag, __VA_ARGS__); }}
#define m
n
Fatal(...) { if (monitorDebugFlag & DEBUG_FATAL) { taosPrintLog("MON FATAL ", 255, __VA_ARGS__); }}
#define m
n
Error(...) { if (monitorDebugFlag & DEBUG_ERROR) { taosPrintLog("MON ERROR ", 255, __VA_ARGS__); }}
#define m
n
Warn(...) { if (monitorDebugFlag & DEBUG_WARN) { taosPrintLog("MON WARN ", 255, __VA_ARGS__); }}
#define m
n
Info(...) { if (monitorDebugFlag & DEBUG_INFO) { taosPrintLog("MON ", 255, __VA_ARGS__); }}
#define m
n
Debug(...) { if (monitorDebugFlag & DEBUG_DEBUG) { taosPrintLog("MON ", monitorDebugFlag, __VA_ARGS__); }}
#define m
n
Trace(...) { if (monitorDebugFlag & DEBUG_TRACE) { taosPrintLog("MON ", monitorDebugFlag, __VA_ARGS__); }}
#define SQL_LENGTH 1030
#define LOG_LEN_STR 100
...
...
@@ -91,12 +91,12 @@ int32_t monitorInitSystem() {
pthread_attr_setdetachstate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
tsMonitor
.
thread
,
&
thAttr
,
monitorThreadFunc
,
NULL
))
{
m
onitor
Error
(
"failed to create thread to for monitor module, reason:%s"
,
strerror
(
errno
));
m
n
Error
(
"failed to create thread to for monitor module, reason:%s"
,
strerror
(
errno
));
return
-
1
;
}
pthread_attr_destroy
(
&
thAttr
);
m
onitor
Debug
(
"monitor thread is launched"
);
m
n
Debug
(
"monitor thread is launched"
);
monitorStartSystemFp
=
monitorStartSystem
;
monitorStopSystemFp
=
monitorStopSystem
;
...
...
@@ -107,12 +107,12 @@ int32_t monitorStartSystem() {
taos_init
();
tsMonitor
.
start
=
1
;
monitorExecuteSQLFp
=
monitorExecuteSQL
;
m
onitor
Info
(
"monitor module start"
);
m
n
Info
(
"monitor module start"
);
return
0
;
}
static
void
*
monitorThreadFunc
(
void
*
param
)
{
m
onitor
Debug
(
"starting to initialize monitor module ..."
);
m
n
Debug
(
"starting to initialize monitor module ..."
);
while
(
1
)
{
static
int32_t
accessTimes
=
0
;
...
...
@@ -121,7 +121,7 @@ static void *monitorThreadFunc(void *param) {
if
(
tsMonitor
.
quiting
)
{
tsMonitor
.
state
=
MON_STATE_NOT_INIT
;
m
onitor
Info
(
"monitor thread will quit, for taosd is quiting"
);
m
n
Info
(
"monitor thread will quit, for taosd is quiting"
);
break
;
}
else
{
taosGetDisk
();
...
...
@@ -132,7 +132,7 @@ static void *monitorThreadFunc(void *param) {
}
if
(
dnodeGetDnodeId
()
<=
0
)
{
m
onitor
Debug
(
"dnode not initialized, waiting for 3000 ms to start monitor module"
);
m
n
Debug
(
"dnode not initialized, waiting for 3000 ms to start monitor module"
);
continue
;
}
...
...
@@ -140,10 +140,10 @@ static void *monitorThreadFunc(void *param) {
tsMonitor
.
state
=
MON_STATE_NOT_INIT
;
tsMonitor
.
conn
=
taos_connect
(
NULL
,
"monitor"
,
tsInternalPass
,
""
,
0
);
if
(
tsMonitor
.
conn
==
NULL
)
{
m
onitor
Error
(
"failed to connect to database, reason:%s"
,
tstrerror
(
terrno
));
m
n
Error
(
"failed to connect to database, reason:%s"
,
tstrerror
(
terrno
));
continue
;
}
else
{
m
onitor
Debug
(
"connect to database success"
);
m
n
Debug
(
"connect to database success"
);
}
}
...
...
@@ -155,10 +155,10 @@ static void *monitorThreadFunc(void *param) {
taos_free_result
(
res
);
if
(
code
!=
0
)
{
m
onitor
Error
(
"failed to exec sql:%s, reason:%s"
,
tsMonitor
.
sql
,
tstrerror
(
code
));
m
n
Error
(
"failed to exec sql:%s, reason:%s"
,
tsMonitor
.
sql
,
tstrerror
(
code
));
break
;
}
else
{
m
onitor
Debug
(
"successfully to exec sql:%s"
,
tsMonitor
.
sql
);
m
n
Debug
(
"successfully to exec sql:%s"
,
tsMonitor
.
sql
);
}
}
...
...
@@ -174,7 +174,7 @@ static void *monitorThreadFunc(void *param) {
}
}
m
onitor
Info
(
"monitor thread is stopped"
);
m
n
Info
(
"monitor thread is stopped"
);
return
NULL
;
}
...
...
@@ -238,7 +238,7 @@ void monitorStopSystem() {
tsMonitor
.
start
=
0
;
tsMonitor
.
state
=
MON_STATE_NOT_INIT
;
monitorExecuteSQLFp
=
NULL
;
m
onitor
Info
(
"monitor module stopped"
);
m
n
Info
(
"monitor module stopped"
);
}
void
monitorCleanUpSystem
()
{
...
...
@@ -249,7 +249,7 @@ void monitorCleanUpSystem() {
taos_close
(
tsMonitor
.
conn
);
tsMonitor
.
conn
=
NULL
;
}
m
onitor
Info
(
"monitor module is cleaned up"
);
m
n
Info
(
"monitor module is cleaned up"
);
}
// unit is MB
...
...
@@ -257,13 +257,13 @@ static int32_t monitorBuildMemorySql(char *sql) {
float
sysMemoryUsedMB
=
0
;
bool
suc
=
taosGetSysMemory
(
&
sysMemoryUsedMB
);
if
(
!
suc
)
{
m
onitor
Debug
(
"failed to get sys memory info"
);
m
n
Debug
(
"failed to get sys memory info"
);
}
float
procMemoryUsedMB
=
0
;
suc
=
taosGetProcMemory
(
&
procMemoryUsedMB
);
if
(
!
suc
)
{
m
onitor
Debug
(
"failed to get proc memory info"
);
m
n
Debug
(
"failed to get proc memory info"
);
}
return
sprintf
(
sql
,
", %f, %f, %d"
,
procMemoryUsedMB
,
sysMemoryUsedMB
,
tsTotalMemoryMB
);
...
...
@@ -274,7 +274,7 @@ static int32_t monitorBuildCpuSql(char *sql) {
float
sysCpuUsage
=
0
,
procCpuUsage
=
0
;
bool
suc
=
taosGetCpuUsage
(
&
sysCpuUsage
,
&
procCpuUsage
);
if
(
!
suc
)
{
m
onitor
Debug
(
"failed to get cpu usage"
);
m
n
Debug
(
"failed to get cpu usage"
);
}
if
(
sysCpuUsage
<=
procCpuUsage
)
{
...
...
@@ -294,14 +294,14 @@ static int32_t monitorBuildBandSql(char *sql) {
float
bandSpeedKb
=
0
;
bool
suc
=
taosGetBandSpeed
(
&
bandSpeedKb
);
if
(
!
suc
)
{
m
onitor
Debug
(
"failed to get bandwidth speed"
);
m
n
Debug
(
"failed to get bandwidth speed"
);
}
return
sprintf
(
sql
,
", %f"
,
bandSpeedKb
);
}
static
int32_t
monitorBuildReqSql
(
char
*
sql
)
{
S
Dnode
StatisInfo
info
=
dnodeGetStatisInfo
();
SStatisInfo
info
=
dnodeGetStatisInfo
();
return
sprintf
(
sql
,
", %d, %d, %d)"
,
info
.
httpReqNum
,
info
.
queryReqNum
,
info
.
submitReqNum
);
}
...
...
@@ -309,7 +309,7 @@ static int32_t monitorBuildIoSql(char *sql) {
float
readKB
=
0
,
writeKB
=
0
;
bool
suc
=
taosGetProcIO
(
&
readKB
,
&
writeKB
);
if
(
!
suc
)
{
m
onitor
Debug
(
"failed to get io info"
);
m
n
Debug
(
"failed to get io info"
);
}
return
sprintf
(
sql
,
", %f, %f"
,
readKB
,
writeKB
);
...
...
@@ -332,19 +332,19 @@ static void monitorSaveSystemInfo() {
taos_free_result
(
res
);
if
(
code
!=
0
)
{
m
onitor
Error
(
"failed to save system info, reason:%s, sql:%s"
,
tstrerror
(
code
),
tsMonitor
.
sql
);
m
n
Error
(
"failed to save system info, reason:%s, sql:%s"
,
tstrerror
(
code
),
tsMonitor
.
sql
);
}
else
{
m
onitor
Debug
(
"successfully to save system info, sql:%s"
,
tsMonitor
.
sql
);
m
n
Debug
(
"successfully to save system info, sql:%s"
,
tsMonitor
.
sql
);
}
}
static
void
montiorExecSqlCb
(
void
*
param
,
TAOS_RES
*
result
,
int32_t
code
)
{
int32_t
c
=
taos_errno
(
result
);
if
(
c
!=
TSDB_CODE_SUCCESS
)
{
m
onitor
Error
(
"save %s failed, reason:%s"
,
(
char
*
)
param
,
tstrerror
(
c
));
m
n
Error
(
"save %s failed, reason:%s"
,
(
char
*
)
param
,
tstrerror
(
c
));
}
else
{
int32_t
rows
=
taos_affected_rows
(
result
);
m
onitor
Debug
(
"save %s succ, rows:%d"
,
(
char
*
)
param
,
rows
);
m
n
Debug
(
"save %s succ, rows:%d"
,
(
char
*
)
param
,
rows
);
}
taos_free_result
(
result
);
...
...
@@ -380,7 +380,7 @@ void monitorSaveAcctLog(SAcctMonitorObj *pMon) {
pMon
->
totalConns
,
pMon
->
maxConns
,
pMon
->
accessState
);
m
onitor
Debug
(
"save account info, sql:%s"
,
sql
);
m
n
Debug
(
"save account info, sql:%s"
,
sql
);
taos_query_a
(
tsMonitor
.
conn
,
sql
,
montiorExecSqlCb
,
"account info"
);
}
...
...
@@ -401,13 +401,13 @@ void monitorSaveLog(int32_t level, const char *const format, ...) {
len
+=
sprintf
(
sql
+
len
,
"', '%s')"
,
tsLocalEp
);
sql
[
len
++
]
=
0
;
m
onitor
Debug
(
"save log, sql: %s"
,
sql
);
m
n
Debug
(
"save log, sql: %s"
,
sql
);
taos_query_a
(
tsMonitor
.
conn
,
sql
,
montiorExecSqlCb
,
"log"
);
}
void
monitorExecuteSQL
(
char
*
sql
)
{
if
(
tsMonitor
.
state
!=
MON_STATE_INITED
)
return
;
m
onitor
Debug
(
"execute sql:%s"
,
sql
);
m
n
Debug
(
"execute sql:%s"
,
sql
);
taos_query_a
(
tsMonitor
.
conn
,
sql
,
montiorExecSqlCb
,
"sql"
);
}
src/query/inc/qExecutor.h
浏览文件 @
d583a4ca
...
...
@@ -200,12 +200,6 @@ enum {
QUERY_RESULT_READY
=
2
,
};
typedef
struct
SMemRef
{
int32_t
ref
;
void
*
mem
;
void
*
imem
;
}
SMemRef
;
typedef
struct
SQInfo
{
void
*
signature
;
int32_t
code
;
// error code to returned to client
...
...
src/query/src/qExecutor.c
浏览文件 @
d583a4ca
...
...
@@ -1711,6 +1711,19 @@ _clean:
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
static
void
doFreeQueryHandle
(
SQInfo
*
pQInfo
)
{
SQueryRuntimeEnv
*
pRuntimeEnv
=
&
pQInfo
->
runtimeEnv
;
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pQueryHandle
);
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pSecQueryHandle
);
pRuntimeEnv
->
pQueryHandle
=
NULL
;
pRuntimeEnv
->
pSecQueryHandle
=
NULL
;
SMemRef
*
pMemRef
=
&
pQInfo
->
memRef
;
assert
(
pMemRef
->
ref
==
0
&&
pMemRef
->
imem
==
NULL
&&
pMemRef
->
mem
==
NULL
);
}
static
void
teardownQueryRuntimeEnv
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
if
(
pRuntimeEnv
->
pQuery
==
NULL
)
{
return
;
...
...
@@ -1740,8 +1753,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
pRuntimeEnv
->
pFillInfo
=
taosDestroyFillInfo
(
pRuntimeEnv
->
pFillInfo
);
destroyResultBuf
(
pRuntimeEnv
->
pResultBuf
);
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pQueryHandle
);
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pSecQueryHandle
);
doFreeQueryHandle
(
pQInfo
);
pRuntimeEnv
->
pTSBuf
=
tsBufDestroy
(
pRuntimeEnv
->
pTSBuf
);
taosTFree
(
pRuntimeEnv
->
keyBuf
);
...
...
@@ -3536,7 +3548,7 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI
tsdbCleanupQueryHandle
(
pRuntimeEnv
->
pSecQueryHandle
);
}
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
,
&
pQInfo
->
memRef
);
if
(
pRuntimeEnv
->
pSecQueryHandle
==
NULL
)
{
longjmp
(
pRuntimeEnv
->
env
,
terrno
);
}
...
...
@@ -3620,7 +3632,7 @@ void scanOneTableDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, TSKEY start) {
}
restoreTimeWindow
(
&
pQInfo
->
tableGroupInfo
,
&
cond
);
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
,
&
pQInfo
->
memRef
);
if
(
pRuntimeEnv
->
pSecQueryHandle
==
NULL
)
{
longjmp
(
pRuntimeEnv
->
env
,
terrno
);
}
...
...
@@ -4462,7 +4474,7 @@ static int32_t setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery)
terrno
=
TSDB_CODE_SUCCESS
;
if
(
isFirstLastRowQuery
(
pQuery
))
{
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryLastRow
(
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryLastRow
(
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
,
&
pQInfo
->
memRef
);
// update the query time window
pQuery
->
window
=
cond
.
twindow
;
...
...
@@ -4484,9 +4496,9 @@ static int32_t setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery)
}
}
}
else
if
(
isPointInterpoQuery
(
pQuery
))
{
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryRowsInExternalWindow
(
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryRowsInExternalWindow
(
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
,
&
pQInfo
->
memRef
);
}
else
{
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryTables
(
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryTables
(
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
,
&
pQInfo
->
memRef
);
}
return
terrno
;
...
...
@@ -4765,7 +4777,7 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) {
pRuntimeEnv
->
pQueryHandle
=
NULL
;
}
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
gp
,
pQInfo
);
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
gp
,
pQInfo
,
&
pQInfo
->
memRef
);
taosArrayDestroy
(
tx
);
taosArrayDestroy
(
g1
);
if
(
pRuntimeEnv
->
pQueryHandle
==
NULL
)
{
...
...
@@ -4880,7 +4892,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
pRuntimeEnv
->
pQueryHandle
=
NULL
;
}
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryRowsInExternalWindow
(
pQInfo
->
tsdb
,
&
cond
,
&
gp
,
pQInfo
);
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryRowsInExternalWindow
(
pQInfo
->
tsdb
,
&
cond
,
&
gp
,
pQInfo
,
&
pQInfo
->
memRef
);
taosArrayDestroy
(
tx
);
taosArrayDestroy
(
g1
);
...
...
@@ -4946,7 +4958,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) {
}
// no need to update the lastkey for each table
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
gp
,
pQInfo
);
pRuntimeEnv
->
pQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
gp
,
pQInfo
,
&
pQInfo
->
memRef
);
taosArrayDestroy
(
g1
);
taosArrayDestroy
(
tx
);
...
...
@@ -5155,7 +5167,7 @@ static void doSaveContext(SQInfo *pQInfo) {
setupQueryRangeForReverseScan
(
pQInfo
);
pRuntimeEnv
->
prevGroupId
=
INT32_MIN
;
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
);
pRuntimeEnv
->
pSecQueryHandle
=
tsdbQueryTables
(
pQInfo
->
tsdb
,
&
cond
,
&
pQInfo
->
tableGroupInfo
,
pQInfo
,
&
pQInfo
->
memRef
);
if
(
pRuntimeEnv
->
pSecQueryHandle
==
NULL
)
{
longjmp
(
pRuntimeEnv
->
env
,
terrno
);
}
...
...
@@ -6841,7 +6853,7 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo, bool* buildRes, void* pRspContex
int32_t
code
=
TSDB_CODE_SUCCESS
;
#if
0
#if
_NON_BLOCKING_RETRIEVE
SQuery
*
pQuery
=
pQInfo
->
runtimeEnv
.
pQuery
;
pthread_mutex_lock
(
&
pQInfo
->
lock
);
...
...
@@ -6913,6 +6925,8 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
pQInfo
->
dataReady
=
QUERY_RESULT_NOT_READY
;
if
(
IS_QUERY_KILLED
(
pQInfo
)
||
Q_STATUS_EQUAL
(
pQuery
->
status
,
QUERY_OVER
))
{
// here current thread hold the refcount, so it is safe to free tsdbQueryHandle.
doFreeQueryHandle
(
pQInfo
);
*
continueExec
=
false
;
(
*
pRsp
)
->
completed
=
1
;
// notify no more result to client
}
else
{
...
...
src/sync/src/syncMain.c
浏览文件 @
d583a4ca
...
...
@@ -1221,8 +1221,8 @@ static int32_t syncForwardToPeerImpl(SSyncNode *pNode, void *data, void *mhandle
// always update version
nodeVersion
=
pWalHead
->
version
;
sDebug
(
"vgId:%d,
replica:%d nodeRole:%s qtype:%d ver:%"
PRIu64
,
pNode
->
vgId
,
pNode
->
replica
,
syncRole
[
nodeRole
]
,
qtype
,
pWalHead
->
version
);
sDebug
(
"vgId:%d,
forward to peer, replica:%d role:%s qtype:%s hver:%"
PRIu64
,
pNode
->
vgId
,
pNode
->
replica
,
syncRole
[
nodeRole
],
qtypeStr
[
qtype
]
,
pWalHead
->
version
);
if
(
pNode
->
replica
==
1
||
nodeRole
!=
TAOS_SYNC_ROLE_MASTER
)
return
0
;
...
...
src/sync/src/syncRestore.c
浏览文件 @
d583a4ca
...
...
@@ -153,7 +153,7 @@ static int syncRestoreWal(SSyncPeer *pPeer) {
ret
=
taosReadMsg
(
pPeer
->
syncFd
,
pHead
->
cont
,
pHead
->
len
);
if
(
ret
<
0
)
break
;
sDebug
(
"%s, restore a record, ver:%"
PRIu64
,
pPeer
->
id
,
pHead
->
version
);
sDebug
(
"%s, restore a record,
qtype:wal h
ver:%"
PRIu64
,
pPeer
->
id
,
pHead
->
version
);
(
*
pNode
->
writeToCache
)(
pNode
->
ahandle
,
pHead
,
TAOS_QTYPE_WAL
,
NULL
);
}
...
...
src/sync/src/syncRetrieve.c
浏览文件 @
d583a4ca
...
...
@@ -256,7 +256,7 @@ static int syncRetrieveLastWal(SSyncPeer *pPeer, char *name, uint64_t fversion,
}
(
void
)
lseek
(
sfd
,
offset
,
SEEK_SET
);
sDebug
(
"%s, retrieve last wal, offset:%"
PRId64
" fver
sion
:%"
PRIu64
,
pPeer
->
id
,
offset
,
fversion
);
sDebug
(
"%s, retrieve last wal, offset:%"
PRId64
" fver:%"
PRIu64
,
pPeer
->
id
,
offset
,
fversion
);
while
(
1
)
{
int
wsize
=
syncReadOneWalRecord
(
sfd
,
pHead
,
pEvent
);
...
...
@@ -325,7 +325,7 @@ static int syncProcessLastWal(SSyncPeer *pPeer, char *wname, int64_t index) {
// if all data up to fversion is read out, it is over
if
(
pPeer
->
sversion
>=
fversion
&&
fversion
>
0
)
{
code
=
0
;
sDebug
(
"%s, data up to fver
sion:%"
PRId
64
" has been read out, bytes:%d"
,
pPeer
->
id
,
fversion
,
bytes
);
sDebug
(
"%s, data up to fver
:%"
PRIu
64
" has been read out, bytes:%d"
,
pPeer
->
id
,
fversion
,
bytes
);
break
;
}
...
...
src/sync/src/taosTcpPool.c
浏览文件 @
d583a4ca
...
...
@@ -13,18 +13,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "tulog.h"
#include "tutil.h"
#include "tsocket.h"
#include "taoserror.h"
#include "taosTcpPool.h"
#include "twal.h"
#include "tsync.h"
#include "syncInt.h"
typedef
struct
SThreadObj
{
pthread_t
thread
;
bool
stop
;
int
pollFd
;
int
numOfFds
;
int
32_t
pollFd
;
int
32_t
numOfFds
;
struct
SPoolObj
*
pPool
;
}
SThreadObj
;
...
...
@@ -32,15 +36,15 @@ typedef struct SPoolObj {
SPoolInfo
info
;
SThreadObj
**
pThread
;
pthread_t
thread
;
int
nextId
;
int
acceptFd
;
// FD for accept new connection
int
32_t
nextId
;
int
32_t
acceptFd
;
// FD for accept new connection
}
SPoolObj
;
typedef
struct
{
SThreadObj
*
pThread
;
void
*
ahandle
;
int
fd
;
int
closedByApp
;
void
*
ahandle
;
int
32_t
fd
;
int
32_t
closedByApp
;
}
SConnObj
;
static
void
*
taosAcceptPeerTcpConnection
(
void
*
argv
);
...
...
@@ -53,66 +57,66 @@ void *taosOpenTcpThreadPool(SPoolInfo *pInfo) {
SPoolObj
*
pPool
=
calloc
(
sizeof
(
SPoolObj
),
1
);
if
(
pPool
==
NULL
)
{
uError
(
"TCP server,
no enough memory"
);
sError
(
"failed to alloc pool for TCP server since
no enough memory"
);
return
NULL
;
}
pPool
->
info
=
*
pInfo
;
pPool
->
pThread
=
(
SThreadObj
**
)
calloc
(
sizeof
(
SThreadObj
*
),
pInfo
->
numOfThreads
);
pPool
->
pThread
=
calloc
(
sizeof
(
SThreadObj
*
),
pInfo
->
numOfThreads
);
if
(
pPool
->
pThread
==
NULL
)
{
uError
(
"TCP server,
no enough memory"
);
free
(
pPool
);
sError
(
"failed to alloc pool thread for TCP server since
no enough memory"
);
t
free
(
pPool
);
return
NULL
;
}
pPool
->
acceptFd
=
taosOpenTcpServerSocket
(
pInfo
->
serverIp
,
pInfo
->
port
);
if
(
pPool
->
acceptFd
<
0
)
{
free
(
pPool
->
pThread
);
free
(
pPool
);
u
Error
(
"failed to create TCP server socket, port:%d (%s)"
,
pInfo
->
port
,
strerror
(
errno
));
t
free
(
pPool
->
pThread
);
t
free
(
pPool
);
s
Error
(
"failed to create TCP server socket, port:%d (%s)"
,
pInfo
->
port
,
strerror
(
errno
));
return
NULL
;
}
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
(
pPool
->
thread
),
&
thattr
,
(
void
*
)
taosAcceptPeerTcpConnection
,
pPool
)
!=
0
)
{
uError
(
"TCP server, failed to create accept thread, reason:
%s"
,
strerror
(
errno
));
sError
(
"failed to create accept thread for TCP server since
%s"
,
strerror
(
errno
));
close
(
pPool
->
acceptFd
);
free
(
pPool
->
pThread
);
free
(
pPool
);
t
free
(
pPool
->
pThread
);
t
free
(
pPool
);
return
NULL
;
}
pthread_attr_destroy
(
&
thattr
);
u
Debug
(
"%p TCP pool is created"
,
pPool
);
s
Debug
(
"%p TCP pool is created"
,
pPool
);
return
pPool
;
}
void
taosCloseTcpThreadPool
(
void
*
param
)
{
SPoolObj
*
pPool
=
(
SPoolObj
*
)
param
;
SPoolObj
*
pPool
=
param
;
SThreadObj
*
pThread
;
shutdown
(
pPool
->
acceptFd
,
SHUT_RD
);
pthread_join
(
pPool
->
thread
,
NULL
);
for
(
int
i
=
0
;
i
<
pPool
->
info
.
numOfThreads
;
++
i
)
{
for
(
int
32_t
i
=
0
;
i
<
pPool
->
info
.
numOfThreads
;
++
i
)
{
pThread
=
pPool
->
pThread
[
i
];
if
(
pThread
)
taosStopPoolThread
(
pThread
);
}
u
Debug
(
"%p TCP pool is closed"
,
pPool
);
s
Debug
(
"%p TCP pool is closed"
,
pPool
);
taosTFree
(
pPool
->
pThread
);
free
(
pPool
);
t
free
(
pPool
);
}
void
*
taosAllocateTcpConn
(
void
*
param
,
void
*
pPeer
,
int
connFd
)
{
void
*
taosAllocateTcpConn
(
void
*
param
,
void
*
pPeer
,
int
32_t
connFd
)
{
struct
epoll_event
event
;
SPoolObj
*
pPool
=
(
SPoolObj
*
)
param
;
SPoolObj
*
pPool
=
param
;
SConnObj
*
pConn
=
(
SConnObj
*
)
calloc
(
sizeof
(
SConnObj
),
1
);
SConnObj
*
pConn
=
calloc
(
sizeof
(
SConnObj
),
1
);
if
(
pConn
==
NULL
)
{
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
return
NULL
;
...
...
@@ -120,7 +124,7 @@ void *taosAllocateTcpConn(void *param, void *pPeer, int connFd) {
SThreadObj
*
pThread
=
taosGetTcpThread
(
pPool
);
if
(
pThread
==
NULL
)
{
free
(
pConn
);
t
free
(
pConn
);
return
NULL
;
}
...
...
@@ -133,13 +137,13 @@ void *taosAllocateTcpConn(void *param, void *pPeer, int connFd) {
event
.
data
.
ptr
=
pConn
;
if
(
epoll_ctl
(
pThread
->
pollFd
,
EPOLL_CTL_ADD
,
connFd
,
&
event
)
<
0
)
{
uError
(
"failed to add fd:%d(%s)
"
,
connFd
,
strerror
(
errno
));
sError
(
"failed to add fd:%d since %s
"
,
connFd
,
strerror
(
errno
));
terrno
=
TAOS_SYSTEM_ERROR
(
errno
);
free
(
pConn
);
t
free
(
pConn
);
pConn
=
NULL
;
}
else
{
pThread
->
numOfFds
++
;
u
Debug
(
"%p fd:%d is added to epoll thread, num:%d"
,
pThread
,
connFd
,
pThread
->
numOfFds
);
s
Debug
(
"%p fd:%d is added to epoll thread, num:%d"
,
pThread
,
connFd
,
pThread
->
numOfFds
);
}
return
pConn
;
...
...
@@ -149,7 +153,7 @@ void taosFreeTcpConn(void *param) {
SConnObj
*
pConn
=
(
SConnObj
*
)
param
;
SThreadObj
*
pThread
=
pConn
->
pThread
;
u
Debug
(
"%p TCP connection will be closed, fd:%d"
,
pThread
,
pConn
->
fd
);
s
Debug
(
"%p TCP connection will be closed, fd:%d"
,
pThread
,
pConn
->
fd
);
pConn
->
closedByApp
=
1
;
shutdown
(
pConn
->
fd
,
SHUT_WR
);
}
...
...
@@ -164,9 +168,9 @@ static void taosProcessBrokenLink(SConnObj *pConn) {
pThread
->
numOfFds
--
;
epoll_ctl
(
pThread
->
pollFd
,
EPOLL_CTL_DEL
,
pConn
->
fd
,
NULL
);
u
Debug
(
"%p fd:%d is removed from epoll thread, num:%d"
,
pThread
,
pConn
->
fd
,
pThread
->
numOfFds
);
s
Debug
(
"%p fd:%d is removed from epoll thread, num:%d"
,
pThread
,
pConn
->
fd
,
pThread
->
numOfFds
);
taosClose
(
pConn
->
fd
);
free
(
pConn
);
t
free
(
pConn
);
}
#define maxEvents 10
...
...
@@ -183,18 +187,18 @@ static void *taosProcessTcpData(void *param) {
while
(
1
)
{
if
(
pThread
->
stop
)
break
;
int
fdNum
=
epoll_wait
(
pThread
->
pollFd
,
events
,
maxEvents
,
TAOS_EPOLL_WAIT_TIME
);
int
32_t
fdNum
=
epoll_wait
(
pThread
->
pollFd
,
events
,
maxEvents
,
TAOS_EPOLL_WAIT_TIME
);
if
(
pThread
->
stop
)
{
u
Debug
(
"%p TCP epoll thread is exiting..."
,
pThread
);
s
Debug
(
"%p TCP epoll thread is exiting..."
,
pThread
);
break
;
}
if
(
fdNum
<
0
)
{
uError
(
"epoll_wait failed (%s)
"
,
strerror
(
errno
));
sError
(
"epoll_wait failed since %s
"
,
strerror
(
errno
));
continue
;
}
for
(
int
i
=
0
;
i
<
fdNum
;
++
i
)
{
for
(
int
32_t
i
=
0
;
i
<
fdNum
;
++
i
)
{
pConn
=
events
[
i
].
data
.
ptr
;
assert
(
pConn
);
...
...
@@ -219,17 +223,16 @@ static void *taosProcessTcpData(void *param) {
continue
;
}
}
}
if
(
pThread
->
stop
)
break
;
}
u
Debug
(
"%p TCP epoll thread exits"
,
pThread
);
s
Debug
(
"%p TCP epoll thread exits"
,
pThread
);
close
(
pThread
->
pollFd
);
free
(
pThread
);
free
(
buffer
);
t
free
(
pThread
);
t
free
(
buffer
);
return
NULL
;
}
...
...
@@ -242,18 +245,18 @@ static void *taosAcceptPeerTcpConnection(void *argv) {
while
(
1
)
{
struct
sockaddr_in
clientAddr
;
socklen_t
addrlen
=
sizeof
(
clientAddr
);
int
connFd
=
accept
(
pPool
->
acceptFd
,
(
struct
sockaddr
*
)
&
clientAddr
,
&
addrlen
);
int
32_t
connFd
=
accept
(
pPool
->
acceptFd
,
(
struct
sockaddr
*
)
&
clientAddr
,
&
addrlen
);
if
(
connFd
<
0
)
{
if
(
errno
==
EINVAL
)
{
u
Debug
(
"%p TCP server accept is exiting..."
,
pPool
);
s
Debug
(
"%p TCP server accept is exiting..."
,
pPool
);
break
;
}
else
{
uError
(
"TCP accept failure, reason:
%s"
,
strerror
(
errno
));
sError
(
"TCP accept failure since
%s"
,
strerror
(
errno
));
continue
;
}
}
//
u
Debug("TCP connection from: 0x%x:%d", clientAddr.sin_addr.s_addr, clientAddr.sin_port);
//
s
Debug("TCP connection from: 0x%x:%d", clientAddr.sin_addr.s_addr, clientAddr.sin_port);
taosKeepTcpAlive
(
connFd
);
(
*
pInfo
->
processIncomingConn
)(
connFd
,
clientAddr
.
sin_addr
.
s_addr
);
}
...
...
@@ -273,23 +276,23 @@ static SThreadObj *taosGetTcpThread(SPoolObj *pPool) {
pThread
->
pPool
=
pPool
;
pThread
->
pollFd
=
epoll_create
(
10
);
// size does not matter
if
(
pThread
->
pollFd
<
0
)
{
free
(
pThread
);
t
free
(
pThread
);
return
NULL
;
}
pthread_attr_t
thattr
;
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
int
ret
=
pthread_create
(
&
(
pThread
->
thread
),
&
thattr
,
(
void
*
)
taosProcessTcpData
,
pThread
);
int
32_t
ret
=
pthread_create
(
&
(
pThread
->
thread
),
&
thattr
,
(
void
*
)
taosProcessTcpData
,
pThread
);
pthread_attr_destroy
(
&
thattr
);
if
(
ret
!=
0
)
{
close
(
pThread
->
pollFd
);
free
(
pThread
);
t
free
(
pThread
);
return
NULL
;
}
u
Debug
(
"%p TCP epoll thread is created"
,
pThread
);
s
Debug
(
"%p TCP epoll thread is created"
,
pThread
);
pPool
->
pThread
[
pPool
->
nextId
]
=
pThread
;
pPool
->
nextId
++
;
pPool
->
nextId
=
pPool
->
nextId
%
pPool
->
info
.
numOfThreads
;
...
...
@@ -314,12 +317,12 @@ static void taosStopPoolThread(SThreadObj *pThread) {
eventfd_t
fd
=
eventfd
(
1
,
0
);
if
(
fd
==
-
1
)
{
// failed to create eventfd, call pthread_cancel instead, which may result in data corruption
uError
(
"failed to create eventfd(%s)
"
,
strerror
(
errno
));
sError
(
"failed to create eventfd since %s
"
,
strerror
(
errno
));
pthread_cancel
(
pThread
->
thread
);
pThread
->
stop
=
true
;
}
else
if
(
epoll_ctl
(
pThread
->
pollFd
,
EPOLL_CTL_ADD
,
fd
,
&
event
)
<
0
)
{
// failed to call epoll_ctl, call pthread_cancel instead, which may result in data corruption
uError
(
"failed to call epoll_ctl(%s)
"
,
strerror
(
errno
));
sError
(
"failed to call epoll_ctl since %s
"
,
strerror
(
errno
));
pthread_cancel
(
pThread
->
thread
);
}
...
...
src/tsdb/src/tsdbMemTable.c
浏览文件 @
d583a4ca
...
...
@@ -198,6 +198,8 @@ void tsdbUnTakeMemSnapShot(STsdbRepo *pRepo, SMemTable *pMem, SMemTable *pIMem)
if
(
pIMem
!=
NULL
)
{
tsdbUnRefMemTable
(
pRepo
,
pIMem
);
}
tsdbDebug
(
"vgId:%d utake memory snapshot, pMem %p pIMem %p"
,
REPO_ID
(
pRepo
),
pMem
,
pIMem
);
}
void
*
tsdbAllocBytes
(
STsdbRepo
*
pRepo
,
int
bytes
)
{
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
d583a4ca
...
...
@@ -20,7 +20,6 @@
#include "exception.h"
#include "../../query/inc/qAst.h" // todo move to common module
#include "../../query/inc/qExecutor.h" // todo move to common module
#include "tlosertree.h"
#include "tsdb.h"
#include "tsdbMain.h"
...
...
@@ -120,8 +119,9 @@ typedef struct STsdbQueryHandle {
SDataCols
*
pDataCols
;
// in order to hold current file data block
int32_t
allocSize
;
// allocated data block size
SMemTable
*
mem
;
// mem-table
SMemTable
*
imem
;
// imem-table, acquired from snapshot
SMemRef
*
pMemRef
;
// SMemTable *mem; // mem-table
// SMemTable *imem; // imem-table, acquired from snapshot
SArray
*
defaultLoadColumn
;
// default load column
SDataBlockLoadInfo
dataBlockLoadInfo
;
/* record current block load information */
SLoadCompBlockInfo
compBlockLoadInfo
;
/* record current compblock information in SQuery */
...
...
@@ -184,26 +184,26 @@ static SArray* getDefaultLoadColumns(STsdbQueryHandle* pQueryHandle, bool loadTS
return
pLocalIdList
;
}
static
void
tsdbMayTakeMemSnapshot
(
TsdbQueryHandleT
pHandle
)
{
STsdbQueryHandle
*
pSecQueryHandle
=
(
STsdbQueryHandle
*
)
pHandle
;
SQInfo
*
pQInfo
=
(
SQInfo
*
)(
pSecQueryHandle
->
qinfo
);
static
void
tsdbMayTakeMemSnapshot
(
STsdbQueryHandle
*
pQueryHandle
)
{
assert
(
pQueryHandle
!=
NULL
&&
pQueryHandle
->
pMemRef
!=
NULL
);
if
(
pQInfo
->
memRef
.
ref
++
==
0
)
{
tsdbTakeMemSnapshot
(
pSecQueryHandle
->
pTsdb
,
&
pSecQueryHandle
->
mem
,
&
pSecQueryHandle
->
imem
);
pQInfo
->
memRef
.
mem
=
pSecQueryHandle
->
mem
;
pQInfo
->
memRef
.
imem
=
pSecQueryHandle
->
imem
;
}
else
{
pSecQueryHandle
->
mem
=
(
SMemTable
*
)(
pQInfo
->
memRef
.
mem
);
pSecQueryHandle
->
imem
=
(
SMemTable
*
)(
pQInfo
->
memRef
.
imem
);
SMemRef
*
pMemRef
=
pQueryHandle
->
pMemRef
;
if
(
pQueryHandle
->
pMemRef
->
ref
++
==
0
)
{
tsdbTakeMemSnapshot
(
pQueryHandle
->
pTsdb
,
(
SMemTable
**
)
&
(
pMemRef
->
mem
),
(
SMemTable
**
)
&
(
pMemRef
->
imem
));
}
}
static
void
tsdbMayUnTakeMemSnapshot
(
TsdbQueryHandleT
pHandle
)
{
STsdbQueryHandle
*
pSecQueryHandle
=
(
STsdbQueryHandle
*
)
pHandle
;
SQInfo
*
pQInfo
=
(
SQInfo
*
)(
pSecQueryHandle
->
qinfo
);
if
(
--
pQInfo
->
memRef
.
ref
==
0
)
{
tsdbUnTakeMemSnapShot
(
pSecQueryHandle
->
pTsdb
,
pSecQueryHandle
->
mem
,
pSecQueryHandle
->
imem
);
static
void
tsdbMayUnTakeMemSnapshot
(
STsdbQueryHandle
*
pQueryHandle
)
{
assert
(
pQueryHandle
!=
NULL
&&
pQueryHandle
->
pMemRef
!=
NULL
);
SMemRef
*
pMemRef
=
pQueryHandle
->
pMemRef
;
if
(
--
pMemRef
->
ref
==
0
)
{
tsdbUnTakeMemSnapShot
(
pQueryHandle
->
pTsdb
,
pMemRef
->
mem
,
pMemRef
->
imem
);
pMemRef
->
mem
=
NULL
;
pMemRef
->
imem
=
NULL
;
}
pQueryHandle
->
pMemRef
=
NULL
;
}
static
SArray
*
createCheckInfoFromTableGroup
(
STsdbQueryHandle
*
pQueryHandle
,
STableGroupInfo
*
pGroupList
,
STsdbMeta
*
pMeta
)
{
size_t
sizeOfGroup
=
taosArrayGetSize
(
pGroupList
->
pGroupList
);
...
...
@@ -270,7 +270,7 @@ static SArray* createCheckInfoFromCheckInfo(SArray* pTableCheckInfo, TSKEY skey)
return
pNew
;
}
static
STsdbQueryHandle
*
tsdbQueryTablesImpl
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
void
*
qinfo
)
{
static
STsdbQueryHandle
*
tsdbQueryTablesImpl
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
void
*
qinfo
,
SMemRef
*
pMemRef
)
{
STsdbQueryHandle
*
pQueryHandle
=
calloc
(
1
,
sizeof
(
STsdbQueryHandle
));
if
(
pQueryHandle
==
NULL
)
{
goto
out_of_memory
;
...
...
@@ -288,13 +288,14 @@ static STsdbQueryHandle* tsdbQueryTablesImpl(TSDB_REPO_T* tsdb, STsdbQueryCond*
pQueryHandle
->
outputCapacity
=
((
STsdbRepo
*
)
tsdb
)
->
config
.
maxRowsPerFileBlock
;
pQueryHandle
->
allocSize
=
0
;
pQueryHandle
->
locateStart
=
false
;
pQueryHandle
->
pMemRef
=
pMemRef
;
if
(
tsdbInitReadHelper
(
&
pQueryHandle
->
rhelper
,
(
STsdbRepo
*
)
tsdb
)
!=
0
)
{
goto
out_of_memory
;
}
tsdbMayTakeMemSnapshot
(
pQueryHandle
);
assert
(
pCond
!=
NULL
&&
pCond
->
numOfCols
>
0
);
assert
(
pCond
!=
NULL
&&
pCond
->
numOfCols
>
0
&&
pMemRef
!=
NULL
);
if
(
ASCENDING_TRAVERSE
(
pCond
->
order
))
{
assert
(
pQueryHandle
->
window
.
skey
<=
pQueryHandle
->
window
.
ekey
);
...
...
@@ -348,8 +349,8 @@ static STsdbQueryHandle* tsdbQueryTablesImpl(TSDB_REPO_T* tsdb, STsdbQueryCond*
return
NULL
;
}
TsdbQueryHandleT
*
tsdbQueryTables
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
void
*
qinfo
)
{
STsdbQueryHandle
*
pQueryHandle
=
tsdbQueryTablesImpl
(
tsdb
,
pCond
,
qinfo
);
TsdbQueryHandleT
*
tsdbQueryTables
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
void
*
qinfo
,
SMemRef
*
pRef
)
{
STsdbQueryHandle
*
pQueryHandle
=
tsdbQueryTablesImpl
(
tsdb
,
pCond
,
qinfo
,
pRef
);
STsdbMeta
*
pMeta
=
tsdbGetMeta
(
tsdb
);
assert
(
pMeta
!=
NULL
);
...
...
@@ -366,7 +367,7 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab
return
(
TsdbQueryHandleT
)
pQueryHandle
;
}
TsdbQueryHandleT
tsdbQueryLastRow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
void
*
qinfo
)
{
TsdbQueryHandleT
tsdbQueryLastRow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
void
*
qinfo
,
SMemRef
*
pMemRef
)
{
pCond
->
twindow
=
changeTableGroupByLastrow
(
groupList
);
// no qualified table
...
...
@@ -374,7 +375,7 @@ TsdbQueryHandleT tsdbQueryLastRow(TSDB_REPO_T *tsdb, STsdbQueryCond *pCond, STab
return
NULL
;
}
STsdbQueryHandle
*
pQueryHandle
=
(
STsdbQueryHandle
*
)
tsdbQueryTables
(
tsdb
,
pCond
,
groupList
,
qinfo
);
STsdbQueryHandle
*
pQueryHandle
=
(
STsdbQueryHandle
*
)
tsdbQueryTables
(
tsdb
,
pCond
,
groupList
,
qinfo
,
pMemRef
);
assert
(
pCond
->
order
==
TSDB_ORDER_ASC
&&
pCond
->
twindow
.
skey
<=
pCond
->
twindow
.
ekey
);
return
pQueryHandle
;
...
...
@@ -396,8 +397,8 @@ SArray* tsdbGetQueriedTableList(TsdbQueryHandleT *pHandle) {
return
res
;
}
TsdbQueryHandleT
tsdbQueryRowsInExternalWindow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
void
*
qinfo
)
{
STsdbQueryHandle
*
pQueryHandle
=
(
STsdbQueryHandle
*
)
tsdbQueryTables
(
tsdb
,
pCond
,
groupList
,
qinfo
);
TsdbQueryHandleT
tsdbQueryRowsInExternalWindow
(
TSDB_REPO_T
*
tsdb
,
STsdbQueryCond
*
pCond
,
STableGroupInfo
*
groupList
,
void
*
qinfo
,
SMemRef
*
pRef
)
{
STsdbQueryHandle
*
pQueryHandle
=
(
STsdbQueryHandle
*
)
tsdbQueryTables
(
tsdb
,
pCond
,
groupList
,
qinfo
,
pRef
);
if
(
pQueryHandle
!=
NULL
)
{
pQueryHandle
->
type
=
TSDB_QUERY_TYPE_EXTERNAL
;
changeQueryHandleForInterpQuery
(
pQueryHandle
);
...
...
@@ -417,7 +418,7 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh
int32_t
order
=
pHandle
->
order
;
// no data in buffer, abort
if
(
pHandle
->
mem
==
NULL
&&
pHandle
->
imem
==
NULL
)
{
if
(
pHandle
->
pMemRef
->
mem
==
NULL
&&
pHandle
->
pMemRef
->
imem
==
NULL
)
{
return
false
;
}
...
...
@@ -426,16 +427,19 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh
STableData
*
pMem
=
NULL
;
STableData
*
pIMem
=
NULL
;
if
(
pHandle
->
mem
&&
pCheckInfo
->
tableId
.
tid
<
pHandle
->
mem
->
maxTables
)
{
pMem
=
pHandle
->
mem
->
tData
[
pCheckInfo
->
tableId
.
tid
];
SMemTable
*
pMemT
=
pHandle
->
pMemRef
->
mem
;
SMemTable
*
pIMemT
=
pHandle
->
pMemRef
->
imem
;
if
(
pMemT
&&
pCheckInfo
->
tableId
.
tid
<
pMemT
->
maxTables
)
{
pMem
=
pMemT
->
tData
[
pCheckInfo
->
tableId
.
tid
];
if
(
pMem
!=
NULL
&&
pMem
->
uid
==
pCheckInfo
->
tableId
.
uid
)
{
// check uid
pCheckInfo
->
iter
=
tSkipListCreateIterFromVal
(
pMem
->
pData
,
(
const
char
*
)
&
pCheckInfo
->
lastKey
,
TSDB_DATA_TYPE_TIMESTAMP
,
order
);
}
}
if
(
p
Handle
->
imem
&&
pCheckInfo
->
tableId
.
tid
<
pHandle
->
imem
->
maxTables
)
{
pIMem
=
p
Handle
->
imem
->
tData
[
pCheckInfo
->
tableId
.
tid
];
if
(
p
IMemT
&&
pCheckInfo
->
tableId
.
tid
<
pIMemT
->
maxTables
)
{
pIMem
=
p
IMemT
->
tData
[
pCheckInfo
->
tableId
.
tid
];
if
(
pIMem
!=
NULL
&&
pIMem
->
uid
==
pCheckInfo
->
tableId
.
uid
)
{
// check uid
pCheckInfo
->
iiter
=
tSkipListCreateIterFromVal
(
pIMem
->
pData
,
(
const
char
*
)
&
pCheckInfo
->
lastKey
,
TSDB_DATA_TYPE_TIMESTAMP
,
order
);
...
...
@@ -2029,7 +2033,7 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) {
memcpy
(
&
cond
.
colList
[
i
],
&
pColInfoData
->
info
,
sizeof
(
SColumnInfo
));
}
STsdbQueryHandle
*
pSecQueryHandle
=
tsdbQueryTablesImpl
(
pQueryHandle
->
pTsdb
,
&
cond
,
pQueryHandle
->
qinfo
);
STsdbQueryHandle
*
pSecQueryHandle
=
tsdbQueryTablesImpl
(
pQueryHandle
->
pTsdb
,
&
cond
,
pQueryHandle
->
qinfo
,
pQueryHandle
->
pMemRef
);
taosTFree
(
cond
.
colList
);
...
...
src/vnode/inc/vnodeInt.h
浏览文件 @
d583a4ca
...
...
@@ -41,8 +41,8 @@ typedef struct {
int8_t
status
;
int8_t
role
;
int8_t
accessState
;
int64_t
version
;
// current version
int64_t
fversion
;
// version on saved data file
uint64_t
version
;
// current version
uint64_t
fversion
;
// version on saved data file
void
*
wqueue
;
void
*
rqueue
;
void
*
wal
;
...
...
src/vnode/src/vnodeCfg.c
浏览文件 @
d583a4ca
...
...
@@ -22,7 +22,6 @@
#include "tsdb.h"
#include "dnode.h"
#include "vnodeInt.h"
#include "vnodeVersion.h"
#include "vnodeCfg.h"
static
void
vnodeLoadCfg
(
SVnodeObj
*
pVnode
,
SCreateVnodeMsg
*
vnodeMsg
)
{
...
...
@@ -40,8 +39,7 @@ static void vnodeLoadCfg(SVnodeObj *pVnode, SCreateVnodeMsg* vnodeMsg) {
pVnode
->
tsdbCfg
.
compression
=
vnodeMsg
->
cfg
.
compression
;
pVnode
->
walCfg
.
walLevel
=
vnodeMsg
->
cfg
.
walLevel
;
pVnode
->
walCfg
.
fsyncPeriod
=
vnodeMsg
->
cfg
.
fsyncPeriod
;
pVnode
->
walCfg
.
wals
=
vnodeMsg
->
cfg
.
wals
;
pVnode
->
walCfg
.
keep
=
0
;
pVnode
->
walCfg
.
keep
=
TAOS_WAL_NOT_KEEP
;
pVnode
->
syncCfg
.
replica
=
vnodeMsg
->
cfg
.
replications
;
pVnode
->
syncCfg
.
quorum
=
vnodeMsg
->
cfg
.
quorum
;
...
...
src/vnode/src/vnodeMain.c
浏览文件 @
d583a4ca
...
...
@@ -15,17 +15,11 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "tcache.h"
#include "cJSON.h"
#include "dnode.h"
#include "hash.h"
#include "taoserror.h"
#include "taosmsg.h"
#include "tglobal.h"
#include "trpc.h"
#include "tsdb.h"
#include "ttimer.h"
#include "tutil.h"
#include "vnode.h"
#include "vnodeInt.h"
...
...
@@ -34,7 +28,7 @@
#include "vnodeCfg.h"
#include "vnodeVersion.h"
static
SHashObj
*
ts
Dnode
VnodesHash
;
static
SHashObj
*
tsVnodesHash
;
static
void
vnodeCleanUp
(
SVnodeObj
*
pVnode
);
static
int
vnodeProcessTsdbStatus
(
void
*
arg
,
int
status
);
static
uint32_t
vnodeGetFileInfo
(
void
*
ahandle
,
char
*
name
,
uint32_t
*
index
,
uint32_t
eindex
,
int64_t
*
size
,
uint64_t
*
fversion
);
...
...
@@ -67,8 +61,8 @@ int32_t vnodeInitResources() {
vnodeInitWriteFp
();
vnodeInitReadFp
();
ts
Dnode
VnodesHash
=
taosHashInit
(
TSDB_MIN_VNODES
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
true
);
if
(
ts
Dnode
VnodesHash
==
NULL
)
{
tsVnodesHash
=
taosHashInit
(
TSDB_MIN_VNODES
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
true
);
if
(
tsVnodesHash
==
NULL
)
{
vError
(
"failed to init vnode list"
);
return
TSDB_CODE_VND_OUT_OF_MEMORY
;
}
...
...
@@ -77,10 +71,10 @@ int32_t vnodeInitResources() {
}
void
vnodeCleanupResources
()
{
if
(
ts
Dnode
VnodesHash
!=
NULL
)
{
if
(
tsVnodesHash
!=
NULL
)
{
vDebug
(
"vnode list is cleanup"
);
taosHashCleanup
(
ts
Dnode
VnodesHash
);
ts
Dnode
VnodesHash
=
NULL
;
taosHashCleanup
(
tsVnodesHash
);
tsVnodesHash
=
NULL
;
}
syncCleanUp
();
...
...
@@ -233,6 +227,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
pVnode
->
vgId
=
vnode
;
pVnode
->
status
=
TAOS_VN_STATUS_INIT
;
pVnode
->
fversion
=
0
;
pVnode
->
version
=
0
;
pVnode
->
tsdbCfg
.
tsdbId
=
pVnode
->
vgId
;
pVnode
->
rootDir
=
strdup
(
rootDir
);
...
...
@@ -294,6 +289,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
vnodeCleanUp
(
pVnode
);
return
terrno
;
}
else
{
pVnode
->
fversion
=
0
;
pVnode
->
version
=
0
;
}
}
...
...
@@ -308,6 +304,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
walRestore
(
pVnode
->
wal
,
pVnode
,
vnodeProcessWrite
);
if
(
pVnode
->
version
==
0
)
{
pVnode
->
fversion
=
0
;
pVnode
->
version
=
walGetVersion
(
pVnode
->
wal
);
}
...
...
@@ -349,7 +346,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
pVnode
->
status
=
TAOS_VN_STATUS_READY
;
vDebug
(
"vgId:%d, vnode is opened in %s, pVnode:%p"
,
pVnode
->
vgId
,
rootDir
,
pVnode
);
taosHashPut
(
ts
Dnode
VnodesHash
,
(
const
char
*
)
&
pVnode
->
vgId
,
sizeof
(
int32_t
),
(
char
*
)(
&
pVnode
),
sizeof
(
SVnodeObj
*
));
taosHashPut
(
tsVnodesHash
,
(
const
char
*
)
&
pVnode
->
vgId
,
sizeof
(
int32_t
),
(
char
*
)(
&
pVnode
),
sizeof
(
SVnodeObj
*
));
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -441,7 +438,7 @@ void vnodeRelease(void *pVnodeRaw) {
tsem_destroy
(
&
pVnode
->
sem
);
free
(
pVnode
);
int32_t
count
=
taosHashGetSize
(
ts
Dnode
VnodesHash
);
int32_t
count
=
taosHashGetSize
(
tsVnodesHash
);
vDebug
(
"vgId:%d, vnode is destroyed, vnodes:%d"
,
vgId
,
count
);
}
...
...
@@ -458,7 +455,7 @@ static void vnodeIncRef(void *ptNode) {
}
void
*
vnodeAcquire
(
int32_t
vgId
)
{
SVnodeObj
**
ppVnode
=
taosHashGetCB
(
ts
Dnode
VnodesHash
,
&
vgId
,
sizeof
(
int32_t
),
vnodeIncRef
,
NULL
,
sizeof
(
void
*
));
SVnodeObj
**
ppVnode
=
taosHashGetCB
(
tsVnodesHash
,
&
vgId
,
sizeof
(
int32_t
),
vnodeIncRef
,
NULL
,
sizeof
(
void
*
));
if
(
ppVnode
==
NULL
||
*
ppVnode
==
NULL
)
{
terrno
=
TSDB_CODE_VND_INVALID_VGROUP_ID
;
...
...
@@ -497,7 +494,7 @@ static void vnodeBuildVloadMsg(SVnodeObj *pVnode, SStatusMsg *pStatus) {
}
int32_t
vnodeGetVnodeList
(
int32_t
vnodeList
[],
int32_t
*
numOfVnodes
)
{
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
ts
Dnode
VnodesHash
);
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
tsVnodesHash
);
while
(
taosHashIterNext
(
pIter
))
{
SVnodeObj
**
pVnode
=
taosHashIterGet
(
pIter
);
if
(
pVnode
==
NULL
)
continue
;
...
...
@@ -518,7 +515,7 @@ int32_t vnodeGetVnodeList(int32_t vnodeList[], int32_t *numOfVnodes) {
void
vnodeBuildStatusMsg
(
void
*
param
)
{
SStatusMsg
*
pStatus
=
param
;
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
ts
Dnode
VnodesHash
);
SHashMutableIterator
*
pIter
=
taosHashCreateIter
(
tsVnodesHash
);
while
(
taosHashIterNext
(
pIter
))
{
SVnodeObj
**
pVnode
=
taosHashIterGet
(
pIter
);
...
...
@@ -547,7 +544,7 @@ void vnodeSetAccess(SVgroupAccess *pAccess, int32_t numOfVnodes) {
static
void
vnodeCleanUp
(
SVnodeObj
*
pVnode
)
{
// remove from hash, so new messages wont be consumed
taosHashRemove
(
ts
Dnode
VnodesHash
,
(
const
char
*
)
&
pVnode
->
vgId
,
sizeof
(
int32_t
));
taosHashRemove
(
tsVnodesHash
,
(
const
char
*
)
&
pVnode
->
vgId
,
sizeof
(
int32_t
));
if
(
pVnode
->
status
!=
TAOS_VN_STATUS_INIT
)
{
// it may be in updateing or reset state, then it shall wait
...
...
@@ -580,10 +577,12 @@ static int vnodeProcessTsdbStatus(void *arg, int status) {
if
(
status
==
TSDB_STATUS_COMMIT_START
)
{
pVnode
->
fversion
=
pVnode
->
version
;
vDebug
(
"vgId:%d, start commit, fver:%"
PRIu64
" vver:%"
PRIu64
,
pVnode
->
vgId
,
pVnode
->
fversion
,
pVnode
->
version
);
return
walRenew
(
pVnode
->
wal
);
}
if
(
status
==
TSDB_STATUS_COMMIT_OVER
)
{
vDebug
(
"vgId:%d, commit over, fver:%"
PRIu64
" vver:%"
PRIu64
,
pVnode
->
vgId
,
pVnode
->
fversion
,
pVnode
->
version
);
return
vnodeSaveVersion
(
pVnode
);
}
...
...
@@ -659,11 +658,12 @@ static int vnodeResetTsdb(SVnodeObj *pVnode) {
static
int
vnodeNotifyFileSynced
(
void
*
ahandle
,
uint64_t
fversion
)
{
SVnodeObj
*
pVnode
=
ahandle
;
vDebug
(
"vgId:%d, data file is synced, fversion:%"
PRId64
,
pVnode
->
vgId
,
fversion
);
pVnode
->
fversion
=
fversion
;
pVnode
->
version
=
fversion
;
vnodeSaveVersion
(
pVnode
);
vDebug
(
"vgId:%d, data file is synced, fver:%"
PRIu64
" vver:%"
PRIu64
,
pVnode
->
vgId
,
pVnode
->
fversion
,
pVnode
->
version
);
return
vnodeResetTsdb
(
pVnode
);
}
src/vnode/src/vnodeRead.c
浏览文件 @
d583a4ca
...
...
@@ -15,13 +15,10 @@
#define _DEFAULT_SOURCE
#define _NON_BLOCKING_RETRIEVE 0
#include "os.h"
#include "tglobal.h"
#include "taoserror.h"
#include "taosmsg.h"
#include "tcache.h"
#include "query.h"
#include "trpc.h"
#include "tsdb.h"
...
...
@@ -29,9 +26,9 @@
#include "vnodeInt.h"
#include "tqueue.h"
static
int32_t
(
*
vnodeProcessReadMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SVnodeObj
*
pVnode
,
SVReadMsg
*
pRead
Msg
);
static
int32_t
vnodeProcessQueryMsg
(
SVnodeObj
*
pVnode
,
SVReadMsg
*
pRead
Msg
);
static
int32_t
vnodeProcessFetchMsg
(
SVnodeObj
*
pVnode
,
SVReadMsg
*
pRead
Msg
);
static
int32_t
(
*
vnodeProcessReadMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SVnodeObj
*
pVnode
,
SVReadMsg
*
pRead
);
static
int32_t
vnodeProcessQueryMsg
(
SVnodeObj
*
pVnode
,
SVReadMsg
*
pRead
);
static
int32_t
vnodeProcessFetchMsg
(
SVnodeObj
*
pVnode
,
SVReadMsg
*
pRead
);
static
int32_t
vnodeNotifyCurrentQhandle
(
void
*
handle
,
void
*
qhandle
,
int32_t
vgId
);
void
vnodeInitReadFp
(
void
)
{
...
...
@@ -44,16 +41,16 @@ void vnodeInitReadFp(void) {
// still required, or there will be a deadlock, so we don’t do any check here, but put the check codes before the
// request enters the queue
//
int32_t
vnodeProcessRead
(
void
*
param
,
SVReadMsg
*
pRead
Msg
)
{
int32_t
vnodeProcessRead
(
void
*
param
,
SVReadMsg
*
pRead
)
{
SVnodeObj
*
pVnode
=
(
SVnodeObj
*
)
param
;
int32_t
msgType
=
pRead
Msg
->
msgType
;
int32_t
msgType
=
pRead
->
msgType
;
if
(
vnodeProcessReadMsgFp
[
msgType
]
==
NULL
)
{
vDebug
(
"vgId:%d, msgType:%s not processed, no handle"
,
pVnode
->
vgId
,
taosMsg
[
msgType
]);
return
TSDB_CODE_VND_MSG_NOT_PROCESSED
;
}
return
(
*
vnodeProcessReadMsgFp
[
msgType
])(
pVnode
,
pRead
Msg
);
return
(
*
vnodeProcessReadMsgFp
[
msgType
])(
pVnode
,
pRead
);
}
static
int32_t
vnodeCheckRead
(
void
*
param
)
{
...
...
@@ -180,27 +177,27 @@ static void vnodeBuildNoResultQueryRsp(SRspRet *pRet) {
pRsp
->
completed
=
true
;
}
static
int32_t
vnodeProcessQueryMsg
(
SVnodeObj
*
pVnode
,
SVReadMsg
*
pRead
Msg
)
{
void
*
pCont
=
pRead
Msg
->
pCont
;
int32_t
contLen
=
pRead
Msg
->
contLen
;
SRspRet
*
pRet
=
&
pRead
Msg
->
rspRet
;
static
int32_t
vnodeProcessQueryMsg
(
SVnodeObj
*
pVnode
,
SVReadMsg
*
pRead
)
{
void
*
pCont
=
pRead
->
pCont
;
int32_t
contLen
=
pRead
->
contLen
;
SRspRet
*
pRet
=
&
pRead
->
rspRet
;
SQueryTableMsg
*
pQueryTableMsg
=
(
SQueryTableMsg
*
)
pCont
;
memset
(
pRet
,
0
,
sizeof
(
SRspRet
));
// qHandle needs to be freed correctly
if
(
pRead
Msg
->
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
)
{
SRetrieveTableMsg
*
killQueryMsg
=
(
SRetrieveTableMsg
*
)
pRead
Msg
->
pCont
;
if
(
pRead
->
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
)
{
SRetrieveTableMsg
*
killQueryMsg
=
(
SRetrieveTableMsg
*
)
pRead
->
pCont
;
killQueryMsg
->
free
=
htons
(
killQueryMsg
->
free
);
killQueryMsg
->
qhandle
=
htobe64
(
killQueryMsg
->
qhandle
);
vWarn
(
"QInfo:%p connection %p broken, kill query"
,
(
void
*
)
killQueryMsg
->
qhandle
,
pRead
Msg
->
rpcHandle
);
assert
(
pRead
Msg
->
contLen
>
0
&&
killQueryMsg
->
free
==
1
);
vWarn
(
"QInfo:%p connection %p broken, kill query"
,
(
void
*
)
killQueryMsg
->
qhandle
,
pRead
->
rpcHandle
);
assert
(
pRead
->
contLen
>
0
&&
killQueryMsg
->
free
==
1
);
void
**
qhandle
=
qAcquireQInfo
(
pVnode
->
qMgmt
,
(
uint64_t
)
killQueryMsg
->
qhandle
);
if
(
qhandle
==
NULL
||
*
qhandle
==
NULL
)
{
vWarn
(
"QInfo:%p invalid qhandle, no matched query handle, conn:%p"
,
(
void
*
)
killQueryMsg
->
qhandle
,
pRead
Msg
->
rpcHandle
);
pRead
->
rpcHandle
);
}
else
{
assert
(
*
qhandle
==
(
void
*
)
killQueryMsg
->
qhandle
);
...
...
@@ -242,9 +239,9 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) {
}
if
(
handle
!=
NULL
&&
vnodeNotifyCurrentQhandle
(
pRead
Msg
->
rpcHandle
,
*
handle
,
pVnode
->
vgId
)
!=
TSDB_CODE_SUCCESS
)
{
vnodeNotifyCurrentQhandle
(
pRead
->
rpcHandle
,
*
handle
,
pVnode
->
vgId
)
!=
TSDB_CODE_SUCCESS
)
{
vError
(
"vgId:%d, QInfo:%p, query discarded since link is broken, %p"
,
pVnode
->
vgId
,
*
handle
,
pRead
Msg
->
rpcHandle
);
pRead
->
rpcHandle
);
pRsp
->
code
=
TSDB_CODE_RPC_NETWORK_UNAVAIL
;
qReleaseQInfo
(
pVnode
->
qMgmt
,
(
void
**
)
&
handle
,
true
);
return
pRsp
->
code
;
...
...
@@ -255,7 +252,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) {
if
(
handle
!=
NULL
)
{
vDebug
(
"vgId:%d, QInfo:%p, dnode query msg disposed, create qhandle and returns to app"
,
vgId
,
*
handle
);
code
=
vnodePutItemIntoReadQueue
(
pVnode
,
handle
,
pRead
Msg
->
rpcHandle
);
code
=
vnodePutItemIntoReadQueue
(
pVnode
,
handle
,
pRead
->
rpcHandle
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pRsp
->
code
=
code
;
qReleaseQInfo
(
pVnode
->
qMgmt
,
(
void
**
)
&
handle
,
true
);
...
...
@@ -264,7 +261,7 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) {
}
}
else
{
assert
(
pCont
!=
NULL
);
void
**
qhandle
=
(
void
**
)
pRead
Msg
->
qhandle
;
void
**
qhandle
=
(
void
**
)
pRead
->
qhandle
;
vDebug
(
"vgId:%d, QInfo:%p, dnode continues to exec query"
,
pVnode
->
vgId
,
*
qhandle
);
...
...
@@ -276,14 +273,14 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) {
// build query rsp, the retrieve request has reached here already
if
(
buildRes
)
{
// update the connection info according to the retrieve connection
pRead
Msg
->
rpcHandle
=
qGetResultRetrieveMsg
(
*
qhandle
);
assert
(
pRead
Msg
->
rpcHandle
!=
NULL
);
pRead
->
rpcHandle
=
qGetResultRetrieveMsg
(
*
qhandle
);
assert
(
pRead
->
rpcHandle
!=
NULL
);
vDebug
(
"vgId:%d, QInfo:%p, start to build retrieval rsp after query paused, %p"
,
pVnode
->
vgId
,
*
qhandle
,
pRead
Msg
->
rpcHandle
);
pRead
->
rpcHandle
);
// set the real rsp error code
pRead
Msg
->
code
=
vnodeDumpQueryResult
(
&
pRead
->
rspRet
,
pVnode
,
qhandle
,
&
freehandle
,
pReadMsg
->
rpcHandle
);
pRead
->
code
=
vnodeDumpQueryResult
(
&
pRead
->
rspRet
,
pVnode
,
qhandle
,
&
freehandle
,
pRead
->
rpcHandle
);
// NOTE: set return code to be TSDB_CODE_QRY_HAS_RSP to notify dnode to return msg to client
code
=
TSDB_CODE_QRY_HAS_RSP
;
...
...
@@ -308,16 +305,16 @@ static int32_t vnodeProcessQueryMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) {
return
code
;
}
static
int32_t
vnodeProcessFetchMsg
(
SVnodeObj
*
pVnode
,
SVReadMsg
*
pRead
Msg
)
{
void
*
pCont
=
pRead
Msg
->
pCont
;
SRspRet
*
pRet
=
&
pRead
Msg
->
rspRet
;
static
int32_t
vnodeProcessFetchMsg
(
SVnodeObj
*
pVnode
,
SVReadMsg
*
pRead
)
{
void
*
pCont
=
pRead
->
pCont
;
SRspRet
*
pRet
=
&
pRead
->
rspRet
;
SRetrieveTableMsg
*
pRetrieve
=
pCont
;
pRetrieve
->
free
=
htons
(
pRetrieve
->
free
);
pRetrieve
->
qhandle
=
htobe64
(
pRetrieve
->
qhandle
);
vDebug
(
"vgId:%d, QInfo:%p, retrieve msg is disposed, free:%d, conn:%p"
,
pVnode
->
vgId
,
(
void
*
)
pRetrieve
->
qhandle
,
pRetrieve
->
free
,
pRead
Msg
->
rpcHandle
);
pRetrieve
->
free
,
pRead
->
rpcHandle
);
memset
(
pRet
,
0
,
sizeof
(
SRspRet
));
...
...
@@ -348,8 +345,8 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) {
}
// register the qhandle to connect to quit query immediate if connection is broken
if
(
vnodeNotifyCurrentQhandle
(
pRead
Msg
->
rpcHandle
,
*
handle
,
pVnode
->
vgId
)
!=
TSDB_CODE_SUCCESS
)
{
vError
(
"vgId:%d, QInfo:%p, retrieve discarded since link is broken, %p"
,
pVnode
->
vgId
,
*
handle
,
pRead
Msg
->
rpcHandle
);
if
(
vnodeNotifyCurrentQhandle
(
pRead
->
rpcHandle
,
*
handle
,
pVnode
->
vgId
)
!=
TSDB_CODE_SUCCESS
)
{
vError
(
"vgId:%d, QInfo:%p, retrieve discarded since link is broken, %p"
,
pVnode
->
vgId
,
*
handle
,
pRead
->
rpcHandle
);
code
=
TSDB_CODE_RPC_NETWORK_UNAVAIL
;
qKillQuery
(
*
handle
);
qReleaseQInfo
(
pVnode
->
qMgmt
,
(
void
**
)
&
handle
,
true
);
...
...
@@ -359,7 +356,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) {
bool
freeHandle
=
true
;
bool
buildRes
=
false
;
code
=
qRetrieveQueryResultInfo
(
*
handle
,
&
buildRes
,
pRead
Msg
->
rpcHandle
);
code
=
qRetrieveQueryResultInfo
(
*
handle
,
&
buildRes
,
pRead
->
rpcHandle
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// TODO handle malloc failure
pRet
->
rsp
=
(
SRetrieveTableRsp
*
)
rpcMallocCont
(
sizeof
(
SRetrieveTableRsp
));
...
...
@@ -370,7 +367,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) {
assert
(
buildRes
==
true
);
#if _NON_BLOCKING_RETRIEVE
if
(
!
buildRes
)
{
assert
(
pRead
Msg
->
rpcHandle
!=
NULL
);
assert
(
pRead
->
rpcHandle
!=
NULL
);
qReleaseQInfo
(
pVnode
->
qMgmt
,
(
void
**
)
&
handle
,
false
);
return
TSDB_CODE_QRY_NOT_READY
;
...
...
@@ -378,7 +375,7 @@ static int32_t vnodeProcessFetchMsg(SVnodeObj *pVnode, SVReadMsg *pReadMsg) {
#endif
// ahandle is the sqlObj pointer
code
=
vnodeDumpQueryResult
(
pRet
,
pVnode
,
handle
,
&
freeHandle
,
pRead
Msg
->
rpcHandle
);
code
=
vnodeDumpQueryResult
(
pRet
,
pVnode
,
handle
,
&
freeHandle
,
pRead
->
rpcHandle
);
}
// If qhandle is not added into vread queue, the query should be completed already or paused with error.
...
...
src/vnode/src/vnodeVersion.c
浏览文件 @
d583a4ca
...
...
@@ -61,10 +61,10 @@ int32_t vnodeReadVersion(SVnodeObj *pVnode) {
vError
(
"vgId:%d, failed to read %s, version not found"
,
pVnode
->
vgId
,
file
);
goto
PARSE_VER_ERROR
;
}
pVnode
->
version
=
ver
->
valueint
;
pVnode
->
version
=
(
uint64_t
)
ver
->
valueint
;
terrno
=
TSDB_CODE_SUCCESS
;
vInfo
(
"vgId:%d, read %s successfully,
version:%"
PRId
64
,
pVnode
->
vgId
,
file
,
pVnode
->
version
);
vInfo
(
"vgId:%d, read %s successfully,
fver:%"
PRIu
64
,
pVnode
->
vgId
,
file
,
pVnode
->
version
);
PARSE_VER_ERROR:
if
(
content
!=
NULL
)
free
(
content
);
...
...
@@ -89,7 +89,7 @@ int32_t vnodeSaveVersion(SVnodeObj *pVnode) {
char
*
content
=
calloc
(
1
,
maxLen
+
1
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"{
\n
"
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
version
\"
: %"
PRI
d
64
"
\n
"
,
pVnode
->
fversion
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"
\"
version
\"
: %"
PRI
u
64
"
\n
"
,
pVnode
->
fversion
);
len
+=
snprintf
(
content
+
len
,
maxLen
-
len
,
"}
\n
"
);
fwrite
(
content
,
1
,
len
,
fp
);
...
...
@@ -98,6 +98,6 @@ int32_t vnodeSaveVersion(SVnodeObj *pVnode) {
free
(
content
);
terrno
=
0
;
vInfo
(
"vgId:%d, successed to write %s,
version:%"
PRId
64
,
pVnode
->
vgId
,
file
,
pVnode
->
fversion
);
vInfo
(
"vgId:%d, successed to write %s,
fver:%"
PRIu
64
,
pVnode
->
vgId
,
file
,
pVnode
->
fversion
);
return
TSDB_CODE_SUCCESS
;
}
\ No newline at end of file
src/vnode/src/vnodeWrite.c
浏览文件 @
d583a4ca
...
...
@@ -19,7 +19,6 @@
#include "taoserror.h"
#include "tqueue.h"
#include "trpc.h"
#include "tutil.h"
#include "tsdb.h"
#include "twal.h"
#include "tsync.h"
...
...
@@ -53,20 +52,24 @@ int32_t vnodeProcessWrite(void *vparam, void *wparam, int32_t qtype, void *rpara
SRspRet
*
pRspRet
=
rparam
;
if
(
vnodeProcessWriteMsgFp
[
pHead
->
msgType
]
==
NULL
)
{
vDebug
(
"vgId:%d, msgType:%s not processed, no handle"
,
pVnode
->
vgId
,
taosMsg
[
pHead
->
msgType
]);
vError
(
"vgId:%d, msg:%s not processed since no handle, qtype:%s hver:%"
PRIu64
,
pVnode
->
vgId
,
taosMsg
[
pHead
->
msgType
],
qtypeStr
[
qtype
],
pHead
->
version
);
return
TSDB_CODE_VND_MSG_NOT_PROCESSED
;
}
vTrace
(
"vgId:%d, msg:%s will be processed in vnode, qtype:%s hver:%"
PRIu64
" vver:%"
PRIu64
,
pVnode
->
vgId
,
taosMsg
[
pHead
->
msgType
],
qtypeStr
[
qtype
],
pHead
->
version
,
pVnode
->
version
);
if
(
pHead
->
version
==
0
)
{
// from client or CQ
if
(
pVnode
->
status
!=
TAOS_VN_STATUS_READY
)
{
vDebug
(
"vgId:%d, msg
Type:%s not processed, vnode status is %d"
,
pVnode
->
vgId
,
taosMsg
[
pHead
->
msgType
]
,
pVnode
->
status
);
vDebug
(
"vgId:%d, msg
:%s not processed since vstatus:%d, qtype:%s hver:%"
PRIu64
,
pVnode
->
vgId
,
taosMsg
[
pHead
->
msgType
],
pVnode
->
status
,
qtypeStr
[
qtype
],
pHead
->
version
);
return
TSDB_CODE_APP_NOT_READY
;
// it may be in deleting or closing state
}
if
(
pVnode
->
role
!=
TAOS_SYNC_ROLE_MASTER
)
{
vDebug
(
"vgId:%d, msg
Type:%s not processed, replica:%d role:%s"
,
pVnode
->
vgId
,
taosMsg
[
pHead
->
msgType
]
,
pVnode
->
syncCfg
.
replica
,
syncRole
[
pVnode
->
role
]
);
vDebug
(
"vgId:%d, msg
:%s not processed since replica:%d role:%s, qtype:%s hver:%"
PRIu64
,
pVnode
->
vgId
,
taosMsg
[
pHead
->
msgType
],
pVnode
->
syncCfg
.
replica
,
syncRole
[
pVnode
->
role
],
qtypeStr
[
qtype
],
pHead
->
version
);
return
TSDB_CODE_APP_NOT_READY
;
}
...
...
@@ -185,7 +188,7 @@ static int32_t vnodeProcessAlterTableMsg(SVnodeObj *pVnode, void *pCont, SRspRet
static
int32_t
vnodeProcessDropStableMsg
(
SVnodeObj
*
pVnode
,
void
*
pCont
,
SRspRet
*
pRet
)
{
SDropSTableMsg
*
pTable
=
pCont
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
vDebug
(
"vgId:%d, stable:%s, start to drop"
,
pVnode
->
vgId
,
pTable
->
tableId
);
...
...
src/wal/src/walMgmt.c
浏览文件 @
d583a4ca
...
...
@@ -128,7 +128,7 @@ void walClose(void *handle) {
taosClose
(
pWal
->
fd
);
if
(
!
pWal
->
keep
)
{
if
(
pWal
->
keep
!=
TAOS_WAL_KEEP
)
{
int64_t
fileId
=
-
1
;
while
(
walGetNextFile
(
pWal
,
&
fileId
)
>=
0
)
{
snprintf
(
pWal
->
name
,
sizeof
(
pWal
->
name
),
"%s/%s%"
PRId64
,
pWal
->
path
,
WAL_PREFIX
,
fileId
);
...
...
src/wal/src/walWrite.c
浏览文件 @
d583a4ca
...
...
@@ -41,7 +41,7 @@ int32_t walRenew(void *handle) {
wDebug
(
"vgId:%d, file:%s, it is closed"
,
pWal
->
vgId
,
pWal
->
name
);
}
if
(
pWal
->
keep
)
{
if
(
pWal
->
keep
==
TAOS_WAL_KEEP
)
{
pWal
->
fileId
=
0
;
}
else
{
if
(
walGetNewFile
(
pWal
,
&
pWal
->
fileId
)
!=
0
)
pWal
->
fileId
=
0
;
...
...
@@ -58,7 +58,7 @@ int32_t walRenew(void *handle) {
wDebug
(
"vgId:%d, file:%s, it is created"
,
pWal
->
vgId
,
pWal
->
name
);
}
if
(
!
pWal
->
keep
)
{
if
(
pWal
->
keep
!=
TAOS_WAL_KEEP
)
{
// remove the oldest wal file
int64_t
oldFileId
=
-
1
;
if
(
walGetOldFile
(
pWal
,
pWal
->
fileId
,
WAL_FILE_NUM
,
&
oldFileId
)
==
0
)
{
...
...
@@ -99,8 +99,8 @@ int32_t walWrite(void *handle, SWalHead *pHead) {
code
=
TAOS_SYSTEM_ERROR
(
errno
);
wError
(
"vgId:%d, file:%s, failed to write since %s"
,
pWal
->
vgId
,
pWal
->
name
,
strerror
(
errno
));
}
else
{
wTrace
(
"vgId:%d,
fileId:%"
PRId64
" fd:%d, write wal ver:%"
PRId64
", head ver:%"
PRIu64
", len:%d
"
,
pWal
->
vgId
,
pWal
->
fileId
,
pWal
->
fd
,
p
Wal
->
version
,
pHead
->
version
,
pHead
->
len
);
wTrace
(
"vgId:%d,
write wal, fileId:%"
PRId64
" fd:%d hver:%"
PRId64
" wver:%"
PRIu64
" len:%d
"
,
pWal
->
vgId
,
pWal
->
fileId
,
pWal
->
fd
,
p
Head
->
version
,
pWal
->
version
,
pHead
->
len
);
pWal
->
version
=
pHead
->
version
;
}
...
...
@@ -144,12 +144,12 @@ int32_t walRestore(void *handle, void *pVnode, FWalWrite writeFp) {
continue
;
}
wDebug
(
"vgId:%d, file:%s, restore success
and keep it
"
,
pWal
->
vgId
,
walName
);
wDebug
(
"vgId:%d, file:%s, restore success"
,
pWal
->
vgId
,
walName
);
count
++
;
}
if
(
!
pWal
->
keep
)
return
TSDB_CODE_SUCCESS
;
if
(
pWal
->
keep
!=
TAOS_WAL_KEEP
)
return
TSDB_CODE_SUCCESS
;
if
(
count
==
0
)
{
wDebug
(
"vgId:%d, wal file not exist, renew it"
,
pWal
->
vgId
);
...
...
@@ -173,7 +173,6 @@ int32_t walGetWalFile(void *handle, char *fileName, int64_t *fileId) {
if
(
handle
==
NULL
)
return
-
1
;
SWal
*
pWal
=
handle
;
// for keep
if
(
*
fileId
==
0
)
*
fileId
=
-
1
;
pthread_mutex_lock
(
&
(
pWal
->
mutex
));
...
...
@@ -262,7 +261,7 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
}
if
(
!
taosCheckChecksumWhole
((
uint8_t
*
)
pHead
,
sizeof
(
SWalHead
)))
{
wError
(
"vgId:%d, file:%s, wal head cksum is messed up, ver:%"
PRIu64
" len:%d offset:%"
PRId64
,
pWal
->
vgId
,
name
,
wError
(
"vgId:%d, file:%s, wal head cksum is messed up,
h
ver:%"
PRIu64
" len:%d offset:%"
PRId64
,
pWal
->
vgId
,
name
,
pHead
->
version
,
pHead
->
len
,
offset
);
code
=
walSkipCorruptedRecord
(
pWal
,
pHead
,
fd
,
&
offset
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -298,8 +297,8 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
offset
=
offset
+
sizeof
(
SWalHead
)
+
pHead
->
len
;
wTrace
(
"vgId:%d,
fileId:%"
PRId64
", restore wal ver:%"
PRIu64
", head ver:%"
PRIu64
" len:%d"
,
pWal
->
vgId
,
file
Id
,
pWal
->
version
,
pHead
->
version
,
pHead
->
len
);
wTrace
(
"vgId:%d,
restore wal, fileId:%"
PRId64
" hver:%"
PRIu64
" wver:%"
PRIu64
" len:%d"
,
pWal
->
vg
Id
,
fileId
,
pHead
->
version
,
pWal
->
version
,
pHead
->
len
);
pWal
->
version
=
pHead
->
version
;
(
*
writeFp
)(
pVnode
,
pHead
,
TAOS_QTYPE_WAL
,
NULL
);
...
...
@@ -311,7 +310,7 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch
return
code
;
}
int64_t
walGetVersion
(
twalh
param
)
{
u
int64_t
walGetVersion
(
twalh
param
)
{
SWal
*
pWal
=
param
;
if
(
pWal
==
0
)
return
0
;
...
...
src/wal/test/waltest.c
浏览文件 @
d583a4ca
...
...
@@ -37,7 +37,6 @@ int writeToQueue(void *pVnode, void *data, int type, void *pMsg) {
int
main
(
int
argc
,
char
*
argv
[])
{
char
path
[
128
]
=
"/home/jhtao/test/wal"
;
int
max
=
3
;
int
level
=
2
;
int
total
=
5
;
int
rows
=
10000
;
...
...
@@ -47,8 +46,6 @@ int main(int argc, char *argv[]) {
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
if
(
strcmp
(
argv
[
i
],
"-p"
)
==
0
&&
i
<
argc
-
1
)
{
tstrncpy
(
path
,
argv
[
++
i
],
sizeof
(
path
));
}
else
if
(
strcmp
(
argv
[
i
],
"-m"
)
==
0
&&
i
<
argc
-
1
)
{
max
=
atoi
(
argv
[
++
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-l"
)
==
0
&&
i
<
argc
-
1
)
{
level
=
atoi
(
argv
[
++
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-r"
)
==
0
&&
i
<
argc
-
1
)
{
...
...
@@ -66,7 +63,6 @@ int main(int argc, char *argv[]) {
}
else
{
printf
(
"
\n
usage: %s [options]
\n
"
,
argv
[
0
]);
printf
(
" [-p path]: wal file path default is:%s
\n
"
,
path
);
printf
(
" [-m max]: max wal files, default is:%d
\n
"
,
max
);
printf
(
" [-l level]: log level, default is:%d
\n
"
,
level
);
printf
(
" [-t total]: total wal files, default is:%d
\n
"
,
total
);
printf
(
" [-r rows]: rows of records per wal file, default is:%d
\n
"
,
rows
);
...
...
@@ -82,7 +78,6 @@ int main(int argc, char *argv[]) {
SWalCfg
walCfg
;
walCfg
.
walLevel
=
level
;
walCfg
.
wals
=
max
;
walCfg
.
keep
=
keep
;
pWal
=
walOpen
(
path
,
&
walCfg
);
...
...
tests/perftest-scripts/perftest-query.sh
0 → 100755
浏览文件 @
d583a4ca
#!/bin/bash
today
=
`
date
+
"%Y%m%d"
`
WORK_DIR
=
/home/ubuntu/pxiao/
PERFORMANCE_TEST_REPORT
=
$TDENGINE_DIR
/tests/performance-test-report-
$today
.log
# Coloured Echoes #
function
red_echo
{
echo
-e
"
\0
33[31m
$@
\0
33[0m"
;
}
#
function
green_echo
{
echo
-e
"
\0
33[32m
$@
\0
33[0m"
;
}
#
function
yellow_echo
{
echo
-e
"
\0
33[33m
$@
\0
33[0m"
;
}
#
function
white_echo
{
echo
-e
"
\0
33[1;37m
$@
\0
33[0m"
;
}
#
# Coloured Printfs #
function
red_printf
{
printf
"
\0
33[31m
$@
\0
33[0m"
;
}
#
function
green_printf
{
printf
"
\0
33[32m
$@
\0
33[0m"
;
}
#
function
yellow_printf
{
printf
"
\0
33[33m
$@
\0
33[0m"
;
}
#
function
white_printf
{
printf
"
\0
33[1;37m
$@
\0
33[0m"
;
}
#
# Debugging Outputs #
function
white_brackets
{
local
args
=
"
$@
"
;
white_printf
"["
;
printf
"
${
args
}
"
;
white_printf
"]"
;
}
#
function
echoInfo
{
local
args
=
"
$@
"
;
white_brackets
$(
green_printf
"INFO"
)
&&
echo
"
${
args
}
"
;
}
#
function
echoWarn
{
local
args
=
"
$@
"
;
echo
"
$(
white_brackets
"
$(
yellow_printf
"WARN"
)
"
&&
echo
"
${
args
}
"
;
)
"
1>&2
;
}
#
function
echoError
{
local
args
=
"
$@
"
;
echo
"
$(
white_brackets
"
$(
red_printf
"ERROR"
)
"
&&
echo
"
${
args
}
"
;
)
"
1>&2
;
}
#
function
stopTaosd
{
echo
"Stop taosd"
systemctl stop taosd
snap stop tdengine
PID
=
`
ps
-ef
|grep
-w
taosd |
grep
-v
grep
|
awk
'{print $2}'
`
while
[
-n
"
$PID
"
]
do
pkill
-TERM
-x
taosd
sleep
1
PID
=
`
ps
-ef
|grep
-w
taosd |
grep
-v
grep
|
awk
'{print $2}'
`
done
}
function
buildTDengine
{
echoInfo
"Build TDengine"
cd
$WORK_DIR
/TDengine
git remote update
>
/dev/null
REMOTE_COMMIT
=
`
git rev-parse
--short
remotes/origin/develop
`
LOCAL_COMMIT
=
`
git rev-parse
--short
@
`
echo
" LOCAL:
$LOCAL_COMMIT
"
echo
"REMOTE:
$REMOTE_COMMIT
"
if
[
"
$LOCAL_COMMIT
"
==
"
$REMOTE_COMMIT
"
]
;
then
echo
"repo up-to-date"
else
echo
"repo need to pull"
git pull
>
/dev/null
LOCAL_COMMIT
=
`
git rev-parse
--short
@
`
cd
debug
rm
-rf
*
cmake ..
>
/dev/null
make
>
/dev/null
make
install
fi
}
function
runQueryPerfTest
{
nohup
$WORK_DIR
/TDengine/debug/build/bin/taosd
-c
/etc/taodperf/
>
/dev/null 2>&1 &
echoInfo
"Run Performance Test"
cd
$WORK_DIR
/TDengine/tests/pytest
python3 query/queryPerformance.py |
tee
-a
$PERFORMANCE_TEST_REPORT
}
function
sendReport
{
echo
"send report"
receiver
=
"pxiao@taosdata.com"
mimebody
=
"MIME-Version: 1.0
\n
Content-Type: text/html; charset=utf-8
\n
"
cd
$TDENGINE_DIR
sed
-i
's/\x1b\[[0-9;]*m//g'
$PERFORMANCE_TEST_REPORT
BODY_CONTENT
=
`
cat
$PERFORMANCE_TEST_REPORT
`
echo
-e
"to:
${
receiver
}
\n
subject: Query Performace Report
${
today
}
, commit ID:
${
LOCAL_COMMIT
}
\n\n
${
today
}
:
\n
${
BODY_CONTENT
}
"
|
\
(
cat
-
&&
uuencode
$PERFORMANCE_TEST_REPORT
performance-test-report-
$today
.log
)
|
\
ssmtp
"
${
receiver
}
"
&&
echo
"Report Sent!"
}
stopTaosd
buildTDengine
runQueryPerfTest
echoInfo
"Send Report"
sendReport
echoInfo
"End of Test"
tests/pytest/crash_gen/crash_gen_main.py
浏览文件 @
d583a4ca
...
...
@@ -2043,6 +2043,7 @@ class ThreadStacks: # stack info for all threads
print
(
"[{sf}] File {filename}, line {lineno}, in {name}"
.
format
(
sf
=
stackFrame
,
filename
=
frame
.
filename
,
lineno
=
frame
.
lineno
,
name
=
frame
.
name
))
print
(
" {}"
.
format
(
frame
.
line
))
stackFrame
+=
1
print
(
"-----> End of Thread Info ----->
\n
"
)
class
ClientManager
:
...
...
tests/pytest/fulltest.sh
浏览文件 @
d583a4ca
...
...
@@ -221,3 +221,6 @@ python3 ./test.py -f update/merge_commit_data2.py
python3 ./test.py
-f
update/merge_commit_data2_update0.py
python3 ./test.py
-f
update/merge_commit_last-0.py
python3 ./test.py
-f
update/merge_commit_last.py
# wal
python3 ./test.py
-f
wal/addOldWalTest.py
\ No newline at end of file
tests/pytest/insert/ningsiInsert.py
0 → 100644
浏览文件 @
d583a4ca
###################################################################
# 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
requests
,
json
import
threading
import
string
import
random
import
time
class
RestfulInsert
:
def
init
(
self
):
self
.
header
=
{
'Authorization'
:
'Basic cm9vdDp0YW9zZGF0YQ=='
}
self
.
url
=
"http://ningsi60:6041/rest/sql"
self
.
ts
=
1104508800000
self
.
numOfThreads
=
10
self
.
numOfTables
=
3000
self
.
dbName
=
'netmonitortaos'
self
.
stbName
=
'devinfomt'
self
.
prefix
=
'dev'
def
get_random_string
(
self
,
length
):
letters
=
string
.
ascii_lowercase
result_str
=
''
.
join
(
random
.
choice
(
letters
)
for
i
in
range
(
length
))
return
result_str
def
createTables
(
self
,
threadID
):
print
(
"create table: thread %d started"
%
threadID
)
tablesPerThread
=
int
(
self
.
numOfTables
/
self
.
numOfThreads
)
for
i
in
range
(
tablesPerThread
):
data
=
"create table '%s'.dev_%d using '%s'.'%s' tags('%s', '%s')"
%
(
self
.
dbName
,
i
+
threadID
*
tablesPerThread
,
self
.
dbName
,
self
.
stbName
,
self
.
get_random_string
(
25
),
self
.
get_random_string
(
25
))
response
=
requests
.
post
(
self
.
url
,
data
,
headers
=
self
.
header
)
if
response
.
status_code
!=
200
:
print
(
response
.
content
)
def
insertData
(
self
,
threadID
):
print
(
"insert data: thread %d started"
%
threadID
)
tablesPerThread
=
int
(
self
.
numOfTables
/
self
.
numOfThreads
)
base_ts
=
self
.
ts
while
True
:
i
=
0
for
i
in
range
(
tablesPerThread
):
data
=
"insert into %s.dev_%d values(%d, '%s', '%s', %d, %d, %d)"
%
(
self
.
dbName
,
i
+
threadID
*
tablesPerThread
,
base_ts
,
self
.
get_random_string
(
25
),
self
.
get_random_string
(
30
),
random
.
randint
(
1
,
10000
),
random
.
randint
(
1
,
10000
),
random
.
randint
(
1
,
10000
))
response
=
requests
.
post
(
self
.
url
,
data
,
headers
=
self
.
header
)
if
response
.
status_code
!=
200
:
print
(
response
.
content
)
time
.
sleep
(
30
)
base_ts
=
base_ts
+
1
def
run
(
self
):
data
=
"create database if not exists %s keep 7300"
%
self
.
dbName
requests
.
post
(
self
.
url
,
data
,
headers
=
self
.
header
)
data
=
"create table '%s'.'%s' (timeid timestamp, devdesc binary(50), devname binary(50), cpu bigint, temp bigint, ram bigint) tags(devid binary(50), modelid binary(50))"
%
(
self
.
dbName
,
self
.
stbName
)
requests
.
post
(
self
.
url
,
data
,
headers
=
self
.
header
)
threads
=
[]
for
i
in
range
(
self
.
numOfThreads
):
thread
=
threading
.
Thread
(
target
=
self
.
createTables
,
args
=
(
i
,))
thread
.
start
()
threads
.
append
(
thread
)
for
i
in
range
(
self
.
numOfThreads
):
threads
[
i
].
join
()
threads
=
[]
for
i
in
range
(
self
.
numOfThreads
):
thread
=
threading
.
Thread
(
target
=
self
.
insertData
,
args
=
(
i
,))
thread
.
start
()
threads
.
append
(
thread
)
for
i
in
range
(
self
.
numOfThreads
):
threads
[
i
].
join
()
ri
=
RestfulInsert
()
ri
.
init
()
ri
.
run
()
tests/pytest/query/query_performance.py
0 → 100644
浏览文件 @
d583a4ca
import
time
import
taos
import
csv
import
numpy
as
np
import
random
import
os
import
requests
import
json
import
sys
"""
需要第三方库: taos,requests,numpy
当前机器已经启动taosd服务
使用方法见底部示例
"""
class
Ding
:
"""
发送消息到钉钉,
urls: 钉钉群的token组成的list,可以发多个钉钉群,需要提前加白名单或其他放行策略
at_mobiles: 需要@的人的手机号组成的list
msg: 要发送的str
"""
def
__init__
(
self
,
url_list
,
at_mobiles
):
self
.
urls
=
url_list
self
.
at_mobiles
=
at_mobiles
def
send_message
(
self
,
msg
):
data1
=
{
"msgtype"
:
"text"
,
"text"
:
{
"content"
:
msg
},
"at"
:
{
"atMobiles"
:
self
.
at_mobiles
,
"isAtAll"
:
False
}
}
header
=
{
'Content-Type'
:
'application/json; charset=utf-8'
}
for
url
in
self
.
urls
:
requests
.
post
(
url
=
url
,
data
=
json
.
dumps
(
data1
),
headers
=
header
)
class
TDConn
:
def
__init__
(
self
,
config
:
dict
):
self
.
host
=
config
[
'host'
]
self
.
user
=
config
[
'user'
]
self
.
password
=
config
[
'password'
]
self
.
config
=
config
[
'config'
]
self
.
conn
=
None
self
.
cursor
=
None
def
connect
(
self
):
conn
=
taos
.
connect
(
host
=
self
.
host
,
user
=
self
.
user
,
password
=
self
.
password
,
config
=
self
.
config
)
cursor
=
conn
.
cursor
()
self
.
conn
=
conn
self
.
cursor
=
cursor
print
(
'connect ...'
)
return
self
.
cursor
def
close
(
self
):
self
.
cursor
.
close
()
self
.
conn
.
close
()
print
(
'close ... '
)
class
Tool
:
"""
可能有用
"""
@
staticmethod
def
str_gen
(
num
):
return
''
.
join
(
random
.
sample
(
'abcdefghijklmnopqrstuvwxyz'
,
num
))
@
staticmethod
def
float_gen
(
n
,
m
):
return
random
.
uniform
(
n
,
m
)
@
staticmethod
def
int_gen
(
n
,
m
):
return
random
.
randint
(
n
,
m
)
class
Demo
:
def
__init__
(
self
,
engine
):
self
.
engine
=
engine
[
'engine'
](
engine
[
'config'
])
self
.
cursor
=
self
.
engine
.
connect
()
def
date_gen
(
self
,
db
,
number_per_table
,
type_of_cols
,
num_of_cols_per_record
,
num_of_tables
):
"""
:目前都是 taosdemo 的参数
:return:
"""
sql
=
'yes | sudo taosdemo -d {db} -n {number_per_table} -b {type_of_cols} -l {num_of_cols_per_record} '
\
'-t {num_of_tables}'
.
format
(
db
=
db
,
number_per_table
=
number_per_table
,
type_of_cols
=
type_of_cols
,
num_of_cols_per_record
=
num_of_cols_per_record
,
num_of_tables
=
num_of_tables
)
os
.
system
(
sql
)
print
(
'insert data completed'
)
# def main(self, db, circle, csv_name, case_func, result_csv, nums, ding_flag):
def
main
(
self
,
every_num_per_table
,
result_csv
,
all_result_csv
,
values
):
db
=
values
[
'db_name'
]
number_per_table
=
every_num_per_table
type_of_cols
=
values
[
'col_type'
]
num_of_cols_per_record
=
values
[
'col_num'
]
num_of_tables
=
values
[
'table_num'
]
self
.
date_gen
(
db
=
db
,
number_per_table
=
number_per_table
,
type_of_cols
=
type_of_cols
,
num_of_cols_per_record
=
num_of_cols_per_record
,
num_of_tables
=
num_of_tables
)
circle
=
values
[
'circle'
]
# print(every_num_per_table, result_csv, values)
csv_name
=
result_csv
case_func
=
values
[
'sql_func'
]
nums
=
num_of_tables
*
number_per_table
ding_flag
=
values
[
'ding_flag'
]
_data
=
[]
f
=
open
(
csv_name
,
'w'
,
encoding
=
'utf-8'
)
f1
=
open
(
all_result_csv
,
'a'
,
encoding
=
'utf-8'
)
csv_writer
=
csv
.
writer
(
f
)
csv_writer1
=
csv
.
writer
(
f1
)
csv_writer
.
writerow
([
"number"
,
"elapse"
,
'sql'
])
self
.
cursor
.
execute
(
'use {db};'
.
format
(
db
=
db
))
for
i
in
range
(
circle
):
self
.
cursor
.
execute
(
'reset query cache;'
)
sql
=
case_func
()
start
=
time
.
time
()
self
.
cursor
.
execute
(
sql
)
self
.
cursor
.
fetchall
()
end
=
time
.
time
()
_data
.
append
(
end
-
start
)
elapse
=
'%.4f'
%
(
end
-
start
)
print
(
sql
,
i
,
elapse
,
'
\n
'
)
csv_writer
.
writerow
([
i
+
1
,
elapse
,
sql
])
# time.sleep(1)
_list
=
[
nums
,
np
.
mean
(
_data
)]
_str
=
'总数据: %s 条 , table数: %s , 每个table数据数: %s , 数据类型: %s
\n
'
%
\
(
nums
,
num_of_tables
,
number_per_table
,
type_of_cols
)
# print('avg : ', np.mean(_data), '\n')
_str
+=
'平均值 : %.4f 秒
\n
'
%
np
.
mean
(
_data
)
for
each
in
(
50
,
80
,
90
,
95
):
_list
.
append
(
np
.
percentile
(
_data
,
each
))
_str
+=
' %d 分位数 : %.4f 秒
\n
'
%
(
each
,
np
.
percentile
(
_data
,
each
))
print
(
_str
)
if
ding_flag
:
ding
=
Ding
(
values
[
'ding_config'
][
'urls'
],
values
[
'ding_config'
][
'at_mobiles'
])
ding
.
send_message
(
_str
)
csv_writer1
.
writerow
(
_list
)
f
.
close
()
f1
.
close
()
self
.
engine
.
close
()
def
run
(
engine
,
test_cases
:
dict
,
result_dir
):
for
each_case
,
values
in
test_cases
.
items
():
for
every_num_per_table
in
values
[
'number_per_table'
]:
result_csv
=
result_dir
+
'{case}_table{table_num}_{number_per_table}.csv'
.
\
format
(
case
=
each_case
,
table_num
=
values
[
'table_num'
],
number_per_table
=
every_num_per_table
)
all_result_csv
=
result_dir
+
'{case_all}_result.csv'
.
format
(
case_all
=
each_case
)
d
=
Demo
(
engine
)
# print(each_case, result_csv)
d
.
main
(
every_num_per_table
,
result_csv
,
all_result_csv
,
values
)
if
__name__
==
'__main__'
:
"""
测试用例在test_cases中添加。
result_dir: 报告生成目录,会生成每次测试结果,和具体某一用例的统计结果.需注意目录权限需要执行用户可写。
case1、case2 : 具体用例名称
engine: 数据库引擎,目前只有taosd。使用时需开启taosd服务。
table_num: 造数据时的table数目
circle: 循环测试次数,求平均值
number_per_table:需要传list,多个数值代表会按照list内的数值逐个测试
col_num:table col的数目
col_type: 表中数据类型
db_name: 造数据的db名,默认用test
sql_func: 当前测试的sql方法,需要自己定义
ding_flag: 如果需要钉钉发送数据,flag设置真值,
ding_config: 如ding_flag 设置为真值,此项才有意义。ding_flag为假时此项可以为空。urls传入一list,内容为要发送的群的token,
需提前设置白名单,at_mobiles传入一list,内容为在群内需要@的人的手机号
"""
engine_dict
=
{
'taosd'
:
{
'engine'
:
TDConn
,
'config'
:
{
'host'
:
'127.0.0.1'
,
'user'
:
'root'
,
'password'
:
'taosdata'
,
'config'
:
'/etc/taos'
}}
}
def
case1
():
return
'select * from meters where f1 = {n};'
.
format
(
n
=
random
.
randint
(
1
,
30
))
def
case2
():
return
'select * from meters where f1 = %.4f;'
%
random
.
uniform
(
1
,
30
)
result_dir
=
'/usr/local/demo/benchmarktestdata/'
test_cases
=
{
'case1'
:
{
'engine'
:
'taosd'
,
'table_num'
:
10
,
'circle'
:
100
,
'number_per_table'
:[
10
,
100
],
'col_num'
:
5
,
'col_type'
:
'INT'
,
'db_name'
:
'test'
,
'sql_func'
:
case1
,
'ding_flag'
:
True
,
'ding_config'
:
{
'urls'
:
[
r
'https://oapi.dingtalk.com/robot/send?access_token=xxxxxxx0cd93'
],
'at_mobiles'
:[
17000000000
,],}},
'case2'
:
{
'engine'
:
'taosd'
,
'table_num'
:
10
,
'circle'
:
50
,
'number_per_table'
:[
10
,
100
],
'col_num'
:
5
,
'col_type'
:
'FLOAT'
,
'db_name'
:
'test'
,
'sql_func'
:
case2
,
'ding_flag'
:
False
,
'ding_config'
:
None
}
}
run
(
engine_dict
[
'taosd'
],
test_cases
,
result_dir
)
tests/pytest/wal/addOldWalTest.py
0 → 100644
浏览文件 @
d583a4ca
###################################################################
# 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
os
import
taos
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.dnodes
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
())
def
createOldDir
(
self
):
oldDir
=
tdDnodes
.
getDnodesRootDir
()
+
"dnode1/data/vnode/vnode2/wal/old"
os
.
system
(
"sudo mkdir -p %s"
%
oldDir
)
def
createOldDirAndAddWal
(
self
):
oldDir
=
tdDnodes
.
getDnodesRootDir
()
+
"dnode1/data/vnode/vnode2/wal/old"
os
.
system
(
"sudo echo 'test' >> %s/wal"
%
oldDir
)
def
run
(
self
):
tdSql
.
prepare
()
tdSql
.
execute
(
"create table t1(ts timestamp, a int)"
)
tdSql
.
execute
(
"insert into t1 values(now, 1)"
)
# create old dir only
self
.
createOldDir
()
os
.
system
(
"sudo kill -9 $(pgrep taosd)"
)
tdDnodes
.
start
(
1
)
tdSql
.
execute
(
"use db"
)
tdSql
.
query
(
"select * from t1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
checkData
(
0
,
1
,
1
)
# create old dir and add wal under old dir
self
.
createOldDir
()
self
.
createOldDirAndAddWal
()
os
.
system
(
"sudo kill -9 $(pgrep taosd)"
)
tdDnodes
.
start
(
1
)
tdSql
.
query
(
"select * from t1"
)
tdSql
.
checkRows
(
1
)
tdSql
.
checkData
(
0
,
1
,
1
)
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
tests/test-all.sh
浏览文件 @
d583a4ca
...
...
@@ -26,7 +26,12 @@ function runPyCaseOneByOne {
while
read
-r
line
;
do
if
[[
$line
=
~ ^python.
*
]]
;
then
if
[[
$line
!=
*
sleep
*
]]
;
then
case
=
`
echo
$line
|awk
'{print $NF}'
`
if
[[
$line
=
~
'-r'
]]
;
then
case
=
`
echo
$line
|awk
'{print $4}'
`
else
case
=
`
echo
$line
|awk
'{print $NF}'
`
fi
start_time
=
`
date
+%s
`
$line
>
/dev/null 2>&1
&&
\
echo
-e
"
${
GREEN
}
$case
success
${
NC
}
"
|
tee
-a
pytest-out.log
||
\
...
...
tests/tsim/inc/sim.h
浏览文件 @
d583a4ca
...
...
@@ -100,7 +100,7 @@ typedef struct _cmd_t {
int16_t
cmdno
;
int16_t
nlen
;
char
name
[
MAX_SIM_CMD_NAME_LEN
];
bool
(
*
parseCmd
)(
char
*
,
struct
_cmd_t
*
,
int
);
bool
(
*
parseCmd
)(
char
*
,
struct
_cmd_t
*
,
int
32_t
);
bool
(
*
executeCmd
)(
struct
_script_t
*
script
,
char
*
option
);
struct
_cmd_t
*
next
;
}
SCommand
;
...
...
@@ -111,7 +111,7 @@ typedef struct {
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
int
optionOffset
;
// relative option offset
int
32_t
optionOffset
;
// relative option offset
}
SCmdLine
;
typedef
struct
_var_t
{
...
...
@@ -121,59 +121,56 @@ typedef struct _var_t {
}
SVariable
;
typedef
struct
_script_t
{
int
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
];
int
varLen
;
int
linePos
;
// current cmd position
int
numOfLines
;
// number of lines in the script
int
bgScriptLen
;
char
fileName
[
MAX_FILE_NAME_LEN
];
// script file name
char
error
[
MAX_ERROR_LEN
];
char
*
optionBuffer
;
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
];
char
auth
[
128
];
}
SScript
;
extern
SScript
*
simScriptList
[
MAX_MAIN_SCRIPT_NUM
];
extern
SCommand
simCmdList
[];
extern
int
simScriptPos
;
extern
int
simScriptSucced
;
extern
int
simDebugFlag
;
extern
char
tsScriptDir
[];
extern
bool
simAsyncQuery
;
extern
int
32_t
simScriptPos
;
extern
int
32_t
simScriptSucced
;
extern
int
32_t
simDebugFlag
;
extern
char
tsScriptDir
[];
extern
bool
simAsyncQuery
;
SScript
*
simParseScript
(
char
*
fileName
);
SScript
*
simProcessCallOver
(
SScript
*
script
);
void
*
simExecuteScript
(
void
*
script
);
void
simInitsimCmdList
();
bool
simSystemInit
();
void
simSystemCleanUp
();
char
*
simGetVariable
(
SScript
*
script
,
char
*
varName
,
in
t
varLen
);
bool
simExecuteExpCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteTestCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteGotoCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteRunCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteRunBackCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteSystemCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteSystemContentCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecutePrintCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteSleepCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteReturnCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteSqlCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteSqlErrorCmd
(
SScript
*
script
,
char
*
rest
);
bool
simExecuteSqlSlowCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteRestfulCmd
(
SScript
*
script
,
char
*
rest
);
void
simVisuallizeOption
(
SScript
*
script
,
char
*
src
,
char
*
dst
);
void
*
simExecuteScript
(
void
*
script
);
void
simInitsimCmdList
();
bool
simSystemInit
();
void
simSystemCleanUp
();
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
);
bool
simExecuteRunCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteRunBackCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteSystemCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteSystemContentCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecutePrintCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteSleepCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteReturnCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteSqlCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteSqlErrorCmd
(
SScript
*
script
,
char
*
rest
);
bool
simExecuteSqlSlowCmd
(
SScript
*
script
,
char
*
option
);
bool
simExecuteRestfulCmd
(
SScript
*
script
,
char
*
rest
);
void
simVisuallizeOption
(
SScript
*
script
,
char
*
src
,
char
*
dst
);
#endif
\ No newline at end of file
tests/tsim/inc/simParse.h
浏览文件 @
d583a4ca
...
...
@@ -50,6 +50,6 @@ typedef struct {
char
sexpLen
[
MAX_NUM_BLOCK
];
/*switch expression length */
}
SBlock
;
bool
simParseExpression
(
char
*
token
,
int
lineNum
);
bool
simParseExpression
(
char
*
token
,
int
32_t
lineNum
);
#endif
\ No newline at end of file
tests/tsim/src/simExe.c
浏览文件 @
d583a4ca
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "sim.h"
#include "taos.h"
...
...
@@ -38,30 +39,28 @@ void simLogSql(char *sql, bool useSharp) {
}
else
{
fprintf
(
fp
,
"%s;
\n
"
,
sql
);
}
fflush
(
fp
);
}
char
*
simParseArbitratorName
(
char
*
varName
);
char
*
simParseHostName
(
char
*
varName
);
char
*
simGetVariable
(
SScript
*
script
,
char
*
varName
,
int
varLen
)
{
char
*
simGetVariable
(
SScript
*
script
,
char
*
varName
,
int
32_t
varLen
)
{
if
(
strncmp
(
varName
,
"hostname"
,
8
)
==
0
)
{
return
simParseHostName
(
varName
);
}
if
(
strncmp
(
varName
,
"arbitrator"
,
10
)
==
0
)
{
return
simParseArbitratorName
(
varName
);
return
simParseArbitratorName
(
varName
);
}
if
(
strncmp
(
varName
,
"error"
,
varLen
)
==
0
)
return
script
->
error
;
if
(
strncmp
(
varName
,
"rows"
,
varLen
)
==
0
)
return
script
->
rows
;
if
(
strncmp
(
varName
,
"system_exit"
,
varLen
)
==
0
)
return
script
->
system_exit_code
;
if
(
strncmp
(
varName
,
"system_exit"
,
varLen
)
==
0
)
return
script
->
system_exit_code
;
if
(
strncmp
(
varName
,
"system_content"
,
varLen
)
==
0
)
return
script
->
system_ret_content
;
if
(
strncmp
(
varName
,
"system_content"
,
varLen
)
==
0
)
return
script
->
system_ret_content
;
// variable like data2_192.168.0.1
if
(
strncmp
(
varName
,
"data"
,
4
)
==
0
)
{
...
...
@@ -70,16 +69,16 @@ char *simGetVariable(SScript *script, char *varName, int varLen) {
}
if
(
varName
[
5
]
==
'_'
)
{
int
col
=
varName
[
4
]
-
'0'
;
int
32_t
col
=
varName
[
4
]
-
'0'
;
if
(
col
<
0
||
col
>=
MAX_QUERY_COL_NUM
)
{
return
"null"
;
}
char
*
keyName
;
int
keyLen
;
char
*
keyName
;
int
32_t
keyLen
;
paGetToken
(
varName
+
6
,
&
keyName
,
&
keyLen
);
for
(
int
i
=
0
;
i
<
MAX_QUERY_ROW_NUM
;
++
i
)
{
for
(
int
32_t
i
=
0
;
i
<
MAX_QUERY_ROW_NUM
;
++
i
)
{
if
(
strncmp
(
keyName
,
script
->
data
[
i
][
0
],
keyLen
)
==
0
)
{
simDebug
(
"script:%s, keyName:%s, keyValue:%s"
,
script
->
fileName
,
script
->
data
[
i
][
0
],
script
->
data
[
i
][
col
]);
return
script
->
data
[
i
][
col
];
...
...
@@ -87,16 +86,16 @@ char *simGetVariable(SScript *script, char *varName, int varLen) {
}
return
"null"
;
}
else
if
(
varName
[
6
]
==
'_'
)
{
int
col
=
(
varName
[
4
]
-
'0'
)
*
10
+
(
varName
[
5
]
-
'0'
);
int
32_t
col
=
(
varName
[
4
]
-
'0'
)
*
10
+
(
varName
[
5
]
-
'0'
);
if
(
col
<
0
||
col
>=
MAX_QUERY_COL_NUM
)
{
return
"null"
;
}
char
*
keyName
;
int
keyLen
;
char
*
keyName
;
int
32_t
keyLen
;
paGetToken
(
varName
+
7
,
&
keyName
,
&
keyLen
);
for
(
int
i
=
0
;
i
<
MAX_QUERY_ROW_NUM
;
++
i
)
{
for
(
int
32_t
i
=
0
;
i
<
MAX_QUERY_ROW_NUM
;
++
i
)
{
if
(
strncmp
(
keyName
,
script
->
data
[
i
][
0
],
keyLen
)
==
0
)
{
simTrace
(
"script:%s, keyName:%s, keyValue:%s"
,
script
->
fileName
,
script
->
data
[
i
][
0
],
script
->
data
[
i
][
col
]);
return
script
->
data
[
i
][
col
];
...
...
@@ -104,8 +103,8 @@ char *simGetVariable(SScript *script, char *varName, int varLen) {
}
return
"null"
;
}
else
{
int
row
=
varName
[
4
]
-
'0'
;
int
col
=
varName
[
5
]
-
'0'
;
int
32_t
row
=
varName
[
4
]
-
'0'
;
int
32_t
col
=
varName
[
5
]
-
'0'
;
if
(
row
<
0
||
row
>=
MAX_QUERY_ROW_NUM
)
{
return
"null"
;
}
...
...
@@ -118,7 +117,7 @@ char *simGetVariable(SScript *script, char *varName, int varLen) {
}
}
for
(
int
i
=
0
;
i
<
script
->
varLen
;
++
i
)
{
for
(
int
32_t
i
=
0
;
i
<
script
->
varLen
;
++
i
)
{
SVariable
*
var
=
&
script
->
variables
[
i
];
if
(
var
->
varNameLen
!=
varLen
)
{
continue
;
...
...
@@ -144,11 +143,11 @@ char *simGetVariable(SScript *script, char *varName, int varLen) {
return
var
->
varValue
;
}
int
simExecuteExpression
(
SScript
*
script
,
char
*
exp
)
{
char
*
op1
,
*
op2
,
*
var1
,
*
var2
,
*
var3
,
*
rest
;
int
op1Len
,
op2Len
,
var1Len
,
var2Len
,
var3Len
,
val0
,
val1
;
char
t0
[
512
],
t1
[
512
],
t2
[
512
],
t3
[
1024
];
int
result
;
int
32_t
simExecuteExpression
(
SScript
*
script
,
char
*
exp
)
{
char
*
op1
,
*
op2
,
*
var1
,
*
var2
,
*
var3
,
*
rest
;
int
32_t
op1Len
,
op2Len
,
var1Len
,
var2Len
,
var3Len
,
val0
,
val1
;
char
t0
[
512
],
t1
[
512
],
t2
[
512
],
t3
[
1024
];
int
32_t
result
;
rest
=
paGetToken
(
exp
,
&
var1
,
&
var1Len
);
rest
=
paGetToken
(
rest
,
&
op1
,
&
op1Len
);
...
...
@@ -234,7 +233,7 @@ bool simExecuteExpCmd(SScript *script, char *option) {
}
bool
simExecuteTestCmd
(
SScript
*
script
,
char
*
option
)
{
int
result
;
int
32_t
result
;
result
=
simExecuteExpression
(
script
,
option
);
if
(
result
>=
0
)
...
...
@@ -285,13 +284,12 @@ bool simExecuteRunBackCmd(SScript *script, char *option) {
sprintf
(
script
->
error
,
"lineNum:%d. parse file:%s error"
,
script
->
lines
[
script
->
linePos
].
lineNum
,
fileName
);
return
false
;
}
simInfo
(
"script:%s, start to execute in background"
,
newScript
->
fileName
);
newScript
->
type
=
SIM_SCRIPT_TYPE_BACKGROUND
;
script
->
bgScripts
[
script
->
bgScriptLen
++
]
=
newScript
;
simInfo
(
"script:%s, start to execute in background,"
,
newScript
->
fileName
);
pthread_t
pid
;
if
(
pthread_create
(
&
pid
,
NULL
,
simExecuteScript
,
(
void
*
)
newScript
)
!=
0
)
{
if
(
pthread_create
(
&
newScript
->
bgPid
,
NULL
,
simExecuteScript
,
(
void
*
)
newScript
)
!=
0
)
{
sprintf
(
script
->
error
,
"lineNum:%d. create background thread failed"
,
script
->
lines
[
script
->
linePos
].
lineNum
);
return
false
;
}
...
...
@@ -307,13 +305,13 @@ bool simExecuteSystemCmd(SScript *script, char *option) {
simVisuallizeOption
(
script
,
option
,
buf
+
strlen
(
buf
));
simLogSql
(
buf
,
true
);
int
code
=
system
(
buf
);
int
repeatTimes
=
0
;
int
32_t
code
=
system
(
buf
);
int
32_t
repeatTimes
=
0
;
while
(
code
<
0
)
{
simError
(
"script:%s, failed to execute %s , code %d, errno:%d %s, repeatTimes:%d"
,
script
->
fileName
,
buf
,
code
,
errno
,
strerror
(
errno
),
repeatTimes
);
simError
(
"script:%s, failed to execute %s , code %d, errno:%d %s, repeatTimes:%d"
,
script
->
fileName
,
buf
,
code
,
errno
,
strerror
(
errno
),
repeatTimes
);
taosMsleep
(
1000
);
#ifdef LINUX
#ifdef LINUX
signal
(
SIGCHLD
,
SIG_DFL
);
#endif
if
(
repeatTimes
++
>=
10
)
{
...
...
@@ -368,8 +366,8 @@ bool simExecutePrintCmd(SScript *script, char *rest) {
}
bool
simExecuteSleepCmd
(
SScript
*
script
,
char
*
option
)
{
int
delta
;
char
buf
[
1024
];
int
32_t
delta
;
char
buf
[
1024
];
simVisuallizeOption
(
script
,
option
,
buf
);
option
=
buf
;
...
...
@@ -395,7 +393,7 @@ bool simExecuteReturnCmd(SScript *script, char *option) {
simVisuallizeOption
(
script
,
option
,
buf
);
option
=
buf
;
int
ret
=
1
;
int
32_t
ret
=
1
;
if
(
option
&&
option
[
0
]
!=
0
)
ret
=
atoi
(
option
);
if
(
ret
<
0
)
{
...
...
@@ -411,8 +409,8 @@ bool simExecuteReturnCmd(SScript *script, char *option) {
}
void
simVisuallizeOption
(
SScript
*
script
,
char
*
src
,
char
*
dst
)
{
char
*
var
,
*
token
,
*
value
;
int
dstLen
,
srcLen
,
tokenLen
;
char
*
var
,
*
token
,
*
value
;
int
32_t
dstLen
,
srcLen
,
tokenLen
;
dst
[
0
]
=
0
,
dstLen
=
0
;
...
...
@@ -420,14 +418,14 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
var
=
strchr
(
src
,
'$'
);
if
(
var
==
NULL
)
break
;
if
(
var
&&
((
var
-
src
-
1
)
>
0
)
&&
*
(
var
-
1
)
==
'\\'
)
{
srcLen
=
(
int
)(
var
-
src
-
1
);
srcLen
=
(
int
32_t
)(
var
-
src
-
1
);
memcpy
(
dst
+
dstLen
,
src
,
srcLen
);
dstLen
+=
srcLen
;
src
=
var
;
break
;
}
srcLen
=
(
int
)(
var
-
src
);
srcLen
=
(
int
32_t
)(
var
-
src
);
memcpy
(
dst
+
dstLen
,
src
,
srcLen
);
dstLen
+=
srcLen
;
...
...
@@ -435,13 +433,13 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
value
=
simGetVariable
(
script
,
token
,
tokenLen
);
strcpy
(
dst
+
dstLen
,
value
);
dstLen
+=
(
int
)
strlen
(
value
);
dstLen
+=
(
int
32_t
)
strlen
(
value
);
}
strcpy
(
dst
+
dstLen
,
src
);
}
void
simCloseRestFulConnect
(
SScript
*
script
)
{
void
simCloseRestFulConnect
(
SScript
*
script
)
{
memset
(
script
->
auth
,
0
,
sizeof
(
script
->
auth
));
}
...
...
@@ -465,7 +463,7 @@ void simCloseTaosdConnect(SScript *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}
int
simParseHttpCommandResult
(
SScript
*
script
,
char
*
command
)
{
int
32_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
);
...
...
@@ -492,14 +490,15 @@ int simParseHttpCommandResult(SScript *script, char *command) {
cJSON_Delete
(
root
);
return
-
1
;
}
int
retcode
=
(
in
t
)
code
->
valueint
;
int
32_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
);
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
);
status
->
valuestring
,
retcode
,
command
);
cJSON_Delete
(
root
);
return
0
;
}
...
...
@@ -524,27 +523,27 @@ int simParseHttpCommandResult(SScript *script, char *command) {
return
-
1
;
}
int
rowsize
=
cJSON_GetArraySize
(
data
);
int
32_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
;
}
int
rowIndex
=
0
;
int
32_t
rowIndex
=
0
;
sprintf
(
script
->
rows
,
"%d"
,
rowsize
);
for
(
int
r
=
0
;
r
<
rowsize
;
++
r
)
{
for
(
int
32_t
r
=
0
;
r
<
rowsize
;
++
r
)
{
cJSON
*
row
=
cJSON_GetArrayItem
(
data
,
r
);
if
(
row
==
NULL
)
continue
;
if
(
rowIndex
++
>=
10
)
break
;
int
colsize
=
cJSON_GetArraySize
(
row
);
int
32_t
colsize
=
cJSON_GetArraySize
(
row
);
if
(
colsize
<
0
)
{
break
;
}
colsize
=
MIN
(
10
,
colsize
);
for
(
int
c
=
0
;
c
<
colsize
;
++
c
)
{
for
(
int
32_t
c
=
0
;
c
<
colsize
;
++
c
)
{
cJSON
*
col
=
cJSON_GetArrayItem
(
row
,
c
);
if
(
col
->
valuestring
!=
NULL
)
{
strcpy
(
script
->
data
[
r
][
c
],
col
->
valuestring
);
...
...
@@ -561,7 +560,7 @@ int simParseHttpCommandResult(SScript *script, char *command) {
return
0
;
}
int
simExecuteRestFulCommand
(
SScript
*
script
,
char
*
command
)
{
int
32_t
simExecuteRestFulCommand
(
SScript
*
script
,
char
*
command
)
{
char
buf
[
5000
]
=
{
0
};
sprintf
(
buf
,
"%s 2>/dev/null"
,
command
);
...
...
@@ -571,13 +570,13 @@ int simExecuteRestFulCommand(SScript *script, char *command) {
return
-
1
;
}
int
mallocSize
=
2000
;
int
alreadyReadSize
=
0
;
char
*
content
=
malloc
(
mallocSize
);
int
32_t
mallocSize
=
2000
;
int
32_t
alreadyReadSize
=
0
;
char
*
content
=
malloc
(
mallocSize
);
while
(
!
feof
(
fp
))
{
int
availSize
=
mallocSize
-
alreadyReadSize
;
int
len
=
(
in
t
)
fread
(
content
+
alreadyReadSize
,
1
,
availSize
,
fp
);
int
32_t
availSize
=
mallocSize
-
alreadyReadSize
;
int
32_t
len
=
(
int32_
t
)
fread
(
content
+
alreadyReadSize
,
1
,
availSize
,
fp
);
if
(
len
>=
availSize
)
{
alreadyReadSize
+=
len
;
mallocSize
*=
2
;
...
...
@@ -595,10 +594,11 @@ bool simCreateRestFulConnect(SScript *script, char *user, char *pass) {
sprintf
(
command
,
"curl 127.0.0.1:6041/rest/login/%s/%s"
,
user
,
pass
);
bool
success
=
false
;
for
(
int
attempt
=
0
;
attempt
<
10
;
++
attempt
)
{
for
(
int
32_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
);
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
);
...
...
@@ -607,7 +607,8 @@ bool simCreateRestFulConnect(SScript *script, char *user, char *pass) {
}
if
(
!
success
)
{
sprintf
(
script
->
error
,
"lineNum:%d. connect taosd failed:%s"
,
script
->
lines
[
script
->
linePos
].
lineNum
,
taos_errstr
(
NULL
));
sprintf
(
script
->
error
,
"lineNum:%d. connect taosd failed:%s"
,
script
->
lines
[
script
->
linePos
].
lineNum
,
taos_errstr
(
NULL
));
return
false
;
}
...
...
@@ -619,10 +620,11 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
simCloseTaosdConnect
(
script
);
void
*
taos
=
NULL
;
taosMsleep
(
2000
);
for
(
int
attempt
=
0
;
attempt
<
10
;
++
attempt
)
{
for
(
int
32_t
attempt
=
0
;
attempt
<
10
;
++
attempt
)
{
taos
=
taos_connect
(
NULL
,
user
,
pass
,
NULL
,
tsDnodeShellPort
);
if
(
taos
==
NULL
)
{
simDebug
(
"script:%s, user:%s connect taosd failed:%s, attempt:%d"
,
script
->
fileName
,
user
,
taos_errstr
(
NULL
),
attempt
);
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
);
...
...
@@ -631,7 +633,8 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
}
if
(
taos
==
NULL
)
{
sprintf
(
script
->
error
,
"lineNum:%d. connect taosd failed:%s"
,
script
->
lines
[
script
->
linePos
].
lineNum
,
taos_errstr
(
NULL
));
sprintf
(
script
->
error
,
"lineNum:%d. connect taosd failed:%s"
,
script
->
lines
[
script
->
linePos
].
lineNum
,
taos_errstr
(
NULL
));
return
false
;
}
...
...
@@ -642,9 +645,9 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
}
bool
simCreateTaosdConnect
(
SScript
*
script
,
char
*
rest
)
{
char
*
user
=
TSDB_DEFAULT_USER
;
char
*
token
;
int
tokenLen
;
char
*
user
=
TSDB_DEFAULT_USER
;
char
*
token
;
int
32_t
tokenLen
;
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
if
(
tokenLen
!=
0
)
{
...
...
@@ -659,26 +662,27 @@ bool simCreateTaosdConnect(SScript *script, char *rest) {
}
bool
simExecuteNativeSqlCommand
(
SScript
*
script
,
char
*
rest
,
bool
isSlow
)
{
char
timeStr
[
30
]
=
{
0
};
time_t
tt
;
char
timeStr
[
30
]
=
{
0
};
time_t
tt
;
struct
tm
*
tp
;
SCmdLine
*
line
=
&
script
->
lines
[
script
->
linePos
];
int
ret
=
-
1
;
SCmdLine
*
line
=
&
script
->
lines
[
script
->
linePos
];
int32_t
ret
=
-
1
;
TAOS_RES
*
pSql
=
NULL
;
TAOS_RES
*
pSql
=
NULL
;
for
(
int
attempt
=
0
;
attempt
<
10
;
++
attempt
)
{
for
(
int32_t
attempt
=
0
;
attempt
<
10
;
++
attempt
)
{
simLogSql
(
rest
,
false
);
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
)
{
simDebug
(
"script:%s, taos:%p, %s success, ret:%d:%s"
,
script
->
fileName
,
script
->
taos
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
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:%s, error:%s"
,
script
->
fileName
,
script
->
taos
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
),
taos_errstr
(
pSql
));
simDebug
(
"script:%s, taos:%p, %s failed, ret:%d:%s, error:%s"
,
script
->
fileName
,
script
->
taos
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
),
taos_errstr
(
pSql
));
if
(
line
->
errorJump
==
SQL_JUMP_TRUE
)
{
script
->
linePos
=
line
->
jump
;
...
...
@@ -689,7 +693,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
}
else
{
break
;
}
taos_free_result
(
pSql
);
}
...
...
@@ -698,8 +702,8 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
return
false
;
}
int
numOfRows
=
0
;
int
num_fields
=
taos_field_count
(
pSql
);
int
32_t
numOfRows
=
0
;
int
32_t
num_fields
=
taos_field_count
(
pSql
);
if
(
num_fields
!=
0
)
{
if
(
pSql
==
NULL
)
{
simDebug
(
"script:%s, taos:%p, %s failed, result is null"
,
script
->
fileName
,
script
->
taos
,
rest
);
...
...
@@ -717,9 +721,9 @@ 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
);
int
*
length
=
taos_fetch_lengths
(
pSql
);
for
(
int
i
=
0
;
i
<
num_fields
;
i
++
)
{
int
32_t
*
length
=
taos_fetch_lengths
(
pSql
);
for
(
int
32_t
i
=
0
;
i
<
num_fields
;
i
++
)
{
char
*
value
=
NULL
;
if
(
i
<
MAX_QUERY_COL_NUM
)
{
value
=
script
->
data
[
numOfRows
][
i
];
...
...
@@ -735,8 +739,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
switch
(
fields
[
i
].
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
sprintf
(
value
,
"%s"
,
((((
int
)(
*
((
char
*
)
row
[
i
])))
==
1
)
?
"1"
:
"0"
));
sprintf
(
value
,
"%s"
,
((((
int32_t
)(
*
((
char
*
)
row
[
i
])))
==
1
)
?
"1"
:
"0"
));
break
;
case
TSDB_DATA_TYPE_TINYINT
:
sprintf
(
value
,
"%d"
,
*
((
int8_t
*
)
row
[
i
]));
...
...
@@ -779,9 +782,8 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
tp
=
localtime
(
&
tt
);
strftime
(
timeStr
,
64
,
"%y-%m-%d %H:%M:%S"
,
tp
);
sprintf
(
value
,
"%s.%03d"
,
timeStr
,
(
int
)(
*
((
int64_t
*
)
row
[
i
])
%
1000
));
sprintf
(
value
,
"%s.%03d"
,
timeStr
,
(
int32_t
)(
*
((
int64_t
*
)
row
[
i
])
%
1000
));
break
;
default:
break
;
...
...
@@ -814,17 +816,16 @@ bool simExecuteRestFulSqlCommand(SScript *script, char *rest) {
char
command
[
4096
];
sprintf
(
command
,
"curl -H 'Authorization: Taosd %s' -d
\"
%s
\"
127.0.0.1:6041/rest/sql"
,
script
->
auth
,
rest
);
int
ret
=
-
1
;
for
(
int
attempt
=
0
;
attempt
<
10
;
++
attempt
)
{
int
32_t
ret
=
-
1
;
for
(
int
32_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
));
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
);
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
;
...
...
@@ -854,8 +855,8 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
simDebug
(
"script:%s, exec:%s"
,
script
->
fileName
,
rest
);
strcpy
(
script
->
rows
,
"-1"
);
for
(
int
row
=
0
;
row
<
MAX_QUERY_ROW_NUM
;
++
row
)
{
for
(
int
col
=
0
;
col
<
MAX_QUERY_COL_NUM
;
++
col
)
{
for
(
int
32_t
row
=
0
;
row
<
MAX_QUERY_ROW_NUM
;
++
row
)
{
for
(
int
32_t
col
=
0
;
col
<
MAX_QUERY_COL_NUM
;
++
col
)
{
strcpy
(
script
->
data
[
row
][
col
],
"null"
);
}
}
...
...
@@ -903,23 +904,23 @@ bool simExecuteSqlSlowCmd(SScript *script, char *rest) {
bool
simExecuteRestfulCmd
(
SScript
*
script
,
char
*
rest
)
{
FILE
*
fp
=
NULL
;
char
filename
[
256
];
sprintf
(
filename
,
"%s/tmp.sql"
,
tsScriptDir
);
char
filename
[
256
];
sprintf
(
filename
,
"%s/tmp.sql"
,
tsScriptDir
);
fp
=
fopen
(
filename
,
"w"
);
if
(
fp
==
NULL
)
{
fprintf
(
stderr
,
"ERROR: failed to open file: %s
\n
"
,
filename
);
return
false
;
}
char
db
[
64
]
=
{
0
};
char
tb
[
64
]
=
{
0
};
char
gzip
[
32
]
=
{
0
};
char
db
[
64
]
=
{
0
};
char
tb
[
64
]
=
{
0
};
char
gzip
[
32
]
=
{
0
};
int32_t
ts
;
int32_t
times
;
sscanf
(
rest
,
"%s %s %d %d %s"
,
db
,
tb
,
&
ts
,
&
times
,
gzip
);
fprintf
(
fp
,
"insert into %s.%s values "
,
db
,
tb
);
for
(
int
i
=
0
;
i
<
times
;
++
i
)
{
for
(
int
32_t
i
=
0
;
i
<
times
;
++
i
)
{
fprintf
(
fp
,
"(%d000, %d)"
,
ts
+
i
,
ts
);
}
fprintf
(
fp
,
"
\n
"
);
...
...
@@ -951,8 +952,8 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
simDebug
(
"script:%s, exec:%s"
,
script
->
fileName
,
rest
);
strcpy
(
script
->
rows
,
"-1"
);
for
(
int
row
=
0
;
row
<
MAX_QUERY_ROW_NUM
;
++
row
)
{
for
(
int
col
=
0
;
col
<
MAX_QUERY_COL_NUM
;
++
col
)
{
for
(
int
32_t
row
=
0
;
row
<
MAX_QUERY_ROW_NUM
;
++
row
)
{
for
(
int
32_t
col
=
0
;
col
<
MAX_QUERY_COL_NUM
;
++
col
)
{
strcpy
(
script
->
data
[
row
][
col
],
"null"
);
}
}
...
...
@@ -981,27 +982,27 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return
true
;
}
int
ret
;
TAOS_RES
*
pSql
=
NULL
;
int
32_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
{
}
else
{
pSql
=
taos_query
(
script
->
taos
,
rest
);
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
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
simDebug
(
"script:%s, taos:%p, %s execute, expect failed, so success, ret:%d:%s"
,
script
->
fileName
,
script
->
taos
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
script
->
linePos
++
;
return
true
;
}
sprintf
(
script
->
error
,
"lineNum:%d. sql:%s expect failed, but success, ret:%d:%s"
,
line
->
lineNum
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
sprintf
(
script
->
error
,
"lineNum:%d. sql:%s expect failed, but success, ret:%d:%s"
,
line
->
lineNum
,
rest
,
ret
&
0XFFFF
,
tstrerror
(
ret
));
return
false
;
}
tests/tsim/src/simMain.c
浏览文件 @
d583a4ca
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "tglobal.h"
#include "sim.h"
...
...
@@ -20,15 +21,15 @@
bool
simAsyncQuery
=
false
;
void
simHandleSignal
(
int
signo
)
{
void
simHandleSignal
(
int
32_t
signo
)
{
simSystemCleanUp
();
exit
(
1
);
}
int
main
(
in
t
argc
,
char
*
argv
[])
{
int
32_t
main
(
int32_
t
argc
,
char
*
argv
[])
{
char
scriptFile
[
MAX_FILE_NAME_LEN
]
=
"sim_main_test.sim"
;
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
int
32_t
i
=
1
;
i
<
argc
;
++
i
)
{
if
(
strcmp
(
argv
[
i
],
"-c"
)
==
0
&&
i
<
argc
-
1
)
{
tstrncpy
(
configDir
,
argv
[
++
i
],
MAX_FILE_NAME_LEN
);
}
else
if
(
strcmp
(
argv
[
i
],
"-f"
)
==
0
&&
i
<
argc
-
1
)
{
...
...
@@ -37,8 +38,7 @@ int main(int argc, char *argv[]) {
simAsyncQuery
=
true
;
}
else
{
printf
(
"usage: %s [options]
\n
"
,
argv
[
0
]);
printf
(
" [-c config]: config directory, default is: %s
\n
"
,
configDir
);
printf
(
" [-c config]: config directory, default is: %s
\n
"
,
configDir
);
printf
(
" [-f script]: script filename
\n
"
);
exit
(
0
);
}
...
...
tests/tsim/src/simParse.c
浏览文件 @
d583a4ca
...
...
@@ -57,6 +57,7 @@
*
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "sim.h"
#include "simParse.h"
...
...
@@ -64,16 +65,16 @@
#undef TAOS_MEM_CHECK
static
SCommand
*
cmdHashList
[
MAX_NUM_CMD
];
static
SCmdLine
cmdLine
[
MAX_CMD_LINES
];
static
char
parseErr
[
MAX_ERROR_LEN
];
static
char
optionBuffer
[
MAX_OPTION_BUFFER
];
static
int
numOfLines
,
optionOffset
;
static
SLabel
label
,
dest
;
static
SBlock
block
;
static
SCmdLine
cmdLine
[
MAX_CMD_LINES
];
static
char
parseErr
[
MAX_ERROR_LEN
];
static
char
optionBuffer
[
MAX_OPTION_BUFFER
];
static
int
32_t
numOfLines
,
optionOffset
;
static
SLabel
label
,
dest
;
static
SBlock
block
;
int
simHashCmd
(
char
*
token
,
in
t
tokenLen
)
{
int
i
;
int
hash
=
0
;
int
32_t
simHashCmd
(
char
*
token
,
int32_
t
tokenLen
)
{
int
32_t
i
;
int
32_t
hash
=
0
;
for
(
i
=
0
;
i
<
tokenLen
;
++
i
)
hash
+=
token
[
i
];
...
...
@@ -82,8 +83,8 @@ int simHashCmd(char *token, int tokenLen) {
return
hash
;
}
SCommand
*
simCheckCmd
(
char
*
token
,
int
tokenLen
)
{
int
hash
;
SCommand
*
simCheckCmd
(
char
*
token
,
int
32_t
tokenLen
)
{
int
32_t
hash
;
SCommand
*
node
;
hash
=
simHashCmd
(
token
,
tokenLen
);
...
...
@@ -102,10 +103,10 @@ SCommand *simCheckCmd(char *token, int tokenLen) {
}
void
simAddCmdIntoHash
(
SCommand
*
pCmd
)
{
int
hash
;
int
32_t
hash
;
SCommand
*
node
;
hash
=
simHashCmd
(
pCmd
->
name
,
(
int
)
strlen
(
pCmd
->
name
));
hash
=
simHashCmd
(
pCmd
->
name
,
(
int
32_t
)
strlen
(
pCmd
->
name
));
node
=
cmdHashList
[
hash
];
pCmd
->
next
=
node
;
cmdHashList
[
hash
]
=
pCmd
;
...
...
@@ -122,7 +123,7 @@ void simResetParser() {
}
SScript
*
simBuildScriptObj
(
char
*
fileName
)
{
int
i
,
destPos
;
int
32_t
i
,
destPos
;
/* process labels */
...
...
@@ -176,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) {
}
SScript
*
simParseScript
(
char
*
fileName
)
{
FILE
*
fd
;
int
tokenLen
,
lineNum
=
0
;
char
buffer
[
MAX_LINE_LEN
],
name
[
128
],
*
token
,
*
rest
;
FILE
*
fd
;
int
32_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
);
...
...
@@ -199,12 +200,13 @@ SScript *simParseScript(char *fileName) {
if
(
fgets
(
buffer
,
sizeof
(
buffer
),
fd
)
==
NULL
)
continue
;
lineNum
++
;
int
cmdlen
=
(
in
t
)
strlen
(
buffer
);
if
(
buffer
[
cmdlen
-
1
]
==
'\r'
||
buffer
[
cmdlen
-
1
]
==
'\n'
)
int
32_t
cmdlen
=
(
int32_
t
)
strlen
(
buffer
);
if
(
buffer
[
cmdlen
-
1
]
==
'\r'
||
buffer
[
cmdlen
-
1
]
==
'\n'
)
{
buffer
[
cmdlen
-
1
]
=
0
;
}
rest
=
buffer
;
for
(
int
i
=
0
;
i
<
cmdlen
;
++
i
)
{
for
(
int
32_t
i
=
0
;
i
<
cmdlen
;
++
i
)
{
if
(
buffer
[
i
]
==
'\r'
||
buffer
[
i
]
==
'\n'
)
{
buffer
[
i
]
=
' '
;
}
...
...
@@ -249,9 +251,9 @@ SScript *simParseScript(char *fileName) {
return
script
;
}
int
simCheckExpression
(
char
*
exp
)
{
char
*
op1
,
*
op2
,
*
op
,
*
rest
;
int
op1Len
,
op2Len
,
opLen
;
int
32_t
simCheckExpression
(
char
*
exp
)
{
char
*
op1
,
*
op2
,
*
op
,
*
rest
;
int
32_t
op1Len
,
op2Len
,
opLen
;
rest
=
paGetToken
(
exp
,
&
op1
,
&
op1Len
);
if
(
op1Len
==
0
)
{
...
...
@@ -282,8 +284,7 @@ int simCheckExpression(char *exp) {
return
-
1
;
}
}
else
if
(
opLen
==
2
)
{
if
(
op
[
1
]
!=
'='
||
(
op
[
0
]
!=
'='
&&
op
[
0
]
!=
'<'
&&
op
[
0
]
!=
'>'
&&
op
[
0
]
!=
'!'
))
{
if
(
op
[
1
]
!=
'='
||
(
op
[
0
]
!=
'='
&&
op
[
0
]
!=
'<'
&&
op
[
0
]
!=
'>'
&&
op
[
0
]
!=
'!'
))
{
sprintf
(
parseErr
,
"left side of assignment must be variable"
);
return
-
1
;
}
...
...
@@ -294,10 +295,10 @@ int simCheckExpression(char *exp) {
rest
=
paGetToken
(
rest
,
&
op
,
&
opLen
);
if
(
opLen
==
0
)
return
(
int
)(
rest
-
exp
);
if
(
opLen
==
0
)
return
(
int
32_t
)(
rest
-
exp
);
/* if it is key word "then" */
if
(
strncmp
(
op
,
"then"
,
4
)
==
0
)
return
(
int
)(
op
-
exp
);
if
(
strncmp
(
op
,
"then"
,
4
)
==
0
)
return
(
int
32_t
)(
op
-
exp
);
rest
=
paGetToken
(
rest
,
&
op2
,
&
op2Len
);
if
(
op2Len
==
0
)
{
...
...
@@ -310,16 +311,15 @@ int simCheckExpression(char *exp) {
return
-
1
;
}
if
(
op
[
0
]
==
'+'
||
op
[
0
]
==
'-'
||
op
[
0
]
==
'*'
||
op
[
0
]
==
'/'
||
op
[
0
]
==
'.'
)
{
return
(
int
)(
rest
-
exp
);
if
(
op
[
0
]
==
'+'
||
op
[
0
]
==
'-'
||
op
[
0
]
==
'*'
||
op
[
0
]
==
'/'
||
op
[
0
]
==
'.'
)
{
return
(
int32_t
)(
rest
-
exp
);
}
return
-
1
;
}
bool
simParseExpression
(
char
*
token
,
int
lineNum
)
{
int
expLen
;
bool
simParseExpression
(
char
*
token
,
int
32_t
lineNum
)
{
int
32_t
expLen
;
expLen
=
simCheckExpression
(
token
);
if
(
expLen
<=
0
)
return
-
1
;
...
...
@@ -335,9 +335,9 @@ bool simParseExpression(char *token, int lineNum) {
return
true
;
}
bool
simParseIfCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
char
*
ret
;
int
expLen
;
bool
simParseIfCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
char
*
ret
;
int
32_t
expLen
;
expLen
=
simCheckExpression
(
rest
);
...
...
@@ -364,8 +364,8 @@ bool simParseIfCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseElifCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
int
expLen
;
bool
simParseElifCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
int
32_t
expLen
;
expLen
=
simCheckExpression
(
rest
);
...
...
@@ -382,8 +382,7 @@ bool simParseElifCmd(char *rest, SCommand *pCmd, int lineNum) {
}
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_GOTO
;
block
.
jump
[
block
.
top
-
1
][(
uint8_t
)
block
.
numJump
[
block
.
top
-
1
]]
=
&
(
cmdLine
[
numOfLines
].
jump
);
block
.
jump
[
block
.
top
-
1
][(
uint8_t
)
block
.
numJump
[
block
.
top
-
1
]]
=
&
(
cmdLine
[
numOfLines
].
jump
);
block
.
numJump
[
block
.
top
-
1
]
++
;
numOfLines
++
;
...
...
@@ -402,7 +401,7 @@ bool simParseElifCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseElseCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
bool
simParseElseCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
if
(
block
.
top
<
1
)
{
sprintf
(
parseErr
,
"no matching if"
);
return
false
;
...
...
@@ -414,8 +413,7 @@ bool simParseElseCmd(char *rest, SCommand *pCmd, int lineNum) {
}
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_GOTO
;
block
.
jump
[
block
.
top
-
1
][(
uint8_t
)
block
.
numJump
[
block
.
top
-
1
]]
=
&
(
cmdLine
[
numOfLines
].
jump
);
block
.
jump
[
block
.
top
-
1
][(
uint8_t
)
block
.
numJump
[
block
.
top
-
1
]]
=
&
(
cmdLine
[
numOfLines
].
jump
);
block
.
numJump
[
block
.
top
-
1
]
++
;
numOfLines
++
;
...
...
@@ -426,8 +424,8 @@ bool simParseElseCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseEndiCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
int
i
;
bool
simParseEndiCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
int
32_t
i
;
if
(
block
.
top
<
1
)
{
sprintf
(
parseErr
,
"no matching if"
);
...
...
@@ -441,8 +439,9 @@ bool simParseEndiCmd(char *rest, SCommand *pCmd, int lineNum) {
if
(
block
.
pos
[
block
.
top
-
1
])
*
(
block
.
pos
[
block
.
top
-
1
])
=
numOfLines
;
for
(
i
=
0
;
i
<
block
.
numJump
[
block
.
top
-
1
];
++
i
)
for
(
i
=
0
;
i
<
block
.
numJump
[
block
.
top
-
1
];
++
i
)
{
*
(
block
.
jump
[
block
.
top
-
1
][
i
])
=
numOfLines
;
}
block
.
numJump
[
block
.
top
-
1
]
=
0
;
block
.
top
--
;
...
...
@@ -450,8 +449,8 @@ bool simParseEndiCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseWhileCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
int
expLen
;
bool
simParseWhileCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
int
32_t
expLen
;
expLen
=
simCheckExpression
(
rest
);
...
...
@@ -473,8 +472,8 @@ bool simParseWhileCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseEndwCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
int
i
;
bool
simParseEndwCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
int
32_t
i
;
if
(
block
.
top
<
1
)
{
sprintf
(
parseErr
,
"no matching while"
);
...
...
@@ -493,17 +492,18 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int lineNum) {
*
(
block
.
pos
[
block
.
top
-
1
])
=
numOfLines
;
for
(
i
=
0
;
i
<
block
.
numJump
[
block
.
top
-
1
];
++
i
)
for
(
i
=
0
;
i
<
block
.
numJump
[
block
.
top
-
1
];
++
i
)
{
*
(
block
.
jump
[
block
.
top
-
1
][
i
])
=
numOfLines
;
}
block
.
top
--
;
return
true
;
}
bool
simParseSwitchCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
char
*
token
;
int
tokenLen
;
bool
simParseSwitchCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_t
tokenLen
;
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
if
(
tokenLen
==
0
)
{
...
...
@@ -524,9 +524,9 @@ bool simParseSwitchCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseCaseCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
char
*
token
;
int
tokenLen
;
bool
simParseCaseCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_t
tokenLen
;
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
if
(
tokenLen
==
0
)
{
...
...
@@ -544,16 +544,16 @@ bool simParseCaseCmd(char *rest, SCommand *pCmd, int lineNum) {
return
false
;
}
if
(
block
.
pos
[
block
.
top
-
1
]
!=
NULL
)
if
(
block
.
pos
[
block
.
top
-
1
]
!=
NULL
)
{
*
(
block
.
pos
[
block
.
top
-
1
])
=
numOfLines
;
}
block
.
pos
[
block
.
top
-
1
]
=
&
(
cmdLine
[
numOfLines
].
jump
);
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_TEST
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
cmdLine
[
numOfLines
].
optionOffset
=
optionOffset
;
memcpy
(
optionBuffer
+
optionOffset
,
block
.
sexp
[
block
.
top
-
1
],
block
.
sexpLen
[
block
.
top
-
1
]);
memcpy
(
optionBuffer
+
optionOffset
,
block
.
sexp
[
block
.
top
-
1
],
block
.
sexpLen
[
block
.
top
-
1
]);
optionOffset
+=
block
.
sexpLen
[
block
.
top
-
1
];
*
(
optionBuffer
+
optionOffset
++
)
=
' '
;
*
(
optionBuffer
+
optionOffset
++
)
=
'='
;
...
...
@@ -567,20 +567,18 @@ bool simParseCaseCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseBreakCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
bool
simParseBreakCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
if
(
block
.
top
<
1
)
{
sprintf
(
parseErr
,
"no blcok exists"
);
return
false
;
}
if
(
block
.
type
[
block
.
top
-
1
]
!=
BLOCK_SWITCH
&&
block
.
type
[
block
.
top
-
1
]
!=
BLOCK_WHILE
)
{
if
(
block
.
type
[
block
.
top
-
1
]
!=
BLOCK_SWITCH
&&
block
.
type
[
block
.
top
-
1
]
!=
BLOCK_WHILE
)
{
sprintf
(
parseErr
,
"not in switch or while block"
);
return
false
;
}
block
.
jump
[
block
.
top
-
1
][(
uint8_t
)
block
.
numJump
[
block
.
top
-
1
]]
=
&
(
cmdLine
[
numOfLines
].
jump
);
block
.
jump
[
block
.
top
-
1
][(
uint8_t
)
block
.
numJump
[
block
.
top
-
1
]]
=
&
(
cmdLine
[
numOfLines
].
jump
);
block
.
numJump
[
block
.
top
-
1
]
++
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_GOTO
;
...
...
@@ -590,7 +588,7 @@ bool simParseBreakCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseDefaultCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
bool
simParseDefaultCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
if
(
block
.
top
<
1
)
{
sprintf
(
parseErr
,
"no matching switch"
);
return
false
;
...
...
@@ -601,14 +599,15 @@ bool simParseDefaultCmd(char *rest, SCommand *pCmd, int lineNum) {
return
false
;
}
if
(
block
.
pos
[
block
.
top
-
1
]
!=
NULL
)
if
(
block
.
pos
[
block
.
top
-
1
]
!=
NULL
)
{
*
(
block
.
pos
[
block
.
top
-
1
])
=
numOfLines
;
}
return
true
;
}
bool
simParseEndsCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
int
i
;
bool
simParseEndsCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
int
32_t
i
;
if
(
block
.
top
<
1
)
{
sprintf
(
parseErr
,
"no matching switch"
);
...
...
@@ -620,8 +619,9 @@ bool simParseEndsCmd(char *rest, SCommand *pCmd, int lineNum) {
return
false
;
}
for
(
i
=
0
;
i
<
block
.
numJump
[
block
.
top
-
1
];
++
i
)
for
(
i
=
0
;
i
<
block
.
numJump
[
block
.
top
-
1
];
++
i
)
{
*
(
block
.
jump
[
block
.
top
-
1
][
i
])
=
numOfLines
;
}
block
.
numJump
[
block
.
top
-
1
]
=
0
;
block
.
top
--
;
...
...
@@ -629,7 +629,7 @@ bool simParseEndsCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseContinueCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
bool
simParseContinueCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
if
(
block
.
top
<
1
)
{
sprintf
(
parseErr
,
"no matching while"
);
return
false
;
...
...
@@ -648,14 +648,14 @@ bool simParseContinueCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParsePrintCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
int
expLen
;
bool
simParsePrintCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
int
32_t
expLen
;
rest
++
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_PRINT
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
cmdLine
[
numOfLines
].
optionOffset
=
optionOffset
;
expLen
=
(
int
)
strlen
(
rest
);
expLen
=
(
int
32_t
)
strlen
(
rest
);
memcpy
(
optionBuffer
+
optionOffset
,
rest
,
expLen
);
optionOffset
+=
expLen
+
1
;
*
(
optionBuffer
+
optionOffset
-
1
)
=
0
;
...
...
@@ -665,8 +665,8 @@ bool simParsePrintCmd(char *rest, SCommand *pCmd, int lineNum) {
}
void
simCheckSqlOption
(
char
*
rest
)
{
int
valueLen
;
char
*
value
,
*
xpos
;
int
32_t
valueLen
;
char
*
value
,
*
xpos
;
xpos
=
strstr
(
rest
,
" -x"
);
// need a blank
if
(
xpos
)
{
...
...
@@ -682,15 +682,15 @@ void simCheckSqlOption(char *rest) {
}
}
bool
simParseSqlCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
int
expLen
;
bool
simParseSqlCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
int
32_t
expLen
;
rest
++
;
simCheckSqlOption
(
rest
);
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_SQL
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
cmdLine
[
numOfLines
].
optionOffset
=
optionOffset
;
expLen
=
(
int
)
strlen
(
rest
);
expLen
=
(
int
32_t
)
strlen
(
rest
);
memcpy
(
optionBuffer
+
optionOffset
,
rest
,
expLen
);
optionOffset
+=
expLen
+
1
;
*
(
optionBuffer
+
optionOffset
-
1
)
=
0
;
...
...
@@ -699,14 +699,14 @@ bool simParseSqlCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseSqlErrorCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
int
expLen
;
bool
simParseSqlErrorCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
int
32_t
expLen
;
rest
++
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_SQL_ERROR
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
cmdLine
[
numOfLines
].
optionOffset
=
optionOffset
;
expLen
=
(
int
)
strlen
(
rest
);
expLen
=
(
int
32_t
)
strlen
(
rest
);
memcpy
(
optionBuffer
+
optionOffset
,
rest
,
expLen
);
optionOffset
+=
expLen
+
1
;
*
(
optionBuffer
+
optionOffset
-
1
)
=
0
;
...
...
@@ -715,26 +715,26 @@ bool simParseSqlErrorCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseSqlSlowCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
bool
simParseSqlSlowCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
simParseSqlCmd
(
rest
,
pCmd
,
lineNum
);
cmdLine
[
numOfLines
-
1
].
cmdno
=
SIM_CMD_SQL_SLOW
;
return
true
;
}
bool
simParseRestfulCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
bool
simParseRestfulCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
simParseSqlCmd
(
rest
,
pCmd
,
lineNum
);
cmdLine
[
numOfLines
-
1
].
cmdno
=
SIM_CMD_RESTFUL
;
return
true
;
}
bool
simParseSystemCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
int
expLen
;
bool
simParseSystemCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
int
32_t
expLen
;
rest
++
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_SYSTEM
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
cmdLine
[
numOfLines
].
optionOffset
=
optionOffset
;
expLen
=
(
int
)
strlen
(
rest
);
expLen
=
(
int
32_t
)
strlen
(
rest
);
memcpy
(
optionBuffer
+
optionOffset
,
rest
,
expLen
);
optionOffset
+=
expLen
+
1
;
*
(
optionBuffer
+
optionOffset
-
1
)
=
0
;
...
...
@@ -743,15 +743,15 @@ bool simParseSystemCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseSystemContentCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
bool
simParseSystemContentCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
simParseSystemCmd
(
rest
,
pCmd
,
lineNum
);
cmdLine
[
numOfLines
-
1
].
cmdno
=
SIM_CMD_SYSTEM_CONTENT
;
return
true
;
}
bool
simParseSleepCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
char
*
token
;
int
tokenLen
;
bool
simParseSleepCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_t
tokenLen
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_SLEEP
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
...
...
@@ -768,9 +768,9 @@ bool simParseSleepCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseReturnCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
char
*
token
;
int
tokenLen
;
bool
simParseReturnCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_t
tokenLen
;
cmdLine
[
numOfLines
].
cmdno
=
SIM_CMD_RETURN
;
cmdLine
[
numOfLines
].
lineNum
=
lineNum
;
...
...
@@ -787,9 +787,9 @@ bool simParseReturnCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseGotoCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
char
*
token
;
int
tokenLen
;
bool
simParseGotoCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_t
tokenLen
;
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
...
...
@@ -810,9 +810,9 @@ bool simParseGotoCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseRunCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
char
*
token
;
int
tokenLen
;
bool
simParseRunCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
char
*
token
;
int
32_t
tokenLen
;
rest
=
paGetToken
(
rest
,
&
token
,
&
tokenLen
);
...
...
@@ -832,14 +832,14 @@ bool simParseRunCmd(char *rest, SCommand *pCmd, int lineNum) {
return
true
;
}
bool
simParseRunBackCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
lineNum
)
{
bool
simParseRunBackCmd
(
char
*
rest
,
SCommand
*
pCmd
,
int
32_t
lineNum
)
{
simParseRunCmd
(
rest
,
pCmd
,
lineNum
);
cmdLine
[
numOfLines
-
1
].
cmdno
=
SIM_CMD_RUN_BACK
;
return
true
;
}
void
simInitsimCmdList
()
{
int
cmdno
;
int
32_t
cmdno
;
memset
(
simCmdList
,
0
,
SIM_CMD_END
*
sizeof
(
SCommand
));
/* internal command */
...
...
tests/tsim/src/simSystem.c
浏览文件 @
d583a4ca
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "sim.h"
#include "taos.h"
...
...
@@ -24,11 +25,11 @@
SScript
*
simScriptList
[
MAX_MAIN_SCRIPT_NUM
];
SCommand
simCmdList
[
SIM_CMD_END
];
int
simScriptPos
=
-
1
;
int
simScriptSucced
=
0
;
int
simDebugFlag
=
135
;
void
simCloseTaosdConnect
(
SScript
*
script
);
char
simHostName
[
128
];
int
32_t
simScriptPos
=
-
1
;
int
32_t
simScriptSucced
=
0
;
int
32_t
simDebugFlag
=
135
;
void
simCloseTaosdConnect
(
SScript
*
script
);
char
simHostName
[
128
];
char
*
simParseArbitratorName
(
char
*
varName
)
{
static
char
hostName
[
140
];
...
...
@@ -39,8 +40,8 @@ char *simParseArbitratorName(char *varName) {
char
*
simParseHostName
(
char
*
varName
)
{
static
char
hostName
[
140
];
int
index
=
atoi
(
varName
+
8
);
int
port
=
7100
;
int
32_t
index
=
atoi
(
varName
+
8
);
int
32_t
port
=
7100
;
switch
(
index
)
{
case
1
:
port
=
7100
;
...
...
@@ -70,9 +71,9 @@ char *simParseHostName(char *varName) {
port
=
7900
;
break
;
}
sprintf
(
hostName
,
"'%s:%d'"
,
simHostName
,
port
);
//simInfo("hostName:%s", hostName);
//
simInfo("hostName:%s", hostName);
return
hostName
;
}
...
...
@@ -88,12 +89,19 @@ void simSystemCleanUp() {}
void
simFreeScript
(
SScript
*
script
)
{
if
(
script
->
type
==
SIM_SCRIPT_TYPE_MAIN
)
{
for
(
int
i
=
0
;
i
<
script
->
bgScriptLen
;
++
i
)
{
simInfo
(
"script:%s, background script num:%d, stop them"
,
script
->
fileName
,
script
->
bgScriptLen
);
for
(
int32_t
i
=
0
;
i
<
script
->
bgScriptLen
;
++
i
)
{
SScript
*
bgScript
=
script
->
bgScripts
[
i
];
simInfo
(
"script:%s, set stop flag"
,
script
->
fileName
);
bgScript
->
killed
=
true
;
if
(
taosCheckPthreadValid
(
bgScript
->
bgPid
))
{
pthread_join
(
bgScript
->
bgPid
,
NULL
);
}
}
}
simDebug
(
"script:%s, is freed"
,
script
->
fileName
);
taos_close
(
script
->
taos
);
taosTFree
(
script
->
lines
);
taosTFree
(
script
->
optionBuffer
);
...
...
@@ -103,24 +111,23 @@ void simFreeScript(SScript *script) {
SScript
*
simProcessCallOver
(
SScript
*
script
)
{
if
(
script
->
type
==
SIM_SCRIPT_TYPE_MAIN
)
{
if
(
script
->
killed
)
{
simInfo
(
"script:"
FAILED_PREFIX
"%s"
FAILED_POSTFIX
", "
FAILED_PREFIX
"failed"
FAILED_POSTFIX
", error:%s"
,
script
->
fileName
,
script
->
error
);
simInfo
(
"script:"
FAILED_PREFIX
"%s"
FAILED_POSTFIX
", "
FAILED_PREFIX
"failed"
FAILED_POSTFIX
", error:%s"
,
script
->
fileName
,
script
->
error
);
exit
(
-
1
);
}
else
{
simInfo
(
"script:"
SUCCESS_PREFIX
"%s"
SUCCESS_POSTFIX
", "
SUCCESS_PREFIX
"success"
SUCCESS_POSTFIX
,
script
->
fileName
);
simInfo
(
"script:"
SUCCESS_PREFIX
"%s"
SUCCESS_POSTFIX
", "
SUCCESS_PREFIX
"success"
SUCCESS_POSTFIX
,
script
->
fileName
);
simCloseTaosdConnect
(
script
);
simScriptSucced
++
;
simScriptPos
--
;
simFreeScript
(
script
);
if
(
simScriptPos
==
-
1
)
{
simInfo
(
"----------------------------------------------------------------------"
);
simInfo
(
"Simulation Test Done, "
SUCCESS_PREFIX
"%d"
SUCCESS_POSTFIX
" Passed:
\n
"
,
simScriptSucced
);
exit
(
0
);
}
simFreeScript
(
script
);
return
simScriptList
[
simScriptPos
];
}
}
else
{
...
...
@@ -143,11 +150,11 @@ void *simExecuteScript(void *inputScript) {
if
(
script
==
NULL
)
break
;
}
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
];
int
ret
=
(
*
(
cmd
->
executeCmd
))(
script
,
option
);
int
32_t
ret
=
(
*
(
cmd
->
executeCmd
))(
script
,
option
);
if
(
!
ret
)
{
script
->
killed
=
true
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录