Merge branch '3.0' into feature/TD-11463-3.0
This commit is contained in:
commit
3adabbc489
|
@ -89,6 +89,7 @@ tests/examples/JDBC/JDBCDemo/.project
|
|||
tests/examples/JDBC/JDBCDemo/.settings/
|
||||
source/libs/parser/inc/sql.*
|
||||
tests/script/tmqResult.txt
|
||||
tests/tmqResult.txt
|
||||
|
||||
# Emacs
|
||||
# -*- mode: gitignore; -*-
|
||||
|
|
|
@ -44,7 +44,7 @@ int32_t init_env() {
|
|||
|
||||
pRes = taos_query(pConn, "create stable if not exists st1 (ts timestamp, k int) tags(a int)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create super table 123_$^), reason:%s\n", taos_errstr(pRes));
|
||||
printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
}
|
||||
taos_free_result(pRes);
|
||||
|
|
|
@ -25,7 +25,7 @@ int32_t init_env() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2");
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
|
|
|
@ -213,8 +213,10 @@ typedef void(tmq_commit_cb(tmq_t *, tmq_resp_err_t, tmq_topic_vgroup_list_t *, v
|
|||
|
||||
DLL_EXPORT tmq_list_t *tmq_list_new();
|
||||
DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *);
|
||||
DLL_EXPORT void tmq_list_destroy(tmq_list_t *);
|
||||
|
||||
DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
||||
DLL_EXPORT tmq_t *tmq_consumer_new1(tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
||||
DLL_EXPORT void tmq_message_destroy(tmq_message_t *tmq_message);
|
||||
DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
|
||||
|
||||
|
@ -244,8 +246,8 @@ enum tmq_conf_res_t {
|
|||
typedef enum tmq_conf_res_t tmq_conf_res_t;
|
||||
|
||||
DLL_EXPORT tmq_conf_t *tmq_conf_new();
|
||||
DLL_EXPORT void tmq_conf_destroy(tmq_conf_t *conf);
|
||||
DLL_EXPORT tmq_conf_res_t tmq_conf_set(tmq_conf_t *conf, const char *key, const char *value);
|
||||
DLL_EXPORT void tmq_conf_destroy(tmq_conf_t *conf);
|
||||
DLL_EXPORT void tmq_conf_set_offset_commit_cb(tmq_conf_t *conf, tmq_commit_cb *cb);
|
||||
|
||||
// temporary used function for demo only
|
||||
|
@ -256,6 +258,7 @@ int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message);
|
|||
|
||||
DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message);
|
||||
DLL_EXPORT char *tmq_get_topic_name(tmq_message_t *message);
|
||||
DLL_EXPORT char *tmq_get_topic_schema(tmq_t *tmq, const char *topic);
|
||||
|
||||
/* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */
|
||||
DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen);
|
||||
|
|
|
@ -127,7 +127,7 @@ static FORCE_INLINE int32_t tEncodeSMqPollRsp(void** buf, const SMqPollRsp* pRsp
|
|||
tlen += taosEncodeFixedI32(buf, pRsp->skipLogNum);
|
||||
tlen += taosEncodeFixedI32(buf, pRsp->numOfTopics);
|
||||
if (pRsp->numOfTopics == 0) return tlen;
|
||||
tlen += tEncodeSSchemaWrapper(buf, pRsp->schema);
|
||||
tlen += taosEncodeSSchemaWrapper(buf, pRsp->schema);
|
||||
if (pRsp->pBlockData) {
|
||||
sz = taosArrayGetSize(pRsp->pBlockData);
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ static FORCE_INLINE void* tDecodeSMqPollRsp(void* buf, SMqPollRsp* pRsp) {
|
|||
if (pRsp->numOfTopics == 0) return buf;
|
||||
pRsp->schema = (SSchemaWrapper*)taosMemoryCalloc(1, sizeof(SSchemaWrapper));
|
||||
if (pRsp->schema == NULL) return NULL;
|
||||
buf = tDecodeSSchemaWrapper(buf, pRsp->schema);
|
||||
buf = taosDecodeSSchemaWrapper(buf, pRsp->schema);
|
||||
buf = taosDecodeFixedI32(buf, &sz);
|
||||
pRsp->pBlockData = taosArrayInit(sz, sizeof(SSDataBlock));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
|
|
|
@ -138,7 +138,7 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
|
|||
size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize);
|
||||
void* blockDataDestroy(SSDataBlock* pBlock);
|
||||
|
||||
void blockDebugShowData(SArray* dataBlocks);
|
||||
void blockDebugShowData(const SArray* dataBlocks);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1125,7 +1125,6 @@ int32_t tDeserializeSSchedulerHbReq(void* buf, int32_t bufLen, SSchedulerHbReq*
|
|||
void tFreeSSchedulerHbReq(SSchedulerHbReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
uint64_t seqId;
|
||||
SQueryNodeEpId epId;
|
||||
SArray* taskStatus; // SArray<STaskStatus>
|
||||
} SSchedulerHbRsp;
|
||||
|
@ -1931,7 +1930,7 @@ static FORCE_INLINE int32_t tDecodeSSchema(SCoder* pDecoder, SSchema* pSchema) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
|
||||
static FORCE_INLINE int32_t taosEncodeSSchemaWrapper(void** buf, const SSchemaWrapper* pSW) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedU32(buf, pSW->nCols);
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
|
@ -1940,7 +1939,7 @@ static FORCE_INLINE int32_t tEncodeSSchemaWrapper(void** buf, const SSchemaWrapp
|
|||
return tlen;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* tDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) {
|
||||
static FORCE_INLINE void* taosDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW) {
|
||||
buf = taosDecodeFixedU32(buf, &pSW->nCols);
|
||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||
if (pSW->pSchema == NULL) {
|
||||
|
@ -1953,6 +1952,27 @@ static FORCE_INLINE void* tDecodeSSchemaWrapper(void* buf, SSchemaWrapper* pSW)
|
|||
return buf;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tEncodeSSchemaWrapper(SCoder* pEncoder, const SSchemaWrapper* pSW) {
|
||||
if (tEncodeU32(pEncoder, pSW->nCols) < 0) return -1;
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
if (tEncodeSSchema(pEncoder, &pSW->pSchema[i]) < 0) return -1;
|
||||
}
|
||||
return pEncoder->pos;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SCoder* pDecoder, SSchemaWrapper* pSW) {
|
||||
if (tDecodeU32(pDecoder, &pSW->nCols) < 0) return -1;
|
||||
void* ptr = taosMemoryRealloc(pSW->pSchema, pSW->nCols * sizeof(SSchema));
|
||||
if (ptr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
pSW->pSchema = (SSchema*)ptr;
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
if (tDecodeSSchema(pDecoder, &pSW->pSchema[i]) < 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
char stb[TSDB_TABLE_FNAME_LEN];
|
||||
|
|
|
@ -28,6 +28,7 @@ typedef struct SMgmtWrapper SMgmtWrapper;
|
|||
typedef enum {
|
||||
QUERY_QUEUE,
|
||||
FETCH_QUEUE,
|
||||
READ_QUEUE,
|
||||
WRITE_QUEUE,
|
||||
APPLY_QUEUE,
|
||||
SYNC_QUEUE,
|
||||
|
|
|
@ -212,6 +212,10 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_SND_TASK_PIPE_EXEC, "snode-task-pipe-exec", SStreamTaskExecReq, SStreamTaskExecRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_SND_TASK_MERGE_EXEC, "snode-task-merge-exec", SStreamTaskExecReq, SStreamTaskExecRsp)
|
||||
|
||||
// Requests handled by SCHEDULER
|
||||
TD_NEW_MSG_SEG(TDMT_SCH_MSG)
|
||||
TD_DEF_MSG_TYPE(TDMT_SCH_LINK_BROKEN, "scheduler-link-broken", NULL, NULL)
|
||||
|
||||
#if defined(TD_MSG_NUMBER_)
|
||||
TDMT_MAX
|
||||
#endif
|
||||
|
|
|
@ -112,7 +112,7 @@ int32_t catalogUpdateDBVgInfo(SCatalog* pCatalog, const char* dbName, uint64_t d
|
|||
|
||||
int32_t catalogRemoveDB(SCatalog* pCatalog, const char* dbName, uint64_t dbId);
|
||||
|
||||
int32_t catalogRemoveTableMeta(SCatalog* pCtg, SName* pTableName);
|
||||
int32_t catalogRemoveTableMeta(SCatalog* pCtg, const SName* pTableName);
|
||||
|
||||
int32_t catalogRemoveStbMeta(SCatalog* pCtg, const char* dbFName, uint64_t dbId, const char* stbName, uint64_t suid);
|
||||
|
||||
|
|
|
@ -57,18 +57,19 @@ typedef enum EFunctionType {
|
|||
|
||||
// math function
|
||||
FUNCTION_TYPE_ABS = 1000,
|
||||
FUNCTION_TYPE_ACOS,
|
||||
FUNCTION_TYPE_ASION,
|
||||
FUNCTION_TYPE_ATAN,
|
||||
FUNCTION_TYPE_CEIL,
|
||||
FUNCTION_TYPE_COS,
|
||||
FUNCTION_TYPE_FLOOR,
|
||||
FUNCTION_TYPE_LOG,
|
||||
FUNCTION_TYPE_POW,
|
||||
FUNCTION_TYPE_ROUND,
|
||||
FUNCTION_TYPE_SIN,
|
||||
FUNCTION_TYPE_SQRT,
|
||||
FUNCTION_TYPE_CEIL,
|
||||
FUNCTION_TYPE_FLOOR,
|
||||
FUNCTION_TYPE_ROUND,
|
||||
|
||||
FUNCTION_TYPE_SIN,
|
||||
FUNCTION_TYPE_COS,
|
||||
FUNCTION_TYPE_TAN,
|
||||
FUNCTION_TYPE_ASIN,
|
||||
FUNCTION_TYPE_ACOS,
|
||||
FUNCTION_TYPE_ATAN,
|
||||
|
||||
// string function
|
||||
FUNCTION_TYPE_CHAR_LENGTH = 1500,
|
||||
|
|
|
@ -120,6 +120,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_LOGIC_PLAN_VNODE_MODIF,
|
||||
QUERY_NODE_LOGIC_PLAN_EXCHANGE,
|
||||
QUERY_NODE_LOGIC_PLAN_WINDOW,
|
||||
QUERY_NODE_LOGIC_PLAN_SORT,
|
||||
QUERY_NODE_LOGIC_SUBPLAN,
|
||||
QUERY_NODE_LOGIC_PLAN,
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ typedef struct SScanLogicNode {
|
|||
uint8_t scanFlag; // denotes reversed scan of data or not
|
||||
STimeWindow scanRange;
|
||||
SName tableName;
|
||||
bool showRewrite;
|
||||
} SScanLogicNode;
|
||||
|
||||
typedef struct SJoinLogicNode {
|
||||
|
@ -65,6 +66,7 @@ typedef struct SAggLogicNode {
|
|||
typedef struct SProjectLogicNode {
|
||||
SLogicNode node;
|
||||
SNodeList* pProjections;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
} SProjectLogicNode;
|
||||
|
||||
typedef struct SVnodeModifLogicNode {
|
||||
|
@ -96,8 +98,14 @@ typedef struct SWindowLogicNode {
|
|||
int8_t slidingUnit;
|
||||
SFillNode* pFill;
|
||||
int64_t sessionGap;
|
||||
SNode* pTspk;
|
||||
} SWindowLogicNode;
|
||||
|
||||
typedef struct SSortLogicNode {
|
||||
SLogicNode node;
|
||||
SNodeList* pSortKeys;
|
||||
} SSortLogicNode;
|
||||
|
||||
typedef enum ESubplanType {
|
||||
SUBPLAN_TYPE_MERGE = 1,
|
||||
SUBPLAN_TYPE_PARTIAL,
|
||||
|
@ -171,6 +179,8 @@ typedef SScanPhysiNode SStreamScanPhysiNode;
|
|||
typedef struct SSystemTableScanPhysiNode {
|
||||
SScanPhysiNode scan;
|
||||
SEpSet mgmtEpSet;
|
||||
bool showRewrite;
|
||||
int32_t accountId;
|
||||
} SSystemTableScanPhysiNode;
|
||||
|
||||
typedef struct STableScanPhysiNode {
|
||||
|
@ -197,7 +207,7 @@ typedef struct SJoinPhysiNode {
|
|||
typedef struct SAggPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pExprs; // these are expression list of group_by_clause and parameter expression of aggregate function
|
||||
SNodeList* pGroupKeys; // SColumnRefNode list
|
||||
SNodeList* pGroupKeys;
|
||||
SNodeList* pAggFuncs;
|
||||
} SAggPhysiNode;
|
||||
|
||||
|
@ -222,6 +232,7 @@ typedef struct SWinodwPhysiNode {
|
|||
|
||||
typedef struct SIntervalPhysiNode {
|
||||
SWinodwPhysiNode window;
|
||||
SNode* pTspk; // timestamp primary key
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
|
@ -235,6 +246,12 @@ typedef struct SSessionWinodwPhysiNode {
|
|||
int64_t gap;
|
||||
} SSessionWinodwPhysiNode;
|
||||
|
||||
typedef struct SSortPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pExprs; // these are expression list of order_by_clause and parameter expression of aggregate function
|
||||
SNodeList* pSortKeys; // element is SOrderByExprNode, and SOrderByExprNode::pExpr is SColumnNode
|
||||
} SSortPhysiNode;
|
||||
|
||||
typedef struct SDataSinkNode {
|
||||
ENodeType type;
|
||||
SDataBlockDescNode* pInputDataBlockDesc;
|
||||
|
|
|
@ -191,12 +191,13 @@ typedef struct SStateWindowNode {
|
|||
|
||||
typedef struct SSessionWindowNode {
|
||||
ENodeType type; // QUERY_NODE_SESSION_WINDOW
|
||||
SNode* pCol;
|
||||
SNode* pCol; // timestamp primary key
|
||||
SNode* pGap; // gap between two session window(in microseconds)
|
||||
} SSessionWindowNode;
|
||||
|
||||
typedef struct SIntervalWindowNode {
|
||||
ENodeType type; // QUERY_NODE_INTERVAL_WINDOW
|
||||
SNode* pCol; // timestamp primary key
|
||||
SNode* pInterval; // SValueNode
|
||||
SNode* pOffset; // SValueNode
|
||||
SNode* pSliding; // SValueNode
|
||||
|
@ -231,6 +232,7 @@ typedef struct SSelectStmt {
|
|||
SNodeList* pOrderByList; // SOrderByExprNode
|
||||
SNode* pLimit;
|
||||
SNode* pSlimit;
|
||||
char stmtName[TSDB_TABLE_NAME_LEN];
|
||||
} SSelectStmt;
|
||||
|
||||
typedef enum ESetOperatorType {
|
||||
|
|
|
@ -54,6 +54,7 @@ typedef struct SQuery {
|
|||
int32_t msgType;
|
||||
SArray* pDbList;
|
||||
SArray* pTableList;
|
||||
bool showRewrite;
|
||||
} SQuery;
|
||||
|
||||
int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery);
|
||||
|
|
|
@ -29,6 +29,7 @@ typedef struct SPlanContext {
|
|||
SNode* pAstRoot;
|
||||
bool topicQuery;
|
||||
bool streamQuery;
|
||||
bool showRewrite;
|
||||
} SPlanContext;
|
||||
|
||||
// Create the physical plan for the query, according to the AST.
|
||||
|
|
|
@ -150,6 +150,8 @@ int32_t cleanupTaskQueue();
|
|||
*/
|
||||
int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code);
|
||||
|
||||
int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo, bool persistHandle, void *ctx);
|
||||
|
||||
/**
|
||||
* Asynchronously send message to server, after the response received, the callback will be incured.
|
||||
*
|
||||
|
|
|
@ -28,6 +28,7 @@ enum {
|
|||
NODE_TYPE_VNODE = 1,
|
||||
NODE_TYPE_QNODE,
|
||||
NODE_TYPE_SNODE,
|
||||
NODE_TYPE_MNODE,
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -42,6 +42,21 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type);
|
|||
int32_t vectorGetConvertType(int32_t type1, int32_t type2);
|
||||
int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut);
|
||||
|
||||
int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t powFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t sqrtFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
||||
int32_t sinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t cosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t tanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t asinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t acosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t atanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
||||
int32_t ceilFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t floorFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t roundFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -30,16 +30,18 @@ enum {
|
|||
STREAM_TASK_STATUS__STOP,
|
||||
};
|
||||
|
||||
#if 0
|
||||
// pipe -> fetch/pipe queue
|
||||
// merge -> merge queue
|
||||
// write -> write queue
|
||||
enum {
|
||||
TASK_SINK_MSG__SND_PIPE = 1,
|
||||
TASK_SINK_MSG__SND_MERGE,
|
||||
TASK_SINK_MSG__VND_PIPE,
|
||||
TASK_SINK_MSG__VND_MERGE,
|
||||
TASK_SINK_MSG__VND_WRITE,
|
||||
TASK_DISPATCH_MSG__SND_PIPE = 1,
|
||||
TASK_DISPATCH_MSG__SND_MERGE,
|
||||
TASK_DISPATCH_MSG__VND_PIPE,
|
||||
TASK_DISPATCH_MSG__VND_MERGE,
|
||||
TASK_DISPATCH_MSG__VND_WRITE,
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int32_t nodeId; // 0 for snode
|
||||
|
@ -93,13 +95,14 @@ typedef struct {
|
|||
|
||||
enum {
|
||||
TASK_SOURCE__SCAN = 1,
|
||||
TASK_SOURCE__SINGLE,
|
||||
TASK_SOURCE__MULTI,
|
||||
TASK_SOURCE__PIPE,
|
||||
TASK_SOURCE__MERGE,
|
||||
};
|
||||
|
||||
enum {
|
||||
TASK_EXEC__NONE = 1,
|
||||
TASK_EXEC__EXEC,
|
||||
TASK_EXEC__PIPE,
|
||||
TASK_EXEC__MERGE,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
@ -129,6 +132,9 @@ typedef struct {
|
|||
int16_t dispatchMsgType;
|
||||
int32_t downstreamTaskId;
|
||||
|
||||
int32_t nodeId;
|
||||
SEpSet epSet;
|
||||
|
||||
// source preprocess
|
||||
|
||||
// exec
|
||||
|
|
|
@ -82,12 +82,20 @@ typedef struct SRpcInit {
|
|||
|
||||
typedef struct {
|
||||
void *val;
|
||||
int32_t len;
|
||||
int32_t (*clone)(void *src, void **dst);
|
||||
void (*freeFunc)(const void *arg);
|
||||
} SRpcCtxVal;
|
||||
|
||||
typedef struct {
|
||||
int32_t msgType;
|
||||
void *val;
|
||||
int32_t (*clone)(void *src, void **dst);
|
||||
void (*freeFunc)(const void *arg);
|
||||
} SRpcBrokenlinkVal;
|
||||
|
||||
typedef struct {
|
||||
SHashObj * args;
|
||||
SRpcBrokenlinkVal brokenVal;
|
||||
} SRpcCtx;
|
||||
|
||||
int32_t rpcInit();
|
||||
|
|
|
@ -75,15 +75,30 @@ extern "C" {
|
|||
#define WAL_CUR_FAILED 1
|
||||
|
||||
#pragma pack(push, 1)
|
||||
typedef enum { TAOS_WAL_NOLOG = 0, TAOS_WAL_WRITE = 1, TAOS_WAL_FSYNC = 2 } EWalType;
|
||||
typedef enum {
|
||||
TAOS_WAL_NOLOG = 0,
|
||||
TAOS_WAL_WRITE = 1,
|
||||
TAOS_WAL_FSYNC = 2,
|
||||
} EWalType;
|
||||
|
||||
// used by sync module
|
||||
typedef struct {
|
||||
int8_t isWeek;
|
||||
uint64_t seqNum;
|
||||
uint64_t term;
|
||||
} SSyncLogMeta;
|
||||
|
||||
typedef struct SWalReadHead {
|
||||
int8_t headVer;
|
||||
int16_t msgType;
|
||||
int8_t reserved;
|
||||
int16_t msgType;
|
||||
int32_t len;
|
||||
int64_t ingestTs; // not implemented
|
||||
int64_t version;
|
||||
|
||||
// sync meta
|
||||
SSyncLogMeta syncMeta;
|
||||
|
||||
char body[];
|
||||
} SWalReadHead;
|
||||
|
||||
|
@ -158,6 +173,8 @@ int32_t walAlter(SWal *, SWalCfg *pCfg);
|
|||
void walClose(SWal *);
|
||||
|
||||
// write
|
||||
int64_t walWriteWithSyncInfo(SWal *, int64_t index, tmsg_t msgType, SSyncLogMeta syncMeta, const void *body,
|
||||
int32_t bodyLen);
|
||||
int64_t walWrite(SWal *, int64_t index, tmsg_t msgType, const void *body, int32_t bodyLen);
|
||||
void walFsync(SWal *, bool force);
|
||||
|
||||
|
|
|
@ -75,7 +75,6 @@ extern "C" {
|
|||
#include "osDef.h"
|
||||
#include "osDir.h"
|
||||
#include "osEndian.h"
|
||||
#include "osEnv.h"
|
||||
#include "osFile.h"
|
||||
#include "osLocale.h"
|
||||
#include "osLz4.h"
|
||||
|
@ -93,8 +92,9 @@ extern "C" {
|
|||
#include "osTime.h"
|
||||
#include "osTimer.h"
|
||||
#include "osTimezone.h"
|
||||
#include "osEnv.h"
|
||||
|
||||
void osInit();
|
||||
void osDefaultInit();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
extern char tsOsName[];
|
||||
extern char tsTimezone[];
|
||||
extern char tsTimezoneStr[];
|
||||
extern enum TdTimezone tsTimezone;
|
||||
extern char tsCharset[];
|
||||
extern char tsLocale[];
|
||||
extern int8_t tsDaylight;
|
||||
|
@ -43,11 +44,12 @@ extern SDiskSpace tsDataSpace;
|
|||
extern SDiskSpace tsLogSpace;
|
||||
extern SDiskSpace tsTempSpace;
|
||||
|
||||
void osInit();
|
||||
void osDefaultInit();
|
||||
void osUpdate();
|
||||
void osCleanup();
|
||||
bool osLogSpaceAvailable();
|
||||
void osSetTimezone(const char *timezone);
|
||||
void osSetSystemLocale(const char *inLocale, const char *inCharSet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -26,8 +26,37 @@ extern "C" {
|
|||
#define tzset TZSET_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
void taosGetSystemTimezone(char *outTimezone);
|
||||
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight);
|
||||
enum TdTimezone
|
||||
{
|
||||
TdWestZone12=-12,
|
||||
TdWestZone11,
|
||||
TdWestZone10,
|
||||
TdWestZone9,
|
||||
TdWestZone8,
|
||||
TdWestZone7,
|
||||
TdWestZone6,
|
||||
TdWestZone5,
|
||||
TdWestZone4,
|
||||
TdWestZone3,
|
||||
TdWestZone2,
|
||||
TdWestZone1,
|
||||
TdZeroZone,
|
||||
TdEastZone1,
|
||||
TdEastZone2,
|
||||
TdEastZone3,
|
||||
TdEastZone4,
|
||||
TdEastZone5,
|
||||
TdEastZone6,
|
||||
TdEastZone7,
|
||||
TdEastZone8,
|
||||
TdEastZone9,
|
||||
TdEastZone10,
|
||||
TdEastZone11,
|
||||
TdEastZone12
|
||||
};
|
||||
|
||||
void taosGetSystemTimezone(char *outTimezone, enum TdTimezone *tsTimezone);
|
||||
void taosSetSystemTimezone(const char *inTimezone, char *outTimezone, int8_t *outDaylight, enum TdTimezone *tsTimezone);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#ifndef _TD_UTIL_TAOS_ERROR_H_
|
||||
#define _TD_UTIL_TAOS_ERROR_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -109,6 +109,8 @@ extern const int32_t TYPE_BYTES[15];
|
|||
#define TSDB_INS_TABLE_USER_USERS "user_users"
|
||||
#define TSDB_INS_TABLE_VGROUPS "vgroups"
|
||||
|
||||
#define TSDB_INS_USER_STABLES_DBNAME_COLID 2
|
||||
|
||||
#define TSDB_TICK_PER_SECOND(precision) \
|
||||
((int64_t)((precision) == TSDB_TIME_PRECISION_MILLI ? 1e3L \
|
||||
: ((precision) == TSDB_TIME_PRECISION_MICRO ? 1e6L : 1e9L)))
|
||||
|
|
|
@ -192,6 +192,10 @@ static void doDestroyRequest(void *p) {
|
|||
doFreeReqResultInfo(&pRequest->body.resInfo);
|
||||
qDestroyQueryPlan(pRequest->body.pDag);
|
||||
|
||||
if (pRequest->body.queryJob != 0) {
|
||||
schedulerFreeJob(pRequest->body.queryJob);
|
||||
}
|
||||
|
||||
if (pRequest->body.showInfo.pArray != NULL) {
|
||||
taosArrayDestroy(pRequest->body.showInfo.pArray);
|
||||
}
|
||||
|
@ -404,10 +408,10 @@ int taos_options_imp(TSDB_OPTION option, const char *str) {
|
|||
assert(cfg != NULL);
|
||||
|
||||
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
|
||||
tstrncpy(tsTimezone, str, TD_TIMEZONE_LEN);
|
||||
tstrncpy(tsTimezoneStr, str, TD_TIMEZONE_LEN);
|
||||
tsSetTimeZone();
|
||||
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
|
||||
tscDebug("timezone set:%s, input:%s by taos_options", tsTimezone, str);
|
||||
tscDebug("timezone set:%s, input:%s by taos_options", tsTimezoneStr, str);
|
||||
} else {
|
||||
tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, str,
|
||||
tsCfgStatusStr[cfg->cfgStatus], (char *)cfg->ptr);
|
||||
|
|
|
@ -199,7 +199,8 @@ int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArra
|
|||
.queryId = pRequest->requestId,
|
||||
.acctId = pRequest->pTscObj->acctId,
|
||||
.mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
|
||||
.pAstRoot = pQuery->pRoot
|
||||
.pAstRoot = pQuery->pRoot,
|
||||
.showRewrite = pQuery->showRewrite
|
||||
};
|
||||
int32_t code = qCreateQueryPlan(&cxt, pPlan, pNodeList);
|
||||
if (code != 0) {
|
||||
|
@ -330,6 +331,8 @@ SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) {
|
|||
pRequest->code = code;
|
||||
break;
|
||||
}
|
||||
|
||||
destroyRequest(pRequest);
|
||||
}
|
||||
|
||||
return pRequest;
|
||||
|
|
|
@ -27,9 +27,7 @@
|
|||
#include "tref.h"
|
||||
|
||||
struct tmq_list_t {
|
||||
int32_t cnt;
|
||||
int32_t tot;
|
||||
char* elems[];
|
||||
SArray container;
|
||||
};
|
||||
|
||||
struct tmq_topic_vgroup_t {
|
||||
|
@ -45,11 +43,14 @@ struct tmq_topic_vgroup_list_t {
|
|||
struct tmq_conf_t {
|
||||
char clientId[256];
|
||||
char groupId[TSDB_CGROUP_LEN];
|
||||
int8_t auto_commit;
|
||||
int8_t autoCommit;
|
||||
int8_t resetOffset;
|
||||
uint16_t port;
|
||||
char* ip;
|
||||
char* user;
|
||||
char* pass;
|
||||
char* db;
|
||||
tmq_commit_cb* commit_cb;
|
||||
/*char* ip;*/
|
||||
/*uint16_t port;*/
|
||||
};
|
||||
|
||||
struct tmq_t {
|
||||
|
@ -104,6 +105,7 @@ typedef struct {
|
|||
int64_t topicId;
|
||||
int32_t nextVgIdx;
|
||||
SArray* vgs; // SArray<SMqClientVg>
|
||||
SSchemaWrapper schema;
|
||||
} SMqClientTopic;
|
||||
|
||||
typedef struct {
|
||||
|
@ -137,7 +139,7 @@ typedef struct {
|
|||
|
||||
tmq_conf_t* tmq_conf_new() {
|
||||
tmq_conf_t* conf = taosMemoryCalloc(1, sizeof(tmq_conf_t));
|
||||
conf->auto_commit = false;
|
||||
conf->autoCommit = false;
|
||||
conf->resetOffset = TMQ_CONF__RESET_OFFSET__EARLIEAST;
|
||||
return conf;
|
||||
}
|
||||
|
@ -151,21 +153,24 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
|||
strcpy(conf->groupId, value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
|
||||
if (strcmp(key, "client.id") == 0) {
|
||||
strcpy(conf->clientId, value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
|
||||
if (strcmp(key, "enable.auto.commit") == 0) {
|
||||
if (strcmp(value, "true") == 0) {
|
||||
conf->auto_commit = true;
|
||||
conf->autoCommit = true;
|
||||
return TMQ_CONF_OK;
|
||||
} else if (strcmp(value, "false") == 0) {
|
||||
conf->auto_commit = false;
|
||||
conf->autoCommit = false;
|
||||
return TMQ_CONF_OK;
|
||||
} else {
|
||||
return TMQ_CONF_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(key, "auto.offset.reset") == 0) {
|
||||
if (strcmp(value, "none") == 0) {
|
||||
conf->resetOffset = TMQ_CONF__RESET_OFFSET__NONE;
|
||||
|
@ -180,26 +185,49 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value
|
|||
return TMQ_CONF_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(key, "connection.ip") == 0) {
|
||||
conf->ip = strdup(value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
if (strcmp(key, "connection.user") == 0) {
|
||||
conf->user = strdup(value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
if (strcmp(key, "connection.pass") == 0) {
|
||||
conf->pass = strdup(value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
if (strcmp(key, "connection.port") == 0) {
|
||||
conf->port = atoi(value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
if (strcmp(key, "connection.db") == 0) {
|
||||
conf->db = strdup(value);
|
||||
return TMQ_CONF_OK;
|
||||
}
|
||||
|
||||
return TMQ_CONF_UNKNOWN;
|
||||
}
|
||||
|
||||
tmq_list_t* tmq_list_new() {
|
||||
tmq_list_t* ptr = taosMemoryMalloc(sizeof(tmq_list_t) + 8 * sizeof(char*));
|
||||
if (ptr == NULL) {
|
||||
return ptr;
|
||||
}
|
||||
ptr->cnt = 0;
|
||||
ptr->tot = 8;
|
||||
return ptr;
|
||||
//
|
||||
return (tmq_list_t*)taosArrayInit(0, sizeof(void*));
|
||||
}
|
||||
|
||||
int32_t tmq_list_append(tmq_list_t* ptr, const char* src) {
|
||||
if (ptr->cnt >= ptr->tot - 1) return -1;
|
||||
ptr->elems[ptr->cnt] = strdup(src);
|
||||
ptr->cnt++;
|
||||
int32_t tmq_list_append(tmq_list_t* list, const char* src) {
|
||||
SArray* container = &list->container;
|
||||
char* topic = strdup(src);
|
||||
if (taosArrayPush(container, &topic) == NULL) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tmq_list_destroy(tmq_list_t* list) {
|
||||
SArray* container = (SArray*)list;
|
||||
/*taosArrayDestroy(container);*/
|
||||
taosArrayDestroyEx(container, (void (*)(void*))taosMemoryFree);
|
||||
}
|
||||
|
||||
void tmqClearUnhandleMsg(tmq_t* tmq) {
|
||||
tmq_message_t* msg;
|
||||
while (1) {
|
||||
|
@ -268,17 +296,57 @@ tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errs
|
|||
// set conf
|
||||
strcpy(pTmq->clientId, conf->clientId);
|
||||
strcpy(pTmq->groupId, conf->groupId);
|
||||
pTmq->autoCommit = conf->auto_commit;
|
||||
pTmq->autoCommit = conf->autoCommit;
|
||||
pTmq->commit_cb = conf->commit_cb;
|
||||
pTmq->resetOffsetCfg = conf->resetOffset;
|
||||
|
||||
tsem_init(&pTmq->rspSem, 0, 0);
|
||||
|
||||
pTmq->consumerId = generateRequestId() & (((uint64_t)-1) >> 1);
|
||||
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
|
||||
if (pTmq->clientTopics == NULL) {
|
||||
taosMemoryFree(pTmq);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTmq->mqueue = taosOpenQueue();
|
||||
pTmq->qall = taosAllocateQall();
|
||||
|
||||
tsem_init(&pTmq->rspSem, 0, 0);
|
||||
|
||||
return pTmq;
|
||||
}
|
||||
|
||||
tmq_t* tmq_consumer_new1(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
|
||||
tmq_t* pTmq = taosMemoryCalloc(1, sizeof(tmq_t));
|
||||
if (pTmq == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
pTmq->pTscObj = taos_connect(conf->ip, conf->user, conf->pass, conf->db, conf->port);
|
||||
|
||||
pTmq->inWaiting = 0;
|
||||
pTmq->status = 0;
|
||||
pTmq->pollCnt = 0;
|
||||
pTmq->epoch = 0;
|
||||
pTmq->waitingRequest = 0;
|
||||
pTmq->readyRequest = 0;
|
||||
// set conf
|
||||
strcpy(pTmq->clientId, conf->clientId);
|
||||
strcpy(pTmq->groupId, conf->groupId);
|
||||
pTmq->autoCommit = conf->autoCommit;
|
||||
pTmq->commit_cb = conf->commit_cb;
|
||||
pTmq->resetOffsetCfg = conf->resetOffset;
|
||||
|
||||
pTmq->consumerId = generateRequestId() & (((uint64_t)-1) >> 1);
|
||||
pTmq->clientTopics = taosArrayInit(0, sizeof(SMqClientTopic));
|
||||
if (pTmq->clientTopics == NULL) {
|
||||
taosMemoryFree(pTmq);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pTmq->mqueue = taosOpenQueue();
|
||||
pTmq->qall = taosAllocateQall();
|
||||
|
||||
tsem_init(&pTmq->rspSem, 0, 0);
|
||||
|
||||
return pTmq;
|
||||
}
|
||||
|
||||
|
@ -372,7 +440,8 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in
|
|||
|
||||
tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
|
||||
SRequestObj* pRequest = NULL;
|
||||
int32_t sz = topic_list->cnt;
|
||||
SArray* container = &topic_list->container;
|
||||
int32_t sz = taosArrayGetSize(container);
|
||||
// destroy ex
|
||||
taosArrayDestroy(tmq->clientTopics);
|
||||
tmq->clientTopics = taosArrayInit(sz, sizeof(SMqClientTopic));
|
||||
|
@ -384,7 +453,8 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) {
|
|||
req.topicNames = taosArrayInit(sz, sizeof(void*));
|
||||
|
||||
for (int i = 0; i < sz; i++) {
|
||||
char* topicName = topic_list->elems[i];
|
||||
/*char* topicName = topic_list->elems[i];*/
|
||||
char* topicName = taosArrayGetP(container, i);
|
||||
|
||||
SName name = {0};
|
||||
char* dbName = getDbOfConnection(tmq->pTscObj);
|
||||
|
|
|
@ -1380,7 +1380,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
|
|||
|
||||
return buf;
|
||||
}
|
||||
void blockDebugShowData(SArray* dataBlocks) {
|
||||
void blockDebugShowData(const SArray* dataBlocks) {
|
||||
char pBuf[128];
|
||||
int32_t sz = taosArrayGetSize(dataBlocks);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
|
@ -1398,13 +1398,17 @@ void blockDebugShowData(SArray* dataBlocks) {
|
|||
printf(" %25s |", pBuf);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
printf(" %15d |", *(int32_t*)var);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
printf(" %15u |", *(uint32_t*)var);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
printf(" %15ld |", *(int64_t*)var);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
printf(" %15lu |", *(uint64_t*)var);
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
|
|
|
@ -122,7 +122,7 @@ bool tsRetrieveBlockingModel = 0;
|
|||
// last_row(*), first(*), last_row(ts, col1, col2) query, the result fields will be the original column name
|
||||
bool tsKeepOriginalColumnName = 0;
|
||||
|
||||
// long query death-lock
|
||||
// kill long query
|
||||
bool tsDeadLockKillQuery = 0;
|
||||
|
||||
// tsdb config
|
||||
|
@ -303,7 +303,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
|
|||
static int32_t taosAddSystemCfg(SConfig *pCfg) {
|
||||
SysNameInfo info = taosGetSysNameInfo();
|
||||
|
||||
if (cfgAddTimezone(pCfg, "timezone", tsTimezone) != 0) return -1;
|
||||
if (cfgAddTimezone(pCfg, "timezone", tsTimezoneStr) != 0) return -1;
|
||||
if (cfgAddLocale(pCfg, "locale", tsLocale) != 0) return -1;
|
||||
if (cfgAddCharset(pCfg, "charset", tsCharset) != 0) return -1;
|
||||
if (cfgAddBool(pCfg, "enableCoreFile", 1, 1) != 0) return -1;
|
||||
|
@ -431,12 +431,13 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
|||
static void taosSetSystemCfg(SConfig *pCfg) {
|
||||
SConfigItem *pItem = cfgGetItem(pCfg, "timezone");
|
||||
osSetTimezone(pItem->str);
|
||||
uDebug("timezone format changed from %s to %s", pItem->str, tsTimezone);
|
||||
cfgSetItem(pCfg, "timezone", tsTimezone, pItem->stype);
|
||||
uDebug("timezone format changed from %s to %s", pItem->str, tsTimezoneStr);
|
||||
cfgSetItem(pCfg, "timezone", tsTimezoneStr, pItem->stype);
|
||||
|
||||
const char *locale = cfgGetItem(pCfg, "locale")->str;
|
||||
const char *charset = cfgGetItem(pCfg, "charset")->str;
|
||||
taosSetSystemLocale(locale, charset);
|
||||
osSetSystemLocale(locale, charset);
|
||||
|
||||
bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval;
|
||||
taosSetConsoleEcho(enableCore);
|
||||
|
@ -483,7 +484,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
|
||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char *envFile,
|
||||
const char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||
osInit();
|
||||
osDefaultInit();
|
||||
|
||||
SConfig *pCfg = cfgInit();
|
||||
if (pCfg == NULL) return -1;
|
||||
|
|
|
@ -2871,7 +2871,6 @@ int32_t tSerializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *pR
|
|||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeU64(&encoder, pRsp->seqId) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pRsp->epId.nodeId) < 0) return -1;
|
||||
if (tEncodeU16(&encoder, pRsp->epId.ep.port) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pRsp->epId.ep.fqdn) < 0) return -1;
|
||||
|
@ -2900,7 +2899,6 @@ int32_t tDeserializeSSchedulerHbRsp(void *buf, int32_t bufLen, SSchedulerHbRsp *
|
|||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeU64(&decoder, &pRsp->seqId) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pRsp->epId.nodeId) < 0) return -1;
|
||||
if (tDecodeU16(&decoder, &pRsp->epId.ep.port) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pRsp->epId.ep.fqdn) < 0) return -1;
|
||||
|
|
|
@ -134,6 +134,7 @@ void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pReq) {
|
|||
dndGetStartup(pDnode, pStartup);
|
||||
|
||||
dDebug("startup req is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished);
|
||||
SRpcMsg rpcRsp = {.handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq)};
|
||||
SRpcMsg rpcRsp = {
|
||||
.handle = pReq->handle, .pCont = pStartup, .contLen = sizeof(SStartupReq), .ahandle = pReq->ahandle};
|
||||
rpcSendResponse(&rpcRsp);
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) {
|
|||
req.clusterCfg.checkTime = 0;
|
||||
char timestr[32] = "1970-01-01 00:00:00.00";
|
||||
(void)taosParseTime(timestr, &req.clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||
memcpy(req.clusterCfg.timezone, tsTimezone, TD_TIMEZONE_LEN);
|
||||
memcpy(req.clusterCfg.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
|
||||
memcpy(req.clusterCfg.locale, tsLocale, TD_LOCALE_LEN);
|
||||
memcpy(req.clusterCfg.charset, tsCharset, TD_LOCALE_LEN);
|
||||
taosRUnLockLatch(&pMgmt->latch);
|
||||
|
|
|
@ -28,6 +28,7 @@ typedef struct SMnodeMgmt {
|
|||
SDnode *pDnode;
|
||||
SMgmtWrapper *pWrapper;
|
||||
const char *path;
|
||||
SSingleWorker queryWorker;
|
||||
SSingleWorker readWorker;
|
||||
SSingleWorker writeWorker;
|
||||
SSingleWorker syncWorker;
|
||||
|
@ -57,8 +58,10 @@ void mmStopWorker(SMnodeMgmt *pMgmt);
|
|||
int32_t mmProcessWriteMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg);
|
||||
int32_t mmProcessSyncMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg);
|
||||
int32_t mmProcessReadMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg);
|
||||
int32_t mmProcessQueryMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg);
|
||||
int32_t mmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpcMsg);
|
||||
int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpcMsg);
|
||||
int32_t mmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -45,7 +45,8 @@ static void mmInitOption(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) {
|
|||
|
||||
SMsgCb msgCb = {0};
|
||||
msgCb.pWrapper = pMgmt->pWrapper;
|
||||
msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToReadQueue;
|
||||
msgCb.queueFps[QUERY_QUEUE] = mmPutMsgToQueryQueue;
|
||||
msgCb.queueFps[READ_QUEUE] = mmPutMsgToReadQueue;
|
||||
msgCb.queueFps[WRITE_QUEUE] = mmPutMsgToWriteQueue;
|
||||
msgCb.sendReqFp = dndSendReqToDnode;
|
||||
msgCb.sendMnodeReqFp = dndSendReqToMnode;
|
||||
|
|
|
@ -156,9 +156,10 @@ void mmInitMsgHandles(SMgmtWrapper *pWrapper) {
|
|||
dndSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA_RSP, (NodeMsgFp)mmProcessWriteMsg, VND_VGID);
|
||||
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)mmProcessReadMsg, MND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)mmProcessReadMsg, MND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)mmProcessReadMsg, MND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, (NodeMsgFp)mmProcessReadMsg, MND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY, (NodeMsgFp)mmProcessQueryMsg, MND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, (NodeMsgFp)mmProcessQueryMsg, MND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_FETCH, (NodeMsgFp)mmProcessQueryMsg, MND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_DROP_TASK, (NodeMsgFp)mmProcessQueryMsg, MND_VGID);
|
||||
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, (NodeMsgFp)mmProcessQueryMsg, MND_VGID);
|
||||
|
||||
}
|
||||
|
|
|
@ -44,6 +44,30 @@ static void mmProcessQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
|
|||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
static void mmProcessQueryQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
|
||||
SMnodeMgmt *pMgmt = pInfo->ahandle;
|
||||
|
||||
dTrace("msg:%p, will be processed in mnode queue", pMsg);
|
||||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
int32_t code = -1;
|
||||
|
||||
pMsg->pNode = pMgmt->pMnode;
|
||||
code = mndProcessMsg(pMsg);
|
||||
|
||||
if (pRpc->msgType & 1U) {
|
||||
if (pRpc->handle == NULL) return;
|
||||
if (code != 0) {
|
||||
SRpcMsg rsp = {.handle = pRpc->handle, .code = code, .ahandle = pRpc->ahandle};
|
||||
dndSendRsp(pMgmt->pWrapper, &rsp);
|
||||
}
|
||||
}
|
||||
|
||||
dTrace("msg:%p, is freed, result:0x%04x:%s", pMsg, code & 0XFFFF, tstrerror(code));
|
||||
rpcFreeCont(pRpc->pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
|
||||
|
||||
static int32_t mmPutMsgToWorker(SMnodeMgmt *pMgmt, SSingleWorker *pWorker, SNodeMsg *pMsg) {
|
||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||
return taosWriteQitem(pWorker->queue, pMsg);
|
||||
|
@ -61,6 +85,10 @@ int32_t mmProcessReadMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) {
|
|||
return mmPutMsgToWorker(pMgmt, &pMgmt->readWorker, pMsg);
|
||||
}
|
||||
|
||||
int32_t mmProcessQueryMsg(SMnodeMgmt *pMgmt, SNodeMsg *pMsg) {
|
||||
return mmPutMsgToWorker(pMgmt, &pMgmt->queryWorker, pMsg);
|
||||
}
|
||||
|
||||
static int32_t mmPutRpcMsgToWorker(SMnodeMgmt *pMgmt, SSingleWorker *pWorker, SRpcMsg *pRpc) {
|
||||
SNodeMsg *pMsg = taosAllocateQitem(sizeof(SNodeMsg));
|
||||
if (pMsg == NULL) {
|
||||
|
@ -90,8 +118,20 @@ int32_t mmPutMsgToReadQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) {
|
|||
return mmPutRpcMsgToWorker(pMgmt, &pMgmt->readWorker, pRpc);
|
||||
}
|
||||
|
||||
int32_t mmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) {
|
||||
SMnodeMgmt *pMgmt = pWrapper->pMgmt;
|
||||
return mmPutRpcMsgToWorker(pMgmt, &pMgmt->queryWorker, pRpc);
|
||||
}
|
||||
|
||||
|
||||
int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||
SSingleWorkerCfg cfg = {.minNum = 0, .maxNum = 1, .name = "mnode-read", .fp = (FItem)mmProcessQueue, .param = pMgmt};
|
||||
SSingleWorkerCfg queryCfg = {.minNum = 0, .maxNum = 1, .name = "mnode-query", .fp = (FItem)mmProcessQueryQueue, .param = pMgmt};
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg) != 0) {
|
||||
dError("failed to start mnode-query worker since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tSingleWorkerInit(&pMgmt->readWorker, &cfg) != 0) {
|
||||
dError("failed to start mnode-read worker since %s", terrstr());
|
||||
|
@ -114,6 +154,7 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
|||
|
||||
void mmStopWorker(SMnodeMgmt *pMgmt) {
|
||||
tSingleWorkerCleanup(&pMgmt->readWorker);
|
||||
tSingleWorkerCleanup(&pMgmt->queryWorker);
|
||||
tSingleWorkerCleanup(&pMgmt->writeWorker);
|
||||
tSingleWorkerCleanup(&pMgmt->syncWorker);
|
||||
dDebug("mnode workers are closed");
|
||||
|
|
|
@ -165,8 +165,8 @@ static int32_t vmPutNodeMsgToQueue(SVnodesMgmt *pMgmt, SNodeMsg *pMsg, EQueueTyp
|
|||
int32_t code = -1;
|
||||
|
||||
SMsgHead *pHead = pRpc->pCont;
|
||||
pHead->contLen = htonl(pHead->contLen);
|
||||
pHead->vgId = htonl(pHead->vgId);
|
||||
pHead->contLen = ntohl(pHead->contLen);
|
||||
pHead->vgId = ntohl(pHead->vgId);
|
||||
|
||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
|
||||
if (pVnode == NULL) {
|
||||
|
|
|
@ -6,7 +6,7 @@ target_include_directories(
|
|||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
mnode scheduler sdb wal transport cjson sync monitor stream parser
|
||||
mnode scheduler sdb wal transport cjson sync monitor executor qworker stream parser
|
||||
)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
|
|
|
@ -645,6 +645,7 @@ typedef struct {
|
|||
char* sql;
|
||||
char* logicalPlan;
|
||||
char* physicalPlan;
|
||||
SSchemaWrapper schema;
|
||||
} SMqTopicObj;
|
||||
|
||||
typedef struct {
|
||||
|
@ -738,7 +739,7 @@ typedef struct {
|
|||
char* logicalPlan;
|
||||
char* physicalPlan;
|
||||
SArray* tasks; // SArray<SArray<SStreamTask>>
|
||||
SArray* ColAlias; // SArray<char*>
|
||||
SSchemaWrapper outputSchema;
|
||||
} SStreamObj;
|
||||
|
||||
int32_t tEncodeSStreamObj(SCoder* pEncoder, const SStreamObj* pObj);
|
||||
|
|
|
@ -59,6 +59,8 @@ typedef struct SMnodeLoad {
|
|||
int64_t compStorage;
|
||||
} SMnodeLoad;
|
||||
|
||||
typedef struct SQWorkerMgmt SQHandle;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
MndInitFp initFp;
|
||||
|
@ -112,6 +114,7 @@ typedef struct SMnode {
|
|||
SSdb *pSdb;
|
||||
SMgmtWrapper *pWrapper;
|
||||
SArray *pSteps;
|
||||
SQHandle *pQuery;
|
||||
SShowMgmt showMgmt;
|
||||
SProfileMgmt profileMgmt;
|
||||
STelemMgmt telemMgmt;
|
||||
|
|
|
@ -12,3 +12,22 @@
|
|||
* 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_MND_QUERY_H_
|
||||
#define _TD_MND_QUERY_H_
|
||||
|
||||
#include "mndInt.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mndInitQuery(SMnode *pMnode);
|
||||
void mndCleanupQuery(SMnode *pMnode);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_MND_QUERY_H_*/
|
|
@ -1035,6 +1035,8 @@ static int32_t mndProcessUseDbReq(SNodeMsg *pReq) {
|
|||
code = 0;
|
||||
}
|
||||
usedbRsp.vgNum = taosArrayGetSize(usedbRsp.pVgroupInfos);
|
||||
|
||||
// no jump, need to construct rsp
|
||||
} else {
|
||||
pDb = mndAcquireDb(pMnode, usedbReq.db);
|
||||
if (pDb == NULL) {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) {
|
||||
int32_t sz = 0;
|
||||
int32_t outputNameSz = 0;
|
||||
/*int32_t outputNameSz = 0;*/
|
||||
if (tEncodeCStr(pEncoder, pObj->name) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pObj->db) < 0) return -1;
|
||||
if (tEncodeI64(pEncoder, pObj->createTime) < 0) return -1;
|
||||
|
@ -45,6 +45,9 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) {
|
|||
}
|
||||
}
|
||||
|
||||
if (tEncodeSSchemaWrapper(pEncoder, &pObj->outputSchema) < 0) return -1;
|
||||
|
||||
#if 0
|
||||
if (pObj->ColAlias != NULL) {
|
||||
outputNameSz = taosArrayGetSize(pObj->ColAlias);
|
||||
}
|
||||
|
@ -53,6 +56,7 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) {
|
|||
char *name = taosArrayGetP(pObj->ColAlias, i);
|
||||
if (tEncodeCStr(pEncoder, name) < 0) return -1;
|
||||
}
|
||||
#endif
|
||||
return pEncoder->pos;
|
||||
}
|
||||
|
||||
|
@ -85,6 +89,9 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) {
|
|||
taosArrayPush(pObj->tasks, pArray);
|
||||
}
|
||||
}
|
||||
|
||||
if (tDecodeSSchemaWrapper(pDecoder, &pObj->outputSchema) < 0) return -1;
|
||||
#if 0
|
||||
int32_t outputNameSz;
|
||||
if (tDecodeI32(pDecoder, &outputNameSz) < 0) return -1;
|
||||
if (outputNameSz != 0) {
|
||||
|
@ -98,5 +105,6 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) {
|
|||
if (tDecodeCStrAlloc(pDecoder, &name) < 0) return -1;
|
||||
taosArrayPush(pObj->ColAlias, &name);
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -277,8 +277,8 @@ static int32_t mndCheckClusterCfgPara(SMnode *pMnode, const SClusterCfg *pCfg) {
|
|||
return DND_REASON_STATUS_INTERVAL_NOT_MATCH;
|
||||
}
|
||||
|
||||
if ((0 != strcasecmp(pCfg->timezone, tsTimezone)) && (pMnode->checkTime != pCfg->checkTime)) {
|
||||
mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezone,
|
||||
if ((0 != strcasecmp(pCfg->timezone, tsTimezoneStr)) && (pMnode->checkTime != pCfg->checkTime)) {
|
||||
mError("timezone [%s - %s] [%" PRId64 " - %" PRId64 "] cfg inconsistent", pCfg->timezone, tsTimezoneStr,
|
||||
pCfg->checkTime, pMnode->checkTime);
|
||||
return DND_REASON_TIME_ZONE_NOT_MATCH;
|
||||
}
|
||||
|
@ -677,7 +677,7 @@ static int32_t mndRetrieveConfigs(SNodeMsg *pReq, SShowObj *pShow, char *data, i
|
|||
totalRows++;
|
||||
|
||||
cfgOpts[totalRows] = "timezone";
|
||||
snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezone);
|
||||
snprintf(cfgVals[totalRows], TSDB_CONIIG_VALUE_LEN, "%s", tsTimezoneStr);
|
||||
totalRows++;
|
||||
|
||||
cfgOpts[totalRows] = "locale";
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
#define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
|
||||
//!!!! Note: only APPEND columns in below tables, NO insert !!!!
|
||||
static const SInfosTableSchema dnodesSchema[] = {{.name = "id", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT},
|
||||
{.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "vnodes", .bytes = 2, .type = TSDB_DATA_TYPE_SMALLINT},
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 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 "mndQuery.h"
|
||||
#include "mndMnode.h"
|
||||
#include "executor.h"
|
||||
#include "qworker.h"
|
||||
|
||||
int32_t mndProcessQueryMsg(SNodeMsg *pReq) {
|
||||
mTrace("message in query queue is processing");
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
SReadHandle handle = {0};
|
||||
|
||||
switch (pReq->rpcMsg.msgType) {
|
||||
case TDMT_VND_QUERY:
|
||||
return qWorkerProcessQueryMsg(&handle, pMnode->pQuery, &pReq->rpcMsg);
|
||||
case TDMT_VND_QUERY_CONTINUE:
|
||||
return qWorkerProcessCQueryMsg(&handle, pMnode->pQuery, &pReq->rpcMsg);
|
||||
default:
|
||||
mError("unknown msg type:%d in query queue", pReq->rpcMsg.msgType);
|
||||
return TSDB_CODE_VND_APP_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mndProcessFetchMsg(SNodeMsg *pReq) {
|
||||
mTrace("message in fetch queue is processing");
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
|
||||
switch (pReq->rpcMsg.msgType) {
|
||||
case TDMT_VND_FETCH:
|
||||
return qWorkerProcessFetchMsg(pMnode, pMnode->pQuery, &pReq->rpcMsg);
|
||||
case TDMT_VND_DROP_TASK:
|
||||
return qWorkerProcessDropMsg(pMnode, pMnode->pQuery, &pReq->rpcMsg);
|
||||
case TDMT_VND_QUERY_HEARTBEAT:
|
||||
return qWorkerProcessHbMsg(pMnode, pMnode->pQuery, &pReq->rpcMsg);
|
||||
default:
|
||||
mError("unknown msg type:%d in fetch queue", pReq->rpcMsg.msgType);
|
||||
return TSDB_CODE_VND_APP_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t mndInitQuery(SMnode *pMnode) {
|
||||
int32_t code = qWorkerInit(NODE_TYPE_MNODE, MND_VGID, NULL, (void **)&pMnode->pQuery, &pMnode->msgCb);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_QUERY, mndProcessQueryMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_QUERY_CONTINUE, mndProcessQueryMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_FETCH, mndProcessFetchMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_DROP_TASK, mndProcessFetchMsg);
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_QUERY_HEARTBEAT, mndProcessFetchMsg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mndCleanupQuery(SMnode *pMnode) { qWorkerDestroy((void **)&pMnode->pQuery); }
|
||||
|
|
@ -66,8 +66,11 @@ int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet
|
|||
|
||||
int32_t mndAssignTaskToVg(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SSubplan* plan, const SVgObj* pVgroup) {
|
||||
int32_t msgLen;
|
||||
pTask->nodeId = pVgroup->vgId;
|
||||
pTask->epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
||||
plan->execNode.nodeId = pVgroup->vgId;
|
||||
plan->execNode.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
plan->execNode.epSet = pTask->epSet;
|
||||
|
||||
if (qSubPlanToString(plan, &pTask->exec.qmsg, &msgLen) < 0) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
|
@ -86,8 +89,12 @@ SSnodeObj* mndSchedFetchSnode(SMnode* pMnode) {
|
|||
int32_t mndAssignTaskToSnode(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask, SSubplan* plan,
|
||||
const SSnodeObj* pSnode) {
|
||||
int32_t msgLen;
|
||||
plan->execNode.nodeId = pSnode->id;
|
||||
plan->execNode.epSet = mndAcquireEpFromSnode(pMnode, pSnode);
|
||||
|
||||
pTask->nodeId = 0;
|
||||
pTask->epSet = mndAcquireEpFromSnode(pMnode, pSnode);
|
||||
|
||||
plan->execNode.nodeId = 0;
|
||||
plan->execNode.epSet = pTask->epSet;
|
||||
|
||||
if (qSubPlanToString(plan, &pTask->exec.qmsg, &msgLen) < 0) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
|
@ -97,9 +104,23 @@ int32_t mndAssignTaskToSnode(SMnode* pMnode, STrans* pTrans, SStreamTask* pTask,
|
|||
return 0;
|
||||
}
|
||||
|
||||
SVgObj* mndSchedFetchOneVg(SMnode* pMnode, int64_t dbUid) {
|
||||
void* pIter = NULL;
|
||||
SVgObj* pVgroup = NULL;
|
||||
while (1) {
|
||||
pIter = sdbFetch(pMnode->pSdb, SDB_VGROUP, pIter, (void**)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (pVgroup->dbUid != dbUid) {
|
||||
sdbRelease(pMnode->pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
return pVgroup;
|
||||
}
|
||||
return pVgroup;
|
||||
}
|
||||
|
||||
int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||
SSdb* pSdb = pMnode->pSdb;
|
||||
SVgObj* pVgroup = NULL;
|
||||
SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan);
|
||||
if (pPlan == NULL) {
|
||||
terrno = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
|
@ -108,80 +129,144 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
ASSERT(pStream->vgNum == 0);
|
||||
|
||||
int32_t totLevel = LIST_LENGTH(pPlan->pSubplans);
|
||||
pStream->tasks = taosArrayInit(totLevel, sizeof(SArray));
|
||||
int32_t lastUsedVgId = 0;
|
||||
ASSERT(totLevel <= 2);
|
||||
pStream->tasks = taosArrayInit(totLevel, sizeof(void*));
|
||||
|
||||
// gather vnodes
|
||||
// gather snodes
|
||||
// iterate plan, expand source to vnodes and assign ep to each task
|
||||
// iterate tasks, assign sink type and sink ep to each task
|
||||
|
||||
for (int32_t revLevel = totLevel - 1; revLevel >= 0; revLevel--) {
|
||||
int32_t level = totLevel - 1 - revLevel;
|
||||
SArray* taskOneLevel = taosArrayInit(0, sizeof(SStreamTask));
|
||||
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, revLevel);
|
||||
int32_t opNum = LIST_LENGTH(inner->pNodeList);
|
||||
ASSERT(opNum == 1);
|
||||
for (int32_t level = 0; level < totLevel; level++) {
|
||||
SArray* taskOneLevel = taosArrayInit(0, sizeof(void*));
|
||||
SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, level);
|
||||
ASSERT(LIST_LENGTH(inner->pNodeList) == 1);
|
||||
|
||||
SSubplan* plan = nodesListGetNode(inner->pNodeList, 0);
|
||||
if (level == 0) {
|
||||
|
||||
// if (level == totLevel - 1 /* or no snode */) {
|
||||
if (level == totLevel - 1) {
|
||||
// last level, source, must assign to vnode
|
||||
// must be scan type
|
||||
ASSERT(plan->subplanType == SUBPLAN_TYPE_SCAN);
|
||||
|
||||
// replicate task to each vnode
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
SVgObj* pVgroup;
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (pVgroup->dbUid != pStream->dbUid) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
|
||||
lastUsedVgId = pVgroup->vgId;
|
||||
pStream->vgNum++;
|
||||
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
/*pTask->level = level;*/
|
||||
// TODO
|
||||
/*pTask->sourceType = STREAM_SOURCE__SUPER;*/
|
||||
/*pTask->sinkType = level == totLevel - 1 ? 1 : 0;*/
|
||||
// source part
|
||||
pTask->sourceType = TASK_SOURCE__SCAN;
|
||||
|
||||
// sink part
|
||||
if (level == 0) {
|
||||
// only for inplace
|
||||
pTask->sinkType = TASK_SINK__SHOW;
|
||||
pTask->showSink.reserved = 0;
|
||||
} else {
|
||||
pTask->sinkType = TASK_SINK__NONE;
|
||||
}
|
||||
|
||||
// dispatch part
|
||||
if (level == 0) {
|
||||
pTask->dispatchType = TASK_DISPATCH__NONE;
|
||||
// if inplace sink, no dispatcher
|
||||
// if fixed ep, add fixed ep dispatcher
|
||||
// if shuffle, add shuffle dispatcher
|
||||
} else {
|
||||
// add fixed ep dispatcher
|
||||
int32_t lastLevel = level - 1;
|
||||
ASSERT(lastLevel == 0);
|
||||
SArray* pArray = taosArrayGetP(pStream->tasks, lastLevel);
|
||||
// one merge only
|
||||
ASSERT(taosArrayGetSize(pArray) == 1);
|
||||
SStreamTask* lastLevelTask = taosArrayGetP(pArray, lastLevel);
|
||||
pTask->dispatchMsgType = TDMT_VND_TASK_MERGE_EXEC;
|
||||
pTask->dispatchType = TASK_DISPATCH__FIXED;
|
||||
|
||||
pTask->fixedEpDispatcher.nodeId = lastLevelTask->nodeId;
|
||||
pTask->fixedEpDispatcher.epSet = lastLevelTask->epSet;
|
||||
}
|
||||
|
||||
// exec part
|
||||
pTask->execType = TASK_EXEC__PIPE;
|
||||
pTask->exec.parallelizable = 1;
|
||||
if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
return -1;
|
||||
}
|
||||
taosArrayPush(taskOneLevel, pTask);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
taosArrayPush(taskOneLevel, &pTask);
|
||||
}
|
||||
} else {
|
||||
// merge plan
|
||||
|
||||
// TODO if has snode, assign to snode
|
||||
|
||||
// else, assign to vnode
|
||||
ASSERT(plan->subplanType == SUBPLAN_TYPE_MERGE);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
/*pTask->level = level;*/
|
||||
/*pTask->sourceType = STREAM_SOURCE__NONE;*/
|
||||
/*pTask->sinkType = level == totLevel - 1 ? 1 : 0;*/
|
||||
pTask->exec.parallelizable = plan->subplanType == SUBPLAN_TYPE_SCAN;
|
||||
|
||||
SSnodeObj* pSnode = mndSchedFetchSnode(pMnode);
|
||||
if (pSnode == NULL || tsStreamSchedV) {
|
||||
ASSERT(lastUsedVgId != 0);
|
||||
SVgObj* pVg = mndAcquireVgroup(pMnode, lastUsedVgId);
|
||||
if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVg) < 0) {
|
||||
sdbRelease(pSdb, pVg);
|
||||
// source part, currently only support multi source
|
||||
pTask->sourceType = TASK_SOURCE__PIPE;
|
||||
|
||||
// sink part
|
||||
pTask->sinkType = TASK_SINK__SHOW;
|
||||
/*pTask->sinkType = TASK_SINK__NONE;*/
|
||||
|
||||
// dispatch part
|
||||
pTask->dispatchType = TASK_DISPATCH__SHUFFLE;
|
||||
pTask->dispatchMsgType = TDMT_VND_TASK_WRITE_EXEC;
|
||||
|
||||
// exec part
|
||||
pTask->execType = TASK_EXEC__MERGE;
|
||||
pTask->exec.parallelizable = 0;
|
||||
SVgObj* pVgroup = mndSchedFetchOneVg(pMnode, pStream->dbUid);
|
||||
ASSERT(pVgroup);
|
||||
if (mndAssignTaskToVg(pMnode, pTrans, pTask, plan, pVgroup) < 0) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
return -1;
|
||||
}
|
||||
sdbRelease(pSdb, pVg);
|
||||
} else {
|
||||
if (mndAssignTaskToSnode(pMnode, pTrans, pTask, plan, pSnode) < 0) {
|
||||
sdbRelease(pSdb, pSnode);
|
||||
qDestroyQueryPlan(pPlan);
|
||||
return -1;
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
taosArrayPush(taskOneLevel, &pTask);
|
||||
}
|
||||
}
|
||||
sdbRelease(pMnode->pSdb, pSnode);
|
||||
|
||||
taosArrayPush(taskOneLevel, pTask);
|
||||
taosArrayPush(pStream->tasks, &taskOneLevel);
|
||||
}
|
||||
taosArrayPush(pStream->tasks, taskOneLevel);
|
||||
|
||||
if (totLevel == 2) {
|
||||
void* pIter = NULL;
|
||||
while (1) {
|
||||
SVgObj* pVgroup;
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (pVgroup->dbUid != pStream->dbUid) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
|
||||
// source part
|
||||
pTask->sourceType = TASK_SOURCE__MERGE;
|
||||
|
||||
// sink part
|
||||
pTask->sinkType = TASK_SINK__SHOW;
|
||||
|
||||
// dispatch part
|
||||
pTask->dispatchType = TASK_DISPATCH__NONE;
|
||||
|
||||
// exec part
|
||||
pTask->execType = TASK_EXEC__NONE;
|
||||
pTask->exec.parallelizable = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// free memory
|
||||
qDestroyQueryPlan(pPlan);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -357,6 +357,13 @@ static int32_t mndProcessRetrieveSysTableReq(SNodeMsg *pReq) {
|
|||
// if free flag is set, client wants to clean the resources
|
||||
if ((retrieveReq.free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) {
|
||||
rowsRead = (*retrieveFp)(pReq, (SShowObj*) pShow, pRsp->data, rowsToRead);
|
||||
if (rowsRead < 0) {
|
||||
terrno = rowsRead;
|
||||
rpcFreeCont(pRsp);
|
||||
mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
|
||||
mndReleaseShowObj((SShowObj*) pShow, true);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
mDebug("show:0x%" PRIx64 ", stop retrieve data, rowsRead:%d rowsToRead:%d", pShow->id, rowsRead, rowsToRead);
|
||||
|
|
|
@ -1613,7 +1613,7 @@ static int32_t mndRetrieveStb(SNodeMsg *pReq, SShowObj *pShow, char *data, int32
|
|||
SDbObj* pDb = NULL;
|
||||
if (strlen(pShow->db) > 0) {
|
||||
pDb = mndAcquireDb(pMnode, pShow->db);
|
||||
if (pDb == NULL) return 0;
|
||||
if (pDb == NULL) return terrno;
|
||||
}
|
||||
|
||||
while (numOfRows < rows) {
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
*/
|
||||
|
||||
#include "mndStream.h"
|
||||
#include "parser.h"
|
||||
#include "mndAuth.h"
|
||||
#include "mndDb.h"
|
||||
#include "mndDnode.h"
|
||||
|
@ -26,6 +25,7 @@
|
|||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
#include "parser.h"
|
||||
#include "tname.h"
|
||||
|
||||
#define MND_STREAM_VER_NUMBER 1
|
||||
|
@ -248,23 +248,22 @@ static int32_t mndStreamGetPlanString(const char *ast, char **pStr) {
|
|||
|
||||
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans) {
|
||||
SNode *pAst = NULL;
|
||||
#if 1 // TODO: remove debug info later
|
||||
printf("ast = %s\n", ast);
|
||||
#endif
|
||||
|
||||
if (nodesStringToNode(ast, &pAst) < 0) {
|
||||
return -1;
|
||||
}
|
||||
#if 1
|
||||
SSchemaWrapper sw = {0};
|
||||
qExtractResultSchema(pAst, (int32_t*)&sw.nCols, &sw.pSchema);
|
||||
|
||||
if (qExtractResultSchema(pAst, (int32_t *)&pStream->outputSchema.nCols, &pStream->outputSchema.pSchema) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 1
|
||||
printf("|");
|
||||
for (int i = 0; i < sw.nCols; i++) {
|
||||
printf(" %15s |", (char *)sw.pSchema[i].name);
|
||||
for (int i = 0; i < pStream->outputSchema.nCols; i++) {
|
||||
printf(" %15s |", (char *)pStream->outputSchema.pSchema[i].name);
|
||||
}
|
||||
printf("\n=======================================================\n");
|
||||
|
||||
pStream->ColAlias = NULL;
|
||||
#endif
|
||||
|
||||
if (TSDB_CODE_SUCCESS != mndStreamGetPlanString(ast, &pStream->physicalPlan)) {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
#include "parser.h"
|
||||
#include "tname.h"
|
||||
|
||||
#define MND_TOPIC_VER_NUMBER 1
|
||||
|
@ -85,6 +86,16 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
|||
SDB_SET_INT32(pRaw, dataPos, physicalPlanLen, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pTopic->physicalPlan, physicalPlanLen, TOPIC_ENCODE_OVER);
|
||||
|
||||
int32_t swLen = taosEncodeSSchemaWrapper(NULL, &pTopic->schema);
|
||||
void *swBuf = taosMemoryMalloc(swLen);
|
||||
if (swBuf == NULL) {
|
||||
goto TOPIC_ENCODE_OVER;
|
||||
}
|
||||
void *aswBuf = swBuf;
|
||||
taosEncodeSSchemaWrapper(&aswBuf, &pTopic->schema);
|
||||
SDB_SET_INT32(pRaw, dataPos, swLen, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_BINARY(pRaw, dataPos, swBuf, swLen, TOPIC_ENCODE_OVER);
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_ENCODE_OVER);
|
||||
SDB_SET_DATALEN(pRaw, dataPos, TOPIC_ENCODE_OVER);
|
||||
|
||||
|
@ -149,6 +160,17 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) {
|
|||
}
|
||||
SDB_GET_BINARY(pRaw, dataPos, pTopic->physicalPlan, len, TOPIC_DECODE_OVER);
|
||||
|
||||
SDB_GET_INT32(pRaw, dataPos, &len, TOPIC_DECODE_OVER);
|
||||
void *buf = taosMemoryMalloc(len);
|
||||
if (buf == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto TOPIC_DECODE_OVER;
|
||||
}
|
||||
SDB_GET_BINARY(pRaw, dataPos, buf, len, TOPIC_DECODE_OVER);
|
||||
if (taosDecodeSSchemaWrapper(buf, &pTopic->schema) == NULL) {
|
||||
goto TOPIC_DECODE_OVER;
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, dataPos, MND_TOPIC_RESERVE_SIZE, TOPIC_DECODE_OVER);
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
|
@ -283,6 +305,14 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
|||
topicObj.physicalPlan = pPlanStr;
|
||||
}
|
||||
|
||||
SNode *pAst = NULL;
|
||||
if (nodesStringToNode(pCreate->ast, &pAst) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (qExtractResultSchema(pAst, &topicObj.schema.nCols, &topicObj.schema.pSchema) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_TOPIC, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
#include "mndQuery.h"
|
||||
|
||||
#define MQ_TIMER_MS 3000
|
||||
#define TRNAS_TIMER_MS 6000
|
||||
|
@ -79,7 +80,7 @@ static void mndCalMqRebalance(void *param, void *tmrId) {
|
|||
.pCont = pReq,
|
||||
.contLen = contLen,
|
||||
};
|
||||
tmsgPutToQueue(&pMnode->msgCb, QUERY_QUEUE, &rpcMsg);
|
||||
tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
|
||||
}
|
||||
|
||||
taosTmrReset(mndCalMqRebalance, MQ_TIMER_MS, pMnode, pMnode->timer, &pMnode->mqTimer);
|
||||
|
@ -91,7 +92,7 @@ static void mndPullupTelem(void *param, void *tmrId) {
|
|||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildTimerMsg(&contLen);
|
||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TELEM_TIMER, .pCont = pReq, .contLen = contLen};
|
||||
tmsgPutToQueue(&pMnode->msgCb, QUERY_QUEUE, &rpcMsg);
|
||||
tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
|
||||
}
|
||||
|
||||
taosTmrReset(mndPullupTelem, TELEM_TIMER_MS, pMnode, pMnode->timer, &pMnode->telemTimer);
|
||||
|
@ -217,6 +218,7 @@ static int32_t mndInitSteps(SMnode *pMnode) {
|
|||
// if (mndAllocStep(pMnode, "mnode-timer", mndInitTimer, NULL) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-query", mndInitQuery, mndCleanupQuery) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-sync", mndInitSync, mndCleanupSync) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-telem", mndInitTelem, mndCleanupTelem) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-timer", NULL, mndCleanupTimer) != 0) return -1;
|
||||
|
|
|
@ -14,12 +14,11 @@
|
|||
*/
|
||||
|
||||
#include "tcompare.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tqInt.h"
|
||||
#include "tqMetaStore.h"
|
||||
#include "tstream.h"
|
||||
|
||||
void blockDebugShowData(SArray* dataBlocks);
|
||||
|
||||
int32_t tqInit() { return tqPushMgrInit(); }
|
||||
|
||||
void tqCleanUp() { tqPushMgrCleanUp(); }
|
||||
|
@ -445,18 +444,19 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) {
|
|||
if (pTask->execType == TASK_EXEC__NONE) return 0;
|
||||
|
||||
pTask->exec.numOfRunners = parallel;
|
||||
pTask->exec.runners = taosMemoryCalloc(parallel, sizeof(SStreamRunner));
|
||||
if (pTask->exec.runners == NULL) {
|
||||
return -1;
|
||||
}
|
||||
for (int32_t i = 0; i < parallel; i++) {
|
||||
STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnodeMeta);
|
||||
SReadHandle handle = {
|
||||
.reader = pReadHandle,
|
||||
.meta = pTq->pVnodeMeta,
|
||||
};
|
||||
pTask->exec.runners = taosMemoryCalloc(parallel, sizeof(SStreamRunner));
|
||||
if (pTask->exec.runners == NULL) {
|
||||
return -1;
|
||||
}
|
||||
pTask->exec.runners[i].inputHandle = pReadHandle;
|
||||
pTask->exec.runners[i].executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle);
|
||||
ASSERT(pTask->exec.runners[i].executor);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -473,7 +473,10 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
}
|
||||
tCoderClear(&decoder);
|
||||
|
||||
tqExpandTask(pTq, pTask, 8);
|
||||
if (tqExpandTask(pTq, pTask, 4) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), pTask, sizeof(SStreamTask));
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -31,9 +31,8 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config};
|
||||
|
||||
switch (pMsg->msgType) {
|
||||
case TDMT_VND_QUERY: {
|
||||
case TDMT_VND_QUERY:
|
||||
return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg);
|
||||
}
|
||||
case TDMT_VND_QUERY_CONTINUE:
|
||||
return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg);
|
||||
default:
|
||||
|
@ -205,7 +204,7 @@ _exit:
|
|||
|
||||
rpcSendResponse(&rpcMsg);
|
||||
|
||||
return code;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void freeItemHelper(void *pItem) {
|
||||
|
|
|
@ -187,7 +187,7 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
}
|
||||
|
||||
// record current timezone of server side
|
||||
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezone, TD_TIMEZONE_LEN);
|
||||
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezoneStr, TD_TIMEZONE_LEN);
|
||||
|
||||
if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) {
|
||||
// TODO: handle error
|
||||
|
|
|
@ -406,9 +406,9 @@ _return:
|
|||
}
|
||||
|
||||
|
||||
int32_t ctgPushRmStbMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *stbName, uint64_t suid) {
|
||||
int32_t ctgPushRmStbMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *stbName, uint64_t suid, bool syncReq) {
|
||||
int32_t code = 0;
|
||||
SCtgMetaAction action= {.act = CTG_ACT_REMOVE_STB};
|
||||
SCtgMetaAction action= {.act = CTG_ACT_REMOVE_STB, .syncReq = syncReq};
|
||||
SCtgRemoveStbMsg *msg = taosMemoryMalloc(sizeof(SCtgRemoveStbMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveStbMsg));
|
||||
|
@ -435,9 +435,9 @@ _return:
|
|||
|
||||
|
||||
|
||||
int32_t ctgPushRmTblMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *tbName) {
|
||||
int32_t ctgPushRmTblMsgInQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *tbName, bool syncReq) {
|
||||
int32_t code = 0;
|
||||
SCtgMetaAction action= {.act = CTG_ACT_REMOVE_TBL};
|
||||
SCtgMetaAction action= {.act = CTG_ACT_REMOVE_TBL, .syncReq = syncReq};
|
||||
SCtgRemoveTblMsg *msg = taosMemoryMalloc(sizeof(SCtgRemoveTblMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveTblMsg));
|
||||
|
@ -496,7 +496,7 @@ _return:
|
|||
|
||||
int32_t ctgPushUpdateTblMsgInQueue(SCatalog* pCtg, STableMetaOutput *output, bool syncReq) {
|
||||
int32_t code = 0;
|
||||
SCtgMetaAction action= {.act = CTG_ACT_UPDATE_TBL};
|
||||
SCtgMetaAction action= {.act = CTG_ACT_UPDATE_TBL, .syncReq = syncReq};
|
||||
SCtgUpdateTblMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateTblMsg));
|
||||
if (NULL == msg) {
|
||||
ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateTblMsg));
|
||||
|
@ -1843,6 +1843,7 @@ int32_t ctgRefreshTblMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps,
|
|||
|
||||
if (CTG_IS_META_NULL(output->metaType)) {
|
||||
ctgError("no tbmeta got, tbNmae:%s", tNameGetTableName(pTableName));
|
||||
catalogRemoveTableMeta(pCtg, pTableName);
|
||||
CTG_ERR_JRET(CTG_ERR_CODE_TABLE_NOT_EXIST);
|
||||
}
|
||||
|
||||
|
@ -1951,9 +1952,9 @@ _return:
|
|||
}
|
||||
|
||||
if (TSDB_SUPER_TABLE == tbType) {
|
||||
ctgPushRmStbMsgInQueue(pCtg, dbFName, dbId, pTableName->tname, suid);
|
||||
ctgPushRmStbMsgInQueue(pCtg, dbFName, dbId, pTableName->tname, suid, false);
|
||||
} else {
|
||||
ctgPushRmTblMsgInQueue(pCtg, dbFName, dbId, pTableName->tname);
|
||||
ctgPushRmTblMsgInQueue(pCtg, dbFName, dbId, pTableName->tname, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2534,7 +2535,7 @@ int32_t catalogUpdateVgEpSet(SCatalog* pCtg, const char* dbFName, int32_t vgId,
|
|||
|
||||
}
|
||||
|
||||
int32_t catalogRemoveTableMeta(SCatalog* pCtg, SName* pTableName) {
|
||||
int32_t catalogRemoveTableMeta(SCatalog* pCtg, const SName* pTableName) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
int32_t code = 0;
|
||||
|
@ -2561,9 +2562,9 @@ int32_t catalogRemoveTableMeta(SCatalog* pCtg, SName* pTableName) {
|
|||
tNameGetFullDbName(pTableName, dbFName);
|
||||
|
||||
if (TSDB_SUPER_TABLE == tblMeta->tableType) {
|
||||
CTG_ERR_JRET(ctgPushRmStbMsgInQueue(pCtg, dbFName, dbId, pTableName->tname, tblMeta->suid));
|
||||
CTG_ERR_JRET(ctgPushRmStbMsgInQueue(pCtg, dbFName, dbId, pTableName->tname, tblMeta->suid, true));
|
||||
} else {
|
||||
CTG_ERR_JRET(ctgPushRmTblMsgInQueue(pCtg, dbFName, dbId, pTableName->tname));
|
||||
CTG_ERR_JRET(ctgPushRmTblMsgInQueue(pCtg, dbFName, dbId, pTableName->tname, true));
|
||||
}
|
||||
|
||||
|
||||
|
@ -2588,7 +2589,7 @@ int32_t catalogRemoveStbMeta(SCatalog* pCtg, const char* dbFName, uint64_t dbId,
|
|||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
CTG_ERR_JRET(ctgPushRmStbMsgInQueue(pCtg, dbFName, dbId, stbName, suid));
|
||||
CTG_ERR_JRET(ctgPushRmStbMsgInQueue(pCtg, dbFName, dbId, stbName, suid, true));
|
||||
|
||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||
|
||||
|
|
|
@ -415,6 +415,7 @@ typedef struct STableScanInfo {
|
|||
int32_t* rowCellInfoOffset;
|
||||
SExprInfo* pExpr;
|
||||
SSDataBlock block;
|
||||
SArray* pColMatchInfo;
|
||||
int32_t numOfOutput;
|
||||
int64_t elapsedTime;
|
||||
int32_t prevGroupId; // previous table group id
|
||||
|
@ -449,6 +450,8 @@ typedef struct SSysTableScanInfo {
|
|||
SEpSet epSet;
|
||||
tsem_t ready;
|
||||
|
||||
int32_t accountId;
|
||||
bool showRewrite;
|
||||
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
||||
void *pCur; // cursor for iterate the local table meta store.
|
||||
SArray *scanCols; // SArray<int16_t> scan column id list
|
||||
|
@ -646,8 +649,8 @@ typedef struct SDistinctOperatorInfo {
|
|||
} SDistinctOperatorInfo;
|
||||
|
||||
SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput,
|
||||
int32_t repeatTime, int32_t reverseTime, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfCols, int32_t repeatTime,
|
||||
int32_t reverseTime, SArray* pColMatchInfo, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock,
|
||||
SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
|
@ -655,7 +658,7 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p
|
|||
SOperatorInfo* createOrderOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SArray* pOrderVal, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pOrderVal, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataBlock* pResBlock, const SName* pName,
|
||||
SNode* pCondition, SEpSet epset, SArray* colList, SExecTaskInfo* pTaskInfo);
|
||||
SNode* pCondition, SEpSet epset, SArray* colList, SExecTaskInfo* pTaskInfo, bool showRewrite, int32_t accountId);
|
||||
SOperatorInfo* createLimitOperatorInfo(SOperatorInfo* downstream, SLimit* pLimit, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval,
|
||||
|
|
|
@ -97,6 +97,8 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle) {
|
|||
pMsg->contentLen = pMsg->contentLen;
|
||||
#endif
|
||||
|
||||
qDebugL("stream task string %s", (const char*)msg);
|
||||
|
||||
struct SSubplan* plan = NULL;
|
||||
int32_t code = qStringToSubplan(msg, &plan);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -66,6 +66,11 @@ typedef enum SResultTsInterpType {
|
|||
RESULT_ROW_END_INTERP = 2,
|
||||
} SResultTsInterpType;
|
||||
|
||||
typedef struct SColMatchInfo {
|
||||
int32_t colId;
|
||||
int32_t targetSlotId;
|
||||
} SColMatchInfo;
|
||||
|
||||
#if 0
|
||||
static UNUSED_FUNC void *u_malloc (size_t __size) {
|
||||
uint32_t v = taosRand();
|
||||
|
@ -2944,12 +2949,21 @@ int32_t loadDataBlock(SExecTaskInfo *pTaskInfo, STableScanInfo* pTableScanInfo,
|
|||
|
||||
*status = BLK_DATA_ALL_NEEDED;
|
||||
|
||||
pBlock->pDataBlock = tsdbRetrieveDataBlock(pTableScanInfo->pTsdbReadHandle, NULL);
|
||||
if (pBlock->pDataBlock == NULL) {
|
||||
SArray* pCols = tsdbRetrieveDataBlock(pTableScanInfo->pTsdbReadHandle, NULL);
|
||||
if (pCols == NULL) {
|
||||
return terrno;
|
||||
} else {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* p = taosArrayGet(pCols, i);
|
||||
SColMatchInfo* pColMatchInfo = taosArrayGet(pTableScanInfo->pColMatchInfo, i);
|
||||
ASSERT(pColMatchInfo->colId == p->info.colId);
|
||||
|
||||
taosArraySet(pBlock->pDataBlock, pColMatchInfo->targetSlotId, p);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t loadDataBlockOnDemand(SExecTaskInfo *pTaskInfo, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) {
|
||||
|
@ -5374,7 +5388,8 @@ SSDataBlock* createResultDataBlock(const SArray* pExprInfo) {
|
|||
return pResBlock;
|
||||
}
|
||||
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, int32_t repeatTime, int32_t reverseTime, SExecTaskInfo* pTaskInfo) {
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
assert(repeatTime > 0);
|
||||
|
||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||
|
@ -5387,12 +5402,19 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pInfo->block.pDataBlock = taosArrayInit(numOfOutput, sizeof(SColumnInfoData));
|
||||
for(int32_t i = 0; i < numOfOutput; ++i) {
|
||||
SColumnInfoData idata = {0};
|
||||
taosArrayPush(pInfo->block.pDataBlock, &idata);
|
||||
}
|
||||
|
||||
pInfo->pTsdbReadHandle = pTsdbReadHandle;
|
||||
pInfo->times = repeatTime;
|
||||
pInfo->reverseTimes = reverseTime;
|
||||
pInfo->order = order;
|
||||
pInfo->current = 0;
|
||||
pInfo->scanFlag = MAIN_SCAN;
|
||||
pInfo->pColMatchInfo = pColMatchInfo;
|
||||
pOperator->name = "TableScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN;
|
||||
pOperator->blockingOptr = false;
|
||||
|
@ -5489,7 +5511,8 @@ SOperatorInfo* createStreamScanOperatorInfo(void *streamReadHandle, SSDataBlock*
|
|||
}
|
||||
|
||||
static int32_t loadSysTableContentCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
SSysTableScanInfo* pScanResInfo = (SSysTableScanInfo*) param;
|
||||
SOperatorInfo* operator = (SOperatorInfo *)param;
|
||||
SSysTableScanInfo* pScanResInfo = (SSysTableScanInfo *)operator->info;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pScanResInfo->pRsp = pMsg->pData;
|
||||
|
||||
|
@ -5498,6 +5521,8 @@ static int32_t loadSysTableContentCb(void* param, const SDataBuf* pMsg, int32_t
|
|||
pRsp->useconds = htobe64(pRsp->useconds);
|
||||
pRsp->handle = htobe64(pRsp->handle);
|
||||
pRsp->compLen = htonl(pRsp->compLen);
|
||||
} else {
|
||||
operator->pTaskInfo->code = code;
|
||||
}
|
||||
|
||||
tsem_post(&pScanResInfo->ready);
|
||||
|
@ -5544,6 +5569,64 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) {
|
|||
return pInfo->pRes->info.rows == 0? NULL:pInfo->pRes;
|
||||
}
|
||||
|
||||
EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
ENodeType nType = nodeType(pNode);
|
||||
|
||||
switch (nType) {
|
||||
case QUERY_NODE_OPERATOR: {
|
||||
SOperatorNode *node = (SOperatorNode *)pNode;
|
||||
|
||||
if (OP_TYPE_EQUAL == node->opType) {
|
||||
*(int32_t *)pContext = 1;
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
*(int32_t *)pContext = 0;
|
||||
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
case QUERY_NODE_COLUMN: {
|
||||
if (1 != *(int32_t *)pContext) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
SColumnNode *node = (SColumnNode *)pNode;
|
||||
if (TSDB_INS_USER_STABLES_DBNAME_COLID == node->colId) {
|
||||
*(int32_t *)pContext = 2;
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
*(int32_t *)pContext = 0;
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
case QUERY_NODE_VALUE: {
|
||||
if (2 != *(int32_t *)pContext) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
SValueNode *node = (SValueNode *)pNode;
|
||||
char *dbName = nodesGetValueFromNode(node);
|
||||
strncpy(pContext, varDataVal(dbName), varDataLen(dbName));
|
||||
*((char *)pContext + varDataLen(dbName)) = 0;
|
||||
return DEAL_RES_ERROR; // stop walk
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
void getDBNameFromCondition(SNode *pCondition, char *dbName) {
|
||||
if (NULL == pCondition) {
|
||||
return;
|
||||
}
|
||||
|
||||
nodesWalkNode(pCondition, getDBNameFromConditionWalker, dbName);
|
||||
}
|
||||
|
||||
static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) {
|
||||
// build message and send to mnode to fetch the content of system tables.
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
@ -5600,6 +5683,11 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) {
|
|||
|
||||
pInfo->req.type = pInfo->type;
|
||||
strncpy(pInfo->req.tb, tNameGetTableName(&pInfo->name), tListLen(pInfo->req.tb));
|
||||
if (pInfo->showRewrite) {
|
||||
char dbName[TSDB_DB_NAME_LEN] = {0};
|
||||
getDBNameFromCondition(pInfo->pCondition, dbName);
|
||||
sprintf(pInfo->req.db, "%d.%s", pInfo->accountId, dbName);
|
||||
}
|
||||
|
||||
int32_t contLen = tSerializeSRetrieveTableReq(NULL, 0, &pInfo->req);
|
||||
char* buf1 = taosMemoryCalloc(1, contLen);
|
||||
|
@ -5613,7 +5701,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pMsgSendInfo->param = pInfo;
|
||||
pMsgSendInfo->param = pOperator;
|
||||
pMsgSendInfo->msgInfo.pData = buf1;
|
||||
pMsgSendInfo->msgInfo.len = contLen;
|
||||
pMsgSendInfo->msgType = TDMT_MND_SYSTABLE_RETRIEVE;
|
||||
|
@ -5623,6 +5711,10 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) {
|
|||
int32_t code = asyncSendMsgToServer(pInfo->pTransporter, &pInfo->epSet, &transporterId, pMsgSendInfo);
|
||||
tsem_wait(&pInfo->ready);
|
||||
|
||||
if (pTaskInfo->code) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SRetrieveMetaTableRsp* pRsp = pInfo->pRsp;
|
||||
pInfo->req.showId = pRsp->handle;
|
||||
|
||||
|
@ -5644,7 +5736,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo *pOperator, bool* newgroup) {
|
|||
}
|
||||
|
||||
SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataBlock* pResBlock, const SName* pName,
|
||||
SNode* pCondition, SEpSet epset, SArray* colList, SExecTaskInfo* pTaskInfo) {
|
||||
SNode* pCondition, SEpSet epset, SArray* colList, SExecTaskInfo* pTaskInfo, bool showRewrite, int32_t accountId) {
|
||||
SSysTableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SSysTableScanInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
if (pInfo == NULL || pOperator == NULL) {
|
||||
|
@ -5654,6 +5746,8 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pInfo->accountId = accountId;
|
||||
pInfo->showRewrite = showRewrite;
|
||||
pInfo->pRes = pResBlock;
|
||||
pInfo->capacity = 4096;
|
||||
pInfo->pCondition = pCondition;
|
||||
|
@ -8497,6 +8591,7 @@ static int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t
|
|||
static SArray* extractTableIdList(const STableGroupInfo* pTableGroupInfo);
|
||||
static SArray* extractScanColumnId(SNodeList* pNodeList);
|
||||
static SArray* extractColumnInfo(SNodeList* pNodeList);
|
||||
static SArray* extractColMatchInfo(SNodeList* pNodeList);
|
||||
|
||||
SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, uint64_t queryId, uint64_t taskId, STableGroupInfo* pTableGroupInfo) {
|
||||
if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) {
|
||||
|
@ -8505,7 +8600,9 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa
|
|||
|
||||
size_t numOfCols = LIST_LENGTH(pScanPhyNode->pScanCols);
|
||||
tsdbReaderT pDataReader = doCreateDataReader((STableScanPhysiNode*)pPhyNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId);
|
||||
return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, pScanPhyNode->reverse, pTaskInfo);
|
||||
SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols);
|
||||
|
||||
return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count, pScanPhyNode->reverse, pColList, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == nodeType(pPhyNode)) {
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pPhyNode;
|
||||
SSDataBlock* pResBlock = createOutputBuf_rv1(pExchange->node.pOutputDataBlockDesc);
|
||||
|
@ -8530,7 +8627,8 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa
|
|||
SArray* colList = extractScanColumnId(pScanNode->pScanCols);
|
||||
|
||||
SOperatorInfo* pOperator = createSysTableScanOperatorInfo(pHandle->meta, pResBlock, &pScanNode->tableName,
|
||||
pScanNode->node.pConditions, pSysScanPhyNode->mgmtEpSet, colList, pTaskInfo);
|
||||
pScanNode->node.pConditions, pSysScanPhyNode->mgmtEpSet,
|
||||
colList, pTaskInfo, pSysScanPhyNode->showRewrite, pSysScanPhyNode->accountId);
|
||||
return pOperator;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
|
@ -8644,9 +8742,14 @@ SArray* extractScanColumnId(SNodeList* pNodeList) {
|
|||
}
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
STargetNode* pNode = (STargetNode*) nodesListGetNode(pNodeList, i);
|
||||
for (int32_t j = 0; j < numOfCols; ++j) {
|
||||
STargetNode* pNode = (STargetNode*) nodesListGetNode(pNodeList, j);
|
||||
if (pNode->slotId == i) {
|
||||
SColumnNode* pColNode = (SColumnNode*) pNode->pExpr;
|
||||
taosArrayPush(pList, &pColNode->colId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pList;
|
||||
|
@ -8678,6 +8781,28 @@ SArray* extractColumnInfo(SNodeList* pNodeList) {
|
|||
return pList;
|
||||
}
|
||||
|
||||
SArray* extractColMatchInfo(SNodeList* pNodeList) {
|
||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||
SArray* pList = taosArrayInit(numOfCols, sizeof(SColMatchInfo));
|
||||
if (pList == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
STargetNode* pNode = (STargetNode*) nodesListGetNode(pNodeList, i);
|
||||
SColumnNode* pColNode = (SColumnNode*) pNode->pExpr;
|
||||
|
||||
SColMatchInfo c = {0};
|
||||
c.colId = pColNode->colId;
|
||||
c.targetSlotId = pNode->slotId;
|
||||
|
||||
taosArrayPush(pList, &c);
|
||||
}
|
||||
|
||||
return pList;
|
||||
}
|
||||
|
||||
int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t tableUid, STableGroupInfo* pGroupInfo, uint64_t queryId, uint64_t taskId) {
|
||||
int32_t code = 0;
|
||||
if (tableType == TSDB_SUPER_TABLE) {
|
||||
|
|
|
@ -11,8 +11,8 @@ target_include_directories(
|
|||
|
||||
target_link_libraries(
|
||||
function
|
||||
PRIVATE os util common nodes scalar
|
||||
PUBLIC uv_a
|
||||
PRIVATE os util common nodes
|
||||
)
|
||||
|
||||
add_executable(runUdf test/runUdf.c)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "builtins.h"
|
||||
#include "builtinsimpl.h"
|
||||
#include "scalar.h"
|
||||
#include "taoserror.h"
|
||||
#include "tdatablock.h"
|
||||
|
||||
|
@ -151,6 +152,136 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.processFunc = lastFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "abs",
|
||||
.type = FUNCTION_TYPE_ABS,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = absFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "log",
|
||||
.type = FUNCTION_TYPE_LOG,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = logFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "power",
|
||||
.type = FUNCTION_TYPE_POW,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = powFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "sqrt",
|
||||
.type = FUNCTION_TYPE_SQRT,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = sqrtFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "ceil",
|
||||
.type = FUNCTION_TYPE_CEIL,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = ceilFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "floor",
|
||||
.type = FUNCTION_TYPE_FLOOR,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = floorFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "round",
|
||||
.type = FUNCTION_TYPE_ROUND,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = roundFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "sin",
|
||||
.type = FUNCTION_TYPE_SIN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = sinFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "cos",
|
||||
.type = FUNCTION_TYPE_COS,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = cosFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "tan",
|
||||
.type = FUNCTION_TYPE_TAN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = tanFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "asin",
|
||||
.type = FUNCTION_TYPE_ASIN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = asinFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "acos",
|
||||
.type = FUNCTION_TYPE_ACOS,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = acosFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "atan",
|
||||
.type = FUNCTION_TYPE_ATAN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = atanFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "concat",
|
||||
.type = FUNCTION_TYPE_CONCAT,
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
#include "taos.h"
|
||||
#include "taoserror.h"
|
||||
|
||||
#define COPY_ALL_SCALAR_FIELDS \
|
||||
do { \
|
||||
memcpy((pDst), (pSrc), sizeof(*pSrc)); \
|
||||
} while (0)
|
||||
|
||||
#define COPY_SCALAR_FIELD(fldname) \
|
||||
do { \
|
||||
(pDst)->fldname = (pSrc)->fldname; \
|
||||
|
@ -195,6 +200,12 @@ static SNode* groupingSetNodeCopy(const SGroupingSetNode* pSrc, SGroupingSetNode
|
|||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* orderByExprNodeCopy(const SOrderByExprNode* pSrc, SOrderByExprNode* pDst) {
|
||||
COPY_ALL_SCALAR_FIELDS;
|
||||
CLONE_NODE_FIELD(pExpr);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* fillNodeCopy(const SFillNode* pSrc, SFillNode* pDst) {
|
||||
COPY_SCALAR_FIELD(mode);
|
||||
CLONE_NODE_FIELD(pValues);
|
||||
|
@ -237,6 +248,7 @@ static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
|
|||
COPY_SCALAR_FIELD(scanFlag);
|
||||
COPY_SCALAR_FIELD(scanRange);
|
||||
COPY_SCALAR_FIELD(tableName);
|
||||
COPY_SCALAR_FIELD(showRewrite);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
|
@ -250,6 +262,7 @@ static SNode* logicAggCopy(const SAggLogicNode* pSrc, SAggLogicNode* pDst) {
|
|||
static SNode* logicProjectCopy(const SProjectLogicNode* pSrc, SProjectLogicNode* pDst) {
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
CLONE_NODE_LIST_FIELD(pProjections);
|
||||
COPY_CHAR_ARRAY_FIELD(stmtName);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
|
@ -266,16 +279,24 @@ static SNode* logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNo
|
|||
}
|
||||
|
||||
static SNode* logicWindowCopy(const SWindowLogicNode* pSrc, SWindowLogicNode* pDst) {
|
||||
COPY_ALL_SCALAR_FIELDS;
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
COPY_SCALAR_FIELD(winType);
|
||||
// COPY_SCALAR_FIELD(winType);
|
||||
CLONE_NODE_LIST_FIELD(pFuncs);
|
||||
COPY_SCALAR_FIELD(interval);
|
||||
COPY_SCALAR_FIELD(offset);
|
||||
COPY_SCALAR_FIELD(sliding);
|
||||
COPY_SCALAR_FIELD(intervalUnit);
|
||||
COPY_SCALAR_FIELD(slidingUnit);
|
||||
// COPY_SCALAR_FIELD(interval);
|
||||
// COPY_SCALAR_FIELD(offset);
|
||||
// COPY_SCALAR_FIELD(sliding);
|
||||
// COPY_SCALAR_FIELD(intervalUnit);
|
||||
// COPY_SCALAR_FIELD(slidingUnit);
|
||||
CLONE_NODE_FIELD(pFill);
|
||||
COPY_SCALAR_FIELD(sessionGap);
|
||||
// COPY_SCALAR_FIELD(sessionGap);
|
||||
CLONE_NODE_FIELD(pTspk);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* logicSortCopy(const SSortLogicNode* pSrc, SSortLogicNode* pDst) {
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
CLONE_NODE_LIST_FIELD(pSortKeys);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
|
@ -338,6 +359,7 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) {
|
|||
case QUERY_NODE_GROUPING_SET:
|
||||
return groupingSetNodeCopy((const SGroupingSetNode*)pNode, (SGroupingSetNode*)pDst);
|
||||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
return orderByExprNodeCopy((const SOrderByExprNode*)pNode, (SOrderByExprNode*)pDst);
|
||||
case QUERY_NODE_LIMIT:
|
||||
break;
|
||||
case QUERY_NODE_FILL:
|
||||
|
@ -360,6 +382,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) {
|
|||
return logicExchangeCopy((const SExchangeLogicNode*)pNode, (SExchangeLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_PLAN_WINDOW:
|
||||
return logicWindowCopy((const SWindowLogicNode*)pNode, (SWindowLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_PLAN_SORT:
|
||||
return logicSortCopy((const SSortLogicNode*)pNode, (SSortLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return logicSubplanCopy((const SLogicSubplan*)pNode, (SLogicSubplan*)pDst);
|
||||
default:
|
||||
|
|
|
@ -764,6 +764,8 @@ static int32_t jsonToEpSet(const SJson* pJson, void* pObj) {
|
|||
}
|
||||
|
||||
static const char* jkSysTableScanPhysiPlanMnodeEpSet = "MnodeEpSet";
|
||||
static const char* jkSysTableScanPhysiPlanShowRewrite = "ShowRewrite";
|
||||
static const char* jkSysTableScanPhysiPlanAccountId = "AccountId";
|
||||
|
||||
static int32_t physiSysTableScanNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SSystemTableScanPhysiNode* pNode = (const SSystemTableScanPhysiNode*)pObj;
|
||||
|
@ -772,6 +774,12 @@ static int32_t physiSysTableScanNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkSysTableScanPhysiPlanMnodeEpSet, epSetToJson, &pNode->mgmtEpSet);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddBoolToObject(pJson, jkSysTableScanPhysiPlanShowRewrite, pNode->showRewrite);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkSysTableScanPhysiPlanAccountId, pNode->accountId);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -783,6 +791,12 @@ static int32_t jsonToPhysiSysTableScanNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonToObject(pJson, jkSysTableScanPhysiPlanMnodeEpSet, jsonToEpSet, &pNode->mgmtEpSet);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBoolValue(pJson, jkSysTableScanPhysiPlanShowRewrite, &pNode->showRewrite);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkSysTableScanPhysiPlanAccountId, pNode->accountId);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -837,9 +851,7 @@ static int32_t jsonToPhysiJoinNode(const SJson* pJson, void* pObj) {
|
|||
|
||||
int32_t code = jsonToPhysicPlanNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t val;
|
||||
code = tjsonGetIntValue(pJson, jkJoinPhysiPlanJoinType, &val);
|
||||
pNode->joinType = val;
|
||||
code = tjsonGetNumberValue(pJson, jkJoinPhysiPlanJoinType, pNode->joinType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkJoinPhysiPlanOnConditions, &pNode->pOnConditions);
|
||||
|
@ -920,6 +932,37 @@ static int32_t jsonToPhysiExchangeNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkSortPhysiPlanExprs = "Exprs";
|
||||
static const char* jkSortPhysiPlanSortKeys = "SortKeys";
|
||||
|
||||
static int32_t physiSortNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SSortPhysiNode* pNode = (const SSortPhysiNode*)pObj;
|
||||
|
||||
int32_t code = physicPlanNodeToJson(pObj, pJson);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkSortPhysiPlanExprs, pNode->pExprs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkSortPhysiPlanSortKeys, pNode->pSortKeys);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToPhysiSortNode(const SJson* pJson, void* pObj) {
|
||||
SSortPhysiNode* pNode = (SSortPhysiNode*)pObj;
|
||||
|
||||
int32_t code = jsonToPhysicPlanNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkSortPhysiPlanExprs, &pNode->pExprs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkSortPhysiPlanSortKeys, &pNode->pSortKeys);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkWindowPhysiPlanExprs = "Exprs";
|
||||
static const char* jkWindowPhysiPlanFuncs = "Funcs";
|
||||
|
||||
|
@ -957,6 +1000,7 @@ static const char* jkIntervalPhysiPlanSliding = "Sliding";
|
|||
static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit";
|
||||
static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit";
|
||||
static const char* jkIntervalPhysiPlanFill = "Fill";
|
||||
static const char* jkIntervalPhysiPlanTsPk = "TsPk";
|
||||
|
||||
static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SIntervalPhysiNode* pNode = (const SIntervalPhysiNode*)pObj;
|
||||
|
@ -980,6 +1024,9 @@ static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkIntervalPhysiPlanFill, nodeToJson, pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkIntervalPhysiPlanTsPk, nodeToJson, pNode->pTspk);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1006,6 +1053,9 @@ static int32_t jsonToPhysiIntervalNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkIntervalPhysiPlanFill, (SNode**)&pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkIntervalPhysiPlanTsPk, (SNode**)&pNode->pTspk);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1164,9 +1214,7 @@ static int32_t jsonToSubplan(const SJson* pJson, void* pObj) {
|
|||
|
||||
int32_t code = tjsonToObject(pJson, jkSubplanId, jsonToSubplanId, &pNode->id);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t val;
|
||||
code = tjsonGetIntValue(pJson, jkSubplanType, &val);
|
||||
pNode->subplanType = val;
|
||||
code = tjsonGetNumberValue(pJson, jkSubplanType, pNode->subplanType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkSubplanMsgType, &pNode->msgType);
|
||||
|
@ -1356,9 +1404,7 @@ static int32_t jsonToColumnNode(const SJson* pJson, void* pObj) {
|
|||
code = tjsonGetSmallIntValue(pJson, jkColumnColId, &pNode->colId);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t tmp;
|
||||
code = tjsonGetIntValue(pJson, jkColumnColType, &tmp);
|
||||
pNode->colType = tmp;
|
||||
code = tjsonGetNumberValue(pJson, jkColumnColType, pNode->colType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkColumnDbName, pNode->dbName);
|
||||
|
@ -1546,9 +1592,7 @@ static int32_t jsonToOperatorNode(const SJson* pJson, void* pObj) {
|
|||
|
||||
int32_t code = jsonToExprNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t val;
|
||||
code = tjsonGetIntValue(pJson, jkOperatorType, &val);
|
||||
pNode->opType = val;
|
||||
code = tjsonGetNumberValue(pJson, jkOperatorType, pNode->opType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkOperatorLeft, &pNode->pLeft);
|
||||
|
@ -1582,9 +1626,7 @@ static int32_t jsonToLogicConditionNode(const SJson* pJson, void* pObj) {
|
|||
|
||||
int32_t code = jsonToExprNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t val;
|
||||
code = tjsonGetIntValue(pJson, jkLogicCondType, &val);
|
||||
pNode->condType = val;
|
||||
code = tjsonGetNumberValue(pJson, jkLogicCondType, pNode->condType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkLogicCondParameters, &pNode->pParameterList);
|
||||
|
@ -1807,10 +1849,43 @@ static int32_t groupingSetNodeToJson(const void* pObj, SJson* pJson) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkOrderByExprExpr = "Expr";
|
||||
static const char* jkOrderByExprOrder = "Order";
|
||||
static const char* jkOrderByExprNullOrder = "NullOrder";
|
||||
|
||||
static int32_t orderByExprNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SOrderByExprNode* pNode = (const SOrderByExprNode*)pObj;
|
||||
|
||||
int32_t code = tjsonAddObject(pJson, jkOrderByExprExpr, nodeToJson, pNode->pExpr);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkOrderByExprOrder, pNode->order);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkOrderByExprNullOrder, pNode->nullOrder);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToOrderByExprNode(const SJson* pJson, void* pObj) {
|
||||
SOrderByExprNode* pNode = (SOrderByExprNode*)pObj;
|
||||
|
||||
int32_t code = jsonToNodeObject(pJson, jkOrderByExprExpr, &pNode->pExpr);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkOrderByExprOrder, pNode->order);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkOrderByExprNullOrder, pNode->nullOrder);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkIntervalWindowInterval = "Interval";
|
||||
static const char* jkIntervalWindowOffset = "Offset";
|
||||
static const char* jkIntervalWindowSliding = "Sliding";
|
||||
static const char* jkIntervalWindowFill = "Fill";
|
||||
static const char* jkIntervalWindowTsPk = "TsPk";
|
||||
|
||||
static int32_t intervalWindowNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SIntervalWindowNode* pNode = (const SIntervalWindowNode*)pObj;
|
||||
|
@ -1825,6 +1900,9 @@ static int32_t intervalWindowNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkIntervalWindowFill, nodeToJson, pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkIntervalWindowTsPk, nodeToJson, pNode->pCol);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1842,6 +1920,9 @@ static int32_t jsonToIntervalWindowNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkIntervalWindowFill, &pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkIntervalWindowTsPk, &pNode->pCol);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -2019,6 +2100,7 @@ static const char* jkSelectStmtHaving = "Having";
|
|||
static const char* jkSelectStmtOrderBy = "OrderBy";
|
||||
static const char* jkSelectStmtLimit = "Limit";
|
||||
static const char* jkSelectStmtSlimit = "Slimit";
|
||||
static const char* jkSelectStmtStmtName = "StmtName";
|
||||
|
||||
static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
|
||||
const SSelectStmt* pNode = (const SSelectStmt*)pObj;
|
||||
|
@ -2054,6 +2136,9 @@ static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkSelectStmtSlimit, nodeToJson, pNode->pSlimit);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddStringToObject(pJson, jkSelectStmtStmtName, pNode->stmtName);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -2092,6 +2177,9 @@ static int32_t jsonToSelectStmt(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkSelectStmtSlimit, &pNode->pSlimit);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkSelectStmtStmtName, pNode->stmtName);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -2155,6 +2243,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
case QUERY_NODE_GROUPING_SET:
|
||||
return groupingSetNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
return orderByExprNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_LIMIT:
|
||||
case QUERY_NODE_STATE_WINDOW:
|
||||
case QUERY_NODE_SESSION_WINDOW:
|
||||
|
@ -2218,7 +2307,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
|
||||
return physiExchangeNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
break;
|
||||
return physiSortNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
return physiIntervalNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
|
@ -2258,7 +2347,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
// break;
|
||||
// case QUERY_NODE_GROUPING_SET:
|
||||
// return jsonToGroupingSetNode(pJson, pObj);
|
||||
// case QUERY_NODE_ORDER_BY_EXPR:
|
||||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
return jsonToOrderByExprNode(pJson, pObj);
|
||||
// case QUERY_NODE_LIMIT:
|
||||
// case QUERY_NODE_STATE_WINDOW:
|
||||
// case QUERY_NODE_SESSION_WINDOW:
|
||||
|
@ -2307,6 +2397,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToPhysiAggNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
|
||||
return jsonToPhysiExchangeNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
return jsonToPhysiSortNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
return jsonToPhysiIntervalNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
|
@ -2348,9 +2440,7 @@ static int32_t nodeToJson(const void* pObj, SJson* pJson) {
|
|||
static int32_t jsonToNode(const SJson* pJson, void* pObj) {
|
||||
SNode* pNode = (SNode*)pObj;
|
||||
|
||||
int32_t val = 0;
|
||||
int32_t code = tjsonGetIntValue(pJson, jkNodeType, &val);
|
||||
pNode->type = val;
|
||||
int32_t code = tjsonGetNumberValue(pJson, jkNodeType, pNode->type);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonToObject(pJson, nodesNodeName(pNode->type), jsonToSpecificNode, pNode);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
|
|
|
@ -99,6 +99,9 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
|
|||
if (DEAL_RES_ERROR != res) {
|
||||
res = walkNode(pInterval->pFill, order, walker, pContext);
|
||||
}
|
||||
if (DEAL_RES_ERROR != res) {
|
||||
res = walkNode(pInterval->pCol, order, walker, pContext);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_NODE_LIST:
|
||||
|
@ -225,6 +228,9 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
|
|||
if (DEAL_RES_ERROR != res) {
|
||||
res = rewriteNode(&(pInterval->pFill), order, rewriter, pContext);
|
||||
}
|
||||
if (DEAL_RES_ERROR != res) {
|
||||
res = rewriteNode(&(pInterval->pCol), order, rewriter, pContext);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_NODE_LIST:
|
||||
|
@ -294,10 +300,10 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa
|
|||
case SQL_CLAUSE_GROUP_BY:
|
||||
nodesWalkNode(pSelect->pHaving, walker, pContext);
|
||||
case SQL_CLAUSE_HAVING:
|
||||
nodesWalkList(pSelect->pProjectionList, walker, pContext);
|
||||
case SQL_CLAUSE_SELECT:
|
||||
nodesWalkList(pSelect->pOrderByList, walker, pContext);
|
||||
case SQL_CLAUSE_ORDER_BY:
|
||||
nodesWalkList(pSelect->pProjectionList, walker, pContext);
|
||||
case SQL_CLAUSE_SELECT:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -159,6 +159,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SExchangeLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_WINDOW:
|
||||
return makeNode(type, sizeof(SWindowLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_SORT:
|
||||
return makeNode(type, sizeof(SSortLogicNode));
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return makeNode(type, sizeof(SLogicSubplan));
|
||||
case QUERY_NODE_LOGIC_PLAN:
|
||||
|
@ -182,7 +184,7 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
|
||||
return makeNode(type, sizeof(SExchangePhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
return makeNode(type, sizeof(SNode));
|
||||
return makeNode(type, sizeof(SSortPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
return makeNode(type, sizeof(SIntervalPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
|
@ -555,7 +557,7 @@ static EDealRes collectColumns(SNode* pNode, void* pContext) {
|
|||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
int32_t colId = pCol->colId;
|
||||
if (0 == strcmp(pCxt->pTableAlias, pCol->tableAlias)) {
|
||||
if (NULL == pCxt->pTableAlias || 0 == strcmp(pCxt->pTableAlias, pCol->tableAlias)) {
|
||||
return doCollect(pCxt, colId, pNode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ extern "C" {
|
|||
#define parserDebug(param, ...) qDebug("PARSER: " param, __VA_ARGS__)
|
||||
#define parserTrace(param, ...) qTrace("PARSER: " param, __VA_ARGS__)
|
||||
|
||||
#define PK_TS_COL_INTERNAL_NAME "_rowts"
|
||||
|
||||
typedef struct SMsgBuf {
|
||||
int32_t len;
|
||||
char *buf;
|
||||
|
|
|
@ -645,6 +645,11 @@ SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, const STok
|
|||
tempTable->pSubquery = pSubquery;
|
||||
if (NULL != pTableAlias && TK_NK_NIL != pTableAlias->type) {
|
||||
strncpy(tempTable->table.tableAlias, pTableAlias->z, pTableAlias->n);
|
||||
} else {
|
||||
sprintf(tempTable->table.tableAlias, "%p", tempTable);
|
||||
}
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pSubquery)) {
|
||||
strcpy(((SSelectStmt*)pSubquery)->stmtName, tempTable->table.tableAlias);
|
||||
}
|
||||
return (SNode*)tempTable;
|
||||
}
|
||||
|
@ -697,6 +702,13 @@ SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pCol) {
|
|||
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding, SNode* pFill) {
|
||||
SIntervalWindowNode* interval = (SIntervalWindowNode*)nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW);
|
||||
CHECK_OUT_OF_MEM(interval);
|
||||
interval->pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
if (NULL == interval->pCol) {
|
||||
nodesDestroyNode(interval);
|
||||
CHECK_OUT_OF_MEM(interval->pCol);
|
||||
}
|
||||
((SColumnNode*)interval->pCol)->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
strcpy(((SColumnNode*)interval->pCol)->colName, PK_TS_COL_INTERNAL_NAME);
|
||||
interval->pInterval = pInterval;
|
||||
interval->pOffset = pOffset;
|
||||
interval->pSliding = pSliding;
|
||||
|
@ -792,6 +804,7 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr
|
|||
select->isDistinct = isDistinct;
|
||||
select->pProjectionList = pProjectionList;
|
||||
select->pFromTable = pTable;
|
||||
sprintf(select->stmtName, "%p", select);
|
||||
return (SNode*)select;
|
||||
}
|
||||
|
||||
|
|
|
@ -84,12 +84,18 @@ static SName* toName(int32_t acctId, const char* pDbName, const char* pTableName
|
|||
return pName;
|
||||
}
|
||||
|
||||
static int32_t collectUseDatabase(const char* pFullDbName, SHashObj* pDbs) {
|
||||
static int32_t collectUseDatabaseImpl(const char* pFullDbName, SHashObj* pDbs) {
|
||||
SFullDatabaseName name = {0};
|
||||
strcpy(name.fullDbName, pFullDbName);
|
||||
return taosHashPut(pDbs, pFullDbName, strlen(pFullDbName), &name, sizeof(SFullDatabaseName));
|
||||
}
|
||||
|
||||
static int32_t collectUseDatabase(const SName* pName, SHashObj* pDbs) {
|
||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||
tNameGetFullDbName(pName, dbFName);
|
||||
return collectUseDatabaseImpl(dbFName, pDbs);
|
||||
}
|
||||
|
||||
static int32_t collectUseTable(const SName* pName, SHashObj* pDbs) {
|
||||
char fullName[TSDB_TABLE_FNAME_LEN];
|
||||
tNameExtractFullName(pName, fullName);
|
||||
|
@ -98,7 +104,10 @@ static int32_t collectUseTable(const SName* pName, SHashObj* pDbs) {
|
|||
|
||||
static int32_t getTableMetaImpl(STranslateContext* pCxt, const SName* pName, STableMeta** pMeta) {
|
||||
SParseContext* pParCxt = pCxt->pParseCxt;
|
||||
int32_t code = collectUseTable(pName, pCxt->pTables);
|
||||
int32_t code = collectUseDatabase(pName, pCxt->pDbs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = collectUseTable(pName, pCxt->pTables);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = catalogGetTableMeta(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pMeta);
|
||||
}
|
||||
|
@ -117,7 +126,10 @@ static int32_t getTableMeta(STranslateContext* pCxt, const char* pDbName, const
|
|||
|
||||
static int32_t getTableDistVgInfo(STranslateContext* pCxt, const SName* pName, SArray** pVgInfo) {
|
||||
SParseContext* pParCxt = pCxt->pParseCxt;
|
||||
int32_t code = collectUseTable(pName, pCxt->pTables);
|
||||
int32_t code = collectUseDatabase(pName, pCxt->pDbs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = collectUseTable(pName, pCxt->pTables);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = catalogGetTableDistVgInfo(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pVgInfo);
|
||||
}
|
||||
|
@ -131,7 +143,7 @@ static int32_t getDBVgInfoImpl(STranslateContext* pCxt, const SName* pName, SArr
|
|||
SParseContext* pParCxt = pCxt->pParseCxt;
|
||||
char fullDbName[TSDB_DB_FNAME_LEN];
|
||||
tNameGetFullDbName(pName, fullDbName);
|
||||
int32_t code = collectUseDatabase(fullDbName, pCxt->pDbs);
|
||||
int32_t code = collectUseDatabaseImpl(fullDbName, pCxt->pDbs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = catalogGetDBVgInfo(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, fullDbName, pVgInfo);
|
||||
}
|
||||
|
@ -151,7 +163,10 @@ static int32_t getDBVgInfo(STranslateContext* pCxt, const char* pDbName, SArray*
|
|||
|
||||
static int32_t getTableHashVgroupImpl(STranslateContext* pCxt, const SName* pName, SVgroupInfo* pInfo) {
|
||||
SParseContext* pParCxt = pCxt->pParseCxt;
|
||||
int32_t code = collectUseTable(pName, pCxt->pTables);
|
||||
int32_t code = collectUseDatabase(pName, pCxt->pDbs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = collectUseTable(pName, pCxt->pTables);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = catalogGetTableHashVgroup(pParCxt->pCatalog, pParCxt->pTransporter, &pParCxt->mgmtEpSet, pName, pInfo);
|
||||
}
|
||||
|
@ -170,7 +185,7 @@ static int32_t getTableHashVgroup(STranslateContext* pCxt, const char* pDbName,
|
|||
|
||||
static int32_t getDBVgVersion(STranslateContext* pCxt, const char* pDbFName, int32_t* pVersion, int64_t* pDbId, int32_t* pTableNum) {
|
||||
SParseContext* pParCxt = pCxt->pParseCxt;
|
||||
int32_t code = collectUseDatabase(pDbFName, pCxt->pDbs);
|
||||
int32_t code = collectUseDatabaseImpl(pDbFName, pCxt->pDbs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = catalogGetDBVgVersion(pParCxt->pCatalog, pDbFName, pVersion, pDbId, pTableNum);
|
||||
}
|
||||
|
@ -256,6 +271,10 @@ static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) {
|
|||
bool found = false;
|
||||
if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
||||
const STableMeta* pMeta = ((SRealTableNode*)pTable)->pMeta;
|
||||
if (PRIMARYKEY_TIMESTAMP_COL_ID == pCol->colId && 0 == strcmp(pCol->colName, PK_TS_COL_INTERNAL_NAME)) {
|
||||
setColumnInfoBySchema((SRealTableNode*)pTable, pMeta->schema, false, pCol);
|
||||
return true;
|
||||
}
|
||||
int32_t nums = pMeta->tableInfo.numOfTags + pMeta->tableInfo.numOfColumns;
|
||||
for (int32_t i = 0; i < nums; ++i) {
|
||||
if (0 == strcmp(pCol->colName, pMeta->schema[i].name)) {
|
||||
|
@ -388,7 +407,7 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
|
|||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
varDataSetLen(pVal->datum.p, pVal->node.resType.bytes);
|
||||
strcpy(varDataVal(pVal->datum.p), pVal->literal);
|
||||
strncpy(varDataVal(pVal->datum.p), pVal->literal, pVal->node.resType.bytes);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
|
@ -599,9 +618,9 @@ static int32_t toVgroupsInfo(SArray* pVgs, SVgroupsInfo** pVgsInfo) {
|
|||
|
||||
static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRealTableNode* pRealTable) {
|
||||
// todo release
|
||||
// if (0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES)) {
|
||||
// return TSDB_CODE_SUCCESS;
|
||||
// }
|
||||
if (0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SArray* vgroupList = NULL;
|
||||
|
@ -613,9 +632,9 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea
|
|||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
// todo remove
|
||||
if (NULL != vgroupList && taosArrayGetSize(vgroupList) > 0 && 0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES)) {
|
||||
taosArrayPopTailBatch(vgroupList, taosArrayGetSize(vgroupList) - 1);
|
||||
}
|
||||
//if (NULL != vgroupList && taosArrayGetSize(vgroupList) > 0 && 0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES)) {
|
||||
// taosArrayPopTailBatch(vgroupList, taosArrayGetSize(vgroupList) - 1);
|
||||
//}
|
||||
|
||||
code = toVgroupsInfo(vgroupList, &pRealTable->pVgroupList);
|
||||
}
|
||||
|
@ -1433,6 +1452,7 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS
|
|||
if (NULL == pSelect) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
sprintf(pSelect->stmtName, "%p", pSelect);
|
||||
|
||||
SRealTableNode* pTable = nodesMakeNode(QUERY_NODE_REAL_TABLE);
|
||||
if (NULL == pTable) {
|
||||
|
@ -1448,6 +1468,10 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS
|
|||
nodesDestroyNode(pSelect);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
SNode* pProject = NULL;
|
||||
FOREACH(pProject, pSelect->pProjectionList) {
|
||||
sprintf(((SExprNode*)pProject)->aliasName, "#sma_%p", pProject);
|
||||
}
|
||||
|
||||
SIntervalWindowNode* pInterval = nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW);
|
||||
if (NULL == pInterval) {
|
||||
|
@ -1455,14 +1479,18 @@ static int32_t getSmaIndexBuildAst(STranslateContext* pCxt, SCreateIndexStmt* pS
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pSelect->pWindow = (SNode*)pInterval;
|
||||
pInterval->pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
pInterval->pInterval = nodesCloneNode(pStmt->pOptions->pInterval);
|
||||
pInterval->pOffset = nodesCloneNode(pStmt->pOptions->pOffset);
|
||||
pInterval->pSliding = nodesCloneNode(pStmt->pOptions->pSliding);
|
||||
if (NULL == pInterval->pInterval || (NULL != pStmt->pOptions->pOffset && NULL == pInterval->pOffset) ||
|
||||
if (NULL == pInterval->pCol || NULL == pInterval->pInterval ||
|
||||
(NULL != pStmt->pOptions->pOffset && NULL == pInterval->pOffset) ||
|
||||
(NULL != pStmt->pOptions->pSliding && NULL == pInterval->pSliding)) {
|
||||
nodesDestroyNode(pSelect);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
((SColumnNode*)pInterval->pCol)->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
strcpy(((SColumnNode*)pInterval->pCol)->colName, PK_TS_COL_INTERNAL_NAME);
|
||||
|
||||
int32_t code = translateQuery(pCxt, (SNode*)pSelect);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -1772,7 +1800,7 @@ static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) {
|
|||
}
|
||||
|
||||
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pRoot)) {
|
||||
if (NULL != pRoot && QUERY_NODE_SELECT_STMT == nodeType(pRoot)) {
|
||||
SSelectStmt* pSelect = (SSelectStmt*) pRoot;
|
||||
*numOfCols = LIST_LENGTH(pSelect->pProjectionList);
|
||||
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
||||
|
@ -1850,6 +1878,7 @@ static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt)
|
|||
if (NULL == pSelect) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
sprintf(pSelect->stmtName, "%p", pSelect);
|
||||
|
||||
SRealTableNode* pTable = nodesMakeNode(QUERY_NODE_REAL_TABLE);
|
||||
if (NULL == pTable) {
|
||||
|
@ -1858,6 +1887,7 @@ static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt)
|
|||
}
|
||||
strcpy(pTable->table.dbName, TSDB_INFORMATION_SCHEMA_DB);
|
||||
strcpy(pTable->table.tableName, getSysTableName(showType));
|
||||
strcpy(pTable->table.tableAlias, pTable->table.tableName);
|
||||
pSelect->pFromTable = (SNode*)pTable;
|
||||
|
||||
*pStmt = pSelect;
|
||||
|
@ -1947,6 +1977,7 @@ static int32_t rewriteShow(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
code = createShowCondition((SShowStmt*)pQuery->pRoot, pStmt);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pQuery->showRewrite = true;
|
||||
nodesDestroyNode(pQuery->pRoot);
|
||||
pQuery->pRoot = (SNode*)pStmt;
|
||||
}
|
||||
|
@ -2369,13 +2400,14 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
}
|
||||
|
||||
static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pQuery->pRoot)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
pQuery->haveResultSet = true;
|
||||
pQuery->directRpc = false;
|
||||
pQuery->msgType = TDMT_VND_QUERY;
|
||||
code = qExtractResultSchema(pQuery->pRoot, &pQuery->numOfResCols, &pQuery->pResSchema);
|
||||
if (TSDB_CODE_SUCCESS != qExtractResultSchema(pQuery->pRoot, &pQuery->numOfResCols, &pQuery->pResSchema)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
break;
|
||||
case QUERY_NODE_VNODE_MODIF_STMT:
|
||||
pQuery->haveResultSet = false;
|
||||
|
@ -2415,7 +2447,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t doTranslate(SParseContext* pParseCxt, SQuery* pQuery) {
|
||||
|
|
|
@ -22,32 +22,6 @@ extern "C" {
|
|||
|
||||
#include "planner.h"
|
||||
|
||||
#define CHECK_ALLOC(p, res) \
|
||||
do { \
|
||||
if (NULL == (p)) { \
|
||||
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY; \
|
||||
return (res); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_CODE(exec, res) \
|
||||
do { \
|
||||
int32_t code = (exec); \
|
||||
if (TSDB_CODE_SUCCESS != code) { \
|
||||
pCxt->errCode = code; \
|
||||
return (res); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_CODE_EXT(exec) \
|
||||
do { \
|
||||
int32_t code = (exec); \
|
||||
if (TSDB_CODE_SUCCESS != code) { \
|
||||
pCxt->errCode = code; \
|
||||
return code; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define planFatal(param, ...) qFatal("PLAN: " param, __VA_ARGS__)
|
||||
#define planError(param, ...) qError("PLAN: " param, __VA_ARGS__)
|
||||
#define planWarn(param, ...) qWarn("PLAN: " param, __VA_ARGS__)
|
||||
|
|
|
@ -45,7 +45,9 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
|
|||
}
|
||||
if (nodesEqualNode(pExpr, *pNode)) {
|
||||
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
CHECK_ALLOC(pCol, DEAL_RES_ERROR);
|
||||
if (NULL == pCol) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
SExprNode* pToBeRewrittenExpr = (SExprNode*)(*pNode);
|
||||
pCol->node.resType = pToBeRewrittenExpr->resType;
|
||||
strcpy(pCol->node.aliasName, pToBeRewrittenExpr->aliasName);
|
||||
|
@ -65,17 +67,12 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
typedef struct SNameExprCxt {
|
||||
int32_t rewriteId;
|
||||
} SNameExprCxt;
|
||||
|
||||
static EDealRes doNameExpr(SNode* pNode, void* pContext) {
|
||||
switch (nodeType(pNode)) {
|
||||
case QUERY_NODE_OPERATOR:
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
case QUERY_NODE_FUNCTION: {
|
||||
SNameExprCxt* pCxt = (SNameExprCxt*)pContext;
|
||||
sprintf(((SExprNode*)pNode)->aliasName, "#expr_%d", pCxt->rewriteId++);
|
||||
sprintf(((SExprNode*)pNode)->aliasName, "#expr_%p", pNode);
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
default:
|
||||
|
@ -86,9 +83,7 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
|
|||
}
|
||||
|
||||
static int32_t rewriteExpr(SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) {
|
||||
static int32_t rewriteId = 1;
|
||||
SNameExprCxt nameCxt = { .rewriteId = rewriteId };
|
||||
nodesWalkList(pExprs, doNameExpr, &nameCxt);
|
||||
nodesWalkList(pExprs, doNameExpr, NULL);
|
||||
SRewriteExprCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs };
|
||||
nodesRewriteSelectStmt(pSelect, clause, doRewriteExpr, &cxt);
|
||||
return cxt.errCode;
|
||||
|
@ -161,6 +156,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
pScan->tableName.acctId = pCxt->pPlanCxt->acctId;
|
||||
strcpy(pScan->tableName.dbname, pRealTable->table.dbName);
|
||||
strcpy(pScan->tableName.tname, pRealTable->table.tableName);
|
||||
pScan->showRewrite = pCxt->pPlanCxt->showRewrite;
|
||||
|
||||
// set columns to scan
|
||||
SNodeList* pCols = NULL;
|
||||
|
@ -290,13 +286,14 @@ static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSel
|
|||
return code;
|
||||
}
|
||||
|
||||
static SColumnNode* createColumnByExpr(SExprNode* pExpr) {
|
||||
static SColumnNode* createColumnByExpr(const char* pStmtName, SExprNode* pExpr) {
|
||||
SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
if (NULL == pCol) {
|
||||
return NULL;
|
||||
}
|
||||
pCol->node.resType = pExpr->resType;
|
||||
strcpy(pCol->colName, pExpr->aliasName);
|
||||
strcpy(pCol->tableAlias, pStmtName);
|
||||
return pCol;
|
||||
}
|
||||
|
||||
|
@ -310,20 +307,22 @@ static EDealRes doCreateColumn(SNode* pNode, void* pContext) {
|
|||
switch (nodeType(pNode)) {
|
||||
case QUERY_NODE_COLUMN: {
|
||||
SNode* pCol = nodesCloneNode(pNode);
|
||||
CHECK_ALLOC(pCol, DEAL_RES_ERROR);
|
||||
CHECK_CODE(nodesListAppend(pCxt->pList, pCol), DEAL_RES_ERROR);
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
if (NULL == pCol) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
return (TSDB_CODE_SUCCESS == nodesListAppend(pCxt->pList, pCol) ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
|
||||
}
|
||||
case QUERY_NODE_OPERATOR:
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
case QUERY_NODE_FUNCTION: {
|
||||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
CHECK_ALLOC(pCol, DEAL_RES_ERROR);
|
||||
if (NULL == pCol) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
pCol->node.resType = pExpr->resType;
|
||||
strcpy(pCol->colName, pExpr->aliasName);
|
||||
CHECK_CODE(nodesListAppend(pCxt->pList, (SNode*)pCol), DEAL_RES_ERROR);
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
return (TSDB_CODE_SUCCESS == nodesListAppend(pCxt->pList, pCol) ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
@ -456,6 +455,12 @@ static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SInterva
|
|||
pWindow->sliding = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->datum.i : pWindow->interval);
|
||||
pWindow->slidingUnit = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit);
|
||||
|
||||
pWindow->pTspk = nodesCloneNode(pInterval->pCol);
|
||||
if (NULL == pWindow->pTspk) {
|
||||
nodesDestroyNode(pWindow);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (NULL != pInterval->pFill) {
|
||||
pWindow->pFill = nodesCloneNode(pInterval->pFill);
|
||||
if (NULL == pWindow->pFill) {
|
||||
|
@ -484,7 +489,42 @@ static int32_t createWindowLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int32_t createColumnByProjections(SLogicPlanContext* pCxt, SNodeList* pExprs, SNodeList** pCols) {
|
||||
static int32_t createSortLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
if (NULL == pSelect->pOrderByList) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SSortLogicNode* pSort = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SORT);
|
||||
if (NULL == pSort) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SNodeList* pCols = NULL;
|
||||
int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_ORDER_BY, NULL, &pCols);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pCols) {
|
||||
pSort->node.pTargets = nodesCloneList(pCols);
|
||||
if (NULL == pSort->node.pTargets) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pSort->pSortKeys = nodesCloneList(pSelect->pOrderByList);
|
||||
if (NULL == pSort->pSortKeys) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pSort;
|
||||
} else {
|
||||
nodesDestroyNode(pSort);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createColumnByProjections(SLogicPlanContext* pCxt, const char* pStmtName, SNodeList* pExprs, SNodeList** pCols) {
|
||||
SNodeList* pList = nodesMakeList();
|
||||
if (NULL == pList) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -492,7 +532,7 @@ static int32_t createColumnByProjections(SLogicPlanContext* pCxt, SNodeList* pEx
|
|||
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pExprs) {
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(pList, createColumnByExpr((SExprNode*)pNode))) {
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(pList, createColumnByExpr(pStmtName, (SExprNode*)pNode))) {
|
||||
nodesDestroyList(pList);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -514,9 +554,10 @@ static int32_t createProjectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSel
|
|||
if (NULL == pProject->pProjections) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(pProject->stmtName, pSelect->stmtName);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createColumnByProjections(pCxt,pSelect->pProjectionList, &pProject->node.pTargets);
|
||||
code = createColumnByProjections(pCxt, pSelect->stmtName, pSelect->pProjectionList, &pProject->node.pTargets);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -537,6 +578,9 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createChildLogicNode(pCxt, pSelect, createAggLogicNode, &pRoot);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createChildLogicNode(pCxt, pSelect, createSortLogicNode, &pRoot);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createChildLogicNode(pCxt, pSelect, createProjectLogicNode, &pRoot);
|
||||
}
|
||||
|
|
|
@ -17,9 +17,14 @@
|
|||
|
||||
#include "functionMgt.h"
|
||||
|
||||
typedef struct SSlotIdInfo {
|
||||
int16_t slotId;
|
||||
bool set;
|
||||
} SSlotIdInfo;
|
||||
|
||||
typedef struct SSlotIndex {
|
||||
int16_t dataBlockId;
|
||||
int16_t slotId;
|
||||
SArray* pSlotIdsInfo; // duplicate name slot
|
||||
} SSlotIndex;
|
||||
|
||||
typedef struct SPhysiPlanContext {
|
||||
|
@ -30,72 +35,195 @@ typedef struct SPhysiPlanContext {
|
|||
SArray* pExecNodeList;
|
||||
} SPhysiPlanContext;
|
||||
|
||||
static int32_t getSlotKey(SNode* pNode, char* pKey) {
|
||||
static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey) {
|
||||
if (QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode)) {
|
||||
return getSlotKey(((SOrderByExprNode*)pNode)->pExpr, pStmtName, pKey);
|
||||
}
|
||||
|
||||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
if (NULL != pStmtName) {
|
||||
return sprintf(pKey, "%s.%s", pStmtName, pCol->node.aliasName);
|
||||
}
|
||||
if ('\0' == pCol->tableAlias[0]) {
|
||||
return sprintf(pKey, "%s", pCol->colName);
|
||||
}
|
||||
return sprintf(pKey, "%s.%s", pCol->tableAlias, pCol->colName);
|
||||
}
|
||||
|
||||
if (NULL != pStmtName) {
|
||||
return sprintf(pKey, "%s.%s", pStmtName, ((SExprNode*)pNode)->aliasName);
|
||||
}
|
||||
return sprintf(pKey, "%s", ((SExprNode*)pNode)->aliasName);
|
||||
}
|
||||
|
||||
static SNode* createSlotDesc(SPhysiPlanContext* pCxt, const SNode* pNode, int16_t slotId) {
|
||||
static SNode* createSlotDesc(SPhysiPlanContext* pCxt, const SNode* pNode, int16_t slotId, bool output) {
|
||||
SSlotDescNode* pSlot = (SSlotDescNode*)nodesMakeNode(QUERY_NODE_SLOT_DESC);
|
||||
CHECK_ALLOC(pSlot, NULL);
|
||||
if (NULL == pSlot) {
|
||||
return NULL;
|
||||
}
|
||||
pSlot->slotId = slotId;
|
||||
pSlot->dataType = ((SExprNode*)pNode)->resType;
|
||||
pSlot->reserve = false;
|
||||
pSlot->output = true;
|
||||
pSlot->output = output;
|
||||
return (SNode*)pSlot;
|
||||
}
|
||||
|
||||
static SNode* createTarget(SNode* pNode, int16_t dataBlockId, int16_t slotId) {
|
||||
static int32_t createTarget(SNode* pNode, int16_t dataBlockId, int16_t slotId, SNode** pOutput) {
|
||||
STargetNode* pTarget = (STargetNode*)nodesMakeNode(QUERY_NODE_TARGET);
|
||||
if (NULL == pTarget) {
|
||||
return NULL;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pTarget->dataBlockId = dataBlockId;
|
||||
pTarget->slotId = slotId;
|
||||
pTarget->pExpr = pNode;
|
||||
return (SNode*)pTarget;
|
||||
|
||||
*pOutput = (SNode*)pTarget;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t addDataBlockDesc(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) {
|
||||
SHashObj* pHash = NULL;
|
||||
if (NULL == pDataBlockDesc->pSlots) {
|
||||
pDataBlockDesc->pSlots = nodesMakeList();
|
||||
CHECK_ALLOC(pDataBlockDesc->pSlots, TSDB_CODE_OUT_OF_MEMORY);
|
||||
static int32_t putSlotToHashImpl(int16_t dataBlockId, int16_t slotId, const char* pName, int32_t len, SHashObj* pHash) {
|
||||
SSlotIndex* pIndex = taosHashGet(pHash, pName, len);
|
||||
if (NULL != pIndex) {
|
||||
SSlotIdInfo info = { .slotId = slotId, .set = false };
|
||||
taosArrayPush(pIndex->pSlotIdsInfo, &info);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pHash = taosHashInit(LIST_LENGTH(pList), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
CHECK_ALLOC(pHash, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == taosArrayInsert(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId, &pHash)) {
|
||||
SSlotIndex index = { .dataBlockId = dataBlockId, .pSlotIdsInfo = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SSlotIdInfo)) };
|
||||
if (NULL == index.pSlotIdsInfo) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
SSlotIdInfo info = { .slotId = slotId, .set = false };
|
||||
taosArrayPush(index.pSlotIdsInfo, &info);
|
||||
return taosHashPut(pHash, pName, len, &index, sizeof(SSlotIndex));
|
||||
}
|
||||
|
||||
static int32_t putSlotToHash(int16_t dataBlockId, int16_t slotId, SNode* pNode, SHashObj* pHash) {
|
||||
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
|
||||
int32_t len = getSlotKey(pNode, NULL, name);
|
||||
return putSlotToHashImpl(dataBlockId, slotId, name, len, pHash);
|
||||
}
|
||||
|
||||
static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity, int16_t dataBlockId, SHashObj** pDescHash) {
|
||||
SHashObj* pHash = taosHashInit(capacity, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
if (NULL == pHash) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (NULL == taosArrayInsert(pCxt->pLocationHelper, dataBlockId, &pHash)) {
|
||||
taosHashCleanup(pHash);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
} else {
|
||||
pHash = taosArrayGetP(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId);
|
||||
|
||||
*pDescHash = pHash;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, SHashObj* pHash) {
|
||||
pDataBlockDesc->pSlots = nodesMakeList();
|
||||
if (NULL == pDataBlockDesc->pSlots) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int16_t slotId = 0;
|
||||
SNode* pNode = NULL;
|
||||
int16_t slotId = taosHashGetSize(pHash);
|
||||
FOREACH(pNode, pList) {
|
||||
CHECK_CODE_EXT(nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pNode, slotId)));
|
||||
|
||||
SSlotIndex index = { .dataBlockId = pDataBlockDesc->dataBlockId, .slotId = slotId };
|
||||
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
|
||||
int32_t len = getSlotKey(pNode, name);
|
||||
CHECK_CODE(taosHashPut(pHash, name, len, &index, sizeof(SSlotIndex)), TSDB_CODE_OUT_OF_MEMORY);
|
||||
|
||||
SNode* pTarget = createTarget(pNode, pDataBlockDesc->dataBlockId, slotId);
|
||||
CHECK_ALLOC(pTarget, TSDB_CODE_OUT_OF_MEMORY);
|
||||
REPLACE_NODE(pTarget);
|
||||
|
||||
code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pNode, slotId, true));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = putSlotToHash(pDataBlockDesc->dataBlockId, slotId, pNode, pHash);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pDataBlockDesc->resultRowSize += ((SExprNode*)pNode)->resType.bytes;
|
||||
++slotId;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createDataBlockDesc(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode** pDataBlockDesc) {
|
||||
SDataBlockDescNode* pDesc = nodesMakeNode(QUERY_NODE_DATABLOCK_DESC);
|
||||
if (NULL == pDesc) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pDesc->dataBlockId = pCxt->nextDataBlockId++;
|
||||
|
||||
SHashObj* pHash = NULL;
|
||||
int32_t code = createDataBlockDescHash(pCxt, LIST_LENGTH(pList), pDesc->dataBlockId, &pHash);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildDataBlockSlots(pCxt, pList, pDesc, pHash);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pDataBlockDesc = pDesc;
|
||||
} else {
|
||||
nodesDestroyNode(pDesc);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int16_t getUnsetSlotId(const SArray* pSlotIdsInfo) {
|
||||
int32_t size = taosArrayGetSize(pSlotIdsInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSlotIdInfo* pInfo = taosArrayGet(pSlotIdsInfo, i);
|
||||
if (!pInfo->set) {
|
||||
pInfo->set = true;
|
||||
return pInfo->slotId;
|
||||
}
|
||||
}
|
||||
return ((SSlotIdInfo*)taosArrayGet(pSlotIdsInfo, 0))->slotId;
|
||||
}
|
||||
|
||||
static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc, const char* pStmtName, bool output) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SHashObj* pHash = taosArrayGetP(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId);
|
||||
int16_t nextSlotId = taosHashGetSize(pHash), slotId = 0;
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pList) {
|
||||
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN] = {0};
|
||||
int32_t len = getSlotKey(pNode, pStmtName, name);
|
||||
SSlotIndex* pIndex = taosHashGet(pHash, name, len);
|
||||
if (NULL == pIndex) {
|
||||
code = nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, pNode, nextSlotId, output));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = putSlotToHashImpl(pDataBlockDesc->dataBlockId, nextSlotId, name, len, pHash);
|
||||
}
|
||||
pDataBlockDesc->resultRowSize += ((SExprNode*)pNode)->resType.bytes;
|
||||
slotId = nextSlotId;
|
||||
++nextSlotId;
|
||||
} else {
|
||||
slotId = getUnsetSlotId(pIndex->pSlotIdsInfo);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SNode* pTarget = NULL;
|
||||
code = createTarget(pNode, pDataBlockDesc->dataBlockId, slotId, &pTarget);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
REPLACE_NODE(pTarget);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t addDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) {
|
||||
return addDataBlockSlotsImpl(pCxt, pList, pDataBlockDesc, NULL, false);
|
||||
}
|
||||
|
||||
static int32_t addDataBlockSlotsForProject(SPhysiPlanContext* pCxt, const char* pStmtName, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) {
|
||||
return addDataBlockSlotsImpl(pCxt, pList, pDataBlockDesc, pStmtName, true);
|
||||
}
|
||||
|
||||
static int32_t pushdownDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode* pDataBlockDesc) {
|
||||
return addDataBlockSlotsImpl(pCxt, pList, pDataBlockDesc, NULL, true);
|
||||
}
|
||||
|
||||
typedef struct SSetSlotIdCxt {
|
||||
|
@ -108,16 +236,17 @@ static EDealRes doSetSlotId(SNode* pNode, void* pContext) {
|
|||
if (QUERY_NODE_COLUMN == nodeType(pNode) && 0 != strcmp(((SColumnNode*)pNode)->colName, "*")) {
|
||||
SSetSlotIdCxt* pCxt = (SSetSlotIdCxt*)pContext;
|
||||
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
|
||||
int32_t len = getSlotKey(pNode, name);
|
||||
int32_t len = getSlotKey(pNode, NULL, name);
|
||||
SSlotIndex* pIndex = taosHashGet(pCxt->pLeftHash, name, len);
|
||||
if (NULL == pIndex) {
|
||||
pIndex = taosHashGet(pCxt->pRightHash, name, len);
|
||||
}
|
||||
// pIndex is definitely not NULL, otherwise it is a bug
|
||||
CHECK_ALLOC(pIndex, DEAL_RES_ERROR);
|
||||
if (NULL == pIndex) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
((SColumnNode*)pNode)->dataBlockId = pIndex->dataBlockId;
|
||||
((SColumnNode*)pNode)->slotId = pIndex->slotId;
|
||||
CHECK_ALLOC(pNode, DEAL_RES_ERROR);
|
||||
((SColumnNode*)pNode)->slotId = ((SSlotIdInfo*)taosArrayGet(pIndex->pSlotIdsInfo, 0))->slotId;
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
|
@ -144,7 +273,7 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, SNodeList* pList, SNodeList** pOutput) {
|
||||
static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, int16_t rightDataBlockId, const SNodeList* pList, SNodeList** pOutput) {
|
||||
SNodeList* pRes = nodesCloneList(pList);
|
||||
if (NULL == pRes) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -164,18 +293,17 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, ENodeType type) {
|
||||
static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, ENodeType type) {
|
||||
SPhysiNode* pPhysiNode = (SPhysiNode*)nodesMakeNode(type);
|
||||
if (NULL == pPhysiNode) {
|
||||
return NULL;
|
||||
}
|
||||
pPhysiNode->pOutputDataBlockDesc = nodesMakeNode(QUERY_NODE_DATABLOCK_DESC);
|
||||
if (NULL == pPhysiNode->pOutputDataBlockDesc) {
|
||||
|
||||
int32_t code = createDataBlockDesc(pCxt, pLogicNode->pTargets, &pPhysiNode->pOutputDataBlockDesc);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode(pPhysiNode);
|
||||
return NULL;
|
||||
}
|
||||
pPhysiNode->pOutputDataBlockDesc->dataBlockId = pCxt->nextDataBlockId++;
|
||||
pPhysiNode->pOutputDataBlockDesc->type = QUERY_NODE_DATABLOCK_DESC;
|
||||
return pPhysiNode;
|
||||
}
|
||||
|
||||
|
@ -186,24 +314,11 @@ static int32_t setConditionsSlotId(SPhysiPlanContext* pCxt, const SLogicNode* pL
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setSlotOutput(SPhysiPlanContext* pCxt, SNodeList* pTargets, SDataBlockDescNode* pDataBlockDesc) {
|
||||
SHashObj* pHash = taosArrayGetP(pCxt->pLocationHelper, pDataBlockDesc->dataBlockId);
|
||||
char name[TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pTargets) {
|
||||
int32_t len = getSlotKey(pNode, name);
|
||||
SSlotIndex* pIndex = taosHashGet(pHash, name, len);
|
||||
// pIndex is definitely not NULL, otherwise it is a bug
|
||||
CHECK_ALLOC(pIndex, TSDB_CODE_FAILED);
|
||||
((SSlotDescNode*)nodesListGetNode(pDataBlockDesc->pSlots, pIndex->slotId))->output = true;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SNodeptr createPrimaryKeyCol(SPhysiPlanContext* pCxt, uint64_t tableId) {
|
||||
SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
CHECK_ALLOC(pCol, NULL);
|
||||
if (NULL == pCol) {
|
||||
return NULL;
|
||||
}
|
||||
pCol->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
pCol->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
|
||||
pCol->tableId = tableId;
|
||||
|
@ -244,8 +359,12 @@ static int32_t createScanCols(SPhysiPlanContext* pCxt, SScanPhysiNode* pScanPhys
|
|||
if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(pScanPhysiNode)
|
||||
|| QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN == nodeType(pScanPhysiNode)) {
|
||||
pScanPhysiNode->pScanCols = nodesMakeList();
|
||||
CHECK_ALLOC(pScanPhysiNode->pScanCols, TSDB_CODE_OUT_OF_MEMORY);
|
||||
CHECK_CODE_EXT(nodesListStrictAppend(pScanPhysiNode->pScanCols, createPrimaryKeyCol(pCxt, pScanPhysiNode->uid)));
|
||||
if (NULL == pScanPhysiNode->pScanCols) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pScanPhysiNode->pScanCols, createPrimaryKeyCol(pCxt, pScanPhysiNode->uid))) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pScanCols) {
|
||||
|
@ -255,29 +374,29 @@ static int32_t createScanCols(SPhysiPlanContext* pCxt, SScanPhysiNode* pScanPhys
|
|||
strcpy(pCol->colName, ((SColumnNode*)pNode)->colName);
|
||||
continue;
|
||||
}
|
||||
CHECK_CODE_EXT(nodesListStrictAppend(pScanPhysiNode->pScanCols, nodesCloneNode(pNode)));
|
||||
if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pScanPhysiNode->pScanCols, nodesCloneNode(pNode))) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pScanPhysiNode->pScanCols = nodesCloneList(pScanCols);
|
||||
CHECK_ALLOC(pScanPhysiNode->pScanCols, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == pScanPhysiNode->pScanCols) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// return sortScanCols(pScanPhysiNode->pScanCols);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return sortScanCols(pScanPhysiNode->pScanCols);
|
||||
}
|
||||
|
||||
static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SScanPhysiNode* pScanPhysiNode, SPhysiNode** pPhyNode) {
|
||||
int32_t code = createScanCols(pCxt, pScanPhysiNode, pScanLogicNode->pScanCols);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
// Data block describe also needs to be set without scanning column, such as SELECT COUNT(*) FROM t
|
||||
code = addDataBlockDesc(pCxt, pScanPhysiNode->pScanCols, pScanPhysiNode->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlots(pCxt, pScanPhysiNode->pScanCols, pScanPhysiNode->node.pOutputDataBlockDesc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pScanLogicNode, (SPhysiNode*)pScanPhysiNode);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setSlotOutput(pCxt, pScanLogicNode->node.pTargets, pScanPhysiNode->node.pOutputDataBlockDesc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pScanPhysiNode->uid = pScanLogicNode->pMeta->uid;
|
||||
pScanPhysiNode->tableType = pScanLogicNode->pMeta->tableType;
|
||||
|
@ -302,7 +421,7 @@ static void vgroupInfoToNodeAddr(const SVgroupInfo* vg, SQueryNodeAddr* pNodeAdd
|
|||
}
|
||||
|
||||
static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN);
|
||||
STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN);
|
||||
if (NULL == pTagScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -310,7 +429,7 @@ static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* p
|
|||
}
|
||||
|
||||
static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
||||
STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
||||
if (NULL == pTableScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -326,21 +445,20 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp
|
|||
}
|
||||
|
||||
static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN);
|
||||
SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pScan->showRewrite = pScanLogicNode->showRewrite;
|
||||
pScan->accountId = pCxt->pPlanCxt->acctId;
|
||||
if (0 == strcmp(pScanLogicNode->tableName.tname, TSDB_INS_TABLE_USER_TABLES)) {
|
||||
vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups, &pSubplan->execNode);
|
||||
taosArrayPush(pCxt->pExecNodeList, &pSubplan->execNode);
|
||||
} else {
|
||||
for (int32_t i = 0; i < pScanLogicNode->pVgroupList->numOfVgroups; ++i) {
|
||||
SQueryNodeAddr addr;
|
||||
vgroupInfoToNodeAddr(pScanLogicNode->pVgroupList->vgroups + i, &addr);
|
||||
SQueryNodeAddr addr = { .nodeId = MND_VGID, .epSet = pCxt->pPlanCxt->mgmtEpSet };
|
||||
taosArrayPush(pCxt->pExecNodeList, &addr);
|
||||
}
|
||||
}
|
||||
pScan->mgmtEpSet = pCxt->pPlanCxt->mgmtEpSet;
|
||||
tNameGetFullDbName(&pScanLogicNode->tableName, pSubplan->dbFName);
|
||||
|
||||
|
@ -348,7 +466,7 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan*
|
|||
}
|
||||
|
||||
static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -412,7 +530,7 @@ static int32_t createJoinOutputCols(SPhysiPlanContext* pCxt, SDataBlockDescNode*
|
|||
}
|
||||
|
||||
static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) {
|
||||
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_JOIN);
|
||||
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN);
|
||||
if (NULL == pJoin) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -425,14 +543,11 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
|||
code = createJoinOutputCols(pCxt, pLeftDesc, pRightDesc, &pJoin->pTargets);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlots(pCxt, pJoin->pTargets, pJoin->node.pOutputDataBlockDesc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pJoinLogicNode, (SPhysiNode*)pJoin);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setSlotOutput(pCxt, pJoinLogicNode->node.pTargets, pJoin->node.pOutputDataBlockDesc);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pJoin;
|
||||
|
@ -452,7 +567,9 @@ typedef struct SRewritePrecalcExprsCxt {
|
|||
|
||||
static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode) {
|
||||
SNode* pExpr = nodesCloneNode(*pNode);
|
||||
CHECK_ALLOC(pExpr, DEAL_RES_ERROR);
|
||||
if (NULL == pExpr) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
if (nodesListAppend(pCxt->pPrecalcExprs, pExpr)) {
|
||||
nodesDestroyNode(pExpr);
|
||||
return DEAL_RES_ERROR;
|
||||
|
@ -500,11 +617,15 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN
|
|||
|
||||
if (NULL == *pPrecalcExprs) {
|
||||
*pPrecalcExprs = nodesMakeList();
|
||||
CHECK_ALLOC(*pPrecalcExprs, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == *pPrecalcExprs) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
if (NULL == *pRewrittenList) {
|
||||
*pRewrittenList = nodesMakeList();
|
||||
CHECK_ALLOC(*pRewrittenList, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == *pRewrittenList) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pList) {
|
||||
|
@ -514,8 +635,12 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN
|
|||
} else {
|
||||
pNew = nodesCloneNode(pNode);
|
||||
}
|
||||
CHECK_ALLOC(pNew, TSDB_CODE_OUT_OF_MEMORY);
|
||||
CHECK_CODE(nodesListAppend(*pRewrittenList, pNew), TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == pNew) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(*pRewrittenList, pNew)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
SRewritePrecalcExprsCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pPrecalcExprs = *pPrecalcExprs };
|
||||
nodesRewriteList(*pRewrittenList, doRewritePrecalcExprs, &cxt);
|
||||
|
@ -527,7 +652,7 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN
|
|||
}
|
||||
|
||||
static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, SPhysiNode** pPhyNode) {
|
||||
SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_AGG);
|
||||
SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG);
|
||||
if (NULL == pAgg) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -545,30 +670,27 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
|||
if (TSDB_CODE_SUCCESS == code && NULL != pPrecalcExprs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs, &pAgg->pExprs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pAgg->pExprs, pChildTupe);
|
||||
code = pushdownDataBlockSlots(pCxt, pAgg->pExprs, pChildTupe);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pGroupKeys) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pGroupKeys, &pAgg->pGroupKeys);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pAgg->pGroupKeys, pAgg->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlots(pCxt, pAgg->pGroupKeys, pAgg->node.pOutputDataBlockDesc);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pAggFuncs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pAggFuncs, &pAgg->pAggFuncs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pAgg->pAggFuncs, pAgg->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlots(pCxt, pAgg->pAggFuncs, pAgg->node.pOutputDataBlockDesc);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pAggLogicNode, (SPhysiNode*)pAgg);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setSlotOutput(pCxt, pAggLogicNode->node.pTargets, pAgg->node.pOutputDataBlockDesc);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pAgg;
|
||||
|
@ -576,18 +698,22 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
|||
nodesDestroyNode(pAgg);
|
||||
}
|
||||
|
||||
nodesDestroyList(pPrecalcExprs);
|
||||
nodesDestroyList(pGroupKeys);
|
||||
nodesDestroyList(pAggFuncs);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) {
|
||||
SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_PROJECT);
|
||||
SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT);
|
||||
if (NULL == pProject) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = setListSlotId(pCxt, ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc->dataBlockId, -1, pProjectLogicNode->pProjections, &pProject->pProjections);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pProject->pProjections, pProject->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlotsForProject(pCxt, pProjectLogicNode->stmtName, pProject->pProjections, pProject->node.pOutputDataBlockDesc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pProjectLogicNode, (SPhysiNode*)pProject);
|
||||
|
@ -603,34 +729,30 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild
|
|||
}
|
||||
|
||||
static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE);
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE);
|
||||
if (NULL == pExchange) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pExchange->srcGroupId = pExchangeLogicNode->srcGroupId;
|
||||
int32_t code = addDataBlockDesc(pCxt, pExchangeLogicNode->node.pTargets, pExchange->node.pOutputDataBlockDesc);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pExchange;
|
||||
} else {
|
||||
nodesDestroyNode(pExchange);
|
||||
}
|
||||
|
||||
return code;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = addDataBlockDesc(pCxt, pExchangeLogicNode->node.pTargets, pScan->node.pOutputDataBlockDesc);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
pScan->pScanCols = nodesCloneList(pExchangeLogicNode->node.pTargets);
|
||||
if (NULL == pScan->pScanCols) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlots(pCxt, pScan->pScanCols, pScan->node.pOutputDataBlockDesc);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -660,21 +782,17 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
|||
if (TSDB_CODE_SUCCESS == code && NULL != pPrecalcExprs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs, &pWindow->pExprs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pWindow->pExprs, pChildTupe);
|
||||
code = addDataBlockSlots(pCxt, pWindow->pExprs, pChildTupe);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pFuncs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pWindow->pFuncs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockDesc(pCxt, pWindow->pFuncs, pWindow->node.pOutputDataBlockDesc);
|
||||
code = addDataBlockSlots(pCxt, pWindow->pFuncs, pWindow->node.pOutputDataBlockDesc);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setSlotOutput(pCxt, pWindowLogicNode->node.pTargets, pWindow->node.pOutputDataBlockDesc);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pWindow;
|
||||
} else {
|
||||
|
@ -685,7 +803,7 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
|||
}
|
||||
|
||||
static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_INTERVAL);
|
||||
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL);
|
||||
if (NULL == pInterval) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -702,11 +820,18 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc);
|
||||
int32_t code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTspk, &pInterval->pTspk);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode(pInterval);
|
||||
return code;
|
||||
}
|
||||
|
||||
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pInterval->window, pWindowLogicNode, pPhyNode);
|
||||
}
|
||||
|
||||
static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW);
|
||||
SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW);
|
||||
if (NULL == pSession) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -730,6 +855,41 @@ static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildr
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT);
|
||||
if (NULL == pSort) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SNodeList* pPrecalcExprs = NULL;
|
||||
SNodeList* pSortKeys = NULL;
|
||||
int32_t code = rewritePrecalcExprs(pCxt, pSortLogicNode->pSortKeys, &pPrecalcExprs, &pSortKeys);
|
||||
|
||||
SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc);
|
||||
// push down expression to pOutputDataBlockDesc of child node
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pPrecalcExprs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPrecalcExprs, &pSort->pExprs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlots(pCxt, pSort->pExprs, pChildTupe);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pSortKeys, &pSort->pSortKeys);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlots(pCxt, pSort->pSortKeys, pSort->node.pOutputDataBlockDesc);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pSort;
|
||||
} else {
|
||||
nodesDestroyNode(pSort);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan, SNodeList* pChildren, SPhysiNode** pPhyNode) {
|
||||
switch (nodeType(pLogicNode)) {
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
|
@ -744,6 +904,8 @@ static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode
|
|||
return createExchangePhysiNode(pCxt, (SExchangeLogicNode*)pLogicNode, pPhyNode);
|
||||
case QUERY_NODE_LOGIC_PLAN_WINDOW:
|
||||
return createWindowPhysiNode(pCxt, pChildren, (SWindowLogicNode*)pLogicNode, pPhyNode);
|
||||
case QUERY_NODE_LOGIC_PLAN_SORT:
|
||||
return createSortPhysiNode(pCxt, pChildren, (SSortLogicNode*)pLogicNode, pPhyNode);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -875,17 +1037,22 @@ static int32_t pushSubplan(SPhysiPlanContext* pCxt, SNodeptr pSubplan, int32_t l
|
|||
SNodeListNode* pGroup;
|
||||
if (level >= LIST_LENGTH(pSubplans)) {
|
||||
pGroup = nodesMakeNode(QUERY_NODE_NODE_LIST);
|
||||
CHECK_ALLOC(pGroup, TSDB_CODE_OUT_OF_MEMORY);
|
||||
CHECK_CODE(nodesListStrictAppend(pSubplans, pGroup), TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == pGroup) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pSubplans, pGroup)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
} else {
|
||||
pGroup = nodesListGetNode(pSubplans, level);
|
||||
}
|
||||
if (NULL == pGroup->pNodeList) {
|
||||
pGroup->pNodeList = nodesMakeList();
|
||||
CHECK_ALLOC(pGroup->pNodeList, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == pGroup->pNodeList) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
CHECK_CODE(nodesListStrictAppend(pGroup->pNodeList, pSubplan), TSDB_CODE_OUT_OF_MEMORY);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return nodesListStrictAppend(pGroup->pNodeList, pSubplan);
|
||||
}
|
||||
|
||||
static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan* pParent, SQueryPlan* pQueryPlan) {
|
||||
|
|
|
@ -65,7 +65,9 @@ static int32_t stsMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
|||
SLogicNode* pSplitNode = stsMatchByNode(pSubplan->pNode);
|
||||
if (NULL != pSplitNode) {
|
||||
SStsInfo* pInfo = taosMemoryCalloc(1, sizeof(SStsInfo));
|
||||
CHECK_ALLOC(pInfo, TSDB_CODE_OUT_OF_MEMORY);
|
||||
if (NULL == pInfo) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pInfo->pScan = (SScanLogicNode*)pSplitNode;
|
||||
pInfo->pSubplan = pSubplan;
|
||||
pCxt->pInfo = pInfo;
|
||||
|
|
|
@ -170,7 +170,7 @@ TEST_F(PlannerTest, groupBy) {
|
|||
bind("SELECT count(*) FROM t1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT c1, count(*) FROM t1 GROUP BY c1");
|
||||
bind("SELECT c1, max(c3), min(c2), count(*) FROM t1 GROUP BY c1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3");
|
||||
|
@ -201,10 +201,31 @@ TEST_F(PlannerTest, sessionWindow) {
|
|||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, orderBy) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("SELECT * FROM t1 order by c1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT c1 FROM t1 order by c2");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT * FROM t1 order by c1 + 10, c2");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, showTables) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("show tables");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, showStables) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("show stables");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, createTopic) {
|
||||
|
|
|
@ -140,7 +140,7 @@ int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t asyncSendMsgToServer(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo) {
|
||||
int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo, bool persistHandle, void *rpcCtx) {
|
||||
char* pMsg = rpcMallocCont(pInfo->msgInfo.len);
|
||||
if (NULL == pMsg) {
|
||||
qError("0x%" PRIx64 " msg:%s malloc failed", pInfo->requestId, TMSG_INFO(pInfo->msgType));
|
||||
|
@ -154,6 +154,7 @@ int32_t asyncSendMsgToServer(void* pTransporter, SEpSet* epSet, int64_t* pTransp
|
|||
.contLen = pInfo->msgInfo.len,
|
||||
.ahandle = (void*)pInfo,
|
||||
.handle = pInfo->msgInfo.handle,
|
||||
.persistHandle = persistHandle,
|
||||
.code = 0};
|
||||
if (pInfo->msgType == TDMT_VND_QUERY || pInfo->msgType == TDMT_VND_FETCH ||
|
||||
pInfo->msgType == TDMT_VND_QUERY_CONTINUE) {
|
||||
|
@ -162,10 +163,14 @@ int32_t asyncSendMsgToServer(void* pTransporter, SEpSet* epSet, int64_t* pTransp
|
|||
|
||||
assert(pInfo->fp != NULL);
|
||||
|
||||
rpcSendRequest(pTransporter, epSet, &rpcMsg, pTransporterId);
|
||||
rpcSendRequestWithCtx(pTransporter, epSet, &rpcMsg, pTransporterId, rpcCtx);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t asyncSendMsgToServer(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo) {
|
||||
return asyncSendMsgToServerExt(pTransporter, epSet, pTransporterId, pInfo, false, NULL);
|
||||
}
|
||||
|
||||
char *jobTaskStatusStr(int32_t status) {
|
||||
switch (status) {
|
||||
case JOB_TASK_STATUS_NULL:
|
||||
|
|
|
@ -69,18 +69,24 @@ enum {
|
|||
typedef struct SQWDebug {
|
||||
bool lockEnable;
|
||||
bool statusEnable;
|
||||
bool dumpEnable;
|
||||
} SQWDebug;
|
||||
|
||||
typedef struct SQWConnInfo {
|
||||
void *handle;
|
||||
void *ahandle;
|
||||
} SQWConnInfo;
|
||||
|
||||
typedef struct SQWMsg {
|
||||
void *node;
|
||||
char *msg;
|
||||
int32_t msgLen;
|
||||
void *connection;
|
||||
SQWConnInfo connInfo;
|
||||
} SQWMsg;
|
||||
|
||||
typedef struct SQWHbInfo {
|
||||
SSchedulerHbRsp rsp;
|
||||
void *connection;
|
||||
SQWConnInfo connInfo;
|
||||
} SQWHbInfo;
|
||||
|
||||
typedef struct SQWPhaseInput {
|
||||
|
@ -102,10 +108,6 @@ typedef struct SQWTaskCtx {
|
|||
int8_t phase;
|
||||
int8_t taskType;
|
||||
|
||||
void *readyConnection;
|
||||
void *dropConnection;
|
||||
void *cancelConnection;
|
||||
|
||||
bool emptyRes;
|
||||
bool queryFetched;
|
||||
bool queryEnd;
|
||||
|
@ -113,6 +115,7 @@ typedef struct SQWTaskCtx {
|
|||
bool queryInQueue;
|
||||
int32_t rspCode;
|
||||
|
||||
SQWConnInfo connInfo;
|
||||
int8_t events[QW_EVENT_MAX];
|
||||
|
||||
qTaskInfo_t taskHandle;
|
||||
|
@ -121,8 +124,9 @@ typedef struct SQWTaskCtx {
|
|||
|
||||
typedef struct SQWSchStatus {
|
||||
int32_t lastAccessTs; // timestamp in second
|
||||
uint64_t hbSeqId;
|
||||
void *hbConnection;
|
||||
SRWLatch hbConnLock;
|
||||
SQWConnInfo hbConnInfo;
|
||||
SQueryNodeEpId hbEpId;
|
||||
SRWLatch tasksLock;
|
||||
SHashObj *tasksHash; // key:queryId+taskId, value: SQWTaskStatus
|
||||
} SQWSchStatus;
|
||||
|
@ -172,12 +176,16 @@ typedef struct SQWorkerMgmt {
|
|||
#define QW_ELOG(param, ...) qError("QW:%p " param, mgmt, __VA_ARGS__)
|
||||
#define QW_DLOG(param, ...) qDebug("QW:%p " param, mgmt, __VA_ARGS__)
|
||||
|
||||
#define QW_DUMP(param, ...) do { if (gQWDebug.dumpEnable) { qDebug("QW:%p " param, mgmt, __VA_ARGS__); } } while (0)
|
||||
|
||||
|
||||
#define QW_SCH_ELOG(param, ...) qError("QW:%p SID:%"PRIx64" " param, mgmt, sId, __VA_ARGS__)
|
||||
#define QW_SCH_DLOG(param, ...) qDebug("QW:%p SID:%"PRIx64" " param, mgmt, sId, __VA_ARGS__)
|
||||
|
||||
#define QW_TASK_ELOG(param, ...) qError("QW:%p QID:0x%"PRIx64",TID:0x%"PRIx64" " param, mgmt, qId, tId, __VA_ARGS__)
|
||||
#define QW_TASK_WLOG(param, ...) qWarn("QW:%p QID:0x%"PRIx64",TID:0x%"PRIx64" " param, mgmt, qId, tId, __VA_ARGS__)
|
||||
#define QW_TASK_DLOG(param, ...) qDebug("QW:%p QID:0x%"PRIx64",TID:0x%"PRIx64" " param, mgmt, qId, tId, __VA_ARGS__)
|
||||
#define QW_TASK_DLOGL(param, ...) qDebugL("QW:%p QID:0x%"PRIx64",TID:0x%"PRIx64" " param, mgmt, qId, tId, __VA_ARGS__)
|
||||
|
||||
#define QW_TASK_ELOG_E(param) qError("QW:%p QID:0x%"PRIx64",TID:0x%"PRIx64" " param, mgmt, qId, tId)
|
||||
#define QW_TASK_WLOG_E(param) qWarn("QW:%p QID:0x%"PRIx64",TID:0x%"PRIx64" " param, mgmt, qId, tId)
|
||||
|
@ -223,8 +231,6 @@ typedef struct SQWorkerMgmt {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
int32_t qwBuildAndSendCancelRsp(SRpcMsg *pMsg, int32_t code);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -30,17 +30,18 @@ int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg);
|
|||
int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg);
|
||||
int32_t qwProcessHb(SQWorkerMgmt *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req);
|
||||
|
||||
int32_t qwBuildAndSendDropRsp(void *connection, int32_t code);
|
||||
int32_t qwBuildAndSendCancelRsp(SRpcMsg *pMsg, int32_t code);
|
||||
int32_t qwBuildAndSendFetchRsp(void *connection, SRetrieveTableRsp *pRsp, int32_t dataLength, int32_t code);
|
||||
int32_t qwBuildAndSendDropRsp(SQWConnInfo *pConn, int32_t code);
|
||||
int32_t qwBuildAndSendCancelRsp(SQWConnInfo *pConn, int32_t code);
|
||||
int32_t qwBuildAndSendFetchRsp(SQWConnInfo *pConn, SRetrieveTableRsp *pRsp, int32_t dataLength, int32_t code);
|
||||
void qwBuildFetchRsp(void *msg, SOutputData *input, int32_t len, bool qComplete);
|
||||
int32_t qwBuildAndSendCQueryMsg(QW_FPARAMS_DEF, void *connection);
|
||||
int32_t qwBuildAndSendReadyRsp(void *connection, int32_t code);
|
||||
int32_t qwBuildAndSendQueryRsp(void *connection, int32_t code);
|
||||
int32_t qwBuildAndSendCQueryMsg(QW_FPARAMS_DEF, SQWConnInfo *pConn);
|
||||
int32_t qwBuildAndSendReadyRsp(SQWConnInfo *pConn, int32_t code);
|
||||
int32_t qwBuildAndSendQueryRsp(SQWConnInfo *pConn, int32_t code);
|
||||
void qwFreeFetchRsp(void *msg);
|
||||
int32_t qwMallocFetchRsp(int32_t length, SRetrieveTableRsp **rsp);
|
||||
int32_t qwGetSchTasksStatus(SQWorkerMgmt *mgmt, uint64_t sId, SSchedulerStatusRsp **rsp);
|
||||
int32_t qwBuildAndSendHbRsp(SRpcMsg *pMsg, SSchedulerHbRsp *rsp, int32_t code);
|
||||
int32_t qwBuildAndSendHbRsp(SQWConnInfo *pConn, SSchedulerHbRsp *rsp, int32_t code);
|
||||
int32_t qwRegisterBrokenLinkArg(QW_FPARAMS_DEF, SQWConnInfo *pConn);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include "tname.h"
|
||||
#include "dataSinkMgt.h"
|
||||
|
||||
SQWDebug gQWDebug = {.statusEnable = true};
|
||||
SQWDebug gQWDebug = {.statusEnable = true, .dumpEnable = true};
|
||||
|
||||
int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, bool *ignore) {
|
||||
if (!gQWDebug.statusEnable) {
|
||||
|
@ -103,6 +103,36 @@ _return:
|
|||
QW_RET(code);
|
||||
}
|
||||
|
||||
void qwDbgDumpSchInfo(SQWSchStatus *sch, int32_t i) {
|
||||
|
||||
}
|
||||
|
||||
void qwDbgDumpMgmtInfo(SQWorkerMgmt *mgmt) {
|
||||
if (!gQWDebug.dumpEnable) {
|
||||
return;
|
||||
}
|
||||
|
||||
QW_LOCK(QW_READ, &mgmt->schLock);
|
||||
|
||||
QW_DUMP("total remain schduler num:%d", taosHashGetSize(mgmt->schHash));
|
||||
|
||||
void *key = NULL;
|
||||
size_t keyLen = 0;
|
||||
int32_t i = 0;
|
||||
SQWSchStatus *sch = NULL;
|
||||
|
||||
void *pIter = taosHashIterate(mgmt->schHash, NULL);
|
||||
while (pIter) {
|
||||
sch = (SQWSchStatus *)pIter;
|
||||
qwDbgDumpSchInfo(sch, i);
|
||||
++i;
|
||||
pIter = taosHashIterate(mgmt->schHash, pIter);
|
||||
}
|
||||
|
||||
QW_UNLOCK(QW_READ, &mgmt->schLock);
|
||||
|
||||
QW_DUMP("total remain ctx num:%d", taosHashGetSize(mgmt->ctxHash));
|
||||
}
|
||||
|
||||
char *qwPhaseStr(int32_t phase) {
|
||||
switch (phase) {
|
||||
|
@ -166,7 +196,7 @@ int32_t qwSetTaskStatus(QW_FPARAMS_DEF, SQWTaskStatus *task, int8_t status) {
|
|||
}
|
||||
|
||||
|
||||
int32_t qwAddSchedulerImpl(SQWorkerMgmt *mgmt, uint64_t sId, int32_t rwType, SQWSchStatus **sch) {
|
||||
int32_t qwAddSchedulerImpl(SQWorkerMgmt *mgmt, uint64_t sId, int32_t rwType) {
|
||||
SQWSchStatus newSch = {0};
|
||||
newSch.tasksHash = taosHashInit(mgmt->cfg.maxSchTaskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
if (NULL == newSch.tasksHash) {
|
||||
|
@ -200,7 +230,7 @@ int32_t qwAcquireSchedulerImpl(SQWorkerMgmt *mgmt, uint64_t sId, int32_t rwType,
|
|||
QW_UNLOCK(rwType, &mgmt->schLock);
|
||||
|
||||
if (QW_NOT_EXIST_ADD == nOpt) {
|
||||
QW_ERR_RET(qwAddSchedulerImpl(mgmt, sId, rwType, sch));
|
||||
QW_ERR_RET(qwAddSchedulerImpl(mgmt, sId, rwType));
|
||||
|
||||
nOpt = QW_NOT_EXIST_RET_ERR;
|
||||
|
||||
|
@ -402,6 +432,9 @@ int32_t qwKillTaskHandle(QW_FPARAMS_DEF, SQWTaskCtx *ctx) {
|
|||
|
||||
|
||||
void qwFreeTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx) {
|
||||
rpcReleaseHandle(ctx->connInfo.handle, TAOS_CONN_SERVER);
|
||||
ctx->connInfo.handle = NULL;
|
||||
|
||||
qwFreeTaskHandle(QW_FPARAMS(), &ctx->taskHandle);
|
||||
|
||||
if (ctx->sinkHandle) {
|
||||
|
@ -577,6 +610,9 @@ int32_t qwExecTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *queryEnd) {
|
|||
int32_t qwGenerateSchHbRsp(SQWorkerMgmt *mgmt, SQWSchStatus *sch, SQWHbInfo *hbInfo) {
|
||||
int32_t taskNum = 0;
|
||||
|
||||
hbInfo->connInfo = sch->hbConnInfo;
|
||||
hbInfo->rsp.epId = sch->hbEpId;
|
||||
|
||||
QW_LOCK(QW_READ, &sch->tasksLock);
|
||||
|
||||
taskNum = taosHashGetSize(sch->tasksHash);
|
||||
|
@ -588,9 +624,6 @@ int32_t qwGenerateSchHbRsp(SQWorkerMgmt *mgmt, SQWSchStatus *sch, SQWHbInfo *hbI
|
|||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
hbInfo->connection = sch->hbConnection;
|
||||
hbInfo->rsp.seqId = -1;
|
||||
|
||||
void *key = NULL;
|
||||
size_t keyLen = 0;
|
||||
int32_t i = 0;
|
||||
|
@ -694,8 +727,8 @@ int32_t qwGetResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void
|
|||
int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *input, SQWPhaseOutput *output) {
|
||||
int32_t code = 0;
|
||||
SQWTaskCtx *ctx = NULL;
|
||||
void *dropConnection = NULL;
|
||||
void *cancelConnection = NULL;
|
||||
SQWConnInfo *dropConnection = NULL;
|
||||
SQWConnInfo *cancelConnection = NULL;
|
||||
|
||||
QW_TASK_DLOG("start to handle event at phase %s", qwPhaseStr(phase));
|
||||
|
||||
|
@ -727,9 +760,13 @@ int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inpu
|
|||
}
|
||||
|
||||
if (QW_IS_EVENT_RECEIVED(ctx, QW_EVENT_DROP)) {
|
||||
dropConnection = &ctx->connInfo;
|
||||
QW_ERR_JRET(qwDropTask(QW_FPARAMS()));
|
||||
dropConnection = NULL;
|
||||
|
||||
qwBuildAndSendDropRsp(&ctx->connInfo, code);
|
||||
QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", ctx->connInfo.handle, code, tstrerror(code));
|
||||
|
||||
dropConnection = ctx->dropConnection;
|
||||
QW_ERR_JRET(TSDB_CODE_QRY_TASK_DROPPED);
|
||||
break;
|
||||
}
|
||||
|
@ -761,9 +798,13 @@ int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inpu
|
|||
}
|
||||
|
||||
if (QW_IS_EVENT_RECEIVED(ctx, QW_EVENT_DROP)) {
|
||||
dropConnection = &ctx->connInfo;
|
||||
QW_ERR_JRET(qwDropTask(QW_FPARAMS()));
|
||||
dropConnection = NULL;
|
||||
|
||||
qwBuildAndSendDropRsp(&ctx->connInfo, code);
|
||||
QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", ctx->connInfo.handle, code, tstrerror(code));
|
||||
|
||||
dropConnection = ctx->dropConnection;
|
||||
QW_ERR_JRET(TSDB_CODE_QRY_TASK_DROPPED);
|
||||
}
|
||||
|
||||
|
@ -790,12 +831,12 @@ _return:
|
|||
|
||||
if (dropConnection) {
|
||||
qwBuildAndSendDropRsp(dropConnection, code);
|
||||
QW_TASK_DLOG("drop msg rsped, code:%x - %s", code, tstrerror(code));
|
||||
QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", dropConnection->handle, code, tstrerror(code));
|
||||
}
|
||||
|
||||
if (cancelConnection) {
|
||||
qwBuildAndSendCancelRsp(cancelConnection, code);
|
||||
QW_TASK_DLOG("cancel msg rsped, code:%x - %s", code, tstrerror(code));
|
||||
QW_TASK_DLOG("cancel rsp send, handle:%p, code:%x - %s", cancelConnection->handle, code, tstrerror(code));
|
||||
}
|
||||
|
||||
QW_TASK_DLOG("end to handle event at phase %s, code:%x - %s", qwPhaseStr(phase), code, tstrerror(code));
|
||||
|
@ -807,9 +848,8 @@ _return:
|
|||
int32_t qwHandlePostPhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *input, SQWPhaseOutput *output) {
|
||||
int32_t code = 0;
|
||||
SQWTaskCtx *ctx = NULL;
|
||||
void *readyConnection = NULL;
|
||||
void *dropConnection = NULL;
|
||||
void *cancelConnection = NULL;
|
||||
SQWConnInfo connInfo = {0};
|
||||
SQWConnInfo *readyConnection = NULL;
|
||||
|
||||
QW_TASK_DLOG("start to handle event at phase %s", qwPhaseStr(phase));
|
||||
|
||||
|
@ -827,10 +867,17 @@ int32_t qwHandlePostPhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inp
|
|||
ctx->emptyRes = true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (QW_IS_EVENT_RECEIVED(ctx, QW_EVENT_READY)) {
|
||||
readyConnection = ctx->readyConnection;
|
||||
readyConnection = &ctx->connInfo;
|
||||
QW_SET_EVENT_PROCESSED(ctx, QW_EVENT_READY);
|
||||
}
|
||||
#else
|
||||
connInfo.handle = ctx->connInfo.handle;
|
||||
readyConnection = &connInfo;
|
||||
|
||||
QW_SET_EVENT_PROCESSED(ctx, QW_EVENT_READY);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (QW_IS_EVENT_RECEIVED(ctx, QW_EVENT_DROP)) {
|
||||
|
@ -839,9 +886,10 @@ int32_t qwHandlePostPhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *inp
|
|||
QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
QW_ERR_JRET(qwDropTask(QW_FPARAMS()));
|
||||
qwBuildAndSendDropRsp(&ctx->connInfo, code);
|
||||
QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", ctx->connInfo.handle, code, tstrerror(code));
|
||||
|
||||
dropConnection = ctx->dropConnection;
|
||||
QW_ERR_JRET(qwDropTask(QW_FPARAMS()));
|
||||
QW_ERR_JRET(TSDB_CODE_QRY_TASK_DROPPED);
|
||||
}
|
||||
|
||||
|
@ -871,17 +919,7 @@ _return:
|
|||
|
||||
if (readyConnection) {
|
||||
qwBuildAndSendReadyRsp(readyConnection, code);
|
||||
QW_TASK_DLOG("ready msg rsped, code:%x - %s", code, tstrerror(code));
|
||||
}
|
||||
|
||||
if (dropConnection) {
|
||||
qwBuildAndSendDropRsp(dropConnection, code);
|
||||
QW_TASK_DLOG("drop msg rsped, code:%x - %s", code, tstrerror(code));
|
||||
}
|
||||
|
||||
if (cancelConnection) {
|
||||
qwBuildAndSendCancelRsp(cancelConnection, code);
|
||||
QW_TASK_DLOG("cancel msg rsped, code:%x - %s", code, tstrerror(code));
|
||||
QW_TASK_DLOG("ready msg rsped, handle:%p, code:%x - %s", readyConnection->handle, code, tstrerror(code));
|
||||
}
|
||||
|
||||
if (code) {
|
||||
|
@ -893,23 +931,28 @@ _return:
|
|||
QW_RET(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, int8_t taskType) {
|
||||
int32_t code = 0;
|
||||
bool queryRsped = false;
|
||||
bool needStop = false;
|
||||
struct SSubplan *plan = NULL;
|
||||
SQWPhaseInput input = {0};
|
||||
qTaskInfo_t pTaskInfo = NULL;
|
||||
DataSinkHandle sinkHandle = NULL;
|
||||
SQWTaskCtx *ctx = NULL;
|
||||
|
||||
QW_ERR_JRET(qwRegisterBrokenLinkArg(QW_FPARAMS(), &qwMsg->connInfo));
|
||||
|
||||
QW_ERR_JRET(qwHandlePrePhaseEvents(QW_FPARAMS(), QW_PHASE_PRE_QUERY, &input, NULL));
|
||||
|
||||
QW_ERR_JRET(qwGetTaskCtx(QW_FPARAMS(), &ctx));
|
||||
|
||||
atomic_store_8(&ctx->taskType, taskType);
|
||||
|
||||
atomic_store_ptr(&ctx->connInfo.handle, qwMsg->connInfo.handle);
|
||||
atomic_store_ptr(&ctx->connInfo.ahandle, qwMsg->connInfo.ahandle);
|
||||
|
||||
QW_TASK_DLOGL("subplan json string, len:%d, %s", qwMsg->msgLen, qwMsg->msg);
|
||||
|
||||
code = qStringToSubplan(qwMsg->msg, &plan);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
QW_TASK_ELOG("task string to subplan failed, code:%x - %s", code, tstrerror(code));
|
||||
|
@ -927,8 +970,8 @@ int32_t qwProcessQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg, int8_t taskType) {
|
|||
QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
QW_ERR_JRET(qwBuildAndSendQueryRsp(qwMsg->connection, code));
|
||||
QW_TASK_DLOG("query msg rsped, code:%x - %s", code, tstrerror(code));
|
||||
QW_ERR_JRET(qwBuildAndSendQueryRsp(&qwMsg->connInfo, code));
|
||||
QW_TASK_DLOG("query msg rsped, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code));
|
||||
|
||||
queryRsped = true;
|
||||
|
||||
|
@ -945,11 +988,11 @@ _return:
|
|||
code = qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_QUERY, &input, NULL);
|
||||
|
||||
if (!queryRsped) {
|
||||
qwBuildAndSendQueryRsp(qwMsg->connection, code);
|
||||
QW_TASK_DLOG("query msg rsped, code:%x - %s", code, tstrerror(code));
|
||||
qwBuildAndSendQueryRsp(&qwMsg->connInfo, code);
|
||||
QW_TASK_DLOG("query msg rsped, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code));
|
||||
}
|
||||
|
||||
QW_RET(code);
|
||||
QW_RET(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t qwProcessReady(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
||||
|
@ -968,8 +1011,9 @@ int32_t qwProcessReady(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
}
|
||||
|
||||
if (ctx->phase == QW_PHASE_PRE_QUERY) {
|
||||
ctx->connInfo.handle == qwMsg->connInfo.handle;
|
||||
ctx->connInfo.ahandle = qwMsg->connInfo.ahandle;
|
||||
QW_SET_EVENT_RECEIVED(ctx, QW_EVENT_READY);
|
||||
ctx->readyConnection = qwMsg->connection;
|
||||
needRsp = false;
|
||||
QW_TASK_DLOG_E("ready msg will not rsp now");
|
||||
goto _return;
|
||||
|
@ -1007,11 +1051,11 @@ _return:
|
|||
}
|
||||
|
||||
if (needRsp) {
|
||||
qwBuildAndSendReadyRsp(qwMsg->connection, code);
|
||||
QW_TASK_DLOG("ready msg rsped, code:%x - %s", code, tstrerror(code));
|
||||
qwBuildAndSendReadyRsp(&qwMsg->connInfo, code);
|
||||
QW_TASK_DLOG("ready msg rsped, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code));
|
||||
}
|
||||
|
||||
QW_RET(code);
|
||||
QW_RET(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1048,10 +1092,11 @@ int32_t qwProcessCQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
qwBuildFetchRsp(rsp, &sOutput, dataLen, qComplete);
|
||||
atomic_store_8((int8_t*)&ctx->queryEnd, qComplete);
|
||||
|
||||
qwMsg->connInfo = ctx->connInfo;
|
||||
QW_SET_EVENT_PROCESSED(ctx, QW_EVENT_FETCH);
|
||||
|
||||
qwBuildAndSendFetchRsp(qwMsg->connection, rsp, dataLen, code);
|
||||
QW_TASK_DLOG("fetch msg rsped, code:%x, dataLen:%d", code, dataLen);
|
||||
qwBuildAndSendFetchRsp(&qwMsg->connInfo, rsp, dataLen, code);
|
||||
QW_TASK_DLOG("fetch rsp send, handle:%p, code:%x - %s, dataLen:%d", qwMsg->connInfo.handle, code, tstrerror(code), dataLen);
|
||||
} else {
|
||||
atomic_store_8((int8_t*)&ctx->queryContinue, 1);
|
||||
}
|
||||
|
@ -1067,8 +1112,10 @@ _return:
|
|||
QW_SET_EVENT_PROCESSED(ctx, QW_EVENT_FETCH);
|
||||
qwFreeFetchRsp(rsp);
|
||||
rsp = NULL;
|
||||
qwBuildAndSendFetchRsp(qwMsg->connection, rsp, 0, code);
|
||||
QW_TASK_DLOG("fetch msg rsped, code:%x - %s", code, tstrerror(code));
|
||||
|
||||
qwMsg->connInfo = ctx->connInfo;
|
||||
qwBuildAndSendFetchRsp(&qwMsg->connInfo, rsp, 0, code);
|
||||
QW_TASK_DLOG("fetch rsp send, handle:%p, code:%x - %s, dataLen:%d", qwMsg->connInfo.handle, code, tstrerror(code), 0);
|
||||
}
|
||||
|
||||
QW_LOCK(QW_WRITE, &ctx->lock);
|
||||
|
@ -1082,7 +1129,9 @@ _return:
|
|||
} while (true);
|
||||
|
||||
input.code = code;
|
||||
QW_RET(qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_CQUERY, &input, NULL));
|
||||
qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_CQUERY, &input, NULL);
|
||||
|
||||
QW_RET(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1102,6 +1151,9 @@ int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
QW_ERR_JRET(qwGetResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput));
|
||||
|
||||
if (NULL == rsp) {
|
||||
atomic_store_ptr(&ctx->connInfo.handle, qwMsg->connInfo.handle);
|
||||
atomic_store_ptr(&ctx->connInfo.ahandle, qwMsg->connInfo.ahandle);
|
||||
|
||||
QW_SET_EVENT_RECEIVED(ctx, QW_EVENT_FETCH);
|
||||
} else {
|
||||
bool qComplete = (DS_BUF_EMPTY == sOutput.bufStatus && sOutput.queryEnd);
|
||||
|
@ -1123,7 +1175,7 @@ int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
|
||||
atomic_store_8((int8_t*)&ctx->queryInQueue, 1);
|
||||
|
||||
QW_ERR_JRET(qwBuildAndSendCQueryMsg(QW_FPARAMS(), qwMsg->connection));
|
||||
QW_ERR_JRET(qwBuildAndSendCQueryMsg(QW_FPARAMS(), &qwMsg->connInfo));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1143,17 +1195,17 @@ _return:
|
|||
}
|
||||
|
||||
if (code || rsp) {
|
||||
qwBuildAndSendFetchRsp(qwMsg->connection, rsp, dataLen, code);
|
||||
QW_TASK_DLOG("fetch msg rsped, code:%x, dataLen:%d", code, dataLen);
|
||||
qwBuildAndSendFetchRsp(&qwMsg->connInfo, rsp, dataLen, code);
|
||||
QW_TASK_DLOG("fetch rsp send, handle:%p, code:%x - %s, dataLen:%d", qwMsg->connInfo.handle, code, tstrerror(code), dataLen);
|
||||
}
|
||||
|
||||
QW_RET(code);
|
||||
QW_RET(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
||||
int32_t code = 0;
|
||||
bool needRsp = false;
|
||||
bool rsped = false;
|
||||
SQWTaskCtx *ctx = NULL;
|
||||
bool locked = false;
|
||||
|
||||
|
@ -1174,14 +1226,18 @@ int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
QW_ERR_JRET(qwKillTaskHandle(QW_FPARAMS(), ctx));
|
||||
qwUpdateTaskStatus(QW_FPARAMS(), JOB_TASK_STATUS_DROPPING);
|
||||
} else if (ctx->phase > 0) {
|
||||
qwBuildAndSendDropRsp(&qwMsg->connInfo, code);
|
||||
QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code));
|
||||
|
||||
QW_ERR_JRET(qwDropTask(QW_FPARAMS()));
|
||||
needRsp = true;
|
||||
rsped = true;
|
||||
} else {
|
||||
// task not started
|
||||
}
|
||||
|
||||
if (!needRsp) {
|
||||
ctx->dropConnection = qwMsg->connection;
|
||||
if (!rsped) {
|
||||
ctx->connInfo.handle = qwMsg->connInfo.handle;
|
||||
ctx->connInfo.ahandle = qwMsg->connInfo.ahandle;
|
||||
|
||||
QW_SET_EVENT_RECEIVED(ctx, QW_EVENT_DROP);
|
||||
}
|
||||
|
@ -1204,13 +1260,12 @@ _return:
|
|||
qwReleaseTaskCtx(mgmt, ctx);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS != code || needRsp) {
|
||||
QW_ERR_RET(qwBuildAndSendDropRsp(qwMsg->connection, code));
|
||||
|
||||
QW_TASK_DLOG("drop msg rsped, code:%x", code);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
qwBuildAndSendDropRsp(&qwMsg->connInfo, code);
|
||||
QW_TASK_DLOG("drop rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code));
|
||||
}
|
||||
|
||||
QW_RET(code);
|
||||
QW_RET(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
int32_t qwProcessHb(SQWorkerMgmt *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req) {
|
||||
|
@ -1218,38 +1273,46 @@ int32_t qwProcessHb(SQWorkerMgmt *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req) {
|
|||
SSchedulerHbRsp rsp = {0};
|
||||
SQWSchStatus *sch = NULL;
|
||||
uint64_t seqId = 0;
|
||||
void *origHandle = NULL;
|
||||
|
||||
memcpy(&rsp.epId, &req->epId, sizeof(req->epId));
|
||||
|
||||
QW_ERR_JRET(qwAcquireAddScheduler(mgmt, req->sId, QW_READ, &sch));
|
||||
|
||||
atomic_store_ptr(&sch->hbConnection, qwMsg->connection);
|
||||
++sch->hbSeqId;
|
||||
QW_LOCK(QW_WRITE, &sch->hbConnLock);
|
||||
|
||||
rsp.seqId = sch->hbSeqId;
|
||||
if (sch->hbConnInfo.handle) {
|
||||
rpcReleaseHandle(sch->hbConnInfo.handle, TAOS_CONN_SERVER);
|
||||
}
|
||||
|
||||
QW_DLOG("hb connection updated, seqId:%" PRIx64 ", sId:%" PRIx64 ", nodeId:%d, fqdn:%s, port:%d, connection:%p",
|
||||
sch->hbSeqId, req->sId, req->epId.nodeId, req->epId.ep.fqdn, req->epId.ep.port, qwMsg->connection);
|
||||
memcpy(&sch->hbConnInfo, &qwMsg->connInfo, sizeof(qwMsg->connInfo));
|
||||
memcpy(&sch->hbEpId, &req->epId, sizeof(req->epId));
|
||||
|
||||
QW_UNLOCK(QW_WRITE, &sch->hbConnLock);
|
||||
|
||||
QW_DLOG("hb connection updated, sId:%" PRIx64 ", nodeId:%d, fqdn:%s, port:%d, handle:%p, ahandle:%p",
|
||||
req->sId, req->epId.nodeId, req->epId.ep.fqdn, req->epId.ep.port, qwMsg->connInfo.handle, qwMsg->connInfo.ahandle);
|
||||
|
||||
qwReleaseScheduler(QW_READ, mgmt);
|
||||
|
||||
_return:
|
||||
|
||||
qwBuildAndSendHbRsp(qwMsg->connection, &rsp, code);
|
||||
qwBuildAndSendHbRsp(&qwMsg->connInfo, &rsp, code);
|
||||
QW_DLOG("hb rsp send, handle:%p, code:%x - %s", qwMsg->connInfo.handle, code, tstrerror(code));
|
||||
|
||||
QW_RET(code);
|
||||
QW_RET(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
void qwProcessHbTimerEvent(void *param, void *tmrId) {
|
||||
return;
|
||||
|
||||
SQWorkerMgmt *mgmt = (SQWorkerMgmt *)param;
|
||||
SQWSchStatus *sch = NULL;
|
||||
int32_t taskNum = 0;
|
||||
SQWHbInfo *rspList = NULL;
|
||||
int32_t code = 0;
|
||||
|
||||
qwDbgDumpMgmtInfo(mgmt);
|
||||
|
||||
QW_LOCK(QW_READ, &mgmt->schLock);
|
||||
|
||||
int32_t schNum = taosHashGetSize(mgmt->schHash);
|
||||
|
@ -1288,8 +1351,8 @@ _return:
|
|||
QW_UNLOCK(QW_READ, &mgmt->schLock);
|
||||
|
||||
for (int32_t j = 0; j < i; ++j) {
|
||||
QW_DLOG("hb on connection %p, taskNum:%d", rspList[j].connection, (rspList[j].rsp.taskStatus ? (int32_t)taosArrayGetSize(rspList[j].rsp.taskStatus) : 0));
|
||||
qwBuildAndSendHbRsp(rspList[j].connection, &rspList[j].rsp, code);
|
||||
qwBuildAndSendHbRsp(&rspList[j].connInfo, &rspList[j].rsp, code);
|
||||
QW_DLOG("hb rsp send, handle:%p, code:%x - %s, taskNum:%d", rspList[j].connInfo.handle, code, tstrerror(code), (rspList[j].rsp.taskStatus ? (int32_t)taosArrayGetSize(rspList[j].rsp.taskStatus) : 0));
|
||||
tFreeSSchedulerHbRsp(&rspList[j].rsp);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,8 @@ int32_t qwMallocFetchRsp(int32_t length, SRetrieveTableRsp **rsp) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void qwBuildFetchRsp(void *msg, SOutputData *input, int32_t len, bool qComplete) {
|
||||
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)msg;
|
||||
|
||||
|
@ -44,8 +46,7 @@ void qwFreeFetchRsp(void *msg) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t qwBuildAndSendQueryRsp(void *connection, int32_t code) {
|
||||
SRpcMsg *pMsg = (SRpcMsg *)connection;
|
||||
int32_t qwBuildAndSendQueryRsp(SQWConnInfo *pConn, int32_t code) {
|
||||
SQueryTableRsp rsp = {.code = code};
|
||||
|
||||
int32_t contLen = tSerializeSQueryTableRsp(NULL, 0, &rsp);
|
||||
|
@ -54,8 +55,8 @@ int32_t qwBuildAndSendQueryRsp(void *connection, int32_t code) {
|
|||
|
||||
SRpcMsg rpcRsp = {
|
||||
.msgType = TDMT_VND_QUERY_RSP,
|
||||
.handle = pMsg->handle,
|
||||
.ahandle = pMsg->ahandle,
|
||||
.handle = pConn->handle,
|
||||
.ahandle = pConn->ahandle,
|
||||
.pCont = msg,
|
||||
.contLen = contLen,
|
||||
.code = code,
|
||||
|
@ -66,15 +67,14 @@ int32_t qwBuildAndSendQueryRsp(void *connection, int32_t code) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwBuildAndSendReadyRsp(void *connection, int32_t code) {
|
||||
SRpcMsg *pMsg = (SRpcMsg *)connection;
|
||||
int32_t qwBuildAndSendReadyRsp(SQWConnInfo *pConn, int32_t code) {
|
||||
SResReadyRsp *pRsp = (SResReadyRsp *)rpcMallocCont(sizeof(SResReadyRsp));
|
||||
pRsp->code = code;
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
.msgType = TDMT_VND_RES_READY_RSP,
|
||||
.handle = pMsg->handle,
|
||||
.ahandle = pMsg->ahandle,
|
||||
.handle = pConn->handle,
|
||||
.ahandle = NULL,
|
||||
.pCont = pRsp,
|
||||
.contLen = sizeof(*pRsp),
|
||||
.code = code,
|
||||
|
@ -85,15 +85,15 @@ int32_t qwBuildAndSendReadyRsp(void *connection, int32_t code) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwBuildAndSendHbRsp(SRpcMsg *pMsg, SSchedulerHbRsp *pStatus, int32_t code) {
|
||||
int32_t qwBuildAndSendHbRsp(SQWConnInfo *pConn, SSchedulerHbRsp *pStatus, int32_t code) {
|
||||
int32_t contLen = tSerializeSSchedulerHbRsp(NULL, 0, pStatus);
|
||||
void *pRsp = rpcMallocCont(contLen);
|
||||
tSerializeSSchedulerHbRsp(pRsp, contLen, pStatus);
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
.msgType = TDMT_VND_QUERY_HEARTBEAT_RSP,
|
||||
.handle = pMsg->handle,
|
||||
.ahandle = pMsg->ahandle,
|
||||
.handle = pConn->handle,
|
||||
.ahandle = pConn->ahandle,
|
||||
.pCont = pRsp,
|
||||
.contLen = contLen,
|
||||
.code = code,
|
||||
|
@ -104,9 +104,7 @@ int32_t qwBuildAndSendHbRsp(SRpcMsg *pMsg, SSchedulerHbRsp *pStatus, int32_t cod
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwBuildAndSendFetchRsp(void *connection, SRetrieveTableRsp *pRsp, int32_t dataLength, int32_t code) {
|
||||
SRpcMsg *pMsg = (SRpcMsg *)connection;
|
||||
|
||||
int32_t qwBuildAndSendFetchRsp(SQWConnInfo *pConn, SRetrieveTableRsp *pRsp, int32_t dataLength, int32_t code) {
|
||||
if (NULL == pRsp) {
|
||||
pRsp = (SRetrieveTableRsp *)rpcMallocCont(sizeof(SRetrieveTableRsp));
|
||||
memset(pRsp, 0, sizeof(SRetrieveTableRsp));
|
||||
|
@ -115,8 +113,8 @@ int32_t qwBuildAndSendFetchRsp(void *connection, SRetrieveTableRsp *pRsp, int32_
|
|||
|
||||
SRpcMsg rpcRsp = {
|
||||
.msgType = TDMT_VND_FETCH_RSP,
|
||||
.handle = pMsg->handle,
|
||||
.ahandle = pMsg->ahandle,
|
||||
.handle = pConn->handle,
|
||||
.ahandle = pConn->ahandle,
|
||||
.pCont = pRsp,
|
||||
.contLen = sizeof(*pRsp) + dataLength,
|
||||
.code = code,
|
||||
|
@ -127,14 +125,14 @@ int32_t qwBuildAndSendFetchRsp(void *connection, SRetrieveTableRsp *pRsp, int32_
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwBuildAndSendCancelRsp(SRpcMsg *pMsg, int32_t code) {
|
||||
int32_t qwBuildAndSendCancelRsp(SQWConnInfo *pConn, int32_t code) {
|
||||
STaskCancelRsp *pRsp = (STaskCancelRsp *)rpcMallocCont(sizeof(STaskCancelRsp));
|
||||
pRsp->code = code;
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
.msgType = TDMT_VND_CANCEL_TASK_RSP,
|
||||
.handle = pMsg->handle,
|
||||
.ahandle = pMsg->ahandle,
|
||||
.handle = pConn->handle,
|
||||
.ahandle = pConn->ahandle,
|
||||
.pCont = pRsp,
|
||||
.contLen = sizeof(*pRsp),
|
||||
.code = code,
|
||||
|
@ -144,15 +142,14 @@ int32_t qwBuildAndSendCancelRsp(SRpcMsg *pMsg, int32_t code) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwBuildAndSendDropRsp(void *connection, int32_t code) {
|
||||
SRpcMsg *pMsg = (SRpcMsg *)connection;
|
||||
int32_t qwBuildAndSendDropRsp(SQWConnInfo *pConn, int32_t code) {
|
||||
STaskDropRsp *pRsp = (STaskDropRsp *)rpcMallocCont(sizeof(STaskDropRsp));
|
||||
pRsp->code = code;
|
||||
|
||||
SRpcMsg rpcRsp = {
|
||||
.msgType = TDMT_VND_DROP_TASK_RSP,
|
||||
.handle = pMsg->handle,
|
||||
.ahandle = pMsg->ahandle,
|
||||
.handle = pConn->handle,
|
||||
.ahandle = pConn->ahandle,
|
||||
.pCont = pRsp,
|
||||
.contLen = sizeof(*pRsp),
|
||||
.code = code,
|
||||
|
@ -234,8 +231,7 @@ int32_t qwBuildAndSendShowFetchRsp(SRpcMsg *pMsg, SVShowTablesFetchReq* pFetchRe
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwBuildAndSendCQueryMsg(QW_FPARAMS_DEF, void *connection) {
|
||||
SRpcMsg *pMsg = (SRpcMsg *)connection;
|
||||
int32_t qwBuildAndSendCQueryMsg(QW_FPARAMS_DEF, SQWConnInfo *pConn) {
|
||||
SQueryContinueReq * req = (SQueryContinueReq *)rpcMallocCont(sizeof(SQueryContinueReq));
|
||||
if (NULL == req) {
|
||||
QW_SCH_TASK_ELOG("rpcMallocCont %d failed", (int32_t)sizeof(SQueryContinueReq));
|
||||
|
@ -248,8 +244,8 @@ int32_t qwBuildAndSendCQueryMsg(QW_FPARAMS_DEF, void *connection) {
|
|||
req->taskId = tId;
|
||||
|
||||
SRpcMsg pNewMsg = {
|
||||
.handle = pMsg->handle,
|
||||
.ahandle = pMsg->ahandle,
|
||||
.handle = pConn->handle,
|
||||
.ahandle = pConn->ahandle,
|
||||
.msgType = TDMT_VND_QUERY_CONTINUE,
|
||||
.pCont = req,
|
||||
.contLen = sizeof(SQueryContinueReq),
|
||||
|
@ -268,6 +264,35 @@ int32_t qwBuildAndSendCQueryMsg(QW_FPARAMS_DEF, void *connection) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t qwRegisterBrokenLinkArg(QW_FPARAMS_DEF, SQWConnInfo *pConn) {
|
||||
STaskDropReq * req = (STaskDropReq *)rpcMallocCont(sizeof(STaskDropReq));
|
||||
if (NULL == req) {
|
||||
QW_SCH_TASK_ELOG("rpcMallocCont %d failed", (int32_t)sizeof(STaskDropReq));
|
||||
QW_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
req->header.vgId = htonl(mgmt->nodeId);
|
||||
req->sId = htobe64(sId);
|
||||
req->queryId = htobe64(qId);
|
||||
req->taskId = htobe64(tId);
|
||||
req->refId = htobe64(rId);
|
||||
|
||||
SRpcMsg pMsg = {
|
||||
.handle = pConn->handle,
|
||||
.ahandle = pConn->ahandle,
|
||||
.msgType = TDMT_VND_DROP_TASK,
|
||||
.pCont = req,
|
||||
.contLen = sizeof(STaskDropReq),
|
||||
.code = TSDB_CODE_RPC_NETWORK_UNAVAIL,
|
||||
};
|
||||
|
||||
rpcRegisterBrokenLinkArg(&pMsg);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
||||
if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) {
|
||||
QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
|
@ -294,10 +319,12 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
uint64_t tId = msg->taskId;
|
||||
int64_t rId = msg->refId;
|
||||
|
||||
SQWMsg qwMsg = {.node = node, .msg = msg->msg + msg->sqlLen, .msgLen = msg->phyLen, .connection = pMsg};
|
||||
SQWMsg qwMsg = {.node = node, .msg = msg->msg + msg->sqlLen, .msgLen = msg->phyLen};
|
||||
qwMsg.connInfo.handle = pMsg->handle;
|
||||
qwMsg.connInfo.ahandle = pMsg->ahandle;
|
||||
|
||||
char* sql = strndup(msg->msg, msg->sqlLen);
|
||||
QW_SCH_TASK_DLOG("processQuery start, node:%p, sql:%s", node, sql);
|
||||
QW_SCH_TASK_DLOG("processQuery start, node:%p, handle:%p, sql:%s", node, pMsg->handle, sql);
|
||||
taosMemoryFreeClear(sql);
|
||||
|
||||
QW_ERR_RET(qwProcessQuery(QW_FPARAMS(), &qwMsg, msg->taskType));
|
||||
|
@ -326,9 +353,11 @@ int32_t qWorkerProcessCQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
uint64_t tId = msg->taskId;
|
||||
int64_t rId = 0;
|
||||
|
||||
SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .connection = pMsg};
|
||||
SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0};
|
||||
qwMsg.connInfo.handle = pMsg->handle;
|
||||
qwMsg.connInfo.ahandle = pMsg->ahandle;
|
||||
|
||||
QW_SCH_TASK_DLOG("processCQuery start, node:%p", node);
|
||||
QW_SCH_TASK_DLOG("processCQuery start, node:%p, handle:%p", node, pMsg->handle);
|
||||
|
||||
QW_ERR_RET(qwProcessCQuery(QW_FPARAMS(), &qwMsg));
|
||||
|
||||
|
@ -358,9 +387,11 @@ int32_t qWorkerProcessReadyMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg){
|
|||
uint64_t tId = msg->taskId;
|
||||
int64_t rId = 0;
|
||||
|
||||
SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .connection = pMsg};
|
||||
SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0};
|
||||
qwMsg.connInfo.handle = pMsg->handle;
|
||||
qwMsg.connInfo.ahandle = pMsg->ahandle;
|
||||
|
||||
QW_SCH_TASK_DLOG("processReady start, node:%p", node);
|
||||
QW_SCH_TASK_DLOG("processReady start, node:%p, handle:%p", node, pMsg->handle);
|
||||
|
||||
QW_ERR_RET(qwProcessReady(QW_FPARAMS(), &qwMsg));
|
||||
|
||||
|
@ -418,9 +449,11 @@ int32_t qWorkerProcessFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
uint64_t tId = msg->taskId;
|
||||
int64_t rId = 0;
|
||||
|
||||
SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .connection = pMsg};
|
||||
SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0};
|
||||
qwMsg.connInfo.handle = pMsg->handle;
|
||||
qwMsg.connInfo.ahandle = pMsg->ahandle;
|
||||
|
||||
QW_SCH_TASK_DLOG("processFetch start, node:%p", node);
|
||||
QW_SCH_TASK_DLOG("processFetch start, node:%p, handle:%p", node, pMsg->handle);
|
||||
|
||||
QW_ERR_RET(qwProcessFetch(QW_FPARAMS(), &qwMsg));
|
||||
|
||||
|
@ -439,6 +472,7 @@ int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||
}
|
||||
|
||||
SQWorkerMgmt *mgmt = (SQWorkerMgmt *)qWorkerMgmt;
|
||||
int32_t code = 0;
|
||||
STaskCancelReq *msg = pMsg->pCont;
|
||||
if (NULL == msg || pMsg->contLen < sizeof(*msg)) {
|
||||
|
@ -451,11 +485,21 @@ int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
msg->taskId = be64toh(msg->taskId);
|
||||
msg->refId = be64toh(msg->refId);
|
||||
|
||||
uint64_t sId = msg->sId;
|
||||
uint64_t qId = msg->queryId;
|
||||
uint64_t tId = msg->taskId;
|
||||
int64_t rId = msg->refId;
|
||||
|
||||
SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0};
|
||||
qwMsg.connInfo.handle = pMsg->handle;
|
||||
qwMsg.connInfo.ahandle = pMsg->ahandle;
|
||||
|
||||
//QW_ERR_JRET(qwCancelTask(qWorkerMgmt, msg->sId, msg->queryId, msg->taskId));
|
||||
|
||||
_return:
|
||||
|
||||
QW_ERR_RET(qwBuildAndSendCancelRsp(pMsg, code));
|
||||
QW_ERR_RET(qwBuildAndSendCancelRsp(&qwMsg.connInfo, code));
|
||||
QW_SCH_TASK_DLOG("cancel rsp send, handle:%p, code:%x - %s", qwMsg.connInfo.handle, code, tstrerror(code));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -484,9 +528,15 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
uint64_t tId = msg->taskId;
|
||||
int64_t rId = msg->refId;
|
||||
|
||||
SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .connection = pMsg};
|
||||
SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0};
|
||||
qwMsg.connInfo.handle = pMsg->handle;
|
||||
qwMsg.connInfo.ahandle = pMsg->ahandle;
|
||||
|
||||
QW_SCH_TASK_DLOG("processDrop start, node:%p", node);
|
||||
if (TSDB_CODE_RPC_NETWORK_UNAVAIL == pMsg->code) {
|
||||
QW_SCH_TASK_DLOG("receive drop task due to network broken, error:%s", tstrerror(pMsg->code));
|
||||
}
|
||||
|
||||
QW_SCH_TASK_DLOG("processDrop start, node:%p, handle:%p", node, pMsg->handle);
|
||||
|
||||
QW_ERR_RET(qwProcessDrop(QW_FPARAMS(), &qwMsg));
|
||||
|
||||
|
@ -516,9 +566,11 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
uint64_t sId = req.sId;
|
||||
SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0, .connection = pMsg};
|
||||
SQWMsg qwMsg = {.node = node, .msg = NULL, .msgLen = 0};
|
||||
qwMsg.connInfo.handle = pMsg->handle;
|
||||
qwMsg.connInfo.ahandle = pMsg->ahandle;
|
||||
|
||||
QW_SCH_DLOG("processHb start, node:%p", node);
|
||||
QW_SCH_DLOG("processHb start, node:%p, handle:%p", node, pMsg->handle);
|
||||
|
||||
QW_ERR_RET(qwProcessHb(mgmt, &qwMsg, &req));
|
||||
|
||||
|
@ -535,7 +587,7 @@ int32_t qWorkerProcessShowMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
|||
|
||||
int32_t code = 0;
|
||||
SVShowTablesReq *pReq = pMsg->pCont;
|
||||
QW_ERR_RET(qwBuildAndSendShowRsp(pMsg, code));
|
||||
QW_RET(qwBuildAndSendShowRsp(pMsg, code));
|
||||
}
|
||||
|
||||
int32_t qWorkerProcessShowFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg) {
|
||||
|
@ -544,7 +596,7 @@ int32_t qWorkerProcessShowFetchMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg)
|
|||
}
|
||||
|
||||
SVShowTablesFetchReq *pFetchReq = pMsg->pCont;
|
||||
QW_ERR_RET(qwBuildAndSendShowFetchRsp(pMsg, pFetchReq));
|
||||
QW_RET(qwBuildAndSendShowFetchRsp(pMsg, pFetchReq));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -887,8 +887,8 @@ TEST(seqTest, normalCase) {
|
|||
code = qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc);
|
||||
ASSERT_EQ(code, 0);
|
||||
//code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc);
|
||||
//ASSERT_EQ(code, 0);
|
||||
|
||||
code = qWorkerProcessFetchMsg(mockPointer, mgmt, &fetchRpc);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
@ -985,12 +985,12 @@ TEST(seqTest, randCase) {
|
|||
qwtBuildQueryReqMsg(&queryRpc);
|
||||
code = qWorkerProcessQueryMsg(mockPointer, mgmt, &queryRpc);
|
||||
} else if (r >= maxr/5 && r < maxr * 2/5) {
|
||||
printf("Ready,%d\n", t++);
|
||||
qwtBuildReadyReqMsg(&readyMsg, &readyRpc);
|
||||
code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc);
|
||||
if (qwtTestEnableSleep) {
|
||||
taosUsleep(1);
|
||||
}
|
||||
//printf("Ready,%d\n", t++);
|
||||
//qwtBuildReadyReqMsg(&readyMsg, &readyRpc);
|
||||
//code = qWorkerProcessReadyMsg(mockPointer, mgmt, &readyRpc);
|
||||
//if (qwtTestEnableSleep) {
|
||||
// taosUsleep(1);
|
||||
//}
|
||||
} else if (r >= maxr * 2/5 && r < maxr* 3/5) {
|
||||
printf("Fetch,%d\n", t++);
|
||||
qwtBuildFetchReqMsg(&fetchMsg, &fetchRpc);
|
||||
|
@ -1054,7 +1054,7 @@ TEST(seqTest, multithreadRand) {
|
|||
|
||||
TdThread t1,t2,t3,t4,t5,t6;
|
||||
taosThreadCreate(&(t1), &thattr, queryThread, mgmt);
|
||||
taosThreadCreate(&(t2), &thattr, readyThread, NULL);
|
||||
//taosThreadCreate(&(t2), &thattr, readyThread, NULL);
|
||||
taosThreadCreate(&(t3), &thattr, fetchThread, NULL);
|
||||
taosThreadCreate(&(t4), &thattr, dropThread, NULL);
|
||||
taosThreadCreate(&(t5), &thattr, statusThread, NULL);
|
||||
|
|
|
@ -37,7 +37,6 @@ int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarParam*
|
|||
void* param, char* (*getSourceDataBlock)(void*, const char*, int32_t));
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -4,145 +4,536 @@
|
|||
static void assignBasicParaInfo(struct SScalarParam* dst, const struct SScalarParam* src) {
|
||||
dst->type = src->type;
|
||||
dst->bytes = src->bytes;
|
||||
dst->num = src->num;
|
||||
//dst->num = src->num;
|
||||
}
|
||||
|
||||
static void tceil(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) {
|
||||
assignBasicParaInfo(pOutput, pLeft);
|
||||
assert(numOfInput == 1);
|
||||
/** Math functions **/
|
||||
int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
assignBasicParaInfo(pOutput, pInput);
|
||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
switch (pLeft->bytes) {
|
||||
char *input = NULL, *output = NULL;
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
if (pInput->num == 1) {
|
||||
input = pInput->data;
|
||||
} else {
|
||||
input = pInput->data + i * pInput->bytes;
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (isNull(input, pInput->type)) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (pInput->type) {
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) pLeft->data;
|
||||
float* out = (float*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = ceilf(p[i]);
|
||||
}
|
||||
float v;
|
||||
GET_TYPED_DATA(v, float, pInput->type, input);
|
||||
float result;
|
||||
result = (v > 0) ? v : -v;
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) pLeft->data;
|
||||
double* out = (double*)pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = ceil(p[i]);
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes);
|
||||
}
|
||||
}
|
||||
|
||||
static void tfloor(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) {
|
||||
assignBasicParaInfo(pOutput, pLeft);
|
||||
assert(numOfInput == 1);
|
||||
|
||||
switch (pLeft->bytes) {
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) pLeft->data;
|
||||
float* out = (float*) pOutput->data;
|
||||
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = floorf(p[i]);
|
||||
}
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) pLeft->data;
|
||||
double* out = (double*) pOutput->data;
|
||||
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = floor(p[i]);
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes);
|
||||
}
|
||||
}
|
||||
|
||||
static void _tabs(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) {
|
||||
assignBasicParaInfo(pOutput, pLeft);
|
||||
assert(numOfInput == 1);
|
||||
|
||||
switch (pLeft->bytes) {
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) pLeft->data;
|
||||
float* out = (float*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
}
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) pLeft->data;
|
||||
double* out = (double*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
}
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
||||
double result;
|
||||
result = (v > 0) ? v : -v;
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_TINYINT: {
|
||||
int8_t* p = (int8_t*) pLeft->data;
|
||||
int8_t* out = (int8_t*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
}
|
||||
int8_t v;
|
||||
GET_TYPED_DATA(v, int8_t, pInput->type, input);
|
||||
int8_t result;
|
||||
result = (v > 0) ? v : -v;
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_SMALLINT: {
|
||||
int16_t* p = (int16_t*) pLeft->data;
|
||||
int16_t* out = (int16_t*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
}
|
||||
int16_t v;
|
||||
GET_TYPED_DATA(v, int16_t, pInput->type, input);
|
||||
int16_t result;
|
||||
result = (v > 0) ? v : -v;
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
int32_t* p = (int32_t*) pLeft->data;
|
||||
int32_t* out = (int32_t*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
}
|
||||
int32_t v;
|
||||
GET_TYPED_DATA(v, int32_t, pInput->type, input);
|
||||
int32_t result;
|
||||
result = (v > 0) ? v : -v;
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
int64_t* p = (int64_t*) pLeft->data;
|
||||
int64_t* out = (int64_t*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = (p[i] > 0)? p[i]:-p[i];
|
||||
int64_t v;
|
||||
GET_TYPED_DATA(v, int64_t, pInput->type, input);
|
||||
int64_t result;
|
||||
result = (v > 0) ? v : -v;
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
memcpy(output, input, pInput->bytes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void tround(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) {
|
||||
assignBasicParaInfo(pOutput, pLeft);
|
||||
assert(numOfInput == 1);
|
||||
int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum != 2 || !IS_NUMERIC_TYPE(pInput[0].type) || !IS_NUMERIC_TYPE(pInput[1].type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
switch (pLeft->bytes) {
|
||||
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
|
||||
char **input = NULL, *output = NULL;
|
||||
bool hasNullInput = false;
|
||||
input = taosMemoryCalloc(inputNum, sizeof(char *));
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
for (int32_t j = 0; j < inputNum; ++j) {
|
||||
if (pInput[j].num == 1) {
|
||||
input[j] = pInput[j].data;
|
||||
} else {
|
||||
input[j] = pInput[j].data + i * pInput[j].bytes;
|
||||
}
|
||||
if (isNull(input[j], pInput[j].type)) {
|
||||
hasNullInput = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (hasNullInput) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
double base;
|
||||
GET_TYPED_DATA(base, double, pInput[1].type, input[1]);
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput[0].type, input[0]);
|
||||
double result = log(v) / log(base);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
}
|
||||
|
||||
taosMemoryFree(input);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t powFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum != 2 || !IS_NUMERIC_TYPE(pInput[0].type) || !IS_NUMERIC_TYPE(pInput[1].type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
|
||||
char **input = NULL, *output = NULL;
|
||||
bool hasNullInput = false;
|
||||
input = taosMemoryCalloc(inputNum, sizeof(char *));
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
for (int32_t j = 0; j < inputNum; ++j) {
|
||||
if (pInput[j].num == 1) {
|
||||
input[j] = pInput[j].data;
|
||||
} else {
|
||||
input[j] = pInput[j].data + i * pInput[j].bytes;
|
||||
}
|
||||
if (isNull(input[j], pInput[j].type)) {
|
||||
hasNullInput = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (hasNullInput) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
double base;
|
||||
GET_TYPED_DATA(base, double, pInput[1].type, input[1]);
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput[0].type, input[0]);
|
||||
double result = pow(v, base);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
}
|
||||
|
||||
taosMemoryFree(input);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t sqrtFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
|
||||
char *input = NULL, *output = NULL;
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
if (pInput->num == 1) {
|
||||
input = pInput->data;
|
||||
} else {
|
||||
input = pInput->data + i * pInput->bytes;
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (isNull(input, pInput->type)) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
||||
double result = sqrt(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t sinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
|
||||
char *input = NULL, *output = NULL;
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
if (pInput->num == 1) {
|
||||
input = pInput->data;
|
||||
} else {
|
||||
input = pInput->data + i * pInput->bytes;
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (isNull(input, pInput->type)) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
||||
double result = sin(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t cosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
|
||||
char *input = NULL, *output = NULL;
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
if (pInput->num == 1) {
|
||||
input = pInput->data;
|
||||
} else {
|
||||
input = pInput->data + i * pInput->bytes;
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (isNull(input, pInput->type)) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
||||
double result = cos(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
|
||||
char *input = NULL, *output = NULL;
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
if (pInput->num == 1) {
|
||||
input = pInput->data;
|
||||
} else {
|
||||
input = pInput->data + i * pInput->bytes;
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (isNull(input, pInput->type)) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
||||
double result = tan(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t asinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
|
||||
char *input = NULL, *output = NULL;
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
if (pInput->num == 1) {
|
||||
input = pInput->data;
|
||||
} else {
|
||||
input = pInput->data + i * pInput->bytes;
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (isNull(input, pInput->type)) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
||||
double result = asin(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t acosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
|
||||
char *input = NULL, *output = NULL;
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
if (pInput->num == 1) {
|
||||
input = pInput->data;
|
||||
} else {
|
||||
input = pInput->data + i * pInput->bytes;
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (isNull(input, pInput->type)) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
||||
double result = acos(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t atanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
|
||||
char *input = NULL, *output = NULL;
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
if (pInput->num == 1) {
|
||||
input = pInput->data;
|
||||
} else {
|
||||
input = pInput->data + i * pInput->bytes;
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (isNull(input, pInput->type)) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
||||
double result = atan(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ceilFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
char *input = NULL, *output = NULL;
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
if (pInput->num == 1) {
|
||||
input = pInput->data;
|
||||
} else {
|
||||
input = pInput->data + i * pInput->bytes;
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (isNull(input, pInput->type)) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (pInput->type) {
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float* p = (float*) pLeft->data;
|
||||
float* out = (float*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = roundf(p[i]);
|
||||
}
|
||||
float v;
|
||||
GET_TYPED_DATA(v, float, pInput->type, input);
|
||||
float result = ceilf(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double* p = (double*) pLeft->data;
|
||||
double* out = (double*) pOutput->data;
|
||||
for (int32_t i = 0; i < pLeft->num; ++i) {
|
||||
out[i] = round(p[i]);
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
||||
double result = ceil(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
memcpy(output, input, pInput->bytes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t floorFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
assignBasicParaInfo(pOutput, pInput);
|
||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
char *input = NULL, *output = NULL;
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
if (pInput->num == 1) {
|
||||
input = pInput->data;
|
||||
} else {
|
||||
input = pInput->data + i * pInput->bytes;
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (isNull(input, pInput->type)) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (pInput->type) {
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float v;
|
||||
GET_TYPED_DATA(v, float, pInput->type, input);
|
||||
float result = floorf(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
||||
double result = floor(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
memcpy(output, input, pInput->bytes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t roundFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
assignBasicParaInfo(pOutput, pInput);
|
||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
char *input = NULL, *output = NULL;
|
||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
||||
if (pInput->num == 1) {
|
||||
input = pInput->data;
|
||||
} else {
|
||||
input = pInput->data + i * pInput->bytes;
|
||||
}
|
||||
output = pOutput->data + i * pOutput->bytes;
|
||||
|
||||
if (isNull(input, pInput->type)) {
|
||||
setNull(output, pOutput->type, pOutput->bytes);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (pInput->type) {
|
||||
case TSDB_DATA_TYPE_FLOAT: {
|
||||
float v;
|
||||
GET_TYPED_DATA(v, float, pInput->type, input);
|
||||
float result = roundf(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_DATA_TYPE_DOUBLE: {
|
||||
double v;
|
||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
||||
double result = round(v);
|
||||
SET_TYPED_DATA(output, pOutput->type, result);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
memcpy(output, input, pInput->bytes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void tlength(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) {
|
||||
|
@ -361,16 +752,16 @@ int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncPa
|
|||
#endif
|
||||
|
||||
|
||||
SScalarFunctionInfo scalarFunc[8] = {
|
||||
{"ceil", FUNCTION_TYPE_SCALAR, FUNCTION_CEIL, tceil},
|
||||
{"floor", FUNCTION_TYPE_SCALAR, FUNCTION_FLOOR, tfloor},
|
||||
{"abs", FUNCTION_TYPE_SCALAR, FUNCTION_ABS, _tabs},
|
||||
{"round", FUNCTION_TYPE_SCALAR, FUNCTION_ROUND, tround},
|
||||
{"length", FUNCTION_TYPE_SCALAR, FUNCTION_LENGTH, tlength},
|
||||
{"concat", FUNCTION_TYPE_SCALAR, FUNCTION_CONCAT, tconcat},
|
||||
{"ltrim", FUNCTION_TYPE_SCALAR, FUNCTION_LTRIM, tltrim},
|
||||
{"rtrim", FUNCTION_TYPE_SCALAR, FUNCTION_RTRIM, trtrim},
|
||||
};
|
||||
//SScalarFunctionInfo scalarFunc[8] = {
|
||||
// {"ceil", FUNCTION_TYPE_SCALAR, FUNCTION_CEIL, tceil},
|
||||
// {"floor", FUNCTION_TYPE_SCALAR, FUNCTION_FLOOR, tfloor},
|
||||
// {"abs", FUNCTION_TYPE_SCALAR, FUNCTION_ABS, _tabs},
|
||||
// {"round", FUNCTION_TYPE_SCALAR, FUNCTION_ROUND, tround},
|
||||
// {"length", FUNCTION_TYPE_SCALAR, FUNCTION_LENGTH, tlength},
|
||||
// {"concat", FUNCTION_TYPE_SCALAR, FUNCTION_CONCAT, tconcat},
|
||||
// {"ltrim", FUNCTION_TYPE_SCALAR, FUNCTION_LTRIM, tltrim},
|
||||
// {"rtrim", FUNCTION_TYPE_SCALAR, FUNCTION_RTRIM, trtrim},
|
||||
//};
|
||||
|
||||
void setScalarFunctionSupp(struct SScalarFunctionSupport* sas, SExprInfo *pExprInfo, SSDataBlock* pSDataBlock) {
|
||||
sas->numOfCols = (int32_t) pSDataBlock->info.numOfCols;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,6 +25,7 @@ extern "C" {
|
|||
#include "planner.h"
|
||||
#include "scheduler.h"
|
||||
#include "thash.h"
|
||||
#include "trpc.h"
|
||||
|
||||
#define SCHEDULE_DEFAULT_MAX_JOB_NUM 1000
|
||||
#define SCHEDULE_DEFAULT_MAX_TASK_NUM 1000
|
||||
|
@ -44,7 +45,7 @@ typedef struct SSchTrans {
|
|||
|
||||
typedef struct SSchHbTrans {
|
||||
SRWLatch lock;
|
||||
uint64_t seqId;
|
||||
SRpcCtx rpcCtx;
|
||||
SSchTrans trans;
|
||||
} SSchHbTrans;
|
||||
|
||||
|
@ -76,12 +77,23 @@ typedef struct SSchedulerMgmt {
|
|||
SHashObj *hbConnections;
|
||||
} SSchedulerMgmt;
|
||||
|
||||
typedef struct SSchCallbackParam {
|
||||
typedef struct SSchCallbackParamHeader {
|
||||
bool isHbParam;
|
||||
} SSchCallbackParamHeader;
|
||||
|
||||
typedef struct SSchTaskCallbackParam {
|
||||
SSchCallbackParamHeader head;
|
||||
uint64_t queryId;
|
||||
int64_t refId;
|
||||
uint64_t taskId;
|
||||
void *transport;
|
||||
} SSchCallbackParam;
|
||||
} SSchTaskCallbackParam;
|
||||
|
||||
typedef struct SSchHbCallbackParam {
|
||||
SSchCallbackParamHeader head;
|
||||
SQueryNodeEpId nodeEpId;
|
||||
void *transport;
|
||||
} SSchHbCallbackParam;
|
||||
|
||||
typedef struct SSchFlowControl {
|
||||
SRWLatch lock;
|
||||
|
@ -91,6 +103,11 @@ typedef struct SSchFlowControl {
|
|||
SArray *taskList; // Element is SSchTask*
|
||||
} SSchFlowControl;
|
||||
|
||||
typedef struct SSchNodeInfo {
|
||||
SQueryNodeAddr addr;
|
||||
void *handle;
|
||||
} SSchNodeInfo;
|
||||
|
||||
typedef struct SSchLevel {
|
||||
int32_t level;
|
||||
int8_t status;
|
||||
|
@ -116,7 +133,7 @@ typedef struct SSchTask {
|
|||
SQueryNodeAddr succeedAddr; // task executed success node address
|
||||
int8_t candidateIdx; // current try condidation index
|
||||
SArray *candidateAddrs; // condidate node addresses, element is SQueryNodeAddr
|
||||
SArray *execAddrs; // all tried node for current task, element is SQueryNodeAddr
|
||||
SArray *execNodes; // all tried node for current task, element is SSchNodeInfo
|
||||
SQueryProfileSummary summary; // task execution summary
|
||||
int32_t childReady; // child task ready number
|
||||
SArray *children; // the datasource tasks,from which to fetch the result, element is SQueryTask*
|
||||
|
@ -178,6 +195,8 @@ extern SSchedulerMgmt schMgmt;
|
|||
#define SCH_GET_TASK_STATUS(task) atomic_load_8(&(task)->status)
|
||||
#define SCH_GET_TASK_STATUS_STR(task) jobTaskStatusStr(SCH_GET_TASK_STATUS(task))
|
||||
|
||||
#define SCH_GET_TASK_HANDLE(_task) ((_task) ? (_task)->handle : NULL)
|
||||
#define SCH_SET_TASK_HANDLE(_task, _handle) ((_task)->handle = (_handle))
|
||||
|
||||
#define SCH_SET_JOB_STATUS(job, st) atomic_store_8(&(job)->status, st)
|
||||
#define SCH_GET_JOB_STATUS(job) atomic_load_8(&(job)->status)
|
||||
|
@ -205,6 +224,8 @@ extern SSchedulerMgmt schMgmt;
|
|||
qError("QID:0x%" PRIx64 ",TID:0x%" PRIx64 " " param, pJob->queryId, SCH_TASK_ID(pTask), __VA_ARGS__)
|
||||
#define SCH_TASK_DLOG(param, ...) \
|
||||
qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 " " param, pJob->queryId, SCH_TASK_ID(pTask), __VA_ARGS__)
|
||||
#define SCH_TASK_DLOGL(param, ...) \
|
||||
qDebugL("QID:0x%" PRIx64 ",TID:0x%" PRIx64 " " param, pJob->queryId, SCH_TASK_ID(pTask), __VA_ARGS__)
|
||||
#define SCH_TASK_WLOG(param, ...) \
|
||||
qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 " " param, pJob->queryId, SCH_TASK_ID(pTask), __VA_ARGS__)
|
||||
|
||||
|
@ -228,6 +249,8 @@ int32_t schLaunchTasksInFlowCtrlList(SSchJob *pJob, SSchTask *pTask);
|
|||
int32_t schLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask);
|
||||
int32_t schFetchFromRemote(SSchJob *pJob);
|
||||
int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode);
|
||||
int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId);
|
||||
int32_t schCloneSMsgSendInfo(void *src, void **dst);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "schedulerInt.h"
|
||||
#include "tmsg.h"
|
||||
#include "tref.h"
|
||||
#include "trpc.h"
|
||||
|
||||
SSchedulerMgmt schMgmt = {0};
|
||||
|
||||
|
@ -56,15 +57,35 @@ int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *
|
|||
pTask->level = pLevel;
|
||||
SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_NOT_START);
|
||||
pTask->taskId = schGenTaskId();
|
||||
pTask->execAddrs = taosArrayInit(SCH_MAX_CANDIDATE_EP_NUM, sizeof(SQueryNodeAddr));
|
||||
if (NULL == pTask->execAddrs) {
|
||||
SCH_TASK_ELOG("taosArrayInit %d exec addrs failed", SCH_MAX_CANDIDATE_EP_NUM);
|
||||
pTask->execNodes = taosArrayInit(SCH_MAX_CANDIDATE_EP_NUM, sizeof(SSchNodeInfo));
|
||||
if (NULL == pTask->execNodes) {
|
||||
SCH_TASK_ELOG("taosArrayInit %d execNodes failed", SCH_MAX_CANDIDATE_EP_NUM);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void schFreeRpcCtx(SRpcCtx *pCtx) {
|
||||
if (NULL == pCtx) {
|
||||
return;
|
||||
}
|
||||
void *pIter = taosHashIterate(pCtx->args, NULL);
|
||||
while (pIter) {
|
||||
SRpcCtxVal *ctxVal = (SRpcCtxVal *)pIter;
|
||||
|
||||
(*ctxVal->freeFunc)(ctxVal->val);
|
||||
|
||||
pIter = taosHashIterate(pCtx->args, pIter);
|
||||
}
|
||||
|
||||
taosHashCleanup(pCtx->args);
|
||||
|
||||
if (pCtx->brokenVal.freeFunc) {
|
||||
(*pCtx->brokenVal.freeFunc)(pCtx->brokenVal.val);
|
||||
}
|
||||
}
|
||||
|
||||
void schFreeTask(SSchTask* pTask) {
|
||||
if (pTask->candidateAddrs) {
|
||||
taosArrayDestroy(pTask->candidateAddrs);
|
||||
|
@ -80,8 +101,8 @@ void schFreeTask(SSchTask *pTask) {
|
|||
taosArrayDestroy(pTask->parents);
|
||||
}
|
||||
|
||||
if (pTask->execAddrs) {
|
||||
taosArrayDestroy(pTask->execAddrs);
|
||||
if (pTask->execNodes) {
|
||||
taosArrayDestroy(pTask->execNodes);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,17 +120,25 @@ static FORCE_INLINE bool schJobNeedToStop(SSchJob *pJob, int8_t *pStatus) {
|
|||
int32_t schValidateTaskReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgType) {
|
||||
int32_t lastMsgType = SCH_GET_TASK_LASTMSG_TYPE(pTask);
|
||||
int32_t taskStatus = SCH_GET_TASK_STATUS(pTask);
|
||||
|
||||
int32_t reqMsgType = msgType - 1;
|
||||
switch (msgType) {
|
||||
case TDMT_VND_CREATE_TABLE_RSP:
|
||||
case TDMT_VND_SUBMIT_RSP:
|
||||
case TDMT_VND_QUERY_RSP:
|
||||
case TDMT_SCH_LINK_BROKEN:
|
||||
return TSDB_CODE_SUCCESS;
|
||||
case TDMT_VND_QUERY_RSP: // query_rsp may be processed later than ready_rsp
|
||||
if (lastMsgType != reqMsgType && -1 != lastMsgType && TDMT_VND_FETCH != lastMsgType) {
|
||||
SCH_TASK_DLOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", TMSG_INFO(lastMsgType), TMSG_INFO(msgType));
|
||||
}
|
||||
|
||||
if (taskStatus != JOB_TASK_STATUS_EXECUTING && taskStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED) {
|
||||
SCH_TASK_DLOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), TMSG_INFO(msgType));
|
||||
}
|
||||
|
||||
SCH_SET_TASK_LASTMSG_TYPE(pTask, -1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
case TDMT_VND_RES_READY_RSP:
|
||||
case TDMT_VND_FETCH_RSP:
|
||||
case TDMT_VND_DROP_TASK:
|
||||
if (lastMsgType != (msgType - 1)) {
|
||||
SCH_TASK_ELOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", TMSG_INFO(lastMsgType),
|
||||
TMSG_INFO(msgType));
|
||||
reqMsgType = TDMT_VND_QUERY;
|
||||
if (lastMsgType != reqMsgType && -1 != lastMsgType) {
|
||||
SCH_TASK_ELOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", (lastMsgType > 0 ? TMSG_INFO(lastMsgType) : "null"), TMSG_INFO(msgType));
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
|
@ -118,12 +147,39 @@ int32_t schValidateTaskReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t m
|
|||
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
SCH_SET_TASK_LASTMSG_TYPE(pTask, -1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
case TDMT_VND_FETCH_RSP:
|
||||
if (lastMsgType != reqMsgType && -1 != lastMsgType) {
|
||||
SCH_TASK_ELOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", TMSG_INFO(lastMsgType), TMSG_INFO(msgType));
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
if (taskStatus != JOB_TASK_STATUS_EXECUTING && taskStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED) {
|
||||
SCH_TASK_ELOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), TMSG_INFO(msgType));
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
SCH_SET_TASK_LASTMSG_TYPE(pTask, -1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
case TDMT_VND_CREATE_TABLE_RSP:
|
||||
case TDMT_VND_SUBMIT_RSP:
|
||||
break;
|
||||
default:
|
||||
SCH_TASK_ELOG("unknown rsp msg, type:%s, status:%s", TMSG_INFO(msgType), jobTaskStatusStr(taskStatus));
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
if (lastMsgType != reqMsgType) {
|
||||
SCH_TASK_ELOG("rsp msg type mis-match, last sent msgType:%s, rspType:%s", TMSG_INFO(lastMsgType), TMSG_INFO(msgType));
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
if (taskStatus != JOB_TASK_STATUS_EXECUTING && taskStatus != JOB_TASK_STATUS_PARTIAL_SUCCEED) {
|
||||
SCH_TASK_ELOG("rsp msg conflicted with task status, status:%s, rspType:%s", jobTaskStatusStr(taskStatus), TMSG_INFO(msgType));
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
SCH_SET_TASK_LASTMSG_TYPE(pTask, -1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -299,12 +355,16 @@ int32_t schRecordTaskSucceedNode(SSchJob *pJob, SSchTask *pTask) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schRecordTaskExecNode(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr) {
|
||||
if (NULL == taosArrayPush(pTask->execAddrs, addr)) {
|
||||
SCH_TASK_ELOG("taosArrayPush addr to execAddr list failed, errno:%d", errno);
|
||||
int32_t schRecordTaskExecNode(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, void *handle) {
|
||||
SSchNodeInfo nodeInfo = {.addr = *addr, .handle = handle};
|
||||
|
||||
if (NULL == taosArrayPush(pTask->execNodes, &nodeInfo)) {
|
||||
SCH_TASK_ELOG("taosArrayPush nodeInfo to execNodes list failed, errno:%d", errno);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCH_TASK_DLOG("task execNode recorded, handle:%p", handle);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -632,53 +692,23 @@ int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schUpdateHbConnection(SQueryNodeEpId *epId, SSchHbTrans *trans) {
|
||||
int32_t schUpdateHbConnection(SQueryNodeEpId *epId, SSchTrans *trans) {
|
||||
int32_t code = 0;
|
||||
SSchHbTrans *hb = NULL;
|
||||
|
||||
while (true) {
|
||||
hb = taosHashGet(schMgmt.hbConnections, epId, sizeof(SQueryNodeEpId));
|
||||
if (NULL == hb) {
|
||||
code = taosHashPut(schMgmt.hbConnections, epId, sizeof(SQueryNodeEpId), trans, sizeof(SSchHbTrans));
|
||||
if (code) {
|
||||
if (HASH_NODE_EXIST(code)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
qError("taosHashPut hb trans failed, nodeId:%d, fqdn:%s, port:%d", epId->nodeId, epId->ep.fqdn, epId->ep.port);
|
||||
SCH_ERR_RET(code);
|
||||
}
|
||||
|
||||
qDebug("hb connection updated, seqId:%" PRIx64 ", sId:%" PRIx64
|
||||
", nodeId:%d, fqdn:%s, port:%d, instance:%p, connection:%p",
|
||||
trans->seqId, schMgmt.sId, epId->nodeId, epId->ep.fqdn, epId->ep.port, trans->trans.transInst,
|
||||
trans->trans.transHandle);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
break;
|
||||
qError("taosHashGet hb connection failed, nodeId:%d, fqdn:%s, port:%d", epId->nodeId, epId->ep.fqdn, epId->ep.port);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
SCH_LOCK(SCH_WRITE, &hb->lock);
|
||||
|
||||
if (hb->seqId >= trans->seqId) {
|
||||
qDebug("hb trans seqId is old, seqId:%" PRId64 ", currentId:%" PRId64 ", nodeId:%d, fqdn:%s, port:%d", trans->seqId,
|
||||
hb->seqId, epId->nodeId, epId->ep.fqdn, epId->ep.port);
|
||||
|
||||
SCH_UNLOCK(SCH_WRITE, &hb->lock);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
hb->seqId = trans->seqId;
|
||||
memcpy(&hb->trans, &trans->trans, sizeof(trans->trans));
|
||||
|
||||
memcpy(&hb->trans, trans, sizeof(*trans));
|
||||
SCH_UNLOCK(SCH_WRITE, &hb->lock);
|
||||
|
||||
qDebug("hb connection updated, seqId:%" PRIx64 ", sId:%" PRIx64
|
||||
", nodeId:%d, fqdn:%s, port:%d, instance:%p, connection:%p",
|
||||
trans->seqId, schMgmt.sId, epId->nodeId, epId->ep.fqdn, epId->ep.port, trans->trans.transInst,
|
||||
trans->trans.transHandle);
|
||||
qDebug("hb connection updated, sId:%" PRIx64 ", nodeId:%d, fqdn:%s, port:%d, instance:%p, handle:%p",
|
||||
schMgmt.sId, epId->nodeId, epId->ep.fqdn, epId->ep.port, trans->transInst,
|
||||
trans->transHandle);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -993,7 +1023,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch
|
|||
SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
SCH_ERR_JRET(schBuildAndSendMsg(pJob, pTask, NULL, TDMT_VND_RES_READY));
|
||||
//SCH_ERR_JRET(schBuildAndSendMsg(pJob, pTask, NULL, TDMT_VND_RES_READY));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -1041,6 +1071,10 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch
|
|||
SCH_ERR_JRET(TSDB_CODE_SCH_INTERNAL_ERROR);
|
||||
break;
|
||||
}
|
||||
case TDMT_SCH_LINK_BROKEN:
|
||||
SCH_TASK_ELOG("link broken received, error:%x - %s", rspCode, tstrerror(rspCode));
|
||||
SCH_ERR_JRET(rspCode);
|
||||
break;
|
||||
default:
|
||||
SCH_TASK_ELOG("unknown rsp msg, type:%d, status:%s", msgType, SCH_GET_TASK_STATUS_STR(pTask));
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
|
@ -1055,12 +1089,12 @@ _return:
|
|||
|
||||
int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, int32_t rspCode) {
|
||||
int32_t code = 0;
|
||||
SSchCallbackParam *pParam = (SSchCallbackParam *)param;
|
||||
SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param;
|
||||
SSchTask *pTask = NULL;
|
||||
|
||||
SSchJob *pJob = schAcquireJob(pParam->refId);
|
||||
if (NULL == pJob) {
|
||||
qError("QID:0x%" PRIx64 ",TID:0x%" PRIx64 "taosAcquireRef job failed, may be dropped, refId:%" PRIx64,
|
||||
qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 "taosAcquireRef job failed, may be dropped, refId:%" PRIx64,
|
||||
pParam->queryId, pParam->taskId, pParam->refId);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_JOB_FREED);
|
||||
}
|
||||
|
@ -1078,9 +1112,9 @@ int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, in
|
|||
}
|
||||
|
||||
pTask = *task;
|
||||
SCH_TASK_DLOG("rsp msg received, type:%s, code:%s", TMSG_INFO(msgType), tstrerror(rspCode));
|
||||
SCH_TASK_DLOG("rsp msg received, type:%s, handle:%p, code:%s", TMSG_INFO(msgType), pMsg->handle, tstrerror(rspCode));
|
||||
|
||||
pTask->handle = pMsg->handle;
|
||||
SCH_SET_TASK_HANDLE(pTask, pMsg->handle);
|
||||
SCH_ERR_JRET(schHandleResponseMsg(pJob, pTask, msgType, pMsg->pData, pMsg->len, rspCode));
|
||||
|
||||
_return:
|
||||
|
@ -1114,7 +1148,7 @@ int32_t schHandleReadyCallback(void *param, const SDataBuf *pMsg, int32_t code)
|
|||
}
|
||||
|
||||
int32_t schHandleDropCallback(void *param, const SDataBuf *pMsg, int32_t code) {
|
||||
SSchCallbackParam *pParam = (SSchCallbackParam *)param;
|
||||
SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param;
|
||||
qDebug("QID:%" PRIx64 ",TID:%" PRIx64 " drop task rsp received, code:%x", pParam->queryId, pParam->taskId, code);
|
||||
}
|
||||
|
||||
|
@ -1125,24 +1159,22 @@ int32_t schHandleHbCallback(void *param, const SDataBuf *pMsg, int32_t code) {
|
|||
}
|
||||
|
||||
SSchedulerHbRsp rsp = {0};
|
||||
|
||||
SSchCallbackParam *pParam = (SSchCallbackParam *)param;
|
||||
|
||||
if (tDeserializeSSchedulerHbRsp(pMsg->pData, pMsg->len, &rsp)) {
|
||||
qError("invalid hb rsp msg, size:%d", pMsg->len);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
if (rsp.seqId != (uint64_t)-1) {
|
||||
SSchHbTrans trans = {0};
|
||||
trans.seqId = rsp.seqId;
|
||||
trans.trans.transInst = pParam->transport;
|
||||
trans.trans.transHandle = pMsg->handle;
|
||||
SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param;
|
||||
|
||||
SCH_RET(schUpdateHbConnection(&rsp.epId, &trans));
|
||||
}
|
||||
SSchTrans trans = {0};
|
||||
trans.transInst = pParam->transport;
|
||||
trans.transHandle = pMsg->handle;
|
||||
|
||||
SCH_ERR_RET(schUpdateHbConnection(&rsp.epId, &trans));
|
||||
|
||||
int32_t taskNum = (int32_t)taosArrayGetSize(rsp.taskStatus);
|
||||
qDebug("%d task status in hb rsp, nodeId:%d, fqdn:%s, port:%d", taskNum, rsp.epId.nodeId, rsp.epId.ep.fqdn, rsp.epId.ep.port);
|
||||
|
||||
for (int32_t i = 0; i < taskNum; ++i) {
|
||||
STaskStatus *taskStatus = taosArrayGet(rsp.taskStatus, i);
|
||||
|
||||
|
@ -1156,6 +1188,8 @@ int32_t schHandleHbCallback(void *param, const SDataBuf *pMsg, int32_t code) {
|
|||
|
||||
// TODO
|
||||
|
||||
SCH_JOB_DLOG("TID:0x%" PRIx64 " task status in server: %s", taskStatus->taskId, jobTaskStatusStr(taskStatus->status));
|
||||
|
||||
schReleaseJob(taskStatus->refId);
|
||||
}
|
||||
|
||||
|
@ -1166,6 +1200,26 @@ _return:
|
|||
SCH_RET(code);
|
||||
}
|
||||
|
||||
int32_t schHandleLinkBrokenCallback(void *param, const SDataBuf *pMsg, int32_t code) {
|
||||
SSchCallbackParamHeader *head = (SSchCallbackParamHeader *)param;
|
||||
rpcReleaseHandle(pMsg->handle, TAOS_CONN_CLIENT);
|
||||
|
||||
qDebug("handle %p is broken", pMsg->handle);
|
||||
|
||||
if (head->isHbParam) {
|
||||
SSchHbCallbackParam *hbParam = (SSchHbCallbackParam *)param;
|
||||
SSchTrans trans = {.transInst = hbParam->transport, .transHandle = NULL};
|
||||
SCH_ERR_RET(schUpdateHbConnection(&hbParam->nodeEpId, &trans));
|
||||
|
||||
SCH_ERR_RET(schBuildAndSendHbMsg(&hbParam->nodeEpId));
|
||||
} else {
|
||||
SCH_ERR_RET(schHandleCallback(param, pMsg, TDMT_SCH_LINK_BROKEN, code));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) {
|
||||
switch (msgType) {
|
||||
case TDMT_VND_CREATE_TABLE:
|
||||
|
@ -1189,6 +1243,9 @@ int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) {
|
|||
case TDMT_VND_QUERY_HEARTBEAT:
|
||||
*fp = schHandleHbCallback;
|
||||
break;
|
||||
case TDMT_SCH_LINK_BROKEN:
|
||||
*fp = schHandleLinkBrokenCallback;
|
||||
break;
|
||||
default:
|
||||
qError("unknown msg type for callback, msgType:%d", msgType);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||
|
@ -1197,8 +1254,322 @@ int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, void *transport, SEpSet *epSet, int32_t msgType, void *msg,
|
||||
uint32_t msgSize) {
|
||||
void schFreeRpcCtxVal(const void *arg) {
|
||||
if (NULL == arg) {
|
||||
return;
|
||||
}
|
||||
|
||||
SMsgSendInfo* pMsgSendInfo = (SMsgSendInfo *)arg;
|
||||
taosMemoryFreeClear(pMsgSendInfo->param);
|
||||
taosMemoryFreeClear(pMsgSendInfo);
|
||||
}
|
||||
|
||||
int32_t schMakeTaskCallbackParam(SSchJob *pJob, SSchTask *pTask, void **pParam) {
|
||||
SSchTaskCallbackParam *param = taosMemoryCalloc(1, sizeof(SSchTaskCallbackParam));
|
||||
if (NULL == param) {
|
||||
SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchTaskCallbackParam));
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
param->queryId = pJob->queryId;
|
||||
param->refId = pJob->refId;
|
||||
param->taskId = SCH_TASK_ID(pTask);
|
||||
param->transport = pJob->transport;
|
||||
|
||||
*pParam = param;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schMakeHbCallbackParam(SSchJob *pJob, SSchTask *pTask, void **pParam) {
|
||||
SSchHbCallbackParam *param = taosMemoryCalloc(1, sizeof(SSchHbCallbackParam));
|
||||
if (NULL == param) {
|
||||
SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchHbCallbackParam));
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
param->head.isHbParam = true;
|
||||
|
||||
SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx);
|
||||
|
||||
param->nodeEpId.nodeId = addr->nodeId;
|
||||
memcpy(¶m->nodeEpId.ep, SCH_GET_CUR_EP(addr), sizeof(SEp));
|
||||
param->transport = pJob->transport;
|
||||
|
||||
*pParam = param;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t schMakeBrokenLinkVal(SSchJob *pJob, SSchTask *pTask, SRpcBrokenlinkVal *brokenVal, bool isHb) {
|
||||
int32_t code = 0;
|
||||
SMsgSendInfo* pMsgSendInfo = NULL;
|
||||
|
||||
pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (NULL == pMsgSendInfo) {
|
||||
SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SMsgSendInfo));
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (isHb) {
|
||||
SCH_ERR_JRET(schMakeHbCallbackParam(pJob, pTask, &pMsgSendInfo->param));
|
||||
} else {
|
||||
SCH_ERR_JRET(schMakeTaskCallbackParam(pJob, pTask, &pMsgSendInfo->param));
|
||||
}
|
||||
|
||||
int32_t msgType = TDMT_SCH_LINK_BROKEN;
|
||||
__async_send_cb_fn_t fp = NULL;
|
||||
SCH_ERR_JRET(schGetCallbackFp(msgType, &fp));
|
||||
|
||||
pMsgSendInfo->fp = fp;
|
||||
|
||||
brokenVal->msgType = msgType;
|
||||
brokenVal->val = pMsgSendInfo;
|
||||
brokenVal->clone = schCloneSMsgSendInfo;
|
||||
brokenVal->freeFunc = schFreeRpcCtxVal;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
taosMemoryFreeClear(pMsgSendInfo->param);
|
||||
taosMemoryFreeClear(pMsgSendInfo);
|
||||
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
int32_t schMakeQueryRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) {
|
||||
int32_t code = 0;
|
||||
SSchTaskCallbackParam *param = NULL;
|
||||
SMsgSendInfo* pMsgSendInfo = NULL;
|
||||
|
||||
pCtx->args = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == pCtx->args) {
|
||||
SCH_TASK_ELOG("taosHashInit %d RpcCtx failed", 1);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (NULL == pMsgSendInfo) {
|
||||
SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SMsgSendInfo));
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
param = taosMemoryCalloc(1, sizeof(SSchTaskCallbackParam));
|
||||
if (NULL == param) {
|
||||
SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchTaskCallbackParam));
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
int32_t msgType = TDMT_VND_RES_READY_RSP;
|
||||
__async_send_cb_fn_t fp = NULL;
|
||||
SCH_ERR_JRET(schGetCallbackFp(TDMT_VND_RES_READY, &fp));
|
||||
|
||||
param->queryId = pJob->queryId;
|
||||
param->refId = pJob->refId;
|
||||
param->taskId = SCH_TASK_ID(pTask);
|
||||
param->transport = pJob->transport;
|
||||
|
||||
pMsgSendInfo->param = param;
|
||||
pMsgSendInfo->fp = fp;
|
||||
|
||||
SRpcCtxVal ctxVal = {.val = pMsgSendInfo, .clone = schCloneSMsgSendInfo, .freeFunc = schFreeRpcCtxVal};
|
||||
if (taosHashPut(pCtx->args, &msgType, sizeof(msgType), &ctxVal, sizeof(ctxVal))) {
|
||||
SCH_TASK_ELOG("taosHashPut msg %d to rpcCtx failed", msgType);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCH_ERR_JRET(schMakeBrokenLinkVal(pJob, pTask, &pCtx->brokenVal, false));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
taosHashCleanup(pCtx->args);
|
||||
taosMemoryFreeClear(param);
|
||||
taosMemoryFreeClear(pMsgSendInfo);
|
||||
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) {
|
||||
int32_t code = 0;
|
||||
SSchHbCallbackParam *param = NULL;
|
||||
SMsgSendInfo* pMsgSendInfo = NULL;
|
||||
SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx);
|
||||
SQueryNodeEpId epId = {0};
|
||||
|
||||
epId.nodeId = addr->nodeId;
|
||||
memcpy(&epId.ep, SCH_GET_CUR_EP(addr), sizeof(SEp));
|
||||
|
||||
pCtx->args = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == pCtx->args) {
|
||||
SCH_TASK_ELOG("taosHashInit %d RpcCtx failed", 1);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (NULL == pMsgSendInfo) {
|
||||
SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SMsgSendInfo));
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
param = taosMemoryCalloc(1, sizeof(SSchHbCallbackParam));
|
||||
if (NULL == param) {
|
||||
SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchHbCallbackParam));
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
int32_t msgType = TDMT_VND_QUERY_HEARTBEAT_RSP;
|
||||
__async_send_cb_fn_t fp = NULL;
|
||||
SCH_ERR_JRET(schGetCallbackFp(TDMT_VND_QUERY_HEARTBEAT, &fp));
|
||||
|
||||
param->nodeEpId = epId;
|
||||
param->transport = pJob->transport;
|
||||
|
||||
pMsgSendInfo->param = param;
|
||||
pMsgSendInfo->fp = fp;
|
||||
|
||||
SRpcCtxVal ctxVal = {.val = pMsgSendInfo, .clone = schCloneSMsgSendInfo, .freeFunc = schFreeRpcCtxVal};
|
||||
if (taosHashPut(pCtx->args, &msgType, sizeof(msgType), &ctxVal, sizeof(ctxVal))) {
|
||||
SCH_TASK_ELOG("taosHashPut msg %d to rpcCtx failed", msgType);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCH_ERR_JRET(schMakeBrokenLinkVal(pJob, pTask, &pCtx->brokenVal, true));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
taosHashCleanup(pCtx->args);
|
||||
taosMemoryFreeClear(param);
|
||||
taosMemoryFreeClear(pMsgSendInfo);
|
||||
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t schRegisterHbConnection(SSchJob *pJob, SSchTask *pTask, SQueryNodeEpId *epId, bool *exist) {
|
||||
int32_t code = 0;
|
||||
SSchHbTrans hb = {0};
|
||||
|
||||
hb.trans.transInst = pJob->transport;
|
||||
|
||||
SCH_ERR_RET(schMakeHbRpcCtx(pJob, pTask, &hb.rpcCtx));
|
||||
|
||||
code = taosHashPut(schMgmt.hbConnections, epId, sizeof(SQueryNodeEpId), &hb, sizeof(SSchHbTrans));
|
||||
if (code) {
|
||||
schFreeRpcCtx(&hb.rpcCtx);
|
||||
|
||||
if (HASH_NODE_EXIST(code)) {
|
||||
*exist = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
qError("taosHashPut hb trans failed, nodeId:%d, fqdn:%s, port:%d", epId->nodeId, epId->ep.fqdn, epId->ep.port);
|
||||
SCH_ERR_RET(code);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32_t schCloneCallbackParam(SSchCallbackParamHeader *pSrc, SSchCallbackParamHeader **pDst) {
|
||||
if (pSrc->isHbParam) {
|
||||
SSchHbCallbackParam *dst = taosMemoryMalloc(sizeof(SSchHbCallbackParam));
|
||||
if (NULL == dst) {
|
||||
qError("malloc SSchHbCallbackParam failed");
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(dst, pSrc, sizeof(*dst));
|
||||
*pDst = (SSchCallbackParamHeader *)dst;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SSchTaskCallbackParam *dst = taosMemoryMalloc(sizeof(SSchTaskCallbackParam));
|
||||
if (NULL == dst) {
|
||||
qError("malloc SSchTaskCallbackParam failed");
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(dst, pSrc, sizeof(*dst));
|
||||
*pDst = (SSchCallbackParamHeader *)dst;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schCloneSMsgSendInfo(void *src, void **dst) {
|
||||
SMsgSendInfo *pSrc = src;
|
||||
int32_t code = 0;
|
||||
SMsgSendInfo *pDst = taosMemoryMalloc(sizeof(*pSrc));
|
||||
if (NULL == pDst) {
|
||||
qError("malloc SMsgSendInfo for rpcCtx failed, len:%d", (int32_t)sizeof(*pSrc));
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(pDst, pSrc, sizeof(*pSrc));
|
||||
pDst->param = NULL;
|
||||
|
||||
SCH_ERR_JRET(schCloneCallbackParam(pSrc->param, (SSchCallbackParamHeader **)&pDst->param));
|
||||
|
||||
*dst = pDst;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
taosMemoryFreeClear(pDst);
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
int32_t schCloneHbRpcCtx(SRpcCtx *pSrc, SRpcCtx *pDst) {
|
||||
int32_t code = 0;
|
||||
memcpy(&pDst->brokenVal, &pSrc->brokenVal, sizeof(pSrc->brokenVal));
|
||||
pDst->brokenVal.val = NULL;
|
||||
|
||||
SCH_ERR_RET(schCloneSMsgSendInfo(pSrc->brokenVal.val, &pDst->brokenVal.val));
|
||||
|
||||
pDst->args = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK);
|
||||
if (NULL == pDst->args) {
|
||||
qError("taosHashInit %d RpcCtx failed", 1);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SRpcCtxVal dst = {0};
|
||||
void *pIter = taosHashIterate(pSrc->args, NULL);
|
||||
while (pIter) {
|
||||
SRpcCtxVal *pVal = (SRpcCtxVal *)pIter;
|
||||
int32_t *msgType = taosHashGetKey(pIter, NULL);
|
||||
|
||||
dst = *pVal;
|
||||
dst.val = NULL;
|
||||
|
||||
SCH_ERR_JRET(schCloneSMsgSendInfo(pVal->val, &dst.val));
|
||||
|
||||
if (taosHashPut(pDst->args, msgType, sizeof(*msgType), &dst, sizeof(dst))) {
|
||||
qError("taosHashPut msg %d to rpcCtx failed", *msgType);
|
||||
(*dst.freeFunc)(dst.val);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pSrc->args, pIter);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
schFreeRpcCtx(pDst);
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, void *transport, SEpSet* epSet, int32_t msgType, void *msg, uint32_t msgSize, bool persistHandle, SRpcCtx *ctx) {
|
||||
int32_t code = 0;
|
||||
|
||||
SSchTrans *trans = (SSchTrans *)transport;
|
||||
|
@ -1209,9 +1580,9 @@ int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, void *transport, SEpSet
|
|||
SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SSchCallbackParam *param = taosMemoryCalloc(1, sizeof(SSchCallbackParam));
|
||||
SSchTaskCallbackParam *param = taosMemoryCalloc(1, sizeof(SSchTaskCallbackParam));
|
||||
if (NULL == param) {
|
||||
SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchCallbackParam));
|
||||
SCH_TASK_ELOG("calloc %d failed", (int32_t)sizeof(SSchTaskCallbackParam));
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
|
@ -1230,8 +1601,12 @@ int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, void *transport, SEpSet
|
|||
pMsgSendInfo->msgType = msgType;
|
||||
pMsgSendInfo->fp = fp;
|
||||
|
||||
qDebug("start to send %s msg to node[%d,%s,%d], refId:%" PRIx64 "instance:%p, handle:%p",
|
||||
TMSG_INFO(msgType), ntohl(((SMsgHead *)msg)->vgId), epSet->eps[epSet->inUse].fqdn, epSet->eps[epSet->inUse].port,
|
||||
pJob->refId, trans->transInst, trans->transHandle);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
code = asyncSendMsgToServer(trans->transInst, epSet, &transporterId, pMsgSendInfo);
|
||||
code = asyncSendMsgToServerExt(trans->transInst, epSet, &transporterId, pMsgSendInfo, persistHandle, ctx);
|
||||
if (code) {
|
||||
SCH_ERR_JRET(code);
|
||||
}
|
||||
|
@ -1246,11 +1621,103 @@ _return:
|
|||
SCH_RET(code);
|
||||
}
|
||||
|
||||
int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId) {
|
||||
SSchedulerHbReq req = {0};
|
||||
int32_t code = 0;
|
||||
SRpcCtx rpcCtx = {0};
|
||||
SSchTrans trans = {0};
|
||||
int32_t msgType = TDMT_VND_QUERY_HEARTBEAT;
|
||||
|
||||
req.header.vgId = htonl(nodeEpId->nodeId);
|
||||
req.sId = schMgmt.sId;
|
||||
memcpy(&req.epId, nodeEpId, sizeof(SQueryNodeEpId));
|
||||
|
||||
SSchHbTrans *hb = taosHashGet(schMgmt.hbConnections, nodeEpId, sizeof(SQueryNodeEpId));
|
||||
if (NULL == hb) {
|
||||
qError("taosHashGet hb connection failed, nodeId:%d, fqdn:%s, port:%d", nodeEpId->nodeId, nodeEpId->ep.fqdn, nodeEpId->ep.port);
|
||||
SCH_ERR_RET(code);
|
||||
}
|
||||
|
||||
SCH_LOCK(SCH_WRITE, &hb->lock);
|
||||
code = schCloneHbRpcCtx(&hb->rpcCtx, &rpcCtx);
|
||||
memcpy(&trans, &hb->trans, sizeof(trans));
|
||||
SCH_UNLOCK(SCH_WRITE, &hb->lock);
|
||||
|
||||
SCH_ERR_RET(code);
|
||||
|
||||
int32_t msgSize = tSerializeSSchedulerHbReq(NULL, 0, &req);
|
||||
if (msgSize < 0) {
|
||||
qError("tSerializeSSchedulerHbReq hbReq failed, size:%d", msgSize);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
void *msg = taosMemoryCalloc(1, msgSize);
|
||||
if (NULL == msg) {
|
||||
qError("calloc hb req %d failed", msgSize);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (tSerializeSSchedulerHbReq(msg, msgSize, &req) < 0) {
|
||||
qError("tSerializeSSchedulerHbReq hbReq failed, size:%d", msgSize);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SMsgSendInfo *pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (NULL == pMsgSendInfo) {
|
||||
qError("calloc SMsgSendInfo failed");
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SSchTaskCallbackParam *param = taosMemoryCalloc(1, sizeof(SSchTaskCallbackParam));
|
||||
if (NULL == param) {
|
||||
qError("calloc SSchTaskCallbackParam failed");
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
__async_send_cb_fn_t fp = NULL;
|
||||
SCH_ERR_JRET(schGetCallbackFp(msgType, &fp));
|
||||
|
||||
param->transport = trans.transInst;
|
||||
|
||||
pMsgSendInfo->param = param;
|
||||
pMsgSendInfo->msgInfo.pData = msg;
|
||||
pMsgSendInfo->msgInfo.len = msgSize;
|
||||
pMsgSendInfo->msgInfo.handle = trans.transHandle;
|
||||
pMsgSendInfo->msgType = msgType;
|
||||
pMsgSendInfo->fp = fp;
|
||||
|
||||
int64_t transporterId = 0;
|
||||
SEpSet epSet = {.inUse = 0, .numOfEps = 1};
|
||||
memcpy(&epSet.eps[0], &nodeEpId->ep, sizeof(nodeEpId->ep));
|
||||
|
||||
qDebug("start to send hb msg, instance:%p, handle:%p, fqdn:%s, port:%d", trans.transInst, trans.transHandle, nodeEpId->ep.fqdn, nodeEpId->ep.port);
|
||||
|
||||
code = asyncSendMsgToServerExt(trans.transInst, &epSet, &transporterId, pMsgSendInfo, true, &rpcCtx);
|
||||
if (code) {
|
||||
qError("fail to send hb msg, instance:%p, handle:%p, fqdn:%s, port:%d, error:%x - %s",
|
||||
trans.transInst, trans.transHandle, nodeEpId->ep.fqdn, nodeEpId->ep.port, code, tstrerror(code));
|
||||
SCH_ERR_JRET(code);
|
||||
}
|
||||
|
||||
qDebug("hb msg sent");
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
taosMemoryFreeClear(msg);
|
||||
taosMemoryFreeClear(param);
|
||||
taosMemoryFreeClear(pMsgSendInfo);
|
||||
schFreeRpcCtx(&rpcCtx);
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, int32_t msgType) {
|
||||
uint32_t msgSize = 0;
|
||||
void *msg = NULL;
|
||||
int32_t code = 0;
|
||||
bool isCandidateAddr = false;
|
||||
bool persistHandle = false;
|
||||
SRpcCtx rpcCtx = {0};
|
||||
|
||||
if (NULL == addr) {
|
||||
addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx);
|
||||
isCandidateAddr = true;
|
||||
|
@ -1273,8 +1740,9 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
}
|
||||
|
||||
case TDMT_VND_QUERY: {
|
||||
uint32_t len = strlen(pJob->sql);
|
||||
SCH_ERR_RET(schMakeQueryRpcCtx(pJob, pTask, &rpcCtx));
|
||||
|
||||
uint32_t len = strlen(pJob->sql);
|
||||
msgSize = sizeof(SSubQueryMsg) + pTask->msgLen + len;
|
||||
msg = taosMemoryCalloc(1, msgSize);
|
||||
if (NULL == msg) {
|
||||
|
@ -1295,6 +1763,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
memcpy(pMsg->msg, pJob->sql, len);
|
||||
memcpy(pMsg->msg + len, pTask->msg, pTask->msgLen);
|
||||
|
||||
persistHandle = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1330,6 +1799,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
pMsg->sId = htobe64(schMgmt.sId);
|
||||
pMsg->queryId = htobe64(pJob->queryId);
|
||||
pMsg->taskId = htobe64(pTask->taskId);
|
||||
|
||||
break;
|
||||
}
|
||||
case TDMT_VND_DROP_TASK: {
|
||||
|
@ -1351,6 +1821,8 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
break;
|
||||
}
|
||||
case TDMT_VND_QUERY_HEARTBEAT: {
|
||||
SCH_ERR_RET(schMakeHbRpcCtx(pJob, pTask, &rpcCtx));
|
||||
|
||||
SSchedulerHbReq req = {0};
|
||||
req.sId = schMgmt.sId;
|
||||
req.header.vgId = addr->nodeId;
|
||||
|
@ -1371,6 +1843,8 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
SCH_JOB_ELOG("tSerializeSSchedulerHbReq hbReq failed, size:%d", msgSize);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
persistHandle = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -1381,11 +1855,11 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
|
||||
SCH_SET_TASK_LASTMSG_TYPE(pTask, msgType);
|
||||
|
||||
SSchTrans trans = {.transInst = pJob->transport, .transHandle = pTask ? pTask->handle : NULL};
|
||||
SCH_ERR_JRET(schAsyncSendMsg(pJob, pTask, &trans, &epSet, msgType, msg, msgSize));
|
||||
SSchTrans trans = {.transInst = pJob->transport, .transHandle = SCH_GET_TASK_HANDLE(pTask)};
|
||||
SCH_ERR_JRET(schAsyncSendMsg(pJob, pTask, &trans, &epSet, msgType, msg, msgSize, persistHandle, (rpcCtx.args ? &rpcCtx : NULL)));
|
||||
|
||||
if (isCandidateAddr) {
|
||||
SCH_ERR_RET(schRecordTaskExecNode(pJob, pTask, addr));
|
||||
if (msgType == TDMT_VND_QUERY) {
|
||||
SCH_ERR_RET(schRecordTaskExecNode(pJob, pTask, addr, trans.transHandle));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1393,6 +1867,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
_return:
|
||||
|
||||
SCH_SET_TASK_LASTMSG_TYPE(pTask, -1);
|
||||
schFreeRpcCtx(&rpcCtx);
|
||||
|
||||
taosMemoryFreeClear(msg);
|
||||
SCH_RET(code);
|
||||
|
@ -1405,10 +1880,16 @@ int32_t schEnsureHbConnection(SSchJob *pJob, SSchTask *pTask) {
|
|||
epId.nodeId = addr->nodeId;
|
||||
memcpy(&epId.ep, SCH_GET_CUR_EP(addr), sizeof(SEp));
|
||||
|
||||
#if 1
|
||||
SSchHbTrans *hb = taosHashGet(schMgmt.hbConnections, &epId, sizeof(SQueryNodeEpId));
|
||||
if (NULL == hb) {
|
||||
SCH_ERR_RET(schBuildAndSendMsg(pJob, NULL, addr, TDMT_VND_QUERY_HEARTBEAT));
|
||||
bool exist = false;
|
||||
SCH_ERR_RET(schRegisterHbConnection(pJob, pTask, &epId, &exist));
|
||||
if (!exist) {
|
||||
SCH_ERR_RET(schBuildAndSendHbMsg(&epId));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1440,7 +1921,7 @@ int32_t schLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask) {
|
|||
pTask->msgLen);
|
||||
SCH_ERR_RET(code);
|
||||
} else {
|
||||
SCH_TASK_DLOG("physical plan len:%d, %s", pTask->msgLen, pTask->msg);
|
||||
SCH_TASK_DLOGL("physical plan len:%d, %s", pTask->msgLen, pTask->msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1460,6 +1941,8 @@ int32_t schLaunchTask(SSchJob *pJob, SSchTask *pTask) {
|
|||
bool enough = false;
|
||||
int32_t code = 0;
|
||||
|
||||
SCH_SET_TASK_HANDLE(pTask, NULL);
|
||||
|
||||
if (SCH_TASK_NEED_FLOW_CTRL(pJob, pTask)) {
|
||||
SCH_ERR_JRET(schCheckIncTaskFlowQuota(pJob, pTask, &enough));
|
||||
|
||||
|
@ -1500,23 +1983,24 @@ int32_t schLaunchJob(SSchJob *pJob) {
|
|||
}
|
||||
|
||||
void schDropTaskOnExecutedNode(SSchJob *pJob, SSchTask *pTask) {
|
||||
if (NULL == pTask->execAddrs) {
|
||||
if (NULL == pTask->execNodes) {
|
||||
SCH_TASK_DLOG("no exec address, status:%s", SCH_GET_TASK_STATUS_STR(pTask));
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t size = (int32_t)taosArrayGetSize(pTask->execAddrs);
|
||||
int32_t size = (int32_t)taosArrayGetSize(pTask->execNodes);
|
||||
|
||||
if (size <= 0) {
|
||||
SCH_TASK_DLOG("task has no exec address, no need to drop it, status:%s", SCH_GET_TASK_STATUS_STR(pTask));
|
||||
SCH_TASK_DLOG("task has no execNodes, no need to drop it, status:%s", SCH_GET_TASK_STATUS_STR(pTask));
|
||||
return;
|
||||
}
|
||||
|
||||
SQueryNodeAddr *addr = NULL;
|
||||
SSchNodeInfo *nodeInfo = NULL;
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
addr = (SQueryNodeAddr *)taosArrayGet(pTask->execAddrs, i);
|
||||
nodeInfo = (SSchNodeInfo *)taosArrayGet(pTask->execNodes, i);
|
||||
SCH_SET_TASK_HANDLE(pTask, nodeInfo->handle);
|
||||
|
||||
schBuildAndSendMsg(pJob, pTask, addr, TDMT_VND_DROP_TASK);
|
||||
schBuildAndSendMsg(pJob, pTask, &nodeInfo->addr, TDMT_VND_DROP_TASK);
|
||||
}
|
||||
|
||||
SCH_TASK_DLOG("task has %d exec address", size);
|
||||
|
|
|
@ -387,7 +387,7 @@ void *schtCreateFetchRspThread(void *param) {
|
|||
|
||||
void *schtFetchRspThread(void *aa) {
|
||||
SDataBuf dataBuf = {0};
|
||||
SSchCallbackParam* param = NULL;
|
||||
SSchTaskCallbackParam* param = NULL;
|
||||
|
||||
while (!schtTestStop) {
|
||||
if (0 == atomic_val_compare_exchange_32(&schtStartFetch, 1, 0)) {
|
||||
|
@ -396,7 +396,7 @@ void *schtFetchRspThread(void *aa) {
|
|||
|
||||
taosUsleep(1);
|
||||
|
||||
param = (SSchCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
|
||||
param->queryId = schtQueryId;
|
||||
param->taskId = schtFetchTaskId;
|
||||
|
@ -449,7 +449,7 @@ void* schtRunJobThread(void *aa) {
|
|||
schtSetAsyncSendMsgToServer();
|
||||
|
||||
SSchJob *pJob = NULL;
|
||||
SSchCallbackParam *param = NULL;
|
||||
SSchTaskCallbackParam *param = NULL;
|
||||
SHashObj *execTasks = NULL;
|
||||
SDataBuf dataBuf = {0};
|
||||
uint32_t jobFinished = 0;
|
||||
|
@ -484,7 +484,7 @@ void* schtRunJobThread(void *aa) {
|
|||
pIter = taosHashIterate(pJob->execTasks, pIter);
|
||||
}
|
||||
|
||||
param = (SSchCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
param->refId = queryJobRefId;
|
||||
param->queryId = pJob->queryId;
|
||||
|
||||
|
@ -504,7 +504,7 @@ void* schtRunJobThread(void *aa) {
|
|||
}
|
||||
|
||||
|
||||
param = (SSchCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
param->refId = queryJobRefId;
|
||||
param->queryId = pJob->queryId;
|
||||
|
||||
|
@ -524,7 +524,7 @@ void* schtRunJobThread(void *aa) {
|
|||
}
|
||||
|
||||
|
||||
param = (SSchCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
param->refId = queryJobRefId;
|
||||
param->queryId = pJob->queryId;
|
||||
|
||||
|
@ -544,7 +544,7 @@ void* schtRunJobThread(void *aa) {
|
|||
}
|
||||
|
||||
|
||||
param = (SSchCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
param = (SSchTaskCallbackParam *)taosMemoryCalloc(1, sizeof(*param));
|
||||
param->refId = queryJobRefId;
|
||||
param->queryId = pJob->queryId;
|
||||
|
||||
|
@ -713,6 +713,116 @@ TEST(queryTest, normalCase) {
|
|||
schedulerDestroy();
|
||||
}
|
||||
|
||||
TEST(queryTest, readyFirstCase) {
|
||||
void *mockPointer = (void *)0x1;
|
||||
char *clusterId = "cluster1";
|
||||
char *dbname = "1.db1";
|
||||
char *tablename = "table1";
|
||||
SVgroupInfo vgInfo = {0};
|
||||
int64_t job = 0;
|
||||
SQueryPlan dag;
|
||||
|
||||
memset(&dag, 0, sizeof(dag));
|
||||
|
||||
SArray *qnodeList = taosArrayInit(1, sizeof(SEp));
|
||||
|
||||
SEp qnodeAddr = {0};
|
||||
strcpy(qnodeAddr.fqdn, "qnode0.ep");
|
||||
qnodeAddr.port = 6031;
|
||||
taosArrayPush(qnodeList, &qnodeAddr);
|
||||
|
||||
int32_t code = schedulerInit(NULL);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
schtBuildQueryDag(&dag);
|
||||
|
||||
schtSetPlanToString();
|
||||
schtSetExecNode();
|
||||
schtSetAsyncSendMsgToServer();
|
||||
|
||||
code = schedulerAsyncExecJob(mockPointer, qnodeList, &dag, "select * from tb", &job);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
|
||||
SSchJob *pJob = schAcquireJob(job);
|
||||
|
||||
void *pIter = taosHashIterate(pJob->execTasks, NULL);
|
||||
while (pIter) {
|
||||
SSchTask *task = *(SSchTask **)pIter;
|
||||
|
||||
SResReadyRsp rsp = {0};
|
||||
code = schHandleResponseMsg(pJob, task, TDMT_VND_RES_READY_RSP, (char *)&rsp, sizeof(rsp), 0);
|
||||
printf("code:%d", code);
|
||||
ASSERT_EQ(code, 0);
|
||||
pIter = taosHashIterate(pJob->execTasks, pIter);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pJob->execTasks, NULL);
|
||||
while (pIter) {
|
||||
SSchTask *task = *(SSchTask **)pIter;
|
||||
|
||||
SQueryTableRsp rsp = {0};
|
||||
code = schHandleResponseMsg(pJob, task, TDMT_VND_QUERY_RSP, (char *)&rsp, sizeof(rsp), 0);
|
||||
|
||||
ASSERT_EQ(code, 0);
|
||||
pIter = taosHashIterate(pJob->execTasks, pIter);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pJob->execTasks, NULL);
|
||||
while (pIter) {
|
||||
SSchTask *task = *(SSchTask **)pIter;
|
||||
|
||||
SResReadyRsp rsp = {0};
|
||||
code = schHandleResponseMsg(pJob, task, TDMT_VND_RES_READY_RSP, (char *)&rsp, sizeof(rsp), 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
pIter = taosHashIterate(pJob->execTasks, pIter);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(pJob->execTasks, NULL);
|
||||
while (pIter) {
|
||||
SSchTask *task = *(SSchTask **)pIter;
|
||||
|
||||
SQueryTableRsp rsp = {0};
|
||||
code = schHandleResponseMsg(pJob, task, TDMT_VND_QUERY_RSP, (char *)&rsp, sizeof(rsp), 0);
|
||||
|
||||
ASSERT_EQ(code, 0);
|
||||
pIter = taosHashIterate(pJob->execTasks, pIter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
TdThread thread1;
|
||||
taosThreadCreate(&(thread1), &thattr, schtCreateFetchRspThread, &job);
|
||||
|
||||
void *data = NULL;
|
||||
code = schedulerFetchRows(job, &data);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
SRetrieveTableRsp *pRsp = (SRetrieveTableRsp *)data;
|
||||
ASSERT_EQ(pRsp->completed, 1);
|
||||
ASSERT_EQ(pRsp->numOfRows, 10);
|
||||
taosMemoryFreeClear(data);
|
||||
|
||||
data = NULL;
|
||||
code = schedulerFetchRows(job, &data);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(data == NULL);
|
||||
|
||||
schReleaseJob(job);
|
||||
|
||||
schedulerFreeJob(job);
|
||||
|
||||
schtFreeQueryDag(&dag);
|
||||
|
||||
schedulerDestroy();
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(queryTest, flowCtrlCase) {
|
||||
void *mockPointer = (void *)0x1;
|
||||
char *clusterId = "cluster1";
|
||||
|
|
|
@ -22,10 +22,13 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in
|
|||
if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK && pTask->sourceType != TASK_SOURCE__SCAN) return 0;
|
||||
|
||||
// exec
|
||||
if (pTask->execType == TASK_EXEC__EXEC) {
|
||||
if (pTask->execType != TASK_EXEC__NONE) {
|
||||
ASSERT(workId < pTask->exec.numOfRunners);
|
||||
void* exec = pTask->exec.runners[workId].executor;
|
||||
pRes = taosArrayInit(0, sizeof(SSDataBlock));
|
||||
if (pRes == NULL) {
|
||||
return -1;
|
||||
}
|
||||
if (inputType == STREAM_DATA_TYPE_SUBMIT_BLOCK) {
|
||||
qSetStreamInput(exec, input, inputType);
|
||||
while (1) {
|
||||
|
@ -79,7 +82,7 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in
|
|||
}
|
||||
|
||||
// dispatch
|
||||
if (pTask->dispatchType != TASK_DISPATCH__NONE) {
|
||||
if (pTask->dispatchType == TASK_DISPATCH__INPLACE) {
|
||||
SStreamTaskExecReq req = {
|
||||
.streamId = pTask->streamId,
|
||||
.taskId = pTask->taskId,
|
||||
|
@ -101,7 +104,7 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in
|
|||
.code = 0,
|
||||
.msgType = pTask->dispatchMsgType,
|
||||
};
|
||||
if (pTask->dispatchType == TASK_DISPATCH__INPLACE) {
|
||||
|
||||
int32_t qType;
|
||||
if (pTask->dispatchMsgType == TDMT_VND_TASK_PIPE_EXEC || pTask->dispatchMsgType == TDMT_SND_TASK_PIPE_EXEC) {
|
||||
qType = FETCH_QUEUE;
|
||||
|
@ -114,15 +117,41 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in
|
|||
ASSERT(0);
|
||||
}
|
||||
tmsgPutToQueue(pMsgCb, qType, &dispatchMsg);
|
||||
|
||||
} else if (pTask->dispatchType == TASK_DISPATCH__FIXED) {
|
||||
((SMsgHead*)buf)->vgId = pTask->fixedEpDispatcher.nodeId;
|
||||
SStreamTaskExecReq req = {
|
||||
.streamId = pTask->streamId,
|
||||
.taskId = pTask->taskId,
|
||||
.data = pRes,
|
||||
};
|
||||
|
||||
int32_t tlen = sizeof(SMsgHead) + tEncodeSStreamTaskExecReq(NULL, &req);
|
||||
void* buf = rpcMallocCont(tlen);
|
||||
|
||||
if (buf == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
((SMsgHead*)buf)->vgId = htonl(pTask->fixedEpDispatcher.nodeId);
|
||||
void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
tEncodeSStreamTaskExecReq(&abuf, &req);
|
||||
|
||||
SRpcMsg dispatchMsg = {
|
||||
.pCont = buf,
|
||||
.contLen = tlen,
|
||||
.code = 0,
|
||||
.msgType = pTask->dispatchMsgType,
|
||||
};
|
||||
|
||||
SEpSet* pEpSet = &pTask->fixedEpDispatcher.epSet;
|
||||
|
||||
tmsgSendReq(pMsgCb, pEpSet, &dispatchMsg);
|
||||
|
||||
} else if (pTask->dispatchType == TASK_DISPATCH__SHUFFLE) {
|
||||
// TODO
|
||||
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
ASSERT(pTask->dispatchType == TASK_DISPATCH__NONE);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -168,7 +197,10 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) {
|
|||
if (tEncodeI16(pEncoder, pTask->dispatchMsgType) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pTask->downstreamTaskId) < 0) return -1;
|
||||
|
||||
if (pTask->execType == TASK_EXEC__EXEC) {
|
||||
if (tEncodeI32(pEncoder, pTask->nodeId) < 0) return -1;
|
||||
if (tEncodeSEpSet(pEncoder, &pTask->epSet) < 0) return -1;
|
||||
|
||||
if (pTask->execType != TASK_EXEC__NONE) {
|
||||
if (tEncodeI8(pEncoder, pTask->exec.parallelizable) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pTask->exec.qmsg) < 0) return -1;
|
||||
}
|
||||
|
@ -203,7 +235,10 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) {
|
|||
if (tDecodeI16(pDecoder, &pTask->dispatchMsgType) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pTask->downstreamTaskId) < 0) return -1;
|
||||
|
||||
if (pTask->execType == TASK_EXEC__EXEC) {
|
||||
if (tDecodeI32(pDecoder, &pTask->nodeId) < 0) return -1;
|
||||
if (tDecodeSEpSet(pDecoder, &pTask->epSet) < 0) return -1;
|
||||
|
||||
if (pTask->execType != TASK_EXEC__NONE) {
|
||||
if (tDecodeI8(pDecoder, &pTask->exec.parallelizable) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg) < 0) return -1;
|
||||
}
|
||||
|
|
|
@ -158,6 +158,7 @@ typedef struct {
|
|||
char secured : 2;
|
||||
char spi : 2;
|
||||
|
||||
uint64_t ahandle; // ahandle assigned by client
|
||||
uint32_t code; // del later
|
||||
uint32_t msgType;
|
||||
int32_t msgLen;
|
||||
|
@ -182,7 +183,7 @@ typedef struct {
|
|||
#pragma pack(pop)
|
||||
|
||||
typedef enum { Normal, Quit, Release, Register } STransMsgType;
|
||||
typedef enum { ConnNormal, ConnAcquire, ConnRelease, ConnBroken } ConnStatus;
|
||||
typedef enum { ConnNormal, ConnAcquire, ConnRelease, ConnBroken, ConnInPool } ConnStatus;
|
||||
|
||||
#define container_of(ptr, type, member) ((type*)((char*)(ptr)-offsetof(type, member)))
|
||||
#define RPC_RESERVE_SIZE (sizeof(STranConnCtx))
|
||||
|
@ -277,6 +278,7 @@ void transCtxCleanup(STransCtx* ctx);
|
|||
void transCtxClear(STransCtx* ctx);
|
||||
void transCtxMerge(STransCtx* dst, STransCtx* src);
|
||||
void* transCtxDumpVal(STransCtx* ctx, int32_t key);
|
||||
void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType);
|
||||
|
||||
// queue sending msgs
|
||||
typedef struct {
|
||||
|
@ -295,20 +297,25 @@ void transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg));
|
|||
* if queue'size > 1, return false; else return true
|
||||
*/
|
||||
bool transQueuePush(STransQueue* queue, void* arg);
|
||||
/*
|
||||
* the size of queue
|
||||
*/
|
||||
int32_t transQueueSize(STransQueue* queue);
|
||||
/*
|
||||
* pop head from queue
|
||||
*/
|
||||
|
||||
void* transQueuePop(STransQueue* queue);
|
||||
/*
|
||||
* get head from queue
|
||||
* get ith from queue
|
||||
*/
|
||||
void* transQueueGet(STransQueue* queue);
|
||||
|
||||
void* transQueueGet(STransQueue* queue, int i);
|
||||
/*
|
||||
* rm ith from queue
|
||||
*/
|
||||
void* transQueueRm(STransQueue* queue, int i);
|
||||
/*
|
||||
* queue empty or not
|
||||
*/
|
||||
|
||||
bool transQueueEmpty(STransQueue* queue);
|
||||
/*
|
||||
* clear queue
|
||||
|
|
|
@ -25,7 +25,6 @@ typedef struct SCliConn {
|
|||
void* hostThrd;
|
||||
SConnBuffer readBuf;
|
||||
void* data;
|
||||
// SArray* cliMsgs;
|
||||
STransQueue cliMsgs;
|
||||
queue conn;
|
||||
uint64_t expireTime;
|
||||
|
@ -54,6 +53,7 @@ typedef struct SCliMsg {
|
|||
queue q;
|
||||
uint64_t st;
|
||||
STransMsgType type;
|
||||
int sent; //(0: no send, 1: alread sent)
|
||||
} SCliMsg;
|
||||
|
||||
typedef struct SCliThrdObj {
|
||||
|
@ -136,6 +136,8 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
|
|||
#define CONN_SHOULD_RELEASE(conn, head) \
|
||||
do { \
|
||||
if ((head)->release == 1 && (head->msgLen) == sizeof(*head)) { \
|
||||
uint64_t ahandle = head->ahandle; \
|
||||
CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle); \
|
||||
conn->status = ConnRelease; \
|
||||
transClearBuffer(&conn->readBuf); \
|
||||
transFreeMsg(transContFromHead((char*)head)); \
|
||||
|
@ -147,10 +149,40 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
|
|||
SCliThrdObj* thrd = conn->hostThrd; \
|
||||
addConnToPool(thrd->pool, conn); \
|
||||
} \
|
||||
destroyCmsg(pMsg); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \
|
||||
do { \
|
||||
int i = 0, sz = transQueueSize(&conn->cliMsgs); \
|
||||
for (; i < sz; i++) { \
|
||||
pMsg = transQueueGet(&conn->cliMsgs, i); \
|
||||
if (pMsg != NULL && pMsg->ctx != NULL && (uint64_t)pMsg->ctx->ahandle == ahandle) { \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
if (i == sz) { \
|
||||
pMsg = NULL; \
|
||||
} else { \
|
||||
pMsg = transQueueRm(&conn->cliMsgs, i); \
|
||||
} \
|
||||
} while (0)
|
||||
#define CONN_GET_NEXT_SENDMSG(conn) \
|
||||
do { \
|
||||
int i = 0; \
|
||||
do { \
|
||||
pCliMsg = transQueueGet(&conn->cliMsgs, i++); \
|
||||
if (pCliMsg && 0 == pCliMsg->sent) { \
|
||||
break; \
|
||||
} \
|
||||
} while (pCliMsg != NULL); \
|
||||
if (pCliMsg == NULL) { \
|
||||
goto _RETURN; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CONN_HANDLE_THREAD_QUIT(thrd) \
|
||||
do { \
|
||||
if (thrd->quit) { \
|
||||
|
@ -173,8 +205,10 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
|
|||
transRefCliHandle(conn); \
|
||||
} \
|
||||
} while (0)
|
||||
#define CONN_NO_PERSIST_BY_APP(conn) ((conn)->status == ConnNormal && T_REF_VAL_GET(conn) == 1)
|
||||
|
||||
#define CONN_NO_PERSIST_BY_APP(conn) \
|
||||
(((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
|
||||
#define CONN_RELEASE_BY_SERVER(conn) \
|
||||
(((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
|
||||
#define REQUEST_NO_RESP(msg) ((msg)->noResp == 1)
|
||||
#define REQUEST_PERSIS_HANDLE(msg) ((msg)->persistHandle == 1)
|
||||
#define REQUEST_RELEASE_HANDLE(cmsg) ((cmsg)->type == Release)
|
||||
|
@ -183,10 +217,13 @@ static void* cliWorkThread(void* arg);
|
|||
|
||||
bool cliMaySendCachedMsg(SCliConn* conn) {
|
||||
if (!transQueueEmpty(&conn->cliMsgs)) {
|
||||
SCliMsg* pCliMsg = NULL;
|
||||
CONN_GET_NEXT_SENDMSG(conn);
|
||||
cliSend(conn);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
_RETURN:
|
||||
return false;
|
||||
}
|
||||
void cliHandleResp(SCliConn* conn) {
|
||||
SCliThrdObj* pThrd = conn->hostThrd;
|
||||
|
@ -203,15 +240,38 @@ void cliHandleResp(SCliConn* conn) {
|
|||
transMsg.msgType = pHead->msgType;
|
||||
transMsg.ahandle = NULL;
|
||||
|
||||
SCliMsg* pMsg = NULL;
|
||||
STransConnCtx* pCtx = NULL;
|
||||
CONN_SHOULD_RELEASE(conn, pHead);
|
||||
|
||||
SCliMsg* pMsg = transQueuePop(&conn->cliMsgs);
|
||||
|
||||
STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL;
|
||||
if (CONN_NO_PERSIST_BY_APP(conn)) {
|
||||
pMsg = transQueuePop(&conn->cliMsgs);
|
||||
pCtx = pMsg ? pMsg->ctx : NULL;
|
||||
if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(conn)) {
|
||||
transMsg.ahandle = transCtxDumpVal(&conn->ctx, transMsg.msgType);
|
||||
if (transMsg.ahandle == NULL) {
|
||||
transMsg.ahandle = transCtxDumpBrokenlinkVal(&conn->ctx, (int32_t*)&(transMsg.msgType));
|
||||
}
|
||||
tDebug("cli conn %p construct ahandle %p, persist: 0", conn, transMsg.ahandle);
|
||||
} else {
|
||||
transMsg.ahandle = pCtx ? pCtx->ahandle : NULL;
|
||||
tDebug("cli conn %p get ahandle %p, persist: 0", conn, transMsg.ahandle);
|
||||
}
|
||||
} else {
|
||||
uint64_t ahandle = (uint64_t)pHead->ahandle;
|
||||
CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle);
|
||||
if (pMsg == NULL) {
|
||||
transMsg.ahandle = transCtxDumpVal(&conn->ctx, transMsg.msgType);
|
||||
tDebug("cli conn %p construct ahandle %p by %d, persist: 1", conn, transMsg.ahandle, transMsg.msgType);
|
||||
if (!CONN_RELEASE_BY_SERVER(conn) && transMsg.ahandle == NULL) {
|
||||
transMsg.ahandle = transCtxDumpBrokenlinkVal(&conn->ctx, (int32_t*)&(transMsg.msgType));
|
||||
tDebug("cli conn %p construct ahandle %p due brokenlink, persist: 1", conn, transMsg.ahandle);
|
||||
}
|
||||
} else {
|
||||
pCtx = pMsg ? pMsg->ctx : NULL;
|
||||
transMsg.ahandle = pCtx ? pCtx->ahandle : NULL;
|
||||
tDebug("cli conn %p get ahandle %p, persist: 1", conn, transMsg.ahandle);
|
||||
}
|
||||
}
|
||||
// buf's mem alread translated to transMsg.pCont
|
||||
transClearBuffer(&conn->readBuf);
|
||||
|
@ -232,6 +292,11 @@ void cliHandleResp(SCliConn* conn) {
|
|||
// transUnrefCliHandle(conn);
|
||||
return;
|
||||
}
|
||||
if (CONN_RELEASE_BY_SERVER(conn) && transMsg.ahandle == NULL) {
|
||||
tTrace("except, server continue send while cli ignore it");
|
||||
// transUnrefCliHandle(conn);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pCtx == NULL || pCtx->pSem == NULL) {
|
||||
tTrace("%s cli conn %p handle resp", pTransInst->label, conn);
|
||||
|
@ -256,41 +321,54 @@ void cliHandleResp(SCliConn* conn) {
|
|||
if (!uv_is_active((uv_handle_t*)&pThrd->timer) && pTransInst->idleTime > 0) {
|
||||
// uv_timer_start((uv_timer_t*)&pThrd->timer, cliTimeoutCb, CONN_PERSIST_TIME(pRpc->idleTime) / 2, 0);
|
||||
}
|
||||
_RETURN:
|
||||
return;
|
||||
}
|
||||
|
||||
void cliHandleExcept(SCliConn* pConn) {
|
||||
if (transQueueEmpty(&pConn->cliMsgs)) {
|
||||
if (pConn->broken == true || CONN_NO_PERSIST_BY_APP(pConn)) {
|
||||
if (pConn->broken == true && CONN_NO_PERSIST_BY_APP(pConn)) {
|
||||
tTrace("%s cli conn %p handle except, persist:0", CONN_GET_INST_LABEL(pConn), pConn);
|
||||
transUnrefCliHandle(pConn);
|
||||
return;
|
||||
}
|
||||
}
|
||||
SCliThrdObj* pThrd = pConn->hostThrd;
|
||||
STrans* pTransInst = pThrd->pTransInst;
|
||||
|
||||
bool once = false;
|
||||
do {
|
||||
SCliMsg* pMsg = transQueuePop(&pConn->cliMsgs);
|
||||
|
||||
if (pMsg == NULL && once) {
|
||||
break;
|
||||
}
|
||||
STransConnCtx* pCtx = pMsg ? pMsg->ctx : NULL;
|
||||
|
||||
STransMsg transMsg = {0};
|
||||
transMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||
transMsg.msgType = pMsg ? pMsg->msg.msgType + 1 : 0;
|
||||
transMsg.ahandle = NULL;
|
||||
transMsg.handle = pConn;
|
||||
|
||||
if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) {
|
||||
transMsg.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType);
|
||||
tDebug("%s cli conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle,
|
||||
TMSG_INFO(transMsg.msgType));
|
||||
if (transMsg.ahandle == NULL) {
|
||||
transMsg.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, (int32_t*)&(transMsg.msgType));
|
||||
tDebug("%s cli conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn,
|
||||
transMsg.ahandle);
|
||||
}
|
||||
} else {
|
||||
transMsg.ahandle = pCtx ? pCtx->ahandle : NULL;
|
||||
}
|
||||
|
||||
if (pCtx == NULL || pCtx->pSem == NULL) {
|
||||
tTrace("%s cli conn %p handle resp", pTransInst->label, pConn);
|
||||
tTrace("%s cli conn %p handle except", pTransInst->label, pConn);
|
||||
if (transMsg.ahandle == NULL) {
|
||||
once = true;
|
||||
continue;
|
||||
}
|
||||
(pTransInst->cfp)(pTransInst->parent, &transMsg, NULL);
|
||||
} else {
|
||||
tTrace("%s cli conn(sync) %p handle resp", pTransInst->label, pConn);
|
||||
tTrace("%s cli conn(sync) %p handle except", pTransInst->label, pConn);
|
||||
memcpy((char*)(pCtx->pRsp), (char*)(&transMsg), sizeof(transMsg));
|
||||
tsem_post(pCtx->pSem);
|
||||
}
|
||||
|
@ -364,8 +442,8 @@ static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port) {
|
|||
}
|
||||
queue* h = QUEUE_HEAD(&plist->conn);
|
||||
QUEUE_REMOVE(h);
|
||||
|
||||
SCliConn* conn = QUEUE_DATA(h, SCliConn, conn);
|
||||
conn->status = ConnNormal;
|
||||
QUEUE_INIT(&conn->conn);
|
||||
return conn;
|
||||
}
|
||||
|
@ -377,7 +455,7 @@ static void addConnToPool(void* pool, SCliConn* conn) {
|
|||
conn->expireTime = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
|
||||
transCtxCleanup(&conn->ctx);
|
||||
transQueueClear(&conn->cliMsgs);
|
||||
conn->status = ConnNormal;
|
||||
conn->status = ConnInPool;
|
||||
|
||||
char key[128] = {0};
|
||||
tstrncpy(key, conn->ip, strlen(conn->ip));
|
||||
|
@ -466,7 +544,7 @@ static void cliDestroy(uv_handle_t* handle) {
|
|||
static bool cliHandleNoResp(SCliConn* conn) {
|
||||
bool res = false;
|
||||
if (!transQueueEmpty(&conn->cliMsgs)) {
|
||||
SCliMsg* pMsg = transQueueGet(&conn->cliMsgs);
|
||||
SCliMsg* pMsg = transQueueGet(&conn->cliMsgs, 0);
|
||||
if (REQUEST_NO_RESP(&pMsg->msg)) {
|
||||
transQueuePop(&conn->cliMsgs);
|
||||
// taosArrayRemove(msgs, 0);
|
||||
|
@ -504,7 +582,11 @@ void cliSend(SCliConn* pConn) {
|
|||
|
||||
// assert(taosArrayGetSize(pConn->cliMsgs) > 0);
|
||||
assert(!transQueueEmpty(&pConn->cliMsgs));
|
||||
SCliMsg* pCliMsg = transQueueGet(&pConn->cliMsgs);
|
||||
|
||||
SCliMsg* pCliMsg = NULL;
|
||||
CONN_GET_NEXT_SENDMSG(pConn);
|
||||
pCliMsg->sent = 1;
|
||||
|
||||
STransConnCtx* pCtx = pCliMsg->ctx;
|
||||
|
||||
SCliThrdObj* pThrd = pConn->hostThrd;
|
||||
|
@ -516,6 +598,8 @@ void cliSend(SCliConn* pConn) {
|
|||
pMsg->contLen = 0;
|
||||
}
|
||||
STransMsgHead* pHead = transHeadFromCont(pMsg->pCont);
|
||||
pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0;
|
||||
|
||||
int msgLen = transMsgLenFromCont(pMsg->contLen);
|
||||
|
||||
if (!pConn->secured) {
|
||||
|
@ -555,6 +639,8 @@ void cliSend(SCliConn* pConn) {
|
|||
pConn->writeReq.data = pConn;
|
||||
uv_write(&pConn->writeReq, (uv_stream_t*)pConn->stream, &wb, 1, cliSendCb);
|
||||
|
||||
return;
|
||||
_RETURN:
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -643,6 +729,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrdObj* pThrd) {
|
|||
cliSend(conn);
|
||||
} else {
|
||||
conn = cliCreateConn(pThrd);
|
||||
transCtxMerge(&conn->ctx, &pCtx->appCtx);
|
||||
transQueuePush(&conn->cliMsgs, pMsg);
|
||||
|
||||
conn->hThrdIdx = pCtx->hThrdIdx;
|
||||
|
|
|
@ -238,12 +238,15 @@ void transCtxCleanup(STransCtx* ctx) {
|
|||
iter->freeFunc(iter->val);
|
||||
iter = taosHashIterate(ctx->args, iter);
|
||||
}
|
||||
|
||||
taosHashCleanup(ctx->args);
|
||||
ctx->args = NULL;
|
||||
}
|
||||
|
||||
void transCtxMerge(STransCtx* dst, STransCtx* src) {
|
||||
if (dst->args == NULL) {
|
||||
dst->args = src->args;
|
||||
dst->brokenVal = src->brokenVal;
|
||||
src->args = NULL;
|
||||
return;
|
||||
}
|
||||
|
@ -271,9 +274,20 @@ void* transCtxDumpVal(STransCtx* ctx, int32_t key) {
|
|||
if (cVal == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
char* ret = taosMemoryCalloc(1, cVal->len);
|
||||
memcpy(ret, (char*)cVal->val, cVal->len);
|
||||
return (void*)ret;
|
||||
void* ret = NULL;
|
||||
(*cVal->clone)(cVal->val, &ret);
|
||||
return ret;
|
||||
}
|
||||
void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType) {
|
||||
void* ret = NULL;
|
||||
if (ctx->brokenVal.clone == NULL) {
|
||||
return ret;
|
||||
}
|
||||
(*ctx->brokenVal.clone)(ctx->brokenVal.val, &ret);
|
||||
|
||||
*msgType = ctx->brokenVal.msgType;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)) {
|
||||
|
@ -281,6 +295,9 @@ void transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)) {
|
|||
queue->freeFunc = freeFunc;
|
||||
}
|
||||
bool transQueuePush(STransQueue* queue, void* arg) {
|
||||
if (queue->q == NULL) {
|
||||
return true;
|
||||
}
|
||||
taosArrayPush(queue->q, &arg);
|
||||
if (taosArrayGetSize(queue->q) > 1) {
|
||||
return false;
|
||||
|
@ -288,23 +305,47 @@ bool transQueuePush(STransQueue* queue, void* arg) {
|
|||
return true;
|
||||
}
|
||||
void* transQueuePop(STransQueue* queue) {
|
||||
if (taosArrayGetSize(queue->q) == 0) {
|
||||
if (queue->q == NULL || taosArrayGetSize(queue->q) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
void* ptr = taosArrayGetP(queue->q, 0);
|
||||
taosArrayRemove(queue->q, 0);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* transQueueGet(STransQueue* queue) {
|
||||
if (taosArrayGetSize(queue->q) == 0) {
|
||||
int32_t transQueueSize(STransQueue* queue) {
|
||||
if (queue->q == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return taosArrayGetSize(queue->q);
|
||||
}
|
||||
void* transQueueGet(STransQueue* queue, int i) {
|
||||
if (queue->q == NULL || taosArrayGetSize(queue->q) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
void* ptr = taosArrayGetP(queue->q, 0);
|
||||
if (i >= taosArrayGetSize(queue->q)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void* ptr = taosArrayGetP(queue->q, i);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void* transQueueRm(STransQueue* queue, int i) {
|
||||
if (queue->q == NULL || taosArrayGetSize(queue->q) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (i >= taosArrayGetSize(queue->q)) {
|
||||
return NULL;
|
||||
}
|
||||
void* ptr = taosArrayGetP(queue->q, i);
|
||||
taosArrayRemove(queue->q, i);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
bool transQueueEmpty(STransQueue* queue) {
|
||||
//
|
||||
if (queue->q == NULL) {
|
||||
return true;
|
||||
}
|
||||
return taosArrayGetSize(queue->q) == 0;
|
||||
}
|
||||
void transQueueClear(STransQueue* queue) {
|
||||
|
|
|
@ -101,7 +101,7 @@ static const char* notify = "a";
|
|||
transFreeMsg(transContFromHead((char*)head)); \
|
||||
tTrace("server conn %p received release request", conn); \
|
||||
\
|
||||
STransMsg tmsg = {.handle = (void*)conn, .code = 0}; \
|
||||
STransMsg tmsg = {.code = 0, .handle = (void*)conn, .ahandle = NULL}; \
|
||||
SSrvMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSrvMsg)); \
|
||||
srvMsg->msg = tmsg; \
|
||||
srvMsg->type = Release; \
|
||||
|
@ -190,7 +190,7 @@ static void uvHandleReq(SSrvConn* pConn) {
|
|||
transMsg.pCont = pHead->content;
|
||||
transMsg.msgType = pHead->msgType;
|
||||
transMsg.code = pHead->code;
|
||||
transMsg.ahandle = NULL;
|
||||
transMsg.ahandle = (void*)pHead->ahandle;
|
||||
transMsg.handle = NULL;
|
||||
|
||||
transClearBuffer(&pConn->readBuf);
|
||||
|
@ -199,6 +199,7 @@ static void uvHandleReq(SSrvConn* pConn) {
|
|||
if (pHead->persist == 1) {
|
||||
pConn->status = ConnAcquire;
|
||||
transRefSrvHandle(pConn);
|
||||
tDebug("server conn %p acquired by server app", pConn);
|
||||
}
|
||||
}
|
||||
if (pConn->status == ConnNormal && pHead->noResp == 0) {
|
||||
|
@ -279,7 +280,7 @@ void uvOnSendCb(uv_write_t* req, int status) {
|
|||
destroySmsg(msg);
|
||||
// send second data, just use for push
|
||||
if (!transQueueEmpty(&conn->srvMsgs)) {
|
||||
msg = (SSrvMsg*)transQueueGet(&conn->srvMsgs);
|
||||
msg = (SSrvMsg*)transQueueGet(&conn->srvMsgs, 0);
|
||||
if (msg->type == Register && conn->status == ConnAcquire) {
|
||||
conn->regArg.notifyCount = 0;
|
||||
conn->regArg.init = 1;
|
||||
|
@ -291,6 +292,11 @@ void uvOnSendCb(uv_write_t* req, int status) {
|
|||
}
|
||||
transQueuePop(&conn->srvMsgs);
|
||||
taosMemoryFree(msg);
|
||||
|
||||
msg = (SSrvMsg*)transQueueGet(&conn->srvMsgs, 0);
|
||||
if (msg != NULL) {
|
||||
uvStartSendRespInternal(msg);
|
||||
}
|
||||
} else {
|
||||
uvStartSendRespInternal(msg);
|
||||
}
|
||||
|
@ -321,6 +327,7 @@ static void uvPrepareSendData(SSrvMsg* smsg, uv_buf_t* wb) {
|
|||
pMsg->contLen = 0;
|
||||
}
|
||||
STransMsgHead* pHead = transHeadFromCont(pMsg->pCont);
|
||||
pHead->ahandle = (uint64_t)pMsg->ahandle;
|
||||
|
||||
// pHead->secured = pMsg->code == 0 ? 1 : 0; //
|
||||
if (!pConn->secured) {
|
||||
|
@ -553,7 +560,7 @@ static bool addHandleToWorkloop(void* arg) {
|
|||
// conn set
|
||||
QUEUE_INIT(&pThrd->conn);
|
||||
|
||||
pThrd->asyncPool = transCreateAsyncPool(pThrd->loop, 4, pThrd, uvWorkerAsyncCb);
|
||||
pThrd->asyncPool = transCreateAsyncPool(pThrd->loop, 5, pThrd, uvWorkerAsyncCb);
|
||||
uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb);
|
||||
return true;
|
||||
}
|
||||
|
@ -617,8 +624,6 @@ static void destroyConn(SSrvConn* conn, bool clear) {
|
|||
return;
|
||||
}
|
||||
transDestroyBuffer(&conn->readBuf);
|
||||
|
||||
transQueueDestroy(&conn->srvMsgs);
|
||||
if (clear) {
|
||||
tTrace("server conn %p to be destroyed", conn);
|
||||
uv_shutdown_t* req = taosMemoryMalloc(sizeof(uv_shutdown_t));
|
||||
|
@ -634,11 +639,13 @@ static void uvDestroyConn(uv_handle_t* handle) {
|
|||
|
||||
tDebug("server conn %p destroy", conn);
|
||||
uv_timer_stop(&conn->pTimer);
|
||||
transQueueDestroy(&conn->srvMsgs);
|
||||
QUEUE_REMOVE(&conn->queue);
|
||||
taosMemoryFree(conn->pTcp);
|
||||
// taosMemoryFree(conn);
|
||||
|
||||
if (thrd->quit && QUEUE_IS_EMPTY(&thrd->conn)) {
|
||||
tTrace("work thread quit");
|
||||
uv_loop_close(thrd->loop);
|
||||
uv_stop(thrd->loop);
|
||||
}
|
||||
|
@ -700,12 +707,12 @@ End:
|
|||
return NULL;
|
||||
}
|
||||
void uvHandleQuit(SSrvMsg* msg, SWorkThrdObj* thrd) {
|
||||
thrd->quit = true;
|
||||
if (QUEUE_IS_EMPTY(&thrd->conn)) {
|
||||
uv_loop_close(thrd->loop);
|
||||
uv_stop(thrd->loop);
|
||||
} else {
|
||||
destroyAllConn(thrd);
|
||||
thrd->quit = true;
|
||||
}
|
||||
taosMemoryFree(msg);
|
||||
}
|
||||
|
@ -725,7 +732,7 @@ void uvHandleRelease(SSrvMsg* msg, SWorkThrdObj* thrd) {
|
|||
}
|
||||
void uvHandleResp(SSrvMsg* msg, SWorkThrdObj* thrd) {
|
||||
// send msg to client
|
||||
tDebug("server conn %p start to send resp", msg->pConn);
|
||||
tDebug("server conn %p start to send resp (2/2)", msg->pConn);
|
||||
uvStartSendResp(msg);
|
||||
}
|
||||
void uvHandleRegister(SSrvMsg* msg, SWorkThrdObj* thrd) {
|
||||
|
@ -735,9 +742,11 @@ void uvHandleRegister(SSrvMsg* msg, SWorkThrdObj* thrd) {
|
|||
if (!transQueuePush(&conn->srvMsgs, msg)) {
|
||||
return;
|
||||
}
|
||||
transQueuePop(&conn->srvMsgs);
|
||||
conn->regArg.notifyCount = 0;
|
||||
conn->regArg.init = 1;
|
||||
conn->regArg.msg = msg->msg;
|
||||
tDebug("server conn %p register brokenlink callback succ", conn);
|
||||
|
||||
if (conn->broken) {
|
||||
STrans* pTransInst = conn->pTransInst;
|
||||
|
@ -766,15 +775,16 @@ void sendQuitToWorkThrd(SWorkThrdObj* pThrd) {
|
|||
void transCloseServer(void* arg) {
|
||||
// impl later
|
||||
SServerObj* srv = arg;
|
||||
for (int i = 0; i < srv->numOfThreads; i++) {
|
||||
sendQuitToWorkThrd(srv->pThreadObj[i]);
|
||||
destroyWorkThrd(srv->pThreadObj[i]);
|
||||
}
|
||||
|
||||
tDebug("send quit msg to accept thread");
|
||||
uv_async_send(srv->pAcceptAsync);
|
||||
taosThreadJoin(srv->thread, NULL);
|
||||
|
||||
for (int i = 0; i < srv->numOfThreads; i++) {
|
||||
sendQuitToWorkThrd(srv->pThreadObj[i]);
|
||||
destroyWorkThrd(srv->pThreadObj[i]);
|
||||
}
|
||||
|
||||
taosMemoryFree(srv->pThreadObj);
|
||||
taosMemoryFree(srv->pAcceptAsync);
|
||||
taosMemoryFree(srv->loop);
|
||||
|
@ -815,7 +825,7 @@ void transReleaseSrvHandle(void* handle) {
|
|||
SSrvConn* pConn = handle;
|
||||
SWorkThrdObj* pThrd = pConn->hostThrd;
|
||||
|
||||
STransMsg tmsg = {.handle = handle, .code = 0};
|
||||
STransMsg tmsg = {.code = 0, .handle = handle, .ahandle = NULL};
|
||||
|
||||
SSrvMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSrvMsg));
|
||||
srvMsg->msg = tmsg;
|
||||
|
@ -831,12 +841,15 @@ void transSendResponse(const STransMsg* pMsg) {
|
|||
}
|
||||
SSrvConn* pConn = pMsg->handle;
|
||||
SWorkThrdObj* pThrd = pConn->hostThrd;
|
||||
if (pThrd->quit) {
|
||||
return;
|
||||
}
|
||||
|
||||
SSrvMsg* srvMsg = taosMemoryCalloc(1, sizeof(SSrvMsg));
|
||||
srvMsg->pConn = pConn;
|
||||
srvMsg->msg = *pMsg;
|
||||
srvMsg->type = Normal;
|
||||
tTrace("server conn %p start to send resp", pConn);
|
||||
tTrace("server conn %p start to send resp (1/2)", pConn);
|
||||
transSendAsync(pThrd->asyncPool, &srvMsg->q);
|
||||
}
|
||||
void transRegisterMsg(const STransMsg* msg) {
|
||||
|
|
|
@ -368,8 +368,9 @@ TEST_F(TransEnv, srvReleaseHandle) {
|
|||
tr->SetSrvContinueSend(processReleaseHandleCb);
|
||||
// tr->Restart(processReleaseHandleCb);
|
||||
void * handle = NULL;
|
||||
for (int i = 0; i < 1; i++) {
|
||||
SRpcMsg req = {0};
|
||||
for (int i = 0; i < 1; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.handle = resp.handle;
|
||||
req.persistHandle = 1;
|
||||
req.msgType = 1;
|
||||
|
@ -383,8 +384,9 @@ TEST_F(TransEnv, srvReleaseHandle) {
|
|||
}
|
||||
TEST_F(TransEnv, cliReleaseHandleExcept) {
|
||||
SRpcMsg resp = {0};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
SRpcMsg req = {0};
|
||||
for (int i = 0; i < 3; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.handle = resp.handle;
|
||||
req.persistHandle = 1;
|
||||
req.msgType = 1;
|
||||
|
@ -403,8 +405,10 @@ TEST_F(TransEnv, cliReleaseHandleExcept) {
|
|||
}
|
||||
TEST_F(TransEnv, srvContinueSend) {
|
||||
tr->SetSrvContinueSend(processContinueSend);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
SRpcMsg req = {0}, resp = {0};
|
||||
for (int i = 0; i < 10; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
memset(&resp, 0, sizeof(resp));
|
||||
req.msgType = 1;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
req.contLen = 10;
|
||||
|
@ -417,8 +421,9 @@ TEST_F(TransEnv, srvPersistHandleExcept) {
|
|||
tr->SetSrvContinueSend(processContinueSend);
|
||||
// tr->SetCliPersistFp(cliPersistHandle);
|
||||
SRpcMsg resp = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
SRpcMsg req = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.handle = resp.handle;
|
||||
req.msgType = 1;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
|
@ -436,8 +441,9 @@ TEST_F(TransEnv, srvPersistHandleExcept) {
|
|||
TEST_F(TransEnv, cliPersistHandleExcept) {
|
||||
tr->SetSrvContinueSend(processContinueSend);
|
||||
SRpcMsg resp = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
SRpcMsg req = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.handle = resp.handle;
|
||||
req.msgType = 1;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
|
@ -459,8 +465,9 @@ TEST_F(TransEnv, multiCliPersistHandleExcept) {
|
|||
TEST_F(TransEnv, queryExcept) {
|
||||
tr->SetSrvContinueSend(processRegisterFailure);
|
||||
SRpcMsg resp = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
SRpcMsg req = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.handle = resp.handle;
|
||||
req.persistHandle = 1;
|
||||
req.msgType = 1;
|
||||
|
@ -477,8 +484,9 @@ TEST_F(TransEnv, queryExcept) {
|
|||
}
|
||||
TEST_F(TransEnv, noResp) {
|
||||
SRpcMsg resp = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
SRpcMsg req = {0};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
memset(&req, 0, sizeof(req));
|
||||
req.noResp = 1;
|
||||
req.msgType = 1;
|
||||
req.pCont = rpcMallocCont(10);
|
||||
|
|
|
@ -156,17 +156,15 @@ TEST_F(TransCtxEnv, mergeTest) {
|
|||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
val1.len = 12;
|
||||
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
val1.len = 12;
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
|
@ -178,17 +176,15 @@ TEST_F(TransCtxEnv, mergeTest) {
|
|||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
val1.len = 12;
|
||||
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
val1.len = 12;
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
|
@ -202,19 +198,17 @@ TEST_F(TransCtxEnv, mergeTest) {
|
|||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree};
|
||||
val1.val = taosMemoryCalloc(1, 11);
|
||||
memcpy(val1.val, val.c_str(), val.size());
|
||||
val1.len = 11;
|
||||
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = {.val = NULL, .len = 0, .freeFunc = taosMemoryFree};
|
||||
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree};
|
||||
val1.val = taosMemoryCalloc(1, 11);
|
||||
memcpy(val1.val, val.c_str(), val.size());
|
||||
val1.len = 11;
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
|
|
|
@ -37,8 +37,7 @@ void* tmemmem(char* haystack, int hlen, char* needle, int nlen) {
|
|||
}
|
||||
|
||||
limit = haystack + hlen - nlen + 1;
|
||||
while ((haystack = (char*)memchr(
|
||||
haystack, needle[0], limit - haystack)) != NULL) {
|
||||
while ((haystack = (char*)memchr(haystack, needle[0], limit - haystack)) != NULL) {
|
||||
if (memcmp(haystack, needle, nlen) == 0) {
|
||||
return haystack;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "walInt.h"
|
||||
#include "taoserror.h"
|
||||
#include "walInt.h"
|
||||
|
||||
SWalReadHandle *walOpenReadHandle(SWal *pWal) {
|
||||
SWalReadHandle *pRead = taosMemoryMalloc(sizeof(SWalReadHandle));
|
||||
|
@ -92,6 +92,7 @@ static int32_t walReadChangeFile(SWalReadHandle *pRead, int64_t fileFirstVer) {
|
|||
walBuildIdxName(pRead->pWal, fileFirstVer, fnameStr);
|
||||
TdFilePtr pIdxTFile = taosOpenFile(fnameStr, TD_FILE_READ);
|
||||
if (pIdxTFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -152,6 +153,7 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) {
|
|||
}
|
||||
code = walValidHeadCksum(pRead->pHead);
|
||||
if (code != 0) {
|
||||
wError("unexpected wal log version: % " PRId64 ", since head checksum not passed", ver);
|
||||
terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
|
||||
return -1;
|
||||
}
|
||||
|
@ -169,7 +171,8 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) {
|
|||
}
|
||||
|
||||
if (pRead->pHead->head.version != ver) {
|
||||
wError("unexpected wal log version: %" PRId64 ", read request version:%" PRId64 "", pRead->pHead->head.version, ver);
|
||||
wError("unexpected wal log version: %" PRId64 ", read request version:%" PRId64 "", pRead->pHead->head.version,
|
||||
ver);
|
||||
pRead->curVersion = -1;
|
||||
terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
|
||||
return -1;
|
||||
|
@ -177,7 +180,7 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) {
|
|||
|
||||
code = walValidBodyCksum(pRead->pHead);
|
||||
if (code != 0) {
|
||||
wError("unexpected wal log version: checksum not passed");
|
||||
wError("unexpected wal log version: % " PRId64 ", since body checksum not passed", ver);
|
||||
pRead->curVersion = -1;
|
||||
terrno = TSDB_CODE_WAL_FILE_CORRUPTED;
|
||||
return -1;
|
||||
|
|
|
@ -253,7 +253,8 @@ static int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int64_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, int32_t bodyLen) {
|
||||
int64_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLogMeta syncMeta, const void *body,
|
||||
int32_t bodyLen) {
|
||||
if (pWal == NULL) return -1;
|
||||
int code = 0;
|
||||
|
||||
|
@ -296,6 +297,10 @@ int64_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, in
|
|||
int64_t offset = walGetCurFileOffset(pWal);
|
||||
pWal->writeHead.head.len = bodyLen;
|
||||
pWal->writeHead.head.msgType = msgType;
|
||||
|
||||
// sync info
|
||||
pWal->writeHead.head.syncMeta = syncMeta;
|
||||
|
||||
pWal->writeHead.cksumHead = walCalcHeadCksum(&pWal->writeHead);
|
||||
pWal->writeHead.cksumBody = walCalcBodyCksum(body, bodyLen);
|
||||
|
||||
|
@ -332,6 +337,15 @@ int64_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, in
|
|||
return 0;
|
||||
}
|
||||
|
||||
int64_t walWrite(SWal *pWal, int64_t index, tmsg_t msgType, const void *body, int32_t bodyLen) {
|
||||
SSyncLogMeta syncMeta = {
|
||||
.isWeek = -1,
|
||||
.seqNum = UINT64_MAX,
|
||||
.term = UINT64_MAX,
|
||||
};
|
||||
return walWriteWithSyncInfo(pWal, index, msgType, syncMeta, body, bodyLen);
|
||||
}
|
||||
|
||||
void walFsync(SWal *pWal, bool forceFsync) {
|
||||
if (forceFsync || (pWal->cfg.level == TAOS_WAL_FSYNC && pWal->cfg.fsyncPeriod == 0)) {
|
||||
wTrace("vgId:%d, fileId:%" PRId64 ".log, do fsync", pWal->cfg.vgId, walGetCurFileFirstVer(pWal));
|
||||
|
|
|
@ -26,7 +26,8 @@ SDiskSpace tsDataSpace = {0};
|
|||
SDiskSpace tsLogSpace = {0};
|
||||
SDiskSpace tsTempSpace = {0};
|
||||
char tsOsName[16] = {0};
|
||||
char tsTimezone[TD_TIMEZONE_LEN] = {0};
|
||||
char tsTimezoneStr[TD_TIMEZONE_LEN] = {0};
|
||||
enum TdTimezone tsTimezone = TdZeroZone;
|
||||
char tsLocale[TD_LOCALE_LEN] = {0};
|
||||
char tsCharset[TD_CHARSET_LEN] = {0};
|
||||
int8_t tsDaylight = 0;
|
||||
|
@ -37,11 +38,11 @@ int64_t tsStreamMax = 0;
|
|||
float tsNumOfCores = 0;
|
||||
int64_t tsTotalMemoryKB = 0;
|
||||
|
||||
void osInit() {
|
||||
void osDefaultInit() {
|
||||
taosSeedRand(taosSafeRand());
|
||||
taosGetSystemLocale(tsLocale, tsCharset);
|
||||
taosGetSystemTimezone(tsTimezone);
|
||||
taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight);
|
||||
taosGetSystemTimezone(tsTimezoneStr, &tsTimezone);
|
||||
taosSetSystemTimezone(tsTimezoneStr, tsTimezoneStr, &tsDaylight, &tsTimezone);
|
||||
taosGetSystemInfo();
|
||||
|
||||
// deadlock in query
|
||||
|
@ -105,4 +106,9 @@ void osCleanup() {}
|
|||
|
||||
bool osLogSpaceAvailable() { return tsLogSpace.reserved <= tsLogSpace.size.avail; }
|
||||
|
||||
void osSetTimezone(const char *timezone) { taosSetSystemTimezone(tsTimezone, tsTimezone, &tsDaylight); }
|
||||
void osSetTimezone(const char *timezone) { taosSetSystemTimezone(timezone, tsTimezoneStr, &tsDaylight, &tsTimezone); }
|
||||
|
||||
void osSetSystemLocale(const char *inLocale, const char *inCharSet) {
|
||||
memcpy(tsLocale, inLocale, strlen(inLocale) + 1);
|
||||
memcpy(tsCharset, inCharSet, strlen(inCharSet) + 1);
|
||||
}
|
||||
|
|
|
@ -16,17 +16,14 @@
|
|||
#define ALLOW_FORBID_FUNC
|
||||
#include "os.h"
|
||||
|
||||
#define USE_TD_MEMORY
|
||||
|
||||
#define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S')
|
||||
|
||||
#define TEST_SIZE 4
|
||||
#define TD_MEMORY_STACK_TRACE_DEPTH 10
|
||||
|
||||
typedef struct TdMemoryInfo
|
||||
{
|
||||
int32_t symbol;
|
||||
char **stackTrace;
|
||||
int32_t stackTraceDepth;
|
||||
void *stackTrace[TD_MEMORY_STACK_TRACE_DEPTH]; // gdb: disassemble /m 0xXXX
|
||||
int32_t memorySize;
|
||||
} *TdMemoryInfoPtr , TdMemoryInfo;
|
||||
|
||||
|
@ -36,7 +33,7 @@ typedef struct TdMemoryInfo
|
|||
|
||||
#include<execinfo.h>
|
||||
#define STACKCALL __attribute__((regparm(1), noinline))
|
||||
void **STACKCALL taosGetEBP(void) {
|
||||
void **STACKCALL taosGetEbp(void) {
|
||||
void **ebp = NULL;
|
||||
__asm__ __volatile__("mov %%rbp, %0;\n\t"
|
||||
: "=m"(ebp) /* output */
|
||||
|
@ -48,27 +45,27 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
|
|||
int32_t frame = 0;
|
||||
void **ebp;
|
||||
void **ret = NULL;
|
||||
unsigned long long func_frame_distance = 0;
|
||||
size_t func_frame_distance = 0;
|
||||
if (buffer != NULL && size > 0) {
|
||||
ebp = taosGetEBP();
|
||||
func_frame_distance = (unsigned long long)(*ebp) - (unsigned long long)ebp;
|
||||
ebp = taosGetEbp();
|
||||
func_frame_distance = (size_t)*ebp - (size_t)ebp;
|
||||
while (ebp && frame < size && (func_frame_distance < (1ULL << 24)) // assume function ebp more than 16M
|
||||
&& (func_frame_distance > 0)) {
|
||||
ret = ebp + 1;
|
||||
buffer[frame++] = *ret;
|
||||
ebp = (void **)(*ebp);
|
||||
func_frame_distance = (unsigned long long)(*ebp) - (unsigned long long)ebp;
|
||||
func_frame_distance = (size_t)*ebp - (size_t)ebp;
|
||||
}
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
#endif
|
||||
|
||||
char **taosBackTraceSymbols(int32_t *size) {
|
||||
void *buffer[20] = {NULL};
|
||||
*size = taosBackTrace(buffer, 10);
|
||||
return backtrace_symbols(buffer, *size);
|
||||
}
|
||||
// char **taosBackTraceSymbols(int32_t *size) {
|
||||
// void *buffer[20] = {NULL};
|
||||
// *size = taosBackTrace(buffer, 20);
|
||||
// return backtrace_symbols(buffer, *size);
|
||||
// }
|
||||
|
||||
void *taosMemoryMalloc(int32_t size) {
|
||||
void *tmp = malloc(size + sizeof(TdMemoryInfo));
|
||||
|
@ -77,7 +74,7 @@ void *taosMemoryMalloc(int32_t size) {
|
|||
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)tmp;
|
||||
pTdMemoryInfo->memorySize = size;
|
||||
pTdMemoryInfo->symbol = TD_MEMORY_SYMBOL;
|
||||
pTdMemoryInfo->stackTrace = taosBackTraceSymbols(&pTdMemoryInfo->stackTraceDepth);
|
||||
taosBackTrace(pTdMemoryInfo->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH);
|
||||
|
||||
return (char*)tmp + sizeof(TdMemoryInfo);
|
||||
}
|
||||
|
@ -90,7 +87,7 @@ void *taosMemoryCalloc(int32_t num, int32_t size) {
|
|||
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)tmp;
|
||||
pTdMemoryInfo->memorySize = memorySize;
|
||||
pTdMemoryInfo->symbol = TD_MEMORY_SYMBOL;
|
||||
pTdMemoryInfo->stackTrace = taosBackTraceSymbols(&pTdMemoryInfo->stackTraceDepth);
|
||||
taosBackTrace(pTdMemoryInfo->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH);
|
||||
|
||||
return (char*)tmp + sizeof(TdMemoryInfo);
|
||||
}
|
||||
|
@ -118,8 +115,8 @@ void taosMemoryFree(const void *ptr) {
|
|||
|
||||
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo));
|
||||
if(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL) {
|
||||
if(pTdMemoryInfo->stackTrace != NULL) free(pTdMemoryInfo->stackTrace);
|
||||
memset(pTdMemoryInfo, 0, sizeof(TdMemoryInfo));
|
||||
pTdMemoryInfo->memorySize = 0;
|
||||
// memset(pTdMemoryInfo, 0, sizeof(TdMemoryInfo));
|
||||
free(pTdMemoryInfo);
|
||||
} else {
|
||||
free((void*)ptr);
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue