TDengine/include/libs/executor/executor.h

311 lines
10 KiB
C
Raw Normal View History

2021-09-24 10:05:56 +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/>.
*/
#ifndef _TD_EXECUTOR_H_
#define _TD_EXECUTOR_H_
2025-05-09 02:03:35 +00:00
#include <stdint.h>
2025-05-14 09:41:51 +00:00
#include "tarray.h"
2021-09-24 10:05:56 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2022-03-10 11:05:58 +00:00
#include "query.h"
#include "storageapi.h"
2022-03-29 07:24:25 +00:00
#include "tcommon.h"
#include "tmsgcb.h"
2025-04-29 07:31:17 +00:00
#include "storageapi.h"
#include "functionMgt.h"
2022-01-18 06:12:25 +00:00
2022-01-08 08:28:44 +00:00
typedef void* qTaskInfo_t;
2022-01-11 02:51:23 +00:00
typedef void* DataSinkHandle;
2023-04-08 17:39:09 +00:00
2022-01-25 07:18:56 +00:00
struct SRpcMsg;
2022-01-11 02:51:23 +00:00
struct SSubplan;
typedef int32_t (*localFetchFp)(void*, uint64_t, uint64_t, uint64_t, uint64_t, int64_t, int32_t, void**, SArray*);
2022-09-09 11:03:42 +00:00
typedef struct {
2022-09-28 02:38:49 +00:00
void* handle;
2022-09-15 08:30:21 +00:00
bool localExec;
2022-09-09 11:03:42 +00:00
localFetchFp fp;
2022-09-28 02:38:49 +00:00
SArray* explainRes;
2022-09-09 11:03:42 +00:00
} SLocalFetch;
typedef struct {
void* tqReader; // todo remove it
void* vnode;
void* mnd;
SMsgCb* pMsgCb;
int64_t version;
uint64_t checkpointId;
bool initTableReader;
bool initTqReader;
2023-11-07 11:59:05 +00:00
bool skipRollup;
int32_t numOfVgroups;
void* sContext; // SSnapContext*
void* pStateBackend;
feat(stream): add new trigger continuous_window_close (#30125) * opt stream build twa result * opt force window close memory * feat(stream):optimize new interval and scan operator * adj log * opt code * opt code * fill history * fix issue for fill history * add ci * feat(stream): add new stream nonblock interval operator * adjust code * use new scan operator * use new scan operator * add log * fix issue * recover stream scan next function * fix issue * fix issue * fix issue * ignore disorder data * fix issue * fix issue for interval sliding * fix issue * fix ci issue * fix ci issue * fix ci issue * add semi && final nonblock interval operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * refactor(stream): track the msgId for each upstream tasks. * fix(stream): fix race condition. * fix(stream): update the task last msgId when putting into input queue succ. * fix issue * fix issue * put recalculate data to rocksdb * fix issue * fix issue * enh(query)[TD-33071]: add support for saving and restoring tsdbReader scan progress - Implement functionality to save scan progress during tsdbReader operations - Enable resuming scans from the last saved position * fix issue * fix issue * fix issue * fix issue * fix issue * add rec interval check * enh(stream):add recalculate tasks. * enh(stream): support the re-calculate the tasks. * fix issue && do refactor * do refactor * fix issue * fix issue * update backend opt * add new interface * add new session operator * support blob * add new session operator * fix issue * add rec state for rec task * fix invalid read * add new session window * enh(stream): update the stream tasks backend. * new session operator * add pull data * fix(stream): fix error in expand stream backend. * fix issue * fix issue * fix issue * merge code * fix issue * fix(stream): check for null ptr. * fix(stream): add more check. * fix issue * fix issue * fix issue * add debug code * fix issue * fix issue * fix issue * set rec end flag * fix(stream): opt re-calculate stream tasks. * fix issue * fix issue * add new operator * enh(stream): dispatch recalculate block to agg tasks. * fix issue * fix issue * fix(stream): adjust filter. * fix issue * refactor * refactor(stream): adjust the recalculate end block. * fix issue * fix(stream): set correct create trigger block. * fix issue * fix(stream): fix error in build recalculate end block. * fix(stream): check null ptr. * add stream client && fix issue * fix mem leak * fix(stream): free msg. * add stream client * fix(stream): fix error. * add stream client && fix issue * add stream client * refactor(stream): set the recalculate task complete. * add wend and group_id for session window dest table * feat(stream): refactor and set the recalcul agg task complete. * add cfg for adapter * fix issue * add state && event operator * feat(stream): support fill-history task. * add new fill operator * fix(stream): set correct backend when updating fill-history task to recalculate task. * add new fill operator * fix(stream): s2025-03-06 11:10:31.272 et ops always open in scan tsdb * fix(stream):set the correct taskType for sink task. * new fill operator * adj stream fill operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * adj test * fix issue * fix(stream): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix: ut com error * fix(stream): fix mem leak and adjust operator type check rule * fix(stream): fix mem leak and adjust test case * refactor code * fix(stream): free items. * fix(stream): free fix memory leak. * fix(stream): fix syntax error. * fix: ignore unexpect block * fix: adjust op type --------- Co-authored-by: Haojun Liao <hjliao@taosdata.com> Co-authored-by: Jinqing Kuang <kuangjinqingcn@gmail.com> Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 12:14:01 +00:00
void* pOtherBackend;
int8_t fillHistory;
STimeWindow winRange;
bool winRangeValid;
struct SStorageAPI api;
2024-06-24 10:28:56 +00:00
void* pWorkerCb;
2024-11-15 02:16:15 +00:00
bool localExec;
2022-01-28 02:44:02 +00:00
} SReadHandle;
2025-05-08 06:58:41 +00:00
typedef struct SStreamInserterParam {
2025-05-17 06:13:08 +00:00
SArray* pFields; // SArray<SFieldWithOptions>
SArray* pTagFields; // SArray<SFieldWithOptions>
2025-05-09 09:05:56 +00:00
int64_t suid;
int32_t sver;
char* tbname;
2025-05-14 09:41:51 +00:00
char* stbname;
2025-05-09 09:05:56 +00:00
int8_t tbType;
char* dbFName;
void* pSinkHandle;
int32_t vgid;
STSchema* pSchema;
2025-05-08 06:58:41 +00:00
} SStreamInserterParam;
2025-04-29 07:31:17 +00:00
typedef struct {
SStreamRuntimeFuncInfo funcInfo;
int32_t execId;
bool resetFlag;
const SArray* pForceOutputCols;
2025-05-08 06:58:41 +00:00
SStreamInserterParam inserterParams;
2025-04-29 07:31:17 +00:00
} SStreamRuntimeInfo;
2022-07-12 06:10:22 +00:00
// in queue mode, data streams are seperated by msg
typedef enum {
OPTR_EXEC_MODEL_BATCH = 0x1,
OPTR_EXEC_MODEL_STREAM = 0x2,
2022-07-12 06:10:22 +00:00
OPTR_EXEC_MODEL_QUEUE = 0x3,
} EOPTR_EXEC_MODEL;
2022-03-22 10:00:03 +00:00
/**
2022-07-12 06:10:22 +00:00
* Create the exec task for stream mode
2022-03-22 10:00:03 +00:00
* @param pMsg
2022-07-12 06:10:22 +00:00
* @param SReadHandle
2023-03-19 02:49:30 +00:00
* @param vgId
2022-03-22 10:00:03 +00:00
* @return
*/
2025-05-08 06:58:41 +00:00
int32_t qCreateStreamExecTaskInfo(qTaskInfo_t* pInfo, void* msg, SReadHandle* readers, SStreamInserterParam* pInsertParams, int32_t vgId, int32_t taskId);
int32_t qResetTableScan(qTaskInfo_t* pInfo, STimeWindow range);
2022-06-23 05:35:24 +00:00
/**
2022-07-12 06:10:22 +00:00
* Create the exec task for queue mode
* @param pMsg
* @param SReadHandle
2022-06-23 05:35:24 +00:00
* @return
*/
2023-04-04 06:50:58 +00:00
qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* pReaderHandle, int32_t vgId, int32_t* numOfCols,
uint64_t id);
2022-06-23 05:35:24 +00:00
int32_t qGetColumnsFromNodeList(void* data, bool isList, SArray** pColList);
SSDataBlock* createDataBlockFromDescNode(void* pNode);
void printDataBlock(SSDataBlock* pBlock, const char* flag, const char* taskIdStr);
int32_t qGetTableList(int64_t suid, void* pVnode, void* node, SArray** tableList, void* pTaskInfo);
2023-03-19 11:06:28 +00:00
/**
* set the task Id, usually used by message queue process
* @param tinfo
* @param taskId
* @param queryId
*/
2024-09-13 15:04:41 +00:00
int32_t qSetTaskId(qTaskInfo_t tinfo, uint64_t taskId, uint64_t queryId);
bool qTaskIsDone(qTaskInfo_t tinfo);
2022-10-27 03:06:16 +00:00
/**
* Set block for sma
* @param tinfo
* @param pBlocks
* @param numOfInputBlock
* @param type
* @return
*/
int32_t qSetSMAInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type);
/**
* Update the table id list, add or remove.
*
* @param tinfo
* @param id
* @param isAdd
* @return
*/
int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd);
bool qIsDynamicExecTask(qTaskInfo_t tinfo);
void qDestroyOperatorParam(SOperatorParam* pParam);
void qUpdateOperatorParam(qTaskInfo_t tinfo, void* pParam);
2022-03-22 10:00:03 +00:00
/**
* Create the exec task object according to task json
* @param readHandle
* @param vgId
* @param pTaskInfoMsg
* @param pTaskInfo
* @param qId
* @return
*/
int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, struct SSubplan* pSubplan,
qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, int8_t compressResult, char* sql,
EOPTR_EXEC_MODEL model);
2021-10-06 15:34:38 +00:00
/**
*
* @param tinfo
* @param sversion
* @param tversion
* @param rversion
* @return
*/
int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, int32_t dbNameBuffLen, char* tableName,
int32_t tbaleNameBuffLen, int32_t* sversion, int32_t* tversion, int32_t* rversion,
int32_t idx, bool* tbGet);
2021-10-06 15:34:38 +00:00
/**
2022-01-11 02:51:23 +00:00
* The main task execution function, including query on both table and multiple tables,
2021-10-06 15:34:38 +00:00
* which are decided according to the tag or table name query conditions
*
2022-01-11 02:51:23 +00:00
* @param tinfo
* @param handle
2021-10-06 15:34:38 +00:00
* @return
*/
int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bool* hasMore, SLocalFetch* pLocal,
bool processOneBlock);
2022-11-27 06:57:44 +00:00
2022-08-09 05:55:51 +00:00
int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pBlock, uint64_t* useconds);
2021-10-06 15:34:38 +00:00
2024-07-02 11:25:33 +00:00
int32_t qExecutorInit(void);
void qResetTaskCode(qTaskInfo_t tinfo);
2024-07-02 11:25:33 +00:00
2022-11-27 06:57:44 +00:00
void qCleanExecTaskBlockBuf(qTaskInfo_t tinfo);
2022-01-20 11:34:46 +00:00
/**
* kill the ongoing query asynchronously
2022-01-21 07:16:17 +00:00
* @param tinfo qhandle
2022-01-20 11:34:46 +00:00
* @return
*/
2022-11-29 08:17:05 +00:00
int32_t qAsyncKillTask(qTaskInfo_t tinfo, int32_t rspCode);
2023-04-08 17:39:09 +00:00
int32_t qKillTask(qTaskInfo_t tinfo, int32_t rspCode, int64_t waitDuration);
2022-01-20 11:34:46 +00:00
bool qTaskIsExecuting(qTaskInfo_t qinfo);
2021-10-06 15:34:38 +00:00
/**
* destroy query info structure
* @param qHandle
*/
2022-01-21 07:16:17 +00:00
void qDestroyTask(qTaskInfo_t tinfo);
2021-10-06 15:34:38 +00:00
2022-07-06 08:29:51 +00:00
void qProcessRspMsg(void* parent, struct SRpcMsg* pMsg, struct SEpSet* pEpSet);
2022-01-25 07:18:56 +00:00
2023-11-03 01:30:50 +00:00
int32_t qGetExplainExecInfo(qTaskInfo_t tinfo, SArray* pExecInfoList);
TSKEY getNextTimeWindowStart(const SInterval* pInterval, TSKEY start, int32_t order);
void getNextTimeWindow(const SInterval* pInterval, STimeWindow* tw, int32_t order);
void getInitialStartTimeWindow(SInterval* pInterval, TSKEY ts, STimeWindow* w, bool ascQuery);
STimeWindow getAlignQueryTimeWindow(const SInterval* pInterval, int64_t key);
2023-04-08 17:39:09 +00:00
SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo);
2022-07-08 09:48:34 +00:00
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType);
2022-07-08 09:48:34 +00:00
void qStreamSetOpen(qTaskInfo_t tinfo);
void qStreamSetSourceExcluded(qTaskInfo_t tinfo, int8_t sourceExcluded);
2024-07-29 02:29:40 +00:00
int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset);
2022-07-08 09:48:34 +00:00
2024-05-23 09:35:54 +00:00
SMqBatchMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo);
2022-06-30 06:41:50 +00:00
2022-08-09 11:06:24 +00:00
const SSchemaWrapper* qExtractSchemaFromTask(qTaskInfo_t tinfo);
const char* qExtractTbnameFromTask(qTaskInfo_t tinfo);
2022-08-09 11:06:24 +00:00
2022-07-13 08:37:33 +00:00
void* qExtractReaderFromStreamScanner(void* scanner);
feat(stream): add new trigger continuous_window_close (#30125) * opt stream build twa result * opt force window close memory * feat(stream):optimize new interval and scan operator * adj log * opt code * opt code * fill history * fix issue for fill history * add ci * feat(stream): add new stream nonblock interval operator * adjust code * use new scan operator * use new scan operator * add log * fix issue * recover stream scan next function * fix issue * fix issue * fix issue * ignore disorder data * fix issue * fix issue for interval sliding * fix issue * fix ci issue * fix ci issue * fix ci issue * add semi && final nonblock interval operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * refactor(stream): track the msgId for each upstream tasks. * fix(stream): fix race condition. * fix(stream): update the task last msgId when putting into input queue succ. * fix issue * fix issue * put recalculate data to rocksdb * fix issue * fix issue * enh(query)[TD-33071]: add support for saving and restoring tsdbReader scan progress - Implement functionality to save scan progress during tsdbReader operations - Enable resuming scans from the last saved position * fix issue * fix issue * fix issue * fix issue * fix issue * add rec interval check * enh(stream):add recalculate tasks. * enh(stream): support the re-calculate the tasks. * fix issue && do refactor * do refactor * fix issue * fix issue * update backend opt * add new interface * add new session operator * support blob * add new session operator * fix issue * add rec state for rec task * fix invalid read * add new session window * enh(stream): update the stream tasks backend. * new session operator * add pull data * fix(stream): fix error in expand stream backend. * fix issue * fix issue * fix issue * merge code * fix issue * fix(stream): check for null ptr. * fix(stream): add more check. * fix issue * fix issue * fix issue * add debug code * fix issue * fix issue * fix issue * set rec end flag * fix(stream): opt re-calculate stream tasks. * fix issue * fix issue * add new operator * enh(stream): dispatch recalculate block to agg tasks. * fix issue * fix issue * fix(stream): adjust filter. * fix issue * refactor * refactor(stream): adjust the recalculate end block. * fix issue * fix(stream): set correct create trigger block. * fix issue * fix(stream): fix error in build recalculate end block. * fix(stream): check null ptr. * add stream client && fix issue * fix mem leak * fix(stream): free msg. * add stream client * fix(stream): fix error. * add stream client && fix issue * add stream client * refactor(stream): set the recalculate task complete. * add wend and group_id for session window dest table * feat(stream): refactor and set the recalcul agg task complete. * add cfg for adapter * fix issue * add state && event operator * feat(stream): support fill-history task. * add new fill operator * fix(stream): set correct backend when updating fill-history task to recalculate task. * add new fill operator * fix(stream): s2025-03-06 11:10:31.272 et ops always open in scan tsdb * fix(stream):set the correct taskType for sink task. * new fill operator * adj stream fill operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * adj test * fix issue * fix(stream): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix: ut com error * fix(stream): fix mem leak and adjust operator type check rule * fix(stream): fix mem leak and adjust test case * refactor code * fix(stream): free items. * fix(stream): free fix memory leak. * fix(stream): fix syntax error. * fix: ignore unexpect block * fix: adjust op type --------- Co-authored-by: Haojun Liao <hjliao@taosdata.com> Co-authored-by: Jinqing Kuang <kuangjinqingcn@gmail.com> Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 12:14:01 +00:00
void qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner);
2022-07-07 09:16:12 +00:00
int32_t qSetStreamOperatorOptionForScanHistory(qTaskInfo_t tinfo);
int32_t qStreamSourceScanParamForHistoryScanStep1(qTaskInfo_t tinfo, SVersionRange* pVerRange, STimeWindow* pWindow);
int32_t qStreamSourceScanParamForHistoryScanStep2(qTaskInfo_t tinfo, SVersionRange* pVerRange, STimeWindow* pWindow);
int32_t qStreamRecoverFinish(qTaskInfo_t tinfo);
bool qStreamScanhistoryFinished(qTaskInfo_t tinfo);
int32_t qStreamInfoResetTimewindowFilter(qTaskInfo_t tinfo);
int32_t qGetStreamIntervalExecInfo(qTaskInfo_t tinfo, int64_t* pWaterMark, SInterval* pInterval,
STimeWindow* pLastWindow, TSKEY* pRecInteral);
int32_t qStreamOperatorReleaseState(qTaskInfo_t tInfo);
int32_t qStreamOperatorReloadState(qTaskInfo_t tInfo);
int32_t streamCollectExprsForReplace(qTaskInfo_t tInfo, SArray* pExprs);
int32_t streamClearStatesForOperators(qTaskInfo_t tInfo);
2025-05-13 05:46:12 +00:00
int32_t streamExecuteTask(qTaskInfo_t tInfo, SSDataBlock** ppBlock, uint64_t* ts, bool* finished);
void streamDestroyExecTask(qTaskInfo_t tInfo);
int32_t qStreamCreateTableListForReader(void* pVnode, uint64_t suid, uint64_t uid, int8_t tableType,
SNodeList* pGroupTags, bool groupSort, SNode* pTagCond, SNode* pTagIndexCond,
SStorageAPI* storageAPI, void** pTableListInfo, SHashObj* groupIdMap);
int32_t qStreamGetTableList(void* pTableListInfo, int32_t currentGroupId, STableKeyInfo** pKeyInfo, int32_t* size);
uint64_t qStreamGetGroupId(void* pTableListInfo, int64_t uid);
void qStreamDestroyTableList(void* pTableListInfo);
int32_t qStreamGetTableListGroupNum(const void* pTableList);
SArray* qStreamGetTableArrayList(const void* pTableList);
int32_t qStreamGetGroupIndex(void* pTableListInfo, int64_t gid);
int32_t qStreamFilter(SSDataBlock* pBlock, void* pFilterInfo);
bool qStreamUidInTableList(void* pTableListInfo, uint64_t uid);
int32_t createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, SExprInfo** pExprInfo, int32_t* numOfExprs);
void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs);
int32_t setTbNameColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId,
const char* name);
int32_t setVgIdColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId, int32_t vgId);
int32_t setVgVerColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId, int64_t vgVer);
2025-04-24 01:11:54 +00:00
2025-04-29 07:31:17 +00:00
int32_t streamCalcOutputTbName(SNode *pExpr, char *tbname, const SStreamRuntimeFuncInfo *pPartColVals);
void streamSetTaskRuntimeInfo(qTaskInfo_t tinfo, SStreamRuntimeInfo* pRuntimeInfo);
2025-05-08 01:48:53 +00:00
typedef void (*getMnodeEpset_f)(void *pDnode, SEpSet *pEpset);
typedef int32_t (*getDnodeId_f)(void *pData);
typedef void (*taskUndeplyCallback)(void*);
typedef struct SGlobalExecInfo {
void* dnode;
int32_t dnodeId;
int32_t snodeId;
getMnodeEpset_f getMnode;
getDnodeId_f getDnodeId;
} SGlobalExecInfo;
extern SGlobalExecInfo gExecInfo;
void gExecInfoInit(void* pDnode, getDnodeId_f getDnodeId, getMnodeEpset_f getMnode);
int32_t getCurrentMnodeEpset(SEpSet* pEpSet);
2025-05-08 15:00:37 +00:00
int32_t cloneStreamInserterParam(SStreamInserterParam** pDst, SStreamInserterParam* pSrc);
void destoryStreamInserterParam(SStreamInserterParam* pParam);
int32_t streamForceOutput(qTaskInfo_t tInfo, SSDataBlock** pRes, int32_t winIdx);
2025-05-20 03:12:55 +00:00
int32_t streamCalcOneScalarExpr(SNode* pExpr, SScalarParam* pDst, const SStreamRuntimeFuncInfo* pExtraParams);
2025-05-08 01:48:53 +00:00
2021-09-24 10:05:56 +00:00
#ifdef __cplusplus
}
#endif
#endif /*_TD_EXECUTOR_H_*/