Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4edcf262
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
4edcf262
编写于
1月 24, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '3.0' of
https://github.com/taosdata/TDengine
into feature/tkv
上级
8aedbe0e
be5a43b9
变更
26
显示空白变更内容
内联
并排
Showing
26 changed file
with
1655 addition
and
648 deletion
+1655
-648
cmake/traft_CMakeLists.txt.in
cmake/traft_CMakeLists.txt.in
+1
-1
contrib/test/CMakeLists.txt
contrib/test/CMakeLists.txt
+1
-1
include/client/taos.h
include/client/taos.h
+29
-0
include/common/tmsg.h
include/common/tmsg.h
+24
-13
include/libs/scheduler/scheduler.h
include/libs/scheduler/scheduler.h
+4
-4
include/util/taoserror.h
include/util/taoserror.h
+1
-1
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+193
-34
source/client/src/clientMsgHandler.c
source/client/src/clientMsgHandler.c
+1
-1
source/client/test/clientTests.cpp
source/client/test/clientTests.cpp
+49
-24
source/dnode/mgmt/impl/src/dndTransport.c
source/dnode/mgmt/impl/src/dndTransport.c
+1
-0
source/dnode/mgmt/impl/src/dndVnodes.c
source/dnode/mgmt/impl/src/dndVnodes.c
+1
-1
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+119
-85
source/dnode/mnode/impl/src/mndSubscribe.c
source/dnode/mnode/impl/src/mndSubscribe.c
+11
-7
source/dnode/vnode/inc/tq.h
source/dnode/vnode/inc/tq.h
+8
-7
source/dnode/vnode/src/inc/tqInt.h
source/dnode/vnode/src/inc/tqInt.h
+4
-2
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+94
-11
source/dnode/vnode/src/vnd/vnodeQuery.c
source/dnode/vnode/src/vnd/vnodeQuery.c
+2
-2
source/dnode/vnode/src/vnd/vnodeWrite.c
source/dnode/vnode/src/vnd/vnodeWrite.c
+1
-3
source/libs/qworker/inc/qworkerInt.h
source/libs/qworker/inc/qworkerInt.h
+14
-12
source/libs/qworker/inc/qworkerMsg.h
source/libs/qworker/inc/qworkerMsg.h
+1
-0
source/libs/qworker/src/qworker.c
source/libs/qworker/src/qworker.c
+353
-285
source/libs/qworker/src/qworkerMsg.c
source/libs/qworker/src/qworkerMsg.c
+12
-11
source/libs/qworker/test/qworkerTests.cpp
source/libs/qworker/test/qworkerTests.cpp
+689
-114
source/libs/scheduler/src/scheduler.c
source/libs/scheduler/src/scheduler.c
+31
-18
source/libs/scheduler/test/schedulerTests.cpp
source/libs/scheduler/test/schedulerTests.cpp
+10
-10
source/util/src/terror.c
source/util/src/terror.c
+1
-1
未找到文件。
cmake/traft_CMakeLists.txt.in
浏览文件 @
4edcf262
...
...
@@ -7,7 +7,7 @@ ExternalProject_Add(traft
BINARY_DIR "${CMAKE_CONTRIB_DIR}/traft"
#BUILD_IN_SOURCE TRUE
# https://answers.ros.org/question/333125/how-to-include-external-automakeautoconf-projects-into-ament_cmake/
CONFIGURE_COMMAND COMMAND autoreconf -i COMMAND ./configure
--enable-example
CONFIGURE_COMMAND COMMAND autoreconf -i COMMAND ./configure
BUILD_COMMAND "$(MAKE)"
INSTALL_COMMAND ""
TEST_COMMAND ""
...
...
contrib/test/CMakeLists.txt
浏览文件 @
4edcf262
...
...
@@ -20,7 +20,7 @@ if(${BUILD_WITH_CRAFT})
endif
(
${
BUILD_WITH_CRAFT
}
)
if
(
${
BUILD_WITH_TRAFT
}
)
add_subdirectory
(
traft
)
#
add_subdirectory(traft)
endif
(
${
BUILD_WITH_TRAFT
}
)
add_subdirectory
(
tdev
)
include/client/taos.h
浏览文件 @
4edcf262
...
...
@@ -192,9 +192,38 @@ DLL_EXPORT void taos_close_stream(TAOS_STREAM *tstr);
DLL_EXPORT
int
taos_load_table_info
(
TAOS
*
taos
,
const
char
*
tableNameList
);
DLL_EXPORT
TAOS_RES
*
taos_schemaless_insert
(
TAOS
*
taos
,
char
*
lines
[],
int
numLines
,
int
protocol
,
int
precision
);
typedef
struct
tmq_t
tmq_t
;
typedef
struct
tmq_conf_t
tmq_conf_t
;
typedef
struct
tmq_list_t
tmq_list_t
;
typedef
struct
tmq_message_t
tmq_message_t
;
typedef
struct
tmq_message_topic_t
tmq_message_topic_t
;
typedef
struct
tmq_message_tb_t
tmq_message_tb_t
;
typedef
struct
tmq_tb_iter_t
tmq_tb_iter_t
;
typedef
struct
tmq_message_col_t
tmq_message_col_t
;
typedef
struct
tmq_col_iter_t
tmq_col_iter_t
;
DLL_EXPORT
tmq_list_t
*
tmq_list_new
();
DLL_EXPORT
int32_t
tmq_list_append
(
tmq_list_t
*
,
char
*
);
DLL_EXPORT
tmq_conf_t
*
tmq_conf_new
();
DLL_EXPORT
int32_t
tmq_conf_set
(
tmq_conf_t
*
conf
,
const
char
*
key
,
const
char
*
value
);
DLL_EXPORT
TAOS_RES
*
taos_create_topic
(
TAOS
*
taos
,
const
char
*
name
,
const
char
*
sql
,
int
sqlLen
);
DLL_EXPORT
tmq_t
*
taos_consumer_new
(
void
*
conn
,
tmq_conf_t
*
conf
,
char
*
errstr
,
int32_t
errstrLen
);
DLL_EXPORT
TAOS_RES
*
tmq_subscribe
(
tmq_t
*
tmq
,
tmq_list_t
*
topic_list
);
DLL_EXPORT
tmq_message_t
*
tmq_consume_poll
(
tmq_t
*
tmq
,
int64_t
blocking_time
);
DLL_EXPORT
int32_t
tmq_topic_num
(
tmq_message_t
*
msg
);
DLL_EXPORT
char
*
tmq_get_topic
(
tmq_message_topic_t
*
msg
);
DLL_EXPORT
int32_t
tmq_get_vgId
(
tmq_message_topic_t
*
msg
);
DLL_EXPORT
tmq_message_tb_t
*
tmq_get_next_tb
(
tmq_message_topic_t
*
msg
,
tmq_tb_iter_t
*
iter
);
DLL_EXPORT
tmq_message_col_t
*
tmq_get_next_col
(
tmq_message_tb_t
*
msg
,
tmq_col_iter_t
*
iter
);
#ifdef __cplusplus
}
#endif
...
...
include/common/tmsg.h
浏览文件 @
4edcf262
...
...
@@ -1519,7 +1519,8 @@ static FORCE_INLINE void* taosDecodeSMqMsg(void* buf, SMqHbMsg* pMsg) {
typedef
struct
SMqSetCVgReq
{
int32_t
vgId
;
int64_t
consumerId
;
int64_t
oldConsumerId
;
int64_t
newConsumerId
;
char
topicName
[
TSDB_TOPIC_FNAME_LEN
];
char
cgroup
[
TSDB_CONSUMER_GROUP_LEN
];
char
*
sql
;
...
...
@@ -1550,7 +1551,8 @@ static FORCE_INLINE void* tDecodeSSubQueryMsg(void* buf, SSubQueryMsg* pMsg) {
static
FORCE_INLINE
int32_t
tEncodeSMqSetCVgReq
(
void
**
buf
,
const
SMqSetCVgReq
*
pReq
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI32
(
buf
,
pReq
->
vgId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
consumerId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
oldConsumerId
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pReq
->
newConsumerId
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
topicName
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
cgroup
);
tlen
+=
taosEncodeString
(
buf
,
pReq
->
sql
);
...
...
@@ -1562,7 +1564,8 @@ static FORCE_INLINE int32_t tEncodeSMqSetCVgReq(void** buf, const SMqSetCVgReq*
static
FORCE_INLINE
void
*
tDecodeSMqSetCVgReq
(
void
*
buf
,
SMqSetCVgReq
*
pReq
)
{
buf
=
taosDecodeFixedI32
(
buf
,
&
pReq
->
vgId
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pReq
->
consumerId
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pReq
->
oldConsumerId
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pReq
->
newConsumerId
);
buf
=
taosDecodeStringTo
(
buf
,
pReq
->
topicName
);
buf
=
taosDecodeStringTo
(
buf
,
pReq
->
cgroup
);
buf
=
taosDecodeString
(
buf
,
&
pReq
->
sql
);
...
...
@@ -1579,15 +1582,6 @@ typedef struct SMqSetCVgRsp {
char
cGroup
[
TSDB_CONSUMER_GROUP_LEN
];
}
SMqSetCVgRsp
;
typedef
struct
SMqConsumeReq
{
int64_t
reqId
;
int64_t
offset
;
int64_t
consumerId
;
int64_t
blockingTime
;
char
topicName
[
TSDB_TOPIC_FNAME_LEN
];
char
cgroup
[
TSDB_CONSUMER_GROUP_LEN
];
}
SMqConsumeReq
;
typedef
struct
SMqColData
{
int16_t
colId
;
int16_t
type
;
...
...
@@ -1615,12 +1609,29 @@ typedef struct SMqTopicBlk {
typedef
struct
SMqConsumeRsp
{
int64_t
reqId
;
int64_t
c
lient
Id
;
int64_t
c
onsumer
Id
;
int32_t
bodyLen
;
int32_t
numOfTopics
;
SMqTopicData
data
[];
}
SMqConsumeRsp
;
// one req for one vg+topic
typedef
struct
SMqConsumeReq
{
//0: commit only, current offset
//1: consume only, poll next offset
//2: commit current and consume next offset
int32_t
reqType
;
int64_t
reqId
;
int64_t
consumerId
;
int64_t
blockingTime
;
char
cgroup
[
TSDB_CONSUMER_GROUP_LEN
];
int64_t
offset
;
char
topic
[
TSDB_TOPIC_FNAME_LEN
];
}
SMqConsumeReq
;
#ifdef __cplusplus
}
#endif
...
...
include/libs/scheduler/scheduler.h
浏览文件 @
4edcf262
...
...
@@ -72,7 +72,7 @@ int32_t schedulerInit(SSchedulerCfg *cfg);
* @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr
* @return
*/
int32_t
scheduleExecJob
(
void
*
transport
,
SArray
*
nodeList
,
SQueryDag
*
pDag
,
struct
SSchJob
**
pJob
,
SQueryResult
*
pRes
);
int32_t
schedule
r
ExecJob
(
void
*
transport
,
SArray
*
nodeList
,
SQueryDag
*
pDag
,
struct
SSchJob
**
pJob
,
SQueryResult
*
pRes
);
/**
* Process the query job, generated according to the query physical plan.
...
...
@@ -80,7 +80,7 @@ int32_t scheduleExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, stru
* @param nodeList Qnode/Vnode address list, element is SQueryNodeAddr
* @return
*/
int32_t
scheduleAsyncExecJob
(
void
*
transport
,
SArray
*
nodeList
,
SQueryDag
*
pDag
,
struct
SSchJob
**
pJob
);
int32_t
schedule
r
AsyncExecJob
(
void
*
transport
,
SArray
*
nodeList
,
SQueryDag
*
pDag
,
struct
SSchJob
**
pJob
);
/**
* Fetch query result from the remote query executor
...
...
@@ -88,7 +88,7 @@ int32_t scheduleAsyncExecJob(void *transport, SArray *nodeList, SQueryDag* pDag,
* @param data
* @return
*/
int32_t
scheduleFetchRows
(
struct
SSchJob
*
pJob
,
void
**
data
);
int32_t
schedule
r
FetchRows
(
struct
SSchJob
*
pJob
,
void
**
data
);
/**
...
...
@@ -102,7 +102,7 @@ int32_t scheduleFetchRows(struct SSchJob *pJob, void **data);
* Free the query job
* @param pJob
*/
void
scheduleFreeJob
(
void
*
pJob
);
void
schedule
r
FreeJob
(
void
*
pJob
);
void
schedulerDestroy
(
void
);
...
...
include/util/taoserror.h
浏览文件 @
4edcf262
...
...
@@ -354,7 +354,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_QRY_SCH_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0710) //"Scheduler not exist")
#define TSDB_CODE_QRY_TASK_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0711) //"Task not exist")
#define TSDB_CODE_QRY_TASK_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0712) //"Task already exist")
#define TSDB_CODE_QRY_
RES_CACHE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0713) //"Task result cache
not exist")
#define TSDB_CODE_QRY_
TASK_CTX_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0713) //"Task context
not exist")
#define TSDB_CODE_QRY_TASK_CANCELLED TAOS_DEF_ERROR_CODE(0, 0x0714) //"Task cancelled")
#define TSDB_CODE_QRY_TASK_DROPPED TAOS_DEF_ERROR_CODE(0, 0x0715) //"Task dropped")
#define TSDB_CODE_QRY_TASK_CANCELLING TAOS_DEF_ERROR_CODE(0, 0x0716) //"Task cancelling")
...
...
source/client/src/clientImpl.c
浏览文件 @
4edcf262
...
...
@@ -117,7 +117,7 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
SAppInstInfo
*
p
=
calloc
(
1
,
sizeof
(
struct
SAppInstInfo
));
p
->
mgmtEp
=
epSet
;
p
->
pTransporter
=
openTransporter
(
user
,
secretEncrypt
,
tsNumOfCores
);
/*p->pAppHbMgr = appHbMgrInit(p);*/
p
->
pAppHbMgr
=
appHbMgrInit
(
p
);
taosHashPut
(
appInfo
.
pInstMap
,
key
,
strlen
(
key
),
&
p
,
POINTER_BYTES
);
pInst
=
&
p
;
...
...
@@ -237,12 +237,12 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, SArray* pNodeList)
if
(
TSDB_SQL_INSERT
==
pRequest
->
type
||
TSDB_SQL_CREATE_TABLE
==
pRequest
->
type
)
{
SQueryResult
res
=
{.
code
=
0
,
.
numOfRows
=
0
,
.
msgSize
=
ERROR_MSG_BUF_DEFAULT_SIZE
,
.
msg
=
pRequest
->
msgBuf
};
int32_t
code
=
scheduleExecJob
(
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
,
NULL
,
pDag
,
&
pRequest
->
body
.
pQueryJob
,
&
res
);
int32_t
code
=
schedule
r
ExecJob
(
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
,
NULL
,
pDag
,
&
pRequest
->
body
.
pQueryJob
,
&
res
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// handle error and retry
}
else
{
if
(
pRequest
->
body
.
pQueryJob
!=
NULL
)
{
scheduleFreeJob
(
pRequest
->
body
.
pQueryJob
);
schedule
r
FreeJob
(
pRequest
->
body
.
pQueryJob
);
}
}
...
...
@@ -251,17 +251,11 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, SArray* pNodeList)
return
pRequest
->
code
;
}
return
scheduleAsyncExecJob
(
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
,
pNodeList
,
pDag
,
&
pRequest
->
body
.
pQueryJob
);
return
schedule
r
AsyncExecJob
(
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
,
pNodeList
,
pDag
,
&
pRequest
->
body
.
pQueryJob
);
}
typedef
struct
tmq_t
tmq_t
;
typedef
struct
SMqClientTopic
{
// subscribe info
int32_t
sqlLen
;
char
*
sql
;
char
*
topicName
;
int64_t
topicId
;
typedef
struct
SMqClientVg
{
// statistics
int64_t
consumeCnt
;
// offset
...
...
@@ -270,36 +264,160 @@ typedef struct SMqClientTopic {
//connection info
int32_t
vgId
;
SEpSet
epSet
;
}
SMqClientVg
;
typedef
struct
SMqClientTopic
{
// subscribe info
int32_t
sqlLen
;
char
*
sql
;
char
*
topicName
;
int64_t
topicId
;
int32_t
nextVgIdx
;
SArray
*
vgs
;
//SArray<SMqClientVg>
}
SMqClientTopic
;
typedef
struct
tmq_resp_err_t
{
int32_t
code
;
}
tmq_resp_err_t
;
typedef
struct
tmq_topic_vgroup_
list_
t
{
char
*
topicName
;
typedef
struct
tmq_topic_vgroup_t
{
char
*
topic
;
int32_t
vgId
;
int64_t
committedOffset
;
int64_t
commitOffset
;
}
tmq_topic_vgroup_t
;
typedef
struct
tmq_topic_vgroup_list_t
{
int32_t
cnt
;
int32_t
size
;
tmq_topic_vgroup_t
*
elems
;
}
tmq_topic_vgroup_list_t
;
typedef
void
(
tmq_commit_cb
(
tmq_t
*
,
tmq_resp_err_t
,
tmq_topic_vgroup_list_t
*
,
void
*
param
));
typedef
struct
tmq_conf_t
{
char
*
clientId
;
char
*
groupId
;
struct
tmq_conf_t
{
char
clientId
[
256
]
;
char
groupId
[
256
]
;
char
*
ip
;
uint16_t
port
;
tmq_commit_cb
*
commit_cb
;
}
tmq_conf_t
;
};
tmq_conf_t
*
tmq_conf_new
()
{
tmq_conf_t
*
conf
=
calloc
(
1
,
sizeof
(
tmq_conf_t
));
return
conf
;
}
int32_t
tmq_conf_set
(
tmq_conf_t
*
conf
,
const
char
*
key
,
const
char
*
value
)
{
if
(
strcmp
(
key
,
"group.id"
))
{
strcpy
(
conf
->
groupId
,
value
);
}
if
(
strcmp
(
key
,
"client.id"
))
{
strcpy
(
conf
->
clientId
,
value
);
}
return
0
;
}
struct
tmq_t
{
char
groupId
[
256
];
char
clientId
[
256
];
int64_t
consumerId
;
int64_t
status
;
STscObj
*
pTscObj
;
tmq_commit_cb
*
commit_cb
;
SArray
*
clientTopics
;
// SArray<SMqClientTopic>
int32_t
nextTopicIdx
;
SArray
*
clientTopics
;
//SArray<SMqClientTopic>
};
tmq_t
*
taos_consumer_new
(
void
*
conn
,
tmq_conf_t
*
conf
,
char
*
errstr
,
int32_t
errstrLen
)
{
tmq_t
*
pTmq
=
calloc
(
sizeof
(
tmq_t
),
1
);
if
(
pTmq
==
NULL
)
{
return
NULL
;
}
pTmq
->
pTscObj
=
(
STscObj
*
)
conn
;
pTmq
->
status
=
0
;
strcpy
(
pTmq
->
clientId
,
conf
->
clientId
);
strcpy
(
pTmq
->
groupId
,
conf
->
groupId
);
pTmq
->
commit_cb
=
conf
->
commit_cb
;
pTmq
->
consumerId
=
generateRequestId
()
&
((
uint64_t
)
-
1
>>
1
);
return
pTmq
;
}
struct
tmq_list_t
{
int32_t
cnt
;
int32_t
tot
;
char
*
elems
[];
};
tmq_list_t
*
tmq_list_new
()
{
tmq_list_t
*
ptr
=
malloc
(
sizeof
(
tmq_list_t
)
+
8
*
sizeof
(
char
*
));
if
(
ptr
==
NULL
)
{
return
ptr
;
}
ptr
->
cnt
=
0
;
ptr
->
tot
=
8
;
return
ptr
;
}
int32_t
tmq_list_append
(
tmq_list_t
*
ptr
,
char
*
src
)
{
if
(
ptr
->
cnt
>=
ptr
->
tot
-
1
)
return
-
1
;
ptr
->
elems
[
ptr
->
cnt
]
=
src
;
ptr
->
cnt
++
;
return
0
;
}
TAOS_RES
*
tmq_subscribe
(
tmq_t
*
tmq
,
tmq_list_t
*
topic_list
)
{
SRequestObj
*
pRequest
=
NULL
;
tmq
->
status
=
1
;
int32_t
sz
=
topic_list
->
cnt
;
tmq
->
clientTopics
=
taosArrayInit
(
sz
,
sizeof
(
void
*
));
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
char
*
topicName
=
strdup
(
topic_list
->
elems
[
i
]);
taosArrayPush
(
tmq
->
clientTopics
,
&
topicName
);
}
SCMSubscribeReq
req
;
req
.
topicNum
=
taosArrayGetSize
(
tmq
->
clientTopics
);
req
.
consumerId
=
tmq
->
consumerId
;
req
.
consumerGroup
=
strdup
(
tmq
->
groupId
);
req
.
topicNames
=
tmq
->
clientTopics
;
int
tlen
=
tSerializeSCMSubscribeReq
(
NULL
,
&
req
);
void
*
buf
=
malloc
(
tlen
);
if
(
buf
==
NULL
)
{
goto
_return
;
}
void
*
abuf
=
buf
;
tSerializeSCMSubscribeReq
(
&
abuf
,
&
req
);
/*printf("formatted: %s\n", dagStr);*/
pRequest
=
createRequest
(
tmq
->
pTscObj
,
NULL
,
NULL
,
TSDB_SQL_SELECT
);
if
(
pRequest
==
NULL
)
{
tscError
(
"failed to malloc sqlObj"
);
}
pRequest
->
body
.
requestMsg
=
(
SDataBuf
){
.
pData
=
buf
,
.
len
=
tlen
};
pRequest
->
type
=
TDMT_MND_CREATE_TOPIC
;
SMsgSendInfo
*
body
=
buildMsgInfoImpl
(
pRequest
);
SEpSet
epSet
=
getEpSet_s
(
&
tmq
->
pTscObj
->
pAppInfo
->
mgmtEp
);
int64_t
transporterId
=
0
;
asyncSendMsgToServer
(
tmq
->
pTscObj
->
pAppInfo
->
pTransporter
,
&
epSet
,
&
transporterId
,
body
);
tsem_wait
(
&
pRequest
->
body
.
rspSem
);
_return:
if
(
body
!=
NULL
)
{
destroySendMsgInfo
(
body
);
}
if
(
pRequest
!=
NULL
&&
terrno
!=
TSDB_CODE_SUCCESS
)
{
pRequest
->
code
=
terrno
;
}
return
pRequest
;
}
void
tmq_conf_set_offset_commit_cb
(
tmq_conf_t
*
conf
,
tmq_commit_cb
*
cb
)
{
conf
->
commit_cb
=
cb
;
}
...
...
@@ -327,10 +445,10 @@ SArray* tmqGetConnInfo(SClientHbKey connKey, void* param) {
int
sz
=
taosArrayGetSize
(
clientTopics
);
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
SMqClientTopic
*
pCTopic
=
taosArrayGet
(
clientTopics
,
i
);
if
(
pCTopic
->
vgId
==
-
1
)
{
pMqHb
->
status
=
1
;
break
;
}
/*if (pCTopic->vgId == -1) {*/
/*pMqHb->status = 1;*/
/*break;*/
/*}*/
}
kv
.
value
=
pMqHb
;
kv
.
valueLen
=
sizeof
(
SMqHbMsg
);
...
...
@@ -451,22 +569,63 @@ _return:
return
pRequest
;
}
typedef
struct
tmq_message_t
{
int32_t
numOfRows
;
char
*
topicName
;
TAOS_ROW
row
[]
;
}
tmq_message_t
;
/*typedef SMqConsumeRsp tmq_message_t;*/
struct
tmq_message_t
{
SMqConsumeRsp
rsp
;
};
tmq_message_t
*
tmq_consume_poll
(
tmq_t
*
mq
,
int64_t
blocking_time
)
{
tmq_message_t
*
tmq_consume_poll
(
tmq_t
*
tmq
,
int64_t
blocking_time
)
{
if
(
tmq
->
clientTopics
==
NULL
||
taosArrayGetSize
(
tmq
->
clientTopics
)
==
0
)
{
return
NULL
;
}
SRequestObj
*
pRequest
=
NULL
;
SMqConsumeReq
req
=
{
0
};
req
.
reqType
=
1
;
req
.
blockingTime
=
blocking_time
;
req
.
consumerId
=
tmq
->
consumerId
;
strcpy
(
req
.
cgroup
,
tmq
->
groupId
);
SMqClientTopic
*
pTopic
=
taosArrayGet
(
tmq
->
clientTopics
,
tmq
->
nextTopicIdx
);
tmq
->
nextTopicIdx
=
(
tmq
->
nextTopicIdx
+
1
)
%
taosArrayGetSize
(
tmq
->
clientTopics
);
strcpy
(
req
.
topic
,
pTopic
->
topicName
);
int32_t
nextVgIdx
=
pTopic
->
nextVgIdx
;
pTopic
->
nextVgIdx
=
(
nextVgIdx
+
1
)
%
taosArrayGetSize
(
pTopic
->
vgs
);
SMqClientVg
*
pVg
=
taosArrayGet
(
pTopic
->
vgs
,
nextVgIdx
);
req
.
offset
=
pVg
->
currentOffset
;
pRequest
->
body
.
requestMsg
=
(
SDataBuf
){
.
pData
=
&
req
,
.
len
=
sizeof
(
SMqConsumeReq
)
};
pRequest
->
type
=
TDMT_VND_CONSUME
;
SMsgSendInfo
*
body
=
buildMsgInfoImpl
(
pRequest
);
int64_t
transporterId
=
0
;
asyncSendMsgToServer
(
tmq
->
pTscObj
->
pAppInfo
->
pTransporter
,
&
pVg
->
epSet
,
&
transporterId
,
body
);
tsem_wait
(
&
pRequest
->
body
.
rspSem
);
return
(
tmq_message_t
*
)
pRequest
->
body
.
resInfo
.
pData
;
/*tsem_wait(&pRequest->body.rspSem);*/
/*if (body != NULL) {*/
/*destroySendMsgInfo(body);*/
/*}*/
/*if (pRequest != NULL && terrno != TSDB_CODE_SUCCESS) {*/
/*pRequest->code = terrno;*/
/*}*/
/*return pRequest;*/
}
tmq_resp_err_t
*
tmq_commit
(
tmq_t
*
mq
,
void
*
callback
,
int32_t
async
)
{
tmq_resp_err_t
*
tmq_commit
(
tmq_t
*
tmq
,
tmq_topic_vgroup_list_t
*
tmq_topic_vgroup_list
,
int32_t
async
)
{
SMqConsumeReq
req
=
{
0
};
return
NULL
;
}
void
tmq_message_destroy
(
tmq_message_t
*
mq_message
)
{
void
tmq_message_destroy
(
tmq_message_t
*
t
mq_message
)
{
if
(
tmq_message
==
NULL
)
return
;
}
...
...
@@ -711,7 +870,7 @@ void* doFetchRow(SRequestObj* pRequest) {
}
SReqResultInfo
*
pResInfo
=
&
pRequest
->
body
.
resInfo
;
int32_t
code
=
scheduleFetchRows
(
pRequest
->
body
.
pQueryJob
,
(
void
**
)
&
pResInfo
->
pData
);
int32_t
code
=
schedule
r
FetchRows
(
pRequest
->
body
.
pQueryJob
,
(
void
**
)
&
pResInfo
->
pData
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pRequest
->
code
=
code
;
return
NULL
;
...
...
source/client/src/clientMsgHandler.c
浏览文件 @
4edcf262
...
...
@@ -72,7 +72,7 @@ int processConnectRsp(void* param, const SDataBuf* pMsg, int32_t code) {
atomic_add_fetch_64
(
&
pTscObj
->
pAppInfo
->
numOfConns
,
1
);
SClientHbKey
connKey
=
{.
connId
=
pConnect
->
connId
,
.
hbType
=
HEARTBEAT_TYPE_QUERY
};
/*hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, connKey, NULL);*/
hbRegisterConn
(
pTscObj
->
pAppInfo
->
pAppHbMgr
,
connKey
,
NULL
);
// pRequest->body.resInfo.pRspMsg = pMsg->pData;
tscDebug
(
"0x%"
PRIx64
" clusterId:%"
PRId64
", totalConn:%"
PRId64
,
pRequest
->
requestId
,
pConnect
->
clusterId
,
...
...
source/client/test/clientTests.cpp
浏览文件 @
4edcf262
...
...
@@ -526,29 +526,54 @@ TEST(testCase, show_table_Test) {
// taosHashCleanup(phash);
//}
//
//TEST(testCase, create_topic_Test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
// assert(pConn != NULL);
//
// TAOS_RES* pRes = taos_query(pConn, "use abc1");
// if (taos_errno(pRes) != 0) {
// printf("error in use db, reason:%s\n", taos_errstr(pRes));
// }
// taos_free_result(pRes);
//
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
// ASSERT_TRUE(pFields == nullptr);
//
// int32_t numOfFields = taos_num_fields(pRes);
// ASSERT_EQ(numOfFields, 0);
//
// taos_free_result(pRes);
//
// char* sql = "select * from tu";
// pRes = taos_create_topic(pConn, "test_topic_1", sql, strlen(sql));
// taos_free_result(pRes);
// taos_close(pConn);
//}
TEST
(
testCase
,
create_topic_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"use abc1"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"error in use db, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_free_result
(
pRes
);
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pRes
);
ASSERT_TRUE
(
pFields
==
nullptr
);
int32_t
numOfFields
=
taos_num_fields
(
pRes
);
ASSERT_EQ
(
numOfFields
,
0
);
taos_free_result
(
pRes
);
char
*
sql
=
"select * from tu"
;
pRes
=
taos_create_topic
(
pConn
,
"test_topic_1"
,
sql
,
strlen
(
sql
));
taos_free_result
(
pRes
);
taos_close
(
pConn
);
}
TEST
(
testCase
,
tmq_subscribe_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
tmq_conf_t
*
conf
=
tmq_conf_new
();
tmq_conf_set
(
conf
,
"group.id"
,
"tg1"
);
tmq_t
*
tmq
=
taos_consumer_new
(
pConn
,
conf
,
NULL
,
0
);
tmq_list_t
*
topic_list
=
tmq_list_new
();
tmq_list_append
(
topic_list
,
"test_topic_1"
);
tmq_subscribe
(
tmq
,
topic_list
);
while
(
1
)
{
tmq_message_t
*
msg
=
tmq_consume_poll
(
tmq
,
0
);
printf
(
"get msg
\n
"
);
if
(
msg
==
NULL
)
break
;
}
}
TEST
(
testCase
,
tmq_consume_Test
)
{
}
TEST
(
testCase
,
tmq_commit_TEST
)
{
}
//TEST(testCase, insert_test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
...
...
source/dnode/mgmt/impl/src/dndTransport.c
浏览文件 @
4edcf262
...
...
@@ -116,6 +116,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
// Requests handled by VNODE
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_VND_SUBMIT
)]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_VND_QUERY
)]
=
dndProcessVnodeQueryMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_VND_QUERY_CONTINUE
)]
=
dndProcessVnodeQueryMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_VND_FETCH
)]
=
dndProcessVnodeFetchMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_VND_ALTER_TABLE
)]
=
dndProcessVnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_VND_UPDATE_TAG_VAL
)]
=
dndProcessVnodeWriteMsg
;
...
...
source/dnode/mgmt/impl/src/dndVnodes.c
浏览文件 @
4edcf262
...
...
@@ -892,7 +892,7 @@ int32_t dndPutReqToVQueryQ(SDnode *pDnode, SRpcMsg *pMsg) {
SVnodeObj
*
pVnode
=
dndAcquireVnode
(
pDnode
,
pHead
->
vgId
);
if
(
pVnode
==
NULL
)
return
-
1
;
int32_t
code
=
dndWriteRpcMsgToVnodeQueue
(
pVnode
->
p
Fetch
Q
,
pMsg
,
false
);
int32_t
code
=
dndWriteRpcMsgToVnodeQueue
(
pVnode
->
p
Query
Q
,
pMsg
,
false
);
dndReleaseVnode
(
pDnode
,
pVnode
);
return
code
;
}
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
4edcf262
...
...
@@ -19,14 +19,14 @@
#include "os.h"
#include "cJSON.h"
#include "scheduler.h"
#include "sync.h"
#include "tmsg.h"
#include "thash.h"
#include "tlist.h"
#include "tlog.h"
#include "tmsg.h"
#include "trpc.h"
#include "ttimer.h"
#include "scheduler.h"
#include "mnode.h"
...
...
@@ -37,12 +37,42 @@ extern "C" {
extern
int32_t
mDebugFlag
;
// mnode log function
#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", 255, __VA_ARGS__); }}
#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", 255, __VA_ARGS__); }}
#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", 255, __VA_ARGS__); }}
#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", 255, __VA_ARGS__); }}
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
#define mFatal(...) \
{ \
if (mDebugFlag & DEBUG_FATAL) { \
taosPrintLog("MND FATAL ", 255, __VA_ARGS__); \
} \
}
#define mError(...) \
{ \
if (mDebugFlag & DEBUG_ERROR) { \
taosPrintLog("MND ERROR ", 255, __VA_ARGS__); \
} \
}
#define mWarn(...) \
{ \
if (mDebugFlag & DEBUG_WARN) { \
taosPrintLog("MND WARN ", 255, __VA_ARGS__); \
} \
}
#define mInfo(...) \
{ \
if (mDebugFlag & DEBUG_INFO) { \
taosPrintLog("MND ", 255, __VA_ARGS__); \
} \
}
#define mDebug(...) \
{ \
if (mDebugFlag & DEBUG_DEBUG) { \
taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); \
} \
}
#define mTrace(...) \
{ \
if (mDebugFlag & DEBUG_TRACE) { \
taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); \
} \
}
typedef
enum
{
MND_AUTH_ACCT_START
=
0
,
...
...
@@ -96,13 +126,13 @@ typedef struct {
ETrnPolicy
policy
;
int32_t
code
;
int32_t
failedTimes
;
void
*
rpcHandle
;
void
*
rpcAHandle
;
SArray
*
redoLogs
;
SArray
*
undoLogs
;
SArray
*
commitLogs
;
SArray
*
redoActions
;
SArray
*
undoActions
;
void
*
rpcHandle
;
void
*
rpcAHandle
;
SArray
*
redoLogs
;
SArray
*
undoLogs
;
SArray
*
commitLogs
;
SArray
*
redoActions
;
SArray
*
undoActions
;
}
STrans
;
typedef
struct
{
...
...
@@ -135,28 +165,28 @@ typedef struct {
ESyncState
role
;
int32_t
roleTerm
;
int64_t
roleTime
;
SDnodeObj
*
pDnode
;
SDnodeObj
*
pDnode
;
}
SMnodeObj
;
typedef
struct
{
int32_t
id
;
int64_t
createdTime
;
int64_t
updateTime
;
SDnodeObj
*
pDnode
;
SDnodeObj
*
pDnode
;
}
SQnodeObj
;
typedef
struct
{
int32_t
id
;
int64_t
createdTime
;
int64_t
updateTime
;
SDnodeObj
*
pDnode
;
SDnodeObj
*
pDnode
;
}
SSnodeObj
;
typedef
struct
{
int32_t
id
;
int64_t
createdTime
;
int64_t
updateTime
;
SDnodeObj
*
pDnode
;
SDnodeObj
*
pDnode
;
}
SBnodeObj
;
typedef
struct
{
...
...
@@ -201,7 +231,7 @@ typedef struct {
int64_t
updateTime
;
int8_t
superUser
;
int32_t
acctId
;
SHashObj
*
prohibitDbHash
;
SHashObj
*
prohibitDbHash
;
}
SUserObj
;
typedef
struct
{
...
...
@@ -272,7 +302,7 @@ typedef struct {
int32_t
numOfColumns
;
int32_t
numOfTags
;
SRWLatch
lock
;
SSchema
*
pSchema
;
SSchema
*
pSchema
;
}
SStbObj
;
typedef
struct
{
...
...
@@ -287,8 +317,8 @@ typedef struct {
int64_t
sigature
;
int32_t
commentSize
;
int32_t
codeSize
;
char
*
pComment
;
char
*
pCode
;
char
*
pComment
;
char
*
pCode
;
char
pData
[];
}
SFuncObj
;
...
...
@@ -301,8 +331,8 @@ typedef struct {
int32_t
numOfRows
;
int32_t
numOfReads
;
int32_t
payloadLen
;
void
*
pIter
;
SMnode
*
pMnode
;
void
*
pIter
;
SMnode
*
pMnode
;
char
db
[
TSDB_DB_FNAME_LEN
];
int16_t
offset
[
TSDB_MAX_COLUMNS
];
int32_t
bytes
[
TSDB_MAX_COLUMNS
];
...
...
@@ -328,6 +358,7 @@ typedef struct SMqTopicConsumer {
typedef
struct
SMqConsumerEp
{
int32_t
vgId
;
// -1 for unassigned
int32_t
status
;
SEpSet
epSet
;
int64_t
consumerId
;
// -1 for unassigned
int64_t
lastConsumerHbTs
;
...
...
@@ -339,6 +370,7 @@ typedef struct SMqConsumerEp {
static
FORCE_INLINE
int32_t
tEncodeSMqConsumerEp
(
void
**
buf
,
SMqConsumerEp
*
pConsumerEp
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeFixedI32
(
buf
,
pConsumerEp
->
vgId
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pConsumerEp
->
status
);
tlen
+=
taosEncodeSEpSet
(
buf
,
&
pConsumerEp
->
epSet
);
tlen
+=
taosEncodeFixedI64
(
buf
,
pConsumerEp
->
consumerId
);
tlen
+=
tEncodeSSubQueryMsg
(
buf
,
&
pConsumerEp
->
qExec
);
...
...
@@ -347,6 +379,7 @@ static FORCE_INLINE int32_t tEncodeSMqConsumerEp(void** buf, SMqConsumerEp* pCon
static
FORCE_INLINE
void
*
tDecodeSMqConsumerEp
(
void
**
buf
,
SMqConsumerEp
*
pConsumerEp
)
{
buf
=
taosDecodeFixedI32
(
buf
,
&
pConsumerEp
->
vgId
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pConsumerEp
->
status
);
buf
=
taosDecodeSEpSet
(
buf
,
&
pConsumerEp
->
epSet
);
buf
=
taosDecodeFixedI64
(
buf
,
&
pConsumerEp
->
consumerId
);
buf
=
tDecodeSSubQueryMsg
(
buf
,
&
pConsumerEp
->
qExec
);
...
...
@@ -354,15 +387,16 @@ static FORCE_INLINE void* tDecodeSMqConsumerEp(void** buf, SMqConsumerEp* pConsu
return
buf
;
}
//unit for rebalance
//
unit for rebalance
typedef
struct
SMqSubscribeObj
{
char
key
[
TSDB_SUBSCRIBE_KEY_LEN
];
int32_t
epoch
;
//TODO: replace with priority queue
//
TODO: replace with priority queue
int32_t
nextConsumerIdx
;
SArray
*
availConsumer
;
// SArray<int64_t> (consumerId)
SArray
*
assigned
;
// SArray<SMqConsumerEp>
SArray
*
unassignedConsumer
;
// SArray<SMqConsumerEp>
SArray
*
idleConsumer
;
// SArray<SMqConsumerEp>
SArray
*
lostConsumer
;
// SArray<SMqConsumerEp>
SArray
*
unassignedVg
;
// SArray<SMqConsumerEp>
}
SMqSubscribeObj
;
...
...
@@ -384,17 +418,17 @@ static FORCE_INLINE SMqSubscribeObj* tNewSubscribeObj() {
free
(
pSub
);
return
NULL
;
}
pSub
->
unassigned
Consumer
=
taosArrayInit
(
0
,
sizeof
(
SMqConsumerEp
));
pSub
->
idle
Consumer
=
taosArrayInit
(
0
,
sizeof
(
SMqConsumerEp
));
if
(
pSub
->
assigned
==
NULL
)
{
taosArrayDestroy
(
pSub
->
availConsumer
);
taosArrayDestroy
(
pSub
->
unassigned
Consumer
);
taosArrayDestroy
(
pSub
->
idle
Consumer
);
free
(
pSub
);
return
NULL
;
}
pSub
->
unassignedVg
=
taosArrayInit
(
0
,
sizeof
(
SMqConsumerEp
));
if
(
pSub
->
assigned
==
NULL
)
{
taosArrayDestroy
(
pSub
->
availConsumer
);
taosArrayDestroy
(
pSub
->
unassigned
Consumer
);
taosArrayDestroy
(
pSub
->
idle
Consumer
);
taosArrayDestroy
(
pSub
->
unassignedVg
);
free
(
pSub
);
return
NULL
;
...
...
@@ -422,10 +456,10 @@ static FORCE_INLINE int32_t tEncodeSubscribeObj(void** buf, const SMqSubscribeOb
tlen
+=
tEncodeSMqConsumerEp
(
buf
,
pCEp
);
}
sz
=
taosArrayGetSize
(
pSub
->
unassigned
Consumer
);
sz
=
taosArrayGetSize
(
pSub
->
idle
Consumer
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqConsumerEp
*
pCEp
=
taosArrayGet
(
pSub
->
unassigned
Consumer
,
i
);
SMqConsumerEp
*
pCEp
=
taosArrayGet
(
pSub
->
idle
Consumer
,
i
);
tlen
+=
tEncodeSMqConsumerEp
(
buf
,
pCEp
);
}
...
...
@@ -457,22 +491,22 @@ static FORCE_INLINE void* tDecodeSubscribeObj(void* buf, SMqSubscribeObj* pSub)
}
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pSub
->
unassigned
Consumer
=
taosArrayInit
(
sz
,
sizeof
(
SMqConsumerEp
));
if
(
pSub
->
unassigned
Consumer
==
NULL
)
{
pSub
->
idle
Consumer
=
taosArrayInit
(
sz
,
sizeof
(
SMqConsumerEp
));
if
(
pSub
->
idle
Consumer
==
NULL
)
{
taosArrayDestroy
(
pSub
->
assigned
);
return
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqConsumerEp
cEp
;
buf
=
tDecodeSMqConsumerEp
(
buf
,
&
cEp
);
taosArrayPush
(
pSub
->
unassigned
Consumer
,
&
cEp
);
taosArrayPush
(
pSub
->
idle
Consumer
,
&
cEp
);
}
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pSub
->
unassignedVg
=
taosArrayInit
(
sz
,
sizeof
(
SMqConsumerEp
));
if
(
pSub
->
unassignedVg
==
NULL
)
{
taosArrayDestroy
(
pSub
->
assigned
);
taosArrayDestroy
(
pSub
->
unassigned
Consumer
);
taosArrayDestroy
(
pSub
->
idle
Consumer
);
return
NULL
;
}
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
...
...
@@ -487,8 +521,8 @@ static FORCE_INLINE void* tDecodeSubscribeObj(void* buf, SMqSubscribeObj* pSub)
typedef
struct
SMqCGroup
{
char
name
[
TSDB_CONSUMER_GROUP_LEN
];
int32_t
status
;
// 0 - uninitialized, 1 - wait rebalance, 2- normal
SList
*
consumerIds
;
// SList<int64_t>
SList
*
idleVGroups
;
// SList<int32_t>
SList
*
consumerIds
;
// SList<int64_t>
SList
*
idleVGroups
;
// SList<int32_t>
}
SMqCGroup
;
typedef
struct
SMqTopicObj
{
...
...
@@ -501,24 +535,23 @@ typedef struct SMqTopicObj {
int32_t
version
;
SRWLatch
lock
;
int32_t
sqlLen
;
char
*
sql
;
char
*
logicalPlan
;
char
*
physicalPlan
;
//SHashObj *cgroups; // SHashObj<SMqCGroup>
//SHashObj *consumers; // SHashObj<SMqConsumerObj>
char
*
sql
;
char
*
logicalPlan
;
char
*
physicalPlan
;
//
SHashObj *cgroups; // SHashObj<SMqCGroup>
//
SHashObj *consumers; // SHashObj<SMqConsumerObj>
}
SMqTopicObj
;
// TODO: add cache and change name to id
typedef
struct
SMqConsumerTopic
{
char
name
[
TSDB_TOPIC_FNAME_LEN
];
int32_t
epoch
;
//TODO: replace with something with ep
//SList *vgroups; // SList<int32_t>
//vg assigned to the consumer on the topic
SArray
*
pVgInfo
;
// SArray<int32_t>
// vg assigned to the consumer on the topic
SArray
*
pVgInfo
;
// SArray<int32_t>
}
SMqConsumerTopic
;
static
FORCE_INLINE
SMqConsumerTopic
*
tNewConsumerTopic
(
int64_t
consumerId
,
SMqTopicObj
*
pTopic
,
SMqSubscribeObj
*
pSub
)
{
static
FORCE_INLINE
SMqConsumerTopic
*
tNewConsumerTopic
(
int64_t
consumerId
,
SMqTopicObj
*
pTopic
,
SMqSubscribeObj
*
pSub
)
{
SMqConsumerTopic
*
pCTopic
=
malloc
(
sizeof
(
SMqConsumerTopic
));
if
(
pCTopic
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -567,10 +600,11 @@ static FORCE_INLINE void* tDecodeSMqConsumerTopic(void* buf, SMqConsumerTopic* p
typedef
struct
SMqConsumerObj
{
int64_t
consumerId
;
int64_t
connId
;
SRWLatch
lock
;
char
cgroup
[
TSDB_CONSUMER_GROUP_LEN
];
SArray
*
topics
;
// SArray<SMqConsumerTopic>
//SHashObj *topicHash; //SHashObj<SMqTopicObj>
SArray
*
topics
;
// SArray<SMqConsumerTopic>
//
SHashObj *topicHash; //SHashObj<SMqTopicObj>
}
SMqConsumerObj
;
static
FORCE_INLINE
int32_t
tEncodeSMqConsumerObj
(
void
**
buf
,
const
SMqConsumerObj
*
pConsumer
)
{
...
...
@@ -602,12 +636,12 @@ static FORCE_INLINE void* tDecodeSMqConsumerObj(void* buf, SMqConsumerObj* pCons
typedef
struct
SMqSubConsumerObj
{
int64_t
consumerUid
;
// if -1, unassigned
SList
*
vgId
;
// SList<int32_t>
SList
*
vgId
;
// SList<int32_t>
}
SMqSubConsumerObj
;
typedef
struct
SMqSubCGroupObj
{
char
name
[
TSDB_CONSUMER_GROUP_LEN
];
SList
*
consumers
;
// SList<SMqConsumerObj>
SList
*
consumers
;
// SList<SMqConsumerObj>
}
SMqSubCGroupObj
;
typedef
struct
SMqSubTopicObj
{
...
...
@@ -620,30 +654,30 @@ typedef struct SMqSubTopicObj {
int32_t
version
;
SRWLatch
lock
;
int32_t
sqlLen
;
char
*
sql
;
char
*
logicalPlan
;
char
*
physicalPlan
;
SList
*
cgroups
;
// SList<SMqSubCGroupObj>
char
*
sql
;
char
*
logicalPlan
;
char
*
physicalPlan
;
SList
*
cgroups
;
// SList<SMqSubCGroupObj>
}
SMqSubTopicObj
;
typedef
struct
SMqConsumerSubObj
{
int64_t
topicUid
;
SList
*
vgIds
;
// SList<int64_t>
SList
*
vgIds
;
// SList<int64_t>
}
SMqConsumerSubObj
;
typedef
struct
SMqConsumerHbObj
{
int64_t
consumerId
;
SList
*
consumerSubs
;
// SList<SMqConsumerSubObj>
SList
*
consumerSubs
;
// SList<SMqConsumerSubObj>
}
SMqConsumerHbObj
;
typedef
struct
SMqVGroupSubObj
{
int64_t
topicUid
;
SList
*
consumerIds
;
// SList<int64_t>
SList
*
consumerIds
;
// SList<int64_t>
}
SMqVGroupSubObj
;
typedef
struct
SMqVGroupHbObj
{
int64_t
vgId
;
SList
*
vgSubs
;
// SList<SMqVGroupSubObj>
SList
*
vgSubs
;
// SList<SMqVGroupSubObj>
}
SMqVGroupHbObj
;
#if 0
...
...
@@ -663,11 +697,11 @@ typedef struct SMnodeMsg {
char
user
[
TSDB_USER_LEN
];
char
db
[
TSDB_DB_FNAME_LEN
];
int32_t
acctId
;
SMnode
*
pMnode
;
SMnode
*
pMnode
;
int64_t
createdTime
;
SRpcMsg
rpcMsg
;
int32_t
contLen
;
void
*
pCont
;
void
*
pCont
;
}
SMnodeMsg
;
#ifdef __cplusplus
...
...
source/dnode/mnode/impl/src/mndSubscribe.c
浏览文件 @
4edcf262
...
...
@@ -98,7 +98,8 @@ static int32_t mndProcessMqTimerMsg(SMnodeMsg *pMsg) {
// build msg
SMqSetCVgReq
req
=
{
.
vgId
=
pCEp
->
vgId
,
.
consumerId
=
consumerId
,
.
oldConsumerId
=
-
1
,
.
newConsumerId
=
consumerId
,
};
strcpy
(
req
.
cgroup
,
cgroup
);
strcpy
(
req
.
topicName
,
topic
);
...
...
@@ -152,6 +153,7 @@ static int mndInitUnassignedVg(SMnode *pMnode, SMqTopicObj *pTopic, SArray *unas
//convert dag to msg
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
SMqConsumerEp
CEp
;
CEp
.
status
=
0
;
CEp
.
lastConsumerHbTs
=
CEp
.
lastVgHbTs
=
-
1
;
STaskInfo
*
pTaskInfo
=
taosArrayGet
(
pArray
,
i
);
tConvertQueryAddrToEpSet
(
&
CEp
.
epSet
,
&
pTaskInfo
->
addr
);
...
...
@@ -171,7 +173,8 @@ static int mndBuildMqSetConsumerVgReq(SMnode *pMnode, STrans *pTrans, SMqConsume
SVgObj
*
pVgObj
=
mndAcquireVgroup
(
pMnode
,
vgId
);
SMqSetCVgReq
req
=
{
.
vgId
=
vgId
,
.
consumerId
=
pConsumer
->
consumerId
,
.
oldConsumerId
=
-
1
,
.
newConsumerId
=
pConsumer
->
consumerId
,
};
strcpy
(
req
.
cgroup
,
pConsumer
->
cgroup
);
strcpy
(
req
.
topicName
,
pTopic
->
name
);
...
...
@@ -451,12 +454,13 @@ static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) {
SMqTopicObj
*
pTopic
=
mndAcquireTopic
(
pMnode
,
newTopicName
);
if
(
pTopic
==
NULL
)
{
/*terrno = */
mError
(
"topic being subscribed not exist: %s"
,
newTopicName
);
continue
;
}
SMqSubscribeObj
*
pSub
=
mndAcquireSubscribe
(
pMnode
,
consumerGroup
,
newTopicName
);
if
(
pSub
==
NULL
)
{
mDebug
(
"create new subscription, group: %s, topic %s"
,
consumerGroup
,
newTopicName
);
pSub
=
tNewSubscribeObj
();
if
(
pSub
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -464,14 +468,15 @@ static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) {
}
// set unassigned vg
mndInitUnassignedVg
(
pMnode
,
pTopic
,
pSub
->
unassignedVg
);
//TODO: disable alter
}
taosArrayPush
(
pSub
->
availConsumer
,
&
consumerId
);
// TODO: no need
SMqConsumerTopic
*
pConsumerTopic
=
tNewConsumerTopic
(
consumerId
,
pTopic
,
pSub
);
taosArrayPush
(
pConsumer
->
topics
,
pConsumerTopic
);
if
(
taosArrayGetSize
(
pConsumerTopic
->
pVgInfo
)
>
0
)
{
ASSERT
(
taosArrayGetSize
(
pConsumerTopic
->
pVgInfo
)
==
1
);
int32_t
vgId
=
*
(
int32_t
*
)
taosArrayGetLast
(
pConsumerTopic
->
pVgInfo
);
// send setmsg to vnode
if
(
mndBuildMqSetConsumerVgReq
(
pMnode
,
pTrans
,
pConsumer
,
pConsumerTopic
,
pTopic
)
<
0
)
{
...
...
@@ -479,8 +484,7 @@ static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) {
return
-
1
;
}
}
taosArrayDestroy
(
pConsumerTopic
->
pVgInfo
);
free
(
pConsumerTopic
);
SSdbRaw
*
pRaw
=
mndSubActionEncode
(
pSub
);
/*sdbSetRawStatus(pRaw, SDB_STATUS_READY);*/
mndTransAppendRedolog
(
pTrans
,
pRaw
);
...
...
@@ -533,12 +537,12 @@ static int32_t mndProcessSubscribeReq(SMnodeMsg *pMsg) {
if
(
mndTransPrepare
(
pMnode
,
pTrans
)
!=
0
)
{
mError
(
"trans:%d, failed to prepare since %s"
,
pTrans
->
id
,
terrstr
());
if
(
newSub
)
taosArrayDestroy
(
newSub
);
mndTransDrop
(
pTrans
);
mndReleaseConsumer
(
pMnode
,
pConsumer
);
return
-
1
;
}
// TODO: free memory
if
(
newSub
)
taosArrayDestroy
(
newSub
);
mndTransDrop
(
pTrans
);
mndReleaseConsumer
(
pMnode
,
pConsumer
);
...
...
source/dnode/vnode/inc/tq.h
浏览文件 @
4edcf262
...
...
@@ -18,7 +18,6 @@
#include "common.h"
#include "executor.h"
#include "vnode.h"
#include "mallocator.h"
#include "meta.h"
#include "os.h"
...
...
@@ -29,6 +28,7 @@
#include "trpc.h"
#include "ttimer.h"
#include "tutil.h"
#include "vnode.h"
#include "wal.h"
#ifdef __cplusplus
...
...
@@ -153,6 +153,7 @@ typedef struct STqTaskItem {
int64_t
offset
;
void
*
dst
;
qTaskInfo_t
task
;
SSubQueryMsg
*
pQueryMsg
;
}
STqTaskItem
;
// new version
...
...
@@ -164,7 +165,6 @@ typedef struct STqBuffer {
typedef
struct
STqTopicHandle
{
char
topicName
[
TSDB_TOPIC_FNAME_LEN
];
char
cgroup
[
TSDB_TOPIC_FNAME_LEN
];
char
*
sql
;
char
*
logicalPlan
;
char
*
physicalPlan
;
...
...
@@ -177,6 +177,7 @@ typedef struct STqTopicHandle {
typedef
struct
STqConsumerHandle
{
int64_t
consumerId
;
int64_t
epoch
;
char
cgroup
[
TSDB_TOPIC_FNAME_LEN
];
SArray
*
topics
;
// SArray<STqClientTopic>
}
STqConsumerHandle
;
...
...
@@ -318,7 +319,7 @@ int tqSendLaunchQuery(STqMsgItem*, int64_t offset);
#endif
int32_t
tqProcessConsumeReq
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
ppRsp
);
int32_t
tqProcessSetConnReq
(
STQ
*
pTq
,
SMqSetCVgReq
*
pReq
);
int32_t
tqProcessSetConnReq
(
STQ
*
pTq
,
char
*
msg
);
#ifdef __cplusplus
}
...
...
source/dnode/vnode/src/inc/tqInt.h
浏览文件 @
4edcf262
...
...
@@ -44,8 +44,10 @@ extern int32_t tqDebugFlag;
// delete persistent storage for meta info
// int tqDropTCGroup(STQ*, const char* topic, int cgId);
int
tqSerializeGroup
(
const
STqGroup
*
,
STqSerializedHead
**
);
const
void
*
tqDeserializeGroup
(
const
STqSerializedHead
*
pHead
,
STqGroup
**
ppGroup
);
//int tqSerializeGroup(const STqGroup*, STqSerializedHead**);
//const void* tqDeserializeGroup(const STqSerializedHead* pHead, STqGroup** ppGroup);
int
tqSerializeConsumer
(
const
STqConsumerHandle
*
,
STqSerializedHead
**
);
const
void
*
tqDeserializeConsumer
(
const
STqSerializedHead
*
pHead
,
STqConsumerHandle
**
);
static
int
FORCE_INLINE
tqQueryExecuting
(
int32_t
status
)
{
return
status
;
}
#ifdef __cplusplus
}
...
...
source/dnode/vnode/src/tq/tq.c
浏览文件 @
4edcf262
...
...
@@ -68,7 +68,7 @@ STQ* tqOpen(const char* path, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig, SMemAl
// TODO: error code of buffer pool
}
#endif
pTq
->
tqMeta
=
tqStoreOpen
(
path
,
(
FTqSerialize
)
tqSerialize
Group
,
(
FTqDeserialize
)
tqDeserializeGroup
,
free
,
0
);
pTq
->
tqMeta
=
tqStoreOpen
(
path
,
(
FTqSerialize
)
tqSerialize
Consumer
,
(
FTqDeserialize
)
tqDeserializeConsumer
,
free
,
0
);
if
(
pTq
->
tqMeta
==
NULL
)
{
free
(
pTq
);
#if 0
...
...
@@ -478,6 +478,59 @@ int tqConsume(STQ* pTq, STqConsumeReq* pMsg) {
}
#endif
int
tqSerializeConsumer
(
const
STqConsumerHandle
*
pConsumer
,
STqSerializedHead
**
ppHead
)
{
int32_t
num
=
taosArrayGetSize
(
pConsumer
->
topics
);
int32_t
sz
=
sizeof
(
STqSerializedHead
)
+
sizeof
(
int64_t
)
*
2
+
TSDB_TOPIC_FNAME_LEN
+
num
*
(
sizeof
(
int64_t
)
+
TSDB_TOPIC_FNAME_LEN
);
if
(
sz
>
(
*
ppHead
)
->
ssize
)
{
void
*
tmpPtr
=
realloc
(
*
ppHead
,
sz
);
if
(
tmpPtr
==
NULL
)
{
free
(
*
ppHead
);
return
-
1
;
}
*
ppHead
=
tmpPtr
;
(
*
ppHead
)
->
ssize
=
sz
;
}
void
*
ptr
=
(
*
ppHead
)
->
content
;
*
(
int64_t
*
)
ptr
=
pConsumer
->
consumerId
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
*
(
int64_t
*
)
ptr
=
pConsumer
->
epoch
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
memcpy
(
ptr
,
pConsumer
->
topics
,
TSDB_TOPIC_FNAME_LEN
);
ptr
=
POINTER_SHIFT
(
ptr
,
TSDB_TOPIC_FNAME_LEN
);
*
(
int32_t
*
)
ptr
=
num
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
for
(
int32_t
i
=
0
;
i
<
num
;
i
++
)
{
STqTopicHandle
*
pTopic
=
taosArrayGet
(
pConsumer
->
topics
,
i
);
memcpy
(
ptr
,
pTopic
->
topicName
,
TSDB_TOPIC_FNAME_LEN
);
ptr
=
POINTER_SHIFT
(
ptr
,
TSDB_TOPIC_FNAME_LEN
);
*
(
int64_t
*
)
ptr
=
pTopic
->
committedOffset
;
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
}
return
0
;
}
const
void
*
tqDeserializeConsumer
(
const
STqSerializedHead
*
pHead
,
STqConsumerHandle
**
ppConsumer
)
{
STqConsumerHandle
*
pConsumer
=
*
ppConsumer
;
const
void
*
ptr
=
pHead
->
content
;
pConsumer
->
consumerId
=
*
(
int64_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
pConsumer
->
epoch
=
*
(
int64_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int64_t
));
memcpy
(
pConsumer
->
cgroup
,
ptr
,
TSDB_TOPIC_FNAME_LEN
);
ptr
=
POINTER_SHIFT
(
ptr
,
TSDB_TOPIC_FNAME_LEN
);
int32_t
sz
=
*
(
int32_t
*
)
ptr
;
ptr
=
POINTER_SHIFT
(
ptr
,
sizeof
(
int32_t
));
pConsumer
->
topics
=
taosArrayInit
(
sz
,
sizeof
(
STqTopicHandle
));
for
(
int32_t
i
=
0
;
i
<
sz
;
i
++
)
{
/*STqTopicHandle* topicHandle = */
/*taosArrayPush(pConsumer->topics, );*/
}
return
NULL
;
}
#if 0
int tqSerializeGroup(const STqGroup* pGroup, STqSerializedHead** ppHead) {
// calculate size
int sz = tqGroupSSize(pGroup) + sizeof(STqSerializedHead);
...
...
@@ -608,6 +661,7 @@ int tqItemSSize() {
// mainly for executor
return 0;
}
#endif
int32_t
tqProcessConsumeReq
(
STQ
*
pTq
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
ppRsp
)
{
SMqConsumeReq
*
pReq
=
pMsg
->
pCont
;
...
...
@@ -625,7 +679,14 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg** ppRsp) {
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
STqTopicHandle
*
pTopic
=
taosArrayGet
(
pConsumer
->
topics
,
i
);
//TODO: support multiple topic in one req
if
(
strcmp
(
pTopic
->
topicName
,
pReq
->
topic
)
!=
0
)
{
continue
;
}
if
(
fetchOffset
==
-
1
)
{
fetchOffset
=
pTopic
->
committedOffset
+
1
;
}
int8_t
pos
;
int8_t
skip
=
0
;
SWalHead
*
pHead
;
...
...
@@ -670,6 +731,23 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg** ppRsp) {
break
;
}
if
(
pDataBlock
!=
NULL
)
{
SMqTbData
tbData
=
{
.
uid
=
pDataBlock
->
info
.
uid
,
.
numOfCols
=
pDataBlock
->
info
.
numOfCols
,
.
numOfRows
=
pDataBlock
->
info
.
rows
,
};
for
(
int
i
=
0
;
i
<
pDataBlock
->
info
.
numOfCols
;
i
++
)
{
SColumnInfoData
*
pColData
=
taosArrayGet
(
pDataBlock
->
pDataBlock
,
i
);
int32_t
sz
=
pColData
->
info
.
bytes
*
pDataBlock
->
info
.
rows
;
SMqColData
colData
=
{
.
bytes
=
pColData
->
info
.
bytes
,
.
colId
=
pColData
->
info
.
colId
,
.
type
=
pColData
->
info
.
type
,
};
memcpy
(
colData
.
data
,
pColData
->
pData
,
colData
.
bytes
*
pDataBlock
->
info
.
rows
);
memcpy
(
&
tbData
.
colData
[
i
],
&
colData
,
sz
);
}
/*pDataBlock->info.*/
taosArrayPush
(
pRes
,
pDataBlock
);
}
else
{
break
;
...
...
@@ -692,29 +770,34 @@ int32_t tqProcessConsumeReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg** ppRsp) {
pTopic
->
buffer
.
lastOffset
=
pReq
->
offset
;
}
// put output into rsp
SMqConsumeRsp
rsp
=
{
.
consumerId
=
consumerId
,
.
numOfTopics
=
1
};
}
// launch query
// get result
return
0
;
}
int32_t
tqProcessSetConnReq
(
STQ
*
pTq
,
SMqSetCVgReq
*
pReq
)
{
int32_t
tqProcessSetConnReq
(
STQ
*
pTq
,
char
*
msg
)
{
SMqSetCVgReq
req
;
tDecodeSMqSetCVgReq
(
msg
,
&
req
);
STqConsumerHandle
*
pConsumer
=
calloc
(
sizeof
(
STqConsumerHandle
),
1
);
if
(
pConsumer
==
NULL
)
{
return
-
1
;
}
strcpy
(
pConsumer
->
cgroup
,
req
.
cgroup
);
pConsumer
->
topics
=
taosArrayInit
(
0
,
sizeof
(
STqTopicHandle
));
STqTopicHandle
*
pTopic
=
calloc
(
sizeof
(
STqTopicHandle
),
1
);
if
(
pTopic
==
NULL
)
{
free
(
pConsumer
);
return
-
1
;
}
strcpy
(
pTopic
->
topicName
,
pReq
->
topicName
);
strcpy
(
pTopic
->
cgroup
,
pReq
->
cgroup
);
strcpy
(
pTopic
->
sql
,
pReq
->
sql
);
strcpy
(
pTopic
->
logicalPlan
,
pReq
->
logicalPlan
);
strcpy
(
pTopic
->
physicalPlan
,
pReq
->
physicalPlan
);
strcpy
(
pTopic
->
topicName
,
req
.
topicName
);
strcpy
(
pTopic
->
sql
,
req
.
sql
);
strcpy
(
pTopic
->
logicalPlan
,
req
.
logicalPlan
);
strcpy
(
pTopic
->
physicalPlan
,
req
.
physicalPlan
);
pTopic
->
buffer
.
firstOffset
=
-
1
;
pTopic
->
buffer
.
lastOffset
=
-
1
;
...
...
@@ -724,9 +807,9 @@ int32_t tqProcessSetConnReq(STQ* pTq, SMqSetCVgReq* pReq) {
for
(
int
i
=
0
;
i
<
TQ_BUFFER_SIZE
;
i
++
)
{
pTopic
->
buffer
.
output
[
i
].
status
=
0
;
STqReadHandle
*
pReadHandle
=
tqInitSubmitMsgScanner
(
pTq
->
pMeta
);
pTopic
->
buffer
.
output
[
i
].
task
=
qCreateStreamExecTaskInfo
(
&
pReq
->
msg
,
pReadHandle
);
pTopic
->
buffer
.
output
[
i
].
task
=
qCreateStreamExecTaskInfo
(
&
req
.
msg
,
pReadHandle
);
}
// write mq meta
taosArrayPush
(
pConsumer
->
topics
,
pTopic
);
return
0
;
}
...
...
source/dnode/vnode/src/vnd/vnodeQuery.c
浏览文件 @
4edcf262
...
...
@@ -25,7 +25,7 @@ int vnodeQueryOpen(SVnode *pVnode) {
}
int
vnodeProcessQueryReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
vTrace
(
"
query messag
e is processing"
);
vTrace
(
"
message in query queu
e is processing"
);
switch
(
pMsg
->
msgType
)
{
case
TDMT_VND_QUERY
:
...
...
@@ -39,7 +39,7 @@ int vnodeProcessQueryReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
}
int
vnodeProcessFetchReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
vTrace
(
"
fetch message is processed
"
);
vTrace
(
"
message in fetch queue is processing
"
);
switch
(
pMsg
->
msgType
)
{
case
TDMT_VND_FETCH
:
return
qWorkerProcessFetchMsg
(
pVnode
,
pVnode
->
pQuery
,
pMsg
);
...
...
source/dnode/vnode/src/vnd/vnodeWrite.c
浏览文件 @
4edcf262
...
...
@@ -112,9 +112,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
}
break
;
case
TDMT_VND_MQ_SET_CONN
:
{
SMqSetCVgReq
req
;
tDecodeSMqSetCVgReq
(
ptr
,
&
req
);
if
(
tqProcessSetConnReq
(
pVnode
->
pTq
,
&
req
)
<
0
)
{
if
(
tqProcessSetConnReq
(
pVnode
->
pTq
,
ptr
)
<
0
)
{
}
}
break
;
default:
...
...
source/libs/qworker/inc/qworkerInt.h
浏览文件 @
4edcf262
...
...
@@ -22,17 +22,17 @@ extern "C" {
#include "tlockfree.h"
#define QW
ORKER
_DEFAULT_SCHEDULER_NUMBER 10000
#define QW
ORKER
_DEFAULT_TASK_NUMBER 10000
#define QW
ORKER
_DEFAULT_SCH_TASK_NUMBER 10000
#define QW_DEFAULT_SCHEDULER_NUMBER 10000
#define QW_DEFAULT_TASK_NUMBER 10000
#define QW_DEFAULT_SCH_TASK_NUMBER 10000
#define QW_DEFAULT_SHORT_RUN_TIMES 2
enum
{
QW_PHASE_PRE_QUERY
=
1
,
QW_PHASE_POST_QUERY
,
QW_PHASE_PRE_CQUERY
,
QW_PHASE_POST_CQUERY
,
QW_PHASE_PRE_FETCH
,
QW_PHASE_POST_FETCH
,
QW_PHASE_PRE_CQUERY
,
QW_PHASE_POST_CQUERY
,
};
enum
{
...
...
@@ -83,11 +83,9 @@ typedef struct SQWMsg {
}
SQWMsg
;
typedef
struct
SQWPhaseInput
{
int8_t
s
tatus
;
int8_t
taskS
tatus
;
int8_t
taskType
;
int32_t
code
;
qTaskInfo_t
taskHandle
;
DataSinkHandle
sinkHandle
;
}
SQWPhaseInput
;
typedef
struct
SQWPhaseOutput
{
...
...
@@ -111,6 +109,7 @@ typedef struct SQWTaskCtx {
void
*
cancelConnection
;
bool
emptyRes
;
bool
multiExec
;
int8_t
queryContinue
;
int8_t
queryInQueue
;
int32_t
rspCode
;
...
...
@@ -133,7 +132,7 @@ typedef struct SQWorkerMgmt {
int8_t
nodeType
;
int32_t
nodeId
;
SRWLatch
schLock
;
SRWLatch
ctxLock
;
//
SRWLatch ctxLock;
SHashObj
*
schHash
;
//key: schedulerId, value: SQWSchStatus
SHashObj
*
ctxHash
;
//key: queryId+taskId, value: SQWTaskCtx
void
*
nodeObj
;
...
...
@@ -144,6 +143,8 @@ typedef struct SQWorkerMgmt {
#define QW_IDS() sId, qId, tId
#define QW_FPARAMS() mgmt, QW_IDS()
#define QW_GET_EVENT_VALUE(ctx, event) atomic_load_8(&(ctx)->events[event])
#define QW_IS_EVENT_RECEIVED(ctx, event) (atomic_load_8(&(ctx)->events[event]) == QW_EVENT_RECEIVED)
#define QW_IS_EVENT_PROCESSED(ctx, event) (atomic_load_8(&(ctx)->events[event]) == QW_EVENT_PROCESSED)
#define QW_SET_EVENT_RECEIVED(ctx, event) atomic_store_8(&(ctx)->events[event], QW_EVENT_RECEIVED)
...
...
@@ -151,9 +152,10 @@ typedef struct SQWorkerMgmt {
#define QW_GET_PHASE(ctx) atomic_load_8(&(ctx)->phase)
#define QW_SET_RSP_CODE(ctx, code) atomic_val_compare_exchange_32(&(ctx)->rspCode, 0, code)
#define QW_SET_RSP_CODE(ctx, code) atomic_store_32(&(ctx)->rspCode, code)
#define QW_UPDATE_RSP_CODE(ctx, code) atomic_val_compare_exchange_32(&(ctx)->rspCode, 0, code)
#define QW_I
N_EXECUTOR(ctx) (QW_GET_PHASE(ctx) == QW_PHASE_PRE_QUERY || QW_GET_PHASE(ctx) == QW_PHASE_PRE_CQUERY || QW_GET_PHASE(ctx) == QW_PHASE_PRE_FETCH
)
#define QW_I
S_QUERY_RUNNING(ctx) (QW_GET_PHASE(ctx) == QW_PHASE_PRE_QUERY || QW_GET_PHASE(ctx) == QW_PHASE_PRE_CQUERY
)
#define QW_TASK_NOT_EXIST(code) (TSDB_CODE_QRY_SCH_NOT_EXIST == (code) || TSDB_CODE_QRY_TASK_NOT_EXIST == (code))
#define QW_TASK_ALREADY_EXIST(code) (TSDB_CODE_QRY_TASK_ALREADY_EXIST == (code))
...
...
source/libs/qworker/inc/qworkerMsg.h
浏览文件 @
4edcf262
...
...
@@ -30,6 +30,7 @@ int32_t qwProcessFetch(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
int32_t
qwProcessDrop
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWMsg
*
qwMsg
);
int32_t
qwBuildAndSendDropRsp
(
void
*
connection
,
int32_t
code
);
int32_t
qwBuildAndSendCancelRsp
(
SRpcMsg
*
pMsg
,
int32_t
code
);
int32_t
qwBuildAndSendFetchRsp
(
void
*
connection
,
SRetrieveTableRsp
*
pRsp
,
int32_t
dataLength
,
int32_t
code
);
void
qwBuildFetchRsp
(
void
*
msg
,
SOutputData
*
input
,
int32_t
len
);
int32_t
qwBuildAndSendCQueryMsg
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
void
*
connection
);
...
...
source/libs/qworker/src/qworker.c
浏览文件 @
4edcf262
...
...
@@ -11,7 +11,7 @@
SQWDebug
gQWDebug
=
{
0
};
int32_t
qwValidateStatus
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int8_t
oriStatus
,
int8_t
newStatus
)
{
int32_t
qwValidateStatus
(
QW_FPARAMS_DEF
,
int8_t
oriStatus
,
int8_t
newStatus
)
{
int32_t
code
=
0
;
if
(
oriStatus
==
newStatus
)
{
...
...
@@ -35,6 +35,7 @@ int32_t qwValidateStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_
break
;
case
JOB_TASK_STATUS_EXECUTING
:
if
(
newStatus
!=
JOB_TASK_STATUS_PARTIAL_SUCCEED
&&
newStatus
!=
JOB_TASK_STATUS_SUCCEED
&&
newStatus
!=
JOB_TASK_STATUS_FAILED
&&
newStatus
!=
JOB_TASK_STATUS_CANCELLING
&&
newStatus
!=
JOB_TASK_STATUS_CANCELLED
...
...
@@ -52,6 +53,12 @@ int32_t qwValidateStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_
break
;
case
JOB_TASK_STATUS_SUCCEED
:
if
(
newStatus
!=
JOB_TASK_STATUS_CANCELLED
&&
newStatus
!=
JOB_TASK_STATUS_DROPPING
)
{
QW_ERR_JRET
(
TSDB_CODE_QRY_APP_ERROR
);
}
break
;
case
JOB_TASK_STATUS_FAILED
:
case
JOB_TASK_STATUS_CANCELLING
:
if
(
newStatus
!=
JOB_TASK_STATUS_CANCELLED
)
{
...
...
@@ -77,7 +84,7 @@ _return:
QW_RET
(
code
);
}
int32_t
qwSetTaskStatus
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWTaskStatus
*
task
,
int8_t
status
)
{
int32_t
qwSetTaskStatus
(
QW_FPARAMS_DEF
,
SQWTaskStatus
*
task
,
int8_t
status
)
{
int32_t
code
=
0
;
int8_t
origStatus
=
0
;
...
...
@@ -99,7 +106,7 @@ int32_t qwSetTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
}
int32_t
qwAddSchedulerImpl
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
rwType
,
SQWSchStatus
**
sch
)
{
int32_t
qwAddSchedulerImpl
(
QW_FPARAMS_DEF
,
int32_t
rwType
,
SQWSchStatus
**
sch
)
{
SQWSchStatus
newSch
=
{
0
};
newSch
.
tasksHash
=
taosHashInit
(
mgmt
->
cfg
.
maxSchTaskNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
newSch
.
tasksHash
)
{
...
...
@@ -125,7 +132,7 @@ int32_t qwAddSchedulerImpl(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint6
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwAcquireSchedulerImpl
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
rwType
,
SQWSchStatus
**
sch
,
int32_t
nOpt
)
{
int32_t
qwAcquireSchedulerImpl
(
QW_FPARAMS_DEF
,
int32_t
rwType
,
SQWSchStatus
**
sch
,
int32_t
nOpt
)
{
while
(
true
)
{
QW_LOCK
(
rwType
,
&
mgmt
->
schLock
);
*
sch
=
taosHashGet
(
mgmt
->
schHash
,
&
sId
,
sizeof
(
sId
));
...
...
@@ -152,11 +159,11 @@ int32_t qwAcquireSchedulerImpl(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, u
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwAcquireAddScheduler
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
rwType
,
SQWSchStatus
**
sch
)
{
int32_t
qwAcquireAddScheduler
(
QW_FPARAMS_DEF
,
int32_t
rwType
,
SQWSchStatus
**
sch
)
{
return
qwAcquireSchedulerImpl
(
QW_FPARAMS
(),
rwType
,
sch
,
QW_NOT_EXIST_ADD
);
}
int32_t
qwAcquireScheduler
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
rwType
,
SQWSchStatus
**
sch
)
{
int32_t
qwAcquireScheduler
(
QW_FPARAMS_DEF
,
int32_t
rwType
,
SQWSchStatus
**
sch
)
{
return
qwAcquireSchedulerImpl
(
QW_FPARAMS
(),
rwType
,
sch
,
QW_NOT_EXIST_RET_ERR
);
}
...
...
@@ -165,7 +172,7 @@ void qwReleaseScheduler(int32_t rwType, SQWorkerMgmt *mgmt) {
}
int32_t
qwAcquireTaskStatus
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
rwType
,
SQWSchStatus
*
sch
,
SQWTaskStatus
**
task
)
{
int32_t
qwAcquireTaskStatus
(
QW_FPARAMS_DEF
,
int32_t
rwType
,
SQWSchStatus
*
sch
,
SQWTaskStatus
**
task
)
{
char
id
[
sizeof
(
qId
)
+
sizeof
(
tId
)]
=
{
0
};
QW_SET_QTID
(
id
,
qId
,
tId
);
...
...
@@ -181,7 +188,7 @@ int32_t qwAcquireTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint
int32_t
qwAddTaskStatusImpl
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWSchStatus
*
sch
,
int32_t
rwType
,
int32_t
status
,
SQWTaskStatus
**
task
)
{
int32_t
qwAddTaskStatusImpl
(
QW_FPARAMS_DEF
,
SQWSchStatus
*
sch
,
int32_t
rwType
,
int32_t
status
,
SQWTaskStatus
**
task
)
{
int32_t
code
=
0
;
char
id
[
sizeof
(
qId
)
+
sizeof
(
tId
)]
=
{
0
};
...
...
@@ -215,7 +222,7 @@ int32_t qwAddTaskStatusImpl(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwAddTaskStatus
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
status
)
{
int32_t
qwAddTaskStatus
(
QW_FPARAMS_DEF
,
int32_t
status
)
{
SQWSchStatus
*
tsch
=
NULL
;
int32_t
code
=
0
;
QW_ERR_RET
(
qwAcquireAddScheduler
(
QW_FPARAMS
(),
QW_READ
,
&
tsch
));
...
...
@@ -230,7 +237,7 @@ _return:
}
int32_t
qwAddAcquireTaskStatus
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
rwType
,
SQWSchStatus
*
sch
,
int32_t
status
,
SQWTaskStatus
**
task
)
{
int32_t
qwAddAcquireTaskStatus
(
QW_FPARAMS_DEF
,
int32_t
rwType
,
SQWSchStatus
*
sch
,
int32_t
status
,
SQWTaskStatus
**
task
)
{
return
qwAddTaskStatusImpl
(
QW_FPARAMS
(),
sch
,
rwType
,
status
,
task
);
}
...
...
@@ -240,48 +247,48 @@ void qwReleaseTaskStatus(int32_t rwType, SQWSchStatus *sch) {
}
int32_t
qwAcquireTaskCtx
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
rwType
,
SQWTaskCtx
**
ctx
)
{
int32_t
qwAcquireTaskCtx
(
QW_FPARAMS_DEF
,
SQWTaskCtx
**
ctx
)
{
char
id
[
sizeof
(
qId
)
+
sizeof
(
tId
)]
=
{
0
};
QW_SET_QTID
(
id
,
qId
,
tId
);
QW_LOCK
(
rwType
,
&
mgmt
->
ctxLock
);
*
ctx
=
taosHash
Get
(
mgmt
->
ctxHash
,
id
,
sizeof
(
id
));
//
QW_LOCK(rwType, &mgmt->ctxLock);
*
ctx
=
taosHash
Acquire
(
mgmt
->
ctxHash
,
id
,
sizeof
(
id
));
if
(
NULL
==
(
*
ctx
))
{
QW_UNLOCK
(
rwType
,
&
mgmt
->
ctxLock
);
QW_TASK_
ELOG
(
"ctx not in ctxHash, id:%s"
,
id
);
QW_ERR_RET
(
TSDB_CODE_QRY_
RES_CACHE
_NOT_EXIST
);
//
QW_UNLOCK(rwType, &mgmt->ctxLock);
QW_TASK_
DLOG_E
(
"task ctx not exist, may be dropped"
);
QW_ERR_RET
(
TSDB_CODE_QRY_
TASK_CTX
_NOT_EXIST
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwGetTaskCtx
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWTaskCtx
**
ctx
)
{
int32_t
qwGetTaskCtx
(
QW_FPARAMS_DEF
,
SQWTaskCtx
**
ctx
)
{
char
id
[
sizeof
(
qId
)
+
sizeof
(
tId
)]
=
{
0
};
QW_SET_QTID
(
id
,
qId
,
tId
);
*
ctx
=
taosHashGet
(
mgmt
->
ctxHash
,
id
,
sizeof
(
id
));
if
(
NULL
==
(
*
ctx
))
{
QW_TASK_
ELOG
(
"ctx not in ctxHash, ctxHashSize:%d"
,
taosHashGetSize
(
mgmt
->
ctxHash
)
);
QW_ERR_RET
(
TSDB_CODE_QRY_
RES_CACHE
_NOT_EXIST
);
QW_TASK_
DLOG_E
(
"task ctx not exist, may be dropped"
);
QW_ERR_RET
(
TSDB_CODE_QRY_
TASK_CTX
_NOT_EXIST
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwAddTaskCtxImpl
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
rwTyp
e
,
int32_t
status
,
SQWTaskCtx
**
ctx
)
{
int32_t
qwAddTaskCtxImpl
(
QW_FPARAMS_DEF
,
bool
acquir
e
,
int32_t
status
,
SQWTaskCtx
**
ctx
)
{
char
id
[
sizeof
(
qId
)
+
sizeof
(
tId
)]
=
{
0
};
QW_SET_QTID
(
id
,
qId
,
tId
);
SQWTaskCtx
nctx
=
{
0
};
QW_LOCK
(
QW_WRITE
,
&
mgmt
->
ctxLock
);
//
QW_LOCK(QW_WRITE, &mgmt->ctxLock);
int32_t
code
=
taosHashPut
(
mgmt
->
ctxHash
,
id
,
sizeof
(
id
),
&
nctx
,
sizeof
(
SQWTaskCtx
));
if
(
0
!=
code
)
{
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
ctxLock
);
//
QW_UNLOCK(QW_WRITE, &mgmt->ctxLock);
if
(
HASH_NODE_EXIST
(
code
))
{
if
(
rwTyp
e
&&
ctx
)
{
QW_RET
(
qwAcquireTaskCtx
(
QW_FPARAMS
(),
rwType
,
ctx
));
if
(
acquir
e
&&
ctx
)
{
QW_RET
(
qwAcquireTaskCtx
(
QW_FPARAMS
(),
ctx
));
}
else
if
(
ctx
)
{
QW_RET
(
qwGetTaskCtx
(
QW_FPARAMS
(),
ctx
));
}
else
{
...
...
@@ -293,10 +300,10 @@ int32_t qwAddTaskCtxImpl(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_
QW_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
ctxLock
);
//
QW_UNLOCK(QW_WRITE, &mgmt->ctxLock);
if
(
rwTyp
e
&&
ctx
)
{
QW_RET
(
qwAcquireTaskCtx
(
QW_FPARAMS
(),
rwType
,
ctx
));
if
(
acquir
e
&&
ctx
)
{
QW_RET
(
qwAcquireTaskCtx
(
QW_FPARAMS
(),
ctx
));
}
else
if
(
ctx
)
{
QW_RET
(
qwGetTaskCtx
(
QW_FPARAMS
(),
ctx
));
}
...
...
@@ -304,23 +311,24 @@ int32_t qwAddTaskCtxImpl(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwAddTaskCtx
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
)
{
QW_RET
(
qwAddTaskCtxImpl
(
QW_FPARAMS
(),
0
,
0
,
NULL
));
int32_t
qwAddTaskCtx
(
QW_FPARAMS_DEF
)
{
QW_RET
(
qwAddTaskCtxImpl
(
QW_FPARAMS
(),
false
,
0
,
NULL
));
}
int32_t
qwAddAcquireTaskCtx
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
rwType
,
SQWTaskCtx
**
ctx
)
{
return
qwAddTaskCtxImpl
(
QW_FPARAMS
(),
rwTyp
e
,
0
,
ctx
);
int32_t
qwAddAcquireTaskCtx
(
QW_FPARAMS_DEF
,
SQWTaskCtx
**
ctx
)
{
return
qwAddTaskCtxImpl
(
QW_FPARAMS
(),
tru
e
,
0
,
ctx
);
}
int32_t
qwAddGetTaskCtx
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWTaskCtx
**
ctx
)
{
return
qwAddTaskCtxImpl
(
QW_FPARAMS
(),
0
,
0
,
ctx
);
int32_t
qwAddGetTaskCtx
(
QW_FPARAMS_DEF
,
SQWTaskCtx
**
ctx
)
{
return
qwAddTaskCtxImpl
(
QW_FPARAMS
(),
false
,
0
,
ctx
);
}
void
qwReleaseTaskCtx
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
)
{
QW_UNLOCK
(
rwType
,
&
mgmt
->
ctxLock
);
void
qwReleaseTaskCtx
(
SQWorkerMgmt
*
mgmt
,
void
*
ctx
)
{
//QW_UNLOCK(rwType, &mgmt->ctxLock);
taosHashRelease
(
mgmt
->
ctxHash
,
ctx
);
}
void
qwFreeTaskHandle
(
QW_FPARAMS_DEF
,
qTaskInfo_t
*
taskHandle
)
{
...
...
@@ -355,21 +363,30 @@ void qwFreeTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx) {
// Note: NEED CTX HASH LOCKED BEFORE ENTRANCE
int32_t
qwDropTaskCtx
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
)
{
int32_t
qwDropTaskCtx
(
QW_FPARAMS_DEF
,
int32_t
rwType
)
{
char
id
[
sizeof
(
qId
)
+
sizeof
(
tId
)]
=
{
0
};
QW_SET_QTID
(
id
,
qId
,
tId
);
SQWTaskCtx
octx
;
SQWTaskCtx
*
ctx
=
taosHashGet
(
mgmt
->
ctxHash
,
id
,
sizeof
(
id
));
if
(
NULL
==
ctx
)
{
QW_ERR_RET
(
TSDB_CODE_QRY_
RES_CACHE
_NOT_EXIST
);
QW_ERR_RET
(
TSDB_CODE_QRY_
TASK_CTX
_NOT_EXIST
);
}
octx
=
*
ctx
;
atomic_store_ptr
(
&
ctx
->
taskHandle
,
NULL
);
atomic_store_ptr
(
&
ctx
->
sinkHandle
,
NULL
);
QW_SET_EVENT_PROCESSED
(
ctx
,
QW_EVENT_DROP
);
if
(
rwType
)
{
QW_UNLOCK
(
rwType
,
&
ctx
->
lock
);
}
if
(
taosHashRemove
(
mgmt
->
ctxHash
,
id
,
sizeof
(
id
)))
{
QW_TASK_ELOG_E
(
"taosHashRemove from ctx hash failed"
);
QW_ERR_RET
(
TSDB_CODE_QRY_
RES_CACHE
_NOT_EXIST
);
QW_ERR_RET
(
TSDB_CODE_QRY_
TASK_CTX
_NOT_EXIST
);
}
if
(
octx
.
taskHandle
)
{
...
...
@@ -386,7 +403,7 @@ int32_t qwDropTaskCtx(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t t
}
int32_t
qwDropTaskStatus
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
)
{
int32_t
qwDropTaskStatus
(
QW_FPARAMS_DEF
)
{
SQWSchStatus
*
sch
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
int32_t
code
=
0
;
...
...
@@ -421,7 +438,7 @@ _return:
QW_RET
(
code
);
}
int32_t
qwUpdateTaskStatus
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int8_t
status
)
{
int32_t
qwUpdateTaskStatus
(
QW_FPARAMS_DEF
,
int8_t
status
)
{
SQWSchStatus
*
sch
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
int32_t
code
=
0
;
...
...
@@ -439,12 +456,15 @@ _return:
QW_RET
(
code
);
}
int32_t
qwExecTask
(
QW_FPARAMS_DEF
,
qTaskInfo_t
*
taskHandle
,
DataSinkHandle
sinkHandle
,
int8_t
taskType
)
{
int32_t
qwExecTask
(
QW_FPARAMS_DEF
,
SQWTaskCtx
*
ctx
)
{
int32_t
code
=
0
;
bool
qcontinue
=
true
;
SSDataBlock
*
pRes
=
NULL
;
uint64_t
useconds
=
0
;
int32_t
i
=
0
;
int32_t
execNum
=
0
;
qTaskInfo_t
*
taskHandle
=
&
ctx
->
taskHandle
;
DataSinkHandle
sinkHandle
=
ctx
->
sinkHandle
;
while
(
true
)
{
QW_TASK_DLOG
(
"start to execTask in executor, loopIdx:%d"
,
i
++
);
...
...
@@ -455,14 +475,17 @@ int32_t qwExecTask(QW_FPARAMS_DEF, qTaskInfo_t *taskHandle, DataSinkHandle sinkH
QW_ERR_JRET
(
code
);
}
++
execNum
;
if
(
NULL
==
pRes
)
{
QW_TASK_DLOG
(
"task query done, useconds:%"
PRIu64
,
useconds
);
dsEndPut
(
sinkHandle
,
useconds
);
if
(
TASK_TYPE_TEMP
==
taskType
)
{
if
(
TASK_TYPE_TEMP
==
ctx
->
taskType
)
{
qwFreeTaskHandle
(
QW_FPARAMS
(),
taskHandle
);
}
break
;
}
...
...
@@ -478,6 +501,14 @@ int32_t qwExecTask(QW_FPARAMS_DEF, qTaskInfo_t *taskHandle, DataSinkHandle sinkH
if
(
!
qcontinue
)
{
break
;
}
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_READY
)
&&
execNum
>=
QW_DEFAULT_SHORT_RUN_TIMES
)
{
break
;
}
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_FETCH
))
{
break
;
}
}
_return:
...
...
@@ -532,6 +563,8 @@ int32_t qwGetResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void
return
TSDB_CODE_SUCCESS
;
}
pOutput
->
bufStatus
=
DS_BUF_EMPTY
;
QW_TASK_DLOG
(
"no res data in sink, need response later, queryEnd:%d"
,
queryEnd
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -567,28 +600,33 @@ int32_t qwGetResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwHandleTaskEvent
(
QW_FPARAMS_DEF
,
int8_t
phase
,
SQWPhaseInput
*
input
,
SQWPhaseOutput
*
output
)
{
int32_t
qwHandlePrePhaseEvents
(
QW_FPARAMS_DEF
,
int8_t
phase
,
SQWPhaseInput
*
input
,
SQWPhaseOutput
*
output
)
{
int32_t
code
=
0
;
int8_t
status
=
0
;
SQWTaskCtx
*
ctx
=
NULL
;
bool
locked
=
false
;
bool
ctxAcquired
=
false
;
void
*
readyConnection
=
NULL
;
void
*
dropConnection
=
NULL
;
void
*
cancelConnection
=
NULL
;
QW_SCH_TASK_DLOG
(
"start to handle event at phase %d"
,
phase
);
output
->
needStop
=
false
;
if
(
QW_PHASE_PRE_QUERY
==
phase
)
{
QW_ERR_JRET
(
qwAddAcquireTaskCtx
(
QW_FPARAMS
(),
&
ctx
));
}
else
{
QW_ERR_JRET
(
qwAcquireTaskCtx
(
QW_FPARAMS
(),
&
ctx
));
}
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
locked
=
true
;
switch
(
phase
)
{
case
QW_PHASE_PRE_QUERY
:
{
QW_ERR_JRET
(
qwAddGetTaskCtx
(
QW_FPARAMS
(),
&
ctx
)
);
atomic_store_8
(
&
ctx
->
phase
,
phase
);
atomic_store_32
(
&
ctx
->
phase
,
phase
);
atomic_store_8
(
&
ctx
->
taskType
,
input
->
taskType
);
if
(
QW_IS_EVENT_PROCESSED
(
ctx
,
QW_EVENT_CANCEL
))
{
QW_TASK_ELOG
(
"task already cancelled at wrong phase, phase:%d"
,
phase
);
if
(
QW_IS_EVENT_PROCESSED
(
ctx
,
QW_EVENT_CANCEL
)
||
QW_IS_EVENT_PROCESSED
(
ctx
,
QW_EVENT_DROP
))
{
QW_TASK_ELOG
(
"task already cancelled/dropped at wrong phase, phase:%d"
,
phase
);
output
->
needStop
=
true
;
output
->
rspCode
=
TSDB_CODE_QRY_TASK_STATUS_ERROR
;
...
...
@@ -597,88 +635,49 @@ int32_t qwHandleTaskEvent(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *input, SQ
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_DROP
))
{
QW_ERR_JRET
(
qwDropTaskStatus
(
QW_FPARAMS
()));
QW_ERR_JRET
(
qwDropTaskCtx
(
QW_FPARAMS
()));
QW_ERR_JRET
(
qwDropTaskCtx
(
QW_FPARAMS
()
,
QW_WRITE
));
output
->
needStop
=
true
;
output
->
rspCode
=
TSDB_CODE_QRY_TASK_DROPPED
;
QW_SET_RSP_CODE
(
ctx
,
output
->
rspCode
);
dropConnection
=
ctx
->
dropConnection
;
// Note: ctx freed, no need to unlock it
locked
=
false
;
}
else
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_CANCEL
))
{
output
->
needStop
=
true
;
break
;
}
else
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_CANCEL
))
{
QW_ERR_JRET
(
qwAddTaskStatus
(
QW_FPARAMS
(),
JOB_TASK_STATUS_CANCELLED
));
QW_SET_EVENT_PROCESSED
(
ctx
,
QW_EVENT_CANCEL
);
output
->
needStop
=
true
;
output
->
rspCode
=
TSDB_CODE_QRY_TASK_CANCELLED
;
}
if
(
!
output
->
needStop
)
{
QW_ERR_JRET
(
qwAddTaskStatus
(
QW_FPARAMS
(),
JOB_TASK_STATUS_EXECUTING
));
}
break
;
}
case
QW_PHASE_POST_QUERY
:
{
QW_ERR_JRET
(
qwGetTaskCtx
(
QW_FPARAMS
(),
&
ctx
));
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
locked
=
true
;
ctx
->
taskHandle
=
input
->
taskHandle
;
ctx
->
sinkHandle
=
input
->
sinkHandle
;
QW_SET_RSP_CODE
(
ctx
,
output
->
rspCode
);
if
(
NULL
==
ctx
->
taskHandle
&&
NULL
==
ctx
->
sinkHandle
)
{
ctx
->
emptyRes
=
true
;
}
cancelConnection
=
ctx
->
cancelConnection
;
if
(
input
->
code
)
{
output
->
rspCode
=
input
->
code
;
break
;
}
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_DROP
))
{
output
->
needStop
=
true
;
QW_ERR_JRET
(
qwDropTaskStatus
(
QW_FPARAMS
()));
QW_ERR_JRET
(
qwDropTaskCtx
(
QW_FPARAMS
()));
output
->
rspCode
=
TSDB_CODE_QRY_TASK_DROPPED
;
dropConnection
=
ctx
->
dropConnection
;
// Note: ctx freed, no need to unlock it
locked
=
false
;
}
else
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_CANCEL
))
{
if
(
ctx
->
rspCode
)
{
QW_TASK_ELOG
(
"task already failed at wrong phase, code:%x, phase:%d"
,
ctx
->
rspCode
,
phase
);
output
->
needStop
=
true
;
QW_ERR_JRET
(
qwUpdateTaskStatus
(
QW_FPARAMS
(),
JOB_TASK_STATUS_CANCELLED
));
qwFreeTask
(
QW_FPARAMS
(),
ctx
);
QW_SET_EVENT_PROCESSED
(
ctx
,
QW_EVENT_CANCEL
);
output
->
rspCode
=
TSDB_CODE_QRY_TASK_CANCELLED
;
}
else
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_READY
))
{
readyConnection
=
ctx
->
readyConnection
;
QW_SET_EVENT_PROCESSED
(
ctx
,
QW_EVENT_READY
);
output
->
rspCode
=
ctx
->
rspCode
;
QW_ERR_JRET
(
output
->
rspCode
);
}
if
(
!
output
->
needStop
)
{
QW_ERR_JRET
(
qw
UpdateTaskStatus
(
QW_FPARAMS
(),
input
->
status
));
QW_ERR_JRET
(
qw
AddTaskStatus
(
QW_FPARAMS
(),
JOB_TASK_STATUS_EXECUTING
));
}
break
;
}
case
QW_PHASE_PRE_FETCH
:
{
QW_ERR_JRET
(
qwAcquireTaskCtx
(
QW_FPARAMS
(),
QW_READ
,
&
ctx
));
ctxAcquired
=
true
;
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
locked
=
true
;
atomic_store_32
(
&
ctx
->
phase
,
phase
);
if
(
QW_IS_EVENT_PROCESSED
(
ctx
,
QW_EVENT_DROP
))
{
QW_TASK_WLOG
(
"task already dropped, phase:%d"
,
phase
);
output
->
needStop
=
true
;
output
->
rspCode
=
TSDB_CODE_QRY_TASK_DROPPED
;
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_DROPPED
);
}
if
(
QW_IS_EVENT_PROCESSED
(
ctx
,
QW_EVENT_CANCEL
))
{
QW_TASK_WLOG
(
"task already cancelled, phase:%d"
,
phase
);
output
->
needStop
=
true
;
...
...
@@ -698,6 +697,13 @@ int32_t qwHandleTaskEvent(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *input, SQ
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_CANCELLED
);
}
if
(
ctx
->
rspCode
)
{
QW_TASK_ELOG
(
"task already failed, code:%x, phase:%d"
,
ctx
->
rspCode
,
phase
);
output
->
needStop
=
true
;
output
->
rspCode
=
ctx
->
rspCode
;
QW_ERR_JRET
(
output
->
rspCode
);
}
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_FETCH
))
{
QW_TASK_WLOG
(
"last fetch not finished, phase:%d"
,
phase
);
output
->
needStop
=
true
;
...
...
@@ -711,25 +717,10 @@ int32_t qwHandleTaskEvent(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *input, SQ
output
->
rspCode
=
TSDB_CODE_QRY_TASK_MSG_ERROR
;
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_MSG_ERROR
);
}
if
(
ctx
->
rspCode
)
{
QW_TASK_ELOG
(
"task already failed, code:%x, phase:%d"
,
ctx
->
rspCode
,
phase
);
output
->
needStop
=
true
;
output
->
rspCode
=
ctx
->
rspCode
;
QW_ERR_JRET
(
output
->
rspCode
);
}
break
;
}
case
QW_PHASE_POST_FETCH
:
{
QW_ERR_JRET
(
qwGetTaskCtx
(
QW_FPARAMS
(),
&
ctx
));
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
locked
=
true
;
if
(
input
->
code
)
{
output
->
rspCode
=
input
->
code
;
}
case
QW_PHASE_PRE_CQUERY
:
{
atomic_store_8
(
&
ctx
->
phase
,
phase
);
if
(
QW_IS_EVENT_PROCESSED
(
ctx
,
QW_EVENT_CANCEL
))
{
QW_TASK_WLOG
(
"task already cancelled, phase:%d"
,
phase
);
...
...
@@ -738,84 +729,111 @@ int32_t qwHandleTaskEvent(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *input, SQ
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_CANCELLED
);
}
if
(
QW_IS_EVENT_
RECEIV
ED
(
ctx
,
QW_EVENT_DROP
))
{
QW_TASK_WLOG
(
"
start to drop task
, phase:%d"
,
phase
);
if
(
QW_IS_EVENT_
PROCESS
ED
(
ctx
,
QW_EVENT_DROP
))
{
QW_TASK_WLOG
(
"
task already dropped
, phase:%d"
,
phase
);
output
->
needStop
=
true
;
output
->
rspCode
=
TSDB_CODE_QRY_TASK_DROPPED
;
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_DROPPED
);
}
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_DROP
))
{
QW_ERR_JRET
(
qwDropTaskStatus
(
QW_FPARAMS
()));
QW_ERR_JRET
(
qwDropTaskCtx
(
QW_FPARAMS
()));
QW_ERR_JRET
(
qwDropTaskCtx
(
QW_FPARAMS
()
,
QW_WRITE
));
output
->
rspCode
=
TSDB_CODE_QRY_TASK_DROPPED
;
output
->
needStop
=
true
;
QW_SET_RSP_CODE
(
ctx
,
output
->
rspCode
);
dropConnection
=
ctx
->
dropConnection
;
// Note: ctx freed, no need to unlock it
locked
=
false
;
}
else
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_CANCEL
))
{
QW_TASK_WLOG
(
"start to cancel task, phase:%d"
,
phase
);
output
->
needStop
=
true
;
QW_ERR_JRET
(
output
->
rspCode
);
}
else
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_CANCEL
))
{
QW_ERR_JRET
(
qwUpdateTaskStatus
(
QW_FPARAMS
(),
JOB_TASK_STATUS_CANCELLED
));
qwFreeTask
(
QW_FPARAMS
(),
ctx
);
QW_SET_EVENT_PROCESSED
(
ctx
,
QW_EVENT_CANCEL
);
output
->
needStop
=
true
;
output
->
rspCode
=
TSDB_CODE_QRY_TASK_CANCELLED
;
QW_SET_RSP_CODE
(
ctx
,
output
->
rspCode
);
cancelConnection
=
ctx
->
cancelConnection
;
QW_ERR_JRET
(
output
->
rspCode
);
}
if
(
ctx
->
rspCode
)
{
QW_TASK_ELOG
(
"task failed, code:%x, phase:%d"
,
ctx
->
rspCode
,
phase
);
QW_TASK_ELOG
(
"task
already
failed, code:%x, phase:%d"
,
ctx
->
rspCode
,
phase
);
output
->
needStop
=
true
;
output
->
rspCode
=
ctx
->
rspCode
;
QW_ERR_JRET
(
output
->
rspCode
);
}
break
;
}
case
QW_PHASE_PRE_CQUERY
:
{
QW_ERR_JRET
(
qwAcquireTaskCtx
(
QW_FPARAMS
(),
QW_READ
,
&
ctx
));
ctxAcquired
=
true
;
}
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
_return:
locked
=
true
;
if
(
ctx
)
{
if
(
output
->
rspCode
)
{
QW_UPDATE_RSP_CODE
(
ctx
,
output
->
rspCode
);
}
atomic_store_32
(
&
ctx
->
phase
,
phase
);
if
(
locked
)
{
QW_UNLOCK
(
QW_WRITE
,
&
ctx
->
lock
);
}
if
(
QW_IS_EVENT_PROCESSED
(
ctx
,
QW_EVENT_CANCEL
))
{
QW_TASK_WLOG
(
"task already cancelled, phase:%d"
,
phase
);
output
->
needStop
=
true
;
output
->
rspCode
=
TSDB_CODE_QRY_TASK_CANCELLED
;
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_CANCELLED
);
qwReleaseTaskCtx
(
mgmt
,
ctx
);
}
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_DROP
))
{
QW_TASK_ELOG
(
"drop event at wrong phase, phase:%d"
,
phase
);
output
->
needStop
=
true
;
output
->
rspCode
=
TSDB_CODE_QRY_TASK_STATUS_ERROR
;
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_CANCELLED
);
}
else
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_CANCEL
))
{
QW_TASK_ELOG
(
"cancel event at wrong phase, phase:%d"
,
phase
);
if
(
code
)
{
output
->
needStop
=
true
;
output
->
rspCode
=
TSDB_CODE_QRY_TASK_STATUS_ERROR
;
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_CANCELLED
);
if
(
TSDB_CODE_SUCCESS
==
output
->
rspCode
)
{
output
->
rspCode
=
code
;
}
}
if
(
ctx
->
rspCode
)
{
QW_TASK_ELOG
(
"task already failed, code:%x, phase:%d"
,
ctx
->
rspCode
,
phase
);
output
->
needStop
=
true
;
output
->
rspCode
=
ctx
->
rspCode
;
QW_ERR_JRET
(
output
->
rspCode
);
if
(
dropConnection
)
{
qwBuildAndSendDropRsp
(
dropConnection
,
output
->
rspCode
);
QW_TASK_DLOG
(
"drop msg rsped, code:%x"
,
output
->
rspCode
);
}
break
;
if
(
cancelConnection
)
{
qwBuildAndSendCancelRsp
(
cancelConnection
,
output
->
rspCode
);
QW_TASK_DLOG
(
"cancel msg rsped, code:%x"
,
output
->
rspCode
);
}
case
QW_PHASE_POST_CQUERY
:
{
QW_ERR_JRET
(
qwGetTaskCtx
(
QW_FPARAMS
(),
&
ctx
));
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
QW_SCH_TASK_DLOG
(
"end to handle event at phase %d"
,
phase
);
QW_RET
(
code
);
}
int32_t
qwHandlePostPhaseEvents
(
QW_FPARAMS_DEF
,
int8_t
phase
,
SQWPhaseInput
*
input
,
SQWPhaseOutput
*
output
)
{
int32_t
code
=
0
;
int8_t
status
=
0
;
SQWTaskCtx
*
ctx
=
NULL
;
bool
locked
=
false
;
void
*
readyConnection
=
NULL
;
void
*
dropConnection
=
NULL
;
void
*
cancelConnection
=
NULL
;
QW_SCH_TASK_DLOG
(
"start to handle event at phase %d"
,
phase
);
output
->
needStop
=
false
;
QW_ERR_JRET
(
qwAcquireTaskCtx
(
QW_FPARAMS
(),
&
ctx
));
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
locked
=
true
;
if
(
input
->
code
)
{
output
->
rspCode
=
input
->
code
;
if
(
QW_IS_EVENT_PROCESSED
(
ctx
,
QW_EVENT_DROP
))
{
QW_TASK_WLOG
(
"task already dropped, phase:%d"
,
phase
);
output
->
needStop
=
true
;
output
->
rspCode
=
TSDB_CODE_QRY_TASK_DROPPED
;
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_DROPPED
);
}
if
(
QW_IS_EVENT_PROCESSED
(
ctx
,
QW_EVENT_CANCEL
))
{
...
...
@@ -825,28 +843,46 @@ int32_t qwHandleTaskEvent(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *input, SQ
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_CANCELLED
);
}
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_DROP
))
{
QW_TASK_WLOG
(
"start to drop task, phase:%d"
,
phase
);
output
->
needStop
=
true
;
if
(
input
->
code
)
{
output
->
rspCode
=
input
->
code
;
}
if
(
QW_PHASE_POST_QUERY
==
phase
)
{
if
(
NULL
==
ctx
->
taskHandle
&&
NULL
==
ctx
->
sinkHandle
)
{
ctx
->
emptyRes
=
true
;
}
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_READY
))
{
readyConnection
=
ctx
->
readyConnection
;
QW_SET_EVENT_PROCESSED
(
ctx
,
QW_EVENT_READY
);
}
}
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_DROP
))
{
QW_ERR_JRET
(
qwDropTaskStatus
(
QW_FPARAMS
()));
QW_ERR_JRET
(
qwDropTaskCtx
(
QW_FPARAMS
()
));
QW_ERR_JRET
(
qwDropTaskCtx
(
QW_FPARAMS
(),
QW_WRITE
));
output
->
rspCode
=
TSDB_CODE_QRY_TASK_DROPPED
;
output
->
needStop
=
true
;
QW_SET_RSP_CODE
(
ctx
,
output
->
rspCode
);
dropConnection
=
ctx
->
dropConnection
;
// Note: ctx freed, no need to unlock it
locked
=
false
;
}
else
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_CANCEL
))
{
QW_TASK_WLOG
(
"start to cancel task, phase:%d"
,
phase
);
output
->
needStop
=
true
;
QW_ERR_JRET
(
output
->
rspCode
);
}
else
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_CANCEL
))
{
QW_ERR_JRET
(
qwUpdateTaskStatus
(
QW_FPARAMS
(),
JOB_TASK_STATUS_CANCELLED
));
qwFreeTask
(
QW_FPARAMS
(),
ctx
);
QW_SET_EVENT_PROCESSED
(
ctx
,
QW_EVENT_CANCEL
);
output
->
needStop
=
true
;
output
->
rspCode
=
TSDB_CODE_QRY_TASK_CANCELLED
;
QW_SET_RSP_CODE
(
ctx
,
output
->
rspCode
);
cancelConnection
=
ctx
->
cancelConnection
;
QW_ERR_JRET
(
output
->
rspCode
);
}
if
(
ctx
->
rspCode
)
{
...
...
@@ -855,24 +891,34 @@ int32_t qwHandleTaskEvent(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *input, SQ
output
->
rspCode
=
ctx
->
rspCode
;
QW_ERR_JRET
(
output
->
rspCode
);
}
break
;
}
if
(
QW_PHASE_POST_QUERY
==
phase
&&
(
!
output
->
needStop
))
{
QW_ERR_JRET
(
qwUpdateTaskStatus
(
QW_FPARAMS
(),
input
->
taskStatus
));
}
_return:
if
(
ctx
)
{
if
(
output
->
rspCode
)
{
QW_SET
_RSP_CODE
(
ctx
,
output
->
rspCode
);
QW_UPDATE
_RSP_CODE
(
ctx
,
output
->
rspCode
);
}
if
(
locked
)
{
atomic_store_32
(
&
ctx
->
phase
,
phase
);
if
(
QW_PHASE_POST_FETCH
!=
phase
)
{
atomic_store_8
(
&
ctx
->
phase
,
phase
);
}
if
(
locked
)
{
QW_UNLOCK
(
QW_WRITE
,
&
ctx
->
lock
);
}
if
(
ctxAcquired
&&
ctx
)
{
qwReleaseTaskCtx
(
QW_READ
,
mgmt
);
qwReleaseTaskCtx
(
mgmt
,
ctx
);
}
if
(
code
)
{
output
->
needStop
=
true
;
if
(
TSDB_CODE_SUCCESS
==
output
->
rspCode
)
{
output
->
rspCode
=
code
;
}
}
if
(
readyConnection
)
{
...
...
@@ -896,7 +942,7 @@ _return:
}
int32_t
qwProcessQuery
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWMsg
*
qwMsg
,
int8_t
taskType
)
{
int32_t
qwProcessQuery
(
QW_FPARAMS_DEF
,
SQWMsg
*
qwMsg
,
int8_t
taskType
)
{
int32_t
code
=
0
;
bool
queryRsped
=
false
;
bool
needStop
=
false
;
...
...
@@ -906,10 +952,9 @@ int32_t qwProcessQuery(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
SQWPhaseOutput
output
=
{
0
};
qTaskInfo_t
pTaskInfo
=
NULL
;
DataSinkHandle
sinkHandle
=
NULL
;
SQWTaskCtx
*
ctx
=
NULL
;
input
.
taskType
=
taskType
;
QW_ERR_JRET
(
qwHandleTaskEvent
(
QW_FPARAMS
(),
QW_PHASE_PRE_QUERY
,
&
input
,
&
output
));
QW_ERR_JRET
(
qwHandlePrePhaseEvents
(
QW_FPARAMS
(),
QW_PHASE_PRE_QUERY
,
&
input
,
&
output
));
needStop
=
output
.
needStop
;
code
=
output
.
rspCode
;
...
...
@@ -919,6 +964,10 @@ int32_t qwProcessQuery(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
QW_ERR_JRET
(
code
);
}
QW_ERR_JRET
(
qwGetTaskCtx
(
QW_FPARAMS
(),
&
ctx
));
atomic_store_8
(
&
ctx
->
taskType
,
taskType
);
code
=
qStringToSubplan
(
qwMsg
->
msg
,
&
plan
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
QW_TASK_ELOG
(
"task string to subplan failed, code:%s"
,
tstrerror
(
code
));
...
...
@@ -943,8 +992,11 @@ int32_t qwProcessQuery(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
queryRsped
=
true
;
atomic_store_ptr
(
&
ctx
->
taskHandle
,
pTaskInfo
);
atomic_store_ptr
(
&
ctx
->
sinkHandle
,
sinkHandle
);
if
(
pTaskInfo
&&
sinkHandle
)
{
QW_ERR_JRET
(
qwExecTask
(
QW_FPARAMS
(),
&
pTaskInfo
,
sinkHandle
,
taskType
));
QW_ERR_JRET
(
qwExecTask
(
QW_FPARAMS
(),
ctx
));
}
_return:
...
...
@@ -954,46 +1006,35 @@ _return:
}
if
(
!
queryRsped
)
{
code
=
qwBuildAndSendQueryRsp
(
qwMsg
->
connection
,
rspCode
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
QW_TASK_DLOG
(
"query msg rsped, code:%d"
,
rspCode
);
}
if
(
TSDB_CODE_SUCCESS
==
rspCode
&&
code
)
{
rspCode
=
code
;
}
}
if
(
needStop
)
{
QW_RET
(
rspCode
);
qwBuildAndSendQueryRsp
(
qwMsg
->
connection
,
rspCode
);
QW_TASK_DLOG
(
"query msg rsped, code:%x"
,
rspCode
);
}
input
.
code
=
rspCode
;
input
.
taskHandle
=
pTaskInfo
;
input
.
sinkHandle
=
sinkHandle
;
input
.
taskStatus
=
rspCode
?
JOB_TASK_STATUS_FAILED
:
JOB_TASK_STATUS_PARTIAL_SUCCEED
;
if
(
TSDB_CODE_SUCCESS
!=
rspCode
)
{
input
.
status
=
JOB_TASK_STATUS_FAILED
;
}
else
{
input
.
status
=
JOB_TASK_STATUS_PARTIAL_SUCCEED
;
}
QW_ERR_RET
(
qwHandleTaskEvent
(
QW_FPARAMS
(),
QW_PHASE_POST_QUERY
,
&
input
,
&
output
));
QW_ERR_RET
(
qwHandlePostPhaseEvents
(
QW_FPARAMS
(),
QW_PHASE_POST_QUERY
,
&
input
,
&
output
));
QW_RET
(
rspCode
);
}
int32_t
qwProcessReady
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWMsg
*
qwMsg
)
{
int32_t
qwProcessReady
(
QW_FPARAMS_DEF
,
SQWMsg
*
qwMsg
)
{
int32_t
code
=
0
;
SQWTaskCtx
*
ctx
=
NULL
;
int8_t
phase
=
0
;
bool
needRsp
=
false
;
int32_t
rspCode
=
0
;
QW_ERR_JRET
(
qw
Get
TaskCtx
(
QW_FPARAMS
(),
&
ctx
));
QW_ERR_JRET
(
qw
Acquire
TaskCtx
(
QW_FPARAMS
(),
&
ctx
));
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
if
(
QW_IS_EVENT_PROCESSED
(
ctx
,
QW_EVENT_CANCEL
)
||
QW_IS_EVENT_PROCESSED
(
ctx
,
QW_EVENT_DROP
)
||
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_CANCEL
)
||
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_DROP
))
{
QW_TASK_WLOG
(
"task already cancelled/dropped, phase:%d"
,
phase
);
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_CANCELLED
);
}
phase
=
QW_GET_PHASE
(
ctx
);
if
(
phase
==
QW_PHASE_PRE_QUERY
)
{
...
...
@@ -1015,11 +1056,12 @@ int32_t qwProcessReady(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
_return:
if
(
code
&&
ctx
)
{
QW_
SET
_RSP_CODE
(
ctx
,
code
);
QW_
UPDATE
_RSP_CODE
(
ctx
,
code
);
}
if
(
ctx
)
{
QW_UNLOCK
(
QW_WRITE
,
&
ctx
->
lock
);
qwReleaseTaskCtx
(
mgmt
,
ctx
);
}
if
(
needRsp
)
{
...
...
@@ -1031,7 +1073,7 @@ _return:
}
int32_t
qwProcessCQuery
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWMsg
*
qwMsg
)
{
int32_t
qwProcessCQuery
(
QW_FPARAMS_DEF
,
SQWMsg
*
qwMsg
)
{
SQWTaskCtx
*
ctx
=
NULL
;
int32_t
code
=
0
;
bool
queryRsped
=
false
;
...
...
@@ -1043,7 +1085,7 @@ int32_t qwProcessCQuery(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
int32_t
dataLen
=
0
;
do
{
QW_ERR_JRET
(
qwHandle
TaskEvent
(
QW_FPARAMS
(),
QW_PHASE_PRE_CQUERY
,
&
input
,
&
output
));
QW_ERR_JRET
(
qwHandle
PrePhaseEvents
(
QW_FPARAMS
(),
QW_PHASE_PRE_CQUERY
,
&
input
,
&
output
));
needStop
=
output
.
needStop
;
code
=
output
.
rspCode
;
...
...
@@ -1056,10 +1098,11 @@ int32_t qwProcessCQuery(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
QW_ERR_JRET
(
qwGetTaskCtx
(
QW_FPARAMS
(),
&
ctx
));
atomic_store_8
(
&
ctx
->
queryInQueue
,
0
);
atomic_store_8
(
&
ctx
->
queryContinue
,
0
);
DataSinkHandle
sinkHandle
=
ctx
->
sinkHandle
;
QW_ERR_JRET
(
qwExecTask
(
QW_FPARAMS
(),
&
ctx
->
taskHandle
,
sinkHandle
,
ctx
->
taskType
));
QW_ERR_JRET
(
qwExecTask
(
QW_FPARAMS
(),
ctx
));
if
(
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_FETCH
))
{
SOutputData
sOutput
=
{
0
};
...
...
@@ -1072,6 +1115,10 @@ int32_t qwProcessCQuery(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
atomic_store_8
(
&
ctx
->
queryContinue
,
1
);
}
if
(
sOutput
.
queryEnd
)
{
needStop
=
true
;
}
if
(
rsp
)
{
qwBuildFetchRsp
(
rsp
,
&
sOutput
,
dataLen
);
...
...
@@ -1086,6 +1133,10 @@ int32_t qwProcessCQuery(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
_return:
if
(
NULL
==
ctx
)
{
break
;
}
if
(
code
&&
QW_IS_EVENT_RECEIVED
(
ctx
,
QW_EVENT_FETCH
))
{
QW_SET_EVENT_PROCESSED
(
ctx
,
QW_EVENT_FETCH
);
qwFreeFetchRsp
(
rsp
);
...
...
@@ -1094,18 +1145,24 @@ int32_t qwProcessCQuery(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
QW_TASK_DLOG
(
"fetch msg rsped, code:%x, dataLen:%d"
,
code
,
0
);
}
input
.
code
=
code
;
qwHandleTaskEvent
(
QW_FPARAMS
(),
QW_PHASE_POST_CQUERY
,
&
input
,
&
output
);
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
if
(
needStop
||
code
||
0
==
atomic_load_8
(
&
ctx
->
queryContinue
))
{
atomic_store_8
(
&
ctx
->
phase
,
0
);
QW_UNLOCK
(
QW_WRITE
,
&
ctx
->
lock
);
break
;
}
needStop
=
output
.
needStop
;
code
=
output
.
rspCode
;
}
while
((
!
needStop
)
&&
(
0
==
code
)
&&
atomic_val_compare_exchange_8
(
&
ctx
->
queryContinue
,
1
,
0
));
QW_UNLOCK
(
QW_WRITE
,
&
ctx
->
lock
);
}
while
(
true
);
input
.
code
=
code
;
qwHandlePostPhaseEvents
(
QW_FPARAMS
(),
QW_PHASE_POST_CQUERY
,
&
input
,
&
output
);
QW_RET
(
code
);
}
int32_t
qwProcessFetch
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWMsg
*
qwMsg
)
{
int32_t
qwProcessFetch
(
QW_FPARAMS_DEF
,
SQWMsg
*
qwMsg
)
{
int32_t
code
=
0
;
int32_t
needRsp
=
true
;
void
*
data
=
NULL
;
...
...
@@ -1121,7 +1178,7 @@ int32_t qwProcessFetch(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
SQWPhaseInput
input
=
{
0
};
SQWPhaseOutput
output
=
{
0
};
QW_ERR_JRET
(
qwHandle
TaskEvent
(
QW_FPARAMS
(),
QW_PHASE_PRE_FETCH
,
&
input
,
&
output
));
QW_ERR_JRET
(
qwHandle
PrePhaseEvents
(
QW_FPARAMS
(),
QW_PHASE_PRE_FETCH
,
&
input
,
&
output
));
needStop
=
output
.
needStop
;
code
=
output
.
rspCode
;
...
...
@@ -1149,14 +1206,19 @@ int32_t qwProcessFetch(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t
locked
=
true
;
// RC WARNING
if
(
QW_I
N_EXECUTOR
(
ctx
))
{
if
(
QW_I
S_QUERY_RUNNING
(
ctx
))
{
atomic_store_8
(
&
ctx
->
queryContinue
,
1
);
}
else
if
(
0
==
atomic_load_8
(
&
ctx
->
queryInQueue
))
{
if
(
!
ctx
->
multiExec
)
{
QW_ERR_JRET
(
qwUpdateTaskStatus
(
QW_FPARAMS
(),
JOB_TASK_STATUS_EXECUTING
));
ctx
->
multiExec
=
true
;
}
atomic_store_8
(
&
ctx
->
queryInQueue
,
1
);
QW_ERR_JRET
(
qwBuildAndSendCQueryMsg
(
QW_FPARAMS
(),
qwMsg
->
connection
));
QW_TASK_DLOG
(
"schedule query in queue, phase:%d"
,
ctx
->
phase
);
}
}
...
...
@@ -1168,7 +1230,11 @@ _return:
input
.
code
=
code
;
qwHandleTaskEvent
(
QW_FPARAMS
(),
QW_PHASE_POST_FETCH
,
&
input
,
&
output
);
qwHandlePostPhaseEvents
(
QW_FPARAMS
(),
QW_PHASE_POST_FETCH
,
&
input
,
&
output
);
if
(
output
.
rspCode
)
{
code
=
output
.
rspCode
;
}
if
(
code
)
{
qwFreeFetchRsp
(
rsp
);
...
...
@@ -1185,13 +1251,13 @@ _return:
}
int32_t
qwProcessDrop
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
SQWMsg
*
qwMsg
)
{
int32_t
qwProcessDrop
(
QW_FPARAMS_DEF
,
SQWMsg
*
qwMsg
)
{
int32_t
code
=
0
;
bool
needRsp
=
false
;
SQWTaskCtx
*
ctx
=
NULL
;
bool
locked
=
false
;
QW_ERR_JRET
(
qwAddAcquireTaskCtx
(
QW_FPARAMS
(),
QW_WRITE
,
&
ctx
));
QW_ERR_JRET
(
qwAddAcquireTaskCtx
(
QW_FPARAMS
(),
&
ctx
));
QW_LOCK
(
QW_WRITE
,
&
ctx
->
lock
);
...
...
@@ -1202,28 +1268,30 @@ int32_t qwProcessDrop(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_t t
QW_ERR_JRET
(
TSDB_CODE_QRY_DUPLICATTED_OPERATION
);
}
if
(
QW_I
N_EXECUTOR
(
ctx
))
{
if
(
QW_I
S_QUERY_RUNNING
(
ctx
))
{
QW_ERR_JRET
(
qwKillTaskHandle
(
QW_FPARAMS
(),
ctx
));
QW_ERR_JRET
(
qwUpdateTaskStatus
(
QW_FPARAMS
(),
JOB_TASK_STATUS_DROPPING
));
ctx
->
dropConnection
=
qwMsg
->
connection
;
}
else
if
(
ctx
->
phase
>
0
)
{
QW_ERR_JRET
(
qwDropTaskStatus
(
QW_FPARAMS
()));
QW_ERR_JRET
(
qwDropTaskCtx
(
QW_FPARAMS
()));
QW_ERR_JRET
(
qwDropTaskCtx
(
QW_FPARAMS
(),
QW_WRITE
));
QW_SET_RSP_CODE
(
ctx
,
TSDB_CODE_QRY_TASK_DROPPED
);
locked
=
false
;
needRsp
=
true
;
}
if
(
!
needRsp
)
{
ctx
->
dropConnection
=
qwMsg
->
connection
;
QW_SET_EVENT_RECEIVED
(
ctx
,
QW_EVENT_DROP
);
}
_return:
if
(
code
)
{
QW_
SET
_RSP_CODE
(
ctx
,
code
);
QW_
UPDATE
_RSP_CODE
(
ctx
,
code
);
}
if
(
locked
)
{
...
...
@@ -1231,7 +1299,7 @@ _return:
}
if
(
ctx
)
{
qwReleaseTaskCtx
(
QW_WRITE
,
mgmt
);
qwReleaseTaskCtx
(
mgmt
,
ctx
);
}
if
(
TSDB_CODE_SUCCESS
!=
code
||
needRsp
)
{
...
...
@@ -1258,18 +1326,18 @@ int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, SQWorkerCfg *cfg, void **qW
if
(
cfg
)
{
mgmt
->
cfg
=
*
cfg
;
if
(
0
==
mgmt
->
cfg
.
maxSchedulerNum
)
{
mgmt
->
cfg
.
maxSchedulerNum
=
QW
ORKER
_DEFAULT_SCHEDULER_NUMBER
;
mgmt
->
cfg
.
maxSchedulerNum
=
QW_DEFAULT_SCHEDULER_NUMBER
;
}
if
(
0
==
mgmt
->
cfg
.
maxTaskNum
)
{
mgmt
->
cfg
.
maxTaskNum
=
QW
ORKER
_DEFAULT_TASK_NUMBER
;
mgmt
->
cfg
.
maxTaskNum
=
QW_DEFAULT_TASK_NUMBER
;
}
if
(
0
==
mgmt
->
cfg
.
maxSchTaskNum
)
{
mgmt
->
cfg
.
maxSchTaskNum
=
QW
ORKER
_DEFAULT_SCH_TASK_NUMBER
;
mgmt
->
cfg
.
maxSchTaskNum
=
QW_DEFAULT_SCH_TASK_NUMBER
;
}
}
else
{
mgmt
->
cfg
.
maxSchedulerNum
=
QW
ORKER
_DEFAULT_SCHEDULER_NUMBER
;
mgmt
->
cfg
.
maxTaskNum
=
QW
ORKER
_DEFAULT_TASK_NUMBER
;
mgmt
->
cfg
.
maxSchTaskNum
=
QW
ORKER
_DEFAULT_SCH_TASK_NUMBER
;
mgmt
->
cfg
.
maxSchedulerNum
=
QW_DEFAULT_SCHEDULER_NUMBER
;
mgmt
->
cfg
.
maxTaskNum
=
QW_DEFAULT_TASK_NUMBER
;
mgmt
->
cfg
.
maxSchTaskNum
=
QW_DEFAULT_SCH_TASK_NUMBER
;
}
mgmt
->
schHash
=
taosHashInit
(
mgmt
->
cfg
.
maxSchedulerNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
false
,
HASH_ENTRY_LOCK
);
...
...
source/libs/qworker/src/qworkerMsg.c
浏览文件 @
4edcf262
...
...
@@ -50,6 +50,7 @@ int32_t qwBuildAndSendQueryRsp(void *connection, int32_t code) {
pRsp
->
code
=
code
;
SRpcMsg
rpcRsp
=
{
.
msgType
=
TDMT_VND_QUERY_RSP
,
.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
pCont
=
pRsp
,
...
...
@@ -68,6 +69,7 @@ int32_t qwBuildAndSendReadyRsp(void *connection, int32_t code) {
pRsp
->
code
=
code
;
SRpcMsg
rpcRsp
=
{
.
msgType
=
TDMT_VND_RES_READY_RSP
,
.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
pCont
=
pRsp
,
...
...
@@ -98,7 +100,7 @@ int32_t qwBuildAndSendStatusRsp(SRpcMsg *pMsg, SSchedulerStatusRsp *sStatus) {
}
SRpcMsg
rpcRsp
=
{
.
msgType
=
pMsg
->
msgType
+
1
,
.
msgType
=
TDMT_VND_TASKS_STATUS_RSP
,
.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
pCont
=
pRsp
,
...
...
@@ -121,6 +123,7 @@ int32_t qwBuildAndSendFetchRsp(void *connection, SRetrieveTableRsp *pRsp, int32_
}
SRpcMsg
rpcRsp
=
{
.
msgType
=
TDMT_VND_FETCH_RSP
,
.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
pCont
=
pRsp
,
...
...
@@ -138,6 +141,7 @@ int32_t qwBuildAndSendCancelRsp(SRpcMsg *pMsg, int32_t code) {
pRsp
->
code
=
code
;
SRpcMsg
rpcRsp
=
{
.
msgType
=
TDMT_VND_CANCEL_TASK_RSP
,
.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
pCont
=
pRsp
,
...
...
@@ -155,6 +159,7 @@ int32_t qwBuildAndSendDropRsp(void *connection, int32_t code) {
pRsp
->
code
=
code
;
SRpcMsg
rpcRsp
=
{
.
msgType
=
TDMT_VND_DROP_TASK_RSP
,
.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
pCont
=
pRsp
,
...
...
@@ -273,7 +278,7 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
SQWorkerMgmt
*
mgmt
=
(
SQWorkerMgmt
*
)
qWorkerMgmt
;
if
(
NULL
==
msg
||
pMsg
->
contLen
<=
sizeof
(
*
msg
))
{
QW_ELOG
(
"invalid query msg,
contLen:%d"
,
pMsg
->
contLen
);
QW_ELOG
(
"invalid query msg,
msg:%p, msgLen:%d"
,
msg
,
pMsg
->
contLen
);
QW_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
...
...
@@ -306,15 +311,11 @@ int32_t qWorkerProcessCQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
SQWTaskCtx
*
handles
=
NULL
;
SQWorkerMgmt
*
mgmt
=
(
SQWorkerMgmt
*
)
qWorkerMgmt
;
if
(
NULL
==
msg
||
pMsg
->
contLen
<
=
sizeof
(
*
msg
))
{
QW_ELOG
(
"invalid cquery msg,
contLen:%d"
,
pMsg
->
contLen
);
if
(
NULL
==
msg
||
pMsg
->
contLen
<
sizeof
(
*
msg
))
{
QW_ELOG
(
"invalid cquery msg,
msg:%p, msgLen:%d"
,
msg
,
pMsg
->
contLen
);
QW_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
msg
->
sId
=
be64toh
(
msg
->
sId
);
msg
->
queryId
=
be64toh
(
msg
->
queryId
);
msg
->
taskId
=
be64toh
(
msg
->
taskId
);
uint64_t
sId
=
msg
->
sId
;
uint64_t
qId
=
msg
->
queryId
;
uint64_t
tId
=
msg
->
taskId
;
...
...
@@ -335,14 +336,13 @@ int32_t qWorkerProcessReadyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg){
return
TSDB_CODE_QRY_INVALID_INPUT
;
}
SQWorkerMgmt
*
mgmt
=
(
SQWorkerMgmt
*
)
qWorkerMgmt
;
SResReadyReq
*
msg
=
pMsg
->
pCont
;
if
(
NULL
==
msg
||
pMsg
->
contLen
<
sizeof
(
*
msg
))
{
qError
(
"invalid task status msg"
);
QW_ELOG
(
"invalid task ready msg, msg:%p, msgLen:%d"
,
msg
,
pMsg
->
contLen
);
QW_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
SQWorkerMgmt
*
mgmt
=
(
SQWorkerMgmt
*
)
qWorkerMgmt
;
msg
->
sId
=
be64toh
(
msg
->
sId
);
msg
->
queryId
=
be64toh
(
msg
->
queryId
);
msg
->
taskId
=
be64toh
(
msg
->
taskId
);
...
...
@@ -398,6 +398,7 @@ int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
SQWorkerMgmt
*
mgmt
=
(
SQWorkerMgmt
*
)
qWorkerMgmt
;
if
(
NULL
==
msg
||
pMsg
->
contLen
<
sizeof
(
*
msg
))
{
QW_ELOG
(
"invalid fetch msg, msg:%p, msgLen:%d"
,
msg
,
pMsg
->
contLen
);
QW_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
...
...
source/libs/qworker/test/qworkerTests.cpp
浏览文件 @
4edcf262
...
...
@@ -44,13 +44,55 @@
namespace
{
#define qwtTestQueryQueueSize 1000000
#define qwtTestFetchQueueSize 1000000
int32_t
qwtTestMaxExecTaskUsec
=
2
;
int32_t
qwtTestReqMaxDelayUsec
=
2
;
uint64_t
qwtTestQueryId
=
0
;
bool
qwtTestEnableSleep
=
true
;
bool
qwtTestStop
=
false
;
bool
qwtTestDeadLoop
=
tru
e
;
int32_t
qwtTestMTRunSec
=
1
0
;
bool
qwtTestDeadLoop
=
fals
e
;
int32_t
qwtTestMTRunSec
=
6
0
;
int32_t
qwtTestPrintNum
=
100000
;
int32_t
qwtTestCaseIdx
=
0
;
int32_t
qwtTestCaseNum
=
4
;
bool
qwtTestCaseFinished
=
false
;
tsem_t
qwtTestQuerySem
;
tsem_t
qwtTestFetchSem
;
int32_t
qwtTestQuitThreadNum
=
0
;
int32_t
qwtTestQueryQueueRIdx
=
0
;
int32_t
qwtTestQueryQueueWIdx
=
0
;
int32_t
qwtTestQueryQueueNum
=
0
;
SRWLatch
qwtTestQueryQueueLock
=
0
;
struct
SRpcMsg
*
qwtTestQueryQueue
[
qwtTestQueryQueueSize
]
=
{
0
};
int32_t
qwtTestFetchQueueRIdx
=
0
;
int32_t
qwtTestFetchQueueWIdx
=
0
;
int32_t
qwtTestFetchQueueNum
=
0
;
SRWLatch
qwtTestFetchQueueLock
=
0
;
struct
SRpcMsg
*
qwtTestFetchQueue
[
qwtTestFetchQueueSize
]
=
{
0
};
int32_t
qwtTestSinkBlockNum
=
0
;
int32_t
qwtTestSinkMaxBlockNum
=
0
;
bool
qwtTestSinkQueryEnd
=
false
;
SRWLatch
qwtTestSinkLock
=
0
;
int32_t
qwtTestSinkLastLen
=
0
;
SSubQueryMsg
qwtqueryMsg
=
{
0
};
SRpcMsg
qwtfetchRpc
=
{
0
};
SResFetchReq
qwtfetchMsg
=
{
0
};
SRpcMsg
qwtreadyRpc
=
{
0
};
SResReadyReq
qwtreadyMsg
=
{
0
};
SRpcMsg
qwtdropRpc
=
{
0
};
STaskDropReq
qwtdropMsg
=
{
0
};
SSchTasksStatusReq
qwtstatusMsg
=
{
0
};
void
qwtInitLogFile
()
{
const
char
*
defaultLogFileNamePrefix
=
"taosdlog"
;
...
...
@@ -68,35 +110,38 @@ void qwtInitLogFile() {
}
void
qwtBuildQueryReqMsg
(
SRpcMsg
*
queryRpc
)
{
SSubQueryMsg
*
queryMsg
=
(
SSubQueryMsg
*
)
calloc
(
1
,
sizeof
(
SSubQueryMsg
)
+
100
);
q
ueryMsg
->
query
Id
=
htobe64
(
1
);
q
ueryMsg
->
s
Id
=
htobe64
(
1
);
q
ueryMsg
->
taskId
=
htobe64
(
1
);
query
Msg
->
contentLen
=
htonl
(
100
)
;
queryRpc
->
pCont
=
queryMsg
;
qwtqueryMsg
.
queryId
=
htobe64
(
atomic_add_fetch_64
(
&
qwtTestQueryId
,
1
)
);
q
wtqueryMsg
.
s
Id
=
htobe64
(
1
);
q
wtqueryMsg
.
task
Id
=
htobe64
(
1
);
q
wtqueryMsg
.
contentLen
=
htonl
(
100
);
query
Rpc
->
msgType
=
TDMT_VND_QUERY
;
queryRpc
->
pCont
=
&
qwt
queryMsg
;
queryRpc
->
contLen
=
sizeof
(
SSubQueryMsg
)
+
100
;
}
void
qwtBuildReadyReqMsg
(
SResReadyReq
*
readyMsg
,
SRpcMsg
*
readyRpc
)
{
readyMsg
->
sId
=
htobe64
(
1
);
readyMsg
->
queryId
=
htobe64
(
1
);
readyMsg
->
queryId
=
htobe64
(
atomic_load_64
(
&
qwtTestQueryId
)
);
readyMsg
->
taskId
=
htobe64
(
1
);
readyRpc
->
msgType
=
TDMT_VND_RES_READY
;
readyRpc
->
pCont
=
readyMsg
;
readyRpc
->
contLen
=
sizeof
(
SResReadyReq
);
}
void
qwtBuildFetchReqMsg
(
SResFetchReq
*
fetchMsg
,
SRpcMsg
*
fetchRpc
)
{
fetchMsg
->
sId
=
htobe64
(
1
);
fetchMsg
->
queryId
=
htobe64
(
1
);
fetchMsg
->
queryId
=
htobe64
(
atomic_load_64
(
&
qwtTestQueryId
)
);
fetchMsg
->
taskId
=
htobe64
(
1
);
fetchRpc
->
msgType
=
TDMT_VND_FETCH
;
fetchRpc
->
pCont
=
fetchMsg
;
fetchRpc
->
contLen
=
sizeof
(
SResFetchReq
);
}
void
qwtBuildDropReqMsg
(
STaskDropReq
*
dropMsg
,
SRpcMsg
*
dropRpc
)
{
dropMsg
->
sId
=
htobe64
(
1
);
dropMsg
->
queryId
=
htobe64
(
1
);
dropMsg
->
queryId
=
htobe64
(
atomic_load_64
(
&
qwtTestQueryId
)
);
dropMsg
->
taskId
=
htobe64
(
1
);
dropRpc
->
msgType
=
TDMT_VND_DROP_TASK
;
dropRpc
->
pCont
=
dropMsg
;
dropRpc
->
contLen
=
sizeof
(
STaskDropReq
);
}
...
...
@@ -109,30 +154,121 @@ void qwtBuildStatusReqMsg(SSchTasksStatusReq *statusMsg, SRpcMsg *statusRpc) {
}
int32_t
qwtStringToPlan
(
const
char
*
str
,
SSubplan
**
subplan
)
{
*
subplan
=
(
SSubplan
*
)
0x1
;
return
0
;
}
int32_t
qwtPutReqToFetchQueue
(
void
*
node
,
struct
SRpcMsg
*
pMsg
)
{
taosWLockLatch
(
&
qwtTestFetchQueueLock
);
struct
SRpcMsg
*
newMsg
=
(
struct
SRpcMsg
*
)
calloc
(
1
,
sizeof
(
struct
SRpcMsg
));
memcpy
(
newMsg
,
pMsg
,
sizeof
(
struct
SRpcMsg
));
qwtTestFetchQueue
[
qwtTestFetchQueueWIdx
++
]
=
newMsg
;
if
(
qwtTestFetchQueueWIdx
>=
qwtTestFetchQueueSize
)
{
qwtTestFetchQueueWIdx
=
0
;
}
qwtTestFetchQueueNum
++
;
if
(
qwtTestFetchQueueWIdx
==
qwtTestFetchQueueRIdx
)
{
printf
(
"Fetch queue is full"
);
assert
(
0
);
}
taosWUnLockLatch
(
&
qwtTestFetchQueueLock
);
tsem_post
(
&
qwtTestFetchSem
);
return
0
;
}
int32_t
qwtPutReqToQueue
(
void
*
node
,
struct
SRpcMsg
*
pMsg
)
{
taosWLockLatch
(
&
qwtTestQueryQueueLock
);
struct
SRpcMsg
*
newMsg
=
(
struct
SRpcMsg
*
)
calloc
(
1
,
sizeof
(
struct
SRpcMsg
));
memcpy
(
newMsg
,
pMsg
,
sizeof
(
struct
SRpcMsg
));
qwtTestQueryQueue
[
qwtTestQueryQueueWIdx
++
]
=
newMsg
;
if
(
qwtTestQueryQueueWIdx
>=
qwtTestQueryQueueSize
)
{
qwtTestQueryQueueWIdx
=
0
;
}
qwtTestQueryQueueNum
++
;
if
(
qwtTestQueryQueueWIdx
==
qwtTestQueryQueueRIdx
)
{
printf
(
"query queue is full"
);
assert
(
0
);
}
taosWUnLockLatch
(
&
qwtTestQueryQueueLock
);
tsem_post
(
&
qwtTestQuerySem
);
return
0
;
}
void
qwtRpcSendResponse
(
const
SRpcMsg
*
pRsp
)
{
/*
if (TDMT_VND_TASKS_STATUS_RSP == pRsp->msgType) {
SSchedulerStatusRsp *rsp = (SSchedulerStatusRsp *)pRsp->pCont;
printf("task num:%d\n", rsp->num);
for (int32_t i = 0; i < rsp->num; ++i) {
STaskStatus *task = &rsp->status[i];
printf("qId:%"PRIx64",tId:%"PRIx64",status:%d\n", task->queryId, task->taskId, task->status);
switch
(
pRsp
->
msgType
)
{
case
TDMT_VND_QUERY_RSP
:
{
SQueryTableRsp
*
rsp
=
(
SQueryTableRsp
*
)
pRsp
->
pCont
;
if
(
0
==
pRsp
->
code
)
{
qwtBuildReadyReqMsg
(
&
qwtreadyMsg
,
&
qwtreadyRpc
);
qwtPutReqToFetchQueue
((
void
*
)
0x1
,
&
qwtreadyRpc
);
}
else
{
qwtBuildDropReqMsg
(
&
qwtdropMsg
,
&
qwtdropRpc
);
qwtPutReqToFetchQueue
((
void
*
)
0x1
,
&
qwtdropRpc
);
}
rpcFreeCont
(
rsp
);
break
;
}
case
TDMT_VND_RES_READY_RSP
:
{
SResReadyRsp
*
rsp
=
(
SResReadyRsp
*
)
pRsp
->
pCont
;
if
(
0
==
pRsp
->
code
)
{
qwtBuildFetchReqMsg
(
&
qwtfetchMsg
,
&
qwtfetchRpc
);
qwtPutReqToFetchQueue
((
void
*
)
0x1
,
&
qwtfetchRpc
);
}
else
{
qwtBuildDropReqMsg
(
&
qwtdropMsg
,
&
qwtdropRpc
);
qwtPutReqToFetchQueue
((
void
*
)
0x1
,
&
qwtdropRpc
);
}
rpcFreeCont
(
rsp
);
break
;
}
*/
case
TDMT_VND_FETCH_RSP
:
{
SRetrieveTableRsp
*
rsp
=
(
SRetrieveTableRsp
*
)
pRsp
->
pCont
;
if
(
0
==
pRsp
->
code
&&
0
==
rsp
->
completed
)
{
qwtBuildFetchReqMsg
(
&
qwtfetchMsg
,
&
qwtfetchRpc
);
qwtPutReqToFetchQueue
((
void
*
)
0x1
,
&
qwtfetchRpc
);
return
;
}
qwtBuildDropReqMsg
(
&
qwtdropMsg
,
&
qwtdropRpc
);
qwtPutReqToFetchQueue
((
void
*
)
0x1
,
&
qwtdropRpc
);
rpcFreeCont
(
rsp
);
break
;
}
case
TDMT_VND_DROP_TASK_RSP
:
{
STaskDropRsp
*
rsp
=
(
STaskDropRsp
*
)
pRsp
->
pCont
;
rpcFreeCont
(
rsp
);
qwtTestCaseFinished
=
true
;
break
;
}
}
return
;
}
int32_t
qwtCreateExecTask
(
void
*
tsdb
,
int32_t
vgId
,
struct
SSubplan
*
pPlan
,
qTaskInfo_t
*
pTaskInfo
,
DataSinkHandle
*
handle
)
{
int32_t
idx
=
qwtTestCaseIdx
%
qwtTestCaseNum
;
int32_t
idx
=
abs
((
++
qwtTestCaseIdx
)
%
qwtTestCaseNum
);
qwtTestSinkBlockNum
=
0
;
qwtTestSinkMaxBlockNum
=
rand
()
%
100
+
1
;
qwtTestSinkQueryEnd
=
false
;
if
(
0
==
idx
)
{
*
pTaskInfo
=
(
qTaskInfo_t
)
qwtTestCaseIdx
;
...
...
@@ -148,12 +284,44 @@ int32_t qwtCreateExecTask(void* tsdb, int32_t vgId, struct SSubplan* pPlan, qTas
*
handle
=
(
DataSinkHandle
)
qwtTestCaseIdx
;
}
++
qwtTestCaseIdx
;
return
0
;
}
int32_t
qwtExecTask
(
qTaskInfo_t
tinfo
,
SSDataBlock
**
pRes
,
uint64_t
*
useconds
)
{
int32_t
endExec
=
0
;
if
(
NULL
==
tinfo
)
{
*
pRes
=
NULL
;
*
useconds
=
0
;
}
else
{
if
(
qwtTestSinkQueryEnd
)
{
*
pRes
=
NULL
;
*
useconds
=
rand
()
%
10
;
return
0
;
}
endExec
=
rand
()
%
5
;
int32_t
runTime
=
0
;
if
(
qwtTestEnableSleep
&&
qwtTestMaxExecTaskUsec
>
0
)
{
runTime
=
rand
()
%
qwtTestMaxExecTaskUsec
;
}
if
(
qwtTestEnableSleep
)
{
if
(
runTime
)
{
usleep
(
runTime
);
}
}
if
(
endExec
)
{
*
pRes
=
(
SSDataBlock
*
)
calloc
(
1
,
sizeof
(
SSDataBlock
));
(
*
pRes
)
->
info
.
rows
=
rand
()
%
1000
;
}
else
{
*
pRes
=
NULL
;
*
useconds
=
rand
()
%
10
;
}
}
return
0
;
}
...
...
@@ -162,21 +330,100 @@ int32_t qwtKillTask(qTaskInfo_t qinfo) {
}
void
qwtDestroyTask
(
qTaskInfo_t
qHandle
)
{
}
int32_t
qwtPutDataBlock
(
DataSinkHandle
handle
,
const
SInputData
*
pInput
,
bool
*
pContinue
)
{
if
(
NULL
==
handle
||
NULL
==
pInput
||
NULL
==
pContinue
)
{
assert
(
0
);
}
free
((
void
*
)
pInput
->
pData
);
taosWLockLatch
(
&
qwtTestSinkLock
);
qwtTestSinkBlockNum
++
;
if
(
qwtTestSinkBlockNum
>=
qwtTestSinkMaxBlockNum
)
{
*
pContinue
=
false
;
}
else
{
*
pContinue
=
true
;
}
taosWUnLockLatch
(
&
qwtTestSinkLock
);
return
0
;
}
void
qwtEndPut
(
DataSinkHandle
handle
,
uint64_t
useconds
)
{
if
(
NULL
==
handle
)
{
assert
(
0
);
}
qwtTestSinkQueryEnd
=
true
;
}
void
qwtGetDataLength
(
DataSinkHandle
handle
,
int32_t
*
pLen
,
bool
*
pQueryEnd
)
{
static
int32_t
in
=
0
;
if
(
in
>
0
)
{
assert
(
0
);
}
atomic_add_fetch_32
(
&
in
,
1
);
if
(
NULL
==
handle
)
{
assert
(
0
);
}
taosWLockLatch
(
&
qwtTestSinkLock
);
if
(
qwtTestSinkBlockNum
>
0
)
{
*
pLen
=
rand
()
%
100
+
1
;
qwtTestSinkBlockNum
--
;
}
else
{
*
pLen
=
0
;
}
qwtTestSinkLastLen
=
*
pLen
;
taosWUnLockLatch
(
&
qwtTestSinkLock
);
*
pQueryEnd
=
qwtTestSinkQueryEnd
;
atomic_sub_fetch_32
(
&
in
,
1
);
}
int32_t
qwtGetDataBlock
(
DataSinkHandle
handle
,
SOutputData
*
pOutput
)
{
taosWLockLatch
(
&
qwtTestSinkLock
);
if
(
qwtTestSinkLastLen
>
0
)
{
pOutput
->
numOfRows
=
rand
()
%
10
+
1
;
pOutput
->
compressed
=
1
;
pOutput
->
queryEnd
=
qwtTestSinkQueryEnd
;
if
(
qwtTestSinkBlockNum
==
0
)
{
pOutput
->
bufStatus
=
DS_BUF_EMPTY
;
}
else
if
(
qwtTestSinkBlockNum
<=
qwtTestSinkMaxBlockNum
*
0.5
)
{
pOutput
->
bufStatus
=
DS_BUF_LOW
;
}
else
{
pOutput
->
bufStatus
=
DS_BUF_FULL
;
}
pOutput
->
useconds
=
rand
()
%
10
+
1
;
pOutput
->
precision
=
1
;
}
else
if
(
qwtTestSinkLastLen
==
0
)
{
pOutput
->
numOfRows
=
0
;
pOutput
->
compressed
=
1
;
pOutput
->
pData
=
NULL
;
pOutput
->
queryEnd
=
qwtTestSinkQueryEnd
;
if
(
qwtTestSinkBlockNum
==
0
)
{
pOutput
->
bufStatus
=
DS_BUF_EMPTY
;
}
else
if
(
qwtTestSinkBlockNum
<=
qwtTestSinkMaxBlockNum
*
0.5
)
{
pOutput
->
bufStatus
=
DS_BUF_LOW
;
}
else
{
pOutput
->
bufStatus
=
DS_BUF_FULL
;
}
pOutput
->
useconds
=
rand
()
%
10
+
1
;
pOutput
->
precision
=
1
;
}
else
{
assert
(
0
);
}
taosWUnLockLatch
(
&
qwtTestSinkLock
);
return
0
;
}
...
...
@@ -343,7 +590,6 @@ void *queryThread(void *param) {
while
(
!
qwtTestStop
)
{
qwtBuildQueryReqMsg
(
&
queryRpc
);
qWorkerProcessQueryMsg
(
mockPointer
,
mgmt
,
&
queryRpc
);
free
(
queryRpc
.
pCont
);
if
(
qwtTestEnableSleep
)
{
usleep
(
rand
()
%
5
);
}
...
...
@@ -444,33 +690,159 @@ void *statusThread(void *param) {
}
void
*
controlThread
(
void
*
param
)
{
SRpcMsg
queryRpc
=
{
0
};
void
*
qwtclientThread
(
void
*
param
)
{
int32_t
code
=
0
;
uint32_t
n
=
0
;
void
*
mockPointer
=
(
void
*
)
0x1
;
void
*
mgmt
=
param
;
void
*
mockPointer
=
(
void
*
)
0x1
;
SRpcMsg
queryRpc
=
{
0
};
sleep
(
1
);
while
(
!
qwtTestStop
)
{
qwtTestCaseFinished
=
false
;
qwtBuildQueryReqMsg
(
&
queryRpc
);
q
WorkerProcessQueryMsg
(
mockPointer
,
mgmt
,
&
queryRpc
);
free
(
queryRpc
.
pCont
);
if
(
qwtTestEnableSleep
)
{
usleep
(
rand
()
%
5
);
q
wtPutReqToQueue
((
void
*
)
0x1
,
&
queryRpc
);
while
(
!
qwtTestCaseFinished
)
{
usleep
(
1
);
}
if
(
++
n
%
qwtTestPrintNum
==
0
)
{
printf
(
"
query
:%d
\n
"
,
n
);
printf
(
"
case run
:%d
\n
"
,
n
);
}
}
atomic_add_fetch_32
(
&
qwtTestQuitThreadNum
,
1
);
return
NULL
;
}
void
*
queryQueueThread
(
void
*
param
)
{
void
*
mockPointer
=
(
void
*
)
0x1
;
SRpcMsg
*
queryRpc
=
NULL
;
void
*
mgmt
=
param
;
while
(
true
)
{
tsem_wait
(
&
qwtTestQuerySem
);
if
(
qwtTestStop
&&
qwtTestQueryQueueNum
<=
0
&&
qwtTestCaseFinished
)
{
break
;
}
taosWLockLatch
(
&
qwtTestQueryQueueLock
);
if
(
qwtTestQueryQueueNum
<=
0
||
qwtTestQueryQueueRIdx
==
qwtTestQueryQueueWIdx
)
{
printf
(
"query queue is empty
\n
"
);
assert
(
0
);
}
queryRpc
=
qwtTestQueryQueue
[
qwtTestQueryQueueRIdx
++
];
if
(
qwtTestQueryQueueRIdx
>=
qwtTestQueryQueueSize
)
{
qwtTestQueryQueueRIdx
=
0
;
}
qwtTestQueryQueueNum
--
;
taosWUnLockLatch
(
&
qwtTestQueryQueueLock
);
if
(
qwtTestEnableSleep
&&
qwtTestReqMaxDelayUsec
>
0
)
{
int32_t
delay
=
rand
()
%
qwtTestReqMaxDelayUsec
;
if
(
delay
)
{
usleep
(
delay
);
}
}
if
(
TDMT_VND_QUERY
==
queryRpc
->
msgType
)
{
qWorkerProcessQueryMsg
(
mockPointer
,
mgmt
,
queryRpc
);
}
else
if
(
TDMT_VND_QUERY_CONTINUE
==
queryRpc
->
msgType
)
{
qWorkerProcessCQueryMsg
(
mockPointer
,
mgmt
,
queryRpc
);
}
else
{
printf
(
"unknown msg in query queue, type:%d
\n
"
,
queryRpc
->
msgType
);
assert
(
0
);
}
free
(
queryRpc
);
if
(
qwtTestStop
&&
qwtTestQueryQueueNum
<=
0
&&
qwtTestCaseFinished
)
{
break
;
}
}
atomic_add_fetch_32
(
&
qwtTestQuitThreadNum
,
1
);
return
NULL
;
}
void
*
fetchQueueThread
(
void
*
param
)
{
void
*
mockPointer
=
(
void
*
)
0x1
;
SRpcMsg
*
fetchRpc
=
NULL
;
void
*
mgmt
=
param
;
while
(
true
)
{
tsem_wait
(
&
qwtTestFetchSem
);
if
(
qwtTestStop
&&
qwtTestFetchQueueNum
<=
0
&&
qwtTestCaseFinished
)
{
break
;
}
taosWLockLatch
(
&
qwtTestFetchQueueLock
);
if
(
qwtTestFetchQueueNum
<=
0
||
qwtTestFetchQueueRIdx
==
qwtTestFetchQueueWIdx
)
{
printf
(
"Fetch queue is empty
\n
"
);
assert
(
0
);
}
fetchRpc
=
qwtTestFetchQueue
[
qwtTestFetchQueueRIdx
++
];
if
(
qwtTestFetchQueueRIdx
>=
qwtTestFetchQueueSize
)
{
qwtTestFetchQueueRIdx
=
0
;
}
qwtTestFetchQueueNum
--
;
taosWUnLockLatch
(
&
qwtTestFetchQueueLock
);
if
(
qwtTestEnableSleep
&&
qwtTestReqMaxDelayUsec
>
0
)
{
int32_t
delay
=
rand
()
%
qwtTestReqMaxDelayUsec
;
if
(
delay
)
{
usleep
(
delay
);
}
}
switch
(
fetchRpc
->
msgType
)
{
case
TDMT_VND_FETCH
:
qWorkerProcessFetchMsg
(
mockPointer
,
mgmt
,
fetchRpc
);
break
;
case
TDMT_VND_RES_READY
:
qWorkerProcessReadyMsg
(
mockPointer
,
mgmt
,
fetchRpc
);
break
;
case
TDMT_VND_TASKS_STATUS
:
qWorkerProcessStatusMsg
(
mockPointer
,
mgmt
,
fetchRpc
);
break
;
case
TDMT_VND_CANCEL_TASK
:
qWorkerProcessCancelMsg
(
mockPointer
,
mgmt
,
fetchRpc
);
break
;
case
TDMT_VND_DROP_TASK
:
qWorkerProcessDropMsg
(
mockPointer
,
mgmt
,
fetchRpc
);
break
;
default:
printf
(
"unknown msg type:%d in fetch queue"
,
fetchRpc
->
msgType
);
assert
(
0
);
break
;
}
free
(
fetchRpc
);
if
(
qwtTestStop
&&
qwtTestFetchQueueNum
<=
0
&&
qwtTestCaseFinished
)
{
break
;
}
}
atomic_add_fetch_32
(
&
qwtTestQuitThreadNum
,
1
);
return
NULL
;
}
...
...
@@ -478,6 +850,7 @@ void *fetchQueueThread(void *param) {
}
#if 0
TEST(seqTest, normalCase) {
void *mgmt = NULL;
...
...
@@ -491,40 +864,10 @@ TEST(seqTest, normalCase) {
qwtInitLogFile();
SSubQueryMsg
*
queryMsg
=
(
SSubQueryMsg
*
)
calloc
(
1
,
sizeof
(
SSubQueryMsg
)
+
100
);
queryMsg
->
queryId
=
htobe64
(
1
);
queryMsg
->
sId
=
htobe64
(
1
);
queryMsg
->
taskId
=
htobe64
(
1
);
queryMsg
->
contentLen
=
htonl
(
100
);
queryRpc
.
pCont
=
queryMsg
;
queryRpc
.
contLen
=
sizeof
(
SSubQueryMsg
)
+
100
;
SResReadyReq
readyMsg
=
{
0
};
readyMsg
.
sId
=
htobe64
(
1
);
readyMsg
.
queryId
=
htobe64
(
1
);
readyMsg
.
taskId
=
htobe64
(
1
);
readyRpc
.
pCont
=
&
readyMsg
;
readyRpc
.
contLen
=
sizeof
(
SResReadyReq
);
SResFetchReq
fetchMsg
=
{
0
};
fetchMsg
.
sId
=
htobe64
(
1
);
fetchMsg
.
queryId
=
htobe64
(
1
);
fetchMsg
.
taskId
=
htobe64
(
1
);
fetchRpc
.
pCont
=
&
fetchMsg
;
fetchRpc
.
contLen
=
sizeof
(
SResFetchReq
);
STaskDropReq
dropMsg
=
{
0
};
dropMsg
.
sId
=
htobe64
(
1
);
dropMsg
.
queryId
=
htobe64
(
1
);
dropMsg
.
taskId
=
htobe64
(
1
);
dropRpc
.
pCont
=
&
dropMsg
;
dropRpc
.
contLen
=
sizeof
(
STaskDropReq
);
SSchTasksStatusReq
statusMsg
=
{
0
};
statusMsg
.
sId
=
htobe64
(
1
);
statusRpc
.
pCont
=
&
statusMsg
;
statusRpc
.
contLen
=
sizeof
(
SSchTasksStatusReq
);
statusRpc
.
msgType
=
TDMT_VND_TASKS_STATUS
;
qwtBuildQueryReqMsg(&queryRpc);
qwtBuildReadyReqMsg(&qwtreadyMsg, &readyRpc);
qwtBuildFetchReqMsg(&qwtfetchMsg, &fetchRpc);
qwtBuildDropReqMsg(&qwtdropMsg, &dropRpc);
stubSetStringToPlan();
stubSetRpcSendResponse();
...
...
@@ -541,35 +884,19 @@ TEST(seqTest, normalCase) {
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0);
statusMsg
.
sId
=
htobe64
(
1
);
code
=
qWorkerProcessStatusMsg
(
mockPointer
,
mgmt
,
&
statusRpc
);
ASSERT_EQ
(
code
,
0
);
code = qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc);
ASSERT_EQ(code, 0);
statusMsg
.
sId
=
htobe64
(
1
);
code
=
qWorkerProcessStatusMsg
(
mockPointer
,
mgmt
,
&
statusRpc
);
ASSERT_EQ
(
code
,
0
);
code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc);
ASSERT_EQ(code, 0);
statusMsg
.
sId
=
htobe64
(
1
);
code
=
qWorkerProcessStatusMsg
(
mockPointer
,
mgmt
,
&
statusRpc
);
ASSERT_EQ
(
code
,
0
);
code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc);
ASSERT_EQ(code, 0);
statusMsg
.
sId
=
htobe64
(
1
);
code
=
qWorkerProcessStatusMsg
(
mockPointer
,
mgmt
,
&
statusRpc
);
ASSERT_EQ
(
code
,
0
);
code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc);
ASSERT_EQ(code, 0);
statusMsg
.
sId
=
htobe64
(
1
);
qwtBuildStatusReqMsg(&qwtstatusMsg, &statusRpc
);
code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc);
ASSERT_EQ(code, 0);
...
...
@@ -586,26 +913,9 @@ TEST(seqTest, cancelFirst) {
qwtInitLogFile();
SSubQueryMsg
*
queryMsg
=
(
SSubQueryMsg
*
)
calloc
(
1
,
sizeof
(
SSubQueryMsg
)
+
100
);
queryMsg
->
queryId
=
htobe64
(
1
);
queryMsg
->
sId
=
htobe64
(
1
);
queryMsg
->
taskId
=
htobe64
(
1
);
queryMsg
->
contentLen
=
htonl
(
100
);
queryRpc
.
pCont
=
queryMsg
;
queryRpc
.
contLen
=
sizeof
(
SSubQueryMsg
)
+
100
;
STaskDropReq
dropMsg
=
{
0
};
dropMsg
.
sId
=
htobe64
(
1
);
dropMsg
.
queryId
=
htobe64
(
1
);
dropMsg
.
taskId
=
htobe64
(
1
);
dropRpc
.
pCont
=
&
dropMsg
;
dropRpc
.
contLen
=
sizeof
(
STaskDropReq
);
SSchTasksStatusReq
statusMsg
=
{
0
};
statusMsg
.
sId
=
htobe64
(
1
);
statusRpc
.
pCont
=
&
statusMsg
;
statusRpc
.
contLen
=
sizeof
(
SSchTasksStatusReq
);
statusRpc
.
msgType
=
TDMT_VND_TASKS_STATUS
;
qwtBuildQueryReqMsg(&queryRpc);
qwtBuildDropReqMsg(&qwtdropMsg, &dropRpc);
qwtBuildStatusReqMsg(&qwtstatusMsg, &statusRpc);
stubSetStringToPlan();
stubSetRpcSendResponse();
...
...
@@ -613,21 +923,21 @@ TEST(seqTest, cancelFirst) {
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0);
statusMsg
.
sId
=
htobe64
(
1
);
qwtBuildStatusReqMsg(&qwtstatusMsg, &statusRpc
);
code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc);
ASSERT_EQ(code, 0);
code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc);
ASSERT_EQ(code, 0);
statusMsg
.
sId
=
htobe64
(
1
);
qwtBuildStatusReqMsg(&qwtstatusMsg, &statusRpc
);
code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc);
ASSERT_EQ(code, 0);
code = qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc);
ASSERT_
EQ
(
code
,
TSDB_CODE_QRY_TASK_DROPPED
);
ASSERT_
TRUE(0 != code
);
statusMsg
.
sId
=
htobe64
(
1
);
qwtBuildStatusReqMsg(&qwtstatusMsg, &statusRpc
);
code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc);
ASSERT_EQ(code, 0);
...
...
@@ -668,24 +978,35 @@ TEST(seqTest, randCase) {
printf("Query,%d\n", t++);
qwtBuildQueryReqMsg(&queryRpc);
code = qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc);
free
(
queryRpc
.
pCont
);
} else if (r >= maxr/5 && r < maxr * 2/5) {
printf("Ready,%d\n", t++);
qwtBuildReadyReqMsg(&readyMsg, &readyRpc);
code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc);
if (qwtTestEnableSleep) {
usleep(1);
}
} else if (r >= maxr * 2/5 && r < maxr* 3/5) {
printf("Fetch,%d\n", t++);
qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc);
code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc);
if (qwtTestEnableSleep) {
usleep(1);
}
} else if (r >= maxr * 3/5 && r < maxr * 4/5) {
printf("Drop,%d\n", t++);
qwtBuildDropReqMsg(&dropMsg, &dropRpc);
code = qWorkerProcessDropMsg(mockPointer, mgmt, &dropRpc);
if (qwtTestEnableSleep) {
usleep(1);
}
} else if (r >= maxr * 4/5 && r < maxr-1) {
printf("Status,%d\n", t++);
qwtBuildStatusReqMsg(&statusMsg, &statusRpc);
code = qWorkerProcessStatusMsg(mockPointer, mgmt, &statusRpc);
ASSERT_EQ(code, 0);
if (qwtTestEnableSleep) {
usleep(1);
}
} else {
printf("QUIT RAND NOW");
break;
...
...
@@ -735,7 +1056,9 @@ TEST(seqTest, multithreadRand) {
qWorkerDestroy(&mgmt);
}
TEST
(
rcTest
,
multithread
)
{
#endif
TEST
(
rcTest
,
shortExecshortDelay
)
{
void
*
mgmt
=
NULL
;
int32_t
code
=
0
;
void
*
mockPointer
=
(
void
*
)
0x1
;
...
...
@@ -755,17 +1078,25 @@ TEST(rcTest, multithread) {
stubSetGetDataBlock
();
srand
(
time
(
NULL
));
qwtTestStop
=
false
;
qwtTestQuitThreadNum
=
0
;
code
=
qWorkerInit
(
NODE_TYPE_VNODE
,
1
,
NULL
,
&
mgmt
,
mockPointer
,
qwtPutReqToQueue
);
ASSERT_EQ
(
code
,
0
);
qwtTestMaxExecTaskUsec
=
0
;
qwtTestReqMaxDelayUsec
=
0
;
tsem_init
(
&
qwtTestQuerySem
,
0
,
0
);
tsem_init
(
&
qwtTestFetchSem
,
0
,
0
);
pthread_attr_t
thattr
;
pthread_attr_init
(
&
thattr
);
pthread_t
t1
,
t2
,
t3
,
t4
,
t5
;
pthread_create
(
&
(
t1
),
&
thattr
,
control
Thread
,
mgmt
);
pthread_create
(
&
(
t2
),
&
thattr
,
queryQueueThread
,
NULL
);
pthread_create
(
&
(
t3
),
&
thattr
,
fetchQueueThread
,
NULL
);
pthread_create
(
&
(
t1
),
&
thattr
,
qwtclient
Thread
,
mgmt
);
pthread_create
(
&
(
t2
),
&
thattr
,
queryQueueThread
,
mgmt
);
pthread_create
(
&
(
t3
),
&
thattr
,
fetchQueueThread
,
mgmt
);
while
(
true
)
{
if
(
qwtTestDeadLoop
)
{
...
...
@@ -777,14 +1108,258 @@ TEST(rcTest, multithread) {
}
qwtTestStop
=
true
;
sleep
(
3
);
while
(
true
)
{
if
(
qwtTestQuitThreadNum
==
3
)
{
break
;
}
sleep
(
1
);
if
(
qwtTestCaseFinished
)
{
if
(
qwtTestQuitThreadNum
<
3
)
{
tsem_post
(
&
qwtTestQuerySem
);
tsem_post
(
&
qwtTestFetchSem
);
usleep
(
10
);
}
}
}
qwtTestQueryQueueNum
=
0
;
qwtTestQueryQueueRIdx
=
0
;
qwtTestQueryQueueWIdx
=
0
;
qwtTestQueryQueueLock
=
0
;
qwtTestFetchQueueNum
=
0
;
qwtTestFetchQueueRIdx
=
0
;
qwtTestFetchQueueWIdx
=
0
;
qwtTestFetchQueueLock
=
0
;
qWorkerDestroy
(
&
mgmt
);
}
TEST
(
rcTest
,
longExecshortDelay
)
{
void
*
mgmt
=
NULL
;
int32_t
code
=
0
;
void
*
mockPointer
=
(
void
*
)
0x1
;
qwtInitLogFile
();
stubSetStringToPlan
();
stubSetRpcSendResponse
();
stubSetExecTask
();
stubSetCreateExecTask
();
stubSetAsyncKillTask
();
stubSetDestroyTask
();
stubSetDestroyDataSinker
();
stubSetGetDataLength
();
stubSetEndPut
();
stubSetPutDataBlock
();
stubSetGetDataBlock
();
srand
(
time
(
NULL
));
qwtTestStop
=
false
;
qwtTestQuitThreadNum
=
0
;
code
=
qWorkerInit
(
NODE_TYPE_VNODE
,
1
,
NULL
,
&
mgmt
,
mockPointer
,
qwtPutReqToQueue
);
ASSERT_EQ
(
code
,
0
);
qwtTestMaxExecTaskUsec
=
1000000
;
qwtTestReqMaxDelayUsec
=
0
;
tsem_init
(
&
qwtTestQuerySem
,
0
,
0
);
tsem_init
(
&
qwtTestFetchSem
,
0
,
0
);
pthread_attr_t
thattr
;
pthread_attr_init
(
&
thattr
);
pthread_t
t1
,
t2
,
t3
,
t4
,
t5
;
pthread_create
(
&
(
t1
),
&
thattr
,
qwtclientThread
,
mgmt
);
pthread_create
(
&
(
t2
),
&
thattr
,
queryQueueThread
,
mgmt
);
pthread_create
(
&
(
t3
),
&
thattr
,
fetchQueueThread
,
mgmt
);
while
(
true
)
{
if
(
qwtTestDeadLoop
)
{
sleep
(
1
);
}
else
{
sleep
(
qwtTestMTRunSec
);
break
;
}
}
qwtTestStop
=
true
;
while
(
true
)
{
if
(
qwtTestQuitThreadNum
==
3
)
{
break
;
}
sleep
(
1
);
if
(
qwtTestCaseFinished
)
{
if
(
qwtTestQuitThreadNum
<
3
)
{
tsem_post
(
&
qwtTestQuerySem
);
tsem_post
(
&
qwtTestFetchSem
);
usleep
(
10
);
}
}
}
qwtTestQueryQueueNum
=
0
;
qwtTestQueryQueueRIdx
=
0
;
qwtTestQueryQueueWIdx
=
0
;
qwtTestQueryQueueLock
=
0
;
qwtTestFetchQueueNum
=
0
;
qwtTestFetchQueueRIdx
=
0
;
qwtTestFetchQueueWIdx
=
0
;
qwtTestFetchQueueLock
=
0
;
qWorkerDestroy
(
&
mgmt
);
}
TEST
(
rcTest
,
shortExeclongDelay
)
{
void
*
mgmt
=
NULL
;
int32_t
code
=
0
;
void
*
mockPointer
=
(
void
*
)
0x1
;
qwtInitLogFile
();
stubSetStringToPlan
();
stubSetRpcSendResponse
();
stubSetExecTask
();
stubSetCreateExecTask
();
stubSetAsyncKillTask
();
stubSetDestroyTask
();
stubSetDestroyDataSinker
();
stubSetGetDataLength
();
stubSetEndPut
();
stubSetPutDataBlock
();
stubSetGetDataBlock
();
srand
(
time
(
NULL
));
qwtTestStop
=
false
;
qwtTestQuitThreadNum
=
0
;
code
=
qWorkerInit
(
NODE_TYPE_VNODE
,
1
,
NULL
,
&
mgmt
,
mockPointer
,
qwtPutReqToQueue
);
ASSERT_EQ
(
code
,
0
);
qwtTestMaxExecTaskUsec
=
0
;
qwtTestReqMaxDelayUsec
=
1000000
;
tsem_init
(
&
qwtTestQuerySem
,
0
,
0
);
tsem_init
(
&
qwtTestFetchSem
,
0
,
0
);
pthread_attr_t
thattr
;
pthread_attr_init
(
&
thattr
);
pthread_t
t1
,
t2
,
t3
,
t4
,
t5
;
pthread_create
(
&
(
t1
),
&
thattr
,
qwtclientThread
,
mgmt
);
pthread_create
(
&
(
t2
),
&
thattr
,
queryQueueThread
,
mgmt
);
pthread_create
(
&
(
t3
),
&
thattr
,
fetchQueueThread
,
mgmt
);
while
(
true
)
{
if
(
qwtTestDeadLoop
)
{
sleep
(
1
);
}
else
{
sleep
(
qwtTestMTRunSec
);
break
;
}
}
qwtTestStop
=
true
;
while
(
true
)
{
if
(
qwtTestQuitThreadNum
==
3
)
{
break
;
}
sleep
(
1
);
if
(
qwtTestCaseFinished
)
{
if
(
qwtTestQuitThreadNum
<
3
)
{
tsem_post
(
&
qwtTestQuerySem
);
tsem_post
(
&
qwtTestFetchSem
);
usleep
(
10
);
}
}
}
qwtTestQueryQueueNum
=
0
;
qwtTestQueryQueueRIdx
=
0
;
qwtTestQueryQueueWIdx
=
0
;
qwtTestQueryQueueLock
=
0
;
qwtTestFetchQueueNum
=
0
;
qwtTestFetchQueueRIdx
=
0
;
qwtTestFetchQueueWIdx
=
0
;
qwtTestFetchQueueLock
=
0
;
qWorkerDestroy
(
&
mgmt
);
}
#if 0
TEST(rcTest, dropTest) {
void *mgmt = NULL;
int32_t code = 0;
void *mockPointer = (void *)0x1;
qwtInitLogFile();
stubSetStringToPlan();
stubSetRpcSendResponse();
stubSetExecTask();
stubSetCreateExecTask();
stubSetAsyncKillTask();
stubSetDestroyTask();
stubSetDestroyDataSinker();
stubSetGetDataLength();
stubSetEndPut();
stubSetPutDataBlock();
stubSetGetDataBlock();
srand(time(NULL));
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0);
tsem_init(&qwtTestQuerySem, 0, 0);
tsem_init(&qwtTestFetchSem, 0, 0);
pthread_attr_t thattr;
pthread_attr_init(&thattr);
pthread_t t1,t2,t3,t4,t5;
pthread_create(&(t1), &thattr, clientThread, mgmt);
pthread_create(&(t2), &thattr, queryQueueThread, mgmt);
pthread_create(&(t3), &thattr, fetchQueueThread, mgmt);
while (true) {
if (qwtTestDeadLoop) {
sleep(1);
} else {
sleep(qwtTestMTRunSec);
break;
}
}
qwtTestStop = true;
sleep(3);
qWorkerDestroy(&mgmt);
}
#endif
int
main
(
int
argc
,
char
**
argv
)
{
srand
(
time
(
NULL
));
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
...
...
source/libs/scheduler/src/scheduler.c
浏览文件 @
4edcf262
...
...
@@ -275,10 +275,13 @@ int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) {
}
int32_t
schRecordTaskSucceedNode
(
SSchTask
*
pTask
)
{
SQueryNodeAddr
*
addr
=
taosArrayGet
(
pTask
->
candidateAddrs
,
atomic_load_8
(
&
pTask
->
candidateIdx
));
assert
(
NULL
!=
addr
);
int32_t
schRecordTaskSucceedNode
(
SSchJob
*
pJob
,
SSchTask
*
pTask
)
{
int32_t
idx
=
atomic_load_8
(
&
pTask
->
candidateIdx
);
SQueryNodeAddr
*
addr
=
taosArrayGet
(
pTask
->
candidateAddrs
,
idx
);
if
(
NULL
==
addr
)
{
SCH_TASK_ELOG
(
"taosArrayGet candidate addr failed, idx:%d, size:%d"
,
idx
,
(
int32_t
)
taosArrayGetSize
(
pTask
->
candidateAddrs
));
SCH_ERR_RET
(
TSDB_CODE_SCH_INTERNAL_ERROR
);
}
pTask
->
succeedAddr
=
*
addr
;
...
...
@@ -578,9 +581,10 @@ int32_t schProcessOnJobFailureImpl(SSchJob *pJob, int32_t status, int32_t errCod
tsem_post
(
&
pJob
->
rspSem
);
}
SCH_ERR_RET
(
atomic_load_32
(
&
pJob
->
errCode
));
int32_t
code
=
atomic_load_32
(
&
pJob
->
errCode
);
SCH_ERR_RET
(
code
);
assert
(
0
);
SCH_JOB_ELOG
(
"job errCode is invalid, errCode:%d"
,
code
);
}
...
...
@@ -721,7 +725,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) {
SCH_SET_TASK_STATUS
(
pTask
,
JOB_TASK_STATUS_PARTIAL_SUCCEED
);
SCH_ERR_JRET
(
schRecordTaskSucceedNode
(
pTask
));
SCH_ERR_JRET
(
schRecordTaskSucceedNode
(
p
Job
,
p
Task
));
int32_t
parentNum
=
pTask
->
parents
?
(
int32_t
)
taosArrayGetSize
(
pTask
->
parents
)
:
0
;
if
(
parentNum
==
0
)
{
...
...
@@ -738,7 +742,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask) {
return
TSDB_CODE_SUCCESS
;
}
else
if
(
taskDone
>
pTask
->
level
->
taskNum
)
{
assert
(
0
);
SCH_TASK_ELOG
(
"taskDone number invalid, done:%d, total:%d"
,
taskDone
,
pTask
->
level
->
taskNum
);
}
if
(
pTask
->
level
->
taskFailed
>
0
)
{
...
...
@@ -871,18 +875,21 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch
}
atomic_store_ptr
(
&
pJob
->
res
,
rsp
);
atomic_
store_32
(
&
pJob
->
resNumOfRows
,
rsp
->
numOfRows
);
atomic_
add_fetch_32
(
&
pJob
->
resNumOfRows
,
htonl
(
rsp
->
numOfRows
)
);
if
(
rsp
->
completed
)
{
SCH_SET_TASK_STATUS
(
pTask
,
JOB_TASK_STATUS_SUCCEED
);
}
SCH_TASK_DLOG
(
"got fetch rsp, rows:%d, complete:%d"
,
htonl
(
rsp
->
numOfRows
),
rsp
->
completed
);
SCH_ERR_JRET
(
schProcessOnDataFetched
(
pJob
));
break
;
}
case
TDMT_VND_DROP_TASK
:
{
case
TDMT_VND_DROP_TASK
_RSP
:
{
// SHOULD NEVER REACH HERE
assert
(
0
);
SCH_TASK_ELOG
(
"invalid status to handle drop task rsp, ref:%d"
,
atomic_load_32
(
&
pJob
->
ref
));
SCH_ERR_JRET
(
TSDB_CODE_SCH_INTERNAL_ERROR
);
break
;
}
default:
...
...
@@ -1031,6 +1038,8 @@ int32_t schAsyncSendMsg(void *transport, SEpSet* epSet, uint64_t qId, uint64_t t
SCH_ERR_JRET
(
code
);
}
qDebug
(
"QID:%"
PRIx64
",TID:%"
PRIx64
" req msg sent, type:%d, %s"
,
qId
,
tId
,
msgType
,
TMSG_INFO
(
msgType
));
return
TSDB_CODE_SUCCESS
;
_return:
...
...
@@ -1289,6 +1298,8 @@ void schDropJobAllTasks(SSchJob *pJob) {
}
int32_t
schExecJobImpl
(
void
*
transport
,
SArray
*
nodeList
,
SQueryDag
*
pDag
,
struct
SSchJob
**
job
,
bool
syncSchedule
)
{
qDebug
(
"QID:%"
PRIx64
" job started"
,
pDag
->
queryId
);
if
(
nodeList
&&
taosArrayGetSize
(
nodeList
)
<=
0
)
{
qInfo
(
"QID:%"
PRIx64
" input nodeList is empty"
,
pDag
->
queryId
);
}
...
...
@@ -1356,7 +1367,7 @@ _return:
*
(
SSchJob
**
)
job
=
NULL
;
scheduleFreeJob
(
pJob
);
schedule
r
FreeJob
(
pJob
);
SCH_RET
(
code
);
}
...
...
@@ -1401,7 +1412,7 @@ int32_t schedulerInit(SSchedulerCfg *cfg) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
scheduleExecJob
(
void
*
transport
,
SArray
*
nodeList
,
SQueryDag
*
pDag
,
struct
SSchJob
**
pJob
,
SQueryResult
*
pRes
)
{
int32_t
schedule
r
ExecJob
(
void
*
transport
,
SArray
*
nodeList
,
SQueryDag
*
pDag
,
struct
SSchJob
**
pJob
,
SQueryResult
*
pRes
)
{
if
(
NULL
==
transport
||
NULL
==
pDag
||
NULL
==
pDag
->
pSubplans
||
NULL
==
pJob
||
NULL
==
pRes
)
{
SCH_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
...
...
@@ -1418,7 +1429,7 @@ int32_t scheduleExecJob(void *transport, SArray *nodeList, SQueryDag* pDag, stru
return
TSDB_CODE_SUCCESS
;
}
int32_t
scheduleAsyncExecJob
(
void
*
transport
,
SArray
*
nodeList
,
SQueryDag
*
pDag
,
struct
SSchJob
**
pJob
)
{
int32_t
schedule
r
AsyncExecJob
(
void
*
transport
,
SArray
*
nodeList
,
SQueryDag
*
pDag
,
struct
SSchJob
**
pJob
)
{
if
(
NULL
==
transport
||
NULL
==
pDag
||
NULL
==
pDag
->
pSubplans
||
NULL
==
pJob
)
{
SCH_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
...
...
@@ -1551,7 +1562,7 @@ _return:
}
int32_t
scheduleFetchRows
(
SSchJob
*
pJob
,
void
**
pData
)
{
int32_t
schedule
r
FetchRows
(
SSchJob
*
pJob
,
void
**
pData
)
{
if
(
NULL
==
pJob
||
NULL
==
pData
)
{
SCH_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
...
...
@@ -1616,11 +1627,12 @@ _return:
}
*
pData
=
rsp
;
SCH_JOB_DLOG
(
"empty res and set query complete, code:%x"
,
code
);
}
atomic_val_compare_exchange_8
(
&
pJob
->
userFetch
,
1
,
0
);
SCH_JOB_DLOG
(
"fetch done,
code:%s"
,
tstrerror
(
code
));
SCH_JOB_DLOG
(
"fetch done,
totalRows:%d, code:%s"
,
pJob
->
resNumOfRows
,
tstrerror
(
code
));
atomic_sub_fetch_32
(
&
pJob
->
ref
,
1
);
SCH_RET
(
code
);
...
...
@@ -1638,7 +1650,7 @@ int32_t scheduleCancelJob(void *job) {
SCH_RET
(
code
);
}
void
scheduleFreeJob
(
void
*
job
)
{
void
schedule
r
FreeJob
(
void
*
job
)
{
if
(
NULL
==
job
)
{
return
;
}
...
...
@@ -1667,7 +1679,8 @@ void scheduleFreeJob(void *job) {
usleep
(
1
);
}
else
{
assert
(
0
);
SCH_JOB_ELOG
(
"invalid job ref number, ref:%d"
,
ref
);
break
;
}
}
...
...
source/libs/scheduler/test/schedulerTests.cpp
浏览文件 @
4edcf262
...
...
@@ -334,7 +334,7 @@ void schtFreeQueryJob(int32_t freeThread) {
SSchJob
*
job
=
atomic_load_ptr
(
&
pQueryJob
);
if
(
job
&&
atomic_val_compare_exchange_ptr
(
&
pQueryJob
,
job
,
NULL
))
{
scheduleFreeJob
(
job
);
schedule
r
FreeJob
(
job
);
if
(
freeThread
)
{
if
(
++
freeNum
%
schtTestPrintNum
==
0
)
{
printf
(
"FreeNum:%d
\n
"
,
freeNum
);
...
...
@@ -378,7 +378,7 @@ void* schtRunJobThread(void *aa) {
qnodeAddr
.
port
=
6031
;
taosArrayPush
(
qnodeList
,
&
qnodeAddr
);
code
=
scheduleAsyncExecJob
(
mockPointer
,
qnodeList
,
&
dag
,
&
job
);
code
=
schedule
r
AsyncExecJob
(
mockPointer
,
qnodeList
,
&
dag
,
&
job
);
assert
(
code
==
0
);
execTasks
=
taosHashInit
(
5
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
false
,
HASH_ENTRY_LOCK
);
...
...
@@ -472,7 +472,7 @@ void* schtRunJobThread(void *aa) {
atomic_store_32
(
&
schtStartFetch
,
1
);
void
*
data
=
NULL
;
code
=
scheduleFetchRows
(
pQueryJob
,
&
data
);
code
=
schedule
r
FetchRows
(
pQueryJob
,
&
data
);
assert
(
code
==
0
||
code
);
if
(
0
==
code
)
{
...
...
@@ -482,7 +482,7 @@ void* schtRunJobThread(void *aa) {
}
data
=
NULL
;
code
=
scheduleFetchRows
(
pQueryJob
,
&
data
);
code
=
schedule
r
FetchRows
(
pQueryJob
,
&
data
);
assert
(
code
==
0
||
code
);
schtFreeQueryJob
(
0
);
...
...
@@ -539,7 +539,7 @@ TEST(queryTest, normalCase) {
schtSetExecNode
();
schtSetAsyncSendMsgToServer
();
code
=
scheduleAsyncExecJob
(
mockPointer
,
qnodeList
,
&
dag
,
&
pJob
);
code
=
schedule
r
AsyncExecJob
(
mockPointer
,
qnodeList
,
&
dag
,
&
pJob
);
ASSERT_EQ
(
code
,
0
);
SSchJob
*
job
=
(
SSchJob
*
)
pJob
;
...
...
@@ -594,7 +594,7 @@ TEST(queryTest, normalCase) {
pthread_create
(
&
(
thread1
),
&
thattr
,
schtCreateFetchRspThread
,
job
);
void
*
data
=
NULL
;
code
=
scheduleFetchRows
(
job
,
&
data
);
code
=
schedule
r
FetchRows
(
job
,
&
data
);
ASSERT_EQ
(
code
,
0
);
SRetrieveTableRsp
*
pRsp
=
(
SRetrieveTableRsp
*
)
data
;
...
...
@@ -603,11 +603,11 @@ TEST(queryTest, normalCase) {
tfree
(
data
);
data
=
NULL
;
code
=
scheduleFetchRows
(
job
,
&
data
);
code
=
schedule
r
FetchRows
(
job
,
&
data
);
ASSERT_EQ
(
code
,
0
);
ASSERT_TRUE
(
data
);
scheduleFreeJob
(
pJob
);
schedule
r
FreeJob
(
pJob
);
schtFreeQueryDag
(
&
dag
);
...
...
@@ -649,11 +649,11 @@ TEST(insertTest, normalCase) {
pthread_create
(
&
(
thread1
),
&
thattr
,
schtSendRsp
,
&
pInsertJob
);
SQueryResult
res
=
{
0
};
code
=
scheduleExecJob
(
mockPointer
,
qnodeList
,
&
dag
,
&
pInsertJob
,
&
res
);
code
=
schedule
r
ExecJob
(
mockPointer
,
qnodeList
,
&
dag
,
&
pInsertJob
,
&
res
);
ASSERT_EQ
(
code
,
0
);
ASSERT_EQ
(
res
.
numOfRows
,
20
);
scheduleFreeJob
(
pInsertJob
);
schedule
r
FreeJob
(
pInsertJob
);
schedulerDestroy
();
}
...
...
source/util/src/terror.c
浏览文件 @
4edcf262
...
...
@@ -353,7 +353,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_INPUT, "invalid input")
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_SCH_NOT_EXIST
,
"Scheduler not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_TASK_NOT_EXIST
,
"Task not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_TASK_ALREADY_EXIST
,
"Task already exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_
RES_CACHE_NOT_EXIST
,
"Task result cache
not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_
TASK_CTX_NOT_EXIST
,
"Task context
not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_TASK_CANCELLED
,
"Task cancelled"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_TASK_DROPPED
,
"Task dropped"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_QRY_TASK_CANCELLING
,
"Task cancelling"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录