Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ca7057ce
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
ca7057ce
编写于
6月 20, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/3.0' into fix/mnode
上级
96434756
e05a6ca7
变更
45
展开全部
隐藏空白更改
内联
并排
Showing
45 changed file
with
1122 addition
and
759 deletion
+1122
-759
examples/c/stream_demo.c
examples/c/stream_demo.c
+3
-10
include/common/tmsgcb.h
include/common/tmsgcb.h
+0
-1
include/dnode/snode/snode.h
include/dnode/snode/snode.h
+3
-3
include/libs/planner/planner.h
include/libs/planner/planner.h
+0
-1
include/libs/stream/tstream.h
include/libs/stream/tstream.h
+3
-2
source/dnode/mgmt/mgmt_snode/src/smHandle.c
source/dnode/mgmt/mgmt_snode/src/smHandle.c
+3
-0
source/dnode/mgmt/mgmt_snode/src/smWorker.c
source/dnode/mgmt/mgmt_snode/src/smWorker.c
+6
-2
source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
+0
-9
source/dnode/mnode/impl/src/mndScheduler.c
source/dnode/mnode/impl/src/mndScheduler.c
+5
-4
source/dnode/mnode/impl/src/mndStb.c
source/dnode/mnode/impl/src/mndStb.c
+2
-2
source/dnode/snode/inc/sndInt.h
source/dnode/snode/inc/sndInt.h
+0
-1
source/dnode/snode/src/snode.c
source/dnode/snode/src/snode.c
+144
-31
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+1
-1
source/dnode/vnode/src/inc/sma.h
source/dnode/vnode/src/inc/sma.h
+6
-5
source/dnode/vnode/src/inc/vnodeInt.h
source/dnode/vnode/src/inc/vnodeInt.h
+1
-1
source/dnode/vnode/src/sma/sma.c
source/dnode/vnode/src/sma/sma.c
+5
-0
source/dnode/vnode/src/sma/smaEnv.c
source/dnode/vnode/src/sma/smaEnv.c
+31
-1
source/dnode/vnode/src/sma/smaRollup.c
source/dnode/vnode/src/sma/smaRollup.c
+157
-59
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+28
-24
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+2
-2
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+4
-1
source/libs/command/src/explain.c
source/libs/command/src/explain.c
+43
-12
source/libs/executor/inc/executil.h
source/libs/executor/inc/executil.h
+1
-1
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+4
-1
source/libs/executor/src/dataDispatcher.c
source/libs/executor/src/dataDispatcher.c
+9
-3
source/libs/executor/src/executil.c
source/libs/executor/src/executil.c
+15
-7
source/libs/executor/src/executor.c
source/libs/executor/src/executor.c
+7
-1
source/libs/executor/src/executorMain.c
source/libs/executor/src/executorMain.c
+40
-43
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+113
-66
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+151
-117
source/libs/function/inc/builtinsimpl.h
source/libs/function/inc/builtinsimpl.h
+2
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+11
-110
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+65
-116
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+5
-0
source/libs/parser/src/parAstParser.c
source/libs/parser/src/parAstParser.c
+20
-0
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+77
-1
source/libs/planner/src/planUtil.c
source/libs/planner/src/planUtil.c
+1
-0
source/libs/planner/test/planOptimizeTest.cpp
source/libs/planner/test/planOptimizeTest.cpp
+10
-0
source/libs/qworker/src/qworker.c
source/libs/qworker/src/qworker.c
+1
-1
source/libs/stream/src/streamTask.c
source/libs/stream/src/streamTask.c
+2
-2
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+3
-3
tests/script/tsim/sma/rsmaCreateInsertQuery.sim
tests/script/tsim/sma/rsmaCreateInsertQuery.sim
+3
-1
tests/system-test/1-insert/create_table_comment.py
tests/system-test/1-insert/create_table_comment.py
+0
-113
tests/system-test/1-insert/table_comment.py
tests/system-test/1-insert/table_comment.py
+134
-0
tests/system-test/fulltest.sh
tests/system-test/fulltest.sh
+1
-1
未找到文件。
examples/c/stream_demo.c
浏览文件 @
ca7057ce
...
...
@@ -88,9 +88,9 @@ int32_t create_stream() {
/*const char* sql = "select min(k), max(k), sum(k) as sum_of_k from st1";*/
/*const char* sql = "select sum(k) from tu1 interval(10m)";*/
/*pRes = tmq_create_stream(pConn, "stream1", "out1", sql);*/
pRes
=
taos_query
(
pConn
,
"create stream stream1 trigger at_once into abc2.outstb as select _wstartts, sum(k) from st1 "
"partition by tbname
interval(10m) "
);
pRes
=
taos_query
(
pConn
,
"create stream stream1 trigger at_once into abc1.outstb as select _wstartts, sum(k) from st1
interval(10m) "
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"failed to create stream stream1, reason:%s
\n
"
,
taos_errstr
(
pRes
));
return
-
1
;
...
...
@@ -107,11 +107,4 @@ int main(int argc, char* argv[]) {
code
=
init_env
();
}
create_stream
();
#if 0
tmq_t* tmq = build_consumer();
tmq_list_t* topic_list = build_topic_list();
/*perf_loop(tmq, topic_list);*/
/*basic_consume_loop(tmq, topic_list);*/
sync_consume_loop(tmq, topic_list);
#endif
}
include/common/tmsgcb.h
浏览文件 @
ca7057ce
...
...
@@ -34,7 +34,6 @@ typedef enum {
WRITE_QUEUE
,
APPLY_QUEUE
,
SYNC_QUEUE
,
MERGE_QUEUE
,
QUEUE_MAX
,
}
EQueueType
;
...
...
include/dnode/snode/snode.h
浏览文件 @
ca7057ce
...
...
@@ -16,8 +16,8 @@
#ifndef _TD_SNODE_H_
#define _TD_SNODE_H_
#include "tmsgcb.h"
#include "tmsg.h"
#include "tmsgcb.h"
#include "trpc.h"
#ifdef __cplusplus
...
...
@@ -68,8 +68,8 @@ int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad);
* @param pMsg The request message
* @param pRsp The response message
*/
void
sndProcessUMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
);
void
sndProcessSMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
);
int32_t
sndProcessUMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
);
int32_t
sndProcessSMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
);
#ifdef __cplusplus
}
...
...
include/libs/planner/planner.h
浏览文件 @
ca7057ce
...
...
@@ -36,7 +36,6 @@ typedef struct SPlanContext {
int64_t
watermark
;
char
*
pMsg
;
int32_t
msgLen
;
// double filesFactor;
}
SPlanContext
;
// Create the physical plan for the query, according to the AST.
...
...
include/libs/stream/tstream.h
浏览文件 @
ca7057ce
...
...
@@ -152,7 +152,7 @@ void* streamDataBlockDecode(const void* buf, SStreamDataBlock* pInput);
typedef
struct
{
char
*
qmsg
;
// followings are not applicable to encoder and decoder
void
*
inputHandle
;
//
void* inputHandle;
void
*
executor
;
}
STaskExec
;
...
...
@@ -240,12 +240,13 @@ struct SStreamTask {
int8_t
inputType
;
int8_t
status
;
int8_t
sourceType
;
int8_t
execType
;
int8_t
sinkType
;
int8_t
dispatchType
;
int16_t
dispatchMsgType
;
int8_t
dataScan
;
// node info
int32_t
childId
;
int32_t
nodeId
;
...
...
source/dnode/mgmt/mgmt_snode/src/smHandle.c
浏览文件 @
ca7057ce
...
...
@@ -95,9 +95,12 @@ SArray *smGetMsgHandles() {
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_MON_SM_INFO
,
smPutNodeMsgToMonitorQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_TASK_DEPLOY
,
smPutNodeMsgToMgmtQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_VND_STREAM_TASK_DROP
,
smPutNodeMsgToMgmtQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_TASK_RUN
,
smPutNodeMsgToMgmtQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_TASK_DISPATCH
,
smPutNodeMsgToMgmtQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_TASK_DISPATCH_RSP
,
smPutNodeMsgToMgmtQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_TASK_RECOVER
,
smPutNodeMsgToMgmtQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_STREAM_TASK_RECOVER_RSP
,
smPutNodeMsgToMgmtQueue
,
1
)
==
NULL
)
goto
_OVER
;
code
=
0
;
_OVER:
...
...
source/dnode/mgmt/mgmt_snode/src/smWorker.c
浏览文件 @
ca7057ce
...
...
@@ -55,7 +55,9 @@ static void smProcessUniqueQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t num
taosGetQitem
(
qall
,
(
void
**
)
&
pMsg
);
dTrace
(
"msg:%p, get from snode-unique queue"
,
pMsg
);
sndProcessUMsg
(
pMgmt
->
pSnode
,
pMsg
);
if
(
sndProcessUMsg
(
pMgmt
->
pSnode
,
pMsg
)
<
0
)
{
ASSERT
(
0
);
}
dTrace
(
"msg:%p, is freed"
,
pMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
...
...
@@ -67,7 +69,9 @@ static void smProcessSharedQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
SSnodeMgmt
*
pMgmt
=
pInfo
->
ahandle
;
dTrace
(
"msg:%p, get from snode-shared queue"
,
pMsg
);
sndProcessSMsg
(
pMgmt
->
pSnode
,
pMsg
);
if
(
sndProcessSMsg
(
pMgmt
->
pSnode
,
pMsg
)
<
0
)
{
ASSERT
(
0
);
}
dTrace
(
"msg:%p, is freed"
,
pMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
...
...
source/dnode/mgmt/mgmt_vnode/src/vmWorker.c
浏览文件 @
ca7057ce
...
...
@@ -170,10 +170,6 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
dTrace
(
"vgId:%d, msg:%p put into vnode-sync queue"
,
pVnode
->
vgId
,
pMsg
);
taosWriteQitem
(
pVnode
->
pSyncQ
,
pMsg
);
break
;
case
MERGE_QUEUE
:
dTrace
(
"vgId:%d, msg:%p put into vnode-merge queue"
,
pVnode
->
vgId
,
pMsg
);
taosWriteQitem
(
pVnode
->
pMergeQ
,
pMsg
);
break
;
case
APPLY_QUEUE
:
dTrace
(
"vgId:%d, msg:%p put into vnode-apply queue"
,
pVnode
->
vgId
,
pMsg
);
taosWriteQitem
(
pVnode
->
pApplyQ
,
pMsg
);
...
...
@@ -196,8 +192,6 @@ int32_t vmPutMsgToQueryQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsg
int32_t
vmPutMsgToFetchQueue
(
SVnodeMgmt
*
pMgmt
,
SRpcMsg
*
pMsg
)
{
return
vmPutMsgToQueue
(
pMgmt
,
pMsg
,
FETCH_QUEUE
);
}
int32_t
vmPutMsgToMergeQueue
(
SVnodeMgmt
*
pMgmt
,
SRpcMsg
*
pMsg
)
{
return
vmPutMsgToQueue
(
pMgmt
,
pMsg
,
MERGE_QUEUE
);
}
int32_t
vmPutMsgToMgmtQueue
(
SVnodeMgmt
*
pMgmt
,
SRpcMsg
*
pMsg
)
{
dTrace
(
"msg:%p, put into vnode-mgmt queue"
,
pMsg
);
taosWriteQitem
(
pMgmt
->
mgmtWorker
.
queue
,
pMsg
);
...
...
@@ -243,9 +237,6 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
case
FETCH_QUEUE
:
size
=
taosQueueItemSize
(
pVnode
->
pFetchQ
);
break
;
case
MERGE_QUEUE
:
size
=
taosQueueItemSize
(
pVnode
->
pMergeQ
);
break
;
default:
break
;
}
...
...
source/dnode/mnode/impl/src/mndScheduler.c
浏览文件 @
ca7057ce
...
...
@@ -63,9 +63,8 @@ int32_t mndConvertRsmaTask(char** pDst, int32_t* pDstLen, const char* ast, int64
.
topicQuery
=
false
,
.
streamQuery
=
true
,
.
rSmaQuery
=
true
,
.
triggerType
=
STREAM_TRIGGER_AT_ONCE
,
.
triggerType
=
triggerType
,
.
watermark
=
watermark
,
/*.filesFactor = filesFactor,*/
};
if
(
qCreateQueryPlan
(
&
cxt
,
&
pPlan
,
NULL
)
<
0
)
{
...
...
@@ -270,7 +269,6 @@ int32_t mndAddShuffleSinkTasksToStream(SMnode* pMnode, STrans* pTrans, SStreamOb
pTask
->
epSet
=
mndGetVgroupEpset
(
pMnode
,
pVgroup
);
// source
pTask
->
sourceType
=
TASK_SOURCE__MERGE
;
pTask
->
inputType
=
TASK_INPUT_TYPE__DATA_BLOCK
;
// exec
...
...
@@ -316,7 +314,6 @@ int32_t mndAddFixedSinkTaskToStream(SMnode* pMnode, STrans* pTrans, SStreamObj*
#endif
pTask
->
epSet
=
mndGetVgroupEpset
(
pMnode
,
&
pStream
->
fixedSinkVg
);
// source
pTask
->
sourceType
=
TASK_SOURCE__MERGE
;
pTask
->
inputType
=
TASK_INPUT_TYPE__DATA_BLOCK
;
// exec
...
...
@@ -427,6 +424,8 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
SStreamTask
*
pTask
=
tNewSStreamTask
(
pStream
->
uid
);
mndAddTaskToTaskSet
(
taskSourceLevel
,
pTask
);
pTask
->
dataScan
=
1
;
// input
pTask
->
inputType
=
TASK_INPUT_TYPE__SUMBIT_BLOCK
;
...
...
@@ -470,6 +469,8 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
SStreamTask
*
pTask
=
tNewSStreamTask
(
pStream
->
uid
);
mndAddTaskToTaskSet
(
taskOneLevel
,
pTask
);
pTask
->
dataScan
=
1
;
// input
pTask
->
inputType
=
TASK_INPUT_TYPE__SUMBIT_BLOCK
;
...
...
source/dnode/mnode/impl/src/mndStb.c
浏览文件 @
ca7057ce
...
...
@@ -403,13 +403,13 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
req
.
pRSmaParam
.
delay
=
pStb
->
delay
;
if
(
pStb
->
ast1Len
>
0
)
{
if
(
mndConvertRsmaTask
(
&
req
.
pRSmaParam
.
qmsg1
,
&
req
.
pRSmaParam
.
qmsg1Len
,
pStb
->
pAst1
,
pStb
->
uid
,
STREAM_TRIGGER_
AT_ONC
E
,
0
,
req
.
pRSmaParam
.
xFilesFactor
)
!=
TSDB_CODE_SUCCESS
)
{
STREAM_TRIGGER_
WINDOW_CLOS
E
,
0
,
req
.
pRSmaParam
.
xFilesFactor
)
!=
TSDB_CODE_SUCCESS
)
{
return
NULL
;
}
}
if
(
pStb
->
ast2Len
>
0
)
{
if
(
mndConvertRsmaTask
(
&
req
.
pRSmaParam
.
qmsg2
,
&
req
.
pRSmaParam
.
qmsg2Len
,
pStb
->
pAst2
,
pStb
->
uid
,
STREAM_TRIGGER_
AT_ONC
E
,
0
,
req
.
pRSmaParam
.
xFilesFactor
)
!=
TSDB_CODE_SUCCESS
)
{
STREAM_TRIGGER_
WINDOW_CLOS
E
,
0
,
req
.
pRSmaParam
.
xFilesFactor
)
!=
TSDB_CODE_SUCCESS
)
{
return
NULL
;
}
}
...
...
source/dnode/snode/inc/sndInt.h
浏览文件 @
ca7057ce
...
...
@@ -56,7 +56,6 @@ SStreamTask* sndMetaGetTask(SStreamMeta* pMeta, int32_t taskId);
int32_t
sndMetaRemoveTask
(
SStreamMeta
*
pMeta
,
int32_t
taskId
);
int32_t
sndDropTaskOfStream
(
SStreamMeta
*
pMeta
,
int64_t
streamId
);
int32_t
sndStopTaskOfStream
(
SStreamMeta
*
pMeta
,
int64_t
streamId
);
int32_t
sndResumeTaskOfStream
(
SStreamMeta
*
pMeta
,
int64_t
streamId
);
...
...
source/dnode/snode/src/snode.c
浏览文件 @
ca7057ce
...
...
@@ -76,45 +76,158 @@ int32_t sndMetaRemoveTask(SStreamMeta *pMeta, int32_t taskId) {
return
taosHashRemove
(
pMeta
->
pHash
,
&
taskId
,
sizeof
(
int32_t
));
}
static
int32_t
sndProcessTaskExecReq
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
)
{
/*SStreamExecMsgHead *pHead = pMsg->pCont;*/
/*int32_t taskId = pHead->streamTaskId;*/
/*SStreamTask *pTask = sndMetaGetTask(pSnode->pMeta, taskId);*/
/*if (pTask == NULL) {*/
/*return -1;*/
/*}*/
static
int32_t
sndProcessTaskDeployReq
(
SSnode
*
pNode
,
SRpcMsg
*
pMsg
)
{
SStreamMeta
*
pMeta
=
pNode
->
pMeta
;
char
*
msg
=
pMsg
->
pCont
;
int32_t
msgLen
=
pMsg
->
contLen
;
SStreamTask
*
pTask
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamTask
));
if
(
pTask
==
NULL
)
{
return
-
1
;
}
SDecoder
decoder
;
tDecoderInit
(
&
decoder
,
(
uint8_t
*
)
msg
,
msgLen
);
if
(
tDecodeSStreamTask
(
&
decoder
,
pTask
)
<
0
)
{
ASSERT
(
0
);
}
tDecoderClear
(
&
decoder
);
pTask
->
status
=
TASK_STATUS__IDLE
;
pTask
->
inputQueue
=
streamQueueOpen
();
pTask
->
outputQueue
=
streamQueueOpen
();
pTask
->
inputStatus
=
TASK_INPUT_STATUS__NORMAL
;
pTask
->
outputStatus
=
TASK_INPUT_STATUS__NORMAL
;
if
(
pTask
->
inputQueue
==
NULL
||
pTask
->
outputQueue
==
NULL
)
goto
FAIL
;
pTask
->
pMsgCb
=
&
pNode
->
msgCb
;
ASSERT
(
pTask
->
execType
!=
TASK_EXEC__NONE
);
SReadHandle
handle
=
{
.
pMsgCb
=
&
pNode
->
msgCb
,
};
/*pTask->exec.inputHandle = NULL;*/
pTask
->
exec
.
executor
=
qCreateStreamExecTaskInfo
(
pTask
->
exec
.
qmsg
,
&
handle
);
ASSERT
(
pTask
->
exec
.
executor
);
streamSetupTrigger
(
pTask
);
qInfo
(
"deploy stream: stream id %ld task id %d child id %d on snode"
,
pTask
->
streamId
,
pTask
->
taskId
,
pTask
->
childId
);
return
0
;
FAIL:
if
(
pTask
->
inputQueue
)
streamQueueClose
(
pTask
->
inputQueue
);
if
(
pTask
->
outputQueue
)
streamQueueClose
(
pTask
->
outputQueue
);
return
-
1
;
}
static
int32_t
sndProcessTaskRunReq
(
SSnode
*
pNode
,
SRpcMsg
*
pMsg
)
{
SStreamMeta
*
pMeta
=
pNode
->
pMeta
;
SStreamTaskRunReq
*
pReq
=
pMsg
->
pCont
;
int32_t
taskId
=
pReq
->
taskId
;
SStreamTask
*
pTask
=
*
(
SStreamTask
**
)
taosHashGet
(
pMeta
->
pHash
,
&
taskId
,
sizeof
(
int32_t
));
streamTaskProcessRunReq
(
pTask
,
&
pNode
->
msgCb
);
return
0
;
}
void
sndProcessUMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
)
{
static
int32_t
sndProcessTaskDispatchReq
(
SSnode
*
pNode
,
SRpcMsg
*
pMsg
)
{
SStreamMeta
*
pMeta
=
pNode
->
pMeta
;
char
*
msgStr
=
pMsg
->
pCont
;
char
*
msgBody
=
POINTER_SHIFT
(
msgStr
,
sizeof
(
SMsgHead
));
int32_t
msgLen
=
pMsg
->
contLen
-
sizeof
(
SMsgHead
);
SStreamDispatchReq
req
;
SDecoder
decoder
;
tDecoderInit
(
&
decoder
,
msgBody
,
msgLen
);
tDecodeStreamDispatchReq
(
&
decoder
,
&
req
);
int32_t
taskId
=
req
.
taskId
;
SStreamTask
*
pTask
=
*
(
SStreamTask
**
)
taosHashGet
(
pMeta
->
pHash
,
&
taskId
,
sizeof
(
int32_t
));
SRpcMsg
rsp
=
{
.
info
=
pMsg
->
info
,
.
code
=
0
,
};
streamProcessDispatchReq
(
pTask
,
&
pNode
->
msgCb
,
&
req
,
&
rsp
);
return
0
;
}
static
int32_t
sndProcessTaskRecoverReq
(
SSnode
*
pNode
,
SRpcMsg
*
pMsg
)
{
SStreamMeta
*
pMeta
=
pNode
->
pMeta
;
SStreamTaskRecoverReq
*
pReq
=
pMsg
->
pCont
;
int32_t
taskId
=
pReq
->
taskId
;
SStreamTask
*
pTask
=
*
(
SStreamTask
**
)
taosHashGet
(
pMeta
->
pHash
,
&
taskId
,
sizeof
(
int32_t
));
streamProcessRecoverReq
(
pTask
,
&
pNode
->
msgCb
,
pReq
,
pMsg
);
return
0
;
}
static
int32_t
sndProcessTaskDispatchRsp
(
SSnode
*
pNode
,
SRpcMsg
*
pMsg
)
{
SStreamMeta
*
pMeta
=
pNode
->
pMeta
;
SStreamDispatchRsp
*
pRsp
=
POINTER_SHIFT
(
pMsg
->
pCont
,
sizeof
(
SMsgHead
));
int32_t
taskId
=
pRsp
->
taskId
;
SStreamTask
*
pTask
=
*
(
SStreamTask
**
)
taosHashGet
(
pMeta
->
pHash
,
&
taskId
,
sizeof
(
int32_t
));
streamProcessDispatchRsp
(
pTask
,
&
pNode
->
msgCb
,
pRsp
);
return
0
;
}
static
int32_t
sndProcessTaskRecoverRsp
(
SSnode
*
pNode
,
SRpcMsg
*
pMsg
)
{
SStreamMeta
*
pMeta
=
pNode
->
pMeta
;
SStreamTaskRecoverRsp
*
pRsp
=
pMsg
->
pCont
;
int32_t
taskId
=
pRsp
->
taskId
;
SStreamTask
*
pTask
=
*
(
SStreamTask
**
)
taosHashGet
(
pMeta
->
pHash
,
&
taskId
,
sizeof
(
int32_t
));
streamProcessRecoverRsp
(
pTask
,
pRsp
);
return
0
;
}
static
int32_t
sndProcessTaskDropReq
(
SSnode
*
pNode
,
SRpcMsg
*
pMsg
)
{
SStreamMeta
*
pMeta
=
pNode
->
pMeta
;
char
*
msg
=
pMsg
->
pCont
;
int32_t
msgLen
=
pMsg
->
contLen
;
SVDropStreamTaskReq
*
pReq
=
(
SVDropStreamTaskReq
*
)
msg
;
int32_t
code
=
taosHashRemove
(
pMeta
->
pHash
,
&
pReq
->
taskId
,
sizeof
(
int32_t
));
ASSERT
(
code
==
0
);
if
(
code
==
0
)
{
// sendrsp
}
return
code
;
}
int32_t
sndProcessUMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
)
{
// stream deploy
// stream stop/resume
// operator exec
if
(
pMsg
->
msgType
==
TDMT_STREAM_TASK_DEPLOY
)
{
void
*
msg
=
POINTER_SHIFT
(
pMsg
->
pCont
,
sizeof
(
SMsgHead
));
SStreamTask
*
pTask
=
taosMemoryMalloc
(
sizeof
(
SStreamTask
));
if
(
pTask
==
NULL
)
{
switch
(
pMsg
->
msgType
)
{
case
TDMT_STREAM_TASK_DEPLOY
:
return
sndProcessTaskDeployReq
(
pSnode
,
pMsg
);
case
TDMT_VND_STREAM_TASK_DROP
:
return
sndProcessTaskDropReq
(
pSnode
,
pMsg
);
default:
ASSERT
(
0
);
return
;
}
SDecoder
decoder
;
tDecoderInit
(
&
decoder
,
msg
,
pMsg
->
contLen
-
sizeof
(
SMsgHead
));
tDecodeSStreamTask
(
&
decoder
,
pTask
);
tDecoderClear
(
&
decoder
);
sndMetaDeployTask
(
pSnode
->
pMeta
,
pTask
);
/*} else if (pMsg->msgType == TDMT_SND_TASK_EXEC) {*/
/*sndProcessTaskExecReq(pSnode, pMsg);*/
}
else
{
ASSERT
(
0
);
}
return
0
;
}
void
sndProcessSMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
)
{
// operator exec
/*if (pMsg->msgType == TDMT_SND_TASK_EXEC) {*/
/*sndProcessTaskExecReq(pSnode, pMsg);*/
/*} else {*/
ASSERT
(
0
);
/*}*/
int32_t
sndProcessSMsg
(
SSnode
*
pSnode
,
SRpcMsg
*
pMsg
)
{
switch
(
pMsg
->
msgType
)
{
case
TDMT_STREAM_TASK_RUN
:
return
sndProcessTaskRunReq
(
pSnode
,
pMsg
);
case
TDMT_STREAM_TASK_DISPATCH
:
return
sndProcessTaskDispatchReq
(
pSnode
,
pMsg
);
case
TDMT_STREAM_TASK_RECOVER
:
return
sndProcessTaskRecoverReq
(
pSnode
,
pMsg
);
case
TDMT_STREAM_TASK_DISPATCH_RSP
:
return
sndProcessTaskDispatchRsp
(
pSnode
,
pMsg
);
case
TDMT_STREAM_TASK_RECOVER_RSP
:
return
sndProcessTaskRecoverRsp
(
pSnode
,
pMsg
);
default:
ASSERT
(
0
);
}
return
0
;
}
source/dnode/vnode/inc/vnode.h
浏览文件 @
ca7057ce
...
...
@@ -116,7 +116,7 @@ typedef void *tsdbReaderT;
#define BLOCK_LOAD_TABLE_SEQ_ORDER 2
#define BLOCK_LOAD_TABLE_RR_ORDER 3
tsdbReaderT
*
tsdbReaderOpen
(
SVnode
*
pVnode
,
SQueryTableDataCond
*
pCond
,
STableListInfo
*
tableInfoGroup
,
uint64_t
qId
,
tsdbReaderT
tsdbReaderOpen
(
SVnode
*
pVnode
,
SQueryTableDataCond
*
pCond
,
STableListInfo
*
tableInfoGroup
,
uint64_t
qId
,
uint64_t
taskId
);
tsdbReaderT
tsdbQueryCacheLast
(
SVnode
*
pVnode
,
SQueryTableDataCond
*
pCond
,
STableListInfo
*
groupList
,
uint64_t
qId
,
void
*
pMemRef
);
...
...
source/dnode/vnode/src/inc/sma.h
浏览文件 @
ca7057ce
...
...
@@ -32,11 +32,12 @@ extern "C" {
#define smaTrace(...) do { if (smaDebugFlag & DEBUG_TRACE) { taosPrintLog("SMA ", DEBUG_TRACE, tsdbDebugFlag, __VA_ARGS__); }} while(0)
// clang-format on
typedef
struct
SSmaEnv
SSmaEnv
;
typedef
struct
SSmaStat
SSmaStat
;
typedef
struct
SSmaStatItem
SSmaStatItem
;
typedef
struct
SSmaKey
SSmaKey
;
typedef
struct
SRSmaInfo
SRSmaInfo
;
typedef
struct
SSmaEnv
SSmaEnv
;
typedef
struct
SSmaStat
SSmaStat
;
typedef
struct
SSmaStatItem
SSmaStatItem
;
typedef
struct
SSmaKey
SSmaKey
;
typedef
struct
SRSmaInfo
SRSmaInfo
;
typedef
struct
SRSmaInfoItem
SRSmaInfoItem
;
struct
SSmaEnv
{
TdThreadRwlock
lock
;
...
...
source/dnode/vnode/src/inc/vnodeInt.h
浏览文件 @
ca7057ce
...
...
@@ -121,7 +121,7 @@ int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSu
int32_t
tsdbInsertTableData
(
STsdb
*
pTsdb
,
int64_t
version
,
SSubmitMsgIter
*
pMsgIter
,
SSubmitBlk
*
pBlock
,
SSubmitBlkRsp
*
pRsp
);
int32_t
tsdbDeleteTableData
(
STsdb
*
pTsdb
,
int64_t
version
,
tb_uid_t
suid
,
tb_uid_t
uid
,
TSKEY
sKey
,
TSKEY
eKey
);
tsdbReaderT
*
tsdbReaderOpen
(
SVnode
*
pVnode
,
SQueryTableDataCond
*
pCond
,
STableListInfo
*
tableList
,
uint64_t
qId
,
tsdbReaderT
tsdbReaderOpen
(
SVnode
*
pVnode
,
SQueryTableDataCond
*
pCond
,
STableListInfo
*
tableList
,
uint64_t
qId
,
uint64_t
taskId
);
tsdbReaderT
tsdbQueryCacheLastT
(
STsdb
*
tsdb
,
SQueryTableDataCond
*
pCond
,
STableListInfo
*
tableList
,
uint64_t
qId
,
void
*
pMemRef
);
...
...
source/dnode/vnode/src/sma/sma.c
浏览文件 @
ca7057ce
...
...
@@ -15,6 +15,8 @@
#include "sma.h"
// functions for external invocation
// TODO: Who is responsible for resource allocate and release?
int32_t
tdProcessTSmaInsert
(
SSma
*
pSma
,
int64_t
indexUid
,
const
char
*
msg
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
...
...
@@ -45,6 +47,9 @@ int32_t smaGetTSmaDays(SVnodeCfg* pCfg, void* pCont, uint32_t contLen, int32_t*
return
code
;
}
// functions for internal invocation
#if 0
/**
...
...
source/dnode/vnode/src/sma/smaEnv.c
浏览文件 @
ca7057ce
...
...
@@ -208,7 +208,6 @@ int32_t tdUnLockSma(SSma *pSma) {
int32_t
tdCheckAndInitSmaEnv
(
SSma
*
pSma
,
int8_t
smaType
)
{
SSmaEnv
*
pEnv
=
NULL
;
// return if already init
switch
(
smaType
)
{
case
TSDB_SMA_TYPE_TIME_RANGE
:
if
((
pEnv
=
(
SSmaEnv
*
)
atomic_load_ptr
(
&
SMA_TSMA_ENV
(
pSma
))))
{
...
...
@@ -244,3 +243,34 @@ int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType) {
return
TSDB_CODE_SUCCESS
;
};
int32_t
smaTimerInit
(
void
**
timer
,
int8_t
*
initFlag
,
const
char
*
label
)
{
int8_t
old
;
while
(
1
)
{
old
=
atomic_val_compare_exchange_8
(
initFlag
,
0
,
2
);
if
(
old
!=
2
)
break
;
}
if
(
old
==
0
)
{
*
timer
=
taosTmrInit
(
10000
,
100
,
10000
,
label
);
if
(
!
(
*
timer
))
{
atomic_store_8
(
initFlag
,
0
);
return
-
1
;
}
atomic_store_8
(
initFlag
,
1
);
}
return
0
;
}
void
smaTimerCleanUp
(
void
*
timer
,
int8_t
*
initFlag
)
{
int8_t
old
;
while
(
1
)
{
old
=
atomic_val_compare_exchange_8
(
initFlag
,
1
,
2
);
if
(
old
!=
2
)
break
;
}
if
(
old
==
1
)
{
taosTmrCleanUp
(
timer
);
atomic_store_8
(
initFlag
,
0
);
}
}
source/dnode/vnode/src/sma/smaRollup.c
浏览文件 @
ca7057ce
...
...
@@ -14,14 +14,36 @@
*/
#include "sma.h"
#include "tstream.h"
static
FORCE_INLINE
int32_t
tdUidStorePut
(
STbUidStore
*
pStore
,
tb_uid_t
suid
,
tb_uid_t
*
uid
);
static
FORCE_INLINE
int32_t
tdUpdateTbUidListImpl
(
SSma
*
pSma
,
tb_uid_t
*
suid
,
SArray
*
tbUids
);
static
FORCE_INLINE
int32_t
tdExecuteRSmaImpl
(
SSma
*
pSma
,
const
void
*
pMsg
,
int32_t
inputType
,
qTaskInfo_t
*
taskInfo
,
STSchema
*
pTSchema
,
tb_uid_t
suid
,
int8_t
level
);
static
FORCE_INLINE
int32_t
tdExecuteRSmaImpl
(
SSma
*
pSma
,
const
void
*
pMsg
,
int32_t
inputType
,
SRSmaInfoItem
*
rsmaItem
,
tb_uid_t
suid
,
int8_t
level
);
struct
SRSmaInfoItem
{
SRSmaInfo
*
pRsmaInfo
;
void
*
taskInfo
;
// qTaskInfo_t
void
*
tmrHandle
;
tmr_h
tmrId
;
int8_t
level
;
int8_t
tmrInitFlag
;
int8_t
triggerStatus
;
// TASK_TRIGGER_STATUS__IN_ACTIVE/TASK_TRIGGER_STATUS__ACTIVE
int32_t
maxDelay
;
};
typedef
struct
{
int64_t
suid
;
SRSmaInfoItem
*
pItem
;
SSma
*
pSma
;
STSchema
*
pTSchema
;
}
SRSmaTriggerParam
;
struct
SRSmaInfo
{
void
*
taskInfo
[
TSDB_RETENTION_L2
];
// qTaskInfo_t
STSchema
*
pTSchema
;
SSma
*
pSma
;
int64_t
suid
;
SRSmaInfoItem
items
[
TSDB_RETENTION_L2
];
};
static
FORCE_INLINE
void
tdFreeTaskHandle
(
qTaskInfo_t
*
taskHandle
)
{
...
...
@@ -33,11 +55,20 @@ static FORCE_INLINE void tdFreeTaskHandle(qTaskInfo_t *taskHandle) {
}
void
*
tdFreeRSmaInfo
(
SRSmaInfo
*
pInfo
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_RETENTION_MAX
;
++
i
)
{
if
(
pInfo
->
taskInfo
[
i
])
{
tdFreeTaskHandle
(
pInfo
->
taskInfo
[
i
]);
if
(
pInfo
)
{
for
(
int32_t
i
=
0
;
i
<
TSDB_RETENTION_MAX
;
++
i
)
{
SRSmaInfoItem
*
pItem
=
&
pInfo
->
items
[
i
];
if
(
pItem
->
taskInfo
)
{
tdFreeTaskHandle
(
pItem
->
taskInfo
);
}
if
(
pItem
->
tmrHandle
)
{
taosTmrCleanUp
(
pItem
->
tmrHandle
);
}
}
taosMemoryFree
(
pInfo
->
pTSchema
);
taosMemoryFree
(
pInfo
);
}
return
NULL
;
}
...
...
@@ -69,20 +100,20 @@ static FORCE_INLINE int32_t tdUpdateTbUidListImpl(SSma *pSma, tb_uid_t *suid, SA
return
TSDB_CODE_FAILED
;
}
if
(
pRSmaInfo
->
taskInfo
[
0
]
&&
(
qUpdateQualifiedTableId
(
pRSmaInfo
->
taskInfo
[
0
],
tbUids
,
true
)
!=
0
))
{
if
(
pRSmaInfo
->
items
[
0
].
taskInfo
&&
(
qUpdateQualifiedTableId
(
pRSmaInfo
->
items
[
0
].
taskInfo
,
tbUids
,
true
)
<
0
))
{
smaError
(
"vgId:%d, update tbUidList failed for uid:%"
PRIi64
" since %s"
,
SMA_VID
(
pSma
),
*
suid
,
terrstr
(
terrno
));
return
TSDB_CODE_FAILED
;
}
else
{
smaDebug
(
"vgId:%d, update tbUidList succeed for qTaskInfo:%p with suid:%"
PRIi64
", uid:%"
PRIi64
,
SMA_VID
(
pSma
),
pRSmaInfo
->
taskInfo
[
0
]
,
*
suid
,
*
(
int64_t
*
)
taosArrayGet
(
tbUids
,
0
));
pRSmaInfo
->
items
[
0
].
taskInfo
,
*
suid
,
*
(
int64_t
*
)
taosArrayGet
(
tbUids
,
0
));
}
if
(
pRSmaInfo
->
taskInfo
[
1
]
&&
(
qUpdateQualifiedTableId
(
pRSmaInfo
->
taskInfo
[
1
],
tbUids
,
true
)
!=
0
))
{
if
(
pRSmaInfo
->
items
[
1
].
taskInfo
&&
(
qUpdateQualifiedTableId
(
pRSmaInfo
->
items
[
1
].
taskInfo
,
tbUids
,
true
)
<
0
))
{
smaError
(
"vgId:%d, update tbUidList failed for uid:%"
PRIi64
" since %s"
,
SMA_VID
(
pSma
),
*
suid
,
terrstr
(
terrno
));
return
TSDB_CODE_FAILED
;
}
else
{
smaDebug
(
"vgId:%d, update tbUidList succeed for qTaskInfo:%p with suid:%"
PRIi64
", uid:%"
PRIi64
,
SMA_VID
(
pSma
),
pRSmaInfo
->
taskInfo
[
1
]
,
*
suid
,
*
(
int64_t
*
)
taosArrayGet
(
tbUids
,
0
));
pRSmaInfo
->
items
[
1
].
taskInfo
,
*
suid
,
*
(
int64_t
*
)
taosArrayGet
(
tbUids
,
0
));
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -144,12 +175,12 @@ int32_t tdFetchTbUidList(SSma *pSma, STbUidStore **ppStore, tb_uid_t suid, tb_ui
ASSERT
(
ppStore
!=
NULL
);
if
(
!
(
*
ppStore
))
{
if
(
tdUidStoreInit
(
ppStore
)
!=
0
)
{
if
(
tdUidStoreInit
(
ppStore
)
<
0
)
{
return
TSDB_CODE_FAILED
;
}
}
if
(
tdUidStorePut
(
*
ppStore
,
suid
,
&
uid
)
!=
0
)
{
if
(
tdUidStorePut
(
*
ppStore
,
suid
,
&
uid
)
<
0
)
{
*
ppStore
=
tdUidStoreFree
(
*
ppStore
);
return
TSDB_CODE_FAILED
;
}
...
...
@@ -172,8 +203,8 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) {
return
TSDB_CODE_SUCCESS
;
}
SMeta
*
pMeta
=
pVnode
->
pMeta
;
SMsgCb
*
pMsgCb
=
&
pVnode
->
msgCb
;
SMeta
*
pMeta
=
pVnode
->
pMeta
;
SMsgCb
*
pMsgCb
=
&
pVnode
->
msgCb
;
SRSmaParam
*
param
=
&
pReq
->
pRSmaParam
;
if
((
param
->
qmsg1Len
==
0
)
&&
(
param
->
qmsg2Len
==
0
))
{
...
...
@@ -192,10 +223,12 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) {
pRSmaInfo
=
taosHashGet
(
SMA_STAT_INFO_HASH
(
pStat
),
&
pReq
->
suid
,
sizeof
(
tb_uid_t
));
if
(
pRSmaInfo
)
{
ASSERT
(
0
);
// TODO: free original pRSmaInfo is exists abnormally
smaWarn
(
"vgId:%d, rsma info already exists for stb: %s, %"
PRIi64
,
SMA_VID
(
pSma
),
pReq
->
name
,
pReq
->
suid
);
return
TSDB_CODE_SUCCESS
;
}
// from write queue: single thead
pRSmaInfo
=
(
SRSmaInfo
*
)
taosMemoryCalloc
(
1
,
sizeof
(
SRSmaInfo
));
if
(
!
pRSmaInfo
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -204,9 +237,8 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) {
STqReadHandle
*
pReadHandle
=
tqInitSubmitMsgScanner
(
pMeta
);
if
(
!
pReadHandle
)
{
taosMemoryFree
(
pRSmaInfo
);
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
goto
_err
;
}
SReadHandle
handle
=
{
...
...
@@ -216,32 +248,58 @@ int32_t tdProcessRSmaCreate(SVnode *pVnode, SVCreateStbReq *pReq) {
.
vnode
=
pVnode
,
};
STSchema
*
pTSchema
=
metaGetTbTSchema
(
SMA_META
(
pSma
),
pReq
->
suid
,
-
1
);
if
(
!
pTSchema
)
{
terrno
=
TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION
;
goto
_err
;
}
pRSmaInfo
->
pTSchema
=
pTSchema
;
pRSmaInfo
->
pSma
=
pSma
;
pRSmaInfo
->
suid
=
pReq
->
suid
;
if
(
param
->
qmsg1
)
{
pRSmaInfo
->
taskInfo
[
0
]
=
qCreateStreamExecTaskInfo
(
param
->
qmsg1
,
&
handle
);
if
(
!
pRSmaInfo
->
taskInfo
[
0
])
{
taosMemoryFree
(
pRSmaInfo
);
taosMemoryFree
(
pReadHandle
);
return
TSDB_CODE_FAILED
;
pRSmaInfo
->
items
[
0
].
pRsmaInfo
=
pRSmaInfo
;
pRSmaInfo
->
items
[
0
].
taskInfo
=
qCreateStreamExecTaskInfo
(
param
->
qmsg1
,
&
handle
);
if
(
!
pRSmaInfo
->
items
[
0
].
taskInfo
)
{
goto
_err
;
}
pRSmaInfo
->
items
[
0
].
triggerStatus
=
TASK_TRIGGER_STATUS__IN_ACTIVE
;
pRSmaInfo
->
items
[
0
].
maxDelay
=
5000
;
pRSmaInfo
->
items
[
0
].
level
=
TSDB_RETENTION_L1
;
pRSmaInfo
->
items
[
0
].
tmrHandle
=
taosTmrInit
(
10000
,
100
,
10000
,
"RSMA_L1"
);
if
(
!
pRSmaInfo
->
items
[
0
].
tmrHandle
)
{
goto
_err
;
}
}
if
(
param
->
qmsg2
)
{
pRSmaInfo
->
taskInfo
[
1
]
=
qCreateStreamExecTaskInfo
(
param
->
qmsg2
,
&
handle
);
if
(
!
pRSmaInfo
->
taskInfo
[
1
])
{
taosMemoryFree
(
pRSmaInfo
);
taosMemoryFree
(
pReadHandle
);
return
TSDB_CODE_FAILED
;
pRSmaInfo
->
items
[
1
].
pRsmaInfo
=
pRSmaInfo
;
pRSmaInfo
->
items
[
1
].
taskInfo
=
qCreateStreamExecTaskInfo
(
param
->
qmsg2
,
&
handle
);
if
(
!
pRSmaInfo
->
items
[
1
].
taskInfo
)
{
goto
_err
;
}
pRSmaInfo
->
items
[
1
].
triggerStatus
=
TASK_TRIGGER_STATUS__IN_ACTIVE
;
pRSmaInfo
->
items
[
1
].
maxDelay
=
5000
;
pRSmaInfo
->
items
[
1
].
level
=
TSDB_RETENTION_L2
;
pRSmaInfo
->
items
[
1
].
tmrHandle
=
taosTmrInit
(
10000
,
100
,
10000
,
"RSMA_L2"
);
if
(
!
pRSmaInfo
->
items
[
1
].
tmrHandle
)
{
goto
_err
;
}
}
if
(
taosHashPut
(
SMA_STAT_INFO_HASH
(
pStat
),
&
pReq
->
suid
,
sizeof
(
tb_uid_t
),
&
pRSmaInfo
,
sizeof
(
pRSmaInfo
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_FAILED
;
goto
_err
;
}
else
{
smaDebug
(
"vgId:%d, register rsma info succeed for suid:%"
PRIi64
,
SMA_VID
(
pSma
),
pReq
->
suid
);
}
return
TSDB_CODE_SUCCESS
;
_err:
tdFreeRSmaInfo
(
pRSmaInfo
);
taosMemoryFree
(
pReadHandle
);
return
TSDB_CODE_FAILED
;
}
/**
...
...
@@ -291,12 +349,12 @@ static int32_t tdUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid)
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
if
(
taosHashPut
(
pStore
->
uidHash
,
&
suid
,
sizeof
(
suid
),
&
pUidArray
,
sizeof
(
pUidArray
))
!=
0
)
{
if
(
taosHashPut
(
pStore
->
uidHash
,
&
suid
,
sizeof
(
suid
),
&
pUidArray
,
sizeof
(
pUidArray
))
<
0
)
{
return
TSDB_CODE_FAILED
;
}
}
}
else
{
if
(
taosHashPut
(
pStore
->
uidHash
,
&
suid
,
sizeof
(
suid
),
NULL
,
0
)
!=
0
)
{
if
(
taosHashPut
(
pStore
->
uidHash
,
&
suid
,
sizeof
(
suid
),
NULL
,
0
)
<
0
)
{
return
TSDB_CODE_FAILED
;
}
}
...
...
@@ -367,22 +425,15 @@ static int32_t tdFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) {
return
0
;
}
static
FORCE_INLINE
int32_t
tdExecuteRSmaImpl
(
SSma
*
pSma
,
const
void
*
pMsg
,
int32_t
inputType
,
qTaskInfo_t
*
taskInfo
,
STSchema
*
pTSchema
,
tb_uid_t
suid
,
int8_t
level
)
{
SArray
*
pResult
=
NULL
;
if
(
!
taskInfo
)
{
smaDebug
(
"vgId:%d, no qTaskInfo to execute rsma %"
PRIi8
" task for suid:%"
PRIu64
,
SMA_VID
(
pSma
),
level
,
suid
);
return
TSDB_CODE_SUCCESS
;
}
smaDebug
(
"vgId:%d, execute rsma %"
PRIi8
" task for qTaskInfo:%p suid:%"
PRIu64
,
SMA_VID
(
pSma
),
level
,
taskInfo
,
suid
);
static
int32_t
tdFetchAndSubmitRSmaResult
(
SRSmaInfoItem
*
pItem
,
int8_t
blkType
)
{
SArray
*
pResult
=
NULL
;
SRSmaInfo
*
pRSmaInfo
=
pItem
->
pRsmaInfo
;
SSma
*
pSma
=
pRSmaInfo
->
pSma
;
qSetStreamInput
(
taskInfo
,
pMsg
,
inputType
,
true
);
while
(
1
)
{
SSDataBlock
*
output
=
NULL
;
uint64_t
ts
;
if
(
qExecTask
(
taskInfo
,
&
output
,
&
ts
)
<
0
)
{
if
(
qExecTask
(
pItem
->
taskInfo
,
&
output
,
&
ts
)
<
0
)
{
ASSERT
(
false
);
}
if
(
!
output
)
{
...
...
@@ -400,18 +451,18 @@ static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int3
}
if
(
taosArrayGetSize
(
pResult
)
>
0
)
{
#if
0
#if
1
char
flag
[
10
]
=
{
0
};
snprintf(flag, 10, "level %" PRIi8, level);
snprintf
(
flag
,
10
,
"level %"
PRIi8
,
pItem
->
level
);
blockDebugShowData
(
pResult
,
flag
);
#endif
STsdb
*
sinkTsdb
=
(
level
==
TSDB_RETENTION_L1
?
pSma
->
pRSmaTsdb1
:
pSma
->
pRSmaTsdb2
);
STsdb
*
sinkTsdb
=
(
pItem
->
level
==
TSDB_RETENTION_L1
?
pSma
->
pRSmaTsdb1
:
pSma
->
pRSmaTsdb2
);
SSubmitReq
*
pReq
=
NULL
;
if
(
buildSubmitReqFromDataBlock
(
&
pReq
,
pResult
,
p
TSchema
,
SMA_VID
(
pSma
),
suid
)
<
0
)
{
if
(
buildSubmitReqFromDataBlock
(
&
pReq
,
pResult
,
p
RSmaInfo
->
pTSchema
,
SMA_VID
(
pSma
),
pRSmaInfo
->
suid
)
<
0
)
{
taosArrayDestroy
(
pResult
);
return
TSDB_CODE_FAILED
;
}
if
(
pReq
&&
tdProcessSubmitReq
(
sinkTsdb
,
INT64_MAX
,
pReq
)
<
0
)
{
taosArrayDestroy
(
pResult
);
taosMemoryFreeClear
(
pReq
);
...
...
@@ -420,10 +471,63 @@ static FORCE_INLINE int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int3
taosMemoryFreeClear
(
pReq
);
}
else
{
smaDebug
(
"vgId:%d, no rsma % "
PRIi8
" data generated since %s"
,
SMA_VID
(
pSma
),
level
,
tstrerror
(
terrno
));
smaDebug
(
"vgId:%d, no rsma % "
PRIi8
" data generated since %s"
,
SMA_VID
(
pSma
),
pItem
->
level
,
tstrerror
(
terrno
));
}
if
(
blkType
==
STREAM_DATA_TYPE_SUBMIT_BLOCK
)
{
atomic_store_8
(
&
pItem
->
triggerStatus
,
TASK_TRIGGER_STATUS__ACTIVE
);
}
taosArrayDestroy
(
pResult
);
return
0
;
}
/**
* @brief trigger to get rsma result
*
* @param param
* @param tmrId
*/
static
void
rsmaTriggerByTimer
(
void
*
param
,
void
*
tmrId
)
{
// SRSmaTriggerParam *pParam = (SRSmaTriggerParam *)param;
// SRSmaInfoItem *pItem = pParam->pItem;
SRSmaInfoItem
*
pItem
=
param
;
if
(
atomic_load_8
(
&
pItem
->
triggerStatus
)
==
TASK_TRIGGER_STATUS__ACTIVE
)
{
printf
(
"%s:%d THREAD:%"
PRIi64
" status = active
\n
"
,
__func__
,
__LINE__
,
taosGetSelfPthreadId
());
SSDataBlock
dataBlock
=
{.
info
.
type
=
STREAM_GET_ALL
};
atomic_store_8
(
&
pItem
->
triggerStatus
,
TASK_TRIGGER_STATUS__IN_ACTIVE
);
qSetStreamInput
(
pItem
->
taskInfo
,
&
dataBlock
,
STREAM_DATA_TYPE_SSDATA_BLOCK
,
false
);
tdFetchAndSubmitRSmaResult
(
pItem
,
STREAM_DATA_TYPE_SSDATA_BLOCK
);
}
else
{
printf
(
"%s:%d THREAD:%"
PRIi64
" status = in active
\n
"
,
__func__
,
__LINE__
,
taosGetSelfPthreadId
());
}
// taosTmrReset(rsmaTriggerByTimer, pItem->maxDelay, pItem, pItem->tmrHandle, &pItem->tmrId);
}
static
FORCE_INLINE
int32_t
tdExecuteRSmaImpl
(
SSma
*
pSma
,
const
void
*
pMsg
,
int32_t
inputType
,
SRSmaInfoItem
*
pItem
,
tb_uid_t
suid
,
int8_t
level
)
{
if
(
!
pItem
||
!
pItem
->
taskInfo
)
{
smaDebug
(
"vgId:%d, no qTaskInfo to execute rsma %"
PRIi8
" task for suid:%"
PRIu64
,
SMA_VID
(
pSma
),
level
,
suid
);
return
TSDB_CODE_SUCCESS
;
}
smaDebug
(
"vgId:%d, execute rsma %"
PRIi8
" task for qTaskInfo:%p suid:%"
PRIu64
,
SMA_VID
(
pSma
),
level
,
pItem
->
taskInfo
,
suid
);
// inputType = STREAM_DATA_TYPE_SUBMIT_BLOCK(1)
if
(
qSetStreamInput
(
pItem
->
taskInfo
,
pMsg
,
inputType
,
true
)
<
0
)
{
smaError
(
"vgId:%d, rsma % "
PRIi8
" qSetStreamInput failed since %s"
,
SMA_VID
(
pSma
),
level
,
tstrerror
(
terrno
));
return
TSDB_CODE_FAILED
;
}
// SRSmaTriggerParam triggerParam = {.suid = suid, .pItem = pItem, .pSma = pSma, .pTSchema = pTSchema};
tdFetchAndSubmitRSmaResult
(
pItem
,
STREAM_DATA_TYPE_SUBMIT_BLOCK
);
atomic_store_8
(
&
pItem
->
triggerStatus
,
TASK_TRIGGER_STATUS__ACTIVE
);
taosTmrReset
(
rsmaTriggerByTimer
,
pItem
->
maxDelay
,
pItem
,
pItem
->
tmrHandle
,
&
pItem
->
tmrId
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -441,24 +545,18 @@ static int32_t tdExecuteRSma(SSma *pSma, const void *pMsg, int32_t inputType, tb
pRSmaInfo
=
taosHashGet
(
SMA_STAT_INFO_HASH
(
pStat
),
&
suid
,
sizeof
(
tb_uid_t
));
if
(
!
pRSmaInfo
||
!
(
pRSmaInfo
=
*
(
SRSmaInfo
**
)
pRSmaInfo
))
{
smaDebug
(
"vgId:%d, no rsma info for suid:%"
PRIu64
,
SMA_VID
(
pSma
),
suid
);
smaDebug
(
"vgId:%d,
return as
no rsma info for suid:%"
PRIu64
,
SMA_VID
(
pSma
),
suid
);
return
TSDB_CODE_SUCCESS
;
}
if
(
!
pRSmaInfo
->
taskInfo
[
0
])
{
smaDebug
(
"vgId:%d, no rsma qTaskInfo for suid:%"
PRIu64
,
SMA_VID
(
pSma
),
suid
);
if
(
!
pRSmaInfo
->
items
[
0
].
taskInfo
)
{
smaDebug
(
"vgId:%d, return as no rsma qTaskInfo for suid:%"
PRIu64
,
SMA_VID
(
pSma
),
suid
);
return
TSDB_CODE_SUCCESS
;
}
if
(
inputType
==
STREAM_DATA_TYPE_SUBMIT_BLOCK
)
{
// TODO: cache STSchema
STSchema
*
pTSchema
=
metaGetTbTSchema
(
SMA_META
(
pSma
),
suid
,
-
1
);
if
(
!
pTSchema
)
{
terrno
=
TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION
;
return
TSDB_CODE_FAILED
;
}
tdExecuteRSmaImpl
(
pSma
,
pMsg
,
inputType
,
pRSmaInfo
->
taskInfo
[
0
],
pTSchema
,
suid
,
TSDB_RETENTION_L1
);
tdExecuteRSmaImpl
(
pSma
,
pMsg
,
inputType
,
pRSmaInfo
->
taskInfo
[
1
],
pTSchema
,
suid
,
TSDB_RETENTION_L2
);
taosMemoryFree
(
pTSchema
);
tdExecuteRSmaImpl
(
pSma
,
pMsg
,
inputType
,
&
pRSmaInfo
->
items
[
0
],
suid
,
TSDB_RETENTION_L1
);
tdExecuteRSmaImpl
(
pSma
,
pMsg
,
inputType
,
&
pRSmaInfo
->
items
[
1
],
suid
,
TSDB_RETENTION_L2
);
}
return
TSDB_CODE_SUCCESS
;
...
...
source/dnode/vnode/src/tq/tq.c
浏览文件 @
ca7057ce
...
...
@@ -125,10 +125,10 @@ int32_t tqProcessOffsetCommitReq(STQ* pTq, char* msg, int32_t msgLen) {
if
(
offset
.
type
==
TMQ_OFFSET__SNAPSHOT
)
{
tqDebug
(
"receive offset commit msg to %s on vg %d, offset(type:snapshot) uid: %ld, ts: %ld"
,
offset
.
subKey
,
pTq
->
pVnode
->
config
.
vgId
,
offset
.
uid
,
offset
.
ts
);
TD_VID
(
pTq
->
pVnode
)
,
offset
.
uid
,
offset
.
ts
);
}
else
if
(
offset
.
type
==
TMQ_OFFSET__LOG
)
{
tqDebug
(
"receive offset commit msg to %s on vg %d, offset(type:log) version: %ld"
,
offset
.
subKey
,
pTq
->
pVnode
->
config
.
vgId
,
offset
.
version
);
TD_VID
(
pTq
->
pVnode
)
,
offset
.
version
);
}
else
{
ASSERT
(
0
);
}
...
...
@@ -159,7 +159,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
if
(
pOffset
!=
NULL
)
{
ASSERT
(
pOffset
->
type
==
TMQ_OFFSET__LOG
);
tqDebug
(
"consumer %ld, restore offset of %s on vg %d, offset(type:log) version: %ld"
,
consumerId
,
pReq
->
subKey
,
pTq
->
pVnode
->
config
.
vgId
,
pOffset
->
version
);
TD_VID
(
pTq
->
pVnode
)
,
pOffset
->
version
);
fetchOffset
=
pOffset
->
version
+
1
;
}
else
{
if
(
pReq
->
currentOffset
==
TMQ_CONF__RESET_OFFSET__EARLIEAST
)
{
...
...
@@ -167,13 +167,13 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
}
else
if
(
pReq
->
currentOffset
==
TMQ_CONF__RESET_OFFSET__LATEST
)
{
fetchOffset
=
walGetCommittedVer
(
pTq
->
pWal
);
}
else
if
(
pReq
->
currentOffset
==
TMQ_CONF__RESET_OFFSET__NONE
)
{
tqError
(
"tmq poll: no offset committed for consumer %ld in vg %d, subkey %s"
,
consumerId
,
p
Tq
->
pVnode
->
config
.
vgId
,
p
Req
->
subKey
);
tqError
(
"tmq poll: no offset committed for consumer %ld in vg %d, subkey %s"
,
consumerId
,
TD_VID
(
pTq
->
pVnode
),
pReq
->
subKey
);
terrno
=
TSDB_CODE_TQ_NO_COMMITTED_OFFSET
;
return
-
1
;
}
tqDebug
(
"consumer %ld, restore offset of %s on vg %d failed, config is %ld, set to %ld"
,
consumerId
,
pReq
->
subKey
,
pTq
->
pVnode
->
config
.
vgId
,
pReq
->
currentOffset
,
fetchOffset
);
TD_VID
(
pTq
->
pVnode
)
,
pReq
->
currentOffset
,
fetchOffset
);
}
}
...
...
@@ -183,14 +183,14 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
STqHandle
*
pHandle
=
taosHashGet
(
pTq
->
handles
,
pReq
->
subKey
,
strlen
(
pReq
->
subKey
));
/*ASSERT(pHandle);*/
if
(
pHandle
==
NULL
)
{
tqError
(
"tmq poll: no consumer handle for consumer %ld in vg %d, subkey %s"
,
consumerId
,
pTq
->
pVnode
->
config
.
vgId
,
tqError
(
"tmq poll: no consumer handle for consumer %ld in vg %d, subkey %s"
,
consumerId
,
TD_VID
(
pTq
->
pVnode
)
,
pReq
->
subKey
);
return
-
1
;
}
if
(
pHandle
->
consumerId
!=
consumerId
)
{
tqError
(
"tmq poll: consumer handle mismatch for consumer %ld in vg %d, subkey %s, handle consumer id %ld"
,
consumerId
,
pTq
->
pVnode
->
config
.
vgId
,
pReq
->
subKey
,
pHandle
->
consumerId
);
consumerId
,
TD_VID
(
pTq
->
pVnode
)
,
pReq
->
subKey
,
pHandle
->
consumerId
);
return
-
1
;
}
...
...
@@ -304,7 +304,6 @@ int32_t tqProcessVgDeleteReq(STQ* pTq, char* msg, int32_t msgLen) {
return
0
;
}
// TODO: persist meta into tdb
int32_t
tqProcessVgChangeReq
(
STQ
*
pTq
,
char
*
msg
,
int32_t
msgLen
)
{
SMqRebVgReq
req
=
{
0
};
tDecodeSMqRebVgReq
(
msg
,
&
req
);
...
...
@@ -346,10 +345,10 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
pHandle
->
execHandle
.
execTb
.
suid
=
req
.
suid
;
SArray
*
tbUidList
=
taosArrayInit
(
0
,
sizeof
(
int64_t
));
tsdbGetCtbIdList
(
pTq
->
pVnode
->
pMeta
,
req
.
suid
,
tbUidList
);
tqDebug
(
"vg %d, tq try get suid: %ld"
,
pTq
->
pVnode
->
config
.
vgId
,
req
.
suid
);
tqDebug
(
"vg %d, tq try get suid: %ld"
,
TD_VID
(
pTq
->
pVnode
)
,
req
.
suid
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
tbUidList
);
i
++
)
{
int64_t
tbUid
=
*
(
int64_t
*
)
taosArrayGet
(
tbUidList
,
i
);
tqDebug
(
"vg %d, idx %d, uid: %ld"
,
pTq
->
pVnode
->
config
.
vgId
,
i
,
tbUid
);
tqDebug
(
"vg %d, idx %d, uid: %ld"
,
TD_VID
(
pTq
->
pVnode
)
,
i
,
tbUid
);
}
for
(
int32_t
i
=
0
;
i
<
5
;
i
++
)
{
tqReadHandleSetTbUidList
(
pHandle
->
execHandle
.
pExecReader
[
i
],
tbUidList
);
...
...
@@ -400,16 +399,21 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
// exec
if
(
pTask
->
execType
!=
TASK_EXEC__NONE
)
{
// expand runners
STqReadHandle
*
pStreamReader
=
tqInitSubmitMsgScanner
(
pTq
->
pVnode
->
pMeta
);
SReadHandle
handle
=
{
.
reader
=
pStreamReader
,
.
meta
=
pTq
->
pVnode
->
pMeta
,
.
pMsgCb
=
&
pTq
->
pVnode
->
msgCb
,
.
vnode
=
pTq
->
pVnode
,
};
pTask
->
exec
.
inputHandle
=
pStreamReader
;
pTask
->
exec
.
executor
=
qCreateStreamExecTaskInfo
(
pTask
->
exec
.
qmsg
,
&
handle
);
ASSERT
(
pTask
->
exec
.
executor
);
if
(
pTask
->
dataScan
)
{
STqReadHandle
*
pStreamReader
=
tqInitSubmitMsgScanner
(
pTq
->
pVnode
->
pMeta
);
SReadHandle
handle
=
{
.
reader
=
pStreamReader
,
.
meta
=
pTq
->
pVnode
->
pMeta
,
.
pMsgCb
=
&
pTq
->
pVnode
->
msgCb
,
.
vnode
=
pTq
->
pVnode
,
};
/*pTask->exec.inputHandle = pStreamReader;*/
pTask
->
exec
.
executor
=
qCreateStreamExecTaskInfo
(
pTask
->
exec
.
qmsg
,
&
handle
);
ASSERT
(
pTask
->
exec
.
executor
);
}
else
{
pTask
->
exec
.
executor
=
qCreateStreamExecTaskInfo
(
pTask
->
exec
.
qmsg
,
NULL
);
ASSERT
(
pTask
->
exec
.
executor
);
}
}
// sink
...
...
@@ -431,7 +435,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
streamSetupTrigger
(
pTask
);
tqInfo
(
"deploy stream task id %d child id %d on vg %d"
,
pTask
->
taskId
,
pTask
->
childId
,
pTq
->
pVnode
->
config
.
vgId
);
tqInfo
(
"deploy stream task id %d child id %d on vg %d"
,
pTask
->
taskId
,
pTask
->
childId
,
TD_VID
(
pTq
->
pVnode
)
);
taosHashPut
(
pTq
->
pStreamTasks
,
&
pTask
->
taskId
,
sizeof
(
int32_t
),
&
pTask
,
sizeof
(
void
*
));
...
...
@@ -464,7 +468,7 @@ int32_t tqProcessStreamTrigger(STQ* pTq, SSubmitReq* pReq) {
continue
;
}
if
(
streamLaunchByWrite
(
pTask
,
pTq
->
pVnode
->
config
.
vgId
,
&
pTq
->
pVnode
->
msgCb
)
<
0
)
{
if
(
streamLaunchByWrite
(
pTask
,
TD_VID
(
pTq
->
pVnode
)
,
&
pTq
->
pVnode
->
msgCb
)
<
0
)
{
continue
;
}
}
else
{
...
...
@@ -534,9 +538,9 @@ int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg) {
int32_t
tqProcessTaskDropReq
(
STQ
*
pTq
,
char
*
msg
,
int32_t
msgLen
)
{
SVDropStreamTaskReq
*
pReq
=
(
SVDropStreamTaskReq
*
)
msg
;
int32_t
code
=
taosHashRemove
(
pTq
->
pStreamTasks
,
&
pReq
->
taskId
,
sizeof
(
int32_t
));
ASSERT
(
code
==
0
);
if
(
code
==
0
)
{
// sendrsp
}
ASSERT
(
code
==
0
);
return
code
;
}
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
ca7057ce
...
...
@@ -500,7 +500,7 @@ static int32_t setCurrentSchema(SVnode* pVnode, STsdbReadHandle* pTsdbReadHandle
return
TSDB_CODE_SUCCESS
;
}
tsdbReaderT
*
tsdbReaderOpen
(
SVnode
*
pVnode
,
SQueryTableDataCond
*
pCond
,
STableListInfo
*
tableList
,
uint64_t
qId
,
tsdbReaderT
tsdbReaderOpen
(
SVnode
*
pVnode
,
SQueryTableDataCond
*
pCond
,
STableListInfo
*
tableList
,
uint64_t
qId
,
uint64_t
taskId
)
{
STsdbReadHandle
*
pTsdbReadHandle
=
tsdbQueryTablesImpl
(
pVnode
,
pCond
,
qId
,
taskId
);
if
(
pTsdbReadHandle
==
NULL
)
{
...
...
@@ -508,7 +508,7 @@ tsdbReaderT* tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, STableLi
}
if
(
emptyQueryTimewindow
(
pTsdbReadHandle
))
{
return
(
tsdbReaderT
*
)
pTsdbReadHandle
;
return
(
tsdbReaderT
)
pTsdbReadHandle
;
}
// todo apply the lastkey of table check to avoid to load header file
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
ca7057ce
...
...
@@ -346,7 +346,10 @@ static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *p
goto
_err
;
}
tdProcessRSmaCreate
(
pVnode
,
&
req
);
if
(
tdProcessRSmaCreate
(
pVnode
,
&
req
)
<
0
)
{
pRsp
->
code
=
terrno
;
goto
_err
;
}
tDecoderClear
(
&
coder
);
return
0
;
...
...
source/libs/command/src/explain.c
浏览文件 @
ca7057ce
...
...
@@ -412,6 +412,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
QRY_ERR_RET
(
qExplainBufAppendExecInfo
(
pResNode
->
pExecInfo
,
tbuf
,
&
tlen
));
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
}
EXPLAIN_ROW_APPEND
(
EXPLAIN_COLUMNS_FORMAT
,
pTblScanNode
->
scan
.
pScanCols
->
length
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_WIDTH_FORMAT
,
pTblScanNode
->
scan
.
node
.
pOutputDataBlockDesc
->
totalRowSize
);
...
...
@@ -426,27 +427,57 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
EXPLAIN_ROW_NEW
(
level
+
1
,
"I/O: "
);
int32_t
nodeNum
=
taosArrayGetSize
(
pResNode
->
pExecInfo
);
for
(
int32_t
i
=
0
;
i
<
nodeNum
;
++
i
)
{
struct
STableScanAnalyzeInfo
info
=
{
0
};
int32_t
maxIndex
=
0
;
int32_t
totalRows
=
0
;
for
(
int32_t
i
=
0
;
i
<
nodeNum
;
++
i
)
{
SExplainExecInfo
*
execInfo
=
taosArrayGet
(
pResNode
->
pExecInfo
,
i
);
STableScanAnalyzeInfo
*
pScanInfo
=
(
STableScanAnalyzeInfo
*
)
execInfo
->
verboseInfo
;
EXPLAIN_ROW_APPEND
(
"total_blocks=%d"
,
pScanInfo
->
totalBlocks
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
info
.
totalBlocks
+=
pScanInfo
->
totalBlocks
;
info
.
loadBlocks
+=
pScanInfo
->
loadBlocks
;
info
.
totalRows
+=
pScanInfo
->
totalRows
;
info
.
skipBlocks
+=
pScanInfo
->
skipBlocks
;
info
.
filterTime
+=
pScanInfo
->
filterTime
;
info
.
loadBlockStatis
+=
pScanInfo
->
loadBlockStatis
;
info
.
totalCheckedRows
+=
pScanInfo
->
totalCheckedRows
;
info
.
filterOutBlocks
+=
pScanInfo
->
filterOutBlocks
;
if
(
pScanInfo
->
totalRows
>
totalRows
)
{
totalRows
=
pScanInfo
->
totalRows
;
maxIndex
=
i
;
}
}
EXPLAIN_ROW_APPEND
(
"load_blocks=%d"
,
pScanInfo
->
loadBlocks
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
EXPLAIN_ROW_APPEND
(
"total_blocks=%.1f"
,
((
double
)
info
.
totalBlocks
)
/
nodeNum
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
EXPLAIN_ROW_APPEND
(
"load_block_SMAs=%d"
,
pScanInfo
->
loadBlockStatis
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
EXPLAIN_ROW_APPEND
(
"load_blocks=%.1f"
,
((
double
)
info
.
loadBlocks
)
/
nodeNum
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
EXPLAIN_ROW_APPEND
(
"total_rows=%"
PRIu64
,
pScanInfo
->
totalRows
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
EXPLAIN_ROW_APPEND
(
"load_block_SMAs=%.1f"
,
((
double
)
info
.
loadBlockStatis
)
/
nodeNum
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
EXPLAIN_ROW_APPEND
(
"check_rows=%"
PRIu64
,
pScanInfo
->
totalCheckedRows
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
}
EXPLAIN_ROW_APPEND
(
"total_rows=%.1f"
,
((
double
)
info
.
totalRows
)
/
nodeNum
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
EXPLAIN_ROW_APPEND
(
"check_rows=%.1f"
,
((
double
)
info
.
totalCheckedRows
)
/
nodeNum
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
EXPLAIN_ROW_END
();
QRY_ERR_RET
(
qExplainResAppendRow
(
ctx
,
tbuf
,
tlen
,
level
+
1
));
//Rows out: Avg 4166.7 rows x 24 workers. Max 4187 rows (seg7) with 0.220 ms to first row, 1.738 ms to end, start offset by 1.470 ms.
SExplainExecInfo
*
execInfo
=
taosArrayGet
(
pResNode
->
pExecInfo
,
maxIndex
);
STableScanAnalyzeInfo
*
p1
=
(
STableScanAnalyzeInfo
*
)
execInfo
->
verboseInfo
;
EXPLAIN_ROW_NEW
(
level
+
1
,
" "
);
EXPLAIN_ROW_APPEND
(
"max_row_task=%d, total_rows:%"
PRId64
", ep:%s (cost=%.3f..%.3f)"
,
maxIndex
,
p1
->
totalRows
,
"tbd"
,
execInfo
->
startupCost
,
execInfo
->
totalCost
);
EXPLAIN_ROW_APPEND
(
EXPLAIN_BLANK_FORMAT
);
EXPLAIN_ROW_END
();
QRY_ERR_RET
(
qExplainResAppendRow
(
ctx
,
tbuf
,
tlen
,
level
+
1
));
}
...
...
source/libs/executor/inc/executil.h
浏览文件 @
ca7057ce
...
...
@@ -114,7 +114,7 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
SExprInfo
*
createExprInfo
(
SNodeList
*
pNodeList
,
SNodeList
*
pGroupKeys
,
int32_t
*
numOfExprs
);
SqlFunctionCtx
*
createSqlFunctionCtx
(
SExprInfo
*
pExprInfo
,
int32_t
numOfOutput
,
int32_t
**
rowEntryInfoOffset
);
void
relocateColumnData
(
SSDataBlock
*
pBlock
,
const
SArray
*
pColMatchInfo
,
SArray
*
pCols
);
void
relocateColumnData
(
SSDataBlock
*
pBlock
,
const
SArray
*
pColMatchInfo
,
SArray
*
pCols
,
bool
outputEveryColumn
);
void
initExecTimeWindowInfo
(
SColumnInfoData
*
pColData
,
STimeWindow
*
pQueryWindow
);
SInterval
extractIntervalInfo
(
const
STableScanPhysiNode
*
pTableScanNode
);
...
...
source/libs/executor/inc/executorimpl.h
浏览文件 @
ca7057ce
...
...
@@ -369,6 +369,8 @@ typedef struct SSysTableScanInfo {
typedef
struct
SBlockDistInfo
{
SSDataBlock
*
pResBlock
;
void
*
pHandle
;
SReadHandle
readHandle
;
uint64_t
uid
;
// table uid
}
SBlockDistInfo
;
// todo remove this
...
...
@@ -740,7 +742,8 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo
SOperatorInfo
*
createGroupOperatorInfo
(
SOperatorInfo
*
downstream
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
SSDataBlock
*
pResultBlock
,
SArray
*
pGroupColList
,
SNode
*
pCondition
,
SExprInfo
*
pScalarExprInfo
,
int32_t
numOfScalarExpr
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createDataBlockInfoScanOperator
(
void
*
dataReader
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createDataBlockInfoScanOperator
(
void
*
dataReader
,
SReadHandle
*
readHandle
,
uint64_t
uid
,
SBlockDistScanPhysiNode
*
pBlockScanNode
,
SExecTaskInfo
*
pTaskInfo
);
SOperatorInfo
*
createStreamScanOperatorInfo
(
void
*
pDataReader
,
SReadHandle
*
pHandle
,
STableScanPhysiNode
*
pTableScanNode
,
SExecTaskInfo
*
pTaskInfo
,
STimeWindowAggSupp
*
pTwSup
);
...
...
source/libs/executor/src/dataDispatcher.c
浏览文件 @
ca7057ce
...
...
@@ -75,12 +75,18 @@ static bool needCompress(const SSDataBlock* pData, int32_t numOfCols) {
// The length of bitmap is decided by number of rows of this data block, and the length of each column data is
// recorded in the first segment, next to the struct header
static
void
toDataCacheEntry
(
SDataDispatchHandle
*
pHandle
,
const
SInputData
*
pInput
,
SDataDispatchBuf
*
pBuf
)
{
int32_t
numOfCols
=
LIST_LENGTH
(
pHandle
->
pSchema
->
pSlots
);
int32_t
numOfCols
=
0
;
SNode
*
pNode
;
FOREACH
(
pNode
,
pHandle
->
pSchema
->
pSlots
)
{
SSlotDescNode
*
pSlotDesc
=
(
SSlotDescNode
*
)
pNode
;
if
(
pSlotDesc
->
output
)
{
++
numOfCols
;
}
}
SDataCacheEntry
*
pEntry
=
(
SDataCacheEntry
*
)
pBuf
->
pData
;
pEntry
->
compressed
=
(
int8_t
)
needCompress
(
pInput
->
pData
,
numOfCols
);
pEntry
->
numOfRows
=
pInput
->
pData
->
info
.
rows
;
pEntry
->
numOfCols
=
pInput
->
pData
->
info
.
numOfCols
;
pEntry
->
numOfCols
=
numOfCols
;
pEntry
->
dataLen
=
0
;
pBuf
->
useSize
=
sizeof
(
SDataCacheEntry
);
...
...
source/libs/executor/src/executil.c
浏览文件 @
ca7057ce
...
...
@@ -193,9 +193,9 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) {
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
SColumnInfoData
idata
=
{{
0
}};
SSlotDescNode
*
pDescNode
=
(
SSlotDescNode
*
)
nodesListGetNode
(
pNode
->
pSlots
,
i
);
// if (!pDescNode->output) { // todo disable it temporarily
// continue;
// }
// if (!pDescNode->output) { // todo disable it temporarily
// continue;
// }
idata
.
info
.
type
=
pDescNode
->
dataType
.
type
;
idata
.
info
.
bytes
=
pDescNode
->
dataType
.
bytes
;
...
...
@@ -235,7 +235,7 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo
terrno
=
code
;
return
code
;
}
else
{
qDebug
(
"sucess to get tableIds, size: %d, suid: %"
PRIu64
""
,
(
int
)
taosArrayGetSize
(
res
),
tableUid
);
qDebug
(
"suc
c
ess to get tableIds, size: %d, suid: %"
PRIu64
""
,
(
int
)
taosArrayGetSize
(
res
),
tableUid
);
}
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
res
);
i
++
)
{
...
...
@@ -319,7 +319,14 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
continue
;
}
SColMatchInfo
*
info
=
taosArrayGet
(
pList
,
pNode
->
slotId
);
SColMatchInfo
*
info
=
NULL
;
for
(
int32_t
j
=
0
;
j
<
taosArrayGetSize
(
pList
);
++
j
)
{
info
=
taosArrayGet
(
pList
,
j
);
if
(
info
->
targetSlotId
==
pNode
->
slotId
)
{
break
;
}
}
if
(
pNode
->
output
)
{
(
*
numOfOutputCols
)
+=
1
;
}
else
{
...
...
@@ -578,14 +585,15 @@ SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput,
}
// NOTE: sources columns are more than the destination SSDatablock columns.
void
relocateColumnData
(
SSDataBlock
*
pBlock
,
const
SArray
*
pColMatchInfo
,
SArray
*
pCols
)
{
// doFilter in table scan needs every column even its output is false
void
relocateColumnData
(
SSDataBlock
*
pBlock
,
const
SArray
*
pColMatchInfo
,
SArray
*
pCols
,
bool
outputEveryColumn
)
{
size_t
numOfSrcCols
=
taosArrayGetSize
(
pCols
);
int32_t
i
=
0
,
j
=
0
;
while
(
i
<
numOfSrcCols
&&
j
<
taosArrayGetSize
(
pColMatchInfo
))
{
SColumnInfoData
*
p
=
taosArrayGet
(
pCols
,
i
);
SColMatchInfo
*
pmInfo
=
taosArrayGet
(
pColMatchInfo
,
j
);
if
(
!
pmInfo
->
output
)
{
if
(
!
outputEveryColumn
&&
!
pmInfo
->
output
)
{
j
++
;
continue
;
}
...
...
source/libs/executor/src/executor.c
浏览文件 @
ca7057ce
...
...
@@ -41,12 +41,18 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu
pInfo
->
assignBlockUid
=
assignUid
;
// the block type can not be changed in the streamscan operators
#if 0
if (pInfo->blockType == 0) {
pInfo->blockType = type;
} else if (pInfo->blockType != type) {
ASSERT(0);
return TSDB_CODE_QRY_APP_ERROR;
}
#endif
// rollup sma, the same qTaskInfo is used to insert data by SubmitReq and fetch result by SSDataBlock
if
(
pInfo
->
blockType
!=
type
)
{
pInfo
->
blockType
=
type
;
}
if
(
type
==
STREAM_DATA_TYPE_SUBMIT_BLOCK
)
{
if
(
tqReadHandleSetMsg
(
pInfo
->
streamBlockReader
,
input
,
0
)
<
0
)
{
...
...
@@ -99,7 +105,7 @@ int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numO
}
qTaskInfo_t
qCreateStreamExecTaskInfo
(
void
*
msg
,
void
*
streamReadHandle
)
{
if
(
msg
==
NULL
||
streamReadHandle
==
NULL
)
{
if
(
msg
==
NULL
)
{
return
NULL
;
}
...
...
source/libs/executor/src/executorMain.c
浏览文件 @
ca7057ce
...
...
@@ -13,10 +13,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "tref.h"
#include "dataSinkMgt.h"
#include "os.h"
#include "tmsg.h"
#include "tref.h"
#include "tudf.h"
#include "executor.h"
...
...
@@ -24,15 +24,13 @@
#include "query.h"
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
);
}
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
)
{
assert
(
readHandle
!=
NULL
&&
pSubplan
!=
NULL
);
assert
(
pSubplan
!=
NULL
);
SExecTaskInfo
**
pTask
=
(
SExecTaskInfo
**
)
pTaskInfo
;
taosThreadOnce
(
&
initPoolOnce
,
initRefPool
);
...
...
@@ -47,57 +45,57 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
if
(
handle
)
{
void
*
pSinkParam
=
NULL
;
code
=
createDataSinkParam
(
pSubplan
->
pDataSink
,
&
pSinkParam
,
pTaskInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
code
=
dsCreateDataSinker
(
pSubplan
->
pDataSink
,
handle
,
pSinkParam
);
}
_error:
_error:
// if failed to add ref for all tables in this query, abort current query
return
code
;
}
#ifdef TEST_IMPL
// wait moment
int
waitMoment
(
SQInfo
*
pQInfo
){
if
(
pQInfo
->
sql
)
{
int
ms
=
0
;
int
waitMoment
(
SQInfo
*
pQInfo
)
{
if
(
pQInfo
->
sql
)
{
int
ms
=
0
;
char
*
pcnt
=
strstr
(
pQInfo
->
sql
,
" count(*)"
);
if
(
pcnt
)
return
0
;
if
(
pcnt
)
return
0
;
char
*
pos
=
strstr
(
pQInfo
->
sql
,
" t_"
);
if
(
pos
)
{
if
(
pos
)
{
pos
+=
3
;
ms
=
atoi
(
pos
);
while
(
*
pos
>=
'0'
&&
*
pos
<=
'9'
)
{
pos
++
;
while
(
*
pos
>=
'0'
&&
*
pos
<=
'9'
)
{
pos
++
;
}
char
unit_char
=
*
pos
;
if
(
unit_char
==
'h'
)
{
ms
*=
3600
*
1000
;
}
else
if
(
unit_char
==
'm'
)
{
ms
*=
60
*
1000
;
}
else
if
(
unit_char
==
's'
)
{
if
(
unit_char
==
'h'
)
{
ms
*=
3600
*
1000
;
}
else
if
(
unit_char
==
'm'
)
{
ms
*=
60
*
1000
;
}
else
if
(
unit_char
==
's'
)
{
ms
*=
1000
;
}
}
if
(
ms
==
0
)
return
0
;
if
(
ms
==
0
)
return
0
;
printf
(
"test wait sleep %dms. sql=%s ...
\n
"
,
ms
,
pQInfo
->
sql
);
if
(
ms
<
1000
)
{
if
(
ms
<
1000
)
{
taosMsleep
(
ms
);
}
else
{
int
used_ms
=
0
;
while
(
used_ms
<
ms
)
{
while
(
used_ms
<
ms
)
{
taosMsleep
(
1000
);
used_ms
+=
1000
;
if
(
isTaskKilled
(
pQInfo
))
{
if
(
isTaskKilled
(
pQInfo
))
{
printf
(
"test check query is canceled, sleep break.%s
\n
"
,
pQInfo
->
sql
);
break
;
}
...
...
@@ -108,15 +106,14 @@ int waitMoment(SQInfo* pQInfo){
}
#endif
int32_t
qExecTask
(
qTaskInfo_t
tinfo
,
SSDataBlock
**
pRes
,
uint64_t
*
useconds
)
{
int32_t
qExecTask
(
qTaskInfo_t
tinfo
,
SSDataBlock
**
pRes
,
uint64_t
*
useconds
)
{
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
tinfo
;
int64_t
threadId
=
taosGetSelfPthreadId
();
*
pRes
=
NULL
;
int64_t
curOwner
=
0
;
if
((
curOwner
=
atomic_val_compare_exchange_64
(
&
pTaskInfo
->
owner
,
0
,
threadId
))
!=
0
)
{
qError
(
"%s-%p execTask is now executed by thread:%p"
,
GET_TASKID
(
pTaskInfo
),
pTaskInfo
,
(
void
*
)
curOwner
);
qError
(
"%s-%p execTask is now executed by thread:%p"
,
GET_TASKID
(
pTaskInfo
),
pTaskInfo
,
(
void
*
)
curOwner
);
pTaskInfo
->
code
=
TSDB_CODE_QRY_IN_EXEC
;
return
pTaskInfo
->
code
;
}
...
...
@@ -152,18 +149,18 @@ int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t *useconds) {
cleanUpUdfs
();
int32_t
current
=
(
*
pRes
!=
NULL
)
?
(
*
pRes
)
->
info
.
rows
:
0
;
int32_t
current
=
(
*
pRes
!=
NULL
)
?
(
*
pRes
)
->
info
.
rows
:
0
;
uint64_t
total
=
pTaskInfo
->
pRoot
->
resultInfo
.
totalRows
;
qDebug
(
"%s task suspended, %d rows returned, total:%"
PRId64
" rows, in sinkNode:%d, elapsed:%.2f ms"
,
GET_TASKID
(
pTaskInfo
),
current
,
total
,
0
,
el
/
1000
.
0
);
GET_TASKID
(
pTaskInfo
),
current
,
total
,
0
,
el
/
1000
.
0
);
atomic_store_64
(
&
pTaskInfo
->
owner
,
0
);
return
pTaskInfo
->
code
;
}
int32_t
qKillTask
(
qTaskInfo_t
qinfo
)
{
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
qinfo
;
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
qinfo
;
if
(
pTaskInfo
==
NULL
)
{
return
TSDB_CODE_QRY_INVALID_QHANDLE
;
...
...
@@ -182,7 +179,7 @@ int32_t qKillTask(qTaskInfo_t qinfo) {
}
int32_t
qAsyncKillTask
(
qTaskInfo_t
qinfo
)
{
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
qinfo
;
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
qinfo
;
if
(
pTaskInfo
==
NULL
)
{
return
TSDB_CODE_QRY_INVALID_QHANDLE
;
...
...
@@ -195,7 +192,7 @@ int32_t qAsyncKillTask(qTaskInfo_t qinfo) {
}
int32_t
qIsTaskCompleted
(
qTaskInfo_t
qinfo
)
{
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
qinfo
;
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
qinfo
;
if
(
pTaskInfo
==
NULL
)
{
return
TSDB_CODE_QRY_INVALID_QHANDLE
;
...
...
@@ -205,18 +202,18 @@ int32_t qIsTaskCompleted(qTaskInfo_t qinfo) {
}
void
qDestroyTask
(
qTaskInfo_t
qTaskHandle
)
{
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
qTaskHandle
;
qDebug
(
"%s execTask completed, numOfRows:%"
PRId64
,
GET_TASKID
(
pTaskInfo
),
pTaskInfo
->
pRoot
->
resultInfo
.
totalRows
);
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
qTaskHandle
;
qDebug
(
"%s execTask completed, numOfRows:%"
PRId64
,
GET_TASKID
(
pTaskInfo
),
pTaskInfo
->
pRoot
->
resultInfo
.
totalRows
);
queryCostStatis
(
pTaskInfo
);
// print the query cost summary
queryCostStatis
(
pTaskInfo
);
// print the query cost summary
doDestroyTask
(
pTaskInfo
);
}
int32_t
qGetExplainExecInfo
(
qTaskInfo_t
tinfo
,
int32_t
*
resNum
,
SExplainExecInfo
**
pRes
)
{
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
tinfo
;
int32_t
capacity
=
0
;
int32_t
qGetExplainExecInfo
(
qTaskInfo_t
tinfo
,
int32_t
*
resNum
,
SExplainExecInfo
**
pRes
)
{
SExecTaskInfo
*
pTaskInfo
=
(
SExecTaskInfo
*
)
tinfo
;
int32_t
capacity
=
0
;
return
getOperatorExplainExecInfo
(
pTaskInfo
->
pRoot
,
pRes
,
&
capacity
,
resNum
);
return
getOperatorExplainExecInfo
(
pTaskInfo
->
pRoot
,
pRes
,
&
capacity
,
resNum
);
}
int32_t
qSerializeTaskStatus
(
qTaskInfo_t
tinfo
,
char
**
pOutput
,
int32_t
*
len
)
{
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
ca7057ce
...
...
@@ -141,8 +141,8 @@ static int32_t doCopyToSDataBlock(SExecTaskInfo* taskInfo, SSDataBlock* pBlock,
SqlFunctionCtx
*
pCtx
,
int32_t
numOfExprs
);
static
void
initCtxOutputBuffer
(
SqlFunctionCtx
*
pCtx
,
int32_t
size
);
static
void
doSetTableGroupOutputBuf
(
SOperatorInfo
*
pOperator
,
SAggOperatorInfo
*
pAggInfo
,
int32_t
numOfOutput
,
uint64_t
groupId
);
static
void
doSetTableGroupOutputBuf
(
SOperatorInfo
*
pOperator
,
SAggOperatorInfo
*
pAggInfo
,
int32_t
numOfOutput
,
uint64_t
groupId
);
// setup the output buffer for each operator
static
bool
hasNull
(
SColumn
*
pColumn
,
SColumnDataAgg
*
pStatis
)
{
...
...
@@ -1230,8 +1230,9 @@ void initResultRow(SResultRow* pResultRow) {
* offset[0] offset[1] offset[2]
*/
// TODO refactor: some function move away
void
setFunctionResultOutput
(
SOperatorInfo
*
pOperator
,
SOptrBasicInfo
*
pInfo
,
SAggSupporter
*
pSup
,
int32_t
stage
,
int32_t
numOfExprs
)
{
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
void
setFunctionResultOutput
(
SOperatorInfo
*
pOperator
,
SOptrBasicInfo
*
pInfo
,
SAggSupporter
*
pSup
,
int32_t
stage
,
int32_t
numOfExprs
)
{
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SqlFunctionCtx
*
pCtx
=
pOperator
->
exprSupp
.
pCtx
;
int32_t
*
rowEntryInfoOffset
=
pOperator
->
exprSupp
.
rowEntryInfoOffset
;
...
...
@@ -1380,9 +1381,10 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const int8_t* rowR
}
}
void
doSetTableGroupOutputBuf
(
SOperatorInfo
*
pOperator
,
SAggOperatorInfo
*
pAggInfo
,
int32_t
numOfOutput
,
uint64_t
groupId
)
{
void
doSetTableGroupOutputBuf
(
SOperatorInfo
*
pOperator
,
SAggOperatorInfo
*
pAggInfo
,
int32_t
numOfOutput
,
uint64_t
groupId
)
{
// for simple group by query without interval, all the tables belong to one group result.
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SResultRowInfo
*
pResultRowInfo
=
&
pAggInfo
->
binfo
.
resultRowInfo
;
SqlFunctionCtx
*
pCtx
=
pOperator
->
exprSupp
.
pCtx
;
int32_t
*
rowEntryInfoOffset
=
pOperator
->
exprSupp
.
rowEntryInfoOffset
;
...
...
@@ -2040,8 +2042,8 @@ static int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInf
}
int32_t
extractDataBlockFromFetchRsp
(
SSDataBlock
*
pRes
,
SLoadRemoteDataInfo
*
pLoadInfo
,
int32_t
numOfRows
,
char
*
pData
,
int32_t
compLen
,
int32_t
numOfOutput
,
int64_t
startTs
,
uint64_t
*
total
,
SArray
*
pColList
)
{
int32_t
compLen
,
int32_t
numOfOutput
,
int64_t
startTs
,
uint64_t
*
total
,
SArray
*
pColList
)
{
if
(
pColList
==
NULL
)
{
// data from other sources
blockCompressDecode
(
pRes
,
numOfOutput
,
numOfRows
,
pData
);
pRes
->
info
.
rows
=
numOfRows
;
...
...
@@ -2084,7 +2086,7 @@ int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLo
// data from mnode
pRes
->
info
.
rows
=
numOfRows
;
relocateColumnData
(
pRes
,
pColList
,
pBlock
->
pDataBlock
);
relocateColumnData
(
pRes
,
pColList
,
pBlock
->
pDataBlock
,
false
);
taosArrayDestroy
(
pBlock
->
pDataBlock
);
taosMemoryFree
(
pBlock
);
// blockDataDestroy(pBlock);
...
...
@@ -2165,8 +2167,9 @@ static SSDataBlock* concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SEx
}
SRetrieveTableRsp
*
pTableRsp
=
pDataInfo
->
pRsp
;
code
=
extractDataBlockFromFetchRsp
(
pExchangeInfo
->
pResult
,
pLoadInfo
,
pTableRsp
->
numOfRows
,
pTableRsp
->
data
,
pTableRsp
->
compLen
,
pTableRsp
->
numOfCols
,
startTs
,
&
pDataInfo
->
totalRows
,
NULL
);
code
=
extractDataBlockFromFetchRsp
(
pExchangeInfo
->
pResult
,
pLoadInfo
,
pTableRsp
->
numOfRows
,
pTableRsp
->
data
,
pTableRsp
->
compLen
,
pTableRsp
->
numOfCols
,
startTs
,
&
pDataInfo
->
totalRows
,
NULL
);
if
(
code
!=
0
)
{
taosMemoryFreeClear
(
pDataInfo
->
pRsp
);
goto
_error
;
...
...
@@ -2281,7 +2284,7 @@ static SSDataBlock* seqLoadRemoteData(SOperatorInfo* pOperator) {
SRetrieveTableRsp
*
pTableRsp
=
pDataInfo
->
pRsp
;
int32_t
code
=
extractDataBlockFromFetchRsp
(
pExchangeInfo
->
pResult
,
pLoadInfo
,
pTableRsp
->
numOfRows
,
pTableRsp
->
data
,
pTableRsp
->
compLen
,
pTableRsp
->
numOfCols
,
startTs
,
&
pDataInfo
->
totalRows
,
NULL
);
pTableRsp
->
compLen
,
pTableRsp
->
numOfCols
,
startTs
,
&
pDataInfo
->
totalRows
,
NULL
);
if
(
pRsp
->
completed
==
1
)
{
qDebug
(
"%s fetch msg rsp from vgId:%d, taskId:0x%"
PRIx64
" numOfRows:%d, rowsOfSource:%"
PRIu64
...
...
@@ -2673,8 +2676,8 @@ static SSDataBlock* doSortedMerge(SOperatorInfo* pOperator) {
}
int32_t
numOfBufPage
=
pInfo
->
sortBufSize
/
pInfo
->
bufPageSize
;
pInfo
->
pSortHandle
=
tsortCreateSortHandle
(
pInfo
->
pSortInfo
,
SORT_MULTISOURCE_MERGE
,
pInfo
->
bufPageSize
,
numOfBufPage
,
pInfo
->
binfo
.
pRes
,
"GET_TASKID(pTaskInfo)"
);
pInfo
->
pSortHandle
=
tsortCreateSortHandle
(
pInfo
->
pSortInfo
,
SORT_MULTISOURCE_MERGE
,
pInfo
->
bufPageSize
,
numOfBufPage
,
pInfo
->
binfo
.
pRes
,
"GET_TASKID(pTaskInfo)"
);
tsortSetFetchRawDataFp
(
pInfo
->
pSortHandle
,
loadNextDataBlock
,
NULL
,
NULL
);
...
...
@@ -2812,7 +2815,8 @@ int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scan
// todo add more information about exchange operation
int32_t
type
=
pOperator
->
operatorType
;
if
(
type
==
QUERY_NODE_PHYSICAL_PLAN_EXCHANGE
||
type
==
QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN
||
type
==
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
||
type
==
QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN
)
{
type
==
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
||
type
==
QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN
||
type
==
QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN
)
{
*
order
=
TSDB_ORDER_ASC
;
*
scanFlag
=
MAIN_SCAN
;
return
TSDB_CODE_SUCCESS
;
...
...
@@ -2840,7 +2844,6 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) {
SAggOperatorInfo
*
pAggInfo
=
pOperator
->
info
;
SExprSupp
*
pSup
=
&
pOperator
->
exprSupp
;
SOptrBasicInfo
*
pInfo
=
&
pAggInfo
->
binfo
;
SOperatorInfo
*
downstream
=
pOperator
->
pDownstream
[
0
];
int64_t
st
=
taosGetTimestampUs
();
...
...
@@ -3130,7 +3133,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
SProjectOperatorInfo
*
pProjectInfo
=
pOperator
->
info
;
SOptrBasicInfo
*
pInfo
=
&
pProjectInfo
->
binfo
;
SExprSupp
*
pSup
=
&
pOperator
->
exprSupp
;
SExprSupp
*
pSup
=
&
pOperator
->
exprSupp
;
SSDataBlock
*
pRes
=
pInfo
->
pRes
;
blockDataCleanup
(
pRes
);
...
...
@@ -3403,8 +3406,8 @@ void cleanupAggSup(SAggSupporter* pAggSup) {
destroyDiskbasedBuf
(
pAggSup
->
pResultBuf
);
}
int32_t
initAggInfo
(
SExprSupp
*
pSup
,
SAggSupporter
*
pAggSup
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
size_t
keyBufSize
,
const
char
*
pkey
)
{
int32_t
initAggInfo
(
SExprSupp
*
pSup
,
SAggSupporter
*
pAggSup
,
SExprInfo
*
pExprInfo
,
int32_t
numOfCols
,
size_t
keyBufSize
,
const
char
*
pkey
)
{
initExprSupp
(
pSup
,
pExprInfo
,
numOfCols
);
doInitAggInfoSup
(
pAggSup
,
pSup
->
pCtx
,
numOfCols
,
keyBufSize
,
pkey
);
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
...
...
@@ -3457,12 +3460,12 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo*
initBasicInfo
(
&
pInfo
->
binfo
,
pResultBlock
);
initExprSupp
(
&
pInfo
->
scalarExprSup
,
pScalarExprInfo
,
numOfScalarExpr
);
pInfo
->
groupId
=
INT32_MIN
;
pOperator
->
name
=
"TableAggregate"
;
pInfo
->
groupId
=
INT32_MIN
;
pOperator
->
name
=
"TableAggregate"
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_HASH_AGG
;
pOperator
->
blocking
=
true
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
info
=
pInfo
;
pOperator
->
blocking
=
true
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
info
=
pInfo
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
fpSet
=
createOperatorFpSet
(
doOpenAggregateOptr
,
getAggregateResult
,
NULL
,
NULL
,
destroyAggOperatorInfo
,
...
...
@@ -3578,25 +3581,26 @@ static SArray* setRowTsColumnOutputInfo(SqlFunctionCtx* pCtx, int32_t numOfCols)
return
pList
;
}
SOperatorInfo
*
createProjectOperatorInfo
(
SOperatorInfo
*
downstream
,
SProjectPhysiNode
*
pProjPhyNode
,
SExecTaskInfo
*
pTaskInfo
)
{
SOperatorInfo
*
createProjectOperatorInfo
(
SOperatorInfo
*
downstream
,
SProjectPhysiNode
*
pProjPhyNode
,
SExecTaskInfo
*
pTaskInfo
)
{
SProjectOperatorInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SProjectOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
goto
_error
;
}
int32_t
numOfCols
=
0
;
int32_t
numOfCols
=
0
;
SExprInfo
*
pExprInfo
=
createExprInfo
(
pProjPhyNode
->
pProjections
,
NULL
,
&
numOfCols
);
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pProjPhyNode
->
node
.
pOutputDataBlockDesc
);
SLimit
limit
=
{.
limit
=
pProjPhyNode
->
limit
,
.
offset
=
pProjPhyNode
->
offset
};
SLimit
slimit
=
{.
limit
=
pProjPhyNode
->
slimit
,
.
offset
=
pProjPhyNode
->
soffset
};
pInfo
->
limit
=
limit
;
pInfo
->
slimit
=
slimit
;
pInfo
->
curOffset
=
limit
.
offset
;
pInfo
->
curSOffset
=
slimit
.
offset
;
pInfo
->
binfo
.
pRes
=
pResBlock
;
pInfo
->
limit
=
limit
;
pInfo
->
slimit
=
slimit
;
pInfo
->
curOffset
=
limit
.
offset
;
pInfo
->
curSOffset
=
slimit
.
offset
;
pInfo
->
binfo
.
pRes
=
pResBlock
;
pInfo
->
pFilterNode
=
pProjPhyNode
->
node
.
pConditions
;
int32_t
numOfRows
=
4096
;
...
...
@@ -3614,12 +3618,12 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys
setFunctionResultOutput
(
pOperator
,
&
pInfo
->
binfo
,
&
pInfo
->
aggSup
,
MAIN_SCAN
,
numOfCols
);
pInfo
->
pPseudoColInfo
=
setRowTsColumnOutputInfo
(
pOperator
->
exprSupp
.
pCtx
,
numOfCols
);
pOperator
->
name
=
"ProjectOperator"
;
pOperator
->
name
=
"ProjectOperator"
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_PROJECT
;
pOperator
->
blocking
=
false
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
info
=
pInfo
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
blocking
=
false
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
info
=
pInfo
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
fpSet
=
createOperatorFpSet
(
operatorDummyOpenFn
,
doProjectOperation
,
NULL
,
NULL
,
destroyProjectOperatorInfo
,
NULL
,
NULL
,
NULL
);
...
...
@@ -3639,7 +3643,7 @@ _error:
static
SSDataBlock
*
doApplyIndefinitFunction
(
SOperatorInfo
*
pOperator
)
{
SIndefOperatorInfo
*
pIndefInfo
=
pOperator
->
info
;
SOptrBasicInfo
*
pInfo
=
&
pIndefInfo
->
binfo
;
SExprSupp
*
pSup
=
&
pOperator
->
exprSupp
;
SExprSupp
*
pSup
=
&
pOperator
->
exprSupp
;
SSDataBlock
*
pRes
=
pInfo
->
pRes
;
blockDataCleanup
(
pRes
);
...
...
@@ -3677,7 +3681,7 @@ static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) {
SExprSupp
*
pScalarSup
=
&
pIndefInfo
->
scalarSup
;
if
(
pScalarSup
->
pExprInfo
!=
NULL
)
{
code
=
projectApplyFunctions
(
pScalarSup
->
pExprInfo
,
pBlock
,
pBlock
,
pScalarSup
->
pCtx
,
pScalarSup
->
numOfExprs
,
pIndefInfo
->
pPseudoColInfo
);
pIndefInfo
->
pPseudoColInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pTaskInfo
->
env
,
code
);
}
...
...
@@ -3686,8 +3690,8 @@ static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) {
setInputDataBlock
(
pOperator
,
pSup
->
pCtx
,
pBlock
,
order
,
scanFlag
,
false
);
blockDataEnsureCapacity
(
pInfo
->
pRes
,
pInfo
->
pRes
->
info
.
rows
+
pBlock
->
info
.
rows
);
code
=
projectApplyFunctions
(
pOperator
->
exprSupp
.
pExprInfo
,
pInfo
->
pRes
,
pBlock
,
pSup
->
pCtx
,
pOperator
->
exprSupp
.
numOfExprs
,
pIndefInfo
->
pPseudoColInfo
);
code
=
projectApplyFunctions
(
pOperator
->
exprSupp
.
pExprInfo
,
pInfo
->
pRes
,
pBlock
,
pSup
->
pCtx
,
p
Operator
->
exprSupp
.
numOfExprs
,
p
IndefInfo
->
pPseudoColInfo
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pTaskInfo
->
env
,
code
);
}
...
...
@@ -3745,14 +3749,14 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy
pInfo
->
binfo
.
pRes
=
pResBlock
;
pInfo
->
pPseudoColInfo
=
setRowTsColumnOutputInfo
(
pSup
->
pCtx
,
numOfExpr
);
pOperator
->
name
=
"IndefinitOperator"
;
pOperator
->
name
=
"IndefinitOperator"
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_PROJECT
;
pOperator
->
blocking
=
false
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
info
=
pInfo
;
pOperator
->
blocking
=
false
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
info
=
pInfo
;
pOperator
->
exprSupp
.
pExprInfo
=
pExprInfo
;
pOperator
->
exprSupp
.
numOfExprs
=
numOfExpr
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
fpSet
=
createOperatorFpSet
(
operatorDummyOpenFn
,
doApplyIndefinitFunction
,
NULL
,
NULL
,
destroyIndefinitOperatorInfo
,
NULL
,
NULL
,
NULL
);
...
...
@@ -3827,11 +3831,11 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
goto
_error
;
}
int32_t
num
=
0
;
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pPhyFillNode
->
node
.
pOutputDataBlockDesc
);
SExprInfo
*
pExprInfo
=
createExprInfo
(
pPhyFillNode
->
pTargets
,
NULL
,
&
num
);
SInterval
*
pInterval
=
&
((
SIntervalAggOperatorInfo
*
)
downstream
->
info
)
->
interval
;
int32_t
type
=
convertFillType
(
pPhyFillNode
->
mode
);
int32_t
num
=
0
;
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pPhyFillNode
->
node
.
pOutputDataBlockDesc
);
SExprInfo
*
pExprInfo
=
createExprInfo
(
pPhyFillNode
->
pTargets
,
NULL
,
&
num
);
SInterval
*
pInterval
=
&
((
SIntervalAggOperatorInfo
*
)
downstream
->
info
)
->
interval
;
int32_t
type
=
convertFillType
(
pPhyFillNode
->
mode
);
SResultInfo
*
pResultInfo
=
&
pOperator
->
resultInfo
;
initResultSizeInfo
(
pOperator
,
4096
);
...
...
@@ -3842,16 +3846,16 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode*
goto
_error
;
}
pInfo
->
pRes
=
pResBlock
;
pInfo
->
pRes
=
pResBlock
;
pInfo
->
multigroupResult
=
multigroupResult
;
pOperator
->
name
=
"FillOperator"
;
pOperator
->
blocking
=
false
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
name
=
"FillOperator"
;
pOperator
->
blocking
=
false
;
pOperator
->
status
=
OP_NOT_OPENED
;
pOperator
->
operatorType
=
QUERY_NODE_PHYSICAL_PLAN_FILL
;
pOperator
->
exprSupp
.
pExprInfo
=
pExprInfo
;
pOperator
->
exprSupp
.
numOfExprs
=
num
;
pOperator
->
info
=
pInfo
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
exprSupp
.
pExprInfo
=
pExprInfo
;
pOperator
->
exprSupp
.
numOfExprs
=
num
;
pOperator
->
info
=
pInfo
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
fpSet
=
createOperatorFpSet
(
operatorDummyOpenFn
,
doFill
,
NULL
,
NULL
,
destroySFillOperatorInfo
,
NULL
,
NULL
,
NULL
);
...
...
@@ -4050,10 +4054,14 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
STimeWindowAggSupp
twSup
=
{
.
waterMark
=
pTableScanNode
->
watermark
,
.
calTrigger
=
pTableScanNode
->
triggerType
,
.
maxTs
=
INT64_MIN
};
tsdbReaderT
pDataReader
=
NULL
;
if
(
pHandle
->
vnode
)
{
pDataReader
=
doCreateDataReader
(
pTableScanNode
,
pHandle
,
pTableListInfo
,
(
uint64_t
)
queryId
,
taskId
,
pTagCond
);
}
else
{
getTableList
(
pHandle
->
meta
,
pScanPhyNode
,
pTableListInfo
,
pTagCond
);
if
(
pHandle
)
{
if
(
pHandle
->
vnode
)
{
pDataReader
=
doCreateDataReader
(
pTableScanNode
,
pHandle
,
pTableListInfo
,
(
uint64_t
)
queryId
,
taskId
,
pTagCond
);
}
else
{
getTableList
(
pHandle
->
meta
,
pScanPhyNode
,
pTableListInfo
,
pTagCond
);
}
}
if
(
pDataReader
==
NULL
&&
terrno
!=
0
)
{
...
...
@@ -4087,6 +4095,46 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
}
return
createTagScanOperatorInfo
(
pHandle
,
pScanPhyNode
,
pTableListInfo
,
pTaskInfo
);
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN
==
type
)
{
SBlockDistScanPhysiNode
*
pBlockNode
=
(
SBlockDistScanPhysiNode
*
)
pPhyNode
;
pTableListInfo
->
pTableList
=
taosArrayInit
(
4
,
sizeof
(
STableKeyInfo
));
if
(
pBlockNode
->
tableType
==
TSDB_SUPER_TABLE
)
{
int32_t
code
=
tsdbGetAllTableList
(
pHandle
->
meta
,
pBlockNode
->
uid
,
pTableListInfo
->
pTableList
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pTaskInfo
->
code
=
terrno
;
return
NULL
;
}
}
else
{
// Create one table group.
STableKeyInfo
info
=
{.
lastKey
=
0
,
.
uid
=
pBlockNode
->
uid
};
taosArrayPush
(
pTableListInfo
->
pTableList
,
&
info
);
}
SQueryTableDataCond
cond
=
{
0
};
{
cond
.
order
=
TSDB_ORDER_ASC
;
cond
.
numOfCols
=
1
;
cond
.
colList
=
taosMemoryCalloc
(
1
,
sizeof
(
SColumnInfo
));
if
(
cond
.
colList
==
NULL
)
{
terrno
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
NULL
;
}
cond
.
colList
->
colId
=
1
;
cond
.
colList
->
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
cond
.
colList
->
bytes
=
sizeof
(
TSKEY
);
cond
.
numOfTWindows
=
1
;
cond
.
twindows
=
taosMemoryCalloc
(
1
,
sizeof
(
STimeWindow
));
cond
.
twindows
[
0
]
=
(
STimeWindow
){.
skey
=
INT64_MIN
,
.
ekey
=
INT64_MAX
};
cond
.
suid
=
pBlockNode
->
suid
;
cond
.
type
=
BLOCK_LOAD_OFFSET_SEQ_ORDER
;
}
tsdbReaderT
*
pReader
=
tsdbReaderOpen
(
pHandle
->
vnode
,
&
cond
,
pTableListInfo
,
queryId
,
taskId
);
cleanupQueryTableDataCond
(
&
cond
);
return
createDataBlockInfoScanOperator
(
pReader
,
pHandle
,
cond
.
suid
,
pBlockNode
,
pTaskInfo
);
}
else
{
ASSERT
(
0
);
}
...
...
@@ -4270,7 +4318,7 @@ SArray* extractColumnInfo(SNodeList* pNodeList) {
SColumn
c
=
{
0
};
c
.
slotId
=
pNode
->
slotId
;
c
.
colId
=
pNode
->
slotId
;
c
.
type
=
pValNode
->
node
.
type
;
c
.
type
=
pValNode
->
node
.
type
;
c
.
bytes
=
pValNode
->
node
.
resType
.
bytes
;
c
.
scale
=
pValNode
->
node
.
resType
.
scale
;
c
.
precision
=
pValNode
->
node
.
resType
.
precision
;
...
...
@@ -4284,8 +4332,7 @@ SArray* extractColumnInfo(SNodeList* pNodeList) {
tsdbReaderT
doCreateDataReader
(
STableScanPhysiNode
*
pTableScanNode
,
SReadHandle
*
pHandle
,
STableListInfo
*
pTableListInfo
,
uint64_t
queryId
,
uint64_t
taskId
,
SNode
*
pTagCond
)
{
int32_t
code
=
getTableList
(
pHandle
->
meta
,
&
pTableScanNode
->
scan
,
pTableListInfo
,
pTagCond
);
int32_t
code
=
getTableList
(
pHandle
->
meta
,
&
pTableScanNode
->
scan
,
pTableListInfo
,
pTagCond
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
...
...
@@ -4374,7 +4421,7 @@ int32_t decodeOperator(SOperatorInfo* ops, const char* result, int32_t length) {
ASSERT
(
length
==
*
(
int32_t
*
)
result
);
const
char
*
data
=
result
+
sizeof
(
int32_t
);
code
=
ops
->
fpSet
.
decodeResultRow
(
ops
,
(
char
*
)
data
);
code
=
ops
->
fpSet
.
decodeResultRow
(
ops
,
(
char
*
)
data
);
if
(
code
!=
TDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
ca7057ce
此差异已折叠。
点击以展开。
source/libs/function/inc/builtinsimpl.h
浏览文件 @
ca7057ce
...
...
@@ -192,6 +192,8 @@ int32_t twaFunction(SqlFunctionCtx *pCtx);
int32_t
twaFinalize
(
struct
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getSelectivityFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
blockDistSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
int32_t
blockDistFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
blockDistFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
ca7057ce
...
...
@@ -419,7 +419,7 @@ static int32_t translateTopBot(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
return
TSDB_CODE_SUCCESS
;
}
int32_t
topCreateMergePara
(
SNodeList
*
pRawParameters
,
SNode
*
pPartialRes
,
SNodeList
**
pParameters
)
{
int32_t
top
Bot
CreateMergePara
(
SNodeList
*
pRawParameters
,
SNode
*
pPartialRes
,
SNodeList
**
pParameters
)
{
int32_t
code
=
nodesListMakeAppend
(
pParameters
,
pPartialRes
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListStrictAppend
(
*
pParameters
,
nodesCloneNode
(
nodesListGetNode
(
pRawParameters
,
1
)));
...
...
@@ -427,65 +427,6 @@ int32_t topCreateMergePara(SNodeList* pRawParameters, SNode* pPartialRes, SNodeL
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateTopBotImpl
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
,
bool
isPartial
)
{
int32_t
numOfParams
=
LIST_LENGTH
(
pFunc
->
pParameterList
);
if
(
isPartial
)
{
if
(
2
!=
numOfParams
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
uint8_t
para1Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
uint8_t
para2Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
))
->
resType
.
type
;
if
(
!
IS_NUMERIC_TYPE
(
para1Type
)
||
!
IS_INTEGER_TYPE
(
para2Type
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
// param1
SNode
*
pParamNode1
=
nodesListGetNode
(
pFunc
->
pParameterList
,
1
);
if
(
nodeType
(
pParamNode1
)
!=
QUERY_NODE_VALUE
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
SValueNode
*
pValue
=
(
SValueNode
*
)
pParamNode1
;
if
(
pValue
->
node
.
resType
.
type
!=
TSDB_DATA_TYPE_BIGINT
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
if
(
pValue
->
datum
.
i
<
1
||
pValue
->
datum
.
i
>
100
)
{
return
invaildFuncParaValueErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
pValue
->
notReserved
=
true
;
// set result type
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
getTopBotInfoSize
(
pValue
->
datum
.
i
)
+
VARSTR_HEADER_SIZE
,
.
type
=
TSDB_DATA_TYPE_BINARY
};
}
else
{
if
(
1
!=
numOfParams
)
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
uint8_t
para1Type
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
if
(
TSDB_DATA_TYPE_BINARY
!=
para1Type
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
// Do nothing. We can only access output of partial functions as input,
// so original input type cannot be obtained, resType will be set same
// as original function input type after merge function created.
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateTopBotPartial
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
return
translateTopBotImpl
(
pFunc
,
pErrBuf
,
len
,
true
);
}
static
int32_t
translateTopBotMerge
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
return
translateTopBotImpl
(
pFunc
,
pErrBuf
,
len
,
false
);
}
static
int32_t
translateSpread
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
if
(
1
!=
LIST_LENGTH
(
pFunc
->
pParameterList
))
{
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
...
...
@@ -1735,31 +1676,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
processFunc
=
topFunction
,
.
finalizeFunc
=
topBotFinalize
,
.
combineFunc
=
topCombine
,
.
pPartialFunc
=
"_top_partial"
,
.
pMergeFunc
=
"_top_merge"
,
// .createMergeParaFuc = topCreateMergePara
},
{
.
name
=
"_top_partial"
,
.
type
=
FUNCTION_TYPE_TOP_PARTIAL
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_INDEFINITE_ROWS_FUNC
,
.
translateFunc
=
translateTopBotPartial
,
.
getEnvFunc
=
getTopBotFuncEnv
,
.
initFunc
=
topBotFunctionSetup
,
.
processFunc
=
topFunction
,
.
finalizeFunc
=
topBotPartialFinalize
,
.
combineFunc
=
topCombine
,
},
{
.
name
=
"_top_merge"
,
.
type
=
FUNCTION_TYPE_TOP_MERGE
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_INDEFINITE_ROWS_FUNC
,
.
translateFunc
=
translateTopBotMerge
,
.
getEnvFunc
=
getTopBotMergeFuncEnv
,
.
initFunc
=
functionSetup
,
.
processFunc
=
topFunctionMerge
,
.
finalizeFunc
=
topBotMergeFinalize
,
.
combineFunc
=
topCombine
,
.
pPartialFunc
=
"top"
,
.
pMergeFunc
=
"top"
,
.
createMergeParaFuc
=
topBotCreateMergePara
},
{
.
name
=
"bottom"
,
...
...
@@ -1771,30 +1690,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
processFunc
=
bottomFunction
,
.
finalizeFunc
=
topBotFinalize
,
.
combineFunc
=
bottomCombine
,
.
pPartialFunc
=
"_bottom_partial"
,
.
pMergeFunc
=
"_bottom_merge"
},
{
.
name
=
"_bottom_partial"
,
.
type
=
FUNCTION_TYPE_BOTTOM_PARTIAL
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_INDEFINITE_ROWS_FUNC
,
.
translateFunc
=
translateTopBotPartial
,
.
getEnvFunc
=
getTopBotFuncEnv
,
.
initFunc
=
topBotFunctionSetup
,
.
processFunc
=
bottomFunction
,
.
finalizeFunc
=
topBotPartialFinalize
,
.
combineFunc
=
bottomCombine
,
},
{
.
name
=
"_bottom_merge"
,
.
type
=
FUNCTION_TYPE_BOTTOM_MERGE
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_INDEFINITE_ROWS_FUNC
,
.
translateFunc
=
translateTopBotMerge
,
.
getEnvFunc
=
getTopBotMergeFuncEnv
,
.
initFunc
=
functionSetup
,
.
processFunc
=
bottomFunctionMerge
,
.
finalizeFunc
=
topBotMergeFinalize
,
.
combineFunc
=
bottomCombine
,
.
pPartialFunc
=
"bottom"
,
.
pMergeFunc
=
"bottom"
,
.
createMergeParaFuc
=
topBotCreateMergePara
},
{
.
name
=
"spread"
,
...
...
@@ -2524,7 +2422,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
getEnvFunc
=
getSelectivityFuncEnv
,
// todo remove this function later.
.
initFunc
=
functionSetup
,
.
processFunc
=
NULL
,
.
finalizeFunc
=
NULL
.
finalizeFunc
=
NULL
,
.
pPartialFunc
=
"_select_value"
,
.
pMergeFunc
=
"_select_value"
},
{
.
name
=
"_block_dist"
,
...
...
@@ -2532,6 +2432,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
translateFunc
=
translateBlockDistFunc
,
.
getEnvFunc
=
getBlockDistFuncEnv
,
.
initFunc
=
blockDistSetup
,
.
processFunc
=
blockDistFunction
,
.
finalizeFunc
=
blockDistFinalize
},
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
ca7057ce
...
...
@@ -67,8 +67,7 @@ typedef struct STopBotResItem {
typedef
struct
STopBotRes
{
int32_t
maxSize
;
int16_t
type
;
// store the original input type, used in merge function
int32_t
numOfItems
;
int16_t
type
;
STopBotResItem
*
pItems
;
}
STopBotRes
;
...
...
@@ -2563,9 +2562,6 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
}
static
void
firstLastTransferInfo
(
SFirstLastRes
*
pInput
,
SFirstLastRes
*
pOutput
,
bool
isFirst
)
{
if
(
!
pInput
->
hasResult
)
{
return
;
}
pOutput
->
bytes
=
pInput
->
bytes
;
TSKEY
*
tsIn
=
(
TSKEY
*
)(
pInput
->
buf
+
pInput
->
bytes
);
TSKEY
*
tsOut
=
(
TSKEY
*
)(
pOutput
->
buf
+
pInput
->
bytes
);
...
...
@@ -2599,7 +2595,9 @@ static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx* pCtx, bool isFirstQuer
firstLastTransferInfo
(
pInputInfo
,
pInfo
,
isFirstQuery
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
1
,
1
);
int32_t
numOfElems
=
pInputInfo
->
hasResult
?
1
:
0
;
SET_VAL
(
GET_RES_INFO
(
pCtx
),
numOfElems
,
1
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -2624,6 +2622,7 @@ int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t
firstLastPartialFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SResultRowEntryInfo
*
pEntryInfo
=
GET_RES_INFO
(
pCtx
);
SFirstLastRes
*
pRes
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
int32_t
resultBytes
=
getFirstLastInfoSize
(
pRes
->
bytes
);
char
*
res
=
taosMemoryCalloc
(
resultBytes
+
VARSTR_HEADER_SIZE
,
sizeof
(
char
));
...
...
@@ -2872,12 +2871,6 @@ bool getTopBotFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
return
true
;
}
bool
getTopBotMergeFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
)
{
// intermediate result is binary and length contains VAR header size
pEnv
->
calcMemSize
=
pFunc
->
node
.
resType
.
bytes
;
return
true
;
}
bool
topBotFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResInfo
)
{
if
(
!
functionSetup
(
pCtx
,
pResInfo
))
{
return
false
;
...
...
@@ -2952,50 +2945,6 @@ int32_t bottomFunction(SqlFunctionCtx* pCtx) {
return
TSDB_CODE_SUCCESS
;
}
static
void
topBotTransferInfo
(
SqlFunctionCtx
*
pCtx
,
STopBotRes
*
pInput
,
bool
isTopQuery
)
{
for
(
int32_t
i
=
0
;
i
<
pInput
->
numOfItems
;
i
++
)
{
addResult
(
pCtx
,
&
pInput
->
pItems
[
i
],
pInput
->
type
,
isTopQuery
);
}
}
int32_t
topFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SResultRowEntryInfo
*
pEntryInfo
=
GET_RES_INFO
(
pCtx
);
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
ASSERT
(
pCol
->
info
.
type
==
TSDB_DATA_TYPE_BINARY
);
int32_t
start
=
pInput
->
startRowIndex
;
char
*
data
=
colDataGetData
(
pCol
,
start
);
STopBotRes
*
pInputInfo
=
(
STopBotRes
*
)
varDataVal
(
data
);
STopBotRes
*
pInfo
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
pInfo
->
maxSize
=
pInputInfo
->
maxSize
;
pInfo
->
type
=
pInputInfo
->
type
;
topBotTransferInfo
(
pCtx
,
pInputInfo
,
true
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
pEntryInfo
->
numOfRes
,
pEntryInfo
->
numOfRes
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
bottomFunctionMerge
(
SqlFunctionCtx
*
pCtx
)
{
SResultRowEntryInfo
*
pEntryInfo
=
GET_RES_INFO
(
pCtx
);
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pCol
=
pInput
->
pData
[
0
];
ASSERT
(
pCol
->
info
.
type
==
TSDB_DATA_TYPE_BINARY
);
int32_t
start
=
pInput
->
startRowIndex
;
char
*
data
=
colDataGetData
(
pCol
,
start
);
STopBotRes
*
pInputInfo
=
(
STopBotRes
*
)
varDataVal
(
data
);
STopBotRes
*
pInfo
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
pInfo
->
maxSize
=
pInputInfo
->
maxSize
;
pInfo
->
type
=
pInputInfo
->
type
;
topBotTransferInfo
(
pCtx
,
pInputInfo
,
false
);
SET_VAL
(
GET_RES_INFO
(
pCtx
),
pEntryInfo
->
numOfRes
,
pEntryInfo
->
numOfRes
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
topBotResComparFn
(
const
void
*
p1
,
const
void
*
p2
,
const
void
*
param
)
{
uint16_t
type
=
*
(
uint16_t
*
)
param
;
...
...
@@ -3044,8 +2993,6 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
// allocate the buffer and keep the data of this row into the new allocated buffer
pEntryInfo
->
numOfRes
++
;
// accumulate number of items for each vgroup, this info is needed for merge
pRes
->
numOfItems
++
;
taosheapsort
((
void
*
)
pItems
,
sizeof
(
STopBotResItem
),
pEntryInfo
->
numOfRes
,
(
const
void
*
)
&
type
,
topBotResComparFn
,
!
isTopQuery
);
}
else
{
// replace the minimum value in the result
...
...
@@ -3144,7 +3091,7 @@ void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
releaseBufPage
(
pCtx
->
pBuf
,
pPage
);
}
int32_t
topBotFinalize
Impl
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
,
bool
isMerge
)
{
int32_t
topBotFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SResultRowEntryInfo
*
pEntryInfo
=
GET_RES_INFO
(
pCtx
);
STopBotRes
*
pRes
=
GET_ROWCELL_INTERBUF
(
pEntryInfo
);
...
...
@@ -3164,39 +3111,13 @@ int32_t topBotFinalizeImpl(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, bool isMer
colDataAppend
(
pCol
,
currentRow
,
(
const
char
*
)
&
pItem
->
v
.
i
,
false
);
}
if
(
!
isMerge
)
{
setSelectivityValue
(
pCtx
,
pBlock
,
&
pRes
->
pItems
[
i
].
tuplePos
,
currentRow
);
}
setSelectivityValue
(
pCtx
,
pBlock
,
&
pRes
->
pItems
[
i
].
tuplePos
,
currentRow
);
currentRow
+=
1
;
}
return
pEntryInfo
->
numOfRes
;
}
int32_t
topBotFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
return
topBotFinalizeImpl
(
pCtx
,
pBlock
,
false
);
}
int32_t
topBotMergeFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
return
topBotFinalizeImpl
(
pCtx
,
pBlock
,
true
);
}
int32_t
topBotPartialFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SResultRowEntryInfo
*
pEntryInfo
=
GET_RES_INFO
(
pCtx
);
STopBotRes
*
pRes
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
int32_t
resultBytes
=
getTopBotInfoSize
(
pRes
->
maxSize
);
char
*
res
=
taosMemoryCalloc
(
resultBytes
+
VARSTR_HEADER_SIZE
,
sizeof
(
char
));
memcpy
(
varDataVal
(
res
),
pRes
,
resultBytes
);
varDataSetLen
(
res
,
resultBytes
);
int32_t
slotId
=
pCtx
->
pExpr
->
base
.
resSchema
.
slotId
;
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
colDataAppend
(
pCol
,
pBlock
->
info
.
rows
,
res
,
false
);
taosMemoryFree
(
res
);
return
1
;
}
void
addResult
(
SqlFunctionCtx
*
pCtx
,
STopBotResItem
*
pSourceItem
,
int16_t
type
,
bool
isTopQuery
)
{
SResultRowEntryInfo
*
pEntryInfo
=
GET_RES_INFO
(
pCtx
);
STopBotRes
*
pRes
=
getTopBotOutputInfo
(
pCtx
);
...
...
@@ -3211,8 +3132,6 @@ void addResult(SqlFunctionCtx* pCtx, STopBotResItem* pSourceItem, int16_t type,
pItem
->
tuplePos
.
pageId
=
-
1
;
replaceTupleData
(
&
pItem
->
tuplePos
,
&
pSourceItem
->
tuplePos
);
pEntryInfo
->
numOfRes
++
;
// accumulate number of items for each vgroup, this info is needed for merge
pRes
->
numOfItems
++
;
taosheapsort
((
void
*
)
pItems
,
sizeof
(
STopBotResItem
),
pEntryInfo
->
numOfRes
,
(
const
void
*
)
&
type
,
topBotResComparFn
,
!
isTopQuery
);
}
else
{
// replace the minimum value in the result
...
...
@@ -5004,7 +4923,19 @@ int32_t twaFinalize(struct SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return
functionFinalize
(
pCtx
,
pBlock
);
}
bool
blockDistSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
)
{
if
(
!
functionSetup
(
pCtx
,
pResultInfo
))
{
return
false
;
}
STableBlockDistInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
pInfo
->
minRows
=
INT32_MAX
;
return
true
;
}
int32_t
blockDistFunction
(
SqlFunctionCtx
*
pCtx
)
{
const
int32_t
BLOCK_DIST_RESULT_ROWS
=
24
;
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pInputCol
=
pInput
->
pData
[
0
];
...
...
@@ -5022,6 +4953,11 @@ int32_t blockDistFunction(SqlFunctionCtx* pCtx) {
pDistInfo
->
totalRows
+=
p1
.
totalRows
;
pDistInfo
->
numOfFiles
+=
p1
.
numOfFiles
;
pDistInfo
->
defMinRows
=
p1
.
defMinRows
;
pDistInfo
->
defMaxRows
=
p1
.
defMaxRows
;
pDistInfo
->
rowSize
=
p1
.
rowSize
;
pDistInfo
->
numOfSmallBlocks
=
p1
.
numOfSmallBlocks
;
if
(
pDistInfo
->
minRows
>
p1
.
minRows
)
{
pDistInfo
->
minRows
=
p1
.
minRows
;
}
...
...
@@ -5033,7 +4969,7 @@ int32_t blockDistFunction(SqlFunctionCtx* pCtx) {
pDistInfo
->
blockRowsHisto
[
i
]
+=
p1
.
blockRowsHisto
[
i
];
}
pResInfo
->
numOfRes
=
1
;
pResInfo
->
numOfRes
=
BLOCK_DIST_RESULT_ROWS
;
// default output rows
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -5045,7 +4981,7 @@ int32_t tSerializeBlockDistInfo(void* buf, int32_t bufLen, const STableBlockDist
if
(
tEncodeU32
(
&
encoder
,
pInfo
->
rowSize
)
<
0
)
return
-
1
;
if
(
tEncodeU16
(
&
encoder
,
pInfo
->
numOfFiles
)
<
0
)
return
-
1
;
if
(
tEncodeU32
(
&
encoder
,
pInfo
->
rowSize
)
<
0
)
return
-
1
;
if
(
tEncodeU32
(
&
encoder
,
pInfo
->
numOfBlocks
)
<
0
)
return
-
1
;
if
(
tEncodeU32
(
&
encoder
,
pInfo
->
numOfTables
)
<
0
)
return
-
1
;
if
(
tEncodeU64
(
&
encoder
,
pInfo
->
totalSize
)
<
0
)
return
-
1
;
...
...
@@ -5076,7 +5012,7 @@ int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo
if
(
tDecodeU32
(
&
decoder
,
&
pInfo
->
rowSize
)
<
0
)
return
-
1
;
if
(
tDecodeU16
(
&
decoder
,
&
pInfo
->
numOfFiles
)
<
0
)
return
-
1
;
if
(
tDecodeU32
(
&
decoder
,
&
pInfo
->
rowSize
)
<
0
)
return
-
1
;
if
(
tDecodeU32
(
&
decoder
,
&
pInfo
->
numOfBlocks
)
<
0
)
return
-
1
;
if
(
tDecodeU32
(
&
decoder
,
&
pInfo
->
numOfTables
)
<
0
)
return
-
1
;
if
(
tDecodeU64
(
&
decoder
,
&
pInfo
->
totalSize
)
<
0
)
return
-
1
;
...
...
@@ -5098,32 +5034,29 @@ int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo
int32_t
blockDistFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
char
*
pData
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
STableBlockDistInfo
*
pData
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SColumnInfoData
*
pColInfo
=
taosArrayGet
(
pBlock
->
pDataBlock
,
0
);
int32_t
row
=
0
;
STableBlockDistInfo
info
=
{
0
};
tDeserializeBlockDistInfo
(
varDataVal
(
pData
),
varDataLen
(
pData
),
&
info
);
char
st
[
256
]
=
{
0
};
double
totalRawSize
=
pData
->
totalRows
*
pData
->
rowSize
;
int32_t
len
=
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"
Blocks=[%d] Size=[%.3fKb] Average_Block_size=[%.3fKb] Compression_Ratio=[%.3f
]"
,
info
.
numOfBlocks
,
info
.
totalSize
/
1024
.
0
,
info
.
totalSize
/
(
info
.
numOfBlocks
*
1024
.
0
)
,
info
.
totalSize
/
(
info
.
totalRows
*
info
.
rowSize
*
1
.
0
)
);
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"
Total_Blocks=[%d] Total_Size=[%.2f Kb] Average_size=[%.2f Kb] Compression_Ratio=[%.2f %c
]"
,
pData
->
numOfBlocks
,
pData
->
totalSize
/
1024
.
0
,
((
double
)
pData
->
totalSize
)
/
pData
->
numOfBlocks
,
pData
->
totalSize
*
100
/
totalRawSize
,
'%'
);
varDataSetLen
(
st
,
len
);
colDataAppend
(
pColInfo
,
row
++
,
st
,
false
);
len
=
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"Total_Rows=[%
ld] MinRows=[%d] MaxRows=[%d] Averge_Rows=[%ld] Inmem_Rows=[%d
]"
,
info
.
totalRows
,
info
.
minRows
,
info
.
maxRows
,
info
.
totalRows
/
info
.
numOfBlocks
,
info
.
numOfInmemRow
s
);
len
=
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"Total_Rows=[%
"
PRId64
"] Inmem_Rows=[%d] MinRows=[%d] MaxRows=[%d] Average_Rows=[%"
PRId64
"
]"
,
pData
->
totalRows
,
pData
->
numOfInmemRows
,
pData
->
minRows
,
pData
->
maxRows
,
pData
->
totalRows
/
pData
->
numOfBlock
s
);
varDataSetLen
(
st
,
len
);
colDataAppend
(
pColInfo
,
row
++
,
st
,
false
);
len
=
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"Total_Tables=[%d] Total_Files=[%d] Total_Vgroups=[%d]"
,
info
.
numOfTables
,
info
.
numOfFiles
,
0
);
len
=
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"Total_Tables=[%d] Total_Files=[%d] Total_Vgroups=[%d]"
,
pData
->
numOfTables
,
pData
->
numOfFiles
,
0
);
varDataSetLen
(
st
,
len
);
colDataAppend
(
pColInfo
,
row
++
,
st
,
false
);
...
...
@@ -5135,40 +5068,56 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t
maxVal
=
0
;
int32_t
minVal
=
INT32_MAX
;
for
(
int32_t
i
=
0
;
i
<
sizeof
(
info
.
blockRowsHisto
)
/
sizeof
(
info
.
blockRowsHisto
[
0
]
);
++
i
)
{
if
(
maxVal
<
info
.
blockRowsHisto
[
i
])
{
maxVal
=
info
.
blockRowsHisto
[
i
];
for
(
int32_t
i
=
0
;
i
<
tListLen
(
pData
->
blockRowsHisto
);
++
i
)
{
if
(
maxVal
<
pData
->
blockRowsHisto
[
i
])
{
maxVal
=
pData
->
blockRowsHisto
[
i
];
}
if
(
minVal
>
info
.
blockRowsHisto
[
i
])
{
minVal
=
info
.
blockRowsHisto
[
i
];
if
(
minVal
>
pData
->
blockRowsHisto
[
i
])
{
minVal
=
pData
->
blockRowsHisto
[
i
];
}
}
int32_t
delta
=
maxVal
-
minVal
;
int32_t
step
=
delta
/
50
;
if
(
step
==
0
)
{
step
=
1
;
}
int32_t
numOfBuckets
=
sizeof
(
info
.
blockRowsHisto
)
/
sizeof
(
info
.
blockRowsHisto
[
0
]);
int32_t
bucketRange
=
(
info
.
maxRows
-
info
.
minRows
)
/
numOfBuckets
;
int32_t
numOfBuckets
=
sizeof
(
pData
->
blockRowsHisto
)
/
sizeof
(
pData
->
blockRowsHisto
[
0
]);
int32_t
bucketRange
=
(
pData
->
maxRows
-
pData
->
minRows
)
/
numOfBuckets
;
bool
singleModel
=
false
;
if
(
bucketRange
==
0
)
{
singleModel
=
true
;
step
=
20
;
bucketRange
=
(
pData
->
defMaxRows
-
pData
->
defMinRows
)
/
numOfBuckets
;
}
for
(
int32_t
i
=
0
;
i
<
20
;
++
i
)
{
len
+=
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"%04d |"
,
info
.
defMinRows
+
bucketRange
*
(
i
+
1
));
for
(
int32_t
i
=
0
;
i
<
tListLen
(
pData
->
blockRowsHisto
);
++
i
)
{
len
=
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"%04d |"
,
pData
->
defMinRows
+
bucketRange
*
(
i
+
1
));
int32_t
num
=
0
;
if
(
singleModel
&&
pData
->
blockRowsHisto
[
i
]
>
0
)
{
num
=
20
;
}
else
{
num
=
(
pData
->
blockRowsHisto
[
i
]
+
step
-
1
)
/
step
;
}
int32_t
num
=
(
info
.
blockRowsHisto
[
i
]
+
step
-
1
)
/
step
;
for
(
int32_t
j
=
0
;
j
<
num
;
++
j
)
{
int32_t
x
=
sprintf
(
st
+
VARSTR_HEADER_SIZE
+
len
,
"%c"
,
'|'
);
len
+=
x
;
}
double
v
=
info
.
blockRowsHisto
[
i
]
*
100
.
0
/
info
.
numOfBlocks
;
len
+=
sprintf
(
st
+
VARSTR_HEADER_SIZE
+
len
,
" %d (%.
3f%c)"
,
info
.
blockRowsHisto
[
i
],
v
,
'%'
);
double
v
=
pData
->
blockRowsHisto
[
i
]
*
100
.
0
/
pData
->
numOfBlocks
;
len
+=
sprintf
(
st
+
VARSTR_HEADER_SIZE
+
len
,
" %d (%.
2f%c)"
,
pData
->
blockRowsHisto
[
i
],
v
,
'%'
);
printf
(
"%s
\n
"
,
st
);
varDataSetLen
(
st
,
len
);
colDataAppend
(
pColInfo
,
row
++
,
st
,
false
);
}
return
row
;
return
TSDB_CODE_SUCCESS
;
}
typedef
struct
SDerivInfo
{
...
...
source/libs/function/src/tudf.c
浏览文件 @
ca7057ce
...
...
@@ -972,6 +972,11 @@ void releaseUdfFuncHandle(char* udfName) {
}
int32_t
cleanUpUdfs
()
{
int8_t
initialized
=
atomic_load_8
(
&
gUdfdProxy
.
initialized
);
if
(
!
initialized
)
{
return
TSDB_CODE_SUCCESS
;
}
uv_mutex_lock
(
&
gUdfdProxy
.
udfStubsMutex
);
int32_t
i
=
0
;
SArray
*
udfStubs
=
taosArrayInit
(
16
,
sizeof
(
SUdfcFuncStub
));
...
...
source/libs/parser/src/parAstParser.c
浏览文件 @
ca7057ce
...
...
@@ -419,6 +419,24 @@ static int32_t collectMetaKeyFromDelete(SCollectMetaKeyCxt* pCxt, SDeleteStmt* p
return
collectMetaKeyFromRealTableImpl
(
pCxt
,
(
SRealTableNode
*
)
pStmt
->
pFromTable
,
AUTH_TYPE_WRITE
);
}
static
int32_t
collectMetaKeyFromShowBlockDist
(
SCollectMetaKeyCxt
*
pCxt
,
SShowTableDistributedStmt
*
pStmt
)
{
SName
name
=
{.
type
=
TSDB_TABLE_NAME_T
,
.
acctId
=
pCxt
->
pParseCxt
->
acctId
};
strcpy
(
name
.
dbname
,
pStmt
->
dbName
);
strcpy
(
name
.
tname
,
pStmt
->
tableName
);
int32_t
code
=
catalogRemoveTableMeta
(
pCxt
->
pParseCxt
->
pCatalog
,
&
name
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
reserveTableMetaInCache
(
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
pStmt
->
tableName
,
pCxt
->
pMetaCache
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
reserveTableVgroupInCache
(
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
pStmt
->
tableName
,
pCxt
->
pMetaCache
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
reserveDbVgInfoInCache
(
pCxt
->
pParseCxt
->
acctId
,
pStmt
->
dbName
,
pCxt
->
pMetaCache
);
}
return
code
;
}
static
int32_t
collectMetaKeyFromQuery
(
SCollectMetaKeyCxt
*
pCxt
,
SNode
*
pStmt
)
{
pCxt
->
pStmt
=
pStmt
;
switch
(
nodeType
(
pStmt
))
{
...
...
@@ -497,6 +515,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
return
collectMetaKeyFromShowTransactions
(
pCxt
,
(
SShowStmt
*
)
pStmt
);
case
QUERY_NODE_DELETE_STMT
:
return
collectMetaKeyFromDelete
(
pCxt
,
(
SDeleteStmt
*
)
pStmt
);
case
QUERY_NODE_SHOW_TABLE_DISTRIBUTED_STMT
:
return
collectMetaKeyFromShowBlockDist
(
pCxt
,
(
SShowTableDistributedStmt
*
)
pStmt
);
default:
break
;
}
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
ca7057ce
...
...
@@ -1082,13 +1082,89 @@ static int32_t partTagsOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub
return
code
;
}
static
bool
eliminateProjOptMayBeOptimized
(
SLogicNode
*
pNode
)
{
//TODO: enable this optimization after new mechanising that map projection and targets of project node
if
(
NULL
!=
pNode
->
pParent
)
{
return
false
;
}
if
(
QUERY_NODE_LOGIC_PLAN_PROJECT
!=
nodeType
(
pNode
)
||
1
!=
LIST_LENGTH
(
pNode
->
pChildren
))
{
return
false
;
}
SProjectLogicNode
*
pProjectNode
=
(
SProjectLogicNode
*
)
pNode
;
if
(
-
1
!=
pProjectNode
->
limit
||
-
1
!=
pProjectNode
->
slimit
||
-
1
!=
pProjectNode
->
offset
||
-
1
!=
pProjectNode
->
soffset
)
{
return
false
;
}
SHashObj
*
pProjColNameHash
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
SNode
*
pProjection
;
FOREACH
(
pProjection
,
pProjectNode
->
pProjections
)
{
SExprNode
*
pExprNode
=
(
SExprNode
*
)
pProjection
;
if
(
QUERY_NODE_COLUMN
!=
nodeType
(
pExprNode
))
{
taosHashCleanup
(
pProjColNameHash
);
return
false
;
}
char
*
projColumnName
=
((
SColumnNode
*
)
pProjection
)
->
colName
;
int32_t
*
pExist
=
taosHashGet
(
pProjColNameHash
,
projColumnName
,
strlen
(
projColumnName
));
if
(
NULL
!=
pExist
)
{
taosHashCleanup
(
pProjColNameHash
);
return
false
;
}
else
{
int32_t
exist
=
1
;
taosHashPut
(
pProjColNameHash
,
projColumnName
,
strlen
(
projColumnName
),
&
exist
,
sizeof
(
exist
));
}
}
taosHashCleanup
(
pProjColNameHash
);
return
true
;
}
static
int32_t
eliminateProjOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
SProjectLogicNode
*
pProjectNode
)
{
SLogicNode
*
pChild
=
(
SLogicNode
*
)
nodesListGetNode
(
pProjectNode
->
node
.
pChildren
,
0
);
SNodeList
*
pNewChildTargets
=
nodesMakeList
();
SNode
*
pProjection
=
NULL
;
FOREACH
(
pProjection
,
pProjectNode
->
pProjections
)
{
SNode
*
pChildTarget
=
NULL
;
FOREACH
(
pChildTarget
,
pChild
->
pTargets
)
{
if
(
strcmp
(((
SColumnNode
*
)
pProjection
)
->
colName
,
((
SColumnNode
*
)
pChildTarget
)
->
colName
)
==
0
)
{
nodesListAppend
(
pNewChildTargets
,
nodesCloneNode
(
pChildTarget
));
break
;
}
}
}
nodesDestroyList
(
pChild
->
pTargets
);
pChild
->
pTargets
=
pNewChildTargets
;
int32_t
code
=
replaceLogicNode
(
pLogicSubplan
,
(
SLogicNode
*
)
pProjectNode
,
pChild
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
NODES_CLEAR_LIST
(
pProjectNode
->
node
.
pChildren
);
nodesDestroyNode
((
SNode
*
)
pProjectNode
);
}
return
code
;
}
static
int32_t
eliminateProjOptimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
SProjectLogicNode
*
pProjectNode
=
(
SProjectLogicNode
*
)
optFindPossibleNode
(
pLogicSubplan
->
pNode
,
eliminateProjOptMayBeOptimized
);
if
(
NULL
==
pProjectNode
)
{
return
TSDB_CODE_SUCCESS
;
}
return
eliminateProjOptimizeImpl
(
pCxt
,
pLogicSubplan
,
pProjectNode
);
}
// clang-format off
static
const
SOptimizeRule
optimizeRuleSet
[]
=
{
{.
pName
=
"OptimizeScanData"
,
.
optimizeFunc
=
osdOptimize
},
{.
pName
=
"ConditionPushDown"
,
.
optimizeFunc
=
cpdOptimize
},
{.
pName
=
"OrderByPrimaryKey"
,
.
optimizeFunc
=
opkOptimize
},
{.
pName
=
"SmaIndex"
,
.
optimizeFunc
=
smaOptimize
},
{.
pName
=
"PartitionByTags"
,
.
optimizeFunc
=
partTagsOptimize
}
{.
pName
=
"PartitionByTags"
,
.
optimizeFunc
=
partTagsOptimize
},
{.
pName
=
"EliminateProject"
,
.
optimizeFunc
=
eliminateProjOptimize
}
};
// clang-format on
...
...
source/libs/planner/src/planUtil.c
浏览文件 @
ca7057ce
...
...
@@ -107,6 +107,7 @@ int32_t createColumnByRewriteExpr(SNode* pExpr, SNodeList** pList) {
int32_t
replaceLogicNode
(
SLogicSubplan
*
pSubplan
,
SLogicNode
*
pOld
,
SLogicNode
*
pNew
)
{
if
(
NULL
==
pOld
->
pParent
)
{
pSubplan
->
pNode
=
(
SLogicNode
*
)
pNew
;
pNew
->
pParent
=
NULL
;
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/planner/test/planOptimizeTest.cpp
浏览文件 @
ca7057ce
...
...
@@ -52,3 +52,13 @@ TEST_F(PlanOptimizeTest, orderByPrimaryKey) {
run
(
"SELECT COUNT(*) FROM t1 INTERVAL(10S) ORDER BY _WSTARTTS DESC"
);
}
TEST_F
(
PlanOptimizeTest
,
eliminateProjection
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT c1, sum(c3) FROM t1 GROUP BY c1"
);
run
(
"SELECT c1 FROM t1"
);
run
(
"SELECT * FROM st1"
);
run
(
"SELECT c1 FROM st1s3"
);
//run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) order by 1 nulls first");
}
source/libs/qworker/src/qworker.c
浏览文件 @
ca7057ce
...
...
@@ -533,7 +533,7 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, int8_t taskType, int8_t ex
atomic_store_8
(
&
ctx
->
taskType
,
taskType
);
atomic_store_8
(
&
ctx
->
explain
,
explain
);
/*QW_TASK_DLOGL("subplan json string, len:%d, %s", qwMsg->msgLen, qwMsg->msg);*/
QW_TASK_DLOGL
(
"subplan json string, len:%d, %s"
,
qwMsg
->
msgLen
,
qwMsg
->
msg
);
code
=
qStringToSubplan
(
qwMsg
->
msg
,
&
plan
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
...
...
source/libs/stream/src/streamTask.c
浏览文件 @
ca7057ce
...
...
@@ -36,11 +36,11 @@ int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) {
if
(
tEncodeI32
(
pEncoder
,
pTask
->
taskId
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
inputType
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
status
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
sourceType
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
execType
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
sinkType
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
dispatchType
)
<
0
)
return
-
1
;
if
(
tEncodeI16
(
pEncoder
,
pTask
->
dispatchMsgType
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pTask
->
dataScan
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pTask
->
childId
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
pEncoder
,
pTask
->
nodeId
)
<
0
)
return
-
1
;
...
...
@@ -84,11 +84,11 @@ int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) {
if
(
tDecodeI32
(
pDecoder
,
&
pTask
->
taskId
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
inputType
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
status
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
sourceType
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
execType
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
sinkType
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
dispatchType
)
<
0
)
return
-
1
;
if
(
tDecodeI16
(
pDecoder
,
&
pTask
->
dispatchMsgType
)
<
0
)
return
-
1
;
if
(
tDecodeI8
(
pDecoder
,
&
pTask
->
dataScan
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pTask
->
childId
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
pDecoder
,
&
pTask
->
nodeId
)
<
0
)
return
-
1
;
...
...
tests/script/jenkins/basic.txt
浏览文件 @
ca7057ce
...
...
@@ -72,14 +72,14 @@
./test.sh -f tsim/stream/basic0.sim
./test.sh -f tsim/stream/basic1.sim
./test.sh -f tsim/stream/basic2.sim
#
./test.sh -f tsim/stream/distributeInterval0.sim
./test.sh -f tsim/stream/distributeInterval0.sim
# ./test.sh -f tsim/stream/distributesession0.sim
# ./test.sh -f tsim/stream/session0.sim
# ./test.sh -f tsim/stream/session1.sim
# ./test.sh -f tsim/stream/state0.sim
#
./test.sh -f tsim/stream/triggerInterval0.sim
./test.sh -f tsim/stream/triggerInterval0.sim
# ./test.sh -f tsim/stream/triggerSession0.sim
#
./test.sh -f tsim/stream/partitionby.sim
./test.sh -f tsim/stream/partitionby.sim
# ---- transaction
...
...
tests/script/tsim/sma/rsmaCreateInsertQuery.sim
浏览文件 @
ca7057ce
...
...
@@ -5,7 +5,7 @@ sleep 50
sql connect
print =============== create database with retentions
sql create database d0 retentions
15s:7d,1m:21d,15m
:365d;
sql create database d0 retentions
5s:7d,10s:21d,15s
:365d;
sql use d0
print =============== create super table and register rsma
...
...
@@ -29,6 +29,8 @@ sql insert into ct1 values(now, 10);
sql insert into ct1 values(now+1s, 1);
sql insert into ct1 values(now+2s, 100);
print =============== wait maxdelay 15+1 seconds for results
sleep 16000
print =============== select * from retention level 2 from memory
sql select * from ct1;
...
...
tests/system-test/1-insert/create_table_comment.py
已删除
100644 → 0
浏览文件 @
96434756
###################################################################
# 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
random
import
string
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
())
def
get_long_name
(
self
,
length
,
mode
=
"mixed"
):
"""
generate long name
mode could be numbers/letters/letters_mixed/mixed
"""
if
mode
==
"numbers"
:
population
=
string
.
digits
elif
mode
==
"letters"
:
population
=
string
.
ascii_letters
.
lower
()
elif
mode
==
"letters_mixed"
:
population
=
string
.
ascii_letters
.
upper
()
+
string
.
ascii_letters
.
lower
()
else
:
population
=
string
.
ascii_letters
.
lower
()
+
string
.
digits
return
""
.
join
(
random
.
choices
(
population
,
k
=
length
))
def
__create_tb
(
self
,
dbname
,
stbname
,
tbname
,
comment
):
tdSql
.
execute
(
f
'create database if not exists
{
dbname
}
'
)
tdSql
.
execute
(
f
'use
{
dbname
}
'
)
tdSql
.
execute
(
f
'create table
{
stbname
}
(ts timestamp,c0 int) tags(t0 int) '
)
tdSql
.
execute
(
f
'create table
{
tbname
}
using
{
stbname
}
tags(1) comment "
{
comment
}
"'
)
def
__create_normaltb
(
self
,
dbname
,
tbname
,
comment
):
tdSql
.
execute
(
f
'create database if not exists
{
dbname
}
'
)
tdSql
.
execute
(
f
'use
{
dbname
}
'
)
tdSql
.
execute
(
f
'create table
{
tbname
}
(ts timestamp,c0 int) comment "
{
comment
}
"'
)
def
check_comment
(
self
):
dbname
=
self
.
get_long_name
(
length
=
10
,
mode
=
"letters"
)
ntbname
=
self
.
get_long_name
(
length
=
5
,
mode
=
"letters"
)
# create normal table with comment
comment
=
self
.
get_long_name
(
length
=
10
,
mode
=
"letters"
)
self
.
__create_normaltb
(
dbname
,
ntbname
,
comment
)
ntb_kv_list
=
tdSql
.
getResult
(
"show tables"
)
print
(
ntb_kv_list
)
tdSql
.
checkEqual
(
ntb_kv_list
[
0
][
8
],
comment
)
tdSql
.
error
(
'alter table {ntbname} comment "test1"'
)
tdSql
.
execute
(
f
'drop database
{
dbname
}
'
)
# max length(1024)
comment
=
self
.
get_long_name
(
length
=
1024
,
mode
=
"letters"
)
self
.
__create_normaltb
(
dbname
,
ntbname
,
comment
)
ntb_kv_list
=
tdSql
.
getResult
(
"show tables"
)
tdSql
.
checkEqual
(
ntb_kv_list
[
0
][
8
],
comment
)
tdSql
.
execute
(
f
'drop database
{
dbname
}
'
)
# error overlength
comment
=
self
.
get_long_name
(
length
=
1025
,
mode
=
"letters"
)
tdSql
.
execute
(
f
'create database if not exists
{
dbname
}
'
)
tdSql
.
execute
(
f
'use
{
dbname
}
'
)
tdSql
.
error
(
f
"create table ntb (ts timestamp,c0 int) comment '
{
comment
}
'"
)
tdSql
.
execute
(
f
'drop database
{
dbname
}
'
)
# create child table with comment
comment
=
self
.
get_long_name
(
length
=
10
,
mode
=
"letters"
)
stbname
=
self
.
get_long_name
(
length
=
5
,
mode
=
"letters"
)
tbname
=
self
.
get_long_name
(
length
=
3
,
mode
=
"letters"
)
self
.
__create_tb
(
dbname
,
stbname
,
tbname
,
comment
)
ntb_kv_list
=
tdSql
.
getResult
(
"show tables"
)
tdSql
.
checkEqual
(
ntb_kv_list
[
0
][
8
],
comment
)
tdSql
.
error
(
f
'alter table
{
tbname
}
comment "test1"'
)
tdSql
.
execute
(
f
'drop database
{
dbname
}
'
)
# max length 1024
comment
=
self
.
get_long_name
(
length
=
1024
,
mode
=
"letters"
)
self
.
__create_tb
(
dbname
,
ntbname
,
comment
)
ntb_kv_list
=
tdSql
.
getResult
(
"show tables"
)
tdSql
.
checkEqual
(
ntb_kv_list
[
0
][
8
],
comment
)
tdSql
.
execute
(
f
'drop database
{
dbname
}
'
)
# error overlength
comment
=
self
.
get_long_name
(
length
=
1025
,
mode
=
"letters"
)
tdSql
.
execute
(
f
'create database if not exists
{
dbname
}
'
)
tdSql
.
execute
(
f
'use
{
dbname
}
'
)
tdSql
.
execute
(
f
"create table stb (ts timestamp,c0 int) tags(t0 int)"
)
tdSql
.
error
(
f
'create table stb_1 us stb tags(1) comment "
{
comment
}
"'
)
tdSql
.
execute
(
f
'drop database
{
dbname
}
'
)
def
run
(
self
):
self
.
check_comment
()
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
\ No newline at end of file
tests/system-test/1-insert/table_comment.py
0 → 100644
浏览文件 @
ca7057ce
###################################################################
# 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
random
import
string
from
util.log
import
*
from
util.cases
import
*
from
util.sql
import
*
from
util.common
import
*
class
TDTestCase
:
def
init
(
self
,
conn
,
logSql
):
tdLog
.
debug
(
"start to execute %s"
%
__file__
)
tdSql
.
init
(
conn
.
cursor
())
# prepare data
self
.
ntbname
=
'ntb'
self
.
stbname
=
'stb'
self
.
column_dict
=
{
'ts'
:
'timestamp'
,
'c1'
:
'int'
,
'c2'
:
'float'
,
'c3'
:
'double'
,
'c4'
:
'timestamp'
}
self
.
tag_dict
=
{
't0'
:
'int'
}
self
.
comment_length
=
[
0
,
1024
]
self
.
error_comment_length
=
[
1025
]
self
.
table_type_list
=
[
'normal_table'
,
'stable'
,
'child_table'
]
self
.
comment_flag_list
=
[
True
,
False
]
def
__set_and_alter_comment
(
self
,
tb_type
=
''
,
comment_flag
=
False
):
column_sql
=
''
tag_sql
=
''
for
k
,
v
in
self
.
column_dict
.
items
():
column_sql
+=
f
"
{
k
}
{
v
}
,"
for
k
,
v
in
self
.
tag_dict
.
items
():
tag_sql
+=
f
"
{
k
}
{
v
}
,"
if
tb_type
==
'normal_table'
or
tb_type
==
''
:
if
comment_flag
==
False
:
tdSql
.
execute
(
f
'create table
{
self
.
ntbname
}
(
{
column_sql
[:
-
1
]
}
)'
)
self
.
check_comment_info
()
self
.
alter_comment
(
self
.
ntbname
)
tdSql
.
execute
(
f
'drop table
{
self
.
ntbname
}
'
)
elif
comment_flag
==
True
:
for
i
in
self
.
comment_length
:
comment_info
=
tdCom
.
getLongName
(
i
)
tdSql
.
execute
(
f
'create table
{
self
.
ntbname
}
(
{
column_sql
[:
-
1
]
}
) comment "
{
comment_info
}
"'
)
self
.
check_comment_info
(
comment_info
)
self
.
alter_comment
(
self
.
ntbname
)
tdSql
.
execute
(
f
'drop table
{
self
.
ntbname
}
'
)
for
i
in
self
.
error_comment_length
:
comment_info
=
tdCom
.
getLongName
(
i
)
tdSql
.
error
(
f
'create table
{
self
.
ntbname
}
(
{
column_sql
[:
-
1
]
}
) comment "
{
comment_info
}
"'
)
elif
tb_type
==
'stable'
:
for
operation
in
[
'table'
,
'stable'
]:
if
comment_flag
==
False
:
tdSql
.
execute
(
f
'create
{
operation
}
{
self
.
stbname
}
(
{
column_sql
[:
-
1
]
}
) tags(
{
tag_sql
[:
-
1
]
}
)'
)
self
.
check_comment_info
(
None
,
'stable'
)
self
.
alter_comment
(
self
.
stbname
,
'stable'
)
tdSql
.
execute
(
f
'drop table
{
self
.
stbname
}
'
)
elif
comment_flag
==
True
:
for
i
in
self
.
comment_length
:
comment_info
=
tdCom
.
getLongName
(
i
)
tdSql
.
execute
(
f
'create
{
operation
}
{
self
.
stbname
}
(
{
column_sql
[:
-
1
]
}
) tags(
{
tag_sql
[:
-
1
]
}
) comment "
{
comment_info
}
"'
)
self
.
check_comment_info
(
comment_info
,
'stable'
)
self
.
alter_comment
(
self
.
stbname
,
'stable'
)
tdSql
.
execute
(
f
'drop table
{
self
.
stbname
}
'
)
elif
tb_type
==
'child_table'
:
tdSql
.
execute
(
f
'create table if not exists
{
self
.
stbname
}
(
{
column_sql
[:
-
1
]
}
) tags(
{
tag_sql
[:
-
1
]
}
)'
)
if
comment_flag
==
False
:
tdSql
.
execute
(
f
'create table if not exists
{
self
.
stbname
}
_ctb using
{
self
.
stbname
}
tags(1)'
)
self
.
check_comment_info
()
self
.
alter_comment
(
f
'
{
self
.
stbname
}
_ctb'
)
tdSql
.
execute
(
f
'drop table
{
self
.
stbname
}
_ctb'
)
elif
comment_flag
==
True
:
for
j
in
self
.
comment_length
:
comment_info
=
tdCom
.
getLongName
(
j
)
tdSql
.
execute
(
f
'create table if not exists
{
self
.
stbname
}
_ctb using
{
self
.
stbname
}
tags(1) comment "
{
comment_info
}
"'
)
self
.
check_comment_info
(
comment_info
)
self
.
alter_comment
(
f
'
{
self
.
stbname
}
_ctb'
)
tdSql
.
execute
(
f
'drop table
{
self
.
stbname
}
_ctb'
)
tdSql
.
execute
(
f
'drop table
{
self
.
stbname
}
'
)
def
alter_comment
(
self
,
tbname
,
tb_type
=
''
):
for
i
in
self
.
comment_length
:
comment_info
=
tdCom
.
getLongName
(
i
)
print
(
comment_info
)
tdSql
.
execute
(
f
'alter table
{
tbname
}
comment "
{
comment_info
}
"'
)
self
.
check_comment_info
(
comment_info
,
tb_type
)
for
i
in
self
.
error_comment_length
:
comment_info
=
tdCom
.
getLongName
(
i
)
tdSql
.
error
(
f
'alter table
{
tbname
}
comment "
{
comment_info
}
"'
)
def
check_comment_info
(
self
,
comment_info
=
None
,
tb_type
=
''
):
if
tb_type
==
''
or
tb_type
==
'normal_table'
or
tb_type
==
'child_table'
:
tdSql
.
query
(
'show tables'
)
if
comment_info
==
None
:
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
0
][
8
],
None
)
else
:
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
0
][
8
],
comment_info
)
elif
tb_type
==
'stable'
:
tdSql
.
query
(
'show stables'
)
if
comment_info
==
None
:
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
0
][
6
],
None
)
else
:
tdSql
.
checkEqual
(
tdSql
.
queryResult
[
0
][
6
],
comment_info
)
def
comment_check_case
(
self
,
table_type
,
comment_flag
):
tdSql
.
prepare
()
for
tb
in
table_type
:
for
flag
in
comment_flag
:
self
.
__set_and_alter_comment
(
tb
,
flag
)
tdSql
.
execute
(
'drop database db'
)
def
run
(
self
):
self
.
comment_check_case
(
self
.
table_type_list
,
self
.
comment_flag_list
)
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
tdCases
.
addWindows
(
__file__
,
TDTestCase
())
tdCases
.
addLinux
(
__file__
,
TDTestCase
())
\ No newline at end of file
tests/system-test/fulltest.sh
浏览文件 @
ca7057ce
...
...
@@ -22,7 +22,7 @@ python3 ./test.py -f 1-insert/opentsdb_json_taosc_insert.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/insertWithMoreVgroup.py
# python3 ./test.py -f 1-inerst/create_
table_comment.py
python3 ./test.py
-f
1-insert/
table_comment.py
python3 ./test.py
-f
2-query/between.py
python3 ./test.py
-f
2-query/distinct.py
python3 ./test.py
-f
2-query/varchar.py
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录