Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4fb1ef08
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4fb1ef08
编写于
7月 06, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' into feature/insertselect
上级
3a176190
9355392c
变更
64
展开全部
显示空白变更内容
内联
并排
Showing
64 changed file
with
1557 addition
and
1000 deletion
+1557
-1000
include/common/tmsg.h
include/common/tmsg.h
+7
-2
include/common/tmsgdef.h
include/common/tmsgdef.h
+7
-0
include/os/osMemory.h
include/os/osMemory.h
+1
-1
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+0
-1
source/client/src/clientMain.c
source/client/src/clientMain.c
+2
-3
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
+1
-2
source/dnode/mgmt/mgmt_vnode/src/vmInt.c
source/dnode/mgmt/mgmt_vnode/src/vmInt.c
+4
-3
source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
+16
-25
source/dnode/mgmt/node_mgmt/src/dmMgmt.c
source/dnode/mgmt/node_mgmt/src/dmMgmt.c
+1
-0
source/dnode/mgmt/node_mgmt/src/dmTransport.c
source/dnode/mgmt/node_mgmt/src/dmTransport.c
+5
-4
source/dnode/mnode/impl/src/mndMain.c
source/dnode/mnode/impl/src/mndMain.c
+2
-0
source/dnode/mnode/impl/src/mndVgroup.c
source/dnode/mnode/impl/src/mndVgroup.c
+6
-3
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+2
-2
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+1
-1
source/dnode/vnode/src/tq/tqOffset.c
source/dnode/vnode/src/tq/tqOffset.c
+1
-0
source/dnode/vnode/src/vnd/vnodeCfg.c
source/dnode/vnode/src/vnd/vnodeCfg.c
+33
-33
source/dnode/vnode/src/vnd/vnodeOpen.c
source/dnode/vnode/src/vnd/vnodeOpen.c
+1
-1
source/dnode/vnode/src/vnd/vnodeQuery.c
source/dnode/vnode/src/vnd/vnodeQuery.c
+7
-5
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+1
-1
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+174
-211
source/libs/command/src/command.c
source/libs/command/src/command.c
+2
-4
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+17
-0
source/libs/executor/src/executorMain.c
source/libs/executor/src/executorMain.c
+5
-1
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+125
-76
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+228
-36
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+28
-27
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+96
-7
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+9
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+17
-17
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+3
-19
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+83
-16
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+2
-1
source/libs/planner/test/planBasicTest.cpp
source/libs/planner/test/planBasicTest.cpp
+6
-0
source/libs/planner/test/planOptimizeTest.cpp
source/libs/planner/test/planOptimizeTest.cpp
+5
-0
source/libs/planner/test/planOtherTest.cpp
source/libs/planner/test/planOtherTest.cpp
+0
-7
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
-0
source/libs/planner/test/planTestUtil.h
source/libs/planner/test/planTestUtil.h
+1
-0
source/libs/scalar/src/sclfunc.c
source/libs/scalar/src/sclfunc.c
+16
-11
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+3
-3
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+2
-1
source/libs/sync/src/syncRespMgr.c
source/libs/sync/src/syncRespMgr.c
+57
-1
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+80
-36
source/libs/sync/test/syncIndexTest.cpp
source/libs/sync/test/syncIndexTest.cpp
+7
-1
source/libs/sync/test/syncRespMgrTest.cpp
source/libs/sync/test/syncRespMgrTest.cpp
+31
-4
source/libs/transport/inc/transComm.h
source/libs/transport/inc/transComm.h
+8
-8
source/libs/transport/src/transSvr.c
source/libs/transport/src/transSvr.c
+29
-18
source/os/src/osFile.c
source/os/src/osFile.c
+39
-5
source/os/src/osMemory.c
source/os/src/osMemory.c
+3
-3
source/util/src/tpagedbuf.c
source/util/src/tpagedbuf.c
+1
-0
tests/pytest/util/gettime.py
tests/pytest/util/gettime.py
+62
-0
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+1
-1
tests/script/sh/checkValgrind.sh
tests/script/sh/checkValgrind.sh
+6
-1
tests/script/tsim/stable/tag_modify.sim
tests/script/tsim/stable/tag_modify.sim
+2
-2
tests/script/tsim/stable/tag_rename.sim
tests/script/tsim/stable/tag_rename.sim
+3
-3
tests/script/tsim/valgrind/basic.sim
tests/script/tsim/valgrind/basic.sim
+1
-1
tests/script/tsim/valgrind/basic2.sim
tests/script/tsim/valgrind/basic2.sim
+25
-0
tests/script/tsim/valgrind/checkError.sim
tests/script/tsim/valgrind/checkError.sim
+25
-74
tests/system-test/1-insert/alter_stable.py
tests/system-test/1-insert/alter_stable.py
+5
-5
tests/system-test/2-query/Timediff.py
tests/system-test/2-query/Timediff.py
+158
-189
tests/system-test/2-query/distribute_agg_stddev.py
tests/system-test/2-query/distribute_agg_stddev.py
+26
-26
tests/system-test/2-query/timetruncate.py
tests/system-test/2-query/timetruncate.py
+42
-95
tests/system-test/fulltest.sh
tests/system-test/fulltest.sh
+2
-2
tests/system-test/simpletest.bat
tests/system-test/simpletest.bat
+1
-1
未找到文件。
include/common/tmsg.h
浏览文件 @
4fb1ef08
...
@@ -55,7 +55,12 @@ extern int32_t tMsgDict[];
...
@@ -55,7 +55,12 @@ extern int32_t tMsgDict[];
#define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8)
#define TMSG_SEG_CODE(TYPE) (((TYPE)&0xff00) >> 8)
#define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff)
#define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff)
#define TMSG_INFO(TYPE) tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)]
#define TMSG_INFO(TYPE) \
((TYPE) >= 0 && \
((TYPE) < TDMT_DND_MAX_MSG | (TYPE) < TDMT_MND_MAX_MSG | (TYPE) < TDMT_VND_MAX_MSG | (TYPE) < TDMT_SCH_MAX_MSG | \
(TYPE) < TDMT_STREAM_MAX_MSG | (TYPE) < TDMT_MON_MAX_MSG | (TYPE) < TDMT_SYNC_MAX_MSG)) \
? tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)] \
: 0
#define TMSG_INDEX(TYPE) (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE))
#define TMSG_INDEX(TYPE) (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE))
typedef
uint16_t
tmsg_t
;
typedef
uint16_t
tmsg_t
;
...
...
include/common/tmsgdef.h
浏览文件 @
4fb1ef08
...
@@ -82,6 +82,7 @@ enum {
...
@@ -82,6 +82,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_DND_NET_TEST
,
"net-test"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_NET_TEST
,
"net-test"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_CONFIG_DNODE
,
"config-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_CONFIG_DNODE
,
"config-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_SYSTABLE_RETRIEVE
,
"dnode-retrieve"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_SYSTABLE_RETRIEVE
,
"dnode-retrieve"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_DND_MAX_MSG
,
"dnd-max"
,
NULL
,
NULL
)
TD_NEW_MSG_SEG
(
TDMT_MND_MSG
)
TD_NEW_MSG_SEG
(
TDMT_MND_MSG
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CONNECT
,
"connect"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CONNECT
,
"connect"
,
NULL
,
NULL
)
...
@@ -164,6 +165,7 @@ enum {
...
@@ -164,6 +165,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_MND_SPLIT_VGROUP
,
"split-vgroup"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_SPLIT_VGROUP
,
"split-vgroup"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_SHOW_VARIABLES
,
"show-variables"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_SHOW_VARIABLES
,
"show-variables"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_SERVER_VERSION
,
"server-version"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_SERVER_VERSION
,
"server-version"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_MAX_MSG
,
"mnd-max"
,
NULL
,
NULL
)
TD_NEW_MSG_SEG
(
TDMT_VND_MSG
)
TD_NEW_MSG_SEG
(
TDMT_VND_MSG
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SUBMIT
,
"submit"
,
SSubmitReq
,
SSubmitRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SUBMIT
,
"submit"
,
SSubmitReq
,
SSubmitRsp
)
...
@@ -198,6 +200,7 @@ enum {
...
@@ -198,6 +200,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_VND_ALTER_HASHRANGE
,
"alter-hashrange"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_ALTER_HASHRANGE
,
"alter-hashrange"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_COMPACT
,
"compact"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_COMPACT
,
"compact"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_DROP_TTL_TABLE
,
"drop-ttl-stb"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_DROP_TTL_TABLE
,
"drop-ttl-stb"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_MAX_MSG
,
"vnd-max"
,
NULL
,
NULL
)
TD_NEW_MSG_SEG
(
TDMT_SCH_MSG
)
TD_NEW_MSG_SEG
(
TDMT_SCH_MSG
)
TD_DEF_MSG_TYPE
(
TDMT_SCH_QUERY
,
"query"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SCH_QUERY
,
"query"
,
NULL
,
NULL
)
...
@@ -209,6 +212,7 @@ enum {
...
@@ -209,6 +212,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_SCH_DROP_TASK
,
"drop-task"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SCH_DROP_TASK
,
"drop-task"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SCH_EXPLAIN
,
"explain"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SCH_EXPLAIN
,
"explain"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SCH_LINK_BROKEN
,
"link-broken"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SCH_LINK_BROKEN
,
"link-broken"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SCH_MAX_MSG
,
"sch-max"
,
NULL
,
NULL
)
TD_NEW_MSG_SEG
(
TDMT_STREAM_MSG
)
TD_NEW_MSG_SEG
(
TDMT_STREAM_MSG
)
TD_DEF_MSG_TYPE
(
TDMT_STREAM_TASK_DEPLOY
,
"stream-task-deploy"
,
SStreamTaskDeployReq
,
SStreamTaskDeployRsp
)
TD_DEF_MSG_TYPE
(
TDMT_STREAM_TASK_DEPLOY
,
"stream-task-deploy"
,
SStreamTaskDeployReq
,
SStreamTaskDeployRsp
)
...
@@ -217,6 +221,7 @@ enum {
...
@@ -217,6 +221,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_STREAM_TASK_DISPATCH
,
"stream-task-dispatch"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_STREAM_TASK_DISPATCH
,
"stream-task-dispatch"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_STREAM_TASK_RECOVER
,
"stream-task-recover"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_STREAM_TASK_RECOVER
,
"stream-task-recover"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_STREAM_RETRIEVE
,
"stream-retrieve"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_STREAM_RETRIEVE
,
"stream-retrieve"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_STREAM_MAX_MSG
,
"stream-max"
,
NULL
,
NULL
)
TD_NEW_MSG_SEG
(
TDMT_MON_MSG
)
TD_NEW_MSG_SEG
(
TDMT_MON_MSG
)
TD_DEF_MSG_TYPE
(
TDMT_MON_MM_INFO
,
"monitor-minfo"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_MM_INFO
,
"monitor-minfo"
,
NULL
,
NULL
)
...
@@ -227,6 +232,7 @@ enum {
...
@@ -227,6 +232,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_MON_VM_LOAD
,
"monitor-vload"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_VM_LOAD
,
"monitor-vload"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_MM_LOAD
,
"monitor-mload"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_MM_LOAD
,
"monitor-mload"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_QM_LOAD
,
"monitor-qload"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_QM_LOAD
,
"monitor-qload"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MON_MAX_MSG
,
"monitor-max"
,
NULL
,
NULL
)
TD_NEW_MSG_SEG
(
TDMT_SYNC_MSG
)
TD_NEW_MSG_SEG
(
TDMT_SYNC_MSG
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_TIMEOUT
,
"sync-timer"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_TIMEOUT
,
"sync-timer"
,
NULL
,
NULL
)
...
@@ -251,6 +257,7 @@ enum {
...
@@ -251,6 +257,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_SYNC_LEADER_TRANSFER
,
"sync-leader-transfer"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_LEADER_TRANSFER
,
"sync-leader-transfer"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SET_MNODE_STANDBY
,
"set-mnode-standby"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SET_MNODE_STANDBY
,
"set-mnode-standby"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SET_VNODE_STANDBY
,
"set-vnode-standby"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_SET_VNODE_STANDBY
,
"set-vnode-standby"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_SYNC_MAX_MSG
,
"sync-max"
,
NULL
,
NULL
)
#if defined(TD_MSG_NUMBER_)
#if defined(TD_MSG_NUMBER_)
TDMT_MAX
TDMT_MAX
...
...
include/os/osMemory.h
浏览文件 @
4fb1ef08
...
@@ -32,7 +32,7 @@ extern "C" {
...
@@ -32,7 +32,7 @@ extern "C" {
void
*
taosMemoryMalloc
(
int32_t
size
);
void
*
taosMemoryMalloc
(
int32_t
size
);
void
*
taosMemoryCalloc
(
int32_t
num
,
int32_t
size
);
void
*
taosMemoryCalloc
(
int32_t
num
,
int32_t
size
);
void
*
taosMemoryRealloc
(
void
*
ptr
,
int32_t
size
);
void
*
taosMemoryRealloc
(
void
*
ptr
,
int32_t
size
);
void
*
taosMemoryStrDup
(
void
*
ptr
);
void
*
taosMemoryStrDup
(
const
char
*
ptr
);
void
taosMemoryFree
(
void
*
ptr
);
void
taosMemoryFree
(
void
*
ptr
);
int32_t
taosMemorySize
(
void
*
ptr
);
int32_t
taosMemorySize
(
void
*
ptr
);
void
taosPrintBackTrace
();
void
taosPrintBackTrace
();
...
...
source/client/src/clientImpl.c
浏览文件 @
4fb1ef08
...
@@ -279,7 +279,6 @@ void asyncExecLocalCmd(SRequestObj* pRequest, SQuery* pQuery) {
...
@@ -279,7 +279,6 @@ void asyncExecLocalCmd(SRequestObj* pRequest, SQuery* pQuery) {
}
}
pRequest
->
body
.
queryFp
(
pRequest
->
body
.
param
,
pRequest
,
code
);
pRequest
->
body
.
queryFp
(
pRequest
->
body
.
param
,
pRequest
,
code
);
// pRequest->body.fetchFp(pRequest->body.param, pRequest, pResultInfo->numOfRows);
}
}
int32_t
asyncExecDdlQuery
(
SRequestObj
*
pRequest
,
SQuery
*
pQuery
)
{
int32_t
asyncExecDdlQuery
(
SRequestObj
*
pRequest
,
SQuery
*
pQuery
)
{
...
...
source/client/src/clientMain.c
浏览文件 @
4fb1ef08
...
@@ -665,8 +665,6 @@ static void destorySqlParseWrapper(SqlParseWrapper *pWrapper) {
...
@@ -665,8 +665,6 @@ static void destorySqlParseWrapper(SqlParseWrapper *pWrapper) {
}
}
void
retrieveMetaCallback
(
SMetaData
*
pResultMeta
,
void
*
param
,
int32_t
code
)
{
void
retrieveMetaCallback
(
SMetaData
*
pResultMeta
,
void
*
param
,
int32_t
code
)
{
tscDebug
(
"enter meta callback, code %s"
,
tstrerror
(
code
));
SqlParseWrapper
*
pWrapper
=
(
SqlParseWrapper
*
)
param
;
SqlParseWrapper
*
pWrapper
=
(
SqlParseWrapper
*
)
param
;
SQuery
*
pQuery
=
pWrapper
->
pQuery
;
SQuery
*
pQuery
=
pWrapper
->
pQuery
;
SRequestObj
*
pRequest
=
pWrapper
->
pRequest
;
SRequestObj
*
pRequest
=
pWrapper
->
pRequest
;
...
@@ -686,10 +684,11 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) {
...
@@ -686,10 +684,11 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) {
TSWAP
(
pRequest
->
tableList
,
(
pQuery
)
->
pTableList
);
TSWAP
(
pRequest
->
tableList
,
(
pQuery
)
->
pTableList
);
destorySqlParseWrapper
(
pWrapper
);
destorySqlParseWrapper
(
pWrapper
);
tscDebug
(
"0x%"
PRIx64
" analysis semantics completed, start async query, reqId:0x%"
PRIx64
,
pRequest
->
self
,
pRequest
->
requestId
);
launchAsyncQuery
(
pRequest
,
pQuery
,
pResultMeta
);
launchAsyncQuery
(
pRequest
,
pQuery
,
pResultMeta
);
}
else
{
}
else
{
destorySqlParseWrapper
(
pWrapper
);
destorySqlParseWrapper
(
pWrapper
);
tscDebug
(
"error happens, code:%d"
,
code
);
if
(
NEED_CLIENT_HANDLE_ERROR
(
code
))
{
if
(
NEED_CLIENT_HANDLE_ERROR
(
code
))
{
tscDebug
(
"0x%"
PRIx64
" client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%"
PRIx64
,
tscDebug
(
"0x%"
PRIx64
" client retry to handle the error, code:%d - %s, tryCount:%d, reqId:0x%"
PRIx64
,
pRequest
->
self
,
code
,
tstrerror
(
code
),
pRequest
->
retry
,
pRequest
->
requestId
);
pRequest
->
self
,
code
,
tstrerror
(
code
),
pRequest
->
retry
,
pRequest
->
requestId
);
...
...
source/dnode/mgmt/mgmt_vnode/src/vmFile.c
浏览文件 @
4fb1ef08
...
@@ -32,8 +32,7 @@ SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
...
@@ -32,8 +32,7 @@ SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
if
(
pVnode
&&
num
<
size
)
{
if
(
pVnode
&&
num
<
size
)
{
int32_t
refCount
=
atomic_add_fetch_32
(
&
pVnode
->
refCount
,
1
);
int32_t
refCount
=
atomic_add_fetch_32
(
&
pVnode
->
refCount
,
1
);
// dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount);
// dTrace("vgId:%d, acquire vnode, refCount:%d", pVnode->vgId, refCount);
pVnodes
[
num
]
=
(
*
ppVnode
);
pVnodes
[
num
++
]
=
(
*
ppVnode
);
num
++
;
pIter
=
taosHashIterate
(
pMgmt
->
hash
,
pIter
);
pIter
=
taosHashIterate
(
pMgmt
->
hash
,
pIter
);
}
else
{
}
else
{
taosHashCancelIterate
(
pMgmt
->
hash
,
pIter
);
taosHashCancelIterate
(
pMgmt
->
hash
,
pIter
);
...
...
source/dnode/mgmt/mgmt_vnode/src/vmInt.c
浏览文件 @
4fb1ef08
...
@@ -88,7 +88,7 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
...
@@ -88,7 +88,7 @@ void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
while
(
!
taosQueueEmpty
(
pVnode
->
pApplyQ
))
taosMsleep
(
10
);
while
(
!
taosQueueEmpty
(
pVnode
->
pApplyQ
))
taosMsleep
(
10
);
while
(
!
taosQueueEmpty
(
pVnode
->
pQueryQ
))
taosMsleep
(
10
);
while
(
!
taosQueueEmpty
(
pVnode
->
pQueryQ
))
taosMsleep
(
10
);
while
(
!
taosQueueEmpty
(
pVnode
->
pFetchQ
))
taosMsleep
(
10
);
while
(
!
taosQueueEmpty
(
pVnode
->
pFetchQ
))
taosMsleep
(
10
);
dTrace
(
"vgId:%d, vnode
-fetch
queue is empty"
,
pVnode
->
vgId
);
dTrace
(
"vgId:%d, vnode queue is empty"
,
pVnode
->
vgId
);
vmFreeQueue
(
pMgmt
,
pVnode
);
vmFreeQueue
(
pMgmt
,
pVnode
);
vnodeClose
(
pVnode
->
pImpl
);
vnodeClose
(
pVnode
->
pImpl
);
...
@@ -140,7 +140,7 @@ static void *vmOpenVnodeInThread(void *param) {
...
@@ -140,7 +140,7 @@ static void *vmOpenVnodeInThread(void *param) {
}
}
static
int32_t
vmOpenVnodes
(
SVnodeMgmt
*
pMgmt
)
{
static
int32_t
vmOpenVnodes
(
SVnodeMgmt
*
pMgmt
)
{
pMgmt
->
hash
=
taosHashInit
(
TSDB_MIN_VNODES
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_
NO
_LOCK
);
pMgmt
->
hash
=
taosHashInit
(
TSDB_MIN_VNODES
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_
ENTRY
_LOCK
);
if
(
pMgmt
->
hash
==
NULL
)
{
if
(
pMgmt
->
hash
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
dError
(
"failed to init vnode hash since %s"
,
terrstr
());
dError
(
"failed to init vnode hash since %s"
,
terrstr
());
...
@@ -156,7 +156,8 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) {
...
@@ -156,7 +156,8 @@ static int32_t vmOpenVnodes(SVnodeMgmt *pMgmt) {
pMgmt
->
state
.
totalVnodes
=
numOfVnodes
;
pMgmt
->
state
.
totalVnodes
=
numOfVnodes
;
int32_t
threadNum
=
1
;
int32_t
threadNum
=
tsNumOfCores
/
2
;
if
(
threadNum
<
1
)
threadNum
=
1
;
int32_t
vnodesPerThread
=
numOfVnodes
/
threadNum
+
1
;
int32_t
vnodesPerThread
=
numOfVnodes
/
threadNum
+
1
;
SVnodeThread
*
threads
=
taosMemoryCalloc
(
threadNum
,
sizeof
(
SVnodeThread
));
SVnodeThread
*
threads
=
taosMemoryCalloc
(
threadNum
,
sizeof
(
SVnodeThread
));
...
...
source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
浏览文件 @
4fb1ef08
...
@@ -107,35 +107,13 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
...
@@ -107,35 +107,13 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
dGTrace
(
"vgId:%d, msg:%p get from vnode-sync queue"
,
pVnode
->
vgId
,
pMsg
);
dGTrace
(
"vgId:%d, msg:%p get from vnode-sync queue"
,
pVnode
->
vgId
,
pMsg
);
int32_t
code
=
vnodeProcessSync
Req
(
pVnode
->
pImpl
,
pMsg
,
NULL
);
// no response here
int32_t
code
=
vnodeProcessSync
Msg
(
pVnode
->
pImpl
,
pMsg
,
NULL
);
// no response here
dGTrace
(
"vgId:%d, msg:%p is freed, code:0x%x"
,
pVnode
->
vgId
,
pMsg
,
code
);
dGTrace
(
"vgId:%d, msg:%p is freed, code:0x%x"
,
pVnode
->
vgId
,
pMsg
,
code
);
rpcFreeCont
(
pMsg
->
pCont
);
rpcFreeCont
(
pMsg
->
pCont
);
taosFreeQitem
(
pMsg
);
taosFreeQitem
(
pMsg
);
}
}
}
}
static
void
vmProcessMergeQueue
(
SQueueInfo
*
pInfo
,
STaosQall
*
qall
,
int32_t
numOfMsgs
)
{
SVnodeObj
*
pVnode
=
pInfo
->
ahandle
;
SRpcMsg
*
pMsg
=
NULL
;
for
(
int32_t
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
if
(
taosGetQitem
(
qall
,
(
void
**
)
&
pMsg
)
==
0
)
continue
;
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
dGTrace
(
"vgId:%d, msg:%p get from vnode-merge queue"
,
pVnode
->
vgId
,
pMsg
);
int32_t
code
=
vnodeProcessFetchMsg
(
pVnode
->
pImpl
,
pMsg
,
pInfo
);
if
(
code
!=
0
)
{
if
(
terrno
!=
0
)
code
=
terrno
;
dGError
(
"vgId:%d, msg:%p failed to merge since %s"
,
pVnode
->
vgId
,
pMsg
,
terrstr
());
vmSendRsp
(
pMsg
,
code
);
}
dGTrace
(
"msg:%p, is freed, code:0x%x"
,
pMsg
,
code
);
rpcFreeCont
(
pMsg
->
pCont
);
taosFreeQitem
(
pMsg
);
}
}
static
int32_t
vmPutMsgToQueue
(
SVnodeMgmt
*
pMgmt
,
SRpcMsg
*
pMsg
,
EQueueType
qtype
)
{
static
int32_t
vmPutMsgToQueue
(
SVnodeMgmt
*
pMgmt
,
SRpcMsg
*
pMsg
,
EQueueType
qtype
)
{
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
SMsgHead
*
pHead
=
pMsg
->
pCont
;
SMsgHead
*
pHead
=
pMsg
->
pCont
;
...
@@ -207,7 +185,11 @@ int32_t vmPutMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
...
@@ -207,7 +185,11 @@ int32_t vmPutMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
int32_t
vmPutRpcMsgToQueue
(
SVnodeMgmt
*
pMgmt
,
EQueueType
qtype
,
SRpcMsg
*
pRpc
)
{
int32_t
vmPutRpcMsgToQueue
(
SVnodeMgmt
*
pMgmt
,
EQueueType
qtype
,
SRpcMsg
*
pRpc
)
{
SRpcMsg
*
pMsg
=
taosAllocateQitem
(
sizeof
(
SRpcMsg
),
RPC_QITEM
);
SRpcMsg
*
pMsg
=
taosAllocateQitem
(
sizeof
(
SRpcMsg
),
RPC_QITEM
);
if
(
pMsg
==
NULL
)
return
-
1
;
if
(
pMsg
==
NULL
)
{
rpcFreeCont
(
pMsg
->
pCont
);
pRpc
->
pCont
=
NULL
;
return
-
1
;
}
SMsgHead
*
pHead
=
pRpc
->
pCont
;
SMsgHead
*
pHead
=
pRpc
->
pCont
;
dTrace
(
"vgId:%d, msg:%p is created, type:%s"
,
pHead
->
vgId
,
pMsg
,
TMSG_INFO
(
pRpc
->
msgType
));
dTrace
(
"vgId:%d, msg:%p is created, type:%s"
,
pHead
->
vgId
,
pMsg
,
TMSG_INFO
(
pRpc
->
msgType
));
...
@@ -215,7 +197,16 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
...
@@ -215,7 +197,16 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
pHead
->
contLen
=
htonl
(
pHead
->
contLen
);
pHead
->
contLen
=
htonl
(
pHead
->
contLen
);
pHead
->
vgId
=
htonl
(
pHead
->
vgId
);
pHead
->
vgId
=
htonl
(
pHead
->
vgId
);
memcpy
(
pMsg
,
pRpc
,
sizeof
(
SRpcMsg
));
memcpy
(
pMsg
,
pRpc
,
sizeof
(
SRpcMsg
));
return
vmPutMsgToQueue
(
pMgmt
,
pMsg
,
qtype
);
int32_t
code
=
vmPutMsgToQueue
(
pMgmt
,
pMsg
,
qtype
);
if
(
code
!=
0
)
{
dTrace
(
"msg:%p, is freed"
,
pMsg
);
taosFreeQitem
(
pMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
pRpc
->
pCont
=
NULL
;
}
return
code
;
}
}
int32_t
vmGetQueueSize
(
SVnodeMgmt
*
pMgmt
,
int32_t
vgId
,
EQueueType
qtype
)
{
int32_t
vmGetQueueSize
(
SVnodeMgmt
*
pMgmt
,
int32_t
vgId
,
EQueueType
qtype
)
{
...
...
source/dnode/mgmt/node_mgmt/src/dmMgmt.c
浏览文件 @
4fb1ef08
...
@@ -212,6 +212,7 @@ void dmCleanupDnode(SDnode *pDnode) {
...
@@ -212,6 +212,7 @@ void dmCleanupDnode(SDnode *pDnode) {
dmCleanupClient
(
pDnode
);
dmCleanupClient
(
pDnode
);
dmCleanupServer
(
pDnode
);
dmCleanupServer
(
pDnode
);
dmClearVars
(
pDnode
);
dmClearVars
(
pDnode
);
rpcCleanup
();
dDebug
(
"dnode is closed, ptr:%p"
,
pDnode
);
dDebug
(
"dnode is closed, ptr:%p"
,
pDnode
);
}
}
...
...
source/dnode/mgmt/node_mgmt/src/dmTransport.c
浏览文件 @
4fb1ef08
...
@@ -71,9 +71,9 @@ int32_t dmProcessNodeMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
...
@@ -71,9 +71,9 @@ int32_t dmProcessNodeMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
}
}
static
void
dmProcessRpcMsg
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpc
,
SEpSet
*
pEpSet
)
{
static
void
dmProcessRpcMsg
(
SDnode
*
pDnode
,
SRpcMsg
*
pRpc
,
SEpSet
*
pEpSet
)
{
SDnodeTrans
*
pTrans
=
&
pDnode
->
trans
;
SDnodeTrans
*
pTrans
=
&
pDnode
->
trans
;
int32_t
code
=
-
1
;
int32_t
code
=
-
1
;
SRpcMsg
*
pMsg
=
NULL
;
SRpcMsg
*
pMsg
=
NULL
;
SMgmtWrapper
*
pWrapper
=
NULL
;
SMgmtWrapper
*
pWrapper
=
NULL
;
SDnodeHandle
*
pHandle
=
&
pTrans
->
msgHandles
[
TMSG_INDEX
(
pRpc
->
msgType
)];
SDnodeHandle
*
pHandle
=
&
pTrans
->
msgHandles
[
TMSG_INDEX
(
pRpc
->
msgType
)];
...
@@ -185,6 +185,7 @@ _OVER:
...
@@ -185,6 +185,7 @@ _OVER:
taosFreeQitem
(
pMsg
);
taosFreeQitem
(
pMsg
);
}
}
rpcFreeCont
(
pRpc
->
pCont
);
rpcFreeCont
(
pRpc
->
pCont
);
pRpc
->
pCont
=
NULL
;
}
}
dmReleaseWrapper
(
pWrapper
);
dmReleaseWrapper
(
pWrapper
);
...
@@ -195,11 +196,11 @@ int32_t dmInitMsgHandle(SDnode *pDnode) {
...
@@ -195,11 +196,11 @@ int32_t dmInitMsgHandle(SDnode *pDnode) {
for
(
EDndNodeType
ntype
=
DNODE
;
ntype
<
NODE_END
;
++
ntype
)
{
for
(
EDndNodeType
ntype
=
DNODE
;
ntype
<
NODE_END
;
++
ntype
)
{
SMgmtWrapper
*
pWrapper
=
&
pDnode
->
wrappers
[
ntype
];
SMgmtWrapper
*
pWrapper
=
&
pDnode
->
wrappers
[
ntype
];
SArray
*
pArray
=
(
*
pWrapper
->
func
.
getHandlesFp
)();
SArray
*
pArray
=
(
*
pWrapper
->
func
.
getHandlesFp
)();
if
(
pArray
==
NULL
)
return
-
1
;
if
(
pArray
==
NULL
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pArray
);
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pArray
);
++
i
)
{
SMgmtHandle
*
pMgmt
=
taosArrayGet
(
pArray
,
i
);
SMgmtHandle
*
pMgmt
=
taosArrayGet
(
pArray
,
i
);
SDnodeHandle
*
pHandle
=
&
pTrans
->
msgHandles
[
TMSG_INDEX
(
pMgmt
->
msgType
)];
SDnodeHandle
*
pHandle
=
&
pTrans
->
msgHandles
[
TMSG_INDEX
(
pMgmt
->
msgType
)];
if
(
pMgmt
->
needCheckVgId
)
{
if
(
pMgmt
->
needCheckVgId
)
{
pHandle
->
needCheckVgId
=
pMgmt
->
needCheckVgId
;
pHandle
->
needCheckVgId
=
pMgmt
->
needCheckVgId
;
...
...
source/dnode/mnode/impl/src/mndMain.c
浏览文件 @
4fb1ef08
...
@@ -519,6 +519,8 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
...
@@ -519,6 +519,8 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
}
}
}
}
syncNodeRelease
(
pSyncNode
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
}
}
...
...
source/dnode/mnode/impl/src/mndVgroup.c
浏览文件 @
4fb1ef08
...
@@ -739,10 +739,13 @@ int64_t mndGetVgroupMemory(SMnode *pMnode, SDbObj *pDbInput, SVgObj *pVgroup) {
...
@@ -739,10 +739,13 @@ int64_t mndGetVgroupMemory(SMnode *pMnode, SDbObj *pDbInput, SVgObj *pVgroup) {
pDb
=
mndAcquireDb
(
pMnode
,
pVgroup
->
dbName
);
pDb
=
mndAcquireDb
(
pMnode
,
pVgroup
->
dbName
);
}
}
int64_t
vgroupMemroy
=
(
int64_t
)
pDb
->
cfg
.
buffer
*
1024
*
1024
+
(
int64_t
)
pDb
->
cfg
.
pages
*
pDb
->
cfg
.
pageSize
*
1024
;
int64_t
vgroupMemroy
=
0
;
if
(
pDb
!=
NULL
)
{
vgroupMemroy
=
(
int64_t
)
pDb
->
cfg
.
buffer
*
1024
*
1024
+
(
int64_t
)
pDb
->
cfg
.
pages
*
pDb
->
cfg
.
pageSize
*
1024
;
if
(
pDb
->
cfg
.
cacheLastRow
>
0
)
{
if
(
pDb
->
cfg
.
cacheLastRow
>
0
)
{
vgroupMemroy
+=
(
int64_t
)
pDb
->
cfg
.
lastRowMem
*
1024
*
1024
;
vgroupMemroy
+=
(
int64_t
)
pDb
->
cfg
.
lastRowMem
*
1024
*
1024
;
}
}
}
if
(
pDbInput
==
NULL
)
{
if
(
pDbInput
==
NULL
)
{
mndReleaseDb
(
pMnode
,
pDb
);
mndReleaseDb
(
pMnode
,
pDb
);
...
...
source/dnode/vnode/inc/vnode.h
浏览文件 @
4fb1ef08
...
@@ -52,10 +52,10 @@ int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs);
...
@@ -52,10 +52,10 @@ int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs);
void
vnodeDestroy
(
const
char
*
path
,
STfs
*
pTfs
);
void
vnodeDestroy
(
const
char
*
path
,
STfs
*
pTfs
);
SVnode
*
vnodeOpen
(
const
char
*
path
,
STfs
*
pTfs
,
SMsgCb
msgCb
);
SVnode
*
vnodeOpen
(
const
char
*
path
,
STfs
*
pTfs
,
SMsgCb
msgCb
);
void
vnodeClose
(
SVnode
*
pVnode
);
void
vnodeClose
(
SVnode
*
pVnode
);
int32_t
vnodePre
p
rocessReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
int32_t
vnodePre
P
rocessReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
int32_t
vnodeProcessWriteReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
int64_t
version
,
SRpcMsg
*
pRsp
);
int32_t
vnodeProcessWriteReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
int64_t
version
,
SRpcMsg
*
pRsp
);
int32_t
vnodeProcessCMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
int32_t
vnodeProcessCMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
int32_t
vnodeProcessSync
Req
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
int32_t
vnodeProcessSync
Msg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
int32_t
vnodePreprocessQueryMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
int32_t
vnodePreprocessQueryMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
int32_t
vnodeProcessQueryMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
int32_t
vnodeProcessQueryMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
int32_t
vnodeProcessFetchMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SQueueInfo
*
pInfo
);
int32_t
vnodeProcessFetchMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SQueueInfo
*
pInfo
);
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
4fb1ef08
...
@@ -240,7 +240,7 @@ struct SVnode {
...
@@ -240,7 +240,7 @@ struct SVnode {
SSink
*
pSink
;
SSink
*
pSink
;
tsem_t
canCommit
;
tsem_t
canCommit
;
int64_t
sync
;
int64_t
sync
;
int32_t
sync
Count
;
int32_t
block
Count
;
tsem_t
syncSem
;
tsem_t
syncSem
;
SQHandle
*
pQuery
;
SQHandle
*
pQuery
;
};
};
...
...
source/dnode/vnode/src/tq/tqOffset.c
浏览文件 @
4fb1ef08
...
@@ -85,6 +85,7 @@ STqOffsetStore* tqOffsetOpen(STQ* pTq) {
...
@@ -85,6 +85,7 @@ STqOffsetStore* tqOffsetOpen(STQ* pTq) {
void
tqOffsetClose
(
STqOffsetStore
*
pStore
)
{
void
tqOffsetClose
(
STqOffsetStore
*
pStore
)
{
tqOffsetSnapshot
(
pStore
);
tqOffsetSnapshot
(
pStore
);
taosHashCleanup
(
pStore
->
pHash
);
taosHashCleanup
(
pStore
->
pHash
);
taosMemoryFree
(
pStore
);
}
}
STqOffset
*
tqOffsetRead
(
STqOffsetStore
*
pStore
,
const
char
*
subscribeKey
)
{
STqOffset
*
tqOffsetRead
(
STqOffsetStore
*
pStore
,
const
char
*
subscribeKey
)
{
...
...
source/dnode/vnode/src/vnd/vnodeCfg.c
浏览文件 @
4fb1ef08
...
@@ -79,7 +79,7 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
...
@@ -79,7 +79,7 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
SJson
*
pNodeRetentions
=
tjsonCreateArray
();
SJson
*
pNodeRetentions
=
tjsonCreateArray
();
tjsonAddItemToObject
(
pJson
,
"retentions"
,
pNodeRetentions
);
tjsonAddItemToObject
(
pJson
,
"retentions"
,
pNodeRetentions
);
for
(
int32_t
i
=
0
;
i
<
nRetention
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
nRetention
;
++
i
)
{
SJson
*
pNodeRetention
=
tjsonCreateObject
();
SJson
*
pNodeRetention
=
tjsonCreateObject
();
const
SRetention
*
pRetention
=
pCfg
->
tsdbCfg
.
retentions
+
i
;
const
SRetention
*
pRetention
=
pCfg
->
tsdbCfg
.
retentions
+
i
;
tjsonAddIntegerToObject
(
pNodeRetention
,
"freq"
,
pRetention
->
freq
);
tjsonAddIntegerToObject
(
pNodeRetention
,
"freq"
,
pRetention
->
freq
);
tjsonAddIntegerToObject
(
pNodeRetention
,
"freqUnit"
,
pRetention
->
freqUnit
);
tjsonAddIntegerToObject
(
pNodeRetention
,
"freqUnit"
,
pRetention
->
freqUnit
);
...
@@ -118,45 +118,45 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
...
@@ -118,45 +118,45 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
int32_t
code
;
int32_t
code
;
tjsonGetNumberValue
(
pJson
,
"vgId"
,
pCfg
->
vgId
,
code
);
tjsonGetNumberValue
(
pJson
,
"vgId"
,
pCfg
->
vgId
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
if
(
tjsonGetStringValue
(
pJson
,
"dbname"
,
pCfg
->
dbname
)
<
0
)
return
-
1
;
if
(
tjsonGetStringValue
(
pJson
,
"dbname"
,
pCfg
->
dbname
)
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"dbId"
,
pCfg
->
dbId
,
code
);
tjsonGetNumberValue
(
pJson
,
"dbId"
,
pCfg
->
dbId
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"szPage"
,
pCfg
->
szPage
,
code
);
tjsonGetNumberValue
(
pJson
,
"szPage"
,
pCfg
->
szPage
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"szCache"
,
pCfg
->
szCache
,
code
);
tjsonGetNumberValue
(
pJson
,
"szCache"
,
pCfg
->
szCache
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"szBuf"
,
pCfg
->
szBuf
,
code
);
tjsonGetNumberValue
(
pJson
,
"szBuf"
,
pCfg
->
szBuf
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"isHeap"
,
pCfg
->
isHeap
,
code
);
tjsonGetNumberValue
(
pJson
,
"isHeap"
,
pCfg
->
isHeap
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"isWeak"
,
pCfg
->
isWeak
,
code
);
tjsonGetNumberValue
(
pJson
,
"isWeak"
,
pCfg
->
isWeak
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"isTsma"
,
pCfg
->
isTsma
,
code
);
tjsonGetNumberValue
(
pJson
,
"isTsma"
,
pCfg
->
isTsma
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"isRsma"
,
pCfg
->
isRsma
,
code
);
tjsonGetNumberValue
(
pJson
,
"isRsma"
,
pCfg
->
isRsma
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"precision"
,
pCfg
->
tsdbCfg
.
precision
,
code
);
tjsonGetNumberValue
(
pJson
,
"precision"
,
pCfg
->
tsdbCfg
.
precision
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"update"
,
pCfg
->
tsdbCfg
.
update
,
code
);
tjsonGetNumberValue
(
pJson
,
"update"
,
pCfg
->
tsdbCfg
.
update
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"compression"
,
pCfg
->
tsdbCfg
.
compression
,
code
);
tjsonGetNumberValue
(
pJson
,
"compression"
,
pCfg
->
tsdbCfg
.
compression
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"slLevel"
,
pCfg
->
tsdbCfg
.
slLevel
,
code
);
tjsonGetNumberValue
(
pJson
,
"slLevel"
,
pCfg
->
tsdbCfg
.
slLevel
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"daysPerFile"
,
pCfg
->
tsdbCfg
.
days
,
code
);
tjsonGetNumberValue
(
pJson
,
"daysPerFile"
,
pCfg
->
tsdbCfg
.
days
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"minRows"
,
pCfg
->
tsdbCfg
.
minRows
,
code
);
tjsonGetNumberValue
(
pJson
,
"minRows"
,
pCfg
->
tsdbCfg
.
minRows
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"maxRows"
,
pCfg
->
tsdbCfg
.
maxRows
,
code
);
tjsonGetNumberValue
(
pJson
,
"maxRows"
,
pCfg
->
tsdbCfg
.
maxRows
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"keep0"
,
pCfg
->
tsdbCfg
.
keep0
,
code
);
tjsonGetNumberValue
(
pJson
,
"keep0"
,
pCfg
->
tsdbCfg
.
keep0
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"keep1"
,
pCfg
->
tsdbCfg
.
keep1
,
code
);
tjsonGetNumberValue
(
pJson
,
"keep1"
,
pCfg
->
tsdbCfg
.
keep1
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"keep2"
,
pCfg
->
tsdbCfg
.
keep2
,
code
);
tjsonGetNumberValue
(
pJson
,
"keep2"
,
pCfg
->
tsdbCfg
.
keep2
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
SJson
*
pNodeRetentions
=
tjsonGetObjectItem
(
pJson
,
"retentions"
);
SJson
*
pNodeRetentions
=
tjsonGetObjectItem
(
pJson
,
"retentions"
);
int32_t
nRetention
=
tjsonGetArraySize
(
pNodeRetentions
);
int32_t
nRetention
=
tjsonGetArraySize
(
pNodeRetentions
);
if
(
nRetention
>
TSDB_RETENTION_MAX
)
{
if
(
nRetention
>
TSDB_RETENTION_MAX
)
{
nRetention
=
TSDB_RETENTION_MAX
;
nRetention
=
TSDB_RETENTION_MAX
;
...
@@ -170,30 +170,30 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
...
@@ -170,30 +170,30 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
tjsonGetNumberValue
(
pNodeRetention
,
"keepUnit"
,
(
pCfg
->
tsdbCfg
.
retentions
)[
i
].
keepUnit
,
code
);
tjsonGetNumberValue
(
pNodeRetention
,
"keepUnit"
,
(
pCfg
->
tsdbCfg
.
retentions
)[
i
].
keepUnit
,
code
);
}
}
tjsonGetNumberValue
(
pJson
,
"wal.vgId"
,
pCfg
->
walCfg
.
vgId
,
code
);
tjsonGetNumberValue
(
pJson
,
"wal.vgId"
,
pCfg
->
walCfg
.
vgId
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"wal.fsyncPeriod"
,
pCfg
->
walCfg
.
fsyncPeriod
,
code
);
tjsonGetNumberValue
(
pJson
,
"wal.fsyncPeriod"
,
pCfg
->
walCfg
.
fsyncPeriod
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"wal.retentionPeriod"
,
pCfg
->
walCfg
.
retentionPeriod
,
code
);
tjsonGetNumberValue
(
pJson
,
"wal.retentionPeriod"
,
pCfg
->
walCfg
.
retentionPeriod
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"wal.rollPeriod"
,
pCfg
->
walCfg
.
rollPeriod
,
code
);
tjsonGetNumberValue
(
pJson
,
"wal.rollPeriod"
,
pCfg
->
walCfg
.
rollPeriod
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"wal.retentionSize"
,
pCfg
->
walCfg
.
retentionSize
,
code
);
tjsonGetNumberValue
(
pJson
,
"wal.retentionSize"
,
pCfg
->
walCfg
.
retentionSize
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"wal.segSize"
,
pCfg
->
walCfg
.
segSize
,
code
);
tjsonGetNumberValue
(
pJson
,
"wal.segSize"
,
pCfg
->
walCfg
.
segSize
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"wal.level"
,
pCfg
->
walCfg
.
level
,
code
);
tjsonGetNumberValue
(
pJson
,
"wal.level"
,
pCfg
->
walCfg
.
level
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"hashBegin"
,
pCfg
->
hashBegin
,
code
);
tjsonGetNumberValue
(
pJson
,
"hashBegin"
,
pCfg
->
hashBegin
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"hashEnd"
,
pCfg
->
hashEnd
,
code
);
tjsonGetNumberValue
(
pJson
,
"hashEnd"
,
pCfg
->
hashEnd
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"hashMethod"
,
pCfg
->
hashMethod
,
code
);
tjsonGetNumberValue
(
pJson
,
"hashMethod"
,
pCfg
->
hashMethod
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"syncCfg.replicaNum"
,
pCfg
->
syncCfg
.
replicaNum
,
code
);
tjsonGetNumberValue
(
pJson
,
"syncCfg.replicaNum"
,
pCfg
->
syncCfg
.
replicaNum
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
tjsonGetNumberValue
(
pJson
,
"syncCfg.myIndex"
,
pCfg
->
syncCfg
.
myIndex
,
code
);
tjsonGetNumberValue
(
pJson
,
"syncCfg.myIndex"
,
pCfg
->
syncCfg
.
myIndex
,
code
);
if
(
code
<
0
)
return
-
1
;
if
(
code
<
0
)
return
-
1
;
SJson
*
pNodeInfoArr
=
tjsonGetObjectItem
(
pJson
,
"syncCfg.nodeInfo"
);
SJson
*
pNodeInfoArr
=
tjsonGetObjectItem
(
pJson
,
"syncCfg.nodeInfo"
);
int
arraySize
=
tjsonGetArraySize
(
pNodeInfoArr
);
int
arraySize
=
tjsonGetArraySize
(
pNodeInfoArr
);
...
...
source/dnode/vnode/src/vnd/vnodeOpen.c
浏览文件 @
4fb1ef08
...
@@ -81,7 +81,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
...
@@ -81,7 +81,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
pVnode
->
state
.
applied
=
info
.
state
.
committed
;
pVnode
->
state
.
applied
=
info
.
state
.
committed
;
pVnode
->
pTfs
=
pTfs
;
pVnode
->
pTfs
=
pTfs
;
pVnode
->
msgCb
=
msgCb
;
pVnode
->
msgCb
=
msgCb
;
pVnode
->
sync
Count
=
0
;
pVnode
->
block
Count
=
0
;
tsem_init
(
&
pVnode
->
syncSem
,
0
,
0
);
tsem_init
(
&
pVnode
->
syncSem
,
0
,
0
);
tsem_init
(
&
(
pVnode
->
canCommit
),
0
,
1
);
tsem_init
(
&
(
pVnode
->
canCommit
),
0
,
1
);
...
...
source/dnode/vnode/src/vnd/vnodeQuery.c
浏览文件 @
4fb1ef08
...
@@ -27,10 +27,10 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
...
@@ -27,10 +27,10 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
SMetaReader
mer1
=
{
0
};
SMetaReader
mer1
=
{
0
};
SMetaReader
mer2
=
{
0
};
SMetaReader
mer2
=
{
0
};
char
tableFName
[
TSDB_TABLE_FNAME_LEN
];
char
tableFName
[
TSDB_TABLE_FNAME_LEN
];
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
=
{
0
}
;
int32_t
code
=
0
;
int32_t
code
=
0
;
int32_t
rspLen
=
0
;
int32_t
rspLen
=
0
;
void
*
pRsp
=
NULL
;
void
*
pRsp
=
NULL
;
SSchemaWrapper
schema
=
{
0
};
SSchemaWrapper
schema
=
{
0
};
SSchemaWrapper
schemaTag
=
{
0
};
SSchemaWrapper
schemaTag
=
{
0
};
...
@@ -111,6 +111,7 @@ _exit:
...
@@ -111,6 +111,7 @@ _exit:
rpcMsg
.
pCont
=
pRsp
;
rpcMsg
.
pCont
=
pRsp
;
rpcMsg
.
contLen
=
rspLen
;
rpcMsg
.
contLen
=
rspLen
;
rpcMsg
.
code
=
code
;
rpcMsg
.
code
=
code
;
rpcMsg
.
msgType
=
pMsg
->
msgType
;
if
(
code
)
{
if
(
code
)
{
qError
(
"get table %s meta failed cause of %s"
,
infoReq
.
tbName
,
tstrerror
(
code
));
qError
(
"get table %s meta failed cause of %s"
,
infoReq
.
tbName
,
tstrerror
(
code
));
...
@@ -130,10 +131,10 @@ int vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg) {
...
@@ -130,10 +131,10 @@ int vnodeGetTableCfg(SVnode *pVnode, SRpcMsg *pMsg) {
SMetaReader
mer1
=
{
0
};
SMetaReader
mer1
=
{
0
};
SMetaReader
mer2
=
{
0
};
SMetaReader
mer2
=
{
0
};
char
tableFName
[
TSDB_TABLE_FNAME_LEN
];
char
tableFName
[
TSDB_TABLE_FNAME_LEN
];
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
=
{
0
}
;
int32_t
code
=
0
;
int32_t
code
=
0
;
int32_t
rspLen
=
0
;
int32_t
rspLen
=
0
;
void
*
pRsp
=
NULL
;
void
*
pRsp
=
NULL
;
SSchemaWrapper
schema
=
{
0
};
SSchemaWrapper
schema
=
{
0
};
SSchemaWrapper
schemaTag
=
{
0
};
SSchemaWrapper
schemaTag
=
{
0
};
...
@@ -220,6 +221,7 @@ _exit:
...
@@ -220,6 +221,7 @@ _exit:
rpcMsg
.
pCont
=
pRsp
;
rpcMsg
.
pCont
=
pRsp
;
rpcMsg
.
contLen
=
rspLen
;
rpcMsg
.
contLen
=
rspLen
;
rpcMsg
.
code
=
code
;
rpcMsg
.
code
=
code
;
rpcMsg
.
msgType
=
pMsg
->
msgType
;
if
(
code
)
{
if
(
code
)
{
qError
(
"get table %s cfg failed cause of %s"
,
cfgReq
.
tbName
,
tstrerror
(
code
));
qError
(
"get table %s cfg failed cause of %s"
,
cfgReq
.
tbName
,
tstrerror
(
code
));
...
@@ -260,7 +262,7 @@ void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId) {
...
@@ -260,7 +262,7 @@ void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId) {
}
}
// wrapper of tsdb read interface
// wrapper of tsdb read interface
tsdbReaderT
tsdbQueryCacheLast
(
SVnode
*
pVnode
,
SQueryTableDataCond
*
pCond
,
STableListInfo
*
tableList
,
uint64_t
qId
,
tsdbReaderT
tsdbQueryCacheLast
(
SVnode
*
pVnode
,
SQueryTableDataCond
*
pCond
,
STableListInfo
*
tableList
,
uint64_t
qId
,
void
*
pMemRef
)
{
void
*
pMemRef
)
{
#if 0
#if 0
return tsdbQueryCacheLastT(pVnode->pTsdb, pCond, groupList, qId, pMemRef);
return tsdbQueryCacheLastT(pVnode->pTsdb, pCond, groupList, qId, pMemRef);
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
4fb1ef08
...
@@ -28,7 +28,7 @@ static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, vo
...
@@ -28,7 +28,7 @@ static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, vo
static
int32_t
vnodeProcessWriteMsg
(
SVnode
*
pVnode
,
int64_t
version
,
SRpcMsg
*
pMsg
,
SRpcMsg
*
pRsp
);
static
int32_t
vnodeProcessWriteMsg
(
SVnode
*
pVnode
,
int64_t
version
,
SRpcMsg
*
pMsg
,
SRpcMsg
*
pRsp
);
static
int32_t
vnodeProcessDropTtlTbReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
);
static
int32_t
vnodeProcessDropTtlTbReq
(
SVnode
*
pVnode
,
int64_t
version
,
void
*
pReq
,
int32_t
len
,
SRpcMsg
*
pRsp
);
int32_t
vnodePre
p
rocessReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
)
{
int32_t
vnodePre
P
rocessReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
SDecoder
dc
=
{
0
};
SDecoder
dc
=
{
0
};
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
4fb1ef08
...
@@ -25,12 +25,12 @@ static inline bool vnodeIsMsgWeak(tmsg_t type) { return false; }
...
@@ -25,12 +25,12 @@ static inline bool vnodeIsMsgWeak(tmsg_t type) { return false; }
static
inline
void
vnodeAccumBlockMsg
(
SVnode
*
pVnode
,
tmsg_t
type
)
{
static
inline
void
vnodeAccumBlockMsg
(
SVnode
*
pVnode
,
tmsg_t
type
)
{
if
(
!
vnodeIsMsgBlock
(
type
))
return
;
if
(
!
vnodeIsMsgBlock
(
type
))
return
;
int32_t
count
=
atomic_add_fetch_32
(
&
pVnode
->
sync
Count
,
1
);
int32_t
count
=
atomic_add_fetch_32
(
&
pVnode
->
block
Count
,
1
);
vTrace
(
"vgId:%d, accum block, count:%d type:%s"
,
pVnode
->
config
.
vgId
,
count
,
TMSG_INFO
(
type
));
vTrace
(
"vgId:%d, accum block, count:%d type:%s"
,
pVnode
->
config
.
vgId
,
count
,
TMSG_INFO
(
type
));
}
}
static
inline
void
vnodeWaitBlockMsg
(
SVnode
*
pVnode
)
{
static
inline
void
vnodeWaitBlockMsg
(
SVnode
*
pVnode
)
{
int32_t
count
=
atomic_load_32
(
&
pVnode
->
sync
Count
);
int32_t
count
=
atomic_load_32
(
&
pVnode
->
block
Count
);
if
(
count
<=
0
)
return
;
if
(
count
<=
0
)
return
;
vTrace
(
"vgId:%d, wait block finish, count:%d"
,
pVnode
->
config
.
vgId
,
count
);
vTrace
(
"vgId:%d, wait block finish, count:%d"
,
pVnode
->
config
.
vgId
,
count
);
...
@@ -40,10 +40,10 @@ static inline void vnodeWaitBlockMsg(SVnode *pVnode) {
...
@@ -40,10 +40,10 @@ static inline void vnodeWaitBlockMsg(SVnode *pVnode) {
static
inline
void
vnodePostBlockMsg
(
SVnode
*
pVnode
,
tmsg_t
type
)
{
static
inline
void
vnodePostBlockMsg
(
SVnode
*
pVnode
,
tmsg_t
type
)
{
if
(
!
vnodeIsMsgBlock
(
type
))
return
;
if
(
!
vnodeIsMsgBlock
(
type
))
return
;
int32_t
count
=
atomic_load_32
(
&
pVnode
->
sync
Count
);
int32_t
count
=
atomic_load_32
(
&
pVnode
->
block
Count
);
if
(
count
<=
0
)
return
;
if
(
count
<=
0
)
return
;
count
=
atomic_sub_fetch_32
(
&
pVnode
->
sync
Count
,
1
);
count
=
atomic_sub_fetch_32
(
&
pVnode
->
block
Count
,
1
);
vTrace
(
"vgId:%d, post block, count:%d type:%s"
,
pVnode
->
config
.
vgId
,
count
,
TMSG_INFO
(
type
));
vTrace
(
"vgId:%d, post block, count:%d type:%s"
,
pVnode
->
config
.
vgId
,
count
,
TMSG_INFO
(
type
));
if
(
count
<=
0
)
{
if
(
count
<=
0
)
{
tsem_post
(
&
pVnode
->
syncSem
);
tsem_post
(
&
pVnode
->
syncSem
);
...
@@ -84,8 +84,10 @@ static int32_t vnodeProcessAlterReplicaReq(SVnode *pVnode, SRpcMsg *pMsg) {
...
@@ -84,8 +84,10 @@ static int32_t vnodeProcessAlterReplicaReq(SVnode *pVnode, SRpcMsg *pMsg) {
terrno
=
TSDB_CODE_INVALID_MSG
;
terrno
=
TSDB_CODE_INVALID_MSG
;
return
TSDB_CODE_INVALID_MSG
;
return
TSDB_CODE_INVALID_MSG
;
}
}
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
vGTrace
(
"vgId:%d, start to alter vnode replica to %d, handle:%p"
,
TD_VID
(
pVnode
),
req
.
replica
,
pMsg
->
info
.
handle
);
vGTrace
(
"vgId:%d, start to alter vnode replica to %d, handle:%p"
,
TD_VID
(
pVnode
),
req
.
replica
,
pMsg
->
info
.
handle
);
SSyncCfg
cfg
=
{.
replicaNum
=
req
.
replica
,
.
myIndex
=
req
.
selfIndex
};
SSyncCfg
cfg
=
{.
replicaNum
=
req
.
replica
,
.
myIndex
=
req
.
selfIndex
};
for
(
int32_t
r
=
0
;
r
<
req
.
replica
;
++
r
)
{
for
(
int32_t
r
=
0
;
r
<
req
.
replica
;
++
r
)
{
SNodeInfo
*
pNode
=
&
cfg
.
nodeInfo
[
r
];
SNodeInfo
*
pNode
=
&
cfg
.
nodeInfo
[
r
];
...
@@ -126,32 +128,23 @@ void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
...
@@ -126,32 +128,23 @@ void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
for
(
int32_t
m
=
0
;
m
<
numOfMsgs
;
m
++
)
{
for
(
int32_t
m
=
0
;
m
<
numOfMsgs
;
m
++
)
{
if
(
taosGetQitem
(
qall
,
(
void
**
)
&
pMsg
)
==
0
)
continue
;
if
(
taosGetQitem
(
qall
,
(
void
**
)
&
pMsg
)
==
0
)
continue
;
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
vGTrace
(
"vgId:%d, msg:%p get from vnode-write queue handle:%p"
,
vgId
,
pMsg
,
pMsg
->
info
.
handle
);
vGTrace
(
"vgId:%d, msg:%p get from vnode-write queue handle:%p"
,
vgId
,
pMsg
,
pMsg
->
info
.
handle
);
code
=
vnodePreProcessReq
(
pVnode
,
pMsg
);
if
(
code
!=
0
)
{
vError
(
"vgId:%d, msg:%p failed to pre-process since %s"
,
vgId
,
pMsg
,
terrstr
());
}
else
{
if
(
pMsg
->
msgType
==
TDMT_VND_ALTER_REPLICA
)
{
if
(
pMsg
->
msgType
==
TDMT_VND_ALTER_REPLICA
)
{
code
=
vnodeProcessAlterReplicaReq
(
pVnode
,
pMsg
);
code
=
vnodeProcessAlterReplicaReq
(
pVnode
,
pMsg
);
}
else
{
code
=
vnodePreprocessReq
(
pVnode
,
pMsg
);
if
(
code
!=
0
)
{
vError
(
"vgId:%d, failed to pre-process msg:%p since %s"
,
vgId
,
pMsg
,
terrstr
());
}
else
{
}
else
{
code
=
syncPropose
(
pVnode
->
sync
,
pMsg
,
vnodeIsMsgWeak
(
pMsg
->
msgType
));
code
=
syncPropose
(
pVnode
->
sync
,
pMsg
,
vnodeIsMsgWeak
(
pMsg
->
msgType
));
if
(
code
==
1
)
{
if
(
code
>
0
)
{
do
{
static
int32_t
cnt
=
0
;
if
(
cnt
++
%
1000
==
1
)
{
vInfo
(
"vgId:%d, msg:%p apply right now, apply index:%ld, msgtype:%s,%d"
,
vgId
,
pMsg
,
pMsg
->
info
.
conn
.
applyIndex
,
TMSG_INFO
(
pMsg
->
msgType
),
pMsg
->
msgType
);
}
}
while
(
0
);
SRpcMsg
rsp
=
{.
code
=
pMsg
->
code
,
.
info
=
pMsg
->
info
};
SRpcMsg
rsp
=
{.
code
=
pMsg
->
code
,
.
info
=
pMsg
->
info
};
if
(
vnodeProcessWriteReq
(
pVnode
,
pMsg
,
pMsg
->
info
.
conn
.
applyIndex
,
&
rsp
)
<
0
)
{
if
(
vnodeProcessWriteReq
(
pVnode
,
pMsg
,
pMsg
->
info
.
conn
.
applyIndex
,
&
rsp
)
<
0
)
{
rsp
.
code
=
terrno
;
rsp
.
code
=
terrno
;
v
Info
(
"vgId:%d, msg:%p failed to apply right now since %s"
,
vgId
,
pMsg
,
terrstr
());
v
Error
(
"vgId:%d, msg:%p failed to apply right now since %s"
,
vgId
,
pMsg
,
terrstr
());
}
}
if
(
rsp
.
info
.
handle
!=
NULL
)
{
if
(
rsp
.
info
.
handle
!=
NULL
)
{
tmsgSendRsp
(
&
rsp
);
tmsgSendRsp
(
&
rsp
);
}
}
...
@@ -161,18 +154,10 @@ void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
...
@@ -161,18 +154,10 @@ void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
if
(
code
==
0
)
{
if
(
code
==
0
)
{
vnodeAccumBlockMsg
(
pVnode
,
pMsg
->
msgType
);
vnodeAccumBlockMsg
(
pVnode
,
pMsg
->
msgType
);
}
else
if
(
code
==
-
1
&&
terrno
==
TSDB_CODE_SYN_NOT_LEADER
)
{
}
else
if
(
code
<
0
)
{
if
(
terrno
==
TSDB_CODE_SYN_NOT_LEADER
)
{
SEpSet
newEpSet
=
{
0
};
SEpSet
newEpSet
=
{
0
};
syncGetRetryEpSet
(
pVnode
->
sync
,
&
newEpSet
);
syncGetRetryEpSet
(
pVnode
->
sync
,
&
newEpSet
);
/*
syncGetEpSet(pVnode->sync, &newEpSet);
SEp *pEp = &newEpSet.eps[newEpSet.inUse];
if (pEp->port == tsServerPort && strcmp(pEp->fqdn, tsLocalFqdn) == 0) {
newEpSet.inUse = (newEpSet.inUse + 1) % newEpSet.numOfEps;
}
*/
vGTrace
(
"vgId:%d, msg:%p is redirect since not leader, numOfEps:%d inUse:%d"
,
vgId
,
pMsg
,
newEpSet
.
numOfEps
,
vGTrace
(
"vgId:%d, msg:%p is redirect since not leader, numOfEps:%d inUse:%d"
,
vgId
,
pMsg
,
newEpSet
.
numOfEps
,
newEpSet
.
inUse
);
newEpSet
.
inUse
);
for
(
int32_t
i
=
0
;
i
<
newEpSet
.
numOfEps
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
newEpSet
.
numOfEps
;
++
i
)
{
...
@@ -182,13 +167,15 @@ void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
...
@@ -182,13 +167,15 @@ void vnodeProposeMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
SRpcMsg
rsp
=
{.
code
=
TSDB_CODE_RPC_REDIRECT
,
.
info
=
pMsg
->
info
};
SRpcMsg
rsp
=
{.
code
=
TSDB_CODE_RPC_REDIRECT
,
.
info
=
pMsg
->
info
};
tmsgSendRedirectRsp
(
&
rsp
,
&
newEpSet
);
tmsgSendRedirectRsp
(
&
rsp
,
&
newEpSet
);
}
else
{
}
else
{
if
(
code
!=
1
)
{
if
(
terrno
!=
0
)
code
=
terrno
;
if
(
terrno
!=
0
)
code
=
terrno
;
vError
(
"vgId:%d, msg:%p failed to propose since %s, code:0x%x"
,
vgId
,
pMsg
,
tstrerror
(
code
),
code
);
vError
(
"vgId:%d, msg:%p failed to propose since %s, code:0x%x"
,
vgId
,
pMsg
,
tstrerror
(
code
),
code
);
SRpcMsg
rsp
=
{.
code
=
code
,
.
info
=
pMsg
->
info
};
SRpcMsg
rsp
=
{.
code
=
code
,
.
info
=
pMsg
->
info
};
if
(
rsp
.
info
.
handle
!=
NULL
)
{
tmsgSendRsp
(
&
rsp
);
tmsgSendRsp
(
&
rsp
);
}
}
}
}
}
else
{
}
vGTrace
(
"vgId:%d, msg:%p is freed, code:0x%x"
,
vgId
,
pMsg
,
code
);
vGTrace
(
"vgId:%d, msg:%p is freed, code:0x%x"
,
vgId
,
pMsg
,
code
);
rpcFreeCont
(
pMsg
->
pCont
);
rpcFreeCont
(
pMsg
->
pCont
);
...
@@ -206,7 +193,7 @@ void vnodeApplyMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
...
@@ -206,7 +193,7 @@ void vnodeApplyMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
for
(
int32_t
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
if
(
taosGetQitem
(
qall
,
(
void
**
)
&
pMsg
)
==
0
)
continue
;
if
(
taosGetQitem
(
qall
,
(
void
**
)
&
pMsg
)
==
0
)
continue
;
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
vGTrace
(
"vgId:%d, msg:%p get from vnode-apply queue, type:%s handle:%p"
,
vgId
,
pMsg
,
TMSG_INFO
(
pMsg
->
msgType
),
vGTrace
(
"vgId:%d, msg:%p get from vnode-apply queue, type:%s handle:%p"
,
vgId
,
pMsg
,
TMSG_INFO
(
pMsg
->
msgType
),
pMsg
->
info
.
handle
);
pMsg
->
info
.
handle
);
...
@@ -229,17 +216,24 @@ void vnodeApplyMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
...
@@ -229,17 +216,24 @@ void vnodeApplyMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) {
}
}
}
}
int32_t
vnodeProcessSyncReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
int32_t
vnodeProcessSyncMsg
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
int32_t
ret
=
0
;
int32_t
code
=
0
;
const
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
if
(
syncEnvIsStart
())
{
if
(
!
syncEnvIsStart
())
{
SSyncNode
*
pSyncNode
=
syncNodeAcquire
(
pVnode
->
sync
);
vGError
(
"vgId:%d, msg:%p failed to process since sync env not start"
,
pVnode
->
config
.
vgId
);
assert
(
pSyncNode
!=
NULL
);
terrno
=
TSDB_CODE_APP_ERROR
;
return
-
1
;
}
SMsgHead
*
pHead
=
pMsg
->
pCont
;
SSyncNode
*
pSyncNode
=
syncNodeAcquire
(
pVnode
->
sync
);
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
if
(
pSyncNode
==
NULL
)
{
vGError
(
"vgId:%d, msg:%p failed to process since invalid sync node"
,
pVnode
->
config
.
vgId
);
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
return
-
1
;
}
do
{
#if 1
char
*
syncNodeStr
=
sync2SimpleStr
(
pVnode
->
sync
);
char
*
syncNodeStr
=
sync2SimpleStr
(
pVnode
->
sync
);
static
int64_t
vndTick
=
0
;
static
int64_t
vndTick
=
0
;
if
(
++
vndTick
%
10
==
1
)
{
if
(
++
vndTick
%
10
==
1
)
{
...
@@ -247,154 +241,125 @@ int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
...
@@ -247,154 +241,125 @@ int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
}
}
if
(
gRaftDetailLog
)
{
if
(
gRaftDetailLog
)
{
char
logBuf
[
512
]
=
{
0
};
char
logBuf
[
512
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==vnodeProcessSyncReq== msgType:%d, syncNode: %s"
,
pMsg
->
msgType
,
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"vnode process syncmsg, msgType:%d, syncNode:%s"
,
pMsg
->
msgType
,
syncNodeStr
);
syncNodeStr
);
syncRpcMsgLog2
(
logBuf
,
pMsg
);
syncRpcMsgLog2
(
logBuf
,
pMsg
);
}
}
taosMemoryFree
(
syncNodeStr
);
taosMemoryFree
(
syncNodeStr
);
}
while
(
0
);
#endif
SRpcMsg
*
pRpcMsg
=
pMsg
;
// ToDo: ugly! use function pointer
// use different strategy
if
(
syncNodeStrategy
(
pSyncNode
)
==
SYNC_STRATEGY_NO_SNAPSHOT
)
{
if
(
syncNodeStrategy
(
pSyncNode
)
==
SYNC_STRATEGY_NO_SNAPSHOT
)
{
if
(
pRpc
Msg
->
msgType
==
TDMT_SYNC_TIMEOUT
)
{
if
(
p
Msg
->
msgType
==
TDMT_SYNC_TIMEOUT
)
{
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pRpc
Msg
);
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
p
Msg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnTimeoutCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnTimeoutCb
(
pSyncNode
,
pSyncMsg
);
syncTimeoutDestroy
(
pSyncMsg
);
syncTimeoutDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_PING
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_PING
)
{
SyncPing
*
pSyncMsg
=
syncPingFromRpcMsg2
(
pMsg
);
SyncPing
*
pSyncMsg
=
syncPingFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnPingCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnPingCb
(
pSyncNode
,
pSyncMsg
);
syncPingDestroy
(
pSyncMsg
);
syncPingDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_PING_REPLY
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_PING_REPLY
)
{
SyncPingReply
*
pSyncMsg
=
syncPingReplyFromRpcMsg2
(
pMsg
);
SyncPingReply
*
pSyncMsg
=
syncPingReplyFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnPingReplyCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnPingReplyCb
(
pSyncNode
,
pSyncMsg
);
syncPingReplyDestroy
(
pSyncMsg
);
syncPingReplyDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST
)
{
SyncClientRequest
*
pSyncMsg
=
syncClientRequestFromRpcMsg2
(
pMsg
);
SyncClientRequest
*
pSyncMsg
=
syncClientRequestFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnClientRequestCb
(
pSyncNode
,
pSyncMsg
,
NULL
);
code
=
syncNodeOnClientRequestCb
(
pSyncNode
,
pSyncMsg
,
NULL
);
syncClientRequestDestroy
(
pSyncMsg
);
syncClientRequestDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE
)
{
SyncRequestVote
*
pSyncMsg
=
syncRequestVoteFromRpcMsg2
(
pMsg
);
SyncRequestVote
*
pSyncMsg
=
syncRequestVoteFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnRequestVoteCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnRequestVoteCb
(
pSyncNode
,
pSyncMsg
);
syncRequestVoteDestroy
(
pSyncMsg
);
syncRequestVoteDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE_REPLY
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE_REPLY
)
{
SyncRequestVoteReply
*
pSyncMsg
=
syncRequestVoteReplyFromRpcMsg2
(
pMsg
);
SyncRequestVoteReply
*
pSyncMsg
=
syncRequestVoteReplyFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnRequestVoteReplyCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnRequestVoteReplyCb
(
pSyncNode
,
pSyncMsg
);
syncRequestVoteReplyDestroy
(
pSyncMsg
);
syncRequestVoteReplyDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES
)
{
SyncAppendEntries
*
pSyncMsg
=
syncAppendEntriesFromRpcMsg2
(
pMsg
);
SyncAppendEntries
*
pSyncMsg
=
syncAppendEntriesFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnAppendEntriesCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnAppendEntriesCb
(
pSyncNode
,
pSyncMsg
);
syncAppendEntriesDestroy
(
pSyncMsg
);
syncAppendEntriesDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_REPLY
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_REPLY
)
{
SyncAppendEntriesReply
*
pSyncMsg
=
syncAppendEntriesReplyFromRpcMsg2
(
pMsg
);
SyncAppendEntriesReply
*
pSyncMsg
=
syncAppendEntriesReplyFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnAppendEntriesReplyCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnAppendEntriesReplyCb
(
pSyncNode
,
pSyncMsg
);
syncAppendEntriesReplyDestroy
(
pSyncMsg
);
syncAppendEntriesReplyDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_SET_VNODE_STANDBY
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_SET_VNODE_STANDBY
)
{
code
=
vnodeSetStandBy
(
pVnode
);
ret
=
vnodeSetStandBy
(
pVnode
);
if
(
code
!=
0
&&
terrno
!=
0
)
code
=
terrno
;
if
(
ret
!=
0
&&
terrno
!=
0
)
ret
=
terrno
;
SRpcMsg
rsp
=
{.
code
=
code
,
.
info
=
pMsg
->
info
};
SRpcMsg
rsp
=
{.
code
=
ret
,
.
info
=
pMsg
->
info
};
tmsgSendRsp
(
&
rsp
);
tmsgSendRsp
(
&
rsp
);
}
else
{
}
else
{
vError
(
"==vnodeProcessSyncReq== error msg type:%d"
,
pRpc
Msg
->
msgType
);
vGError
(
"vgId:%d, msg:%p failed to process since error msg type:%d"
,
pVnode
->
config
.
vgId
,
p
Msg
->
msgType
);
ret
=
-
1
;
code
=
-
1
;
}
}
}
else
{
}
else
{
// use wal first strategy
// use wal first strategy
if
(
pMsg
->
msgType
==
TDMT_SYNC_TIMEOUT
)
{
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_TIMEOUT
)
{
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pMsg
);
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnTimeoutCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnTimeoutCb
(
pSyncNode
,
pSyncMsg
);
syncTimeoutDestroy
(
pSyncMsg
);
syncTimeoutDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_PING
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_PING
)
{
SyncPing
*
pSyncMsg
=
syncPingFromRpcMsg2
(
pMsg
);
SyncPing
*
pSyncMsg
=
syncPingFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnPingCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnPingCb
(
pSyncNode
,
pSyncMsg
);
syncPingDestroy
(
pSyncMsg
);
syncPingDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_PING_REPLY
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_PING_REPLY
)
{
SyncPingReply
*
pSyncMsg
=
syncPingReplyFromRpcMsg2
(
pMsg
);
SyncPingReply
*
pSyncMsg
=
syncPingReplyFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnPingReplyCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnPingReplyCb
(
pSyncNode
,
pSyncMsg
);
syncPingReplyDestroy
(
pSyncMsg
);
syncPingReplyDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST
)
{
SyncClientRequest
*
pSyncMsg
=
syncClientRequestFromRpcMsg2
(
pMsg
);
SyncClientRequest
*
pSyncMsg
=
syncClientRequestFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnClientRequestCb
(
pSyncNode
,
pSyncMsg
,
NULL
);
code
=
syncNodeOnClientRequestCb
(
pSyncNode
,
pSyncMsg
,
NULL
);
syncClientRequestDestroy
(
pSyncMsg
);
syncClientRequestDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST_BATCH
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST_BATCH
)
{
SyncClientRequestBatch
*
pSyncMsg
=
syncClientRequestBatchFromRpcMsg
(
pMsg
);
SyncClientRequestBatch
*
pSyncMsg
=
syncClientRequestBatchFromRpcMsg
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnClientRequestBatchCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnClientRequestBatchCb
(
pSyncNode
,
pSyncMsg
);
syncClientRequestBatchDestroyDeep
(
pSyncMsg
);
syncClientRequestBatchDestroyDeep
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE
)
{
SyncRequestVote
*
pSyncMsg
=
syncRequestVoteFromRpcMsg2
(
pMsg
);
SyncRequestVote
*
pSyncMsg
=
syncRequestVoteFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnRequestVoteCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnRequestVoteCb
(
pSyncNode
,
pSyncMsg
);
syncRequestVoteDestroy
(
pSyncMsg
);
syncRequestVoteDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE_REPLY
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE_REPLY
)
{
SyncRequestVoteReply
*
pSyncMsg
=
syncRequestVoteReplyFromRpcMsg2
(
pMsg
);
SyncRequestVoteReply
*
pSyncMsg
=
syncRequestVoteReplyFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnRequestVoteReplyCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnRequestVoteReplyCb
(
pSyncNode
,
pSyncMsg
);
syncRequestVoteReplyDestroy
(
pSyncMsg
);
syncRequestVoteReplyDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_BATCH
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_BATCH
)
{
SyncAppendEntriesBatch
*
pSyncMsg
=
syncAppendEntriesBatchFromRpcMsg2
(
pMsg
);
SyncAppendEntriesBatch
*
pSyncMsg
=
syncAppendEntriesBatchFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnAppendEntriesSnapshot2Cb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnAppendEntriesSnapshot2Cb
(
pSyncNode
,
pSyncMsg
);
syncAppendEntriesBatchDestroy
(
pSyncMsg
);
syncAppendEntriesBatchDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_REPLY
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_REPLY
)
{
SyncAppendEntriesReply
*
pSyncMsg
=
syncAppendEntriesReplyFromRpcMsg2
(
pMsg
);
SyncAppendEntriesReply
*
pSyncMsg
=
syncAppendEntriesReplyFromRpcMsg2
(
pRpcMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
ASSERT
(
pSyncMsg
!=
NULL
);
ret
=
syncNodeOnAppendEntriesReplySnapshot2Cb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnAppendEntriesReplySnapshot2Cb
(
pSyncNode
,
pSyncMsg
);
syncAppendEntriesReplyDestroy
(
pSyncMsg
);
syncAppendEntriesReplyDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_SET_VNODE_STANDBY
)
{
}
else
if
(
pRpcMsg
->
msgType
==
TDMT_SYNC_SET_VNODE_STANDBY
)
{
code
=
vnodeSetStandBy
(
pVnode
);
ret
=
vnodeSetStandBy
(
pVnode
);
if
(
code
!=
0
&&
terrno
!=
0
)
code
=
terrno
;
if
(
ret
!=
0
&&
terrno
!=
0
)
ret
=
terrno
;
SRpcMsg
rsp
=
{.
code
=
code
,
.
info
=
pMsg
->
info
};
SRpcMsg
rsp
=
{.
code
=
ret
,
.
info
=
pMsg
->
info
};
tmsgSendRsp
(
&
rsp
);
tmsgSendRsp
(
&
rsp
);
}
else
{
}
else
{
vError
(
"==vnodeProcessSyncReq== error msg type:%d"
,
pRpc
Msg
->
msgType
);
vGError
(
"vgId:%d, msg:%p failed to process since error msg type:%d"
,
pVnode
->
config
.
vgId
,
p
Msg
->
msgType
);
ret
=
-
1
;
code
=
-
1
;
}
}
}
}
syncNodeRelease
(
pSyncNode
);
syncNodeRelease
(
pSyncNode
);
}
else
{
if
(
code
!=
0
&&
terrno
==
0
)
{
vError
(
"==vnodeProcessSyncReq== error syncEnv stop"
);
ret
=
-
1
;
}
if
(
ret
!=
0
&&
terrno
==
0
)
{
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
}
}
return
ret
;
return
code
;
}
}
static
int32_t
vnodeSyncEqMsg
(
const
SMsgCb
*
msgcb
,
SRpcMsg
*
pMsg
)
{
static
int32_t
vnodeSyncEqMsg
(
const
SMsgCb
*
msgcb
,
SRpcMsg
*
pMsg
)
{
...
@@ -427,7 +392,7 @@ static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReCon
...
@@ -427,7 +392,7 @@ static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReCon
syncGetAndDelRespRpc
(
pVnode
->
sync
,
cbMeta
.
newCfgSeqNum
,
&
rpcMsg
.
info
);
syncGetAndDelRespRpc
(
pVnode
->
sync
,
cbMeta
.
newCfgSeqNum
,
&
rpcMsg
.
info
);
rpcMsg
.
info
.
conn
.
applyIndex
=
cbMeta
.
index
;
rpcMsg
.
info
.
conn
.
applyIndex
=
cbMeta
.
index
;
STraceId
*
trace
=
(
STraceId
*
)
&
pMsg
->
info
.
traceId
;
const
STraceId
*
trace
=
(
STraceId
*
)
&
pMsg
->
info
.
traceId
;
vGTrace
(
"vgId:%d, alter vnode replica is confirmed, type:%s contLen:%d seq:%"
PRIu64
" handle:%p"
,
TD_VID
(
pVnode
),
vGTrace
(
"vgId:%d, alter vnode replica is confirmed, type:%s contLen:%d seq:%"
PRIu64
" handle:%p"
,
TD_VID
(
pVnode
),
TMSG_INFO
(
pMsg
->
msgType
),
pMsg
->
contLen
,
cbMeta
.
seqNum
,
rpcMsg
.
info
.
handle
);
TMSG_INFO
(
pMsg
->
msgType
),
pMsg
->
contLen
,
cbMeta
.
seqNum
,
rpcMsg
.
info
.
handle
);
if
(
rpcMsg
.
info
.
handle
!=
NULL
)
{
if
(
rpcMsg
.
info
.
handle
!=
NULL
)
{
...
@@ -444,9 +409,8 @@ static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta c
...
@@ -444,9 +409,8 @@ static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta c
char
logBuf
[
256
]
=
{
0
};
char
logBuf
[
256
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==callback== ==CommitCb== execute, pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, beginIndex :%ld
\n
"
,
"commitCb execute, pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s, beginIndex :%ld
\n
"
,
pFsm
,
pFsm
,
cbMeta
.
index
,
cbMeta
.
isWeak
,
cbMeta
.
code
,
cbMeta
.
state
,
syncUtilState2String
(
cbMeta
.
state
),
cbMeta
.
index
,
cbMeta
.
isWeak
,
cbMeta
.
code
,
cbMeta
.
state
,
syncUtilState2String
(
cbMeta
.
state
),
beginIndex
);
beginIndex
);
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
SRpcMsg
rpcMsg
=
{.
msgType
=
pMsg
->
msgType
,
.
contLen
=
pMsg
->
contLen
};
SRpcMsg
rpcMsg
=
{.
msgType
=
pMsg
->
msgType
,
.
contLen
=
pMsg
->
contLen
};
...
@@ -459,16 +423,15 @@ static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta c
...
@@ -459,16 +423,15 @@ static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta c
static
void
vnodeSyncPreCommitMsg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
static
void
vnodeSyncPreCommitMsg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
char
logBuf
[
256
]
=
{
0
};
char
logBuf
[
256
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"preCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
"==callback== ==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
cbMeta
.
index
,
cbMeta
.
index
,
cbMeta
.
isWeak
,
cbMeta
.
code
,
cbMeta
.
state
,
syncUtilState2String
(
cbMeta
.
state
));
cbMeta
.
isWeak
,
cbMeta
.
code
,
cbMeta
.
state
,
syncUtilState2String
(
cbMeta
.
state
));
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
}
static
void
vnodeSyncRollBackMsg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
static
void
vnodeSyncRollBackMsg
(
SSyncFSM
*
pFsm
,
const
SRpcMsg
*
pMsg
,
SFsmCbMeta
cbMeta
)
{
char
logBuf
[
256
]
=
{
0
};
char
logBuf
[
256
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"
==callback== ==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"
rollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d, state:%d %s
\n
"
,
pFsm
,
pFsm
,
cbMeta
.
index
,
cbMeta
.
isWeak
,
cbMeta
.
code
,
cbMeta
.
state
,
syncUtilState2String
(
cbMeta
.
state
));
cbMeta
.
index
,
cbMeta
.
isWeak
,
cbMeta
.
code
,
cbMeta
.
state
,
syncUtilState2String
(
cbMeta
.
state
));
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
syncRpcMsgLog2
(
logBuf
,
(
SRpcMsg
*
)
pMsg
);
}
}
...
...
source/libs/command/src/command.c
浏览文件 @
4fb1ef08
...
@@ -548,19 +548,17 @@ static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) {
...
@@ -548,19 +548,17 @@ static int32_t execShowLocalVariables(SRetrieveTableRsp** pRsp) {
}
}
static
int32_t
createSelectResultDataBlock
(
SNodeList
*
pProjects
,
SSDataBlock
**
pOutput
)
{
static
int32_t
createSelectResultDataBlock
(
SNodeList
*
pProjects
,
SSDataBlock
**
pOutput
)
{
SSDataBlock
*
pBlock
=
taosMemoryCalloc
(
1
,
sizeof
(
SSDataBlock
)
);
SSDataBlock
*
pBlock
=
createDataBlock
(
);
if
(
NULL
==
pBlock
)
{
if
(
NULL
==
pBlock
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
pBlock
->
pDataBlock
=
taosArrayInit
(
LIST_LENGTH
(
pProjects
),
sizeof
(
SColumnInfoData
));
SNode
*
pProj
=
NULL
;
SNode
*
pProj
=
NULL
;
FOREACH
(
pProj
,
pProjects
)
{
FOREACH
(
pProj
,
pProjects
)
{
SColumnInfoData
infoData
=
{
0
};
SColumnInfoData
infoData
=
{
0
};
infoData
.
info
.
type
=
((
SExprNode
*
)
pProj
)
->
resType
.
type
;
infoData
.
info
.
type
=
((
SExprNode
*
)
pProj
)
->
resType
.
type
;
infoData
.
info
.
bytes
=
((
SExprNode
*
)
pProj
)
->
resType
.
bytes
;
infoData
.
info
.
bytes
=
((
SExprNode
*
)
pProj
)
->
resType
.
bytes
;
taosArrayPush
(
pBlock
->
pData
Block
,
&
infoData
);
blockDataAppendColInfo
(
p
Block
,
&
infoData
);
}
}
*
pOutput
=
pBlock
;
*
pOutput
=
pBlock
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
4fb1ef08
...
@@ -51,6 +51,13 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int
...
@@ -51,6 +51,13 @@ typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int
#define NEEDTO_COMPRESS_QUERY(size) ((size) > tsCompressColData ? 1 : 0)
#define NEEDTO_COMPRESS_QUERY(size) ((size) > tsCompressColData ? 1 : 0)
#define START_TS_COLUMN_INDEX 0
#define END_TS_COLUMN_INDEX 1
#define UID_COLUMN_INDEX 2
#define GROUPID_COLUMN_INDEX UID_COLUMN_INDEX
#define DELETE_GROUPID_COLUMN_INDEX 2
enum
{
enum
{
// when this task starts to execute, this status will set
// when this task starts to execute, this status will set
TASK_NOT_COMPLETED
=
0x1u
,
TASK_NOT_COMPLETED
=
0x1u
,
...
@@ -364,6 +371,8 @@ typedef struct SStreamBlockScanInfo {
...
@@ -364,6 +371,8 @@ typedef struct SStreamBlockScanInfo {
int32_t
scanWinIndex
;
// for state operator
int32_t
scanWinIndex
;
// for state operator
int32_t
pullDataResIndex
;
int32_t
pullDataResIndex
;
SSDataBlock
*
pPullDataRes
;
// pull data SSDataBlock
SSDataBlock
*
pPullDataRes
;
// pull data SSDataBlock
SSDataBlock
*
pDeleteDataRes
;
// delete data SSDataBlock
int32_t
deleteDataIndex
;
}
SStreamBlockScanInfo
;
}
SStreamBlockScanInfo
;
typedef
struct
SSysTableScanInfo
{
typedef
struct
SSysTableScanInfo
{
...
@@ -429,6 +438,10 @@ typedef struct SIntervalAggOperatorInfo {
...
@@ -429,6 +438,10 @@ typedef struct SIntervalAggOperatorInfo {
bool
invertible
;
bool
invertible
;
SArray
*
pPrevValues
;
// SArray<SGroupKeys> used to keep the previous not null value for interpolation.
SArray
*
pPrevValues
;
// SArray<SGroupKeys> used to keep the previous not null value for interpolation.
bool
ignoreExpiredData
;
bool
ignoreExpiredData
;
SArray
*
pRecycledPages
;
SArray
*
pDelWins
;
// SWinRes
int32_t
delIndex
;
SSDataBlock
*
pDelRes
;
}
SIntervalAggOperatorInfo
;
}
SIntervalAggOperatorInfo
;
typedef
struct
SStreamFinalIntervalOperatorInfo
{
typedef
struct
SStreamFinalIntervalOperatorInfo
{
...
@@ -451,6 +464,10 @@ typedef struct SStreamFinalIntervalOperatorInfo {
...
@@ -451,6 +464,10 @@ typedef struct SStreamFinalIntervalOperatorInfo {
int32_t
pullIndex
;
int32_t
pullIndex
;
SSDataBlock
*
pPullDataRes
;
SSDataBlock
*
pPullDataRes
;
bool
ignoreExpiredData
;
bool
ignoreExpiredData
;
SArray
*
pRecycledPages
;
SArray
*
pDelWins
;
// SWinRes
int32_t
delIndex
;
SSDataBlock
*
pDelRes
;
}
SStreamFinalIntervalOperatorInfo
;
}
SStreamFinalIntervalOperatorInfo
;
typedef
struct
SAggOperatorInfo
{
typedef
struct
SAggOperatorInfo
{
...
...
source/libs/executor/src/executorMain.c
浏览文件 @
4fb1ef08
...
@@ -27,6 +27,10 @@ static TdThreadOnce initPoolOnce = PTHREAD_ONCE_INIT;
...
@@ -27,6 +27,10 @@ static TdThreadOnce initPoolOnce = PTHREAD_ONCE_INIT;
int32_t
exchangeObjRefPool
=
-
1
;
int32_t
exchangeObjRefPool
=
-
1
;
static
void
initRefPool
()
{
exchangeObjRefPool
=
taosOpenRef
(
1024
,
doDestroyExchangeOperatorInfo
);
}
static
void
initRefPool
()
{
exchangeObjRefPool
=
taosOpenRef
(
1024
,
doDestroyExchangeOperatorInfo
);
}
static
void
cleanupRefPool
()
{
int32_t
ref
=
atomic_val_compare_exchange_32
(
&
exchangeObjRefPool
,
exchangeObjRefPool
,
0
);
taosCloseRef
(
ref
);
}
int32_t
qCreateExecTask
(
SReadHandle
*
readHandle
,
int32_t
vgId
,
uint64_t
taskId
,
SSubplan
*
pSubplan
,
int32_t
qCreateExecTask
(
SReadHandle
*
readHandle
,
int32_t
vgId
,
uint64_t
taskId
,
SSubplan
*
pSubplan
,
qTaskInfo_t
*
pTaskInfo
,
DataSinkHandle
*
handle
,
const
char
*
sql
,
EOPTR_EXEC_MODEL
model
)
{
qTaskInfo_t
*
pTaskInfo
,
DataSinkHandle
*
handle
,
const
char
*
sql
,
EOPTR_EXEC_MODEL
model
)
{
...
@@ -34,7 +38,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
...
@@ -34,7 +38,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
SExecTaskInfo
**
pTask
=
(
SExecTaskInfo
**
)
pTaskInfo
;
SExecTaskInfo
**
pTask
=
(
SExecTaskInfo
**
)
pTaskInfo
;
taosThreadOnce
(
&
initPoolOnce
,
initRefPool
);
taosThreadOnce
(
&
initPoolOnce
,
initRefPool
);
atexit
(
cleanupRefPool
);
int32_t
code
=
createExecTaskInfoImpl
(
pSubplan
,
pTask
,
readHandle
,
taskId
,
sql
,
model
);
int32_t
code
=
createExecTaskInfoImpl
(
pSubplan
,
pTask
,
readHandle
,
taskId
,
sql
,
model
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
goto
_error
;
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
4fb1ef08
...
@@ -807,18 +807,38 @@ static bool isStateWindow(SStreamBlockScanInfo* pInfo) {
...
@@ -807,18 +807,38 @@ static bool isStateWindow(SStreamBlockScanInfo* pInfo) {
return
pInfo
->
sessionSup
.
parentType
==
QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE
;
return
pInfo
->
sessionSup
.
parentType
==
QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE
;
}
}
static
uint64_t
getGroupId
(
SOperatorInfo
*
pOperator
,
uint64_t
uid
)
{
uint64_t
*
groupId
=
taosHashGet
(
pOperator
->
pTaskInfo
->
tableqinfoList
.
map
,
&
uid
,
sizeof
(
int64_t
));
if
(
groupId
)
{
return
*
groupId
;
}
return
0
;
/* Todo(liuyao) for partition by column
recordNewGroupKeys(pTableScanInfo->pGroupCols, pTableScanInfo->pGroupColVals, pBlock, rowId);
int32_t len = buildGroupKeys(pTableScanInfo->keyBuf, pTableScanInfo->pGroupColVals);
uint64_t resId = 0;
uint64_t* groupId = taosHashGet(pTableScanInfo->pGroupSet, pTableScanInfo->keyBuf, len);
if (groupId) {
return *groupId;
} else if (len != 0) {
resId = calcGroupId(pTableScanInfo->keyBuf, len);
taosHashPut(pTableScanInfo->pGroupSet, pTableScanInfo->keyBuf, len, &resId, sizeof(uint64_t));
}
return resId;
*/
}
static
void
setGroupId
(
SStreamBlockScanInfo
*
pInfo
,
SSDataBlock
*
pBlock
,
int32_t
groupColIndex
,
int32_t
rowIndex
)
{
static
void
setGroupId
(
SStreamBlockScanInfo
*
pInfo
,
SSDataBlock
*
pBlock
,
int32_t
groupColIndex
,
int32_t
rowIndex
)
{
ASSERT
(
rowIndex
<
pBlock
->
info
.
rows
);
ASSERT
(
rowIndex
<
pBlock
->
info
.
rows
);
switch
(
pBlock
->
info
.
type
)
switch
(
pBlock
->
info
.
type
)
{
{
case
STREAM_DELETE_DATA
:
case
STREAM_RETRIEVE
:
{
case
STREAM_RETRIEVE
:
{
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
groupColIndex
);
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
groupColIndex
);
uint64_t
*
groupCol
=
(
uint64_t
*
)
pColInfo
->
pData
;
uint64_t
*
groupCol
=
(
uint64_t
*
)
pColInfo
->
pData
;
pInfo
->
groupId
=
groupCol
[
rowIndex
];
pInfo
->
groupId
=
groupCol
[
rowIndex
];
}
}
break
;
break
;
case
STREAM_DELETE_DATA
:
break
;
default:
default:
break
;
break
;
}
}
...
@@ -840,14 +860,14 @@ static bool prepareDataScan(SStreamBlockScanInfo* pInfo, SSDataBlock* pSDB, int3
...
@@ -840,14 +860,14 @@ static bool prepareDataScan(SStreamBlockScanInfo* pInfo, SSDataBlock* pSDB, int3
int64_t
gap
=
pInfo
->
sessionSup
.
gap
;
int64_t
gap
=
pInfo
->
sessionSup
.
gap
;
int32_t
winIndex
=
0
;
int32_t
winIndex
=
0
;
SResultWindowInfo
*
pCurWin
=
SResultWindowInfo
*
pCurWin
=
getSessionTimeWindow
(
pAggSup
,
tsCols
[
(
*
pRowIndex
)
],
INT64_MIN
,
pSDB
->
info
.
groupId
,
gap
,
&
winIndex
);
getSessionTimeWindow
(
pAggSup
,
tsCols
[
*
pRowIndex
],
INT64_MIN
,
pSDB
->
info
.
groupId
,
gap
,
&
winIndex
);
win
=
pCurWin
->
win
;
win
=
pCurWin
->
win
;
(
*
pRowIndex
)
+=
updateSessionWindowInfo
(
pCurWin
,
tsCols
,
NULL
,
pSDB
->
info
.
rows
,
(
*
pRowIndex
)
,
gap
,
NULL
);
(
*
pRowIndex
)
+=
updateSessionWindowInfo
(
pCurWin
,
tsCols
,
NULL
,
pSDB
->
info
.
rows
,
*
pRowIndex
,
gap
,
NULL
);
}
else
{
}
else
{
win
=
win
=
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
tsCols
[
(
*
pRowIndex
)
],
&
pInfo
->
interval
,
pInfo
->
interval
.
precision
,
NULL
);
getActiveTimeWindow
(
NULL
,
&
dumyInfo
,
tsCols
[
*
pRowIndex
],
&
pInfo
->
interval
,
pInfo
->
interval
.
precision
,
NULL
);
setGroupId
(
pInfo
,
pSDB
,
2
,
*
pRowIndex
);
setGroupId
(
pInfo
,
pSDB
,
GROUPID_COLUMN_INDEX
,
*
pRowIndex
);
(
*
pRowIndex
)
+=
getNumOfRowsInTimeWindow
(
&
pSDB
->
info
,
tsCols
,
(
*
pRowIndex
)
,
win
.
ekey
,
binarySearchForKey
,
NULL
,
(
*
pRowIndex
)
+=
getNumOfRowsInTimeWindow
(
&
pSDB
->
info
,
tsCols
,
*
pRowIndex
,
win
.
ekey
,
binarySearchForKey
,
NULL
,
TSDB_ORDER_ASC
);
TSDB_ORDER_ASC
);
}
}
needRead
=
true
;
needRead
=
true
;
...
@@ -891,27 +911,6 @@ static void copyOneRow(SSDataBlock* dest, SSDataBlock* source, int32_t sourceRow
...
@@ -891,27 +911,6 @@ static void copyOneRow(SSDataBlock* dest, SSDataBlock* source, int32_t sourceRow
dest
->
info
.
rows
++
;
dest
->
info
.
rows
++
;
}
}
static
uint64_t
getGroupId
(
SOperatorInfo
*
pOperator
,
SSDataBlock
*
pBlock
,
int32_t
rowId
)
{
uint64_t
*
groupId
=
taosHashGet
(
pOperator
->
pTaskInfo
->
tableqinfoList
.
map
,
&
pBlock
->
info
.
uid
,
sizeof
(
int64_t
));
if
(
groupId
)
{
return
*
groupId
;
}
return
0
;
/* Todo(liuyao) for partition by column
recordNewGroupKeys(pTableScanInfo->pGroupCols, pTableScanInfo->pGroupColVals, pBlock, rowId);
int32_t len = buildGroupKeys(pTableScanInfo->keyBuf, pTableScanInfo->pGroupColVals);
uint64_t resId = 0;
uint64_t* groupId = taosHashGet(pTableScanInfo->pGroupSet, pTableScanInfo->keyBuf, len);
if (groupId) {
return *groupId;
} else if (len != 0) {
resId = calcGroupId(pTableScanInfo->keyBuf, len);
taosHashPut(pTableScanInfo->pGroupSet, pTableScanInfo->keyBuf, len, &resId, sizeof(uint64_t));
}
return resId;
*/
}
static
SSDataBlock
*
doDataScan
(
SStreamBlockScanInfo
*
pInfo
,
SSDataBlock
*
pSDB
,
int32_t
tsColIndex
,
int32_t
*
pRowIndex
)
{
static
SSDataBlock
*
doDataScan
(
SStreamBlockScanInfo
*
pInfo
,
SSDataBlock
*
pSDB
,
int32_t
tsColIndex
,
int32_t
*
pRowIndex
)
{
while
(
1
)
{
while
(
1
)
{
SSDataBlock
*
pResult
=
NULL
;
SSDataBlock
*
pResult
=
NULL
;
...
@@ -935,7 +934,7 @@ static SSDataBlock* doDataScan(SStreamBlockScanInfo* pInfo, SSDataBlock* pSDB, i
...
@@ -935,7 +934,7 @@ static SSDataBlock* doDataScan(SStreamBlockScanInfo* pInfo, SSDataBlock* pSDB, i
SSDataBlock* pBlock = createOneDataBlock(pResult, true);
SSDataBlock* pBlock = createOneDataBlock(pResult, true);
blockDataCleanup(pResult);
blockDataCleanup(pResult);
for (int32_t i = 0; i < pBlock->info.rows; i++) {
for (int32_t i = 0; i < pBlock->info.rows; i++) {
uint64_t id = getGroupId(pInfo->pOperatorDumy, pBlock
, i
);
uint64_t id = getGroupId(pInfo->pOperatorDumy, pBlock
->info.uid
);
if (id == pInfo->groupId) {
if (id == pInfo->groupId) {
copyOneRow(pResult, pBlock, i);
copyOneRow(pResult, pBlock, i);
}
}
...
@@ -944,6 +943,40 @@ static SSDataBlock* doDataScan(SStreamBlockScanInfo* pInfo, SSDataBlock* pSDB, i
...
@@ -944,6 +943,40 @@ static SSDataBlock* doDataScan(SStreamBlockScanInfo* pInfo, SSDataBlock* pSDB, i
*/
*/
}
}
static
void
copyDeleteDataBlock
(
SStreamBlockScanInfo
*
pInfo
,
SSDataBlock
*
pDelBlock
,
SOperatorInfo
*
pOperator
,
SSDataBlock
*
pUpdateRes
)
{
if
(
pDelBlock
->
info
.
rows
==
0
)
{
return
;
}
blockDataCleanup
(
pUpdateRes
);
blockDataEnsureCapacity
(
pUpdateRes
,
64
);
ASSERT
(
taosArrayGetSize
(
pDelBlock
->
pDataBlock
)
>=
3
);
SColumnInfoData
*
pStartTsCol
=
taosArrayGet
(
pDelBlock
->
pDataBlock
,
START_TS_COLUMN_INDEX
);
TSKEY
*
startData
=
(
TSKEY
*
)
pStartTsCol
->
pData
;
SColumnInfoData
*
pEndTsCol
=
taosArrayGet
(
pDelBlock
->
pDataBlock
,
END_TS_COLUMN_INDEX
);
TSKEY
*
endData
=
(
TSKEY
*
)
pEndTsCol
->
pData
;
SColumnInfoData
*
pGpCol
=
taosArrayGet
(
pDelBlock
->
pDataBlock
,
UID_COLUMN_INDEX
);
uint64_t
*
uidCol
=
(
uint64_t
*
)
pGpCol
->
pData
;
SColumnInfoData
*
pDestTsCol
=
taosArrayGet
(
pUpdateRes
->
pDataBlock
,
START_TS_COLUMN_INDEX
);
SColumnInfoData
*
pDestGpCol
=
taosArrayGet
(
pUpdateRes
->
pDataBlock
,
DELETE_GROUPID_COLUMN_INDEX
);
for
(
int32_t
i
=
pInfo
->
deleteDataIndex
;
i
<
pDelBlock
->
info
.
rows
&&
i
<
pDelBlock
->
info
.
capacity
-
(
endData
[
i
]
-
startData
[
i
])
/
pInfo
->
interval
.
interval
-
1
;
i
++
)
{
uint64_t
groupId
=
getGroupId
(
pOperator
,
uidCol
[
i
]);
for
(
TSKEY
startTs
=
startData
[
i
];
startTs
<=
endData
[
i
];
)
{
colDataAppend
(
pDestTsCol
,
pUpdateRes
->
info
.
rows
,
(
const
char
*
)
&
startTs
,
false
);
colDataAppend
(
pDestGpCol
,
pUpdateRes
->
info
.
rows
,
(
const
char
*
)
&
groupId
,
false
);
pUpdateRes
->
info
.
rows
++
;
startTs
=
taosTimeAdd
(
startTs
,
pInfo
->
interval
.
interval
,
pInfo
->
interval
.
intervalUnit
,
pInfo
->
interval
.
precision
);
}
pInfo
->
deleteDataIndex
++
;
}
if
(
pInfo
->
deleteDataIndex
>
0
&&
pInfo
->
deleteDataIndex
==
pDelBlock
->
info
.
rows
)
{
blockDataCleanup
(
pDelBlock
);
pInfo
->
deleteDataIndex
=
0
;
}
}
static
void
setUpdateData
(
SStreamBlockScanInfo
*
pInfo
,
SSDataBlock
*
pBlock
,
SSDataBlock
*
pUpdateBlock
)
{
static
void
setUpdateData
(
SStreamBlockScanInfo
*
pInfo
,
SSDataBlock
*
pBlock
,
SSDataBlock
*
pUpdateBlock
)
{
blockDataCleanup
(
pUpdateBlock
);
blockDataCleanup
(
pUpdateBlock
);
int32_t
size
=
taosArrayGetSize
(
pInfo
->
tsArray
);
int32_t
size
=
taosArrayGetSize
(
pInfo
->
tsArray
);
...
@@ -953,11 +986,11 @@ static void setUpdateData(SStreamBlockScanInfo* pInfo, SSDataBlock* pBlock, SSDa
...
@@ -953,11 +986,11 @@ static void setUpdateData(SStreamBlockScanInfo* pInfo, SSDataBlock* pBlock, SSDa
blockDataEnsureCapacity
(
pUpdateBlock
,
size
);
blockDataEnsureCapacity
(
pUpdateBlock
,
size
);
int32_t
rowId
=
*
(
int32_t
*
)
taosArrayGet
(
pInfo
->
tsArray
,
pInfo
->
tsArrayIndex
);
int32_t
rowId
=
*
(
int32_t
*
)
taosArrayGet
(
pInfo
->
tsArray
,
pInfo
->
tsArrayIndex
);
pInfo
->
groupId
=
getGroupId
(
pInfo
->
pSnapshotReadOp
,
pBlock
,
rowI
d
);
pInfo
->
groupId
=
getGroupId
(
pInfo
->
pSnapshotReadOp
,
pBlock
->
info
.
ui
d
);
int32_t
i
=
0
;
int32_t
i
=
0
;
for
(;
i
<
size
;
i
++
)
{
for
(;
i
<
size
;
i
++
)
{
rowId
=
*
(
int32_t
*
)
taosArrayGet
(
pInfo
->
tsArray
,
i
+
pInfo
->
tsArrayIndex
);
rowId
=
*
(
int32_t
*
)
taosArrayGet
(
pInfo
->
tsArray
,
i
+
pInfo
->
tsArrayIndex
);
uint64_t
id
=
getGroupId
(
pInfo
->
pSnapshotReadOp
,
pBlock
,
rowI
d
);
uint64_t
id
=
getGroupId
(
pInfo
->
pSnapshotReadOp
,
pBlock
->
info
.
ui
d
);
if
(
pInfo
->
groupId
!=
id
)
{
if
(
pInfo
->
groupId
!=
id
)
{
break
;
break
;
}
}
...
@@ -974,28 +1007,32 @@ static void setUpdateData(SStreamBlockScanInfo* pInfo, SSDataBlock* pBlock, SSDa
...
@@ -974,28 +1007,32 @@ static void setUpdateData(SStreamBlockScanInfo* pInfo, SSDataBlock* pBlock, SSDa
if
(
size
>
0
&&
pInfo
->
tsArrayIndex
==
size
)
{
if
(
size
>
0
&&
pInfo
->
tsArrayIndex
==
size
)
{
taosArrayClear
(
pInfo
->
tsArray
);
taosArrayClear
(
pInfo
->
tsArray
);
}
}
if
(
size
==
0
)
{
copyDeleteDataBlock
(
pInfo
,
pInfo
->
pDeleteDataRes
,
pInfo
->
pSnapshotReadOp
,
pUpdateBlock
);
}
}
}
static
void
getUpdateDataBlock
(
SStreamBlockScanInfo
*
pInfo
,
bool
invertible
,
SSDataBlock
*
pBlock
,
static
void
checkUpdateData
(
SStreamBlockScanInfo
*
pInfo
,
bool
invertible
,
SSDataBlock
*
pBlock
,
SSDataBlock
*
pUpdateBlock
)
{
bool
out
)
{
SColumnInfoData
*
pColDataInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
pInfo
->
primaryTsIndex
);
SColumnInfoData
*
pColDataInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
pInfo
->
primaryTsIndex
);
ASSERT
(
pColDataInfo
->
info
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
);
ASSERT
(
pColDataInfo
->
info
.
type
==
TSDB_DATA_TYPE_TIMESTAMP
);
TSKEY
*
ts
=
(
TSKEY
*
)
pColDataInfo
->
pData
;
TSKEY
*
ts
=
(
TSKEY
*
)
pColDataInfo
->
pData
;
for
(
int32_t
rowId
=
0
;
rowId
<
pBlock
->
info
.
rows
;
rowId
++
)
{
for
(
int32_t
rowId
=
0
;
rowId
<
pBlock
->
info
.
rows
;
rowId
++
)
{
if
(
updateInfoIsUpdated
(
pInfo
->
pUpdateInfo
,
pBlock
->
info
.
uid
,
ts
[
rowId
]))
{
if
(
updateInfoIsUpdated
(
pInfo
->
pUpdateInfo
,
pBlock
->
info
.
uid
,
ts
[
rowId
])
&&
out
)
{
taosArrayPush
(
pInfo
->
tsArray
,
&
rowId
);
taosArrayPush
(
pInfo
->
tsArray
,
&
rowId
);
}
}
}
}
if
(
!
pUpdateBlock
)
{
}
taosArrayClear
(
pInfo
->
tsArray
);
return
;
static
void
setBlockGroupId
(
SOperatorInfo
*
pOperator
,
SSDataBlock
*
pBlock
,
int32_t
uidColIndex
)
{
ASSERT
(
taosArrayGetSize
(
pBlock
->
pDataBlock
)
>=
3
);
SColumnInfoData
*
pColDataInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
uidColIndex
);
uint64_t
*
uidCol
=
(
uint64_t
*
)
pColDataInfo
->
pData
;
ASSERT
(
pBlock
->
info
.
rows
>
0
);
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
rows
;
i
++
)
{
uidCol
[
i
]
=
getGroupId
(
pOperator
,
uidCol
[
i
]);
}
}
setUpdateData
(
pInfo
,
pBlock
,
pUpdateBlock
);
// Todo(liuyao) get from tsdb
// SSDataBlock* p = createOneDataBlock(pBlock, true);
// p->info.type = STREAM_INVERT;
// taosArrayClear(pInfo->tsArray);
// return p;
}
}
static
SSDataBlock
*
doStreamBlockScan
(
SOperatorInfo
*
pOperator
)
{
static
SSDataBlock
*
doStreamBlockScan
(
SOperatorInfo
*
pOperator
)
{
...
@@ -1020,13 +1057,29 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
...
@@ -1020,13 +1057,29 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
int32_t
current
=
pInfo
->
validBlockIndex
++
;
int32_t
current
=
pInfo
->
validBlockIndex
++
;
SSDataBlock
*
pBlock
=
taosArrayGetP
(
pInfo
->
pBlockLists
,
current
);
SSDataBlock
*
pBlock
=
taosArrayGetP
(
pInfo
->
pBlockLists
,
current
);
blockDataUpdateTsWindow
(
pBlock
,
0
);
blockDataUpdateTsWindow
(
pBlock
,
0
);
if
(
pBlock
->
info
.
type
==
STREAM_RETRIEVE
)
{
switch
(
pBlock
->
info
.
type
)
{
case
STREAM_RETRIEVE
:{
pInfo
->
blockType
=
STREAM_INPUT__DATA_SUBMIT
;
pInfo
->
blockType
=
STREAM_INPUT__DATA_SUBMIT
;
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DATAREADER_RETRIEVE
;
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DATAREADER_RETRIEVE
;
copyDataBlock
(
pInfo
->
pPullDataRes
,
pBlock
);
copyDataBlock
(
pInfo
->
pPullDataRes
,
pBlock
);
pInfo
->
pullDataResIndex
=
0
;
pInfo
->
pullDataResIndex
=
0
;
prepareDataScan
(
pInfo
,
pInfo
->
pPullDataRes
,
0
,
&
pInfo
->
pullDataResIndex
);
prepareDataScan
(
pInfo
,
pInfo
->
pPullDataRes
,
START_TS_COLUMN_INDEX
,
&
pInfo
->
pullDataResIndex
);
updateInfoAddCloseWindowSBF
(
pInfo
->
pUpdateInfo
);
updateInfoAddCloseWindowSBF
(
pInfo
->
pUpdateInfo
);
}
break
;
case
STREAM_DELETE_DATA
:
{
pInfo
->
blockType
=
STREAM_INPUT__DATA_SUBMIT
;
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DATAREADER
;
copyDataBlock
(
pInfo
->
pDeleteDataRes
,
pBlock
);
copyDeleteDataBlock
(
pInfo
,
pInfo
->
pDeleteDataRes
,
pInfo
->
pSnapshotReadOp
,
pInfo
->
pUpdateRes
);
pInfo
->
updateResIndex
=
0
;
prepareDataScan
(
pInfo
,
pInfo
->
pUpdateRes
,
START_TS_COLUMN_INDEX
,
&
pInfo
->
updateResIndex
);
pInfo
->
pUpdateRes
->
info
.
type
=
STREAM_DELETE_DATA
;
return
pInfo
->
pUpdateRes
;
}
break
;
default:
break
;
}
}
return
pBlock
;
return
pBlock
;
}
else
if
(
pInfo
->
blockType
==
STREAM_INPUT__DATA_SUBMIT
)
{
}
else
if
(
pInfo
->
blockType
==
STREAM_INPUT__DATA_SUBMIT
)
{
...
@@ -1043,39 +1096,33 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
...
@@ -1043,39 +1096,33 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
}
else
if
(
pInfo
->
scanMode
==
STREAM_SCAN_FROM_DATAREADER_RETRIEVE
)
{
}
else
if
(
pInfo
->
scanMode
==
STREAM_SCAN_FROM_DATAREADER_RETRIEVE
)
{
SSDataBlock
*
pSDB
=
doDataScan
(
pInfo
,
pInfo
->
pPullDataRes
,
0
,
&
pInfo
->
pullDataResIndex
);
SSDataBlock
*
pSDB
=
doDataScan
(
pInfo
,
pInfo
->
pPullDataRes
,
0
,
&
pInfo
->
pullDataResIndex
);
if
(
pSDB
!=
NULL
)
{
if
(
pSDB
!=
NULL
)
{
getUpdateDataBlock
(
pInfo
,
true
,
pSDB
,
NULL
);
checkUpdateData
(
pInfo
,
true
,
pSDB
,
false
);
pSDB
->
info
.
type
=
STREAM_PULL_DATA
;
pSDB
->
info
.
type
=
STREAM_PULL_DATA
;
return
pSDB
;
return
pSDB
;
}
}
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DATAREADER
;
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DATAREADER
;
}
else
{
}
else
if
(
pInfo
->
scanMode
==
STREAM_SCAN_FROM_DATAREADER
)
{
if
(
isStateWindow
(
pInfo
))
{
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DATAREADER
;
pInfo
->
updateResIndex
=
pInfo
->
pUpdateRes
->
info
.
rows
;
if
(
!
prepareDataScan
(
pInfo
,
pInfo
->
pUpdateRes
,
pInfo
->
primaryTsIndex
,
&
pInfo
->
updateResIndex
))
{
pInfo
->
scanMode
=
STREAM_SCAN_FROM_READERHANDLE
;
}
}
if
(
pInfo
->
scanMode
==
STREAM_SCAN_FROM_DATAREADER
)
{
SSDataBlock
*
pSDB
=
doDataScan
(
pInfo
,
pInfo
->
pUpdateRes
,
pInfo
->
primaryTsIndex
,
&
pInfo
->
updateResIndex
);
SSDataBlock
*
pSDB
=
doDataScan
(
pInfo
,
pInfo
->
pUpdateRes
,
pInfo
->
primaryTsIndex
,
&
pInfo
->
updateResIndex
);
if
(
pSDB
==
NULL
)
{
if
(
pSDB
)
{
pSDB
->
info
.
type
=
STREAM_NORMAL
;
checkUpdateData
(
pInfo
,
true
,
pSDB
,
false
);
return
pSDB
;
}
setUpdateData
(
pInfo
,
pInfo
->
pRes
,
pInfo
->
pUpdateRes
);
setUpdateData
(
pInfo
,
pInfo
->
pRes
,
pInfo
->
pUpdateRes
);
if
(
pInfo
->
pUpdateRes
->
info
.
rows
>
0
)
{
if
(
pInfo
->
pUpdateRes
->
info
.
rows
>
0
)
{
if
(
!
isStateWindow
(
pInfo
))
{
prepareDataScan
(
pInfo
,
pInfo
->
pUpdateRes
,
pInfo
->
primaryTsIndex
,
&
pInfo
->
updateResIndex
);
// Todo(liuyao) mybe can delete this.
bool
test
=
prepareDataScan
(
pInfo
,
pInfo
->
pUpdateRes
,
pInfo
->
primaryTsIndex
,
&
pInfo
->
updateResIndex
);
ASSERT
(
test
==
false
);
}
return
pInfo
->
pUpdateRes
;
return
pInfo
->
pUpdateRes
;
}
else
{
pInfo
->
scanMode
=
STREAM_SCAN_FROM_READERHANDLE
;
}
}
else
{
pSDB
->
info
.
type
=
STREAM_NORMAL
;
getUpdateDataBlock
(
pInfo
,
true
,
pSDB
,
NULL
);
return
pSDB
;
}
}
pInfo
->
scanMode
=
STREAM_SCAN_FROM_READERHANDLE
;
}
else
if
(
isStateWindow
(
pInfo
))
{
pInfo
->
scanMode
=
STREAM_SCAN_FROM_DATAREADER
;
pInfo
->
updateResIndex
=
pInfo
->
pUpdateRes
->
info
.
rows
;
if
(
prepareDataScan
(
pInfo
,
pInfo
->
pUpdateRes
,
pInfo
->
primaryTsIndex
,
&
pInfo
->
updateResIndex
))
{
ASSERT
(
pInfo
->
pUpdateRes
->
info
.
rows
==
0
);
// return empty data blcok
return
pInfo
->
pUpdateRes
;
}
}
pInfo
->
scanMode
=
STREAM_SCAN_FROM_READERHANDLE
;
}
}
SDataBlockInfo
*
pBlockInfo
=
&
pInfo
->
pRes
->
info
;
SDataBlockInfo
*
pBlockInfo
=
&
pInfo
->
pRes
->
info
;
...
@@ -1169,7 +1216,8 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
...
@@ -1169,7 +1216,8 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
pOperator
->
status
=
OP_EXEC_DONE
;
pOperator
->
status
=
OP_EXEC_DONE
;
}
else
if
(
pInfo
->
pUpdateInfo
)
{
}
else
if
(
pInfo
->
pUpdateInfo
)
{
pInfo
->
tsArrayIndex
=
0
;
pInfo
->
tsArrayIndex
=
0
;
getUpdateDataBlock
(
pInfo
,
true
,
pInfo
->
pRes
,
pInfo
->
pUpdateRes
);
checkUpdateData
(
pInfo
,
true
,
pInfo
->
pRes
,
true
);
setUpdateData
(
pInfo
,
pInfo
->
pRes
,
pInfo
->
pUpdateRes
);
if
(
pInfo
->
pUpdateRes
->
info
.
rows
>
0
)
{
if
(
pInfo
->
pUpdateRes
->
info
.
rows
>
0
)
{
if
(
pInfo
->
pUpdateRes
->
info
.
type
==
STREAM_CLEAR
)
{
if
(
pInfo
->
pUpdateRes
->
info
.
type
==
STREAM_CLEAR
)
{
pInfo
->
updateResIndex
=
0
;
pInfo
->
updateResIndex
=
0
;
...
@@ -1180,9 +1228,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
...
@@ -1180,9 +1228,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
}
}
}
}
}
}
return
(
pBlockInfo
->
rows
==
0
)
?
NULL
:
pInfo
->
pRes
;
return
(
pBlockInfo
->
rows
==
0
)
?
NULL
:
pInfo
->
pRes
;
}
else
if
(
pInfo
->
blockType
==
STREAM_INPUT__DATA_SCAN
)
{
}
else
if
(
pInfo
->
blockType
==
STREAM_INPUT__DATA_SCAN
)
{
// check reader last status
// check reader last status
// if not match, reset status
// if not match, reset status
...
@@ -1295,6 +1341,8 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
...
@@ -1295,6 +1341,8 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
pInfo
->
groupId
=
0
;
pInfo
->
groupId
=
0
;
pInfo
->
pPullDataRes
=
createPullDataBlock
();
pInfo
->
pPullDataRes
=
createPullDataBlock
();
pInfo
->
pStreamScanOp
=
pOperator
;
pInfo
->
pStreamScanOp
=
pOperator
;
pInfo
->
deleteDataIndex
=
0
;
pInfo
->
pDeleteDataRes
=
createPullDataBlock
();
pOperator
->
name
=
"StreamBlockScanOperator"
;
pOperator
->
name
=
"StreamBlockScanOperator"
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
;
...
@@ -1327,6 +1375,7 @@ static void destroySysScanOperator(void* param, int32_t numOfOutput) {
...
@@ -1327,6 +1375,7 @@ static void destroySysScanOperator(void* param, int32_t numOfOutput) {
}
}
taosArrayDestroy
(
pInfo
->
scanCols
);
taosArrayDestroy
(
pInfo
->
scanCols
);
taosMemoryFreeClear
(
pInfo
->
pUser
);
}
}
static
int32_t
getSysTableDbNameColId
(
const
char
*
pTable
)
{
static
int32_t
getSysTableDbNameColId
(
const
char
*
pTable
)
{
...
@@ -1748,8 +1797,8 @@ int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capacity) {
...
@@ -1748,8 +1797,8 @@ int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capacity) {
getPerfDbMeta
(
&
pSysDbTableMeta
,
&
size
);
getPerfDbMeta
(
&
pSysDbTableMeta
,
&
size
);
p
->
info
.
rows
=
buildDbTableInfoBlock
(
p
,
pSysDbTableMeta
,
size
,
TSDB_PERFORMANCE_SCHEMA_DB
);
p
->
info
.
rows
=
buildDbTableInfoBlock
(
p
,
pSysDbTableMeta
,
size
,
TSDB_PERFORMANCE_SCHEMA_DB
);
relocateColumnData
(
pInfo
->
pRes
,
pInfo
->
scanCols
,
p
->
pDataBlock
,
false
);
pInfo
->
pRes
->
info
.
rows
=
p
->
info
.
rows
;
pInfo
->
pRes
->
info
.
rows
=
p
->
info
.
rows
;
relocateColumnData
(
pInfo
->
pRes
,
pInfo
->
scanCols
,
p
->
pDataBlock
,
false
);
blockDataDestroy
(
p
);
blockDataDestroy
(
p
);
return
pInfo
->
pRes
->
info
.
rows
;
return
pInfo
->
pRes
->
info
.
rows
;
...
...
source/libs/executor/src/timewindowoperator.c
浏览文件 @
4fb1ef08
此差异已折叠。
点击以展开。
source/libs/function/src/builtins.c
浏览文件 @
4fb1ef08
...
@@ -15,10 +15,10 @@
...
@@ -15,10 +15,10 @@
#include "builtins.h"
#include "builtins.h"
#include "builtinsimpl.h"
#include "builtinsimpl.h"
#include "cJSON.h"
#include "querynodes.h"
#include "querynodes.h"
#include "scalar.h"
#include "scalar.h"
#include "taoserror.h"
#include "taoserror.h"
#include "cJSON.h"
static
int32_t
buildFuncErrMsg
(
char
*
pErrBuf
,
int32_t
len
,
int32_t
errCode
,
const
char
*
pFormat
,
...)
{
static
int32_t
buildFuncErrMsg
(
char
*
pErrBuf
,
int32_t
len
,
int32_t
errCode
,
const
char
*
pFormat
,
...)
{
va_list
vArgList
;
va_list
vArgList
;
...
@@ -48,14 +48,19 @@ static int32_t validateTimeUnitParam(uint8_t dbPrec, const SValueNode* pVal) {
...
@@ -48,14 +48,19 @@ static int32_t validateTimeUnitParam(uint8_t dbPrec, const SValueNode* pVal) {
return
TIME_UNIT_INVALID
;
return
TIME_UNIT_INVALID
;
}
}
if
(
TSDB_TIME_PRECISION_MILLI
==
dbPrec
&&
0
==
strcasecmp
(
pVal
->
literal
,
"1u"
))
{
if
(
TSDB_TIME_PRECISION_MILLI
==
dbPrec
&&
(
0
==
strcasecmp
(
pVal
->
literal
,
"1u"
)
||
0
==
strcasecmp
(
pVal
->
literal
,
"1b"
)))
{
return
TIME_UNIT_TOO_SMALL
;
}
if
(
TSDB_TIME_PRECISION_MICRO
==
dbPrec
&&
0
==
strcasecmp
(
pVal
->
literal
,
"1b"
))
{
return
TIME_UNIT_TOO_SMALL
;
return
TIME_UNIT_TOO_SMALL
;
}
}
if
(
pVal
->
literal
[
0
]
!=
'1'
||
(
pVal
->
literal
[
1
]
!=
'u'
&&
pVal
->
literal
[
1
]
!=
'a'
&&
if
(
pVal
->
literal
[
0
]
!=
'1'
||
(
pVal
->
literal
[
1
]
!=
'u'
&&
pVal
->
literal
[
1
]
!=
'a'
&&
pVal
->
literal
[
1
]
!=
's'
&&
pVal
->
literal
[
1
]
!=
'm'
&&
pVal
->
literal
[
1
]
!=
's'
&&
pVal
->
literal
[
1
]
!=
'm'
&&
pVal
->
literal
[
1
]
!=
'h'
&&
pVal
->
literal
[
1
]
!=
'd'
&&
pVal
->
literal
[
1
]
!=
'h'
&&
pVal
->
literal
[
1
]
!=
'd'
&&
pVal
->
literal
[
1
]
!=
'w'
))
{
pVal
->
literal
[
1
]
!=
'w'
&&
pVal
->
literal
[
1
]
!=
'b'
))
{
return
TIME_UNIT_INVALID
;
return
TIME_UNIT_INVALID
;
}
}
...
@@ -696,13 +701,13 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
...
@@ -696,13 +701,13 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
int32_t
ret
=
validateTimeUnitParam
(
dbPrec
,
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
));
int32_t
ret
=
validateTimeUnitParam
(
dbPrec
,
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
));
if
(
ret
==
TIME_UNIT_TOO_SMALL
)
{
if
(
ret
==
TIME_UNIT_TOO_SMALL
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"ELAPSED function time unit parameter should be greater than db precision"
);
"ELAPSED function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"ELAPSED function time unit parameter should be one of the following: [1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
"ELAPSED function time unit parameter should be one of the following: [1
b, 1
u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
}
}
}
...
@@ -815,13 +820,13 @@ static int8_t validateHistogramBinType(char* binTypeStr) {
...
@@ -815,13 +820,13 @@ static int8_t validateHistogramBinType(char* binTypeStr) {
}
}
static
bool
validateHistogramBinDesc
(
char
*
binDescStr
,
int8_t
binType
,
char
*
errMsg
,
int32_t
msgLen
)
{
static
bool
validateHistogramBinDesc
(
char
*
binDescStr
,
int8_t
binType
,
char
*
errMsg
,
int32_t
msgLen
)
{
const
char
*
msg1
=
"HISTOGRAM function requires four parameters"
;
const
char
*
msg1
=
"HISTOGRAM function requires four parameters"
;
const
char
*
msg3
=
"HISTOGRAM function invalid format for binDesc parameter"
;
const
char
*
msg3
=
"HISTOGRAM function invalid format for binDesc parameter"
;
const
char
*
msg4
=
"HISTOGRAM function binDesc parameter
\"
count
\"
should be in range [1, 1000]"
;
const
char
*
msg4
=
"HISTOGRAM function binDesc parameter
\"
count
\"
should be in range [1, 1000]"
;
const
char
*
msg5
=
"HISTOGRAM function bin/parameter should be in range [-DBL_MAX, DBL_MAX]"
;
const
char
*
msg5
=
"HISTOGRAM function bin/parameter should be in range [-DBL_MAX, DBL_MAX]"
;
const
char
*
msg6
=
"HISTOGRAM function binDesc parameter
\"
width
\"
cannot be 0"
;
const
char
*
msg6
=
"HISTOGRAM function binDesc parameter
\"
width
\"
cannot be 0"
;
const
char
*
msg7
=
"HISTOGRAM function binDesc parameter
\"
start
\"
cannot be 0 with
\"
log_bin
\"
type"
;
const
char
*
msg7
=
"HISTOGRAM function binDesc parameter
\"
start
\"
cannot be 0 with
\"
log_bin
\"
type"
;
const
char
*
msg8
=
"HISTOGRAM function binDesc parameter
\"
factor
\"
cannot be negative or equal to 0/1"
;
const
char
*
msg8
=
"HISTOGRAM function binDesc parameter
\"
factor
\"
cannot be negative or equal to 0/1"
;
cJSON
*
binDesc
=
cJSON_Parse
(
binDescStr
);
cJSON
*
binDesc
=
cJSON_Parse
(
binDescStr
);
int32_t
numOfBins
;
int32_t
numOfBins
;
...
@@ -1218,13 +1223,13 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32
...
@@ -1218,13 +1223,13 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32
if
(
numOfParams
==
4
)
{
if
(
numOfParams
==
4
)
{
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
int32_t
ret
=
validateTimeUnitParam
(
dbPrec
,
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
3
));
int32_t
ret
=
validateTimeUnitParam
(
dbPrec
,
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
3
));
if
(
ret
==
TIME_UNIT_TOO_SMALL
)
{
if
(
ret
==
TIME_UNIT_TOO_SMALL
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"STATEDURATION function time unit parameter should be greater than db precision"
);
"STATEDURATION function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"STATEDURATION function time unit parameter should be one of the following: [1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
"STATEDURATION function time unit parameter should be one of the following: [1
b, 1
u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
}
}
}
...
@@ -1432,10 +1437,6 @@ static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t l
...
@@ -1432,10 +1437,6 @@ static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t l
static
int32_t
translateFirstLastImpl
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
,
bool
isPartial
)
{
static
int32_t
translateFirstLastImpl
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
,
bool
isPartial
)
{
// first(col_list) will be rewritten as first(col)
// first(col_list) will be rewritten as first(col)
if
(
2
!=
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
// input has two params c0,ts, is this a bug?
return
TSDB_CODE_SUCCESS
;
}
SNode
*
pPara
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
SNode
*
pPara
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
uint8_t
paraType
=
((
SExprNode
*
)
pPara
)
->
resType
.
type
;
uint8_t
paraType
=
((
SExprNode
*
)
pPara
)
->
resType
.
type
;
int32_t
paraBytes
=
((
SExprNode
*
)
pPara
)
->
resType
.
bytes
;
int32_t
paraBytes
=
((
SExprNode
*
)
pPara
)
->
resType
.
bytes
;
...
@@ -1733,13 +1734,13 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
...
@@ -1733,13 +1734,13 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
// add database precision as param
// add database precision as param
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
int32_t
ret
=
validateTimeUnitParam
(
dbPrec
,
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
));
int32_t
ret
=
validateTimeUnitParam
(
dbPrec
,
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
));
if
(
ret
==
TIME_UNIT_TOO_SMALL
)
{
if
(
ret
==
TIME_UNIT_TOO_SMALL
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMETRUNCATE function time unit parameter should be greater than db precision"
);
"TIMETRUNCATE function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMETRUNCATE function time unit parameter should be one of the following: [1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
"TIMETRUNCATE function time unit parameter should be one of the following: [1
b, 1
u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
}
addDbPrecisonParam
(
&
pFunc
->
pParameterList
,
dbPrec
);
addDbPrecisonParam
(
&
pFunc
->
pParameterList
,
dbPrec
);
...
@@ -1772,13 +1773,13 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le
...
@@ -1772,13 +1773,13 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
if
(
3
==
numOfParams
)
{
if
(
3
==
numOfParams
)
{
int32_t
ret
=
validateTimeUnitParam
(
dbPrec
,
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
2
));
int32_t
ret
=
validateTimeUnitParam
(
dbPrec
,
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
2
));
if
(
ret
==
TIME_UNIT_TOO_SMALL
)
{
if
(
ret
==
TIME_UNIT_TOO_SMALL
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMEDIFF function time unit parameter should be greater than db precision"
);
"TIMEDIFF function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMEDIFF function time unit parameter should be one of the following: [1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
"TIMEDIFF function time unit parameter should be one of the following: [1
b, 1
u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
}
}
}
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
4fb1ef08
...
@@ -92,10 +92,12 @@ typedef struct SStddevRes {
...
@@ -92,10 +92,12 @@ typedef struct SStddevRes {
union
{
union
{
double
quadraticDSum
;
double
quadraticDSum
;
int64_t
quadraticISum
;
int64_t
quadraticISum
;
uint64_t
quadraticUSum
;
};
};
union
{
union
{
double
dsum
;
double
dsum
;
int64_t
isum
;
int64_t
isum
;
uint64_t
usum
;
};
};
int16_t
type
;
int16_t
type
;
}
SStddevRes
;
}
SStddevRes
;
...
@@ -1729,6 +1731,68 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) {
...
@@ -1729,6 +1731,68 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) {
break
;
break
;
}
}
case
TSDB_DATA_TYPE_UTINYINT
:
{
uint8_t
*
plist
=
(
uint8_t
*
)
pCol
->
pData
;
for
(
int32_t
i
=
start
;
i
<
numOfRows
+
start
;
++
i
)
{
if
(
pCol
->
hasNull
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
numOfElem
+=
1
;
pStddevRes
->
count
+=
1
;
pStddevRes
->
usum
+=
plist
[
i
];
pStddevRes
->
quadraticISum
+=
plist
[
i
]
*
plist
[
i
];
}
break
;
}
case
TSDB_DATA_TYPE_USMALLINT
:
{
uint16_t
*
plist
=
(
uint16_t
*
)
pCol
->
pData
;
for
(
int32_t
i
=
start
;
i
<
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
if
(
pCol
->
hasNull
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
numOfElem
+=
1
;
pStddevRes
->
count
+=
1
;
pStddevRes
->
usum
+=
plist
[
i
];
pStddevRes
->
quadraticISum
+=
plist
[
i
]
*
plist
[
i
];
}
break
;
}
case
TSDB_DATA_TYPE_UINT
:
{
uint32_t
*
plist
=
(
uint32_t
*
)
pCol
->
pData
;
for
(
int32_t
i
=
start
;
i
<
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
if
(
pCol
->
hasNull
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
numOfElem
+=
1
;
pStddevRes
->
count
+=
1
;
pStddevRes
->
usum
+=
plist
[
i
];
pStddevRes
->
quadraticISum
+=
plist
[
i
]
*
plist
[
i
];
}
break
;
}
case
TSDB_DATA_TYPE_UBIGINT
:
{
uint64_t
*
plist
=
(
uint64_t
*
)
pCol
->
pData
;
for
(
int32_t
i
=
start
;
i
<
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
if
(
pCol
->
hasNull
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
numOfElem
+=
1
;
pStddevRes
->
count
+=
1
;
pStddevRes
->
usum
+=
plist
[
i
];
pStddevRes
->
quadraticISum
+=
plist
[
i
]
*
plist
[
i
];
}
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
case
TSDB_DATA_TYPE_FLOAT
:
{
float
*
plist
=
(
float
*
)
pCol
->
pData
;
float
*
plist
=
(
float
*
)
pCol
->
pData
;
for
(
int32_t
i
=
start
;
i
<
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
for
(
int32_t
i
=
start
;
i
<
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
...
@@ -1771,9 +1835,12 @@ _stddev_over:
...
@@ -1771,9 +1835,12 @@ _stddev_over:
static
void
stddevTransferInfo
(
SStddevRes
*
pInput
,
SStddevRes
*
pOutput
)
{
static
void
stddevTransferInfo
(
SStddevRes
*
pInput
,
SStddevRes
*
pOutput
)
{
pOutput
->
type
=
pInput
->
type
;
pOutput
->
type
=
pInput
->
type
;
if
(
IS_
INTEGER
_TYPE
(
pOutput
->
type
))
{
if
(
IS_
SIGNED_NUMERIC
_TYPE
(
pOutput
->
type
))
{
pOutput
->
quadraticISum
+=
pInput
->
quadraticISum
;
pOutput
->
quadraticISum
+=
pInput
->
quadraticISum
;
pOutput
->
isum
+=
pInput
->
isum
;
pOutput
->
isum
+=
pInput
->
isum
;
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
pOutput
->
type
))
{
pOutput
->
quadraticUSum
+=
pInput
->
quadraticUSum
;
pOutput
->
usum
+=
pInput
->
usum
;
}
else
{
}
else
{
pOutput
->
quadraticDSum
+=
pInput
->
quadraticDSum
;
pOutput
->
quadraticDSum
+=
pInput
->
quadraticDSum
;
pOutput
->
dsum
+=
pInput
->
dsum
;
pOutput
->
dsum
+=
pInput
->
dsum
;
...
@@ -1848,6 +1915,22 @@ int32_t stddevInvertFunction(SqlFunctionCtx* pCtx) {
...
@@ -1848,6 +1915,22 @@ int32_t stddevInvertFunction(SqlFunctionCtx* pCtx) {
LIST_STDDEV_SUB_N
(
pStddevRes
->
isum
,
int64_t
);
LIST_STDDEV_SUB_N
(
pStddevRes
->
isum
,
int64_t
);
break
;
break
;
}
}
case
TSDB_DATA_TYPE_UTINYINT
:
{
LIST_STDDEV_SUB_N
(
pStddevRes
->
isum
,
uint8_t
);
break
;
}
case
TSDB_DATA_TYPE_USMALLINT
:
{
LIST_STDDEV_SUB_N
(
pStddevRes
->
isum
,
uint16_t
);
break
;
}
case
TSDB_DATA_TYPE_UINT
:
{
LIST_STDDEV_SUB_N
(
pStddevRes
->
isum
,
uint32_t
);
break
;
}
case
TSDB_DATA_TYPE_UBIGINT
:
{
LIST_STDDEV_SUB_N
(
pStddevRes
->
isum
,
uint64_t
);
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
case
TSDB_DATA_TYPE_FLOAT
:
{
LIST_STDDEV_SUB_N
(
pStddevRes
->
dsum
,
float
);
LIST_STDDEV_SUB_N
(
pStddevRes
->
dsum
,
float
);
break
;
break
;
...
@@ -1871,9 +1954,12 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
...
@@ -1871,9 +1954,12 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t
type
=
pStddevRes
->
type
;
int32_t
type
=
pStddevRes
->
type
;
double
avg
;
double
avg
;
if
(
IS_
INTEGER
_TYPE
(
type
))
{
if
(
IS_
SIGNED_NUMERIC
_TYPE
(
type
))
{
avg
=
pStddevRes
->
isum
/
((
double
)
pStddevRes
->
count
);
avg
=
pStddevRes
->
isum
/
((
double
)
pStddevRes
->
count
);
pStddevRes
->
result
=
sqrt
(
fabs
(
pStddevRes
->
quadraticISum
/
((
double
)
pStddevRes
->
count
)
-
avg
*
avg
));
pStddevRes
->
result
=
sqrt
(
fabs
(
pStddevRes
->
quadraticISum
/
((
double
)
pStddevRes
->
count
)
-
avg
*
avg
));
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
avg
=
pStddevRes
->
usum
/
((
double
)
pStddevRes
->
count
);
pStddevRes
->
result
=
sqrt
(
fabs
(
pStddevRes
->
quadraticUSum
/
((
double
)
pStddevRes
->
count
)
-
avg
*
avg
));
}
else
{
}
else
{
avg
=
pStddevRes
->
dsum
/
((
double
)
pStddevRes
->
count
);
avg
=
pStddevRes
->
dsum
/
((
double
)
pStddevRes
->
count
);
pStddevRes
->
result
=
sqrt
(
fabs
(
pStddevRes
->
quadraticDSum
/
((
double
)
pStddevRes
->
count
)
-
avg
*
avg
));
pStddevRes
->
result
=
sqrt
(
fabs
(
pStddevRes
->
quadraticDSum
/
((
double
)
pStddevRes
->
count
)
-
avg
*
avg
));
...
@@ -1913,9 +1999,12 @@ int32_t stddevCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
...
@@ -1913,9 +1999,12 @@ int32_t stddevCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
SResultRowEntryInfo
*
pSResInfo
=
GET_RES_INFO
(
pSourceCtx
);
SResultRowEntryInfo
*
pSResInfo
=
GET_RES_INFO
(
pSourceCtx
);
SStddevRes
*
pSBuf
=
GET_ROWCELL_INTERBUF
(
pSResInfo
);
SStddevRes
*
pSBuf
=
GET_ROWCELL_INTERBUF
(
pSResInfo
);
if
(
IS_
INTEGER
_TYPE
(
type
))
{
if
(
IS_
SIGNED_NUMERIC
_TYPE
(
type
))
{
pDBuf
->
isum
+=
pSBuf
->
isum
;
pDBuf
->
isum
+=
pSBuf
->
isum
;
pDBuf
->
quadraticISum
+=
pSBuf
->
quadraticISum
;
pDBuf
->
quadraticISum
+=
pSBuf
->
quadraticISum
;
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
pDBuf
->
usum
+=
pSBuf
->
usum
;
pDBuf
->
quadraticUSum
+=
pSBuf
->
quadraticUSum
;
}
else
{
}
else
{
pDBuf
->
dsum
+=
pSBuf
->
dsum
;
pDBuf
->
dsum
+=
pSBuf
->
dsum
;
pDBuf
->
quadraticDSum
+=
pSBuf
->
quadraticDSum
;
pDBuf
->
quadraticDSum
+=
pSBuf
->
quadraticDSum
;
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
4fb1ef08
...
@@ -385,6 +385,15 @@ SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType typ
...
@@ -385,6 +385,15 @@ SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType typ
SNode
*
createOperatorNode
(
SAstCreateContext
*
pCxt
,
EOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
)
{
SNode
*
createOperatorNode
(
SAstCreateContext
*
pCxt
,
EOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
)
{
CHECK_PARSER_STATUS
(
pCxt
);
CHECK_PARSER_STATUS
(
pCxt
);
if
(
OP_TYPE_MINUS
==
type
&&
QUERY_NODE_VALUE
==
nodeType
(
pLeft
))
{
SValueNode
*
pVal
=
(
SValueNode
*
)
pLeft
;
char
*
pNewLiteral
=
taosMemoryCalloc
(
1
,
strlen
(
pVal
->
literal
)
+
2
);
CHECK_OUT_OF_MEM
(
pNewLiteral
);
sprintf
(
pNewLiteral
,
"-%s"
,
pVal
->
literal
);
taosMemoryFree
(
pVal
->
literal
);
pVal
->
literal
=
pNewLiteral
;
return
pLeft
;
}
SOperatorNode
*
op
=
(
SOperatorNode
*
)
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
SOperatorNode
*
op
=
(
SOperatorNode
*
)
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
CHECK_OUT_OF_MEM
(
op
);
CHECK_OUT_OF_MEM
(
op
);
op
->
opType
=
type
;
op
->
opType
=
type
;
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
4fb1ef08
...
@@ -558,11 +558,11 @@ static void setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColum
...
@@ -558,11 +558,11 @@ static void setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColum
pCol
->
node
.
resType
=
pExpr
->
resType
;
pCol
->
node
.
resType
=
pExpr
->
resType
;
}
}
static
int32_t
createColumnsByTable
(
STranslateContext
*
pCxt
,
const
STableNode
*
pTable
,
SNodeList
*
pList
)
{
static
int32_t
createColumnsByTable
(
STranslateContext
*
pCxt
,
const
STableNode
*
pTable
,
bool
igTags
,
SNodeList
*
pList
)
{
if
(
QUERY_NODE_REAL_TABLE
==
nodeType
(
pTable
))
{
if
(
QUERY_NODE_REAL_TABLE
==
nodeType
(
pTable
))
{
const
STableMeta
*
pMeta
=
((
SRealTableNode
*
)
pTable
)
->
pMeta
;
const
STableMeta
*
pMeta
=
((
SRealTableNode
*
)
pTable
)
->
pMeta
;
int32_t
nums
=
int32_t
nums
=
pMeta
->
tableInfo
.
numOfColumns
+
pMeta
->
tableInfo
.
numOfColumns
+
((
TSDB_SUPER_TABLE
==
pMeta
->
tableType
)
?
pMeta
->
tableInfo
.
numOfTags
:
0
);
(
igTags
?
0
:
((
TSDB_SUPER_TABLE
==
pMeta
->
tableType
)
?
pMeta
->
tableInfo
.
numOfTags
:
0
)
);
for
(
int32_t
i
=
0
;
i
<
nums
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
nums
;
++
i
)
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN
);
SColumnNode
*
pCol
=
(
SColumnNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN
);
if
(
NULL
==
pCol
)
{
if
(
NULL
==
pCol
)
{
...
@@ -878,6 +878,9 @@ static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal,
...
@@ -878,6 +878,9 @@ static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal,
}
}
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARBINARY
:
{
case
TSDB_DATA_TYPE_VARBINARY
:
{
if
(
strict
&&
(
pVal
->
node
.
resType
.
bytes
>
targetDt
.
bytes
-
VARSTR_HEADER_SIZE
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
targetDt
.
bytes
+
1
);
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
targetDt
.
bytes
+
1
);
if
(
NULL
==
pVal
->
datum
.
p
)
{
if
(
NULL
==
pVal
->
datum
.
p
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_OUT_OF_MEMORY
);
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_OUT_OF_MEMORY
);
...
@@ -1333,6 +1336,9 @@ static int32_t rewriteSystemInfoFuncImpl(STranslateContext* pCxt, char* pLiteral
...
@@ -1333,6 +1336,9 @@ static int32_t rewriteSystemInfoFuncImpl(STranslateContext* pCxt, char* pLiteral
pVal
->
isNull
=
true
;
pVal
->
isNull
=
true
;
}
else
{
}
else
{
pVal
->
literal
=
pLiteral
;
pVal
->
literal
=
pLiteral
;
if
(
IS_VAR_DATA_TYPE
(
pVal
->
node
.
resType
.
type
))
{
pVal
->
node
.
resType
.
bytes
=
strlen
(
pLiteral
);
}
}
}
if
(
DEAL_RES_ERROR
!=
translateValue
(
pCxt
,
pVal
))
{
if
(
DEAL_RES_ERROR
!=
translateValue
(
pCxt
,
pVal
))
{
*
pNode
=
(
SNode
*
)
pVal
;
*
pNode
=
(
SNode
*
)
pVal
;
...
@@ -1928,7 +1934,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
...
@@ -1928,7 +1934,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
return
code
;
return
code
;
}
}
static
int32_t
createAllColumns
(
STranslateContext
*
pCxt
,
SNodeList
**
pCols
)
{
static
int32_t
createAllColumns
(
STranslateContext
*
pCxt
,
bool
igTags
,
SNodeList
**
pCols
)
{
*
pCols
=
nodesMakeList
();
*
pCols
=
nodesMakeList
();
if
(
NULL
==
*
pCols
)
{
if
(
NULL
==
*
pCols
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_OUT_OF_MEMORY
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_OUT_OF_MEMORY
);
...
@@ -1937,7 +1943,7 @@ static int32_t createAllColumns(STranslateContext* pCxt, SNodeList** pCols) {
...
@@ -1937,7 +1943,7 @@ static int32_t createAllColumns(STranslateContext* pCxt, SNodeList** pCols) {
size_t
nums
=
taosArrayGetSize
(
pTables
);
size_t
nums
=
taosArrayGetSize
(
pTables
);
for
(
size_t
i
=
0
;
i
<
nums
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
nums
;
++
i
)
{
STableNode
*
pTable
=
taosArrayGetP
(
pTables
,
i
);
STableNode
*
pTable
=
taosArrayGetP
(
pTables
,
i
);
int32_t
code
=
createColumnsByTable
(
pCxt
,
pTable
,
*
pCols
);
int32_t
code
=
createColumnsByTable
(
pCxt
,
pTable
,
igTags
,
*
pCols
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
return
code
;
}
}
...
@@ -1974,7 +1980,7 @@ static SNode* createMultiResFunc(SFunctionNode* pSrcFunc, SExprNode* pExpr) {
...
@@ -1974,7 +1980,7 @@ static SNode* createMultiResFunc(SFunctionNode* pSrcFunc, SExprNode* pExpr) {
return
(
SNode
*
)
pFunc
;
return
(
SNode
*
)
pFunc
;
}
}
static
int32_t
createTableAllCols
(
STranslateContext
*
pCxt
,
SColumnNode
*
pCol
,
SNodeList
**
pOutput
)
{
static
int32_t
createTableAllCols
(
STranslateContext
*
pCxt
,
SColumnNode
*
pCol
,
bool
igTags
,
SNodeList
**
pOutput
)
{
STableNode
*
pTable
=
NULL
;
STableNode
*
pTable
=
NULL
;
int32_t
code
=
findTable
(
pCxt
,
pCol
->
tableAlias
,
&
pTable
);
int32_t
code
=
findTable
(
pCxt
,
pCol
->
tableAlias
,
&
pTable
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
==
*
pOutput
)
{
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
==
*
pOutput
)
{
...
@@ -1984,7 +1990,7 @@ static int32_t createTableAllCols(STranslateContext* pCxt, SColumnNode* pCol, SN
...
@@ -1984,7 +1990,7 @@ static int32_t createTableAllCols(STranslateContext* pCxt, SColumnNode* pCol, SN
}
}
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
createColumnsByTable
(
pCxt
,
pTable
,
*
pOutput
);
code
=
createColumnsByTable
(
pCxt
,
pTable
,
igTags
,
*
pOutput
);
}
}
return
code
;
return
code
;
}
}
...
@@ -2006,11 +2012,9 @@ static int32_t createMultiResFuncsParas(STranslateContext* pCxt, SNodeList* pSrc
...
@@ -2006,11 +2012,9 @@ static int32_t createMultiResFuncsParas(STranslateContext* pCxt, SNodeList* pSrc
SNode
*
pPara
=
NULL
;
SNode
*
pPara
=
NULL
;
FOREACH
(
pPara
,
pSrcParas
)
{
FOREACH
(
pPara
,
pSrcParas
)
{
if
(
isStar
(
pPara
))
{
if
(
isStar
(
pPara
))
{
code
=
createAllColumns
(
pCxt
,
&
pExprs
);
code
=
createAllColumns
(
pCxt
,
true
,
&
pExprs
);
// The syntax definition ensures that * and other parameters do not appear at the same time
break
;
}
else
if
(
isTableStar
(
pPara
))
{
}
else
if
(
isTableStar
(
pPara
))
{
code
=
createTableAllCols
(
pCxt
,
(
SColumnNode
*
)
pPara
,
&
pExprs
);
code
=
createTableAllCols
(
pCxt
,
(
SColumnNode
*
)
pPara
,
true
,
&
pExprs
);
}
else
{
}
else
{
code
=
nodesListMakeStrictAppend
(
&
pExprs
,
nodesCloneNode
(
pPara
));
code
=
nodesListMakeStrictAppend
(
&
pExprs
,
nodesCloneNode
(
pPara
));
}
}
...
@@ -2069,7 +2073,7 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
...
@@ -2069,7 +2073,7 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
isStar
(
pNode
))
{
if
(
isStar
(
pNode
))
{
SNodeList
*
pCols
=
NULL
;
SNodeList
*
pCols
=
NULL
;
code
=
createAllColumns
(
pCxt
,
&
pCols
);
code
=
createAllColumns
(
pCxt
,
false
,
&
pCols
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
INSERT_LIST
(
pSelect
->
pProjectionList
,
pCols
);
INSERT_LIST
(
pSelect
->
pProjectionList
,
pCols
);
ERASE_NODE
(
pSelect
->
pProjectionList
);
ERASE_NODE
(
pSelect
->
pProjectionList
);
...
@@ -2085,7 +2089,7 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
...
@@ -2085,7 +2089,7 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
}
}
}
else
if
(
isTableStar
(
pNode
))
{
}
else
if
(
isTableStar
(
pNode
))
{
SNodeList
*
pCols
=
NULL
;
SNodeList
*
pCols
=
NULL
;
code
=
createTableAllCols
(
pCxt
,
(
SColumnNode
*
)
pNode
,
&
pCols
);
code
=
createTableAllCols
(
pCxt
,
(
SColumnNode
*
)
pNode
,
false
,
&
pCols
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
INSERT_LIST
(
pSelect
->
pProjectionList
,
pCols
);
INSERT_LIST
(
pSelect
->
pProjectionList
,
pCols
);
ERASE_NODE
(
pSelect
->
pProjectionList
);
ERASE_NODE
(
pSelect
->
pProjectionList
);
...
@@ -5826,10 +5830,6 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
...
@@ -5826,10 +5830,6 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
return
pCxt
->
errCode
;
return
pCxt
->
errCode
;
}
}
if
(
IS_VAR_DATA_TYPE
(
pSchema
->
type
)
&&
strlen
(
pStmt
->
pVal
->
literal
)
>
pSchema
->
bytes
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pStmt
->
pVal
->
literal
);
}
pReq
->
isNull
=
(
TSDB_DATA_TYPE_NULL
==
pStmt
->
pVal
->
node
.
resType
.
type
);
pReq
->
isNull
=
(
TSDB_DATA_TYPE_NULL
==
pStmt
->
pVal
->
node
.
resType
.
type
);
if
(
targetDt
.
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
targetDt
.
type
==
TSDB_DATA_TYPE_JSON
)
{
pReq
->
isNull
=
0
;
pReq
->
isNull
=
0
;
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
4fb1ef08
...
@@ -236,7 +236,6 @@ int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char*
...
@@ -236,7 +236,6 @@ int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char*
const
char
*
prefix
=
"syntax error"
;
const
char
*
prefix
=
"syntax error"
;
if
(
sourceStr
==
NULL
)
{
if
(
sourceStr
==
NULL
)
{
assert
(
additionalInfo
!=
NULL
);
snprintf
(
pBuf
->
buf
,
pBuf
->
len
,
msgFormat1
,
additionalInfo
);
snprintf
(
pBuf
->
buf
,
pBuf
->
len
,
msgFormat1
,
additionalInfo
);
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
}
}
...
@@ -254,40 +253,25 @@ int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char*
...
@@ -254,40 +253,25 @@ int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char*
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
return
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
}
}
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
)
{
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
)
{
return
(
SSchema
*
)
pTableMeta
->
schema
;
}
assert
(
pTableMeta
!=
NULL
);
return
(
SSchema
*
)
pTableMeta
->
schema
;
}
static
SSchema
*
getOneColumnSchema
(
const
STableMeta
*
pTableMeta
,
int32_t
colIndex
)
{
static
SSchema
*
getOneColumnSchema
(
const
STableMeta
*
pTableMeta
,
int32_t
colIndex
)
{
assert
(
pTableMeta
!=
NULL
&&
pTableMeta
->
schema
!=
NULL
&&
colIndex
>=
0
&&
colIndex
<
(
getNumOfColumns
(
pTableMeta
)
+
getNumOfTags
(
pTableMeta
)));
SSchema
*
pSchema
=
(
SSchema
*
)
pTableMeta
->
schema
;
SSchema
*
pSchema
=
(
SSchema
*
)
pTableMeta
->
schema
;
return
&
pSchema
[
colIndex
];
return
&
pSchema
[
colIndex
];
}
}
SSchema
*
getTableTagSchema
(
const
STableMeta
*
pTableMeta
)
{
SSchema
*
getTableTagSchema
(
const
STableMeta
*
pTableMeta
)
{
assert
(
pTableMeta
!=
NULL
&&
(
pTableMeta
->
tableType
==
TSDB_SUPER_TABLE
||
pTableMeta
->
tableType
==
TSDB_CHILD_TABLE
));
return
getOneColumnSchema
(
pTableMeta
,
getTableInfo
(
pTableMeta
).
numOfColumns
);
return
getOneColumnSchema
(
pTableMeta
,
getTableInfo
(
pTableMeta
).
numOfColumns
);
}
}
int32_t
getNumOfColumns
(
const
STableMeta
*
pTableMeta
)
{
int32_t
getNumOfColumns
(
const
STableMeta
*
pTableMeta
)
{
assert
(
pTableMeta
!=
NULL
);
// table created according to super table, use data from super table
// table created according to super table, use data from super table
return
getTableInfo
(
pTableMeta
).
numOfColumns
;
return
getTableInfo
(
pTableMeta
).
numOfColumns
;
}
}
int32_t
getNumOfTags
(
const
STableMeta
*
pTableMeta
)
{
int32_t
getNumOfTags
(
const
STableMeta
*
pTableMeta
)
{
return
getTableInfo
(
pTableMeta
).
numOfTags
;
}
assert
(
pTableMeta
!=
NULL
);
return
getTableInfo
(
pTableMeta
).
numOfTags
;
}
STableComInfo
getTableInfo
(
const
STableMeta
*
pTableMeta
)
{
STableComInfo
getTableInfo
(
const
STableMeta
*
pTableMeta
)
{
return
pTableMeta
->
tableInfo
;
}
assert
(
pTableMeta
!=
NULL
);
return
pTableMeta
->
tableInfo
;
}
STableMeta
*
tableMetaDup
(
const
STableMeta
*
pTableMeta
)
{
STableMeta
*
tableMetaDup
(
const
STableMeta
*
pTableMeta
)
{
size_t
size
=
TABLE_META_SIZE
(
pTableMeta
);
size_t
size
=
TABLE_META_SIZE
(
pTableMeta
);
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
4fb1ef08
...
@@ -75,6 +75,11 @@ static SLogicNode* optFindPossibleNode(SLogicNode* pNode, FMayBeOptimized func)
...
@@ -75,6 +75,11 @@ static SLogicNode* optFindPossibleNode(SLogicNode* pNode, FMayBeOptimized func)
return
NULL
;
return
NULL
;
}
}
static
void
optResetParent
(
SLogicNode
*
pNode
)
{
SNode
*
pChild
=
NULL
;
FOREACH
(
pChild
,
pNode
->
pChildren
)
{
((
SLogicNode
*
)
pChild
)
->
pParent
=
pNode
;
}
}
EDealRes
scanPathOptHaveNormalColImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
EDealRes
scanPathOptHaveNormalColImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
// *((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType);
// *((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType);
...
@@ -485,18 +490,7 @@ static int32_t pushDownCondOptPushCondToJoin(SOptimizeContext* pCxt, SJoinLogicN
...
@@ -485,18 +490,7 @@ static int32_t pushDownCondOptPushCondToJoin(SOptimizeContext* pCxt, SJoinLogicN
}
}
static
int32_t
pushDownCondOptPushCondToChild
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pChild
,
SNode
**
pCond
)
{
static
int32_t
pushDownCondOptPushCondToChild
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pChild
,
SNode
**
pCond
)
{
switch
(
nodeType
(
pChild
))
{
return
pushDownCondOptAppendCond
(
&
pChild
->
pConditions
,
pCond
);
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
return
pushDownCondOptPushCondToScan
(
pCxt
,
(
SScanLogicNode
*
)
pChild
,
pCond
);
case
QUERY_NODE_LOGIC_PLAN_PROJECT
:
return
pushDownCondOptPushCondToProject
(
pCxt
,
(
SProjectLogicNode
*
)
pChild
,
pCond
);
case
QUERY_NODE_LOGIC_PLAN_JOIN
:
return
pushDownCondOptPushCondToJoin
(
pCxt
,
(
SJoinLogicNode
*
)
pChild
,
pCond
);
default:
break
;
}
planError
(
"pushDownCondOptPushCondToChild failed, invalid logic plan node %s"
,
nodesNodeName
(
nodeType
(
pChild
)));
return
TSDB_CODE_PLAN_INTERNAL_ERROR
;
}
}
static
bool
pushDownCondOptIsPriKey
(
SNode
*
pNode
,
SNodeList
*
pTableCols
)
{
static
bool
pushDownCondOptIsPriKey
(
SNode
*
pNode
,
SNodeList
*
pTableCols
)
{
...
@@ -797,10 +791,7 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
...
@@ -797,10 +791,7 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
// TODO: remove it after full implementation of pushing down to child
// TODO: remove it after full implementation of pushing down to child
if
(
1
!=
LIST_LENGTH
(
pAgg
->
node
.
pChildren
)
||
if
(
1
!=
LIST_LENGTH
(
pAgg
->
node
.
pChildren
))
{
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
))
&&
QUERY_NODE_LOGIC_PLAN_PROJECT
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
))
&&
QUERY_NODE_LOGIC_PLAN_JOIN
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
)))
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -827,6 +818,77 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
...
@@ -827,6 +818,77 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
return
code
;
return
code
;
}
}
typedef
struct
SRewriteProjCondContext
{
SProjectLogicNode
*
pProj
;
int32_t
errCode
;
}
SRewriteProjCondContext
;
static
EDealRes
rewriteProjectCondForPushDownImpl
(
SNode
**
ppNode
,
void
*
pContext
)
{
SRewriteProjCondContext
*
pCxt
=
pContext
;
SProjectLogicNode
*
pProj
=
pCxt
->
pProj
;
if
(
QUERY_NODE_COLUMN
==
nodeType
(
*
ppNode
))
{
SNode
*
pTarget
=
NULL
;
FOREACH
(
pTarget
,
pProj
->
node
.
pTargets
)
{
if
(
nodesEqualNode
(
pTarget
,
*
ppNode
))
{
SNode
*
pProjection
=
NULL
;
FOREACH
(
pProjection
,
pProj
->
pProjections
)
{
if
(
0
==
strcmp
(((
SExprNode
*
)
pProjection
)
->
aliasName
,
((
SColumnNode
*
)(
*
ppNode
))
->
colName
))
{
SNode
*
pExpr
=
nodesCloneNode
(
pProjection
);
if
(
pExpr
==
NULL
)
{
pCxt
->
errCode
=
terrno
;
return
DEAL_RES_ERROR
;
}
nodesDestroyNode
(
*
ppNode
);
*
ppNode
=
pExpr
;
}
// end if expr alias name equal column name
}
// end for each project
}
// end if target node equals cond column node
}
// end for each targets
return
DEAL_RES_IGNORE_CHILD
;
}
return
DEAL_RES_CONTINUE
;
}
static
int32_t
rewriteProjectCondForPushDown
(
SOptimizeContext
*
pCxt
,
SProjectLogicNode
*
pProject
,
SNode
**
ppProjectCond
)
{
SRewriteProjCondContext
cxt
=
{.
pProj
=
pProject
,
.
errCode
=
TSDB_CODE_SUCCESS
};
SNode
*
pProjectCond
=
pProject
->
node
.
pConditions
;
nodesRewriteExpr
(
&
pProjectCond
,
rewriteProjectCondForPushDownImpl
,
&
cxt
);
*
ppProjectCond
=
pProjectCond
;
pProject
->
node
.
pConditions
=
NULL
;
return
cxt
.
errCode
;
}
static
int32_t
pushDownCondOptDealProject
(
SOptimizeContext
*
pCxt
,
SProjectLogicNode
*
pProject
)
{
if
(
NULL
==
pProject
->
node
.
pConditions
||
OPTIMIZE_FLAG_TEST_MASK
(
pProject
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_PUSH_DOWN_CONDE
))
{
return
TSDB_CODE_SUCCESS
;
}
// TODO: remove it after full implementation of pushing down to child
if
(
1
!=
LIST_LENGTH
(
pProject
->
node
.
pChildren
))
{
return
TSDB_CODE_SUCCESS
;
}
if
(
NULL
!=
pProject
->
node
.
pLimit
||
NULL
!=
pProject
->
node
.
pSlimit
)
{
return
TSDB_CODE_SUCCESS
;
}
int32_t
code
=
TSDB_CODE_SUCCESS
;
SNode
*
pProjCond
=
NULL
;
code
=
rewriteProjectCondForPushDown
(
pCxt
,
pProject
,
&
pProjCond
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
SLogicNode
*
pChild
=
(
SLogicNode
*
)
nodesListGetNode
(
pProject
->
node
.
pChildren
,
0
);
code
=
pushDownCondOptPushCondToChild
(
pCxt
,
pChild
,
&
pProjCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
OPTIMIZE_FLAG_SET_MASK
(
pProject
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_PUSH_DOWN_CONDE
);
pCxt
->
optimized
=
true
;
}
else
{
nodesDestroyNode
(
pProjCond
);
}
return
code
;
}
static
int32_t
pushDownCondOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
static
int32_t
pushDownCondOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pLogicNode
))
{
switch
(
nodeType
(
pLogicNode
))
{
...
@@ -839,6 +901,9 @@ static int32_t pushDownCondOptimizeImpl(SOptimizeContext* pCxt, SLogicNode* pLog
...
@@ -839,6 +901,9 @@ static int32_t pushDownCondOptimizeImpl(SOptimizeContext* pCxt, SLogicNode* pLog
case
QUERY_NODE_LOGIC_PLAN_AGG
:
case
QUERY_NODE_LOGIC_PLAN_AGG
:
code
=
pushDownCondOptDealAgg
(
pCxt
,
(
SAggLogicNode
*
)
pLogicNode
);
code
=
pushDownCondOptDealAgg
(
pCxt
,
(
SAggLogicNode
*
)
pLogicNode
);
break
;
break
;
case
QUERY_NODE_LOGIC_PLAN_PROJECT
:
code
=
pushDownCondOptDealProject
(
pCxt
,
(
SProjectLogicNode
*
)
pLogicNode
);
break
;
default:
default:
break
;
break
;
}
}
...
@@ -1540,6 +1605,7 @@ static int32_t rewriteTailOptCreateSort(SIndefRowsFuncLogicNode* pIndef, SLogicN
...
@@ -1540,6 +1605,7 @@ static int32_t rewriteTailOptCreateSort(SIndefRowsFuncLogicNode* pIndef, SLogicN
pSort
->
groupSort
=
rewriteTailOptNeedGroupSort
(
pIndef
);
pSort
->
groupSort
=
rewriteTailOptNeedGroupSort
(
pIndef
);
TSWAP
(
pSort
->
node
.
pChildren
,
pIndef
->
node
.
pChildren
);
TSWAP
(
pSort
->
node
.
pChildren
,
pIndef
->
node
.
pChildren
);
optResetParent
((
SLogicNode
*
)
pSort
);
pSort
->
node
.
precision
=
pIndef
->
node
.
precision
;
pSort
->
node
.
precision
=
pIndef
->
node
.
precision
;
SFunctionNode
*
pTail
=
NULL
;
SFunctionNode
*
pTail
=
NULL
;
...
@@ -1747,6 +1813,7 @@ static int32_t rewriteUniqueOptCreateAgg(SIndefRowsFuncLogicNode* pIndef, SLogic
...
@@ -1747,6 +1813,7 @@ static int32_t rewriteUniqueOptCreateAgg(SIndefRowsFuncLogicNode* pIndef, SLogic
}
}
TSWAP
(
pAgg
->
node
.
pChildren
,
pIndef
->
node
.
pChildren
);
TSWAP
(
pAgg
->
node
.
pChildren
,
pIndef
->
node
.
pChildren
);
optResetParent
((
SLogicNode
*
)
pAgg
);
pAgg
->
node
.
precision
=
pIndef
->
node
.
precision
;
pAgg
->
node
.
precision
=
pIndef
->
node
.
precision
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
4fb1ef08
...
@@ -1203,7 +1203,8 @@ typedef struct SQnodeSplitInfo {
...
@@ -1203,7 +1203,8 @@ typedef struct SQnodeSplitInfo {
static
bool
qndSplFindSplitNode
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
SLogicNode
*
pNode
,
static
bool
qndSplFindSplitNode
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
SLogicNode
*
pNode
,
SQnodeSplitInfo
*
pInfo
)
{
SQnodeSplitInfo
*
pInfo
)
{
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pNode
)
&&
NULL
!=
pNode
->
pParent
)
{
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pNode
)
&&
NULL
!=
pNode
->
pParent
&&
((
SScanLogicNode
*
)
pNode
)
->
scanSeq
[
0
]
<
1
&&
((
SScanLogicNode
*
)
pNode
)
->
scanSeq
[
1
]
<
1
)
{
pInfo
->
pSplitNode
=
pNode
;
pInfo
->
pSplitNode
=
pNode
;
pInfo
->
pSubplan
=
pSubplan
;
pInfo
->
pSubplan
=
pSubplan
;
return
true
;
return
true
;
...
...
source/libs/planner/test/planBasicTest.cpp
浏览文件 @
4fb1ef08
...
@@ -63,6 +63,10 @@ TEST_F(PlanBasicTest, uniqueFunc) {
...
@@ -63,6 +63,10 @@ TEST_F(PlanBasicTest, uniqueFunc) {
run
(
"SELECT UNIQUE(c2 + 10), ts, c2 FROM t1 WHERE c1 > 10"
);
run
(
"SELECT UNIQUE(c2 + 10), ts, c2 FROM t1 WHERE c1 > 10"
);
run
(
"SELECT UNIQUE(c1) a FROM t1 ORDER BY a"
);
run
(
"SELECT UNIQUE(c1) a FROM t1 ORDER BY a"
);
run
(
"SELECT ts, UNIQUE(c1) FROM st1 PARTITION BY TBNAME"
);
run
(
"SELECT TBNAME, UNIQUE(c1) FROM st1 PARTITION BY TBNAME"
);
}
}
TEST_F
(
PlanBasicTest
,
tailFunc
)
{
TEST_F
(
PlanBasicTest
,
tailFunc
)
{
...
@@ -81,6 +85,8 @@ TEST_F(PlanBasicTest, tailFunc) {
...
@@ -81,6 +85,8 @@ TEST_F(PlanBasicTest, tailFunc) {
run
(
"SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10 PARTITION BY c1 LIMIT 5"
);
run
(
"SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10 PARTITION BY c1 LIMIT 5"
);
run
(
"SELECT TAIL(c1, 2, 1) FROM st1s1 UNION ALL SELECT c1 FROM st1s2"
);
run
(
"SELECT TAIL(c1, 2, 1) FROM st1s1 UNION ALL SELECT c1 FROM st1s2"
);
run
(
"SELECT TAIL(c1, 1) FROM st2 WHERE jtag->'tag1' > 10"
);
}
}
TEST_F
(
PlanBasicTest
,
interpFunc
)
{
TEST_F
(
PlanBasicTest
,
interpFunc
)
{
...
...
source/libs/planner/test/planOptimizeTest.cpp
浏览文件 @
4fb1ef08
...
@@ -81,3 +81,8 @@ TEST_F(PlanOptimizeTest, eliminateProjection) {
...
@@ -81,3 +81,8 @@ TEST_F(PlanOptimizeTest, eliminateProjection) {
run
(
"SELECT c1 FROM st1s3"
);
run
(
"SELECT c1 FROM st1s3"
);
// run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) order by 1 nulls first");
// run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) order by 1 nulls first");
}
}
TEST_F
(
PlanOptimizeTest
,
pushDownProjectCond
)
{
useDb
(
"root"
,
"test"
);
run
(
"select 1-abs(c1) from (select unique(c1) c1 from st1s3) where 1-c1>5 order by 1 nulls first"
);
}
\ No newline at end of file
source/libs/planner/test/planOtherTest.cpp
浏览文件 @
4fb1ef08
...
@@ -91,10 +91,3 @@ TEST_F(PlanOtherTest, delete) {
...
@@ -91,10 +91,3 @@ TEST_F(PlanOtherTest, delete) {
run
(
"DELETE FROM st1 WHERE ts > now - 2d and ts < now - 1d AND tag1 = 10"
);
run
(
"DELETE FROM st1 WHERE ts > now - 2d and ts < now - 1d AND tag1 = 10"
);
}
}
TEST_F
(
PlanOtherTest
,
queryPolicy
)
{
useDb
(
"root"
,
"test"
);
tsQueryPolicy
=
QUERY_POLICY_QNODE
;
run
(
"SELECT COUNT(*) FROM st1"
);
}
source/libs/planner/test/planTestMain.cpp
浏览文件 @
4fb1ef08
...
@@ -78,6 +78,7 @@ static void parseArg(int argc, char* argv[]) {
...
@@ -78,6 +78,7 @@ static void parseArg(int argc, char* argv[]) {
{
"skipSql"
,
required_argument
,
NULL
,
's'
},
{
"skipSql"
,
required_argument
,
NULL
,
's'
},
{
"limitSql"
,
required_argument
,
NULL
,
'i'
},
{
"limitSql"
,
required_argument
,
NULL
,
'i'
},
{
"log"
,
required_argument
,
NULL
,
'l'
},
{
"log"
,
required_argument
,
NULL
,
'l'
},
{
"queryPolicy"
,
required_argument
,
NULL
,
'q'
},
{
0
,
0
,
0
,
0
}
{
0
,
0
,
0
,
0
}
};
};
// clang-format on
// clang-format on
...
@@ -95,6 +96,9 @@ static void parseArg(int argc, char* argv[]) {
...
@@ -95,6 +96,9 @@ static void parseArg(int argc, char* argv[]) {
case
'l'
:
case
'l'
:
setLogLevel
(
optarg
);
setLogLevel
(
optarg
);
break
;
break
;
case
'q'
:
setQueryPolicy
(
optarg
);
break
;
default:
default:
break
;
break
;
}
}
...
...
source/libs/planner/test/planTestUtil.cpp
浏览文件 @
4fb1ef08
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include "mockCatalogService.h"
#include "mockCatalogService.h"
#include "parser.h"
#include "parser.h"
#include "planInt.h"
#include "planInt.h"
#include "tglobal.h"
using
namespace
std
;
using
namespace
std
;
using
namespace
testing
;
using
namespace
testing
;
...
@@ -53,6 +54,7 @@ DumpModule g_dumpModule = DUMP_MODULE_NOTHING;
...
@@ -53,6 +54,7 @@ DumpModule g_dumpModule = DUMP_MODULE_NOTHING;
int32_t
g_skipSql
=
0
;
int32_t
g_skipSql
=
0
;
int32_t
g_limitSql
=
0
;
int32_t
g_limitSql
=
0
;
int32_t
g_logLevel
=
131
;
int32_t
g_logLevel
=
131
;
int32_t
g_queryPolicy
=
QUERY_POLICY_VNODE
;
void
setDumpModule
(
const
char
*
pModule
)
{
void
setDumpModule
(
const
char
*
pModule
)
{
if
(
NULL
==
pModule
)
{
if
(
NULL
==
pModule
)
{
...
@@ -79,6 +81,7 @@ void setDumpModule(const char* pModule) {
...
@@ -79,6 +81,7 @@ void setDumpModule(const char* pModule) {
void
setSkipSqlNum
(
const
char
*
pNum
)
{
g_skipSql
=
stoi
(
pNum
);
}
void
setSkipSqlNum
(
const
char
*
pNum
)
{
g_skipSql
=
stoi
(
pNum
);
}
void
setLimitSqlNum
(
const
char
*
pNum
)
{
g_limitSql
=
stoi
(
pNum
);
}
void
setLimitSqlNum
(
const
char
*
pNum
)
{
g_limitSql
=
stoi
(
pNum
);
}
void
setLogLevel
(
const
char
*
pLogLevel
)
{
g_logLevel
=
stoi
(
pLogLevel
);
}
void
setLogLevel
(
const
char
*
pLogLevel
)
{
g_logLevel
=
stoi
(
pLogLevel
);
}
void
setQueryPolicy
(
const
char
*
pQueryPolicy
)
{
g_queryPolicy
=
stoi
(
pQueryPolicy
);
}
int32_t
getLogLevel
()
{
return
g_logLevel
;
}
int32_t
getLogLevel
()
{
return
g_logLevel
;
}
...
@@ -105,7 +108,23 @@ class PlannerTestBaseImpl {
...
@@ -105,7 +108,23 @@ class PlannerTestBaseImpl {
}
}
++
sqlNum_
;
++
sqlNum_
;
switch
(
g_queryPolicy
)
{
case
QUERY_POLICY_VNODE
:
case
QUERY_POLICY_HYBRID
:
case
QUERY_POLICY_QNODE
:
runImpl
(
sql
,
g_queryPolicy
);
break
;
default:
runImpl
(
sql
,
QUERY_POLICY_VNODE
);
runImpl
(
sql
,
QUERY_POLICY_HYBRID
);
runImpl
(
sql
,
QUERY_POLICY_QNODE
);
break
;
}
}
void
runImpl
(
const
string
&
sql
,
int32_t
queryPolicy
)
{
reset
();
reset
();
tsQueryPolicy
=
queryPolicy
;
try
{
try
{
SQuery
*
pQuery
=
nullptr
;
SQuery
*
pQuery
=
nullptr
;
doParseSql
(
sql
,
&
pQuery
);
doParseSql
(
sql
,
&
pQuery
);
...
...
source/libs/planner/test/planTestUtil.h
浏览文件 @
4fb1ef08
...
@@ -45,6 +45,7 @@ extern void setDumpModule(const char* pModule);
...
@@ -45,6 +45,7 @@ extern void setDumpModule(const char* pModule);
extern
void
setSkipSqlNum
(
const
char
*
pNum
);
extern
void
setSkipSqlNum
(
const
char
*
pNum
);
extern
void
setLimitSqlNum
(
const
char
*
pNum
);
extern
void
setLimitSqlNum
(
const
char
*
pNum
);
extern
void
setLogLevel
(
const
char
*
pLogLevel
);
extern
void
setLogLevel
(
const
char
*
pLogLevel
);
extern
void
setQueryPolicy
(
const
char
*
pQueryPolicy
);
extern
int32_t
getLogLevel
();
extern
int32_t
getLogLevel
();
#endif // PLAN_TEST_UTIL_H
#endif // PLAN_TEST_UTIL_H
source/libs/scalar/src/sclfunc.c
浏览文件 @
4fb1ef08
...
@@ -1174,7 +1174,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
...
@@ -1174,7 +1174,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
timeU
nit
=
timeUnit
*
1000
/
factor
;
int64_t
u
nit
=
timeUnit
*
1000
/
factor
;
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pInput
[
0
].
numOfRows
;
++
i
)
{
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
if
(
colDataIsNull_s
(
pInput
[
0
].
columnData
,
i
))
{
...
@@ -1209,12 +1209,14 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
...
@@ -1209,12 +1209,14 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
NUM_TO_STRING
(
TSDB_DATA_TYPE_BIGINT
,
&
timeVal
,
sizeof
(
buf
),
buf
);
NUM_TO_STRING
(
TSDB_DATA_TYPE_BIGINT
,
&
timeVal
,
sizeof
(
buf
),
buf
);
int32_t
tsDigits
=
(
int32_t
)
strlen
(
buf
);
int32_t
tsDigits
=
(
int32_t
)
strlen
(
buf
);
switch
(
timeU
nit
)
{
switch
(
u
nit
)
{
case
0
:
{
/* 1u */
case
0
:
{
/* 1u
or 1b
*/
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
if
(
tsDigits
==
TSDB_TIME_PRECISION_NANO_DIGITS
)
{
if
(
timePrec
==
TSDB_TIME_PRECISION_NANO
&&
timeUnit
==
1
)
{
timeVal
=
timeVal
*
1
;
}
else
{
timeVal
=
timeVal
/
1000
*
1000
;
timeVal
=
timeVal
/
1000
*
1000
;
//} else if (tsDigits == TSDB_TIME_PRECISION_MICRO_DIGITS) {
}
// //timeVal = timeVal / 1000;
}
else
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
}
else
if
(
tsDigits
<=
TSDB_TIME_PRECISION_SEC_DIGITS
)
{
timeVal
=
timeVal
*
factor
;
timeVal
=
timeVal
*
factor
;
}
else
{
}
else
{
...
@@ -1366,8 +1368,6 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
...
@@ -1366,8 +1368,6 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
int64_t
factor
=
(
timePrec
==
TSDB_TIME_PRECISION_MILLI
)
?
1000
:
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
(
timePrec
==
TSDB_TIME_PRECISION_MICRO
?
1000000
:
1000000000
);
timeUnit
=
timeUnit
*
1000
/
factor
;
int32_t
numOfRows
=
0
;
int32_t
numOfRows
=
0
;
for
(
int32_t
i
=
0
;
i
<
inputNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
inputNum
;
++
i
)
{
if
(
pInput
[
i
].
numOfRows
>
numOfRows
)
{
if
(
pInput
[
i
].
numOfRows
>
numOfRows
)
{
...
@@ -1447,9 +1447,14 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
...
@@ -1447,9 +1447,14 @@ int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
}
}
}
}
}
else
{
}
else
{
switch
(
timeUnit
)
{
int64_t
unit
=
timeUnit
*
1000
/
factor
;
case
0
:
{
/* 1u */
switch
(
unit
)
{
case
0
:
{
/* 1u or 1b */
if
(
timePrec
==
TSDB_TIME_PRECISION_NANO
&&
timeUnit
==
1
)
{
result
=
result
/
1
;
}
else
{
result
=
result
/
1000
;
result
=
result
/
1000
;
}
break
;
break
;
}
}
case
1
:
{
/* 1a */
case
1
:
{
/* 1a */
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
4fb1ef08
...
@@ -83,7 +83,7 @@ typedef struct SSyncSnapshotReceiver {
...
@@ -83,7 +83,7 @@ typedef struct SSyncSnapshotReceiver {
SSyncSnapshotReceiver
*
snapshotReceiverCreate
(
SSyncNode
*
pSyncNode
,
SRaftId
fromId
);
SSyncSnapshotReceiver
*
snapshotReceiverCreate
(
SSyncNode
*
pSyncNode
,
SRaftId
fromId
);
void
snapshotReceiverDestroy
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverDestroy
(
SSyncSnapshotReceiver
*
pReceiver
);
int32_t
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
SyncSnapshotSend
*
pBeginMsg
);
int32_t
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncSnapshotSend
*
pBeginMsg
);
int32_t
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
);
int32_t
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
);
bool
snapshotReceiverIsStart
(
SSyncSnapshotReceiver
*
pReceiver
);
bool
snapshotReceiverIsStart
(
SSyncSnapshotReceiver
*
pReceiver
);
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
4fb1ef08
...
@@ -158,13 +158,13 @@ int32_t syncSetStandby(int64_t rid) {
...
@@ -158,13 +158,13 @@ int32_t syncSetStandby(int64_t rid) {
}
}
if
(
pSyncNode
->
state
!=
TAOS_SYNC_STATE_FOLLOWER
)
{
if
(
pSyncNode
->
state
!=
TAOS_SYNC_STATE_FOLLOWER
)
{
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
terrno
=
TSDB_CODE_SYN_IS_LEADER
;
terrno
=
TSDB_CODE_SYN_IS_LEADER
;
}
else
{
}
else
{
terrno
=
TSDB_CODE_SYN_STANDBY_NOT_READY
;
terrno
=
TSDB_CODE_SYN_STANDBY_NOT_READY
;
}
}
sError
(
"failed to set standby since it is not follower, state:%s rid:%"
PRId64
,
syncStr
(
pSyncNode
->
state
),
rid
);
sError
(
"failed to set standby since it is not follower, state:%s rid:%"
PRId64
,
syncStr
(
pSyncNode
->
state
),
rid
);
taosReleaseRef
(
tsNodeRefId
,
pSyncNode
->
rid
);
return
-
1
;
return
-
1
;
}
}
...
@@ -620,6 +620,7 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
...
@@ -620,6 +620,7 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
SSyncNode
*
pSyncNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
SSyncNode
*
pSyncNode
=
taosAcquireRef
(
tsNodeRefId
,
rid
);
if
(
pSyncNode
==
NULL
)
{
if
(
pSyncNode
==
NULL
)
{
taosReleaseRef
(
tsNodeRefId
,
rid
);
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
terrno
=
TSDB_CODE_SYN_INTERNAL_ERROR
;
return
-
1
;
return
-
1
;
}
}
...
...
source/libs/sync/src/syncRespMgr.c
浏览文件 @
4fb1ef08
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
*/
*/
#include "syncRespMgr.h"
#include "syncRespMgr.h"
#include "syncRaftEntry.h"
#include "syncRaftStore.h"
#include "syncRaftStore.h"
SSyncRespMgr
*
syncRespMgrCreate
(
void
*
data
,
int64_t
ttl
)
{
SSyncRespMgr
*
syncRespMgrCreate
(
void
*
data
,
int64_t
ttl
)
{
...
@@ -116,4 +117,59 @@ void syncRespClean(SSyncRespMgr *pObj) {
...
@@ -116,4 +117,59 @@ void syncRespClean(SSyncRespMgr *pObj) {
taosThreadMutexUnlock
(
&
(
pObj
->
mutex
));
taosThreadMutexUnlock
(
&
(
pObj
->
mutex
));
}
}
void
syncRespCleanByTTL
(
SSyncRespMgr
*
pObj
,
int64_t
ttl
)
{}
void
syncRespCleanByTTL
(
SSyncRespMgr
*
pObj
,
int64_t
ttl
)
{
SRespStub
*
pStub
=
(
SRespStub
*
)
taosHashIterate
(
pObj
->
pRespHash
,
NULL
);
int
cnt
=
0
;
SSyncNode
*
pSyncNode
=
pObj
->
data
;
SArray
*
delIndexArray
=
taosArrayInit
(
0
,
sizeof
(
SyncIndex
));
ASSERT
(
delIndexArray
!=
NULL
);
while
(
pStub
)
{
size_t
len
;
void
*
key
=
taosHashGetKey
(
pStub
,
&
len
);
SyncIndex
*
pIndex
=
(
SyncIndex
*
)
key
;
int64_t
nowMS
=
taosGetTimestampMs
();
if
(
nowMS
-
pStub
->
createTime
>
ttl
)
{
taosArrayPush
(
delIndexArray
,
pIndex
);
cnt
++
;
SSyncRaftEntry
*
pEntry
=
NULL
;
int32_t
code
=
0
;
if
(
pSyncNode
->
pLogStore
!=
NULL
)
{
code
=
pSyncNode
->
pLogStore
->
syncLogGetEntry
(
pSyncNode
->
pLogStore
,
*
pIndex
,
&
pEntry
);
if
(
code
==
0
&&
pEntry
!=
NULL
)
{
SFsmCbMeta
cbMeta
=
{
0
};
cbMeta
.
index
=
pEntry
->
index
;
cbMeta
.
lastConfigIndex
=
syncNodeGetSnapshotConfigIndex
(
pSyncNode
,
cbMeta
.
index
);
cbMeta
.
isWeak
=
pEntry
->
isWeak
;
cbMeta
.
code
=
TSDB_CODE_SYN_TIMEOUT
;
cbMeta
.
state
=
pSyncNode
->
state
;
cbMeta
.
seqNum
=
pEntry
->
seqNum
;
cbMeta
.
term
=
pEntry
->
term
;
cbMeta
.
currentTerm
=
pSyncNode
->
pRaftStore
->
currentTerm
;
cbMeta
.
flag
=
0
;
SRpcMsg
rpcMsg
=
pStub
->
rpcMsg
;
rpcMsg
.
pCont
=
rpcMallocCont
(
pEntry
->
dataLen
);
memcpy
(
rpcMsg
.
pCont
,
pEntry
->
data
,
pEntry
->
dataLen
);
pSyncNode
->
pFsm
->
FpCommitCb
(
pSyncNode
->
pFsm
,
&
rpcMsg
,
cbMeta
);
syncEntryDestory
(
pEntry
);
}
}
}
pStub
=
(
SRespStub
*
)
taosHashIterate
(
pObj
->
pRespHash
,
pStub
);
}
int32_t
arraySize
=
taosArrayGetSize
(
delIndexArray
);
sDebug
(
"vgId:%d, resp clean by ttl, cnt:%d, array-size:%d"
,
pSyncNode
->
vgId
,
cnt
,
arraySize
);
for
(
int32_t
i
=
0
;
i
<
arraySize
;
++
i
)
{
SyncIndex
*
pIndex
=
taosArrayGet
(
delIndexArray
,
i
);
taosHashRemove
(
pObj
->
pRespHash
,
pIndex
,
sizeof
(
SyncIndex
));
}
taosArrayDestroy
(
delIndexArray
);
}
source/libs/sync/src/syncSnapshot.c
浏览文件 @
4fb1ef08
...
@@ -22,9 +22,11 @@
...
@@ -22,9 +22,11 @@
#include "wal.h"
#include "wal.h"
//----------------------------------
//----------------------------------
static
void
snapshotReceiverDoStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
static
void
snapshotSenderUpdateProgress
(
SSyncSnapshotSender
*
pSender
,
SyncSnapshotRsp
*
pMsg
);
SyncSnapshotSend
*
pBeginMsg
);
static
void
snapshotReceiverDoStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncSnapshotSend
*
pBeginMsg
);
static
void
snapshotReceiverForceStop
(
SSyncSnapshotReceiver
*
pReceiver
);
static
void
snapshotReceiverGotData
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncSnapshotSend
*
pMsg
);
static
void
snapshotReceiverGotData
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncSnapshotSend
*
pMsg
);
static
int32_t
snapshotReceiverFinish
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncSnapshotSend
*
pMsg
);
//----------------------------------
//----------------------------------
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
)
{
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
)
{
...
@@ -68,7 +70,9 @@ void snapshotSenderDestroy(SSyncSnapshotSender *pSender) {
...
@@ -68,7 +70,9 @@ void snapshotSenderDestroy(SSyncSnapshotSender *pSender) {
// close reader
// close reader
if
(
pSender
->
pReader
!=
NULL
)
{
if
(
pSender
->
pReader
!=
NULL
)
{
int32_t
ret
=
pSender
->
pSyncNode
->
pFsm
->
FpSnapshotStopRead
(
pSender
->
pSyncNode
->
pFsm
,
pSender
->
pReader
);
int32_t
ret
=
pSender
->
pSyncNode
->
pFsm
->
FpSnapshotStopRead
(
pSender
->
pSyncNode
->
pFsm
,
pSender
->
pReader
);
ASSERT
(
ret
==
0
);
if
(
ret
!=
0
)
{
syncNodeErrorLog
(
pSender
->
pSyncNode
,
"stop reader error"
);
}
pSender
->
pReader
=
NULL
;
pSender
->
pReader
=
NULL
;
}
}
...
@@ -79,7 +83,12 @@ void snapshotSenderDestroy(SSyncSnapshotSender *pSender) {
...
@@ -79,7 +83,12 @@ void snapshotSenderDestroy(SSyncSnapshotSender *pSender) {
bool
snapshotSenderIsStart
(
SSyncSnapshotSender
*
pSender
)
{
return
pSender
->
start
;
}
bool
snapshotSenderIsStart
(
SSyncSnapshotSender
*
pSender
)
{
return
pSender
->
start
;
}
// begin send snapshot by snapshot, pReader
// begin send snapshot by param, snapshot, pReader
//
// action:
// 1. assert reader not start
// 2. update state
// 3. send first snapshot block
int32_t
snapshotSenderStart
(
SSyncSnapshotSender
*
pSender
,
SSnapshotParam
snapshotParam
,
SSnapshot
snapshot
,
int32_t
snapshotSenderStart
(
SSyncSnapshotSender
*
pSender
,
SSnapshotParam
snapshotParam
,
SSnapshot
snapshot
,
void
*
pReader
)
{
void
*
pReader
)
{
ASSERT
(
!
snapshotSenderIsStart
(
pSender
));
ASSERT
(
!
snapshotSenderIsStart
(
pSender
));
...
@@ -98,7 +107,7 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapsho
...
@@ -98,7 +107,7 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapsho
// update term
// update term
pSender
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pSender
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
++
(
pSender
->
privateTerm
);
++
(
pSender
->
privateTerm
);
// increase private term
// update state
// update state
pSender
->
finish
=
false
;
pSender
->
finish
=
false
;
...
@@ -114,9 +123,7 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapsho
...
@@ -114,9 +123,7 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapsho
code
=
pSender
->
pSyncNode
->
pLogStore
->
syncLogGetEntry
(
pSender
->
pSyncNode
->
pLogStore
,
code
=
pSender
->
pSyncNode
->
pLogStore
->
syncLogGetEntry
(
pSender
->
pSyncNode
->
pLogStore
,
pSender
->
snapshot
.
lastConfigIndex
,
&
pEntry
);
pSender
->
snapshot
.
lastConfigIndex
,
&
pEntry
);
if
(
code
==
0
)
{
if
(
code
==
0
&&
pEntry
!=
NULL
)
{
ASSERT
(
pEntry
!=
NULL
);
SRpcMsg
rpcMsg
;
SRpcMsg
rpcMsg
;
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
syncEntry2OriginalRpc
(
pEntry
,
&
rpcMsg
);
...
@@ -207,6 +214,8 @@ int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) {
...
@@ -207,6 +214,8 @@ int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) {
pSender
->
start
=
false
;
pSender
->
start
=
false
;
pSender
->
finish
=
finish
;
pSender
->
finish
=
finish
;
// do not update term, maybe print
// event log
// event log
do
{
do
{
char
*
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
"snapshot sender stop"
);
char
*
eventLog
=
snapshotSender2SimpleStr
(
pSender
,
"snapshot sender stop"
);
...
@@ -243,6 +252,7 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
...
@@ -243,6 +252,7 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
pMsg
->
srcId
=
pSender
->
pSyncNode
->
myRaftId
;
pMsg
->
srcId
=
pSender
->
pSyncNode
->
myRaftId
;
pMsg
->
destId
=
(
pSender
->
pSyncNode
->
replicasId
)[
pSender
->
replicaIndex
];
pMsg
->
destId
=
(
pSender
->
pSyncNode
->
replicasId
)[
pSender
->
replicaIndex
];
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
beginIndex
=
pSender
->
snapshotParam
.
start
;
pMsg
->
lastIndex
=
pSender
->
snapshot
.
lastApplyIndex
;
pMsg
->
lastIndex
=
pSender
->
snapshot
.
lastApplyIndex
;
pMsg
->
lastTerm
=
pSender
->
snapshot
.
lastApplyTerm
;
pMsg
->
lastTerm
=
pSender
->
snapshot
.
lastApplyTerm
;
pMsg
->
lastConfigIndex
=
pSender
->
snapshot
.
lastConfigIndex
;
pMsg
->
lastConfigIndex
=
pSender
->
snapshot
.
lastConfigIndex
;
...
@@ -281,11 +291,13 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
...
@@ -281,11 +291,13 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
pMsg
->
srcId
=
pSender
->
pSyncNode
->
myRaftId
;
pMsg
->
srcId
=
pSender
->
pSyncNode
->
myRaftId
;
pMsg
->
destId
=
(
pSender
->
pSyncNode
->
replicasId
)[
pSender
->
replicaIndex
];
pMsg
->
destId
=
(
pSender
->
pSyncNode
->
replicasId
)[
pSender
->
replicaIndex
];
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pMsg
->
beginIndex
=
pSender
->
snapshotParam
.
start
;
pMsg
->
lastIndex
=
pSender
->
snapshot
.
lastApplyIndex
;
pMsg
->
lastIndex
=
pSender
->
snapshot
.
lastApplyIndex
;
pMsg
->
lastTerm
=
pSender
->
snapshot
.
lastApplyTerm
;
pMsg
->
lastTerm
=
pSender
->
snapshot
.
lastApplyTerm
;
pMsg
->
lastConfigIndex
=
pSender
->
snapshot
.
lastConfigIndex
;
pMsg
->
lastConfigIndex
=
pSender
->
snapshot
.
lastConfigIndex
;
pMsg
->
lastConfig
=
pSender
->
lastConfig
;
pMsg
->
lastConfig
=
pSender
->
lastConfig
;
pMsg
->
seq
=
pSender
->
seq
;
pMsg
->
seq
=
pSender
->
seq
;
pMsg
->
privateTerm
=
pSender
->
privateTerm
;
memcpy
(
pMsg
->
data
,
pSender
->
pCurrentBlock
,
pSender
->
blockLen
);
memcpy
(
pMsg
->
data
,
pSender
->
pCurrentBlock
,
pSender
->
blockLen
);
// send msg
// send msg
...
@@ -305,6 +317,12 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
...
@@ -305,6 +317,12 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
return
0
;
return
0
;
}
}
static
void
snapshotSenderUpdateProgress
(
SSyncSnapshotSender
*
pSender
,
SyncSnapshotRsp
*
pMsg
)
{
ASSERT
(
pMsg
->
ack
==
pSender
->
seq
);
pSender
->
ack
=
pMsg
->
ack
;
++
(
pSender
->
seq
);
}
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
)
{
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
)
{
char
u64buf
[
128
];
char
u64buf
[
128
];
cJSON
*
pRoot
=
cJSON_CreateObject
();
cJSON
*
pRoot
=
cJSON_CreateObject
();
...
@@ -371,10 +389,11 @@ char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event) {
...
@@ -371,10 +389,11 @@ char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event) {
syncUtilU642Addr
(
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
syncUtilU642Addr
(
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
snprintf
(
s
,
len
,
snprintf
(
s
,
len
,
"%s {%p laindex:%ld laterm:%lu lcindex:%ld seq:%d ack:%d finish:%d pterm:%lu replica-index:%d %s:%d}"
,
event
,
"%s {%p s-param:%ld e-param:%ld laindex:%ld laterm:%lu lcindex:%ld seq:%d ack:%d finish:%d pterm:%lu "
pSender
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
snapshot
.
lastApplyTerm
,
"replica-index:%d %s:%d}"
,
pSender
->
snapshot
.
lastConfigIndex
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
finish
,
pSender
->
privateTerm
,
event
,
pSender
,
pSender
->
snapshotParam
.
start
,
pSender
->
snapshotParam
.
end
,
pSender
->
snapshot
.
lastApplyIndex
,
pSender
->
replicaIndex
,
host
,
port
);
pSender
->
snapshot
.
lastApplyTerm
,
pSender
->
snapshot
.
lastConfigIndex
,
pSender
->
seq
,
pSender
->
ack
,
pSender
->
finish
,
pSender
->
privateTerm
,
pSender
->
replicaIndex
,
host
,
port
);
return
s
;
return
s
;
}
}
...
@@ -429,11 +448,10 @@ bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver) { return pReceive
...
@@ -429,11 +448,10 @@ bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver) { return pReceive
// static do start by privateTerm, pBeginMsg
// static do start by privateTerm, pBeginMsg
// receive first snapshot data
// receive first snapshot data
// write first block data
// write first block data
static
void
snapshotReceiverDoStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncTerm
privateTerm
,
static
void
snapshotReceiverDoStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncSnapshotSend
*
pBeginMsg
)
{
SyncSnapshotSend
*
pBeginMsg
)
{
// update state
// update state
pReceiver
->
term
=
pReceiver
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pReceiver
->
term
=
pReceiver
->
pSyncNode
->
pRaftStore
->
currentTerm
;
pReceiver
->
privateTerm
=
privateTerm
;
pReceiver
->
privateTerm
=
p
BeginMsg
->
p
rivateTerm
;
pReceiver
->
ack
=
SYNC_SNAPSHOT_SEQ_BEGIN
;
pReceiver
->
ack
=
SYNC_SNAPSHOT_SEQ_BEGIN
;
pReceiver
->
fromId
=
pBeginMsg
->
srcId
;
pReceiver
->
fromId
=
pBeginMsg
->
srcId
;
pReceiver
->
start
=
true
;
pReceiver
->
start
=
true
;
...
@@ -445,7 +463,7 @@ static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm p
...
@@ -445,7 +463,7 @@ static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncTerm p
pReceiver
->
snapshotParam
.
start
=
pBeginMsg
->
beginIndex
;
pReceiver
->
snapshotParam
.
start
=
pBeginMsg
->
beginIndex
;
pReceiver
->
snapshotParam
.
end
=
pBeginMsg
->
lastIndex
;
pReceiver
->
snapshotParam
.
end
=
pBeginMsg
->
lastIndex
;
//
write data
//
start writer
ASSERT
(
pReceiver
->
pWriter
==
NULL
);
ASSERT
(
pReceiver
->
pWriter
==
NULL
);
int32_t
ret
=
pReceiver
->
pSyncNode
->
pFsm
->
FpSnapshotStartWrite
(
pReceiver
->
pSyncNode
->
pFsm
,
int32_t
ret
=
pReceiver
->
pSyncNode
->
pFsm
->
FpSnapshotStartWrite
(
pReceiver
->
pSyncNode
->
pFsm
,
&
(
pReceiver
->
snapshotParam
),
&
(
pReceiver
->
pWriter
));
&
(
pReceiver
->
snapshotParam
),
&
(
pReceiver
->
pWriter
));
...
@@ -481,10 +499,10 @@ static void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver) {
...
@@ -481,10 +499,10 @@ static void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver) {
// if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver
// if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver
// if already start, force close, start again
// if already start, force close, start again
int32_t
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
,
Sync
Term
privateTerm
,
Sync
SnapshotSend
*
pBeginMsg
)
{
int32_t
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncSnapshotSend
*
pBeginMsg
)
{
if
(
!
snapshotReceiverIsStart
(
pReceiver
))
{
if
(
!
snapshotReceiverIsStart
(
pReceiver
))
{
// first start
// first start
snapshotReceiverDoStart
(
pReceiver
,
p
rivateTerm
,
p
BeginMsg
);
snapshotReceiverDoStart
(
pReceiver
,
pBeginMsg
);
}
else
{
}
else
{
// already start
// already start
...
@@ -494,12 +512,14 @@ int32_t snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm private
...
@@ -494,12 +512,14 @@ int32_t snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncTerm private
snapshotReceiverForceStop
(
pReceiver
);
snapshotReceiverForceStop
(
pReceiver
);
// start again
// start again
snapshotReceiverDoStart
(
pReceiver
,
p
rivateTerm
,
p
BeginMsg
);
snapshotReceiverDoStart
(
pReceiver
,
pBeginMsg
);
}
}
return
0
;
return
0
;
}
}
// just set start = false
// FpSnapshotStopWrite should not be called, assert writer == NULL
int32_t
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
)
{
int32_t
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
)
{
if
(
pReceiver
->
pWriter
!=
NULL
)
{
if
(
pReceiver
->
pWriter
!=
NULL
)
{
int32_t
ret
=
int32_t
ret
=
...
@@ -522,6 +542,7 @@ int32_t snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver) {
...
@@ -522,6 +542,7 @@ int32_t snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver) {
return
0
;
return
0
;
}
}
// when recv last snapshot block, apply data into snapshot
static
int32_t
snapshotReceiverFinish
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncSnapshotSend
*
pMsg
)
{
static
int32_t
snapshotReceiverFinish
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncSnapshotSend
*
pMsg
)
{
ASSERT
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_END
);
ASSERT
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_END
);
...
@@ -550,7 +571,7 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap
...
@@ -550,7 +571,7 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap
pReceiver
->
pSyncNode
->
commitIndex
=
pReceiver
->
snapshot
.
lastApplyIndex
;
pReceiver
->
pSyncNode
->
commitIndex
=
pReceiver
->
snapshot
.
lastApplyIndex
;
}
}
// stop writer
// stop writer
, apply data
code
=
pReceiver
->
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pReceiver
->
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
true
);
code
=
pReceiver
->
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pReceiver
->
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
true
);
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
syncNodeErrorLog
(
pReceiver
->
pSyncNode
,
"snapshot stop writer true error"
);
syncNodeErrorLog
(
pReceiver
->
pSyncNode
,
"snapshot stop writer true error"
);
...
@@ -579,15 +600,20 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap
...
@@ -579,15 +600,20 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap
return
0
;
return
0
;
}
}
// apply data block
// update progress
static
void
snapshotReceiverGotData
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncSnapshotSend
*
pMsg
)
{
static
void
snapshotReceiverGotData
(
SSyncSnapshotReceiver
*
pReceiver
,
SyncSnapshotSend
*
pMsg
)
{
ASSERT
(
pMsg
->
seq
==
pReceiver
->
ack
+
1
);
ASSERT
(
pMsg
->
seq
==
pReceiver
->
ack
+
1
);
if
(
pReceiver
->
pWriter
!=
NULL
)
{
if
(
pReceiver
->
pWriter
!=
NULL
)
{
if
(
pMsg
->
dataLen
>
0
)
{
if
(
pMsg
->
dataLen
>
0
)
{
// apply data block
int32_t
code
=
pReceiver
->
pSyncNode
->
pFsm
->
FpSnapshotDoWrite
(
pReceiver
->
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
int32_t
code
=
pReceiver
->
pSyncNode
->
pFsm
->
FpSnapshotDoWrite
(
pReceiver
->
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
pMsg
->
data
,
pMsg
->
dataLen
);
pMsg
->
data
,
pMsg
->
dataLen
);
ASSERT
(
code
==
0
);
ASSERT
(
code
==
0
);
}
}
// update progress
pReceiver
->
ack
=
pMsg
->
seq
;
pReceiver
->
ack
=
pMsg
->
seq
;
// event log
// event log
...
@@ -665,14 +691,23 @@ char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event)
...
@@ -665,14 +691,23 @@ char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event)
uint16_t
port
;
uint16_t
port
;
syncUtilU642Addr
(
fromId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
syncUtilU642Addr
(
fromId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
snprintf
(
s
,
len
,
"%s {%p start:%d ack:%d term:%lu pterm:%lu from:%s:%d laindex:%ld laterm:%lu lcindex:%ld}"
,
event
,
snprintf
(
s
,
len
,
pReceiver
,
pReceiver
->
start
,
pReceiver
->
ack
,
pReceiver
->
term
,
pReceiver
->
privateTerm
,
host
,
port
,
"%s {%p start:%d ack:%d term:%lu pterm:%lu from:%s:%d s-param:%ld e-param:%ld laindex:%ld laterm:%lu "
pReceiver
->
snapshot
.
lastApplyIndex
,
pReceiver
->
snapshot
.
lastApplyTerm
,
pReceiver
->
snapshot
.
lastConfigIndex
);
"lcindex:%ld}"
,
event
,
pReceiver
,
pReceiver
->
start
,
pReceiver
->
ack
,
pReceiver
->
term
,
pReceiver
->
privateTerm
,
host
,
port
,
pReceiver
->
snapshotParam
.
start
,
pReceiver
->
snapshotParam
.
end
,
pReceiver
->
snapshot
.
lastApplyIndex
,
pReceiver
->
snapshot
.
lastApplyTerm
,
pReceiver
->
snapshot
.
lastConfigIndex
);
return
s
;
return
s
;
}
}
// receiver do something
// receiver on message
//
// condition 1, recv SYNC_SNAPSHOT_SEQ_BEGIN, start receiver, update privateTerm
// condition 2, recv SYNC_SNAPSHOT_SEQ_END, finish receiver(apply snapshot data, update commit index, maybe reconfig)
// condition 3, recv SYNC_SNAPSHOT_SEQ_FORCE_CLOSE, force close
// condition 4, got data, update ack
//
int32_t
syncNodeOnSnapshotSendCb
(
SSyncNode
*
pSyncNode
,
SyncSnapshotSend
*
pMsg
)
{
int32_t
syncNodeOnSnapshotSendCb
(
SSyncNode
*
pSyncNode
,
SyncSnapshotSend
*
pMsg
)
{
// get receiver
// get receiver
SSyncSnapshotReceiver
*
pReceiver
=
pSyncNode
->
pNewNodeReceiver
;
SSyncSnapshotReceiver
*
pReceiver
=
pSyncNode
->
pNewNodeReceiver
;
...
@@ -683,11 +718,13 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -683,11 +718,13 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
{
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
{
if
(
pMsg
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
if
(
pMsg
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_BEGIN
)
{
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_BEGIN
)
{
// condition 1
// begin, no data
// begin, no data
snapshotReceiverStart
(
pReceiver
,
pMsg
->
privateTerm
,
pMsg
);
snapshotReceiverStart
(
pReceiver
,
pMsg
);
needRsp
=
true
;
needRsp
=
true
;
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_END
)
{
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_END
)
{
// condition 2
// end, finish FSM
// end, finish FSM
code
=
snapshotReceiverFinish
(
pReceiver
,
pMsg
);
code
=
snapshotReceiverFinish
(
pReceiver
,
pMsg
);
if
(
code
==
0
)
{
if
(
code
==
0
)
{
...
@@ -697,7 +734,6 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -697,7 +734,6 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
// maybe update lastconfig
// maybe update lastconfig
if
(
pMsg
->
lastConfigIndex
>=
SYNC_INDEX_BEGIN
)
{
if
(
pMsg
->
lastConfigIndex
>=
SYNC_INDEX_BEGIN
)
{
// int32_t oldReplicaNum = pSyncNode->replicaNum;
SSyncCfg
oldSyncCfg
=
pSyncNode
->
pRaftCfg
->
cfg
;
SSyncCfg
oldSyncCfg
=
pSyncNode
->
pRaftCfg
->
cfg
;
// update new config myIndex
// update new config myIndex
...
@@ -709,11 +745,13 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -709,11 +745,13 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
}
}
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_FORCE_CLOSE
)
{
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_FORCE_CLOSE
)
{
// condition 3
// force close
// force close
snapshotReceiverForceStop
(
pReceiver
);
snapshotReceiverForceStop
(
pReceiver
);
needRsp
=
false
;
needRsp
=
false
;
}
else
if
(
pMsg
->
seq
>
SYNC_SNAPSHOT_SEQ_BEGIN
&&
pMsg
->
seq
<
SYNC_SNAPSHOT_SEQ_END
)
{
}
else
if
(
pMsg
->
seq
>
SYNC_SNAPSHOT_SEQ_BEGIN
&&
pMsg
->
seq
<
SYNC_SNAPSHOT_SEQ_END
)
{
// condition 4
// transfering
// transfering
if
(
pMsg
->
seq
==
pReceiver
->
ack
+
1
)
{
if
(
pMsg
->
seq
==
pReceiver
->
ack
+
1
)
{
snapshotReceiverGotData
(
pReceiver
,
pMsg
);
snapshotReceiverGotData
(
pReceiver
,
pMsg
);
...
@@ -752,6 +790,7 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -752,6 +790,7 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
syncNodeSendMsgById
(
&
(
pRspMsg
->
destId
),
pSyncNode
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pRspMsg
->
destId
),
pSyncNode
,
&
rpcMsg
);
syncSnapshotRspDestroy
(
pRspMsg
);
syncSnapshotRspDestroy
(
pRspMsg
);
}
}
}
else
{
}
else
{
// error log
// error log
do
{
do
{
...
@@ -759,6 +798,8 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -759,6 +798,8 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
syncNodeErrorLog
(
pSyncNode
,
eventLog
);
syncNodeErrorLog
(
pSyncNode
,
eventLog
);
taosMemoryFree
(
eventLog
);
taosMemoryFree
(
eventLog
);
}
while
(
0
);
}
while
(
0
);
return
-
1
;
}
}
}
else
{
}
else
{
// error log
// error log
...
@@ -767,19 +808,19 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -767,19 +808,19 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
syncNodeErrorLog
(
pSyncNode
,
eventLog
);
syncNodeErrorLog
(
pSyncNode
,
eventLog
);
taosMemoryFree
(
eventLog
);
taosMemoryFree
(
eventLog
);
}
while
(
0
);
}
while
(
0
);
return
-
1
;
}
}
return
0
;
return
0
;
}
}
static
void
snapshotSenderUpdateProgress
(
SSyncSnapshotSender
*
pSender
,
SyncSnapshotRsp
*
pMsg
)
{
// sender on message
ASSERT
(
pMsg
->
ack
==
pSender
->
seq
);
//
pSender
->
ack
=
pMsg
->
ack
;
// condition 1 sender receives SYNC_SNAPSHOT_SEQ_END, close sender
++
(
pSender
->
seq
);
// condition 2 sender receives ack, set seq = ack + 1, send msg from seq
}
// condition 3 sender receives error msg, just print error log
//
// sender receives ack, set seq = ack + 1, send msg from seq
// if ack == SYNC_SNAPSHOT_SEQ_END, stop sender
int32_t
syncNodeOnSnapshotRspCb
(
SSyncNode
*
pSyncNode
,
SyncSnapshotRsp
*
pMsg
)
{
int32_t
syncNodeOnSnapshotRspCb
(
SSyncNode
*
pSyncNode
,
SyncSnapshotRsp
*
pMsg
)
{
// if already drop replica, do not process
// if already drop replica, do not process
if
(
!
syncNodeInRaftGroup
(
pSyncNode
,
&
(
pMsg
->
srcId
))
&&
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
!
syncNodeInRaftGroup
(
pSyncNode
,
&
(
pMsg
->
srcId
))
&&
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
...
@@ -794,12 +835,14 @@ int32_t syncNodeOnSnapshotRspCb(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
...
@@ -794,12 +835,14 @@ int32_t syncNodeOnSnapshotRspCb(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
// state, term, seq/ack
// state, term, seq/ack
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
pMsg
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
if
(
pMsg
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
// receiver ack is finish, close sender
// condition 1
// receive ack is finish, close sender
if
(
pMsg
->
ack
==
SYNC_SNAPSHOT_SEQ_END
)
{
if
(
pMsg
->
ack
==
SYNC_SNAPSHOT_SEQ_END
)
{
snapshotSenderStop
(
pSender
,
true
);
snapshotSenderStop
(
pSender
,
true
);
return
0
;
return
0
;
}
}
// condition 2
// send next msg
// send next msg
if
(
pMsg
->
ack
==
pSender
->
seq
)
{
if
(
pMsg
->
ack
==
pSender
->
seq
)
{
// update sender ack
// update sender ack
...
@@ -807,6 +850,7 @@ int32_t syncNodeOnSnapshotRspCb(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
...
@@ -807,6 +850,7 @@ int32_t syncNodeOnSnapshotRspCb(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
snapshotSend
(
pSender
);
snapshotSend
(
pSender
);
}
else
if
(
pMsg
->
ack
==
pSender
->
seq
-
1
)
{
}
else
if
(
pMsg
->
ack
==
pSender
->
seq
-
1
)
{
// maybe resend
snapshotReSend
(
pSender
);
snapshotReSend
(
pSender
);
}
else
{
}
else
{
...
...
source/libs/sync/test/syncIndexTest.cpp
浏览文件 @
4fb1ef08
...
@@ -8,7 +8,13 @@ void print(SHashObj *pNextIndex) {
...
@@ -8,7 +8,13 @@ void print(SHashObj *pNextIndex) {
printf
(
"----------------
\n
"
);
printf
(
"----------------
\n
"
);
uint64_t
*
p
=
(
uint64_t
*
)
taosHashIterate
(
pNextIndex
,
NULL
);
uint64_t
*
p
=
(
uint64_t
*
)
taosHashIterate
(
pNextIndex
,
NULL
);
while
(
p
)
{
while
(
p
)
{
printf
(
"%lu
\n
"
,
*
p
);
size_t
len
;
void
*
key
=
taosHashGetKey
(
p
,
&
len
);
SRaftId
*
pRaftId
=
(
SRaftId
*
)
key
;
printf
(
"key:<%lu, %d>, value:%lu
\n
"
,
pRaftId
->
addr
,
pRaftId
->
vgId
,
*
p
);
p
=
(
uint64_t
*
)
taosHashIterate
(
pNextIndex
,
p
);
p
=
(
uint64_t
*
)
taosHashIterate
(
pNextIndex
,
p
);
}
}
}
}
...
...
source/libs/sync/test/syncRespMgrTest.cpp
浏览文件 @
4fb1ef08
...
@@ -73,9 +73,15 @@ void syncRespMgrGetAndDelTest(uint64_t i) {
...
@@ -73,9 +73,15 @@ void syncRespMgrGetAndDelTest(uint64_t i) {
}
}
}
}
SSyncNode
*
createSyncNode
()
{
SSyncNode
*
pSyncNode
=
(
SSyncNode
*
)
taosMemoryMalloc
(
sizeof
(
SSyncNode
));
memset
(
pSyncNode
,
0
,
sizeof
(
SSyncNode
));
return
pSyncNode
;
}
void
test1
()
{
void
test1
()
{
printf
(
"------- test1 ---------
\n
"
);
printf
(
"------- test1 ---------
\n
"
);
pMgr
=
syncRespMgrCreate
(
NULL
,
0
);
pMgr
=
syncRespMgrCreate
(
createSyncNode
()
,
0
);
assert
(
pMgr
!=
NULL
);
assert
(
pMgr
!=
NULL
);
syncRespMgrInsert
(
10
);
syncRespMgrInsert
(
10
);
...
@@ -100,7 +106,7 @@ void test1() {
...
@@ -100,7 +106,7 @@ void test1() {
void
test2
()
{
void
test2
()
{
printf
(
"------- test2 ---------
\n
"
);
printf
(
"------- test2 ---------
\n
"
);
pMgr
=
syncRespMgrCreate
(
NULL
,
0
);
pMgr
=
syncRespMgrCreate
(
createSyncNode
()
,
0
);
assert
(
pMgr
!=
NULL
);
assert
(
pMgr
!=
NULL
);
syncRespMgrInsert
(
10
);
syncRespMgrInsert
(
10
);
...
@@ -117,7 +123,7 @@ void test2() {
...
@@ -117,7 +123,7 @@ void test2() {
void
test3
()
{
void
test3
()
{
printf
(
"------- test3 ---------
\n
"
);
printf
(
"------- test3 ---------
\n
"
);
pMgr
=
syncRespMgrCreate
(
NULL
,
0
);
pMgr
=
syncRespMgrCreate
(
createSyncNode
()
,
0
);
assert
(
pMgr
!=
NULL
);
assert
(
pMgr
!=
NULL
);
syncRespMgrInsert
(
10
);
syncRespMgrInsert
(
10
);
...
@@ -132,13 +138,34 @@ void test3() {
...
@@ -132,13 +138,34 @@ void test3() {
syncRespMgrDestroy
(
pMgr
);
syncRespMgrDestroy
(
pMgr
);
}
}
void
test4
()
{
printf
(
"------- test4 ---------
\n
"
);
pMgr
=
syncRespMgrCreate
(
createSyncNode
(),
2
);
assert
(
pMgr
!=
NULL
);
syncRespMgrInsert
(
5
);
syncRespMgrPrint
();
taosMsleep
(
3000
);
syncRespMgrInsert
(
3
);
syncRespMgrPrint
();
printf
(
"====== after clean ttl
\n
"
);
syncRespClean
(
pMgr
);
syncRespMgrPrint
();
syncRespMgrDestroy
(
pMgr
);
}
int
main
()
{
int
main
()
{
tsAsyncLog
=
0
;
tsAsyncLog
=
0
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
sDebugFlag
=
DEBUG_
DEBUG
+
DEBUG_
TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
logTest
();
logTest
();
test1
();
test1
();
test2
();
test2
();
test3
();
test3
();
test4
();
return
0
;
return
0
;
}
}
source/libs/transport/inc/transComm.h
浏览文件 @
4fb1ef08
source/libs/transport/src/transSvr.c
浏览文件 @
4fb1ef08
...
@@ -241,18 +241,19 @@ static void uvHandleReq(SSvrConn* pConn) {
...
@@ -241,18 +241,19 @@ static void uvHandleReq(SSvrConn* pConn) {
tDebug
(
"conn %p acquired by server app"
,
pConn
);
tDebug
(
"conn %p acquired by server app"
,
pConn
);
}
}
}
}
STrans
*
pTransInst
=
pConn
->
pTransInst
;
STraceId
*
trace
=
&
pHead
->
traceId
;
STraceId
*
trace
=
&
pHead
->
traceId
;
if
(
pConn
->
status
==
ConnNormal
&&
pHead
->
noResp
==
0
)
{
if
(
pConn
->
status
==
ConnNormal
&&
pHead
->
noResp
==
0
)
{
transRefSrvHandle
(
pConn
);
transRefSrvHandle
(
pConn
);
tGTrace
(
"%s conn %p %s received from %s:%d, local info: %s:%d, msg size: %d"
,
transLabel
(
p
Conn
),
pConn
,
tGTrace
(
"%s conn %p %s received from %s:%d, local info: %s:%d, msg size: %d"
,
transLabel
(
p
TransInst
),
pConn
,
TMSG_INFO
(
transMsg
.
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
TMSG_INFO
(
transMsg
.
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetNtoa
(
pConn
->
localAddr
.
sin_addr
),
ntohs
(
pConn
->
localAddr
.
sin_port
),
transMsg
.
contLen
);
taosInetNtoa
(
pConn
->
localAddr
.
sin_addr
),
ntohs
(
pConn
->
localAddr
.
sin_port
),
transMsg
.
contLen
);
}
else
{
}
else
{
tGTrace
(
"%s conn %p %s received from %s:%d, local info: %s:%d, msg size: %d, resp:%d, code: %d"
,
transLabel
(
pConn
),
tGTrace
(
"%s conn %p %s received from %s:%d, local info: %s:%d, msg size: %d, resp:%d, code: %d"
,
pConn
,
TMSG_INFO
(
transMsg
.
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
transLabel
(
pTransInst
),
pConn
,
TMSG_INFO
(
transMsg
.
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
taosInetNtoa
(
pConn
->
localAddr
.
sin_addr
),
ntohs
(
pConn
->
localAddr
.
sin_port
),
transMsg
.
contLen
,
pHead
->
noResp
,
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetNtoa
(
pConn
->
localAddr
.
sin_addr
),
ntohs
(
pConn
->
localAddr
.
sin_port
)
,
transMsg
.
code
);
transMsg
.
co
ntLen
,
pHead
->
noResp
,
transMsg
.
co
de
);
// no ref here
// no ref here
}
}
...
@@ -265,8 +266,8 @@ static void uvHandleReq(SSvrConn* pConn) {
...
@@ -265,8 +266,8 @@ static void uvHandleReq(SSvrConn* pConn) {
transMsg
.
info
.
refId
=
pConn
->
refId
;
transMsg
.
info
.
refId
=
pConn
->
refId
;
transMsg
.
info
.
traceId
=
pHead
->
traceId
;
transMsg
.
info
.
traceId
=
pHead
->
traceId
;
tGTrace
(
"%s handle %p conn: %p translated to app, refId: %"
PRIu64
""
,
transLabel
(
p
Conn
),
transMsg
.
info
.
handle
,
pConn
,
tGTrace
(
"%s handle %p conn: %p translated to app, refId: %"
PRIu64
""
,
transLabel
(
p
TransInst
),
transMsg
.
info
.
handle
,
pConn
->
refId
);
pConn
,
pConn
->
refId
);
assert
(
transMsg
.
info
.
handle
!=
NULL
);
assert
(
transMsg
.
info
.
handle
!=
NULL
);
if
(
pHead
->
noResp
==
1
)
{
if
(
pHead
->
noResp
==
1
)
{
...
@@ -281,7 +282,6 @@ static void uvHandleReq(SSvrConn* pConn) {
...
@@ -281,7 +282,6 @@ static void uvHandleReq(SSvrConn* pConn) {
transReleaseExHandle
(
transGetRefMgt
(),
pConn
->
refId
);
transReleaseExHandle
(
transGetRefMgt
(),
pConn
->
refId
);
STrans
*
pTransInst
=
pConn
->
pTransInst
;
(
*
pTransInst
->
cfp
)(
pTransInst
->
parent
,
&
transMsg
,
NULL
);
(
*
pTransInst
->
cfp
)(
pTransInst
->
parent
,
&
transMsg
,
NULL
);
// uv_timer_start(&pConn->pTimer, uvHandleActivityTimeout, pRpc->idleTime * 10000, 0);
// uv_timer_start(&pConn->pTimer, uvHandleActivityTimeout, pRpc->idleTime * 10000, 0);
}
}
...
@@ -290,14 +290,15 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) {
...
@@ -290,14 +290,15 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) {
// opt
// opt
SSvrConn
*
conn
=
cli
->
data
;
SSvrConn
*
conn
=
cli
->
data
;
SConnBuffer
*
pBuf
=
&
conn
->
readBuf
;
SConnBuffer
*
pBuf
=
&
conn
->
readBuf
;
STrans
*
pTransInst
=
conn
->
pTransInst
;
if
(
nread
>
0
)
{
if
(
nread
>
0
)
{
pBuf
->
len
+=
nread
;
pBuf
->
len
+=
nread
;
tTrace
(
"%s conn %p total read: %d, current read: %d"
,
transLabel
(
conn
->
pTransInst
),
conn
,
pBuf
->
len
,
(
int
)
nread
);
tTrace
(
"%s conn %p total read: %d, current read: %d"
,
transLabel
(
pTransInst
),
conn
,
pBuf
->
len
,
(
int
)
nread
);
if
(
transReadComplete
(
pBuf
))
{
if
(
transReadComplete
(
pBuf
))
{
tTrace
(
"%s conn %p alread read complete packet"
,
transLabel
(
conn
->
pTransInst
),
conn
);
tTrace
(
"%s conn %p alread read complete packet"
,
transLabel
(
pTransInst
),
conn
);
uvHandleReq
(
conn
);
uvHandleReq
(
conn
);
}
else
{
}
else
{
tTrace
(
"%s conn %p read partial packet, continue to read"
,
transLabel
(
conn
->
pTransInst
),
conn
);
tTrace
(
"%s conn %p read partial packet, continue to read"
,
transLabel
(
pTransInst
),
conn
);
}
}
return
;
return
;
}
}
...
@@ -305,12 +306,12 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) {
...
@@ -305,12 +306,12 @@ void uvOnRecvCb(uv_stream_t* cli, ssize_t nread, const uv_buf_t* buf) {
return
;
return
;
}
}
tError
(
"%s conn %p read error: %s"
,
transLabel
(
conn
->
pTransInst
),
conn
,
uv_err_name
(
nread
));
tError
(
"%s conn %p read error: %s"
,
transLabel
(
pTransInst
),
conn
,
uv_err_name
(
nread
));
if
(
nread
<
0
)
{
if
(
nread
<
0
)
{
conn
->
broken
=
true
;
conn
->
broken
=
true
;
if
(
conn
->
status
==
ConnAcquire
)
{
if
(
conn
->
status
==
ConnAcquire
)
{
if
(
conn
->
regArg
.
init
)
{
if
(
conn
->
regArg
.
init
)
{
tTrace
(
"%s conn %p broken, notify server app"
,
transLabel
(
conn
->
pTransInst
),
conn
);
tTrace
(
"%s conn %p broken, notify server app"
,
transLabel
(
pTransInst
),
conn
);
STrans
*
pTransInst
=
conn
->
pTransInst
;
STrans
*
pTransInst
=
conn
->
pTransInst
;
(
*
pTransInst
->
cfp
)(
pTransInst
->
parent
,
&
(
conn
->
regArg
.
msg
),
NULL
);
(
*
pTransInst
->
cfp
)(
pTransInst
->
parent
,
&
(
conn
->
regArg
.
msg
),
NULL
);
memset
(
&
conn
->
regArg
,
0
,
sizeof
(
conn
->
regArg
));
memset
(
&
conn
->
regArg
,
0
,
sizeof
(
conn
->
regArg
));
...
@@ -402,10 +403,11 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) {
...
@@ -402,10 +403,11 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) {
}
else
{
}
else
{
pHead
->
msgType
=
pMsg
->
msgType
;
pHead
->
msgType
=
pMsg
->
msgType
;
// set up resp msg type
// set up resp msg type
if
(
pHead
->
msgType
==
0
&&
transMsgLenFromCont
(
pMsg
->
contLen
)
==
sizeof
(
STransMsgHead
))
if
(
pHead
->
msgType
==
0
&&
transMsgLenFromCont
(
pMsg
->
contLen
)
==
sizeof
(
STransMsgHead
))
{
pHead
->
msgType
=
pConn
->
inType
+
1
;
pHead
->
msgType
=
pConn
->
inType
+
1
;
}
}
}
}
}
pHead
->
release
=
smsg
->
type
==
Release
?
1
:
0
;
pHead
->
release
=
smsg
->
type
==
Release
?
1
:
0
;
pHead
->
code
=
htonl
(
pMsg
->
code
);
pHead
->
code
=
htonl
(
pMsg
->
code
);
...
@@ -413,8 +415,9 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) {
...
@@ -413,8 +415,9 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) {
char
*
msg
=
(
char
*
)
pHead
;
char
*
msg
=
(
char
*
)
pHead
;
int32_t
len
=
transMsgLenFromCont
(
pMsg
->
contLen
);
int32_t
len
=
transMsgLenFromCont
(
pMsg
->
contLen
);
STrans
*
pTransInst
=
pConn
->
pTransInst
;
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
STraceId
*
trace
=
&
pMsg
->
info
.
traceId
;
tGTrace
(
"%s conn %p %s is sent to %s:%d, local info: %s:%d, msglen:%d"
,
transLabel
(
p
Conn
->
p
TransInst
),
pConn
,
tGTrace
(
"%s conn %p %s is sent to %s:%d, local info: %s:%d, msglen:%d"
,
transLabel
(
pTransInst
),
pConn
,
TMSG_INFO
(
pHead
->
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
TMSG_INFO
(
pHead
->
msgType
),
taosInetNtoa
(
pConn
->
addr
.
sin_addr
),
ntohs
(
pConn
->
addr
.
sin_port
),
taosInetNtoa
(
pConn
->
localAddr
.
sin_addr
),
ntohs
(
pConn
->
localAddr
.
sin_port
),
len
);
taosInetNtoa
(
pConn
->
localAddr
.
sin_addr
),
ntohs
(
pConn
->
localAddr
.
sin_port
),
len
);
pHead
->
msgLen
=
htonl
(
len
);
pHead
->
msgLen
=
htonl
(
len
);
...
@@ -760,9 +763,10 @@ static SSvrConn* createConn(void* hThrd) {
...
@@ -760,9 +763,10 @@ static SSvrConn* createConn(void* hThrd) {
exh
->
refId
=
transAddExHandle
(
transGetRefMgt
(),
exh
);
exh
->
refId
=
transAddExHandle
(
transGetRefMgt
(),
exh
);
transAcquireExHandle
(
transGetRefMgt
(),
exh
->
refId
);
transAcquireExHandle
(
transGetRefMgt
(),
exh
->
refId
);
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
pConn
->
refId
=
exh
->
refId
;
pConn
->
refId
=
exh
->
refId
;
transRefSrvHandle
(
pConn
);
transRefSrvHandle
(
pConn
);
tTrace
(
"%s handle %p, conn %p created, refId: %"
PRId64
""
,
transLabel
(
pT
hrd
->
pT
ransInst
),
exh
,
pConn
,
pConn
->
refId
);
tTrace
(
"%s handle %p, conn %p created, refId: %"
PRId64
""
,
transLabel
(
pTransInst
),
exh
,
pConn
,
pConn
->
refId
);
return
pConn
;
return
pConn
;
}
}
...
@@ -811,7 +815,13 @@ static void uvDestroyConn(uv_handle_t* handle) {
...
@@ -811,7 +815,13 @@ static void uvDestroyConn(uv_handle_t* handle) {
transReleaseExHandle
(
transGetRefMgt
(),
conn
->
refId
);
transReleaseExHandle
(
transGetRefMgt
(),
conn
->
refId
);
transRemoveExHandle
(
transGetRefMgt
(),
conn
->
refId
);
transRemoveExHandle
(
transGetRefMgt
(),
conn
->
refId
);
tDebug
(
"%s conn %p destroy"
,
transLabel
(
thrd
->
pTransInst
),
conn
);
STrans
*
pTransInst
=
thrd
->
pTransInst
;
tDebug
(
"%s conn %p destroy"
,
transLabel
(
pTransInst
),
conn
);
for
(
int
i
=
0
;
i
<
transQueueSize
(
&
conn
->
srvMsgs
);
i
++
)
{
SSvrMsg
*
msg
=
transQueueGet
(
&
conn
->
srvMsgs
,
i
);
destroySmsg
(
msg
);
}
transQueueDestroy
(
&
conn
->
srvMsgs
);
transQueueDestroy
(
&
conn
->
srvMsgs
);
QUEUE_REMOVE
(
&
conn
->
queue
);
QUEUE_REMOVE
(
&
conn
->
queue
);
...
@@ -1102,7 +1112,8 @@ void transRegisterMsg(const STransMsg* msg) {
...
@@ -1102,7 +1112,8 @@ void transRegisterMsg(const STransMsg* msg) {
m
->
msg
=
tmsg
;
m
->
msg
=
tmsg
;
m
->
type
=
Register
;
m
->
type
=
Register
;
tTrace
(
"%s conn %p start to register brokenlink callback"
,
transLabel
(
pThrd
->
pTransInst
),
exh
->
handle
);
STrans
*
pTransInst
=
pThrd
->
pTransInst
;
tTrace
(
"%s conn %p start to register brokenlink callback"
,
transLabel
(
pTransInst
),
exh
->
handle
);
transAsyncSend
(
pThrd
->
asyncPool
,
&
m
->
q
);
transAsyncSend
(
pThrd
->
asyncPool
,
&
m
->
q
);
transReleaseExHandle
(
transGetRefMgt
(),
refId
);
transReleaseExHandle
(
transGetRefMgt
(),
refId
);
return
;
return
;
...
...
source/os/src/osFile.c
浏览文件 @
4fb1ef08
...
@@ -58,6 +58,15 @@ typedef struct TdFile {
...
@@ -58,6 +58,15 @@ typedef struct TdFile {
#define FILE_WITH_LOCK 1
#define FILE_WITH_LOCK 1
typedef
struct
AutoDelFile
*
AutoDelFilePtr
;
typedef
struct
AutoDelFile
{
char
*
name
;
AutoDelFilePtr
lastAutoDelFilePtr
;
}
AutoDelFile
;
static
TdThreadMutex
autoDelFileLock
;
static
AutoDelFilePtr
nowAutoDelFilePtr
=
NULL
;
static
TdThreadOnce
autoDelFileInit
=
PTHREAD_ONCE_INIT
;
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
void
taosGetTmpfilePath
(
const
char
*
inputTmpDir
,
const
char
*
fileNamePrefix
,
char
*
dstPath
)
{
#ifdef WINDOWS
#ifdef WINDOWS
const
char
*
tdengineTmpFileNamePrefix
=
"tdengine-"
;
const
char
*
tdengineTmpFileNamePrefix
=
"tdengine-"
;
...
@@ -238,7 +247,33 @@ int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) {
...
@@ -238,7 +247,33 @@ int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) {
return
0
;
return
0
;
}
}
void
autoDelFileListAdd
(
const
char
*
path
)
{
return
;
}
void
autoDelFileList
()
{
taosThreadMutexLock
(
&
autoDelFileLock
);
while
(
nowAutoDelFilePtr
!=
NULL
)
{
taosRemoveFile
(
nowAutoDelFilePtr
->
name
);
AutoDelFilePtr
tmp
=
nowAutoDelFilePtr
->
lastAutoDelFilePtr
;
taosMemoryFree
(
nowAutoDelFilePtr
->
name
);
taosMemoryFree
(
nowAutoDelFilePtr
);
nowAutoDelFilePtr
=
tmp
;
}
taosThreadMutexUnlock
(
&
autoDelFileLock
);
taosThreadMutexDestroy
(
&
autoDelFileLock
);
}
void
autoDelFileListInit
()
{
taosThreadMutexInit
(
&
autoDelFileLock
,
NULL
);
atexit
(
autoDelFileList
);
}
void
autoDelFileListAdd
(
const
char
*
path
)
{
taosThreadOnce
(
&
autoDelFileInit
,
autoDelFileListInit
);
taosThreadMutexLock
(
&
autoDelFileLock
);
AutoDelFilePtr
tmp
=
taosMemoryMalloc
(
sizeof
(
AutoDelFile
));
tmp
->
lastAutoDelFilePtr
=
nowAutoDelFilePtr
;
tmp
->
name
=
taosMemoryStrDup
(
path
);
nowAutoDelFilePtr
=
tmp
;
taosThreadMutexUnlock
(
&
autoDelFileLock
);
}
TdFilePtr
taosOpenFile
(
const
char
*
path
,
int32_t
tdFileOptions
)
{
TdFilePtr
taosOpenFile
(
const
char
*
path
,
int32_t
tdFileOptions
)
{
int
fd
=
-
1
;
int
fd
=
-
1
;
...
@@ -283,10 +318,6 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
...
@@ -283,10 +318,6 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
}
}
}
}
if
(
tdFileOptions
&
TD_FILE_AUTO_DEL
)
{
autoDelFileListAdd
(
path
);
}
TdFilePtr
pFile
=
(
TdFilePtr
)
taosMemoryMalloc
(
sizeof
(
TdFile
));
TdFilePtr
pFile
=
(
TdFilePtr
)
taosMemoryMalloc
(
sizeof
(
TdFile
));
if
(
pFile
==
NULL
)
{
if
(
pFile
==
NULL
)
{
if
(
fd
>=
0
)
close
(
fd
);
if
(
fd
>=
0
)
close
(
fd
);
...
@@ -299,6 +330,9 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
...
@@ -299,6 +330,9 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
pFile
->
fd
=
fd
;
pFile
->
fd
=
fd
;
pFile
->
fp
=
fp
;
pFile
->
fp
=
fp
;
pFile
->
refId
=
0
;
pFile
->
refId
=
0
;
if
(
tdFileOptions
&
TD_FILE_AUTO_DEL
)
{
autoDelFileListAdd
(
path
);
}
return
pFile
;
return
pFile
;
}
}
...
...
source/os/src/osMemory.c
浏览文件 @
4fb1ef08
...
@@ -282,14 +282,14 @@ void *taosMemoryRealloc(void *ptr, int32_t size) {
...
@@ -282,14 +282,14 @@ void *taosMemoryRealloc(void *ptr, int32_t size) {
#endif
#endif
}
}
void
*
taosMemoryStrDup
(
void
*
ptr
)
{
void
*
taosMemoryStrDup
(
const
char
*
ptr
)
{
#ifdef USE_TD_MEMORY
#ifdef USE_TD_MEMORY
if
(
ptr
==
NULL
)
return
NULL
;
if
(
ptr
==
NULL
)
return
NULL
;
TdMemoryInfoPtr
pTdMemoryInfo
=
(
TdMemoryInfoPtr
)((
char
*
)
ptr
-
sizeof
(
TdMemoryInfo
));
TdMemoryInfoPtr
pTdMemoryInfo
=
(
TdMemoryInfoPtr
)((
char
*
)
ptr
-
sizeof
(
TdMemoryInfo
));
assert
(
pTdMemoryInfo
->
symbol
==
TD_MEMORY_SYMBOL
);
assert
(
pTdMemoryInfo
->
symbol
==
TD_MEMORY_SYMBOL
);
void
*
tmp
=
tstrdup
(
(
const
char
*
)
pTdMemoryInfo
);
void
*
tmp
=
tstrdup
(
pTdMemoryInfo
);
if
(
tmp
==
NULL
)
return
NULL
;
if
(
tmp
==
NULL
)
return
NULL
;
memcpy
(
tmp
,
pTdMemoryInfo
,
sizeof
(
TdMemoryInfo
));
memcpy
(
tmp
,
pTdMemoryInfo
,
sizeof
(
TdMemoryInfo
));
...
@@ -297,7 +297,7 @@ void *taosMemoryStrDup(void *ptr) {
...
@@ -297,7 +297,7 @@ void *taosMemoryStrDup(void *ptr) {
return
(
char
*
)
tmp
+
sizeof
(
TdMemoryInfo
);
return
(
char
*
)
tmp
+
sizeof
(
TdMemoryInfo
);
#else
#else
return
tstrdup
(
(
const
char
*
)
ptr
);
return
tstrdup
(
ptr
);
#endif
#endif
}
}
...
...
source/util/src/tpagedbuf.c
浏览文件 @
4fb1ef08
...
@@ -637,6 +637,7 @@ void dBufSetBufPageRecycled(SDiskbasedBuf* pBuf, void* pPage) {
...
@@ -637,6 +637,7 @@ void dBufSetBufPageRecycled(SDiskbasedBuf* pBuf, void* pPage) {
SListNode
*
pNode
=
tdListPopNode
(
pBuf
->
lruList
,
ppi
->
pn
);
SListNode
*
pNode
=
tdListPopNode
(
pBuf
->
lruList
,
ppi
->
pn
);
taosMemoryFreeClear
(
ppi
->
pData
);
taosMemoryFreeClear
(
ppi
->
pData
);
taosMemoryFreeClear
(
pNode
);
taosMemoryFreeClear
(
pNode
);
ppi
->
pn
=
NULL
;
tdListAppend
(
pBuf
->
freePgList
,
&
ppi
);
tdListAppend
(
pBuf
->
freePgList
,
&
ppi
);
}
}
...
...
tests/pytest/util/gettime.py
0 → 100644
浏览文件 @
4fb1ef08
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import
time
from
datetime
import
datetime
class
GetTime
:
def
get_ms_timestamp
(
self
,
ts_str
):
_ts_str
=
ts_str
if
" "
in
ts_str
:
p
=
ts_str
.
split
(
" "
)[
1
]
if
len
(
p
)
>
15
:
_ts_str
=
ts_str
[:
-
3
]
if
':'
in
_ts_str
and
'.'
in
_ts_str
:
timestamp
=
datetime
.
strptime
(
_ts_str
,
"%Y-%m-%d %H:%M:%S.%f"
)
date_time
=
int
(
int
(
time
.
mktime
(
timestamp
.
timetuple
()))
*
1000
+
timestamp
.
microsecond
/
1000
)
elif
':'
in
_ts_str
and
'.'
not
in
_ts_str
:
timestamp
=
datetime
.
strptime
(
_ts_str
,
"%Y-%m-%d %H:%M:%S"
)
date_time
=
int
(
int
(
time
.
mktime
(
timestamp
.
timetuple
()))
*
1000
+
timestamp
.
microsecond
/
1000
)
else
:
timestamp
=
datetime
.
strptime
(
_ts_str
,
"%Y-%m-%d"
)
date_time
=
int
(
int
(
time
.
mktime
(
timestamp
.
timetuple
()))
*
1000
+
timestamp
.
microsecond
/
1000
)
return
date_time
def
get_us_timestamp
(
self
,
ts_str
):
_ts
=
self
.
get_ms_timestamp
(
ts_str
)
*
1000
if
" "
in
ts_str
:
p
=
ts_str
.
split
(
" "
)[
1
]
if
len
(
p
)
>
12
:
us_ts
=
p
[
12
:
15
]
_ts
+=
int
(
us_ts
)
return
_ts
def
get_ns_timestamp
(
self
,
ts_str
):
_ts
=
self
.
get_us_timestamp
(
ts_str
)
*
1000
if
" "
in
ts_str
:
p
=
ts_str
.
split
(
" "
)[
1
]
if
len
(
p
)
>
15
:
us_ts
=
p
[
15
:]
_ts
+=
int
(
us_ts
)
return
_ts
def
time_transform
(
self
,
ts_str
,
precision
):
date_time
=
[]
if
precision
==
'ms'
:
for
i
in
ts_str
:
date_time
.
append
(
self
.
get_ms_timestamp
(
i
))
elif
precision
==
'us'
:
for
i
in
ts_str
:
date_time
.
append
(
self
.
get_us_timestamp
(
i
))
elif
precision
==
'ns'
:
for
i
in
ts_str
:
date_time
.
append
(
self
.
get_ns_timestamp
(
i
))
return
date_time
\ No newline at end of file
tests/script/jenkins/basic.txt
浏览文件 @
4fb1ef08
...
@@ -167,7 +167,7 @@
...
@@ -167,7 +167,7 @@
./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim
./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim
# --- valgrind
# --- valgrind
./test.sh -f tsim/valgrind/checkError.sim
-v
./test.sh -f tsim/valgrind/checkError.sim
# --- vnode
# --- vnode
# ./test.sh -f tsim/vnode/replica3_basic.sim
# ./test.sh -f tsim/vnode/replica3_basic.sim
...
...
tests/script/sh/checkValgrind.sh
浏览文件 @
4fb1ef08
...
@@ -35,5 +35,10 @@ LOG_DIR=$TAOS_DIR/sim/$NODE_NAME/log
...
@@ -35,5 +35,10 @@ LOG_DIR=$TAOS_DIR/sim/$NODE_NAME/log
#echo ---- $LOG_DIR
#echo ---- $LOG_DIR
#errors=`grep "ERROR SUMMARY:" ${LOG_DIR}/valgrind-taosd-*.log | cut -d ' ' -f 2,3,4,5 | tr -d "\n"`
#errors=`grep "ERROR SUMMARY:" ${LOG_DIR}/valgrind-taosd-*.log | cut -d ' ' -f 2,3,4,5 | tr -d "\n"`
errors
=
`
cat
${
LOG_DIR
}
/valgrind-taosd-
*
.log |
grep
"ERROR SUMMARY:"
|
awk
'{print $4}'
|
awk
'{sum+=$1}END{print sum}'
`
error_summary
=
`
cat
${
LOG_DIR
}
/valgrind-taosd-
*
.log |
grep
"ERROR SUMMARY:"
|
awk
'{print $4}'
|
awk
'{sum+=$1}END{print sum}'
`
still_reachable
=
`
cat
${
LOG_DIR
}
/valgrind-taosd-
*
.log |
grep
"still reachable in"
|
wc
-l
`
definitely_lost
=
`
cat
${
LOG_DIR
}
/valgrind-taosd-
*
.log |
grep
"definitely lost in"
|
wc
-l
`
let
"errors=
$still_reachable
+
$error_summary
+
$definitely_lost
"
echo
$errors
echo
$errors
tests/script/tsim/stable/tag_modify.sim
浏览文件 @
4fb1ef08
...
@@ -14,7 +14,7 @@ sql_error alter table db.stb MODIFY tag ts int
...
@@ -14,7 +14,7 @@ sql_error alter table db.stb MODIFY tag ts int
sql_error alter table db.stb MODIFY tag t2 binary(3)
sql_error alter table db.stb MODIFY tag t2 binary(3)
sql_error alter table db.stb MODIFY tag t2 int
sql_error alter table db.stb MODIFY tag t2 int
sql_error alter table db.stb MODIFY tag t1 int
sql_error alter table db.stb MODIFY tag t1 int
sql create table db.ctb using db.stb tags(101, "123
45
")
sql create table db.ctb using db.stb tags(101, "123")
sql insert into db.ctb values(now, 1, "1234")
sql insert into db.ctb values(now, 1, "1234")
sql select * from db.stb
sql select * from db.stb
...
@@ -32,7 +32,7 @@ endi
...
@@ -32,7 +32,7 @@ endi
if $data[0][3] != 101 then
if $data[0][3] != 101 then
return -1
return -1
endi
endi
if $data[0][4] != 123
4
then
if $data[0][4] != 123 then
return -1
return -1
endi
endi
...
...
tests/script/tsim/stable/tag_rename.sim
浏览文件 @
4fb1ef08
...
@@ -14,7 +14,7 @@ sql_error alter table db.stb rename tag ts c3
...
@@ -14,7 +14,7 @@ sql_error alter table db.stb rename tag ts c3
sql_error alter table db.stb rename tag t2 t1
sql_error alter table db.stb rename tag t2 t1
sql_error alter table db.stb rename tag t2 t2
sql_error alter table db.stb rename tag t2 t2
sql_error alter table db.stb rename tag t1 t2
sql_error alter table db.stb rename tag t1 t2
sql create table db.ctb using db.stb tags(101, "123
45
")
sql create table db.ctb using db.stb tags(101, "123")
sql insert into db.ctb values(now, 1, "1234")
sql insert into db.ctb values(now, 1, "1234")
sql select * from db.stb
sql select * from db.stb
...
@@ -32,7 +32,7 @@ endi
...
@@ -32,7 +32,7 @@ endi
if $data[0][3] != 101 then
if $data[0][3] != 101 then
return -1
return -1
endi
endi
if $data[0][4] != 123
4
then
if $data[0][4] != 123 then
return -1
return -1
endi
endi
...
@@ -56,7 +56,7 @@ endi
...
@@ -56,7 +56,7 @@ endi
if $data[0][3] != 101 then
if $data[0][3] != 101 then
return -1
return -1
endi
endi
if $data[0][4] != 123
4
then
if $data[0][4] != 123 then
return -1
return -1
endi
endi
...
...
tests/script/tsim/valgrind/basic.sim
浏览文件 @
4fb1ef08
...
@@ -26,8 +26,8 @@ sql show users
...
@@ -26,8 +26,8 @@ sql show users
sql alter user u1 sysinfo 1
sql alter user u1 sysinfo 1
sql alter user u1 enable 1
sql alter user u1 enable 1
sql alter user u1 pass 'taosdata'
sql alter user u1 pass 'taosdata'
sql alter user u2 sysinfo 0
sql drop user u1
sql drop user u1
sql_error alter user u2 sysinfo 0
_OVER:
_OVER:
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode1 -s stop -x SIGINT
tests/script/tsim/valgrind/basic2.sim
0 → 100644
浏览文件 @
4fb1ef08
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start -v
sql connect
print =============== step1: create drop show dnodes
$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
if $rows != 1 then
return -1
endi
print =============== step2: create db
sql create database db vgroups 1
_OVER:
system sh/exec.sh -n dnode1 -s stop -x SIGINT
tests/script/tsim/valgrind/checkError.sim
浏览文件 @
4fb1ef08
system sh/stop_dnodes.sh
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode1 -i 1
#system sh/deploy.sh -n dnode2 -i 2
system sh/exec.sh -n dnode1 -s start -v
#system sh/deploy.sh -n dnode3 -i 3
sql connect
#system sh/deploy.sh -n dnode4 -i 4
#system sh/cfg.sh -n dnode1 -c supportVnodes -v 0
print =============== step1
system sh/exec.sh -n dnode1 -s start
#system sh/exec.sh -n dnode2 -s start
$x = 0
#system sh/exec.sh -n dnode3 -s start
step1:
#system sh/exec.sh -n dnode4 -s start
$x = $x + 1
sleep 1000
sleep 2000
if $x == 10 then
print ----> dnode not ready!
#$loop_cnt = 0
return -1
#check_dnode_ready:
endi
# $loop_cnt = $loop_cnt + 1
sql show dnodes
# sleep 200
print ----> $data00 $data01 $data02 $data03 $data04 $data05
# if $loop_cnt == 10 then
if $rows != 1 then
# print ====> dnode not ready!
return -1
# return -1
endi
# endi
#sql show dnodes
#print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6]
#print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6]
#print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6]
#print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6]
#if $data[0][0] != 1 then
# return -1
#endi
#if $data[0][4] != ready then
# goto check_dnode_ready
#endi
#
##sql connect
#sql create dnode $hostname port 7200
#sql create dnode $hostname port 7300
#sql create dnode $hostname port 7400
#
#$loop_cnt = 0
#check_dnode_ready_1:
#$loop_cnt = $loop_cnt + 1
#sleep 200
#if $loop_cnt == 10 then
# print ====> dnodes not ready!
# return -1
#endi
#sql show dnodes
#print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6]
#print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6]
#print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6]
#print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6]
#if $data[0][4] != ready then
# goto check_dnode_ready_1
#endi
#if $data[1][4] != ready then
# goto check_dnode_ready_1
#endi
#if $data[2][4] != ready then
# goto check_dnode_ready_1
#endi
#if $data[3][4] != ready then
# goto check_dnode_ready_1
#endi
#=========== please add any actions above =================
print =============== step2
print ====
> stop all dondes to output valgrind log file
print ====
=========== stop
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode1 -s stop -x SIGINT
print
====
> start to check if there are ERRORS in vagrind log file for each dnode
print
----
> start to check if there are ERRORS in vagrind log file for each dnode
# -n : dnode[x] be check
# -n : dnode[x] be check
system_content sh/checkValgrind.sh -n dnode1
system_content sh/checkValgrind.sh -n dnode1
print cmd return result----> [ $system_content ]
# temporarily expand the threshold, since no time to fix the memory leaks.
# temporarily expand the threshold, since no time to fix the memory leaks.
print cmd return result ----> [ $system_content ]
if $system_content <= 5 then
if $system_content <= 5 then
return 0
return 0
endi
endi
# This error occurs frequently, allowing it
# ==435850== 46 bytes in 1 blocks are definitely lost in loss record 1 of 3
# ==435850== at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgp reload_memcheck-amd64-linux.so)
# ==435850== by 0x414AE0: taosMemoryCalloc (osMemory.c:212)
# ==435850== by 0x352730: transAllocBuffer (transComm.c:123)
# ==435850== by 0x34F42A: cliAllocRecvBufferCb (transCli.c:485)
$null=
$null=
if $system_content == $null then
if $system_content == $null then
return 0
return 0
...
...
tests/system-test/1-insert/alter_stable.py
浏览文件 @
4fb1ef08
...
@@ -108,8 +108,8 @@ class TDTestCase:
...
@@ -108,8 +108,8 @@ class TDTestCase:
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
_
{
i
}
add column
{
key
}
{
values
}
'
)
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
_
{
i
}
add column
{
key
}
{
values
}
'
)
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
_
{
i
}
drop column
{
key
}
'
)
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
_
{
i
}
drop column
{
key
}
'
)
#! bug TD-16921
#! bug TD-16921
#
tdSql.error(f'alter stable {self.ntbname} add column {key} {values}')
tdSql
.
error
(
f
'alter stable
{
self
.
ntbname
}
add column
{
key
}
{
values
}
'
)
#
tdSql.error(f'alter stable {self.ntbname} drop column {key}')
tdSql
.
error
(
f
'alter stable
{
self
.
ntbname
}
drop column
{
key
}
'
)
tdSql
.
execute
(
f
'alter stable
{
self
.
stbname
}
drop column
{
key
}
'
)
tdSql
.
execute
(
f
'alter stable
{
self
.
stbname
}
drop column
{
key
}
'
)
tdSql
.
query
(
f
'describe
{
self
.
stbname
}
'
)
tdSql
.
query
(
f
'describe
{
self
.
stbname
}
'
)
tdSql
.
checkRows
(
len
(
self
.
column_dict
)
+
len
(
self
.
tag_dict
))
tdSql
.
checkRows
(
len
(
self
.
column_dict
)
+
len
(
self
.
tag_dict
))
...
@@ -132,7 +132,7 @@ class TDTestCase:
...
@@ -132,7 +132,7 @@ class TDTestCase:
tdSql
.
checkEqual
(
result
[
0
][
2
],
self
.
binary_length
+
1
)
tdSql
.
checkEqual
(
result
[
0
][
2
],
self
.
binary_length
+
1
)
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
_
{
i
}
modify column
{
key
}
{
v
}
'
)
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
_
{
i
}
modify column
{
key
}
{
v
}
'
)
#! bug TD-16921
#! bug TD-16921
#
tdSql.error(f'alter stable {self.ntbname} modify column {key} {v}')
tdSql
.
error
(
f
'alter stable
{
self
.
ntbname
}
modify column
{
key
}
{
v
}
'
)
elif
'nchar'
in
values
.
lower
():
elif
'nchar'
in
values
.
lower
():
v
=
f
'nchar(
{
self
.
binary_length
+
1
}
)'
v
=
f
'nchar(
{
self
.
binary_length
+
1
}
)'
v_error
=
f
'nchar(
{
self
.
binary_length
-
1
}
)'
v_error
=
f
'nchar(
{
self
.
binary_length
-
1
}
)'
...
@@ -147,11 +147,11 @@ class TDTestCase:
...
@@ -147,11 +147,11 @@ class TDTestCase:
tdSql
.
checkEqual
(
result
[
0
][
2
],
self
.
binary_length
+
1
)
tdSql
.
checkEqual
(
result
[
0
][
2
],
self
.
binary_length
+
1
)
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
_
{
i
}
modify column
{
key
}
{
v
}
'
)
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
_
{
i
}
modify column
{
key
}
{
v
}
'
)
#! bug TD-16921
#! bug TD-16921
#
tdSql.error(f'alter stable {self.ntbname} modify column {key} {v}')
tdSql
.
error
(
f
'alter stable
{
self
.
ntbname
}
modify column
{
key
}
{
v
}
'
)
else
:
else
:
for
v
in
self
.
column_dict
.
values
():
for
v
in
self
.
column_dict
.
values
():
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
modify column
{
key
}
{
v
}
'
)
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
modify column
{
key
}
{
v
}
'
)
#
tdSql.error(f'alter stable {self.ntbname} modify column {key} {v}')
tdSql
.
error
(
f
'alter stable
{
self
.
ntbname
}
modify column
{
key
}
{
v
}
'
)
for
i
in
range
(
self
.
tbnum
):
for
i
in
range
(
self
.
tbnum
):
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
_
{
i
}
modify column
{
key
}
{
v
}
'
)
tdSql
.
error
(
f
'alter stable
{
self
.
stbname
}
_
{
i
}
modify column
{
key
}
{
v
}
'
)
def
run
(
self
):
def
run
(
self
):
...
...
tests/system-test/2-query/Timediff.py
浏览文件 @
4fb1ef08
from
util.log
import
*
from
util.log
import
*
from
util.sql
import
*
from
util.sql
import
*
from
util.cases
import
*
from
util.cases
import
*
from
util.gettime
import
*
class
TDTestCase
:
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
f
"start to excute
{
__file__
}
"
)
tdLog
.
debug
(
f
"start to excute
{
__file__
}
"
)
tdSql
.
init
(
conn
.
cursor
())
tdSql
.
init
(
conn
.
cursor
())
self
.
get_time
=
GetTime
()
self
.
ts_str
=
[
'2020-1-1'
,
'2020-2-1 00:00:01'
,
'2020-3-1 00:00:00.001'
,
'2020-4-1 00:00:00.001002'
,
'2020-5-1 00:00:00.001002001'
]
self
.
db_param_precision
=
[
'ms'
,
'us'
,
'ns'
]
self
.
time_unit
=
[
'1w'
,
'1d'
,
'1h'
,
'1m'
,
'1s'
,
'1a'
,
'1u'
,
'1b'
]
self
.
error_unit
=
[
'2w'
,
'2d'
,
'2h'
,
'2m'
,
'2s'
,
'2a'
,
'2u'
,
'1c'
,
'#1'
]
self
.
ntbname
=
'ntb'
self
.
stbname
=
'stb'
self
.
ctbname
=
'ctb'
self
.
subtractor
=
1
# unit:s
def
check_tbtype
(
self
,
tb_type
):
if
tb_type
.
lower
()
==
'ntb'
:
tdSql
.
query
(
f
'select timediff(ts,
{
self
.
subtractor
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
query
(
f
'select timediff(ts,
{
self
.
subtractor
}
) from
{
self
.
ctbname
}
'
)
elif
tb_type
.
lower
()
==
'stb'
:
tdSql
.
query
(
f
'select timediff(ts,
{
self
.
subtractor
}
) from
{
self
.
stbname
}
'
)
def
check_tb_type
(
self
,
unit
,
tb_type
):
if
tb_type
.
lower
()
==
'ntb'
:
tdSql
.
query
(
f
'select timediff(ts,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
query
(
f
'select timediff(ts,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
ctbname
}
'
)
elif
tb_type
.
lower
()
==
'stb'
:
tdSql
.
query
(
f
'select timediff(ts,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
stbname
}
'
)
def
data_check
(
self
,
date_time
,
precision
,
tb_type
):
for
unit
in
self
.
time_unit
:
if
(
unit
.
lower
()
==
'1u'
and
precision
.
lower
()
==
'ms'
)
or
(
unit
.
lower
()
==
'1b'
and
precision
.
lower
()
==
'us'
)
or
(
unit
.
lower
()
==
'1b'
and
precision
.
lower
()
==
'ms'
):
if
tb_type
.
lower
()
==
'ntb'
:
tdSql
.
error
(
f
'select timediff(ts,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
error
(
f
'select timediff(ts,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
ctbname
}
'
)
elif
tb_type
.
lower
()
==
'stb'
:
tdSql
.
error
(
f
'select timediff(ts,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
stbname
}
'
)
elif
precision
.
lower
()
==
'ms'
:
self
.
check_tb_type
(
unit
,
tb_type
)
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
if
unit
.
lower
()
==
'1a'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
])
-
self
.
subtractor
*
1000
)
elif
unit
.
lower
()
==
'1s'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
/
1000
)
-
self
.
subtractor
)
elif
unit
.
lower
()
==
'1m'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000
)
-
self
.
subtractor
)
/
60
))
elif
unit
.
lower
()
==
'1h'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000
)
-
self
.
subtractor
)
/
60
/
60
))
elif
unit
.
lower
()
==
'1d'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000
)
-
self
.
subtractor
)
/
60
/
60
/
24
))
elif
unit
.
lower
()
==
'1w'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000
)
-
self
.
subtractor
)
/
60
/
60
/
24
/
7
))
self
.
check_tbtype
(
tb_type
)
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
])
-
self
.
subtractor
*
1000
)
elif
precision
.
lower
()
==
'us'
:
self
.
check_tb_type
(
unit
,
tb_type
)
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
if
unit
.
lower
()
==
'1w'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000000
)
-
self
.
subtractor
)
/
60
/
60
/
24
/
7
))
elif
unit
.
lower
()
==
'1d'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000000
)
-
self
.
subtractor
)
/
60
/
60
/
24
))
elif
unit
.
lower
()
==
'1h'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000000
)
-
self
.
subtractor
)
/
60
/
60
))
elif
unit
.
lower
()
==
'1m'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000000
)
-
self
.
subtractor
)
/
60
))
elif
unit
.
lower
()
==
'1s'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000000
)
-
self
.
subtractor
)))
elif
unit
.
lower
()
==
'1a'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000
)
-
self
.
subtractor
*
1000
)))
elif
unit
.
lower
()
==
'1u'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
])
-
self
.
subtractor
*
1000000
)))
self
.
check_tbtype
(
tb_type
)
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
])
-
self
.
subtractor
*
1000000
)))
elif
precision
.
lower
()
==
'ns'
:
self
.
check_tb_type
(
unit
,
tb_type
)
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
if
unit
.
lower
()
==
'1w'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000000000
)
-
self
.
subtractor
)
/
60
/
60
/
24
/
7
))
elif
unit
.
lower
()
==
'1d'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000000000
)
-
self
.
subtractor
)
/
60
/
60
/
24
))
elif
unit
.
lower
()
==
'1h'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000000000
)
-
self
.
subtractor
)
/
60
/
60
))
elif
unit
.
lower
()
==
'1m'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000000000
)
-
self
.
subtractor
)
/
60
))
elif
unit
.
lower
()
==
'1s'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000000000
)
-
self
.
subtractor
)))
elif
unit
.
lower
()
==
'1a'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000000
)
-
self
.
subtractor
*
1000
)))
elif
unit
.
lower
()
==
'1u'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(((
date_time
[
i
]
/
1000
)
-
self
.
subtractor
*
1000000
)))
# self.check_tbtype(tb_type)
# tdSql.checkRows(len(self.ts_str))
# for i in range(len(self.ts_str)):
# tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i]/1000000)-self.subtractor*1000000000)))
for
unit
in
self
.
error_unit
:
if
tb_type
.
lower
()
==
'ntb'
:
tdSql
.
error
(
f
'select timediff(ts,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
ntbname
}
'
)
tdSql
.
error
(
f
'select timediff(c0,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
error
(
f
'select timediff(ts,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
ctbname
}
'
)
tdSql
.
error
(
f
'select timediff(c0,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'stb'
:
tdSql
.
error
(
f
'select timediff(ts,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
stbname
}
'
)
tdSql
.
error
(
f
'select timediff(c0,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
ntbname
}
'
)
def
function_check_ntb
(
self
):
for
precision
in
self
.
db_param_precision
:
tdSql
.
execute
(
'drop database if exists db'
)
tdSql
.
execute
(
f
'create database db precision "
{
precision
}
"'
)
tdSql
.
execute
(
'use db'
)
tdSql
.
execute
(
f
'create table
{
self
.
ntbname
}
(ts timestamp,c0 int)'
)
for
ts
in
self
.
ts_str
:
tdSql
.
execute
(
f
'insert into
{
self
.
ntbname
}
values("
{
ts
}
",1)'
)
for
unit
in
self
.
error_unit
:
tdSql
.
error
(
f
'select timediff(ts,
{
self
.
subtractor
}
,
{
unit
}
) from
{
self
.
ntbname
}
'
)
date_time
=
self
.
get_time
.
time_transform
(
self
.
ts_str
,
precision
)
self
.
data_check
(
date_time
,
precision
,
'ntb'
)
def
function_check_stb
(
self
):
for
precision
in
self
.
db_param_precision
:
tdSql
.
execute
(
'drop database if exists db'
)
tdSql
.
execute
(
f
'create database db precision "
{
precision
}
"'
)
tdSql
.
execute
(
'use db'
)
tdSql
.
execute
(
f
'create table
{
self
.
stbname
}
(ts timestamp,c0 int) tags(t0 int)'
)
tdSql
.
execute
(
f
'create table
{
self
.
ctbname
}
using
{
self
.
stbname
}
tags(1)'
)
for
ts
in
self
.
ts_str
:
tdSql
.
execute
(
f
'insert into
{
self
.
ctbname
}
values("
{
ts
}
",1)'
)
date_time
=
self
.
get_time
.
time_transform
(
self
.
ts_str
,
precision
)
self
.
data_check
(
date_time
,
precision
,
'ctb'
)
self
.
data_check
(
date_time
,
precision
,
'stb'
)
def
run
(
self
):
# sourcery skip: extract-duplicate-method
def
run
(
self
):
# sourcery skip: extract-duplicate-method
tdSql
.
prepare
()
tdLog
.
printNoPrefix
(
"==========step1:create tables=========="
)
tdSql
.
execute
(
'''create table if not exists ntb
(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp)
'''
)
tdSql
.
execute
(
'''create table if not exists stb
(ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int)
'''
)
tdSql
.
execute
(
'''create table if not exists stb_1 using stb tags(100)
'''
)
tdLog
.
printNoPrefix
(
"==========step2:insert data into ntb=========="
)
# RFC3339:2020-01-01T00:00:00+8:00
# ISO8601:2020-01-01T00:00:00.000+0800
tdSql
.
execute
(
'insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())'
)
tdSql
.
execute
(
'insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())'
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00') from ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select timediff(1,0,1d) from ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff(1,0,1d) from db.ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff(1,0,1s) from ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
1
)
tdSql
.
query
(
"select timediff(1,0,1s) from db.ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
1
)
tdSql
.
query
(
"select timediff(1,0,1w) from ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff(1,0,1w) from db.ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff(1,0,1h) from ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff(1,0,1h) from db.ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff(1,0,1m) from ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff(1,0,1m) from db.ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff(1,0,1a) from ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
1000
)
tdSql
.
query
(
"select timediff(1,0,1a) from db.ntb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
1000
)
tdSql
.
error
(
"select timediff(1,0,1u) from ntb"
)
#tdSql.checkRows(3)
#tdSql.checkData(0,0,1000000)
tdSql
.
error
(
"select timediff(1,0,1u) from db.ntb"
)
#tdSql.checkRows(3)
#tdSql.checkData(0,0,1000000)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00') from stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00') from db.stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1d) from stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
1
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1d) from db.stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
1
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1h) from stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
24
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1h) from db.stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
24
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1w) from stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1m) from stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
1440
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1m) from db.stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
1440
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1s) from stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
86400
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1s) from db.stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
86400
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1a) from stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
86400000
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1a) from db.stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
86400000
)
tdSql
.
error
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1u) from stb"
)
#tdSql.checkRows(3)
#tdSql.checkData(0,0,86400000000)
tdSql
.
error
(
"select timediff('2020-1-1 00:00:00','2020-1-2 00:00:00',1u) from db.stb"
)
#tdSql.checkRows(3)
#tdSql.checkData(0,0,86400000000)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00') from stb_1"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00') from db.stb_1"
)
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1w) from stb_1 "
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1w) from db.stb_1 "
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1d) from stb_1 "
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1d) from db.stb_1 "
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1h) from stb_1 "
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
12
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1h) from db.stb_1 "
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
12
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1m) from stb_1"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
720
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1m) from db.stb_1"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
720
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1s) from stb_1"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
43200
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1s) from db.stb_1"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
43200
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1a) from stb_1"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
43200000
)
tdSql
.
query
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1a) from db.stb_1"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
43200000
)
tdSql
.
error
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1u) from stb_1"
)
#tdSql.checkRows(3)
#tdSql.checkData(0,0,43200000000)
tdSql
.
error
(
"select timediff('2020-1-1 00:00:00','2020-1-1 12:00:00',1u) from db.stb_1"
)
#tdSql.checkRows(3)
#tdSql.checkData(0,0,43200000000)
tdSql
.
query
(
"select timediff('a','b') from stb"
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
None
)
tdSql
.
checkData
(
1
,
0
,
None
)
tdSql
.
checkData
(
2
,
0
,
None
)
tdSql
.
error
(
"select timediff(1.5,1.5) from stb"
)
tdSql
.
error
(
"select timediff(1) from stb"
)
tdSql
.
error
(
"select timediff(10,1,1.5) from stb"
)
# tdSql.error("select timediff(10,1,2s) from stb")
# tdSql.error("select timedifff(10,1,c1) from stb")
tdSql
.
error
(
"select timediff(1.5,1.5) from stb_1"
)
tdSql
.
error
(
"select timediff(1) from stb_1"
)
tdSql
.
error
(
"select timediff(10,1,1.5) from stb_1"
)
# tdSql.error("select timediff(10,1,2s) from stb_1")
# tdSql.error("select timedifff(10,1,c1) from stb_1")
tdSql
.
error
(
"select timediff(1.5,1.5) from ntb"
)
tdSql
.
error
(
"select timediff(1) from ntb"
)
tdSql
.
error
(
"select timediff(10,1,1.5) from ntb"
)
# tdSql.error("select timediff(10,1,2s) from ntb")
# tdSql.error("select timedifff(10,1,c1) from ntb")
self
.
function_check_ntb
()
self
.
function_check_stb
()
def
stop
(
self
):
def
stop
(
self
):
tdSql
.
close
()
tdSql
.
close
()
...
...
tests/system-test/2-query/distribute_agg_stddev.py
浏览文件 @
4fb1ef08
tests/system-test/2-query/timetruncate.py
浏览文件 @
4fb1ef08
...
@@ -5,152 +5,115 @@ from util.sql import *
...
@@ -5,152 +5,115 @@ from util.sql import *
import
numpy
as
np
import
numpy
as
np
import
time
import
time
from
datetime
import
datetime
from
datetime
import
datetime
from
util.gettime
import
*
class
TDTestCase
:
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
())
tdSql
.
init
(
conn
.
cursor
())
self
.
get_time
=
GetTime
()
self
.
rowNum
=
10
self
.
ts
=
1537146000000
# 2018-9-17 09:00:00.000
self
.
ts_str
=
[
self
.
ts_str
=
[
'2020-1-1'
,
'2020-1-1'
,
'2020-2-1 00:00:01'
,
'2020-2-1 00:00:01'
,
'2020-3-1 00:00:00.001'
,
'2020-3-1 00:00:00.001'
,
'2020-4-1 00:00:00.001002'
,
'2020-4-1 00:00:00.001002'
,
'2020-5-1 00:00:00.001002001'
'2020-5-1 00:00:00.001002001'
]
]
self
.
db_param_precision
=
[
'ms'
,
'us'
,
'ns'
]
self
.
db_param_precision
=
[
'ms'
,
'us'
,
'ns'
]
self
.
time_unit
=
[
'1w'
,
'1d'
,
'1h'
,
'1m'
,
'1s'
,
'1a'
,
'1u'
]
self
.
time_unit
=
[
'1w'
,
'1d'
,
'1h'
,
'1m'
,
'1s'
,
'1a'
,
'1u'
,
'1b'
]
self
.
error_unit
=
[
'1b'
,
'2w'
,
'2d'
,
'2h'
,
'2m'
,
'2s'
,
'2a'
,
'2u'
,
'1c'
,
'#1'
]
self
.
error_unit
=
[
'2w'
,
'2d'
,
'2h'
,
'2m'
,
'2s'
,
'2a'
,
'2u'
,
'1c'
,
'#1'
]
self
.
error_unit
=
[
'2w'
,
'2d'
,
'2h'
,
'2m'
,
'2s'
,
'2a'
,
'2u'
,
'1c'
,
'#1'
]
self
.
ntbname
=
'ntb'
self
.
ntbname
=
'ntb'
self
.
stbname
=
'stb'
self
.
stbname
=
'stb'
self
.
ctbname
=
'ctb'
self
.
ctbname
=
'ctb'
def
get_ms_timestamp
(
self
,
ts_str
):
_ts_str
=
ts_str
if
" "
in
ts_str
:
p
=
ts_str
.
split
(
" "
)[
1
]
if
len
(
p
)
>
15
:
_ts_str
=
ts_str
[:
-
3
]
if
':'
in
_ts_str
and
'.'
in
_ts_str
:
timestamp
=
datetime
.
strptime
(
_ts_str
,
"%Y-%m-%d %H:%M:%S.%f"
)
date_time
=
int
(
int
(
time
.
mktime
(
timestamp
.
timetuple
()))
*
1000
+
timestamp
.
microsecond
/
1000
)
elif
':'
in
_ts_str
and
'.'
not
in
_ts_str
:
timestamp
=
datetime
.
strptime
(
_ts_str
,
"%Y-%m-%d %H:%M:%S"
)
date_time
=
int
(
int
(
time
.
mktime
(
timestamp
.
timetuple
()))
*
1000
+
timestamp
.
microsecond
/
1000
)
else
:
timestamp
=
datetime
.
strptime
(
_ts_str
,
"%Y-%m-%d"
)
date_time
=
int
(
int
(
time
.
mktime
(
timestamp
.
timetuple
()))
*
1000
+
timestamp
.
microsecond
/
1000
)
return
date_time
def
get_us_timestamp
(
self
,
ts_str
):
_ts
=
self
.
get_ms_timestamp
(
ts_str
)
*
1000
if
" "
in
ts_str
:
p
=
ts_str
.
split
(
" "
)[
1
]
if
len
(
p
)
>
12
:
us_ts
=
p
[
12
:
15
]
_ts
+=
int
(
us_ts
)
return
_ts
def
get_ns_timestamp
(
self
,
ts_str
):
_ts
=
self
.
get_us_timestamp
(
ts_str
)
*
1000
if
" "
in
ts_str
:
p
=
ts_str
.
split
(
" "
)[
1
]
if
len
(
p
)
>
15
:
us_ts
=
p
[
15
:]
_ts
+=
int
(
us_ts
)
return
_ts
def
time_transform
(
self
,
ts_str
,
precision
):
date_time
=
[]
if
precision
==
'ms'
:
for
i
in
ts_str
:
date_time
.
append
(
self
.
get_ms_timestamp
(
i
))
elif
precision
==
'us'
:
for
i
in
ts_str
:
date_time
.
append
(
self
.
get_us_timestamp
(
i
))
elif
precision
==
'ns'
:
for
i
in
ts_str
:
date_time
.
append
(
self
.
get_us_timestamp
(
i
))
return
date_time
def
check_ms_timestamp
(
self
,
unit
,
date_time
):
def
check_ms_timestamp
(
self
,
unit
,
date_time
):
if
unit
.
lower
()
==
'1a'
:
if
unit
.
lower
()
==
'1a'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]))
elif
unit
.
lower
()
==
'1s'
:
elif
unit
.
lower
()
==
'1s'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
)
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
)
*
1000
)
elif
unit
.
lower
()
==
'1m'
:
elif
unit
.
lower
()
==
'1m'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
60
)
*
60
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
60
)
*
60
*
1000
)
elif
unit
.
lower
()
==
'1h'
:
elif
unit
.
lower
()
==
'1h'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
60
/
60
)
*
60
*
60
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
60
/
60
)
*
60
*
60
*
1000
)
elif
unit
.
lower
()
==
'1d'
:
elif
unit
.
lower
()
==
'1d'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
)
elif
unit
.
lower
()
==
'1w'
:
elif
unit
.
lower
()
==
'1w'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
ms_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
60
/
60
/
24
/
7
)
*
7
*
24
*
60
*
60
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
60
/
60
/
24
/
7
)
*
7
*
24
*
60
*
60
*
1000
)
def
check_us_timestamp
(
self
,
unit
,
date_time
):
def
check_us_timestamp
(
self
,
unit
,
date_time
):
if
unit
.
lower
()
==
'1u'
:
if
unit
.
lower
()
==
'1u'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]))
elif
unit
.
lower
()
==
'1a'
:
elif
unit
.
lower
()
==
'1a'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
)
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
)
*
1000
)
elif
unit
.
lower
()
==
'1s'
:
elif
unit
.
lower
()
==
'1s'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
)
*
1000
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
)
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1m'
:
elif
unit
.
lower
()
==
'1m'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
/
60
)
*
60
*
1000
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
/
60
)
*
60
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1h'
:
elif
unit
.
lower
()
==
'1h'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
/
60
/
60
)
*
60
*
60
*
1000
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
/
60
/
60
)
*
60
*
60
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1d'
:
elif
unit
.
lower
()
==
'1d'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1w'
:
elif
unit
.
lower
()
==
'1w'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
ts_result
=
self
.
get_us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
ts_result
=
self
.
get_
time
.
get_
us_timestamp
(
str
(
tdSql
.
queryResult
[
i
][
0
]))
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
/
60
/
60
/
24
/
7
)
*
7
*
24
*
60
*
60
*
1000
*
1000
)
tdSql
.
checkEqual
(
ts_result
,
int
(
date_time
[
i
]
/
1000
/
1000
/
60
/
60
/
24
/
7
)
*
7
*
24
*
60
*
60
*
1000
*
1000
)
def
check_ns_timestamp
(
self
,
unit
,
date_time
):
def
check_ns_timestamp
(
self
,
unit
,
date_time
):
if
unit
.
lower
()
==
'1u'
:
if
unit
.
lower
()
==
'1b'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]))
elif
unit
.
lower
()
==
'1u'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
)
*
1000
)
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
)
*
1000
)
elif
unit
.
lower
()
==
'1a'
:
elif
unit
.
lower
()
==
'1a'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
)
*
1000
*
1000
)
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
)
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1s'
:
elif
unit
.
lower
()
==
'1s'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
)
*
1000
*
1000
*
1000
)
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
1000
)
*
1000
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1m'
:
elif
unit
.
lower
()
==
'1m'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
60
)
*
60
*
1000
*
1000
*
1000
)
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
1000
/
60
)
*
60
*
1000
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1h'
:
elif
unit
.
lower
()
==
'1h'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
60
/
60
)
*
60
*
60
*
1000
*
1000
*
1000
)
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
1000
/
60
/
60
)
*
60
*
60
*
1000
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1d'
:
elif
unit
.
lower
()
==
'1d'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
*
1000
*
1000
)
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
1000
/
60
/
60
/
24
)
*
24
*
60
*
60
*
1000
*
1000
*
1000
)
elif
unit
.
lower
()
==
'1w'
:
elif
unit
.
lower
()
==
'1w'
:
for
i
in
range
(
len
(
self
.
ts_str
)):
for
i
in
range
(
len
(
self
.
ts_str
)):
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
60
/
60
/
24
/
7
)
*
7
*
24
*
60
*
60
*
1000
*
1000
*
1000
)
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
i
][
0
],
int
(
date_time
[
i
]
*
1000
/
1000
/
1000
/
1000
/
1000
/
60
/
60
/
24
/
7
)
*
7
*
24
*
60
*
60
*
1000
*
1000
*
1000
)
def
check_tb_type
(
self
,
unit
,
tb_type
):
if
tb_type
.
lower
()
==
'ntb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ctbname
}
'
)
elif
tb_type
.
lower
()
==
'stb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
stbname
}
'
)
def
data_check
(
self
,
date_time
,
precision
,
tb_type
):
def
data_check
(
self
,
date_time
,
precision
,
tb_type
):
for
unit
in
self
.
time_unit
:
for
unit
in
self
.
time_unit
:
if
(
unit
.
lower
()
==
'1u'
and
precision
.
lower
()
==
'ms'
)
or
(
)
:
if
(
unit
.
lower
()
==
'1u'
and
precision
.
lower
()
==
'ms'
)
or
(
unit
.
lower
()
==
'1b'
and
precision
.
lower
()
==
'us'
)
or
(
unit
.
lower
()
==
'1b'
and
precision
.
lower
()
==
'ms'
)
:
if
tb_type
.
lower
()
==
'ntb'
:
if
tb_type
.
lower
()
==
'ntb'
:
tdSql
.
error
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ntbname
}
'
)
tdSql
.
error
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
elif
tb_type
.
lower
()
==
'ctb'
:
...
@@ -158,30 +121,15 @@ class TDTestCase:
...
@@ -158,30 +121,15 @@ class TDTestCase:
elif
tb_type
.
lower
()
==
'stb'
:
elif
tb_type
.
lower
()
==
'stb'
:
tdSql
.
error
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
stbname
}
'
)
tdSql
.
error
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
stbname
}
'
)
elif
precision
.
lower
()
==
'ms'
:
elif
precision
.
lower
()
==
'ms'
:
if
tb_type
.
lower
()
==
'ntb'
:
self
.
check_tb_type
(
unit
,
tb_type
)
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ctbname
}
'
)
elif
tb_type
.
lower
()
==
'stb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
stbname
}
'
)
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
self
.
check_ms_timestamp
(
unit
,
date_time
)
self
.
check_ms_timestamp
(
unit
,
date_time
)
elif
precision
.
lower
()
==
'us'
:
elif
precision
.
lower
()
==
'us'
:
if
tb_type
.
lower
()
==
'ntb'
:
self
.
check_tb_type
(
unit
,
tb_type
)
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ctbname
}
'
)
elif
tb_type
.
lower
()
==
'stb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
stbname
}
'
)
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
self
.
check_us_timestamp
(
unit
,
date_time
)
self
.
check_us_timestamp
(
unit
,
date_time
)
elif
precision
.
lower
()
==
'ns'
:
elif
precision
.
lower
()
==
'ns'
:
if
tb_type
.
lower
()
==
'ntb'
:
self
.
check_tb_type
(
unit
,
tb_type
)
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ntbname
}
'
)
elif
tb_type
.
lower
()
==
'ctb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
ctbname
}
'
)
elif
tb_type
.
lower
()
==
'stb'
:
tdSql
.
query
(
f
'select timetruncate(ts,
{
unit
}
) from
{
self
.
stbname
}
'
)
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
tdSql
.
checkRows
(
len
(
self
.
ts_str
))
self
.
check_ns_timestamp
(
unit
,
date_time
)
self
.
check_ns_timestamp
(
unit
,
date_time
)
for
unit
in
self
.
error_unit
:
for
unit
in
self
.
error_unit
:
...
@@ -199,9 +147,8 @@ class TDTestCase:
...
@@ -199,9 +147,8 @@ class TDTestCase:
tdSql
.
execute
(
f
'create table
{
self
.
ntbname
}
(ts timestamp,c0 int)'
)
tdSql
.
execute
(
f
'create table
{
self
.
ntbname
}
(ts timestamp,c0 int)'
)
for
ts
in
self
.
ts_str
:
for
ts
in
self
.
ts_str
:
tdSql
.
execute
(
f
'insert into
{
self
.
ntbname
}
values("
{
ts
}
",1)'
)
tdSql
.
execute
(
f
'insert into
{
self
.
ntbname
}
values("
{
ts
}
",1)'
)
date_time
=
self
.
time_transform
(
self
.
ts_str
,
precision
)
date_time
=
self
.
get_time
.
time_transform
(
self
.
ts_str
,
precision
)
self
.
data_check
(
date_time
,
precision
,
'ntb'
)
self
.
data_check
(
date_time
,
precision
,
'ntb'
)
def
function_check_stb
(
self
):
def
function_check_stb
(
self
):
for
precision
in
self
.
db_param_precision
:
for
precision
in
self
.
db_param_precision
:
tdSql
.
execute
(
'drop database if exists db'
)
tdSql
.
execute
(
'drop database if exists db'
)
...
@@ -211,7 +158,7 @@ class TDTestCase:
...
@@ -211,7 +158,7 @@ class TDTestCase:
tdSql
.
execute
(
f
'create table
{
self
.
ctbname
}
using
{
self
.
stbname
}
tags(1)'
)
tdSql
.
execute
(
f
'create table
{
self
.
ctbname
}
using
{
self
.
stbname
}
tags(1)'
)
for
ts
in
self
.
ts_str
:
for
ts
in
self
.
ts_str
:
tdSql
.
execute
(
f
'insert into
{
self
.
ctbname
}
values("
{
ts
}
",1)'
)
tdSql
.
execute
(
f
'insert into
{
self
.
ctbname
}
values("
{
ts
}
",1)'
)
date_time
=
self
.
time_transform
(
self
.
ts_str
,
precision
)
date_time
=
self
.
get_time
.
time_transform
(
self
.
ts_str
,
precision
)
self
.
data_check
(
date_time
,
precision
,
'ctb'
)
self
.
data_check
(
date_time
,
precision
,
'ctb'
)
self
.
data_check
(
date_time
,
precision
,
'stb'
)
self
.
data_check
(
date_time
,
precision
,
'stb'
)
def
run
(
self
):
def
run
(
self
):
...
...
tests/system-test/fulltest.sh
浏览文件 @
4fb1ef08
...
@@ -21,7 +21,7 @@ python3 ./test.py -f 1-insert/opentsdb_json_taosc_insert.py
...
@@ -21,7 +21,7 @@ python3 ./test.py -f 1-insert/opentsdb_json_taosc_insert.py
python3 ./test.py
-f
1-insert/test_stmt_muti_insert_query.py
python3 ./test.py
-f
1-insert/test_stmt_muti_insert_query.py
python3 ./test.py
-f
1-insert/test_stmt_set_tbname_tag.py
python3 ./test.py
-f
1-insert/test_stmt_set_tbname_tag.py
python3 ./test.py
-f
1-insert/alter_stable.py
python3 ./test.py
-f
1-insert/alter_stable.py
python3 ./test.py
-f
1-insert/alter_table.py
#
python3 ./test.py -f 1-insert/alter_table.py
python3 ./test.py
-f
1-insert/insertWithMoreVgroup.py
python3 ./test.py
-f
1-insert/insertWithMoreVgroup.py
python3 ./test.py
-f
1-insert/table_comment.py
python3 ./test.py
-f
1-insert/table_comment.py
python3 ./test.py
-f
1-insert/time_range_wise.py
python3 ./test.py
-f
1-insert/time_range_wise.py
...
@@ -118,7 +118,7 @@ python3 ./test.py -f 2-query/twa.py
...
@@ -118,7 +118,7 @@ python3 ./test.py -f 2-query/twa.py
python3 ./test.py
-f
2-query/irate.py
python3 ./test.py
-f
2-query/irate.py
python3 ./test.py
-f
2-query/function_null.py
python3 ./test.py
-f
2-query/function_null.py
python3 ./test.py
-f
2-query/queryQnode.py
#
python3 ./test.py -f 2-query/queryQnode.py
#python3 ./test.py -f 6-cluster/5dnode1mnode.py
#python3 ./test.py -f 6-cluster/5dnode1mnode.py
#python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5 -M 3
#python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5 -M 3
...
...
tests/system-test/simpletest.bat
浏览文件 @
4fb1ef08
...
@@ -6,7 +6,7 @@ python3 .\test.py -f 0-others\telemetry.py
...
@@ -6,7 +6,7 @@ python3 .\test.py -f 0-others\telemetry.py
python3
.\test.py
-f
0
-others
\taosdMonitor.py
python3
.\test.py
-f
0
-others
\taosdMonitor.py
python3
.\test.py
-f
0
-others
\udfTest.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_create.py
python3
.\test.py
-f
0
-others
\udf_restart_taosd.py
@REM
python3 .\test.py -f 0-others\udf_restart_taosd.py
@REM python3 .\test.py -f 0-others\cachelast.py
@REM python3 .\test.py -f 0-others\cachelast.py
@REM python3 .\test.py -f 0-others\user_control.py
@REM python3 .\test.py -f 0-others\user_control.py
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录