fix: add plan validation in scheduler

This commit is contained in:
dapan1121 2024-10-22 09:04:12 +08:00
parent 6a9fd0c95e
commit a2665ebc82
4 changed files with 35 additions and 10 deletions

View File

@ -76,8 +76,6 @@ int32_t schedulerExecJob(SSchedulerReq* pReq, int64_t* pJob);
int32_t schedulerFetchRows(int64_t jobId, SSchedulerReq* pReq); int32_t schedulerFetchRows(int64_t jobId, SSchedulerReq* pReq);
void schedulerFetchRowsA(int64_t job, schedulerFetchFp fp, void* param);
int32_t schedulerGetTasksStatus(int64_t job, SArray* pSub); int32_t schedulerGetTasksStatus(int64_t job, SArray* pSub);
void schedulerStopQueryHb(void* pTrans); void schedulerStopQueryHb(void* pTrans);
@ -100,6 +98,8 @@ void schedulerFreeJob(int64_t* job, int32_t errCode);
void schedulerDestroy(void); void schedulerDestroy(void);
int32_t schedulerValidatePlan(SQueryPlan* pPlan);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -43,6 +43,7 @@
#include "querytask.h" #include "querytask.h"
#include "functionMgt.h" #include "functionMgt.h"
#include "ttime.h" #include "ttime.h"
#include "scheduler.h"
namespace { namespace {
@ -3091,12 +3092,11 @@ void qptExecPlan(SReadHandle* pReadHandle, SNode* pNode, SExecTaskInfo* pTaskInf
dsDestroyDataSinker(handle); dsDestroyDataSinker(handle);
break; break;
} }
case QUERY_NODE_PHYSICAL_SUBPLAN: case QUERY_NODE_PHYSICAL_SUBPLAN: {
break; break;
}
case QUERY_NODE_PHYSICAL_PLAN: { case QUERY_NODE_PHYSICAL_PLAN: {
SSchJob job = {0}; qptCtx.result.code = schedulerValidatePlan((SQueryPlan*)pNode);
qptCtx.result.code = schValidateAndBuildJob((SQueryPlan*)pNode, &job);
schFreeJobImpl(&job);
break; break;
} }
case QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN: case QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN:

View File

@ -794,9 +794,11 @@ void schFreeJobImpl(void *job) {
} }
taosMemoryFree(pJob); taosMemoryFree(pJob);
int32_t jobNum = atomic_sub_fetch_32(&schMgmt.jobNum, 1); if (refId > 0) {
if (jobNum == 0) { int32_t jobNum = atomic_sub_fetch_32(&schMgmt.jobNum, 1);
schCloseJobRef(); if (jobNum == 0) {
schCloseJobRef();
}
} }
qDebug("QID:0x%" PRIx64 " sch job freed, refId:0x%" PRIx64 ", pointer:%p", queryId, refId, pJob); qDebug("QID:0x%" PRIx64 " sch job freed, refId:0x%" PRIx64 ", pointer:%p", queryId, refId, pJob);
@ -917,7 +919,7 @@ _return:
if (NULL == pJob) { if (NULL == pJob) {
qDestroyQueryPlan(pReq->pDag); qDestroyQueryPlan(pReq->pDag);
} else if (pJob->refId < 0) { } else if (pJob->refId <= 0) {
schFreeJobImpl(pJob); schFreeJobImpl(pJob);
} else { } else {
code = taosRemoveRef(schMgmt.jobRef, pJob->refId); code = taosRemoveRef(schMgmt.jobRef, pJob->refId);

View File

@ -224,3 +224,26 @@ void schedulerDestroy(void) {
qWorkerDestroy(&schMgmt.queryMgmt); qWorkerDestroy(&schMgmt.queryMgmt);
schMgmt.queryMgmt = NULL; schMgmt.queryMgmt = NULL;
} }
int32_t schedulerValidatePlan(SQueryPlan* pPlan) {
int32_t code = TSDB_CODE_SUCCESS;
SSchJob *pJob = taosMemoryCalloc(1, sizeof(SSchJob));
if (NULL == pJob) {
qError("QID:0x%" PRIx64 " calloc %d failed", pPlan->queryId, (int32_t)sizeof(SSchJob));
SCH_ERR_RET(terrno);
}
SCH_ERR_JRET(schValidateAndBuildJob(pPlan, pJob));
if (SCH_IS_EXPLAIN_JOB(pJob)) {
SCH_ERR_JRET(qExecExplainBegin(pPlan, &pJob->explainCtx, 0));
}
_return:
schFreeJobImpl(pJob);
return code;
}