TDengine/source/libs/scheduler/test/schedulerTests.cpp

1784 lines
47 KiB
C++
Raw Normal View History

2021-12-20 05:24:30 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include <iostream>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wformat"
#include <addr_any.h>
2022-04-22 01:54:27 +00:00
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
2021-12-20 05:24:30 +00:00
#include "os.h"
2021-12-24 11:01:48 +00:00
#include "catalog.h"
#include "scheduler.h"
2022-03-04 05:25:39 +00:00
#include "taos.h"
#include "tdatablock.h"
#include "tdef.h"
2022-10-13 08:58:43 +00:00
#include "tglobal.h"
2024-07-08 01:37:47 +00:00
#include "tmisce.h"
2021-12-20 05:24:30 +00:00
#include "trpc.h"
2022-03-04 05:25:39 +00:00
#include "tvariant.h"
2022-01-21 10:19:40 +00:00
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wreturn-type"
#pragma GCC diagnostic ignored "-Wformat"
2022-07-05 10:12:01 +00:00
#include "schInt.h"
2021-12-25 13:29:42 +00:00
#include "stub.h"
2022-03-03 07:07:33 +00:00
#include "tref.h"
2022-01-18 06:12:25 +00:00
2021-12-20 05:24:30 +00:00
namespace {
2021-12-25 13:29:42 +00:00
2024-12-10 09:27:02 +00:00
extern "C" int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, uint64_t sId, int32_t execId, SDataBuf *pMsg,
2024-07-08 01:37:47 +00:00
int32_t rspCode);
2024-02-02 08:05:25 +00:00
extern "C" int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t rspCode);
2024-12-20 05:52:53 +00:00
extern "C" int32_t schHandleNotifyCallback(void *param, SDataBuf *pMsg, int32_t code);
extern "C" int32_t schHandleLinkBrokenCallback(void *param, SDataBuf *pMsg, int32_t code);
extern "C" int32_t schRescheduleTask(SSchJob *pJob, SSchTask *pTask);
2024-12-23 08:07:47 +00:00
extern "C" int32_t schValidateRspMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgType);
2024-12-25 03:44:20 +00:00
//extern "C" int32_t schProcessFetchRsp(SSchJob *pJob, SSchTask *pTask, char *msg, int32_t rspCode);
2024-12-23 08:07:47 +00:00
extern "C" int32_t schProcessResponseMsg(SSchJob *pJob, SSchTask *pTask, SDataBuf *pMsg, int32_t rspCode);
2024-12-25 01:59:26 +00:00
extern "C" void schInitTaskRetryTimes(SSchJob *pJob, SSchTask *pTask, SSchLevel *pLevel);
extern "C" int32_t schRecordTaskSucceedNode(SSchJob *pJob, SSchTask *pTask);
extern "C" int32_t schDropTaskExecNode(SSchJob *pJob, SSchTask *pTask, void *handle, int32_t execId);
extern "C" int32_t schPushTaskToExecList(SSchJob *pJob, SSchTask *pTask);
extern "C" int32_t schSetAddrsFromNodeList(SSchJob *pJob, SSchTask *pTask);
extern "C" int32_t schNotifyTaskOnExecNode(SSchJob *pJob, SSchTask *pTask, ETaskNotifyType type);
extern "C" int32_t schLaunchRemoteTask(SSchJob *pJob, SSchTask *pTask);
extern "C" int32_t schLaunchTaskImpl(void *param);
extern "C" void schHandleTimerEvent(void *param, void *tmrId);
2024-12-23 08:07:47 +00:00
2022-01-18 11:32:29 +00:00
2022-03-03 07:07:33 +00:00
int64_t insertJobRefId = 0;
int64_t queryJobRefId = 0;
2022-01-18 11:32:29 +00:00
2024-02-20 09:06:41 +00:00
bool schtJobDone = false;
2022-01-18 11:32:29 +00:00
uint64_t schtMergeTemplateId = 0x4;
uint64_t schtFetchTaskId = 0;
uint64_t schtQueryId = 1;
2022-10-13 08:58:43 +00:00
bool schtTestStop = false;
bool schtTestDeadLoop = false;
2024-02-19 05:29:06 +00:00
int32_t schtTestMTRunSec = 1;
2022-01-18 11:32:29 +00:00
int32_t schtTestPrintNum = 1000;
int32_t schtStartFetch = 0;
2021-12-25 13:29:42 +00:00
2022-01-11 02:14:06 +00:00
void schtInitLogFile() {
2022-10-13 08:58:43 +00:00
const char *defaultLogFileNamePrefix = "taoslog";
const int32_t maxLogFileNum = 10;
2022-01-11 02:14:06 +00:00
tsAsyncLog = 0;
qDebugFlag = 159;
TAOS_STRCPY(tsLogDir, TD_LOG_DIR_PATH);
2022-01-11 02:14:06 +00:00
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum, false) < 0) {
(void)printf("failed to open log file in directory:%s\n", tsLogDir);
2022-01-11 02:14:06 +00:00
}
}
2024-07-08 01:37:47 +00:00
void schtQueryCb(SExecResult *pResult, void *param, int32_t code) { *(int32_t *)param = 1; }
2022-05-24 09:49:22 +00:00
2024-07-08 01:37:47 +00:00
int32_t schtBuildQueryRspMsg(uint32_t *msize, void **rspMsg) {
SQueryTableRsp rsp = {0};
2024-02-02 08:05:25 +00:00
rsp.code = 0;
rsp.affectedRows = 0;
rsp.tbVerInfo = NULL;
int32_t msgSize = tSerializeSQueryTableRsp(NULL, 0, &rsp);
if (msgSize < 0) {
qError("tSerializeSQueryTableRsp failed");
return TSDB_CODE_OUT_OF_MEMORY;
}
2024-07-08 01:37:47 +00:00
2024-02-02 08:05:25 +00:00
void *pRsp = taosMemoryCalloc(msgSize, 1);
if (NULL == pRsp) {
qError("rpcMallocCont %d failed", msgSize);
return TSDB_CODE_OUT_OF_MEMORY;
}
if (tSerializeSQueryTableRsp(pRsp, msgSize, &rsp) < 0) {
qError("tSerializeSQueryTableRsp %d failed", msgSize);
return TSDB_CODE_OUT_OF_MEMORY;
}
*rspMsg = pRsp;
*msize = msgSize;
return TSDB_CODE_SUCCESS;
}
2024-07-08 01:37:47 +00:00
int32_t schtBuildFetchRspMsg(uint32_t *msize, void **rspMsg) {
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(sizeof(SRetrieveTableRsp), 1);
2024-02-02 08:05:25 +00:00
rsp->completed = 1;
rsp->numOfRows = 10;
rsp->compLen = 0;
*rspMsg = rsp;
*msize = sizeof(SRetrieveTableRsp);
return TSDB_CODE_SUCCESS;
}
2024-07-08 01:37:47 +00:00
int32_t schtBuildSubmitRspMsg(uint32_t *msize, void **rspMsg) {
2024-02-02 08:05:25 +00:00
SSubmitRsp2 submitRsp = {0};
2024-07-08 01:37:47 +00:00
int32_t msgSize = 0, ret = 0;
SEncoder ec = {0};
2024-02-02 08:05:25 +00:00
tEncodeSize(tEncodeSSubmitRsp2, &submitRsp, msgSize, ret);
2024-07-08 01:37:47 +00:00
void *msg = taosMemoryCalloc(1, msgSize);
2024-07-17 01:12:42 +00:00
if (NULL == msg) {
return terrno;
}
2024-07-08 01:37:47 +00:00
tEncoderInit(&ec, (uint8_t *)msg, msgSize);
2024-07-17 01:12:42 +00:00
if (tEncodeSSubmitRsp2(&ec, &submitRsp) < 0) {
return -1;
}
2024-02-02 08:05:25 +00:00
tEncoderClear(&ec);
*rspMsg = msg;
*msize = msgSize;
return TSDB_CODE_SUCCESS;
}
2022-02-28 09:02:43 +00:00
void schtBuildQueryDag(SQueryPlan *dag) {
2022-01-18 11:32:29 +00:00
uint64_t qId = schtQueryId;
2022-10-13 08:58:43 +00:00
2021-12-24 11:01:48 +00:00
dag->queryId = qId;
dag->numOfSubplans = 2;
2024-07-21 10:20:30 +00:00
dag->pSubplans = NULL;
int32_t code = nodesMakeList(&dag->pSubplans);
2024-07-17 01:12:42 +00:00
if (NULL == dag->pSubplans) {
return;
}
2024-07-21 10:20:30 +00:00
SNodeListNode *scan = NULL;
code = nodesMakeNode(QUERY_NODE_NODE_LIST, (SNode**)&scan);
2024-07-17 01:12:42 +00:00
if (NULL == scan) {
return;
}
2024-07-21 10:20:30 +00:00
SNodeListNode *merge = NULL;
code = nodesMakeNode(QUERY_NODE_NODE_LIST, (SNode**)&merge);
2024-07-17 01:12:42 +00:00
if (NULL == merge) {
return;
}
2022-10-13 08:58:43 +00:00
2024-07-21 10:20:30 +00:00
SSubplan *scanPlan = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN, (SNode**)&scanPlan);
2024-07-17 01:12:42 +00:00
if (NULL == scanPlan) {
return;
}
2024-07-21 10:20:30 +00:00
SSubplan *mergePlan = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN, (SNode**)&mergePlan);
2024-07-17 01:12:42 +00:00
if (NULL == mergePlan) {
return;
}
2022-01-11 02:14:06 +00:00
scanPlan->id.queryId = qId;
2022-03-09 09:32:12 +00:00
scanPlan->id.groupId = 0x0000000000000002;
2022-01-11 02:14:06 +00:00
scanPlan->id.subplanId = 0x0000000000000003;
2022-03-02 02:50:51 +00:00
scanPlan->subplanType = SUBPLAN_TYPE_SCAN;
2022-01-26 06:00:15 +00:00
2022-01-11 02:14:06 +00:00
scanPlan->execNode.nodeId = 1;
2022-03-08 09:22:21 +00:00
scanPlan->execNode.epSet.inUse = 0;
addEpIntoEpSet(&scanPlan->execNode.epSet, "ep0", 6030);
2022-01-26 06:00:15 +00:00
2022-01-11 02:14:06 +00:00
scanPlan->pChildren = NULL;
scanPlan->level = 1;
2024-07-21 10:20:30 +00:00
scanPlan->pParents = NULL;
code = nodesMakeList(&scanPlan->pParents);
2024-07-17 01:12:42 +00:00
if (NULL == scanPlan->pParents) {
return;
}
2024-07-21 10:20:30 +00:00
scanPlan->pNode = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, (SNode**)&scanPlan->pNode);
2024-07-17 01:12:42 +00:00
if (NULL == scanPlan->pNode) {
return;
}
2022-06-28 02:34:51 +00:00
scanPlan->msgType = TDMT_SCH_QUERY;
2024-10-28 10:44:41 +00:00
code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_DISPATCH, (SNode**)&scanPlan->pDataSink);
if (NULL == scanPlan->pDataSink) {
return;
}
2022-01-11 02:14:06 +00:00
mergePlan->id.queryId = qId;
2022-03-09 09:32:12 +00:00
mergePlan->id.groupId = schtMergeTemplateId;
2022-03-02 02:50:51 +00:00
mergePlan->id.subplanId = 0x5555;
mergePlan->subplanType = SUBPLAN_TYPE_MERGE;
2022-01-11 02:14:06 +00:00
mergePlan->level = 0;
2022-03-08 09:22:21 +00:00
mergePlan->execNode.epSet.numOfEps = 0;
2022-01-26 06:00:15 +00:00
2024-07-21 10:20:30 +00:00
mergePlan->pChildren = NULL;
code = nodesMakeList(&mergePlan->pChildren);
2024-07-17 01:12:42 +00:00
if (NULL == mergePlan->pChildren) {
return;
}
2022-01-11 02:14:06 +00:00
mergePlan->pParents = NULL;
2024-07-21 10:20:30 +00:00
mergePlan->pNode = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_MERGE, (SNode**)&mergePlan->pNode);
2024-07-17 01:12:42 +00:00
if (NULL == mergePlan->pNode) {
return;
}
2022-06-28 02:34:51 +00:00
mergePlan->msgType = TDMT_SCH_QUERY;
2024-10-28 10:44:41 +00:00
code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_DISPATCH, (SNode**)&mergePlan->pDataSink);
if (NULL == mergePlan->pDataSink) {
return;
}
2021-12-24 11:01:48 +00:00
2024-07-21 10:20:30 +00:00
merge->pNodeList = NULL;
code = nodesMakeList(&merge->pNodeList);
2024-07-17 01:12:42 +00:00
if (NULL == merge->pNodeList) {
return;
}
2024-07-21 10:20:30 +00:00
scan->pNodeList = NULL;
code = nodesMakeList(&scan->pNodeList);
2024-07-17 01:12:42 +00:00
if (NULL == scan->pNodeList) {
return;
}
2022-03-05 04:15:22 +00:00
2024-10-28 10:44:41 +00:00
2024-07-17 01:12:42 +00:00
(void)nodesListAppend(merge->pNodeList, (SNode *)mergePlan);
(void)nodesListAppend(scan->pNodeList, (SNode *)scanPlan);
2021-12-24 11:01:48 +00:00
2024-07-17 01:12:42 +00:00
(void)nodesListAppend(mergePlan->pChildren, (SNode *)scanPlan);
(void)nodesListAppend(scanPlan->pParents, (SNode *)mergePlan);
2021-12-24 11:01:48 +00:00
2024-07-17 01:12:42 +00:00
(void)nodesListAppend(dag->pSubplans, (SNode *)merge);
(void)nodesListAppend(dag->pSubplans, (SNode *)scan);
2021-12-24 11:01:48 +00:00
}
2022-03-05 09:19:21 +00:00
void schtBuildQueryFlowCtrlDag(SQueryPlan *dag) {
uint64_t qId = schtQueryId;
2022-10-13 08:58:43 +00:00
int32_t scanPlanNum = 20;
2022-03-05 09:19:21 +00:00
dag->queryId = qId;
2024-10-28 10:44:41 +00:00
dag->numOfSubplans = scanPlanNum + 1;
2024-07-21 10:20:30 +00:00
dag->pSubplans = NULL;
int32_t code = nodesMakeList(&dag->pSubplans);
2024-07-17 01:12:42 +00:00
if (NULL == dag->pSubplans) {
return;
}
2024-07-21 10:20:30 +00:00
SNodeListNode *scan = NULL;
code = nodesMakeNode(QUERY_NODE_NODE_LIST, (SNode**)&scan);
2024-07-17 01:12:42 +00:00
if (NULL == scan) {
return;
}
2024-07-21 10:20:30 +00:00
SNodeListNode *merge = NULL;
code = nodesMakeNode(QUERY_NODE_NODE_LIST, (SNode**)&merge);
2024-07-17 01:12:42 +00:00
if (NULL == merge) {
return;
}
2022-10-13 08:58:43 +00:00
2024-07-21 10:20:30 +00:00
SSubplan *mergePlan = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN, (SNode**)&mergePlan);
2024-07-17 01:12:42 +00:00
if (NULL == mergePlan) {
return;
}
2022-03-05 09:19:21 +00:00
2024-07-21 10:20:30 +00:00
merge->pNodeList = NULL;
code = nodesMakeList(&merge->pNodeList);
2024-07-17 01:12:42 +00:00
if (NULL == merge->pNodeList) {
return;
}
2024-07-21 10:20:30 +00:00
scan->pNodeList = NULL;
code = nodesMakeList(&scan->pNodeList);
2024-07-17 01:12:42 +00:00
if (NULL == scan->pNodeList) {
return;
}
2022-03-05 09:19:21 +00:00
2024-07-21 10:20:30 +00:00
mergePlan->pChildren = NULL;
code = nodesMakeList(&mergePlan->pChildren);
2024-07-17 01:12:42 +00:00
if (NULL == mergePlan->pChildren) {
return;
}
2024-10-28 10:44:41 +00:00
code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_DISPATCH, (SNode**)&mergePlan->pDataSink);
if (NULL == mergePlan->pDataSink) {
return;
}
2022-03-05 09:19:21 +00:00
for (int32_t i = 0; i < scanPlanNum; ++i) {
2024-07-21 10:20:30 +00:00
SSubplan *scanPlan = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN, (SNode**)&scanPlan);
2024-07-17 01:12:42 +00:00
if (NULL == scanPlan) {
return;
}
2024-02-02 08:05:25 +00:00
scanPlan->id.queryId = qId;
scanPlan->id.groupId = 0x0000000000000002;
scanPlan->id.subplanId = 0x0000000000000003 + i;
scanPlan->subplanType = SUBPLAN_TYPE_SCAN;
scanPlan->execNode.nodeId = 1 + i;
scanPlan->execNode.epSet.inUse = 0;
2024-12-20 05:52:53 +00:00
scanPlan->execNodeStat.tableNum = taosRand() % 100;
2024-02-02 08:05:25 +00:00
addEpIntoEpSet(&scanPlan->execNode.epSet, "ep0", 6030);
addEpIntoEpSet(&scanPlan->execNode.epSet, "ep1", 6030);
addEpIntoEpSet(&scanPlan->execNode.epSet, "ep2", 6030);
scanPlan->execNode.epSet.inUse = taosRand() % 3;
scanPlan->pChildren = NULL;
scanPlan->level = 1;
2024-07-21 10:20:30 +00:00
scanPlan->pParents = NULL;
code = nodesMakeList(&scanPlan->pParents);
2024-07-17 01:12:42 +00:00
if (NULL == scanPlan->pParents) {
return;
}
2024-07-21 10:20:30 +00:00
scanPlan->pNode = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, (SNode**)&scanPlan->pNode);
2024-07-17 01:12:42 +00:00
if (NULL == scanPlan->pNode) {
return;
}
2024-02-02 08:05:25 +00:00
scanPlan->msgType = TDMT_SCH_QUERY;
2024-10-28 10:44:41 +00:00
code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_DISPATCH, (SNode**)&scanPlan->pDataSink);
if (NULL == scanPlan->pDataSink) {
return;
}
2024-02-02 08:05:25 +00:00
2024-07-17 01:12:42 +00:00
(void)nodesListAppend(scanPlan->pParents, (SNode *)mergePlan);
(void)nodesListAppend(mergePlan->pChildren, (SNode *)scanPlan);
2024-02-02 08:05:25 +00:00
2024-07-17 01:12:42 +00:00
(void)nodesListAppend(scan->pNodeList, (SNode *)scanPlan);
2022-03-05 09:19:21 +00:00
}
mergePlan->id.queryId = qId;
2022-03-09 09:32:12 +00:00
mergePlan->id.groupId = schtMergeTemplateId;
2022-03-05 09:19:21 +00:00
mergePlan->id.subplanId = 0x5555;
mergePlan->subplanType = SUBPLAN_TYPE_MERGE;
mergePlan->level = 0;
2022-03-10 02:35:24 +00:00
mergePlan->execNode.epSet.numOfEps = 0;
2022-03-05 09:19:21 +00:00
mergePlan->pParents = NULL;
2024-07-21 10:20:30 +00:00
mergePlan->pNode = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_MERGE, (SNode**)&mergePlan->pNode);
2024-07-17 01:12:42 +00:00
if (NULL == mergePlan->pNode) {
return;
}
2022-06-28 02:34:51 +00:00
mergePlan->msgType = TDMT_SCH_QUERY;
2022-03-05 09:19:21 +00:00
2024-07-17 01:12:42 +00:00
(void)nodesListAppend(merge->pNodeList, (SNode *)mergePlan);
2022-01-11 02:14:06 +00:00
2024-07-17 01:12:42 +00:00
(void)nodesListAppend(dag->pSubplans, (SNode *)merge);
(void)nodesListAppend(dag->pSubplans, (SNode *)scan);
2022-01-11 02:14:06 +00:00
}
2022-10-13 08:58:43 +00:00
void schtFreeQueryDag(SQueryPlan *dag) {}
2022-01-11 02:14:06 +00:00
2022-02-28 09:02:43 +00:00
void schtBuildInsertDag(SQueryPlan *dag) {
2021-12-26 12:05:24 +00:00
uint64_t qId = 0x0000000000000002;
2022-10-13 08:58:43 +00:00
2021-12-26 12:05:24 +00:00
dag->queryId = qId;
dag->numOfSubplans = 2;
2024-07-21 10:20:30 +00:00
dag->pSubplans = NULL;
int32_t code = nodesMakeList(&dag->pSubplans);
2024-07-17 01:12:42 +00:00
if (NULL == dag->pSubplans) {
return;
}
2024-07-21 10:20:30 +00:00
SNodeListNode *inserta = NULL;
code = nodesMakeNode(QUERY_NODE_NODE_LIST, (SNode**)&inserta);
2024-07-17 01:12:42 +00:00
if (NULL == inserta) {
return;
}
2024-07-21 10:20:30 +00:00
inserta->pNodeList = NULL;
code = nodesMakeList(&inserta->pNodeList);
2024-07-17 01:12:42 +00:00
if (NULL == inserta->pNodeList) {
return;
}
2022-10-13 08:58:43 +00:00
2024-07-21 10:20:30 +00:00
SSubplan *insertPlan = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN, (SNode**)&insertPlan);
2024-07-17 01:12:42 +00:00
if (NULL == insertPlan) {
return;
}
2021-12-26 12:05:24 +00:00
2024-02-02 08:05:25 +00:00
insertPlan->id.queryId = qId;
insertPlan->id.groupId = 0x0000000000000003;
insertPlan->id.subplanId = 0x0000000000000004;
insertPlan->subplanType = SUBPLAN_TYPE_MODIFY;
insertPlan->level = 0;
2022-01-26 06:00:15 +00:00
2024-02-02 08:05:25 +00:00
insertPlan->execNode.nodeId = 1;
insertPlan->execNode.epSet.inUse = 0;
addEpIntoEpSet(&insertPlan->execNode.epSet, "ep0", 6030);
2022-01-26 06:00:15 +00:00
2024-02-02 08:05:25 +00:00
insertPlan->pChildren = NULL;
insertPlan->pParents = NULL;
insertPlan->pNode = NULL;
2024-07-21 10:20:30 +00:00
insertPlan->pDataSink = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_INSERT, (SNode**)&insertPlan->pDataSink);
2024-07-17 01:12:42 +00:00
if (NULL == insertPlan->pDataSink) {
return;
}
2024-07-08 01:37:47 +00:00
((SDataInserterNode *)insertPlan->pDataSink)->size = 1;
((SDataInserterNode *)insertPlan->pDataSink)->pData = taosMemoryCalloc(1, 1);
2024-07-17 01:12:42 +00:00
if (NULL == ((SDataInserterNode *)insertPlan->pDataSink)->pData) {
return;
}
2024-02-02 08:05:25 +00:00
insertPlan->msgType = TDMT_VND_SUBMIT;
2021-12-26 12:05:24 +00:00
2024-07-17 01:12:42 +00:00
(void)nodesListAppend(inserta->pNodeList, (SNode *)insertPlan);
2022-01-26 06:00:15 +00:00
2024-07-21 10:20:30 +00:00
insertPlan = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN, (SNode**)&insertPlan);
2024-07-17 01:12:42 +00:00
if (NULL == insertPlan) {
return;
}
2022-01-26 06:00:15 +00:00
2024-02-02 08:05:25 +00:00
insertPlan->id.queryId = qId;
insertPlan->id.groupId = 0x0000000000000003;
insertPlan->id.subplanId = 0x0000000000000005;
insertPlan->subplanType = SUBPLAN_TYPE_MODIFY;
insertPlan->level = 0;
2021-12-26 12:05:24 +00:00
2024-02-02 08:05:25 +00:00
insertPlan->execNode.nodeId = 1;
insertPlan->execNode.epSet.inUse = 0;
addEpIntoEpSet(&insertPlan->execNode.epSet, "ep0", 6030);
insertPlan->pChildren = NULL;
insertPlan->pParents = NULL;
insertPlan->pNode = NULL;
2024-07-21 10:20:30 +00:00
insertPlan->pDataSink = NULL;
code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_INSERT, (SNode**)&insertPlan->pDataSink);
2024-07-17 01:12:42 +00:00
if (NULL == insertPlan->pDataSink) {
return;
}
2024-07-08 01:37:47 +00:00
((SDataInserterNode *)insertPlan->pDataSink)->size = 1;
((SDataInserterNode *)insertPlan->pDataSink)->pData = taosMemoryCalloc(1, 1);
2024-07-17 01:12:42 +00:00
if (NULL == ((SDataInserterNode *)insertPlan->pDataSink)->pData) {
return;
}
2024-02-02 08:05:25 +00:00
insertPlan->msgType = TDMT_VND_SUBMIT;
2022-03-05 04:15:22 +00:00
2024-07-17 01:12:42 +00:00
(void)nodesListAppend(inserta->pNodeList, (SNode *)insertPlan);
2021-12-26 12:05:24 +00:00
2024-07-17 01:12:42 +00:00
(void)nodesListAppend(dag->pSubplans, (SNode *)inserta);
2021-12-26 12:05:24 +00:00
}
2022-10-13 08:58:43 +00:00
int32_t schtPlanToString(const SSubplan *subplan, char **str, int32_t *len) {
2022-03-25 16:29:53 +00:00
*str = (char *)taosMemoryCalloc(1, 20);
2024-07-17 01:12:42 +00:00
if (NULL == *str) {
return -1;
}
2021-12-25 13:29:42 +00:00
*len = 20;
return 0;
}
2024-07-17 01:12:42 +00:00
int32_t schtExecNode(SSubplan *subplan, uint64_t groupId, SQueryNodeAddr *ep) { return 0; }
2022-01-11 15:16:45 +00:00
2022-10-13 08:58:43 +00:00
void schtRpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t *pRid) {}
2022-01-12 01:22:48 +00:00
2021-12-25 13:29:42 +00:00
void schtSetPlanToString() {
static Stub stub;
stub.set(qSubPlanToString, schtPlanToString);
{
2022-04-22 01:54:27 +00:00
#ifdef WINDOWS
2022-10-13 08:58:43 +00:00
AddrAny any;
std::map<std::string, void *> result;
2022-04-22 01:54:27 +00:00
any.get_func_addr("qSubPlanToString", result);
#endif
#ifdef LINUX
2022-10-13 08:58:43 +00:00
AddrAny any("libplanner.so");
std::map<std::string, void *> result;
2021-12-25 13:29:42 +00:00
any.get_global_func_addr_dynsym("^qSubPlanToString$", result);
2022-04-22 01:54:27 +00:00
#endif
2022-10-13 08:58:43 +00:00
for (const auto &f : result) {
2021-12-25 13:29:42 +00:00
stub.set(f.second, schtPlanToString);
}
}
}
void schtSetExecNode() {
static Stub stub;
stub.set(qSetSubplanExecutionNode, schtExecNode);
{
2022-04-22 01:54:27 +00:00
#ifdef WINDOWS
2022-10-13 08:58:43 +00:00
AddrAny any;
std::map<std::string, void *> result;
2022-04-22 01:54:27 +00:00
any.get_func_addr("qSetSubplanExecutionNode", result);
#endif
#ifdef LINUX
2022-10-13 08:58:43 +00:00
AddrAny any("libplanner.so");
std::map<std::string, void *> result;
2021-12-25 13:29:42 +00:00
any.get_global_func_addr_dynsym("^qSetSubplanExecutionNode$", result);
2022-04-22 01:54:27 +00:00
#endif
2022-10-13 08:58:43 +00:00
for (const auto &f : result) {
2021-12-25 13:29:42 +00:00
stub.set(f.second, schtExecNode);
}
}
}
2022-01-12 01:22:48 +00:00
void schtSetRpcSendRequest() {
static Stub stub;
stub.set(rpcSendRequest, schtRpcSendRequest);
{
2022-04-22 01:54:27 +00:00
#ifdef WINDOWS
2022-10-13 08:58:43 +00:00
AddrAny any;
std::map<std::string, void *> result;
2022-04-22 01:54:27 +00:00
any.get_func_addr("rpcSendRequest", result);
#endif
#ifdef LINUX
2022-10-13 08:58:43 +00:00
AddrAny any("libtransport.so");
std::map<std::string, void *> result;
2022-01-12 01:22:48 +00:00
any.get_global_func_addr_dynsym("^rpcSendRequest$", result);
2022-04-22 01:54:27 +00:00
#endif
2022-10-13 08:58:43 +00:00
for (const auto &f : result) {
2022-01-12 01:22:48 +00:00
stub.set(f.second, schtRpcSendRequest);
}
}
}
2024-07-08 01:37:47 +00:00
int32_t schtAsyncSendMsgToServer(void *pTransporter, SEpSet *epSet, int64_t *pTransporterId, SMsgSendInfo *pInfo,
bool persistHandle, void *rpcCtx) {
2022-01-19 02:18:31 +00:00
if (pInfo) {
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(pInfo->param);
taosMemoryFreeClear(pInfo->msgInfo.pData);
taosMemoryFree(pInfo);
2022-01-19 02:18:31 +00:00
}
2022-01-18 06:12:25 +00:00
return 0;
}
void schtSetAsyncSendMsgToServer() {
static Stub stub;
2024-02-02 08:05:25 +00:00
stub.set(asyncSendMsgToServerExt, schtAsyncSendMsgToServer);
2022-01-18 06:12:25 +00:00
{
2022-04-22 01:54:27 +00:00
#ifdef WINDOWS
2022-10-13 08:58:43 +00:00
AddrAny any;
std::map<std::string, void *> result;
2024-02-02 08:05:25 +00:00
any.get_func_addr("asyncSendMsgToServerExt", result);
2022-04-22 01:54:27 +00:00
#endif
#ifdef LINUX
2022-10-13 08:58:43 +00:00
AddrAny any("libtransport.so");
std::map<std::string, void *> result;
2024-02-02 08:05:25 +00:00
any.get_global_func_addr_dynsym("^asyncSendMsgToServerExt$", result);
2022-04-22 01:54:27 +00:00
#endif
2022-10-13 08:58:43 +00:00
for (const auto &f : result) {
2022-01-18 06:12:25 +00:00
stub.set(f.second, schtAsyncSendMsgToServer);
}
}
}
2021-12-26 12:05:24 +00:00
void *schtSendRsp(void *param) {
2022-03-03 07:07:33 +00:00
SSchJob *pJob = NULL;
2022-10-13 08:58:43 +00:00
int64_t job = 0;
int32_t code = 0;
2021-12-26 12:05:24 +00:00
while (true) {
2022-03-03 07:07:33 +00:00
job = *(int64_t *)param;
2021-12-26 12:05:24 +00:00
if (job) {
break;
}
2022-03-10 03:56:11 +00:00
taosMsleep(1);
2021-12-26 12:05:24 +00:00
}
2022-03-03 07:07:33 +00:00
2024-07-16 11:03:12 +00:00
code = schAcquireJob(job, &pJob);
if (code) {
return NULL;
}
2022-03-03 07:07:33 +00:00
void *pIter = taosHashIterate(pJob->execTasks, NULL);
2021-12-26 12:05:24 +00:00
while (pIter) {
SSchTask *task = *(SSchTask **)pIter;
2024-02-02 08:05:25 +00:00
SDataBuf msg = {0};
2024-07-08 01:37:47 +00:00
void *rmsg = NULL;
2024-07-17 01:12:42 +00:00
(void)schtBuildSubmitRspMsg(&msg.len, &rmsg);
2024-02-02 08:05:25 +00:00
msg.msgType = TDMT_VND_SUBMIT_RSP;
msg.pData = rmsg;
2024-07-08 01:37:47 +00:00
(void)schHandleResponseMsg(pJob, task, task->seriesId, task->execId, &msg, 0);
2022-10-13 08:58:43 +00:00
2022-03-03 07:07:33 +00:00
pIter = taosHashIterate(pJob->execTasks, pIter);
2022-10-13 08:58:43 +00:00
}
2021-12-26 12:05:24 +00:00
2024-07-17 01:12:42 +00:00
(void)schReleaseJob(job);
2022-03-03 07:07:33 +00:00
2024-02-20 09:06:41 +00:00
schtJobDone = true;
2024-07-08 01:37:47 +00:00
2021-12-26 12:05:24 +00:00
return NULL;
}
2022-01-18 06:12:25 +00:00
void *schtCreateFetchRspThread(void *param) {
2022-10-13 08:58:43 +00:00
int64_t job = *(int64_t *)param;
2024-07-16 11:03:12 +00:00
SSchJob *pJob = NULL;
2022-01-18 06:12:25 +00:00
2024-07-16 11:03:12 +00:00
(void)schAcquireJob(job, &pJob);
if (NULL == pJob) {
return NULL;
}
2022-03-10 03:56:11 +00:00
taosSsleep(1);
2022-01-18 06:12:25 +00:00
2024-07-08 01:37:47 +00:00
int32_t code = 0;
2024-02-02 08:05:25 +00:00
SDataBuf msg = {0};
2024-07-08 01:37:47 +00:00
void *rmsg = NULL;
2024-07-17 01:12:42 +00:00
(void)schtBuildFetchRspMsg(&msg.len, &rmsg);
2024-02-02 08:05:25 +00:00
msg.msgType = TDMT_SCH_MERGE_FETCH_RSP;
msg.pData = rmsg;
2024-07-08 01:37:47 +00:00
code = schHandleResponseMsg(pJob, pJob->fetchTask, pJob->fetchTask->seriesId, pJob->fetchTask->execId, &msg, 0);
2022-03-03 07:07:33 +00:00
2024-07-17 01:12:42 +00:00
(void)schReleaseJob(job);
2022-10-13 08:58:43 +00:00
TD_ALWAYS_ASSERT(code == 0);
2022-04-22 01:54:27 +00:00
return NULL;
2022-01-18 06:12:25 +00:00
}
2022-01-18 11:32:29 +00:00
void *schtFetchRspThread(void *aa) {
2022-10-13 08:58:43 +00:00
SDataBuf dataBuf = {0};
SSchTaskCallbackParam *param = NULL;
2022-01-18 11:32:29 +00:00
while (!schtTestStop) {
if (0 == atomic_val_compare_exchange_32(&schtStartFetch, 1, 0)) {
continue;
}
2024-02-19 05:29:06 +00:00
taosUsleep(100);
2022-10-13 08:58:43 +00:00
param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
2024-07-17 01:12:42 +00:00
if (NULL == param) {
return NULL;
}
2022-10-13 08:58:43 +00:00
param->queryId = schtQueryId;
2022-01-18 11:32:29 +00:00
param->taskId = schtFetchTaskId;
2022-10-13 08:58:43 +00:00
int32_t code = 0;
2022-03-25 16:29:53 +00:00
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, sizeof(SRetrieveTableRsp));
2024-07-17 01:12:42 +00:00
if (NULL == rsp) {
return NULL;
}
2022-01-18 11:32:29 +00:00
rsp->completed = 1;
rsp->numOfRows = 10;
2024-02-02 08:05:25 +00:00
dataBuf.msgType = TDMT_SCH_FETCH_RSP;
2022-01-18 11:32:29 +00:00
dataBuf.pData = rsp;
dataBuf.len = sizeof(*rsp);
2024-02-02 08:05:25 +00:00
code = schHandleCallback(param, &dataBuf, 0);
2022-10-13 08:58:43 +00:00
TD_ALWAYS_ASSERT(code == 0 || code);
2022-01-18 11:32:29 +00:00
}
2022-04-22 01:54:27 +00:00
return NULL;
2022-01-18 11:32:29 +00:00
}
void schtFreeQueryJob(int32_t freeThread) {
static uint32_t freeNum = 0;
2022-10-13 08:58:43 +00:00
int64_t job = queryJobRefId;
2022-03-03 07:07:33 +00:00
if (job && atomic_val_compare_exchange_64(&queryJobRefId, job, 0)) {
2022-07-01 13:01:35 +00:00
schedulerFreeJob(&job, 0);
2022-01-18 11:32:29 +00:00
if (freeThread) {
if (++freeNum % schtTestPrintNum == 0) {
(void)printf("FreeNum:%d\n", freeNum);
2022-01-18 11:32:29 +00:00
}
}
}
}
2022-10-13 08:58:43 +00:00
void *schtRunJobThread(void *aa) {
void *mockPointer = (void *)0x1;
char *clusterId = "cluster1";
char *dbname = "1.db1";
char *tablename = "table1";
2022-01-18 11:32:29 +00:00
SVgroupInfo vgInfo = {0};
2024-07-21 10:20:30 +00:00
SQueryPlan *dag = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN, (SNode**)&dag);
TD_ALWAYS_ASSERT(code == 0);
2022-01-18 11:32:29 +00:00
schtInitLogFile();
2024-07-21 10:20:30 +00:00
code = schedulerInit();
TD_ALWAYS_ASSERT(code == 0);
2022-01-18 11:32:29 +00:00
schtSetPlanToString();
schtSetExecNode();
schtSetAsyncSendMsgToServer();
2022-10-13 08:58:43 +00:00
SSchJob *pJob = NULL;
2022-03-22 03:32:53 +00:00
SSchTaskCallbackParam *param = NULL;
2022-10-13 08:58:43 +00:00
SHashObj *execTasks = NULL;
uint32_t jobFinished = 0;
int32_t queryDone = 0;
2022-01-18 11:32:29 +00:00
while (!schtTestStop) {
2024-02-02 08:05:25 +00:00
schtBuildQueryDag(dag);
2022-01-18 11:32:29 +00:00
2024-02-19 06:02:16 +00:00
SArray *qnodeList = taosArrayInit(1, sizeof(SQueryNodeLoad));
2024-07-17 01:12:42 +00:00
if (NULL == qnodeList) {
TD_ALWAYS_ASSERT(0);
2024-07-17 01:12:42 +00:00
}
2024-02-19 06:02:16 +00:00
SQueryNodeLoad load = {0};
load.addr.epSet.numOfEps = 1;
TAOS_STRCPY(load.addr.epSet.eps[0].fqdn, "qnode0.ep");
2024-02-19 06:02:16 +00:00
load.addr.epSet.eps[0].port = 6031;
2024-07-17 01:12:42 +00:00
if (NULL == taosArrayPush(qnodeList, &load)) {
TD_ALWAYS_ASSERT(0);
2024-07-17 01:12:42 +00:00
}
2022-01-19 02:18:31 +00:00
2022-05-24 09:49:22 +00:00
queryDone = 0;
2022-10-13 08:58:43 +00:00
2022-06-11 00:22:18 +00:00
SRequestConnInfo conn = {0};
conn.pTrans = mockPointer;
2022-10-13 08:58:43 +00:00
SSchedulerReq req = {0};
2022-07-02 08:59:49 +00:00
req.syncReq = false;
2022-06-11 00:22:18 +00:00
req.pConn = &conn;
req.pNodeList = qnodeList;
2024-02-02 08:05:25 +00:00
req.pDag = dag;
2022-06-11 00:22:18 +00:00
req.sql = "select * from tb";
2022-06-29 09:00:48 +00:00
req.execFp = schtQueryCb;
2022-07-05 08:10:38 +00:00
req.cbParam = &queryDone;
2022-10-13 08:58:43 +00:00
code = schedulerExecJob(&req, &queryJobRefId);
TD_ALWAYS_ASSERT(code == 0);
2022-01-18 11:32:29 +00:00
2024-07-16 11:03:12 +00:00
pJob = NULL;
code = schAcquireJob(queryJobRefId, &pJob);
2022-03-03 07:07:33 +00:00
if (NULL == pJob) {
taosArrayDestroy(qnodeList);
2024-02-02 08:05:25 +00:00
schtFreeQueryDag(dag);
2022-03-03 07:07:33 +00:00
continue;
}
2022-10-13 08:58:43 +00:00
2022-01-18 11:32:29 +00:00
execTasks = taosHashInit(5, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK);
2024-07-17 01:12:42 +00:00
if (NULL == execTasks) {
TD_ALWAYS_ASSERT(0);
2024-07-17 01:12:42 +00:00
}
2022-03-03 07:07:33 +00:00
void *pIter = taosHashIterate(pJob->execTasks, NULL);
2022-01-18 11:32:29 +00:00
while (pIter) {
SSchTask *task = *(SSchTask **)pIter;
schtFetchTaskId = task->taskId - 1;
2022-10-13 08:58:43 +00:00
2024-07-17 01:12:42 +00:00
if (taosHashPut(execTasks, &task->taskId, sizeof(task->taskId), task, sizeof(*task))) {
TD_ALWAYS_ASSERT(0);
2024-07-17 01:12:42 +00:00
}
2022-03-03 07:07:33 +00:00
pIter = taosHashIterate(pJob->execTasks, pIter);
2022-10-13 08:58:43 +00:00
}
2022-01-18 11:32:29 +00:00
param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
2024-07-17 01:12:42 +00:00
if (NULL == param) {
TD_ALWAYS_ASSERT(0);
2024-07-17 01:12:42 +00:00
}
2022-03-03 07:07:33 +00:00
param->refId = queryJobRefId;
2022-10-13 08:58:43 +00:00
param->queryId = pJob->queryId;
2022-01-18 11:32:29 +00:00
pIter = taosHashIterate(execTasks, NULL);
while (pIter) {
SSchTask *task = (SSchTask *)pIter;
param->taskId = task->taskId;
2022-10-13 08:58:43 +00:00
2024-02-02 08:05:25 +00:00
SDataBuf msg = {0};
2024-07-08 01:37:47 +00:00
void *rmsg = NULL;
2024-07-17 01:12:42 +00:00
if (schtBuildQueryRspMsg(&msg.len, &rmsg)) {
TD_ALWAYS_ASSERT(0);
2024-07-17 01:12:42 +00:00
}
2024-02-02 08:05:25 +00:00
msg.msgType = TDMT_SCH_QUERY_RSP;
msg.pData = rmsg;
code = schHandleCallback(param, &msg, 0);
TD_ALWAYS_ASSERT(code == 0 || code);
2022-01-18 11:32:29 +00:00
pIter = taosHashIterate(execTasks, pIter);
2022-10-13 08:58:43 +00:00
}
2022-01-18 11:32:29 +00:00
param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
2024-07-17 01:12:42 +00:00
if (NULL == param) {
TD_ALWAYS_ASSERT(0);
2024-07-17 01:12:42 +00:00
}
2022-03-03 07:07:33 +00:00
param->refId = queryJobRefId;
2022-10-13 08:58:43 +00:00
param->queryId = pJob->queryId;
2022-01-18 11:32:29 +00:00
pIter = taosHashIterate(execTasks, NULL);
while (pIter) {
SSchTask *task = (SSchTask *)pIter;
param->taskId = task->taskId - 1;
2024-02-02 08:05:25 +00:00
SDataBuf msg = {0};
2024-07-08 01:37:47 +00:00
void *rmsg = NULL;
2024-07-17 01:12:42 +00:00
if (schtBuildQueryRspMsg(&msg.len, &rmsg)) {
TD_ALWAYS_ASSERT(0);
2024-07-17 01:12:42 +00:00
}
2024-02-02 08:05:25 +00:00
msg.msgType = TDMT_SCH_QUERY_RSP;
msg.pData = rmsg;
2022-10-13 08:58:43 +00:00
2024-02-02 08:05:25 +00:00
code = schHandleCallback(param, &msg, 0);
TD_ALWAYS_ASSERT(code == 0 || code);
2022-01-18 11:32:29 +00:00
2022-10-13 08:58:43 +00:00
pIter = taosHashIterate(execTasks, pIter);
}
2022-01-18 11:32:29 +00:00
2022-05-24 09:49:22 +00:00
while (true) {
if (queryDone) {
break;
}
2022-10-13 08:58:43 +00:00
2022-05-24 09:49:22 +00:00
taosUsleep(10000);
}
2022-01-18 11:32:29 +00:00
atomic_store_32(&schtStartFetch, 1);
2022-10-13 08:58:43 +00:00
void *data = NULL;
2022-07-05 10:12:01 +00:00
req.syncReq = true;
req.pFetchRes = &data;
2022-10-13 08:58:43 +00:00
2022-07-05 10:12:01 +00:00
code = schedulerFetchRows(queryJobRefId, &req);
TD_ALWAYS_ASSERT(code == 0 || code);
2022-01-18 11:32:29 +00:00
if (0 == code) {
SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data;
TD_ALWAYS_ASSERT(pRsp->completed == 1);
2022-01-18 11:32:29 +00:00
}
data = NULL;
2022-07-05 10:12:01 +00:00
code = schedulerFetchRows(queryJobRefId, &req);
TD_ALWAYS_ASSERT(code == 0 || code);
2022-10-13 08:58:43 +00:00
2022-01-18 11:32:29 +00:00
schtFreeQueryJob(0);
taosHashCleanup(execTasks);
2022-03-03 07:07:33 +00:00
taosArrayDestroy(qnodeList);
2022-01-18 11:32:29 +00:00
2024-02-02 08:05:25 +00:00
schtFreeQueryDag(dag);
2022-01-18 11:32:29 +00:00
if (++jobFinished % schtTestPrintNum == 0) {
(void)printf("jobFinished:%d\n", jobFinished);
2022-01-18 11:32:29 +00:00
}
++schtQueryId;
}
schedulerDestroy();
2022-04-22 01:54:27 +00:00
return NULL;
2022-01-18 11:32:29 +00:00
}
2022-10-13 08:58:43 +00:00
void *schtFreeJobThread(void *aa) {
2022-01-18 11:32:29 +00:00
while (!schtTestStop) {
2022-03-10 03:56:11 +00:00
taosUsleep(taosRand() % 100);
2022-01-18 11:32:29 +00:00
schtFreeQueryJob(1);
}
2022-04-22 01:54:27 +00:00
return NULL;
2022-01-18 11:32:29 +00:00
}
2022-01-18 06:12:25 +00:00
2022-10-13 08:58:43 +00:00
} // namespace
2021-12-20 05:24:30 +00:00
2021-12-25 13:29:42 +00:00
TEST(queryTest, normalCase) {
2022-10-13 08:58:43 +00:00
void *mockPointer = (void *)0x1;
char *clusterId = "cluster1";
char *dbname = "1.db1";
char *tablename = "table1";
2021-12-24 11:01:48 +00:00
SVgroupInfo vgInfo = {0};
2022-10-13 08:58:43 +00:00
int64_t job = 0;
2024-07-21 10:20:30 +00:00
SQueryPlan *dag = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN, (SNode**)&dag);
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
2022-01-11 02:14:06 +00:00
2024-02-19 06:02:16 +00:00
SArray *qnodeList = taosArrayInit(1, sizeof(SQueryNodeLoad));
2021-12-25 13:29:42 +00:00
2024-02-19 06:02:16 +00:00
SQueryNodeLoad load = {0};
load.addr.epSet.numOfEps = 1;
TAOS_STRCPY(load.addr.epSet.eps[0].fqdn, "qnode0.ep");
2024-02-19 06:02:16 +00:00
load.addr.epSet.eps[0].port = 6031;
ASSERT_NE(taosArrayPush(qnodeList, &load), nullptr);
2022-10-13 08:58:43 +00:00
2024-07-21 10:20:30 +00:00
code = schedulerInit();
2021-12-20 05:24:30 +00:00
ASSERT_EQ(code, 0);
2021-12-24 11:01:48 +00:00
2024-02-02 08:05:25 +00:00
schtBuildQueryDag(dag);
2021-12-25 13:29:42 +00:00
schtSetPlanToString();
schtSetExecNode();
2022-01-18 06:12:25 +00:00
schtSetAsyncSendMsgToServer();
2022-05-24 09:49:22 +00:00
int32_t queryDone = 0;
2022-06-11 00:22:18 +00:00
SRequestConnInfo conn = {0};
conn.pTrans = mockPointer;
2022-10-13 08:58:43 +00:00
SSchedulerReq req = {0};
2022-06-11 00:22:18 +00:00
req.pConn = &conn;
req.pNodeList = qnodeList;
2024-02-02 08:05:25 +00:00
req.pDag = dag;
2022-06-11 00:22:18 +00:00
req.sql = "select * from tb";
2022-06-29 09:00:48 +00:00
req.execFp = schtQueryCb;
2022-07-05 08:10:38 +00:00
req.cbParam = &queryDone;
2022-10-13 08:58:43 +00:00
code = schedulerExecJob(&req, &job);
2021-12-20 05:24:30 +00:00
ASSERT_EQ(code, 0);
2021-12-25 13:29:42 +00:00
2024-07-16 11:03:12 +00:00
SSchJob *pJob = NULL;
code = schAcquireJob(job, &pJob);
ASSERT_EQ(code, 0);
2022-10-13 08:58:43 +00:00
2022-03-03 07:07:33 +00:00
void *pIter = taosHashIterate(pJob->execTasks, NULL);
2021-12-25 13:29:42 +00:00
while (pIter) {
2021-12-26 12:05:24 +00:00
SSchTask *task = *(SSchTask **)pIter;
2021-12-25 13:29:42 +00:00
2024-02-02 08:05:25 +00:00
SDataBuf msg = {0};
2024-07-08 01:37:47 +00:00
void *rmsg = NULL;
ASSERT_EQ(0, schtBuildQueryRspMsg(&msg.len, &rmsg));
2024-02-02 08:05:25 +00:00
msg.msgType = TDMT_SCH_QUERY_RSP;
msg.pData = rmsg;
2024-07-08 01:37:47 +00:00
code = schHandleResponseMsg(pJob, task, task->seriesId, task->execId, &msg, 0);
2024-07-08 01:37:47 +00:00
2021-12-25 13:29:42 +00:00
ASSERT_EQ(code, 0);
2022-03-03 07:07:33 +00:00
pIter = taosHashIterate(pJob->execTasks, pIter);
2022-10-13 08:58:43 +00:00
}
2021-12-25 13:29:42 +00:00
2022-03-03 07:07:33 +00:00
pIter = taosHashIterate(pJob->execTasks, NULL);
2021-12-25 13:29:42 +00:00
while (pIter) {
2021-12-26 12:05:24 +00:00
SSchTask *task = *(SSchTask **)pIter;
2024-02-02 08:05:25 +00:00
if (JOB_TASK_STATUS_EXEC == task->status) {
SDataBuf msg = {0};
2024-07-08 01:37:47 +00:00
void *rmsg = NULL;
ASSERT_EQ(0, schtBuildQueryRspMsg(&msg.len, &rmsg));
2024-02-02 08:05:25 +00:00
msg.msgType = TDMT_SCH_QUERY_RSP;
msg.pData = rmsg;
2024-07-08 01:37:47 +00:00
code = schHandleResponseMsg(pJob, task, task->seriesId, task->execId, &msg, 0);
2024-07-08 01:37:47 +00:00
2024-02-02 08:05:25 +00:00
ASSERT_EQ(code, 0);
}
2021-12-25 13:29:42 +00:00
2022-03-03 07:07:33 +00:00
pIter = taosHashIterate(pJob->execTasks, pIter);
2022-10-13 08:58:43 +00:00
}
2021-12-25 13:29:42 +00:00
2022-05-24 09:49:22 +00:00
while (true) {
if (queryDone) {
break;
}
taosUsleep(10000);
}
2022-10-13 08:58:43 +00:00
2022-03-19 16:47:45 +00:00
TdThreadAttr thattr;
ASSERT_EQ(0, taosThreadAttrInit(&thattr));
2021-12-25 13:29:42 +00:00
2022-03-19 16:47:45 +00:00
TdThread thread1;
ASSERT_EQ(0, taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job));
2021-12-25 13:29:42 +00:00
2022-10-13 08:58:43 +00:00
void *data = NULL;
2022-07-05 10:12:01 +00:00
req.syncReq = true;
req.pFetchRes = &data;
code = schedulerFetchRows(job, &req);
2021-12-25 13:29:42 +00:00
ASSERT_EQ(code, 0);
SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data;
ASSERT_EQ(pRsp->completed, 1);
ASSERT_EQ(pRsp->numOfRows, 10);
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(data);
2021-12-25 13:29:42 +00:00
(void)schReleaseJob(job);
2024-07-08 01:37:47 +00:00
2024-02-02 08:05:25 +00:00
schedulerDestroy();
2021-12-25 13:29:42 +00:00
2022-07-01 13:01:35 +00:00
schedulerFreeJob(&job, 0);
2022-01-11 02:14:06 +00:00
(void)taosThreadJoin(thread1, NULL);
2024-12-20 05:52:53 +00:00
schMgmt.jobRef = -1;
2021-12-24 11:01:48 +00:00
}
2021-12-20 05:24:30 +00:00
2024-12-20 05:52:53 +00:00
TEST(queryTest, rescheduleCase) {
void *mockPointer = (void *)0x1;
char *clusterId = "cluster1";
char *dbname = "1.db1";
char *tablename = "table1";
SVgroupInfo vgInfo = {0};
int64_t job = 0;
SQueryPlan *dag = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN, (SNode**)&dag);
ASSERT_EQ(code, TSDB_CODE_SUCCESS);
SArray *qnodeList = taosArrayInit(1, sizeof(SQueryNodeLoad));
SQueryNodeLoad load = {0};
load.addr.epSet.numOfEps = 1;
TAOS_STRCPY(load.addr.epSet.eps[0].fqdn, "qnode0.ep");
load.addr.epSet.eps[0].port = 6031;
ASSERT_NE(taosArrayPush(qnodeList, &load), nullptr);
2024-12-20 05:52:53 +00:00
2024-12-23 00:49:16 +00:00
TAOS_STRCPY(load.addr.epSet.eps[0].fqdn, "qnode1.ep");
ASSERT_NE(taosArrayPush(qnodeList, &load), nullptr);
2024-12-23 00:49:16 +00:00
2024-12-20 05:52:53 +00:00
code = schedulerInit();
ASSERT_EQ(code, 0);
schtBuildQueryDag(dag);
schtSetPlanToString();
schtSetExecNode();
schtSetAsyncSendMsgToServer();
int32_t queryDone = 0;
SRequestConnInfo conn = {0};
conn.pTrans = mockPointer;
SSchedulerReq req = {0};
req.pConn = &conn;
req.pNodeList = qnodeList;
req.pDag = dag;
req.sql = "select * from tb";
req.execFp = schtQueryCb;
req.cbParam = &queryDone;
code = schedulerExecJob(&req, &job);
ASSERT_EQ(code, 0);
SSchJob *pJob = NULL;
code = schAcquireJob(job, &pJob);
ASSERT_EQ(code, 0);
schedulerEnableReSchedule(true);
void *pIter = taosHashIterate(pJob->execTasks, NULL);
while (pIter) {
SSchTask *task = *(SSchTask **)pIter;
task->timeoutUsec = -1;
code = schRescheduleTask(pJob, task);
ASSERT_EQ(code, 0);
task->timeoutUsec = SCH_DEFAULT_TASK_TIMEOUT_USEC;
pIter = taosHashIterate(pJob->execTasks, pIter);
}
pIter = taosHashIterate(pJob->execTasks, NULL);
while (pIter) {
SSchTask *task = *(SSchTask **)pIter;
SDataBuf msg = {0};
void *rmsg = NULL;
ASSERT_EQ(0, schtBuildQueryRspMsg(&msg.len, &rmsg));
2024-12-20 05:52:53 +00:00
msg.msgType = TDMT_SCH_QUERY_RSP;
msg.pData = rmsg;
code = schHandleResponseMsg(pJob, task, task->seriesId, task->execId, &msg, 0);
2024-12-20 05:52:53 +00:00
ASSERT_EQ(code, 0);
pIter = taosHashIterate(pJob->execTasks, pIter);
}
pIter = taosHashIterate(pJob->execTasks, NULL);
while (pIter) {
SSchTask *task = *(SSchTask **)pIter;
task->timeoutUsec = -1;
code = schRescheduleTask(pJob, task);
ASSERT_EQ(code, 0);
task->timeoutUsec = SCH_DEFAULT_TASK_TIMEOUT_USEC;
pIter = taosHashIterate(pJob->execTasks, pIter);
}
pIter = taosHashIterate(pJob->execTasks, NULL);
while (pIter) {
SSchTask *task = *(SSchTask **)pIter;
if (JOB_TASK_STATUS_EXEC == task->status) {
SDataBuf msg = {0};
void *rmsg = NULL;
ASSERT_EQ(0, schtBuildQueryRspMsg(&msg.len, &rmsg));
2024-12-20 05:52:53 +00:00
msg.msgType = TDMT_SCH_QUERY_RSP;
msg.pData = rmsg;
code = schHandleResponseMsg(pJob, task, task->seriesId, task->execId, &msg, 0);
2024-12-20 05:52:53 +00:00
ASSERT_EQ(code, 0);
}
pIter = taosHashIterate(pJob->execTasks, pIter);
}
while (true) {
if (queryDone) {
break;
}
taosUsleep(10000);
}
TdThreadAttr thattr;
ASSERT_EQ(0, taosThreadAttrInit(&thattr));
2024-12-20 05:52:53 +00:00
TdThread thread1;
ASSERT_EQ(0, taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job));
2024-12-20 05:52:53 +00:00
void *data = NULL;
req.syncReq = true;
req.pFetchRes = &data;
code = schedulerFetchRows(job, &req);
ASSERT_EQ(code, 0);
SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data;
ASSERT_EQ(pRsp->completed, 1);
ASSERT_EQ(pRsp->numOfRows, 10);
taosMemoryFreeClear(data);
(void)schReleaseJob(job);
schedulerDestroy();
schedulerFreeJob(&job, 0);
(void)taosThreadJoin(thread1, NULL);
schMgmt.jobRef = -1;
}
2022-03-21 00:32:22 +00:00
TEST(queryTest, readyFirstCase) {
2022-10-13 08:58:43 +00:00
void *mockPointer = (void *)0x1;
char *clusterId = "cluster1";
char *dbname = "1.db1";
char *tablename = "table1";
2022-03-21 00:32:22 +00:00
SVgroupInfo vgInfo = {0};
2022-10-13 08:58:43 +00:00
int64_t job = 0;
2024-07-21 10:20:30 +00:00
SQueryPlan *dag = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN, (SNode**)&dag);
ASSERT_EQ(TSDB_CODE_SUCCESS, code);
2022-03-21 00:32:22 +00:00
2024-02-19 06:02:16 +00:00
SArray *qnodeList = taosArrayInit(1, sizeof(SQueryNodeLoad));
2022-03-21 00:32:22 +00:00
2024-02-19 06:02:16 +00:00
SQueryNodeLoad load = {0};
load.addr.epSet.numOfEps = 1;
TAOS_STRCPY(load.addr.epSet.eps[0].fqdn, "qnode0.ep");
2024-02-19 06:02:16 +00:00
load.addr.epSet.eps[0].port = 6031;
ASSERT_NE(nullptr, taosArrayPush(qnodeList, &load));
2022-10-13 08:58:43 +00:00
2024-07-21 10:20:30 +00:00
code = schedulerInit();
2022-03-21 00:32:22 +00:00
ASSERT_EQ(code, 0);
2024-02-02 08:05:25 +00:00
schtBuildQueryDag(dag);
2022-03-21 00:32:22 +00:00
schtSetPlanToString();
schtSetExecNode();
schtSetAsyncSendMsgToServer();
2022-05-24 09:49:22 +00:00
2022-10-13 08:58:43 +00:00
int32_t queryDone = 0;
2022-06-11 00:22:18 +00:00
SRequestConnInfo conn = {0};
conn.pTrans = mockPointer;
2022-10-13 08:58:43 +00:00
SSchedulerReq req = {0};
2022-06-11 00:22:18 +00:00
req.pConn = &conn;
req.pNodeList = qnodeList;
2024-02-02 08:05:25 +00:00
req.pDag = dag;
2022-06-11 00:22:18 +00:00
req.sql = "select * from tb";
2022-06-29 09:00:48 +00:00
req.execFp = schtQueryCb;
2022-07-05 08:10:38 +00:00
req.cbParam = &queryDone;
2022-07-02 08:59:49 +00:00
code = schedulerExecJob(&req, &job);
2022-03-21 00:32:22 +00:00
ASSERT_EQ(code, 0);
2024-07-16 11:03:12 +00:00
SSchJob *pJob = NULL;
code = schAcquireJob(job, &pJob);
ASSERT_EQ(code, 0);
2022-05-27 08:01:40 +00:00
void *pIter = taosHashIterate(pJob->execTasks, NULL);
2022-03-21 00:32:22 +00:00
while (pIter) {
SSchTask *task = *(SSchTask **)pIter;
2024-02-02 08:05:25 +00:00
SDataBuf msg = {0};
2024-07-08 01:37:47 +00:00
void *rmsg = NULL;
ASSERT_EQ(0, schtBuildQueryRspMsg(&msg.len, &rmsg));
2024-02-02 08:05:25 +00:00
msg.msgType = TDMT_SCH_QUERY_RSP;
msg.pData = rmsg;
2024-07-08 01:37:47 +00:00
code = schHandleResponseMsg(pJob, task, task->seriesId, task->execId, &msg, 0);
2022-10-13 08:58:43 +00:00
2022-03-21 00:32:22 +00:00
ASSERT_EQ(code, 0);
pIter = taosHashIterate(pJob->execTasks, pIter);
2022-10-13 08:58:43 +00:00
}
2022-03-21 00:32:22 +00:00
pIter = taosHashIterate(pJob->execTasks, NULL);
while (pIter) {
SSchTask *task = *(SSchTask **)pIter;
2024-02-02 08:05:25 +00:00
if (JOB_TASK_STATUS_EXEC == task->status) {
SDataBuf msg = {0};
2024-07-08 01:37:47 +00:00
void *rmsg = NULL;
ASSERT_EQ(0, schtBuildQueryRspMsg(&msg.len, &rmsg));
2024-02-02 08:05:25 +00:00
msg.msgType = TDMT_SCH_QUERY_RSP;
msg.pData = rmsg;
2024-07-08 01:37:47 +00:00
code = schHandleResponseMsg(pJob, task, task->seriesId, task->execId, &msg, 0);
2024-07-08 01:37:47 +00:00
2024-02-02 08:05:25 +00:00
ASSERT_EQ(code, 0);
}
2022-10-13 08:58:43 +00:00
2022-03-21 00:32:22 +00:00
pIter = taosHashIterate(pJob->execTasks, pIter);
2022-10-13 08:58:43 +00:00
}
2022-03-21 00:32:22 +00:00
2022-05-24 09:49:22 +00:00
while (true) {
if (queryDone) {
break;
}
taosUsleep(10000);
}
2022-03-21 00:32:22 +00:00
2022-03-21 08:43:27 +00:00
TdThreadAttr thattr;
ASSERT_EQ(0, taosThreadAttrInit(&thattr));
2022-03-21 00:32:22 +00:00
2022-03-21 08:43:27 +00:00
TdThread thread1;
ASSERT_EQ(0, taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job));
2022-03-21 00:32:22 +00:00
2022-10-13 08:58:43 +00:00
void *data = NULL;
2022-07-05 10:12:01 +00:00
req.syncReq = true;
req.pFetchRes = &data;
code = schedulerFetchRows(job, &req);
2022-03-21 00:32:22 +00:00
ASSERT_EQ(code, 0);
SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data;
ASSERT_EQ(pRsp->completed, 1);
ASSERT_EQ(pRsp->numOfRows, 10);
2022-03-26 07:03:22 +00:00
taosMemoryFreeClear(data);
2022-03-21 00:32:22 +00:00
(void)schReleaseJob(job);
2022-03-21 00:32:22 +00:00
schedulerDestroy();
2024-02-02 08:05:25 +00:00
schedulerFreeJob(&job, 0);
2024-05-29 09:20:56 +00:00
(void)taosThreadJoin(thread1, NULL);
2024-12-20 05:52:53 +00:00
schMgmt.jobRef = -1;
2022-03-21 00:32:22 +00:00
}
2022-03-05 03:21:09 +00:00
TEST(queryTest, flowCtrlCase) {
2022-10-13 08:58:43 +00:00
void *mockPointer = (void *)0x1;
char *clusterId = "cluster1";
char *dbname = "1.db1";
char *tablename = "table1";
2022-03-05 03:21:09 +00:00
SVgroupInfo vgInfo = {0};
2022-10-13 08:58:43 +00:00
int64_t job = 0;
2024-07-21 10:20:30 +00:00
SQueryPlan *dag = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN, (SNode**)&dag);
ASSERT_EQ(TSDB_CODE_SUCCESS, code);
2022-03-05 03:21:09 +00:00
schtInitLogFile();
2022-03-11 08:49:07 +00:00
taosSeedRand(taosGetTimestampSec());
2022-10-13 08:58:43 +00:00
2024-02-19 06:02:16 +00:00
SArray *qnodeList = taosArrayInit(1, sizeof(SQueryNodeLoad));
SQueryNodeLoad load = {0};
load.addr.epSet.numOfEps = 1;
TAOS_STRCPY(load.addr.epSet.eps[0].fqdn, "qnode0.ep");
2024-02-19 06:02:16 +00:00
load.addr.epSet.eps[0].port = 6031;
ASSERT_NE(nullptr, taosArrayPush(qnodeList, &load));
2022-03-05 03:21:09 +00:00
2024-07-21 10:20:30 +00:00
code = schedulerInit();
2022-03-05 03:21:09 +00:00
ASSERT_EQ(code, 0);
2024-02-02 08:05:25 +00:00
schtBuildQueryFlowCtrlDag(dag);
2022-03-05 03:21:09 +00:00
schtSetPlanToString();
schtSetExecNode();
schtSetAsyncSendMsgToServer();
2022-05-24 09:49:22 +00:00
ASSERT_EQ(0, initTaskQueue());
2024-02-02 08:05:25 +00:00
2022-10-13 08:58:43 +00:00
int32_t queryDone = 0;
2022-06-11 00:22:18 +00:00
SRequestConnInfo conn = {0};
conn.pTrans = mockPointer;
2022-10-13 08:58:43 +00:00
SSchedulerReq req = {0};
2022-06-11 00:22:18 +00:00
req.pConn = &conn;
req.pNodeList = qnodeList;
2024-02-02 08:05:25 +00:00
req.pDag = dag;
2022-06-11 00:22:18 +00:00
req.sql = "select * from tb";
2022-06-29 09:00:48 +00:00
req.execFp = schtQueryCb;
2022-07-05 08:10:38 +00:00
req.cbParam = &queryDone;
2022-06-11 00:22:18 +00:00
2022-07-02 08:59:49 +00:00
code = schedulerExecJob(&req, &job);
2022-03-05 03:21:09 +00:00
ASSERT_EQ(code, 0);
2024-07-16 11:03:12 +00:00
SSchJob *pJob = NULL;
code = schAcquireJob(job, &pJob);
ASSERT_EQ(code, 0);
2022-03-05 03:21:09 +00:00
2024-02-02 08:05:25 +00:00
while (!queryDone) {
2022-03-05 09:19:21 +00:00
void *pIter = taosHashIterate(pJob->execTasks, NULL);
while (pIter) {
SSchTask *task = *(SSchTask **)pIter;
2022-03-05 03:21:09 +00:00
2024-02-02 08:05:25 +00:00
if (JOB_TASK_STATUS_EXEC == task->status && 0 != task->lastMsgType) {
SDataBuf msg = {0};
2024-07-08 01:37:47 +00:00
void *rmsg = NULL;
ASSERT_EQ(0, schtBuildQueryRspMsg(&msg.len, &rmsg));
2024-02-02 08:05:25 +00:00
msg.msgType = TDMT_SCH_QUERY_RSP;
msg.pData = rmsg;
2024-07-08 01:37:47 +00:00
code = schHandleResponseMsg(pJob, task, task->seriesId, task->execId, &msg, 0);
2024-07-08 01:37:47 +00:00
2022-03-05 09:19:21 +00:00
ASSERT_EQ(code, 0);
}
2022-10-13 08:58:43 +00:00
2024-02-02 08:05:25 +00:00
pIter = taosHashIterate(pJob->execTasks, pIter);
2022-05-24 09:49:22 +00:00
}
}
2022-03-05 03:21:09 +00:00
2022-03-19 16:47:45 +00:00
TdThreadAttr thattr;
ASSERT_EQ(0, taosThreadAttrInit(&thattr));
2022-03-05 03:21:09 +00:00
2022-03-19 16:47:45 +00:00
TdThread thread1;
ASSERT_EQ(0, taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job));
2022-03-05 03:21:09 +00:00
2022-10-13 08:58:43 +00:00
void *data = NULL;
2022-07-05 10:12:01 +00:00
req.syncReq = true;
req.pFetchRes = &data;
code = schedulerFetchRows(job, &req);
2022-03-05 03:21:09 +00:00
ASSERT_EQ(code, 0);
SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data;
ASSERT_EQ(pRsp->completed, 1);
ASSERT_EQ(pRsp->numOfRows, 10);
2022-03-25 16:29:53 +00:00
taosMemoryFreeClear(data);
2022-03-05 03:21:09 +00:00
(void)schReleaseJob(job);
2022-03-05 03:21:09 +00:00
schedulerDestroy();
2024-02-02 08:05:25 +00:00
schedulerFreeJob(&job, 0);
2024-05-29 09:20:56 +00:00
(void)taosThreadJoin(thread1, NULL);
2024-12-20 05:52:53 +00:00
schMgmt.jobRef = -1;
cleanupTaskQueue();
2022-03-05 03:21:09 +00:00
}
2021-12-20 05:24:30 +00:00
2021-12-26 12:05:24 +00:00
TEST(insertTest, normalCase) {
2022-10-13 08:58:43 +00:00
void *mockPointer = (void *)0x1;
char *clusterId = "cluster1";
char *dbname = "1.db1";
char *tablename = "table1";
2021-12-26 12:05:24 +00:00
SVgroupInfo vgInfo = {0};
2024-07-21 10:20:30 +00:00
SQueryPlan *dag = NULL;
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN, (SNode**)&dag);
ASSERT_EQ(TSDB_CODE_SUCCESS, code);
2022-10-13 08:58:43 +00:00
uint64_t numOfRows = 0;
2022-01-11 02:14:06 +00:00
2024-02-19 06:02:16 +00:00
SArray *qnodeList = taosArrayInit(1, sizeof(SQueryNodeLoad));
2021-12-26 12:05:24 +00:00
2024-02-19 06:02:16 +00:00
SQueryNodeLoad load = {0};
load.addr.epSet.numOfEps = 1;
TAOS_STRCPY(load.addr.epSet.eps[0].fqdn, "qnode0.ep");
2024-02-19 06:02:16 +00:00
load.addr.epSet.eps[0].port = 6031;
ASSERT_NE(nullptr, taosArrayPush(qnodeList, &load));
2022-10-13 08:58:43 +00:00
2024-07-21 10:20:30 +00:00
code = schedulerInit();
2021-12-26 12:05:24 +00:00
ASSERT_EQ(code, 0);
2024-02-02 08:05:25 +00:00
schtBuildInsertDag(dag);
2021-12-26 12:05:24 +00:00
schtSetPlanToString();
2022-01-18 06:12:25 +00:00
schtSetAsyncSendMsgToServer();
2021-12-26 12:05:24 +00:00
2022-03-19 16:47:45 +00:00
TdThreadAttr thattr;
ASSERT_EQ(0, taosThreadAttrInit(&thattr));
2021-12-26 12:05:24 +00:00
2024-02-20 09:06:41 +00:00
schtJobDone = false;
2022-03-19 16:47:45 +00:00
TdThread thread1;
ASSERT_EQ(0, taosThreadCreate(&(thread1), &thattr, schtSendRsp, &insertJobRefId));
2021-12-31 03:23:44 +00:00
2024-02-02 08:05:25 +00:00
int32_t queryDone = 0;
2022-06-11 00:22:18 +00:00
SRequestConnInfo conn = {0};
conn.pTrans = mockPointer;
2022-10-13 08:58:43 +00:00
SSchedulerReq req = {0};
2022-06-11 00:22:18 +00:00
req.pConn = &conn;
req.pNodeList = qnodeList;
2024-02-02 08:05:25 +00:00
req.pDag = dag;
2022-06-11 00:22:18 +00:00
req.sql = "insert into tb values(now,1)";
2022-06-29 09:00:48 +00:00
req.execFp = schtQueryCb;
2024-02-02 08:05:25 +00:00
req.cbParam = &queryDone;
2022-10-13 08:58:43 +00:00
2022-07-05 10:12:01 +00:00
code = schedulerExecJob(&req, &insertJobRefId);
2021-12-26 12:05:24 +00:00
ASSERT_EQ(code, 0);
2024-02-20 09:06:41 +00:00
while (true) {
if (schtJobDone) {
break;
}
taosUsleep(10000);
}
2022-07-01 13:01:35 +00:00
schedulerFreeJob(&insertJobRefId, 0);
2022-01-18 06:12:25 +00:00
2022-10-13 08:58:43 +00:00
schedulerDestroy();
2024-05-29 09:20:56 +00:00
(void)taosThreadJoin(thread1, NULL);
2024-12-20 05:52:53 +00:00
schMgmt.jobRef = -1;
2021-12-26 12:05:24 +00:00
}
2022-01-11 02:14:06 +00:00
TEST(multiThread, forceFree) {
2022-03-19 16:47:45 +00:00
TdThreadAttr thattr;
ASSERT_EQ(0, taosThreadAttrInit(&thattr));
2021-12-26 12:05:24 +00:00
2022-03-19 16:47:45 +00:00
TdThread thread1, thread2, thread3;
ASSERT_EQ(0, taosThreadCreate(&(thread1), &thattr, schtRunJobThread, NULL));
2024-07-08 01:37:47 +00:00
// taosThreadCreate(&(thread2), &thattr, schtFreeJobThread, NULL);
ASSERT_EQ(0, taosThreadCreate(&(thread3), &thattr, schtFetchRspThread, NULL));
2022-01-11 02:14:06 +00:00
2022-01-18 11:32:29 +00:00
while (true) {
if (schtTestDeadLoop) {
2022-03-10 03:56:11 +00:00
taosSsleep(1);
2022-01-18 11:32:29 +00:00
} else {
2022-03-10 03:56:11 +00:00
taosSsleep(schtTestMTRunSec);
2022-01-18 11:32:29 +00:00
break;
}
}
2022-10-13 08:58:43 +00:00
2022-01-18 11:32:29 +00:00
schtTestStop = true;
2024-07-08 01:37:47 +00:00
// taosSsleep(3);
2024-12-20 05:52:53 +00:00
schMgmt.jobRef = -1;
2022-01-11 02:14:06 +00:00
}
2021-12-26 12:05:24 +00:00
2024-12-20 05:52:53 +00:00
TEST(otherTest, function) {
// excpet test
(void)schReleaseJob(0);
schFreeRpcCtx(NULL);
2024-07-17 01:12:42 +00:00
char* ep = NULL;
ASSERT_EQ(schDumpEpSet(NULL, &ep), TSDB_CODE_SUCCESS);
2024-02-18 06:57:29 +00:00
ASSERT_EQ(strcmp(schGetOpStr(SCH_OP_NULL), "NULL"), 0);
ASSERT_EQ(strcmp(schGetOpStr((SCH_OP_TYPE)100), "UNKNOWN"), 0);
2024-12-20 05:52:53 +00:00
SSchTaskCallbackParam param = {0};
SDataBuf dataBuf = {0};
dataBuf.pData = taosMemoryMalloc(1);
dataBuf.pEpSet = (SEpSet*)taosMemoryMalloc(sizeof(*dataBuf.pEpSet));
ASSERT_EQ(schHandleNotifyCallback(&param, &dataBuf, TSDB_CODE_SUCCESS), TSDB_CODE_SUCCESS);
SSchCallbackParamHeader param2 = {0};
dataBuf.pData = taosMemoryMalloc(1);
dataBuf.pEpSet = (SEpSet*)taosMemoryMalloc(sizeof(*dataBuf.pEpSet));
schHandleLinkBrokenCallback(&param2, &dataBuf, TSDB_CODE_SUCCESS);
param2.isHbParam = true;
dataBuf.pData = taosMemoryMalloc(1);
dataBuf.pEpSet = (SEpSet*)taosMemoryMalloc(sizeof(*dataBuf.pEpSet));
schHandleLinkBrokenCallback(&param2, &dataBuf, TSDB_CODE_SUCCESS);
schMgmt.jobRef = -1;
}
2024-12-23 08:07:47 +00:00
TEST(otherTest, branch) {
SSchJob job = {0};
SSchTask task = {0};
2024-12-25 01:59:26 +00:00
memset(&schMgmt, 0, sizeof(schMgmt));
2024-12-23 08:07:47 +00:00
schValidateRspMsgType(&job, &task, TDMT_SCH_MERGE_FETCH_RSP);
task.lastMsgType = TDMT_SCH_MERGE_FETCH_RSP - 1;
schValidateRspMsgType(&job, &task, TDMT_SCH_MERGE_FETCH_RSP);
schValidateRspMsgType(&job, &task, 0);
schValidateRspMsgType(&job, &task, TDMT_SCH_QUERY_RSP);
task.lastMsgType = TDMT_SCH_QUERY_RSP - 1;
schValidateRspMsgType(&job, &task, TDMT_SCH_QUERY_RSP);
schProcessFetchRsp(&job, &task, NULL, -1);
schProcessFetchRsp(&job, &task, NULL, 0);
job.fetchRes = (void*)0x1;
schProcessFetchRsp(&job, &task, (char*)taosMemoryMalloc(0), 0);
job.fetchRes = NULL;
SDataBuf databuf = {0};
databuf.msgType = TDMT_VND_ALTER_TABLE_RSP;
job.status = JOB_TASK_STATUS_FAIL;
schProcessResponseMsg(&job, &task, &databuf, 0);
databuf.msgType = TDMT_VND_SUBMIT_RSP;
databuf.pData = taosMemoryMalloc(0);
job.status = JOB_TASK_STATUS_FAIL;
schProcessResponseMsg(&job, &task, &databuf, 0);
databuf.msgType = TDMT_VND_DELETE_RSP;
databuf.pData = taosMemoryMalloc(0);
job.status = JOB_TASK_STATUS_FAIL;
schProcessResponseMsg(&job, &task, &databuf, 0);
databuf.msgType = TDMT_SCH_QUERY_RSP;
job.status = JOB_TASK_STATUS_FAIL;
schProcessResponseMsg(&job, &task, &databuf, 0);
databuf.msgType = TDMT_SCH_QUERY_RSP;
databuf.pData = taosMemoryMalloc(0);
job.status = JOB_TASK_STATUS_FAIL;
schProcessResponseMsg(&job, &task, &databuf, 0);
databuf.msgType = TDMT_SCH_EXPLAIN_RSP;
job.status = JOB_TASK_STATUS_FAIL;
schProcessResponseMsg(&job, &task, &databuf, 0);
databuf.msgType = TDMT_SCH_EXPLAIN_RSP;
databuf.pData = taosMemoryMalloc(0);
job.status = JOB_TASK_STATUS_FAIL;
schProcessResponseMsg(&job, &task, &databuf, 0);
2024-12-25 01:59:26 +00:00
job.status = 0;
2024-12-23 08:07:47 +00:00
job.attr.explainMode = EXPLAIN_MODE_ANALYZE;
databuf.msgType = TDMT_SCH_EXPLAIN_RSP;
databuf.pData = taosMemoryMalloc(0);
job.status = JOB_TASK_STATUS_FAIL;
job.fetchRes = (void*)0x1;
schProcessResponseMsg(&job, &task, &databuf, 0);
job.fetchRes = NULL;
job.attr.explainMode = EXPLAIN_MODE_ANALYZE;
databuf.msgType = TDMT_SCH_EXPLAIN_RSP;
databuf.pData = taosMemoryMalloc(0);
job.status = JOB_TASK_STATUS_FAIL;
schProcessResponseMsg(&job, &task, &databuf, 0);
databuf.msgType = TDMT_SCH_DROP_TASK_RSP;
job.status = JOB_TASK_STATUS_FAIL;
schProcessResponseMsg(&job, &task, &databuf, 0);
databuf.msgType = TDMT_SCH_LINK_BROKEN;
job.status = JOB_TASK_STATUS_FAIL;
schProcessResponseMsg(&job, &task, &databuf, 0);
databuf.msgType = 0;
job.status = JOB_TASK_STATUS_FAIL;
schProcessResponseMsg(&job, &task, &databuf, 0);
databuf.pData = taosMemoryMalloc(0);
schHandleHbCallback(NULL, &databuf, 0);
__async_send_cb_fn_t fp = NULL;
schGetCallbackFp(TDMT_SCH_TASK_NOTIFY, &fp);
schGetCallbackFp(0, &fp);
SQueryNodeEpId ep = {0};
schBuildAndSendHbMsg(&ep, NULL);
schBuildAndSendMsg(&job, &task, NULL, 0, NULL);
2024-12-25 01:59:26 +00:00
SSchLevel level = {0};
SSubplan subplan;
memset(&subplan, 0, sizeof(subplan));
job.attr.type = JOB_TYPE_QUERY;
2024-12-25 01:59:26 +00:00
schMgmt.cfg.schPolicy = SCH_ALL;
task.plan = &subplan;
schInitTaskRetryTimes(&job, &task, &level);
job.attr.type = JOB_TYPE_INSERT;
2024-12-25 01:59:26 +00:00
memset(&schMgmt.cfg, 0, sizeof(schMgmt.cfg));
memset(&level, 0, sizeof(level));
schRecordTaskSucceedNode(&job, &task);
schDropTaskExecNode(&job, &task, NULL, 0);
task.execNodes = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
schDropTaskExecNode(&job, &task, NULL, 0);
int32_t execId = 0;
task.execId = 1;
(void)taosHashPut(task.execNodes, &execId, sizeof(execId), &execId, sizeof(execId));
schDropTaskExecNode(&job, &task, NULL, execId);
task.execId = 0;
taosHashCleanup(task.execNodes);
task.execNodes = NULL;
job.status = JOB_TASK_STATUS_FAIL;
schProcessOnTaskFailure(&job, &task, 0);
job.status = 0;
task.status = JOB_TASK_STATUS_FAIL;
schProcessOnTaskFailure(&job, &task, 0);
task.status = 0;
task.level = &level;
schProcessOnTaskFailure(&job, &task, TSDB_CODE_SCH_TIMEOUT_ERROR);
memset(&level, 0, sizeof(level));
task.level = NULL;
subplan.subplanType = SUBPLAN_TYPE_SCAN;
task.plan = &subplan;
SEpSet epset = {0};
epset.numOfEps = 127;
schChkUpdateRedirectCtx(&job, &task, &epset, 0);
schChkUpdateRedirectCtx(&job, &task, NULL, 0);
task.plan = NULL;
schPushTaskToExecList(&job, &task);
job.execTasks = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK);
taosHashPut(job.execTasks, &task.taskId, sizeof(task.taskId), &task, POINTER_BYTES);
schPushTaskToExecList(&job, &task);
taosHashCleanup(job.execTasks);
job.execTasks = NULL;
bool needRetry = false;
task.timeoutUsec = SCH_MAX_TASK_TIMEOUT_USEC / 2 + 1;
task.retryTimes = 0;
task.maxRetryTimes = 0;
schTaskCheckSetRetry(&job, &task, TSDB_CODE_SCH_TIMEOUT_ERROR, &needRetry);
task.execId = 0;
task.retryTimes = 0;
task.maxRetryTimes = 100;
task.maxExecTimes = 1;
schTaskCheckSetRetry(&job, &task, TSDB_CODE_SCH_TIMEOUT_ERROR, &needRetry);
task.execId = 0;
task.retryTimes = 0;
task.maxRetryTimes = 100;
task.maxExecTimes = 100;
task.lastMsgType = TDMT_SCH_LINK_BROKEN;
schTaskCheckSetRetry(&job, &task, TSDB_CODE_SCH_TIMEOUT_ERROR, &needRetry);
schSetAddrsFromNodeList(&job, &task);
schSwitchTaskCandidateAddr(&job, &task);
task.candidateAddrs = taosArrayInit(SCHEDULE_DEFAULT_MAX_NODE_NUM, sizeof(SQueryNodeAddr));
SQueryNodeAddr addr = {0};
taosArrayPush(task.candidateAddrs, &addr);
taosArrayPush(task.candidateAddrs, &addr);
schMgmt.cfg.schPolicy = SCH_LOAD_SEQ;
task.candidateIdx = 1;
schSwitchTaskCandidateAddr(&job, &task);
schMgmt.cfg.schPolicy = SCH_RANDOM;
schSwitchTaskCandidateAddr(&job, &task);
taosArrayDestroy(task.candidateAddrs);
task.candidateAddrs = NULL;
memset(&schMgmt.cfg, 0, sizeof(schMgmt.cfg));
task.candidateIdx = 0;
schDropTaskOnExecNode(&job, &task);
schNotifyTaskOnExecNode(&job, &task, TASK_NOTIFY_FINISHED);
schLaunchRemoteTask(&job, &task);
SSchTaskCtx* pCtx = (SSchTaskCtx*)taosMemoryCalloc(1, sizeof(SSchTaskCtx));
pCtx->jobRid = -1;
schLaunchTaskImpl((void*)pCtx);
task.plan = &subplan;
subplan.subplanType = SUBPLAN_TYPE_SCAN;
job.attr.needFlowCtrl = true;
level.taskNum = 1000;
task.level = &level;
schLaunchTask(&job, &task);
task.plan = NULL;
task.level = NULL;
job.attr.needFlowCtrl = false;
SSchTimerParam param = {0};
param.rId = -1;
schHandleTimerEvent(&param, NULL);
job.execTasks = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_ENTRY_LOCK);
task.delayExecMs = 1;
schMgmt.timer = NULL;
schDelayLaunchTask(&job, &task);
task.delayExecMs = 0;
taosHashCleanup(job.execTasks);
job.execTasks = NULL;
job.fetchRes = (void*)0x1;
schLaunchFetchTask(&job);
job.fetchRes = NULL;
job.fetchTask = &task;
job.attr.localExec = true;
job.attr.type = JOB_TYPE_QUERY;
2024-12-25 01:59:26 +00:00
subplan.subplanType = SUBPLAN_TYPE_MERGE;
task.plan = &subplan;
void* p = taosMemoryCalloc(1, 1024);
schMgmt.queryMgmt = p;
schLaunchFetchTask(&job);
memset(&job, 0, sizeof(job));
memset(&subplan, 0, sizeof(subplan));
task.plan = NULL;
taosMemoryFreeClear(schMgmt.queryMgmt);
// flow ctrl
job.flowCtrl = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK);
SEp sep = {0};
SSchFlowControl nctrl = {0};
nctrl.taskList = taosArrayInit(1, POINTER_BYTES);
taosHashPut(job.flowCtrl, &sep, sizeof(SEp), &nctrl, sizeof(nctrl));
schFreeFlowCtrl(&job);
2024-12-23 08:07:47 +00:00
schMgmt.jobRef = -1;
}
2024-12-20 05:52:53 +00:00
void schtReset() {
insertJobRefId = 0;
queryJobRefId = 0;
schtJobDone = false;
schtMergeTemplateId = 0x4;
schtFetchTaskId = 0;
schtQueryId = 1;
schtTestStop = false;
schtTestDeadLoop = false;
schtTestMTRunSec = 1;
schtTestPrintNum = 1000;
schtStartFetch = 0;
}
2022-10-13 08:58:43 +00:00
int main(int argc, char **argv) {
2024-07-08 01:37:47 +00:00
schtInitLogFile();
2024-07-17 01:12:42 +00:00
if (rpcInit()) {
TD_ALWAYS_ASSERT(0);
2024-07-17 01:12:42 +00:00
}
2022-03-11 08:49:07 +00:00
taosSeedRand(taosGetTimestampSec());
2021-12-20 05:24:30 +00:00
testing::InitGoogleTest(&argc, argv);
2024-12-20 05:52:53 +00:00
int code = 0;
for (int32_t i = 0; i < 10; ++i) {
schtReset();
code = RUN_ALL_TESTS();
if (code) {
break;
}
}
return code;
2021-12-20 05:24:30 +00:00
}
2022-03-03 07:07:33 +00:00
#pragma GCC diagnostic pop