Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5cf4edac
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5cf4edac
编写于
1月 12, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature/qnode
上级
0a281a4f
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
383 addition
and
139 deletion
+383
-139
include/common/tmsg.h
include/common/tmsg.h
+7
-0
include/common/tmsgdef.h
include/common/tmsgdef.h
+2
-0
include/libs/qworker/qworker.h
include/libs/qworker/qworker.h
+17
-2
source/dnode/vnode/impl/inc/vnodeQuery.h
source/dnode/vnode/impl/inc/vnodeQuery.h
+1
-0
source/dnode/vnode/impl/src/vnodeQuery.c
source/dnode/vnode/impl/src/vnodeQuery.c
+14
-3
source/libs/executor/src/executorMain.c
source/libs/executor/src/executorMain.c
+4
-2
source/libs/qworker/inc/qworkerInt.h
source/libs/qworker/inc/qworkerInt.h
+52
-24
source/libs/qworker/src/qworker.c
source/libs/qworker/src/qworker.c
+277
-104
source/libs/qworker/test/qworkerTests.cpp
source/libs/qworker/test/qworkerTests.cpp
+9
-4
未找到文件。
include/common/tmsg.h
浏览文件 @
5cf4edac
...
@@ -993,6 +993,13 @@ typedef struct {
...
@@ -993,6 +993,13 @@ typedef struct {
uint64_t
taskId
;
uint64_t
taskId
;
}
SSinkDataReq
;
}
SSinkDataReq
;
typedef
struct
{
SMsgHead
header
;
uint64_t
sId
;
uint64_t
queryId
;
uint64_t
taskId
;
}
SQueryContinueReq
;
typedef
struct
{
typedef
struct
{
SMsgHead
header
;
SMsgHead
header
;
...
...
include/common/tmsgdef.h
浏览文件 @
5cf4edac
...
@@ -170,6 +170,8 @@ enum {
...
@@ -170,6 +170,8 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_VND_DROP_TOPIC
,
"vnode-drop-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_DROP_TOPIC
,
"vnode-drop-topic"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SHOW_TABLES
,
"vnode-show-tables"
,
SVShowTablesReq
,
SVShowTablesRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SHOW_TABLES
,
"vnode-show-tables"
,
SVShowTablesReq
,
SVShowTablesRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SHOW_TABLES_FETCH
,
"vnode-show-tables-fetch"
,
SVShowTablesFetchReq
,
SVShowTablesFetchRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SHOW_TABLES_FETCH
,
"vnode-show-tables-fetch"
,
SVShowTablesFetchReq
,
SVShowTablesFetchRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_QUERY_CONTINUE
,
"vnode-query-continue"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SCHEDULE_DATA_SINK
,
"vnode-schedule-data-sink"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SUBSCRIBE
,
"vnode-subscribe"
,
SMVSubscribeReq
,
SMVSubscribeRsp
)
TD_DEF_MSG_TYPE
(
TDMT_VND_SUBSCRIBE
,
"vnode-subscribe"
,
SMVSubscribeReq
,
SMVSubscribeRsp
)
...
...
include/libs/qworker/qworker.h
浏览文件 @
5cf4edac
...
@@ -22,9 +22,18 @@ extern "C" {
...
@@ -22,9 +22,18 @@ extern "C" {
#include "trpc.h"
#include "trpc.h"
enum
{
NODE_TYPE_VNODE
=
1
,
NODE_TYPE_QNODE
,
NODE_TYPE_SNODE
,
};
typedef
struct
SQWorkerCfg
{
typedef
struct
SQWorkerCfg
{
uint32_t
maxSchedulerNum
;
uint32_t
maxSchedulerNum
;
uint32_t
max
ResCache
Num
;
uint32_t
max
Task
Num
;
uint32_t
maxSchTaskNum
;
uint32_t
maxSchTaskNum
;
}
SQWorkerCfg
;
}
SQWorkerCfg
;
...
@@ -39,11 +48,17 @@ typedef struct {
...
@@ -39,11 +48,17 @@ typedef struct {
uint64_t
numOfErrors
;
uint64_t
numOfErrors
;
}
SQWorkerStat
;
}
SQWorkerStat
;
typedef
int32_t
(
*
putReqToQueryQFp
)(
void
*
,
struct
SRpcMsg
*
);
int32_t
qWorkerInit
(
SQWorkerCfg
*
cfg
,
void
**
qWorkerMgmt
);
int32_t
qWorkerInit
(
int8_t
nodeType
,
int32_t
nodeId
,
SQWorkerCfg
*
cfg
,
void
**
qWorkerMgmt
,
void
*
nodeObj
,
putReqToQueryQFp
fp
);
int32_t
qWorkerProcessQueryMsg
(
void
*
node
,
void
*
qWorkerMgmt
,
SRpcMsg
*
pMsg
);
int32_t
qWorkerProcessQueryMsg
(
void
*
node
,
void
*
qWorkerMgmt
,
SRpcMsg
*
pMsg
);
int32_t
qWorkerProcessQueryContinueMsg
(
void
*
node
,
void
*
qWorkerMgmt
,
SRpcMsg
*
pMsg
);
int32_t
qWorkerProcessDataSinkMsg
(
void
*
node
,
void
*
qWorkerMgmt
,
SRpcMsg
*
pMsg
);
int32_t
qWorkerProcessReadyMsg
(
void
*
node
,
void
*
qWorkerMgmt
,
SRpcMsg
*
pMsg
);
int32_t
qWorkerProcessReadyMsg
(
void
*
node
,
void
*
qWorkerMgmt
,
SRpcMsg
*
pMsg
);
int32_t
qWorkerProcessStatusMsg
(
void
*
node
,
void
*
qWorkerMgmt
,
SRpcMsg
*
pMsg
);
int32_t
qWorkerProcessStatusMsg
(
void
*
node
,
void
*
qWorkerMgmt
,
SRpcMsg
*
pMsg
);
...
...
source/dnode/vnode/impl/inc/vnodeQuery.h
浏览文件 @
5cf4edac
...
@@ -22,6 +22,7 @@ extern "C" {
...
@@ -22,6 +22,7 @@ extern "C" {
#include "vnodeInt.h"
#include "vnodeInt.h"
#include "qworker.h"
#include "qworker.h"
typedef
struct
SQWorkerMgmt
SQHandle
;
typedef
struct
SQWorkerMgmt
SQHandle
;
...
...
source/dnode/vnode/impl/src/vnodeQuery.c
浏览文件 @
5cf4edac
...
@@ -19,11 +19,22 @@
...
@@ -19,11 +19,22 @@
static
int32_t
vnodeGetTableList
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
static
int32_t
vnodeGetTableList
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
);
static
int
vnodeGetTableMeta
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
static
int
vnodeGetTableMeta
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
);
int
vnodeQueryOpen
(
SVnode
*
pVnode
)
{
return
qWorkerInit
(
N
ULL
,
&
pVnode
->
pQuery
);
}
int
vnodeQueryOpen
(
SVnode
*
pVnode
)
{
return
qWorkerInit
(
N
ODE_TYPE_VNODE
,
pVnode
->
vgId
,
NULL
,
&
pVnode
->
pQuery
,
pVnode
,
vnodePutReqToVQueryQ
);
}
int
vnodeProcessQueryReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
int
vnodeProcessQueryReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
vTrace
(
"query message is processed"
);
vTrace
(
"query message is processing"
);
switch
(
pMsg
->
msgType
)
{
case
TDMT_VND_QUERY
:
return
qWorkerProcessQueryMsg
(
pVnode
->
pTsdb
,
pVnode
->
pQuery
,
pMsg
);
return
qWorkerProcessQueryMsg
(
pVnode
->
pTsdb
,
pVnode
->
pQuery
,
pMsg
);
case
TDMT_VND_QUERY_CONTINUE
:
return
qWorkerProcessQueryContinueMsg
(
pVnode
->
pTsdb
,
pVnode
->
pQuery
,
pMsg
);
case
TDMT_VND_SCHEDULE_DATA_SINK
:
return
qWorkerProcessDataSinkMsg
(
pVnode
->
pTsdb
,
pVnode
->
pQuery
,
pMsg
);
default:
vError
(
"unknown msg type:%d in query queue"
,
pMsg
->
msgType
);
return
TSDB_CODE_VND_APP_ERROR
;
}
}
}
int
vnodeProcessFetchReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
int
vnodeProcessFetchReq
(
SVnode
*
pVnode
,
SRpcMsg
*
pMsg
,
SRpcMsg
**
pRsp
)
{
...
...
source/libs/executor/src/executorMain.c
浏览文件 @
5cf4edac
...
@@ -178,7 +178,9 @@ int32_t qExecTask(qTaskInfo_t tinfo, DataSinkHandle* handle) {
...
@@ -178,7 +178,9 @@ int32_t qExecTask(qTaskInfo_t tinfo, DataSinkHandle* handle) {
publishOperatorProfEvent
(
pTaskInfo
->
pRoot
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
publishOperatorProfEvent
(
pTaskInfo
->
pRoot
,
QUERY_PROF_BEFORE_OPERATOR_EXEC
);
int64_t
st
=
0
;
int64_t
st
=
0
;
if
(
handle
)
{
*
handle
=
pTaskInfo
->
dsHandle
;
*
handle
=
pTaskInfo
->
dsHandle
;
}
while
(
1
)
{
while
(
1
)
{
st
=
taosGetTimestampUs
();
st
=
taosGetTimestampUs
();
...
...
source/libs/qworker/inc/qworkerInt.h
浏览文件 @
5cf4edac
...
@@ -23,7 +23,7 @@ extern "C" {
...
@@ -23,7 +23,7 @@ extern "C" {
#include "tlockfree.h"
#include "tlockfree.h"
#define QWORKER_DEFAULT_SCHEDULER_NUMBER 10000
#define QWORKER_DEFAULT_SCHEDULER_NUMBER 10000
#define QWORKER_DEFAULT_
RES_CACHE
_NUMBER 10000
#define QWORKER_DEFAULT_
TASK
_NUMBER 10000
#define QWORKER_DEFAULT_SCH_TASK_NUMBER 10000
#define QWORKER_DEFAULT_SCH_TASK_NUMBER 10000
enum
{
enum
{
...
@@ -57,7 +57,6 @@ enum {
...
@@ -57,7 +57,6 @@ enum {
QW_ADD_ACQUIRE
,
QW_ADD_ACQUIRE
,
};
};
typedef
struct
SQWTaskStatus
{
typedef
struct
SQWTaskStatus
{
SRWLatch
lock
;
SRWLatch
lock
;
int32_t
code
;
int32_t
code
;
...
@@ -67,12 +66,14 @@ typedef struct SQWTaskStatus {
...
@@ -67,12 +66,14 @@ typedef struct SQWTaskStatus {
bool
drop
;
bool
drop
;
}
SQWTaskStatus
;
}
SQWTaskStatus
;
typedef
struct
SQW
orkerTaskHandlesCache
{
typedef
struct
SQW
TaskCtx
{
SRWLatch
lock
;
SRWLatch
lock
;
int8_t
sinkScheduled
;
int8_t
queryScheduled
;
bool
needRsp
;
bool
needRsp
;
qTaskInfo_t
taskHandle
;
qTaskInfo_t
taskHandle
;
DataSinkHandle
sinkHandle
;
DataSinkHandle
sinkHandle
;
}
SQW
orkerTaskHandlesCache
;
}
SQW
TaskCtx
;
typedef
struct
SQWSchStatus
{
typedef
struct
SQWSchStatus
{
int32_t
lastAccessTs
;
// timestamp in second
int32_t
lastAccessTs
;
// timestamp in second
...
@@ -83,10 +84,14 @@ typedef struct SQWSchStatus {
...
@@ -83,10 +84,14 @@ typedef struct SQWSchStatus {
// Qnode/Vnode level task management
// Qnode/Vnode level task management
typedef
struct
SQWorkerMgmt
{
typedef
struct
SQWorkerMgmt
{
SQWorkerCfg
cfg
;
SQWorkerCfg
cfg
;
int8_t
nodeType
;
int32_t
nodeId
;
SRWLatch
schLock
;
SRWLatch
schLock
;
SRWLatch
res
Lock
;
SRWLatch
ctx
Lock
;
SHashObj
*
schHash
;
//key: schedulerId, value: SQWSchStatus
SHashObj
*
schHash
;
//key: schedulerId, value: SQWSchStatus
SHashObj
*
resHash
;
//key: queryId+taskId, value: SQWorkerResCache
SHashObj
*
ctxHash
;
//key: queryId+taskId, value: SQWTaskCtx
void
*
nodeObj
;
putReqToQueryQFp
putToQueueFp
;
}
SQWorkerMgmt
;
}
SQWorkerMgmt
;
#define QW_GOT_RES_DATA(data) (true)
#define QW_GOT_RES_DATA(data) (true)
...
@@ -95,40 +100,63 @@ typedef struct SQWorkerMgmt {
...
@@ -95,40 +100,63 @@ typedef struct SQWorkerMgmt {
#define QW_TASK_NOT_EXIST(code) (TSDB_CODE_QRY_SCH_NOT_EXIST == (code) || TSDB_CODE_QRY_TASK_NOT_EXIST == (code))
#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))
#define QW_TASK_ALREADY_EXIST(code) (TSDB_CODE_QRY_TASK_ALREADY_EXIST == (code))
#define QW_TASK_READY_RESP(status) (status == JOB_TASK_STATUS_SUCCEED || status == JOB_TASK_STATUS_FAILED || status == JOB_TASK_STATUS_CANCELLED || status == JOB_TASK_STATUS_PARTIAL_SUCCEED)
#define QW_TASK_READY_RESP(status) (status == JOB_TASK_STATUS_SUCCEED || status == JOB_TASK_STATUS_FAILED || status == JOB_TASK_STATUS_CANCELLED || status == JOB_TASK_STATUS_PARTIAL_SUCCEED)
#define QW_SET_QTID(id, q
id, tid) do { *(uint64_t *)(id) = (qid); *(uint64_t *)((char *)(id) + sizeof(qid)) = (ti
d); } while (0)
#define QW_SET_QTID(id, q
Id, tId) do { *(uint64_t *)(id) = (qId); *(uint64_t *)((char *)(id) + sizeof(qId)) = (tI
d); } while (0)
#define QW_GET_QTID(id, q
id, tid) do { (qid) = *(uint64_t *)(id); (tid) = *(uint64_t *)((char *)(id) + sizeof(qi
d)); } while (0)
#define QW_GET_QTID(id, q
Id, tId) do { (qId) = *(uint64_t *)(id); (tId) = *(uint64_t *)((char *)(id) + sizeof(qI
d)); } while (0)
#define QW_IDS() sId, qId, tId
#define QW_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
#define QW_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
#define QW_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
#define QW_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
#define QW_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { qError(__VA_ARGS__); terrno = _code; return _code; } } while (0)
#define QW_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
#define QW_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
#define QW_ELOG(param, ...) qError("QW:%p " param, mgmt, __VA_ARGS__)
#define QW_DLOG(param, ...) qDebug("QW:%p " param, mgmt, __VA_ARGS__)
#define QW_SCH_ELOG(param, ...) qError("QW:%p SID:%"PRIx64 param, mgmt, sId, __VA_ARGS__)
#define QW_SCH_DLOG(param, ...) qDebug("QW:%p SID:%"PRIx64 param, mgmt, sId, __VA_ARGS__)
#define QW_TASK_ELOG(param, ...) qError("QW:%p SID:%"PRIx64",QID:%"PRIx64",TID:%"PRIx64 param, mgmt, sId, qId, tId, __VA_ARGS__)
#define QW_TASK_WLOG(param, ...) qWarn("QW:%p SID:%"PRIx64",QID:%"PRIx64",TID:%"PRIx64 param, mgmt, sId, qId, tId, __VA_ARGS__)
#define QW_TASK_DLOG(param, ...) qDebug("QW:%p SID:%"PRIx64",QID:%"PRIx64",TID:%"PRIx64 param, mgmt, sId, qId, tId, __VA_ARGS__)
#define TD_RWLATCH_WRITE_FLAG_COPY 0x40000000
#define QW_LOCK(type, _lock) do { \
#define QW_LOCK(type, _lock) do { \
if (QW_READ == (type)) { \
if (QW_READ == (type)) { \
if ((*(_lock)) < 0) assert(0); \
assert(atomic_load_32((_lock)) >= 0); \
qDebug("QW RLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
taosRLockLatch(_lock); \
taosRLockLatch(_lock); \
qDebug("QW RLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
qDebug("QW RLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
assert(atomic_load_32((_lock)) > 0); \
} else { \
} else { \
if ((*(_lock)) < 0) assert(0); \
assert(atomic_load_32((_lock)) >= 0); \
qDebug("QW WLOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
taosWLockLatch(_lock); \
taosWLockLatch(_lock); \
qDebug("QW WLOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
qDebug("QW WLOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \
} \
} \
} while (0)
} while (0)
#define QW_UNLOCK(type, _lock) do { \
#define QW_UNLOCK(type, _lock) do { \
if (QW_READ == (type)) { \
if (QW_READ == (type)) { \
if ((*(_lock)) <= 0) assert(0); \
assert(atomic_load_32((_lock)) > 0); \
qDebug("QW RULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
taosRUnLockLatch(_lock); \
taosRUnLockLatch(_lock); \
qDebug("QW RULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
qDebug("QW RULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
assert(atomic_load_32((_lock)) >= 0); \
} else { \
} else { \
if ((*(_lock)) <= 0) assert(0); \
assert(atomic_load_32((_lock)) == TD_RWLATCH_WRITE_FLAG_COPY); \
qDebug("QW WULOCK%p:%d, %s:%d B", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
taosWUnLockLatch(_lock); \
taosWUnLockLatch(_lock); \
qDebug("QW WULOCK%p, %s:%d", (_lock), __FILE__, __LINE__); \
qDebug("QW WULOCK%p:%d, %s:%d E", (_lock), atomic_load_32(_lock), __FILE__, __LINE__); \
assert(atomic_load_32((_lock)) >= 0); \
} \
} \
} while (0)
} while (0)
static
int32_t
qwAcquireScheduler
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
SQWSchStatus
**
sch
,
int32_t
nOpt
);
static
int32_t
qwAcquireScheduler
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
SQWSchStatus
**
sch
);
static
int32_t
qwAddAcquireScheduler
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
SQWSchStatus
**
sch
);
#ifdef __cplusplus
#ifdef __cplusplus
...
...
source/libs/qworker/src/qworker.c
浏览文件 @
5cf4edac
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#include "tname.h"
#include "tname.h"
#include "dataSinkMgt.h"
#include "dataSinkMgt.h"
int32_t
qwValidateStatus
(
int8_t
oriStatus
,
int8_t
newStatus
)
{
int32_t
qwValidateStatus
(
SQWorkerMgmt
*
mgmt
,
int8_t
oriStatus
,
int8_t
newStatus
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
if
(
oriStatus
==
newStatus
)
{
if
(
oriStatus
==
newStatus
)
{
...
@@ -62,7 +62,7 @@ int32_t qwValidateStatus(int8_t oriStatus, int8_t newStatus) {
...
@@ -62,7 +62,7 @@ int32_t qwValidateStatus(int8_t oriStatus, int8_t newStatus) {
break
;
break
;
default:
default:
qError
(
"invalid task status:%d"
,
oriStatus
);
QW_TASK_ELOG
(
"invalid task status:%d"
,
oriStatus
);
return
TSDB_CODE_QRY_APP_ERROR
;
return
TSDB_CODE_QRY_APP_ERROR
;
}
}
...
@@ -70,22 +70,27 @@ int32_t qwValidateStatus(int8_t oriStatus, int8_t newStatus) {
...
@@ -70,22 +70,27 @@ int32_t qwValidateStatus(int8_t oriStatus, int8_t newStatus) {
_return:
_return:
qError
(
"invalid task status,
from %d to %d"
,
oriStatus
,
newStatus
);
QW_TASK_ELOG
(
"invalid task status update
from %d to %d"
,
oriStatus
,
newStatus
);
QW_
ERR_
RET
(
code
);
QW_RET
(
code
);
}
}
int32_t
qwUpdateTaskInfo
(
SQW
TaskStatus
*
task
,
int8_t
type
,
void
*
data
)
{
int32_t
qwUpdateTaskInfo
(
SQW
orkerMgmt
*
mgmt
,
SQWTaskStatus
*
task
,
int8_t
type
,
void
*
data
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
)
{
int32_t
code
=
0
;
int32_t
code
=
0
;
int8_t
origStatus
=
0
;
switch
(
type
)
{
switch
(
type
)
{
case
QW_TASK_INFO_STATUS
:
{
case
QW_TASK_INFO_STATUS
:
{
int8_t
newStatus
=
*
(
int8_t
*
)
data
;
int8_t
newStatus
=
*
(
int8_t
*
)
data
;
QW_ERR_RET
(
qwValidateStatus
(
task
->
status
,
newStatus
));
QW_ERR_RET
(
qwValidateStatus
(
mgmt
,
task
->
status
,
newStatus
,
QW_IDS
()));
origStatus
=
task
->
status
;
task
->
status
=
newStatus
;
task
->
status
=
newStatus
;
QW_TASK_DLOG
(
"task status updated from %d to %d"
,
origStatus
,
newStatus
);
break
;
break
;
}
}
default:
default:
qError
(
"uknown task info
type:%d"
,
type
);
QW_TASK_ELOG
(
"unknown task info,
type:%d"
,
type
);
return
TSDB_CODE_QRY_APP_ERROR
;
return
TSDB_CODE_QRY_APP_ERROR
;
}
}
...
@@ -96,18 +101,18 @@ int32_t qwAddTaskHandlesToCache(SQWorkerMgmt *mgmt, uint64_t qId, uint64_t tId,
...
@@ -96,18 +101,18 @@ int32_t qwAddTaskHandlesToCache(SQWorkerMgmt *mgmt, uint64_t qId, uint64_t tId,
char
id
[
sizeof
(
qId
)
+
sizeof
(
tId
)]
=
{
0
};
char
id
[
sizeof
(
qId
)
+
sizeof
(
tId
)]
=
{
0
};
QW_SET_QTID
(
id
,
qId
,
tId
);
QW_SET_QTID
(
id
,
qId
,
tId
);
SQW
orkerTaskHandlesCache
resCache
=
{
0
};
SQW
TaskCtx
resCache
=
{
0
};
resCache
.
taskHandle
=
taskHandle
;
resCache
.
taskHandle
=
taskHandle
;
resCache
.
sinkHandle
=
sinkHandle
;
resCache
.
sinkHandle
=
sinkHandle
;
QW_LOCK
(
QW_WRITE
,
&
mgmt
->
res
Lock
);
QW_LOCK
(
QW_WRITE
,
&
mgmt
->
ctx
Lock
);
if
(
0
!=
taosHashPut
(
mgmt
->
resHash
,
id
,
sizeof
(
id
),
&
resCache
,
sizeof
(
SQWorkerTaskHandlesCache
)))
{
if
(
0
!=
taosHashPut
(
mgmt
->
ctxHash
,
id
,
sizeof
(
id
),
&
resCache
,
sizeof
(
SQWTaskCtx
)))
{
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
res
Lock
);
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
ctx
Lock
);
qError
(
"taosHashPut queryId[%"
PRIx64
"] taskId[%"
PRIx64
"] to resHash failed"
,
qId
,
tId
);
qError
(
"taosHashPut queryId[%"
PRIx64
"] taskId[%"
PRIx64
"] to resHash failed"
,
qId
,
tId
);
return
TSDB_CODE_QRY_APP_ERROR
;
return
TSDB_CODE_QRY_APP_ERROR
;
}
}
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
res
Lock
);
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
ctx
Lock
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -116,7 +121,7 @@ static int32_t qwAddScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t sId,
...
@@ -116,7 +121,7 @@ static int32_t qwAddScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t sId,
SQWSchStatus
newSch
=
{
0
};
SQWSchStatus
newSch
=
{
0
};
newSch
.
tasksHash
=
taosHashInit
(
mgmt
->
cfg
.
maxSchTaskNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
newSch
.
tasksHash
=
taosHashInit
(
mgmt
->
cfg
.
maxSchTaskNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
newSch
.
tasksHash
)
{
if
(
NULL
==
newSch
.
tasksHash
)
{
qError
(
"taosHashInit %d failed"
,
mgmt
->
cfg
.
maxSchTaskNum
);
QW_SCH_DLOG
(
"taosHashInit %d failed"
,
mgmt
->
cfg
.
maxSchTaskNum
);
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
}
...
@@ -126,14 +131,18 @@ static int32_t qwAddScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t sId,
...
@@ -126,14 +131,18 @@ static int32_t qwAddScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t sId,
if
(
0
!=
code
)
{
if
(
0
!=
code
)
{
if
(
!
HASH_NODE_EXIST
(
code
))
{
if
(
!
HASH_NODE_EXIST
(
code
))
{
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
schLock
);
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
schLock
);
qError
(
"taosHashPut sId[%"
PRIx64
"] to scheduleHash failed"
,
sId
);
QW_SCH_ELOG
(
"taosHashPut new sch to scheduleHash failed, errno:%d"
,
errno
);
taosHashCleanup
(
newSch
.
tasksHash
);
taosHashCleanup
(
newSch
.
tasksHash
);
return
TSDB_CODE_QRY_APP_ERROR
;
return
TSDB_CODE_QRY_APP_ERROR
;
}
}
}
}
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
schLock
);
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
schLock
);
if
(
TSDB_CODE_SUCCESS
==
qwAcquireScheduler
(
rwType
,
mgmt
,
sId
,
sch
,
QW_NOT_EXIST_ADD
))
{
if
(
TSDB_CODE_SUCCESS
==
qwAcquireScheduler
(
rwType
,
mgmt
,
sId
,
sch
))
{
if
(
code
)
{
taosHashCleanup
(
newSch
.
tasksHash
);
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
}
}
...
@@ -141,7 +150,7 @@ static int32_t qwAddScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t sId,
...
@@ -141,7 +150,7 @@ static int32_t qwAddScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t sId,
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
qwAcquireScheduler
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
SQWSchStatus
**
sch
,
int32_t
nOpt
)
{
static
int32_t
qwAcquireScheduler
Impl
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
SQWSchStatus
**
sch
,
int32_t
nOpt
)
{
QW_LOCK
(
rwType
,
&
mgmt
->
schLock
);
QW_LOCK
(
rwType
,
&
mgmt
->
schLock
);
*
sch
=
taosHashGet
(
mgmt
->
schHash
,
&
sId
,
sizeof
(
sId
));
*
sch
=
taosHashGet
(
mgmt
->
schHash
,
&
sId
,
sizeof
(
sId
));
if
(
NULL
==
(
*
sch
))
{
if
(
NULL
==
(
*
sch
))
{
...
@@ -159,6 +168,14 @@ static int32_t qwAcquireScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t s
...
@@ -159,6 +168,14 @@ static int32_t qwAcquireScheduler(int32_t rwType, SQWorkerMgmt *mgmt, uint64_t s
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
qwAddAcquireScheduler
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
SQWSchStatus
**
sch
)
{
return
qwAcquireSchedulerImpl
(
rwType
,
mgmt
,
sId
,
sch
,
QW_NOT_EXIST_ADD
);
}
static
int32_t
qwAcquireScheduler
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
SQWSchStatus
**
sch
)
{
return
qwAcquireSchedulerImpl
(
rwType
,
mgmt
,
sId
,
sch
,
QW_NOT_EXIST_RET_ERR
);
}
static
FORCE_INLINE
void
qwReleaseScheduler
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
)
{
static
FORCE_INLINE
void
qwReleaseScheduler
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
)
{
QW_UNLOCK
(
rwType
,
&
mgmt
->
schLock
);
QW_UNLOCK
(
rwType
,
&
mgmt
->
schLock
);
}
}
...
@@ -234,7 +251,7 @@ int32_t qwAddTaskToSch(int32_t rwType, SQWSchStatus *sch, uint64_t qId, uint64_t
...
@@ -234,7 +251,7 @@ int32_t qwAddTaskToSch(int32_t rwType, SQWSchStatus *sch, uint64_t qId, uint64_t
static
int32_t
qwAddTask
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
status
,
int32_t
eOpt
,
SQWSchStatus
**
sch
,
SQWTaskStatus
**
task
)
{
static
int32_t
qwAddTask
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
tId
,
int32_t
status
,
int32_t
eOpt
,
SQWSchStatus
**
sch
,
SQWTaskStatus
**
task
)
{
SQWSchStatus
*
tsch
=
NULL
;
SQWSchStatus
*
tsch
=
NULL
;
QW_ERR_RET
(
qwA
cquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
tsch
,
QW_NOT_EXIST_ADD
));
QW_ERR_RET
(
qwA
ddAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
tsch
));
int32_t
code
=
qwAddTaskToSch
(
QW_READ
,
tsch
,
qId
,
tId
,
status
,
eOpt
,
task
);
int32_t
code
=
qwAddTaskToSch
(
QW_READ
,
tsch
,
qId
,
tId
,
status
,
eOpt
,
task
);
if
(
code
)
{
if
(
code
)
{
...
@@ -250,14 +267,14 @@ static int32_t qwAddTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_
...
@@ -250,14 +267,14 @@ static int32_t qwAddTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint64_
QW_RET
(
code
);
QW_RET
(
code
);
}
}
static
FORCE_INLINE
int32_t
qwAcquireTask
Handles
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
,
uint64_t
queryId
,
uint64_t
taskId
,
SQWorkerTaskHandlesCache
**
handles
)
{
static
FORCE_INLINE
int32_t
qwAcquireTask
Ctx
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
,
uint64_t
queryId
,
uint64_t
taskId
,
SQWTaskCtx
**
handles
)
{
char
id
[
sizeof
(
queryId
)
+
sizeof
(
taskId
)]
=
{
0
};
char
id
[
sizeof
(
queryId
)
+
sizeof
(
taskId
)]
=
{
0
};
QW_SET_QTID
(
id
,
queryId
,
taskId
);
QW_SET_QTID
(
id
,
queryId
,
taskId
);
QW_LOCK
(
rwType
,
&
mgmt
->
res
Lock
);
QW_LOCK
(
rwType
,
&
mgmt
->
ctx
Lock
);
*
handles
=
taosHashGet
(
mgmt
->
res
Hash
,
id
,
sizeof
(
id
));
*
handles
=
taosHashGet
(
mgmt
->
ctx
Hash
,
id
,
sizeof
(
id
));
if
(
NULL
==
(
*
handles
))
{
if
(
NULL
==
(
*
handles
))
{
QW_UNLOCK
(
rwType
,
&
mgmt
->
res
Lock
);
QW_UNLOCK
(
rwType
,
&
mgmt
->
ctx
Lock
);
return
TSDB_CODE_QRY_RES_CACHE_NOT_EXIST
;
return
TSDB_CODE_QRY_RES_CACHE_NOT_EXIST
;
}
}
...
@@ -265,7 +282,7 @@ static FORCE_INLINE int32_t qwAcquireTaskHandles(int32_t rwType, SQWorkerMgmt *m
...
@@ -265,7 +282,7 @@ static FORCE_INLINE int32_t qwAcquireTaskHandles(int32_t rwType, SQWorkerMgmt *m
}
}
static
FORCE_INLINE
void
qwReleaseTaskResCache
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
)
{
static
FORCE_INLINE
void
qwReleaseTaskResCache
(
int32_t
rwType
,
SQWorkerMgmt
*
mgmt
)
{
QW_UNLOCK
(
rwType
,
&
mgmt
->
res
Lock
);
QW_UNLOCK
(
rwType
,
&
mgmt
->
ctx
Lock
);
}
}
...
@@ -273,7 +290,7 @@ int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRs
...
@@ -273,7 +290,7 @@ int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRs
SQWSchStatus
*
sch
=
NULL
;
SQWSchStatus
*
sch
=
NULL
;
int32_t
taskNum
=
0
;
int32_t
taskNum
=
0
;
QW_ERR_RET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_RET_ERR
));
QW_ERR_RET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
));
sch
->
lastAccessTs
=
taosGetTimestampSec
();
sch
->
lastAccessTs
=
taosGetTimestampSec
();
...
@@ -319,7 +336,7 @@ int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRs
...
@@ -319,7 +336,7 @@ int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRs
int32_t
qwUpdateSchLastAccess
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
)
{
int32_t
qwUpdateSchLastAccess
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
)
{
SQWSchStatus
*
sch
=
NULL
;
SQWSchStatus
*
sch
=
NULL
;
QW_ERR_RET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_RET_ERR
));
QW_ERR_RET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
));
sch
->
lastAccessTs
=
taosGetTimestampSec
();
sch
->
lastAccessTs
=
taosGetTimestampSec
();
...
@@ -333,12 +350,12 @@ int32_t qwUpdateTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint6
...
@@ -333,12 +350,12 @@ int32_t qwUpdateTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint6
SQWTaskStatus
*
task
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
QW_ERR_RET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_RET_ERR
));
QW_ERR_RET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
));
QW_ERR_JRET
(
qwAcquireTask
(
QW_READ
,
sch
,
qId
,
tId
,
&
task
));
QW_ERR_JRET
(
qwAcquireTask
(
QW_READ
,
sch
,
qId
,
tId
,
&
task
));
QW_LOCK
(
QW_WRITE
,
&
task
->
lock
);
QW_LOCK
(
QW_WRITE
,
&
task
->
lock
);
qwUpdateTaskInfo
(
task
,
QW_TASK_INFO_STATUS
,
&
status
);
qwUpdateTaskInfo
(
mgmt
,
task
,
QW_TASK_INFO_STATUS
,
&
status
,
QW_IDS
()
);
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
_return:
_return:
...
@@ -355,7 +372,7 @@ int32_t qwGetTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint
...
@@ -355,7 +372,7 @@ int32_t qwGetTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint
SQWTaskStatus
*
task
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
if
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_RET_ERR
))
{
if
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
))
{
*
taskStatus
=
JOB_TASK_STATUS_NULL
;
*
taskStatus
=
JOB_TASK_STATUS_NULL
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -376,17 +393,17 @@ int32_t qwGetTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint
...
@@ -376,17 +393,17 @@ int32_t qwGetTaskStatus(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint
}
}
int32_t
qwCancelTask
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
q
ueryId
,
uint64_t
task
Id
)
{
int32_t
qwCancelTask
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
q
Id
,
uint64_t
t
Id
)
{
SQWSchStatus
*
sch
=
NULL
;
SQWSchStatus
*
sch
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
QW_ERR_RET
(
qwA
cquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_ADD
));
QW_ERR_RET
(
qwA
ddAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
));
if
(
qwAcquireTask
(
QW_READ
,
sch
,
q
ueryId
,
task
Id
,
&
task
))
{
if
(
qwAcquireTask
(
QW_READ
,
sch
,
q
Id
,
t
Id
,
&
task
))
{
qwReleaseScheduler
(
QW_READ
,
mgmt
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
code
=
qwAddTask
(
mgmt
,
sId
,
q
ueryId
,
task
Id
,
JOB_TASK_STATUS_NOT_START
,
QW_EXIST_ACQUIRE
,
&
sch
,
&
task
);
code
=
qwAddTask
(
mgmt
,
sId
,
q
Id
,
t
Id
,
JOB_TASK_STATUS_NOT_START
,
QW_EXIST_ACQUIRE
,
&
sch
,
&
task
);
if
(
code
)
{
if
(
code
)
{
qwReleaseScheduler
(
QW_READ
,
mgmt
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
QW_ERR_RET
(
code
);
QW_ERR_RET
(
code
);
...
@@ -409,10 +426,10 @@ int32_t qwCancelTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_
...
@@ -409,10 +426,10 @@ int32_t qwCancelTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64_
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
else
if
(
task
->
status
==
JOB_TASK_STATUS_FAILED
||
task
->
status
==
JOB_TASK_STATUS_SUCCEED
||
task
->
status
==
JOB_TASK_STATUS_PARTIAL_SUCCEED
)
{
}
else
if
(
task
->
status
==
JOB_TASK_STATUS_FAILED
||
task
->
status
==
JOB_TASK_STATUS_SUCCEED
||
task
->
status
==
JOB_TASK_STATUS_PARTIAL_SUCCEED
)
{
newStatus
=
JOB_TASK_STATUS_CANCELLED
;
newStatus
=
JOB_TASK_STATUS_CANCELLED
;
QW_ERR_JRET
(
qwUpdateTaskInfo
(
task
,
QW_TASK_INFO_STATUS
,
&
newStatus
));
QW_ERR_JRET
(
qwUpdateTaskInfo
(
mgmt
,
task
,
QW_TASK_INFO_STATUS
,
&
newStatus
,
QW_IDS
()
));
}
else
{
}
else
{
newStatus
=
JOB_TASK_STATUS_CANCELLING
;
newStatus
=
JOB_TASK_STATUS_CANCELLING
;
QW_ERR_JRET
(
qwUpdateTaskInfo
(
task
,
QW_TASK_INFO_STATUS
,
&
newStatus
));
QW_ERR_JRET
(
qwUpdateTaskInfo
(
mgmt
,
task
,
QW_TASK_INFO_STATUS
,
&
newStatus
,
QW_IDS
()
));
}
}
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
...
@@ -441,50 +458,60 @@ _return:
...
@@ -441,50 +458,60 @@ _return:
QW_RET
(
code
);
QW_RET
(
code
);
}
}
int32_t
qwDropTask
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
q
ueryId
,
uint64_t
task
Id
)
{
int32_t
qwDropTask
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
q
Id
,
uint64_t
t
Id
)
{
SQWSchStatus
*
sch
=
NULL
;
SQWSchStatus
*
sch
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
char
id
[
sizeof
(
queryId
)
+
sizeof
(
taskId
)]
=
{
0
};
QW_SET_QTID
(
id
,
queryId
,
taskId
);
QW_LOCK
(
QW_WRITE
,
&
mgmt
->
resLock
);
char
id
[
sizeof
(
qId
)
+
sizeof
(
tId
)]
=
{
0
};
if
(
mgmt
->
resHash
)
{
QW_SET_QTID
(
id
,
qId
,
tId
);
taosHashRemove
(
mgmt
->
resHash
,
id
,
sizeof
(
id
));
QW_LOCK
(
QW_WRITE
,
&
mgmt
->
ctxLock
);
if
(
mgmt
->
ctxHash
)
{
if
(
taosHashRemove
(
mgmt
->
ctxHash
,
id
,
sizeof
(
id
)))
{
QW_TASK_WLOG
(
"taosHashRemove from ctx hash failed, id:%s"
,
id
);
}
}
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
resLock
);
}
QW_UNLOCK
(
QW_WRITE
,
&
mgmt
->
ctxLock
);
if
(
TSDB_CODE_SUCCESS
!=
qwAcquireScheduler
(
QW_WRITE
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_RET_ERR
))
{
if
(
qwAcquireScheduler
(
QW_WRITE
,
mgmt
,
sId
,
&
sch
))
{
qWarn
(
"scheduler %"
PRIx64
" doesn't exist"
,
sId
);
QW_TASK_WLOG
(
"scheduler does not exist, sch:%p"
,
sch
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
qwAcquireTask
(
QW_WRITE
,
sch
,
q
ueryId
,
task
Id
,
&
task
))
{
if
(
qwAcquireTask
(
QW_WRITE
,
sch
,
q
Id
,
t
Id
,
&
task
))
{
qwReleaseScheduler
(
QW_WRITE
,
mgmt
);
qwReleaseScheduler
(
QW_WRITE
,
mgmt
);
qWarn
(
"scheduler %"
PRIx64
" queryId %"
PRIx64
" taskId:%"
PRIx64
" doesn't exist"
,
sId
,
queryId
,
taskId
);
QW_TASK_WLOG
(
"task does not exist, task:%p"
,
task
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
taosHashRemove
(
sch
->
tasksHash
,
id
,
sizeof
(
id
));
QW_TASK_DLOG
(
"drop task, status:%d, code:%x, ready:%d, cancel:%d, drop:%d"
,
task
->
status
,
task
->
code
,
task
->
ready
,
task
->
cancel
,
task
->
drop
);
if
(
taosHashRemove
(
sch
->
tasksHash
,
id
,
sizeof
(
id
)))
{
QW_TASK_ELOG
(
"taosHashRemove task from hash failed, task:%p"
,
task
);
QW_ERR_JRET
(
TSDB_CODE_QRY_APP_ERROR
);
}
_return:
qwReleaseTask
(
QW_WRITE
,
sch
);
qwReleaseTask
(
QW_WRITE
,
sch
);
qwReleaseScheduler
(
QW_WRITE
,
mgmt
);
qwReleaseScheduler
(
QW_WRITE
,
mgmt
);
return
TSDB_CODE_SUCCESS
;
QW_RET
(
code
)
;
}
}
int32_t
qwCancelDropTask
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
q
ueryId
,
uint64_t
task
Id
)
{
int32_t
qwCancelDropTask
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
q
Id
,
uint64_t
t
Id
)
{
SQWSchStatus
*
sch
=
NULL
;
SQWSchStatus
*
sch
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
QW_ERR_RET
(
qwA
cquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_ADD
));
QW_ERR_RET
(
qwA
ddAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
));
if
(
qwAcquireTask
(
QW_READ
,
sch
,
q
ueryId
,
task
Id
,
&
task
))
{
if
(
qwAcquireTask
(
QW_READ
,
sch
,
q
Id
,
t
Id
,
&
task
))
{
qwReleaseScheduler
(
QW_READ
,
mgmt
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
code
=
qwAddTask
(
mgmt
,
sId
,
q
ueryId
,
task
Id
,
JOB_TASK_STATUS_NOT_START
,
QW_EXIST_ACQUIRE
,
&
sch
,
&
task
);
code
=
qwAddTask
(
mgmt
,
sId
,
q
Id
,
t
Id
,
JOB_TASK_STATUS_NOT_START
,
QW_EXIST_ACQUIRE
,
&
sch
,
&
task
);
if
(
code
)
{
if
(
code
)
{
qwReleaseScheduler
(
QW_READ
,
mgmt
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
QW_ERR_RET
(
code
);
QW_ERR_RET
(
code
);
...
@@ -500,7 +527,7 @@ int32_t qwCancelDropTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uin
...
@@ -500,7 +527,7 @@ int32_t qwCancelDropTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uin
if
(
task
->
status
==
JOB_TASK_STATUS_EXECUTING
)
{
if
(
task
->
status
==
JOB_TASK_STATUS_EXECUTING
)
{
newStatus
=
JOB_TASK_STATUS_DROPPING
;
newStatus
=
JOB_TASK_STATUS_DROPPING
;
QW_ERR_JRET
(
qwUpdateTaskInfo
(
task
,
QW_TASK_INFO_STATUS
,
&
newStatus
));
QW_ERR_JRET
(
qwUpdateTaskInfo
(
mgmt
,
task
,
QW_TASK_INFO_STATUS
,
&
newStatus
,
QW_IDS
()
));
}
else
if
(
task
->
status
==
JOB_TASK_STATUS_CANCELLING
||
task
->
status
==
JOB_TASK_STATUS_DROPPING
||
task
->
status
==
JOB_TASK_STATUS_NOT_START
)
{
}
else
if
(
task
->
status
==
JOB_TASK_STATUS_CANCELLING
||
task
->
status
==
JOB_TASK_STATUS_DROPPING
||
task
->
status
==
JOB_TASK_STATUS_NOT_START
)
{
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
qwReleaseTask
(
QW_READ
,
sch
);
qwReleaseTask
(
QW_READ
,
sch
);
...
@@ -512,7 +539,7 @@ int32_t qwCancelDropTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uin
...
@@ -512,7 +539,7 @@ int32_t qwCancelDropTask(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uin
qwReleaseTask
(
QW_READ
,
sch
);
qwReleaseTask
(
QW_READ
,
sch
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
QW_ERR_RET
(
qwDropTask
(
mgmt
,
sId
,
q
ueryId
,
task
Id
));
QW_ERR_RET
(
qwDropTask
(
mgmt
,
sId
,
q
Id
,
t
Id
));
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -743,7 +770,7 @@ int32_t qwCheckAndSendReadyRsp(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryI
...
@@ -743,7 +770,7 @@ int32_t qwCheckAndSendReadyRsp(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryI
SQWTaskStatus
*
task
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
QW_ERR_RET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_RET_ERR
));
QW_ERR_RET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
));
QW_ERR_JRET
(
qwAcquireTask
(
QW_READ
,
sch
,
queryId
,
taskId
,
&
task
));
QW_ERR_JRET
(
qwAcquireTask
(
QW_READ
,
sch
,
queryId
,
taskId
,
&
task
));
...
@@ -785,7 +812,7 @@ int32_t qwSetAndSendReadyRsp(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId,
...
@@ -785,7 +812,7 @@ int32_t qwSetAndSendReadyRsp(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId,
SQWTaskStatus
*
task
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
QW_ERR_RET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_RET_ERR
));
QW_ERR_RET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
));
QW_ERR_JRET
(
qwAcquireTask
(
QW_READ
,
sch
,
queryId
,
taskId
,
&
task
));
QW_ERR_JRET
(
qwAcquireTask
(
QW_READ
,
sch
,
queryId
,
taskId
,
&
task
));
...
@@ -816,7 +843,7 @@ _return:
...
@@ -816,7 +843,7 @@ _return:
QW_RET
(
code
);
QW_RET
(
code
);
}
}
int32_t
qwCheckTaskCancelDrop
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
queryId
,
uint64_t
task
Id
,
bool
*
needStop
)
{
int32_t
qwCheckTaskCancelDrop
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
qId
,
uint64_t
t
Id
,
bool
*
needStop
)
{
SQWSchStatus
*
sch
=
NULL
;
SQWSchStatus
*
sch
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
SQWTaskStatus
*
task
=
NULL
;
int32_t
code
=
0
;
int32_t
code
=
0
;
...
@@ -824,11 +851,11 @@ int32_t qwCheckTaskCancelDrop( SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryI
...
@@ -824,11 +851,11 @@ int32_t qwCheckTaskCancelDrop( SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryI
*
needStop
=
false
;
*
needStop
=
false
;
if
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_RET_ERR
))
{
if
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
))
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
qwAcquireTask
(
QW_READ
,
sch
,
q
ueryId
,
task
Id
,
&
task
))
{
if
(
qwAcquireTask
(
QW_READ
,
sch
,
q
Id
,
t
Id
,
&
task
))
{
qwReleaseScheduler
(
QW_READ
,
mgmt
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -836,9 +863,10 @@ int32_t qwCheckTaskCancelDrop( SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryI
...
@@ -836,9 +863,10 @@ int32_t qwCheckTaskCancelDrop( SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryI
QW_LOCK
(
QW_READ
,
&
task
->
lock
);
QW_LOCK
(
QW_READ
,
&
task
->
lock
);
if
((
!
task
->
cancel
)
&&
(
!
task
->
drop
))
{
if
((
!
task
->
cancel
)
&&
(
!
task
->
drop
))
{
qError
(
"no cancel or drop, but task:%"
PRIx64
" exists"
,
taskId
);
QW_TASK_ELOG
(
"no cancel or drop but task exists, status:%d"
,
task
->
status
);
QW_UNLOCK
(
QW_READ
,
&
task
->
lock
);
QW_UNLOCK
(
QW_READ
,
&
task
->
lock
);
qwReleaseTask
(
QW_READ
,
sch
);
qwReleaseTask
(
QW_READ
,
sch
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
...
@@ -851,17 +879,21 @@ int32_t qwCheckTaskCancelDrop( SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryI
...
@@ -851,17 +879,21 @@ int32_t qwCheckTaskCancelDrop( SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryI
if
(
task
->
cancel
)
{
if
(
task
->
cancel
)
{
QW_LOCK
(
QW_WRITE
,
&
task
->
lock
);
QW_LOCK
(
QW_WRITE
,
&
task
->
lock
);
qwUpdateTaskInfo
(
task
,
QW_TASK_INFO_STATUS
,
&
status
);
code
=
qwUpdateTaskInfo
(
mgmt
,
task
,
QW_TASK_INFO_STATUS
,
&
status
,
QW_IDS
()
);
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
QW_ERR_JRET
(
code
);
}
}
if
(
task
->
drop
)
{
if
(
task
->
drop
)
{
qwReleaseTask
(
QW_READ
,
sch
);
qwReleaseTask
(
QW_READ
,
sch
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
return
qwDropTask
(
mgmt
,
sId
,
queryId
,
taskId
);
QW_RET
(
qwDropTask
(
mgmt
,
sId
,
qId
,
tId
)
);
}
}
_return:
qwReleaseTask
(
QW_READ
,
sch
);
qwReleaseTask
(
QW_READ
,
sch
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
qwReleaseScheduler
(
QW_READ
,
mgmt
);
...
@@ -875,7 +907,7 @@ int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint6
...
@@ -875,7 +907,7 @@ int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint6
int32_t
code
=
0
;
int32_t
code
=
0
;
int8_t
newStatus
=
JOB_TASK_STATUS_CANCELLED
;
int8_t
newStatus
=
JOB_TASK_STATUS_CANCELLED
;
code
=
qwA
cquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_ADD
);
code
=
qwA
ddAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
);
if
(
code
)
{
if
(
code
)
{
qError
(
"sId:%"
PRIx64
" not in cache"
,
sId
);
qError
(
"sId:%"
PRIx64
" not in cache"
,
sId
);
QW_ERR_RET
(
code
);
QW_ERR_RET
(
code
);
...
@@ -895,7 +927,7 @@ int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint6
...
@@ -895,7 +927,7 @@ int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint6
if
(
task
->
cancel
)
{
if
(
task
->
cancel
)
{
QW_LOCK
(
QW_WRITE
,
&
task
->
lock
);
QW_LOCK
(
QW_WRITE
,
&
task
->
lock
);
qwUpdateTaskInfo
(
task
,
QW_TASK_INFO_STATUS
,
&
newStatus
);
qwUpdateTaskInfo
(
mgmt
,
task
,
QW_TASK_INFO_STATUS
,
&
newStatus
,
QW_IDS
()
);
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
}
}
...
@@ -910,7 +942,7 @@ int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint6
...
@@ -910,7 +942,7 @@ int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint6
if
(
!
(
task
->
cancel
||
task
->
drop
))
{
if
(
!
(
task
->
cancel
||
task
->
drop
))
{
QW_LOCK
(
QW_WRITE
,
&
task
->
lock
);
QW_LOCK
(
QW_WRITE
,
&
task
->
lock
);
qwUpdateTaskInfo
(
task
,
QW_TASK_INFO_STATUS
,
&
status
);
qwUpdateTaskInfo
(
mgmt
,
task
,
QW_TASK_INFO_STATUS
,
&
status
,
QW_IDS
()
);
task
->
code
=
errCode
;
task
->
code
=
errCode
;
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
QW_UNLOCK
(
QW_WRITE
,
&
task
->
lock
);
}
}
...
@@ -921,6 +953,86 @@ int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint6
...
@@ -921,6 +953,86 @@ int32_t qwQueryPostProcess(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t qId, uint6
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
qwScheduleDataSink
(
SQWTaskCtx
*
handles
,
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
queryId
,
uint64_t
taskId
,
SRpcMsg
*
pMsg
)
{
if
(
atomic_load_8
(
&
handles
->
sinkScheduled
))
{
qDebug
(
"data sink already scheduled"
);
return
TSDB_CODE_SUCCESS
;
}
SSinkDataReq
*
req
=
(
SSinkDataReq
*
)
rpcMallocCont
(
sizeof
(
SSinkDataReq
));
if
(
NULL
==
req
)
{
qError
(
"rpcMallocCont %d failed"
,
(
int32_t
)
sizeof
(
SSinkDataReq
));
QW_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
req
->
header
.
vgId
=
mgmt
->
nodeId
;
req
->
sId
=
sId
;
req
->
queryId
=
queryId
;
req
->
taskId
=
taskId
;
SRpcMsg
pNewMsg
=
{
.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
msgType
=
TDMT_VND_SCHEDULE_DATA_SINK
,
.
pCont
=
req
,
.
contLen
=
sizeof
(
SSinkDataReq
),
.
code
=
0
,
};
int32_t
code
=
(
*
mgmt
->
putToQueueFp
)(
mgmt
->
nodeObj
,
&
pNewMsg
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
qError
(
"put data sink schedule msg to queue failed, code:%x"
,
code
);
rpcFreeCont
(
req
);
QW_ERR_RET
(
code
);
}
qDebug
(
"put data sink schedule msg to query queue"
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwScheduleQuery
(
SQWTaskCtx
*
handles
,
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
queryId
,
uint64_t
taskId
,
SRpcMsg
*
pMsg
)
{
if
(
atomic_load_8
(
&
handles
->
queryScheduled
))
{
qDebug
(
"query already scheduled"
);
return
TSDB_CODE_SUCCESS
;
}
QW_ERR_RET
(
qwUpdateTaskStatus
(
mgmt
,
sId
,
queryId
,
taskId
,
JOB_TASK_STATUS_EXECUTING
));
SQueryContinueReq
*
req
=
(
SQueryContinueReq
*
)
rpcMallocCont
(
sizeof
(
SQueryContinueReq
));
if
(
NULL
==
req
)
{
qError
(
"rpcMallocCont %d failed"
,
(
int32_t
)
sizeof
(
SQueryContinueReq
));
QW_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
req
->
header
.
vgId
=
mgmt
->
nodeId
;
req
->
sId
=
sId
;
req
->
queryId
=
queryId
;
req
->
taskId
=
taskId
;
SRpcMsg
pNewMsg
=
{
.
handle
=
pMsg
->
handle
,
.
ahandle
=
pMsg
->
ahandle
,
.
msgType
=
TDMT_VND_QUERY_CONTINUE
,
.
pCont
=
req
,
.
contLen
=
sizeof
(
SQueryContinueReq
),
.
code
=
0
,
};
int32_t
code
=
(
*
mgmt
->
putToQueueFp
)(
mgmt
->
nodeObj
,
&
pNewMsg
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
qError
(
"put query continue msg to queue failed, code:%x"
,
code
);
rpcFreeCont
(
req
);
QW_ERR_RET
(
code
);
}
qDebug
(
"put query continue msg to query queue"
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
qwHandleFetch
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
queryId
,
uint64_t
taskId
,
SRpcMsg
*
pMsg
)
{
int32_t
qwHandleFetch
(
SQWorkerMgmt
*
mgmt
,
uint64_t
sId
,
uint64_t
queryId
,
uint64_t
taskId
,
SRpcMsg
*
pMsg
)
{
SQWSchStatus
*
sch
=
NULL
;
SQWSchStatus
*
sch
=
NULL
;
...
@@ -932,11 +1044,15 @@ int32_t qwHandleFetch(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64
...
@@ -932,11 +1044,15 @@ int32_t qwHandleFetch(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64
int32_t
dataLength
=
0
;
int32_t
dataLength
=
0
;
SRetrieveTableRsp
*
rsp
=
NULL
;
SRetrieveTableRsp
*
rsp
=
NULL
;
bool
queryEnd
=
false
;
bool
queryEnd
=
false
;
SQW
orkerTaskHandlesCache
*
handles
=
NULL
;
SQW
TaskCtx
*
handles
=
NULL
;
QW_ERR_JRET
(
qwAcquireTaskHandles
(
QW_READ
,
mgmt
,
queryId
,
taskId
,
&
handles
));
QW_ERR_JRET
(
qwAcquireTaskCtx
(
QW_READ
,
mgmt
,
queryId
,
taskId
,
&
handles
));
if
(
atomic_load_8
(
&
handles
->
needRsp
))
{
qError
(
"last fetch not responsed"
);
QW_ERR_JRET
(
TSDB_CODE_QRY_APP_ERROR
);
}
QW_ERR_JRET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
,
QW_NOT_EXIST_RET_ERR
));
QW_ERR_JRET
(
qwAcquireScheduler
(
QW_READ
,
mgmt
,
sId
,
&
sch
));
QW_ERR_JRET
(
qwAcquireTask
(
QW_READ
,
sch
,
queryId
,
taskId
,
&
task
));
QW_ERR_JRET
(
qwAcquireTask
(
QW_READ
,
sch
,
queryId
,
taskId
,
&
task
));
QW_LOCK
(
QW_READ
,
&
task
->
lock
);
QW_LOCK
(
QW_READ
,
&
task
->
lock
);
...
@@ -974,15 +1090,15 @@ int32_t qwHandleFetch(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64
...
@@ -974,15 +1090,15 @@ int32_t qwHandleFetch(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64
if
(
DS_BUF_EMPTY
==
output
.
bufStatus
&&
output
.
queryEnd
)
{
if
(
DS_BUF_EMPTY
==
output
.
bufStatus
&&
output
.
queryEnd
)
{
rsp
->
completed
=
1
;
rsp
->
completed
=
1
;
}
if
(
output
.
needSchedule
)
{
QW_ERR_JRET
(
qwUpdateTaskStatus
(
mgmt
,
sId
,
queryId
,
taskId
,
JOB_TASK_STATUS_SUCCEED
));
//TODO
}
}
if
((
!
output
.
queryEnd
)
&&
DS_BUF_LOW
==
output
.
bufStatus
)
{
// Note: schedule data sink firstly and will schedule query after it's done
//TODO
if
(
output
.
needSchedule
)
{
//UPDATE STATUS TO EXECUTING
QW_ERR_JRET
(
qwScheduleDataSink
(
handles
,
mgmt
,
sId
,
queryId
,
taskId
,
pMsg
));
}
else
if
((
!
output
.
queryEnd
)
&&
(
DS_BUF_LOW
==
output
.
bufStatus
||
DS_BUF_EMPTY
==
output
.
bufStatus
))
{
QW_ERR_JRET
(
qwScheduleQuery
(
handles
,
mgmt
,
sId
,
queryId
,
taskId
,
pMsg
));
}
}
}
else
{
}
else
{
if
(
dataLength
<
0
)
{
if
(
dataLength
<
0
)
{
...
@@ -991,12 +1107,11 @@ int32_t qwHandleFetch(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64
...
@@ -991,12 +1107,11 @@ int32_t qwHandleFetch(SQWorkerMgmt *mgmt, uint64_t sId, uint64_t queryId, uint64
}
}
if
(
queryEnd
)
{
if
(
queryEnd
)
{
QW_ERR_JRET
(
qw
QueryPostProcess
(
mgmt
,
sId
,
queryId
,
taskId
,
JOB_TASK_STATUS_SUCCEED
,
code
));
QW_ERR_JRET
(
qw
UpdateTaskStatus
(
mgmt
,
sId
,
queryId
,
taskId
,
JOB_TASK_STATUS_SUCCEED
));
}
else
{
}
else
{
if
(
task
->
status
!=
JOB_TASK_STATUS_EXECUTING
)
{
assert
(
0
==
handles
->
needRsp
);
qError
(
"invalid status %d for fetch without res"
,
task
->
status
);
QW_ERR_JRET
(
TSDB_CODE_QRY_APP_ERROR
);
qDebug
(
"no res data in sink, need response later"
);
}
QW_LOCK
(
QW_WRITE
,
&
handles
->
lock
);
QW_LOCK
(
QW_WRITE
,
&
handles
->
lock
);
handles
->
needRsp
=
true
;
handles
->
needRsp
=
true
;
...
@@ -1028,7 +1143,12 @@ _return:
...
@@ -1028,7 +1143,12 @@ _return:
QW_RET
(
code
);
QW_RET
(
code
);
}
}
int32_t
qWorkerInit
(
SQWorkerCfg
*
cfg
,
void
**
qWorkerMgmt
)
{
int32_t
qWorkerInit
(
int8_t
nodeType
,
int32_t
nodeId
,
SQWorkerCfg
*
cfg
,
void
**
qWorkerMgmt
,
void
*
nodeObj
,
putReqToQueryQFp
fp
)
{
if
(
NULL
==
qWorkerMgmt
||
NULL
==
nodeObj
||
NULL
==
fp
)
{
qError
(
"invalid param to init qworker"
);
QW_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
SQWorkerMgmt
*
mgmt
=
calloc
(
1
,
sizeof
(
SQWorkerMgmt
));
SQWorkerMgmt
*
mgmt
=
calloc
(
1
,
sizeof
(
SQWorkerMgmt
));
if
(
NULL
==
mgmt
)
{
if
(
NULL
==
mgmt
)
{
qError
(
"calloc %d failed"
,
(
int32_t
)
sizeof
(
SQWorkerMgmt
));
qError
(
"calloc %d failed"
,
(
int32_t
)
sizeof
(
SQWorkerMgmt
));
...
@@ -1037,29 +1157,46 @@ int32_t qWorkerInit(SQWorkerCfg *cfg, void **qWorkerMgmt) {
...
@@ -1037,29 +1157,46 @@ int32_t qWorkerInit(SQWorkerCfg *cfg, void **qWorkerMgmt) {
if
(
cfg
)
{
if
(
cfg
)
{
mgmt
->
cfg
=
*
cfg
;
mgmt
->
cfg
=
*
cfg
;
if
(
0
==
mgmt
->
cfg
.
maxSchedulerNum
)
{
mgmt
->
cfg
.
maxSchedulerNum
=
QWORKER_DEFAULT_SCHEDULER_NUMBER
;
}
if
(
0
==
mgmt
->
cfg
.
maxTaskNum
)
{
mgmt
->
cfg
.
maxTaskNum
=
QWORKER_DEFAULT_TASK_NUMBER
;
}
if
(
0
==
mgmt
->
cfg
.
maxSchTaskNum
)
{
mgmt
->
cfg
.
maxSchTaskNum
=
QWORKER_DEFAULT_SCH_TASK_NUMBER
;
}
}
else
{
}
else
{
mgmt
->
cfg
.
maxSchedulerNum
=
QWORKER_DEFAULT_SCHEDULER_NUMBER
;
mgmt
->
cfg
.
maxSchedulerNum
=
QWORKER_DEFAULT_SCHEDULER_NUMBER
;
mgmt
->
cfg
.
max
ResCacheNum
=
QWORKER_DEFAULT_RES_CACHE
_NUMBER
;
mgmt
->
cfg
.
max
TaskNum
=
QWORKER_DEFAULT_TASK
_NUMBER
;
mgmt
->
cfg
.
maxSchTaskNum
=
QWORKER_DEFAULT_SCH_TASK_NUMBER
;
mgmt
->
cfg
.
maxSchTaskNum
=
QWORKER_DEFAULT_SCH_TASK_NUMBER
;
}
}
mgmt
->
schHash
=
taosHashInit
(
mgmt
->
cfg
.
maxSchedulerNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
false
,
HASH_NO_LOCK
);
mgmt
->
schHash
=
taosHashInit
(
mgmt
->
cfg
.
maxSchedulerNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_UBIGINT
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
mgmt
->
schHash
)
{
if
(
NULL
==
mgmt
->
schHash
)
{
tfree
(
mgmt
);
tfree
(
mgmt
);
QW_ERR_LRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
,
"init %d schduler hash failed"
,
mgmt
->
cfg
.
maxSchedulerNum
);
qError
(
"init %d scheduler hash failed"
,
mgmt
->
cfg
.
maxSchedulerNum
);
QW_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
mgmt
->
resHash
=
taosHashInit
(
mgmt
->
cfg
.
maxResCache
Num
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
mgmt
->
ctxHash
=
taosHashInit
(
mgmt
->
cfg
.
maxTask
Num
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
mgmt
->
res
Hash
)
{
if
(
NULL
==
mgmt
->
ctx
Hash
)
{
taosHashCleanup
(
mgmt
->
schHash
);
taosHashCleanup
(
mgmt
->
schHash
);
mgmt
->
schHash
=
NULL
;
mgmt
->
schHash
=
NULL
;
tfree
(
mgmt
);
tfree
(
mgmt
);
qError
(
"init %d task ctx hash failed"
,
mgmt
->
cfg
.
maxTaskNum
);
QW_ERR_
LRET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
,
"init %d res cache hash failed"
,
mgmt
->
cfg
.
maxResCacheNum
);
QW_ERR_
RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
mgmt
->
nodeType
=
nodeType
;
mgmt
->
nodeId
=
nodeId
;
mgmt
->
nodeObj
=
nodeObj
;
mgmt
->
putToQueueFp
=
fp
;
*
qWorkerMgmt
=
mgmt
;
*
qWorkerMgmt
=
mgmt
;
qDebug
(
"qworker initialized for node, type:%d, id:%d, handle:%p"
,
mgmt
->
nodeType
,
mgmt
->
nodeId
,
mgmt
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -1069,25 +1206,31 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
...
@@ -1069,25 +1206,31 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
}
}
int32_t
code
=
0
;
int32_t
code
=
0
;
bool
queryRsped
=
false
;
bool
needStop
=
false
;
struct
SSubplan
*
plan
=
NULL
;
SSubQueryMsg
*
msg
=
pMsg
->
pCont
;
SSubQueryMsg
*
msg
=
pMsg
->
pCont
;
SQWorkerMgmt
*
mgmt
=
(
SQWorkerMgmt
*
)
qWorkerMgmt
;
if
(
NULL
==
msg
||
pMsg
->
contLen
<=
sizeof
(
*
msg
))
{
if
(
NULL
==
msg
||
pMsg
->
contLen
<=
sizeof
(
*
msg
))
{
qError
(
"invalid query msg"
);
QW_ELOG
(
"invalid query msg, contLen:%d"
,
pMsg
->
contLen
);
QW_ERR_JRET
(
TSDB_CODE_QRY_INVALID_INPUT
);
QW_ERR_JRET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
}
msg
->
sId
=
htobe64
(
msg
->
sId
);
msg
->
sId
=
be64toh
(
msg
->
sId
);
msg
->
queryId
=
htobe64
(
msg
->
queryId
);
msg
->
queryId
=
be64toh
(
msg
->
queryId
);
msg
->
taskId
=
htobe64
(
msg
->
taskId
);
msg
->
taskId
=
be64toh
(
msg
->
taskId
);
msg
->
contentLen
=
ntohl
(
msg
->
contentLen
);
msg
->
contentLen
=
ntohl
(
msg
->
contentLen
);
bool
queryRsped
=
false
;
uint64_t
sId
=
msg
->
sId
;
bool
needStop
=
false
;
uint64_t
qId
=
msg
->
queryId
;
struct
SSubplan
*
plan
=
NULL
;
uint64_t
tId
=
msg
->
taskId
;
QW_ERR_JRET
(
qwCheckTaskCancelDrop
(
qWorkerMgmt
,
msg
->
sId
,
msg
->
queryId
,
msg
->
taskId
,
&
needStop
));
QW_ERR_JRET
(
qwCheckTaskCancelDrop
(
qWorkerMgmt
,
msg
->
sId
,
msg
->
queryId
,
msg
->
taskId
,
&
needStop
));
if
(
needStop
)
{
if
(
needStop
)
{
qWarn
(
"task need stop"
);
qWarn
(
"task need stop"
);
QW_ERR_JRET
(
TSDB_CODE_QRY_TASK_CANCELLED
);
qwBuildAndSendQueryRsp
(
pMsg
,
TSDB_CODE_QRY_TASK_CANCELLED
);
QW_ERR_RET
(
TSDB_CODE_QRY_TASK_CANCELLED
);
}
}
code
=
qStringToSubplan
(
msg
->
msg
,
&
plan
);
code
=
qStringToSubplan
(
msg
->
msg
,
&
plan
);
...
@@ -1144,30 +1287,59 @@ int32_t qWorkerProcessQueryContinueMsg(void *node, void *qWorkerMgmt, SRpcMsg *p
...
@@ -1144,30 +1287,59 @@ int32_t qWorkerProcessQueryContinueMsg(void *node, void *qWorkerMgmt, SRpcMsg *p
int32_t
code
=
0
;
int32_t
code
=
0
;
int8_t
status
=
0
;
int8_t
status
=
0
;
bool
queryDone
=
false
;
bool
queryDone
=
false
;
uint64_t
sId
,
qId
,
tId
;
SQueryContinueReq
*
req
=
(
SQueryContinueReq
*
)
pMsg
->
pCont
;
bool
needStop
=
false
;
SQWTaskCtx
*
handles
=
NULL
;
//TODO call executer to continue execute subquery
QW_ERR_JRET
(
qwAcquireTaskCtx
(
QW_READ
,
qWorkerMgmt
,
req
->
queryId
,
req
->
taskId
,
&
handles
));
code
=
0
;
void
*
data
=
NULL
;
qTaskInfo_t
taskHandle
=
handles
->
taskHandle
;
queryDone
=
false
;
DataSinkHandle
sinkHandle
=
handles
->
sinkHandle
;
//TODO call executer to continue execute subquery
bool
needRsp
=
handles
->
needRsp
;
qwReleaseTaskResCache
(
QW_READ
,
qWorkerMgmt
);
QW_ERR_JRET
(
qwCheckTaskCancelDrop
(
qWorkerMgmt
,
req
->
sId
,
req
->
queryId
,
req
->
taskId
,
&
needStop
));
if
(
needStop
)
{
qWarn
(
"task need stop"
);
if
(
needRsp
)
{
qwBuildAndSendQueryRsp
(
pMsg
,
TSDB_CODE_QRY_TASK_CANCELLED
);
}
QW_ERR_RET
(
TSDB_CODE_QRY_TASK_CANCELLED
);
}
DataSinkHandle
newHandle
=
NULL
;
code
=
qExecTask
(
taskHandle
,
&
newHandle
);
if
(
code
)
{
qError
(
"qExecTask failed, code:%x"
,
code
);
QW_ERR_JRET
(
code
);
}
if
(
sinkHandle
!=
newHandle
)
{
qError
(
"data sink mis-match"
);
QW_ERR_JRET
(
TSDB_CODE_QRY_APP_ERROR
);
}
_return:
if
(
needRsp
)
{
code
=
qwBuildAndSendQueryRsp
(
pMsg
,
code
);
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
status
=
JOB_TASK_STATUS_FAILED
;
status
=
JOB_TASK_STATUS_FAILED
;
}
else
if
(
queryDone
)
{
status
=
JOB_TASK_STATUS_SUCCEED
;
}
else
{
}
else
{
status
=
JOB_TASK_STATUS_PARTIAL_SUCCEED
;
status
=
JOB_TASK_STATUS_PARTIAL_SUCCEED
;
}
}
code
=
qwQueryPostProcess
(
qWorkerMgmt
,
sId
,
qId
,
t
Id
,
status
,
code
);
code
=
qwQueryPostProcess
(
qWorkerMgmt
,
req
->
sId
,
req
->
queryId
,
req
->
task
Id
,
status
,
code
);
QW_RET
(
code
);
QW_RET
(
code
);
}
}
int32_t
qWorkerProcess
SinkData
Msg
(
void
*
node
,
void
*
qWorkerMgmt
,
SRpcMsg
*
pMsg
){
int32_t
qWorkerProcess
DataSink
Msg
(
void
*
node
,
void
*
qWorkerMgmt
,
SRpcMsg
*
pMsg
){
if
(
NULL
==
node
||
NULL
==
qWorkerMgmt
||
NULL
==
pMsg
)
{
if
(
NULL
==
node
||
NULL
==
qWorkerMgmt
||
NULL
==
pMsg
)
{
return
TSDB_CODE_QRY_INVALID_INPUT
;
return
TSDB_CODE_QRY_INVALID_INPUT
;
}
}
...
@@ -1178,6 +1350,7 @@ int32_t qWorkerProcessSinkDataMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg){
...
@@ -1178,6 +1350,7 @@ int32_t qWorkerProcessSinkDataMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg){
QW_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
QW_ERR_RET
(
TSDB_CODE_QRY_INVALID_INPUT
);
}
}
//dsScheduleProcess();
//TODO
//TODO
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/qworker/test/qworkerTests.cpp
浏览文件 @
5cf4edac
...
@@ -42,6 +42,11 @@ int32_t qwtStringToPlan(const char* str, SSubplan** subplan) {
...
@@ -42,6 +42,11 @@ int32_t qwtStringToPlan(const char* str, SSubplan** subplan) {
return
0
;
return
0
;
}
}
int32_t
qwtPutReqToQueue
(
void
*
node
,
struct
SRpcMsg
*
pMsg
)
{
return
0
;
}
void
qwtRpcSendResponse
(
const
SRpcMsg
*
pRsp
)
{
void
qwtRpcSendResponse
(
const
SRpcMsg
*
pRsp
)
{
if
(
TDMT_VND_TASKS_STATUS_RSP
==
pRsp
->
msgType
)
{
if
(
TDMT_VND_TASKS_STATUS_RSP
==
pRsp
->
msgType
)
{
SSchedulerStatusRsp
*
rsp
=
(
SSchedulerStatusRsp
*
)
pRsp
->
pCont
;
SSchedulerStatusRsp
*
rsp
=
(
SSchedulerStatusRsp
*
)
pRsp
->
pCont
;
...
@@ -258,7 +263,7 @@ TEST(seqTest, normalCase) {
...
@@ -258,7 +263,7 @@ TEST(seqTest, normalCase) {
stubSetStringToPlan
();
stubSetStringToPlan
();
stubSetRpcSendResponse
();
stubSetRpcSendResponse
();
code
=
qWorkerInit
(
N
ULL
,
&
mgmt
);
code
=
qWorkerInit
(
N
ODE_TYPE_VNODE
,
1
,
NULL
,
&
mgmt
,
mockPointer
,
qwtPutReqToQueue
);
ASSERT_EQ
(
code
,
0
);
ASSERT_EQ
(
code
,
0
);
statusMsg
.
sId
=
htobe64
(
1
);
statusMsg
.
sId
=
htobe64
(
1
);
...
@@ -328,7 +333,7 @@ TEST(seqTest, cancelFirst) {
...
@@ -328,7 +333,7 @@ TEST(seqTest, cancelFirst) {
stubSetStringToPlan
();
stubSetStringToPlan
();
stubSetRpcSendResponse
();
stubSetRpcSendResponse
();
code
=
qWorkerInit
(
N
ULL
,
&
mgmt
);
code
=
qWorkerInit
(
N
ODE_TYPE_VNODE
,
1
,
NULL
,
&
mgmt
,
mockPointer
,
qwtPutReqToQueue
);
ASSERT_EQ
(
code
,
0
);
ASSERT_EQ
(
code
,
0
);
statusMsg
.
sId
=
htobe64
(
1
);
statusMsg
.
sId
=
htobe64
(
1
);
...
@@ -402,7 +407,7 @@ TEST(seqTest, randCase) {
...
@@ -402,7 +407,7 @@ TEST(seqTest, randCase) {
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
code
=
qWorkerInit
(
N
ULL
,
&
mgmt
);
code
=
qWorkerInit
(
N
ODE_TYPE_VNODE
,
1
,
NULL
,
&
mgmt
,
mockPointer
,
qwtPutReqToQueue
);
ASSERT_EQ
(
code
,
0
);
ASSERT_EQ
(
code
,
0
);
int32_t
t
=
0
;
int32_t
t
=
0
;
...
@@ -446,7 +451,7 @@ TEST(seqTest, multithreadRand) {
...
@@ -446,7 +451,7 @@ TEST(seqTest, multithreadRand) {
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
code
=
qWorkerInit
(
N
ULL
,
&
mgmt
);
code
=
qWorkerInit
(
N
ODE_TYPE_VNODE
,
1
,
NULL
,
&
mgmt
,
mockPointer
,
qwtPutReqToQueue
);
ASSERT_EQ
(
code
,
0
);
ASSERT_EQ
(
code
,
0
);
pthread_attr_t
thattr
;
pthread_attr_t
thattr
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录