Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
da8db399
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
da8db399
编写于
6月 27, 2022
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into feature/TD-11274-3.0
上级
23a9c8f3
0db14e94
变更
63
隐藏空白更改
内联
并排
Showing
63 changed file
with
3568 addition
and
821 deletion
+3568
-821
include/common/tdatablock.h
include/common/tdatablock.h
+1
-1
include/libs/nodes/plannodes.h
include/libs/nodes/plannodes.h
+11
-3
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+1
-0
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+2
-2
source/dnode/mnode/impl/inc/mndTrans.h
source/dnode/mnode/impl/inc/mndTrans.h
+3
-1
source/dnode/mnode/impl/src/mndShow.c
source/dnode/mnode/impl/src/mndShow.c
+1
-1
source/dnode/mnode/impl/src/mndTrans.c
source/dnode/mnode/impl/src/mndTrans.c
+63
-27
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+71
-24
source/dnode/vnode/src/sma/smaRollup.c
source/dnode/vnode/src/sma/smaRollup.c
+1
-1
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+1
-1
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+1
-4
source/libs/executor/inc/tsort.h
source/libs/executor/inc/tsort.h
+7
-0
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+6
-1
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+1
-11
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+2
-2
source/libs/executor/src/sortoperator.c
source/libs/executor/src/sortoperator.c
+80
-37
source/libs/executor/src/tsort.c
source/libs/executor/src/tsort.c
+4
-0
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+4
-2
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+31
-6
source/libs/nodes/src/nodesTraverseFuncs.c
source/libs/nodes/src/nodesTraverseFuncs.c
+2
-1
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+6
-3
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+0
-87
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+5
-0
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+4
-0
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+321
-195
source/libs/planner/src/planPhysiCreater.c
source/libs/planner/src/planPhysiCreater.c
+25
-15
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+34
-14
source/libs/planner/test/planBasicTest.cpp
source/libs/planner/test/planBasicTest.cpp
+8
-0
source/libs/planner/test/planTestMain.cpp
source/libs/planner/test/planTestMain.cpp
+4
-0
source/libs/planner/test/planTestUtil.cpp
source/libs/planner/test/planTestUtil.cpp
+19
-11
source/libs/planner/test/planTestUtil.h
source/libs/planner/test/planTestUtil.h
+1
-0
source/libs/sync/inc/syncRaftEntry.h
source/libs/sync/inc/syncRaftEntry.h
+25
-0
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+23
-19
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+8
-3
source/libs/sync/src/syncRaftEntry.c
source/libs/sync/src/syncRaftEntry.c
+244
-0
source/libs/sync/src/syncRespMgr.c
source/libs/sync/src/syncRespMgr.c
+7
-5
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+114
-74
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+14
-0
source/libs/sync/test/syncEntryCacheTest.cpp
source/libs/sync/test/syncEntryCacheTest.cpp
+162
-0
tests/parallel_test/container_build.sh
tests/parallel_test/container_build.sh
+1
-1
tests/pytest/util/constant.py
tests/pytest/util/constant.py
+103
-4
tests/pytest/util/sql.py
tests/pytest/util/sql.py
+37
-2
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+8
-4
tests/script/test-all.bat
tests/script/test-all.bat
+18
-8
tests/script/tsim/dnode/balance_replica1.sim
tests/script/tsim/dnode/balance_replica1.sim
+0
-1
tests/script/tsim/dnode/balance_replica3.sim
tests/script/tsim/dnode/balance_replica3.sim
+362
-0
tests/script/tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim
...script/tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim
+236
-17
tests/script/tsim/dnode/drop_dnode_has_vnode_replica3.sim
tests/script/tsim/dnode/drop_dnode_has_vnode_replica3.sim
+84
-14
tests/script/tsim/dnode/redistribute_vgroup_replica1.sim
tests/script/tsim/dnode/redistribute_vgroup_replica1.sim
+178
-0
tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim
...t/tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim
+1
-3
tests/script/tsim/dnode/redistribute_vgroup_replica3_v2.sim
tests/script/tsim/dnode/redistribute_vgroup_replica3_v2.sim
+245
-0
tests/script/tsim/dnode/redistribute_vgroup_replica3_v3.sim
tests/script/tsim/dnode/redistribute_vgroup_replica3_v3.sim
+263
-0
tests/script/tsim/stream/distributeInterval0.sim
tests/script/tsim/stream/distributeInterval0.sim
+1
-1
tests/script/tsim/stream/distributeIntervalRetrive0.sim
tests/script/tsim/stream/distributeIntervalRetrive0.sim
+291
-0
tests/script/tsim/stream/distributeSession0.sim
tests/script/tsim/stream/distributeSession0.sim
+0
-0
tests/system-test/1-insert/create_retentions.py
tests/system-test/1-insert/create_retentions.py
+41
-39
tests/system-test/1-insert/time_range_wise.py
tests/system-test/1-insert/time_range_wise.py
+358
-59
tests/system-test/2-query/join.py
tests/system-test/2-query/join.py
+1
-1
tests/system-test/2-query/join2.py
tests/system-test/2-query/join2.py
+1
-1
tests/system-test/2-query/substr.py
tests/system-test/2-query/substr.py
+1
-1
tests/system-test/2-query/tail.py
tests/system-test/2-query/tail.py
+3
-3
tests/system-test/fulltest.bat
tests/system-test/fulltest.bat
+0
-102
tests/system-test/test-all.bat
tests/system-test/test-all.bat
+18
-9
未找到文件。
include/common/tdatablock.h
浏览文件 @
da8db399
...
...
@@ -236,7 +236,7 @@ void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t*
int8_t
needCompress
);
const
char
*
blockCompressDecode
(
SSDataBlock
*
pBlock
,
int32_t
numOfCols
,
int32_t
numOfRows
,
const
char
*
pData
);
void
blockDebugShowData
(
const
SArray
*
dataBlocks
,
const
char
*
flag
);
void
blockDebugShowData
Blocks
(
const
SArray
*
dataBlocks
,
const
char
*
flag
);
// for debug
char
*
dumpBlockData
(
SSDataBlock
*
pDataBlock
,
const
char
*
flag
,
char
**
dumpBuf
);
...
...
include/libs/nodes/plannodes.h
浏览文件 @
da8db399
...
...
@@ -24,6 +24,8 @@ extern "C" {
#include "querynodes.h"
#include "tname.h"
#define SLOT_NAME_LEN TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN
typedef
struct
SLogicNode
{
ENodeType
type
;
SNodeList
*
pTargets
;
// SColumnNode
...
...
@@ -74,8 +76,8 @@ typedef struct SScanLogicNode {
int16_t
tsColId
;
double
filesFactor
;
SArray
*
pSmaIndexes
;
SNodeList
*
p
Part
Tags
;
bool
part
Sort
;
SNodeList
*
p
Group
Tags
;
bool
group
Sort
;
}
SScanLogicNode
;
typedef
struct
SJoinLogicNode
{
...
...
@@ -100,6 +102,7 @@ typedef struct SProjectLogicNode {
typedef
struct
SIndefRowsFuncLogicNode
{
SLogicNode
node
;
SNodeList
*
pFuncs
;
bool
isTailFunc
;
}
SIndefRowsFuncLogicNode
;
typedef
struct
SInterpFuncLogicNode
{
...
...
@@ -138,6 +141,7 @@ typedef struct SMergeLogicNode {
SNodeList
*
pInputs
;
int32_t
numOfChannels
;
int32_t
srcGroupId
;
bool
groupSort
;
}
SMergeLogicNode
;
typedef
enum
EWindowType
{
WINDOW_TYPE_INTERVAL
=
1
,
WINDOW_TYPE_SESSION
,
WINDOW_TYPE_STATE
}
EWindowType
;
...
...
@@ -184,6 +188,7 @@ typedef struct SFillLogicNode {
typedef
struct
SSortLogicNode
{
SLogicNode
node
;
SNodeList
*
pSortKeys
;
bool
groupSort
;
}
SSortLogicNode
;
typedef
struct
SPartitionLogicNode
{
...
...
@@ -230,6 +235,7 @@ typedef struct SSlotDescNode {
bool
reserve
;
bool
output
;
bool
tag
;
char
name
[
SLOT_NAME_LEN
];
}
SSlotDescNode
;
typedef
struct
SDataBlockDescNode
{
...
...
@@ -279,7 +285,8 @@ typedef struct STableScanPhysiNode {
double
ratio
;
int32_t
dataRequired
;
SNodeList
*
pDynamicScanFuncs
;
SNodeList
*
pPartitionTags
;
SNodeList
*
pGroupTags
;
bool
groupSort
;
int64_t
interval
;
int64_t
offset
;
int64_t
sliding
;
...
...
@@ -353,6 +360,7 @@ typedef struct SMergePhysiNode {
SNodeList
*
pTargets
;
int32_t
numOfChannels
;
int32_t
srcGroupId
;
bool
groupSort
;
}
SMergePhysiNode
;
typedef
struct
SWinodwPhysiNode
{
...
...
include/libs/nodes/querynodes.h
浏览文件 @
da8db399
...
...
@@ -259,6 +259,7 @@ typedef struct SSelectStmt {
bool
hasTailFunc
;
bool
hasInterpFunc
;
bool
hasLastRowFunc
;
bool
groupSort
;
}
SSelectStmt
;
typedef
enum
ESetOperatorType
{
SET_OP_TYPE_UNION_ALL
=
1
,
SET_OP_TYPE_UNION
}
ESetOperatorType
;
...
...
source/common/src/tdatablock.c
浏览文件 @
da8db399
...
...
@@ -1605,7 +1605,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
return
buf
;
}
void
blockDebugShowData
(
const
SArray
*
dataBlocks
,
const
char
*
flag
)
{
void
blockDebugShowData
Blocks
(
const
SArray
*
dataBlocks
,
const
char
*
flag
)
{
char
pBuf
[
128
]
=
{
0
};
int32_t
sz
=
taosArrayGetSize
(
dataBlocks
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
...
...
@@ -1613,7 +1613,7 @@ void blockDebugShowData(const SArray* dataBlocks, const char* flag) {
size_t
numOfCols
=
taosArrayGetSize
(
pDataBlock
->
pDataBlock
);
int32_t
rows
=
pDataBlock
->
info
.
rows
;
printf
(
"%s |block type %d |child id %d|
\n
"
,
flag
,
(
int32_t
)
pDataBlock
->
info
.
type
,
pDataBlock
->
info
.
child
Id
);
printf
(
"%s |block type %d |child id %d|
group id %zX
\n
"
,
flag
,
(
int32_t
)
pDataBlock
->
info
.
type
,
pDataBlock
->
info
.
childId
,
pDataBlock
->
info
.
group
Id
);
for
(
int32_t
j
=
0
;
j
<
rows
;
j
++
)
{
printf
(
"%s |"
,
flag
);
for
(
int32_t
k
=
0
;
k
<
numOfCols
;
k
++
)
{
...
...
source/dnode/mnode/impl/inc/mndTrans.h
浏览文件 @
da8db399
...
...
@@ -39,8 +39,10 @@ typedef struct {
int32_t
id
;
int32_t
errCode
;
int32_t
acceptableCode
;
ETrnStage
stag
e
;
int32_t
retryCod
e
;
ETrnAct
actionType
;
ETrnStage
stage
;
int8_t
reserved
;
int8_t
rawWritten
;
int8_t
msgSent
;
int8_t
msgReceived
;
...
...
source/dnode/mnode/impl/src/mndShow.c
浏览文件 @
da8db399
...
...
@@ -234,7 +234,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
if
(
retrieveReq
.
user
[
0
]
!=
0
)
{
memcpy
(
pReq
->
info
.
conn
.
user
,
retrieveReq
.
user
,
TSDB_USER_LEN
);
}
else
{
memcpy
(
pReq
->
info
.
conn
.
user
,
TSDB_DEFAULT_USER
,
TSDB_USER_LEN
);
memcpy
(
pReq
->
info
.
conn
.
user
,
TSDB_DEFAULT_USER
,
strlen
(
TSDB_DEFAULT_USER
)
+
1
);
}
if
(
mndCheckShowPrivilege
(
pMnode
,
pReq
->
info
.
conn
.
user
,
pShow
->
type
,
retrieveReq
.
db
)
!=
0
)
{
return
-
1
;
...
...
source/dnode/mnode/impl/src/mndTrans.c
浏览文件 @
da8db399
...
...
@@ -15,15 +15,15 @@
#define _DEFAULT_SOURCE
#include "mndTrans.h"
#include "mndPrivilege.h"
#include "mndConsumer.h"
#include "mndDb.h"
#include "mndPrivilege.h"
#include "mndShow.h"
#include "mndSync.h"
#include "mndUser.h"
#define TRANS_VER_NUMBER 1
#define TRANS_ARRAY_SIZE 8
#define TRANS_VER_NUMBER
1
#define TRANS_ARRAY_SIZE
8
#define TRANS_RESERVE_SIZE 64
static
SSdbRaw
*
mndTransActionEncode
(
STrans
*
pTrans
);
...
...
@@ -55,7 +55,7 @@ static bool mndTransPerfromFinishedStage(SMnode *pMnode, STrans *pTrans);
static
bool
mndCannotExecuteTransAction
(
SMnode
*
pMnode
)
{
return
!
pMnode
->
deploy
&&
!
mndIsMaster
(
pMnode
);
}
static
void
mndTransSendRpcRsp
(
SMnode
*
pMnode
,
STrans
*
pTrans
);
static
int32_t
mndProcessTrans
Req
(
SRpcMsg
*
pReq
);
static
int32_t
mndProcessTrans
Timer
(
SRpcMsg
*
pReq
);
static
int32_t
mndProcessTtl
(
SRpcMsg
*
pReq
);
static
int32_t
mndProcessKillTransReq
(
SRpcMsg
*
pReq
);
...
...
@@ -73,7 +73,7 @@ int32_t mndInitTrans(SMnode *pMnode) {
.
deleteFp
=
(
SdbDeleteFp
)
mndTransActionDelete
,
};
mndSetMsgHandle
(
pMnode
,
TDMT_MND_TRANS_TIMER
,
mndProcessTrans
Req
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_TRANS_TIMER
,
mndProcessTrans
Timer
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_KILL_TRANS
,
mndProcessKillTransReq
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_TRANS
,
mndRetrieveTrans
);
...
...
@@ -139,8 +139,10 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
id
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
errCode
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
acceptableCode
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
retryCode
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
actionType
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
stage
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
reserved
,
_OVER
)
if
(
pAction
->
actionType
==
TRANS_ACTION_RAW
)
{
int32_t
len
=
sdbGetRawTotalSize
(
pAction
->
pRaw
);
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
rawWritten
,
_OVER
)
...
...
@@ -163,8 +165,10 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
id
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
errCode
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
acceptableCode
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
retryCode
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
actionType
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
stage
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
reserved
,
_OVER
)
if
(
pAction
->
actionType
==
TRANS_ACTION_RAW
)
{
int32_t
len
=
sdbGetRawTotalSize
(
pAction
->
pRaw
);
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
rawWritten
,
_OVER
)
...
...
@@ -187,8 +191,10 @@ static SSdbRaw *mndTransActionEncode(STrans *pTrans) {
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
id
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
errCode
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
acceptableCode
,
_OVER
)
SDB_SET_INT32
(
pRaw
,
dataPos
,
pAction
->
retryCode
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
actionType
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
stage
,
_OVER
)
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
reserved
,
_OVER
)
if
(
pAction
->
actionType
==
TRANS_ACTION_RAW
)
{
int32_t
len
=
sdbGetRawTotalSize
(
pAction
->
pRaw
);
SDB_SET_INT8
(
pRaw
,
dataPos
,
pAction
->
rawWritten
,
_OVER
)
...
...
@@ -291,10 +297,12 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
id
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
errCode
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
acceptableCode
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
retryCode
,
_OVER
)
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
actionType
,
_OVER
)
action
.
actionType
=
actionType
;
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
stage
,
_OVER
)
action
.
stage
=
stage
;
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
action
.
reserved
,
_OVER
)
if
(
action
.
actionType
==
TRANS_ACTION_RAW
)
{
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
action
.
rawWritten
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
_OVER
)
...
...
@@ -324,10 +332,12 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
id
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
errCode
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
acceptableCode
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
retryCode
,
_OVER
)
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
actionType
,
_OVER
)
action
.
actionType
=
actionType
;
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
stage
,
_OVER
)
action
.
stage
=
stage
;
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
action
.
reserved
,
_OVER
)
if
(
action
.
actionType
==
TRANS_ACTION_RAW
)
{
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
action
.
rawWritten
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
_OVER
)
...
...
@@ -357,10 +367,12 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
id
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
errCode
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
acceptableCode
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
action
.
retryCode
,
_OVER
)
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
actionType
,
_OVER
)
action
.
actionType
=
actionType
;
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
stage
,
_OVER
)
action
.
stage
=
stage
;
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
action
.
reserved
,
_OVER
)
if
(
action
.
actionType
)
{
SDB_GET_INT8
(
pRaw
,
dataPos
,
&
action
.
rawWritten
,
_OVER
)
SDB_GET_INT32
(
pRaw
,
dataPos
,
&
dataLen
,
_OVER
)
...
...
@@ -463,15 +475,25 @@ static int32_t mndTransActionInsert(SSdb *pSdb, STrans *pTrans) {
if
(
fp
)
{
(
*
fp
)(
pSdb
->
pMnode
,
pTrans
->
param
,
pTrans
->
paramLen
);
}
pTrans
->
startFunc
=
0
;
}
return
0
;
}
static
void
mndTransDropData
(
STrans
*
pTrans
)
{
mndTransDropActions
(
pTrans
->
redoActions
);
mndTransDropActions
(
pTrans
->
undoActions
);
mndTransDropActions
(
pTrans
->
commitActions
);
if
(
pTrans
->
redoActions
!=
NULL
)
{
mndTransDropActions
(
pTrans
->
redoActions
);
pTrans
->
redoActions
=
NULL
;
}
if
(
pTrans
->
undoActions
!=
NULL
)
{
mndTransDropActions
(
pTrans
->
undoActions
);
pTrans
->
undoActions
=
NULL
;
}
if
(
pTrans
->
commitActions
!=
NULL
)
{
mndTransDropActions
(
pTrans
->
commitActions
);
pTrans
->
commitActions
=
NULL
;
}
if
(
pTrans
->
rpcRsp
!=
NULL
)
{
taosMemoryFree
(
pTrans
->
rpcRsp
);
pTrans
->
rpcRsp
=
NULL
;
...
...
@@ -492,6 +514,7 @@ static int32_t mndTransActionDelete(SSdb *pSdb, STrans *pTrans, bool callFunc) {
if
(
fp
)
{
(
*
fp
)(
pSdb
->
pMnode
,
pTrans
->
param
,
pTrans
->
paramLen
);
}
pTrans
->
stopFunc
=
0
;
}
mndTransDropData
(
pTrans
);
...
...
@@ -805,7 +828,7 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) {
sendRsp
=
true
;
}
}
else
{
if
(
pTrans
->
stage
==
TRN_STAGE_REDO_ACTION
&&
pTrans
->
failedTimes
>
3
)
{
if
(
pTrans
->
stage
==
TRN_STAGE_REDO_ACTION
&&
pTrans
->
failedTimes
>
6
)
{
if
(
code
==
0
)
code
=
TSDB_CODE_MND_TRANS_UNKNOW_ERROR
;
sendRsp
=
true
;
}
...
...
@@ -875,8 +898,8 @@ int32_t mndTransProcessRsp(SRpcMsg *pRsp) {
pAction
->
errCode
=
pRsp
->
code
;
}
mDebug
(
"trans:%d, %s:%d response is received, code:0x%x, accept:0x%x
"
,
transId
,
mndTransStr
(
pAction
->
stage
),
action
,
pRsp
->
code
,
pAction
->
acceptable
Code
);
mDebug
(
"trans:%d, %s:%d response is received, code:0x%x, accept:0x%x
retry:0x%x"
,
transId
,
mndTransStr
(
pAction
->
stage
),
action
,
pRsp
->
code
,
pAction
->
acceptableCode
,
pAction
->
retry
Code
);
mndTransExecute
(
pMnode
,
pTrans
);
_OVER:
...
...
@@ -884,6 +907,21 @@ _OVER:
return
0
;
}
static
void
mndTransResetAction
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
STransAction
*
pAction
)
{
pAction
->
rawWritten
=
0
;
pAction
->
msgSent
=
0
;
pAction
->
msgReceived
=
0
;
if
(
pAction
->
errCode
==
TSDB_CODE_RPC_REDIRECT
||
pAction
->
errCode
==
TSDB_CODE_SYN_NEW_CONFIG_ERROR
||
pAction
->
errCode
==
TSDB_CODE_SYN_INTERNAL_ERROR
||
pAction
->
errCode
==
TSDB_CODE_SYN_NOT_LEADER
)
{
pAction
->
epSet
.
inUse
=
(
pAction
->
epSet
.
inUse
+
1
)
%
pAction
->
epSet
.
numOfEps
;
mDebug
(
"trans:%d, %s:%d execute status is reset and set epset inuse:%d"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
,
pAction
->
epSet
.
inUse
);
}
else
{
mDebug
(
"trans:%d, %s:%d execute status is reset"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
);
}
pAction
->
errCode
=
0
;
}
static
void
mndTransResetActions
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
SArray
*
pArray
)
{
int32_t
numOfActions
=
taosArrayGetSize
(
pArray
);
...
...
@@ -894,18 +932,7 @@ static void mndTransResetActions(SMnode *pMnode, STrans *pTrans, SArray *pArray)
continue
;
if
(
pAction
->
rawWritten
&&
(
pAction
->
errCode
==
0
||
pAction
->
errCode
==
pAction
->
acceptableCode
))
continue
;
pAction
->
rawWritten
=
0
;
pAction
->
msgSent
=
0
;
pAction
->
msgReceived
=
0
;
if
(
pAction
->
errCode
==
TSDB_CODE_RPC_REDIRECT
||
pAction
->
errCode
==
TSDB_CODE_SYN_NEW_CONFIG_ERROR
||
pAction
->
errCode
==
TSDB_CODE_SYN_INTERNAL_ERROR
||
pAction
->
errCode
==
TSDB_CODE_SYN_NOT_LEADER
)
{
pAction
->
epSet
.
inUse
=
(
pAction
->
epSet
.
inUse
+
1
)
%
pAction
->
epSet
.
numOfEps
;
mDebug
(
"trans:%d, %s:%d execute status is reset and set epset inuse:%d"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
action
,
pAction
->
epSet
.
inUse
);
}
else
{
mDebug
(
"trans:%d, %s:%d execute status is reset"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
action
);
}
pAction
->
errCode
=
0
;
mndTransResetAction
(
pMnode
,
pTrans
,
pAction
);
}
}
...
...
@@ -1112,9 +1139,9 @@ static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans)
if
(
pAction
->
msgReceived
)
{
if
(
pAction
->
errCode
!=
0
&&
pAction
->
errCode
!=
pAction
->
acceptableCode
)
{
code
=
pAction
->
errCode
;
pAction
->
msgSent
=
0
;
pAction
->
msgReceived
=
0
;
mDebug
(
"trans:%d, %s:%d execute s
tatus is reset
"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
action
);
mndTransResetAction
(
pMnode
,
pTrans
,
pAction
)
;
}
else
{
mDebug
(
"trans:%d, %s:%d execute s
uccessfully
"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
action
);
}
}
else
{
code
=
TSDB_CODE_ACTION_IN_PROGRESS
;
...
...
@@ -1123,6 +1150,8 @@ static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans)
if
(
pAction
->
rawWritten
)
{
if
(
pAction
->
errCode
!=
0
&&
pAction
->
errCode
!=
pAction
->
acceptableCode
)
{
code
=
pAction
->
errCode
;
}
else
{
mDebug
(
"trans:%d, %s:%d write successfully"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
action
);
}
}
}
...
...
@@ -1156,9 +1185,16 @@ static int32_t mndTransExecuteRedoActionsSerial(SMnode *pMnode, STrans *pTrans)
}
else
if
(
code
==
TSDB_CODE_ACTION_IN_PROGRESS
)
{
mDebug
(
"trans:%d, %s:%d is in progress and wait it finish"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
);
break
;
}
else
if
(
code
==
pAction
->
retryCode
)
{
mDebug
(
"trans:%d, %s:%d receive code:0x%x and retry"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
,
code
);
taosMsleep
(
300
);
action
--
;
continue
;
}
else
{
terrno
=
code
;
pTrans
->
code
=
code
;
mDebug
(
"trans:%d, %s:%d receive code:0x%x and wait another schedule, failedTimes:%d"
,
pTrans
->
id
,
mndTransStr
(
pAction
->
stage
),
pAction
->
id
,
code
,
pTrans
->
failedTimes
);
break
;
}
}
...
...
@@ -1343,7 +1379,7 @@ void mndTransExecute(SMnode *pMnode, STrans *pTrans) {
mndTransSendRpcRsp
(
pMnode
,
pTrans
);
}
static
int32_t
mndProcessTrans
Req
(
SRpcMsg
*
pReq
)
{
static
int32_t
mndProcessTrans
Timer
(
SRpcMsg
*
pReq
)
{
mndTransPullup
(
pReq
->
info
.
node
);
return
0
;
}
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
da8db399
...
...
@@ -15,10 +15,10 @@
#define _DEFAULT_SOURCE
#include "mndVgroup.h"
#include "mndPrivilege.h"
#include "mndDb.h"
#include "mndDnode.h"
#include "mndMnode.h"
#include "mndPrivilege.h"
#include "mndShow.h"
#include "mndTrans.h"
#include "mndUser.h"
...
...
@@ -896,6 +896,8 @@ int32_t mndAddAlterVnodeConfirmAction(SMnode *pMnode, STrans *pTrans, SDbObj *pD
action
.
pCont
=
pHead
;
action
.
contLen
=
contLen
;
action
.
msgType
=
TDMT_VND_ALTER_CONFIRM
;
// incorrect redirect result will cause this erro
action
.
retryCode
=
TSDB_CODE_VND_INVALID_VGROUP_ID
;
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
taosMemoryFree
(
pHead
);
...
...
@@ -942,6 +944,8 @@ static int32_t mndAddSetVnodeStandByAction(SMnode *pMnode, STrans *pTrans, SDbOb
action
.
contLen
=
contLen
;
action
.
msgType
=
TDMT_SYNC_SET_VNODE_STANDBY
;
action
.
acceptableCode
=
TSDB_CODE_NODE_NOT_DEPLOYED
;
// Keep retrying until the target vnode is not the leader
action
.
retryCode
=
TSDB_CODE_SYN_IS_LEADER
;
if
(
isRedo
)
{
if
(
mndTransAppendRedoAction
(
pTrans
,
&
action
)
!=
0
)
{
...
...
@@ -1003,7 +1007,7 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb,
mInfo
(
"vgId:%d, will add 1 vnodes"
,
pVgroup
->
vgId
);
if
(
mndAddVnodeToVgroup
(
pMnode
,
&
newVg
,
pArray
)
!=
0
)
return
-
1
;
if
(
mndAddCreateVnodeAction
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
&
newVg
.
vnodeGid
[
1
],
true
)
!=
0
)
return
-
1
;
if
(
mndAddCreateVnodeAction
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
&
newVg
.
vnodeGid
[
newVg
.
replica
-
1
],
true
)
!=
0
)
return
-
1
;
if
(
mndAddAlterVnodeAction
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
TDMT_VND_ALTER_REPLICA
)
!=
0
)
return
-
1
;
if
(
mndAddAlterVnodeConfirmAction
(
pMnode
,
pTrans
,
pDb
,
&
newVg
)
!=
0
)
return
-
1
;
...
...
@@ -1017,10 +1021,19 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb,
if
(
mndAddDropVnodeAction
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
&
del
,
true
)
!=
0
)
return
-
1
;
if
(
mndAddAlterVnodeConfirmAction
(
pMnode
,
pTrans
,
pDb
,
&
newVg
)
!=
0
)
return
-
1
;
SSdbRaw
*
pRaw
=
mndVgroupActionEncode
(
&
newVg
);
if
(
pRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pRaw
)
!=
0
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
pRaw
=
NULL
;
{
SSdbRaw
*
pRaw
=
mndVgroupActionEncode
(
&
newVg
);
if
(
pRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRaw
)
!=
0
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
pRaw
=
NULL
;
}
{
SSdbRaw
*
pRaw
=
mndVgroupActionEncode
(
&
newVg
);
if
(
pRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pRaw
)
!=
0
)
return
-
1
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
pRaw
=
NULL
;
}
mInfo
(
"vgId:%d, vgroup info after move, replica:%d"
,
newVg
.
vgId
,
newVg
.
replica
);
for
(
int32_t
i
=
0
;
i
<
newVg
.
replica
;
++
i
)
{
...
...
@@ -1168,10 +1181,19 @@ static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb,
if
(
mndAddDecVgroupReplicaFromTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pOld3
->
id
)
!=
0
)
goto
_OVER
;
}
pRaw
=
mndVgroupActionEncode
(
&
newVg
);
if
(
pRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pRaw
)
!=
0
)
goto
_OVER
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
pRaw
=
NULL
;
{
pRaw
=
mndVgroupActionEncode
(
&
newVg
);
if
(
pRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRaw
)
!=
0
)
goto
_OVER
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
pRaw
=
NULL
;
}
{
pRaw
=
mndVgroupActionEncode
(
&
newVg
);
if
(
pRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pRaw
)
!=
0
)
goto
_OVER
;
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
pRaw
=
NULL
;
}
mInfo
(
"vgId:%d, vgroup info after redistribute, replica:%d"
,
newVg
.
vgId
,
newVg
.
replica
);
for
(
int32_t
i
=
0
;
i
<
newVg
.
replica
;
++
i
)
{
...
...
@@ -1229,7 +1251,8 @@ static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq) {
}
if
(
req
.
dnodeId1
==
pVgroup
->
vnodeGid
[
0
].
dnodeId
)
{
terrno
=
TSDB_CODE_MND_VGROUP_UN_CHANGED
;
// terrno = TSDB_CODE_MND_VGROUP_UN_CHANGED;
code
=
0
;
goto
_OVER
;
}
...
...
@@ -1351,7 +1374,8 @@ static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq) {
}
if
(
pNew1
==
NULL
&&
pOld1
==
NULL
&&
pNew2
==
NULL
&&
pOld2
==
NULL
&&
pNew3
==
NULL
&&
pOld3
==
NULL
)
{
terrno
=
TSDB_CODE_MND_VGROUP_UN_CHANGED
;
// terrno = TSDB_CODE_MND_VGROUP_UN_CHANGED;
code
=
0
;
goto
_OVER
;
}
...
...
@@ -1424,13 +1448,25 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, S
}
else
{
}
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
&
newVgroup
);
if
(
pVgRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pVgRaw
)
!=
0
)
{
sdbFreeRaw
(
pVgRaw
);
return
-
1
;
{
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
&
newVgroup
);
if
(
pVgRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendRedolog
(
pTrans
,
pVgRaw
)
!=
0
)
{
sdbFreeRaw
(
pVgRaw
);
return
-
1
;
}
sdbSetRawStatus
(
pVgRaw
,
SDB_STATUS_READY
);
}
{
SSdbRaw
*
pVgRaw
=
mndVgroupActionEncode
(
&
newVgroup
);
if
(
pVgRaw
==
NULL
)
return
-
1
;
if
(
mndTransAppendCommitlog
(
pTrans
,
pVgRaw
)
!=
0
)
{
sdbFreeRaw
(
pVgRaw
);
return
-
1
;
}
sdbSetRawStatus
(
pVgRaw
,
SDB_STATUS_READY
);
}
sdbSetRawStatus
(
pVgRaw
,
SDB_STATUS_READY
);
}
return
0
;
...
...
@@ -1538,12 +1574,23 @@ static int32_t mndSetBalanceVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SD
if
(
mndAddIncVgroupReplicaToTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pDst
->
id
)
!=
0
)
return
-
1
;
if
(
mndAddDecVgroupReplicaFromTrans
(
pMnode
,
pTrans
,
pDb
,
&
newVg
,
pSrc
->
id
)
!=
0
)
return
-
1
;
SSdbRaw
*
pRaw
=
mndVgroupActionEncode
(
&
newVg
);
if
(
pRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pRaw
)
!=
0
)
{
sdbFreeRaw
(
pRaw
);
return
-
1
;
{
SSdbRaw
*
pRaw
=
mndVgroupActionEncode
(
&
newVg
);
if
(
pRaw
==
NULL
||
mndTransAppendRedolog
(
pTrans
,
pRaw
)
!=
0
)
{
sdbFreeRaw
(
pRaw
);
return
-
1
;
}
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
}
{
SSdbRaw
*
pRaw
=
mndVgroupActionEncode
(
&
newVg
);
if
(
pRaw
==
NULL
||
mndTransAppendCommitlog
(
pTrans
,
pRaw
)
!=
0
)
{
sdbFreeRaw
(
pRaw
);
return
-
1
;
}
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
}
sdbSetRawStatus
(
pRaw
,
SDB_STATUS_READY
);
mInfo
(
"vgId:%d, vgroup info after balance, replica:%d"
,
newVg
.
vgId
,
newVg
.
replica
);
for
(
int32_t
i
=
0
;
i
<
newVg
.
replica
;
++
i
)
{
...
...
@@ -1624,7 +1671,7 @@ static int32_t mndBalanceVgroup(SMnode *pMnode, SRpcMsg *pReq, SArray *pArray) {
return
-
1
;
}
}
else
{
mDebug
(
"trans:%d, no vgroup need to balance
vgroup
any more"
,
pTrans
->
id
);
mDebug
(
"trans:%d, no vgroup need to balance any more"
,
pTrans
->
id
);
break
;
}
}
...
...
source/dnode/vnode/src/sma/smaRollup.c
浏览文件 @
da8db399
...
...
@@ -529,7 +529,7 @@ static int32_t tdFetchAndSubmitRSmaResult(SRSmaInfoItem *pItem, int8_t blkType)
#if 1
char
flag
[
10
]
=
{
0
};
snprintf
(
flag
,
10
,
"level %"
PRIi8
,
pItem
->
level
);
blockDebugShowData
(
pResult
,
flag
);
blockDebugShowData
Blocks
(
pResult
,
flag
);
#endif
STsdb
*
sinkTsdb
=
(
pItem
->
level
==
TSDB_RETENTION_L1
?
pSma
->
pRSmaTsdb1
:
pSma
->
pRSmaTsdb2
);
SSubmitReq
*
pReq
=
NULL
;
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
da8db399
...
...
@@ -299,7 +299,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRp
void
smaHandleRes
(
void
*
pVnode
,
int64_t
smaId
,
const
SArray
*
data
)
{
// TODO
blockDebugShowData
(
data
,
__func__
);
blockDebugShowData
Blocks
(
data
,
__func__
);
tdProcessTSmaInsert
(((
SVnode
*
)
pVnode
)
->
pSma
,
smaId
,
(
const
char
*
)
data
);
}
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
da8db399
...
...
@@ -730,10 +730,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo*
SOperatorInfo
*
createIndefinitOutputOperatorInfo
(
SOperatorInfo
*
downstream
,
SPhysiNode
*
pNode
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createProjectOperatorInfo
(
SOperatorInfo
*
downstream
,
SProjectPhysiNode
*
pProjPhyNode
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createSortOperatorInfo
(
SOperatorInfo
*
downstream
,
SSortPhysiNode
*
pSortPhyNode
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createMultiwaySortMergeOperatorInfo
(
SOperatorInfo
**
downStreams
,
int32_t
numStreams
,
SSDataBlock
*
pInputBlock
,
SSDataBlock
*
pResBlock
,
SArray
*
pSortInfo
,
SArray
*
pColMatchColInfo
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createMultiwayMergeOperatorInfo
(
SOperatorInfo
**
dowStreams
,
size_t
numStreams
,
SMergePhysiNode
*
pMergePhysiNode
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createSortedMergeOperatorInfo
(
SOperatorInfo
**
downstream
,
int32_t
numOfDownstream
,
SExprInfo
*
pExprInfo
,
int32_t
num
,
SArray
*
pSortInfo
,
SArray
*
pGroupInfo
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createIntervalOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
...
...
source/libs/executor/inc/tsort.h
浏览文件 @
da8db399
...
...
@@ -136,6 +136,13 @@ bool tsortIsNullVal(STupleHandle* pVHandle, int32_t colId);
*/
void
*
tsortGetValue
(
STupleHandle
*
pVHandle
,
int32_t
colId
);
/**
*
* @param pVHandle
* @return
*/
uint64_t
tsortGetGroupId
(
STupleHandle
*
pVHandle
);
/**
*
* @param pSortHandle
...
...
source/libs/executor/src/executil.c
浏览文件 @
da8db399
...
...
@@ -159,7 +159,12 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo) {
}
SArray
*
createSortInfo
(
SNodeList
*
pNodeList
)
{
size_t
numOfCols
=
LIST_LENGTH
(
pNodeList
);
size_t
numOfCols
=
0
;
if
(
pNodeList
!=
NULL
)
{
numOfCols
=
LIST_LENGTH
(
pNodeList
);
}
else
{
numOfCols
=
0
;
}
SArray
*
pList
=
taosArrayInit
(
numOfCols
,
sizeof
(
SBlockOrderInfo
));
if
(
pList
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
da8db399
...
...
@@ -4269,17 +4269,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
pOptr
=
createGroupSortOperatorInfo
(
ops
[
0
],
(
SGroupSortPhysiNode
*
)
pPhyNode
,
pTaskInfo
);
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_MERGE
==
type
)
{
SMergePhysiNode
*
pMergePhyNode
=
(
SMergePhysiNode
*
)
pPhyNode
;
SDataBlockDescNode
*
pDescNode
=
pPhyNode
->
pOutputDataBlockDesc
;
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pDescNode
);
SArray
*
sortInfo
=
createSortInfo
(
pMergePhyNode
->
pMergeKeys
);
int32_t
numOfOutputCols
=
0
;
SArray
*
pColList
=
extractColMatchInfo
(
pMergePhyNode
->
pTargets
,
pDescNode
,
&
numOfOutputCols
,
COL_MATCH_FROM_SLOT_ID
);
SPhysiNode
*
pChildNode
=
(
SPhysiNode
*
)
nodesListGetNode
(
pPhyNode
->
pChildren
,
0
);
SSDataBlock
*
pInputDataBlock
=
createResDataBlock
(
pChildNode
->
pOutputDataBlockDesc
);
pOptr
=
createMultiwaySortMergeOperatorInfo
(
ops
,
size
,
pInputDataBlock
,
pResBlock
,
sortInfo
,
pColList
,
pTaskInfo
);
pOptr
=
createMultiwayMergeOperatorInfo
(
ops
,
size
,
pMergePhyNode
,
pTaskInfo
);
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION
==
type
)
{
SSessionWinodwPhysiNode
*
pSessionNode
=
(
SSessionWinodwPhysiNode
*
)
pPhyNode
;
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
da8db399
...
...
@@ -2051,7 +2051,7 @@ int32_t createScanTableListInfo(STableScanPhysiNode* pTableScanNode, SReadHandle
qDebug
(
"no table qualified for query, TID:0x%"
PRIx64
", QID:0x%"
PRIx64
,
taskId
,
queryId
);
return
TSDB_CODE_SUCCESS
;
}
code
=
generateGroupIdMap
(
pTableListInfo
,
pHandle
,
pTableScanNode
->
p
Partition
Tags
);
code
=
generateGroupIdMap
(
pTableListInfo
,
pHandle
,
pTableScanNode
->
p
Group
Tags
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -2455,7 +2455,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
goto
_error
;
}
if
(
pTableScanNode
->
p
Partition
Tags
)
{
if
(
pTableScanNode
->
p
Group
Tags
)
{
taosArraySort
(
pTableListInfo
->
pTableList
,
compareTableKeyInfoByGid
);
}
...
...
source/libs/executor/src/sortoperator.c
浏览文件 @
da8db399
...
...
@@ -142,7 +142,8 @@ SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, i
SSDataBlock
*
loadNextDataBlock
(
void
*
param
)
{
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
return
pOperator
->
fpSet
.
getNextFn
(
pOperator
);
SSDataBlock
*
pBlock
=
pOperator
->
fpSet
.
getNextFn
(
pOperator
);
return
pBlock
;
}
// todo refactor: merged with fetch fp
...
...
@@ -442,7 +443,7 @@ void destroyGroupSortOperatorInfo(void* param, int32_t numOfOutput) {
SOperatorInfo
*
createGroupSortOperatorInfo
(
SOperatorInfo
*
downstream
,
SGroupSortPhysiNode
*
pSortPhyNode
,
SExecTaskInfo
*
pTaskInfo
)
{
SGroupSortOperatorInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SGroupSortOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
if
(
pInfo
==
NULL
||
pOperator
==
NULL
/* || rowSize > 100 * 1024 * 1024*/
)
{
goto
_error
;
}
...
...
@@ -474,8 +475,8 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort
pOperator
->
exprSupp
.
numOfExprs
=
numOfCols
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
fpSet
=
createOperatorFpSet
(
operatorDummyOpenFn
,
doGroupSort
,
NULL
,
NULL
,
destroyGroupSortOperatorInfo
,
NULL
,
NULL
,
getGroupSortExplainExecInfo
);
pOperator
->
fpSet
=
createOperatorFpSet
(
operatorDummyOpenFn
,
doGroupSort
,
NULL
,
NULL
,
destroyGroupSortOperatorInfo
,
NULL
,
NULL
,
getGroupSortExplainExecInfo
);
int32_t
code
=
appendDownstream
(
pOperator
,
&
downstream
,
1
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -493,7 +494,7 @@ _error:
//=====================================================================================
// Multiway Sort Merge operator
typedef
struct
SMultiway
Sort
MergeOperatorInfo
{
typedef
struct
SMultiwayMergeOperatorInfo
{
SOptrBasicInfo
binfo
;
int32_t
bufPageSize
;
...
...
@@ -503,14 +504,17 @@ typedef struct SMultiwaySortMergeOperatorInfo {
SSortHandle
*
pSortHandle
;
SArray
*
pColMatchInfo
;
// for index map from table scan output
SSDataBlock
*
pInputBlock
;
int64_t
startTs
;
// sort start time
uint64_t
groupId
;
}
SMultiwaySortMergeOperatorInfo
;
SSDataBlock
*
pInputBlock
;
int64_t
startTs
;
// sort start time
bool
groupSort
;
bool
hasGroupId
;
uint64_t
groupId
;
STupleHandle
*
prefetchedTuple
;
}
SMultiwayMergeOperatorInfo
;
int32_t
doOpenMultiway
Sort
MergeOperator
(
SOperatorInfo
*
pOperator
)
{
SMultiway
Sort
MergeOperatorInfo
*
pInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
int32_t
doOpenMultiwayMergeOperator
(
SOperatorInfo
*
pOperator
)
{
SMultiwayMergeOperatorInfo
*
pInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
if
(
OPTR_IS_OPENED
(
pOperator
))
{
return
TSDB_CODE_SUCCESS
;
...
...
@@ -524,8 +528,9 @@ int32_t doOpenMultiwaySortMergeOperator(SOperatorInfo* pOperator) {
pInfo
->
pInputBlock
,
pTaskInfo
->
id
.
str
);
tsortSetFetchRawDataFp
(
pInfo
->
pSortHandle
,
loadNextDataBlock
,
NULL
,
NULL
);
tsortSetCompareGroupId
(
pInfo
->
pSortHandle
,
true
);
tsortSetCompareGroupId
(
pInfo
->
pSortHandle
,
pInfo
->
groupSort
);
for
(
int32_t
i
=
0
;
i
<
pOperator
->
numOfDownstream
;
++
i
)
{
SSortSource
*
ps
=
taosMemoryCalloc
(
1
,
sizeof
(
SSortSource
));
ps
->
param
=
pOperator
->
pDownstream
[
i
];
...
...
@@ -547,8 +552,8 @@ int32_t doOpenMultiwaySortMergeOperator(SOperatorInfo* pOperator) {
SSDataBlock
*
getMultiwaySortedBlockData
(
SSortHandle
*
pHandle
,
SSDataBlock
*
pDataBlock
,
int32_t
capacity
,
SArray
*
pColMatchInfo
,
SOperatorInfo
*
pOperator
)
{
SMultiway
Sort
MergeOperatorInfo
*
pInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SMultiwayMergeOperatorInfo
*
pInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
blockDataCleanup
(
pDataBlock
);
...
...
@@ -560,18 +565,47 @@ SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pData
blockDataEnsureCapacity
(
p
,
capacity
);
while
(
1
)
{
STupleHandle
*
pTupleHandle
=
tsortNextTuple
(
pHandle
);
STupleHandle
*
pTupleHandle
=
NULL
;
if
(
pInfo
->
groupSort
)
{
if
(
pInfo
->
prefetchedTuple
==
NULL
)
{
pTupleHandle
=
tsortNextTuple
(
pHandle
);
}
else
{
pTupleHandle
=
pInfo
->
prefetchedTuple
;
pInfo
->
groupId
=
tsortGetGroupId
(
pTupleHandle
);
pInfo
->
prefetchedTuple
=
NULL
;
}
}
else
{
pTupleHandle
=
tsortNextTuple
(
pHandle
);
pInfo
->
groupId
=
0
;
}
if
(
pTupleHandle
==
NULL
)
{
break
;
}
appendOneRowToDataBlock
(
p
,
pTupleHandle
);
if
(
pInfo
->
groupSort
)
{
uint64_t
tupleGroupId
=
tsortGetGroupId
(
pTupleHandle
);
if
(
!
pInfo
->
hasGroupId
)
{
pInfo
->
groupId
=
tupleGroupId
;
pInfo
->
hasGroupId
=
true
;
appendOneRowToDataBlock
(
p
,
pTupleHandle
);
}
else
if
(
pInfo
->
groupId
==
tupleGroupId
)
{
appendOneRowToDataBlock
(
p
,
pTupleHandle
);
}
else
{
pInfo
->
prefetchedTuple
=
pTupleHandle
;
break
;
}
}
else
{
appendOneRowToDataBlock
(
p
,
pTupleHandle
);
}
if
(
p
->
info
.
rows
>=
capacity
)
{
break
;
}
}
if
(
p
->
info
.
rows
>
0
)
{
// todo extract method
if
(
p
->
info
.
rows
>
0
)
{
// todo extract method
blockDataEnsureCapacity
(
pDataBlock
,
p
->
info
.
rows
);
int32_t
numOfCols
=
taosArrayGetSize
(
pColMatchInfo
);
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
...
...
@@ -593,13 +627,13 @@ SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pData
return
(
pDataBlock
->
info
.
rows
>
0
)
?
pDataBlock
:
NULL
;
}
SSDataBlock
*
doMultiway
Sort
Merge
(
SOperatorInfo
*
pOperator
)
{
SSDataBlock
*
doMultiwayMerge
(
SOperatorInfo
*
pOperator
)
{
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
}
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SMultiway
Sort
MergeOperatorInfo
*
pInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SMultiwayMergeOperatorInfo
*
pInfo
=
pOperator
->
info
;
int32_t
code
=
pOperator
->
fpSet
.
_openFn
(
pOperator
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -608,7 +642,6 @@ SSDataBlock* doMultiwaySortMerge(SOperatorInfo* pOperator) {
SSDataBlock
*
pBlock
=
getMultiwaySortedBlockData
(
pInfo
->
pSortHandle
,
pInfo
->
binfo
.
pRes
,
pOperator
->
resultInfo
.
capacity
,
pInfo
->
pColMatchInfo
,
pOperator
);
if
(
pBlock
!=
NULL
)
{
pOperator
->
resultInfo
.
totalRows
+=
pBlock
->
info
.
rows
;
}
else
{
...
...
@@ -617,8 +650,8 @@ SSDataBlock* doMultiwaySortMerge(SOperatorInfo* pOperator) {
return
pBlock
;
}
void
destroyMultiway
Sort
MergeOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
SMultiway
SortMergeOperatorInfo
*
pInfo
=
(
SMultiwaySort
MergeOperatorInfo
*
)
param
;
void
destroyMultiwayMergeOperatorInfo
(
void
*
param
,
int32_t
numOfOutput
)
{
SMultiway
MergeOperatorInfo
*
pInfo
=
(
SMultiway
MergeOperatorInfo
*
)
param
;
pInfo
->
binfo
.
pRes
=
blockDataDestroy
(
pInfo
->
binfo
.
pRes
);
pInfo
->
pInputBlock
=
blockDataDestroy
(
pInfo
->
pInputBlock
);
...
...
@@ -626,11 +659,11 @@ void destroyMultiwaySortMergeOperatorInfo(void* param, int32_t numOfOutput) {
taosArrayDestroy
(
pInfo
->
pColMatchInfo
);
}
int32_t
getMultiway
Sort
MergeExplainExecInfo
(
SOperatorInfo
*
pOptr
,
void
**
pOptrExplain
,
uint32_t
*
len
)
{
int32_t
getMultiwayMergeExplainExecInfo
(
SOperatorInfo
*
pOptr
,
void
**
pOptrExplain
,
uint32_t
*
len
)
{
ASSERT
(
pOptr
!=
NULL
);
SSortExecInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SSortExecInfo
));
SMultiway
SortMergeOperatorInfo
*
pOperatorInfo
=
(
SMultiwaySort
MergeOperatorInfo
*
)
pOptr
->
info
;
SMultiway
MergeOperatorInfo
*
pOperatorInfo
=
(
SMultiway
MergeOperatorInfo
*
)
pOptr
->
info
;
*
pInfo
=
tsortGetSortExecInfo
(
pOperatorInfo
->
pSortHandle
);
*
pOptrExplain
=
pInfo
;
...
...
@@ -638,24 +671,35 @@ int32_t getMultiwaySortMergeExplainExecInfo(SOperatorInfo* pOptr, void** pOptrEx
return
TSDB_CODE_SUCCESS
;
}
SOperatorInfo
*
createMultiwaySortMergeOperatorInfo
(
SOperatorInfo
**
downStreams
,
int32_t
numStreams
,
SSDataBlock
*
pInputBlock
,
SSDataBlock
*
pResBlock
,
SArray
*
pSortInfo
,
SArray
*
pColMatchColInfo
,
SExecTaskInfo
*
pTaskInfo
)
{
SMultiwaySortMergeOperatorInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SMultiwaySortMergeOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
int32_t
rowSize
=
pResBlock
->
info
.
rowSize
;
SOperatorInfo
*
createMultiwayMergeOperatorInfo
(
SOperatorInfo
**
downStreams
,
size_t
numStreams
,
SMergePhysiNode
*
pMergePhyNode
,
SExecTaskInfo
*
pTaskInfo
)
{
SPhysiNode
*
pPhyNode
=
(
SPhysiNode
*
)
pMergePhyNode
;
SMultiwayMergeOperatorInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SMultiwayMergeOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
SDataBlockDescNode
*
pDescNode
=
pPhyNode
->
pOutputDataBlockDesc
;
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pDescNode
);
int32_t
rowSize
=
pResBlock
->
info
.
rowSize
;
if
(
pInfo
==
NULL
||
pOperator
==
NULL
||
rowSize
>
100
*
1024
*
1024
)
{
goto
_error
;
}
SArray
*
pSortInfo
=
createSortInfo
(
pMergePhyNode
->
pMergeKeys
);
int32_t
numOfOutputCols
=
0
;
SArray
*
pColMatchColInfo
=
extractColMatchInfo
(
pMergePhyNode
->
pTargets
,
pDescNode
,
&
numOfOutputCols
,
COL_MATCH_FROM_SLOT_ID
);
SPhysiNode
*
pChildNode
=
(
SPhysiNode
*
)
nodesListGetNode
(
pPhyNode
->
pChildren
,
0
);
SSDataBlock
*
pInputBlock
=
createResDataBlock
(
pChildNode
->
pOutputDataBlockDesc
);
initResultSizeInfo
(
pOperator
,
1024
);
pInfo
->
groupSort
=
pMergePhyNode
->
groupSort
;
pInfo
->
binfo
.
pRes
=
pResBlock
;
pInfo
->
pSortInfo
=
pSortInfo
;
pInfo
->
pColMatchInfo
=
pColMatchColInfo
;
pInfo
->
pInputBlock
=
pInputBlock
;
pOperator
->
name
=
"Multiway
Sort
Merge"
;
pOperator
->
name
=
"MultiwayMerge"
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_MERGE
;
pOperator
->
blocking
=
false
;
pOperator
->
status
=
OP_NOT_OPENED
;
...
...
@@ -667,9 +711,8 @@ SOperatorInfo* createMultiwaySortMergeOperatorInfo(SOperatorInfo** downStreams,
// one additional is reserved for merged result.
pInfo
->
sortBufSize
=
pInfo
->
bufPageSize
*
(
numStreams
+
1
);
pOperator
->
fpSet
=
createOperatorFpSet
(
doOpenMultiwaySortMergeOperator
,
doMultiwaySortMerge
,
NULL
,
NULL
,
destroyMultiwaySortMergeOperatorInfo
,
NULL
,
NULL
,
getMultiwaySortMergeExplainExecInfo
);
pOperator
->
fpSet
=
createOperatorFpSet
(
doOpenMultiwayMergeOperator
,
doMultiwayMerge
,
NULL
,
NULL
,
destroyMultiwayMergeOperatorInfo
,
NULL
,
NULL
,
getMultiwayMergeExplainExecInfo
);
int32_t
code
=
appendDownstream
(
pOperator
,
downStreams
,
numStreams
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
source/libs/executor/src/tsort.c
浏览文件 @
da8db399
...
...
@@ -752,6 +752,10 @@ void* tsortGetValue(STupleHandle* pVHandle, int32_t colIndex) {
}
}
uint64_t
tsortGetGroupId
(
STupleHandle
*
pVHandle
)
{
return
pVHandle
->
pBlock
->
info
.
groupId
;
}
SSortExecInfo
tsortGetSortExecInfo
(
SSortHandle
*
pHandle
)
{
SSortExecInfo
info
=
{
0
};
...
...
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
da8db399
...
...
@@ -351,7 +351,7 @@ static int32_t logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
COPY_SCALAR_FIELD
(
watermark
);
COPY_SCALAR_FIELD
(
tsColId
);
COPY_SCALAR_FIELD
(
filesFactor
);
CLONE_NODE_LIST_FIELD
(
p
Part
Tags
);
CLONE_NODE_LIST_FIELD
(
p
Group
Tags
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -401,6 +401,7 @@ static int32_t logicMergeCopy(const SMergeLogicNode* pSrc, SMergeLogicNode* pDst
CLONE_NODE_LIST_FIELD
(
pInputs
);
COPY_SCALAR_FIELD
(
numOfChannels
);
COPY_SCALAR_FIELD
(
srcGroupId
);
COPY_SCALAR_FIELD
(
groupSort
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -436,6 +437,7 @@ static int32_t logicFillCopy(const SFillLogicNode* pSrc, SFillLogicNode* pDst) {
static
int32_t
logicSortCopy
(
const
SSortLogicNode
*
pSrc
,
SSortLogicNode
*
pDst
)
{
COPY_BASE_OBJECT_FIELD
(
node
,
logicNodeCopy
);
CLONE_NODE_LIST_FIELD
(
pSortKeys
);
COPY_SCALAR_FIELD
(
groupSort
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -500,7 +502,7 @@ static int32_t physiTableScanCopy(const STableScanPhysiNode* pSrc, STableScanPhy
COPY_SCALAR_FIELD
(
ratio
);
COPY_SCALAR_FIELD
(
dataRequired
);
CLONE_NODE_LIST_FIELD
(
pDynamicScanFuncs
);
CLONE_NODE_LIST_FIELD
(
p
Partition
Tags
);
CLONE_NODE_LIST_FIELD
(
p
Group
Tags
);
COPY_SCALAR_FIELD
(
interval
);
COPY_SCALAR_FIELD
(
offset
);
COPY_SCALAR_FIELD
(
sliding
);
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
da8db399
...
...
@@ -234,6 +234,8 @@ const char* nodesNodeName(ENodeType type) {
return
"PhysiMerge"
;
case
QUERY_NODE_PHYSICAL_PLAN_SORT
:
return
"PhysiSort"
;
case
QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT
:
return
"PhysiGroupSort"
;
case
QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL
:
return
"PhysiHashInterval"
;
case
QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL
:
...
...
@@ -539,7 +541,7 @@ static const char* jkScanLogicPlanScanPseudoCols = "ScanPseudoCols";
static
const
char
*
jkScanLogicPlanTableId
=
"TableId"
;
static
const
char
*
jkScanLogicPlanTableType
=
"TableType"
;
static
const
char
*
jkScanLogicPlanTagCond
=
"TagCond"
;
static
const
char
*
jkScanLogicPlan
PartTags
=
"Part
Tags"
;
static
const
char
*
jkScanLogicPlan
GroupTags
=
"Group
Tags"
;
static
int32_t
logicScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SScanLogicNode
*
pNode
=
(
const
SScanLogicNode
*
)
pObj
;
...
...
@@ -561,7 +563,7 @@ static int32_t logicScanNodeToJson(const void* pObj, SJson* pJson) {
code
=
tjsonAddObject
(
pJson
,
jkScanLogicPlanTagCond
,
nodeToJson
,
pNode
->
pTagCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodeListToJson
(
pJson
,
jkScanLogicPlan
PartTags
,
pNode
->
pPart
Tags
);
code
=
nodeListToJson
(
pJson
,
jkScanLogicPlan
GroupTags
,
pNode
->
pGroup
Tags
);
}
return
code
;
...
...
@@ -588,7 +590,7 @@ static int32_t jsonToLogicScanNode(const SJson* pJson, void* pObj) {
code
=
jsonToNodeObject
(
pJson
,
jkScanLogicPlanTagCond
,
&
pNode
->
pTagCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkScanLogicPlan
PartTags
,
&
pNode
->
pPart
Tags
);
code
=
jsonToNodeList
(
pJson
,
jkScanLogicPlan
GroupTags
,
&
pNode
->
pGroup
Tags
);
}
return
code
;
...
...
@@ -1430,7 +1432,8 @@ static const char* jkTableScanPhysiPlanTriggerType = "triggerType";
static
const
char
*
jkTableScanPhysiPlanWatermark
=
"watermark"
;
static
const
char
*
jkTableScanPhysiPlanTsColId
=
"tsColId"
;
static
const
char
*
jkTableScanPhysiPlanFilesFactor
=
"FilesFactor"
;
static
const
char
*
jkTableScanPhysiPlanPartitionTags
=
"PartitionTags"
;
static
const
char
*
jkTableScanPhysiPlanGroupTags
=
"GroupTags"
;
static
const
char
*
jkTableScanPhysiPlanGroupSort
=
"GroupSort"
;
static
int32_t
physiTableScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
STableScanPhysiNode
*
pNode
=
(
const
STableScanPhysiNode
*
)
pObj
;
...
...
@@ -1485,7 +1488,10 @@ static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) {
code
=
tjsonAddDoubleToObject
(
pJson
,
jkTableScanPhysiPlanFilesFactor
,
pNode
->
filesFactor
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodeListToJson
(
pJson
,
jkTableScanPhysiPlanPartitionTags
,
pNode
->
pPartitionTags
);
code
=
nodeListToJson
(
pJson
,
jkTableScanPhysiPlanGroupTags
,
pNode
->
pGroupTags
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddBoolToObject
(
pJson
,
jkTableScanPhysiPlanGroupSort
,
pNode
->
groupSort
);
}
return
code
;
...
...
@@ -1544,7 +1550,10 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
code
=
tjsonGetDoubleValue
(
pJson
,
jkTableScanPhysiPlanFilesFactor
,
&
pNode
->
filesFactor
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkTableScanPhysiPlanPartitionTags
,
&
pNode
->
pPartitionTags
);
code
=
jsonToNodeList
(
pJson
,
jkTableScanPhysiPlanGroupTags
,
&
pNode
->
pGroupTags
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetBoolValue
(
pJson
,
jkTableScanPhysiPlanGroupSort
,
&
pNode
->
groupSort
);
}
return
code
;
...
...
@@ -1725,6 +1734,7 @@ static const char* jkMergePhysiPlanMergeKeys = "MergeKeys";
static
const
char
*
jkMergePhysiPlanTargets
=
"Targets"
;
static
const
char
*
jkMergePhysiPlanNumOfChannels
=
"NumOfChannels"
;
static
const
char
*
jkMergePhysiPlanSrcGroupId
=
"SrcGroupId"
;
static
const
char
*
jkMergePhysiPlanGroupSort
=
"GroupSort"
;
static
int32_t
physiMergeNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SMergePhysiNode
*
pNode
=
(
const
SMergePhysiNode
*
)
pObj
;
...
...
@@ -1742,6 +1752,9 @@ static int32_t physiMergeNodeToJson(const void* pObj, SJson* pJson) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkMergePhysiPlanSrcGroupId
,
pNode
->
srcGroupId
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddBoolToObject
(
pJson
,
jkMergePhysiPlanGroupSort
,
pNode
->
groupSort
);
}
return
code
;
}
...
...
@@ -1762,6 +1775,9 @@ static int32_t jsonToPhysiMergeNode(const SJson* pJson, void* pObj) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetIntValue
(
pJson
,
jkMergePhysiPlanSrcGroupId
,
&
pNode
->
srcGroupId
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetBoolValue
(
pJson
,
jkMergePhysiPlanGroupSort
,
&
pNode
->
groupSort
);
}
return
code
;
}
...
...
@@ -3369,6 +3385,7 @@ static const char* jkSlotDescSlotId = "SlotId";
static
const
char
*
jkSlotDescDataType
=
"DataType"
;
static
const
char
*
jkSlotDescReserve
=
"Reserve"
;
static
const
char
*
jkSlotDescOutput
=
"Output"
;
static
const
char
*
jkSlotDescName
=
"Name"
;
static
int32_t
slotDescNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SSlotDescNode
*
pNode
=
(
const
SSlotDescNode
*
)
pObj
;
...
...
@@ -3383,6 +3400,9 @@ static int32_t slotDescNodeToJson(const void* pObj, SJson* pJson) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddBoolToObject
(
pJson
,
jkSlotDescOutput
,
pNode
->
output
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddStringToObject
(
pJson
,
jkSlotDescName
,
pNode
->
name
);
}
return
code
;
}
...
...
@@ -3400,6 +3420,9 @@ static int32_t jsonToSlotDescNode(const SJson* pJson, void* pObj) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetBoolValue
(
pJson
,
jkSlotDescOutput
,
&
pNode
->
output
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetStringValue
(
pJson
,
jkSlotDescName
,
pNode
->
name
);
}
return
code
;
}
...
...
@@ -4137,6 +4160,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
case
QUERY_NODE_PHYSICAL_PLAN_MERGE
:
return
physiMergeNodeToJson
(
pObj
,
pJson
);
case
QUERY_NODE_PHYSICAL_PLAN_SORT
:
case
QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT
:
return
physiSortNodeToJson
(
pObj
,
pJson
);
case
QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL
:
case
QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL
:
...
...
@@ -4280,6 +4304,7 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
case
QUERY_NODE_PHYSICAL_PLAN_MERGE
:
return
jsonToPhysiMergeNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_SORT
:
case
QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT
:
return
jsonToPhysiSortNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL
:
case
QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL
:
...
...
source/libs/nodes/src/nodesTraverseFuncs.c
浏览文件 @
da8db399
...
...
@@ -500,7 +500,8 @@ static EDealRes dispatchPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalk
}
break
;
}
case
QUERY_NODE_PHYSICAL_PLAN_SORT
:
{
case
QUERY_NODE_PHYSICAL_PLAN_SORT
:
case
QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT
:
{
SSortPhysiNode
*
pSort
=
(
SSortPhysiNode
*
)
pNode
;
res
=
walkPhysiNode
((
SPhysiNode
*
)
pNode
,
order
,
walker
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
da8db399
...
...
@@ -288,6 +288,8 @@ SNode* nodesMakeNode(ENodeType type) {
return
makeNode
(
type
,
sizeof
(
SMergePhysiNode
));
case
QUERY_NODE_PHYSICAL_PLAN_SORT
:
return
makeNode
(
type
,
sizeof
(
SSortPhysiNode
));
case
QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT
:
return
makeNode
(
type
,
sizeof
(
SGroupSortPhysiNode
));
case
QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL
:
return
makeNode
(
type
,
sizeof
(
SIntervalPhysiNode
));
case
QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL
:
...
...
@@ -709,7 +711,7 @@ void nodesDestroyNode(SNode* pNode) {
nodesDestroyNode
(
pLogicNode
->
pTagCond
);
nodesDestroyNode
(
pLogicNode
->
pTagIndexCond
);
taosArrayDestroy
(
pLogicNode
->
pSmaIndexes
);
nodesDestroyList
(
pLogicNode
->
p
Part
Tags
);
nodesDestroyList
(
pLogicNode
->
p
Group
Tags
);
break
;
}
case
QUERY_NODE_LOGIC_PLAN_JOIN
:
{
...
...
@@ -813,7 +815,7 @@ void nodesDestroyNode(SNode* pNode) {
STableScanPhysiNode
*
pPhyNode
=
(
STableScanPhysiNode
*
)
pNode
;
destroyScanPhysiNode
((
SScanPhysiNode
*
)
pNode
);
nodesDestroyList
(
pPhyNode
->
pDynamicScanFuncs
);
nodesDestroyList
(
pPhyNode
->
p
Partition
Tags
);
nodesDestroyList
(
pPhyNode
->
p
Group
Tags
);
break
;
}
case
QUERY_NODE_PHYSICAL_PLAN_PROJECT
:
{
...
...
@@ -850,7 +852,8 @@ void nodesDestroyNode(SNode* pNode) {
nodesDestroyList
(
pPhyNode
->
pTargets
);
break
;
}
case
QUERY_NODE_PHYSICAL_PLAN_SORT
:
{
case
QUERY_NODE_PHYSICAL_PLAN_SORT
:
case
QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT
:
{
SSortPhysiNode
*
pPhyNode
=
(
SSortPhysiNode
*
)
pNode
;
destroyPhysiNode
((
SPhysiNode
*
)
pPhyNode
);
nodesDestroyList
(
pPhyNode
->
pExprs
);
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
da8db399
...
...
@@ -2456,90 +2456,6 @@ static int32_t rewriteUniqueStmt(STranslateContext* pCxt, SSelectStmt* pSelect)
return
cxt
.
pTranslateCxt
->
errCode
;
}
typedef
struct
SRwriteTailCxt
{
STranslateContext
*
pTranslateCxt
;
int64_t
limit
;
int64_t
offset
;
}
SRwriteTailCxt
;
static
EDealRes
rewriteTailFunc
(
SNode
**
pNode
,
void
*
pContext
)
{
SRwriteTailCxt
*
pCxt
=
pContext
;
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
*
pNode
))
{
SFunctionNode
*
pFunc
=
(
SFunctionNode
*
)
*
pNode
;
if
(
FUNCTION_TYPE_TAIL
==
pFunc
->
funcType
)
{
pCxt
->
limit
=
((
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
))
->
datum
.
i
;
if
(
3
==
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
pCxt
->
offset
=
((
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
2
))
->
datum
.
i
;
}
SNode
*
pExpr
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
strcpy
(((
SExprNode
*
)
pExpr
)
->
aliasName
,
((
SExprNode
*
)
*
pNode
)
->
aliasName
);
NODES_CLEAR_LIST
(
pFunc
->
pParameterList
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
pExpr
;
return
DEAL_RES_IGNORE_CHILD
;
}
}
return
DEAL_RES_CONTINUE
;
}
static
int32_t
createLimieNode
(
SRwriteTailCxt
*
pCxt
,
SLimitNode
**
pOutput
)
{
*
pOutput
=
(
SLimitNode
*
)
nodesMakeNode
(
QUERY_NODE_LIMIT
);
if
(
NULL
==
*
pOutput
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
(
*
pOutput
)
->
limit
=
pCxt
->
limit
;
(
*
pOutput
)
->
offset
=
pCxt
->
offset
;
return
TSDB_CODE_SUCCESS
;
}
static
SNode
*
createOrderByExpr
(
STranslateContext
*
pCxt
)
{
SOrderByExprNode
*
pOrder
=
(
SOrderByExprNode
*
)
nodesMakeNode
(
QUERY_NODE_ORDER_BY_EXPR
);
if
(
NULL
==
pOrder
)
{
return
NULL
;
}
pCxt
->
errCode
=
createPrimaryKeyCol
(
pCxt
,
&
pOrder
->
pExpr
);
if
(
TSDB_CODE_SUCCESS
!=
pCxt
->
errCode
)
{
nodesDestroyNode
((
SNode
*
)
pOrder
);
return
NULL
;
}
pOrder
->
order
=
ORDER_DESC
;
pOrder
->
nullOrder
=
NULL_ORDER_FIRST
;
return
(
SNode
*
)
pOrder
;
}
/* case 1:
* in: select tail(expr, k, f) from t where_clause
* out: select expr from t where_clause order by _rowts desc limit k offset f
*
* case 2:
* in: select tail(expr, k, f) from t where_clause partition_by_clause
* out: select expr from t where_clause partition_by_clause sort by _rowts desc limit k offset f
*
* case 3:
* in: select tail(expr, k, f) from t where_clause order_by_clause limit_clause
* out: select expr from (
* select expr from t where_clause order by _rowts desc limit k offset f
* ) order_by_clause limit_clause
*
* case 4:
* in: select tail(expr, k, f) from t where_clause partition_by_clause limit_clause
* out:
*/
static
int32_t
rewriteTailStmt
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
if
(
!
pSelect
->
hasTailFunc
)
{
return
TSDB_CODE_SUCCESS
;
}
SRwriteTailCxt
cxt
=
{.
pTranslateCxt
=
pCxt
,
.
limit
=
-
1
,
.
offset
=
-
1
};
nodesRewriteExprs
(
pSelect
->
pProjectionList
,
rewriteTailFunc
,
&
cxt
);
int32_t
code
=
nodesListMakeStrictAppend
(
&
pSelect
->
pOrderByList
,
createOrderByExpr
(
pCxt
));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
createLimieNode
(
&
cxt
,
&
pSelect
->
pLimit
);
}
pSelect
->
hasIndefiniteRowsFunc
=
false
;
return
code
;
}
typedef
struct
SReplaceOrderByAliasCxt
{
STranslateContext
*
pTranslateCxt
;
SNodeList
*
pProjectionList
;
...
...
@@ -2616,9 +2532,6 @@ static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteUniqueStmt
(
pCxt
,
pSelect
);
}
// if (TSDB_CODE_SUCCESS == code) {
// code = rewriteTailStmt(pCxt, pSelect);
// }
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteTimelineFunc
(
pCxt
,
pSelect
);
}
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
da8db399
...
...
@@ -337,7 +337,11 @@ int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) {
static
bool
isValidateTag
(
char
*
input
)
{
if
(
!
input
)
return
false
;
for
(
size_t
i
=
0
;
i
<
strlen
(
input
);
++
i
)
{
#ifdef WINDOWS
if
(
input
[
i
]
<
0x20
||
input
[
i
]
>
0x7E
)
return
false
;
#else
if
(
isprint
(
input
[
i
])
==
0
)
return
false
;
#endif
}
return
true
;
}
...
...
@@ -377,6 +381,7 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, SMs
char
*
jsonKey
=
item
->
string
;
if
(
!
isValidateTag
(
jsonKey
))
{
fprintf
(
stdout
,
"%s(%d) %s %08"
PRId64
"
\n
"
,
__FILE__
,
__LINE__
,
__func__
,
taosGetSelfPthreadId
());
fflush
(
stdout
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json key not validate"
,
jsonKey
);
goto
end
;
}
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
da8db399
...
...
@@ -507,6 +507,8 @@ static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pIdfRowsFunc
->
isTailFunc
=
pSelect
->
hasTailFunc
;
// indefinite rows functions and _select_values functions
int32_t
code
=
nodesCollectFuncs
(
pSelect
,
SQL_CLAUSE_SELECT
,
fmIsVectorFunc
,
&
pIdfRowsFunc
->
pFuncs
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -733,6 +735,8 @@ static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pSort
->
groupSort
=
pSelect
->
groupSort
;
int32_t
code
=
nodesCollectColumns
(
pSelect
,
SQL_CLAUSE_ORDER_BY
,
NULL
,
COLLECT_COL_TYPE_ALL
,
&
pSort
->
node
.
pTargets
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
==
pSort
->
node
.
pTargets
)
{
code
=
nodesListMakeStrictAppend
(
&
pSort
->
node
.
pTargets
,
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
da8db399
...
...
@@ -20,9 +20,8 @@
#define OPTIMIZE_FLAG_MASK(n) (1 << n)
#define OPTIMIZE_FLAG_OSD OPTIMIZE_FLAG_MASK(0)
#define OPTIMIZE_FLAG_CPD OPTIMIZE_FLAG_MASK(1)
#define OPTIMIZE_FLAG_OPK OPTIMIZE_FLAG_MASK(2)
#define OPTIMIZE_FLAG_SCAN_PATH OPTIMIZE_FLAG_MASK(0)
#define OPTIMIZE_FLAG_PUSH_DOWN_CONDE OPTIMIZE_FLAG_MASK(1)
#define OPTIMIZE_FLAG_SET_MASK(val, mask) (val) |= (mask)
#define OPTIMIZE_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
...
...
@@ -76,7 +75,7 @@ static SLogicNode* optFindPossibleNode(SLogicNode* pNode, FMayBeOptimized func)
return
NULL
;
}
EDealRes
osd
HaveNormalColImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
EDealRes
scanPathOpt
HaveNormalColImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
// *((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType);
*
((
bool
*
)
pContext
)
=
true
;
...
...
@@ -85,14 +84,14 @@ EDealRes osdHaveNormalColImpl(SNode* pNode, void* pContext) {
return
DEAL_RES_CONTINUE
;
}
static
bool
osd
HaveNormalCol
(
SNodeList
*
pList
)
{
static
bool
scanPathOpt
HaveNormalCol
(
SNodeList
*
pList
)
{
bool
res
=
false
;
nodesWalkExprsPostOrder
(
pList
,
osd
HaveNormalColImpl
,
&
res
);
nodesWalkExprsPostOrder
(
pList
,
scanPathOpt
HaveNormalColImpl
,
&
res
);
return
res
;
}
static
bool
osd
MayBeOptimized
(
SLogicNode
*
pNode
)
{
if
(
OPTIMIZE_FLAG_TEST_MASK
(
pNode
->
optimizedFlag
,
OPTIMIZE_FLAG_
OSD
))
{
static
bool
scanPathOpt
MayBeOptimized
(
SLogicNode
*
pNode
)
{
if
(
OPTIMIZE_FLAG_TEST_MASK
(
pNode
->
optimizedFlag
,
OPTIMIZE_FLAG_
SCAN_PATH
))
{
return
false
;
}
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
pNode
))
{
...
...
@@ -108,10 +107,10 @@ static bool osdMayBeOptimized(SLogicNode* pNode) {
QUERY_NODE_LOGIC_PLAN_WINDOW
==
nodeType
(
pNode
->
pParent
->
pParent
)))
{
return
true
;
}
return
!
osd
HaveNormalCol
(((
SAggLogicNode
*
)
pNode
->
pParent
)
->
pGroupKeys
);
return
!
scanPathOpt
HaveNormalCol
(((
SAggLogicNode
*
)
pNode
->
pParent
)
->
pGroupKeys
);
}
static
SNodeList
*
osd
GetAllFuncs
(
SLogicNode
*
pNode
)
{
static
SNodeList
*
scanPathOpt
GetAllFuncs
(
SLogicNode
*
pNode
)
{
switch
(
nodeType
(
pNode
))
{
case
QUERY_NODE_LOGIC_PLAN_WINDOW
:
return
((
SWindowLogicNode
*
)
pNode
)
->
pFuncs
;
...
...
@@ -123,7 +122,7 @@ static SNodeList* osdGetAllFuncs(SLogicNode* pNode) {
return
NULL
;
}
static
bool
n
eedOptimizeDataRequire
(
const
SFunctionNode
*
pFunc
)
{
static
bool
scanPathOptN
eedOptimizeDataRequire
(
const
SFunctionNode
*
pFunc
)
{
if
(
!
fmIsSpecialDataRequiredFunc
(
pFunc
->
funcId
))
{
return
false
;
}
...
...
@@ -136,7 +135,7 @@ static bool needOptimizeDataRequire(const SFunctionNode* pFunc) {
return
true
;
}
static
bool
needOptimizeDynamicScan
(
const
SFunctionNode
*
pFunc
)
{
static
bool
scanPathOptNeedDynOptimize
(
const
SFunctionNode
*
pFunc
)
{
if
(
!
fmIsDynamicScanOptimizedFunc
(
pFunc
->
funcId
))
{
return
false
;
}
...
...
@@ -149,17 +148,17 @@ static bool needOptimizeDynamicScan(const SFunctionNode* pFunc) {
return
true
;
}
static
int32_t
osd
GetRelatedFuncs
(
SScanLogicNode
*
pScan
,
SNodeList
**
pSdrFuncs
,
SNodeList
**
pDsoFuncs
)
{
SNodeList
*
pAllFuncs
=
osd
GetAllFuncs
(
pScan
->
node
.
pParent
);
static
int32_t
scanPathOpt
GetRelatedFuncs
(
SScanLogicNode
*
pScan
,
SNodeList
**
pSdrFuncs
,
SNodeList
**
pDsoFuncs
)
{
SNodeList
*
pAllFuncs
=
scanPathOpt
GetAllFuncs
(
pScan
->
node
.
pParent
);
SNodeList
*
pTmpSdrFuncs
=
NULL
;
SNodeList
*
pTmpDsoFuncs
=
NULL
;
SNode
*
pFunc
=
NULL
;
bool
otherFunc
=
false
;
FOREACH
(
pFunc
,
pAllFuncs
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
n
eedOptimizeDataRequire
((
SFunctionNode
*
)
pFunc
))
{
if
(
scanPathOptN
eedOptimizeDataRequire
((
SFunctionNode
*
)
pFunc
))
{
code
=
nodesListMakeStrictAppend
(
&
pTmpSdrFuncs
,
nodesCloneNode
(
pFunc
));
}
else
if
(
needOptimizeDynamicScan
((
SFunctionNode
*
)
pFunc
))
{
}
else
if
(
scanPathOptNeedDynOptimize
((
SFunctionNode
*
)
pFunc
))
{
code
=
nodesListMakeStrictAppend
(
&
pTmpDsoFuncs
,
nodesCloneNode
(
pFunc
));
}
else
{
otherFunc
=
true
;
...
...
@@ -180,15 +179,15 @@ static int32_t osdGetRelatedFuncs(SScanLogicNode* pScan, SNodeList** pSdrFuncs,
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
osd
Match
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pLogicNode
,
SOsdInfo
*
pInfo
)
{
pInfo
->
pScan
=
(
SScanLogicNode
*
)
optFindPossibleNode
(
pLogicNode
,
osd
MayBeOptimized
);
static
int32_t
scanPathOpt
Match
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pLogicNode
,
SOsdInfo
*
pInfo
)
{
pInfo
->
pScan
=
(
SScanLogicNode
*
)
optFindPossibleNode
(
pLogicNode
,
scanPathOpt
MayBeOptimized
);
if
(
NULL
==
pInfo
->
pScan
)
{
return
TSDB_CODE_SUCCESS
;
}
return
osd
GetRelatedFuncs
(
pInfo
->
pScan
,
&
pInfo
->
pSdrFuncs
,
&
pInfo
->
pDsoFuncs
);
return
scanPathOpt
GetRelatedFuncs
(
pInfo
->
pScan
,
&
pInfo
->
pSdrFuncs
,
&
pInfo
->
pDsoFuncs
);
}
static
EFuncDataRequired
osd
PromoteDataRequired
(
EFuncDataRequired
l
,
EFuncDataRequired
r
)
{
static
EFuncDataRequired
scanPathOpt
PromoteDataRequired
(
EFuncDataRequired
l
,
EFuncDataRequired
r
)
{
switch
(
l
)
{
case
FUNC_DATA_REQUIRED_DATA_LOAD
:
return
l
;
...
...
@@ -202,19 +201,19 @@ static EFuncDataRequired osdPromoteDataRequired(EFuncDataRequired l, EFuncDataRe
return
r
;
}
static
int32_t
osd
GetDataRequired
(
SNodeList
*
pFuncs
)
{
static
int32_t
scanPathOpt
GetDataRequired
(
SNodeList
*
pFuncs
)
{
if
(
NULL
==
pFuncs
)
{
return
FUNC_DATA_REQUIRED_DATA_LOAD
;
}
EFuncDataRequired
dataRequired
=
FUNC_DATA_REQUIRED_FILTEROUT
;
SNode
*
pFunc
=
NULL
;
FOREACH
(
pFunc
,
pFuncs
)
{
dataRequired
=
osd
PromoteDataRequired
(
dataRequired
,
fmFuncDataRequired
((
SFunctionNode
*
)
pFunc
,
NULL
));
dataRequired
=
scanPathOpt
PromoteDataRequired
(
dataRequired
,
fmFuncDataRequired
((
SFunctionNode
*
)
pFunc
,
NULL
));
}
return
dataRequired
;
}
static
void
s
etScanWindowInfo
(
SScanLogicNode
*
pScan
)
{
static
void
s
canPathOptSetScanWin
(
SScanLogicNode
*
pScan
)
{
SLogicNode
*
pParent
=
pScan
->
node
.
pParent
;
if
(
QUERY_NODE_LOGIC_PLAN_PARTITION
==
nodeType
(
pParent
)
&&
pParent
->
pParent
&&
QUERY_NODE_LOGIC_PLAN_WINDOW
==
nodeType
(
pParent
->
pParent
))
{
...
...
@@ -233,23 +232,23 @@ static void setScanWindowInfo(SScanLogicNode* pScan) {
}
}
static
int32_t
osd
Optimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
static
int32_t
scanPath
Optimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
SOsdInfo
info
=
{
0
};
int32_t
code
=
osd
Match
(
pCxt
,
pLogicSubplan
->
pNode
,
&
info
);
int32_t
code
=
scanPathOpt
Match
(
pCxt
,
pLogicSubplan
->
pNode
,
&
info
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
info
.
pScan
)
{
s
etScanWindowInfo
((
SScanLogicNode
*
)
info
.
pScan
);
s
canPathOptSetScanWin
((
SScanLogicNode
*
)
info
.
pScan
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
(
NULL
!=
info
.
pDsoFuncs
||
NULL
!=
info
.
pSdrFuncs
))
{
info
.
pScan
->
dataRequired
=
osd
GetDataRequired
(
info
.
pSdrFuncs
);
info
.
pScan
->
dataRequired
=
scanPathOpt
GetDataRequired
(
info
.
pSdrFuncs
);
info
.
pScan
->
pDynamicScanFuncs
=
info
.
pDsoFuncs
;
OPTIMIZE_FLAG_SET_MASK
(
info
.
pScan
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_
OSD
);
OPTIMIZE_FLAG_SET_MASK
(
info
.
pScan
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_
SCAN_PATH
);
pCxt
->
optimized
=
true
;
}
nodesDestroyList
(
info
.
pSdrFuncs
);
return
code
;
}
static
int32_t
cpd
MergeCond
(
SNode
**
pDst
,
SNode
**
pSrc
)
{
static
int32_t
pushDownCondOpt
MergeCond
(
SNode
**
pDst
,
SNode
**
pSrc
)
{
SLogicConditionNode
*
pLogicCond
=
(
SLogicConditionNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_CONDITION
);
if
(
NULL
==
pLogicCond
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -270,7 +269,7 @@ static int32_t cpdMergeCond(SNode** pDst, SNode** pSrc) {
return
code
;
}
static
int32_t
cpdCondAppe
nd
(
SNode
**
pCond
,
SNode
**
pAdditionalCond
)
{
static
int32_t
pushDownCondOptAppendCo
nd
(
SNode
**
pCond
,
SNode
**
pAdditionalCond
)
{
if
(
NULL
==
*
pCond
)
{
TSWAP
(
*
pCond
,
*
pAdditionalCond
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -283,16 +282,16 @@ static int32_t cpdCondAppend(SNode** pCond, SNode** pAdditionalCond) {
*
pAdditionalCond
=
NULL
;
}
}
else
{
code
=
cpd
MergeCond
(
pCond
,
pAdditionalCond
);
code
=
pushDownCondOpt
MergeCond
(
pCond
,
pAdditionalCond
);
}
return
code
;
}
static
int32_t
cpd
CalcTimeRange
(
SOptimizeContext
*
pCxt
,
SScanLogicNode
*
pScan
,
SNode
**
pPrimaryKeyCond
,
SNode
**
pOtherCond
)
{
static
int32_t
pushDownCondOpt
CalcTimeRange
(
SOptimizeContext
*
pCxt
,
SScanLogicNode
*
pScan
,
SNode
**
pPrimaryKeyCond
,
SNode
**
pOtherCond
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
pCxt
->
pPlanCxt
->
topicQuery
||
pCxt
->
pPlanCxt
->
streamQuery
)
{
code
=
cpdCondAppe
nd
(
pOtherCond
,
pPrimaryKeyCond
);
code
=
pushDownCondOptAppendCo
nd
(
pOtherCond
,
pPrimaryKeyCond
);
}
else
{
bool
isStrict
=
false
;
code
=
filterGetTimeRange
(
*
pPrimaryKeyCond
,
&
pScan
->
scanRange
,
&
isStrict
);
...
...
@@ -300,7 +299,7 @@ static int32_t cpdCalcTimeRange(SOptimizeContext* pCxt, SScanLogicNode* pScan, S
if
(
isStrict
)
{
nodesDestroyNode
(
*
pPrimaryKeyCond
);
}
else
{
code
=
cpdCondAppe
nd
(
pOtherCond
,
pPrimaryKeyCond
);
code
=
pushDownCondOptAppendCo
nd
(
pOtherCond
,
pPrimaryKeyCond
);
}
*
pPrimaryKeyCond
=
NULL
;
}
...
...
@@ -308,8 +307,9 @@ static int32_t cpdCalcTimeRange(SOptimizeContext* pCxt, SScanLogicNode* pScan, S
return
code
;
}
static
int32_t
cpdOptimizeScanCondition
(
SOptimizeContext
*
pCxt
,
SScanLogicNode
*
pScan
)
{
if
(
NULL
==
pScan
->
node
.
pConditions
||
OPTIMIZE_FLAG_TEST_MASK
(
pScan
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_CPD
)
||
static
int32_t
pushDownCondOptDealScan
(
SOptimizeContext
*
pCxt
,
SScanLogicNode
*
pScan
)
{
if
(
NULL
==
pScan
->
node
.
pConditions
||
OPTIMIZE_FLAG_TEST_MASK
(
pScan
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_PUSH_DOWN_CONDE
)
||
TSDB_SYSTEM_TABLE
==
pScan
->
tableType
)
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -319,14 +319,14 @@ static int32_t cpdOptimizeScanCondition(SOptimizeContext* pCxt, SScanLogicNode*
int32_t
code
=
nodesPartitionCond
(
&
pScan
->
node
.
pConditions
,
&
pPrimaryKeyCond
,
&
pScan
->
pTagIndexCond
,
&
pScan
->
pTagCond
,
&
pOtherCond
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pPrimaryKeyCond
)
{
code
=
cpd
CalcTimeRange
(
pCxt
,
pScan
,
&
pPrimaryKeyCond
,
&
pOtherCond
);
code
=
pushDownCondOpt
CalcTimeRange
(
pCxt
,
pScan
,
&
pPrimaryKeyCond
,
&
pOtherCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pScan
->
node
.
pConditions
=
pOtherCond
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
OPTIMIZE_FLAG_SET_MASK
(
pScan
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_
CPD
);
OPTIMIZE_FLAG_SET_MASK
(
pScan
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_
PUSH_DOWN_CONDE
);
pCxt
->
optimized
=
true
;
}
else
{
nodesDestroyNode
(
pPrimaryKeyCond
);
...
...
@@ -336,7 +336,7 @@ static int32_t cpdOptimizeScanCondition(SOptimizeContext* pCxt, SScanLogicNode*
return
code
;
}
static
bool
cpd
BelongThisTable
(
SNode
*
pCondCol
,
SNodeList
*
pTableCols
)
{
static
bool
pushDownCondOpt
BelongThisTable
(
SNode
*
pCondCol
,
SNodeList
*
pTableCols
)
{
SNode
*
pTableCol
=
NULL
;
FOREACH
(
pTableCol
,
pTableCols
)
{
if
(
nodesEqualNode
(
pCondCol
,
pTableCol
))
{
...
...
@@ -346,12 +346,12 @@ static bool cpdBelongThisTable(SNode* pCondCol, SNodeList* pTableCols) {
return
false
;
}
static
EDealRes
cpdIsMultiTableCondImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
static
EDealRes
pushDownCondOptIsCrossTableCond
(
SNode
*
pNode
,
void
*
pContext
)
{
SCpdIsMultiTableCondCxt
*
pCxt
=
pContext
;
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
if
(
cpd
BelongThisTable
(
pNode
,
pCxt
->
pLeftCols
))
{
if
(
pushDownCondOpt
BelongThisTable
(
pNode
,
pCxt
->
pLeftCols
))
{
pCxt
->
havaLeftCol
=
true
;
}
else
if
(
cpd
BelongThisTable
(
pNode
,
pCxt
->
pRightCols
))
{
}
else
if
(
pushDownCondOpt
BelongThisTable
(
pNode
,
pCxt
->
pRightCols
))
{
pCxt
->
haveRightCol
=
true
;
}
return
pCxt
->
havaLeftCol
&&
pCxt
->
haveRightCol
?
DEAL_RES_END
:
DEAL_RES_CONTINUE
;
...
...
@@ -359,10 +359,11 @@ static EDealRes cpdIsMultiTableCondImpl(SNode* pNode, void* pContext) {
return
DEAL_RES_CONTINUE
;
}
static
ECondAction
cpdCondAction
(
EJoinType
joinType
,
SNodeList
*
pLeftCols
,
SNodeList
*
pRightCols
,
SNode
*
pNode
)
{
static
ECondAction
pushDownCondOptGetCondAction
(
EJoinType
joinType
,
SNodeList
*
pLeftCols
,
SNodeList
*
pRightCols
,
SNode
*
pNode
)
{
SCpdIsMultiTableCondCxt
cxt
=
{
.
pLeftCols
=
pLeftCols
,
.
pRightCols
=
pRightCols
,
.
havaLeftCol
=
false
,
.
haveRightCol
=
false
};
nodesWalkExpr
(
pNode
,
cpdIsMultiTableCondImpl
,
&
cxt
);
nodesWalkExpr
(
pNode
,
pushDownCondOptIsCrossTableCond
,
&
cxt
);
return
(
JOIN_TYPE_INNER
!=
joinType
?
COND_ACTION_STAY
:
(
cxt
.
havaLeftCol
&&
cxt
.
haveRightCol
...
...
@@ -370,8 +371,8 @@ static ECondAction cpdCondAction(EJoinType joinType, SNodeList* pLeftCols, SNode
:
(
cxt
.
havaLeftCol
?
COND_ACTION_PUSH_LEFT_CHILD
:
COND_ACTION_PUSH_RIGHT_CHILD
)));
}
static
int32_t
cpdPartition
LogicCond
(
SJoinLogicNode
*
pJoin
,
SNode
**
pOnCond
,
SNode
**
pLeftChildCond
,
SNode
**
pRightChildCond
)
{
static
int32_t
pushDownCondOptPart
LogicCond
(
SJoinLogicNode
*
pJoin
,
SNode
**
pOnCond
,
SNode
**
pLeftChildCond
,
SNode
**
pRightChildCond
)
{
SLogicConditionNode
*
pLogicCond
=
(
SLogicConditionNode
*
)
pJoin
->
node
.
pConditions
;
if
(
LOGIC_COND_TYPE_AND
!=
pLogicCond
->
condType
)
{
return
TSDB_CODE_SUCCESS
;
...
...
@@ -387,7 +388,7 @@ static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNo
SNodeList
*
pRemainConds
=
NULL
;
SNode
*
pCond
=
NULL
;
FOREACH
(
pCond
,
pLogicCond
->
pParameterList
)
{
ECondAction
condAction
=
cpd
CondAction
(
pJoin
->
joinType
,
pLeftCols
,
pRightCols
,
pCond
);
ECondAction
condAction
=
pushDownCondOptGet
CondAction
(
pJoin
->
joinType
,
pLeftCols
,
pRightCols
,
pCond
);
if
(
COND_ACTION_PUSH_JOIN
==
condAction
)
{
code
=
nodesListMakeAppend
(
&
pOnConds
,
nodesCloneNode
(
pCond
));
}
else
if
(
COND_ACTION_PUSH_LEFT_CHILD
==
condAction
)
{
...
...
@@ -439,11 +440,12 @@ static int32_t cpdPartitionLogicCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNo
return
code
;
}
static
int32_t
cpdPartition
OpCond
(
SJoinLogicNode
*
pJoin
,
SNode
**
pOnCond
,
SNode
**
pLeftChildCond
,
SNode
**
pRightChildCond
)
{
static
int32_t
pushDownCondOptPart
OpCond
(
SJoinLogicNode
*
pJoin
,
SNode
**
pOnCond
,
SNode
**
pLeftChildCond
,
SNode
**
pRightChildCond
)
{
SNodeList
*
pLeftCols
=
((
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
0
))
->
pTargets
;
SNodeList
*
pRightCols
=
((
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
1
))
->
pTargets
;
ECondAction
condAction
=
cpdCondAction
(
pJoin
->
joinType
,
pLeftCols
,
pRightCols
,
pJoin
->
node
.
pConditions
);
ECondAction
condAction
=
pushDownCondOptGetCondAction
(
pJoin
->
joinType
,
pLeftCols
,
pRightCols
,
pJoin
->
node
.
pConditions
);
if
(
COND_ACTION_STAY
==
condAction
)
{
return
TSDB_CODE_SUCCESS
;
}
else
if
(
COND_ACTION_PUSH_JOIN
==
condAction
)
{
...
...
@@ -457,35 +459,35 @@ static int32_t cpdPartitionOpCond(SJoinLogicNode* pJoin, SNode** pOnCond, SNode*
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cpdPartition
Cond
(
SJoinLogicNode
*
pJoin
,
SNode
**
pOnCond
,
SNode
**
pLeftChildCond
,
SNode
**
pRightChildCond
)
{
static
int32_t
pushDownCondOptPart
Cond
(
SJoinLogicNode
*
pJoin
,
SNode
**
pOnCond
,
SNode
**
pLeftChildCond
,
SNode
**
pRightChildCond
)
{
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pJoin
->
node
.
pConditions
))
{
return
cpdPartition
LogicCond
(
pJoin
,
pOnCond
,
pLeftChildCond
,
pRightChildCond
);
return
pushDownCondOptPart
LogicCond
(
pJoin
,
pOnCond
,
pLeftChildCond
,
pRightChildCond
);
}
else
{
return
cpdPartition
OpCond
(
pJoin
,
pOnCond
,
pLeftChildCond
,
pRightChildCond
);
return
pushDownCondOptPart
OpCond
(
pJoin
,
pOnCond
,
pLeftChildCond
,
pRightChildCond
);
}
}
static
int32_t
cpd
PushCondToOnCond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
,
SNode
**
pCond
)
{
return
cpdCondAppe
nd
(
&
pJoin
->
pOnConditions
,
pCond
);
static
int32_t
pushDownCondOpt
PushCondToOnCond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
,
SNode
**
pCond
)
{
return
pushDownCondOptAppendCo
nd
(
&
pJoin
->
pOnConditions
,
pCond
);
}
static
int32_t
cpd
PushCondToScan
(
SOptimizeContext
*
pCxt
,
SScanLogicNode
*
pScan
,
SNode
**
pCond
)
{
return
cpdCondAppe
nd
(
&
pScan
->
node
.
pConditions
,
pCond
);
static
int32_t
pushDownCondOpt
PushCondToScan
(
SOptimizeContext
*
pCxt
,
SScanLogicNode
*
pScan
,
SNode
**
pCond
)
{
return
pushDownCondOptAppendCo
nd
(
&
pScan
->
node
.
pConditions
,
pCond
);
}
static
int32_t
cpd
PushCondToChild
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pChild
,
SNode
**
pCond
)
{
static
int32_t
pushDownCondOpt
PushCondToChild
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pChild
,
SNode
**
pCond
)
{
switch
(
nodeType
(
pChild
))
{
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
return
cpd
PushCondToScan
(
pCxt
,
(
SScanLogicNode
*
)
pChild
,
pCond
);
return
pushDownCondOpt
PushCondToScan
(
pCxt
,
(
SScanLogicNode
*
)
pChild
,
pCond
);
default:
break
;
}
planError
(
"
cpd
PushCondToChild failed, invalid logic plan node %s"
,
nodesNodeName
(
nodeType
(
pChild
)));
planError
(
"
pushDownCondOpt
PushCondToChild failed, invalid logic plan node %s"
,
nodesNodeName
(
nodeType
(
pChild
)));
return
TSDB_CODE_PLAN_INTERNAL_ERROR
;
}
static
bool
cpdIsPrimary
Key
(
SNode
*
pNode
,
SNodeList
*
pTableCols
)
{
static
bool
pushDownCondOptIsPri
Key
(
SNode
*
pNode
,
SNodeList
*
pTableCols
)
{
if
(
QUERY_NODE_COLUMN
!=
nodeType
(
pNode
))
{
return
false
;
}
...
...
@@ -493,10 +495,10 @@ static bool cpdIsPrimaryKey(SNode* pNode, SNodeList* pTableCols) {
if
(
PRIMARYKEY_TIMESTAMP_COL_ID
!=
pCol
->
colId
)
{
return
false
;
}
return
cpd
BelongThisTable
(
pNode
,
pTableCols
);
return
pushDownCondOpt
BelongThisTable
(
pNode
,
pTableCols
);
}
static
bool
cpdIsPrimary
KeyEqualCond
(
SJoinLogicNode
*
pJoin
,
SNode
*
pCond
)
{
static
bool
pushDownCondOptIsPri
KeyEqualCond
(
SJoinLogicNode
*
pJoin
,
SNode
*
pCond
)
{
if
(
QUERY_NODE_OPERATOR
!=
nodeType
(
pCond
))
{
return
false
;
}
...
...
@@ -508,15 +510,15 @@ static bool cpdIsPrimaryKeyEqualCond(SJoinLogicNode* pJoin, SNode* pCond) {
SNodeList
*
pLeftCols
=
((
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
0
))
->
pTargets
;
SNodeList
*
pRightCols
=
((
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
1
))
->
pTargets
;
if
(
cpdIsPrimary
Key
(
pOper
->
pLeft
,
pLeftCols
))
{
return
cpdIsPrimary
Key
(
pOper
->
pRight
,
pRightCols
);
}
else
if
(
cpdIsPrimary
Key
(
pOper
->
pLeft
,
pRightCols
))
{
return
cpdIsPrimary
Key
(
pOper
->
pRight
,
pLeftCols
);
if
(
pushDownCondOptIsPri
Key
(
pOper
->
pLeft
,
pLeftCols
))
{
return
pushDownCondOptIsPri
Key
(
pOper
->
pRight
,
pRightCols
);
}
else
if
(
pushDownCondOptIsPri
Key
(
pOper
->
pLeft
,
pRightCols
))
{
return
pushDownCondOptIsPri
Key
(
pOper
->
pRight
,
pLeftCols
);
}
return
false
;
}
static
bool
cpdContainPrimary
KeyEqualCond
(
SJoinLogicNode
*
pJoin
,
SNode
*
pCond
)
{
static
bool
pushDownCondOptContainPri
KeyEqualCond
(
SJoinLogicNode
*
pJoin
,
SNode
*
pCond
)
{
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pCond
))
{
SLogicConditionNode
*
pLogicCond
=
(
SLogicConditionNode
*
)
pCond
;
if
(
LOGIC_COND_TYPE_AND
!=
pLogicCond
->
condType
)
{
...
...
@@ -525,54 +527,56 @@ static bool cpdContainPrimaryKeyEqualCond(SJoinLogicNode* pJoin, SNode* pCond) {
bool
hasPrimaryKeyEqualCond
=
false
;
SNode
*
pCond
=
NULL
;
FOREACH
(
pCond
,
pLogicCond
->
pParameterList
)
{
if
(
cpdContainPrimary
KeyEqualCond
(
pJoin
,
pCond
))
{
if
(
pushDownCondOptContainPri
KeyEqualCond
(
pJoin
,
pCond
))
{
hasPrimaryKeyEqualCond
=
true
;
break
;
}
}
return
hasPrimaryKeyEqualCond
;
}
else
{
return
cpdIsPrimary
KeyEqualCond
(
pJoin
,
pCond
);
return
pushDownCondOptIsPri
KeyEqualCond
(
pJoin
,
pCond
);
}
}
static
int32_t
cpd
CheckJoinOnCond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
static
int32_t
pushDownCondOpt
CheckJoinOnCond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
if
(
NULL
==
pJoin
->
pOnConditions
)
{
return
generateUsageErrMsg
(
pCxt
->
pPlanCxt
->
pMsg
,
pCxt
->
pPlanCxt
->
msgLen
,
TSDB_CODE_PLAN_NOT_SUPPORT_CROSS_JOIN
);
}
if
(
!
cpdContainPrimary
KeyEqualCond
(
pJoin
,
pJoin
->
pOnConditions
))
{
if
(
!
pushDownCondOptContainPri
KeyEqualCond
(
pJoin
,
pJoin
->
pOnConditions
))
{
return
generateUsageErrMsg
(
pCxt
->
pPlanCxt
->
pMsg
,
pCxt
->
pPlanCxt
->
msgLen
,
TSDB_CODE_PLAN_EXPECTED_TS_EQUAL
);
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cpdPushJoinConditio
n
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
if
(
OPTIMIZE_FLAG_TEST_MASK
(
pJoin
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_
CPD
))
{
static
int32_t
pushDownCondOptDealJoi
n
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
if
(
OPTIMIZE_FLAG_TEST_MASK
(
pJoin
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_
PUSH_DOWN_CONDE
))
{
return
TSDB_CODE_SUCCESS
;
}
if
(
NULL
==
pJoin
->
node
.
pConditions
)
{
return
cpd
CheckJoinOnCond
(
pCxt
,
pJoin
);
return
pushDownCondOpt
CheckJoinOnCond
(
pCxt
,
pJoin
);
}
SNode
*
pOnCond
=
NULL
;
SNode
*
pLeftChildCond
=
NULL
;
SNode
*
pRightChildCond
=
NULL
;
int32_t
code
=
cpdPartition
Cond
(
pJoin
,
&
pOnCond
,
&
pLeftChildCond
,
&
pRightChildCond
);
int32_t
code
=
pushDownCondOptPart
Cond
(
pJoin
,
&
pOnCond
,
&
pLeftChildCond
,
&
pRightChildCond
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pOnCond
)
{
code
=
cpd
PushCondToOnCond
(
pCxt
,
pJoin
,
&
pOnCond
);
code
=
pushDownCondOpt
PushCondToOnCond
(
pCxt
,
pJoin
,
&
pOnCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pLeftChildCond
)
{
code
=
cpdPushCondToChild
(
pCxt
,
(
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
0
),
&
pLeftChildCond
);
code
=
pushDownCondOptPushCondToChild
(
pCxt
,
(
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
0
),
&
pLeftChildCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pRightChildCond
)
{
code
=
cpdPushCondToChild
(
pCxt
,
(
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
1
),
&
pRightChildCond
);
code
=
pushDownCondOptPushCondToChild
(
pCxt
,
(
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
1
),
&
pRightChildCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
OPTIMIZE_FLAG_SET_MASK
(
pJoin
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_
CPD
);
OPTIMIZE_FLAG_SET_MASK
(
pJoin
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_
PUSH_DOWN_CONDE
);
pCxt
->
optimized
=
true
;
code
=
cpd
CheckJoinOnCond
(
pCxt
,
pJoin
);
code
=
pushDownCondOpt
CheckJoinOnCond
(
pCxt
,
pJoin
);
}
else
{
nodesDestroyNode
(
pOnCond
);
nodesDestroyNode
(
pLeftChildCond
);
...
...
@@ -582,22 +586,22 @@ static int32_t cpdPushJoinCondition(SOptimizeContext* pCxt, SJoinLogicNode* pJoi
return
code
;
}
static
int32_t
cpdPushAggCondition
(
SOptimizeContext
*
pCxt
,
SAggLogicNode
*
pAgg
)
{
static
int32_t
pushDownCondOptDealAgg
(
SOptimizeContext
*
pCxt
,
SAggLogicNode
*
pAgg
)
{
// todo
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cpdPushCondition
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
static
int32_t
pushDownCondOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pLogicNode
))
{
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
code
=
cpdOptimizeScanConditio
n
(
pCxt
,
(
SScanLogicNode
*
)
pLogicNode
);
code
=
pushDownCondOptDealSca
n
(
pCxt
,
(
SScanLogicNode
*
)
pLogicNode
);
break
;
case
QUERY_NODE_LOGIC_PLAN_JOIN
:
code
=
cpdPushJoinConditio
n
(
pCxt
,
(
SJoinLogicNode
*
)
pLogicNode
);
code
=
pushDownCondOptDealJoi
n
(
pCxt
,
(
SJoinLogicNode
*
)
pLogicNode
);
break
;
case
QUERY_NODE_LOGIC_PLAN_AGG
:
code
=
cpdPushAggCondition
(
pCxt
,
(
SAggLogicNode
*
)
pLogicNode
);
code
=
pushDownCondOptDealAgg
(
pCxt
,
(
SAggLogicNode
*
)
pLogicNode
);
break
;
default:
break
;
...
...
@@ -605,7 +609,7 @@ static int32_t cpdPushCondition(SOptimizeContext* pCxt, SLogicNode* pLogicNode)
if
(
TSDB_CODE_SUCCESS
==
code
)
{
SNode
*
pChild
=
NULL
;
FOREACH
(
pChild
,
pLogicNode
->
pChildren
)
{
code
=
cpdPushCondition
(
pCxt
,
(
SLogicNode
*
)
pChild
);
code
=
pushDownCondOptimizeImpl
(
pCxt
,
(
SLogicNode
*
)
pChild
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
break
;
}
...
...
@@ -614,11 +618,11 @@ static int32_t cpdPushCondition(SOptimizeContext* pCxt, SLogicNode* pLogicNode)
return
code
;
}
static
int32_t
cp
dOptimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
return
cpdPushCondition
(
pCxt
,
pLogicSubplan
->
pNode
);
static
int32_t
pushDownCon
dOptimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
return
pushDownCondOptimizeImpl
(
pCxt
,
pLogicSubplan
->
pNode
);
}
static
bool
opkIsPrimary
KeyOrderBy
(
SNodeList
*
pSortKeys
)
{
static
bool
sortPriKeyOptIsPri
KeyOrderBy
(
SNodeList
*
pSortKeys
)
{
if
(
1
!=
LIST_LENGTH
(
pSortKeys
))
{
return
false
;
}
...
...
@@ -626,17 +630,18 @@ static bool opkIsPrimaryKeyOrderBy(SNodeList* pSortKeys) {
return
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
)
?
(
PRIMARYKEY_TIMESTAMP_COL_ID
==
((
SColumnNode
*
)
pNode
)
->
colId
)
:
false
);
}
static
bool
opkSor
tMayBeOptimized
(
SLogicNode
*
pNode
)
{
static
bool
sortPriKeyOp
tMayBeOptimized
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_SORT
!=
nodeType
(
pNode
))
{
return
false
;
}
if
(
OPTIMIZE_FLAG_TEST_MASK
(
pNode
->
optimizedFlag
,
OPTIMIZE_FLAG_OPK
))
{
return
false
;
SSortLogicNode
*
pSort
=
(
SSortLogicNode
*
)
pNode
;
if
(
pSort
->
groupSort
||
!
sortPriKeyOptIsPriKeyOrderBy
(
pSort
->
pSortKeys
)
||
1
!=
LIST_LENGTH
(
pSort
->
node
.
pChildren
))
{
return
TSDB_CODE_SUCCESS
;
}
return
true
;
}
static
int32_t
opk
GetScanNodesImpl
(
SLogicNode
*
pNode
,
bool
*
pNotOptimize
,
SNodeList
**
pScanNodes
)
{
static
int32_t
sortPriKeyOpt
GetScanNodesImpl
(
SLogicNode
*
pNode
,
bool
*
pNotOptimize
,
SNodeList
**
pScanNodes
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pNode
))
{
...
...
@@ -646,9 +651,11 @@ static int32_t opkGetScanNodesImpl(SLogicNode* pNode, bool* pNotOptimize, SNodeL
}
break
;
case
QUERY_NODE_LOGIC_PLAN_JOIN
:
code
=
opkGetScanNodesImpl
((
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
),
pNotOptimize
,
pScanNodes
);
code
=
sortPriKeyOptGetScanNodesImpl
((
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
),
pNotOptimize
,
pScanNodes
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
opkGetScanNodesImpl
((
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
1
),
pNotOptimize
,
pScanNodes
);
code
=
sortPriKeyOptGetScanNodesImpl
((
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
1
),
pNotOptimize
,
pScanNodes
);
}
return
code
;
case
QUERY_NODE_LOGIC_PLAN_AGG
:
...
...
@@ -663,77 +670,58 @@ static int32_t opkGetScanNodesImpl(SLogicNode* pNode, bool* pNotOptimize, SNodeL
return
TSDB_CODE_SUCCESS
;
}
return
opk
GetScanNodesImpl
((
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
),
pNotOptimize
,
pScanNodes
);
return
sortPriKeyOpt
GetScanNodesImpl
((
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
),
pNotOptimize
,
pScanNodes
);
}
static
int32_t
opk
GetScanNodes
(
SLogicNode
*
pNode
,
SNodeList
**
pScanNodes
)
{
static
int32_t
sortPriKeyOpt
GetScanNodes
(
SLogicNode
*
pNode
,
SNodeList
**
pScanNodes
)
{
bool
notOptimize
=
false
;
int32_t
code
=
opk
GetScanNodesImpl
(
pNode
,
&
notOptimize
,
pScanNodes
);
int32_t
code
=
sortPriKeyOpt
GetScanNodesImpl
(
pNode
,
&
notOptimize
,
pScanNodes
);
if
(
TSDB_CODE_SUCCESS
!=
code
||
notOptimize
)
{
nodesClearList
(
*
pScanNodes
);
}
return
code
;
}
static
EOrder
opkGetPrimary
KeyOrder
(
SSortLogicNode
*
pSort
)
{
static
EOrder
sortPriKeyOptGetPri
KeyOrder
(
SSortLogicNode
*
pSort
)
{
return
((
SOrderByExprNode
*
)
nodesListGetNode
(
pSort
->
pSortKeys
,
0
))
->
order
;
}
static
SNode
*
opkRewriteDownNode
(
SSortLogicNode
*
pSort
)
{
SNode
*
pDownNode
=
nodesListGetNode
(
pSort
->
node
.
pChildren
,
0
);
// todo
NODES_CLEAR_LIST
(
pSort
->
node
.
pChildren
);
return
pDownNode
;
}
static
int32_t
opkDoOptimized
(
SOptimizeContext
*
pCxt
,
SSortLogicNode
*
pSort
,
SNodeList
*
pScanNodes
)
{
EOrder
order
=
opkGetPrimaryKeyOrder
(
pSort
);
static
int32_t
sortPriKeyOptApply
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
SSortLogicNode
*
pSort
,
SNodeList
*
pScanNodes
)
{
EOrder
order
=
sortPriKeyOptGetPriKeyOrder
(
pSort
);
if
(
ORDER_DESC
==
order
)
{
SNode
*
pScan
=
NULL
;
FOREACH
(
pScan
,
pScanNodes
)
{
TSWAP
(((
SScanLogicNode
*
)
pScan
)
->
scanSeq
[
0
],
((
SScanLogicNode
*
)
pScan
)
->
scanSeq
[
1
]);
}
}
if
(
NULL
==
pSort
->
node
.
pParent
)
{
// todo
return
TSDB_CODE_SUCCESS
;
}
SNode
*
pDownNode
=
opkRewriteDownNode
(
pSort
);
SNode
*
pNode
;
FOREACH
(
pNode
,
pSort
->
node
.
pParent
->
pChildren
)
{
if
(
nodesEqualNode
(
pNode
,
(
SNode
*
)
pSort
))
{
REPLACE_NODE
(
pDownNode
);
((
SLogicNode
*
)
pDownNode
)
->
pParent
=
pSort
->
node
.
pParent
;
break
;
}
int32_t
code
=
replaceLogicNode
(
pLogicSubplan
,
(
SLogicNode
*
)
pSort
,
(
SLogicNode
*
)
nodesListGetNode
(
pSort
->
node
.
pChildren
,
0
));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
NODES_CLEAR_LIST
(
pSort
->
node
.
pChildren
);
nodesDestroyNode
((
SNode
*
)
pSort
);
}
nodesDestroyNode
((
SNode
*
)
pSort
);
return
TSDB_CODE_SUCCESS
;
return
code
;
}
static
int32_t
opkOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SSortLogicNode
*
pSort
)
{
OPTIMIZE_FLAG_SET_MASK
(
pSort
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_OPK
);
if
(
!
opkIsPrimaryKeyOrderBy
(
pSort
->
pSortKeys
)
||
1
!=
LIST_LENGTH
(
pSort
->
node
.
pChildren
))
{
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
sortPrimaryKeyOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
SSortLogicNode
*
pSort
)
{
SNodeList
*
pScanNodes
=
NULL
;
int32_t
code
=
opk
GetScanNodes
((
SLogicNode
*
)
nodesListGetNode
(
pSort
->
node
.
pChildren
,
0
),
&
pScanNodes
);
int32_t
code
=
sortPriKeyOpt
GetScanNodes
((
SLogicNode
*
)
nodesListGetNode
(
pSort
->
node
.
pChildren
,
0
),
&
pScanNodes
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pScanNodes
)
{
code
=
opkDoOptimized
(
pCxt
,
pSort
,
pScanNodes
);
code
=
sortPriKeyOptApply
(
pCxt
,
pLogicSubplan
,
pSort
,
pScanNodes
);
}
nodesClearList
(
pScanNodes
);
return
code
;
}
static
int32_t
opk
Optimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
SSortLogicNode
*
pSort
=
(
SSortLogicNode
*
)
optFindPossibleNode
(
pLogicSubplan
->
pNode
,
opkSor
tMayBeOptimized
);
static
int32_t
sortPrimaryKey
Optimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
SSortLogicNode
*
pSort
=
(
SSortLogicNode
*
)
optFindPossibleNode
(
pLogicSubplan
->
pNode
,
sortPriKeyOp
tMayBeOptimized
);
if
(
NULL
==
pSort
)
{
return
TSDB_CODE_SUCCESS
;
}
return
opkOptimizeImpl
(
pCxt
,
pSort
);
return
sortPrimaryKeyOptimizeImpl
(
pCxt
,
pLogicSubplan
,
pSort
);
}
static
bool
smaOptMayBeOptimized
(
SLogicNode
*
pNode
)
{
static
bool
sma
Index
OptMayBeOptimized
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
pNode
)
||
NULL
==
pNode
->
pParent
||
QUERY_NODE_LOGIC_PLAN_WINDOW
!=
nodeType
(
pNode
->
pParent
)
||
WINDOW_TYPE_INTERVAL
!=
((
SWindowLogicNode
*
)
pNode
->
pParent
)
->
winType
)
{
...
...
@@ -748,7 +736,8 @@ static bool smaOptMayBeOptimized(SLogicNode* pNode) {
return
true
;
}
static
int32_t
smaOptCreateMerge
(
SLogicNode
*
pChild
,
SNodeList
*
pMergeKeys
,
SNodeList
*
pTargets
,
SLogicNode
**
pOutput
)
{
static
int32_t
smaIndexOptCreateMerge
(
SLogicNode
*
pChild
,
SNodeList
*
pMergeKeys
,
SNodeList
*
pTargets
,
SLogicNode
**
pOutput
)
{
SMergeLogicNode
*
pMerge
=
(
SMergeLogicNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_MERGE
);
if
(
NULL
==
pMerge
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -767,8 +756,8 @@ static int32_t smaOptCreateMerge(SLogicNode* pChild, SNodeList* pMergeKeys, SNod
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
smaOptRecombinationNode
(
SLogicSubplan
*
pLogicSubplan
,
SLogicNode
*
pInterval
,
SLogicNode
*
pMerge
,
SLogicNode
*
pSmaScan
)
{
static
int32_t
sma
Index
OptRecombinationNode
(
SLogicSubplan
*
pLogicSubplan
,
SLogicNode
*
pInterval
,
SLogicNode
*
pMerge
,
SLogicNode
*
pSmaScan
)
{
int32_t
code
=
nodesListMakeAppend
(
&
pMerge
->
pChildren
,
(
SNode
*
)
pInterval
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListMakeAppend
(
&
pMerge
->
pChildren
,
(
SNode
*
)
pSmaScan
);
...
...
@@ -781,8 +770,8 @@ static int32_t smaOptRecombinationNode(SLogicSubplan* pLogicSubplan, SLogicNode*
return
code
;
}
static
int32_t
smaOptCreateSmaScan
(
SScanLogicNode
*
pScan
,
STableIndexInfo
*
pIndex
,
SNodeList
*
pCols
,
SLogicNode
**
pOutput
)
{
static
int32_t
sma
Index
OptCreateSmaScan
(
SScanLogicNode
*
pScan
,
STableIndexInfo
*
pIndex
,
SNodeList
*
pCols
,
SLogicNode
**
pOutput
)
{
SScanLogicNode
*
pSmaScan
=
(
SScanLogicNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_SCAN
);
if
(
NULL
==
pSmaScan
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -811,7 +800,7 @@ static int32_t smaOptCreateSmaScan(SScanLogicNode* pScan, STableIndexInfo* pInde
return
TSDB_CODE_SUCCESS
;
}
static
bool
smaOptEqualInterval
(
SScanLogicNode
*
pScan
,
SWindowLogicNode
*
pWindow
,
STableIndexInfo
*
pIndex
)
{
static
bool
sma
Index
OptEqualInterval
(
SScanLogicNode
*
pScan
,
SWindowLogicNode
*
pWindow
,
STableIndexInfo
*
pIndex
)
{
if
(
pWindow
->
interval
!=
pIndex
->
interval
||
pWindow
->
intervalUnit
!=
pIndex
->
intervalUnit
||
pWindow
->
offset
!=
pIndex
->
offset
||
pWindow
->
sliding
!=
pIndex
->
sliding
||
pWindow
->
slidingUnit
!=
pIndex
->
slidingUnit
)
{
...
...
@@ -831,7 +820,7 @@ static bool smaOptEqualInterval(SScanLogicNode* pScan, SWindowLogicNode* pWindow
return
true
;
}
static
SNode
*
smaOptCreateSmaCol
(
SNode
*
pFunc
,
uint64_t
tableId
,
int32_t
colId
)
{
static
SNode
*
sma
Index
OptCreateSmaCol
(
SNode
*
pFunc
,
uint64_t
tableId
,
int32_t
colId
)
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN
);
if
(
NULL
==
pCol
)
{
return
NULL
;
...
...
@@ -846,7 +835,7 @@ static SNode* smaOptCreateSmaCol(SNode* pFunc, uint64_t tableId, int32_t colId)
return
(
SNode
*
)
pCol
;
}
static
int32_t
smaOptFindSmaFunc
(
SNode
*
pQueryFunc
,
SNodeList
*
pSmaFuncs
)
{
static
int32_t
sma
Index
OptFindSmaFunc
(
SNode
*
pQueryFunc
,
SNodeList
*
pSmaFuncs
)
{
int32_t
index
=
0
;
SNode
*
pSmaFunc
=
NULL
;
FOREACH
(
pSmaFunc
,
pSmaFuncs
)
{
...
...
@@ -858,8 +847,8 @@ static int32_t smaOptFindSmaFunc(SNode* pQueryFunc, SNodeList* pSmaFuncs) {
return
-
1
;
}
static
int32_t
smaOptCreateSmaCols
(
SNodeList
*
pFuncs
,
uint64_t
tableId
,
SNodeList
*
pSmaFuncs
,
SNodeList
**
pOutput
,
int32_t
*
pWStrartIndex
)
{
static
int32_t
sma
Index
OptCreateSmaCols
(
SNodeList
*
pFuncs
,
uint64_t
tableId
,
SNodeList
*
pSmaFuncs
,
SNodeList
**
pOutput
,
int32_t
*
pWStrartIndex
)
{
SNodeList
*
pCols
=
NULL
;
SNode
*
pFunc
=
NULL
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
@@ -870,11 +859,11 @@ static int32_t smaOptCreateSmaCols(SNodeList* pFuncs, uint64_t tableId, SNodeLis
if
(
FUNCTION_TYPE_WSTARTTS
==
((
SFunctionNode
*
)
pFunc
)
->
funcType
)
{
*
pWStrartIndex
=
index
;
}
smaFuncIndex
=
smaOptFindSmaFunc
(
pFunc
,
pSmaFuncs
);
smaFuncIndex
=
sma
Index
OptFindSmaFunc
(
pFunc
,
pSmaFuncs
);
if
(
smaFuncIndex
<
0
)
{
break
;
}
else
{
code
=
nodesListMakeStrictAppend
(
&
pCols
,
smaOptCreateSmaCol
(
pFunc
,
tableId
,
smaFuncIndex
+
2
));
code
=
nodesListMakeStrictAppend
(
&
pCols
,
sma
Index
OptCreateSmaCol
(
pFunc
,
tableId
,
smaFuncIndex
+
2
));
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
break
;
}
...
...
@@ -891,22 +880,22 @@ static int32_t smaOptCreateSmaCols(SNodeList* pFuncs, uint64_t tableId, SNodeLis
return
code
;
}
static
int32_t
smaOptCouldApplyIndex
(
SScanLogicNode
*
pScan
,
STableIndexInfo
*
pIndex
,
SNodeList
**
pCols
,
int32_t
*
pWStrartIndex
)
{
static
int32_t
sma
Index
OptCouldApplyIndex
(
SScanLogicNode
*
pScan
,
STableIndexInfo
*
pIndex
,
SNodeList
**
pCols
,
int32_t
*
pWStrartIndex
)
{
SWindowLogicNode
*
pWindow
=
(
SWindowLogicNode
*
)
pScan
->
node
.
pParent
;
if
(
!
smaOptEqualInterval
(
pScan
,
pWindow
,
pIndex
))
{
if
(
!
sma
Index
OptEqualInterval
(
pScan
,
pWindow
,
pIndex
))
{
return
TSDB_CODE_SUCCESS
;
}
SNodeList
*
pSmaFuncs
=
NULL
;
int32_t
code
=
nodesStringToList
(
pIndex
->
expr
,
&
pSmaFuncs
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
smaOptCreateSmaCols
(
pWindow
->
pFuncs
,
pIndex
->
dstTbUid
,
pSmaFuncs
,
pCols
,
pWStrartIndex
);
code
=
sma
Index
OptCreateSmaCols
(
pWindow
->
pFuncs
,
pIndex
->
dstTbUid
,
pSmaFuncs
,
pCols
,
pWStrartIndex
);
}
nodesDestroyList
(
pSmaFuncs
);
return
code
;
}
static
SNode
*
smaOptCreateWStartTs
()
{
static
SNode
*
sma
Index
OptCreateWStartTs
()
{
SFunctionNode
*
pWStart
=
(
SFunctionNode
*
)
nodesMakeNode
(
QUERY_NODE_FUNCTION
);
if
(
NULL
==
pWStart
)
{
return
NULL
;
...
...
@@ -920,7 +909,7 @@ static SNode* smaOptCreateWStartTs() {
return
(
SNode
*
)
pWStart
;
}
static
int32_t
smaOptCreateMergeKey
(
SNode
*
pCol
,
SNodeList
**
pMergeKeys
)
{
static
int32_t
sma
Index
OptCreateMergeKey
(
SNode
*
pCol
,
SNodeList
**
pMergeKeys
)
{
SOrderByExprNode
*
pMergeKey
=
(
SOrderByExprNode
*
)
nodesMakeNode
(
QUERY_NODE_ORDER_BY_EXPR
);
if
(
NULL
==
pMergeKey
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -935,9 +924,9 @@ static int32_t smaOptCreateMergeKey(SNode* pCol, SNodeList** pMergeKeys) {
return
nodesListMakeStrictAppend
(
pMergeKeys
,
(
SNode
*
)
pMergeKey
);
}
static
int32_t
smaOptRewriteInterval
(
SWindowLogicNode
*
pInterval
,
int32_t
wstrartIndex
,
SNodeList
**
pMergeKeys
)
{
static
int32_t
sma
Index
OptRewriteInterval
(
SWindowLogicNode
*
pInterval
,
int32_t
wstrartIndex
,
SNodeList
**
pMergeKeys
)
{
if
(
wstrartIndex
<
0
)
{
SNode
*
pWStart
=
smaOptCreateWStartTs
();
SNode
*
pWStart
=
sma
Index
OptCreateWStartTs
();
if
(
NULL
==
pWStart
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
@@ -948,11 +937,11 @@ static int32_t smaOptRewriteInterval(SWindowLogicNode* pInterval, int32_t wstrar
}
wstrartIndex
=
LIST_LENGTH
(
pInterval
->
node
.
pTargets
)
-
1
;
}
return
smaOptCreateMergeKey
(
nodesListGetNode
(
pInterval
->
node
.
pTargets
,
wstrartIndex
),
pMergeKeys
);
return
sma
Index
OptCreateMergeKey
(
nodesListGetNode
(
pInterval
->
node
.
pTargets
,
wstrartIndex
),
pMergeKeys
);
}
static
int32_t
smaOptApplyIndexExt
(
SLogicSubplan
*
pLogicSubplan
,
SScanLogicNode
*
pScan
,
STableIndexInfo
*
pIndex
,
SNodeList
*
pSmaCols
,
int32_t
wstrartIndex
)
{
static
int32_t
sma
Index
OptApplyIndexExt
(
SLogicSubplan
*
pLogicSubplan
,
SScanLogicNode
*
pScan
,
STableIndexInfo
*
pIndex
,
SNodeList
*
pSmaCols
,
int32_t
wstrartIndex
)
{
SWindowLogicNode
*
pInterval
=
(
SWindowLogicNode
*
)
pScan
->
node
.
pParent
;
SNodeList
*
pMergeTargets
=
nodesCloneList
(
pInterval
->
node
.
pTargets
);
if
(
NULL
==
pMergeTargets
)
{
...
...
@@ -961,42 +950,42 @@ static int32_t smaOptApplyIndexExt(SLogicSubplan* pLogicSubplan, SScanLogicNode*
SLogicNode
*
pSmaScan
=
NULL
;
SLogicNode
*
pMerge
=
NULL
;
SNodeList
*
pMergeKeys
=
NULL
;
int32_t
code
=
smaOptRewriteInterval
(
pInterval
,
wstrartIndex
,
&
pMergeKeys
);
int32_t
code
=
sma
Index
OptRewriteInterval
(
pInterval
,
wstrartIndex
,
&
pMergeKeys
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
smaOptCreateSmaScan
(
pScan
,
pIndex
,
pSmaCols
,
&
pSmaScan
);
code
=
sma
Index
OptCreateSmaScan
(
pScan
,
pIndex
,
pSmaCols
,
&
pSmaScan
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
smaOptCreateMerge
(
pScan
->
node
.
pParent
,
pMergeKeys
,
pMergeTargets
,
&
pMerge
);
code
=
sma
Index
OptCreateMerge
(
pScan
->
node
.
pParent
,
pMergeKeys
,
pMergeTargets
,
&
pMerge
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
smaOptRecombinationNode
(
pLogicSubplan
,
pScan
->
node
.
pParent
,
pMerge
,
pSmaScan
);
code
=
sma
Index
OptRecombinationNode
(
pLogicSubplan
,
pScan
->
node
.
pParent
,
pMerge
,
pSmaScan
);
}
return
code
;
}
static
int32_t
smaOptApplyIndex
(
SLogicSubplan
*
pLogicSubplan
,
SScanLogicNode
*
pScan
,
STableIndexInfo
*
pIndex
,
SNodeList
*
pSmaCols
,
int32_t
wstrartIndex
)
{
static
int32_t
sma
Index
OptApplyIndex
(
SLogicSubplan
*
pLogicSubplan
,
SScanLogicNode
*
pScan
,
STableIndexInfo
*
pIndex
,
SNodeList
*
pSmaCols
,
int32_t
wstrartIndex
)
{
SLogicNode
*
pSmaScan
=
NULL
;
int32_t
code
=
smaOptCreateSmaScan
(
pScan
,
pIndex
,
pSmaCols
,
&
pSmaScan
);
int32_t
code
=
sma
Index
OptCreateSmaScan
(
pScan
,
pIndex
,
pSmaCols
,
&
pSmaScan
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
replaceLogicNode
(
pLogicSubplan
,
pScan
->
node
.
pParent
,
pSmaScan
);
}
return
code
;
}
static
void
smaOptDestroySmaIndex
(
void
*
p
)
{
taosMemoryFree
(((
STableIndexInfo
*
)
p
)
->
expr
);
}
static
void
sma
Index
OptDestroySmaIndex
(
void
*
p
)
{
taosMemoryFree
(((
STableIndexInfo
*
)
p
)
->
expr
);
}
static
int32_t
smaOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
SScanLogicNode
*
pScan
)
{
static
int32_t
sma
Index
OptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
SScanLogicNode
*
pScan
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
nindexes
=
taosArrayGetSize
(
pScan
->
pSmaIndexes
);
for
(
int32_t
i
=
0
;
i
<
nindexes
;
++
i
)
{
STableIndexInfo
*
pIndex
=
taosArrayGet
(
pScan
->
pSmaIndexes
,
i
);
SNodeList
*
pSmaCols
=
NULL
;
int32_t
wstrartIndex
=
-
1
;
code
=
smaOptCouldApplyIndex
(
pScan
,
pIndex
,
&
pSmaCols
,
&
wstrartIndex
);
code
=
sma
Index
OptCouldApplyIndex
(
pScan
,
pIndex
,
&
pSmaCols
,
&
wstrartIndex
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pSmaCols
)
{
code
=
smaOptApplyIndex
(
pLogicSubplan
,
pScan
,
pIndex
,
pSmaCols
,
wstrartIndex
);
taosArrayDestroyEx
(
pScan
->
pSmaIndexes
,
smaOptDestroySmaIndex
);
code
=
sma
Index
OptApplyIndex
(
pLogicSubplan
,
pScan
,
pIndex
,
pSmaCols
,
wstrartIndex
);
taosArrayDestroyEx
(
pScan
->
pSmaIndexes
,
sma
Index
OptDestroySmaIndex
);
pScan
->
pSmaIndexes
=
NULL
;
break
;
}
...
...
@@ -1004,12 +993,12 @@ static int32_t smaOptimizeImpl(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubp
return
code
;
}
static
int32_t
smaOptimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
SScanLogicNode
*
pScan
=
(
SScanLogicNode
*
)
optFindPossibleNode
(
pLogicSubplan
->
pNode
,
smaOptMayBeOptimized
);
static
int32_t
sma
Index
Optimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
SScanLogicNode
*
pScan
=
(
SScanLogicNode
*
)
optFindPossibleNode
(
pLogicSubplan
->
pNode
,
sma
Index
OptMayBeOptimized
);
if
(
NULL
==
pScan
)
{
return
TSDB_CODE_SUCCESS
;
}
return
smaOptimizeImpl
(
pCxt
,
pLogicSubplan
,
pScan
);
return
sma
Index
OptimizeImpl
(
pCxt
,
pLogicSubplan
,
pScan
);
}
static
EDealRes
partTagsOptHasColImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
...
...
@@ -1084,7 +1073,7 @@ static int32_t partTagsOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub
int32_t
code
=
TSDB_CODE_SUCCESS
;
SScanLogicNode
*
pScan
=
(
SScanLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
);
if
(
QUERY_NODE_LOGIC_PLAN_PARTITION
==
nodeType
(
pNode
))
{
TSWAP
(((
SPartitionLogicNode
*
)
pNode
)
->
pPartitionKeys
,
pScan
->
p
Part
Tags
);
TSWAP
(((
SPartitionLogicNode
*
)
pNode
)
->
pPartitionKeys
,
pScan
->
p
Group
Tags
);
int32_t
code
=
replaceLogicNode
(
pLogicSubplan
,
pNode
,
(
SLogicNode
*
)
pScan
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
NODES_CLEAR_LIST
(
pNode
->
pChildren
);
...
...
@@ -1094,7 +1083,7 @@ static int32_t partTagsOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub
SNode
*
pGroupKey
=
NULL
;
FOREACH
(
pGroupKey
,
((
SAggLogicNode
*
)
pNode
)
->
pGroupKeys
)
{
code
=
nodesListMakeStrictAppend
(
&
pScan
->
p
Part
Tags
,
nodesCloneNode
(
nodesListGetNode
(((
SGroupingSetNode
*
)
pGroupKey
)
->
pParameterList
,
0
)));
&
pScan
->
p
Group
Tags
,
nodesCloneNode
(
nodesListGetNode
(((
SGroupingSetNode
*
)
pGroupKey
)
->
pParameterList
,
0
)));
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
break
;
}
...
...
@@ -1102,13 +1091,11 @@ static int32_t partTagsOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub
NODES_DESTORY_LIST
(((
SAggLogicNode
*
)
pNode
)
->
pGroupKeys
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
partTagsOptRebuildTbanme
(
pScan
->
p
Part
Tags
);
code
=
partTagsOptRebuildTbanme
(
pScan
->
p
Group
Tags
);
}
return
code
;
}
//=====================================================================================================================
// eliminate project optimization
static
bool
eliminateProjOptCheckProjColumnNames
(
SProjectLogicNode
*
pProjectNode
)
{
SHashObj
*
pProjColNameHash
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
SNode
*
pProjection
;
...
...
@@ -1142,7 +1129,7 @@ static bool eliminateProjOptMayBeOptimized(SLogicNode* pNode) {
return
false
;
}
SNode
*
pProjection
;
SNode
*
pProjection
;
FOREACH
(
pProjection
,
pProjectNode
->
pProjections
)
{
SExprNode
*
pExprNode
=
(
SExprNode
*
)
pProjection
;
if
(
QUERY_NODE_COLUMN
!=
nodeType
(
pExprNode
))
{
...
...
@@ -1190,31 +1177,169 @@ static int32_t eliminateProjOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLog
return
eliminateProjOptimizeImpl
(
pCxt
,
pLogicSubplan
,
pProjectNode
);
}
//=====================================================================================================================
// eliminate Set Operator optimization
static
bool
rewriteTailOptMayBeOptimized
(
SLogicNode
*
pNode
)
{
return
QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC
==
nodeType
(
pNode
)
&&
((
SIndefRowsFuncLogicNode
*
)
pNode
)
->
isTailFunc
;
}
static
SNode
*
rewriteTailOptCreateOrderByExpr
(
SNode
*
pSortKey
)
{
SOrderByExprNode
*
pOrder
=
(
SOrderByExprNode
*
)
nodesMakeNode
(
QUERY_NODE_ORDER_BY_EXPR
);
if
(
NULL
==
pOrder
)
{
return
NULL
;
}
pOrder
->
order
=
ORDER_DESC
;
pOrder
->
pExpr
=
nodesCloneNode
(
pSortKey
);
if
(
NULL
==
pOrder
->
pExpr
)
{
nodesDestroyNode
((
SNode
*
)
pOrder
);
return
NULL
;
}
return
(
SNode
*
)
pOrder
;
}
static
int32_t
rewriteTailOptCreateLimit
(
SNode
*
pLimit
,
SNode
*
pOffset
,
SNode
**
pOutput
)
{
SLimitNode
*
pLimitNode
=
(
SLimitNode
*
)
nodesMakeNode
(
QUERY_NODE_LIMIT
);
if
(
NULL
==
pLimitNode
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pLimitNode
->
limit
=
NULL
==
pLimit
?
-
1
:
((
SValueNode
*
)
pLimit
)
->
datum
.
i
;
pLimitNode
->
offset
=
NULL
==
pOffset
?
-
1
:
((
SValueNode
*
)
pOffset
)
->
datum
.
i
;
*
pOutput
=
(
SNode
*
)
pLimitNode
;
return
TSDB_CODE_SUCCESS
;
}
static
bool
rewriteTailOptNeedGroupSort
(
SIndefRowsFuncLogicNode
*
pIndef
)
{
if
(
1
!=
LIST_LENGTH
(
pIndef
->
node
.
pChildren
))
{
return
false
;
}
SNode
*
pChild
=
nodesListGetNode
(
pIndef
->
node
.
pChildren
,
0
);
return
QUERY_NODE_LOGIC_PLAN_PARTITION
==
nodeType
(
pChild
)
||
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pChild
)
&&
NULL
!=
((
SScanLogicNode
*
)
pChild
)
->
pGroupTags
);
}
static
int32_t
rewriteTailOptCreateSort
(
SIndefRowsFuncLogicNode
*
pIndef
,
SLogicNode
**
pOutput
)
{
SSortLogicNode
*
pSort
=
(
SSortLogicNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_SORT
);
if
(
NULL
==
pSort
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pSort
->
groupSort
=
rewriteTailOptNeedGroupSort
(
pIndef
);
TSWAP
(
pSort
->
node
.
pChildren
,
pIndef
->
node
.
pChildren
);
pSort
->
node
.
precision
=
pIndef
->
node
.
precision
;
// tail(expr, [limit, offset,] _rowts)
SFunctionNode
*
pTail
=
(
SFunctionNode
*
)
nodesListGetNode
(
pIndef
->
pFuncs
,
0
);
int32_t
rowtsIndex
=
LIST_LENGTH
(
pTail
->
pParameterList
)
-
1
;
int32_t
code
=
nodesListMakeStrictAppend
(
&
pSort
->
pSortKeys
,
rewriteTailOptCreateOrderByExpr
(
nodesListGetNode
(
pTail
->
pParameterList
,
rowtsIndex
)));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pSort
->
node
.
pTargets
=
nodesCloneList
(((
SLogicNode
*
)
nodesListGetNode
(
pSort
->
node
.
pChildren
,
0
))
->
pTargets
);
if
(
NULL
==
pSort
->
node
.
pTargets
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pOutput
=
(
SLogicNode
*
)
pSort
;
}
else
{
nodesDestroyNode
((
SNode
*
)
pSort
);
}
return
code
;
}
static
SNode
*
rewriteTailOptCreateProjectExpr
(
SFunctionNode
*
pTail
)
{
SNode
*
pExpr
=
nodesCloneNode
(
nodesListGetNode
(
pTail
->
pParameterList
,
0
));
if
(
NULL
==
pExpr
)
{
return
NULL
;
}
strcpy
(((
SExprNode
*
)
pExpr
)
->
aliasName
,
pTail
->
node
.
aliasName
);
return
pExpr
;
}
static
int32_t
rewriteTailOptCreateProject
(
SIndefRowsFuncLogicNode
*
pIndef
,
SLogicNode
**
pOutput
)
{
SProjectLogicNode
*
pProject
=
(
SProjectLogicNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_PROJECT
);
if
(
NULL
==
pProject
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
TSWAP
(
pProject
->
node
.
pTargets
,
pIndef
->
node
.
pTargets
);
pProject
->
node
.
precision
=
pIndef
->
node
.
precision
;
// tail(expr, [limit, offset,] _rowts)
SFunctionNode
*
pTail
=
(
SFunctionNode
*
)
nodesListGetNode
(
pIndef
->
pFuncs
,
0
);
int32_t
limitIndex
=
LIST_LENGTH
(
pTail
->
pParameterList
)
>
2
?
1
:
-
1
;
int32_t
offsetIndex
=
LIST_LENGTH
(
pTail
->
pParameterList
)
>
3
?
2
:
-
1
;
int32_t
code
=
nodesListMakeStrictAppend
(
&
pProject
->
pProjections
,
rewriteTailOptCreateProjectExpr
(
pTail
));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteTailOptCreateLimit
(
limitIndex
<
0
?
NULL
:
nodesListGetNode
(
pTail
->
pParameterList
,
limitIndex
),
offsetIndex
<
0
?
NULL
:
nodesListGetNode
(
pTail
->
pParameterList
,
offsetIndex
),
&
pProject
->
node
.
pLimit
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pOutput
=
(
SLogicNode
*
)
pProject
;
}
else
{
nodesDestroyNode
((
SNode
*
)
pProject
);
}
return
code
;
}
static
int32_t
rewriteTailOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
SIndefRowsFuncLogicNode
*
pIndef
)
{
SLogicNode
*
pSort
=
NULL
;
SLogicNode
*
pProject
=
NULL
;
int32_t
code
=
rewriteTailOptCreateSort
(
pIndef
,
&
pSort
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteTailOptCreateProject
(
pIndef
,
&
pProject
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListMakeAppend
(
&
pProject
->
pChildren
,
(
SNode
*
)
pSort
);
pSort
->
pParent
=
pProject
;
pSort
=
NULL
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
replaceLogicNode
(
pLogicSubplan
,
(
SLogicNode
*
)
pIndef
,
pProject
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
nodesDestroyNode
((
SNode
*
)
pIndef
);
}
else
{
nodesDestroyNode
((
SNode
*
)
pSort
);
nodesDestroyNode
((
SNode
*
)
pProject
);
}
return
code
;
}
static
int32_t
rewriteTailOptimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
SIndefRowsFuncLogicNode
*
pIndef
=
(
SIndefRowsFuncLogicNode
*
)
optFindPossibleNode
(
pLogicSubplan
->
pNode
,
rewriteTailOptMayBeOptimized
);
if
(
NULL
==
pIndef
)
{
return
TSDB_CODE_SUCCESS
;
}
return
rewriteTailOptimizeImpl
(
pCxt
,
pLogicSubplan
,
pIndef
);
}
static
bool
eliminateSetOpMayBeOptimized
(
SLogicNode
*
pNode
)
{
SLogicNode
*
pParent
=
pNode
->
pParent
;
if
(
NULL
==
pParent
||
QUERY_NODE_LOGIC_PLAN_AGG
!=
nodeType
(
pParent
)
&&
QUERY_NODE_LOGIC_PLAN_PROJECT
!=
nodeType
(
pParent
)
||
QUERY_NODE_LOGIC_PLAN_AGG
!=
nodeType
(
pParent
)
&&
QUERY_NODE_LOGIC_PLAN_PROJECT
!=
nodeType
(
pParent
)
||
LIST_LENGTH
(
pParent
->
pChildren
)
<
2
)
{
return
false
;
}
if
(
nodeType
(
pNode
)
!=
nodeType
(
pNode
->
pParent
)
||
LIST_LENGTH
(
pNode
->
pChildren
)
<
2
)
{
if
(
nodeType
(
pNode
)
!=
nodeType
(
pNode
->
pParent
)
||
LIST_LENGTH
(
pNode
->
pChildren
)
<
2
)
{
return
false
;
}
return
true
;
}
static
int32_t
eliminateSetOpOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
SLogicNode
*
pSetOpNode
)
{
static
int32_t
eliminateSetOpOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
SLogicNode
*
pSetOpNode
)
{
SNode
*
pSibling
;
FOREACH
(
pSibling
,
pSetOpNode
->
pParent
->
pChildren
)
{
if
(
nodesEqualNode
(
pSibling
,
(
SNode
*
)
pSetOpNode
))
{
SNode
*
pChild
;
FOREACH
(
pChild
,
pSetOpNode
->
pChildren
)
{
((
SLogicNode
*
)
pChild
)
->
pParent
=
pSetOpNode
->
pParent
;
}
FOREACH
(
pChild
,
pSetOpNode
->
pChildren
)
{
((
SLogicNode
*
)
pChild
)
->
pParent
=
pSetOpNode
->
pParent
;
}
INSERT_LIST
(
pSetOpNode
->
pParent
->
pChildren
,
pSetOpNode
->
pChildren
);
pSetOpNode
->
pChildren
=
NULL
;
...
...
@@ -1237,13 +1362,14 @@ static int32_t eliminateSetOpOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLo
// clang-format off
static
const
SOptimizeRule
optimizeRuleSet
[]
=
{
{.
pName
=
"
OptimizeScanData"
,
.
optimizeFunc
=
osd
Optimize
},
{.
pName
=
"
ConditionPushDown"
,
.
optimizeFunc
=
cp
dOptimize
},
{.
pName
=
"
OrderByPrimaryKey"
,
.
optimizeFunc
=
opk
Optimize
},
{.
pName
=
"SmaIndex"
,
.
optimizeFunc
=
smaOptimize
},
{.
pName
=
"
ScanPath"
,
.
optimizeFunc
=
scanPath
Optimize
},
{.
pName
=
"
PushDownCondition"
,
.
optimizeFunc
=
pushDownCon
dOptimize
},
{.
pName
=
"
SortPrimaryKey"
,
.
optimizeFunc
=
sortPrimaryKey
Optimize
},
{.
pName
=
"SmaIndex"
,
.
optimizeFunc
=
sma
Index
Optimize
},
{.
pName
=
"PartitionTags"
,
.
optimizeFunc
=
partTagsOptimize
},
{.
pName
=
"EliminateProject"
,
.
optimizeFunc
=
eliminateProjOptimize
},
{.
pName
=
"EliminateSetOperator"
,
.
optimizeFunc
=
eliminateSetOpOptimize
}
{.
pName
=
"EliminateSetOperator"
,
.
optimizeFunc
=
eliminateSetOpOptimize
},
{.
pName
=
"RewriteTail"
,
.
optimizeFunc
=
rewriteTailOptimize
}
};
// clang-format on
...
...
source/libs/planner/src/planPhysiCreater.c
浏览文件 @
da8db399
...
...
@@ -41,8 +41,12 @@ typedef struct SPhysiPlanContext {
static
int32_t
getSlotKey
(
SNode
*
pNode
,
const
char
*
pStmtName
,
char
*
pKey
)
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
if
(
NULL
!=
pStmtName
&&
'\0'
!=
pStmtName
[
0
])
{
return
sprintf
(
pKey
,
"%s.%s"
,
pStmtName
,
pCol
->
node
.
aliasName
);
if
(
NULL
!=
pStmtName
)
{
if
(
'\0'
!=
pStmtName
[
0
])
{
return
sprintf
(
pKey
,
"%s.%s"
,
pStmtName
,
pCol
->
node
.
aliasName
);
}
else
{
return
sprintf
(
pKey
,
"%s"
,
pCol
->
node
.
aliasName
);
}
}
if
(
'\0'
==
pCol
->
tableAlias
[
0
])
{
return
sprintf
(
pKey
,
"%s"
,
pCol
->
colName
);
...
...
@@ -56,11 +60,13 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey) {
return
sprintf
(
pKey
,
"%s"
,
((
SExprNode
*
)
pNode
)
->
aliasName
);
}
static
SNode
*
createSlotDesc
(
SPhysiPlanContext
*
pCxt
,
const
SNode
*
pNode
,
int16_t
slotId
,
bool
output
,
bool
reserve
)
{
static
SNode
*
createSlotDesc
(
SPhysiPlanContext
*
pCxt
,
const
char
*
pName
,
const
SNode
*
pNode
,
int16_t
slotId
,
bool
output
,
bool
reserve
)
{
SSlotDescNode
*
pSlot
=
(
SSlotDescNode
*
)
nodesMakeNode
(
QUERY_NODE_SLOT_DESC
);
if
(
NULL
==
pSlot
)
{
return
NULL
;
}
strcpy
(
pSlot
->
name
,
pName
);
pSlot
->
slotId
=
slotId
;
pSlot
->
dataType
=
((
SExprNode
*
)
pNode
)
->
resType
;
pSlot
->
reserve
=
reserve
;
...
...
@@ -99,10 +105,8 @@ static int32_t putSlotToHashImpl(int16_t dataBlockId, int16_t slotId, const char
return
taosHashPut
(
pHash
,
pName
,
len
,
&
index
,
sizeof
(
SSlotIndex
));
}
static
int32_t
putSlotToHash
(
int16_t
dataBlockId
,
int16_t
slotId
,
SNode
*
pNode
,
SHashObj
*
pHash
)
{
char
name
[
TSDB_TABLE_NAME_LEN
+
TSDB_COL_NAME_LEN
];
int32_t
len
=
getSlotKey
(
pNode
,
NULL
,
name
);
return
putSlotToHashImpl
(
dataBlockId
,
slotId
,
name
,
len
,
pHash
);
static
int32_t
putSlotToHash
(
const
char
*
pName
,
int16_t
dataBlockId
,
int16_t
slotId
,
SNode
*
pNode
,
SHashObj
*
pHash
)
{
return
putSlotToHashImpl
(
dataBlockId
,
slotId
,
pName
,
strlen
(
pName
),
pHash
);
}
static
int32_t
createDataBlockDescHash
(
SPhysiPlanContext
*
pCxt
,
int32_t
capacity
,
int16_t
dataBlockId
,
...
...
@@ -131,9 +135,11 @@ static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SD
int16_t
slotId
=
0
;
SNode
*
pNode
=
NULL
;
FOREACH
(
pNode
,
pList
)
{
code
=
nodesListStrictAppend
(
pDataBlockDesc
->
pSlots
,
createSlotDesc
(
pCxt
,
pNode
,
slotId
,
true
,
false
));
char
name
[
TSDB_TABLE_NAME_LEN
+
TSDB_COL_NAME_LEN
];
getSlotKey
(
pNode
,
NULL
,
name
);
code
=
nodesListStrictAppend
(
pDataBlockDesc
->
pSlots
,
createSlotDesc
(
pCxt
,
name
,
pNode
,
slotId
,
true
,
false
));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
putSlotToHash
(
pDataBlockDesc
->
dataBlockId
,
slotId
,
pNode
,
pHash
);
code
=
putSlotToHash
(
name
,
pDataBlockDesc
->
dataBlockId
,
slotId
,
pNode
,
pHash
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pDataBlockDesc
->
totalRowSize
+=
((
SExprNode
*
)
pNode
)
->
resType
.
bytes
;
...
...
@@ -196,7 +202,8 @@ static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList,
int32_t
len
=
getSlotKey
(
pExpr
,
pStmtName
,
name
);
SSlotIndex
*
pIndex
=
taosHashGet
(
pHash
,
name
,
len
);
if
(
NULL
==
pIndex
)
{
code
=
nodesListStrictAppend
(
pDataBlockDesc
->
pSlots
,
createSlotDesc
(
pCxt
,
pExpr
,
nextSlotId
,
output
,
reserve
));
code
=
nodesListStrictAppend
(
pDataBlockDesc
->
pSlots
,
createSlotDesc
(
pCxt
,
name
,
pExpr
,
nextSlotId
,
output
,
reserve
));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
putSlotToHashImpl
(
pDataBlockDesc
->
dataBlockId
,
nextSlotId
,
name
,
len
,
pHash
);
}
...
...
@@ -513,12 +520,13 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp
tNameGetFullDbName
(
&
pScanLogicNode
->
tableName
,
pSubplan
->
dbFName
);
pTableScan
->
dataRequired
=
pScanLogicNode
->
dataRequired
;
pTableScan
->
pDynamicScanFuncs
=
nodesCloneList
(
pScanLogicNode
->
pDynamicScanFuncs
);
pTableScan
->
p
PartitionTags
=
nodesCloneList
(
pScanLogicNode
->
pPart
Tags
);
pTableScan
->
p
GroupTags
=
nodesCloneList
(
pScanLogicNode
->
pGroup
Tags
);
if
((
NULL
!=
pScanLogicNode
->
pDynamicScanFuncs
&&
NULL
==
pTableScan
->
pDynamicScanFuncs
)
||
(
NULL
!=
pScanLogicNode
->
p
PartTags
&&
NULL
==
pTableScan
->
pPartition
Tags
))
{
(
NULL
!=
pScanLogicNode
->
p
GroupTags
&&
NULL
==
pTableScan
->
pGroup
Tags
))
{
nodesDestroyNode
((
SNode
*
)
pTableScan
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pTableScan
->
groupSort
=
pScanLogicNode
->
groupSort
;
pTableScan
->
interval
=
pScanLogicNode
->
interval
;
pTableScan
->
offset
=
pScanLogicNode
->
offset
;
pTableScan
->
sliding
=
pScanLogicNode
->
sliding
;
...
...
@@ -1170,8 +1178,9 @@ static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildr
static
int32_t
createSortPhysiNode
(
SPhysiPlanContext
*
pCxt
,
SNodeList
*
pChildren
,
SSortLogicNode
*
pSortLogicNode
,
SPhysiNode
**
pPhyNode
)
{
SSortPhysiNode
*
pSort
=
(
SSortPhysiNode
*
)
makePhysiNode
(
pCxt
,
(
SLogicNode
*
)
pSortLogicNode
,
QUERY_NODE_PHYSICAL_PLAN_SORT
);
SSortPhysiNode
*
pSort
=
(
SSortPhysiNode
*
)
makePhysiNode
(
pCxt
,
(
SLogicNode
*
)
pSortLogicNode
,
pSortLogicNode
->
groupSort
?
QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT
:
QUERY_NODE_PHYSICAL_PLAN_SORT
);
if
(
NULL
==
pSort
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
@@ -1185,7 +1194,7 @@ static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pPrecalcExprs
)
{
code
=
setListSlotId
(
pCxt
,
pChildTupe
->
dataBlockId
,
-
1
,
pPrecalcExprs
,
&
pSort
->
pExprs
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
add
DataBlockSlots
(
pCxt
,
pSort
->
pExprs
,
pChildTupe
);
code
=
pushdown
DataBlockSlots
(
pCxt
,
pSort
->
pExprs
,
pChildTupe
);
}
}
...
...
@@ -1322,6 +1331,7 @@ static int32_t createMergePhysiNode(SPhysiPlanContext* pCxt, SMergeLogicNode* pM
pMerge
->
numOfChannels
=
pMergeLogicNode
->
numOfChannels
;
pMerge
->
srcGroupId
=
pMergeLogicNode
->
srcGroupId
;
pMerge
->
groupSort
=
pMergeLogicNode
->
groupSort
;
int32_t
code
=
addDataBlockSlots
(
pCxt
,
pMergeLogicNode
->
pInputs
,
pMerge
->
node
.
pOutputDataBlockDesc
);
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
da8db399
...
...
@@ -362,7 +362,7 @@ static int32_t stbSplGetNumOfVgroups(SLogicNode* pNode) {
}
static
int32_t
stbSplCreateMergeNode
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
SLogicNode
*
pSplitNode
,
SNodeList
*
pMergeKeys
,
SLogicNode
*
pPartChild
)
{
SNodeList
*
pMergeKeys
,
SLogicNode
*
pPartChild
,
bool
groupSort
)
{
SMergeLogicNode
*
pMerge
=
(
SMergeLogicNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_MERGE
);
if
(
NULL
==
pMerge
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -371,6 +371,7 @@ static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla
pMerge
->
srcGroupId
=
pCxt
->
groupId
;
pMerge
->
node
.
precision
=
pPartChild
->
precision
;
pMerge
->
pMergeKeys
=
pMergeKeys
;
pMerge
->
groupSort
=
groupSort
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
pMerge
->
pInputs
=
nodesCloneList
(
pPartChild
->
pTargets
);
...
...
@@ -430,7 +431,7 @@ static int32_t stbSplSplitIntervalForBatch(SSplitContext* pCxt, SStableSplitInfo
SNodeList
*
pMergeKeys
=
NULL
;
code
=
stbSplCreateMergeKeysByPrimaryKey
(((
SWindowLogicNode
*
)
pInfo
->
pSplitNode
)
->
pTspk
,
&
pMergeKeys
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
stbSplCreateMergeNode
(
pCxt
,
NULL
,
pInfo
->
pSplitNode
,
pMergeKeys
,
pPartWindow
);
code
=
stbSplCreateMergeNode
(
pCxt
,
NULL
,
pInfo
->
pSplitNode
,
pMergeKeys
,
pPartWindow
,
false
);
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
nodesDestroyList
(
pMergeKeys
);
...
...
@@ -497,12 +498,16 @@ static int32_t stbSplSplitSessionForStream(SSplitContext* pCxt, SStableSplitInfo
return
code
;
}
static
void
s
plSetTableScanType
(
SLogicNode
*
pNode
,
EScanType
scanTyp
e
)
{
static
void
s
tbSplSetTableMergeScan
(
SLogicNode
*
pNod
e
)
{
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pNode
))
{
((
SScanLogicNode
*
)
pNode
)
->
scanType
=
scanType
;
SScanLogicNode
*
pScan
=
(
SScanLogicNode
*
)
pNode
;
pScan
->
scanType
=
SCAN_TYPE_TABLE_MERGE
;
if
(
NULL
!=
pScan
->
pGroupTags
)
{
pScan
->
groupSort
=
true
;
}
}
else
{
if
(
1
==
LIST_LENGTH
(
pNode
->
pChildren
))
{
s
plSetTableScanType
((
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
),
scanType
);
s
tbSplSetTableMergeScan
((
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
)
);
}
}
}
...
...
@@ -515,7 +520,7 @@ static int32_t stbSplSplitSessionOrStateForBatch(SSplitContext* pCxt, SStableSpl
int32_t
code
=
stbSplCreateMergeKeysByPrimaryKey
(((
SWindowLogicNode
*
)
pWindow
)
->
pTspk
,
&
pMergeKeys
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
stbSplCreateMergeNode
(
pCxt
,
pInfo
->
pSubplan
,
pChild
,
pMergeKeys
,
(
SLogicNode
*
)
pChild
);
code
=
stbSplCreateMergeNode
(
pCxt
,
pInfo
->
pSubplan
,
pChild
,
pMergeKeys
,
(
SLogicNode
*
)
pChild
,
true
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -524,13 +529,10 @@ static int32_t stbSplSplitSessionOrStateForBatch(SSplitContext* pCxt, SStableSpl
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
splSetTableScanType
(
pChild
,
SCAN_TYPE_TABLE_MERGE
);
++
(
pCxt
->
groupId
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
stbSplSetTableMergeScan
(
pChild
);
pInfo
->
pSubplan
->
subplanType
=
SUBPLAN_TYPE_MERGE
;
SPLIT_FLAG_SET_MASK
(
pInfo
->
pSubplan
->
splitFlag
,
SPLIT_FLAG_STABLE_SPLIT
);
++
(
pCxt
->
groupId
);
}
else
{
nodesDestroyList
(
pMergeKeys
);
}
...
...
@@ -560,7 +562,7 @@ static int32_t stbSplSplitState(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
static
SNodeList
*
stbSplGetPartKeys
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pNode
))
{
return
((
SScanLogicNode
*
)
pNode
)
->
p
Part
Tags
;
return
((
SScanLogicNode
*
)
pNode
)
->
p
Group
Tags
;
}
else
if
(
QUERY_NODE_LOGIC_PLAN_PARTITION
==
nodeType
(
pNode
))
{
return
((
SPartitionLogicNode
*
)
pNode
)
->
pPartitionKeys
;
}
else
{
...
...
@@ -775,6 +777,7 @@ static int32_t stbSplCreatePartSortNode(SSortLogicNode* pSort, SLogicNode** pOut
pPartSort
->
node
.
pChildren
=
pChildren
;
splSetParent
((
SLogicNode
*
)
pPartSort
);
pPartSort
->
pSortKeys
=
pSortKeys
;
pPartSort
->
groupSort
=
pSort
->
groupSort
;
code
=
stbSplCreateMergeKeys
(
pPartSort
->
pSortKeys
,
pPartSort
->
node
.
pTargets
,
&
pMergeKeys
);
}
...
...
@@ -789,12 +792,29 @@ static int32_t stbSplCreatePartSortNode(SSortLogicNode* pSort, SLogicNode** pOut
return
code
;
}
static
void
stbSplSetScanPartSort
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pNode
))
{
SScanLogicNode
*
pScan
=
(
SScanLogicNode
*
)
pNode
;
if
(
NULL
!=
pScan
->
pGroupTags
)
{
pScan
->
groupSort
=
true
;
}
}
else
{
if
(
1
==
LIST_LENGTH
(
pNode
->
pChildren
))
{
stbSplSetScanPartSort
((
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
));
}
}
}
static
int32_t
stbSplSplitSortNode
(
SSplitContext
*
pCxt
,
SStableSplitInfo
*
pInfo
)
{
SLogicNode
*
pPartSort
=
NULL
;
SNodeList
*
pMergeKeys
=
NULL
;
bool
groupSort
=
((
SSortLogicNode
*
)
pInfo
->
pSplitNode
)
->
groupSort
;
int32_t
code
=
stbSplCreatePartSortNode
((
SSortLogicNode
*
)
pInfo
->
pSplitNode
,
&
pPartSort
,
&
pMergeKeys
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
stbSplCreateMergeNode
(
pCxt
,
pInfo
->
pSubplan
,
pInfo
->
pSplitNode
,
pMergeKeys
,
pPartSort
);
code
=
stbSplCreateMergeNode
(
pCxt
,
pInfo
->
pSubplan
,
pInfo
->
pSplitNode
,
pMergeKeys
,
pPartSort
,
groupSort
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
groupSort
)
{
stbSplSetScanPartSort
(
pPartSort
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListMakeStrictAppend
(
&
pInfo
->
pSubplan
->
pChildren
,
...
...
@@ -829,7 +849,7 @@ static int32_t stbSplSplitScanNodeForJoin(SSplitContext* pCxt, SLogicSubplan* pS
SNodeList
*
pMergeKeys
=
NULL
;
int32_t
code
=
stbSplCreateMergeKeysByPrimaryKey
(
stbSplFindPrimaryKeyFromScan
(
pScan
),
&
pMergeKeys
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
stbSplCreateMergeNode
(
pCxt
,
pSubplan
,
(
SLogicNode
*
)
pScan
,
pMergeKeys
,
(
SLogicNode
*
)
pScan
);
code
=
stbSplCreateMergeNode
(
pCxt
,
pSubplan
,
(
SLogicNode
*
)
pScan
,
pMergeKeys
,
(
SLogicNode
*
)
pScan
,
false
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListMakeStrictAppend
(
&
pSubplan
->
pChildren
,
...
...
source/libs/planner/test/planBasicTest.cpp
浏览文件 @
da8db399
...
...
@@ -67,6 +67,14 @@ TEST_F(PlanBasicTest, tailFunc) {
run
(
"SELECT TAIL(c1, 10) FROM t1"
);
run
(
"SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10"
);
run
(
"SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10 PARTITION BY c1"
);
run
(
"SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10 ORDER BY 1"
);
run
(
"SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10 LIMIT 5"
);
run
(
"SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10 PARTITION BY c1 LIMIT 5"
);
}
TEST_F
(
PlanBasicTest
,
interpFunc
)
{
...
...
source/libs/planner/test/planTestMain.cpp
浏览文件 @
da8db399
...
...
@@ -76,6 +76,7 @@ static void parseArg(int argc, char* argv[]) {
static
struct
option
long_options
[]
=
{
{
"dump"
,
optional_argument
,
NULL
,
'd'
},
{
"skipSql"
,
required_argument
,
NULL
,
's'
},
{
"limitSql"
,
required_argument
,
NULL
,
'i'
},
{
"log"
,
required_argument
,
NULL
,
'l'
},
{
0
,
0
,
0
,
0
}
};
...
...
@@ -88,6 +89,9 @@ static void parseArg(int argc, char* argv[]) {
case
's'
:
setSkipSqlNum
(
optarg
);
break
;
case
'i'
:
setLimitSqlNum
(
optarg
);
break
;
case
'l'
:
setLogLevel
(
optarg
);
break
;
...
...
source/libs/planner/test/planTestUtil.cpp
浏览文件 @
da8db399
...
...
@@ -51,6 +51,7 @@ enum DumpModule {
DumpModule
g_dumpModule
=
DUMP_MODULE_NOTHING
;
int32_t
g_skipSql
=
0
;
int32_t
g_limitSql
=
0
;
int32_t
g_logLevel
=
131
;
void
setDumpModule
(
const
char
*
pModule
)
{
...
...
@@ -76,28 +77,33 @@ void setDumpModule(const char* pModule) {
}
void
setSkipSqlNum
(
const
char
*
pNum
)
{
g_skipSql
=
stoi
(
pNum
);
}
void
setLimitSqlNum
(
const
char
*
pNum
)
{
g_limitSql
=
stoi
(
pNum
);
}
void
setLogLevel
(
const
char
*
pLogLevel
)
{
g_logLevel
=
stoi
(
pLogLevel
);
}
int32_t
getLogLevel
()
{
return
g_logLevel
;
}
class
PlannerTestBaseImpl
{
public:
PlannerTestBaseImpl
()
:
sqlNo_
(
0
)
{}
PlannerTestBaseImpl
()
:
sqlNo_
(
0
)
,
sqlNum_
(
0
)
{}
void
useDb
(
const
string
&
user
,
const
string
&
db
)
{
caseEnv_
.
acctId_
=
0
;
caseEnv_
.
user_
=
user
;
caseEnv_
.
db_
=
db
;
caseEnv_
.
nsql_
=
g_skipSql
;
caseEnv_
.
numOfSkipSql_
=
g_skipSql
;
caseEnv_
.
numOfLimitSql_
=
g_limitSql
;
}
void
run
(
const
string
&
sql
)
{
++
sqlNo_
;
if
(
caseEnv_
.
nsql_
>
0
)
{
--
(
caseEnv_
.
nsql_
);
if
(
caseEnv_
.
numOfSkipSql_
>
0
)
{
--
(
caseEnv_
.
numOfSkipSql_
);
return
;
}
if
(
caseEnv_
.
numOfLimitSql_
>
0
&&
caseEnv_
.
numOfLimitSql_
==
sqlNum_
)
{
return
;
}
++
sqlNum_
;
reset
();
try
{
...
...
@@ -134,7 +140,7 @@ class PlannerTestBaseImpl {
}
void
prepare
(
const
string
&
sql
)
{
if
(
caseEnv_
.
n
s
ql_
>
0
)
{
if
(
caseEnv_
.
n
umOfSkipS
ql_
>
0
)
{
return
;
}
...
...
@@ -148,7 +154,7 @@ class PlannerTestBaseImpl {
}
void
bindParams
(
TAOS_MULTI_BIND
*
pParams
,
int32_t
colIdx
)
{
if
(
caseEnv_
.
n
s
ql_
>
0
)
{
if
(
caseEnv_
.
n
umOfSkipS
ql_
>
0
)
{
return
;
}
...
...
@@ -161,8 +167,8 @@ class PlannerTestBaseImpl {
}
void
exec
()
{
if
(
caseEnv_
.
n
s
ql_
>
0
)
{
--
(
caseEnv_
.
n
s
ql_
);
if
(
caseEnv_
.
n
umOfSkipS
ql_
>
0
)
{
--
(
caseEnv_
.
n
umOfSkipS
ql_
);
return
;
}
...
...
@@ -197,9 +203,10 @@ class PlannerTestBaseImpl {
int32_t
acctId_
;
string
user_
;
string
db_
;
int32_t
nsql_
;
int32_t
numOfSkipSql_
;
int32_t
numOfLimitSql_
;
caseEnv
()
:
n
s
ql_
(
0
)
{}
caseEnv
()
:
n
umOfSkipS
ql_
(
0
)
{}
};
struct
stmtEnv
{
...
...
@@ -401,6 +408,7 @@ class PlannerTestBaseImpl {
stmtEnv
stmtEnv_
;
stmtRes
res_
;
int32_t
sqlNo_
;
int32_t
sqlNum_
;
};
PlannerTestBase
::
PlannerTestBase
()
:
impl_
(
new
PlannerTestBaseImpl
())
{}
...
...
source/libs/planner/test/planTestUtil.h
浏览文件 @
da8db399
...
...
@@ -43,6 +43,7 @@ class PlannerTestBase : public testing::Test {
extern
void
setDumpModule
(
const
char
*
pModule
);
extern
void
setSkipSqlNum
(
const
char
*
pNum
);
extern
void
setLimitSqlNum
(
const
char
*
pNum
);
extern
void
setLogLevel
(
const
char
*
pLogLevel
);
extern
int32_t
getLogLevel
();
...
...
source/libs/sync/inc/syncRaftEntry.h
浏览文件 @
da8db399
...
...
@@ -56,6 +56,31 @@ void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj);
void
syncEntryLog
(
const
SSyncRaftEntry
*
pObj
);
void
syncEntryLog2
(
char
*
s
,
const
SSyncRaftEntry
*
pObj
);
//-----------------------------------
typedef
struct
SRaftEntryCache
{
SHashObj
*
pEntryHash
;
int32_t
maxCount
;
int32_t
currentCount
;
TdThreadMutex
mutex
;
SSyncNode
*
pSyncNode
;
}
SRaftEntryCache
;
SRaftEntryCache
*
raftCacheCreate
(
SSyncNode
*
pSyncNode
,
int32_t
maxCount
);
void
raftCacheDestroy
(
SRaftEntryCache
*
pCache
);
int32_t
raftCachePutEntry
(
struct
SRaftEntryCache
*
pCache
,
SSyncRaftEntry
*
pEntry
);
int32_t
raftCacheGetEntry
(
struct
SRaftEntryCache
*
pCache
,
SyncIndex
index
,
SSyncRaftEntry
**
ppEntry
);
int32_t
raftCacheGetEntryP
(
struct
SRaftEntryCache
*
pCache
,
SyncIndex
index
,
SSyncRaftEntry
**
ppEntry
);
int32_t
raftCacheDelEntry
(
struct
SRaftEntryCache
*
pCache
,
SyncIndex
index
);
int32_t
raftCacheGetAndDel
(
struct
SRaftEntryCache
*
pCache
,
SyncIndex
index
,
SSyncRaftEntry
**
ppEntry
);
int32_t
raftCacheClear
(
struct
SRaftEntryCache
*
pCache
);
cJSON
*
raftCache2Json
(
SRaftEntryCache
*
pObj
);
char
*
raftCache2Str
(
SRaftEntryCache
*
pObj
);
void
raftCachePrint
(
SRaftEntryCache
*
pObj
);
void
raftCachePrint2
(
char
*
s
,
SRaftEntryCache
*
pObj
);
void
raftCacheLog
(
SRaftEntryCache
*
pObj
);
void
raftCacheLog2
(
char
*
s
,
SRaftEntryCache
*
pObj
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
da8db399
...
...
@@ -35,12 +35,13 @@ extern "C" {
#define SYNC_SNAPSHOT_RETRY_MS 5000
//---------------------------------------------------
typedef
struct
SSyncSnapshotSender
{
bool
start
;
int32_t
seq
;
int32_t
ack
;
void
*
pReader
;
void
*
pCurrentBlock
;
void
*
pReader
;
void
*
pCurrentBlock
;
int32_t
blockLen
;
SSnapshot
snapshot
;
SSyncCfg
lastConfig
;
...
...
@@ -59,33 +60,36 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshot
void
snapshotSenderStop
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotSend
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotReSend
(
SSyncSnapshotSender
*
pSender
);
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2SimpleStr
(
SSyncSnapshotSender
*
pSender
,
char
*
event
);
typedef
struct
SSyncSnapshotReceiver
{
bool
start
;
int32_t
ack
;
void
*
pWriter
;
SyncTerm
term
;
SyncTerm
privateTerm
;
SSnapshot
snapshot
;
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2SimpleStr
(
SSyncSnapshotSender
*
pSender
,
char
*
event
);
SSyncNode
*
pSyncNode
;
//---------------------------------------------------
typedef
struct
SSyncSnapshotReceiver
{
bool
start
;
int32_t
ack
;
void
*
pWriter
;
SyncTerm
term
;
SyncTerm
privateTerm
;
SSnapshot
snapshot
;
SRaftId
fromId
;
SSyncNode
*
pSyncNode
;
}
SSyncSnapshotReceiver
;
SSyncSnapshotReceiver
*
snapshotReceiverCreate
(
SSyncNode
*
pSyncNode
,
SRaftId
fromId
);
void
snapshotReceiverDestroy
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
SyncSnapshotSend
*
pBeginMsg
);
bool
snapshotReceiverIsStart
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
,
bool
apply
);
void
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
SyncSnapshotSend
*
pBeginMsg
);
bool
snapshotReceiverIsStart
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
,
bool
apply
);
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
);
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
);
char
*
snapshotReceiver2SimpleStr
(
SSyncSnapshotReceiver
*
pReceiver
,
char
*
event
);
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
);
char
*
snapshotReceiver2SimpleStr
(
SSyncSnapshotReceiver
*
pReceiver
,
char
*
event
);
//---------------------------------------------------
// on message
int32_t
syncNodeOnSnapshotSendCb
(
SSyncNode
*
ths
,
SyncSnapshotSend
*
pMsg
);
int32_t
syncNodeOnSnapshotRspCb
(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
da8db399
...
...
@@ -1355,11 +1355,16 @@ void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) {
int32_t
userStrLen
=
strlen
(
str
);
SSnapshot
snapshot
=
{.
data
=
NULL
,
.
lastApplyIndex
=
-
1
,
.
lastApplyTerm
=
0
};
if
(
pSyncNode
->
pFsm
->
FpGetSnapshotInfo
!=
NULL
)
{
if
(
pSyncNode
->
pFsm
!=
NULL
&&
pSyncNode
->
pFsm
->
FpGetSnapshotInfo
!=
NULL
)
{
pSyncNode
->
pFsm
->
FpGetSnapshotInfo
(
pSyncNode
->
pFsm
,
&
snapshot
);
}
SyncIndex
logLastIndex
=
pSyncNode
->
pLogStore
->
syncLogLastIndex
(
pSyncNode
->
pLogStore
);
SyncIndex
logBeginIndex
=
pSyncNode
->
pLogStore
->
syncLogBeginIndex
(
pSyncNode
->
pLogStore
);
SyncIndex
logLastIndex
=
SYNC_INDEX_INVALID
;
SyncIndex
logBeginIndex
=
SYNC_INDEX_INVALID
;
if
(
pSyncNode
->
pLogStore
!=
NULL
)
{
logLastIndex
=
pSyncNode
->
pLogStore
->
syncLogLastIndex
(
pSyncNode
->
pLogStore
);
logBeginIndex
=
pSyncNode
->
pLogStore
->
syncLogBeginIndex
(
pSyncNode
->
pLogStore
);
}
char
*
pCfgStr
=
syncCfg2SimpleStr
(
&
(
pSyncNode
->
pRaftCfg
->
cfg
));
char
*
printStr
=
""
;
...
...
source/libs/sync/src/syncRaftEntry.c
浏览文件 @
da8db399
...
...
@@ -180,3 +180,247 @@ void syncEntryLog2(char* s, const SSyncRaftEntry* pObj) {
sTrace
(
"syncEntryLog2 | len:%zu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
//-----------------------------------
SRaftEntryCache
*
raftCacheCreate
(
SSyncNode
*
pSyncNode
,
int32_t
maxCount
)
{
SRaftEntryCache
*
pCache
=
taosMemoryMalloc
(
sizeof
(
SRaftEntryCache
));
if
(
pCache
==
NULL
)
{
sError
(
"vgId:%d raft cache create error"
,
pSyncNode
->
vgId
);
return
NULL
;
}
pCache
->
pEntryHash
=
taosHashInit
(
sizeof
(
SyncIndex
),
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
if
(
pCache
->
pEntryHash
==
NULL
)
{
sError
(
"vgId:%d raft cache create hash error"
,
pSyncNode
->
vgId
);
return
NULL
;
}
taosThreadMutexInit
(
&
(
pCache
->
mutex
),
NULL
);
pCache
->
maxCount
=
maxCount
;
pCache
->
currentCount
=
0
;
pCache
->
pSyncNode
=
pSyncNode
;
return
pCache
;
}
void
raftCacheDestroy
(
SRaftEntryCache
*
pCache
)
{
if
(
pCache
!=
NULL
)
{
taosThreadMutexLock
(
&
(
pCache
->
mutex
));
taosHashCleanup
(
pCache
->
pEntryHash
);
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
taosThreadMutexDestroy
(
&
(
pCache
->
mutex
));
taosMemoryFree
(
pCache
);
}
}
// success, return 1
// max count, return 0
// error, return -1
int32_t
raftCachePutEntry
(
struct
SRaftEntryCache
*
pCache
,
SSyncRaftEntry
*
pEntry
)
{
taosThreadMutexLock
(
&
(
pCache
->
mutex
));
if
(
pCache
->
currentCount
>=
pCache
->
maxCount
)
{
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
return
0
;
}
taosHashPut
(
pCache
->
pEntryHash
,
&
(
pEntry
->
index
),
sizeof
(
pEntry
->
index
),
pEntry
,
pEntry
->
bytes
);
++
(
pCache
->
currentCount
);
do
{
char
eventLog
[
128
];
snprintf
(
eventLog
,
sizeof
(
eventLog
),
"raft cache add, type:%s,%d, type2:%s,%d, index:%ld, bytes:%d"
,
TMSG_INFO
(
pEntry
->
msgType
),
pEntry
->
msgType
,
TMSG_INFO
(
pEntry
->
originalRpcType
),
pEntry
->
originalRpcType
,
pEntry
->
index
,
pEntry
->
bytes
);
syncNodeEventLog
(
pCache
->
pSyncNode
,
eventLog
);
}
while
(
0
);
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
return
1
;
}
// success, return 0
// error, return -1
// not exist, return -1, terrno = TSDB_CODE_WAL_LOG_NOT_EXIST
int32_t
raftCacheGetEntry
(
struct
SRaftEntryCache
*
pCache
,
SyncIndex
index
,
SSyncRaftEntry
**
ppEntry
)
{
if
(
ppEntry
==
NULL
)
{
return
-
1
;
}
*
ppEntry
=
NULL
;
taosThreadMutexLock
(
&
(
pCache
->
mutex
));
void
*
pTmp
=
taosHashGet
(
pCache
->
pEntryHash
,
&
index
,
sizeof
(
index
));
if
(
pTmp
!=
NULL
)
{
SSyncRaftEntry
*
pEntry
=
pTmp
;
*
ppEntry
=
taosMemoryMalloc
(
pEntry
->
bytes
);
memcpy
(
*
ppEntry
,
pTmp
,
pEntry
->
bytes
);
do
{
char
eventLog
[
128
];
snprintf
(
eventLog
,
sizeof
(
eventLog
),
"raft cache get, type:%s,%d, type2:%s,%d, index:%ld"
,
TMSG_INFO
((
*
ppEntry
)
->
msgType
),
(
*
ppEntry
)
->
msgType
,
TMSG_INFO
((
*
ppEntry
)
->
originalRpcType
),
(
*
ppEntry
)
->
originalRpcType
,
(
*
ppEntry
)
->
index
);
syncNodeEventLog
(
pCache
->
pSyncNode
,
eventLog
);
}
while
(
0
);
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
return
0
;
}
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
terrno
=
TSDB_CODE_WAL_LOG_NOT_EXIST
;
return
-
1
;
}
// success, return 0
// error, return -1
// not exist, return -1, terrno = TSDB_CODE_WAL_LOG_NOT_EXIST
int32_t
raftCacheGetEntryP
(
struct
SRaftEntryCache
*
pCache
,
SyncIndex
index
,
SSyncRaftEntry
**
ppEntry
)
{
if
(
ppEntry
==
NULL
)
{
return
-
1
;
}
*
ppEntry
=
NULL
;
taosThreadMutexLock
(
&
(
pCache
->
mutex
));
void
*
pTmp
=
taosHashGet
(
pCache
->
pEntryHash
,
&
index
,
sizeof
(
index
));
if
(
pTmp
!=
NULL
)
{
SSyncRaftEntry
*
pEntry
=
pTmp
;
*
ppEntry
=
pEntry
;
do
{
char
eventLog
[
128
];
snprintf
(
eventLog
,
sizeof
(
eventLog
),
"raft cache get, type:%s,%d, type2:%s,%d, index:%ld"
,
TMSG_INFO
((
*
ppEntry
)
->
msgType
),
(
*
ppEntry
)
->
msgType
,
TMSG_INFO
((
*
ppEntry
)
->
originalRpcType
),
(
*
ppEntry
)
->
originalRpcType
,
(
*
ppEntry
)
->
index
);
syncNodeEventLog
(
pCache
->
pSyncNode
,
eventLog
);
}
while
(
0
);
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
return
0
;
}
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
terrno
=
TSDB_CODE_WAL_LOG_NOT_EXIST
;
return
-
1
;
}
int32_t
raftCacheDelEntry
(
struct
SRaftEntryCache
*
pCache
,
SyncIndex
index
)
{
taosThreadMutexLock
(
&
(
pCache
->
mutex
));
taosHashRemove
(
pCache
->
pEntryHash
,
&
index
,
sizeof
(
index
));
--
(
pCache
->
currentCount
);
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
return
0
;
}
int32_t
raftCacheGetAndDel
(
struct
SRaftEntryCache
*
pCache
,
SyncIndex
index
,
SSyncRaftEntry
**
ppEntry
)
{
if
(
ppEntry
==
NULL
)
{
return
-
1
;
}
*
ppEntry
=
NULL
;
taosThreadMutexLock
(
&
(
pCache
->
mutex
));
void
*
pTmp
=
taosHashGet
(
pCache
->
pEntryHash
,
&
index
,
sizeof
(
index
));
if
(
pTmp
!=
NULL
)
{
SSyncRaftEntry
*
pEntry
=
pTmp
;
*
ppEntry
=
taosMemoryMalloc
(
pEntry
->
bytes
);
memcpy
(
*
ppEntry
,
pTmp
,
pEntry
->
bytes
);
do
{
char
eventLog
[
128
];
snprintf
(
eventLog
,
sizeof
(
eventLog
),
"raft cache get-and-del, type:%s,%d, type2:%s,%d, index:%ld"
,
TMSG_INFO
((
*
ppEntry
)
->
msgType
),
(
*
ppEntry
)
->
msgType
,
TMSG_INFO
((
*
ppEntry
)
->
originalRpcType
),
(
*
ppEntry
)
->
originalRpcType
,
(
*
ppEntry
)
->
index
);
syncNodeEventLog
(
pCache
->
pSyncNode
,
eventLog
);
}
while
(
0
);
taosHashRemove
(
pCache
->
pEntryHash
,
&
index
,
sizeof
(
index
));
--
(
pCache
->
currentCount
);
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
return
0
;
}
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
terrno
=
TSDB_CODE_WAL_LOG_NOT_EXIST
;
return
-
1
;
}
int32_t
raftCacheClear
(
struct
SRaftEntryCache
*
pCache
)
{
taosThreadMutexLock
(
&
(
pCache
->
mutex
));
taosHashClear
(
pCache
->
pEntryHash
);
pCache
->
currentCount
=
0
;
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
return
0
;
}
//-----------------------------------
cJSON
*
raftCache2Json
(
SRaftEntryCache
*
pCache
)
{
char
u64buf
[
128
]
=
{
0
};
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pCache
!=
NULL
)
{
taosThreadMutexLock
(
&
(
pCache
->
mutex
));
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pCache
->
pSyncNode
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"currentCount"
,
pCache
->
currentCount
);
cJSON_AddNumberToObject
(
pRoot
,
"maxCount"
,
pCache
->
maxCount
);
cJSON
*
pEntries
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"entries"
,
pEntries
);
SSyncRaftEntry
*
pIter
=
(
SSyncRaftEntry
*
)
taosHashIterate
(
pCache
->
pEntryHash
,
NULL
);
if
(
pIter
!=
NULL
)
{
SSyncRaftEntry
*
pEntry
=
(
SSyncRaftEntry
*
)
pIter
;
cJSON_AddItemToArray
(
pEntries
,
syncEntry2Json
(
pEntry
));
}
while
(
pIter
)
{
pIter
=
taosHashIterate
(
pCache
->
pEntryHash
,
pIter
);
if
(
pIter
!=
NULL
)
{
SSyncRaftEntry
*
pEntry
=
(
SSyncRaftEntry
*
)
pIter
;
cJSON_AddItemToArray
(
pEntries
,
syncEntry2Json
(
pEntry
));
}
}
taosThreadMutexUnlock
(
&
(
pCache
->
mutex
));
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SRaftEntryCache"
,
pRoot
);
return
pJson
;
}
char
*
raftCache2Str
(
SRaftEntryCache
*
pCache
)
{
cJSON
*
pJson
=
raftCache2Json
(
pCache
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
void
raftCachePrint
(
SRaftEntryCache
*
pCache
)
{
char
*
serialized
=
raftCache2Str
(
pCache
);
printf
(
"raftCachePrint | len:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
raftCachePrint2
(
char
*
s
,
SRaftEntryCache
*
pCache
)
{
char
*
serialized
=
raftCache2Str
(
pCache
);
printf
(
"raftCachePrint2 | len:%lu | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
raftCacheLog
(
SRaftEntryCache
*
pCache
)
{
char
*
serialized
=
raftCache2Str
(
pCache
);
sTrace
(
"raftCacheLog | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
raftCacheLog2
(
char
*
s
,
SRaftEntryCache
*
pCache
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
raftCache2Str
(
pCache
);
sTraceLong
(
"raftCacheLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
}
\ No newline at end of file
source/libs/sync/src/syncRespMgr.c
浏览文件 @
da8db399
...
...
@@ -32,11 +32,13 @@ SSyncRespMgr *syncRespMgrCreate(void *data, int64_t ttl) {
}
void
syncRespMgrDestroy
(
SSyncRespMgr
*
pObj
)
{
taosThreadMutexLock
(
&
(
pObj
->
mutex
));
taosHashCleanup
(
pObj
->
pRespHash
);
taosThreadMutexUnlock
(
&
(
pObj
->
mutex
));
taosThreadMutexDestroy
(
&
(
pObj
->
mutex
));
taosMemoryFree
(
pObj
);
if
(
pObj
!=
NULL
)
{
taosThreadMutexLock
(
&
(
pObj
->
mutex
));
taosHashCleanup
(
pObj
->
pRespHash
);
taosThreadMutexUnlock
(
&
(
pObj
->
mutex
));
taosThreadMutexDestroy
(
&
(
pObj
->
mutex
));
taosMemoryFree
(
pObj
);
}
}
int64_t
syncRespMgrAdd
(
SSyncRespMgr
*
pObj
,
SRespStub
*
pStub
)
{
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
da8db399
...
...
@@ -21,6 +21,7 @@
#include "syncUtil.h"
#include "wal.h"
//----------------------------------
static
void
snapshotReceiverDoStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
SyncSnapshotSend
*
pBeginMsg
);
...
...
@@ -49,7 +50,7 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
pSender
->
pSyncNode
->
pFsm
->
FpGetSnapshotInfo
(
pSender
->
pSyncNode
->
pFsm
,
&
(
pSender
->
snapshot
));
pSender
->
finish
=
false
;
}
else
{
sError
(
"
snapshotSenderCreate cannot create sender"
);
sError
(
"
vgId:%d cannot create snapshot sender"
,
pSyncNode
->
vgId
);
}
return
pSender
;
...
...
@@ -57,39 +58,59 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
void
snapshotSenderDestroy
(
SSyncSnapshotSender
*
pSender
)
{
if
(
pSender
!=
NULL
)
{
// free current block
if
(
pSender
->
pCurrentBlock
!=
NULL
)
{
taosMemoryFree
(
pSender
->
pCurrentBlock
);
pSender
->
pCurrentBlock
=
NULL
;
}
// close reader
if
(
pSender
->
pReader
!=
NULL
)
{
int32_t
ret
=
pSender
->
pSyncNode
->
pFsm
->
FpSnapshotStopRead
(
pSender
->
pSyncNode
->
pFsm
,
pSender
->
pReader
);
ASSERT
(
ret
==
0
);
pSender
->
pReader
=
NULL
;
}
// free sender
taosMemoryFree
(
pSender
);
}
}
bool
snapshotSenderIsStart
(
SSyncSnapshotSender
*
pSender
)
{
return
pSender
->
start
;
}
// begin send snapshot
(current term, seq begin)
// begin send snapshot
by snapshot, pReader
void
snapshotSenderStart
(
SSyncSnapshotSender
*
pSender
,
SSnapshot
snapshot
,
void
*
pReader
)
{
ASSERT
(
!
snapshotSenderIsStart
(
pSender
));
pSender
->
seq
=
SYNC_SNAPSHOT_SEQ_BEGIN
;
pSender
->
ack
=
SYNC_SNAPSHOT_SEQ_INVALID
;
// init snapshot and reader
ASSERT
(
pSender
->
pReader
==
NULL
);
pSender
->
pReader
=
pReader
;
pSender
->
snapshot
=
snapshot
;
// init current block
if
(
pSender
->
pCurrentBlock
!=
NULL
)
{
taosMemoryFree
(
pSender
->
pCurrentBlock
);
}
pSender
->
blockLen
=
0
;
// update term
pSender
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
++
(
pSender
->
privateTerm
);
// update state
pSender
->
finish
=
false
;
pSender
->
start
=
true
;
pSender
->
seq
=
SYNC_SNAPSHOT_SEQ_BEGIN
;
pSender
->
ack
=
SYNC_SNAPSHOT_SEQ_INVALID
;
// init last config
if
(
pSender
->
snapshot
.
lastConfigIndex
!=
SYNC_INDEX_INVALID
)
{
int32_t
code
=
0
;
SSyncRaftEntry
*
pEntry
=
NULL
;
bool
getLastConfig
=
false
;
code
=
pSender
->
pSyncNode
->
pLogStore
->
syncLogGetEntry
(
pSender
->
pSyncNode
->
pLogStore
,
pSender
->
snapshot
.
lastConfigIndex
,
&
pEntry
);
bool
getLastConfig
=
false
;
if
(
code
==
0
)
{
ASSERT
(
pEntry
!=
NULL
);
...
...
@@ -112,29 +133,29 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshot snapshot, void
}
}
// last config not found in wal, update to -1
if
(
!
getLastConfig
)
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"snapshot sender update lcindex from %ld to -1"
,
pSender
->
snapshot
.
lastConfigIndex
);
pSender
->
snapshot
.
lastConfigIndex
=
-
1
;
char
*
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
logBuf
);
syncNodeEventLog
(
pSender
->
pSyncNode
,
eventLog
);
taosMemoryFree
(
eventLog
);
SyncIndex
oldLastConfigIndex
=
pSender
->
snapshot
.
lastConfigIndex
;
SyncIndex
newLastConfigIndex
=
SYNC_INDEX_INVALID
;
pSender
->
snapshot
.
lastConfigIndex
=
SYNC_INDEX_INVALID
;
memset
(
&
(
pSender
->
lastConfig
),
0
,
sizeof
(
SSyncCfg
));
// event log
do
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"snapshot sender update lcindex from %ld to %ld"
,
oldLastConfigIndex
,
newLastConfigIndex
);
char
*
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
logBuf
);
syncNodeEventLog
(
pSender
->
pSyncNode
,
eventLog
);
taosMemoryFree
(
eventLog
);
}
while
(
0
);
}
}
else
{
// no last config
memset
(
&
(
pSender
->
lastConfig
),
0
,
sizeof
(
SSyncCfg
));
}
pSender
->
sendingMS
=
SYNC_SNAPSHOT_RETRY_MS
;
pSender
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
++
(
pSender
->
privateTerm
);
pSender
->
finish
=
false
;
pSender
->
start
=
true
;
// build begin msg
SyncSnapshotSend
*
pMsg
=
syncSnapshotSendBuild
(
0
,
pSender
->
pSyncNode
->
vgId
);
pMsg
->
srcId
=
pSender
->
pSyncNode
->
myRaftId
;
...
...
@@ -151,40 +172,39 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshot snapshot, void
SRpcMsg
rpcMsg
;
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
char
*
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
"snapshot sender send"
);
syncNodeEventLog
(
pSender
->
pSyncNode
,
eventLog
);
taosMemoryFree
(
eventLog
);
syncSnapshotSendDestroy
(
pMsg
);
// event log
do
{
char
*
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
"snapshot sender send"
);
syncNodeEventLog
(
pSender
->
pSyncNode
,
eventLog
);
taosMemoryFree
(
eventLog
);
}
while
(
0
);
}
void
snapshotSenderStop
(
SSyncSnapshotSender
*
pSender
)
{
// close reader
if
(
pSender
->
pReader
!=
NULL
)
{
int32_t
ret
=
pSender
->
pSyncNode
->
pFsm
->
FpSnapshotStopRead
(
pSender
->
pSyncNode
->
pFsm
,
pSender
->
pReader
);
ASSERT
(
ret
==
0
);
pSender
->
pReader
=
NULL
;
}
// free current block
if
(
pSender
->
pCurrentBlock
!=
NULL
)
{
taosMemoryFree
(
pSender
->
pCurrentBlock
);
pSender
->
pCurrentBlock
=
NULL
;
pSender
->
blockLen
=
0
;
}
// update flag
pSender
->
start
=
false
;
if
(
gRaftDetailLog
)
{
char
*
s
=
snapshotSender2Str
(
pSender
);
sInfo
(
"snapshotSenderStop %s"
,
s
);
taosMemoryFree
(
s
);
}
}
// when sender receive
r
ack, call this function to send msg from seq
// when sender receive ack, call this function to send msg from seq
// seq = ack + 1, already updated
int32_t
snapshotSend
(
SSyncSnapshotSender
*
pSender
)
{
// free memory last time (seq - 1)
// free memory last time (
current
seq - 1)
if
(
pSender
->
pCurrentBlock
!=
NULL
)
{
taosMemoryFree
(
pSender
->
pCurrentBlock
);
pSender
->
pCurrentBlock
=
NULL
;
...
...
@@ -198,7 +218,7 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
if
(
pSender
->
blockLen
>
0
)
{
// has read data
}
else
{
// read finish
// read finish
, update seq to end
pSender
->
seq
=
SYNC_SNAPSHOT_SEQ_END
;
}
...
...
@@ -219,25 +239,28 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
SRpcMsg
rpcMsg
;
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
syncSnapshotSendDestroy
(
pMsg
);
if
(
pSender
->
seq
==
SYNC_SNAPSHOT_SEQ_END
)
{
char
*
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
"snapshot sender finish"
);
syncNodeEventLog
(
pSender
->
pSyncNode
,
eventLog
);
taosMemoryFree
(
eventLog
);
}
else
{
char
*
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
"snapshot sender sending"
);
// event log
do
{
char
*
eventLog
=
NULL
;
if
(
pSender
->
seq
==
SYNC_SNAPSHOT_SEQ_END
)
{
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
"snapshot sender finish"
);
}
else
{
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
"snapshot sender sending"
);
}
syncNodeEventLog
(
pSender
->
pSyncNode
,
eventLog
);
taosMemoryFree
(
eventLog
);
}
}
while
(
0
);
syncSnapshotSendDestroy
(
pMsg
);
return
0
;
}
// send snapshot data from cache
int32_t
snapshotReSend
(
SSyncSnapshotSender
*
pSender
)
{
if
(
pSender
->
pCurrentBlock
!=
NULL
)
{
// send current block data
if
(
pSender
->
pCurrentBlock
!=
NULL
&&
pSender
->
blockLen
>
0
)
{
// build msg
SyncSnapshotSend
*
pMsg
=
syncSnapshotSendBuild
(
pSender
->
blockLen
,
pSender
->
pSyncNode
->
vgId
);
pMsg
->
srcId
=
pSender
->
pSyncNode
->
myRaftId
;
pMsg
->
destId
=
(
pSender
->
pSyncNode
->
replicasId
)[
pSender
->
replicaIndex
];
...
...
@@ -249,16 +272,20 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
pMsg
->
seq
=
pSender
->
seq
;
memcpy
(
pMsg
->
data
,
pSender
->
pCurrentBlock
,
pSender
->
blockLen
);
// send msg
SRpcMsg
rpcMsg
;
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
char
*
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
"snapshot sender resend"
);
syncNodeEventLog
(
pSender
->
pSyncNode
,
eventLog
);
taosMemoryFree
(
eventLog
);
syncSnapshotSendDestroy
(
pMsg
);
// event log
do
{
char
*
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
"snapshot sender resend"
);
syncNodeEventLog
(
pSender
->
pSyncNode
,
eventLog
);
taosMemoryFree
(
eventLog
);
}
while
(
0
);
}
return
0
;
}
...
...
@@ -294,7 +321,6 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSender
->
snapshot
.
lastApplyTerm
);
cJSON_AddStringToObject
(
pSnapshot
,
"lastApplyTerm"
,
u64buf
);
cJSON_AddItemToObject
(
pRoot
,
"snapshot"
,
pSnapshot
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSender
->
sendingMS
);
cJSON_AddStringToObject
(
pRoot
,
"sendingMS"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSender
->
pSyncNode
);
...
...
@@ -314,17 +340,17 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
)
{
cJSON
*
pJson
=
snapshotSender2Json
(
pSender
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
char
*
snapshotSender2SimpleStr
(
SSyncSnapshotSender
*
pSender
,
char
*
event
)
{
int32_t
len
=
256
;
char
*
s
=
taosMemoryMalloc
(
len
);
char
*
s
=
taosMemoryMalloc
(
len
);
SRaftId
destId
=
pSender
->
pSyncNode
->
replicasId
[
pSender
->
replicaIndex
];
char
host
[
128
];
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
...
...
@@ -355,12 +381,12 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId from
pReceiver
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
pReceiver
->
privateTerm
=
0
;
pReceiver
->
snapshot
.
data
=
NULL
;
pReceiver
->
snapshot
.
lastApplyIndex
=
-
1
;
pReceiver
->
snapshot
.
lastApplyIndex
=
SYNC_INDEX_INVALID
;
pReceiver
->
snapshot
.
lastApplyTerm
=
0
;
pReceiver
->
snapshot
.
lastConfigIndex
=
-
1
;
pReceiver
->
snapshot
.
lastConfigIndex
=
SYNC_INDEX_INVALID
;
}
else
{
s
Info
(
"snapshotReceiverCreate cannot create receiver"
);
s
Error
(
"vgId:%d cannot create snapshot receiver"
,
pSyncNode
->
vgId
);
}
return
pReceiver
;
...
...
@@ -368,29 +394,55 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId from
void
snapshotReceiverDestroy
(
SSyncSnapshotReceiver
*
pReceiver
)
{
if
(
pReceiver
!=
NULL
)
{
// close writer
if
(
pReceiver
->
pWriter
!=
NULL
)
{
int32_t
ret
=
pReceiver
->
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pReceiver
->
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
false
);
ASSERT
(
ret
==
0
);
pReceiver
->
pWriter
=
NULL
;
}
// free receiver
taosMemoryFree
(
pReceiver
);
}
}
bool
snapshotReceiverIsStart
(
SSyncSnapshotReceiver
*
pReceiver
)
{
return
pReceiver
->
start
;
}
// begin receive snapshot msg (current term, seq begin)
// static do start
// receive first snapshot data
// privateTerm, pBeginMsg
static
void
snapshotReceiverDoStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
SyncSnapshotSend
*
pBeginMsg
)
{
// update state
pReceiver
->
term
=
pReceiver
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pReceiver
->
privateTerm
=
privateTerm
;
pReceiver
->
ack
=
SYNC_SNAPSHOT_SEQ_BEGIN
;
pReceiver
->
fromId
=
pBeginMsg
->
srcId
;
// update snapshot
pReceiver
->
snapshot
.
lastApplyIndex
=
pBeginMsg
->
lastIndex
;
pReceiver
->
snapshot
.
lastApplyTerm
=
pBeginMsg
->
lastTerm
;
pReceiver
->
snapshot
.
lastConfigIndex
=
pBeginMsg
->
lastConfigIndex
;
// write data
ASSERT
(
pReceiver
->
pWriter
==
NULL
);
int32_t
ret
=
pReceiver
->
pSyncNode
->
pFsm
->
FpSnapshotStartWrite
(
pReceiver
->
pSyncNode
->
pFsm
,
&
(
pReceiver
->
pWriter
));
ASSERT
(
ret
==
0
);
}
static
void
snapshotReceiverForceStop
(
SSyncSnapshotReceiver
*
pReceiver
)
{
// force close, abandon incomplete data
if
(
pReceiver
->
pWriter
!=
NULL
)
{
int32_t
ret
=
pReceiver
->
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pReceiver
->
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
false
);
ASSERT
(
ret
==
0
);
pReceiver
->
pWriter
=
NULL
;
}
pReceiver
->
start
=
false
;
}
// if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver
// if already start, force close, start again
void
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
SyncSnapshotSend
*
pBeginMsg
)
{
...
...
@@ -413,12 +465,6 @@ void snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm privateTer
snapshotReceiverDoStart
(
pReceiver
,
privateTerm
,
pBeginMsg
);
pReceiver
->
start
=
true
;
}
if
(
gRaftDetailLog
)
{
char
*
s
=
snapshotReceiver2Str
(
pReceiver
);
sInfo
(
"snapshotReceiverStart %s"
,
s
);
taosMemoryFree
(
s
);
}
}
void
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
,
bool
apply
)
{
...
...
@@ -434,12 +480,6 @@ void snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver, bool apply) {
if
(
apply
)
{
// ++(pReceiver->privateTerm);
}
if
(
gRaftDetailLog
)
{
char
*
s
=
snapshotReceiver2Str
(
pReceiver
);
sInfo
(
"snapshotReceiverStop %s"
,
s
);
taosMemoryFree
(
s
);
}
}
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
)
{
...
...
@@ -461,7 +501,7 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
cJSON_AddStringToObject
(
pFromId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pReceiver
->
fromId
.
addr
;
cJSON
*
pTmp
=
pFromId
;
cJSON
*
pTmp
=
pFromId
;
char
host
[
128
]
=
{
0
};
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
...
...
@@ -494,14 +534,14 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) {
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
)
{
cJSON
*
pJson
=
snapshotReceiver2Json
(
pReceiver
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
char
*
snapshotReceiver2SimpleStr
(
SSyncSnapshotReceiver
*
pReceiver
,
char
*
event
)
{
int32_t
len
=
256
;
char
*
s
=
taosMemoryMalloc
(
len
);
char
*
s
=
taosMemoryMalloc
(
len
);
SRaftId
fromId
=
pReceiver
->
fromId
;
char
host
[
128
];
...
...
source/libs/sync/test/CMakeLists.txt
浏览文件 @
da8db399
...
...
@@ -17,6 +17,7 @@ add_executable(syncVotesRespondTest "")
add_executable
(
syncIndexMgrTest
""
)
add_executable
(
syncLogStoreTest
""
)
add_executable
(
syncEntryTest
""
)
add_executable
(
syncEntryCacheTest
""
)
add_executable
(
syncRequestVoteTest
""
)
add_executable
(
syncRequestVoteReplyTest
""
)
add_executable
(
syncAppendEntriesTest
""
)
...
...
@@ -129,6 +130,10 @@ target_sources(syncEntryTest
PRIVATE
"syncEntryTest.cpp"
)
target_sources
(
syncEntryCacheTest
PRIVATE
"syncEntryCacheTest.cpp"
)
target_sources
(
syncRequestVoteTest
PRIVATE
"syncRequestVoteTest.cpp"
...
...
@@ -362,6 +367,11 @@ target_include_directories(syncEntryTest
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncEntryCacheTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncRequestVoteTest
PUBLIC
"
${
TD_SOURCE_DIR
}
/include/libs/sync"
...
...
@@ -610,6 +620,10 @@ target_link_libraries(syncEntryTest
sync
gtest_main
)
target_link_libraries
(
syncEntryCacheTest
sync
gtest_main
)
target_link_libraries
(
syncRequestVoteTest
sync
gtest_main
...
...
source/libs/sync/test/syncEntryCacheTest.cpp
0 → 100644
浏览文件 @
da8db399
#include <stdio.h>
#include "syncEnv.h"
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
sDebug
(
"--- sync log test: debug"
);
sInfo
(
"--- sync log test: info"
);
sWarn
(
"--- sync log test: warn"
);
sError
(
"--- sync log test: error"
);
sFatal
(
"--- sync log test: fatal"
);
}
SSyncRaftEntry
*
createEntry
(
int
i
)
{
int32_t
dataLen
=
20
;
SSyncRaftEntry
*
pEntry
=
syncEntryBuild
(
dataLen
);
assert
(
pEntry
!=
NULL
);
pEntry
->
msgType
=
88
;
pEntry
->
originalRpcType
=
99
;
pEntry
->
seqNum
=
3
;
pEntry
->
isWeak
=
true
;
pEntry
->
term
=
100
+
i
;
pEntry
->
index
=
i
;
snprintf
(
pEntry
->
data
,
dataLen
,
"value%d"
,
i
);
return
pEntry
;
}
SSyncNode
*
createFakeNode
()
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosMemoryMalloc
(
sizeof
(
SSyncNode
));
ASSERT
(
pSyncNode
!=
NULL
);
memset
(
pSyncNode
,
0
,
sizeof
(
SSyncNode
));
return
pSyncNode
;
}
SRaftEntryCache
*
createCache
(
int
maxCount
)
{
SSyncNode
*
pSyncNode
=
createFakeNode
();
ASSERT
(
pSyncNode
!=
NULL
);
SRaftEntryCache
*
pCache
=
raftCacheCreate
(
pSyncNode
,
maxCount
);
ASSERT
(
pCache
!=
NULL
);
return
pCache
;
}
void
test1
()
{
int32_t
code
=
0
;
SRaftEntryCache
*
pCache
=
createCache
(
5
);
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
SSyncRaftEntry
*
pEntry
=
createEntry
(
i
);
code
=
raftCachePutEntry
(
pCache
,
pEntry
);
ASSERT
(
code
==
1
);
syncEntryDestory
(
pEntry
);
}
raftCacheLog2
((
char
*
)
"==test1 write 5 entries=="
,
pCache
);
SyncIndex
index
;
index
=
1
;
code
=
raftCacheDelEntry
(
pCache
,
index
);
ASSERT
(
code
==
0
);
index
=
3
;
code
=
raftCacheDelEntry
(
pCache
,
index
);
ASSERT
(
code
==
0
);
raftCacheLog2
((
char
*
)
"==test1 delete 1,3=="
,
pCache
);
code
=
raftCacheClear
(
pCache
);
ASSERT
(
code
==
0
);
raftCacheLog2
((
char
*
)
"==clear all=="
,
pCache
);
}
void
test2
()
{
int32_t
code
=
0
;
SRaftEntryCache
*
pCache
=
createCache
(
5
);
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
SSyncRaftEntry
*
pEntry
=
createEntry
(
i
);
code
=
raftCachePutEntry
(
pCache
,
pEntry
);
ASSERT
(
code
==
1
);
syncEntryDestory
(
pEntry
);
}
raftCacheLog2
((
char
*
)
"==test2 write 5 entries=="
,
pCache
);
SyncIndex
index
;
index
=
1
;
SSyncRaftEntry
*
pEntry
;
code
=
raftCacheGetEntry
(
pCache
,
index
,
&
pEntry
);
ASSERT
(
code
==
0
);
syncEntryDestory
(
pEntry
);
syncEntryLog2
((
char
*
)
"==test2 get entry 1=="
,
pEntry
);
index
=
2
;
code
=
raftCacheGetEntryP
(
pCache
,
index
,
&
pEntry
);
ASSERT
(
code
==
0
);
syncEntryLog2
((
char
*
)
"==test2 get entry pointer 2=="
,
pEntry
);
// not found
index
=
8
;
code
=
raftCacheGetEntry
(
pCache
,
index
,
&
pEntry
);
ASSERT
(
code
==
-
1
&&
terrno
==
TSDB_CODE_WAL_LOG_NOT_EXIST
);
sTrace
(
"==test2 get entry 8 not found=="
);
// not found
index
=
9
;
code
=
raftCacheGetEntryP
(
pCache
,
index
,
&
pEntry
);
ASSERT
(
code
==
-
1
&&
terrno
==
TSDB_CODE_WAL_LOG_NOT_EXIST
);
sTrace
(
"==test2 get entry pointer 9 not found=="
);
}
void
test3
()
{
int32_t
code
=
0
;
SRaftEntryCache
*
pCache
=
createCache
(
5
);
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
SSyncRaftEntry
*
pEntry
=
createEntry
(
i
);
code
=
raftCachePutEntry
(
pCache
,
pEntry
);
ASSERT
(
code
==
1
);
syncEntryDestory
(
pEntry
);
}
for
(
int
i
=
6
;
i
<
10
;
++
i
)
{
SSyncRaftEntry
*
pEntry
=
createEntry
(
i
);
code
=
raftCachePutEntry
(
pCache
,
pEntry
);
ASSERT
(
code
==
0
);
syncEntryDestory
(
pEntry
);
}
raftCacheLog2
((
char
*
)
"==test3 write 10 entries, max count is 5=="
,
pCache
);
}
void
test4
()
{
int32_t
code
=
0
;
SRaftEntryCache
*
pCache
=
createCache
(
5
);
for
(
int
i
=
0
;
i
<
5
;
++
i
)
{
SSyncRaftEntry
*
pEntry
=
createEntry
(
i
);
code
=
raftCachePutEntry
(
pCache
,
pEntry
);
ASSERT
(
code
==
1
);
syncEntryDestory
(
pEntry
);
}
raftCacheLog2
((
char
*
)
"==test4 write 5 entries=="
,
pCache
);
SyncIndex
index
;
index
=
3
;
SSyncRaftEntry
*
pEntry
;
code
=
raftCacheGetAndDel
(
pCache
,
index
,
&
pEntry
);
ASSERT
(
code
==
0
);
syncEntryLog2
((
char
*
)
"==test4 get-and-del entry 3=="
,
pEntry
);
raftCacheLog2
((
char
*
)
"==test4 after get-and-del entry 3=="
,
pCache
);
}
int
main
(
int
argc
,
char
**
argv
)
{
gRaftDetailLog
=
true
;
tsAsyncLog
=
0
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
+
DEBUG_DEBUG
;
test1
();
test2
();
test3
();
test4
();
return
0
;
}
tests/parallel_test/container_build.sh
浏览文件 @
da8db399
...
...
@@ -52,7 +52,7 @@ fi
docker run
\
-v
$REP_MOUNT_PARAM
\
--rm
--ulimit
core
=
-1
taos_test:v1.0 sh
-c
"cd
$REP_DIR
;rm -rf debug;mkdir -p debug;cd debug;cmake .. -DBUILD_TOOLS=true;make -j
$THREAD_COUNT
"
--rm
--ulimit
core
=
-1
taos_test:v1.0 sh
-c
"cd
$REP_DIR
;rm -rf debug;mkdir -p debug;cd debug;cmake .. -DBUILD_
HTTP=false -DBUILD_
TOOLS=true;make -j
$THREAD_COUNT
"
ret
=
$?
exit
$ret
...
...
tests/pytest/util/constant.py
浏览文件 @
da8db399
# -*- coding: utf-8 -*-
# basic type
TAOS_DATA_TYPE
=
[
"INT"
,
"BIGINT"
,
"SMALLINT"
,
"TINYINT"
,
"INT UNSIGNED"
,
"BIGINT UNSIGNED"
,
"SMALLINT UNSIGNED"
,
"TINYINT UNSIGNED"
,
"FLOAT"
,
"DOUBLE"
,
"BOOL"
,
"BINARY"
,
"NCHAR"
,
"VARCHAR"
,
"TIMESTAMP"
,
# "MEDIUMBLOB", "BLOB", # add in 3.x
# "DECIMAL", "NUMERIC", # add in 3.x
"JSON"
,
# only for tag
]
TAOS_NUM_TYPE
=
[
"INT"
,
"BIGINT"
,
"SMALLINT"
,
"TINYINT"
,
"INT UNSIGNED"
,
"BIGINT UNSIGNED"
,
"SMALLINT UNSIGNED"
,
"TINYINT UNSIGNED"
,
"FLOAT"
,
"DOUBLE"
,
# "DECIMAL", "NUMERIC", # add in 3.x
]
TAOS_CHAR_TYPE
=
[
"BINARY"
,
"NCHAR"
,
"VARCHAR"
,
]
TAOS_BOOL_TYPE
=
[
"BOOL"
,]
TAOS_TS_TYPE
=
[
"TIMESTAMP"
,]
TAOS_BIN_TYPE
=
[
"MEDIUMBLOB"
,
"BLOB"
,
# add in 3.x
]
TAOS_TIME_INIT
=
[
"b"
,
"u"
,
"a"
,
"s"
,
"m"
,
"h"
,
"d"
,
"w"
,
"n"
,
"y"
]
TAOS_PRECISION
=
[
"ms"
,
"us"
,
"ns"
]
PRECISION_DEFAULT
=
"ms"
PRECISION
=
PRECISION_DEFAULT
TAOS_KEYWORDS
=
[
"ABORT"
,
"CREATE"
,
"IGNORE"
,
"NULL"
,
"STAR"
,
"ACCOUNT"
,
"CTIME"
,
"IMMEDIATE"
,
"OF"
,
"STATE"
,
"ACCOUNTS"
,
"DATABASE"
,
"IMPORT"
,
"OFFSET"
,
"STATEMENT"
,
"ADD"
,
"DATABASES"
,
"IN"
,
"OR"
,
"STATE_WINDOW"
,
"AFTER"
,
"DAYS"
,
"INITIALLY"
,
"ORDER"
,
"STORAGE"
,
"ALL"
,
"DBS"
,
"INSERT"
,
"PARTITIONS"
,
"STREAM"
,
"ALTER"
,
"DEFERRED"
,
"INSTEAD"
,
"PASS"
,
"STREAMS"
,
"AND"
,
"DELIMITERS"
,
"INT"
,
"PLUS"
,
"STRING"
,
"AS"
,
"DESC"
,
"INTEGER"
,
"PPS"
,
"SYNCDB"
,
"ASC"
,
"DESCRIBE"
,
"INTERVAL"
,
"PRECISION"
,
"TABLE"
,
"ATTACH"
,
"DETACH"
,
"INTO"
,
"PREV"
,
"TABLES"
,
"BEFORE"
,
"DISTINCT"
,
"IS"
,
"PRIVILEGE"
,
"TAG"
,
"BEGIN"
,
"DIVIDE"
,
"ISNULL"
,
"QTIME"
,
"TAGS"
,
"BETWEEN"
,
"DNODE"
,
"JOIN"
,
"QUERIES"
,
"TBNAME"
,
"BIGINT"
,
"DNODES"
,
"KEEP"
,
"QUERY"
,
"TIMES"
,
"BINARY"
,
"DOT"
,
"KEY"
,
"QUORUM"
,
"TIMESTAMP"
,
"BITAND"
,
"DOUBLE"
,
"KILL"
,
"RAISE"
,
"TINYINT"
,
"BITNOT"
,
"DROP"
,
"LE"
,
"REM"
,
"TOPIC"
,
"BITOR"
,
"EACH"
,
"LIKE"
,
"REPLACE"
,
"TOPICS"
,
"BLOCKS"
,
"END"
,
"LIMIT"
,
"REPLICA"
,
"TRIGGER"
,
"BOOL"
,
"EQ"
,
"LINEAR"
,
"RESET"
,
"TSERIES"
,
"BY"
,
"EXISTS"
,
"LOCAL"
,
"RESTRICT"
,
"UMINUS"
,
"CACHE"
,
"EXPLAIN"
,
"LP"
,
"ROW"
,
"UNION"
,
"CACHELAST"
,
"FAIL"
,
"LSHIFT"
,
"RP"
,
"UNSIGNED"
,
"CASCADE"
,
"FILE"
,
"LT"
,
"RSHIFT"
,
"UPDATE"
,
"CHANGE"
,
"FILL"
,
"MATCH"
,
"SCORES"
,
"UPLUS"
,
"CLUSTER"
,
"FLOAT"
,
"MAXROWS"
,
"SELECT"
,
"USE"
,
"COLON"
,
"FOR"
,
"MINROWS"
,
"SEMI"
,
"USER"
,
"COLUMN"
,
"FROM"
,
"MINUS"
,
"SESSION"
,
"USERS"
,
"COMMA"
,
"FSYNC"
,
"MNODES"
,
"SET"
,
"USING"
,
"COMP"
,
"GE"
,
"MODIFY"
,
"SHOW"
,
"VALUES"
,
"COMPACT"
,
"GLOB"
,
"MODULES"
,
"SLASH"
,
"VARIABLE"
,
"CONCAT"
,
"GRANTS"
,
"NCHAR"
,
"SLIDING"
,
"VARIABLES"
,
"CONFLICT"
,
"GROUP"
,
"NE"
,
"SLIMIT"
,
"VGROUPS"
,
"CONNECTION"
,
"GT"
,
"NONE"
,
"SMALLINT"
,
"VIEW"
,
"CONNECTIONS"
,
"HAVING"
,
"NOT"
,
"SOFFSET"
,
"VNODES"
,
"CONNS"
,
"ID"
,
"NOTNULL"
,
"STABLE"
,
"WAL"
,
"COPY"
,
"IF"
,
"NOW"
,
"STABLES"
,
"WHERE"
,
]
# basic data type boundary
TINYINT_MAX
=
127
TINYINT_MIN
=
-
128
...
...
@@ -11,7 +82,7 @@ SMALLINT_MAX = 32767
SMALLINT_MIN
=
-
32768
SMALLINT_UN_MAX
=
65535
MALLINT_UN_MIN
=
0
SMALLINT_UN_MIN
=
0
INT_MAX
=
2147483647
INT_MIN
=
-
2147483648
...
...
@@ -33,8 +104,8 @@ DOUBLE_MIN = -1.7E+308
# schema boundary
BINARY_LENGTH_MAX
=
16374
NCAHR_LENGTH_MAX
_
=
4093
DBNAME_LENGTH_MAX
_
=
64
NCAHR_LENGTH_MAX
=
4093
DBNAME_LENGTH_MAX
=
64
STBNAME_LENGTH_MAX
=
192
STBNAME_LENGTH_MIN
=
1
...
...
@@ -66,4 +137,32 @@ MNODE_SHM_SIZE_DEFAULT = 6292480
VNODE_SHM_SIZE_MAX
=
2147483647
VNODE_SHM_SIZE_MIN
=
6292480
VNODE_SHM_SIZE_DEFAULT
=
31458304
\ No newline at end of file
VNODE_SHM_SIZE_DEFAULT
=
31458304
# time_init
TIME_MS
=
1
TIME_US
=
TIME_MS
/
1000
TIME_NS
=
TIME_US
/
1000
TIME_S
=
1000
*
TIME_MS
TIME_M
=
60
*
TIME_S
TIME_H
=
60
*
TIME_M
TIME_D
=
24
*
TIME_H
TIME_W
=
7
*
TIME_D
TIME_N
=
30
*
TIME_D
TIME_Y
=
365
*
TIME_D
# session parameters
INTERVAL_MIN
=
1
*
TIME_MS
if
PRECISION
==
PRECISION_DEFAULT
else
1
*
TIME_US
# streams and related agg-function
SMA_INDEX_FUNCTIONS
=
[
"MIN"
,
"MAX"
]
ROLLUP_FUNCTIONS
=
[
"AVG"
,
"SUM"
,
"MIN"
,
"MAX"
,
"LAST"
,
"FIRST"
]
SMA_WATMARK_MAXDELAY_INIT
=
[
'a'
,
"s"
,
"m"
]
WATERMARK_MAX
=
900000
WATERMARK_MIN
=
0
MAX_DELAY_MAX
=
900000
MAX_DELAY_MIN
=
1
\ No newline at end of file
tests/pytest/util/sql.py
浏览文件 @
da8db399
...
...
@@ -21,6 +21,7 @@ import psutil
import
shutil
import
pandas
as
pd
from
util.log
import
*
from
util.constant
import
*
def
_parse_datetime
(
timestr
):
try
:
...
...
@@ -117,8 +118,7 @@ class TDSql:
col_name_list
=
[]
col_type_list
=
[]
self
.
cursor
.
execute
(
sql
)
self
.
queryCols
=
self
.
cursor
.
description
for
query_col
in
self
.
queryCols
:
for
query_col
in
self
.
cursor
.
description
:
col_name_list
.
append
(
query_col
[
0
])
col_type_list
.
append
(
query_col
[
1
])
except
Exception
as
e
:
...
...
@@ -301,6 +301,41 @@ class TDSql:
args
=
(
caller
.
filename
,
caller
.
lineno
,
self
.
sql
,
elm
,
expect_elm
)
tdLog
.
exit
(
"%s(%d) failed: sql:%s, elm:%s == expect_elm:%s"
%
args
)
def
get_times
(
self
,
time_str
,
precision
=
"ms"
):
caller
=
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
])
if
time_str
[
-
1
]
not
in
TAOS_TIME_INIT
:
tdLog
.
exit
(
f
"
{
caller
.
filename
}
(
{
caller
.
lineno
}
) failed:
{
time_str
}
not a standard taos time init"
)
if
precision
not
in
TAOS_PRECISION
:
tdLog
.
exit
(
f
"
{
caller
.
filename
}
(
{
caller
.
lineno
}
) failed:
{
precision
}
not a standard taos time precision"
)
if
time_str
[
-
1
]
==
TAOS_TIME_INIT
[
0
]:
times
=
int
(
time_str
[:
-
1
])
*
TIME_NS
if
time_str
[
-
1
]
==
TAOS_TIME_INIT
[
1
]:
times
=
int
(
time_str
[:
-
1
])
*
TIME_US
if
time_str
[
-
1
]
==
TAOS_TIME_INIT
[
2
]:
times
=
int
(
time_str
[:
-
1
])
*
TIME_MS
if
time_str
[
-
1
]
==
TAOS_TIME_INIT
[
3
]:
times
=
int
(
time_str
[:
-
1
])
*
TIME_S
if
time_str
[
-
1
]
==
TAOS_TIME_INIT
[
4
]:
times
=
int
(
time_str
[:
-
1
])
*
TIME_M
if
time_str
[
-
1
]
==
TAOS_TIME_INIT
[
5
]:
times
=
int
(
time_str
[:
-
1
])
*
TIME_H
if
time_str
[
-
1
]
==
TAOS_TIME_INIT
[
6
]:
times
=
int
(
time_str
[:
-
1
])
*
TIME_D
if
time_str
[
-
1
]
==
TAOS_TIME_INIT
[
7
]:
times
=
int
(
time_str
[:
-
1
])
*
TIME_W
if
time_str
[
-
1
]
==
TAOS_TIME_INIT
[
8
]:
times
=
int
(
time_str
[:
-
1
])
*
TIME_N
if
time_str
[
-
1
]
==
TAOS_TIME_INIT
[
9
]:
times
=
int
(
time_str
[:
-
1
])
*
TIME_Y
if
precision
==
"ms"
:
return
int
(
times
)
elif
precision
==
"us"
:
return
int
(
times
*
1000
)
elif
precision
==
"ns"
:
return
int
(
times
*
1000
*
1000
)
def
taosdStatus
(
self
,
state
):
tdLog
.
sleep
(
5
)
pstate
=
0
...
...
tests/script/jenkins/basic.txt
浏览文件 @
da8db399
...
...
@@ -22,15 +22,19 @@
# ---- dnode
./test.sh -f tsim/dnode/balance_replica1.sim
#./test.sh -f tsim/dnode/balance_replica3.sim
./test.sh -f tsim/dnode/create_dnode.sim
./test.sh -f tsim/dnode/drop_dnode_has_mnode.sim
./test.sh -f tsim/dnode/drop_dnode_has_qnode_snode.sim
./test.sh -f tsim/dnode/drop_dnode_has_vnode_replica1.sim
#./test.sh -f tsim/dnode/drop_dnode_has_vnode_replica3.sim
#./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica1.sim
#./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim
#./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim
./test.sh -f tsim/dnode/drop_dnode_has_vnode_replica3.sim
./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica1.sim
./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim
./test.sh -f tsim/dnode/redistribute_vgroup_replica1.sim
./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim
./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim
./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v2.sim
./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v3.sim
# ---- insert
./test.sh -f tsim/insert/basic0.sim
...
...
tests/script/test-all.bat
浏览文件 @
da8db399
...
...
@@ -11,14 +11,17 @@ if not "%2" == "" (
)
for
/F
"usebackq tokens=*"
%%i
in
(
!caseFile!
)
do
(
set
line
=
%%i
if
"
!
line:~,9
!
"
==
"./test.sh"
(
set
/a
a
+=
1
echo
!a!
Processing
%%i
call
:GetTimeSeconds
!time!
set
time1
=
!_timeTemp!
echo
Start
at
!time!
call
!
line
:./test.sh
=
wtest
.bat
!
>
result_
!a!
.txt
2
>
error_
!a!
.txt
if
errorlevel
1
(
call
:colorEcho
0
c
"failed"
&
echo
.
&&
set
/a
exitNum
=
8
&&
echo
%%i
>>
failed
.txt
)
else
(
call
:colorEcho
0
a
"Success"
&
echo
.
)
call
:CheckSkipCase
%%i
if
!skipCase!
==
false
(
if
"
!
line:~,9
!
"
==
"./test.sh"
(
set
/a
a
+=
1
echo
!a!
Processing
%%i
call
:GetTimeSeconds
!time!
set
time1
=
!_timeTemp!
echo
Start
at
!time!
call
!
line
:./test.sh
=
wtest
.bat
!
>
result_
!a!
.txt
2
>
error_
!a!
.txt
if
errorlevel
1
(
call
:colorEcho
0
c
"failed"
&
echo
.
&&
set
/a
exitNum
=
8
&&
echo
%%i
>>
failed
.txt
)
else
(
call
:colorEcho
0
a
"Success"
&
echo
.
)
)
)
)
exit
!exitNum!
...
...
@@ -56,3 +59,10 @@ for %%a in (%tt%) do (
)
set
/a
_timeTemp
=(
%hh%
*
60
+
%mm%
)*
60
+
%ss%
goto
:eof
:CheckSkipCase
set
skipCase
=
false
if
"
%
*"
==
"./test.sh -f tsim/query/scalarFunction.sim"
(
set
skipCase
=
true
)
if
"
%
*"
==
"./test.sh -f tsim/stream/distributeInterval0.sim"
(
set
skipCase
=
true
)
if
"
%
*"
==
"./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim"
(
set
skipCase
=
true
)
:goto
eof
\ No newline at end of file
tests/script/tsim/dnode/balance_replica1.sim
浏览文件 @
da8db399
...
...
@@ -117,7 +117,6 @@ if $rows != 6 then
return -1
endi
return
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
tests/script/tsim/dnode/balance_replica3.sim
0 → 100644
浏览文件 @
da8db399
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4
system sh/deploy.sh -n dnode5 -i 5
system sh/cfg.sh -n dnode1 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode2 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode3 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode4 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode5 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode1 -c supportVnodes -v 0
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
system sh/exec.sh -n dnode4 -s start
sql connect
print =============== step1 create dnode2
sql create dnode $hostname port 7200
sql create dnode $hostname port 7300
sql create dnode $hostname port 7400
sql create dnode $hostname port 7500
$x = 0
step1:
$x = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
print ===> $data40 $data41 $data42 $data43 $data44 $data45
if $rows != 5 then
return -1
endi
if $data(1)[4] != ready then
goto step1
endi
if $data(2)[4] != ready then
goto step1
endi
if $data(3)[4] != ready then
goto step1
endi
if $data(4)[4] != ready then
goto step1
endi
print =============== step2: create db
sql create database d1 vgroups 4 replica 3
print =============== step32 wait vgroup2
$x = 0
step32:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(2)[4] == leader then
$leaderExist = 1
endi
if $data(2)[6] == leader then
$leaderExist = 1
endi
if $data(2)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step32
endi
print =============== step33 wait vgroup3
$x = 0
step33:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(3)[4] == leader then
$leaderExist = 1
endi
if $data(3)[6] == leader then
$leaderExist = 1
endi
if $data(3)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step33
endi
print =============== step34 wait vgroup4
$x = 0
step34:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(4)[4] == leader then
$leaderExist = 1
endi
if $data(4)[6] == leader then
$leaderExist = 1
endi
if $data(4)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step34
endi
print =============== step35 wait vgroup5
$x = 0
step35:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(4)[4] == leader then
$leaderExist = 1
endi
if $data(4)[6] == leader then
$leaderExist = 1
endi
if $data(4)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step35
endi
print =============== step36: create table
sql use d1
sql create table d1.st (ts timestamp, i int) tags (j int)
sql create table d1.c1 using st tags(1)
sql create table d1.c2 using st tags(1)
sql create table d1.c3 using st tags(1)
sql create table d1.c4 using st tags(1)
sql create table d1.c5 using st tags(1)
sql create table d1.c6 using st tags(1)
sql show d1.tables
if $rows != 6 then
return -1
endi
print =============== step4: start dnode5
system sh/exec.sh -n dnode5 -s start
$x = 0
step4:
$x = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
print ===> $data40 $data41 $data42 $data43 $data44 $data45
if $rows != 5 then
return -1
endi
if $data(1)[4] != ready then
goto step4
endi
if $data(2)[4] != ready then
goto step4
endi
if $data(3)[4] != ready then
goto step4
endi
if $data(4)[4] != ready then
goto step4
endi
if $data(5)[4] != ready then
goto step4
endi
print =============== step5: balance
sql balance vgroup
print =============== step62 wait vgroup2
$x = 0
step62:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(2)[4] == leader then
$leaderExist = 1
endi
if $data(2)[6] == leader then
$leaderExist = 1
endi
if $data(2)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step62
endi
print =============== step63 wait vgroup3
$x = 0
step63:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(3)[4] == leader then
$leaderExist = 1
endi
if $data(3)[6] == leader then
$leaderExist = 1
endi
if $data(3)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step63
endi
print =============== step64 wait vgroup4
$x = 0
step64:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(4)[4] == leader then
$leaderExist = 1
endi
if $data(4)[6] == leader then
$leaderExist = 1
endi
if $data(4)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step64
endi
print =============== step65 wait vgroup5
$x = 0
step65:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(4)[4] == leader then
$leaderExist = 1
endi
if $data(4)[6] == leader then
$leaderExist = 1
endi
if $data(4)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step65
endi
print =============== step7: select data
sql show d1.tables
print rows $rows
if $rows != 6 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
tests/script/tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim
浏览文件 @
da8db399
...
...
@@ -28,7 +28,7 @@ step1:
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
if $rows !=
3
then
if $rows !=
5
then
return -1
endi
if $data(1)[4] != ready then
...
...
@@ -49,26 +49,133 @@ endi
print =============== step3 create database
sql create database d1 vgroups 4 replica 3
sql use d1
sql create table d1.st (ts timestamp, i int) tags (j int)
sql create table d1.c1 using st tags(1)
sql show d1.tables
if $rows != 1 then
print =============== step32 wait vgroup2
$x = 0
step32:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(2)[4] == leader then
$leaderExist = 1
endi
if $data(2)[6] == leader then
$leaderExist = 1
endi
if $data(2)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step32
endi
print =============== step33 wait vgroup3
$x = 0
step33:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4]
if $rows != 1 then
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(2)[3] != 2 then
if $data(3)[4] == leader then
$leaderExist = 1
endi
if $data(3)[6] == leader then
$leaderExist = 1
endi
if $data(3)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step33
endi
print =============== step34 wait vgroup4
$x = 0
step34:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(2)[5] != 3 then
if $data(4)[4] == leader then
$leaderExist = 1
endi
if $data(4)[6] == leader then
$leaderExist = 1
endi
if $data(4)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step34
endi
print =============== step35 wait vgroup5
$x = 0
step35:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(2)[7] != 4 then
if $data(4)[4] == leader then
$leaderExist = 1
endi
if $data(4)[6] == leader then
$leaderExist = 1
endi
if $data(4)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step35
endi
print =============== step36: create table
sql use d1
sql create table d1.st (ts timestamp, i int) tags (j int)
sql create table d1.c1 using st tags(1)
sql show d1.tables
if $rows != 1 then
return -1
endi
...
...
@@ -85,7 +192,7 @@ step4:
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
if $rows !=
3
then
if $rows !=
5
then
return -1
endi
if $data(1)[4] != ready then
...
...
@@ -115,21 +222,133 @@ if $rows != 4 then
return -1
endi
print show d1.vgroups
print =============== step62 wait vgroup2
$x = 0
step62:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4]
if $rows != 1 then
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(2)[4] == leader then
$leaderExist = 1
endi
if $data(2)[6] == leader then
$leaderExist = 1
endi
if $data(2)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step62
endi
print =============== step63 wait vgroup3
$x = 0
step63:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(3)[4] == leader then
$leaderExist = 1
endi
if $data(3)[6] == leader then
$leaderExist = 1
endi
if $data(3)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step63
endi
print =============== step64 wait vgroup4
$x = 0
step64:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(4)[4] == leader then
$leaderExist = 1
endi
if $data(4)[6] == leader then
$leaderExist = 1
endi
if $data(4)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step64
endi
print =============== step35 wait vgroup5
$x = 0
step65:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
print ===> $data10 $data11 $data12 $data13 $data14 $data15 $data16 $data17 $data18 $data19
print ===> $data20 $data21 $data22 $data23 $data24 $data25 $data26 $data27 $data28 $data29
print ===> $data30 $data31 $data32 $data33 $data34 $data35 $data36 $data37 $data38 $data39
if $rows != 4 then
return -1
endi
if $data(4)[4] == leader then
$leaderExist = 1
endi
if $data(4)[6] == leader then
$leaderExist = 1
endi
if $data(4)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step65
endi
print =============== step6: select data
print =============== step7: select data
print ===> $data00 $data01
sql show d1.tables
if $rows != 1 then
return -1
endi
return
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
tests/script/tsim/dnode/drop_dnode_has_vnode_replica3.sim
浏览文件 @
da8db399
...
...
@@ -49,6 +49,50 @@ endi
print =============== step3 create database
sql create database d1 vgroups 1 replica 3
$leaderExist = 0
$leaderVnode = 0
$follower1 = 0
$follower2 = 0
$x = 0
step3:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
if $rows != 1 then
return -1
endi
if $data(2)[4] == leader then
$leaderExist = 1
$leaderVnode = 2
$follower1 = 3
$follower2 = 4
endi
if $data(2)[6] == leader then
$leaderExist = 1
$leaderVnode = 3
$follower1 = 2
$follower2 = 4
endi
if $data(2)[8] == leader then
$leaderExist = 1
$leaderVnode = 4
$follower1 = 2
$follower2 = 3
endi
if $leaderExist != 1 then
goto step3
endi
print leader $leaderVnode
print follower1 $follower1
print follower2 $follower2
sql use d1
sql create table d1.st (ts timestamp, i int) tags (j int)
sql create table d1.c1 using st tags(1)
...
...
@@ -72,13 +116,6 @@ if $data(2)[7] != 4 then
return -1
endi
system sh/exec.sh -n dnode4 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
return
print =============== step4: drop dnode 2
system sh/exec.sh -n dnode5 -s start
$x = 0
...
...
@@ -92,7 +129,7 @@ step4:
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
if $rows !=
3
then
if $rows !=
5
then
return -1
endi
if $data(1)[4] != ready then
...
...
@@ -116,8 +153,11 @@ sql drop dnode 2
print show dnodes;
sql show dnodes;
print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4]
print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4]
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
print ===> $data40 $data41 $data42 $data43 $data44 $data45
if $rows != 4 then
return -1
endi
...
...
@@ -128,9 +168,9 @@ print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4]
if $rows != 1 then
return -1
endi
#if $data(2)[3] != 3
then
#
return -1
#
endi
if $data(2)[3] != 5
then
return -1
endi
print =============== step6: select data
sql show d1.tables
...
...
@@ -138,7 +178,37 @@ if $rows != 1 then
return -1
endi
return
$leaderExist = 0
$leaderVnode = 0
$follower1 = 0
$follower2 = 0
$x = 0
step6:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
if $rows != 1 then
return -1
endi
if $data(2)[4] == leader then
$leaderExist = 1
endi
if $data(2)[6] == leader then
$leaderExist = 1
endi
if $data(2)[8] == leader then
$leaderExist = 1
endi
if $leaderExist != 1 then
goto step6
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
tests/script/tsim/dnode/redistribute_vgroup_replica1.sim
0 → 100644
浏览文件 @
da8db399
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4
system sh/cfg.sh -n dnode1 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode2 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode3 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode4 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode1 -c supportVnodes -v 0
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode2 -s start
sql connect
sql create user u1 pass 'taosdata'
print =============== step1 create dnode2
sql create dnode $hostname port 7200
sql create dnode $hostname port 7300
sql create dnode $hostname port 7400
$x = 0
step1:
$x = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
if $rows != 4 then
return -1
endi
if $data(1)[4] != ready then
goto step1
endi
if $data(2)[4] != ready then
goto step1
endi
print =============== step2: create db
sql create database d1 vgroups 1 replica 1
system sh/exec.sh -n dnode3 -s start
system sh/exec.sh -n dnode4 -s start
$x = 0
step2:
$x = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
if $rows != 4 then
return -1
endi
if $data(1)[4] != ready then
goto step2
endi
if $data(2)[4] != ready then
goto step2
endi
if $data(3)[4] != ready then
goto step2
endi
if $data(4)[4] != ready then
goto step2
endi
print =============== step3: create database
sql use d1
sql create table d1.st (ts timestamp, i int) tags (j int)
sql create table d1.c1 using st tags(1)
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step40:
print redistribute vgroup 2 dnode 3
sql redistribute vgroup 2 dnode 3
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step41:
print redistribute vgroup 2 dnode 4
sql redistribute vgroup 2 dnode 4
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step42:
print redistribute vgroup 2 dnode 2
sql redistribute vgroup 2 dnode 2
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step43:
print redistribute vgroup 2 dnode 3
sql redistribute vgroup 2 dnode 3
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step44:
print redistribute vgroup 2 dnode 4
sql redistribute vgroup 2 dnode 4
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step45:
print redistribute vgroup 2 dnode 2
sql redistribute vgroup 2 dnode 2
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step46:
print redistribute vgroup 2 dnode 3
sql redistribute vgroup 2 dnode 3
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step47:
print redistribute vgroup 2 dnode 2
sql redistribute vgroup 2 dnode 2
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT
tests/script/tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim
浏览文件 @
da8db399
...
...
@@ -65,7 +65,7 @@ sql_error redistribute vgroup 3 dnode 6 dnode 3 dnode 4
# vgroup not exist
sql_error redistribute vgroup 3 dnode 5 dnode 3 dnode 4
# un changed
sql_error redistribute vgroup 2 dnode 2 dnode 3 dnode 4
#
sql_error redistribute vgroup 2 dnode 2 dnode 3 dnode 4
# no enought vnodes
sql_error redistribute vgroup 2 dnode 1 dnode 3 dnode 4
# offline vnodes
...
...
@@ -176,8 +176,6 @@ if $rows != 1 then
return -1
endi
return
print =============== step32:
print redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5
sql redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 5
...
...
tests/script/tsim/dnode/redistribute_vgroup_replica3_v2.sim
0 → 100644
浏览文件 @
da8db399
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4
system sh/deploy.sh -n dnode5 -i 5
system sh/deploy.sh -n dnode6 -i 6
system sh/cfg.sh -n dnode1 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode2 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode3 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode4 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode5 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode6 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode1 -c supportVnodes -v 0
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
system sh/exec.sh -n dnode4 -s start
sql connect
sql create user u1 pass 'taosdata'
print =============== step1 create dnode2
sql create dnode $hostname port 7200
sql create dnode $hostname port 7300
sql create dnode $hostname port 7400
sql create dnode $hostname port 7500
sql create dnode $hostname port 7600
$x = 0
step1:
$x = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
print ===> $data40 $data41 $data42 $data43 $data44 $data45
if $rows != 6 then
return -1
endi
if $data(1)[4] != ready then
goto step1
endi
if $data(2)[4] != ready then
goto step1
endi
if $data(3)[4] != ready then
goto step1
endi
if $data(4)[4] != ready then
goto step1
endi
print =============== step2: create db
sql create database d1 vgroups 1 replica 3
system sh/exec.sh -n dnode5 -s start
system sh/exec.sh -n dnode6 -s start
$x = 0
step2:
$x = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
print ===> $data40 $data41 $data42 $data43 $data44 $data45
if $rows != 6 then
return -1
endi
if $data(1)[4] != ready then
goto step2
endi
if $data(2)[4] != ready then
goto step2
endi
if $data(3)[4] != ready then
goto step2
endi
if $data(4)[4] != ready then
goto step2
endi
if $data(5)[4] != ready then
goto step2
endi
if $data(6)[4] != ready then
goto step2
endi
print =============== step3: create database
$leaderExist = 0
$leaderVnode = 0
$follower1 = 0
$follower2 = 0
$x = 0
step3:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
if $rows != 1 then
return -1
endi
if $data(2)[4] == leader then
$leaderExist = 1
$leaderVnode = 2
$follower1 = 3
$follower2 = 4
endi
if $data(2)[6] == leader then
$leaderExist = 1
$leaderVnode = 3
$follower1 = 2
$follower2 = 4
endi
if $data(2)[8] == leader then
$leaderExist = 1
$leaderVnode = 4
$follower1 = 2
$follower2 = 3
endi
if $leaderExist != 1 then
goto step3
endi
print leader $leaderVnode
print follower1 $follower1
print follower2 $follower2
sql use d1
sql create table d1.st (ts timestamp, i int) tags (j int)
sql create table d1.c1 using st tags(1)
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step40:
print redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode 6
sql redistribute vgroup 2 dnode $leaderVnode dnode 5 dnode 6
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step41:
print redistribute vgroup 2 dnode 5 dnode $follower2 dnode $follower1
sql redistribute vgroup 2 dnode 5 dnode $follower2 dnode $follower1
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step42:
print redistribute vgroup 2 dnode $follower2 dnode 6 dnode $leaderVnode
sql redistribute vgroup 2 dnode $follower2 dnode 6 dnode $leaderVnode
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step43:
print redistribute vgroup 2 dnode $follower1 dnode 5 dnode 6
sql redistribute vgroup 2 dnode $follower1 dnode 5 dnode 6
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step44:
print redistribute vgroup 2 dnode $follower2 dnode 5 dnode $leaderVnode
sql redistribute vgroup 2 dnode $follower2 dnode 5 dnode $leaderVnode
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step45:
print redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 6
sql redistribute vgroup 2 dnode $leaderVnode dnode $follower1 dnode 6
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step46:
print redistribute vgroup 2 dnode $follower1 dnode $follower2 dnode 5
sql redistribute vgroup 2 dnode $follower1 dnode $follower2 dnode 5
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step47:
print redistribute vgroup 2 dnode $follower1 dnode 6 dnode $leaderVnode
sql redistribute vgroup 2 dnode $follower1 dnode 6 dnode $leaderVnode
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT
system sh/exec.sh -n dnode5 -s stop -x SIGINT
tests/script/tsim/dnode/redistribute_vgroup_replica3_v3.sim
0 → 100644
浏览文件 @
da8db399
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4
system sh/deploy.sh -n dnode5 -i 5
system sh/deploy.sh -n dnode6 -i 6
system sh/deploy.sh -n dnode7 -i 7
system sh/deploy.sh -n dnode8 -i 8
system sh/cfg.sh -n dnode1 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode2 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode3 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode4 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode5 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode6 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode7 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode8 -c transPullupInterval -v 1
system sh/cfg.sh -n dnode1 -c supportVnodes -v 0
system sh/exec.sh -n dnode1 -s start
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
system sh/exec.sh -n dnode4 -s start
sql connect
sql create user u1 pass 'taosdata'
print =============== step1 create dnode2
sql create dnode $hostname port 7200
sql create dnode $hostname port 7300
sql create dnode $hostname port 7400
sql create dnode $hostname port 7500
sql create dnode $hostname port 7600
sql create dnode $hostname port 7700
sql create dnode $hostname port 7800
$x = 0
step1:
$x = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
print ===> $data40 $data41 $data42 $data43 $data44 $data45
if $rows != 8 then
return -1
endi
if $data(1)[4] != ready then
goto step1
endi
if $data(2)[4] != ready then
goto step1
endi
if $data(3)[4] != ready then
goto step1
endi
if $data(4)[4] != ready then
goto step1
endi
print =============== step2: create db
sql create database d1 vgroups 1 replica 3
system sh/exec.sh -n dnode5 -s start
system sh/exec.sh -n dnode6 -s start
system sh/exec.sh -n dnode7 -s start
system sh/exec.sh -n dnode8 -s start
$x = 0
step2:
$x = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
print ===> $data40 $data41 $data42 $data43 $data44 $data45
if $rows != 8 then
return -1
endi
if $data(1)[4] != ready then
goto step2
endi
if $data(2)[4] != ready then
goto step2
endi
if $data(3)[4] != ready then
goto step2
endi
if $data(4)[4] != ready then
goto step2
endi
if $data(5)[4] != ready then
goto step2
endi
if $data(6)[4] != ready then
goto step2
endi
if $data(7)[4] != ready then
goto step2
endi
if $data(8)[4] != ready then
goto step2
endi
print =============== step3: create database
$leaderExist = 0
$leaderVnode = 0
$follower1 = 0
$follower2 = 0
$x = 0
step3:
$x = $x + 1
sleep 1000
if $x == 60 then
print ====> db not ready!
return -1
endi
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
if $rows != 1 then
return -1
endi
if $data(2)[4] == leader then
$leaderExist = 1
$leaderVnode = 2
$follower1 = 3
$follower2 = 4
endi
if $data(2)[6] == leader then
$leaderExist = 1
$leaderVnode = 3
$follower1 = 2
$follower2 = 4
endi
if $data(2)[8] == leader then
$leaderExist = 1
$leaderVnode = 4
$follower1 = 2
$follower2 = 3
endi
if $leaderExist != 1 then
goto step3
endi
print leader $leaderVnode
print follower1 $follower1
print follower2 $follower2
sql use d1
sql create table d1.st (ts timestamp, i int) tags (j int)
sql create table d1.c1 using st tags(1)
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step40:
print redistribute vgroup 2 dnode 7 dnode 5 dnode 6
sql redistribute vgroup 2 dnode 7 dnode 5 dnode 6
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step41:
print redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode $follower1
sql redistribute vgroup 2 dnode $leaderVnode dnode $follower2 dnode $follower1
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step42:
print redistribute vgroup 2 dnode 7 dnode 6 dnode 8
sql redistribute vgroup 2 dnode 7 dnode 6 dnode 8
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step43:
print redistribute vgroup 2 dnode $follower1 dnode $follower2 dnode 5
sql redistribute vgroup 2 dnode $follower1 dnode $follower2 dnode 5
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
return
print =============== step44:
print redistribute vgroup 2 dnode 6 dnode 7 dnode $leaderVnode
sql redistribute vgroup 2 dnode 6 dnode 7 dnode $leaderVnode
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step45:
print redistribute vgroup 2 dnode $follower1 dnode $follower2 dnode 8
sql redistribute vgroup 2dnode $follower1 dnode $follower2 dnode 8
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step46:
print redistribute vgroup 2 dnode $leaderVnode dnode 6 dnode 5
sql redistribute vgroup 2 dnode $leaderVnode dnode 6 dnode 5
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
print =============== step47:
print redistribute vgroup 2 dnode $follower1 dnode 7 dnode 8
sql redistribute vgroup 2 dnode $follower1 dnode 7 dnode 8
sql show d1.vgroups
print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
sql show d1.tables
if $rows != 1 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT
system sh/exec.sh -n dnode3 -s stop -x SIGINT
system sh/exec.sh -n dnode4 -s stop -x SIGINT
system sh/exec.sh -n dnode5 -s stop -x SIGINT
tests/script/tsim/stream/distributeInterval0.sim
浏览文件 @
da8db399
...
...
@@ -41,7 +41,7 @@ sql create table ts1 using st tags(1,1,1);
sql create table ts2 using st tags(2,2,2);
sql create table ts3 using st tags(3,2,2);
sql create table ts4 using st tags(4,2,2);
sql create stream stream_t1 trigger at_once into streamtST1 as select _wstartts, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5 from st interval(10s);
sql create stream stream_t1 trigger at_once
watermark 1d
into streamtST1 as select _wstartts, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5 from st interval(10s);
sleep 1000
...
...
tests/script/tsim/stream/distributeIntervalRetrive0.sim
0 → 100644
浏览文件 @
da8db399
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/exec.sh -n dnode1 -s start
sleep 50
sql connect
sql create dnode $hostname2 port 7200
system sh/exec.sh -n dnode2 -s start
print ===== step1
$x = 0
step1:
$x = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
if $rows != 2 then
return -1
endi
if $data(1)[4] != ready then
goto step1
endi
if $data(2)[4] != ready then
goto step1
endi
print ===== step2
sql create database test vgroups 4;
sql use test;
sql create stable st(ts timestamp, a int, b int , c int, d double) tags(ta int,tb int,tc int);
sql create table ts1 using st tags(1,1,1);
sql create table ts2 using st tags(2,2,2);
sql create table ts3 using st tags(3,2,2);
sql create table ts4 using st tags(4,2,2);
sql create stream stream_t1 trigger at_once into streamtST1 as select _wstartts, count(*) c1, sum(a) c3 , max(b) c4, min(c) c5 from st interval(10s);
sleep 1000
sql insert into ts1 values(1648791213001,1,12,3,1.0);
sql insert into ts2 values(1648791213001,1,12,3,1.0);
sql insert into ts1 values(1648791213002,NULL,NULL,NULL,NULL);
sql insert into ts2 values(1648791213002,NULL,NULL,NULL,NULL);
sql insert into ts1 values(1648791223002,2,2,3,1.1);
sql insert into ts1 values(1648791233003,3,2,3,2.1);
sql insert into ts2 values(1648791243004,4,2,43,73.1);
sql insert into ts1 values(1648791213002,24,22,23,4.1) (1648791243005,4,20,3,3.1);
sleep 1000
sql insert into ts3 values(1648791213001,12,12,13,14.1) (1648791243005,14,30,30,30.1);
$loop_count = 0
loop1:
sleep 1000
sql select * from streamtST1;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
# row 0
if $data01 != 5 then
print =====data01=$data01
goto loop1
endi
if $data02 != 14 then
print =====data02=$data02
goto loop1
endi
# row 1
if $data11 != 1 then
print =====data11=$data11
goto loop1
endi
if $data12 != 2 then
print =====data12=$data12
goto loop1
endi
#row2
if $data21 != 1 then
print =====data21=$data21
goto loop1
endi
if $data22 != 3 then
print =====data22=$data22
goto loop1
endi
#row 3
if $data31 != 3 then
print =====data31=$data31
goto loop1
endi
if $data32 != 22 then
print =====data32=$data32
goto loop1
endi
print loop1 over
sql insert into ts1 values(1648791223008,4,2,30,3.1) (1648791213009,4,2,3,3.1) (1648791233010,4,2,3,3.1) (1648791243011,4,2,3,3.1)(1648791243012,34,32,33,3.1);
$loop_count = 0
loop2:
sleep 1000
sql select * from streamtST1;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
# row 0
if $data01 != 6 then
print =====data01=$data01
goto loop2
endi
if $data02 != 18 then
print =====data02=$data02
goto loop2
endi
# row 1
if $data11 != 2 then
print =====data11=$data11
goto loop2
endi
if $data12 != 6 then
print =====data12=$data12
goto loop2
endi
#row2
if $data21 != 2 then
print =====data21=$data21
goto loop2
endi
if $data22 != 7 then
print =====data22=$data22
goto loop2
endi
#row 3
if $data31 != 5 then
print =====data31=$data31
goto loop2
endi
if $data32 != 60 then
print =====data32=$data32
goto loop2
endi
print loop2 over
sql insert into ts4 values(1648791223008,4,2,30,3.1) (1648791213009,4,2,3,3.1) (1648791233010,4,2,3,3.1);
$loop_count = 0
loop3:
sleep 1000
sql select * from streamtST1;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
# row 0
if $data01 != 7 then
print =====data01=$data01
goto loop3
endi
if $data02 != 22 then
print =====data02=$data02
goto loop3
endi
# row 1
if $data11 != 3 then
print =====data11=$data11
goto loop3
endi
if $data12 != 10 then
print =====data12=$data12
goto loop3
endi
#row2
if $data21 != 3 then
print =====data21=$data21
goto loop3
endi
if $data22 != 11 then
print =====data22=$data22
goto loop3
endi
#row 3
if $data31 != 5 then
print =====data31=$data31
goto loop3
endi
if $data32 != 60 then
print =====data32=$data32
goto loop3
endi
print loop3 over
$loop_count = 0
loop4:
sleep 1000
sql select * from streamtST1;
$loop_count = $loop_count + 1
if $loop_count == 10 then
return -1
endi
# row 0
if $data01 != 7 then
print =====data01=$data01
goto loop4
endi
if $data02 != 22 then
print =====data02=$data02
goto loop4
endi
# row 1
if $data11 != 3 then
print =====data11=$data11
goto loop4
endi
if $data12 != 10 then
print =====data12=$data12
goto loop4
endi
#row2
if $data21 != 3 then
print =====data21=$data21
goto loop4
endi
if $data22 != 11 then
print =====data22=$data22
goto loop4
endi
#row 3
if $data31 != 5 then
print =====data31=$data31
goto loop4
endi
if $data32 != 60 then
print =====data32=$data32
goto loop4
endi
print loop4 over
system sh/stop_dnodes.sh
tests/script/tsim/stream/distribute
s
ession0.sim
→
tests/script/tsim/stream/distribute
S
ession0.sim
浏览文件 @
da8db399
文件已移动
tests/system-test/1-insert/create_retentions.py
浏览文件 @
da8db399
...
...
@@ -21,9 +21,9 @@ SINT_UN_COL = "c_sint_un"
BINT_UN_COL
=
"c_bint_un"
INT_UN_COL
=
"c_int_un"
BINARY_COL
=
"c
8
"
NCHAR_COL
=
"c
9
"
TS_COL
=
"c
10
"
BINARY_COL
=
"c
_binary
"
NCHAR_COL
=
"c
_nchar
"
TS_COL
=
"c
_ts
"
NUM_COL
=
[
INT_COL
,
BINT_COL
,
SINT_COL
,
TINT_COL
,
FLOAT_COL
,
DOUBLE_COL
,
]
CHAR_COL
=
[
BINARY_COL
,
NCHAR_COL
,
]
...
...
@@ -51,12 +51,28 @@ class DataSet:
binary_data
:
List
[
str
]
=
None
nchar_data
:
List
[
str
]
=
None
def
__post_init__
(
self
):
self
.
ts_data
=
[]
self
.
int_data
=
[]
self
.
bint_data
=
[]
self
.
sint_data
=
[]
self
.
tint_data
=
[]
self
.
int_un_data
=
[]
self
.
bint_un_data
=
[]
self
.
sint_un_data
=
[]
self
.
tint_un_data
=
[]
self
.
float_data
=
[]
self
.
double_data
=
[]
self
.
bool_data
=
[]
self
.
binary_data
=
[]
self
.
nchar_data
=
[]
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to excute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
Tru
e
)
tdSql
.
init
(
conn
.
cursor
(),
Fals
e
)
@
property
def
create_databases_sql_err
(
self
):
...
...
@@ -87,28 +103,28 @@ class TDTestCase:
@
property
def
create_stable_sql_err
(
self
):
return
[
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(ceil) watermark 1s maxdelay 1m"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(ceil) watermark 1s max
_
delay 1m"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(count) watermark 1min"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) maxdelay -1s"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) max
_
delay -1s"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) watermark -1m"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) watermark 1m "
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) max
delay 1m "
,
#
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 1m ",
# f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) max_
delay 1m ",
f
"create stable stb2 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int,
{
BINARY_COL
}
binary(16)) tags (tag1 int) rollup(avg) watermark 1s"
,
f
"create stable stb2 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int,
{
BINARY_COL
}
nchar(16)) tags (tag1 int) rollup(avg) maxdelay 1m"
,
# f"create table ntb_1 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) rollup(avg) watermark 1s maxdelay 1s",
f
"create stable stb2 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int,
{
BINARY_COL
}
nchar(16)) tags (tag1 int) rollup(avg) max
_
delay 1m"
,
# f"create table ntb_1 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) rollup(avg) watermark 1s max
_
delay 1s",
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) tags (tag1 int) " ,
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) " ,
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) " ,
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) " ,
# watermark, maxdelay: [0, 900000], [ms, s, m, ?]
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) maxdelay 1u"
,
# watermark, max
_
delay: [0, 900000], [ms, s, m, ?]
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) max
_
delay 1u"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) watermark 1b"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) watermark 900001ms"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) maxdelay 16m"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) maxdelay 901s"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) maxdelay 1h"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) maxdelay 0.2h"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) max
_
delay 16m"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) max
_
delay 901s"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) max
_
delay 1h"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) max
_
delay 0.2h"
,
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) watermark 0.002d"
,
]
...
...
@@ -117,11 +133,11 @@ class TDTestCase:
def
create_stable_sql_current
(
self
):
return
[
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(avg)"
,
f
"create stable stb2 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) watermark 5s maxdelay 1m"
,
f
"create stable stb3 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(max) watermark 5s maxdelay 1m"
,
f
"create stable stb4 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(sum) watermark 5s maxdelay 1m"
,
# f"create stable stb5 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(last) watermark 5s maxdelay 1m",
# f"create stable stb6 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s maxdelay 1m",
f
"create stable stb2 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(min) watermark 5s max
_
delay 1m"
,
f
"create stable stb3 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(max) watermark 5s max
_
delay 1m"
,
f
"create stable stb4 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(sum) watermark 5s max
_
delay 1m"
,
# f"create stable stb5 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(last) watermark 5s max
_
delay 1m",
# f"create stable stb6 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max
_
delay 1m",
]
def
test_create_stb
(
self
):
...
...
@@ -135,7 +151,7 @@ class TDTestCase:
tdSql
.
checkRows
(
len
(
self
.
create_stable_sql_current
))
# tdSql.execute("use db") # because db is a noraml database, not a rollup database, should not be able to create a rollup database
# tdSql.error(f"create stable nor_db_rollup_stb ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int)
file_factor 5.0
")
# tdSql.error(f"create stable nor_db_rollup_stb ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int)
watermark 5s max_delay 1m
")
def
test_create_databases
(
self
):
...
...
@@ -177,21 +193,6 @@ class TDTestCase:
def
__data_set
(
self
,
rows
):
data_set
=
DataSet
()
# neg_data_set = DataSet()
data_set
.
ts_data
=
[]
data_set
.
int_data
=
[]
data_set
.
bint_data
=
[]
data_set
.
sint_data
=
[]
data_set
.
tint_data
=
[]
data_set
.
int_un_data
=
[]
data_set
.
bint_un_data
=
[]
data_set
.
sint_un_data
=
[]
data_set
.
tint_un_data
=
[]
data_set
.
float_data
=
[]
data_set
.
double_data
=
[]
data_set
.
bool_data
=
[]
data_set
.
binary_data
=
[]
data_set
.
nchar_data
=
[]
for
i
in
range
(
rows
):
data_set
.
ts_data
.
append
(
NOW
+
1
*
(
rows
-
i
))
...
...
@@ -226,6 +227,7 @@ class TDTestCase:
return
data_set
def
__insert_data
(
self
):
tdLog
.
printNoPrefix
(
"==========step: start inser data into tables now....."
)
data
=
self
.
__data_set
(
rows
=
self
.
rows
)
# now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000)
...
...
@@ -264,10 +266,10 @@ class TDTestCase:
def
run
(
self
):
self
.
rows
=
10
tdSql
.
prepare
()
tdLog
.
printNoPrefix
(
"==========step0:all check"
)
#
self.all_test()
self
.
all_test
()
tdLog
.
printNoPrefix
(
"==========step1:create table in normal database"
)
tdSql
.
prepare
()
...
...
tests/system-test/1-insert/time_range_wise.py
浏览文件 @
da8db399
...
...
@@ -17,25 +17,34 @@ TINT_COL = "c_tint"
FLOAT_COL
=
"c_float"
DOUBLE_COL
=
"c_double"
BOOL_COL
=
"c_bool"
TINT_UN_COL
=
"c_
tint_un
"
SINT_UN_COL
=
"c_
sint_un
"
BINT_UN_COL
=
"c_
bint_un
"
INT_UN_COL
=
"c_
int_un
"
TINT_UN_COL
=
"c_
utint
"
SINT_UN_COL
=
"c_
usint
"
BINT_UN_COL
=
"c_
ubint
"
INT_UN_COL
=
"c_
uint
"
BINARY_COL
=
"c_binary"
NCHAR_COL
=
"c_nchar"
TS_COL
=
"c_ts"
NUM_COL
=
[
INT_COL
,
BINT_COL
,
SINT_COL
,
TINT_COL
,
FLOAT_COL
,
DOUBLE_COL
,
]
CHAR_COL
=
[
BINARY_COL
,
NCHAR_COL
,
]
BOOLEAN_COL
=
[
BOOL_COL
,
]
TS_TYPE_COL
=
[
TS_COL
,
]
INT_TAG
=
"t_int"
ALL_COL
=
[
PRIMARY_COL
,
INT_COL
,
BINT_COL
,
SINT_COL
,
TINT_COL
,
FLOAT_COL
,
DOUBLE_COL
,
BINARY_COL
,
NCHAR_COL
,
BOOL_COL
,
TS_COL
]
TAG_COL
=
[
INT_TAG
]
# insert data args:
TIME_STEP
=
10000
NOW
=
int
(
datetime
.
datetime
.
timestamp
(
datetime
.
datetime
.
now
())
*
1000
)
# init db/table
DBNAME
=
"db"
STBNAME
=
"stb1"
CTBNAME
=
"ct1"
NTBNAME
=
"nt1"
@
dataclass
class
DataSet
:
...
...
@@ -73,19 +82,25 @@ class DataSet:
@
dataclass
class
SMAschema
:
creation
:
str
=
"CREATE"
index_name
:
str
=
"sma_index_1"
index_flag
:
str
=
"SMA INDEX"
operator
:
str
=
"ON"
tbname
:
str
=
None
watermark
:
str
=
None
maxdelay
:
str
=
None
func
:
Tuple
[
str
]
=
None
interval
:
Tuple
[
str
]
=
None
sliding
:
str
=
None
other
:
Any
=
None
drop
:
str
=
"DROP"
drop_flag
:
str
=
"INDEX"
creation
:
str
=
"CREATE"
index_name
:
str
=
"sma_index_1"
index_flag
:
str
=
"SMA INDEX"
operator
:
str
=
"ON"
tbname
:
str
=
None
watermark
:
str
=
"5s"
max_delay
:
str
=
"6m"
func
:
Tuple
[
str
]
=
None
interval
:
Tuple
[
str
]
=
(
"6m"
,
"10s"
)
sliding
:
str
=
"6m"
other
:
Any
=
None
drop
:
str
=
"DROP"
drop_flag
:
str
=
"INDEX"
querySmaOptimize
:
int
=
1
show
:
str
=
"SHOW"
show_msg
:
str
=
"INDEXES"
show_oper
:
str
=
"FROM"
dbname
:
str
=
None
rollup_db
:
bool
=
False
def
__post_init__
(
self
):
if
isinstance
(
self
.
other
,
dict
):
...
...
@@ -111,8 +126,8 @@ class SMAschema:
self
.
watermark
=
v
del
self
.
other
[
k
]
if
k
.
lower
()
==
"max
delay"
and
isinstance
(
v
,
str
)
and
not
self
.
max
delay
:
self
.
maxdelay
=
v
if
k
.
lower
()
==
"max
_delay"
and
isinstance
(
v
,
str
)
and
not
self
.
max_
delay
:
self
.
max
_
delay
=
v
del
self
.
other
[
k
]
if
k
.
lower
()
==
"functions"
and
isinstance
(
v
,
tuple
)
and
not
self
.
func
:
...
...
@@ -131,12 +146,36 @@ class SMAschema:
self
.
drop_flag
=
v
del
self
.
other
[
k
]
if
k
.
lower
()
==
"show_msg"
and
isinstance
(
v
,
str
)
and
not
self
.
show_msg
:
self
.
show_msg
=
v
del
self
.
other
[
k
]
if
k
.
lower
()
==
"dbname"
and
isinstance
(
v
,
str
)
and
not
self
.
dbname
:
self
.
dbname
=
v
del
self
.
other
[
k
]
if
k
.
lower
()
==
"show_oper"
and
isinstance
(
v
,
str
)
and
not
self
.
show_oper
:
self
.
show_oper
=
v
del
self
.
other
[
k
]
if
k
.
lower
()
==
"rollup_db"
and
isinstance
(
v
,
bool
)
and
not
self
.
rollup_db
:
self
.
rollup_db
=
v
del
self
.
other
[
k
]
# from ...pytest.util.sql import *
# from ...pytest.util.constant import *
class
TDTestCase
:
updatecfgDict
=
{
"querySmaOptimize"
:
1
}
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to excute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
False
)
self
.
precision
=
"ms"
self
.
sma_count
=
0
self
.
sma_created_index
=
[]
"""
create sma index :
...
...
@@ -155,13 +194,17 @@ class TDTestCase:
if
sma
.
func
:
sql
+=
f
" function(
{
', '
.
join
(
sma
.
func
)
}
)"
if
sma
.
interval
:
sql
+=
f
" interval(
{
', '
.
join
(
sma
.
interval
)
}
)"
interval
,
offset
=
self
.
__get_interval_offset
(
sma
.
interval
)
if
offset
:
sql
+=
f
" interval(
{
interval
}
,
{
offset
}
)"
else
:
sql
+=
f
" interval(
{
interval
}
)"
if
sma
.
sliding
:
sql
+=
f
" sliding(
{
sma
.
sliding
}
)"
if
sma
.
watermark
:
sql
+=
f
" watermark
{
sma
.
watermark
}
"
if
sma
.
maxdelay
:
sql
+=
f
" max
delay
{
sma
.
max
delay
}
"
if
sma
.
max
_
delay
:
sql
+=
f
" max
_delay
{
sma
.
max_
delay
}
"
if
isinstance
(
sma
.
other
,
dict
):
for
k
,
v
in
sma
.
other
.
items
():
if
isinstance
(
v
,
tuple
)
or
isinstance
(
v
,
list
):
...
...
@@ -171,53 +214,305 @@ class TDTestCase:
if
isinstance
(
sma
.
other
,
tuple
)
or
isinstance
(
sma
.
other
,
list
):
sql
+=
" "
.
join
(
sma
.
other
)
if
isinstance
(
sma
.
other
,
int
)
or
isinstance
(
sma
.
other
,
float
)
or
isinstance
(
sma
.
other
,
str
):
sql
+=
sma
.
other
sql
+=
f
"
{
sma
.
other
}
"
return
sql
def
sma_create_check
(
self
,
sma
:
SMAschema
):
def
__get_sma_func_col
(
self
,
func
):
cols
=
[]
if
isinstance
(
func
,
str
):
cols
.
append
(
func
.
split
(
"("
)[
-
1
].
split
(
")"
)[
0
]
)
elif
isinstance
(
func
,
tuple
)
or
isinstance
(
func
,
list
):
for
func_col
in
func
:
cols
.
append
(
func_col
.
split
(
"("
)[
-
1
].
split
(
")"
)[
0
])
else
:
cols
=
[]
return
cols
def
__check_sma_func
(
self
,
func
:
tuple
):
if
not
isinstance
(
func
,
str
)
and
not
isinstance
(
func
,
tuple
)
and
not
isinstance
(
func
,
list
):
return
False
if
isinstance
(
func
,
str
)
:
if
"("
not
in
func
or
")"
not
in
func
:
return
False
if
func
.
split
(
"("
)[
0
].
upper
()
not
in
SMA_INDEX_FUNCTIONS
:
return
False
if
func
.
split
(
"("
)[
1
].
split
(
")"
)[
0
]
not
in
ALL_COL
and
func
.
split
(
"("
)[
1
].
split
(
")"
)[
0
]
not
in
TAG_COL
:
return
False
if
isinstance
(
func
,
tuple
)
or
isinstance
(
func
,
list
):
for
arg
in
func
:
if
not
isinstance
(
arg
,
str
):
return
False
if
"("
not
in
arg
or
")"
not
in
arg
:
return
False
if
arg
.
split
(
"("
)[
0
].
upper
()
not
in
SMA_INDEX_FUNCTIONS
:
return
False
if
arg
.
split
(
"("
)[
1
].
split
(
")"
)[
0
]
not
in
ALL_COL
and
arg
.
split
(
"("
)[
1
].
split
(
")"
)[
0
]
not
in
TAG_COL
:
return
False
return
True
def
__check_sma_watermark
(
self
,
arg
):
if
not
arg
:
return
False
if
not
isinstance
(
arg
,
str
):
return
False
if
arg
[
-
1
]
not
in
SMA_WATMARK_MAXDELAY_INIT
:
return
False
if
len
(
arg
)
==
1
:
return
False
if
not
arg
[:
-
1
].
isdecimal
():
return
False
if
tdSql
.
get_times
(
arg
)
>
WATERMARK_MAX
:
return
False
if
tdSql
.
get_times
(
arg
)
<
WATERMARK_MIN
:
return
False
return
True
def
__check_sma_max_delay
(
self
,
arg
):
if
not
self
.
__check_sma_watermark
(
arg
):
return
False
if
tdSql
.
get_times
(
arg
)
<
MAX_DELAY_MIN
:
return
False
return
True
def
__check_sma_sliding
(
self
,
arg
):
if
not
isinstance
(
arg
,
str
):
return
False
if
arg
[
-
1
]
not
in
TAOS_TIME_INIT
:
return
False
if
len
(
arg
)
==
1
:
return
False
if
not
arg
[:
-
1
].
isdecimal
():
return
False
return
True
def
__get_interval_offset
(
self
,
args
):
if
isinstance
(
args
,
str
):
interval
,
offset
=
args
,
None
elif
isinstance
(
args
,
tuple
)
or
isinstance
(
args
,
list
):
if
len
(
args
)
==
1
:
interval
,
offset
=
args
[
0
],
None
elif
len
(
args
)
==
2
:
interval
,
offset
=
args
else
:
interval
,
offset
=
False
,
False
else
:
interval
,
offset
=
False
,
False
return
interval
,
offset
def
__check_sma_interval
(
self
,
args
):
if
not
isinstance
(
args
,
tuple
)
and
not
isinstance
(
args
,
str
):
return
False
interval
,
offset
=
self
.
__get_interval_offset
(
args
)
if
not
interval
:
return
False
if
not
self
.
__check_sma_sliding
(
interval
):
return
False
if
tdSql
.
get_times
(
interval
)
<
INTERVAL_MIN
:
return
False
if
offset
:
if
not
self
.
__check_sma_sliding
(
offset
):
return
False
if
tdSql
.
get_times
(
interval
)
<=
tdSql
.
get_times
(
offset
)
:
return
False
return
True
def
__sma_create_check
(
self
,
sma
:
SMAschema
):
if
self
.
updatecfgDict
[
"querySmaOptimize"
]
==
0
:
return
False
# # TODO: if database is a rollup-db, can not create sma index
# tdSql.query("select database()")
# if sma.rollup_db :
# return False
tdSql
.
query
(
"show stables"
)
if
not
sma
.
tbname
:
return
False
stb_in_list
=
False
for
row
in
tdSql
.
queryResult
:
if
sma
.
tbname
==
row
[
0
]:
stb_in_list
=
True
break
if
not
stb_in_list
:
tdSql
.
error
(
self
.
__create_sma_index
(
sma
))
if
not
sma
.
creation
:
tdSql
.
error
(
self
.
__create_sma_index
(
sma
))
if
not
sma
.
index_flag
:
tdSql
.
error
(
self
.
__create_sma_index
(
sma
))
if
not
sma
.
index_name
:
tdSql
.
error
(
self
.
__create_sma_index
(
sma
))
if
not
sma
.
operator
:
tdSql
.
error
(
self
.
__create_sma_index
(
sma
))
if
not
sma
.
tbname
:
tdSql
.
error
(
self
.
__create_sma_index
(
sma
))
if
not
sma
.
func
:
tdSql
.
error
(
self
.
__create_sma_index
(
sma
))
if
not
sma
.
interval
:
tdSql
.
error
(
self
.
__create_sma_index
(
sma
))
if
not
sma
.
sliding
:
tdSql
.
error
(
self
.
__create_sma_index
(
sma
))
return
False
if
not
sma
.
creation
or
not
isinstance
(
sma
.
creation
,
str
)
or
sma
.
creation
.
upper
()
!=
"CREATE"
:
return
False
if
not
sma
.
index_flag
or
not
isinstance
(
sma
.
index_flag
,
str
)
or
sma
.
index_flag
.
upper
()
!=
"SMA INDEX"
:
return
False
if
not
sma
.
index_name
or
not
isinstance
(
sma
.
index_name
,
str
)
or
sma
.
index_name
.
upper
()
in
TAOS_KEYWORDS
:
return
False
if
not
sma
.
operator
or
not
isinstance
(
sma
.
operator
,
str
)
or
sma
.
operator
.
upper
()
!=
"ON"
:
return
False
if
not
sma
.
func
or
not
self
.
__check_sma_func
(
sma
.
func
):
return
False
tdSql
.
query
(
f
"desc
{
sma
.
tbname
}
"
)
_col_list
=
[]
for
col_row
in
tdSql
.
queryResult
:
_col_list
.
append
(
col_row
[
0
])
_sma_func_cols
=
self
.
__get_sma_func_col
(
sma
.
func
)
for
_sma_func_col
in
_sma_func_cols
:
if
_sma_func_col
not
in
_col_list
:
return
False
if
sma
.
sliding
and
not
self
.
__check_sma_sliding
(
sma
.
sliding
):
return
False
interval
,
_
=
self
.
__get_interval_offset
(
sma
.
interval
)
if
not
sma
.
interval
or
not
self
.
__check_sma_interval
(
sma
.
interval
)
:
return
False
if
sma
.
sliding
and
tdSql
.
get_times
(
interval
)
<
tdSql
.
get_times
(
sma
.
sliding
):
return
False
if
sma
.
watermark
and
not
self
.
__check_sma_watermark
(
sma
.
watermark
):
return
False
if
sma
.
max_delay
and
not
self
.
__check_sma_max_delay
(
sma
.
max_delay
):
return
False
if
sma
.
other
:
return
False
return
True
def
sma_create_check
(
self
,
sma
:
SMAschema
):
if
self
.
__sma_create_check
(
sma
):
tdSql
.
query
(
self
.
__create_sma_index
(
sma
))
self
.
sma_count
+=
1
self
.
sma_created_index
.
append
(
sma
.
index_name
)
tdSql
.
query
(
"show streams"
)
tdSql
.
checkRows
(
self
.
sma_count
)
else
:
tdSql
.
error
(
self
.
__create_sma_index
(
sma
))
def
__drop_sma_index
(
self
,
sma
:
SMAschema
):
sql
=
f
"
{
sma
.
drop
}
{
sma
.
drop_flag
}
{
sma
.
index_name
}
"
return
sql
def
__sma_drop_check
(
self
,
sma
:
SMAschema
):
if
not
sma
.
drop
:
return
False
if
not
sma
.
drop_flag
:
return
False
if
not
sma
.
index_name
:
return
False
return
True
def
sma_drop_check
(
self
,
sma
:
SMAschema
):
if
self
.
__sma_drop_check
(
sma
):
tdSql
.
query
(
self
.
__drop_sma_index
(
sma
))
print
(
self
.
__drop_sma_index
(
sma
))
self
.
sma_count
-=
1
self
.
sma_created_index
=
list
(
filter
(
lambda
x
:
x
!=
sma
.
index_name
,
self
.
sma_created_index
))
tdSql
.
query
(
"show streams"
)
tdSql
.
checkRows
(
self
.
sma_count
)
else
:
tdSql
.
error
(
self
.
__drop_sma_index
(
sma
))
def
__show_sma_index
(
self
,
sma
:
SMAschema
):
sql
=
f
"
{
sma
.
show
}
{
sma
.
show_msg
}
{
sma
.
show_oper
}
{
sma
.
tbname
}
"
return
sql
def
__sma_show_check
(
self
,
sma
:
SMAschema
):
if
not
sma
.
show
:
return
False
if
not
sma
.
show_msg
:
return
False
if
not
sma
.
show_oper
:
return
False
if
not
sma
.
tbname
:
return
False
return
True
def
sma_show_check
(
self
,
sma
:
SMAschema
):
if
self
.
__sma_show_check
(
sma
):
tdSql
.
query
(
self
.
__show_sma_index
(
sma
))
tdSql
.
checkRows
(
self
.
sma_count
)
else
:
tdSql
.
error
(
self
.
__show_sma_index
(
sma
))
@
property
def
__create_sma_sql
(
self
):
err_sqls
=
[]
cur_sqls
=
[]
# err_set
# # case 1: required fields check
err_sqls
.
append
(
SMAschema
(
creation
=
""
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
err_sqls
.
append
(
SMAschema
(
index_name
=
""
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
err_sqls
.
append
(
SMAschema
(
index_flag
=
""
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
err_sqls
.
append
(
SMAschema
(
operator
=
""
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
err_sqls
.
append
(
SMAschema
(
tbname
=
""
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
err_sqls
.
append
(
SMAschema
(
func
=
(
""
,),
tbname
=
STBNAME
)
)
err_sqls
.
append
(
SMAschema
(
interval
=
(
""
),
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
# # case 2: err fields
err_sqls
.
append
(
SMAschema
(
creation
=
"show"
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
err_sqls
.
append
(
SMAschema
(
creation
=
"alter"
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
err_sqls
.
append
(
SMAschema
(
creation
=
"select"
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
err_sqls
.
append
(
SMAschema
(
index_flag
=
"SMA INDEXES"
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
err_sqls
.
append
(
SMAschema
(
index_flag
=
"SMA INDEX ,"
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
err_sqls
.
append
(
SMAschema
(
index_name
=
"tbname"
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
# current_set
cur_sqls
.
append
(
SMAschema
(
max_delay
=
""
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
cur_sqls
.
append
(
SMAschema
(
watermark
=
""
,
index_name
=
"sma_index_2"
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
cur_sqls
.
append
(
SMAschema
(
sliding
=
""
,
index_name
=
'sma_index_3'
,
tbname
=
STBNAME
,
func
=
(
f
"min(
{
INT_COL
}
)"
,
f
"max(
{
INT_COL
}
)"
)
)
)
return
err_sqls
,
cur_sqls
def
test_create_sma
(
self
):
err_sqls
,
cur_sqls
=
self
.
__create_sma_sql
for
err_sql
in
err_sqls
:
self
.
sma_create_check
(
err_sql
)
for
cur_sql
in
cur_sqls
:
self
.
sma_create_check
(
cur_sql
)
@
property
def
__drop_sma_sql
(
self
):
err_sqls
=
[]
cur_sqls
=
[]
# err_set
## case 1: required fields check
err_sqls
.
append
(
SMAschema
(
drop
=
""
)
)
err_sqls
.
append
(
SMAschema
(
drop_flag
=
""
)
)
err_sqls
.
append
(
SMAschema
(
index_name
=
""
)
)
for
index
in
self
.
sma_created_index
:
cur_sqls
.
append
(
SMAschema
(
index_name
=
index
))
return
err_sqls
,
cur_sqls
def
test_drop_sma
(
self
):
err_sqls
,
cur_sqls
=
self
.
__drop_sma_sql
for
err_sql
in
err_sqls
:
self
.
sma_drop_check
(
err_sql
)
# for cur_sql in cur_sqls:
# self.sma_drop_check(cur_sql)
def
all_test
(
self
):
self
.
test_create_sma
()
self
.
test_drop_sma
()
pass
def
__create_tb
(
self
):
tdLog
.
printNoPrefix
(
"==========step: create table"
)
create_stb_sql
=
f
'''create table
stb1
(
create_stb_sql
=
f
'''create table
{
STBNAME
}
(
ts timestamp,
{
INT_COL
}
int,
{
BINT_COL
}
bigint,
{
SINT_COL
}
smallint,
{
TINT_COL
}
tinyint,
{
FLOAT_COL
}
float,
{
DOUBLE_COL
}
double,
{
BOOL_COL
}
bool,
{
BINARY_COL
}
binary(16),
{
NCHAR_COL
}
nchar(32),
{
TS_COL
}
timestamp,
{
TINT_UN_COL
}
tinyint unsigned,
{
SINT_UN_COL
}
smallint unsigned,
{
INT_UN_COL
}
int unsigned,
{
BINT_UN_COL
}
bigint unsigned
) tags (
tag1
int)
) tags (
{
INT_TAG
}
int)
'''
create_ntb_sql
=
f
'''create table
t1
(
create_ntb_sql
=
f
'''create table
{
NTBNAME
}
(
ts timestamp,
{
INT_COL
}
int,
{
BINT_COL
}
bigint,
{
SINT_COL
}
smallint,
{
TINT_COL
}
tinyint,
{
FLOAT_COL
}
float,
{
DOUBLE_COL
}
double,
{
BOOL_COL
}
bool,
{
BINARY_COL
}
binary(16),
{
NCHAR_COL
}
nchar(32),
{
TS_COL
}
timestamp,
...
...
@@ -253,6 +548,7 @@ class TDTestCase:
return
data_set
def
__insert_data
(
self
):
tdLog
.
printNoPrefix
(
"==========step: start inser data into tables now....."
)
data
=
self
.
__data_set
(
rows
=
self
.
rows
)
# now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000)
...
...
@@ -278,7 +574,7 @@ class TDTestCase:
tdSql
.
execute
(
f
"insert into ct4 values (
{
NOW
-
i
*
int
(
TIME_STEP
*
0.8
)
}
,
{
row_data
}
)"
)
tdSql
.
execute
(
f
"insert into
t1
values (
{
NOW
-
i
*
int
(
TIME_STEP
*
1.2
)
}
,
{
row_data
}
)"
)
f
"insert into
{
NTBNAME
}
values (
{
NOW
-
i
*
int
(
TIME_STEP
*
1.2
)
}
,
{
row_data
}
)"
)
tdSql
.
execute
(
f
"insert into ct2 values (
{
NOW
+
int
(
TIME_STEP
*
0.6
)
}
,
{
null_data
}
)"
)
...
...
@@ -295,28 +591,31 @@ class TDTestCase:
f
"insert into ct4 values (
{
NOW
-
self
.
rows
*
int
(
TIME_STEP
*
0.39
)
}
,
{
null_data
}
)"
)
tdSql
.
execute
(
f
"insert into
t1
values (
{
NOW
+
int
(
TIME_STEP
*
1.2
)
}
,
{
null_data
}
)"
)
f
"insert into
{
NTBNAME
}
values (
{
NOW
+
int
(
TIME_STEP
*
1.2
)
}
,
{
null_data
}
)"
)
tdSql
.
execute
(
f
"insert into
t1
values (
{
NOW
-
(
self
.
rows
+
1
)
*
int
(
TIME_STEP
*
1.2
)
}
,
{
null_data
}
)"
)
f
"insert into
{
NTBNAME
}
values (
{
NOW
-
(
self
.
rows
+
1
)
*
int
(
TIME_STEP
*
1.2
)
}
,
{
null_data
}
)"
)
tdSql
.
execute
(
f
"insert into
t1
values (
{
NOW
-
self
.
rows
*
int
(
TIME_STEP
*
0.59
)
}
,
{
null_data
}
)"
)
f
"insert into
{
NTBNAME
}
values (
{
NOW
-
self
.
rows
*
int
(
TIME_STEP
*
0.59
)
}
,
{
null_data
}
)"
)
def
run
(
self
):
sma1
=
SMAschema
(
func
=
(
"min(c1)"
,
"max(c2)"
))
sql1
=
self
.
__create_sma_index
(
sma1
)
print
(
"================"
)
print
(
sql1
)
# a = DataSet()
# return
self
.
rows
=
10
tdLog
.
printNoPrefix
(
"==========step0:all check"
)
# self.all_test()
tdLog
.
printNoPrefix
(
"==========step1:create table in normal database"
)
tdSql
.
prepare
()
self
.
__create_tb
()
self
.
__insert_data
()
# self.__insert_data()
self
.
all_test
()
# drop databases, create same name db、stb and sma index
# tdSql.prepare()
# self.__create_tb()
# self.__insert_data()
# self.all_test()
return
tdLog
.
printNoPrefix
(
"==========step2:create table in rollup database"
)
...
...
tests/system-test/2-query/join.py
浏览文件 @
da8db399
...
...
@@ -28,7 +28,7 @@ class TDTestCase:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to excute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
Tru
e
)
tdSql
.
init
(
conn
.
cursor
(),
Fals
e
)
def
__query_condition
(
self
,
tbname
):
query_condition
=
[]
...
...
tests/system-test/2-query/join2.py
浏览文件 @
da8db399
...
...
@@ -28,7 +28,7 @@ class TDTestCase:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to excute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
(),
Tru
e
)
tdSql
.
init
(
conn
.
cursor
(),
Fals
e
)
def
__query_condition
(
self
,
tbname
):
query_condition
=
[]
...
...
tests/system-test/2-query/substr.py
浏览文件 @
da8db399
...
...
@@ -31,7 +31,7 @@ class TDTestCase:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to excute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
())
tdSql
.
init
(
conn
.
cursor
()
,
False
)
def
__substr_condition
(
self
):
# sourcery skip: extract-method
substr_condition
=
[]
...
...
tests/system-test/2-query/tail.py
浏览文件 @
da8db399
...
...
@@ -188,8 +188,8 @@ class TDTestCase:
def
check_tail_table
(
self
,
tbname
,
col_name
,
tail_rows
,
offset
):
tail_sql
=
f
"select tail(
{
col_name
}
,
{
tail_rows
}
,
{
offset
}
) from
{
tbname
}
"
equal_sql
=
f
"select
{
col_name
}
from (select ts ,
{
col_name
}
from
{
tbname
}
order by ts desc limit
{
tail_rows
}
offset
{
offset
}
) order by ts"
#
equal_sql = f"select {col_name} from {tbname} order by ts desc limit {tail_rows} offset {offset}"
#
equal_sql = f"select {col_name} from (select ts , {col_name} from {tbname} order by ts desc limit {tail_rows} offset {offset}) order by ts"
equal_sql
=
f
"select
{
col_name
}
from
{
tbname
}
order by ts desc limit
{
tail_rows
}
offset
{
offset
}
"
tdSql
.
query
(
tail_sql
)
tail_result
=
tdSql
.
queryResult
...
...
@@ -404,7 +404,7 @@ class TDTestCase:
f
"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
)
tdSql
.
query
(
"select tail(c2,2) from sub1_bound"
)
tdSql
.
query
(
"select tail(c2,2) from sub1_bound
order by 1 desc
"
)
tdSql
.
checkRows
(
2
)
tdSql
.
checkData
(
0
,
0
,
9223372036854775803
)
...
...
tests/system-test/fulltest.bat
已删除
100644 → 0
浏览文件 @
23a9c8f3
python3
.\test.py
-f
0
-others
\taosShell.py
python3
.\test.py
-f
0
-others
\taosShellError.py
python3
.\test.py
-f
0
-others
\taosShellNetChk.py
python3
.\test.py
-f
0
-others
\telemetry.py
python3
.\test.py
-f
0
-others
\taosdMonitor.py
python3
.\test.py
-f
0
-others
\udfTest.py
python3
.\test.py
-f
0
-others
\udf_create.py
python3
.\test.py
-f
0
-others
\udf_restart_taosd.py
python3
.\test.py
-f
0
-others
\cachelast.py
python3
.\test.py
-f
0
-others
\user_control.py
python3
.\test.py
-f
0
-others
\fsync.py
python3
.\test.py
-f
1
-insert
\influxdb_line_taosc_insert.py
python3
.\test.py
-f
1
-insert
\opentsdb_telnet_line_taosc_insert.py
python3
.\test.py
-f
1
-insert
\opentsdb_json_taosc_insert.py
@REM #python3 .\test.py -f 1-insert\test_stmt_muti_insert_query.py
python3
.\test.py
-f
1
-insert
\alter_stable.py
python3
.\test.py
-f
1
-insert
\alter_table.py
python3
.\test.py
-f
2
-query
\between.py
python3
.\test.py
-f
2
-query
\distinct.py
python3
.\test.py
-f
2
-query
\varchar.py
python3
.\test.py
-f
2
-query
\ltrim.py
python3
.\test.py
-f
2
-query
\rtrim.py
python3
.\test.py
-f
2
-query
\length.py
python3
.\test.py
-f
2
-query
\char_length.py
python3
.\test.py
-f
2
-query
\upper.py
python3
.\test.py
-f
2
-query
\lower.py
python3
.\test.py
-f
2
-query
\join.py
python3
.\test.py
-f
2
-query
\join2.py
python3
.\test.py
-f
2
-query
\cast.py
python3
.\test.py
-f
2
-query
\union.py
python3
.\test.py
-f
2
-query
\union1.py
python3
.\test.py
-f
2
-query
\concat.py
python3
.\test.py
-f
2
-query
\concat2.py
python3
.\test.py
-f
2
-query
\concat_ws.py
python3
.\test.py
-f
2
-query
\concat_ws2.py
python3
.\test.py
-f
2
-query
\check_tsdb.py
python3
.\test.py
-f
2
-query
\spread.py
python3
.\test.py
-f
2
-query
\hyperloglog.py
python3
.\test.py
-f
2
-query
\timezone.py
python3
.\test.py
-f
2
-query
\Now.py
python3
.\test.py
-f
2
-query
\Today.py
python3
.\test.py
-f
2
-query
\max.py
python3
.\test.py
-f
2
-query
\min.py
python3
.\test.py
-f
2
-query
\count.py
python3
.\test.py
-f
2
-query
\last.py
python3
.\test.py
-f
2
-query
\first.py
python3
.\test.py
-f
2
-query
\To_iso8601.py
python3
.\test.py
-f
2
-query
\To_unixtimestamp.py
python3
.\test.py
-f
2
-query
\timetruncate.py
python3
.\test.py
-f
2
-query
\diff.py
python3
.\test.py
-f
2
-query
\Timediff.py
python3
.\test.py
-f
2
-query
\top.py
python3
.\test.py
-f
2
-query
\bottom.py
python3
.\test.py
-f
2
-query
\percentile.py
python3
.\test.py
-f
2
-query
\apercentile.py
python3
.\test.py
-f
2
-query
\abs.py
python3
.\test.py
-f
2
-query
\ceil.py
python3
.\test.py
-f
2
-query
\floor.py
python3
.\test.py
-f
2
-query
\round.py
python3
.\test.py
-f
2
-query
\log.py
python3
.\test.py
-f
2
-query
\pow.py
python3
.\test.py
-f
2
-query
\sqrt.py
python3
.\test.py
-f
2
-query
\sin.py
python3
.\test.py
-f
2
-query
\cos.py
python3
.\test.py
-f
2
-query
\tan.py
python3
.\test.py
-f
2
-query
\arcsin.py
python3
.\test.py
-f
2
-query
\arccos.py
python3
.\test.py
-f
2
-query
\arctan.py
python3
.\test.py
-f
2
-query
\query_cols_tags_and_or.py
@REM # python3 .\test.py -f 2-query\nestedQuery.py
@REM # TD-15983 subquery output duplicate name column.
@REM # Please Xiangyang Guo modify the following script
@REM # python3 .\test.py -f 2-query\nestedQuery_str.py
python3
.\test.py
-f
2
-query
\avg.py
python3
.\test.py
-f
2
-query
\elapsed.py
python3
.\test.py
-f
2
-query
\csum.py
python3
.\test.py
-f
2
-query
\mavg.py
python3
.\test.py
-f
2
-query
\diff.py
python3
.\test.py
-f
2
-query
\sample.py
python3
.\test.py
-f
2
-query
\function_diff.py
python3
.\test.py
-f
2
-query
\unique.py
python3
.\test.py
-f
2
-query
\stateduration.py
python3
.\test.py
-f
2
-query
\function_stateduration.py
python3
.\test.py
-f
2
-query
\statecount.py
python3
.\test.py
-f
7
-tmq
\basic5.py
python3
.\test.py
-f
7
-tmq
\subscribeDb.py
python3
.\test.py
-f
7
-tmq
\subscribeDb0.py
python3
.\test.py
-f
7
-tmq
\subscribeDb1.py
python3
.\test.py
-f
7
-tmq
\subscribeStb.py
python3
.\test.py
-f
7
-tmq
\subscribeStb0.py
python3
.\test.py
-f
7
-tmq
\subscribeStb1.py
python3
.\test.py
-f
7
-tmq
\subscribeStb2.py
python3
.\test.py
-f
7
-tmq
\subscribeStb3.py
python3
.\test.py
-f
7
-tmq
\subscribeStb4.py
python3
.\test.py
-f
7
-tmq
\db.py
\ No newline at end of file
tests/system-test/test-all.bat
浏览文件 @
da8db399
...
...
@@ -6,19 +6,23 @@ if "%1" == "full" (
echo
Windows
Taosd
Full
Test
set
/a
exitNum
=
0
del
/Q /F
failed
.txt
set
caseFile
=
"fulltest.
bat
"
set
caseFile
=
"fulltest.
sh
"
if
not
"
%
2"
==
""
(
set
caseFile
=
"
%
2"
)
for
/F
"usebackq tokens=*"
%%i
in
(
!caseFile!
)
do
(
for
/f
"tokens=1* delims= "
%%a
in
(
"
%%i
"
)
do
if
not
"
%%a
"
==
"@REM"
(
set
/a
a
+=
1
echo
!a!
Processing
%%i
call
:GetTimeSeconds
!time!
set
time1
=
!_timeTemp!
echo
Start
at
!time!
call
%%i
ARG1
>
result_
!a!
.txt
2
>
error_
!a!
.txt
if
errorlevel
1
(
call
:colorEcho
0
c
"failed"
&
echo
.
&&
set
/a
exitNum
=
8
&&
echo
%%i
>>
failed
.txt
)
else
(
call
:colorEcho
0
a
"Success"
&
echo
.
)
call
:CheckSkipCase
%%i
if
!skipCase!
==
false
(
set
line
=
%%i
if
"
!
line:~,7
!
"
==
"python3"
(
set
/a
a
+=
1
echo
!a!
Processing
%%i
call
:GetTimeSeconds
!time!
set
time1
=
!_timeTemp!
echo
Start
at
!time!
call
%%i
ARG1
>
result_
!a!
.txt
2
>
error_
!a!
.txt
if
errorlevel
1
(
call
:colorEcho
0
c
"failed"
&
echo
.
&&
set
/a
exitNum
=
8
&&
echo
%%i
>>
failed
.txt
)
else
(
call
:colorEcho
0
a
"Success"
&
echo
.
)
)
)
)
exit
!exitNum!
...
...
@@ -83,3 +87,8 @@ for %%a in (%tt%) do (
)
set
/a
_timeTemp
=(
%hh%
*
60
+
%mm%
)*
60
+
%ss%
goto
:eof
:CheckSkipCase
set
skipCase
=
false
if
"
%
*"
==
"python3 ./test.py -f 1-insert/insertWithMoreVgroup.py"
(
set
skipCase
=
true
)
:goto
eof
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录