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

1292 lines
33 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-07-08 01:37:47 +00:00
extern "C" int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDataBuf *pMsg,
int32_t rspCode);
2024-02-02 08:05:25 +00:00
extern "C" int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t rspCode);
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
2022-02-23 02:35:53 +00:00
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 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;
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;
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-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;
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 *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;
}
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;
scanPlan->execNodeStat.tableNum = taosRand() % 30;
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-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
2024-07-17 01:12:42 +00:00
(void)schHandleResponseMsg(pJob, task, 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
2024-02-02 08:05:25 +00:00
code = schHandleResponseMsg(pJob, pJob->fetchTask, 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
2022-01-18 06:12:25 +00:00
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
2022-01-18 11:32:29 +00:00
assert(code == 0 || code);
}
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);
assert(code == 0);
2022-01-18 11:32:29 +00:00
schtInitLogFile();
2024-07-21 10:20:30 +00:00
code = schedulerInit();
2022-01-18 11:32:29 +00:00
assert(code == 0);
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) {
assert(0);
}
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)) {
assert(0);
}
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);
2022-01-18 11:32:29 +00:00
assert(code == 0);
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) {
assert(0);
}
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))) {
assert(0);
}
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) {
assert(0);
}
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)) {
assert(0);
}
2024-02-02 08:05:25 +00:00
msg.msgType = TDMT_SCH_QUERY_RSP;
msg.pData = rmsg;
code = schHandleCallback(param, &msg, 0);
2022-01-18 11:32:29 +00:00
assert(code == 0 || code);
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) {
assert(0);
}
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)) {
assert(0);
}
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);
2022-01-18 11:32:29 +00:00
assert(code == 0 || code);
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);
2022-01-18 11:32:29 +00:00
assert(code == 0 || code);
if (0 == code) {
SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data;
assert(pRsp->completed == 1);
}
data = NULL;
2022-07-05 10:12:01 +00:00
code = schedulerFetchRows(queryJobRefId, &req);
2022-01-18 11:32:29 +00:00
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(taosArrayPush(qnodeList, &load) != NULL);
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(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
2024-02-02 08:05:25 +00:00
code = schHandleResponseMsg(pJob, task, 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(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
2024-02-02 08:05:25 +00:00
code = schHandleResponseMsg(pJob, task, 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(0 == taosThreadAttrInit(&thattr));
2021-12-25 13:29:42 +00:00
2022-03-19 16:47:45 +00:00
TdThread thread1;
assert(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);
2021-12-24 11:01:48 +00:00
}
2021-12-20 05:24:30 +00:00
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(NULL != 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(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
2024-02-02 08:05:25 +00:00
code = schHandleResponseMsg(pJob, task, 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(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
2024-02-02 08:05:25 +00:00
code = schHandleResponseMsg(pJob, task, 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(0 == taosThreadAttrInit(&thattr));
2022-03-21 00:32:22 +00:00
2022-03-21 08:43:27 +00:00
TdThread thread1;
assert(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);
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(NULL != 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(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(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
2024-02-02 08:05:25 +00:00
code = schHandleResponseMsg(pJob, task, 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(0 == taosThreadAttrInit(&thattr));
2022-03-05 03:21:09 +00:00
2022-03-19 16:47:45 +00:00
TdThread thread1;
assert(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);
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(NULL != 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(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(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);
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(0 == taosThreadAttrInit(&thattr));
2021-12-26 12:05:24 +00:00
2022-03-19 16:47:45 +00:00
TdThread thread1, thread2, thread3;
assert(0 == taosThreadCreate(&(thread1), &thattr, schtRunJobThread, NULL));
2024-07-08 01:37:47 +00:00
// taosThreadCreate(&(thread2), &thattr, schtFreeJobThread, NULL);
assert(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);
2022-01-11 02:14:06 +00:00
}
2021-12-26 12:05:24 +00:00
TEST(otherTest, otherCase) {
// 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);
}
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()) {
assert(0);
}
2022-03-11 08:49:07 +00:00
taosSeedRand(taosGetTimestampSec());
2021-12-20 05:24:30 +00:00
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
2022-03-03 07:07:33 +00:00
#pragma GCC diagnostic pop