Merge branch '3.0' of github.com:taosdata/TDengine into 3.0
This commit is contained in:
commit
384f226267
|
@ -25,7 +25,7 @@ int32_t init_env() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1");
|
||||
TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("error in create db, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
|
@ -82,7 +82,7 @@ int32_t create_stream() {
|
|||
/*const char* sql = "select sum(k) from tu1 interval(10m)";*/
|
||||
/*pRes = tmq_create_stream(pConn, "stream1", "out1", sql);*/
|
||||
pRes = taos_query(
|
||||
pConn, "create stream stream1 trigger at_once into outstb as select _wstartts, sum(k) from tu1 interval(10m)");
|
||||
pConn, "create stream stream1 trigger at_once into outstb as select _wstartts, sum(k) from st1 interval(10m)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create stream stream1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
|
|
|
@ -77,7 +77,9 @@ typedef struct SDataBlockInfo {
|
|||
int16_t numOfCols;
|
||||
int16_t hasVarCol;
|
||||
int32_t capacity;
|
||||
EStreamType type;
|
||||
// TODO: optimize and remove following
|
||||
int32_t childId; // used for stream, do not serialize
|
||||
EStreamType type; // used for stream, do not serialize
|
||||
} SDataBlockInfo;
|
||||
|
||||
typedef struct SSDataBlock {
|
||||
|
@ -105,14 +107,14 @@ typedef struct SColumnInfoData {
|
|||
} SColumnInfoData;
|
||||
|
||||
typedef struct SQueryTableDataCond {
|
||||
//STimeWindow twindow;
|
||||
// STimeWindow twindow;
|
||||
int32_t order; // desc|asc order to iterate the data block
|
||||
int32_t numOfCols;
|
||||
SColumnInfo *colList;
|
||||
SColumnInfo* colList;
|
||||
bool loadExternalRows; // load external rows or not
|
||||
int32_t type; // data block load type:
|
||||
int32_t numOfTWindows;
|
||||
STimeWindow *twindows;
|
||||
STimeWindow* twindows;
|
||||
} SQueryTableDataCond;
|
||||
|
||||
void* blockDataDestroy(SSDataBlock* pBlock);
|
||||
|
@ -205,7 +207,7 @@ typedef struct {
|
|||
const char* key;
|
||||
int32_t keyLen;
|
||||
uint8_t type;
|
||||
union{
|
||||
union {
|
||||
const char* value;
|
||||
int64_t i;
|
||||
uint64_t u;
|
||||
|
|
|
@ -933,6 +933,7 @@ typedef struct {
|
|||
int64_t numOfProcessedFetch;
|
||||
int64_t numOfProcessedDrop;
|
||||
int64_t numOfProcessedHb;
|
||||
int64_t numOfProcessedDelete;
|
||||
int64_t cacheDataSize;
|
||||
int64_t numOfQueryInQueue;
|
||||
int64_t numOfFetchInQueue;
|
||||
|
@ -1126,8 +1127,8 @@ typedef struct {
|
|||
STableMetaRsp* pMeta;
|
||||
} SMAlterStbRsp;
|
||||
|
||||
int32_t tEncodeSMAlterStbRsp(SEncoder *pEncoder, const SMAlterStbRsp *pRsp);
|
||||
int32_t tDecodeSMAlterStbRsp(SDecoder *pDecoder, SMAlterStbRsp *pRsp);
|
||||
int32_t tEncodeSMAlterStbRsp(SEncoder* pEncoder, const SMAlterStbRsp* pRsp);
|
||||
int32_t tDecodeSMAlterStbRsp(SDecoder* pDecoder, SMAlterStbRsp* pRsp);
|
||||
void tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp);
|
||||
|
||||
int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp);
|
||||
|
@ -2319,7 +2320,7 @@ typedef struct {
|
|||
int64_t sliding;
|
||||
char* expr; // sma expression
|
||||
char* tagsFilter;
|
||||
SVgEpSet vgEpSet[];
|
||||
SVgEpSet* pVgEpSet;
|
||||
} STSma; // Time-range-wise SMA
|
||||
|
||||
typedef STSma SVCreateTSmaReq;
|
||||
|
@ -2689,20 +2690,20 @@ int32_t tEncodeSVSubmitReq(SEncoder* pCoder, const SVSubmitReq* pReq);
|
|||
int32_t tDecodeSVSubmitReq(SDecoder* pCoder, SVSubmitReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int64_t delUid;
|
||||
int64_t tbUid; // super/child/normal table
|
||||
int8_t type; // table type
|
||||
int16_t nWnds;
|
||||
char* tbFullName;
|
||||
char* subPlan;
|
||||
STimeWindow wnds[];
|
||||
SMsgHead header;
|
||||
uint64_t sId;
|
||||
uint64_t queryId;
|
||||
uint64_t taskId;
|
||||
uint32_t sqlLen;
|
||||
uint32_t phyLen;
|
||||
char* sql;
|
||||
char* msg;
|
||||
} SVDeleteReq;
|
||||
|
||||
int32_t tEncodeSVDeleteReq(SEncoder* pCoder, const SVDeleteReq* pReq);
|
||||
int32_t tDecodeSVDeleteReq(SDecoder* pCoder, SVDeleteReq* pReq);
|
||||
int32_t tSerializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq);
|
||||
int32_t tDeserializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t code;
|
||||
int64_t affectedRows;
|
||||
} SVDeleteRsp;
|
||||
|
||||
|
|
|
@ -187,6 +187,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_VND_STREAM_TRIGGER, "vnode-stream-trigger", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_RUN, "vnode-stream-task-run", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_DISPATCH, "vnode-stream-task-dispatch", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_DISPATCH_WRITE, "vnode-stream-task-dispatch-write", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TASK_RECOVER, "vnode-stream-task-recover", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_SMA, "vnode-create-sma", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_SMA, "vnode-cancel-sma", NULL, NULL)
|
||||
|
|
|
@ -32,6 +32,18 @@ extern "C" {
|
|||
struct SDataSink;
|
||||
struct SSDataBlock;
|
||||
|
||||
typedef struct SDeleterRes {
|
||||
uint64_t uid;
|
||||
SArray* uidList;
|
||||
int64_t skey;
|
||||
int64_t ekey;
|
||||
int64_t affectedRows;
|
||||
} SDeleterRes;
|
||||
|
||||
typedef struct SDeleterParam {
|
||||
SArray* pUidList;
|
||||
} SDeleterParam;
|
||||
|
||||
typedef struct SDataSinkStat {
|
||||
uint64_t cachedSize;
|
||||
} SDataSinkStat;
|
||||
|
@ -64,7 +76,7 @@ typedef struct SOutputData {
|
|||
* @param pHandle output
|
||||
* @return error code
|
||||
*/
|
||||
int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle);
|
||||
int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void* pParam);
|
||||
|
||||
int32_t dsDataSinkGetCacheSize(SDataSinkStat *pStat);
|
||||
|
||||
|
|
|
@ -195,6 +195,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_LOGIC_PLAN_FILL,
|
||||
QUERY_NODE_LOGIC_PLAN_SORT,
|
||||
QUERY_NODE_LOGIC_PLAN_PARTITION,
|
||||
QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC,
|
||||
QUERY_NODE_LOGIC_SUBPLAN,
|
||||
QUERY_NODE_LOGIC_PLAN,
|
||||
|
||||
|
@ -211,7 +212,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_PHYSICAL_PLAN_MERGE,
|
||||
QUERY_NODE_PHYSICAL_PLAN_SORT,
|
||||
QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_SORT_MERGE_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL,
|
||||
|
@ -222,6 +223,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE_WINDOW,
|
||||
QUERY_NODE_PHYSICAL_PLAN_PARTITION,
|
||||
QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC,
|
||||
QUERY_NODE_PHYSICAL_PLAN_DISPATCH,
|
||||
QUERY_NODE_PHYSICAL_PLAN_INSERT,
|
||||
QUERY_NODE_PHYSICAL_PLAN_DELETE,
|
||||
|
|
|
@ -42,6 +42,7 @@ typedef struct SScanLogicNode {
|
|||
SNodeList* pScanPseudoCols;
|
||||
int8_t tableType;
|
||||
uint64_t tableId;
|
||||
uint64_t stableId;
|
||||
SVgroupsInfo* pVgroupList;
|
||||
EScanType scanType;
|
||||
uint8_t scanSeq[2]; // first is scan count, and second is reverse scan count
|
||||
|
@ -86,6 +87,11 @@ typedef struct SProjectLogicNode {
|
|||
int64_t soffset;
|
||||
} SProjectLogicNode;
|
||||
|
||||
typedef struct SIndefRowsFuncLogicNode {
|
||||
SLogicNode node;
|
||||
SNodeList* pVectorFuncs;
|
||||
} SIndefRowsFuncLogicNode;
|
||||
|
||||
typedef enum EModifyTableType { MODIFY_TABLE_TYPE_INSERT = 1, MODIFY_TABLE_TYPE_DELETE } EModifyTableType;
|
||||
|
||||
typedef struct SVnodeModifyLogicNode {
|
||||
|
@ -94,7 +100,7 @@ typedef struct SVnodeModifyLogicNode {
|
|||
int32_t msgType;
|
||||
SArray* pDataBlocks;
|
||||
SVgDataBlocks* pVgDataBlocks;
|
||||
SNode* pModifyRows; // SColumnNode
|
||||
SNode* pAffectedRows; // SColumnNode
|
||||
uint64_t tableId;
|
||||
int8_t tableType; // table type
|
||||
char tableFName[TSDB_TABLE_FNAME_LEN];
|
||||
|
@ -109,6 +115,7 @@ typedef struct SExchangeLogicNode {
|
|||
typedef struct SMergeLogicNode {
|
||||
SLogicNode node;
|
||||
SNodeList* pMergeKeys;
|
||||
SNodeList* pInputs;
|
||||
int32_t numOfChannels;
|
||||
int32_t srcGroupId;
|
||||
} SMergeLogicNode;
|
||||
|
@ -117,7 +124,7 @@ typedef enum EWindowType { WINDOW_TYPE_INTERVAL = 1, WINDOW_TYPE_SESSION, WINDOW
|
|||
|
||||
typedef enum EIntervalAlgorithm {
|
||||
INTERVAL_ALGO_HASH = 1,
|
||||
INTERVAL_ALGO_SORT_MERGE,
|
||||
INTERVAL_ALGO_MERGE,
|
||||
INTERVAL_ALGO_STREAM_FINAL,
|
||||
INTERVAL_ALGO_STREAM_SEMI,
|
||||
INTERVAL_ALGO_STREAM_SINGLE,
|
||||
|
@ -220,6 +227,7 @@ typedef struct SScanPhysiNode {
|
|||
SNodeList* pScanCols;
|
||||
SNodeList* pScanPseudoCols;
|
||||
uint64_t uid; // unique id of the table
|
||||
uint64_t suid;
|
||||
int8_t tableType;
|
||||
SName tableName;
|
||||
} SScanPhysiNode;
|
||||
|
@ -264,6 +272,12 @@ typedef struct SProjectPhysiNode {
|
|||
int64_t soffset;
|
||||
} SProjectPhysiNode;
|
||||
|
||||
typedef struct SIndefRowsFuncPhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pExprs;
|
||||
SNodeList* pVectorFuncs;
|
||||
} SIndefRowsFuncPhysiNode;
|
||||
|
||||
typedef struct SJoinPhysiNode {
|
||||
SPhysiNode node;
|
||||
EJoinType joinType;
|
||||
|
@ -296,6 +310,7 @@ typedef struct SExchangePhysiNode {
|
|||
typedef struct SMergePhysiNode {
|
||||
SPhysiNode node;
|
||||
SNodeList* pMergeKeys;
|
||||
SNodeList* pTargets;
|
||||
int32_t numOfChannels;
|
||||
int32_t srcGroupId;
|
||||
} SMergePhysiNode;
|
||||
|
@ -319,7 +334,7 @@ typedef struct SIntervalPhysiNode {
|
|||
int8_t slidingUnit;
|
||||
} SIntervalPhysiNode;
|
||||
|
||||
typedef SIntervalPhysiNode SSortMergeIntervalPhysiNode;
|
||||
typedef SIntervalPhysiNode SMergeIntervalPhysiNode;
|
||||
typedef SIntervalPhysiNode SStreamIntervalPhysiNode;
|
||||
typedef SIntervalPhysiNode SStreamFinalIntervalPhysiNode;
|
||||
typedef SIntervalPhysiNode SStreamSemiIntervalPhysiNode;
|
||||
|
@ -388,6 +403,7 @@ typedef struct SDataDeleterNode {
|
|||
int8_t tableType; // table type
|
||||
char tableFName[TSDB_TABLE_FNAME_LEN];
|
||||
STimeWindow deleteTimeRange;
|
||||
SNode* pAffectedRows;
|
||||
} SDataDeleterNode;
|
||||
|
||||
typedef struct SSubplan {
|
||||
|
|
|
@ -224,7 +224,7 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
|||
#define NEED_SCHEDULER_RETRY_ERROR(_code) \
|
||||
((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL || (_code) == TSDB_CODE_SCH_TIMEOUT_ERROR)
|
||||
|
||||
#define REQUEST_MAX_TRY_TIMES 1
|
||||
#define REQUEST_TOTAL_EXEC_TIMES 2
|
||||
|
||||
#define qFatal(...) \
|
||||
do { \
|
||||
|
|
|
@ -31,7 +31,12 @@ enum {
|
|||
NODE_TYPE_MNODE,
|
||||
};
|
||||
|
||||
|
||||
typedef struct SDeleteRes {
|
||||
uint64_t uid;
|
||||
SArray* uidList;
|
||||
int64_t skey;
|
||||
int64_t ekey;
|
||||
} SDeleteRes;
|
||||
|
||||
typedef struct SQWorkerCfg {
|
||||
uint32_t maxSchedulerNum;
|
||||
|
@ -47,6 +52,7 @@ typedef struct {
|
|||
uint64_t fetchProcessed;
|
||||
uint64_t dropProcessed;
|
||||
uint64_t hbProcessed;
|
||||
uint64_t deleteProcessed;
|
||||
|
||||
uint64_t numOfQueryInQueue;
|
||||
uint64_t numOfFetchInQueue;
|
||||
|
@ -74,6 +80,8 @@ int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int6
|
|||
|
||||
int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_t ts);
|
||||
|
||||
int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *pRsp, SDeleteRes *pRes);
|
||||
|
||||
void qWorkerDestroy(void **qWorkerMgmt);
|
||||
|
||||
int32_t qWorkerGetStat(SReadHandle *handle, void *qWorkerMgmt, SQWorkerStat *pStat);
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _TSTREAM_H_
|
||||
#define _TSTREAM_H_
|
||||
#ifndef _STREAM_H_
|
||||
#define _STREAM_H_
|
||||
|
||||
typedef struct SStreamTask SStreamTask;
|
||||
|
||||
|
@ -39,6 +39,7 @@ enum {
|
|||
TASK_INPUT_STATUS__NORMAL = 1,
|
||||
TASK_INPUT_STATUS__BLOCKED,
|
||||
TASK_INPUT_STATUS__RECOVER,
|
||||
TASK_INPUT_STATUS__PROCESSING,
|
||||
TASK_INPUT_STATUS__STOP,
|
||||
TASK_INPUT_STATUS__FAILED,
|
||||
};
|
||||
|
@ -60,6 +61,10 @@ enum {
|
|||
STREAM_INPUT__CHECKPOINT,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
} SStreamQueueItem;
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
int64_t ver;
|
||||
|
@ -80,55 +85,51 @@ typedef struct {
|
|||
int8_t type;
|
||||
} SStreamCheckpoint;
|
||||
|
||||
enum {
|
||||
STREAM_QUEUE__SUCESS = 1,
|
||||
STREAM_QUEUE__FAILED,
|
||||
STREAM_QUEUE__PROCESSING,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
STaosQueue* queue;
|
||||
STaosQall* qall;
|
||||
void* qItem;
|
||||
int8_t failed;
|
||||
} SStreamQ;
|
||||
int8_t status;
|
||||
} SStreamQueue;
|
||||
|
||||
static FORCE_INLINE void* streamQCurItem(SStreamQ* queue) {
|
||||
//
|
||||
return queue->qItem;
|
||||
SStreamQueue* streamQueueOpen();
|
||||
void streamQueueClose(SStreamQueue* queue);
|
||||
|
||||
static FORCE_INLINE void streamQueueProcessSuccess(SStreamQueue* queue) {
|
||||
ASSERT(atomic_load_8(&queue->status) == STREAM_QUEUE__PROCESSING);
|
||||
queue->qItem = NULL;
|
||||
atomic_store_8(&queue->status, STREAM_QUEUE__SUCESS);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* streamQNextItem(SStreamQ* queue) {
|
||||
int8_t failed = atomic_load_8(&queue->failed);
|
||||
if (failed) {
|
||||
static FORCE_INLINE void streamQueueProcessFail(SStreamQueue* queue) {
|
||||
ASSERT(atomic_load_8(&queue->status) == STREAM_QUEUE__PROCESSING);
|
||||
atomic_store_8(&queue->status, STREAM_QUEUE__FAILED);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void* streamQueueCurItem(SStreamQueue* queue) { return queue->qItem; }
|
||||
|
||||
static FORCE_INLINE void* streamQueueNextItem(SStreamQueue* queue) {
|
||||
int8_t dequeueFlag = atomic_exchange_8(&queue->status, STREAM_QUEUE__PROCESSING);
|
||||
if (dequeueFlag == STREAM_QUEUE__FAILED) {
|
||||
ASSERT(queue->qItem != NULL);
|
||||
return streamQCurItem(queue);
|
||||
return streamQueueCurItem(queue);
|
||||
} else {
|
||||
taosGetQitem(queue->qall, &queue->qItem);
|
||||
if (queue->qItem == NULL) {
|
||||
taosReadAllQitems(queue->queue, queue->qall);
|
||||
taosGetQitem(queue->qall, &queue->qItem);
|
||||
}
|
||||
return streamQCurItem(queue);
|
||||
return streamQueueCurItem(queue);
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE void streamQSetFail(SStreamQ* queue) { atomic_store_8(&queue->failed, 1); }
|
||||
|
||||
static FORCE_INLINE void streamQSetSuccess(SStreamQ* queue) { atomic_store_8(&queue->failed, 0); }
|
||||
|
||||
static FORCE_INLINE SStreamDataSubmit* streamDataSubmitNew(SSubmitReq* pReq) {
|
||||
SStreamDataSubmit* pDataSubmit = (SStreamDataSubmit*)taosAllocateQitem(sizeof(SStreamDataSubmit), DEF_QITEM);
|
||||
if (pDataSubmit == NULL) return NULL;
|
||||
pDataSubmit->dataRef = (int32_t*)taosMemoryMalloc(sizeof(int32_t));
|
||||
if (pDataSubmit->dataRef == NULL) goto FAIL;
|
||||
pDataSubmit->data = pReq;
|
||||
*pDataSubmit->dataRef = 1;
|
||||
pDataSubmit->type = STREAM_INPUT__DATA_SUBMIT;
|
||||
return pDataSubmit;
|
||||
FAIL:
|
||||
taosFreeQitem(pDataSubmit);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void streamDataSubmitRefInc(SStreamDataSubmit* pDataSubmit) {
|
||||
//
|
||||
atomic_add_fetch_32(pDataSubmit->dataRef, 1);
|
||||
}
|
||||
SStreamDataSubmit* streamDataSubmitNew(SSubmitReq* pReq);
|
||||
|
||||
static FORCE_INLINE void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit) {
|
||||
int32_t ref = atomic_sub_fetch_32(pDataSubmit->dataRef, 1);
|
||||
|
@ -141,9 +142,31 @@ static FORCE_INLINE void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit)
|
|||
|
||||
SStreamDataSubmit* streamSubmitRefClone(SStreamDataSubmit* pSubmit);
|
||||
|
||||
#if 0
|
||||
int32_t streamDataBlockEncode(void** buf, const SStreamDataBlock* pOutput);
|
||||
void* streamDataBlockDecode(const void* buf, SStreamDataBlock* pInput);
|
||||
|
||||
static FORCE_INLINE int32_t streamEnqueue1(SStreamQueue* queue, SStreamQueueItem* pItem) {
|
||||
int8_t inputStatus = atomic_load_8(&queue->enqueueStatus);
|
||||
if (inputStatus == TASK_INPUT_STATUS__NORMAL) {
|
||||
if (pItem->type == STREAM_INPUT__DATA_SUBMIT) {
|
||||
SStreamDataSubmit* pSubmitClone = streamSubmitRefClone((SStreamDataSubmit*)pItem);
|
||||
if (pSubmitClone == NULL) {
|
||||
atomic_store_8(&queue->enqueueStatus, TASK_INPUT_STATUS__FAILED);
|
||||
return -1;
|
||||
}
|
||||
taosWriteQitem(queue->queue, pSubmitClone);
|
||||
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK) {
|
||||
taosWriteQitem(queue->queue, pItem);
|
||||
} else if (pItem->type == STREAM_INPUT__CHECKPOINT) {
|
||||
taosWriteQitem(queue->queue, pItem);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int8_t parallelizable;
|
||||
char* qmsg;
|
||||
|
@ -236,12 +259,16 @@ struct SStreamTask {
|
|||
int8_t dispatchType;
|
||||
int16_t dispatchMsgType;
|
||||
|
||||
// node info
|
||||
int32_t childId;
|
||||
int32_t nodeId;
|
||||
SEpSet epSet;
|
||||
|
||||
// exec
|
||||
STaskExec exec;
|
||||
|
||||
// TODO: merge sink and dispatch
|
||||
|
||||
// local sink
|
||||
union {
|
||||
STaskSinkTb tbSink;
|
||||
|
@ -259,24 +286,54 @@ struct SStreamTask {
|
|||
int8_t inputStatus;
|
||||
int8_t outputStatus;
|
||||
|
||||
STaosQueue* inputQ;
|
||||
STaosQall* inputQAll;
|
||||
STaosQueue* outputQ;
|
||||
STaosQall* outputQAll;
|
||||
SStreamQueue* inputQueue;
|
||||
SStreamQueue* outputQueue;
|
||||
|
||||
// application storage
|
||||
void* ahandle;
|
||||
};
|
||||
|
||||
SStreamTask* tNewSStreamTask(int64_t streamId);
|
||||
SStreamTask* tNewSStreamTask(int64_t streamId, int32_t childId);
|
||||
int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask);
|
||||
int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask);
|
||||
void tFreeSStreamTask(SStreamTask* pTask);
|
||||
|
||||
typedef struct {
|
||||
// SMsgHead head;
|
||||
SStreamTask* task;
|
||||
} SStreamTaskDeployReq;
|
||||
static FORCE_INLINE int32_t streamTaskInput(SStreamTask* pTask, SStreamQueueItem* pItem) {
|
||||
while (1) {
|
||||
int8_t inputStatus =
|
||||
atomic_val_compare_exchange_8(&pTask->inputStatus, TASK_INPUT_STATUS__NORMAL, TASK_INPUT_STATUS__PROCESSING);
|
||||
if (inputStatus == TASK_INPUT_STATUS__NORMAL) {
|
||||
break;
|
||||
}
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (pItem->type == STREAM_INPUT__DATA_SUBMIT) {
|
||||
SStreamDataSubmit* pSubmitClone = streamSubmitRefClone((SStreamDataSubmit*)pItem);
|
||||
if (pSubmitClone == NULL) {
|
||||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
||||
return -1;
|
||||
}
|
||||
taosWriteQitem(pTask->inputQueue->queue, pSubmitClone);
|
||||
} else if (pItem->type == STREAM_INPUT__DATA_BLOCK) {
|
||||
taosWriteQitem(pTask->inputQueue->queue, pItem);
|
||||
} else if (pItem->type == STREAM_INPUT__CHECKPOINT) {
|
||||
taosWriteQitem(pTask->inputQueue->queue, pItem);
|
||||
}
|
||||
|
||||
// TODO: back pressure
|
||||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__NORMAL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void streamTaskInputFail(SStreamTask* pTask) {
|
||||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t streamTaskOutput(SStreamTask* pTask, SStreamDataBlock* pBlock) {
|
||||
taosWriteQitem(pTask->outputQueue->queue, pBlock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int32_t reserved;
|
||||
|
@ -289,6 +346,11 @@ typedef struct {
|
|||
SArray* data; // SArray<SSDataBlock>
|
||||
} SStreamTaskExecReq;
|
||||
|
||||
typedef struct {
|
||||
// SMsgHead head;
|
||||
SStreamTask* task;
|
||||
} SStreamTaskDeployReq;
|
||||
|
||||
int32_t tEncodeSStreamTaskExecReq(void** buf, const SStreamTaskExecReq* pReq);
|
||||
void* tDecodeSStreamTaskExecReq(const void* buf, SStreamTaskExecReq* pReq);
|
||||
void tFreeSStreamTaskExecReq(SStreamTaskExecReq* pReq);
|
||||
|
@ -297,13 +359,6 @@ typedef struct {
|
|||
int32_t reserved;
|
||||
} SStreamTaskExecRsp;
|
||||
|
||||
typedef struct {
|
||||
// SMsgHead head;
|
||||
int64_t streamId;
|
||||
int64_t version;
|
||||
SArray* res; // SArray<SSDataBlock>
|
||||
} SStreamSinkReq;
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
int64_t streamId;
|
||||
|
@ -315,10 +370,13 @@ typedef struct {
|
|||
int32_t taskId;
|
||||
int32_t sourceTaskId;
|
||||
int32_t sourceVg;
|
||||
int32_t sourceChildId;
|
||||
#if 0
|
||||
int64_t sourceVer;
|
||||
#endif
|
||||
SArray* data; // SArray<SSDataBlock>
|
||||
int32_t blockNum;
|
||||
SArray* dataLen; // SArray<int32_t>
|
||||
SArray* data; // SArray<SRetrieveTableRsp*>
|
||||
} SStreamDispatchReq;
|
||||
|
||||
typedef struct {
|
||||
|
@ -340,9 +398,9 @@ typedef struct {
|
|||
int8_t inputStatus;
|
||||
} SStreamTaskRecoverRsp;
|
||||
|
||||
int32_t streamEnqueueDataSubmit(SStreamTask* pTask, SStreamDataSubmit* input);
|
||||
int32_t streamEnqueueDataBlk(SStreamTask* pTask, SStreamDataBlock* input);
|
||||
int32_t streamDequeueOutput(SStreamTask* pTask, void** output);
|
||||
int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq);
|
||||
|
||||
int32_t streamTriggerByWrite(SStreamTask* pTask, int32_t vgId, SMsgCb* pMsgCb);
|
||||
|
||||
int32_t streamTaskRun(SStreamTask* pTask);
|
||||
|
||||
|
@ -356,4 +414,4 @@ int32_t streamProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp)
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /* ifndef _TSTREAM_H_ */
|
||||
#endif /* ifndef _STREAM_H_ */
|
||||
|
|
|
@ -218,6 +218,8 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_VGROUP_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0390)
|
||||
#define TSDB_CODE_MND_VGROUP_NOT_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0391)
|
||||
#define TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0392)
|
||||
#define TSDB_CODE_MND_VGROUP_UN_CHANGED TAOS_DEF_ERROR_CODE(0, 0x0393)
|
||||
#define TSDB_CODE_MND_HAS_OFFLINE_DNODE TAOS_DEF_ERROR_CODE(0, 0x0394)
|
||||
|
||||
// mnode-stable
|
||||
#define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A0)
|
||||
|
|
|
@ -105,8 +105,6 @@ int32_t compareStrPatternNotMatch(const void *pLeft, const void *pRight);
|
|||
int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight);
|
||||
int32_t compareWStrPatternNotMatch(const void *pLeft, const void *pRight);
|
||||
|
||||
int32_t compareJsonContainsKey(const void *pLeft, const void *pRight);
|
||||
|
||||
__compar_fn_t getComparFunc(int32_t type, int32_t optr);
|
||||
__compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order);
|
||||
int32_t doCompare(const char *a, const char *b, int32_t type, size_t size);
|
||||
|
|
|
@ -212,6 +212,9 @@ typedef struct SRequestObj {
|
|||
SArray* tableList;
|
||||
SQueryExecMetric metric;
|
||||
SRequestSendRecvBody body;
|
||||
|
||||
uint32_t prevCode; //previous error code: todo refactor, add update flag for catalog
|
||||
uint32_t retry;
|
||||
} SRequestObj;
|
||||
|
||||
typedef struct SSyncQueryParam {
|
||||
|
@ -263,8 +266,8 @@ extern SAppInfo appInfo;
|
|||
extern int32_t clientReqRefPool;
|
||||
extern int32_t clientConnRefPool;
|
||||
|
||||
extern int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code);
|
||||
int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code);
|
||||
__async_send_cb_fn_t getMsgRspHandle(int32_t msgType);
|
||||
|
||||
SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pReqObj);
|
||||
|
||||
void* createTscObj(const char* user, const char* auth, const char* db, int32_t connType, SAppInstInfo* pAppInfo);
|
||||
|
@ -274,7 +277,7 @@ int32_t releaseTscObj(int64_t rid);
|
|||
|
||||
uint64_t generateRequestId();
|
||||
|
||||
void* createRequest(STscObj* pObj, void* param, int32_t type);
|
||||
void* createRequest(STscObj* pObj, int32_t type);
|
||||
void destroyRequest(SRequestObj* pRequest);
|
||||
SRequestObj* acquireRequest(int64_t rid);
|
||||
int32_t releaseRequest(int64_t rid);
|
||||
|
@ -290,8 +293,6 @@ void* openTransporter(const char* user, const char* auth, int32_t numOfThreads);
|
|||
bool persistConnForSpecificMsg(void* parenct, tmsg_t msgType);
|
||||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet);
|
||||
|
||||
void initMsgHandleFp();
|
||||
|
||||
TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
|
||||
uint16_t port, int connType);
|
||||
|
||||
|
@ -325,6 +326,9 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNod
|
|||
void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery);
|
||||
int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest);
|
||||
int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList);
|
||||
void doAsyncQuery(SRequestObj* pRequest, bool forceUpdateMeta);
|
||||
int32_t removeMeta(STscObj* pTscObj, SArray* tbList);// todo move to clientImpl.c and become a static function
|
||||
int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog);// todo move to xxx
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -177,7 +177,7 @@ STscObj *acquireTscObj(int64_t rid) { return (STscObj *)taosAcquireRef(clientCon
|
|||
|
||||
int32_t releaseTscObj(int64_t rid) { return taosReleaseRef(clientConnRefPool, rid); }
|
||||
|
||||
void *createRequest(STscObj *pObj, void *param, int32_t type) {
|
||||
void *createRequest(STscObj *pObj, int32_t type) {
|
||||
assert(pObj != NULL);
|
||||
|
||||
SRequestObj *pRequest = (SRequestObj *)taosMemoryCalloc(1, sizeof(SRequestObj));
|
||||
|
@ -191,8 +191,6 @@ void *createRequest(STscObj *pObj, void *param, int32_t type) {
|
|||
pRequest->requestId = generateRequestId();
|
||||
pRequest->metric.start = taosGetTimestampUs();
|
||||
|
||||
pRequest->body.param = param;
|
||||
|
||||
pRequest->type = type;
|
||||
pRequest->pTscObj = pObj;
|
||||
pRequest->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE);
|
||||
|
@ -280,7 +278,6 @@ void taos_init_imp(void) {
|
|||
return;
|
||||
}
|
||||
|
||||
initMsgHandleFp();
|
||||
initQueryModuleMsgHandle();
|
||||
|
||||
rpcInit();
|
||||
|
|
|
@ -133,7 +133,7 @@ TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass,
|
|||
}
|
||||
|
||||
int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest) {
|
||||
*pRequest = createRequest(pTscObj, NULL, TSDB_SQL_SELECT);
|
||||
*pRequest = createRequest(pTscObj, TSDB_SQL_SELECT);
|
||||
if (*pRequest == NULL) {
|
||||
tscError("failed to malloc sqlObj");
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
@ -207,6 +207,7 @@ int32_t execLocalCmd(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
if (TSDB_CODE_SUCCESS == code && NULL != pRsp) {
|
||||
code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false, false);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -235,6 +236,31 @@ static SAppInstInfo* getAppInfo(SRequestObj* pRequest) {
|
|||
return pRequest->pTscObj->pAppInfo;
|
||||
}
|
||||
|
||||
void asyncExecLocalCmd(SRequestObj* pRequest, SQuery* pQuery) {
|
||||
SRetrieveTableRsp* pRsp = NULL;
|
||||
|
||||
int32_t code = qExecCommand(pQuery->pRoot, &pRsp);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pRsp) {
|
||||
code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false, false);
|
||||
}
|
||||
|
||||
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
pRequest->code = code;
|
||||
tscError("0x%" PRIx64 " fetch results failed, code:%s, reqId:0x%" PRIx64, pRequest->self, tstrerror(code),
|
||||
pRequest->requestId);
|
||||
} else {
|
||||
tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, pResultInfo->numOfRows, pResultInfo->totalRows, pResultInfo->completed,
|
||||
pRequest->requestId);
|
||||
}
|
||||
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, 0);
|
||||
// pRequest->body.fetchFp(pRequest->body.param, pRequest, pResultInfo->numOfRows);
|
||||
}
|
||||
|
||||
int32_t asyncExecDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
||||
// drop table if exists not_exists_table
|
||||
if (NULL == pQuery->pCmdMsg) {
|
||||
|
@ -431,7 +457,7 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
|
|||
return pRequest->code;
|
||||
}
|
||||
|
||||
if (TDMT_VND_SUBMIT == pRequest->type || TDMT_VND_CREATE_TABLE == pRequest->type) {
|
||||
if (TDMT_VND_SUBMIT == pRequest->type || TDMT_VND_DELETE == pRequest->type || TDMT_VND_CREATE_TABLE == pRequest->type) {
|
||||
pRequest->body.resInfo.numOfRows = res.numOfRows;
|
||||
|
||||
if (pRequest->body.queryJob != 0) {
|
||||
|
@ -509,19 +535,20 @@ int32_t handleAlterTbExecRes(void* res, SCatalog* pCatalog) {
|
|||
return catalogUpdateTableMeta(pCatalog, (STableMetaRsp*)res);
|
||||
}
|
||||
|
||||
int32_t handleExecRes(SRequestObj* pRequest) {
|
||||
int32_t handleQueryExecRsp(SRequestObj* pRequest) {
|
||||
if (NULL == pRequest->body.resInfo.execRes.res) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
SCatalog* pCatalog = NULL;
|
||||
code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
SAppInstInfo* pAppInfo = getAppInfo(pRequest);
|
||||
|
||||
int32_t code = catalogGetHandle(pAppInfo->clusterId, &pCatalog);
|
||||
if (code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SEpSet epset = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp);
|
||||
SEpSet epset = getEpSet_s(&pAppInfo->mgmtEp);
|
||||
SQueryExecRes* pRes = &pRequest->body.resInfo.execRes;
|
||||
|
||||
switch (pRes->msgType) {
|
||||
|
@ -539,8 +566,9 @@ int32_t handleExecRes(SRequestObj* pRequest) {
|
|||
break;
|
||||
}
|
||||
default:
|
||||
tscError("invalid exec result for request type %d", pRequest->type);
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
tscError("0x%"PRIx64", invalid exec result for request type %d, reqId:0x%"PRIx64, pRequest->self,
|
||||
pRequest->type, pRequest->requestId);
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -548,6 +576,25 @@ int32_t handleExecRes(SRequestObj* pRequest) {
|
|||
|
||||
void schedulerExecCb(SQueryResult* pResult, void* param, int32_t code) {
|
||||
SRequestObj* pRequest = (SRequestObj*) param;
|
||||
pRequest->code = code;
|
||||
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
if (code != TSDB_CODE_SUCCESS && NEED_CLIENT_HANDLE_ERROR(code)) {
|
||||
tscDebug("0x%"PRIx64" client retry to handle the error, code:%s, reqId:0x%"PRIx64, pRequest->self, tstrerror(code), pRequest->requestId);
|
||||
pRequest->prevCode = code;
|
||||
doAsyncQuery(pRequest, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = handleQueryExecRsp(pRequest);
|
||||
ASSERT(pRequest->code == TSDB_CODE_SUCCESS);
|
||||
pRequest->code = code;
|
||||
}
|
||||
|
||||
if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) {
|
||||
removeMeta(pTscObj, pRequest->tableList);
|
||||
}
|
||||
|
||||
// return to client
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
|
@ -583,7 +630,7 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, bool keepQue
|
|||
qDestroyQuery(pQuery);
|
||||
}
|
||||
|
||||
handleExecRes(pRequest);
|
||||
handleQueryExecRsp(pRequest);
|
||||
|
||||
if (NULL != pRequest && TSDB_CODE_SUCCESS != code) {
|
||||
pRequest->code = terrno;
|
||||
|
@ -617,13 +664,12 @@ SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen) {
|
|||
}
|
||||
|
||||
void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
||||
void* pRes = NULL;
|
||||
|
||||
int32_t code = 0;
|
||||
|
||||
switch (pQuery->execMode) {
|
||||
case QUERY_EXEC_MODE_LOCAL:
|
||||
code = execLocalCmd(pRequest, pQuery);
|
||||
break;
|
||||
asyncExecLocalCmd(pRequest, pQuery);
|
||||
return;
|
||||
case QUERY_EXEC_MODE_RPC:
|
||||
code = asyncExecDdlQuery(pRequest, pQuery);
|
||||
break;
|
||||
|
@ -649,11 +695,9 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
schedulerAsyncExecJob(pAppInfo->pTransporter, pNodeList, pRequest->body.pDag, &pRequest->body.queryJob,
|
||||
pRequest->sqlstr, pRequest->metric.start, schedulerExecCb, pRequest);
|
||||
// if (NULL != pRes) {
|
||||
// code = validateSversion(pRequest, pRes);
|
||||
// }
|
||||
}
|
||||
|
||||
//todo not to be released here
|
||||
taosArrayDestroy(pNodeList);
|
||||
break;
|
||||
}
|
||||
|
@ -671,12 +715,6 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
if (NULL != pRequest && TSDB_CODE_SUCCESS != code) {
|
||||
pRequest->code = terrno;
|
||||
}
|
||||
|
||||
// if (res) {
|
||||
// *res = pRes;
|
||||
// } else {
|
||||
// freeRequestRes(pRequest, pRes);
|
||||
// pRes = NULL;
|
||||
}
|
||||
|
||||
int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) {
|
||||
|
@ -750,7 +788,7 @@ SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) {
|
|||
pRequest->code = code;
|
||||
break;
|
||||
}
|
||||
} while (retryNum++ < REQUEST_MAX_TRY_TIMES);
|
||||
} while (retryNum++ < REQUEST_TOTAL_EXEC_TIMES);
|
||||
|
||||
if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) {
|
||||
removeMeta(pTscObj, pRequest->tableList);
|
||||
|
@ -808,7 +846,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t
|
|||
return pTscObj;
|
||||
}
|
||||
|
||||
SRequestObj* pRequest = createRequest(pTscObj, param, TDMT_MND_CONNECT);
|
||||
SRequestObj* pRequest = createRequest(pTscObj, TDMT_MND_CONNECT);
|
||||
if (pRequest == NULL) {
|
||||
destroyTscObj(pTscObj);
|
||||
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
|
@ -850,7 +888,7 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) {
|
|||
|
||||
pMsgSendInfo->requestObjRefId = pRequest->self;
|
||||
pMsgSendInfo->requestId = pRequest->requestId;
|
||||
pMsgSendInfo->fp = handleRequestRspFp[TMSG_INDEX(pMsgSendInfo->msgType)];
|
||||
pMsgSendInfo->fp = getMsgRspHandle(pMsgSendInfo->msgType);
|
||||
pMsgSendInfo->param = pRequest;
|
||||
|
||||
SConnectReq connectReq = {0};
|
||||
|
@ -1429,7 +1467,7 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de
|
|||
}
|
||||
|
||||
code = statusRsp.statusCode;
|
||||
if (details != NULL && statusRsp.details != NULL) {
|
||||
if (details != NULL) {
|
||||
tstrncpy(details, statusRsp.details, maxlen);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#define TSC_VAR_RELEASED 0
|
||||
|
||||
static int32_t sentinel = TSC_VAR_NOT_RELEASE;
|
||||
static int32_t createParseContext(const SRequestObj *pRequest, SParseContext** pCxt);
|
||||
|
||||
int taos_options(TSDB_OPTION option, const void *arg, ...) {
|
||||
static int32_t lock = 0;
|
||||
|
@ -192,7 +193,7 @@ TAOS_RES *taos_query(TAOS *taos, const char *sql) {
|
|||
STscObj* pTscObj = (STscObj*)taos;
|
||||
|
||||
#if SYNC_ON_TOP_OF_ASYNC
|
||||
SSyncQueryParam* param = taosMemoryCalloc(1, sizeof(struct SSyncQueryParam));
|
||||
SSyncQueryParam* param = taosMemoryCalloc(1, sizeof(SSyncQueryParam));
|
||||
tsem_init(¶m->sem, 0, 0);
|
||||
|
||||
taos_query_a(pTscObj, sql, syncQueryFn, param);
|
||||
|
@ -608,18 +609,14 @@ void retrieveMetaCallback(SMetaData* pResultMeta, void* param, int32_t code) {
|
|||
SQuery* pQuery = pWrapper->pQuery;
|
||||
SRequestObj* pRequest = pWrapper->pRequest;
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
code = qAnalyseSqlSemantic(pWrapper->pCtx, &pWrapper->catalogReq, pResultMeta, pQuery);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
if (pQuery->haveResultSet) {
|
||||
setResSchemaInfo(&pRequest->body.resInfo, pQuery->pResSchema, (pQuery)->numOfResCols);
|
||||
setResPrecision(&pRequest->body.resInfo, (pQuery)->precision);
|
||||
setResSchemaInfo(&pRequest->body.resInfo, pQuery->pResSchema, pQuery->numOfResCols);
|
||||
setResPrecision(&pRequest->body.resInfo, pQuery->precision);
|
||||
}
|
||||
|
||||
TSWAP(pRequest->dbList, (pQuery)->pDbList);
|
||||
|
@ -627,17 +624,23 @@ void retrieveMetaCallback(SMetaData* pResultMeta, void* param, int32_t code) {
|
|||
|
||||
taosMemoryFree(pWrapper);
|
||||
launchAsyncQuery(pRequest, pQuery);
|
||||
} else {
|
||||
if (NEED_CLIENT_HANDLE_ERROR(code)) {
|
||||
tscDebug("0x%"PRIx64" client retry to handle the error, code:%s, reqId:0x%"PRIx64, pRequest->self, tstrerror(code), pRequest->requestId);
|
||||
pRequest->prevCode = code;
|
||||
doAsyncQuery(pRequest, true);
|
||||
return;
|
||||
}
|
||||
|
||||
_error:
|
||||
// return to app directly
|
||||
taosMemoryFree(pWrapper);
|
||||
tscError("0x%" PRIx64 " error occurs, code:%s, return to user app, reqId:%" PRIx64, pRequest->self, tstrerror(code),
|
||||
tscError("0x%" PRIx64 " error occurs, code:%s, return to user app, reqId:0x%" PRIx64, pRequest->self, tstrerror(code),
|
||||
pRequest->requestId);
|
||||
pRequest->code = code;
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
}
|
||||
}
|
||||
|
||||
// todo add retry before return user's callback
|
||||
void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) {
|
||||
ASSERT(fp != NULL);
|
||||
|
||||
|
@ -657,24 +660,27 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param
|
|||
}
|
||||
|
||||
SRequestObj *pRequest = NULL;
|
||||
int32_t retryNum = 0;
|
||||
int32_t code = 0;
|
||||
|
||||
// while (retryNum++ < REQUEST_MAX_TRY_TIMES) {
|
||||
code = buildRequest(taos, sql, sqlLen, &pRequest);
|
||||
int32_t code = buildRequest(taos, sql, sqlLen, &pRequest);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
terrno = code;
|
||||
fp(param, NULL, code);
|
||||
fp(param, NULL, terrno);
|
||||
return;
|
||||
}
|
||||
|
||||
pRequest->body.queryFp = fp;
|
||||
pRequest->body.param = param;
|
||||
doAsyncQuery(pRequest, false);
|
||||
}
|
||||
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
int32_t createParseContext(const SRequestObj *pRequest, SParseContext** pCxt) {
|
||||
const STscObj *pTscObj = pRequest->pTscObj;
|
||||
|
||||
SParseContext* pCxt = taosMemoryCalloc(1, sizeof(SParseContext));
|
||||
*pCxt = (SParseContext){.requestId = pRequest->requestId,
|
||||
*pCxt = taosMemoryCalloc(1, sizeof(SParseContext));
|
||||
if (*pCxt == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
**pCxt = (SParseContext){.requestId = pRequest->requestId,
|
||||
.acctId = pTscObj->acctId,
|
||||
.db = pRequest->pDb,
|
||||
.topicQuery = false,
|
||||
|
@ -687,6 +693,22 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param
|
|||
.pUser = pTscObj->user,
|
||||
.isSuperUser = (0 == strcmp(pTscObj->user, TSDB_DEFAULT_USER)),
|
||||
.async = true,};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void doAsyncQuery(SRequestObj* pRequest, bool updateMetaForce) {
|
||||
SParseContext* pCxt = NULL;
|
||||
STscObj *pTscObj = pRequest->pTscObj;
|
||||
|
||||
if (pRequest->retry++ > REQUEST_TOTAL_EXEC_TIMES) {
|
||||
pRequest->code = pRequest->prevCode;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
int32_t code = createParseContext(pRequest, &pCxt);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pCxt->mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||
code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &pCxt->pCatalog);
|
||||
|
@ -694,14 +716,20 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param
|
|||
goto _error;
|
||||
}
|
||||
|
||||
SQuery * pQuery = NULL;
|
||||
SCatalogReq catalogReq = {0};
|
||||
SQuery *pQuery = NULL;
|
||||
|
||||
SCatalogReq catalogReq = {.forceUpdate = updateMetaForce};
|
||||
code = qParseSqlSyntax(pCxt, &pQuery, &catalogReq);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
SqlParseWrapper *pWrapper = taosMemoryCalloc(1, sizeof(SqlParseWrapper));
|
||||
if (pWrapper == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pWrapper->pCtx = pCxt;
|
||||
pWrapper->pQuery = pQuery;
|
||||
pWrapper->pRequest = pRequest;
|
||||
|
@ -709,24 +737,15 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param
|
|||
|
||||
code = catalogAsyncGetAllMeta(pCxt->pCatalog, pCxt->pTransporter, &pCxt->mgmtEpSet, pRequest->requestId,
|
||||
&catalogReq, retrieveMetaCallback, pWrapper, &pRequest->body.queryJob);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
// todo handle the retry process
|
||||
|
||||
// if (TSDB_CODE_SUCCESS == code || NEED_CLIENT_HANDLE_ERROR(code)) {
|
||||
// TSWAP(pRequest->dbList, (pQuery)->pDbList);
|
||||
// TSWAP(pRequest->tableList, (pQuery)->pTableList);
|
||||
// }
|
||||
|
||||
_error:
|
||||
tscError("0x%"PRIx64" error happens, code:%s, reqId:0x%"PRIx64, pRequest->self, tstrerror(code), pRequest->requestId);
|
||||
terrno = code;
|
||||
pRequest->code = code;
|
||||
fp(param, pRequest, code);
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
}
|
||||
|
||||
static void fetchCallback(void* pResult, void* param, int32_t code) {
|
||||
|
@ -751,13 +770,14 @@ static void fetchCallback(void* pResult, void* param, int32_t code) {
|
|||
pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResultInfo->pData, true, false);
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
|
||||
pRequest->code = code;
|
||||
pRequest->body.fetchFp(pRequest->body.param, pRequest, 0);
|
||||
}
|
||||
|
||||
tscError("0x%" PRIx64 " fetch results failed, code:%s, reqId:0x%" PRIx64, pRequest->self, tstrerror(code),
|
||||
pRequest->requestId);
|
||||
} else {
|
||||
tscDebug("0x%" PRIx64 " fetch results, numOfRows:%d total Rows:%" PRId64 ", complete:%d, reqId:0x%" PRIx64,
|
||||
pRequest->self, pResultInfo->numOfRows, pResultInfo->totalRows, pResultInfo->completed, pRequest->requestId);
|
||||
pRequest->self, pResultInfo->numOfRows, pResultInfo->totalRows, pResultInfo->completed,
|
||||
pRequest->requestId);
|
||||
}
|
||||
|
||||
pRequest->body.fetchFp(pRequest->body.param, pRequest, pResultInfo->numOfRows);
|
||||
}
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
#include "tdef.h"
|
||||
#include "tname.h"
|
||||
|
||||
int32_t (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code);
|
||||
|
||||
static void setErrno(SRequestObj* pRequest, int32_t code) {
|
||||
pRequest->code = code;
|
||||
terrno = code;
|
||||
|
@ -107,10 +105,7 @@ SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pRequest) {
|
|||
|
||||
assert(pRequest != NULL);
|
||||
pMsgSendInfo->msgInfo = pRequest->body.requestMsg;
|
||||
|
||||
pMsgSendInfo->fp = (handleRequestRspFp[TMSG_INDEX(pRequest->type)] == NULL)
|
||||
? genericRspCallback
|
||||
: handleRequestRspFp[TMSG_INDEX(pRequest->type)];
|
||||
pMsgSendInfo->fp = getMsgRspHandle(pRequest->type);
|
||||
return pMsgSendInfo;
|
||||
}
|
||||
|
||||
|
@ -209,7 +204,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
int32_t processCreateSTableRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||
assert(pMsg != NULL && param != NULL);
|
||||
SRequestObj* pRequest = param;
|
||||
|
||||
|
@ -219,6 +214,7 @@ int32_t processCreateTableRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
|
||||
if (pRequest->body.queryFp != NULL) {
|
||||
removeMeta(pRequest->pTscObj, pRequest->tableList);
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
} else {
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
|
@ -251,10 +247,7 @@ int32_t processAlterStbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
SRequestObj* pRequest = param;
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
setErrno(pRequest, code);
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
return code;
|
||||
}
|
||||
|
||||
} else {
|
||||
SMAlterStbRsp alterRsp = {0};
|
||||
SDecoder coder = {0};
|
||||
tDecoderInit(&coder, pMsg->pData, pMsg->len);
|
||||
|
@ -263,18 +256,45 @@ int32_t processAlterStbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
|
||||
pRequest->body.resInfo.execRes.msgType = TDMT_MND_ALTER_STB;
|
||||
pRequest->body.resInfo.execRes.res = alterRsp.pMeta;
|
||||
}
|
||||
|
||||
if (pRequest->body.queryFp != NULL) {
|
||||
SQueryExecRes* pRes = &pRequest->body.resInfo.execRes;
|
||||
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
SCatalog* pCatalog = NULL;
|
||||
int32_t ret = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
if (pRes->res != NULL) {
|
||||
ret = handleAlterTbExecRes(pRes->res, pCatalog);
|
||||
}
|
||||
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
code = ret;
|
||||
}
|
||||
}
|
||||
|
||||
pRequest->body.queryFp(pRequest->body.param, pRequest, code);
|
||||
} else {
|
||||
tsem_post(&pRequest->body.rspSem);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
// todo refactor: this arraylist is too large
|
||||
void initMsgHandleFp() {
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CONNECT)] = processConnectRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = processCreateDbRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_USE_DB)] = processUseDbRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = processCreateTableRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = processDropDbRsp;
|
||||
handleRequestRspFp[TMSG_INDEX(TDMT_MND_ALTER_STB)] = processAlterStbRsp;
|
||||
__async_send_cb_fn_t getMsgRspHandle(int32_t msgType) {
|
||||
switch (msgType) {
|
||||
case TDMT_MND_CONNECT:
|
||||
return processConnectRsp;
|
||||
case TDMT_MND_CREATE_DB:
|
||||
return processCreateDbRsp;
|
||||
case TDMT_MND_USE_DB:
|
||||
return processUseDbRsp;
|
||||
case TDMT_MND_CREATE_STB:
|
||||
return processCreateSTableRsp;
|
||||
case TDMT_MND_DROP_DB:
|
||||
return processDropDbRsp;
|
||||
case TDMT_MND_ALTER_STB:
|
||||
return processAlterStbRsp;
|
||||
default:
|
||||
return genericRspCallback;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2364,7 +2364,7 @@ static int32_t isSchemalessDb(SSmlHandle* info){
|
|||
*/
|
||||
|
||||
TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int protocol, int precision) {
|
||||
SRequestObj* request = (SRequestObj*)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj* request = (SRequestObj*)createRequest((STscObj *)taos, TSDB_SQL_INSERT);
|
||||
if(!request){
|
||||
uError("SML:taos_schemaless_insert error request is null");
|
||||
return NULL;
|
||||
|
|
|
@ -778,7 +778,35 @@ TEST(testCase, async_api_test) {
|
|||
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
|
||||
ASSERT_NE(pConn, nullptr);
|
||||
|
||||
taos_query_a(pConn, "drop table test.tm0", queryCallback, pConn);
|
||||
taos_query(pConn, "use test");
|
||||
|
||||
TAOS_RES* pRes = taos_query(pConn, "select * from t1");
|
||||
|
||||
taos_query(pConn, "alter table t1 add column b int");
|
||||
pRes = taos_query(pConn, "insert into t1 values(now, 1, 2)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed, reason:%s\n", taos_errstr(pRes));
|
||||
}
|
||||
|
||||
// int32_t n = 0;
|
||||
// TAOS_ROW pRow = NULL;
|
||||
// TAOS_FIELD* pFields = taos_fetch_fields(pRes);
|
||||
// int32_t numOfFields = taos_num_fields(pRes);
|
||||
//
|
||||
// char str[512] = {0};
|
||||
// while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
// int32_t* length = taos_fetch_lengths(pRes);
|
||||
// for(int32_t i = 0; i < numOfFields; ++i) {
|
||||
// printf("(%d):%d " , i, length[i]);
|
||||
// }
|
||||
// printf("\n");
|
||||
//
|
||||
// int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
|
||||
// printf("%s\n", str);
|
||||
// memset(str, 0, sizeof(str));
|
||||
// }
|
||||
|
||||
taos_query_a(pConn, "alter table test.m1 comment 'abcde' ", queryCallback, pConn);
|
||||
getchar();
|
||||
taos_close(pConn);
|
||||
}
|
||||
|
|
|
@ -486,7 +486,7 @@ TEST(testCase, smlProcess_influx_Test) {
|
|||
pRes = taos_query(taos, "use inflx_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -607,7 +607,7 @@ TEST(testCase, smlParseLine_error_Test) {
|
|||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -656,7 +656,7 @@ TEST(testCase, smlProcess_telnet_Test) {
|
|||
pRes = taos_query(taos, "use telnet_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -710,7 +710,7 @@ TEST(testCase, smlProcess_json1_Test) {
|
|||
pRes = taos_query(taos, "use json_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -779,7 +779,7 @@ TEST(testCase, smlProcess_json2_Test) {
|
|||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -823,7 +823,7 @@ TEST(testCase, smlProcess_json3_Test) {
|
|||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -895,7 +895,7 @@ TEST(testCase, smlProcess_json4_Test) {
|
|||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -957,7 +957,7 @@ TEST(testCase, smlParseTelnetLine_error_Test) {
|
|||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -1006,7 +1006,7 @@ TEST(testCase, smlParseTelnetLine_diff_type_Test) {
|
|||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -1033,7 +1033,7 @@ TEST(testCase, smlParseTelnetLine_json_error_Test) {
|
|||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -1101,7 +1101,7 @@ TEST(testCase, smlParseTelnetLine_diff_json_type1_Test) {
|
|||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -1146,7 +1146,7 @@ TEST(testCase, smlParseTelnetLine_diff_json_type2_Test) {
|
|||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -1191,7 +1191,7 @@ TEST(testCase, sml_TD15662_Test) {
|
|||
pRes = taos_query(taos, "use db_15662");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj *)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
|
@ -1218,7 +1218,7 @@ TEST(testCase, sml_TD15735_Test) {
|
|||
pRes = taos_query(taos, "use sml_db");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
|
@ -1244,7 +1244,7 @@ TEST(testCase, sml_TD15742_Test) {
|
|||
pRes = taos_query(taos, "use TD15742");
|
||||
taos_free_result(pRes);
|
||||
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, NULL, TSDB_SQL_INSERT);
|
||||
SRequestObj *request = (SRequestObj *)createRequest((STscObj*)taos, TSDB_SQL_INSERT);
|
||||
ASSERT_NE(request, nullptr);
|
||||
|
||||
SSmlHandle *info = smlBuildSmlInfo(taos, request, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
|
|
|
@ -1590,7 +1590,6 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
|
|||
for (int32_t k = 0; k < colNum; ++k) { // iterate by column
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
STColumn* pCol = &pTSchema->columns[k];
|
||||
ASSERT(pCol->type == pColInfoData->info.type);
|
||||
void* var = POINTER_SHIFT(pColInfoData->pData, j * pColInfoData->info.bytes);
|
||||
switch (pColInfoData->info.type) {
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
|
@ -1614,20 +1613,39 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
|
|||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
case TSDB_DATA_TYPE_DECIMAL:
|
||||
case TSDB_DATA_TYPE_BLOB:
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||
uError("the column type %" PRIi16 " is defined but not implemented yet", pColInfoData->info.type);
|
||||
TASSERT(0);
|
||||
break;
|
||||
default:
|
||||
if (pColInfoData->info.type < TSDB_DATA_TYPE_MAX && pColInfoData->info.type > TSDB_DATA_TYPE_NULL) {
|
||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pColInfoData->info.type, TD_VTYPE_NORM, var, true, offset, k);
|
||||
char tv[8] = {0};
|
||||
if (pColInfoData->info.type == TSDB_DATA_TYPE_FLOAT) {
|
||||
float v = 0;
|
||||
GET_TYPED_DATA(v, float, pColInfoData->info.type, var);
|
||||
SET_TYPED_DATA(&tv, pCol->type, v);
|
||||
} else if (pColInfoData->info.type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
double v = 0;
|
||||
GET_TYPED_DATA(v, double, pColInfoData->info.type, var);
|
||||
SET_TYPED_DATA(&tv, pCol->type, v);
|
||||
} else if (IS_SIGNED_NUMERIC_TYPE(pColInfoData->info.type)) {
|
||||
int64_t v = 0;
|
||||
GET_TYPED_DATA(v, int64_t, pColInfoData->info.type, var);
|
||||
SET_TYPED_DATA(&tv, pCol->type, v);
|
||||
} else {
|
||||
uint64_t v = 0;
|
||||
GET_TYPED_DATA(v, uint64_t, pColInfoData->info.type, var);
|
||||
SET_TYPED_DATA(&tv, pCol->type, v);
|
||||
}
|
||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, tv, true, offset, k);
|
||||
} else {
|
||||
uError("the column type %" PRIi16 " is undefined\n", pColInfoData->info.type);
|
||||
TASSERT(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
offset += TYPE_BYTES[pColInfoData->info.type];
|
||||
offset += TYPE_BYTES[pCol->type]; // sum/avg would convert to int64_t/uint64_t/double during aggregation
|
||||
}
|
||||
dataLen += TD_ROW_LEN(rb.pBuf);
|
||||
#ifdef TD_DEBUG_PRINT_ROW
|
||||
|
|
|
@ -694,7 +694,6 @@ void tFreeSMAltertbReq(SMAlterStbReq *pReq) {
|
|||
pReq->pFields = NULL;
|
||||
}
|
||||
|
||||
|
||||
int32_t tSerializeSEpSet(void *buf, int32_t bufLen, const SEpSet *pEpset) {
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
@ -933,6 +932,7 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
|||
if (tEncodeI64(&encoder, pReq->qload.numOfProcessedFetch) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->qload.numOfProcessedDrop) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->qload.numOfProcessedHb) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->qload.numOfProcessedDelete) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->qload.cacheDataSize) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->qload.numOfQueryInQueue) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->qload.numOfFetchInQueue) < 0) return -1;
|
||||
|
@ -1002,6 +1002,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) {
|
|||
if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedFetch) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedDrop) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedHb) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->qload.numOfProcessedDelete) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->qload.cacheDataSize) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->qload.numOfQueryInQueue) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->qload.numOfFetchInQueue) < 0) return -1;
|
||||
|
@ -3674,12 +3675,12 @@ int32_t tEncodeTSma(SEncoder *pCoder, const STSma *pSma) {
|
|||
if (tEncodeCStr(pCoder, pSma->tagsFilter) < 0) return -1;
|
||||
}
|
||||
for (int32_t v = 0; v < pSma->numOfVgroups; ++v) {
|
||||
if (tEncodeI32(pCoder, pSma->vgEpSet[v].vgId) < 0) return -1;
|
||||
if (tEncodeI8(pCoder, pSma->vgEpSet[v].epSet.inUse) < 0) return -1;
|
||||
int8_t numOfEps = pSma->vgEpSet[v].epSet.numOfEps;
|
||||
if (tEncodeI32(pCoder, pSma->pVgEpSet[v].vgId) < 0) return -1;
|
||||
if (tEncodeI8(pCoder, pSma->pVgEpSet[v].epSet.inUse) < 0) return -1;
|
||||
int8_t numOfEps = pSma->pVgEpSet[v].epSet.numOfEps;
|
||||
if (tEncodeI8(pCoder, numOfEps) < 0) return -1;
|
||||
for (int32_t n = 0; n < numOfEps; ++n) {
|
||||
const SEp *pEp = &pSma->vgEpSet[v].epSet.eps[n];
|
||||
const SEp *pEp = &pSma->pVgEpSet[v].epSet.eps[n];
|
||||
if (tEncodeCStr(pCoder, pEp->fqdn) < 0) return -1;
|
||||
if (tEncodeU16(pCoder, pEp->port) < 0) return -1;
|
||||
}
|
||||
|
@ -3712,17 +3713,27 @@ int32_t tDecodeTSma(SDecoder *pCoder, STSma *pSma) {
|
|||
} else {
|
||||
pSma->tagsFilter = NULL;
|
||||
}
|
||||
if (pSma->numOfVgroups > 0) {
|
||||
pSma->pVgEpSet = (SVgEpSet *)tDecoderMalloc(pCoder, pSma->numOfVgroups * sizeof(SVgEpSet));
|
||||
if (!pSma->pVgEpSet) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(pSma->pVgEpSet, 0, pSma->numOfVgroups * sizeof(SVgEpSet));
|
||||
|
||||
for (int32_t v = 0; v < pSma->numOfVgroups; ++v) {
|
||||
if (tDecodeI32(pCoder, &pSma->vgEpSet[v].vgId) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pSma->vgEpSet[v].epSet.inUse) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pSma->vgEpSet[v].epSet.numOfEps) < 0) return -1;
|
||||
int8_t numOfEps = pSma->vgEpSet[v].epSet.numOfEps;
|
||||
if (tDecodeI32(pCoder, &pSma->pVgEpSet[v].vgId) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pSma->pVgEpSet[v].epSet.inUse) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pSma->pVgEpSet[v].epSet.numOfEps) < 0) return -1;
|
||||
int8_t numOfEps = pSma->pVgEpSet[v].epSet.numOfEps;
|
||||
for (int32_t n = 0; n < numOfEps; ++n) {
|
||||
SEp *pEp = &pSma->vgEpSet[v].epSet.eps[n];
|
||||
SEp *pEp = &pSma->pVgEpSet[v].epSet.eps[n];
|
||||
if (tDecodeCStrTo(pCoder, pEp->fqdn) < 0) return -1;
|
||||
if (tDecodeU16(pCoder, &pEp->port) < 0) return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -3765,7 +3776,7 @@ int32_t tDecodeSVDropTSmaReq(SDecoder *pCoder, SVDropTSmaReq *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSVGetTSmaExpWndsReq(SEncoder* pCoder, const SVGetTsmaExpWndsReq* pReq) {
|
||||
int32_t tEncodeSVGetTSmaExpWndsReq(SEncoder *pCoder, const SVGetTsmaExpWndsReq *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI64(pCoder, pReq->indexUid) < 0) return -1;
|
||||
|
@ -3776,7 +3787,7 @@ int32_t tEncodeSVGetTSmaExpWndsReq(SEncoder* pCoder, const SVGetTsmaExpWndsReq*
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVGetTsmaExpWndsReq(SDecoder* pCoder, SVGetTsmaExpWndsReq* pReq) {
|
||||
int32_t tDecodeSVGetTsmaExpWndsReq(SDecoder *pCoder, SVGetTsmaExpWndsReq *pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI64(pCoder, &pReq->indexUid) < 0) return -1;
|
||||
|
@ -3787,7 +3798,7 @@ int32_t tDecodeSVGetTsmaExpWndsReq(SDecoder* pCoder, SVGetTsmaExpWndsReq* pReq)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSVGetTSmaExpWndsRsp(SEncoder* pCoder, const SVGetTsmaExpWndsRsp* pReq) {
|
||||
int32_t tEncodeSVGetTSmaExpWndsRsp(SEncoder *pCoder, const SVGetTsmaExpWndsRsp *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI64(pCoder, pReq->indexUid) < 0) return -1;
|
||||
|
@ -3814,56 +3825,79 @@ int32_t tDecodeSVGetTsmaExpWndsRsp(SDecoder *pCoder, SVGetTsmaExpWndsRsp *pReq)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSVDeleteReq(SEncoder* pCoder, const SVDeleteReq* pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI64(pCoder, pReq->delUid) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pReq->tbUid) < 0) return -1;
|
||||
if (tEncodeI8(pCoder, pReq->type) < 0) return -1;
|
||||
if (tEncodeI16v(pCoder, pReq->nWnds) < 0) return -1;
|
||||
if (tEncodeCStr(pCoder, pReq->tbFullName) < 0) return -1;
|
||||
if (tEncodeCStr(pCoder, pReq->subPlan) < 0) return -1;
|
||||
for (int16_t i = 0; i < pReq->nWnds; ++i) {
|
||||
if (tEncodeI64(pCoder, pReq->wnds[i].skey) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pReq->wnds[i].ekey) < 0) return -1;
|
||||
int32_t tSerializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq) {
|
||||
int32_t headLen = sizeof(SMsgHead);
|
||||
if (buf != NULL) {
|
||||
buf = (char *)buf + headLen;
|
||||
bufLen -= headLen;
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
SEncoder encoder = {0};
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeU64(&encoder, pReq->sId) < 0) return -1;
|
||||
if (tEncodeU64(&encoder, pReq->queryId) < 0) return -1;
|
||||
if (tEncodeU64(&encoder, pReq->taskId) < 0) return -1;
|
||||
if (tEncodeU32(&encoder, pReq->sqlLen) < 0) return -1;
|
||||
if (tEncodeU32(&encoder, pReq->phyLen) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
|
||||
if (tEncodeCStr(&encoder, pReq->msg) < 0) return -1;
|
||||
tEndEncode(&encoder);
|
||||
|
||||
int32_t tlen = encoder.pos;
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
if (buf != NULL) {
|
||||
SMsgHead *pHead = (SMsgHead *)((char *)buf - headLen);
|
||||
pHead->vgId = htonl(pReq->header.vgId);
|
||||
pHead->contLen = htonl(tlen + headLen);
|
||||
}
|
||||
|
||||
return tlen + headLen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSVDeleteReq(void *buf, int32_t bufLen, SVDeleteReq *pReq) {
|
||||
int32_t headLen = sizeof(SMsgHead);
|
||||
|
||||
SMsgHead *pHead = buf;
|
||||
pHead->vgId = pReq->header.vgId;
|
||||
pHead->contLen = pReq->header.contLen;
|
||||
|
||||
SDecoder decoder = {0};
|
||||
tDecoderInit(&decoder, (char *)buf + headLen, bufLen - headLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeU64(&decoder, &pReq->sId) < 0) return -1;
|
||||
if (tDecodeU64(&decoder, &pReq->queryId) < 0) return -1;
|
||||
if (tDecodeU64(&decoder, &pReq->taskId) < 0) return -1;
|
||||
if (tDecodeU32(&decoder, &pReq->sqlLen) < 0) return -1;
|
||||
if (tDecodeU32(&decoder, &pReq->phyLen) < 0) return -1;
|
||||
pReq->sql = taosMemoryCalloc(1, pReq->sqlLen + 1);
|
||||
if (NULL == pReq->sql) return -1;
|
||||
pReq->msg = taosMemoryCalloc(1, pReq->phyLen + 1);
|
||||
if (NULL == pReq->msg) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->sql) < 0) return -1;
|
||||
if (tDecodeCStrTo(&decoder, pReq->msg) < 0) return -1;
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
||||
tDecoderClear(&decoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVDeleteReq(SDecoder* pCoder, SVDeleteReq* pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI64(pCoder, &pReq->delUid) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pReq->tbUid) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pReq->type) < 0) return -1;
|
||||
if (tDecodeI16v(pCoder, &pReq->nWnds) < 0) return -1;
|
||||
if (tDecodeCStr(pCoder, &pReq->tbFullName) < 0) return -1;
|
||||
if (tDecodeCStr(pCoder, &pReq->subPlan) < 0) return -1;
|
||||
for (int16_t i = 0; i < pReq->nWnds; ++i) {
|
||||
if (tDecodeI64(pCoder, &pReq->wnds[i].skey) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pReq->wnds[i].ekey) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSVDeleteRsp(SEncoder* pCoder, const SVDeleteRsp* pReq) {
|
||||
int32_t tEncodeSVDeleteRsp(SEncoder *pCoder, const SVDeleteRsp *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI32(pCoder, pReq->code) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pReq->affectedRows) < 0) return -1;
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVDeleteRsp(SDecoder* pCoder, SVDeleteRsp* pReq) {
|
||||
int32_t tDecodeSVDeleteRsp(SDecoder *pCoder, SVDeleteRsp *pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI32(pCoder, &pReq->code) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pReq->affectedRows) < 0) return -1;
|
||||
|
||||
tEndDecode(pCoder);
|
||||
|
@ -4559,7 +4593,7 @@ int32_t tDeserializeSMAlterStbRsp(void *buf, int32_t bufLen, SMAlterStbRsp *pRsp
|
|||
return 0;
|
||||
}
|
||||
|
||||
void tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp) {
|
||||
void tFreeSMAlterStbRsp(SMAlterStbRsp *pRsp) {
|
||||
if (NULL == pRsp) {
|
||||
return;
|
||||
}
|
||||
|
@ -4569,6 +4603,3 @@ void tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp) {
|
|||
taosMemoryFree(pRsp->pMeta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -358,6 +358,7 @@ SArray *vmGetMsgHandles() {
|
|||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RUN, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_DISPATCH, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_TASK_RECOVER, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||
|
|
|
@ -316,10 +316,12 @@ typedef struct {
|
|||
int32_t tagsFilterLen;
|
||||
int32_t sqlLen;
|
||||
int32_t astLen;
|
||||
int32_t numOfVgroups;
|
||||
char* expr;
|
||||
char* tagsFilter;
|
||||
char* sql;
|
||||
char* ast;
|
||||
SVgEpSet* pVgEpSet;
|
||||
} SSmaObj;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -28,7 +28,7 @@ SDnodeObj *mndAcquireDnode(SMnode *pMnode, int32_t dnodeId);
|
|||
void mndReleaseDnode(SMnode *pMnode, SDnodeObj *pDnode);
|
||||
SEpSet mndGetDnodeEpset(SDnodeObj *pDnode);
|
||||
int32_t mndGetDnodeSize(SMnode *pMnode);
|
||||
bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs);
|
||||
bool mndIsDnodeOnline(SDnodeObj *pDnode, int64_t curMs);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId);
|
|||
void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj);
|
||||
bool mndIsMnode(SMnode *pMnode, int32_t dnodeId);
|
||||
void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet);
|
||||
int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -30,15 +30,21 @@ SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup);
|
|||
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup);
|
||||
int32_t mndGetVnodesNum(SMnode *pMnode, int32_t dnodeId);
|
||||
|
||||
int32_t mndAllocSmaVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup);
|
||||
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups);
|
||||
SArray *mndBuildDnodesArray(SMnode *pMnode);
|
||||
int32_t mndAddVnodeToVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray);
|
||||
int32_t mndRemoveVnodeFromVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray, SVnodeGid *pVgId);
|
||||
SArray *mndBuildDnodesArray(SMnode *, int32_t exceptDnodeId);
|
||||
int32_t mndAllocSmaVgroup(SMnode *, SDbObj *pDb, SVgObj *pVgroup);
|
||||
int32_t mndAllocVgroup(SMnode *, SDbObj *pDb, SVgObj **ppVgroups);
|
||||
int32_t mndAddVnodeToVgroup(SMnode *, SVgObj *pVgroup, SArray *pArray);
|
||||
int32_t mndRemoveVnodeFromVgroup(SMnode *, SVgObj *pVgroup, SArray *pArray, SVnodeGid *pDelVgid);
|
||||
int32_t mndAddCreateVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, bool standby);
|
||||
int32_t mndAddAlterVnodeConfirmAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup);
|
||||
int32_t mndAddAlterVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, tmsg_t msgType);
|
||||
int32_t mndAddDropVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, bool isRedo);
|
||||
int32_t mndSetMoveVgroupInfoToTrans(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t vn, SArray *pArray);
|
||||
int32_t mndSetMoveVgroupsInfoToTrans(SMnode *, STrans *pTrans, int32_t dropDnodeId);
|
||||
|
||||
void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen, bool standby);
|
||||
void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
void *mndBuildCreateVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *cntlen, bool standby);
|
||||
void *mndBuildDropVnodeReq(SMnode *, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
void *mndBuildAlterVnodeReq(SMnode *, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -299,7 +299,7 @@ static int32_t mndProcessCreateBnodeReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser)) {
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -409,7 +409,7 @@ static int32_t mndProcessDropBnodeReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser)) {
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
|
|
@ -263,111 +263,6 @@ void mndReleaseDb(SMnode *pMnode, SDbObj *pDb) {
|
|||
sdbRelease(pSdb, pDb);
|
||||
}
|
||||
|
||||
static int32_t mndAddCreateVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid,
|
||||
bool standby) {
|
||||
STransAction action = {0};
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildCreateVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen, standby);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_CREATE_VNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAddAlterVnodeConfirmAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
||||
int32_t contLen = sizeof(SMsgHead);
|
||||
SMsgHead *pHead = taosMemoryMalloc(contLen);
|
||||
if (pHead == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pHead->contLen = htonl(contLen);
|
||||
pHead->vgId = htonl(pVgroup->vgId);
|
||||
|
||||
action.pCont = pHead;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_VND_ALTER_CONFIRM;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pHead);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAddAlterVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, tmsg_t msgType) {
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildAlterVnodeReq(pMnode, pDb, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = msgType;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAddDropVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid,
|
||||
bool isRedo) {
|
||||
STransAction action = {0};
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildDropVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_DROP_VNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
|
||||
if (isRedo) {
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCheckDbName(const char *dbName, SUserObj *pUser) {
|
||||
char *pos = strstr(dbName, TS_PATH_DELIMITER);
|
||||
if (pos == NULL) {
|
||||
|
@ -795,7 +690,7 @@ static int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj
|
|||
static int32_t mndSetAlterDbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pOld, SDbObj *pNew) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode);
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, 0);
|
||||
|
||||
while (1) {
|
||||
SVgObj *pVgroup = NULL;
|
||||
|
@ -1497,19 +1392,25 @@ char *buildRetension(SArray *pRetension) {
|
|||
|
||||
int64_t v1 = getValOfDiffPrecision(p->freqUnit, p->freq);
|
||||
int64_t v2 = getValOfDiffPrecision(p->keepUnit, p->keep);
|
||||
len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c,", v1, p->freqUnit, v2, p->keepUnit);
|
||||
len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit);
|
||||
|
||||
if (size > 1) {
|
||||
len += sprintf(p1 + len, ",");
|
||||
p = taosArrayGet(pRetension, 1);
|
||||
|
||||
v1 = getValOfDiffPrecision(p->freqUnit, p->freq);
|
||||
v2 = getValOfDiffPrecision(p->keepUnit, p->keep);
|
||||
len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c,", v1, p->freqUnit, v2, p->keepUnit);
|
||||
len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit);
|
||||
}
|
||||
|
||||
if (size > 2) {
|
||||
len += sprintf(p1 + len, ",");
|
||||
p = taosArrayGet(pRetension, 2);
|
||||
|
||||
v1 = getValOfDiffPrecision(p->freqUnit, p->freq);
|
||||
v2 = getValOfDiffPrecision(p->keepUnit, p->keep);
|
||||
len += sprintf(p1 + len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit);
|
||||
}
|
||||
|
||||
varDataSetLen(p1, len);
|
||||
return p1;
|
||||
|
@ -1742,3 +1643,4 @@ static void mndCancelGetNextDb(SMnode *pMnode, void *pIter) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
|
|
|
@ -254,7 +254,7 @@ int32_t mndGetDnodeSize(SMnode *pMnode) {
|
|||
return sdbGetSize(pSdb, SDB_DNODE);
|
||||
}
|
||||
|
||||
bool mndIsDnodeOnline(SMnode *pMnode, SDnodeObj *pDnode, int64_t curMs) {
|
||||
bool mndIsDnodeOnline(SDnodeObj *pDnode, int64_t curMs) {
|
||||
int64_t interval = TABS(pDnode->lastAccessTime - curMs);
|
||||
if (interval > 5000 * tsStatusInterval) {
|
||||
if (pDnode->rebootTime > 0) {
|
||||
|
@ -393,7 +393,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
|
|||
|
||||
int64_t dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE) + sdbGetTableVer(pMnode->pSdb, SDB_MNODE);
|
||||
int64_t curMs = taosGetTimestampMs();
|
||||
bool online = mndIsDnodeOnline(pMnode, pDnode, curMs);
|
||||
bool online = mndIsDnodeOnline(pDnode, curMs);
|
||||
bool dnodeChanged = (statusReq.dnodeVer != dnodeVer);
|
||||
bool reboot = (pDnode->rebootTime != statusReq.rebootTime);
|
||||
bool needCheck = !online || dnodeChanged || reboot;
|
||||
|
@ -542,7 +542,7 @@ static int32_t mndProcessCreateDnodeReq(SRpcMsg *pReq) {
|
|||
goto CREATE_DNODE_OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser)) {
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto CREATE_DNODE_OVER;
|
||||
}
|
||||
|
||||
|
@ -559,30 +559,36 @@ CREATE_DNODE_OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode) {
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_GLOBAL, pReq);
|
||||
if (pTrans == NULL) {
|
||||
mError("dnode:%d, failed to drop since %s", pDnode->id, terrstr());
|
||||
return -1;
|
||||
}
|
||||
static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMnodeObj *pMObj) {
|
||||
int32_t code = -1;
|
||||
SSdbRaw *pRaw = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq);
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
mndTransSetSerial(pTrans);
|
||||
mDebug("trans:%d, used to drop dnode:%d", pTrans->id, pDnode->id);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndDnodeActionEncode(pDnode);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||
pRaw = mndDnodeActionEncode(pDnode);
|
||||
if (pRaw == NULL || mndTransAppendRedolog(pTrans, pRaw) != 0) goto _OVER;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_DROPPING);
|
||||
pRaw = NULL;
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
pRaw = mndDnodeActionEncode(pDnode);
|
||||
if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_DROPPED);
|
||||
pRaw = NULL;
|
||||
|
||||
if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pMObj) != 0) goto _OVER;
|
||||
if (mndSetMoveVgroupsInfoToTrans(pMnode, pTrans, pDnode->id) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
sdbFreeRaw(pRaw);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) {
|
||||
|
@ -595,42 +601,53 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) {
|
|||
|
||||
if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto DROP_DNODE_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
mDebug("dnode:%d, start to drop", dropReq.dnodeId);
|
||||
|
||||
if (dropReq.dnodeId <= 0) {
|
||||
terrno = TSDB_CODE_MND_INVALID_DNODE_ID;
|
||||
goto DROP_DNODE_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pDnode = mndAcquireDnode(pMnode, dropReq.dnodeId);
|
||||
if (pDnode == NULL) {
|
||||
terrno = TSDB_CODE_MND_DNODE_NOT_EXIST;
|
||||
goto DROP_DNODE_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (!mndIsDnodeOnline(pDnode, taosGetTimestampMs())) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pMObj = mndAcquireMnode(pMnode, dropReq.dnodeId);
|
||||
if (pMObj != NULL) {
|
||||
terrno = TSDB_CODE_MND_MNODE_NOT_EXIST;
|
||||
goto DROP_DNODE_OVER;
|
||||
if (sdbGetSize(pMnode->pSdb, SDB_MNODE) <= 1) {
|
||||
terrno = TSDB_CODE_MND_TOO_FEW_MNODES;
|
||||
goto _OVER;
|
||||
}
|
||||
if (pMnode->selfDnodeId == dropReq.dnodeId) {
|
||||
terrno = TSDB_CODE_MND_CANT_DROP_MASTER;
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
|
||||
pUser = mndAcquireUser(pMnode, pReq->conn.user);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
goto DROP_DNODE_OVER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser)) {
|
||||
goto DROP_DNODE_OVER;
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
code = mndDropDnode(pMnode, pReq, pDnode);
|
||||
code = mndDropDnode(pMnode, pReq, pDnode, pMObj);
|
||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
||||
DROP_DNODE_OVER:
|
||||
_OVER:
|
||||
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||
mError("dnode:%d, failed to drop since %s", dropReq.dnodeId, terrstr());
|
||||
}
|
||||
|
@ -638,7 +655,6 @@ DROP_DNODE_OVER:
|
|||
mndReleaseDnode(pMnode, pDnode);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
mndReleaseMnode(pMnode, pMObj);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -736,7 +752,7 @@ static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
|||
while (numOfRows < rows) {
|
||||
pShow->pIter = sdbFetch(pSdb, SDB_DNODE, pShow->pIter, (void **)&pDnode);
|
||||
if (pShow->pIter == NULL) break;
|
||||
bool online = mndIsDnodeOnline(pMnode, pDnode, curMs);
|
||||
bool online = mndIsDnodeOnline(pDnode, curMs);
|
||||
|
||||
cols = 0;
|
||||
|
||||
|
|
|
@ -529,7 +529,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
|||
SMonDnodeDesc desc = {0};
|
||||
desc.dnode_id = pObj->id;
|
||||
tstrncpy(desc.dnode_ep, pObj->ep, sizeof(desc.dnode_ep));
|
||||
if (mndIsDnodeOnline(pMnode, pObj, ms)) {
|
||||
if (mndIsDnodeOnline(pObj, ms)) {
|
||||
tstrncpy(desc.status, "ready", sizeof(desc.status));
|
||||
} else {
|
||||
tstrncpy(desc.status, "offline", sizeof(desc.status));
|
||||
|
|
|
@ -358,9 +358,9 @@ static int32_t mndCreateMnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode,
|
|||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq);
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
|
||||
mDebug("trans:%d, used to create mnode:%d", pTrans->id, pCreate->dnodeId);
|
||||
mndTransSetSerial(pTrans);
|
||||
mDebug("trans:%d, used to create mnode:%d", pTrans->id, pCreate->dnodeId);
|
||||
|
||||
if (mndSetCreateMnodeRedoLogs(pMnode, pTrans, &mnodeObj) != 0) goto _OVER;
|
||||
if (mndSetCreateMnodeCommitLogs(pMnode, pTrans, &mnodeObj) != 0) goto _OVER;
|
||||
if (mndSetCreateMnodeRedoActions(pMnode, pTrans, pDnode, &mnodeObj) != 0) goto _OVER;
|
||||
|
@ -408,7 +408,7 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (!mndIsDnodeOnline(pMnode, pDnode, taosGetTimestampMs())) {
|
||||
if (!mndIsDnodeOnline(pDnode, taosGetTimestampMs())) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -419,7 +419,7 @@ static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser)) {
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -535,18 +535,25 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) {
|
||||
if (pObj == NULL) return 0;
|
||||
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1;
|
||||
if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) return -1;
|
||||
if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj) != 0) return -1;
|
||||
if (mndTransAppendNullLog(pTrans) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndDropMnode(SMnode *pMnode, SRpcMsg *pReq, SMnodeObj *pObj) {
|
||||
int32_t code = -1;
|
||||
STrans *pTrans = NULL;
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq);
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq);
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
|
||||
mDebug("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id);
|
||||
mndTransSetSerial(pTrans);
|
||||
if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) goto _OVER;
|
||||
if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) goto _OVER;
|
||||
if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj) != 0) goto _OVER;
|
||||
if (mndTransAppendNullLog(pTrans) != 0) goto _OVER;
|
||||
mDebug("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id);
|
||||
|
||||
if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pObj) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
|
@ -596,7 +603,7 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser)) {
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -642,7 +649,7 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
|||
if (pObj->id == pMnode->selfDnodeId) {
|
||||
roles = syncStr(TAOS_SYNC_STATE_LEADER);
|
||||
}
|
||||
if (pObj->pDnode && mndIsDnodeOnline(pMnode, pObj->pDnode, curMs)) {
|
||||
if (pObj->pDnode && mndIsDnodeOnline(pObj->pDnode, curMs)) {
|
||||
roles = syncStr(pObj->state);
|
||||
}
|
||||
char b2[12 + VARSTR_HEADER_SIZE] = {0};
|
||||
|
|
|
@ -301,7 +301,7 @@ static int32_t mndProcessCreateQnodeReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser)) {
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -411,7 +411,7 @@ static int32_t mndProcessDropQnodeReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser)) {
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -230,7 +230,7 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p
|
|||
int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
||||
ASSERT(pStream->fixedSinkVgId != 0);
|
||||
SArray* tasks = taosArrayGetP(pStream->tasks, 0);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
if (pTask == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
|
@ -322,7 +322,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
// source part
|
||||
pTask->sourceType = TASK_SOURCE__SCAN;
|
||||
pTask->inputType = TASK_INPUT_TYPE__SUMBIT_BLOCK;
|
||||
|
@ -387,7 +387,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
|
||||
// else, assign to vnode
|
||||
ASSERT(plan->subplanType == SUBPLAN_TYPE_MERGE);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
|
||||
// source part, currently only support multi source
|
||||
pTask->sourceType = TASK_SOURCE__PIPE;
|
||||
|
@ -477,7 +477,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid);
|
||||
SStreamTask* pTask = tNewSStreamTask(pStream->uid, 0);
|
||||
|
||||
// source part
|
||||
pTask->sourceType = TASK_SOURCE__MERGE;
|
||||
|
|
|
@ -36,6 +36,7 @@ static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw);
|
|||
static int32_t mndSmaActionInsert(SSdb *pSdb, SSmaObj *pSma);
|
||||
static int32_t mndSmaActionDelete(SSdb *pSdb, SSmaObj *pSpSmatb);
|
||||
static int32_t mndSmaActionUpdate(SSdb *pSdb, SSmaObj *pOld, SSmaObj *pNew);
|
||||
static int32_t mndSmaGetVgEpSet(SMnode *pMnode, SDbObj *pDb, SVgEpSet **ppVgEpSet, int32_t *numOfVgroups);
|
||||
static int32_t mndProcessMCreateSmaReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessMDropSmaReq(SRpcMsg *pReq);
|
||||
static int32_t mndProcessGetSmaReq(SRpcMsg *pReq);
|
||||
|
@ -262,6 +263,8 @@ static void *mndBuildVCreateSmaReq(SMnode *pMnode, SVgObj *pVgroup, SSmaObj *pSm
|
|||
req.sliding = pSma->sliding;
|
||||
req.expr = pSma->expr;
|
||||
req.tagsFilter = pSma->tagsFilter;
|
||||
req.numOfVgroups = pSma->numOfVgroups;
|
||||
req.pVgEpSet = pSma->pVgEpSet;
|
||||
|
||||
// get length
|
||||
int32_t ret = 0;
|
||||
|
@ -420,6 +423,15 @@ static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans,
|
|||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
// todo add sma info here
|
||||
SVgEpSet *pVgEpSet = NULL;
|
||||
int32_t numOfVgroups = 0;
|
||||
if (mndSmaGetVgEpSet(pMnode, pDb, &pVgEpSet, &numOfVgroups) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pSma->pVgEpSet = pVgEpSet;
|
||||
pSma->numOfVgroups = numOfVgroups;
|
||||
|
||||
int32_t smaContLen = 0;
|
||||
void *pSmaReq = mndBuildVCreateSmaReq(pMnode, pVgroup, pSma, &smaContLen);
|
||||
if (pSmaReq == NULL) return -1;
|
||||
|
@ -510,10 +522,9 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
|
|||
int32_t code = -1;
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB, pReq);
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
|
||||
mDebug("trans:%d, used to create sma:%s", pTrans->id, pCreate->name);
|
||||
mndTransSetDbName(pTrans, pDb->name);
|
||||
mndTransSetSerial(pTrans);
|
||||
mDebug("trans:%d, used to create sma:%s", pTrans->id, pCreate->name);
|
||||
|
||||
if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER;
|
||||
if (mndSetCreateSmaVgroupRedoLogs(pMnode, pTrans, &streamObj.fixedSinkVg) != 0) goto _OVER;
|
||||
|
@ -964,3 +975,52 @@ static void mndCancelGetNextSma(SMnode *pMnode, void *pIter) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
static int32_t mndSmaGetVgEpSet(SMnode *pMnode, SDbObj *pDb, SVgEpSet **ppVgEpSet, int32_t *numOfVgroups) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
SVgObj *pVgroup = NULL;
|
||||
void *pIter = NULL;
|
||||
SVgEpSet *pVgEpSet = NULL;
|
||||
int32_t nAllocVgs = 16;
|
||||
int32_t nVgs = 0;
|
||||
|
||||
pVgEpSet = taosMemoryCalloc(nAllocVgs, sizeof(SVgEpSet));
|
||||
if (!pVgEpSet) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
if (pVgroup->dbUid != pDb->uid) {
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nVgs >= nAllocVgs) {
|
||||
void *p = taosMemoryRealloc(pVgEpSet, nAllocVgs * 2 * sizeof(SVgEpSet));
|
||||
if (!p) {
|
||||
taosMemoryFree(pVgEpSet);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
pVgEpSet = (SVgEpSet *)p;
|
||||
nAllocVgs *= 2;
|
||||
}
|
||||
|
||||
(pVgEpSet + nVgs)->vgId = pVgroup->vgId;
|
||||
(pVgEpSet + nVgs)->epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
||||
++nVgs;
|
||||
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
}
|
||||
|
||||
*ppVgEpSet = pVgEpSet;
|
||||
*numOfVgroups = nVgs;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -307,7 +307,7 @@ static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser)) {
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -419,7 +419,7 @@ static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser)) {
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
|
|
@ -1108,7 +1108,7 @@ static int32_t mndDropSuperTableColumn(SMnode *pMnode, const SStbObj *pOld, SStb
|
|||
return -1;
|
||||
}
|
||||
|
||||
col_id_t colId = pOld->pTags[col].colId;
|
||||
col_id_t colId = pOld->pColumns[col].colId;
|
||||
if (mndCheckColAndTagModifiable(pMnode, pOld->uid, colId) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -1142,7 +1142,7 @@ static int32_t mndAlterStbColumnBytes(SMnode *pMnode, const SStbObj *pOld, SStbO
|
|||
return -1;
|
||||
}
|
||||
|
||||
col_id_t colId = pOld->pTags[col].colId;
|
||||
col_id_t colId = pOld->pColumns[col].colId;
|
||||
if (mndCheckColAndTagModifiable(pMnode, pOld->uid, colId) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ int32_t mndCheckColAndTagModifiable(SMnode *pMnode, int64_t suid, col_id_t colId
|
|||
}
|
||||
|
||||
SHashObj *pColHash = NULL;
|
||||
SNodeList *pNodeList;
|
||||
SNodeList *pNodeList = NULL;
|
||||
nodesCollectColumns((SSelectStmt *)pAst, SQL_CLAUSE_FROM, NULL, COLLECT_COL_TYPE_ALL, &pNodeList);
|
||||
SNode *pNode = NULL;
|
||||
FOREACH(pNode, pNodeList) {
|
||||
|
@ -103,6 +103,7 @@ int32_t mndCheckColAndTagModifiable(SMnode *pMnode, int64_t suid, col_id_t colId
|
|||
if (pCol->colId > 0) {
|
||||
taosHashPut(pColHash, &pCol->colId, sizeof(int16_t), NULL, 0);
|
||||
}
|
||||
mTrace("topic:%s, colId:%d is used", pTopic->name, pCol->colId);
|
||||
}
|
||||
|
||||
if (taosHashGet(pColHash, &colId, sizeof(int16_t)) != NULL) {
|
||||
|
|
|
@ -15,11 +15,13 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mndVgroup.h"
|
||||
#include "mndAuth.h"
|
||||
#include "mndDb.h"
|
||||
#include "mndDnode.h"
|
||||
#include "mndMnode.h"
|
||||
#include "mndShow.h"
|
||||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
|
||||
#define VGROUP_VER_NUMBER 1
|
||||
#define VGROUP_RESERVE_SIZE 64
|
||||
|
@ -34,6 +36,10 @@ static void mndCancelGetNextVgroup(SMnode *pMnode, void *pIter);
|
|||
static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||
static void mndCancelGetNextVnode(SMnode *pMnode, void *pIter);
|
||||
|
||||
static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq);
|
||||
static int32_t mndProcessSplitVgroupMsg(SRpcMsg *pReq);
|
||||
static int32_t mndProcessBalanceVgroupMsg(SRpcMsg *pReq);
|
||||
|
||||
int32_t mndInitVgroup(SMnode *pMnode) {
|
||||
SSdbTable table = {
|
||||
.sdbType = SDB_VGROUP,
|
||||
|
@ -344,9 +350,14 @@ static bool mndResetDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2
|
|||
static bool mndBuildDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) {
|
||||
SDnodeObj *pDnode = pObj;
|
||||
SArray *pArray = p1;
|
||||
int32_t exceptDnodeId = *(int32_t *)p2;
|
||||
|
||||
if (exceptDnodeId == pDnode->id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int64_t curMs = taosGetTimestampMs();
|
||||
bool online = mndIsDnodeOnline(pMnode, pDnode, curMs);
|
||||
bool online = mndIsDnodeOnline(pDnode, curMs);
|
||||
bool isMnode = mndIsMnode(pMnode, pDnode->id);
|
||||
pDnode->numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id);
|
||||
|
||||
|
@ -363,7 +374,7 @@ static bool mndBuildDnodesArrayFp(SMnode *pMnode, void *pObj, void *p1, void *p2
|
|||
return true;
|
||||
}
|
||||
|
||||
SArray *mndBuildDnodesArray(SMnode *pMnode) {
|
||||
SArray *mndBuildDnodesArray(SMnode *pMnode, int32_t exceptDnodeId) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfDnodes = mndGetDnodeSize(pMnode);
|
||||
|
||||
|
@ -374,7 +385,7 @@ SArray *mndBuildDnodesArray(SMnode *pMnode) {
|
|||
}
|
||||
|
||||
sdbTraverse(pSdb, SDB_DNODE, mndResetDnodesArrayFp, NULL, NULL, NULL);
|
||||
sdbTraverse(pSdb, SDB_DNODE, mndBuildDnodesArrayFp, pArray, NULL, NULL);
|
||||
sdbTraverse(pSdb, SDB_DNODE, mndBuildDnodesArrayFp, pArray, &exceptDnodeId, NULL);
|
||||
return pArray;
|
||||
}
|
||||
|
||||
|
@ -422,7 +433,7 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup, SArray *pAr
|
|||
}
|
||||
|
||||
int32_t mndAllocSmaVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode);
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, 0);
|
||||
if (pArray == NULL) return -1;
|
||||
|
||||
pVgroup->vgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP);
|
||||
|
@ -451,7 +462,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
pArray = mndBuildDnodesArray(pMnode);
|
||||
pArray = mndBuildDnodesArray(pMnode, 0);
|
||||
if (pArray == NULL) goto _OVER;
|
||||
|
||||
mInfo("db:%s, total %d dnodes used to create %d vgroups (%d vnodes)", pDb->name, (int32_t)taosArrayGetSize(pArray),
|
||||
|
@ -501,86 +512,6 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t mndAddVnodeToVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray) {
|
||||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mDebug("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes);
|
||||
}
|
||||
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[pVgroup->replica];
|
||||
for (int32_t d = 0; d < taosArrayGetSize(pArray); ++d) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, d);
|
||||
|
||||
bool used = false;
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
if (pDnode->id == pVgroup->vnodeGid[vn].dnodeId) {
|
||||
used = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (used) continue;
|
||||
|
||||
if (pDnode == NULL || pDnode->numOfVnodes > pDnode->numOfSupportVnodes) {
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pVgid->dnodeId = pDnode->id;
|
||||
pVgid->role = TAOS_SYNC_STATE_ERROR;
|
||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d, is added", pVgroup->dbName, pVgroup->vgId, pVgroup->replica,
|
||||
pVgid->dnodeId);
|
||||
|
||||
pVgroup->replica++;
|
||||
pDnode->numOfVnodes++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
mError("db:%s, failed to add vnode to vgId:%d since %s", pVgroup->dbName, pVgroup->vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mndRemoveVnodeFromVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray, SVnodeGid *pDelVgid) {
|
||||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mDebug("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes);
|
||||
}
|
||||
|
||||
int32_t code = -1;
|
||||
for (int32_t d = taosArrayGetSize(pArray) - 1; d >= 0; --d) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, d);
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[vn];
|
||||
if (pVgid->dnodeId == pDnode->id) {
|
||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d, is removed", pVgroup->dbName, pVgroup->vgId, vn, pVgid->dnodeId);
|
||||
pDnode->numOfVnodes--;
|
||||
pVgroup->replica--;
|
||||
*pDelVgid = *pVgid;
|
||||
*pVgid = pVgroup->vnodeGid[pVgroup->replica];
|
||||
memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid));
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_OVER:
|
||||
if (code != 0) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
mError("db:%s, failed to remove vnode from vgId:%d since %s", pVgroup->dbName, pVgroup->vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[vn];
|
||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d is reserved", pVgroup->dbName, pVgroup->vgId, vn, pVgid->dnodeId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup) {
|
||||
SEpSet epset = {0};
|
||||
|
||||
|
@ -678,7 +609,7 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p
|
|||
bool online = false;
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgroup->vnodeGid[i].dnodeId);
|
||||
if (pDnode != NULL) {
|
||||
online = mndIsDnodeOnline(pMnode, pDnode, curMs);
|
||||
online = mndIsDnodeOnline(pDnode, curMs);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
}
|
||||
|
||||
|
@ -797,3 +728,597 @@ static void mndCancelGetNextVnode(SMnode *pMnode, void *pIter) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
int32_t mndAddVnodeToVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray) {
|
||||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mDebug("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes);
|
||||
}
|
||||
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[pVgroup->replica];
|
||||
for (int32_t d = 0; d < taosArrayGetSize(pArray); ++d) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, d);
|
||||
|
||||
bool used = false;
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
if (pDnode->id == pVgroup->vnodeGid[vn].dnodeId) {
|
||||
used = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (used) continue;
|
||||
|
||||
if (pDnode == NULL || pDnode->numOfVnodes > pDnode->numOfSupportVnodes) {
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pVgid->dnodeId = pDnode->id;
|
||||
pVgid->role = TAOS_SYNC_STATE_ERROR;
|
||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d, is added", pVgroup->dbName, pVgroup->vgId, pVgroup->replica, pVgid->dnodeId);
|
||||
|
||||
pVgroup->replica++;
|
||||
pDnode->numOfVnodes++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
|
||||
mError("db:%s, failed to add vnode to vgId:%d since %s", pVgroup->dbName, pVgroup->vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mndRemoveVnodeFromVgroup(SMnode *pMnode, SVgObj *pVgroup, SArray *pArray, SVnodeGid *pDelVgid) {
|
||||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pArray); ++i) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, i);
|
||||
mDebug("dnode:%d, equivalent vnodes:%d", pDnode->id, pDnode->numOfVnodes);
|
||||
}
|
||||
|
||||
int32_t code = -1;
|
||||
for (int32_t d = taosArrayGetSize(pArray) - 1; d >= 0; --d) {
|
||||
SDnodeObj *pDnode = taosArrayGet(pArray, d);
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[vn];
|
||||
if (pVgid->dnodeId == pDnode->id) {
|
||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d, is removed", pVgroup->dbName, pVgroup->vgId, vn, pVgid->dnodeId);
|
||||
pDnode->numOfVnodes--;
|
||||
pVgroup->replica--;
|
||||
*pDelVgid = *pVgid;
|
||||
*pVgid = pVgroup->vnodeGid[pVgroup->replica];
|
||||
memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid));
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_OVER:
|
||||
if (code != 0) {
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
mError("db:%s, failed to remove vnode from vgId:%d since %s", pVgroup->dbName, pVgroup->vgId, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int32_t vn = 0; vn < pVgroup->replica; ++vn) {
|
||||
SVnodeGid *pVgid = &pVgroup->vnodeGid[vn];
|
||||
mInfo("db:%s, vgId:%d, vn:%d dnode:%d is reserved", pVgroup->dbName, pVgroup->vgId, vn, pVgid->dnodeId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddCreateVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid,
|
||||
bool standby) {
|
||||
STransAction action = {0};
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildCreateVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen, standby);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_CREATE_VNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddAlterVnodeConfirmAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup) {
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
||||
int32_t contLen = sizeof(SMsgHead);
|
||||
SMsgHead *pHead = taosMemoryMalloc(contLen);
|
||||
if (pHead == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pHead->contLen = htonl(contLen);
|
||||
pHead->vgId = htonl(pVgroup->vgId);
|
||||
|
||||
action.pCont = pHead;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_VND_ALTER_CONFIRM;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pHead);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddAlterVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, tmsg_t msgType) {
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetVgroupEpset(pMnode, pVgroup);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildAlterVnodeReq(pMnode, pDb, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = msgType;
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndAddDropVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid,
|
||||
bool isRedo) {
|
||||
STransAction action = {0};
|
||||
|
||||
SDnodeObj *pDnode = mndAcquireDnode(pMnode, pVgid->dnodeId);
|
||||
if (pDnode == NULL) return -1;
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
mndReleaseDnode(pMnode, pDnode);
|
||||
|
||||
int32_t contLen = 0;
|
||||
void *pReq = mndBuildDropVnodeReq(pMnode, pDnode, pDb, pVgroup, &contLen);
|
||||
if (pReq == NULL) return -1;
|
||||
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_DROP_VNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
|
||||
if (isRedo) {
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (mndTransAppendUndoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t vnIndex,
|
||||
SArray *pArray) {
|
||||
SVgObj newVg = {0};
|
||||
memcpy(&newVg, pVgroup, sizeof(SVgObj));
|
||||
|
||||
mInfo("vgId:%d, vgroup info before move, replica:%d", newVg.vgId, newVg.replica);
|
||||
for (int32_t i = 0; i < newVg.replica; ++i) {
|
||||
mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId);
|
||||
}
|
||||
|
||||
mInfo("vgId:%d, will add 1 vnodes", pVgroup->vgId);
|
||||
if (mndAddVnodeToVgroup(pMnode, &newVg, pArray) != 0) return -1;
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[1], true) != 0) return -1;
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1;
|
||||
|
||||
mInfo("vgId:%d, will remove 1 vnodes", pVgroup->vgId);
|
||||
newVg.replica--;
|
||||
SVnodeGid del = newVg.vnodeGid[vnIndex];
|
||||
newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica];
|
||||
memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid));
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1;
|
||||
|
||||
mInfo("vgId:%d, vgroup info after move, replica:%d", newVg.vgId, newVg.replica);
|
||||
for (int32_t i = 0; i < newVg.replica; ++i) {
|
||||
mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndSetMoveVgroupsInfoToTrans(SMnode *pMnode, STrans *pTrans, int32_t delDnodeId) {
|
||||
SArray *pArray = mndBuildDnodesArray(pMnode, delDnodeId);
|
||||
if (pArray == NULL) return -1;
|
||||
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
SVgObj *pVgroup = NULL;
|
||||
pIter = sdbFetch(pMnode->pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
int32_t vnIndex = -1;
|
||||
for (int32_t i = 0; i < pVgroup->replica; ++i) {
|
||||
if (pVgroup->vnodeGid[i].dnodeId == delDnodeId) {
|
||||
vnIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (vnIndex != -1) {
|
||||
mInfo("vgId:%d, vnode:%d will be removed from dnode:%d", pVgroup->vgId, vnIndex, delDnodeId);
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName);
|
||||
mndSetMoveVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, vnIndex, pArray);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
}
|
||||
|
||||
sdbRelease(pMnode->pSdb, pVgroup);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAddIncVgroupReplicaToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup,
|
||||
int32_t newDnodeId) {
|
||||
mDebug("vgId:%d, will add 1 vnode, replica:%d, dnode:%d", pVgroup->vgId, pVgroup->replica, newDnodeId);
|
||||
|
||||
SVnodeGid *pGid = &pVgroup->vnodeGid[pVgroup->replica];
|
||||
pVgroup->replica++;
|
||||
pGid->dnodeId = newDnodeId;
|
||||
pGid->role = TAOS_SYNC_STATE_ERROR;
|
||||
|
||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pGid, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, pVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndAddDecVgroupReplicaFromTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup,
|
||||
int32_t delDnodeId) {
|
||||
mDebug("vgId:%d, will remove 1 vnode, replica:%d, dnode:%d", pVgroup->vgId, pVgroup->replica, delDnodeId);
|
||||
|
||||
SVnodeGid *pGid = NULL;
|
||||
SVnodeGid delGid = {0};
|
||||
for (int32_t i = 0; i < pVgroup->replica; ++i) {
|
||||
if (pVgroup->vnodeGid[i].dnodeId == delDnodeId) {
|
||||
pGid = &pVgroup->vnodeGid[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pGid == NULL) return 0;
|
||||
|
||||
memcpy(&delGid, pGid, sizeof(SVnodeGid));
|
||||
memcpy(pGid, &pVgroup->vnodeGid[pVgroup->replica], sizeof(SVnodeGid));
|
||||
memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid));
|
||||
pVgroup->replica--;
|
||||
|
||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, pVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1;
|
||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj *pVgroup, SDnodeObj *pNew1,
|
||||
SDnodeObj *pOld1, SDnodeObj *pNew2, SDnodeObj *pOld2, SDnodeObj *pNew3,
|
||||
SDnodeObj *pOld3) {
|
||||
int32_t code = -1;
|
||||
SSdbRaw *pRaw = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq);
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
mndTransSetSerial(pTrans);
|
||||
mDebug("trans:%d, used to drop redistribute vgId:%d", pTrans->id, pVgroup->vgId);
|
||||
|
||||
SVgObj newVg = {0};
|
||||
memcpy(&newVg, pVgroup, sizeof(SVgObj));
|
||||
mInfo("vgId:%d, vgroup info before redistribute, replica:%d", newVg.vgId, newVg.replica);
|
||||
for (int32_t i = 0; i < newVg.replica; ++i) {
|
||||
mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId);
|
||||
}
|
||||
|
||||
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew1->id) != 0) goto _OVER;
|
||||
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld1->id) != 0) goto _OVER;
|
||||
if (pNew2 != NULL) {
|
||||
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew2->id) != 0) goto _OVER;
|
||||
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld2->id) != 0) goto _OVER;
|
||||
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pNew3->id) != 0) goto _OVER;
|
||||
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pOld3->id) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
pRaw = mndVgroupActionEncode(&newVg);
|
||||
if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER;
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
pRaw = NULL;
|
||||
|
||||
mInfo("vgId:%d, vgroup info after redistribute, replica:%d", newVg.vgId, newVg.replica);
|
||||
for (int32_t i = 0; i < newVg.replica; ++i) {
|
||||
mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId);
|
||||
}
|
||||
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
code = 0;
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
sdbFreeRaw(pRaw);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessRedistributeVgroupMsg(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SUserObj *pUser = NULL;
|
||||
SDnodeObj *pNew1 = NULL;
|
||||
SDnodeObj *pNew2 = NULL;
|
||||
SDnodeObj *pNew3 = NULL;
|
||||
SDnodeObj *pOld1 = NULL;
|
||||
SDnodeObj *pOld2 = NULL;
|
||||
SDnodeObj *pOld3 = NULL;
|
||||
SVgObj *pVgroup = NULL;
|
||||
SDbObj *pDb = NULL;
|
||||
int32_t code = -1;
|
||||
int64_t curMs = taosGetTimestampMs();
|
||||
SMDropMnodeReq redReq = {0};
|
||||
|
||||
#if 0
|
||||
if (tDeserializeSCreateDropMQSBNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _OVER;
|
||||
}
|
||||
#endif
|
||||
|
||||
mDebug("vgId:%d, start to redistribute", 2);
|
||||
pUser = mndAcquireUser(pMnode, pReq->conn.user);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pVgroup = mndAcquireVgroup(pMnode, 2);
|
||||
if (pVgroup == NULL) goto _OVER;
|
||||
|
||||
pDb = mndAcquireDb(pMnode, pVgroup->dbName);
|
||||
if (pDb == NULL) goto _OVER;
|
||||
|
||||
if (pVgroup->replica == 1) {
|
||||
pNew1 = mndAcquireDnode(pMnode, 1);
|
||||
pOld1 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[0].dnodeId);
|
||||
if (pNew1 == NULL || pOld1 == NULL) goto _OVER;
|
||||
if (!mndIsDnodeOnline(pNew1, curMs) || !mndIsDnodeOnline(pOld1, curMs)) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
goto _OVER;
|
||||
}
|
||||
if (pNew1 == pOld1) {
|
||||
terrno = TSDB_CODE_MND_VGROUP_UN_CHANGED;
|
||||
goto _OVER;
|
||||
}
|
||||
if (mndRedistributeVgroup(pMnode, pReq, pDb, pVgroup, pNew1, pOld1, NULL, NULL, NULL, NULL) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (pVgroup->replica == 3) {
|
||||
pNew1 = mndAcquireDnode(pMnode, 1);
|
||||
pNew2 = mndAcquireDnode(pMnode, 2);
|
||||
pNew3 = mndAcquireDnode(pMnode, 3);
|
||||
pOld1 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[0].dnodeId);
|
||||
pOld2 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[1].dnodeId);
|
||||
pOld3 = mndAcquireDnode(pMnode, pVgroup->vnodeGid[2].dnodeId);
|
||||
if (pNew1 == NULL || pOld1 == NULL || pNew2 == NULL || pOld2 == NULL || pNew3 == NULL || pOld3 == NULL) goto _OVER;
|
||||
if (!mndIsDnodeOnline(pNew1, curMs) || !mndIsDnodeOnline(pOld1, curMs) || !mndIsDnodeOnline(pNew2, curMs) ||
|
||||
!mndIsDnodeOnline(pOld2, curMs) || !mndIsDnodeOnline(pNew3, curMs) || !mndIsDnodeOnline(pOld3, curMs)) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
goto _OVER;
|
||||
}
|
||||
bool changed = true;
|
||||
if (pNew1 != pOld1 || pNew1 != pOld2 || pNew1 != pOld3) changed = true;
|
||||
if (pNew2 != pOld1 || pNew2 != pOld2 || pNew2 != pOld3) changed = true;
|
||||
if (pNew3 != pOld1 || pNew3 != pOld2 || pNew3 != pOld3) changed = true;
|
||||
if (!changed) {
|
||||
terrno = TSDB_CODE_MND_VGROUP_UN_CHANGED;
|
||||
goto _OVER;
|
||||
}
|
||||
if (mndRedistributeVgroup(pMnode, pReq, pDb, pVgroup, pNew1, pOld1, pNew2, pOld2, pNew3, pOld3) != 0) goto _OVER;
|
||||
}
|
||||
|
||||
if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
|
||||
_OVER:
|
||||
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||
mDebug("vgId:%d, failed to redistribute since %s", 1, terrstr());
|
||||
}
|
||||
|
||||
mndReleaseDnode(pMnode, pNew1);
|
||||
mndReleaseDnode(pMnode, pNew2);
|
||||
mndReleaseDnode(pMnode, pNew3);
|
||||
mndReleaseDnode(pMnode, pOld1);
|
||||
mndReleaseDnode(pMnode, pOld2);
|
||||
mndReleaseDnode(pMnode, pOld3);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
mndReleaseVgroup(pMnode, pVgroup);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessSplitVgroupMsg(SRpcMsg *pReq) { return 0; }
|
||||
|
||||
static int32_t mndSetBalanceVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup,
|
||||
SDnodeObj *pSrc, SDnodeObj *pDst) {
|
||||
SVgObj newVg = {0};
|
||||
memcpy(&newVg, pVgroup, sizeof(SVgObj));
|
||||
mInfo("vgId:%d, vgroup info before balance, replica:%d", newVg.vgId, newVg.replica);
|
||||
for (int32_t i = 0; i < newVg.replica; ++i) {
|
||||
mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId);
|
||||
}
|
||||
|
||||
if (mndAddIncVgroupReplicaToTrans(pMnode, pTrans, pDb, &newVg, pDst->id) != 0) return -1;
|
||||
if (mndAddDecVgroupReplicaFromTrans(pMnode, pTrans, pDb, &newVg, pSrc->id) != 0) return -1;
|
||||
|
||||
SSdbRaw *pRaw = mndVgroupActionEncode(&newVg);
|
||||
if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) {
|
||||
sdbFreeRaw(pRaw);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||
|
||||
mInfo("vgId:%d, vgroup info after balance, replica:%d", newVg.vgId, newVg.replica);
|
||||
for (int32_t i = 0; i < newVg.replica; ++i) {
|
||||
mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndBalanceVgroupBetweenDnode(SMnode *pMnode, STrans *pTrans, SDnodeObj *pSrc, SDnodeObj *pDst) {
|
||||
void *pIter = NULL;
|
||||
int32_t code = -1;
|
||||
|
||||
while (1) {
|
||||
SVgObj *pVgroup = NULL;
|
||||
pIter = sdbFetch(pMnode->pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
bool existInSrc = false;
|
||||
bool existInDst = false;
|
||||
for (int32_t i = 0; i < pVgroup->replica; ++i) {
|
||||
SVnodeGid *pGid = &pVgroup->vnodeGid[i];
|
||||
if (pGid->dnodeId == pSrc->id) existInSrc = true;
|
||||
if (pGid->dnodeId == pDst->id) existInDst = true;
|
||||
}
|
||||
|
||||
if (!existInSrc || existInDst) {
|
||||
sdbRelease(pMnode->pSdb, pVgroup);
|
||||
}
|
||||
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName);
|
||||
code = mndSetBalanceVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, pSrc, pDst);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
sdbRelease(pMnode->pSdb, pVgroup);
|
||||
break;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndBalanceVgroup(SMnode *pMnode, SRpcMsg *pReq, SArray *pArray) {
|
||||
int32_t code = -1;
|
||||
int32_t numOfVgroups = 0;
|
||||
STrans *pTrans = NULL;
|
||||
|
||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq);
|
||||
if (pTrans == NULL) goto _OVER;
|
||||
mndTransSetSerial(pTrans);
|
||||
mDebug("trans:%d, used to balance vgroup", pTrans->id);
|
||||
|
||||
while (1) {
|
||||
taosArraySort(pArray, (__compar_fn_t)mndCompareDnodeVnodes);
|
||||
SDnodeObj *pSrc = taosArrayGet(pArray, 0);
|
||||
SDnodeObj *pDst = taosArrayGet(pArray, taosArrayGetSize(pArray) - 1);
|
||||
|
||||
float srcScore = (float)(pSrc->numOfVnodes - 1) / pSrc->numOfSupportVnodes;
|
||||
float dstScore = (float)(pDst->numOfVnodes + 1) / pDst->numOfSupportVnodes;
|
||||
if (srcScore + 0.0001 < dstScore) {
|
||||
mDebug("trans:%d, balance vgroup from dnode:%d to dnode:%d", pTrans->id, pSrc->id, pDst->id);
|
||||
code = mndBalanceVgroupBetweenDnode(pMnode, pTrans, pSrc, pDst);
|
||||
if (code == 0) {
|
||||
numOfVgroups++;
|
||||
continue;
|
||||
} else {
|
||||
mError("trans:%d, failed to balance vgroup from dnode:%d to dnode:%d", pTrans->id, pSrc->id, pDst->id);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
mDebug("trans:%d, no vgroup need to balance vgroup any more", pTrans->id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (numOfVgroups <= 0) {
|
||||
mDebug("no need to balance vgroup");
|
||||
code = 0;
|
||||
} else {
|
||||
mDebug("start to balance vgroup, numOfVgroups:%d", numOfVgroups);
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
code = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
_OVER:
|
||||
mndTransDrop(pTrans);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndProcessBalanceVgroupMsg(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
int32_t code = -1;
|
||||
SUserObj *pUser = NULL;
|
||||
SArray *pArray = NULL;
|
||||
void *pIter = NULL;
|
||||
int64_t curMs = taosGetTimestampMs();
|
||||
|
||||
mDebug("start to balance vgroup");
|
||||
pUser = mndAcquireUser(pMnode, pReq->conn.user);
|
||||
if (pUser == NULL) {
|
||||
terrno = TSDB_CODE_MND_NO_USER_FROM_CONN;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckNodeAuth(pUser) != 0) goto _OVER;
|
||||
|
||||
while (1) {
|
||||
SDnodeObj *pDnode = NULL;
|
||||
pIter = sdbFetch(pMnode->pSdb, SDB_DNODE, pIter, (void **)&pDnode);
|
||||
if (pIter == NULL) break;
|
||||
if (!mndIsDnodeOnline(pDnode, curMs)) {
|
||||
terrno = TSDB_CODE_MND_HAS_OFFLINE_DNODE;
|
||||
mError("failed to balance vgroup since %s, dnode:%d", terrstr(), pDnode->id);
|
||||
sdbRelease(pMnode->pSdb, pDnode);
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
sdbRelease(pMnode->pSdb, pDnode);
|
||||
}
|
||||
|
||||
pArray = mndBuildDnodesArray(pMnode, 0);
|
||||
if (pArray == NULL) goto _OVER;
|
||||
|
||||
if (taosArrayGetSize(pArray) < 2) {
|
||||
mDebug("no need to balance vgroup since dnode num less than 2");
|
||||
code = 0;
|
||||
} else {
|
||||
code = mndBalanceVgroup(pMnode, pReq, pArray);
|
||||
}
|
||||
|
||||
_OVER:
|
||||
if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
|
||||
mError("failed to balance vgroup since %s", terrstr());
|
||||
}
|
||||
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
taosArrayDestroy(pArray);
|
||||
return code;
|
||||
}
|
|
@ -42,8 +42,10 @@ SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) {
|
|||
}
|
||||
|
||||
void sdbFreeRaw(SSdbRaw *pRaw) {
|
||||
if (pRaw != NULL) {
|
||||
mTrace("raw:%p, is freed", pRaw);
|
||||
taosMemoryFree(pRaw);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
||||
|
|
|
@ -59,6 +59,7 @@ int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) {
|
|||
pLoad->numOfProcessedFetch = stat.fetchProcessed;
|
||||
pLoad->numOfProcessedDrop = stat.dropProcessed;
|
||||
pLoad->numOfProcessedHb = stat.hbProcessed;
|
||||
pLoad->numOfProcessedDelete = stat.deleteProcessed;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ typedef struct {
|
|||
// exec
|
||||
int8_t inputStatus;
|
||||
int8_t execStatus;
|
||||
SStreamQ inputQ;
|
||||
SStreamQueue inputQ;
|
||||
SRWLatch lock;
|
||||
} STqPushHandle;
|
||||
|
||||
|
@ -107,7 +107,7 @@ typedef struct {
|
|||
STqExecCol execCol;
|
||||
STqExecTb execTb;
|
||||
STqExecDb execDb;
|
||||
} exec;
|
||||
};
|
||||
} STqExecHandle;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -103,7 +103,7 @@ static int metaSaveJsonVarToIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const
|
|||
tIndexJsonPut(pMeta->pTagIvtIdx, terms, tuid);
|
||||
indexMultiTermDestroy(terms);
|
||||
#endif
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
||||
|
|
|
@ -216,8 +216,8 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
}
|
||||
|
||||
// TODO wrap in destroy func
|
||||
taosArrayDestroy(rsp.blockData);
|
||||
taosArrayDestroy(rsp.blockDataLen);
|
||||
taosArrayDestroyP(rsp.blockData, (FDelete)taosMemoryFree);
|
||||
|
||||
if (rsp.withSchema) {
|
||||
taosArrayDestroyP(rsp.blockSchema, (FDelete)tDeleteSSchemaWrapper);
|
||||
|
@ -266,7 +266,7 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
pHandle->execHandle.pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta);
|
||||
}
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
pHandle->execHandle.exec.execCol.qmsg = req.qmsg;
|
||||
pHandle->execHandle.execCol.qmsg = req.qmsg;
|
||||
req.qmsg = NULL;
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
SReadHandle handle = {
|
||||
|
@ -274,15 +274,14 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
.meta = pTq->pVnode->pMeta,
|
||||
.pMsgCb = &pTq->pVnode->msgCb,
|
||||
};
|
||||
pHandle->execHandle.exec.execCol.task[i] =
|
||||
qCreateStreamExecTaskInfo(pHandle->execHandle.exec.execCol.qmsg, &handle);
|
||||
ASSERT(pHandle->execHandle.exec.execCol.task[i]);
|
||||
pHandle->execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(pHandle->execHandle.execCol.qmsg, &handle);
|
||||
ASSERT(pHandle->execHandle.execCol.task[i]);
|
||||
}
|
||||
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
|
||||
pHandle->execHandle.exec.execDb.pFilterOutTbUid =
|
||||
pHandle->execHandle.execDb.pFilterOutTbUid =
|
||||
taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
pHandle->execHandle.exec.execTb.suid = req.suid;
|
||||
pHandle->execHandle.execTb.suid = req.suid;
|
||||
SArray* tbUidList = taosArrayInit(0, sizeof(int64_t));
|
||||
tsdbGetCtbIdList(pTq->pVnode->pMeta, req.suid, tbUidList);
|
||||
tqDebug("vg %d, tq try get suid: %ld", pTq->pVnode->config.vgId, req.suid);
|
||||
|
@ -296,17 +295,20 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
taosArrayDestroy(tbUidList);
|
||||
}
|
||||
taosHashPut(pTq->handles, req.subKey, strlen(req.subKey), pHandle, sizeof(STqHandle));
|
||||
if (tqMetaSaveHandle(pTq, req.subKey, pHandle) < 0) {
|
||||
// TODO
|
||||
}
|
||||
} else {
|
||||
/*ASSERT(pExec->consumerId == req.oldConsumerId);*/
|
||||
// TODO handle qmsg and exec modification
|
||||
atomic_store_32(&pHandle->epoch, -1);
|
||||
atomic_store_64(&pHandle->consumerId, req.newConsumerId);
|
||||
atomic_add_fetch_32(&pHandle->epoch, 1);
|
||||
}
|
||||
|
||||
if (tqMetaSaveHandle(pTq, req.subKey, pHandle) < 0) {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -323,16 +325,13 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
tDecoderClear(&decoder);
|
||||
|
||||
pTask->status = TASK_STATUS__IDLE;
|
||||
|
||||
pTask->inputQueue = streamQueueOpen();
|
||||
pTask->outputQueue = streamQueueOpen();
|
||||
pTask->inputStatus = TASK_INPUT_STATUS__NORMAL;
|
||||
pTask->outputStatus = TASK_OUTPUT_STATUS__NORMAL;
|
||||
|
||||
pTask->inputQ = taosOpenQueue();
|
||||
pTask->outputQ = taosOpenQueue();
|
||||
pTask->inputQAll = taosAllocateQall();
|
||||
pTask->outputQAll = taosAllocateQall();
|
||||
|
||||
if (pTask->inputQ == NULL || pTask->outputQ == NULL || pTask->inputQAll == NULL || pTask->outputQAll == NULL)
|
||||
goto FAIL;
|
||||
if (pTask->inputQueue == NULL || pTask->outputQueue == NULL) goto FAIL;
|
||||
|
||||
// exec
|
||||
if (pTask->execType != TASK_EXEC__NONE) {
|
||||
|
@ -369,10 +368,8 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
|
||||
return 0;
|
||||
FAIL:
|
||||
if (pTask->inputQ) taosCloseQueue(pTask->inputQ);
|
||||
if (pTask->outputQ) taosCloseQueue(pTask->outputQ);
|
||||
if (pTask->inputQAll) taosFreeQall(pTask->inputQAll);
|
||||
if (pTask->outputQAll) taosFreeQall(pTask->outputQAll);
|
||||
if (pTask->inputQueue) streamQueueClose(pTask->inputQueue);
|
||||
if (pTask->outputQueue) streamQueueClose(pTask->outputQueue);
|
||||
if (pTask) taosMemoryFree(pTask);
|
||||
return -1;
|
||||
}
|
||||
|
@ -393,38 +390,16 @@ int32_t tqProcessStreamTrigger(STQ* pTq, SSubmitReq* pReq) {
|
|||
SStreamTask* pTask = (SStreamTask*)pIter;
|
||||
if (pTask->inputType != STREAM_INPUT__DATA_SUBMIT) continue;
|
||||
|
||||
int8_t inputStatus = atomic_load_8(&pTask->inputStatus);
|
||||
if (inputStatus == TASK_INPUT_STATUS__NORMAL) {
|
||||
if (failed) {
|
||||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
||||
if (!failed) {
|
||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pSubmit) < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SStreamDataSubmit* pSubmitClone = streamSubmitRefClone(pSubmit);
|
||||
if (pSubmitClone == NULL) {
|
||||
atomic_store_8(&pTask->inputStatus, TASK_INPUT_STATUS__FAILED);
|
||||
if (streamTriggerByWrite(pTask, pTq->pVnode->config.vgId, &pTq->pVnode->msgCb) < 0) {
|
||||
continue;
|
||||
}
|
||||
taosWriteQitem(pTask->inputQ, pSubmitClone);
|
||||
|
||||
int8_t execStatus = atomic_load_8(&pTask->status);
|
||||
if (execStatus == TASK_STATUS__IDLE || execStatus == TASK_STATUS__CLOSING) {
|
||||
SStreamTaskRunReq* pRunReq = taosMemoryMalloc(sizeof(SStreamTaskRunReq));
|
||||
if (pRunReq == NULL) continue;
|
||||
// TODO: do we need htonl?
|
||||
pRunReq->head.vgId = pTq->pVnode->config.vgId;
|
||||
pRunReq->streamId = pTask->streamId;
|
||||
pRunReq->taskId = pTask->taskId;
|
||||
SRpcMsg msg = {
|
||||
.msgType = TDMT_VND_TASK_RUN,
|
||||
.pCont = pRunReq,
|
||||
.contLen = sizeof(SStreamTaskRunReq),
|
||||
};
|
||||
tmsgPutToQueue(&pTq->pVnode->msgCb, FETCH_QUEUE, &msg);
|
||||
}
|
||||
|
||||
} else {
|
||||
// blocked or stopped, do nothing
|
||||
streamTaskInputFail(pTask);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -446,10 +421,20 @@ int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) {
|
|||
}
|
||||
|
||||
int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg) {
|
||||
SStreamDispatchReq* pReq = pMsg->pCont;
|
||||
int32_t taskId = pReq->taskId;
|
||||
char* msgStr = pMsg->pCont;
|
||||
char* msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead));
|
||||
int32_t msgLen = pMsg->contLen - sizeof(SMsgHead);
|
||||
SStreamDispatchReq req;
|
||||
SDecoder decoder;
|
||||
tDecoderInit(&decoder, msgBody, msgLen);
|
||||
tDecodeStreamDispatchReq(&decoder, &req);
|
||||
int32_t taskId = req.taskId;
|
||||
SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
|
||||
streamProcessDispatchReq(pTask, &pTq->pVnode->msgCb, pReq, pMsg);
|
||||
SRpcMsg rsp = {
|
||||
.info = pMsg->info,
|
||||
.code = 0,
|
||||
};
|
||||
streamProcessDispatchReq(pTask, &pTq->pVnode->msgCb, &req, &rsp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ static int32_t tqAddTbNameToRsp(const STQ* pTq, const STqExecHandle* pExec, SMqD
|
|||
|
||||
int32_t tqDataExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataBlkRsp* pRsp, int32_t workerId) {
|
||||
if (pExec->subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
qTaskInfo_t task = pExec->exec.execCol.task[workerId];
|
||||
qTaskInfo_t task = pExec->execCol.task[workerId];
|
||||
ASSERT(task);
|
||||
qSetStreamInput(task, pReq, STREAM_DATA_TYPE_SUBMIT_BLOCK, false);
|
||||
while (1) {
|
||||
|
@ -101,7 +101,7 @@ int32_t tqDataExec(STQ* pTq, STqExecHandle* pExec, SSubmitReq* pReq, SMqDataBlkR
|
|||
pRsp->withSchema = 1;
|
||||
STqReadHandle* pReader = pExec->pExecReader[workerId];
|
||||
tqReadHandleSetMsg(pReader, pReq, 0);
|
||||
while (tqNextDataBlockFilterOut(pReader, pExec->exec.execDb.pFilterOutTbUid)) {
|
||||
while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
|
||||
SSDataBlock block = {0};
|
||||
if (tqRetrieveDataBlock(&block.pDataBlock, pReader, &block.info.groupId, &block.info.uid, &block.info.rows,
|
||||
&block.info.numOfCols) < 0) {
|
||||
|
|
|
@ -22,7 +22,7 @@ static int32_t tEncodeSTqHandle(SEncoder* pEncoder, const STqHandle* pHandle) {
|
|||
if (tEncodeI32(pEncoder, pHandle->epoch) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pHandle->execHandle.subType) < 0) return -1;
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
if (tEncodeCStr(pEncoder, pHandle->execHandle.exec.execCol.qmsg) < 0) return -1;
|
||||
if (tEncodeCStr(pEncoder, pHandle->execHandle.execCol.qmsg) < 0) return -1;
|
||||
}
|
||||
tEndEncode(pEncoder);
|
||||
return pEncoder->pos;
|
||||
|
@ -35,7 +35,7 @@ static int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle) {
|
|||
if (tDecodeI32(pDecoder, &pHandle->epoch) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pHandle->execHandle.subType) < 0) return -1;
|
||||
if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
if (tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.exec.execCol.qmsg) < 0) return -1;
|
||||
if (tDecodeCStrAlloc(pDecoder, &pHandle->execHandle.execCol.qmsg) < 0) return -1;
|
||||
}
|
||||
tEndDecode(pDecoder);
|
||||
return 0;
|
||||
|
@ -88,12 +88,11 @@ int32_t tqMetaOpen(STQ* pTq) {
|
|||
.meta = pTq->pVnode->pMeta,
|
||||
.pMsgCb = &pTq->pVnode->msgCb,
|
||||
};
|
||||
handle.execHandle.exec.execCol.task[i] =
|
||||
qCreateStreamExecTaskInfo(handle.execHandle.exec.execCol.qmsg, &reader);
|
||||
ASSERT(handle.execHandle.exec.execCol.task[i]);
|
||||
handle.execHandle.execCol.task[i] = qCreateStreamExecTaskInfo(handle.execHandle.execCol.qmsg, &reader);
|
||||
ASSERT(handle.execHandle.execCol.task[i]);
|
||||
}
|
||||
} else {
|
||||
handle.execHandle.exec.execDb.pFilterOutTbUid =
|
||||
handle.execHandle.execDb.pFilterOutTbUid =
|
||||
taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||
}
|
||||
taosHashPut(pTq->handles, pKey, kLen, &handle, sizeof(STqHandle));
|
||||
|
|
|
@ -29,13 +29,13 @@ static int32_t tqLoopExecFromQueue(STQ* pTq, STqHandle* pHandle, SStreamDataSubm
|
|||
}
|
||||
// update processed
|
||||
atomic_store_64(&pHandle->pushHandle.processedVer, pSubmit->ver);
|
||||
streamQSetSuccess(&pHandle->pushHandle.inputQ);
|
||||
streamQueueProcessSuccess(&pHandle->pushHandle.inputQ);
|
||||
streamDataSubmitRefDec(pSubmit);
|
||||
if (pRsp->blockNum > 0) {
|
||||
*ppSubmit = pSubmit;
|
||||
return 0;
|
||||
} else {
|
||||
pSubmit = streamQNextItem(&pHandle->pushHandle.inputQ);
|
||||
pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ);
|
||||
}
|
||||
}
|
||||
*ppSubmit = pSubmit;
|
||||
|
@ -52,14 +52,14 @@ int32_t tqExecFromInputQ(STQ* pTq, STqHandle* pHandle) {
|
|||
// 2. check processedVer
|
||||
// 2.1. if not missed, get msg from queue
|
||||
// 2.2. if missed, scan wal
|
||||
pSubmit = streamQNextItem(&pHandle->pushHandle.inputQ);
|
||||
pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ);
|
||||
while (pHandle->pushHandle.processedVer <= pSubmit->ver) {
|
||||
// read from wal
|
||||
}
|
||||
while (pHandle->pushHandle.processedVer > pSubmit->ver + 1) {
|
||||
streamQSetSuccess(&pHandle->pushHandle.inputQ);
|
||||
streamQueueProcessSuccess(&pHandle->pushHandle.inputQ);
|
||||
streamDataSubmitRefDec(pSubmit);
|
||||
pSubmit = streamQNextItem(&pHandle->pushHandle.inputQ);
|
||||
pSubmit = streamQueueNextItem(&pHandle->pushHandle.inputQ);
|
||||
if (pSubmit == NULL) break;
|
||||
}
|
||||
// 3. exec, after each success, update processed ver
|
||||
|
|
|
@ -307,7 +307,7 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
|
|||
STqHandle* pExec = (STqHandle*)pIter;
|
||||
if (pExec->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
int32_t code = qUpdateQualifiedTableId(pExec->execHandle.exec.execCol.task[i], tbUidList, isAdd);
|
||||
int32_t code = qUpdateQualifiedTableId(pExec->execHandle.execCol.task[i], tbUidList, isAdd);
|
||||
ASSERT(code == 0);
|
||||
}
|
||||
} else if (pExec->execHandle.subType == TOPIC_SUB_TYPE__DB) {
|
||||
|
@ -315,7 +315,7 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
|
|||
int32_t sz = taosArrayGetSize(tbUidList);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i);
|
||||
taosHashPut(pExec->execHandle.exec.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0);
|
||||
taosHashPut(pExec->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -24,6 +24,7 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq
|
|||
static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRpcMsg *pRsp);
|
||||
|
||||
int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
|
@ -142,6 +143,9 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
|||
case TDMT_VND_SUBMIT:
|
||||
if (vnodeProcessSubmitReq(pVnode, version, pMsg->pCont, pMsg->contLen, pRsp) < 0) goto _err;
|
||||
break;
|
||||
case TDMT_VND_DELETE:
|
||||
if (vnodeProcessWriteMsg(pVnode, version, pMsg, pRsp) < 0) goto _err;
|
||||
break;
|
||||
/* TQ */
|
||||
case TDMT_VND_MQ_VG_CHANGE:
|
||||
if (tqProcessVgChangeReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
||||
|
@ -256,6 +260,22 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRpcMsg *pRsp) {
|
||||
vTrace("message in write queue is processing");
|
||||
char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
|
||||
int32_t msgLen = pMsg->contLen - sizeof(SMsgHead);
|
||||
SDeleteRes res = {0};
|
||||
SReadHandle handle = {.meta = pVnode->pMeta, .config = &pVnode->config, .vnode = pVnode, .pMsgCb = &pVnode->msgCb};
|
||||
|
||||
switch (pMsg->msgType) {
|
||||
case TDMT_VND_DELETE:
|
||||
return qWorkerProcessDeleteMsg(&handle, pVnode->pQuery, pMsg, pRsp, &res);
|
||||
default:
|
||||
vError("unknown msg type:%d in write queue", pMsg->msgType);
|
||||
return TSDB_CODE_VND_APP_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: remove the function
|
||||
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
|
||||
// TODO
|
||||
|
|
|
@ -518,6 +518,7 @@ int32_t ctgStbVersionSearchCompare(const void* key1, const void* key2);
|
|||
int32_t ctgDbVgVersionSearchCompare(const void* key1, const void* key2);
|
||||
void ctgFreeSTableMetaOutput(STableMetaOutput* pOutput);
|
||||
int32_t ctgUpdateMsgCtx(SCtgMsgCtx* pCtx, int32_t reqType, void* out, char* target);
|
||||
char *ctgTaskTypeStr(CTG_TASK_TYPE type);
|
||||
|
||||
|
||||
extern SCatalogMgmt gCtgMgmt;
|
||||
|
|
|
@ -44,7 +44,7 @@ int32_t ctgInitGetTbMetaTask(SCtgJob *pJob, int32_t taskIdx, SName *name) {
|
|||
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:0x%" PRIx64 " task %d type %d initialized, tableName:%s", pJob->queryId, taskIdx, task.type, name->tname);
|
||||
qDebug("QID:0x%" PRIx64 " the %d task type %s initialized, tableName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), name->tname);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ int32_t ctgInitGetDbVgTask(SCtgJob *pJob, int32_t taskIdx, char *dbFName) {
|
|||
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, dbFName:%s", pJob->queryId, taskIdx, task.type, dbFName);
|
||||
qDebug("QID:0x%" PRIx64 " the %d task type %s initialized, dbFName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), dbFName);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ int32_t ctgInitGetDbCfgTask(SCtgJob *pJob, int32_t taskIdx, char *dbFName) {
|
|||
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, dbFName:%s", pJob->queryId, taskIdx, task.type, dbFName);
|
||||
qDebug("QID:0x%" PRIx64 " the %d task type %s initialized, dbFName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), dbFName);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ int32_t ctgInitGetDbInfoTask(SCtgJob *pJob, int32_t taskIdx, char *dbFName) {
|
|||
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, dbFName:%s", pJob->queryId, taskIdx, task.type, dbFName);
|
||||
qDebug("QID:0x%" PRIx64 " the %d task type %s initialized, dbFName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), dbFName);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ int32_t ctgInitGetTbHashTask(SCtgJob *pJob, int32_t taskIdx, SName *name) {
|
|||
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:0x%" PRIx64 " task %d type %d initialized, tableName:%s", pJob->queryId, taskIdx, task.type, name->tname);
|
||||
qDebug("QID:0x%" PRIx64 " the %d task type %s initialized, tableName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), name->tname);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ int32_t ctgInitGetQnodeTask(SCtgJob *pJob, int32_t taskIdx) {
|
|||
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized", pJob->queryId, taskIdx, task.type);
|
||||
qDebug("QID:%" PRIx64 " the %d task type %s initialized", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ int32_t ctgInitGetIndexTask(SCtgJob *pJob, int32_t taskIdx, char *name) {
|
|||
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, indexFName:%s", pJob->queryId, taskIdx, task.type, name);
|
||||
qDebug("QID:%" PRIx64 " the %d task type %s initialized, indexFName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), name);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ int32_t ctgInitGetUdfTask(SCtgJob *pJob, int32_t taskIdx, char *name) {
|
|||
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, udfName:%s", pJob->queryId, taskIdx, task.type, name);
|
||||
qDebug("QID:%" PRIx64 " the %d task type %s initialized, udfName:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), name);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -227,11 +227,96 @@ int32_t ctgInitGetUserTask(SCtgJob *pJob, int32_t taskIdx, SUserAuthInfo *user)
|
|||
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, user:%s", pJob->queryId, taskIdx, task.type, user->user);
|
||||
qDebug("QID:%" PRIx64 " the %d task type %s initialized, user:%s", pJob->queryId, taskIdx, ctgTaskTypeStr(task.type), user->user);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgHandleForceUpdate(SCatalog* pCtg, SCtgJob *pJob, const SCatalogReq* pReq) {
|
||||
int32_t dbNum = pJob->dbCfgNum + pJob->dbVgNum + pJob->dbInfoNum;
|
||||
if (dbNum > 0) {
|
||||
if (dbNum > pJob->dbCfgNum && dbNum > pJob->dbVgNum && dbNum > pJob->dbInfoNum) {
|
||||
SHashObj* pDb = taosHashInit(dbNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
if (NULL == pDb) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pJob->dbVgNum; ++i) {
|
||||
char* dbFName = taosArrayGet(pReq->pDbVgroup, i);
|
||||
taosHashPut(pDb, dbFName, strlen(dbFName), dbFName, TSDB_DB_FNAME_LEN);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pJob->dbCfgNum; ++i) {
|
||||
char* dbFName = taosArrayGet(pReq->pDbCfg, i);
|
||||
taosHashPut(pDb, dbFName, strlen(dbFName), dbFName, TSDB_DB_FNAME_LEN);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pJob->dbInfoNum; ++i) {
|
||||
char* dbFName = taosArrayGet(pReq->pDbInfo, i);
|
||||
taosHashPut(pDb, dbFName, strlen(dbFName), dbFName, TSDB_DB_FNAME_LEN);
|
||||
}
|
||||
|
||||
char* dbFName = taosHashIterate(pDb, NULL);
|
||||
while (dbFName) {
|
||||
ctgDropDbVgroupEnqueue(pCtg, dbFName, true);
|
||||
dbFName = taosHashIterate(pDb, dbFName);
|
||||
}
|
||||
|
||||
taosHashCleanup(pDb);
|
||||
} else {
|
||||
for (int32_t i = 0; i < pJob->dbVgNum; ++i) {
|
||||
char* dbFName = taosArrayGet(pReq->pDbVgroup, i);
|
||||
CTG_ERR_RET(ctgDropDbVgroupEnqueue(pCtg, dbFName, true));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pJob->dbCfgNum; ++i) {
|
||||
char* dbFName = taosArrayGet(pReq->pDbCfg, i);
|
||||
CTG_ERR_RET(ctgDropDbVgroupEnqueue(pCtg, dbFName, true));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pJob->dbInfoNum; ++i) {
|
||||
char* dbFName = taosArrayGet(pReq->pDbInfo, i);
|
||||
CTG_ERR_RET(ctgDropDbVgroupEnqueue(pCtg, dbFName, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tbNum = pJob->tbMetaNum + pJob->tbHashNum;
|
||||
if (tbNum > 0) {
|
||||
if (tbNum > pJob->tbMetaNum && tbNum > pJob->tbHashNum) {
|
||||
SHashObj* pTb = taosHashInit(tbNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||
for (int32_t i = 0; i < pJob->tbMetaNum; ++i) {
|
||||
SName* name = taosArrayGet(pReq->pTableMeta, i);
|
||||
taosHashPut(pTb, name, sizeof(SName), name, sizeof(SName));
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pJob->tbHashNum; ++i) {
|
||||
SName* name = taosArrayGet(pReq->pTableHash, i);
|
||||
taosHashPut(pTb, name, sizeof(SName), name, sizeof(SName));
|
||||
}
|
||||
|
||||
SName* name = taosHashIterate(pTb, NULL);
|
||||
while (name) {
|
||||
catalogRemoveTableMeta(pCtg, name);
|
||||
name = taosHashIterate(pTb, name);
|
||||
}
|
||||
|
||||
taosHashCleanup(pTb);
|
||||
} else {
|
||||
for (int32_t i = 0; i < pJob->tbMetaNum; ++i) {
|
||||
SName* name = taosArrayGet(pReq->pTableMeta, i);
|
||||
catalogRemoveTableMeta(pCtg, name);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pJob->tbHashNum; ++i) {
|
||||
SName* name = taosArrayGet(pReq->pTableHash, i);
|
||||
catalogRemoveTableMeta(pCtg, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq* pReq, catalogCallback fp, void* param, int32_t* taskNum) {
|
||||
int32_t code = 0;
|
||||
|
@ -283,12 +368,13 @@ int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq*
|
|||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (pReq->forceUpdate) {
|
||||
CTG_ERR_JRET(ctgHandleForceUpdate(pCtg, pJob, pReq));
|
||||
}
|
||||
|
||||
int32_t taskIdx = 0;
|
||||
for (int32_t i = 0; i < dbVgNum; ++i) {
|
||||
char* dbFName = taosArrayGet(pReq->pDbVgroup, i);
|
||||
if (pReq->forceUpdate) {
|
||||
ctgDropDbVgroupEnqueue(pCtg, dbFName, true);
|
||||
}
|
||||
CTG_ERR_JRET(ctgInitGetDbVgTask(pJob, taskIdx++, dbFName));
|
||||
}
|
||||
|
||||
|
@ -304,9 +390,6 @@ int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq*
|
|||
|
||||
for (int32_t i = 0; i < tbMetaNum; ++i) {
|
||||
SName* name = taosArrayGet(pReq->pTableMeta, i);
|
||||
if (pReq->forceUpdate) {
|
||||
catalogRemoveTableMeta(pCtg, name);
|
||||
}
|
||||
CTG_ERR_JRET(ctgInitGetTbMetaTask(pJob, taskIdx++, name));
|
||||
}
|
||||
|
||||
|
@ -342,7 +425,7 @@ int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq*
|
|||
|
||||
taosAcquireRef(gCtgMgmt.jobPool, pJob->refId);
|
||||
|
||||
qDebug("QID:%" PRIx64 ", job %" PRIx64 " initialized, task num %d", pJob->queryId, pJob->refId, *taskNum);
|
||||
qDebug("QID:0x%" PRIx64 ", jobId: 0x%" PRIx64 " initialized, task num %d, forceUpdate %d", pJob->queryId, pJob->refId, *taskNum, pReq->forceUpdate);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
|
||||
|
@ -1108,7 +1191,7 @@ int32_t ctgLaunchJob(SCtgJob *pJob) {
|
|||
for (int32_t i = 0; i < taskNum; ++i) {
|
||||
SCtgTask *pTask = taosArrayGet(pJob->pTasks, i);
|
||||
|
||||
qDebug("QID:%" PRIx64 " start to launch task %d", pJob->queryId, pTask->taskId);
|
||||
qDebug("QID:0x%" PRIx64 " start to launch task %d", pJob->queryId, pTask->taskId);
|
||||
CTG_ERR_RET((*gCtgAsyncFps[pTask->type].launchFp)(pTask));
|
||||
}
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ int32_t ctgHandleMsgCallback(void *param, const SDataBuf *pMsg, int32_t rspCode)
|
|||
|
||||
SCtgTask *pTask = taosArrayGet(pJob->pTasks, cbParam->taskId);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d start to handle rsp %s", pJob->queryId, pTask->taskId, TMSG_INFO(cbParam->reqType + 1));
|
||||
qDebug("QID:0x%" PRIx64 " task %d start to handle rsp %s", pJob->queryId, pTask->taskId, TMSG_INFO(cbParam->reqType + 1));
|
||||
|
||||
CTG_ERR_JRET((*gCtgAsyncFps[pTask->type].handleRspFp)(pTask, cbParam->reqType, pMsg, rspCode));
|
||||
|
||||
|
@ -244,7 +244,7 @@ int32_t ctgAsyncSendMsg(CTG_PARAMS, SCtgTask* pTask, int32_t msgType, void *msg,
|
|||
CTG_ERR_JRET(code);
|
||||
}
|
||||
|
||||
ctgDebug("req msg sent, reqId:%" PRIx64 ", msg type:%d, %s", pTask->pJob->queryId, msgType, TMSG_INFO(msgType));
|
||||
ctgDebug("req msg sent, reqId:0x%" PRIx64 ", msg type:%d, %s", pTask->pJob->queryId, msgType, TMSG_INFO(msgType));
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
@ -565,7 +565,7 @@ int32_t ctgGetTbMetaFromVnode(CTG_PARAMS, const SName* pTableName, SVgroupInfo *
|
|||
}
|
||||
CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, tbFName));
|
||||
|
||||
CTG_RET(ctgAsyncSendMsg(CTG_PARAMS_LIST(), pTask, reqType, msg, msgLen));
|
||||
CTG_RET(ctgAsyncSendMsg(pCtg, pTrans, &vgroupInfo->epSet, pTask, reqType, msg, msgLen));
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
|
|
|
@ -19,6 +19,31 @@
|
|||
#include "catalogInt.h"
|
||||
#include "systable.h"
|
||||
|
||||
char *ctgTaskTypeStr(CTG_TASK_TYPE type) {
|
||||
switch (type) {
|
||||
case CTG_TASK_GET_QNODE:
|
||||
return "[get qnode list]";
|
||||
case CTG_TASK_GET_DB_VGROUP:
|
||||
return "[get db vgroup]";
|
||||
case CTG_TASK_GET_DB_CFG:
|
||||
return "[get db cfg]";
|
||||
case CTG_TASK_GET_DB_INFO:
|
||||
return "[get db info]";
|
||||
case CTG_TASK_GET_TB_META:
|
||||
return "[get table meta]";
|
||||
case CTG_TASK_GET_TB_HASH:
|
||||
return "[get table hash]";
|
||||
case CTG_TASK_GET_INDEX:
|
||||
return "[get index]";
|
||||
case CTG_TASK_GET_UDF:
|
||||
return "[get udf]";
|
||||
case CTG_TASK_GET_USER:
|
||||
return "[get user]";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
void ctgFreeSMetaData(SMetaData* pData) {
|
||||
taosArrayDestroy(pData->pTableMeta);
|
||||
pData->pTableMeta = NULL;
|
||||
|
@ -477,6 +502,9 @@ int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName
|
|||
|
||||
*pVgroup = *vgInfo;
|
||||
|
||||
ctgDebug("Got tb %s hash vgroup, vgId %d, epNum %d, current %s port %d", tbFullName, vgInfo->vgId, vgInfo->epSet.numOfEps,
|
||||
vgInfo->epSet.eps[vgInfo->epSet.inUse].fqdn, vgInfo->epSet.eps[vgInfo->epSet.inUse].port);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ typedef struct SDataSinkHandle {
|
|||
} SDataSinkHandle;
|
||||
|
||||
int32_t createDataDispatcher(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle);
|
||||
int32_t createDataDeleter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void *pParam);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -524,6 +524,17 @@ typedef struct SProjectOperatorInfo {
|
|||
int64_t curOutput;
|
||||
} SProjectOperatorInfo;
|
||||
|
||||
typedef struct SIndefOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SAggSupporter aggSup;
|
||||
SArray* pPseudoColInfo;
|
||||
|
||||
SExprInfo* pScalarExpr;
|
||||
int32_t numOfScalarExpr;
|
||||
SqlFunctionCtx* pScalarCtx;
|
||||
int32_t* rowCellInfoOffset;
|
||||
} SIndefOperatorInfo;
|
||||
|
||||
typedef struct SFillOperatorInfo {
|
||||
struct SFillInfo* pFillInfo;
|
||||
SSDataBlock* pRes;
|
||||
|
@ -770,10 +781,13 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan
|
|||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo,
|
||||
int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhysiNode *pNode, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, SSDataBlock* pResBlock, SLimit* pLimit, SLimit* pSlimit, SNode* pCondition, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo *createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SArray* pIndexMap, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createMultiwaySortMergeOperatorInfo(SOperatorInfo** downStreams, int32_t numStreams,
|
||||
SSDataBlock* pResBlock, SArray* pSortInfo, SArray* pColMatchColInfo,
|
||||
SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pSortInfo, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
|
@ -855,6 +869,7 @@ int32_t decodeOperator(SOperatorInfo* ops, char* data, int32_t length);
|
|||
void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status);
|
||||
int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId,
|
||||
EOPTR_EXEC_MODEL model);
|
||||
int32_t createDataSinkParam(SDataSinkNode *pNode, void **pParam, qTaskInfo_t* pTaskInfo);
|
||||
int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SExplainExecInfo** pRes, int32_t* capacity,
|
||||
int32_t* resNum);
|
||||
|
||||
|
|
|
@ -0,0 +1,254 @@
|
|||
/*
|
||||
* 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 "dataSinkInt.h"
|
||||
#include "dataSinkMgt.h"
|
||||
#include "executorimpl.h"
|
||||
#include "planner.h"
|
||||
#include "tcompression.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tglobal.h"
|
||||
#include "tqueue.h"
|
||||
|
||||
extern SDataSinkStat gDataSinkStat;
|
||||
|
||||
typedef struct SDataDeleterBuf {
|
||||
int32_t useSize;
|
||||
int32_t allocSize;
|
||||
char* pData;
|
||||
} SDataDeleterBuf;
|
||||
|
||||
typedef struct SDataCacheEntry {
|
||||
int32_t dataLen;
|
||||
int32_t numOfRows;
|
||||
int32_t numOfCols;
|
||||
int8_t compressed;
|
||||
char data[];
|
||||
} SDataCacheEntry;
|
||||
|
||||
typedef struct SDataDeleterHandle {
|
||||
SDataSinkHandle sink;
|
||||
SDataSinkManager* pManager;
|
||||
SDataBlockDescNode* pSchema;
|
||||
SDataDeleterNode* pDeleter;
|
||||
SDeleterParam* pParam;
|
||||
STaosQueue* pDataBlocks;
|
||||
SDataDeleterBuf nextOutput;
|
||||
int32_t status;
|
||||
bool queryEnd;
|
||||
uint64_t useconds;
|
||||
uint64_t cachedSize;
|
||||
TdThreadMutex mutex;
|
||||
} SDataDeleterHandle;
|
||||
|
||||
static bool needCompress(const SSDataBlock* pData, int32_t numOfCols) {
|
||||
if (tsCompressColData < 0 || 0 == pData->info.rows) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int32_t col = 0; col < numOfCols; ++col) {
|
||||
SColumnInfoData* pColRes = taosArrayGet(pData->pDataBlock, col);
|
||||
int32_t colSize = pColRes->info.bytes * pData->info.rows;
|
||||
if (NEEDTO_COMPRESS_QUERY(colSize)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void toDataCacheEntry(SDataDeleterHandle* pHandle, const SInputData* pInput, SDataDeleterBuf* pBuf) {
|
||||
int32_t numOfCols = LIST_LENGTH(pHandle->pSchema->pSlots);
|
||||
|
||||
SDataCacheEntry* pEntry = (SDataCacheEntry*)pBuf->pData;
|
||||
pEntry->compressed = 0;
|
||||
pEntry->numOfRows = pInput->pData->info.rows;
|
||||
pEntry->numOfCols = pInput->pData->info.numOfCols;
|
||||
pEntry->dataLen = sizeof(SDeleterRes);
|
||||
|
||||
ASSERT(1 == pEntry->numOfRows);
|
||||
ASSERT(1 == pEntry->numOfCols);
|
||||
|
||||
pBuf->useSize = sizeof(SDataCacheEntry);
|
||||
|
||||
SColumnInfoData* pColRes = (SColumnInfoData*)taosArrayGet(pInput->pData->pDataBlock, 0);
|
||||
|
||||
SDeleterRes* pRes = (SDeleterRes*)pEntry->data;
|
||||
pRes->uid = pHandle->pDeleter->tableId;
|
||||
pRes->uidList = pHandle->pParam->pUidList;
|
||||
pRes->skey = pHandle->pDeleter->deleteTimeRange.skey;
|
||||
pRes->ekey = pHandle->pDeleter->deleteTimeRange.ekey;
|
||||
pRes->affectedRows = *(int64_t*)pColRes->pData;
|
||||
|
||||
pBuf->useSize += pEntry->dataLen;
|
||||
|
||||
atomic_add_fetch_64(&pHandle->cachedSize, pEntry->dataLen);
|
||||
atomic_add_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
|
||||
}
|
||||
|
||||
static bool allocBuf(SDataDeleterHandle* pDeleter, const SInputData* pInput, SDataDeleterBuf* pBuf) {
|
||||
uint32_t capacity = pDeleter->pManager->cfg.maxDataBlockNumPerQuery;
|
||||
if (taosQueueItemSize(pDeleter->pDataBlocks) > capacity) {
|
||||
qError("SinkNode queue is full, no capacity, max:%d, current:%d, no capacity", capacity,
|
||||
taosQueueItemSize(pDeleter->pDataBlocks));
|
||||
return false;
|
||||
}
|
||||
|
||||
pBuf->allocSize = sizeof(SDataCacheEntry) + sizeof(SDeleterRes);
|
||||
|
||||
pBuf->pData = taosMemoryMalloc(pBuf->allocSize);
|
||||
if (pBuf->pData == NULL) {
|
||||
qError("SinkNode failed to malloc memory, size:%d, code:%d", pBuf->allocSize, TAOS_SYSTEM_ERROR(errno));
|
||||
}
|
||||
|
||||
return NULL != pBuf->pData;
|
||||
}
|
||||
|
||||
static int32_t updateStatus(SDataDeleterHandle* pDeleter) {
|
||||
taosThreadMutexLock(&pDeleter->mutex);
|
||||
int32_t blockNums = taosQueueItemSize(pDeleter->pDataBlocks);
|
||||
int32_t status =
|
||||
(0 == blockNums ? DS_BUF_EMPTY
|
||||
: (blockNums < pDeleter->pManager->cfg.maxDataBlockNumPerQuery ? DS_BUF_LOW : DS_BUF_FULL));
|
||||
pDeleter->status = status;
|
||||
taosThreadMutexUnlock(&pDeleter->mutex);
|
||||
return status;
|
||||
}
|
||||
|
||||
static int32_t getStatus(SDataDeleterHandle* pDeleter) {
|
||||
taosThreadMutexLock(&pDeleter->mutex);
|
||||
int32_t status = pDeleter->status;
|
||||
taosThreadMutexUnlock(&pDeleter->mutex);
|
||||
return status;
|
||||
}
|
||||
|
||||
static int32_t putDataBlock(SDataSinkHandle* pHandle, const SInputData* pInput, bool* pContinue) {
|
||||
SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle;
|
||||
SDataDeleterBuf* pBuf = taosAllocateQitem(sizeof(SDataDeleterBuf), DEF_QITEM);
|
||||
if (NULL == pBuf || !allocBuf(pDeleter, pInput, pBuf)) {
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
toDataCacheEntry(pDeleter, pInput, pBuf);
|
||||
taosWriteQitem(pDeleter->pDataBlocks, pBuf);
|
||||
*pContinue = (DS_BUF_LOW == updateStatus(pDeleter) ? true : false);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void endPut(struct SDataSinkHandle* pHandle, uint64_t useconds) {
|
||||
SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle;
|
||||
taosThreadMutexLock(&pDeleter->mutex);
|
||||
pDeleter->queryEnd = true;
|
||||
pDeleter->useconds = useconds;
|
||||
taosThreadMutexUnlock(&pDeleter->mutex);
|
||||
}
|
||||
|
||||
static void getDataLength(SDataSinkHandle* pHandle, int32_t* pLen, bool* pQueryEnd) {
|
||||
SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle;
|
||||
if (taosQueueEmpty(pDeleter->pDataBlocks)) {
|
||||
*pQueryEnd = pDeleter->queryEnd;
|
||||
*pLen = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
SDataDeleterBuf* pBuf = NULL;
|
||||
taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf);
|
||||
memcpy(&pDeleter->nextOutput, pBuf, sizeof(SDataDeleterBuf));
|
||||
taosFreeQitem(pBuf);
|
||||
*pLen = ((SDataCacheEntry*)(pDeleter->nextOutput.pData))->dataLen;
|
||||
*pQueryEnd = pDeleter->queryEnd;
|
||||
qDebug("got data len %d, row num %d in sink", *pLen, ((SDataCacheEntry*)(pDeleter->nextOutput.pData))->numOfRows);
|
||||
}
|
||||
|
||||
static int32_t getDataBlock(SDataSinkHandle* pHandle, SOutputData* pOutput) {
|
||||
SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle;
|
||||
if (NULL == pDeleter->nextOutput.pData) {
|
||||
assert(pDeleter->queryEnd);
|
||||
pOutput->useconds = pDeleter->useconds;
|
||||
pOutput->precision = pDeleter->pSchema->precision;
|
||||
pOutput->bufStatus = DS_BUF_EMPTY;
|
||||
pOutput->queryEnd = pDeleter->queryEnd;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SDataCacheEntry* pEntry = (SDataCacheEntry*)(pDeleter->nextOutput.pData);
|
||||
memcpy(pOutput->pData, pEntry->data, pEntry->dataLen);
|
||||
pOutput->numOfRows = pEntry->numOfRows;
|
||||
pOutput->numOfCols = pEntry->numOfCols;
|
||||
pOutput->compressed = pEntry->compressed;
|
||||
|
||||
atomic_sub_fetch_64(&pDeleter->cachedSize, pEntry->dataLen);
|
||||
atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pEntry->dataLen);
|
||||
|
||||
taosMemoryFreeClear(pDeleter->nextOutput.pData); // todo persistent
|
||||
pOutput->bufStatus = updateStatus(pDeleter);
|
||||
taosThreadMutexLock(&pDeleter->mutex);
|
||||
pOutput->queryEnd = pDeleter->queryEnd;
|
||||
pOutput->useconds = pDeleter->useconds;
|
||||
pOutput->precision = pDeleter->pSchema->precision;
|
||||
taosThreadMutexUnlock(&pDeleter->mutex);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t destroyDataSinker(SDataSinkHandle* pHandle) {
|
||||
SDataDeleterHandle* pDeleter = (SDataDeleterHandle*)pHandle;
|
||||
atomic_sub_fetch_64(&gDataSinkStat.cachedSize, pDeleter->cachedSize);
|
||||
taosMemoryFreeClear(pDeleter->nextOutput.pData);
|
||||
while (!taosQueueEmpty(pDeleter->pDataBlocks)) {
|
||||
SDataDeleterBuf* pBuf = NULL;
|
||||
taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf);
|
||||
taosMemoryFreeClear(pBuf->pData);
|
||||
taosFreeQitem(pBuf);
|
||||
}
|
||||
taosCloseQueue(pDeleter->pDataBlocks);
|
||||
taosThreadMutexDestroy(&pDeleter->mutex);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) {
|
||||
SDataDeleterHandle* pDispatcher = (SDataDeleterHandle*)pHandle;
|
||||
|
||||
*size = atomic_load_64(&pDispatcher->cachedSize);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t createDataDeleter(SDataSinkManager* pManager, const SDataSinkNode* pDataSink, DataSinkHandle* pHandle, void *pParam) {
|
||||
SDataDeleterHandle* deleter = taosMemoryCalloc(1, sizeof(SDataDeleterHandle));
|
||||
if (NULL == deleter) {
|
||||
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SDataDeleterNode* pDeleterNode = (SDataDeleterNode *)pDataSink;
|
||||
deleter->sink.fPut = putDataBlock;
|
||||
deleter->sink.fEndPut = endPut;
|
||||
deleter->sink.fGetLen = getDataLength;
|
||||
deleter->sink.fGetData = getDataBlock;
|
||||
deleter->sink.fDestroy = destroyDataSinker;
|
||||
deleter->sink.fGetCacheSize = getCacheSize;
|
||||
deleter->pManager = pManager;
|
||||
deleter->pDeleter = pDeleterNode;
|
||||
deleter->pSchema = pDataSink->pInputDataBlockDesc;
|
||||
deleter->pParam = pParam;
|
||||
deleter->status = DS_BUF_EMPTY;
|
||||
deleter->queryEnd = false;
|
||||
deleter->pDataBlocks = taosOpenQueue();
|
||||
taosThreadMutexInit(&deleter->mutex, NULL);
|
||||
if (NULL == deleter->pDataBlocks) {
|
||||
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
*pHandle = deleter;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
|
@ -83,7 +83,7 @@ static void toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pIn
|
|||
pEntry->numOfCols = pInput->pData->info.numOfCols;
|
||||
pEntry->dataLen = 0;
|
||||
|
||||
pBuf->useSize = sizeof(SRetrieveTableRsp);
|
||||
pBuf->useSize = sizeof(SDataCacheEntry);
|
||||
blockCompressEncode(pInput->pData, pEntry->data, &pEntry->dataLen, numOfCols, pEntry->compressed);
|
||||
|
||||
pBuf->useSize += pEntry->dataLen;
|
||||
|
@ -100,7 +100,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput,
|
|||
return false;
|
||||
}
|
||||
|
||||
pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pInput->pData);
|
||||
pBuf->allocSize = sizeof(SDataCacheEntry) + blockGetEncodeSize(pInput->pData);
|
||||
|
||||
pBuf->pData = taosMemoryMalloc(pBuf->allocSize);
|
||||
if (pBuf->pData == NULL) {
|
||||
|
@ -211,7 +211,7 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) {
|
||||
static int32_t getCacheSize(struct SDataSinkHandle* pHandle, uint64_t* size) {
|
||||
SDataDispatchHandle* pDispatcher = (SDataDispatchHandle*)pHandle;
|
||||
|
||||
*size = atomic_load_64(&pDispatcher->cachedSize);
|
||||
|
|
|
@ -34,9 +34,12 @@ int32_t dsDataSinkGetCacheSize(SDataSinkStat *pStat) {
|
|||
}
|
||||
|
||||
|
||||
int32_t dsCreateDataSinker(const SDataSinkNode *pDataSink, DataSinkHandle* pHandle) {
|
||||
if (QUERY_NODE_PHYSICAL_PLAN_DISPATCH == nodeType(pDataSink)) {
|
||||
int32_t dsCreateDataSinker(const SDataSinkNode *pDataSink, DataSinkHandle* pHandle, void* pParam) {
|
||||
switch (nodeType(pDataSink)) {
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||
return createDataDispatcher(&gDataSinkManager, pDataSink, pHandle);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DELETE:
|
||||
return createDataDeleter(&gDataSinkManager, pDataSink, pHandle, pParam);
|
||||
}
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
|
|
@ -45,8 +45,15 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
|
|||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
if (handle) {
|
||||
code = dsCreateDataSinker(pSubplan->pDataSink, handle);
|
||||
void* pSinkParam = NULL;
|
||||
code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, pTaskInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
code = dsCreateDataSinker(pSubplan->pDataSink, handle, pSinkParam);
|
||||
}
|
||||
|
||||
_error:
|
||||
|
|
|
@ -108,8 +108,6 @@ static SColumnInfo* extractColumnFilterInfo(SExprInfo* pExpr, int32_t numOfOutpu
|
|||
|
||||
static void releaseQueryBuf(size_t numOfTables);
|
||||
|
||||
static int32_t getNumOfScanTimes(STaskAttr* pQueryAttr);
|
||||
|
||||
static void destroySFillOperatorInfo(void* param, int32_t numOfOutput);
|
||||
static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput);
|
||||
static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput);
|
||||
|
@ -2856,7 +2854,7 @@ static SSDataBlock* doLoadRemoteData(SOperatorInfo* pOperator) {
|
|||
return seqLoadRemoteData(pOperator);
|
||||
} else {
|
||||
return concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo);
|
||||
// return concurrentlyLoadRemoteData(pOperator);
|
||||
// return concurrentlyLoadRemoteData(pOperator);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3636,18 +3634,6 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
break;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Return result of the previous group in the firstly.
|
||||
if (false) {
|
||||
if (pRes->info.rows > 0) {
|
||||
pProjectInfo->existDataBlock = pBlock;
|
||||
break;
|
||||
} else { // init output buffer for a new group data
|
||||
initCtxOutputBuffer(pInfo->pCtx, pOperator->numOfExprs);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
int32_t code = getTableScanInfo(pOperator->pDownstream[0], &order, &scanFlag);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -3793,6 +3779,17 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
|||
}
|
||||
}
|
||||
|
||||
static void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs) {
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
SExprInfo* pExprInfo = &pExpr[i];
|
||||
if (pExprInfo->pExpr->nodeType == QUERY_NODE_COLUMN) {
|
||||
taosMemoryFree(pExprInfo->base.pParam[0].pCol);
|
||||
}
|
||||
taosMemoryFree(pExprInfo->base.pParam);
|
||||
taosMemoryFree(pExprInfo->pExpr);
|
||||
}
|
||||
}
|
||||
|
||||
static void destroyOperatorInfo(SOperatorInfo* pOperator) {
|
||||
if (pOperator == NULL) {
|
||||
return;
|
||||
|
@ -3812,14 +3809,7 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
if (pOperator->pExpr != NULL) {
|
||||
for (int32_t i = 0; i < pOperator->numOfExprs; ++i) {
|
||||
SExprInfo* pExprInfo = &pOperator->pExpr[i];
|
||||
if (pExprInfo->pExpr->nodeType == QUERY_NODE_COLUMN) {
|
||||
taosMemoryFree(pExprInfo->base.pParam[0].pCol);
|
||||
}
|
||||
taosMemoryFree(pExprInfo->base.pParam);
|
||||
taosMemoryFree(pExprInfo->pExpr);
|
||||
}
|
||||
destroyExprInfo(pOperator->pExpr, pOperator->numOfExprs);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pOperator->pExpr);
|
||||
|
@ -4008,6 +3998,19 @@ static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
taosArrayDestroy(pInfo->pPseudoColInfo);
|
||||
}
|
||||
|
||||
static void destroyIndefinitOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SIndefOperatorInfo* pInfo = (SIndefOperatorInfo*)param;
|
||||
doDestroyBasicInfo(&pInfo->binfo, numOfOutput);
|
||||
|
||||
taosArrayDestroy(pInfo->pPseudoColInfo);
|
||||
cleanupAggSup(&pInfo->aggSup);
|
||||
|
||||
destroySqlFunctionCtx(pInfo->pScalarCtx, numOfOutput);
|
||||
destroyExprInfo(pInfo->pScalarExpr, pInfo->numOfScalarExpr);
|
||||
|
||||
taosMemoryFree(pInfo->rowCellInfoOffset);
|
||||
}
|
||||
|
||||
void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SExchangeInfo* pExInfo = (SExchangeInfo*)param;
|
||||
taosArrayDestroy(pExInfo->pSources);
|
||||
|
@ -4085,6 +4088,136 @@ _error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) {
|
||||
SIndefOperatorInfo* pIndefInfo = pOperator->info;
|
||||
SOptrBasicInfo* pInfo = &pIndefInfo->binfo;
|
||||
|
||||
SSDataBlock* pRes = pInfo->pRes;
|
||||
blockDataCleanup(pRes);
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int64_t st = 0;
|
||||
int32_t order = 0;
|
||||
int32_t scanFlag = 0;
|
||||
|
||||
if (pOperator->cost.openCost == 0) {
|
||||
st = taosGetTimestampUs();
|
||||
}
|
||||
|
||||
SOperatorInfo* downstream = pOperator->pDownstream[0];
|
||||
|
||||
while (1) {
|
||||
// The downstream exec may change the value of the newgroup, so use a local variable instead.
|
||||
SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream);
|
||||
if (pBlock == NULL) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
break;
|
||||
}
|
||||
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
int32_t code = getTableScanInfo(pOperator->pDownstream[0], &order, &scanFlag);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
// there is an scalar expression that needs to be calculated before apply the group aggregation.
|
||||
if (pIndefInfo->pScalarExpr != NULL) {
|
||||
code = projectApplyFunctions(pIndefInfo->pScalarExpr, pBlock, pBlock, pIndefInfo->pScalarCtx,
|
||||
pIndefInfo->numOfScalarExpr, pIndefInfo->pPseudoColInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, code);
|
||||
}
|
||||
}
|
||||
|
||||
setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order, scanFlag, false);
|
||||
blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows);
|
||||
|
||||
code = projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfExprs,
|
||||
pIndefInfo->pPseudoColInfo);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, code);
|
||||
}
|
||||
}
|
||||
|
||||
size_t rows = pInfo->pRes->info.rows;
|
||||
pOperator->resultInfo.totalRows += rows;
|
||||
|
||||
if (pOperator->cost.openCost == 0) {
|
||||
pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0;
|
||||
}
|
||||
|
||||
return (rows > 0) ? pInfo->pRes : NULL;
|
||||
}
|
||||
|
||||
SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pNode,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
SIndefOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SIndefOperatorInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
if (pInfo == NULL || pOperator == NULL) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
SIndefRowsFuncPhysiNode* pPhyNode = (SIndefRowsFuncPhysiNode*)pNode;
|
||||
|
||||
int32_t numOfExpr = 0;
|
||||
SExprInfo* pExprInfo = createExprInfo(pPhyNode->pVectorFuncs, NULL, &numOfExpr);
|
||||
|
||||
int32_t numOfScalarExpr = 0;
|
||||
if (pPhyNode->pExprs != NULL) {
|
||||
pInfo->pScalarExpr = createExprInfo(pPhyNode->pExprs, NULL, &numOfScalarExpr);
|
||||
pInfo->pScalarCtx = createSqlFunctionCtx(pInfo->pScalarExpr, numOfScalarExpr, &pInfo->rowCellInfoOffset);
|
||||
}
|
||||
|
||||
SSDataBlock* pResBlock = createResDataBlock(pPhyNode->node.pOutputDataBlockDesc);
|
||||
;
|
||||
|
||||
int32_t numOfRows = 4096;
|
||||
size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
|
||||
|
||||
// Make sure the size of SSDataBlock will never exceed the size of 2MB.
|
||||
int32_t TWOMB = 2 * 1024 * 1024;
|
||||
if (numOfRows * pResBlock->info.rowSize > TWOMB) {
|
||||
numOfRows = TWOMB / pResBlock->info.rowSize;
|
||||
}
|
||||
initResultSizeInfo(pOperator, numOfRows);
|
||||
|
||||
initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExprInfo, numOfExpr, pResBlock, keyBufSize, pTaskInfo->id.str);
|
||||
setFunctionResultOutput(&pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, numOfExpr, pTaskInfo);
|
||||
|
||||
pInfo->binfo.pRes = pResBlock;
|
||||
pInfo->numOfScalarExpr = numOfScalarExpr;
|
||||
pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pInfo->binfo.pCtx, numOfExpr);
|
||||
|
||||
pOperator->name = "IndefinitOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PROJECT;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->numOfExprs = numOfExpr;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doApplyIndefinitFunction, NULL, NULL,
|
||||
destroyIndefinitOperatorInfo, NULL, NULL, NULL);
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
taosMemoryFree(pInfo);
|
||||
taosMemoryFree(pOperator);
|
||||
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t numOfCols, SNodeListNode* pValNode,
|
||||
STimeWindow win, int32_t capacity, const char* id, SInterval* pInterval, int32_t fillType) {
|
||||
SFillColInfo* pColInfo = createFillColInfo(pExpr, numOfCols, pValNode);
|
||||
|
@ -4517,6 +4650,18 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
extractColMatchInfo(pSortPhyNode->pTargets, pDescNode, &numOfOutputCols, pTaskInfo, COL_MATCH_FROM_SLOT_ID);
|
||||
|
||||
pOptr = createSortOperatorInfo(ops[0], pResBlock, info, pExprInfo, numOfCols, pColList, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_MERGE == type) {
|
||||
SMergePhysiNode* pMergePhyNode = (SMergePhysiNode*)pPhyNode;
|
||||
|
||||
SDataBlockDescNode* pDescNode = pPhyNode->pOutputDataBlockDesc;
|
||||
SSDataBlock* pResBlock = createResDataBlock(pDescNode);
|
||||
|
||||
SArray* sortInfo = createSortInfo(pMergePhyNode->pMergeKeys);
|
||||
int32_t numOfOutputCols = 0;
|
||||
SArray* pColList =
|
||||
extractColMatchInfo(pMergePhyNode->pTargets, pDescNode, &numOfOutputCols, pTaskInfo, COL_MATCH_FROM_SLOT_ID);
|
||||
|
||||
pOptr = createMultiwaySortMergeOperatorInfo(ops, size, pResBlock, sortInfo, pColList, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW == type) {
|
||||
SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode;
|
||||
|
||||
|
@ -4577,6 +4722,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
SInterval* pInterval = &((SIntervalAggOperatorInfo*)ops[0]->info)->interval;
|
||||
pOptr = createFillOperatorInfo(ops[0], pExprInfo, num, pInterval, &pFillNode->timeRange, pResBlock, pFillNode->mode,
|
||||
(SNodeListNode*)pFillNode->pValues, false, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC == type) {
|
||||
pOptr = createIndefinitOutputOperatorInfo(ops[0], pPhyNode, pTaskInfo);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -4952,6 +5099,37 @@ int32_t decodeOperator(SOperatorInfo* ops, char* result, int32_t length) {
|
|||
return TDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t createDataSinkParam(SDataSinkNode *pNode, void **pParam, qTaskInfo_t* pTaskInfo) {
|
||||
SExecTaskInfo* pTask = *(SExecTaskInfo**)pTaskInfo;
|
||||
|
||||
switch (pNode->type) {
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DELETE: {
|
||||
SDeleterParam *pDeleterParam = taosMemoryCalloc(1, sizeof(SDeleterParam));
|
||||
if (NULL == pDeleterParam) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
int32_t tbNum = taosArrayGetSize(pTask->tableqinfoList.pTableList);
|
||||
pDeleterParam->pUidList = taosArrayInit(tbNum, sizeof(uint64_t));
|
||||
if (NULL == pDeleterParam->pUidList) {
|
||||
taosMemoryFree(pDeleterParam);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
for (int32_t i = 0; i < tbNum; ++i) {
|
||||
STableKeyInfo *pTable = taosArrayGet(pTask->tableqinfoList.pTableList, i);
|
||||
taosArrayPush(pDeleterParam->pUidList, &pTable->uid);
|
||||
}
|
||||
|
||||
*pParam = pDeleterParam;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId,
|
||||
EOPTR_EXEC_MODEL model) {
|
||||
uint64_t queryId = pPlan->id.queryId;
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tdatablock.h"
|
||||
#include "executorimpl.h"
|
||||
#include "tdatablock.h"
|
||||
|
||||
static SSDataBlock* doSort(SOperatorInfo* pOperator);
|
||||
static int32_t doOpenSortOperator(SOperatorInfo* pOperator);
|
||||
|
@ -22,8 +22,9 @@ static int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uin
|
|||
|
||||
static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput);
|
||||
|
||||
SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SArray* pColMatchColInfo, SExecTaskInfo* pTaskInfo) {
|
||||
SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo,
|
||||
SExprInfo* pExprInfo, int32_t numOfCols, SArray* pColMatchColInfo,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
SSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortOperatorInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
int32_t rowSize = pResBlock->info.rowSize;
|
||||
|
@ -40,7 +41,7 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR
|
|||
initResultSizeInfo(pOperator, 1024);
|
||||
|
||||
pInfo->pSortInfo = pSortInfo;
|
||||
pInfo->pColMatchInfo= pColMatchColInfo;
|
||||
pInfo->pColMatchInfo = pColMatchColInfo;
|
||||
pOperator->name = "SortOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT;
|
||||
pOperator->blocking = true;
|
||||
|
@ -48,17 +49,17 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR
|
|||
pOperator->info = pInfo;
|
||||
|
||||
// lazy evaluation for the following parameter since the input datablock is not known till now.
|
||||
// pInfo->bufPageSize = rowSize < 1024 ? 1024 * 2 : rowSize * 2; // there are headers, so pageSize = rowSize + header
|
||||
// pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer
|
||||
// pInfo->bufPageSize = rowSize < 1024 ? 1024 * 2 : rowSize * 2; // there are headers, so pageSize = rowSize +
|
||||
// header pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(doOpenSortOperator, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, getExplainExecInfo);
|
||||
pOperator->fpSet = createOperatorFpSet(doOpenSortOperator, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL,
|
||||
getExplainExecInfo);
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
_error:
|
||||
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(pInfo);
|
||||
taosMemoryFree(pOperator);
|
||||
|
@ -80,7 +81,8 @@ void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle) {
|
|||
pBlock->info.rows += 1;
|
||||
}
|
||||
|
||||
SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, SArray* pColMatchInfo) {
|
||||
SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity,
|
||||
SArray* pColMatchInfo) {
|
||||
blockDataCleanup(pDataBlock);
|
||||
ASSERT(taosArrayGetSize(pColMatchInfo) == pDataBlock->info.numOfCols);
|
||||
|
||||
|
@ -132,7 +134,8 @@ void applyScalarFunction(SSDataBlock* pBlock, void* param) {
|
|||
SOperatorInfo* pOperator = param;
|
||||
SSortOperatorInfo* pSort = pOperator->info;
|
||||
if (pOperator->pExpr != NULL) {
|
||||
int32_t code = projectApplyFunctions(pOperator->pExpr, pBlock, pBlock, pSort->binfo.pCtx, pOperator->numOfExprs, NULL);
|
||||
int32_t code =
|
||||
projectApplyFunctions(pOperator->pExpr, pBlock, pBlock, pSort->binfo.pCtx, pOperator->numOfExprs, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pOperator->pTaskInfo->env, code);
|
||||
}
|
||||
|
@ -150,8 +153,8 @@ int32_t doOpenSortOperator(SOperatorInfo* pOperator) {
|
|||
pInfo->startTs = taosGetTimestampUs();
|
||||
|
||||
// pInfo->binfo.pRes is not equalled to the input datablock.
|
||||
pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->pColMatchInfo, SORT_SINGLESOURCE_SORT,
|
||||
-1, -1, NULL, pTaskInfo->id.str);
|
||||
pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->pColMatchInfo, SORT_SINGLESOURCE_SORT, -1, -1,
|
||||
NULL, pTaskInfo->id.str);
|
||||
|
||||
tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, applyScalarFunction, pOperator);
|
||||
|
||||
|
@ -166,7 +169,7 @@ int32_t doOpenSortOperator(SOperatorInfo* pOperator) {
|
|||
longjmp(pTaskInfo->env, terrno);
|
||||
}
|
||||
|
||||
pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs)/1000.0;
|
||||
pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs) / 1000.0;
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
|
||||
OPTR_SET_OPENED(pOperator);
|
||||
|
@ -186,7 +189,8 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) {
|
|||
longjmp(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
SSDataBlock* pBlock = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo);
|
||||
SSDataBlock* pBlock =
|
||||
getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo);
|
||||
|
||||
if (pBlock != NULL) {
|
||||
pOperator->resultInfo.totalRows += pBlock->info.rows;
|
||||
|
@ -208,10 +212,147 @@ int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t*
|
|||
ASSERT(pOptr != NULL);
|
||||
SSortExecInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortExecInfo));
|
||||
|
||||
SSortOperatorInfo *pOperatorInfo = (SSortOperatorInfo*)pOptr->info;
|
||||
SSortOperatorInfo* pOperatorInfo = (SSortOperatorInfo*)pOptr->info;
|
||||
|
||||
*pInfo = tsortGetSortExecInfo(pOperatorInfo->pSortHandle);
|
||||
*pOptrExplain = pInfo;
|
||||
*len = sizeof(SSortExecInfo);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
typedef struct SMultiwaySortMergeOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
|
||||
int32_t bufPageSize;
|
||||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
|
||||
SArray* pSortInfo;
|
||||
SSortHandle* pSortHandle;
|
||||
SArray* pColMatchInfo; // for index map from table scan output
|
||||
|
||||
int64_t startTs; // sort start time
|
||||
} SMultiwaySortMergeOperatorInfo;
|
||||
|
||||
int32_t doOpenMultiwaySortMergeOperator(SOperatorInfo* pOperator) {
|
||||
SMultiwaySortMergeOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
if (OPTR_IS_OPENED(pOperator)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
pInfo->startTs = taosGetTimestampUs();
|
||||
|
||||
int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize;
|
||||
|
||||
pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->pColMatchInfo, SORT_MULTISOURCE_MERGE,
|
||||
pInfo->bufPageSize, numOfBufPage, NULL, pTaskInfo->id.str);
|
||||
|
||||
tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, NULL, NULL);
|
||||
|
||||
for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
|
||||
SSortSource ps = {0};
|
||||
ps.param = pOperator->pDownstream[i];
|
||||
tsortAddSource(pInfo->pSortHandle, &ps);
|
||||
}
|
||||
|
||||
int32_t code = tsortOpen(pInfo->pSortHandle);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, terrno);
|
||||
}
|
||||
|
||||
pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs) / 1000.0;
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
|
||||
OPTR_SET_OPENED(pOperator);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SSDataBlock* doMultiwaySortMerge(SOperatorInfo* pOperator) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SMultiwaySortMergeOperatorInfo* pInfo = pOperator->info;
|
||||
|
||||
int32_t code = pOperator->fpSet._openFn(pOperator);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
SSDataBlock* pBlock =
|
||||
getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo);
|
||||
|
||||
if (pBlock != NULL) {
|
||||
pOperator->resultInfo.totalRows += pBlock->info.rows;
|
||||
} else {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
}
|
||||
return pBlock;
|
||||
}
|
||||
|
||||
void destroyMultiwaySortMergeOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SMultiwaySortMergeOperatorInfo * pInfo = (SMultiwaySortMergeOperatorInfo*)param;
|
||||
pInfo->binfo.pRes = blockDataDestroy(pInfo->binfo.pRes);
|
||||
|
||||
taosArrayDestroy(pInfo->pSortInfo);
|
||||
taosArrayDestroy(pInfo->pColMatchInfo);
|
||||
}
|
||||
|
||||
int32_t getMultiwaySortMergeExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) {
|
||||
ASSERT(pOptr != NULL);
|
||||
SSortExecInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortExecInfo));
|
||||
|
||||
SMultiwaySortMergeOperatorInfo* pOperatorInfo = (SMultiwaySortMergeOperatorInfo*)pOptr->info;
|
||||
|
||||
*pInfo = tsortGetSortExecInfo(pOperatorInfo->pSortHandle);
|
||||
*pOptrExplain = pInfo;
|
||||
*len = sizeof(SSortExecInfo);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SOperatorInfo* createMultiwaySortMergeOperatorInfo(SOperatorInfo** downStreams, int32_t numStreams,
|
||||
SSDataBlock* pResBlock, SArray* pSortInfo, SArray* pColMatchColInfo,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
SMultiwaySortMergeOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SMultiwaySortMergeOperatorInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
int32_t rowSize = pResBlock->info.rowSize;
|
||||
|
||||
if (pInfo == NULL || pOperator == NULL || rowSize > 100 * 1024 * 1024) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pInfo->binfo.pRes = pResBlock;
|
||||
|
||||
initResultSizeInfo(pOperator, 1024);
|
||||
|
||||
pInfo->pSortInfo = pSortInfo;
|
||||
pInfo->pColMatchInfo = pColMatchColInfo;
|
||||
pOperator->name = "MultiwaySortMerge";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE;
|
||||
pOperator->blocking = true;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
pInfo->bufPageSize = rowSize < 1024 ? 1024 : rowSize * 2;
|
||||
pInfo->sortBufSize = pInfo->bufPageSize * 16;
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(doOpenMultiwaySortMergeOperator, doMultiwaySortMerge, NULL, NULL,
|
||||
destroyMultiwaySortMergeOperatorInfo, NULL, NULL, getMultiwaySortMergeExplainExecInfo);
|
||||
|
||||
int32_t code = appendDownstream(pOperator, downStreams, numStreams);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(pInfo);
|
||||
taosMemoryFree(pOperator);
|
||||
return NULL;
|
||||
}
|
|
@ -177,13 +177,6 @@ static int32_t translatePercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param0
|
||||
SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (nodeType(pParamNode0) != QUERY_NODE_COLUMN) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The first parameter of PERCENTILE function can only be column");
|
||||
}
|
||||
|
||||
// param1
|
||||
SValueNode* pValue = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 1);
|
||||
|
||||
|
@ -218,13 +211,6 @@ static int32_t translateApercentileImpl(SFunctionNode* pFunc, char* pErrBuf, int
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param0
|
||||
SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (nodeType(pParamNode0) != QUERY_NODE_COLUMN) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The first parameter of APERCENTILE function can only be column");
|
||||
}
|
||||
|
||||
// param1
|
||||
SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1);
|
||||
if (nodeType(pParamNode1) != QUERY_NODE_VALUE) {
|
||||
|
@ -296,13 +282,6 @@ static int32_t translateTop(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param0
|
||||
SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (nodeType(pParamNode0) != QUERY_NODE_COLUMN) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The first parameter of TOP/BOTTOM function can only be column");
|
||||
}
|
||||
|
||||
// param1
|
||||
SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1);
|
||||
if (nodeType(pParamNode1) != QUERY_NODE_VALUE) {
|
||||
|
@ -350,13 +329,6 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param0
|
||||
SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The first parameter of ELAPSED function can only be column");
|
||||
}
|
||||
|
||||
uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
if (TSDB_DATA_TYPE_TIMESTAMP != paraType) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
|
@ -422,13 +394,6 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param0
|
||||
SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The first parameter of HISTOGRAM function can only be column");
|
||||
}
|
||||
|
||||
uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
if (!IS_NUMERIC_TYPE(colType)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
|
@ -461,12 +426,6 @@ static int32_t translateHLL(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pPara)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The input parameter of HYPERLOGLOG function can only be column");
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -486,12 +445,6 @@ static int32_t translateStateCount(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param0
|
||||
SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The input parameter of STATECOUNT function can only be column");
|
||||
}
|
||||
uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
if (!IS_NUMERIC_TYPE(colType)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
|
@ -532,12 +485,6 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param0
|
||||
SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The input parameter of STATEDURATION function can only be column");
|
||||
}
|
||||
uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
if (!IS_NUMERIC_TYPE(colType)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
|
@ -585,12 +532,6 @@ static int32_t translateCsum(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pPara)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The input parameter of CSUM function can only be column");
|
||||
}
|
||||
|
||||
uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
uint8_t resType;
|
||||
if (!IS_NUMERIC_TYPE(colType)) {
|
||||
|
@ -616,13 +557,6 @@ static int32_t translateMavg(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param0
|
||||
SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The first parameter of MAVG function can only be column");
|
||||
}
|
||||
|
||||
uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
|
||||
// param1
|
||||
|
@ -652,13 +586,6 @@ static int32_t translateSample(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param0
|
||||
SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pParamNode0)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The first parameter of SAMPLE function can only be column");
|
||||
}
|
||||
|
||||
SExprNode* pCol = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||
uint8_t colType = pCol->resType.type;
|
||||
|
||||
|
@ -696,12 +623,6 @@ static int32_t translateTail(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param0
|
||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pPara)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The first parameter of TAIL function can only be column");
|
||||
}
|
||||
SExprNode* pCol = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||
uint8_t colType = pCol->resType.type;
|
||||
|
||||
|
@ -778,13 +699,6 @@ static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
// param0
|
||||
SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (nodeType(pParamNode0) != QUERY_NODE_COLUMN) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"The first parameter of DIFF function can only be column");
|
||||
}
|
||||
|
||||
uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
if (!IS_SIGNED_NUMERIC_TYPE(colType) && !IS_FLOAT_TYPE(colType) && TSDB_DATA_TYPE_BOOL != colType) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
|
|
|
@ -35,15 +35,15 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// clang-format off
|
||||
#define indexFatal(...) do { if (idxDebugFlag & DEBUG_FATAL) { taosPrintLog("INDEX FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while (0)
|
||||
#define indexError(...) do { if (idxDebugFlag & DEBUG_ERROR) { taosPrintLog("INDEX ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while (0)
|
||||
#define indexWarn(...) do { if (idxDebugFlag & DEBUG_WARN) { taosPrintLog("INDEX WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while (0)
|
||||
#define indexInfo(...) do { if (idxDebugFlag & DEBUG_INFO) { taosPrintLog("INDEX ", DEBUG_INFO, 255, __VA_ARGS__); } } while (0)
|
||||
#define indexDebug(...) do { if (idxDebugFlag & DEBUG_DEBUG) { taosPrintLog("INDEX ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__);} } while (0)
|
||||
#define indexTrace(...) do { if (idxDebugFlag & DEBUG_TRACE) { taosPrintLog("INDEX ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__);} } while (0)
|
||||
#define indexFatal(...) do { if (idxDebugFlag & DEBUG_FATAL) { taosPrintLog("IDX FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while (0)
|
||||
#define indexError(...) do { if (idxDebugFlag & DEBUG_ERROR) { taosPrintLog("IDX ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while (0)
|
||||
#define indexWarn(...) do { if (idxDebugFlag & DEBUG_WARN) { taosPrintLog("IDX WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while (0)
|
||||
#define indexInfo(...) do { if (idxDebugFlag & DEBUG_INFO) { taosPrintLog("IDX ", DEBUG_INFO, 255, __VA_ARGS__); } } while (0)
|
||||
#define indexDebug(...) do { if (idxDebugFlag & DEBUG_DEBUG) { taosPrintLog("IDX ", DEBUG_DEBUG, idxDebugFlag, __VA_ARGS__);} } while (0)
|
||||
#define indexTrace(...) do { if (idxDebugFlag & DEBUG_TRACE) { taosPrintLog("IDX", DEBUG_TRACE, idxDebugFlag, __VA_ARGS__);} } while (0)
|
||||
// clang-format on
|
||||
|
||||
typedef enum { LT, LE, GT, GE } RangeType;
|
||||
typedef enum { LT, LE, GT, GE, CONTAINS } RangeType;
|
||||
typedef enum { kTypeValue, kTypeDeletion } STermValueType;
|
||||
|
||||
typedef struct SIndexStat {
|
||||
|
|
|
@ -90,7 +90,7 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTRslt* tr, STe
|
|||
break;
|
||||
}
|
||||
CacheTerm* c = (CacheTerm*)SL_GET_NODE_DATA(node);
|
||||
if (0 == strcmp(c->colVal, pCt->colVal)) {
|
||||
if (0 == strcmp(c->colVal, pCt->colVal) && strlen(pCt->colVal) == strlen(c->colVal)) {
|
||||
if (c->operaType == ADD_VALUE) {
|
||||
INDEX_MERGE_ADD_DEL(tr->del, tr->add, c->uid)
|
||||
// taosArrayPush(result, &c->uid);
|
||||
|
@ -222,7 +222,7 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t cacheSearchPrefix_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return cacheSearchCompareFunc_JSON(cache, term, tr, s, CONTAINS);
|
||||
}
|
||||
static int32_t cacheSearchSuffix_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -242,6 +242,9 @@ static int32_t cacheSearchGreaterThan_JSON(void* cache, SIndexTerm* term, SIdxTR
|
|||
static int32_t cacheSearchGreaterEqual_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) {
|
||||
return cacheSearchCompareFunc_JSON(cache, term, tr, s, GE);
|
||||
}
|
||||
static int32_t cacheSearchContain_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) {
|
||||
return cacheSearchCompareFunc_JSON(cache, term, tr, s, CONTAINS);
|
||||
}
|
||||
static int32_t cacheSearchRange_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -97,6 +97,11 @@ static TExeCond tCompareGreaterEqual(void* a, void* b, int8_t type) {
|
|||
__compar_fn_t func = indexGetCompar(type);
|
||||
return tCompare(func, QUERY_GREATER_EQUAL, a, b, type);
|
||||
}
|
||||
|
||||
static TExeCond tCompareContains(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = indexGetCompar(type);
|
||||
return tCompare(func, QUERY_TERM, a, b, type);
|
||||
}
|
||||
TExeCond tCompare(__compar_fn_t func, int8_t cmptype, void* a, void* b, int8_t dtype) {
|
||||
if (dtype == TSDB_DATA_TYPE_BINARY || dtype == TSDB_DATA_TYPE_NCHAR || dtype == TSDB_DATA_TYPE_VARBINARY) {
|
||||
return tDoCompare(func, cmptype, a, b);
|
||||
|
@ -185,12 +190,14 @@ TExeCond tDoCompare(__compar_fn_t func, int8_t comparType, void* a, void* b) {
|
|||
case QUERY_TERM: {
|
||||
if (ret == 0) return MATCH;
|
||||
}
|
||||
default:
|
||||
return BREAK;
|
||||
}
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
static TExeCond (*rangeCompare[])(void* a, void* b, int8_t type) = {tCompareLessThan, tCompareLessEqual,
|
||||
tCompareGreaterThan, tCompareGreaterEqual};
|
||||
static TExeCond (*rangeCompare[])(void* a, void* b, int8_t type) = {
|
||||
tCompareLessThan, tCompareLessEqual, tCompareGreaterThan, tCompareGreaterEqual, tCompareContains};
|
||||
|
||||
_cache_range_compare indexGetCompare(RangeType ty) { return rangeCompare[ty]; }
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ typedef struct SIFParam {
|
|||
col_id_t colId;
|
||||
int64_t suid; // add later
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char colName[TSDB_COL_NAME_LEN];
|
||||
char colName[TSDB_COL_NAME_LEN * 2 + 4];
|
||||
|
||||
SIndexMetaArg arg;
|
||||
} SIFParam;
|
||||
|
@ -64,6 +64,8 @@ static int32_t sifGetFuncFromSql(EOperatorType src, EIndexQueryType *dst) {
|
|||
*dst = QUERY_TERM;
|
||||
} else if (src == OP_TYPE_LIKE || src == OP_TYPE_MATCH || src == OP_TYPE_NMATCH) {
|
||||
*dst = QUERY_REGEX;
|
||||
} else if (src == OP_TYPE_JSON_CONTAINS) {
|
||||
*dst = QUERY_PREFIX;
|
||||
} else {
|
||||
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||
}
|
||||
|
@ -171,7 +173,10 @@ static int32_t sifInitJsonParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
|
|||
param->colId = l->colId;
|
||||
param->colValType = l->node.resType.type;
|
||||
memcpy(param->dbName, l->dbName, sizeof(l->dbName));
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-overflow"
|
||||
sprintf(param->colName, "%s_%s", l->colName, r->literal);
|
||||
#pragma GCC diagnostic pop
|
||||
param->colValType = r->typeData;
|
||||
return 0;
|
||||
// memcpy(param->colName, l->colName, sizeof(l->colName));
|
||||
|
@ -183,6 +188,7 @@ static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
|
|||
SIF_ERR_RET(sifGetValueFromNode(node, ¶m->condValue));
|
||||
param->colId = -1;
|
||||
param->colValType = (uint8_t)(vn->node.resType.type);
|
||||
memcpy(param->colName, vn->literal, strlen(vn->literal));
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_COLUMN: {
|
||||
|
@ -234,7 +240,7 @@ static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx
|
|||
indexError("invalid operation node, left: %p, rigth: %p", node->pLeft, node->pRight);
|
||||
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
if (node->opType == OP_TYPE_JSON_GET_VALUE || node->opType == OP_TYPE_JSON_CONTAINS) {
|
||||
if (node->opType == OP_TYPE_JSON_GET_VALUE) {
|
||||
return code;
|
||||
}
|
||||
SIFParam *paramList = taosMemoryCalloc(nParam, sizeof(SIFParam));
|
||||
|
@ -417,8 +423,8 @@ static int32_t sifNotMatchFunc(SIFParam *left, SIFParam *right, SIFParam *output
|
|||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
static int32_t sifJsonContains(SIFParam *left, SIFParam *right, SIFParam *output) {
|
||||
// return 0
|
||||
return 0;
|
||||
int id = OP_TYPE_JSON_CONTAINS;
|
||||
return sifDoIndex(left, right, id, output);
|
||||
}
|
||||
static int32_t sifJsonGetValue(SIFParam *left, SIFParam *rigth, SIFParam *output) {
|
||||
// return 0
|
||||
|
@ -498,9 +504,11 @@ static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) {
|
|||
int32_t code = 0;
|
||||
int32_t nParam = sifGetOperParamNum(node->opType);
|
||||
if (nParam <= 1) {
|
||||
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
output->status = SFLT_NOT_INDEX;
|
||||
return code;
|
||||
// SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
if (node->opType == OP_TYPE_JSON_GET_VALUE || node->opType == OP_TYPE_JSON_CONTAINS) {
|
||||
if (node->opType == OP_TYPE_JSON_GET_VALUE) {
|
||||
return code;
|
||||
}
|
||||
SIFParam *params = NULL;
|
||||
|
@ -614,11 +622,11 @@ EDealRes sifCalcWalker(SNode *node, void *context) {
|
|||
}
|
||||
|
||||
if (QUERY_NODE_OPERATOR == nodeType(node)) {
|
||||
indexInfo("node type for index filter, type: %d", nodeType(node));
|
||||
// indexInfo("node type for index filter, type: %d", nodeType(node));
|
||||
return sifWalkOper(node, ctx);
|
||||
}
|
||||
|
||||
indexError("invalid node type for index filter calculating, type:%d", nodeType(node));
|
||||
// indexError("invalid node type for index filter calculating, type:%d", nodeType(node));
|
||||
ctx->code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
|
|
@ -425,8 +425,7 @@ static int32_t tfSearchTerm_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t tfSearchPrefix_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return tfSearchCompareFunc_JSON(reader, tem, tr, CONTAINS);
|
||||
}
|
||||
static int32_t tfSearchSuffix_JSON(void* reader, SIndexTerm* tem, SIdxTRslt* tr) {
|
||||
// impl later
|
||||
|
@ -466,10 +465,6 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt
|
|||
AutomationCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX);
|
||||
FstStreamBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx);
|
||||
|
||||
// FstSlice h = fstSliceCreate((uint8_t*)p, skip);
|
||||
// fstStreamBuilderSetRange(sb, &h, ctype);
|
||||
// fstSliceDestroy(&h);
|
||||
|
||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
||||
StreamWithStateResult* rt = NULL;
|
||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
||||
|
|
|
@ -569,6 +569,7 @@ int32_t tSerializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) {
|
|||
if (tEncodeI64(&encoder, pInfo->numOfProcessedFetch) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pInfo->numOfProcessedDrop) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pInfo->numOfProcessedHb) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pInfo->numOfProcessedDelete) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pInfo->cacheDataSize) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pInfo->numOfQueryInQueue) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pInfo->numOfFetchInQueue) < 0) return -1;
|
||||
|
@ -591,6 +592,7 @@ int32_t tDeserializeSQnodeLoad(void *buf, int32_t bufLen, SQnodeLoad *pInfo) {
|
|||
if (tDecodeI64(&decoder, &pInfo->numOfProcessedFetch) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pInfo->numOfProcessedDrop) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pInfo->numOfProcessedHb) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pInfo->numOfProcessedDelete) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pInfo->cacheDataSize) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pInfo->numOfQueryInQueue) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pInfo->numOfFetchInQueue) < 0) return -1;
|
||||
|
|
|
@ -318,6 +318,7 @@ static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
|
|||
CLONE_NODE_LIST_FIELD(pScanPseudoCols);
|
||||
COPY_SCALAR_FIELD(tableType);
|
||||
COPY_SCALAR_FIELD(tableId);
|
||||
COPY_SCALAR_FIELD(stableId);
|
||||
CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone);
|
||||
COPY_SCALAR_FIELD(scanType);
|
||||
COPY_OBJECT_FIELD(scanSeq[0], sizeof(uint8_t) * 2);
|
||||
|
@ -370,7 +371,7 @@ static SNode* logicVnodeModifCopy(const SVnodeModifyLogicNode* pSrc, SVnodeModif
|
|||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
COPY_SCALAR_FIELD(modifyType);
|
||||
COPY_SCALAR_FIELD(msgType);
|
||||
CLONE_NODE_FIELD(pModifyRows);
|
||||
CLONE_NODE_FIELD(pAffectedRows);
|
||||
COPY_SCALAR_FIELD(tableId);
|
||||
COPY_SCALAR_FIELD(tableType);
|
||||
COPY_CHAR_ARRAY_FIELD(tableFName);
|
||||
|
@ -387,6 +388,7 @@ static SNode* logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNo
|
|||
static SNode* logicMergeCopy(const SMergeLogicNode* pSrc, SMergeLogicNode* pDst) {
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
CLONE_NODE_LIST_FIELD(pMergeKeys);
|
||||
CLONE_NODE_LIST_FIELD(pInputs);
|
||||
COPY_SCALAR_FIELD(numOfChannels);
|
||||
COPY_SCALAR_FIELD(srcGroupId);
|
||||
return (SNode*)pDst;
|
||||
|
@ -432,6 +434,12 @@ static SNode* logicPartitionCopy(const SPartitionLogicNode* pSrc, SPartitionLogi
|
|||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* logicIndefRowsFuncCopy(const SIndefRowsFuncLogicNode* pSrc, SIndefRowsFuncLogicNode* pDst) {
|
||||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
CLONE_NODE_LIST_FIELD(pVectorFuncs);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
static SNode* logicSubplanCopy(const SLogicSubplan* pSrc, SLogicSubplan* pDst) {
|
||||
COPY_OBJECT_FIELD(id, sizeof(SSubplanId));
|
||||
CLONE_NODE_FIELD(pNode);
|
||||
|
@ -563,6 +571,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) {
|
|||
return logicSortCopy((const SSortLogicNode*)pNode, (SSortLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_PLAN_PARTITION:
|
||||
return logicPartitionCopy((const SPartitionLogicNode*)pNode, (SPartitionLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||
return logicIndefRowsFuncCopy((const SIndefRowsFuncLogicNode*)pNode, (SIndefRowsFuncLogicNode*)pDst);
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return logicSubplanCopy((const SLogicSubplan*)pNode, (SLogicSubplan*)pDst);
|
||||
default:
|
||||
|
|
|
@ -202,6 +202,8 @@ const char* nodesNodeName(ENodeType type) {
|
|||
return "LogicSort";
|
||||
case QUERY_NODE_LOGIC_PLAN_PARTITION:
|
||||
return "LogicPartition";
|
||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||
return "LogicIndefRowsFunc";
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return "LogicSubplan";
|
||||
case QUERY_NODE_LOGIC_PLAN:
|
||||
|
@ -230,6 +232,8 @@ const char* nodesNodeName(ENodeType type) {
|
|||
return "PhysiSort";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
|
||||
return "PhysiHashInterval";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL:
|
||||
return "PhysiMergeInterval";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
|
||||
return "PhysiStreamInterval";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
|
||||
|
@ -248,6 +252,8 @@ const char* nodesNodeName(ENodeType type) {
|
|||
return "PhysiStreamStateWindow";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
|
||||
return "PhysiPartition";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
||||
return "PhysiIndefRowsFunc";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||
return "PhysiDispatch";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
||||
|
@ -611,7 +617,7 @@ static int32_t jsonToLogicProjectNode(const SJson* pJson, void* pObj) {
|
|||
|
||||
static const char* jkVnodeModifyLogicPlanModifyType = "ModifyType";
|
||||
static const char* jkVnodeModifyLogicPlanMsgType = "MsgType";
|
||||
static const char* jkVnodeModifyLogicPlanModifyRows = "ModifyRows";
|
||||
static const char* jkVnodeModifyLogicPlanAffectedRows = "AffectedRows";
|
||||
|
||||
static int32_t logicVnodeModifyNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SVnodeModifyLogicNode* pNode = (const SVnodeModifyLogicNode*)pObj;
|
||||
|
@ -624,7 +630,7 @@ static int32_t logicVnodeModifyNodeToJson(const void* pObj, SJson* pJson) {
|
|||
code = tjsonAddIntegerToObject(pJson, jkVnodeModifyLogicPlanMsgType, pNode->msgType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkVnodeModifyLogicPlanModifyRows, nodeToJson, pNode->pModifyRows);
|
||||
code = tjsonAddObject(pJson, jkVnodeModifyLogicPlanAffectedRows, nodeToJson, pNode->pAffectedRows);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -641,7 +647,7 @@ static int32_t jsonToLogicVnodeModifyNode(const SJson* pJson, void* pObj) {
|
|||
code = tjsonGetIntValue(pJson, jkVnodeModifyLogicPlanMsgType, &pNode->msgType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkVnodeModifyLogicPlanModifyRows, &pNode->pModifyRows);
|
||||
code = jsonToNodeObject(pJson, jkVnodeModifyLogicPlanAffectedRows, &pNode->pAffectedRows);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -911,6 +917,30 @@ static int32_t jsonToLogicPartitionNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkIndefRowsFuncLogicPlanVectorFuncs = "VectorFuncs";
|
||||
|
||||
static int32_t logicIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SIndefRowsFuncLogicNode* pNode = (const SIndefRowsFuncLogicNode*)pObj;
|
||||
|
||||
int32_t code = logicPlanNodeToJson(pObj, pJson);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkIndefRowsFuncLogicPlanVectorFuncs, pNode->pVectorFuncs);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToLogicIndefRowsFuncNode(const SJson* pJson, void* pObj) {
|
||||
SIndefRowsFuncLogicNode* pNode = (SIndefRowsFuncLogicNode*)pObj;
|
||||
|
||||
int32_t code = jsonToLogicPlanNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkIndefRowsFuncLogicPlanVectorFuncs, &pNode->pVectorFuncs);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkSubplanIdQueryId = "QueryId";
|
||||
static const char* jkSubplanIdGroupId = "GroupId";
|
||||
static const char* jkSubplanIdSubplanId = "SubplanId";
|
||||
|
@ -1249,6 +1279,7 @@ static int32_t jsonToName(const SJson* pJson, void* pObj) {
|
|||
static const char* jkScanPhysiPlanScanCols = "ScanCols";
|
||||
static const char* jkScanPhysiPlanScanPseudoCols = "ScanPseudoCols";
|
||||
static const char* jkScanPhysiPlanTableId = "TableId";
|
||||
static const char* jkScanPhysiPlanSTableId = "STableId";
|
||||
static const char* jkScanPhysiPlanTableType = "TableType";
|
||||
static const char* jkScanPhysiPlanTableName = "TableName";
|
||||
|
||||
|
@ -1265,6 +1296,9 @@ static int32_t physiScanNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanTableId, pNode->uid);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanSTableId, pNode->suid);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkScanPhysiPlanTableType, pNode->tableType);
|
||||
}
|
||||
|
@ -1288,6 +1322,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetUBigIntValue(pJson, jkScanPhysiPlanTableId, &pNode->uid);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetUBigIntValue(pJson, jkScanPhysiPlanSTableId, &pNode->suid);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetTinyIntValue(pJson, jkScanPhysiPlanTableType, &pNode->tableType);
|
||||
}
|
||||
|
@ -1644,6 +1681,7 @@ static int32_t jsonToPhysiExchangeNode(const SJson* pJson, void* pObj) {
|
|||
}
|
||||
|
||||
static const char* jkMergePhysiPlanMergeKeys = "MergeKeys";
|
||||
static const char* jkMergePhysiPlanTargets = "Targets";
|
||||
static const char* jkMergePhysiPlanNumOfChannels = "NumOfChannels";
|
||||
static const char* jkMergePhysiPlanSrcGroupId = "SrcGroupId";
|
||||
|
||||
|
@ -1654,6 +1692,9 @@ static int32_t physiMergeNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkMergePhysiPlanMergeKeys, pNode->pMergeKeys);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkMergePhysiPlanTargets, pNode->pTargets);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkMergePhysiPlanNumOfChannels, pNode->numOfChannels);
|
||||
}
|
||||
|
@ -1671,6 +1712,9 @@ static int32_t jsonToPhysiMergeNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkMergePhysiPlanMergeKeys, &pNode->pMergeKeys);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkMergePhysiPlanTargets, &pNode->pTargets);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkMergePhysiPlanNumOfChannels, &pNode->numOfChannels);
|
||||
}
|
||||
|
@ -1979,6 +2023,37 @@ static int32_t jsonToPhysiPartitionNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkIndefRowsFuncPhysiPlanExprs = "Exprs";
|
||||
static const char* jkIndefRowsFuncPhysiPlanVectorFuncs = "VectorFuncs";
|
||||
|
||||
static int32_t physiIndefRowsFuncNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SIndefRowsFuncPhysiNode* pNode = (const SIndefRowsFuncPhysiNode*)pObj;
|
||||
|
||||
int32_t code = physicPlanNodeToJson(pObj, pJson);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanExprs, pNode->pExprs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkIndefRowsFuncPhysiPlanVectorFuncs, pNode->pVectorFuncs);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToPhysiIndefRowsFuncNode(const SJson* pJson, void* pObj) {
|
||||
SIndefRowsFuncPhysiNode* pNode = (SIndefRowsFuncPhysiNode*)pObj;
|
||||
|
||||
int32_t code = jsonToPhysicPlanNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanExprs, &pNode->pExprs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkIndefRowsFuncPhysiPlanVectorFuncs, &pNode->pVectorFuncs);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkDataSinkInputDataBlockDesc = "InputDataBlockDesc";
|
||||
|
||||
static int32_t physicDataSinkNodeToJson(const void* pObj, SJson* pJson) {
|
||||
|
@ -2000,6 +2075,7 @@ static const char* jkDeletePhysiPlanTableType = "TableType";
|
|||
static const char* jkDeletePhysiPlanTableFName = "TableFName";
|
||||
static const char* jkDeletePhysiPlanDeleteTimeRangeStartKey = "DeleteTimeRangeStartKey";
|
||||
static const char* jkDeletePhysiPlanDeleteTimeRangeEndKey = "DeleteTimeRangeEndKey";
|
||||
static const char* jkDeletePhysiPlanAffectedRows = "AffectedRows";
|
||||
|
||||
static int32_t physiDeleteNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SDataDeleterNode* pNode = (const SDataDeleterNode*)pObj;
|
||||
|
@ -2020,6 +2096,9 @@ static int32_t physiDeleteNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkDeletePhysiPlanDeleteTimeRangeEndKey, pNode->deleteTimeRange.ekey);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkDeletePhysiPlanAffectedRows, nodeToJson, pNode->pAffectedRows);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -2043,6 +2122,9 @@ static int32_t jsonToPhysiDeleteNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBigIntValue(pJson, jkDeletePhysiPlanDeleteTimeRangeEndKey, &pNode->deleteTimeRange.ekey);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkDeletePhysiPlanAffectedRows, &pNode->pAffectedRows);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -3777,6 +3859,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
return logicSortNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_LOGIC_PLAN_PARTITION:
|
||||
return logicPartitionNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||
return logicIndefRowsFuncNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return logicSubplanToJson(pObj, pJson);
|
||||
case QUERY_NODE_LOGIC_PLAN:
|
||||
|
@ -3802,6 +3886,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
return physiSortNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
|
||||
|
@ -3816,6 +3901,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
return physiStateWindowNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
|
||||
return physiPartitionNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
||||
return physiIndefRowsFuncNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||
return physiDispatchNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
||||
|
@ -3905,6 +3992,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToLogicSortNode(pJson, pObj);
|
||||
case QUERY_NODE_LOGIC_PLAN_PARTITION:
|
||||
return jsonToLogicPartitionNode(pJson, pObj);
|
||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||
return jsonToLogicIndefRowsFuncNode(pJson, pObj);
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return jsonToLogicSubplan(pJson, pObj);
|
||||
case QUERY_NODE_LOGIC_PLAN:
|
||||
|
@ -3930,6 +4019,7 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
return jsonToPhysiSortNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL:
|
||||
|
@ -3944,6 +4034,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToPhysiStateWindowNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
|
||||
return jsonToPhysiPartitionNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
||||
return jsonToPhysiIndefRowsFuncNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||
return jsonToPhysiDispatchNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DELETE:
|
||||
|
|
|
@ -350,6 +350,7 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa
|
|||
case SQL_CLAUSE_GROUP_BY:
|
||||
nodesWalkExpr(pSelect->pHaving, walker, pContext);
|
||||
case SQL_CLAUSE_HAVING:
|
||||
case SQL_CLAUSE_SELECT:
|
||||
case SQL_CLAUSE_DISTINCT:
|
||||
nodesWalkExprs(pSelect->pOrderByList, walker, pContext);
|
||||
case SQL_CLAUSE_ORDER_BY:
|
||||
|
@ -382,6 +383,7 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit
|
|||
case SQL_CLAUSE_GROUP_BY:
|
||||
nodesRewriteExpr(&(pSelect->pHaving), rewriter, pContext);
|
||||
case SQL_CLAUSE_HAVING:
|
||||
case SQL_CLAUSE_SELECT:
|
||||
case SQL_CLAUSE_DISTINCT:
|
||||
nodesRewriteExprs(pSelect->pOrderByList, rewriter, pContext);
|
||||
case SQL_CLAUSE_ORDER_BY:
|
||||
|
|
|
@ -232,6 +232,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SSortLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_PARTITION:
|
||||
return makeNode(type, sizeof(SPartitionLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||
return makeNode(type, sizeof(SIndefRowsFuncLogicNode));
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return makeNode(type, sizeof(SLogicSubplan));
|
||||
case QUERY_NODE_LOGIC_PLAN:
|
||||
|
@ -260,8 +262,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SSortPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL:
|
||||
return makeNode(type, sizeof(SIntervalPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SORT_MERGE_INTERVAL:
|
||||
return makeNode(type, sizeof(SSortMergeIntervalPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL:
|
||||
return makeNode(type, sizeof(SMergeIntervalPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
|
||||
return makeNode(type, sizeof(SStreamIntervalPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL:
|
||||
|
@ -280,6 +282,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SStreamStateWinodwPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
|
||||
return makeNode(type, sizeof(SPartitionPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC:
|
||||
return makeNode(type, sizeof(SIndefRowsFuncPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||
return makeNode(type, sizeof(SDataDispatcherNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
||||
|
|
|
@ -258,6 +258,17 @@ static int32_t collectMetaKeyFromExplain(SCollectMetaKeyCxt* pCxt, SExplainStmt*
|
|||
return collectMetaKeyFromQuery(pCxt, pStmt->pQuery);
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromDescribe(SCollectMetaKeyCxt* pCxt, SDescribeStmt* pStmt) {
|
||||
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
|
||||
strcpy(name.dbname, pStmt->dbName);
|
||||
strcpy(name.tname, pStmt->tableName);
|
||||
int32_t code = catalogRemoveTableMeta(pCxt->pParseCxt->pCatalog, &name);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t collectMetaKeyFromCreateStream(SCollectMetaKeyCxt* pCxt, SCreateStreamStmt* pStmt) {
|
||||
return collectMetaKeyFromQuery(pCxt, pStmt->pQuery);
|
||||
}
|
||||
|
@ -381,6 +392,8 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
|||
return collectMetaKeyFromCreateTopic(pCxt, (SCreateTopicStmt*)pStmt);
|
||||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
return collectMetaKeyFromExplain(pCxt, (SExplainStmt*)pStmt);
|
||||
case QUERY_NODE_DESCRIBE_STMT:
|
||||
return collectMetaKeyFromDescribe(pCxt, (SDescribeStmt*)pStmt);
|
||||
case QUERY_NODE_CREATE_STREAM_STMT:
|
||||
return collectMetaKeyFromCreateStream(pCxt, (SCreateStreamStmt*)pStmt);
|
||||
case QUERY_NODE_SHOW_DNODES_STMT:
|
||||
|
|
|
@ -1006,7 +1006,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
|
|||
}
|
||||
|
||||
SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i]];
|
||||
char* tmpTokenBuf = taosMemoryCalloc(1, sToken.n); // this can be optimize with parse column
|
||||
char* tmpTokenBuf = taosMemoryCalloc(1, sToken.n); //todo this can be optimize with parse column
|
||||
code = checkAndTrimValue(&sToken, tmpTokenBuf, &pCxt->msg);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(tmpTokenBuf);
|
||||
|
@ -1018,7 +1018,11 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
|
|||
taosMemoryFree(tmpTokenBuf);
|
||||
goto end;
|
||||
}
|
||||
if(isNullStr(&sToken)) {
|
||||
code = tTagNew(pTagVals, 1, true, &pTag);
|
||||
} else {
|
||||
code = parseJsontoTagData(sToken.z, pTagVals, &pTag, &pCxt->msg);
|
||||
}
|
||||
taosMemoryFree(tmpTokenBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
|
|
|
@ -64,6 +64,7 @@ static SKeyword keywordTable[] = {
|
|||
{"CONSUMER", TK_CONSUMER},
|
||||
{"COUNT", TK_COUNT},
|
||||
{"CREATE", TK_CREATE},
|
||||
{"CONTAINS", TK_CONTAINS},
|
||||
{"DATABASE", TK_DATABASE},
|
||||
{"DATABASES", TK_DATABASES},
|
||||
{"DAYS", TK_DAYS},
|
||||
|
|
|
@ -847,8 +847,12 @@ static EDealRes translateJsonOperator(STranslateContext* pCxt, SOperatorNode* pO
|
|||
if (TSDB_DATA_TYPE_JSON != ldt.type || TSDB_DATA_TYPE_BINARY != rdt.type) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName);
|
||||
}
|
||||
if(pOp->opType == OP_TYPE_JSON_GET_VALUE){
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_JSON;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_JSON].bytes;
|
||||
}else if(pOp->opType == OP_TYPE_JSON_CONTAINS){
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_BOOL;
|
||||
}
|
||||
pOp->node.resType.bytes = tDataTypes[pOp->node.resType.type].bytes;
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -2903,7 +2907,6 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt,
|
|||
}
|
||||
}
|
||||
|
||||
taosArrayDestroy(dbCfg.pRetensions);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -5012,6 +5015,10 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
pQuery->haveResultSet = true;
|
||||
pQuery->msgType = TDMT_VND_QUERY;
|
||||
break;
|
||||
case QUERY_NODE_DELETE_STMT:
|
||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||
pQuery->msgType = TDMT_VND_DELETE;
|
||||
break;
|
||||
case QUERY_NODE_VNODE_MODIF_STMT:
|
||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||
pQuery->msgType = toMsgType(((SVnodeModifOpStmt*)pQuery->pRoot)->sqlNodeType);
|
||||
|
|
|
@ -207,6 +207,13 @@ int32_t __catalogGetUdfInfo(SCatalog* pCtg, void* pTrans, const SEpSet* pMgmtEps
|
|||
return g_mockCatalogService->catalogGetUdfInfo(funcName, pInfo);
|
||||
}
|
||||
|
||||
int32_t __catalogRefreshGetTableMeta(SCatalog* pCatalog, void* pTransporter, const SEpSet* pMgmtEps,
|
||||
const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable) {
|
||||
return g_mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta);
|
||||
}
|
||||
|
||||
int32_t __catalogRemoveTableMeta(SCatalog* pCtg, SName* pTableName) { return 0; }
|
||||
|
||||
void initMetaDataEnv() {
|
||||
g_mockCatalogService.reset(new MockCatalogService());
|
||||
|
||||
|
@ -221,6 +228,8 @@ void initMetaDataEnv() {
|
|||
stub.set(catalogGetDBCfg, __catalogGetDBCfg);
|
||||
stub.set(catalogChkAuth, __catalogChkAuth);
|
||||
stub.set(catalogGetUdfInfo, __catalogGetUdfInfo);
|
||||
stub.set(catalogRefreshGetTableMeta, __catalogRefreshGetTableMeta);
|
||||
stub.set(catalogRemoveTableMeta, __catalogRemoveTableMeta);
|
||||
// {
|
||||
// AddrAny any("libcatalog.so");
|
||||
// std::map<std::string,void*> result;
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ParserTest {
|
|||
|
||||
class ParserInitialDTest : public ParserDdlTest {};
|
||||
|
||||
// DELETE FROM tb_name [WHERE condition]
|
||||
// DELETE FROM table_name [WHERE condition]
|
||||
TEST_F(ParserInitialDTest, delete) {
|
||||
useDb("root", "test");
|
||||
|
||||
|
@ -40,7 +40,15 @@ TEST_F(ParserInitialDTest, deleteSemanticCheck) {
|
|||
run("DELETE FROM t1 WHERE c1 > 10", TSDB_CODE_PAR_INVALID_DELETE_WHERE, PARSER_STAGE_TRANSLATE);
|
||||
}
|
||||
|
||||
// todo desc
|
||||
// DESC table_name
|
||||
TEST_F(ParserInitialDTest, describe) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("DESC t1");
|
||||
|
||||
run("DESCRIBE st1");
|
||||
}
|
||||
|
||||
// todo describe
|
||||
// todo DROP account
|
||||
|
||||
|
@ -51,7 +59,7 @@ TEST_F(ParserInitialDTest, dropBnode) {
|
|||
}
|
||||
|
||||
// DROP CONSUMER GROUP [ IF EXISTS ] cgroup_name ON topic_name
|
||||
TEST_F(ParserInitialDTest, dropCGroup) {
|
||||
TEST_F(ParserInitialDTest, dropConsumerGroup) {
|
||||
useDb("root", "test");
|
||||
|
||||
SMDropCgroupReq expect = {0};
|
||||
|
|
|
@ -50,11 +50,13 @@ class ParserDdlTest : public ParserTestBase {
|
|||
|
||||
virtual void checkDdl(const SQuery* pQuery, ParserStage stage) {
|
||||
ASSERT_NE(pQuery, nullptr);
|
||||
ASSERT_EQ(pQuery->haveResultSet, false);
|
||||
ASSERT_NE(pQuery->pRoot, nullptr);
|
||||
if (QUERY_EXEC_MODE_RPC == pQuery->execMode) {
|
||||
ASSERT_EQ(pQuery->haveResultSet, false);
|
||||
ASSERT_EQ(pQuery->numOfResCols, 0);
|
||||
ASSERT_EQ(pQuery->pResSchema, nullptr);
|
||||
ASSERT_EQ(pQuery->precision, 0);
|
||||
}
|
||||
if (nullptr != checkDdl_) {
|
||||
checkDdl_(pQuery, stage);
|
||||
}
|
||||
|
|
|
@ -219,9 +219,9 @@ static int32_t makeScanLogicNode(SLogicPlanContext* pCxt, SRealTableNode* pRealT
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// TSWAP(pScan->pMeta, pRealTable->pMeta);
|
||||
TSWAP(pScan->pVgroupList, pRealTable->pVgroupList);
|
||||
pScan->tableId = pRealTable->pMeta->uid;
|
||||
pScan->stableId = pRealTable->pMeta->suid;
|
||||
pScan->tableType = pRealTable->pMeta->tableType;
|
||||
pScan->scanSeq[0] = hasRepeatScanFuncs ? 2 : 1;
|
||||
pScan->scanSeq[1] = 0;
|
||||
|
@ -456,6 +456,37 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
// top/bottom are both an aggregate function and a indefinite rows function
|
||||
if (!pSelect->hasIndefiniteRowsFunc || pSelect->hasAggFuncs || NULL != pSelect->pWindow) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SIndefRowsFuncLogicNode* pIdfRowsFunc =
|
||||
(SIndefRowsFuncLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC);
|
||||
if (NULL == pIdfRowsFunc) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, fmIsVectorFunc, &pIdfRowsFunc->pVectorFuncs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = rewriteExprForSelect(pIdfRowsFunc->pVectorFuncs, pSelect, SQL_CLAUSE_SELECT);
|
||||
}
|
||||
|
||||
// set the output
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createColumnByRewriteExps(pIdfRowsFunc->pVectorFuncs, &pIdfRowsFunc->node.pTargets);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pIdfRowsFunc;
|
||||
} else {
|
||||
nodesDestroyNode(pIdfRowsFunc);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow,
|
||||
SLogicNode** pLogicNode) {
|
||||
int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_WINDOW, fmIsWindowClauseFunc, &pWindow->pFuncs);
|
||||
|
@ -772,6 +803,9 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createSelectRootLogicNode(pCxt, pSelect, createAggLogicNode, &pRoot);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createSelectRootLogicNode(pCxt, pSelect, createIndefRowsFuncLogicNode, &pRoot);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createSelectRootLogicNode(pCxt, pSelect, createDistinctLogicNode, &pRoot);
|
||||
}
|
||||
|
@ -1057,8 +1091,8 @@ static int32_t createVnodeModifLogicNodeByDelete(SLogicPlanContext* pCxt, SDelet
|
|||
snprintf(pModify->tableFName, sizeof(pModify->tableFName), "%d.%s.%s", pCxt->pPlanCxt->acctId,
|
||||
pRealTable->table.dbName, pRealTable->table.tableName);
|
||||
pModify->deleteTimeRange = pDelete->timeRange;
|
||||
pModify->pModifyRows = nodesCloneNode(pDelete->pCountFunc);
|
||||
if (NULL == pModify->pModifyRows) {
|
||||
pModify->pAffectedRows = nodesCloneNode(pDelete->pCountFunc);
|
||||
if (NULL == pModify->pAffectedRows) {
|
||||
nodesDestroyNode(pModify);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -425,6 +425,7 @@ static int32_t createScanPhysiNodeFinalize(SPhysiPlanContext* pCxt, SSubplan* pS
|
|||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pScanPhysiNode->uid = pScanLogicNode->tableId;
|
||||
pScanPhysiNode->suid = pScanLogicNode->stableId;
|
||||
pScanPhysiNode->tableType = pScanLogicNode->tableType;
|
||||
memcpy(&pScanPhysiNode->tableName, &pScanLogicNode->tableName, sizeof(SName));
|
||||
if (NULL != pScanLogicNode->pTagCond) {
|
||||
|
@ -790,6 +791,43 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createIndefRowsFuncPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||
SIndefRowsFuncLogicNode* pFuncLogicNode, SPhysiNode** pPhyNode) {
|
||||
SIndefRowsFuncPhysiNode* pIdfRowsFunc = (SIndefRowsFuncPhysiNode*)makePhysiNode(
|
||||
pCxt, (SLogicNode*)pFuncLogicNode, QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC);
|
||||
if (NULL == pIdfRowsFunc) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SNodeList* pPrecalcExprs = NULL;
|
||||
SNodeList* pVectorFuncs = NULL;
|
||||
int32_t code = rewritePrecalcExprs(pCxt, pFuncLogicNode->pVectorFuncs, &pPrecalcExprs, &pVectorFuncs);
|
||||
|
||||
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, &pIdfRowsFunc->pExprs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = pushdownDataBlockSlots(pCxt, pIdfRowsFunc->pExprs, pChildTupe);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pVectorFuncs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pVectorFuncs, &pIdfRowsFunc->pVectorFuncs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlots(pCxt, pIdfRowsFunc->pVectorFuncs, pIdfRowsFunc->node.pOutputDataBlockDesc);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pIdfRowsFunc;
|
||||
} else {
|
||||
nodesDestroyNode(pIdfRowsFunc);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||
SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) {
|
||||
SProjectPhysiNode* pProject =
|
||||
|
@ -923,8 +961,8 @@ static ENodeType getIntervalOperatorType(EIntervalAlgorithm intervalAlgo) {
|
|||
switch (intervalAlgo) {
|
||||
case INTERVAL_ALGO_HASH:
|
||||
return QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL;
|
||||
case INTERVAL_ALGO_SORT_MERGE:
|
||||
return QUERY_NODE_PHYSICAL_PLAN_SORT_MERGE_INTERVAL;
|
||||
case INTERVAL_ALGO_MERGE:
|
||||
return QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL;
|
||||
case INTERVAL_ALGO_STREAM_FINAL:
|
||||
return QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL;
|
||||
case INTERVAL_ALGO_STREAM_SEMI:
|
||||
|
@ -1155,6 +1193,8 @@ static int32_t createExchangePhysiNodeByMerge(SMergePhysiNode* pMerge) {
|
|||
nodesDestroyNode(pExchange);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
SNode* pSlot = NULL;
|
||||
FOREACH(pSlot, pExchange->node.pOutputDataBlockDesc->pSlots) { ((SSlotDescNode*)pSlot)->output = true; }
|
||||
return nodesListMakeStrictAppend(&pMerge->node.pChildren, pExchange);
|
||||
}
|
||||
|
||||
|
@ -1168,20 +1208,30 @@ static int32_t createMergePhysiNode(SPhysiPlanContext* pCxt, SMergeLogicNode* pM
|
|||
pMerge->numOfChannels = pMergeLogicNode->numOfChannels;
|
||||
pMerge->srcGroupId = pMergeLogicNode->srcGroupId;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t code = addDataBlockSlots(pCxt, pMergeLogicNode->pInputs, pMerge->node.pOutputDataBlockDesc);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
for (int32_t i = 0; i < pMerge->numOfChannels; ++i) {
|
||||
code = createExchangePhysiNodeByMerge(pMerge);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setListSlotId(pCxt, pMerge->node.pOutputDataBlockDesc->dataBlockId, -1, pMergeLogicNode->pMergeKeys,
|
||||
&pMerge->pMergeKeys);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setListSlotId(pCxt, pMerge->node.pOutputDataBlockDesc->dataBlockId, -1, pMergeLogicNode->node.pTargets,
|
||||
&pMerge->pTargets);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlots(pCxt, pMerge->pTargets, pMerge->node.pOutputDataBlockDesc);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pMerge;
|
||||
} else {
|
||||
|
@ -1212,6 +1262,8 @@ static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode
|
|||
return createPartitionPhysiNode(pCxt, pChildren, (SPartitionLogicNode*)pLogicNode, pPhyNode);
|
||||
case QUERY_NODE_LOGIC_PLAN_FILL:
|
||||
return createFillPhysiNode(pCxt, pChildren, (SFillLogicNode*)pLogicNode, pPhyNode);
|
||||
case QUERY_NODE_LOGIC_PLAN_INDEF_ROWS_FUNC:
|
||||
return createIndefRowsFuncPhysiNode(pCxt, pChildren, (SIndefRowsFuncLogicNode*)pLogicNode, pPhyNode);
|
||||
case QUERY_NODE_LOGIC_PLAN_MERGE:
|
||||
return createMergePhysiNode(pCxt, (SMergeLogicNode*)pLogicNode, pPhyNode);
|
||||
default:
|
||||
|
@ -1319,13 +1371,21 @@ static int32_t createDataDeleter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode*
|
|||
strcpy(pDeleter->tableFName, pModify->tableFName);
|
||||
pDeleter->deleteTimeRange = pModify->deleteTimeRange;
|
||||
|
||||
int32_t code = setNodeSlotId(pCxt, pRoot->pOutputDataBlockDesc->dataBlockId, -1, pModify->pAffectedRows,
|
||||
&pDeleter->pAffectedRows);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pDeleter->sink.pInputDataBlockDesc = nodesCloneNode(pRoot->pOutputDataBlockDesc);
|
||||
if (NULL == pDeleter->sink.pInputDataBlockDesc) {
|
||||
nodesDestroyNode(pDeleter);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pSink = (SDataSinkNode*)pDeleter;
|
||||
} else {
|
||||
nodesDestroyNode(pDeleter);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1335,6 +1395,7 @@ static int32_t buildDeleteSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createDataDeleter(pCxt, pModify, pSubplan->pNode, &pSubplan->pDataSink);
|
||||
}
|
||||
pSubplan->msgType = TDMT_VND_DELETE;
|
||||
return code;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,30 +80,36 @@ static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicNode* pChild, SE
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t splCreateExchangeNodeForSubplan(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pSplitNode,
|
||||
ESubplanType subplanType) {
|
||||
SExchangeLogicNode* pExchange = NULL;
|
||||
if (TSDB_CODE_SUCCESS != splCreateExchangeNode(pCxt, pSplitNode, &pExchange)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pSubplan->subplanType = subplanType;
|
||||
|
||||
if (NULL == pSplitNode->pParent) {
|
||||
pSubplan->pNode = (SLogicNode*)pExchange;
|
||||
static int32_t splReplaceLogicNode(SLogicSubplan* pSubplan, SLogicNode* pOld, SLogicNode* pNew) {
|
||||
if (NULL == pOld->pParent) {
|
||||
pSubplan->pNode = (SLogicNode*)pNew;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pSplitNode->pParent->pChildren) {
|
||||
if (nodesEqualNode(pNode, pSplitNode)) {
|
||||
REPLACE_NODE(pExchange);
|
||||
pExchange->node.pParent = pSplitNode->pParent;
|
||||
FOREACH(pNode, pOld->pParent->pChildren) {
|
||||
if (nodesEqualNode(pNode, pOld)) {
|
||||
REPLACE_NODE(pNew);
|
||||
pNew->pParent = pOld->pParent;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_PLAN_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
static int32_t splCreateExchangeNodeForSubplan(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pSplitNode,
|
||||
ESubplanType subplanType) {
|
||||
SExchangeLogicNode* pExchange = NULL;
|
||||
int32_t code = splCreateExchangeNode(pCxt, pSplitNode, &pExchange);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = splReplaceLogicNode(pSubplan, pSplitNode, (SLogicNode*)pExchange);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pSubplan->subplanType = subplanType;
|
||||
} else {
|
||||
nodesDestroyNode(pExchange);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool splMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, int32_t flag, FSplFindSplitNode func, void* pInfo) {
|
||||
|
@ -295,24 +301,34 @@ static int32_t stbSplCreatePartWindowNode(SWindowLogicNode* pMergeWindow, SLogic
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicNode* pParent, SNodeList* pMergeKeys,
|
||||
SLogicNode* pPartChild) {
|
||||
static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pSplitNode,
|
||||
SNodeList* pMergeKeys, SLogicNode* pPartChild) {
|
||||
SMergeLogicNode* pMerge = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_MERGE);
|
||||
if (NULL == pMerge) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pMerge->numOfChannels = ((SScanLogicNode*)nodesListGetNode(pPartChild->pChildren, 0))->pVgroupList->numOfVgroups;
|
||||
pMerge->srcGroupId = pCxt->groupId;
|
||||
pMerge->node.pParent = pParent;
|
||||
pMerge->node.precision = pPartChild->precision;
|
||||
pMerge->pMergeKeys = pMergeKeys;
|
||||
pMerge->node.pTargets = nodesCloneList(pPartChild->pTargets);
|
||||
if (NULL == pMerge->node.pTargets) {
|
||||
nodesDestroyNode(pMerge);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return nodesListMakeAppend(&pParent->pChildren, pMerge);
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
pMerge->pInputs = nodesCloneList(pPartChild->pTargets);
|
||||
pMerge->node.pTargets = nodesCloneList(pSplitNode->pTargets);
|
||||
if (NULL == pMerge->node.pTargets || NULL == pMerge->pInputs) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (NULL == pSubplan) {
|
||||
code = nodesListMakeAppend(&pSplitNode->pChildren, pMerge);
|
||||
} else {
|
||||
code = splReplaceLogicNode(pSubplan, pSplitNode, (SLogicNode*)pMerge);
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode(pMerge);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t stbSplCreateExchangeNode(SSplitContext* pCxt, SLogicNode* pParent, SLogicNode* pPartChild) {
|
||||
|
@ -329,8 +345,15 @@ static int32_t stbSplSplitWindowNodeForBatch(SSplitContext* pCxt, SStableSplitIn
|
|||
int32_t code = stbSplCreatePartWindowNode((SWindowLogicNode*)pInfo->pSplitNode, &pPartWindow);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
((SWindowLogicNode*)pPartWindow)->intervalAlgo = INTERVAL_ALGO_HASH;
|
||||
((SWindowLogicNode*)pInfo->pSplitNode)->intervalAlgo = INTERVAL_ALGO_SORT_MERGE;
|
||||
code = stbSplCreateExchangeNode(pCxt, pInfo->pSplitNode, pPartWindow);
|
||||
((SWindowLogicNode*)pInfo->pSplitNode)->intervalAlgo = INTERVAL_ALGO_MERGE;
|
||||
SNodeList* pMergeKeys = NULL;
|
||||
code = nodesListMakeStrictAppend(&pMergeKeys, nodesCloneNode(((SWindowLogicNode*)pInfo->pSplitNode)->pTspk));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = stbSplCreateMergeNode(pCxt, NULL, pInfo->pSplitNode, pMergeKeys, pPartWindow);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyList(pMergeKeys);
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren,
|
||||
|
@ -424,37 +447,99 @@ static int32_t stbSplSplitAggNode(SSplitContext* pCxt, SStableSplitInfo* pInfo)
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t stbSplCreatePartSortNode(SSortLogicNode* pMergeSort, SLogicNode** pOutput) {
|
||||
SNodeList* pSortKeys = pMergeSort->pSortKeys;
|
||||
pMergeSort->pSortKeys = NULL;
|
||||
SNodeList* pTargets = pMergeSort->node.pTargets;
|
||||
pMergeSort->node.pTargets = NULL;
|
||||
SNodeList* pChildren = pMergeSort->node.pChildren;
|
||||
pMergeSort->node.pChildren = NULL;
|
||||
static SNode* stbSplCreateColumnNode(SExprNode* pExpr) {
|
||||
SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
if (NULL == pCol) {
|
||||
return NULL;
|
||||
}
|
||||
if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
|
||||
strcpy(pCol->tableAlias, ((SColumnNode*)pExpr)->tableAlias);
|
||||
}
|
||||
strcpy(pCol->colName, pExpr->aliasName);
|
||||
strcpy(pCol->node.aliasName, pExpr->aliasName);
|
||||
pCol->node.resType = pExpr->resType;
|
||||
return (SNode*)pCol;
|
||||
}
|
||||
|
||||
static SNode* stbSplCreateOrderByExpr(SOrderByExprNode* pSortKey, SNode* pCol) {
|
||||
SOrderByExprNode* pOutput = nodesMakeNode(QUERY_NODE_ORDER_BY_EXPR);
|
||||
if (NULL == pOutput) {
|
||||
return NULL;
|
||||
}
|
||||
pOutput->pExpr = nodesCloneNode(pCol);
|
||||
if (NULL == pOutput->pExpr) {
|
||||
nodesDestroyNode(pOutput);
|
||||
return NULL;
|
||||
}
|
||||
pOutput->order = pSortKey->order;
|
||||
pOutput->nullOrder = pSortKey->nullOrder;
|
||||
return (SNode*)pOutput;
|
||||
}
|
||||
|
||||
static int32_t stbSplCreateMergeKeys(SNodeList* pSortKeys, SNodeList* pTargets, SNodeList** pOutput) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SNodeList* pMergeKeys = NULL;
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pSortKeys) {
|
||||
SOrderByExprNode* pSortKey = (SOrderByExprNode*)pNode;
|
||||
SNode* pTarget = NULL;
|
||||
bool found = false;
|
||||
FOREACH(pTarget, pTargets) {
|
||||
if (0 == strcmp(((SExprNode*)pSortKey->pExpr)->aliasName, ((SColumnNode*)pTarget)->colName)) {
|
||||
code = nodesListMakeStrictAppend(&pMergeKeys, stbSplCreateOrderByExpr(pSortKey, pTarget));
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && !found) {
|
||||
SNode* pCol = stbSplCreateColumnNode((SExprNode*)pSortKey->pExpr);
|
||||
code = nodesListMakeStrictAppend(&pMergeKeys, stbSplCreateOrderByExpr(pSortKey, pCol));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListStrictAppend(pTargets, pCol);
|
||||
} else {
|
||||
nodesDestroyNode(pCol);
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = pMergeKeys;
|
||||
} else {
|
||||
nodesDestroyList(pMergeKeys);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t stbSplCreatePartSortNode(SSortLogicNode* pSort, SLogicNode** pOutputPartSort,
|
||||
SNodeList** pOutputMergeKeys) {
|
||||
SNodeList* pSortKeys = pSort->pSortKeys;
|
||||
pSort->pSortKeys = NULL;
|
||||
SNodeList* pChildren = pSort->node.pChildren;
|
||||
pSort->node.pChildren = NULL;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SSortLogicNode* pPartSort = nodesCloneNode(pMergeSort);
|
||||
SSortLogicNode* pPartSort = nodesCloneNode(pSort);
|
||||
if (NULL == pPartSort) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pMergeSort->node.pTargets = pTargets;
|
||||
SNodeList* pMergeKeys = NULL;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pPartSort->node.pChildren = pChildren;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pPartSort->pSortKeys = pSortKeys;
|
||||
code = createColumnByRewriteExps(pPartSort->pSortKeys, &pPartSort->node.pTargets);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pMergeSort->pSortKeys = nodesCloneList(pPartSort->node.pTargets);
|
||||
if (NULL == pMergeSort->pSortKeys) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
code = stbSplCreateMergeKeys(pPartSort->pSortKeys, pPartSort->node.pTargets, &pMergeKeys);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = (SLogicNode*)pPartSort;
|
||||
*pOutputPartSort = (SLogicNode*)pPartSort;
|
||||
*pOutputMergeKeys = pMergeKeys;
|
||||
} else {
|
||||
nodesDestroyNode(pPartSort);
|
||||
nodesDestroyList(pMergeKeys);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -462,17 +547,10 @@ static int32_t stbSplCreatePartSortNode(SSortLogicNode* pMergeSort, SLogicNode**
|
|||
|
||||
static int32_t stbSplSplitSortNode(SSplitContext* pCxt, SStableSplitInfo* pInfo) {
|
||||
SLogicNode* pPartSort = NULL;
|
||||
int32_t code = stbSplCreatePartSortNode((SSortLogicNode*)pInfo->pSplitNode, &pPartSort);
|
||||
SNodeList* pMergeKeys = NULL;
|
||||
int32_t code = stbSplCreatePartSortNode((SSortLogicNode*)pInfo->pSplitNode, &pPartSort, &pMergeKeys);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SNodeList* pMergeKeys = nodesCloneList(((SSortLogicNode*)pInfo->pSplitNode)->pSortKeys);
|
||||
if (NULL != pMergeKeys) {
|
||||
code = stbSplCreateMergeNode(pCxt, pInfo->pSplitNode, pMergeKeys, pPartSort);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyList(pMergeKeys);
|
||||
}
|
||||
} else {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
code = stbSplCreateMergeNode(pCxt, pInfo->pSubplan, pInfo->pSplitNode, pMergeKeys, pPartSort);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListMakeStrictAppend(&pInfo->pSubplan->pChildren,
|
||||
|
|
|
@ -88,7 +88,7 @@ int32_t qSetSubplanExecutionNode(SSubplan* subplan, int32_t groupId, SDownstream
|
|||
}
|
||||
|
||||
int32_t qSubPlanToString(const SSubplan* pSubplan, char** pStr, int32_t* pLen) {
|
||||
if (SUBPLAN_TYPE_MODIFY == pSubplan->subplanType) {
|
||||
if (SUBPLAN_TYPE_MODIFY == pSubplan->subplanType && NULL == pSubplan->pNode) {
|
||||
SDataInserterNode* insert = (SDataInserterNode*)pSubplan->pDataSink;
|
||||
*pLen = insert->size;
|
||||
*pStr = insert->pData;
|
||||
|
|
|
@ -50,6 +50,8 @@ TEST_F(PlanIntervalTest, selectFunc) {
|
|||
run("SELECT MAX(c1), MIN(c1) FROM t1 INTERVAL(10s)");
|
||||
// select function along with the columns of select row, and with INTERVAL clause
|
||||
run("SELECT MAX(c1), c2 FROM t1 INTERVAL(10s)");
|
||||
|
||||
run("SELECT TOP(c1, 1) FROM t1 INTERVAL(10s) ORDER BY c1");
|
||||
}
|
||||
|
||||
TEST_F(PlanIntervalTest, stable) {
|
||||
|
|
|
@ -46,4 +46,7 @@ TEST_F(PlanOrderByTest, stable) {
|
|||
|
||||
// ORDER BY key is in the projection list
|
||||
run("SELECT c1 FROM st1 ORDER BY c1");
|
||||
|
||||
// ORDER BY key is not in the projection list
|
||||
run("SELECT c2 FROM st1 ORDER BY c1");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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 "planTestUtil.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class PlanProjectTest : public PlannerTestBase {};
|
||||
|
||||
TEST_F(PlanProjectTest, basic) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT CEIL(c1) FROM t1");
|
||||
}
|
||||
|
||||
TEST_F(PlanProjectTest, indefiniteRowsFunc) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT MAVG(c1, 10) FROM t1");
|
||||
|
||||
run("SELECT MAVG(CEIL(c1), 20) + 2 FROM t1");
|
||||
}
|
|
@ -81,6 +81,8 @@ int32_t getLogLevel() { return g_logLevel; }
|
|||
|
||||
class PlannerTestBaseImpl {
|
||||
public:
|
||||
PlannerTestBaseImpl() : sqlNo_(0) {}
|
||||
|
||||
void useDb(const string& acctId, const string& db) {
|
||||
caseEnv_.acctId_ = acctId;
|
||||
caseEnv_.db_ = db;
|
||||
|
@ -88,6 +90,7 @@ class PlannerTestBaseImpl {
|
|||
}
|
||||
|
||||
void run(const string& sql) {
|
||||
++sqlNo_;
|
||||
if (caseEnv_.nsql_ > 0) {
|
||||
--(caseEnv_.nsql_);
|
||||
return;
|
||||
|
@ -187,6 +190,8 @@ class PlannerTestBaseImpl {
|
|||
string acctId_;
|
||||
string db_;
|
||||
int32_t nsql_;
|
||||
|
||||
caseEnv() : nsql_(0) {}
|
||||
};
|
||||
|
||||
struct stmtEnv {
|
||||
|
@ -194,6 +199,7 @@ class PlannerTestBaseImpl {
|
|||
array<char, 1024> msgBuf_;
|
||||
SQuery* pQuery_;
|
||||
|
||||
stmtEnv() : pQuery_(nullptr) {}
|
||||
~stmtEnv() { qDestroyQuery(pQuery_); }
|
||||
};
|
||||
|
||||
|
@ -229,7 +235,7 @@ class PlannerTestBaseImpl {
|
|||
return;
|
||||
}
|
||||
|
||||
cout << "==========================================sql : [" << stmtEnv_.sql_ << "]" << endl;
|
||||
cout << "========================================== " << sqlNo_ << " sql : [" << stmtEnv_.sql_ << "]" << endl;
|
||||
|
||||
if (DUMP_MODULE_ALL == module || DUMP_MODULE_PARSER == module) {
|
||||
if (res_.prepareAst_.empty()) {
|
||||
|
@ -382,6 +388,7 @@ class PlannerTestBaseImpl {
|
|||
caseEnv caseEnv_;
|
||||
stmtEnv stmtEnv_;
|
||||
stmtRes res_;
|
||||
int32_t sqlNo_;
|
||||
};
|
||||
|
||||
PlannerTestBase::PlannerTestBase() : impl_(new PlannerTestBaseImpl()) {}
|
||||
|
|
|
@ -37,6 +37,8 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) {
|
|||
pOut->dbVgroup->vgVersion = usedbRsp->vgVersion;
|
||||
pOut->dbVgroup->hashMethod = usedbRsp->hashMethod;
|
||||
|
||||
qDebug("Got %d vgroup for db %s", usedbRsp->vgNum, usedbRsp->db);
|
||||
|
||||
if (usedbRsp->vgNum <= 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -50,6 +52,8 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) {
|
|||
for (int32_t i = 0; i < usedbRsp->vgNum; ++i) {
|
||||
SVgroupInfo *pVgInfo = taosArrayGet(usedbRsp->pVgroupInfos, i);
|
||||
pOut->dbVgroup->numOfTable += pVgInfo->numOfTable;
|
||||
qDebug("the %dth vgroup, id %d, epNum %d, current %s port %d", i, pVgInfo->vgId, pVgInfo->epSet.numOfEps,
|
||||
pVgInfo->epSet.eps[pVgInfo->epSet.inUse].fqdn, pVgInfo->epSet.eps[pVgInfo->epSet.inUse].port);
|
||||
if (0 != taosHashPut(pOut->dbVgroup->vgHash, &pVgInfo->vgId, sizeof(int32_t), pVgInfo, sizeof(SVgroupInfo))) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -160,6 +160,7 @@ typedef struct SQWMsgStat {
|
|||
uint64_t cancelProcessed;
|
||||
uint64_t dropProcessed;
|
||||
uint64_t hbProcessed;
|
||||
uint64_t deleteProcessed;
|
||||
} SQWMsgStat;
|
||||
|
||||
typedef struct SQWRTStat {
|
||||
|
@ -357,6 +358,7 @@ int32_t qwUpdateTimeInQueue(SQWorker *mgmt, int64_t ts, EQueueType type);
|
|||
int64_t qwGetTimeInQueue(SQWorker *mgmt, EQueueType type);
|
||||
void qwClearExpiredSch(SArray* pExpiredSch);
|
||||
int32_t qwAcquireScheduler(SQWorker *mgmt, uint64_t sId, int32_t rwType, SQWSchStatus **sch);
|
||||
void qwFreeTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx *ctx);
|
||||
|
||||
void qwDbgDumpMgmtInfo(SQWorker *mgmt);
|
||||
int32_t qwDbgValidateStatus(QW_FPARAMS_DEF, int8_t oriStatus, int8_t newStatus, bool *ignore);
|
||||
|
|
|
@ -30,6 +30,7 @@ int32_t qwProcessReady(QW_FPARAMS_DEF, SQWMsg *qwMsg);
|
|||
int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg);
|
||||
int32_t qwProcessDrop(QW_FPARAMS_DEF, SQWMsg *qwMsg);
|
||||
int32_t qwProcessHb(SQWorker *mgmt, SQWMsg *qwMsg, SSchedulerHbReq *req);
|
||||
int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SRpcMsg *pRsp, SDeleteRes *pRes);
|
||||
|
||||
int32_t qwBuildAndSendDropRsp(SRpcHandleInfo *pConn, int32_t code);
|
||||
int32_t qwBuildAndSendCancelRsp(SRpcHandleInfo *pConn, int32_t code);
|
||||
|
|
|
@ -300,13 +300,6 @@ int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int
|
|||
QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
msg->sId = msg->sId;
|
||||
msg->queryId = msg->queryId;
|
||||
msg->taskId = msg->taskId;
|
||||
msg->refId = msg->refId;
|
||||
msg->phyLen = msg->phyLen;
|
||||
msg->sqlLen = msg->sqlLen;
|
||||
|
||||
uint64_t sId = msg->sId;
|
||||
uint64_t qId = msg->queryId;
|
||||
uint64_t tId = msg->taskId;
|
||||
|
@ -523,3 +516,37 @@ int32_t qWorkerProcessHbMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t qWorkerProcessDeleteMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, SRpcMsg *pRsp, SDeleteRes *pRes) {
|
||||
if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg || NULL == pRsp) {
|
||||
QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
SVDeleteReq req = {0};
|
||||
SQWorker * mgmt = (SQWorker *)qWorkerMgmt;
|
||||
|
||||
QW_STAT_INC(mgmt->stat.msgStat.deleteProcessed, 1);
|
||||
|
||||
tDeserializeSVDeleteReq(pMsg->pCont, pMsg->contLen, &req);
|
||||
|
||||
uint64_t sId = req.sId;
|
||||
uint64_t qId = req.queryId;
|
||||
uint64_t tId = req.taskId;
|
||||
int64_t rId = 0;
|
||||
|
||||
SQWMsg qwMsg = {.node = node, .msg = req.msg, .msgLen = req.phyLen, .connInfo = pMsg->info};
|
||||
QW_SCH_TASK_DLOG("processDelete start, node:%p, handle:%p, sql:%s", node, pMsg->info.handle, req.sql);
|
||||
taosMemoryFreeClear(req.sql);
|
||||
|
||||
QW_ERR_JRET(qwProcessDelete(QW_FPARAMS(), &qwMsg, pRsp, pRes));
|
||||
|
||||
QW_SCH_TASK_DLOG("processDelete end, node:%p", node);
|
||||
|
||||
_return:
|
||||
|
||||
QW_RET(code);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -290,8 +290,11 @@ int32_t qwKillTaskHandle(QW_FPARAMS_DEF, SQWTaskCtx *ctx) {
|
|||
QW_RET(code);
|
||||
}
|
||||
|
||||
void qwFreeTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx) {
|
||||
void qwFreeTaskCtx(QW_FPARAMS_DEF, SQWTaskCtx *ctx) {
|
||||
if (ctx->ctrlConnInfo.handle) {
|
||||
tmsgReleaseHandle(&ctx->ctrlConnInfo, TAOS_CONN_SERVER);
|
||||
}
|
||||
|
||||
ctx->ctrlConnInfo.handle = NULL;
|
||||
ctx->ctrlConnInfo.refId = -1;
|
||||
|
||||
|
@ -333,7 +336,7 @@ int32_t qwDropTaskCtx(QW_FPARAMS_DEF) {
|
|||
QW_ERR_RET(TSDB_CODE_QRY_TASK_CTX_NOT_EXIST);
|
||||
}
|
||||
|
||||
qwFreeTask(QW_FPARAMS(), &octx);
|
||||
qwFreeTaskCtx(QW_FPARAMS(), &octx);
|
||||
|
||||
QW_TASK_DLOG_E("task ctx dropped");
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ int32_t qwGenerateSchHbRsp(SQWorker *mgmt, SQWSchStatus *sch, SQWHbInfo *hbInfo)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwGetResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void **rspMsg, SOutputData *pOutput) {
|
||||
int32_t qwGetQueryResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void **rspMsg, SOutputData *pOutput) {
|
||||
int32_t len = 0;
|
||||
SRetrieveTableRsp *rsp = NULL;
|
||||
bool queryEnd = false;
|
||||
|
@ -242,6 +242,53 @@ int32_t qwGetResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qwGetDeleteResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, void **rspMsg, SDeleteRes *pRes) {
|
||||
int32_t len = 0;
|
||||
SVDeleteRsp rsp = {0};
|
||||
bool queryEnd = false;
|
||||
int32_t code = 0;
|
||||
SOutputData output = {0};
|
||||
|
||||
dsGetDataLength(ctx->sinkHandle, &len, &queryEnd);
|
||||
|
||||
if (len <= 0 || len != sizeof(SDeleterRes)) {
|
||||
QW_TASK_ELOG("invalid length from dsGetDataLength, length:%d", len);
|
||||
QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
output.pData = taosMemoryCalloc(1, len);
|
||||
if (NULL == output.pData) {
|
||||
QW_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
code = dsGetDataBlock(ctx->sinkHandle, &output);
|
||||
if (code) {
|
||||
QW_TASK_ELOG("dsGetDataBlock failed, code:%x - %s", code, tstrerror(code));
|
||||
taosMemoryFree(output.pData);
|
||||
QW_ERR_RET(code);
|
||||
}
|
||||
|
||||
SDeleterRes* pDelRes = (SDeleterRes*)output.pData;
|
||||
|
||||
rsp.affectedRows = pDelRes->affectedRows;
|
||||
pRes->uid = pDelRes->uid;
|
||||
pRes->uidList = pDelRes->uidList;
|
||||
pRes->skey = pDelRes->skey;
|
||||
pRes->ekey = pDelRes->ekey;
|
||||
|
||||
SEncoder coder = {0};
|
||||
tEncodeSize(tEncodeSVDeleteRsp, &rsp, len, code);
|
||||
void *msg = rpcMallocCont(len);
|
||||
tEncoderInit(&coder, msg, len);
|
||||
tEncodeSVDeleteRsp(&coder, &rsp);
|
||||
tEncoderClear(&coder);
|
||||
|
||||
*rspMsg = msg;
|
||||
*dataLen = len;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t qwHandlePrePhaseEvents(QW_FPARAMS_DEF, int8_t phase, SQWPhaseInput *input, SQWPhaseOutput *output) {
|
||||
int32_t code = 0;
|
||||
|
@ -547,7 +594,7 @@ int32_t qwProcessCQuery(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
|
||||
if (QW_IS_EVENT_RECEIVED(ctx, QW_EVENT_FETCH)) {
|
||||
SOutputData sOutput = {0};
|
||||
QW_ERR_JRET(qwGetResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput));
|
||||
QW_ERR_JRET(qwGetQueryResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput));
|
||||
|
||||
if ((!sOutput.queryEnd) && (DS_BUF_LOW == sOutput.bufStatus || DS_BUF_EMPTY == sOutput.bufStatus)) {
|
||||
QW_TASK_DLOG("task not end and buf is %s, need to continue query", qwBufStatusStr(sOutput.bufStatus));
|
||||
|
@ -620,7 +667,7 @@ int32_t qwProcessFetch(QW_FPARAMS_DEF, SQWMsg *qwMsg) {
|
|||
QW_ERR_JRET(qwGetTaskCtx(QW_FPARAMS(), &ctx));
|
||||
|
||||
SOutputData sOutput = {0};
|
||||
QW_ERR_JRET(qwGetResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput));
|
||||
QW_ERR_JRET(qwGetQueryResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput));
|
||||
|
||||
if (NULL == rsp) {
|
||||
ctx->dataConnInfo = qwMsg->connInfo;
|
||||
|
@ -875,6 +922,47 @@ _return:
|
|||
qwRelease(refId);
|
||||
}
|
||||
|
||||
int32_t qwProcessDelete(QW_FPARAMS_DEF, SQWMsg *qwMsg, SRpcMsg *pRsp, SDeleteRes *pRes) {
|
||||
int32_t code = 0;
|
||||
SSubplan *plan = NULL;
|
||||
qTaskInfo_t pTaskInfo = NULL;
|
||||
DataSinkHandle sinkHandle = NULL;
|
||||
SQWTaskCtx ctx = {0};
|
||||
|
||||
code = qStringToSubplan(qwMsg->msg, &plan);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
QW_TASK_ELOG("task physical plan to subplan failed, code:%x - %s", code, tstrerror(code));
|
||||
QW_ERR_JRET(code);
|
||||
}
|
||||
|
||||
ctx.plan = plan;
|
||||
|
||||
code = qCreateExecTask(qwMsg->node, mgmt->nodeId, tId, plan, &pTaskInfo, &sinkHandle, OPTR_EXEC_MODEL_BATCH);
|
||||
if (code) {
|
||||
QW_TASK_ELOG("qCreateExecTask failed, code:%x - %s", code, tstrerror(code));
|
||||
QW_ERR_JRET(code);
|
||||
}
|
||||
|
||||
if (NULL == sinkHandle || NULL == pTaskInfo) {
|
||||
QW_TASK_ELOG("create task result error, taskHandle:%p, sinkHandle:%p", pTaskInfo, sinkHandle);
|
||||
QW_ERR_JRET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
ctx.taskHandle = pTaskInfo;
|
||||
ctx.sinkHandle = sinkHandle;
|
||||
|
||||
QW_ERR_JRET(qwExecTask(QW_FPARAMS(), &ctx, NULL));
|
||||
|
||||
QW_ERR_JRET(qwGetDeleteResFromSink(QW_FPARAMS(), &ctx, &pRsp->contLen, &pRsp->pCont, pRes));
|
||||
|
||||
_return:
|
||||
|
||||
qwFreeTaskCtx(QW_FPARAMS(), &ctx);
|
||||
|
||||
QW_RET(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, SQWorkerCfg *cfg, void **qWorkerMgmt, const SMsgCb *pMsgCb) {
|
||||
if (NULL == qWorkerMgmt || pMsgCb->mgmt == NULL) {
|
||||
|
@ -1007,6 +1095,7 @@ int32_t qWorkerGetStat(SReadHandle *handle, void *qWorkerMgmt, SQWorkerStat *pSt
|
|||
pStat->fetchProcessed = QW_STAT_GET(mgmt->stat.msgStat.fetchProcessed);
|
||||
pStat->dropProcessed = QW_STAT_GET(mgmt->stat.msgStat.dropProcessed);
|
||||
pStat->hbProcessed = QW_STAT_GET(mgmt->stat.msgStat.hbProcessed);
|
||||
pStat->deleteProcessed = QW_STAT_GET(mgmt->stat.msgStat.deleteProcessed);
|
||||
|
||||
pStat->numOfQueryInQueue = handle->pMsgCb->qsizeFp(handle->pMsgCb->mgmt, mgmt->nodeId, QUERY_QUEUE);
|
||||
pStat->numOfFetchInQueue = handle->pMsgCb->qsizeFp(handle->pMsgCb->mgmt, mgmt->nodeId, FETCH_QUEUE);
|
||||
|
|
|
@ -168,7 +168,7 @@ __compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val
|
|||
compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val,
|
||||
setChkInBytes1, setChkInBytes2, setChkInBytes4, setChkInBytes8, compareStrRegexCompMatch,
|
||||
compareStrRegexCompNMatch, setChkNotInBytes1, setChkNotInBytes2, setChkNotInBytes4, setChkNotInBytes8,
|
||||
compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch, compareJsonContainsKey
|
||||
compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch
|
||||
};
|
||||
|
||||
int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
|
||||
|
|
|
@ -88,7 +88,7 @@ void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int
|
|||
}
|
||||
}
|
||||
|
||||
void convertStringToDouble(const void *inData, void *outData, int8_t inType, int8_t outType){
|
||||
void convertNcharToDouble(const void *inData, void *outData){
|
||||
char *tmp = taosMemoryMalloc(varDataTLen(inData));
|
||||
int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(inData), varDataLen(inData), tmp);
|
||||
if (len < 0) {
|
||||
|
@ -97,13 +97,24 @@ void convertStringToDouble(const void *inData, void *outData, int8_t inType, int
|
|||
|
||||
tmp[len] = 0;
|
||||
|
||||
ASSERT(outType == TSDB_DATA_TYPE_DOUBLE);
|
||||
double value = taosStr2Double(tmp, NULL);
|
||||
|
||||
*((double *)outData) = value;
|
||||
taosMemoryFreeClear(tmp);
|
||||
}
|
||||
|
||||
void convertBinaryToDouble(const void *inData, void *outData){
|
||||
char *tmp = taosMemoryCalloc(1, varDataTLen(inData));
|
||||
if(tmp == NULL){
|
||||
*((double *)outData) = 0.;
|
||||
return;
|
||||
}
|
||||
memcpy(tmp, varDataVal(inData), varDataLen(inData));
|
||||
double ret = taosStr2Double(tmp, NULL);
|
||||
taosMemoryFree(tmp);
|
||||
*((double *)outData) = ret;
|
||||
}
|
||||
|
||||
typedef int64_t (*_getBigintValue_fn_t)(void *src, int32_t index);
|
||||
|
||||
int64_t getVectorBigintValue_TINYINT(void *src, int32_t index) {
|
||||
|
@ -147,7 +158,7 @@ int64_t getVectorBigintValue_JSON(void *src, int32_t index){
|
|||
if (*data == TSDB_DATA_TYPE_NULL){
|
||||
return 0;
|
||||
} else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY
|
||||
convertStringToDouble(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE);
|
||||
convertNcharToDouble(data+CHAR_BYTES, &out);
|
||||
} else {
|
||||
convertNumberToNumber(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE);
|
||||
}
|
||||
|
@ -445,14 +456,30 @@ double getVectorDoubleValue_JSON(void *src, int32_t index){
|
|||
if (*data == TSDB_DATA_TYPE_NULL){
|
||||
return out;
|
||||
} else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY
|
||||
convertStringToDouble(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE);
|
||||
convertNcharToDouble(data+CHAR_BYTES, &out);
|
||||
} else {
|
||||
convertNumberToNumber(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t typeRight, char **pLeftData, char **pRightData, void *pLeftOut, void *pRightOut, bool *isNull){
|
||||
void* ncharTobinary(void *buf){ // todo need to remove , if tobinary is nchar
|
||||
int32_t inputLen = varDataLen(buf);
|
||||
|
||||
void* t = taosMemoryCalloc(1, inputLen);
|
||||
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(buf), varDataLen(buf), varDataVal(t));
|
||||
if (len < 0) {
|
||||
sclError("charset:%s to %s. val:%s convert ncharTobinary failed.", DEFAULT_UNICODE_ENCODEC, tsCharset,
|
||||
(char*)varDataVal(buf));
|
||||
taosMemoryFree(t);
|
||||
return NULL;
|
||||
}
|
||||
varDataSetLen(t, len);
|
||||
return t;
|
||||
}
|
||||
|
||||
bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t typeRight, char **pLeftData, char **pRightData,
|
||||
void *pLeftOut, void *pRightOut, bool *isNull, bool *freeLeft, bool *freeRight){
|
||||
if(optr == OP_TYPE_JSON_CONTAINS) {
|
||||
return true;
|
||||
}
|
||||
|
@ -489,8 +516,12 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
|
|||
|
||||
*fp = filterGetCompFunc(type, optr);
|
||||
|
||||
if(IS_NUMERIC_TYPE(type) || IS_FLOAT_TYPE(type)){
|
||||
if(typeLeft == TSDB_DATA_TYPE_NCHAR) {
|
||||
convertStringToDouble(*pLeftData, pLeftOut, typeLeft, type);
|
||||
convertNcharToDouble(*pLeftData, pLeftOut);
|
||||
*pLeftData = pLeftOut;
|
||||
} else if(typeLeft == TSDB_DATA_TYPE_BINARY) {
|
||||
convertBinaryToDouble(*pLeftData, pLeftOut);
|
||||
*pLeftData = pLeftOut;
|
||||
} else if(typeLeft != type) {
|
||||
convertNumberToNumber(*pLeftData, pLeftOut, typeLeft, type);
|
||||
|
@ -498,12 +529,28 @@ bool convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t t
|
|||
}
|
||||
|
||||
if(typeRight == TSDB_DATA_TYPE_NCHAR) {
|
||||
convertStringToDouble(*pRightData, pRightOut, typeRight, type);
|
||||
convertNcharToDouble(*pRightData, pRightOut);
|
||||
*pRightData = pRightOut;
|
||||
} else if(typeRight == TSDB_DATA_TYPE_BINARY) {
|
||||
convertBinaryToDouble(*pRightData, pRightOut);
|
||||
*pRightData = pRightOut;
|
||||
} else if(typeRight != type) {
|
||||
convertNumberToNumber(*pRightData, pRightOut, typeRight, type);
|
||||
*pRightData = pRightOut;
|
||||
}
|
||||
}else if(type == TSDB_DATA_TYPE_BINARY){
|
||||
if(typeLeft == TSDB_DATA_TYPE_NCHAR){
|
||||
*pLeftData = ncharTobinary(*pLeftData);
|
||||
*freeLeft = true;
|
||||
}
|
||||
if(typeRight == TSDB_DATA_TYPE_NCHAR){
|
||||
*pRightData = ncharTobinary(*pRightData);
|
||||
*freeRight = true;
|
||||
}
|
||||
}else{
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -935,44 +982,6 @@ static void doReleaseVec(SColumnInfoData* pCol, int32_t type) {
|
|||
}
|
||||
}
|
||||
|
||||
STagVal getJsonValue(char *json, char *key, bool *isExist) {
|
||||
STagVal val = {.pKey = key};
|
||||
bool find = tTagGet(((const STag *)json), &val); // json value is null and not exist is different
|
||||
if(isExist){
|
||||
*isExist = find;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
|
||||
SColumnInfoData *pOutputCol = pOut->columnData;
|
||||
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
|
||||
|
||||
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
|
||||
|
||||
char *pRightData = colDataGetVarData(pRight->columnData, 0);
|
||||
char *jsonKey = taosMemoryCalloc(1, varDataLen(pRightData) + 1);
|
||||
memcpy(jsonKey, varDataVal(pRightData), varDataLen(pRightData));
|
||||
for (; i >= 0 && i < pLeft->numOfRows; i += step) {
|
||||
if (colDataIsNull_var(pLeft->columnData, i)) {
|
||||
colDataSetNull_var(pOutputCol, i);
|
||||
pOutputCol->hasNull = true;
|
||||
continue;
|
||||
}
|
||||
char *pLeftData = colDataGetVarData(pLeft->columnData, i);
|
||||
bool isExist = false;
|
||||
STagVal value = getJsonValue(pLeftData, jsonKey, &isExist);
|
||||
char *data = isExist ? tTagValToData(&value, true) : NULL;
|
||||
colDataAppend(pOutputCol, i, data, data == NULL);
|
||||
if(isExist && IS_VAR_DATA_TYPE(value.type) && data){
|
||||
taosMemoryFree(data);
|
||||
}
|
||||
}
|
||||
taosMemoryFree(jsonKey);
|
||||
}
|
||||
|
||||
void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
|
||||
SColumnInfoData *pOutputCol = pOut->columnData;
|
||||
|
||||
|
@ -1510,6 +1519,38 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
|
|||
doReleaseVec(pRightCol, rightConvert);
|
||||
}
|
||||
|
||||
#define VEC_COM_INNER(pCol, index1, index2) \
|
||||
for (; i < pCol->numOfRows && i >= 0; i += step) {\
|
||||
if (IS_HELPER_NULL(pLeft->columnData, index1) || IS_HELPER_NULL(pRight->columnData, index2)) {\
|
||||
bool res = false;\
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);\
|
||||
continue;\
|
||||
}\
|
||||
char *pLeftData = colDataGetData(pLeft->columnData, index1);\
|
||||
char *pRightData = colDataGetData(pRight->columnData, index2);\
|
||||
int64_t leftOut = 0;\
|
||||
int64_t rightOut = 0;\
|
||||
bool freeLeft = false;\
|
||||
bool freeRight = false;\
|
||||
bool isJsonnull = false;\
|
||||
bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight),\
|
||||
&pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull, &freeLeft, &freeRight);\
|
||||
if(isJsonnull){\
|
||||
ASSERT(0);\
|
||||
}\
|
||||
if(!pLeftData || !pRightData){\
|
||||
result = false;\
|
||||
}\
|
||||
if(!result){\
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&result);\
|
||||
}else{\
|
||||
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);\
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);\
|
||||
}\
|
||||
if(freeLeft) taosMemoryFreeClear(pLeftData);\
|
||||
if(freeRight) taosMemoryFreeClear(pRightData);\
|
||||
}
|
||||
|
||||
void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
@ -1533,79 +1574,11 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *
|
|||
}
|
||||
|
||||
if (pLeft->numOfRows == pRight->numOfRows) {
|
||||
for (; i < pRight->numOfRows && i >= 0; i += step) {
|
||||
if (IS_HELPER_NULL(pLeft->columnData, i) || IS_HELPER_NULL(pRight->columnData, i)) {
|
||||
bool res = false;
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
continue; // TODO set null or ignore
|
||||
}
|
||||
|
||||
char *pLeftData = colDataGetData(pLeft->columnData, i);
|
||||
char *pRightData = colDataGetData(pRight->columnData, i);
|
||||
|
||||
int64_t leftOut = 0;
|
||||
int64_t rightOut = 0;
|
||||
bool isJsonnull = false;
|
||||
bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull);
|
||||
if(isJsonnull){
|
||||
ASSERT(0);
|
||||
}
|
||||
if(!result){
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&result);
|
||||
}else{
|
||||
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
}
|
||||
}
|
||||
VEC_COM_INNER(pLeft, i, i)
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
ASSERT(pLeft->pHashFilter == NULL);
|
||||
for (; i >= 0 && i < pLeft->numOfRows; i += step) {
|
||||
if (IS_HELPER_NULL(pLeft->columnData, i) || IS_HELPER_NULL(pRight->columnData, 0)) {
|
||||
bool res = false;
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
continue;
|
||||
}
|
||||
|
||||
char *pLeftData = colDataGetData(pLeft->columnData, i);
|
||||
char *pRightData = colDataGetData(pRight->columnData, 0);
|
||||
int64_t leftOut = 0;
|
||||
int64_t rightOut = 0;
|
||||
bool isJsonnull = false;
|
||||
bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull);
|
||||
if(isJsonnull){
|
||||
ASSERT(0);
|
||||
}
|
||||
if(!result){
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&result);
|
||||
}else{
|
||||
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
}
|
||||
}
|
||||
VEC_COM_INNER(pLeft, i, 0)
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
for (; i >= 0 && i < pRight->numOfRows; i += step) {
|
||||
if (IS_HELPER_NULL(pRight->columnData, i) || IS_HELPER_NULL(pLeft->columnData, 0)) {
|
||||
bool res = false;
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
continue;
|
||||
}
|
||||
|
||||
char *pLeftData = colDataGetData(pLeft->columnData, 0);
|
||||
char *pRightData = colDataGetData(pLeft->columnData, i);
|
||||
int64_t leftOut = 0;
|
||||
int64_t rightOut = 0;
|
||||
bool isJsonnull = false;
|
||||
bool result = convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull);
|
||||
if(isJsonnull){
|
||||
ASSERT(0);
|
||||
}
|
||||
if(!result){
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&result);
|
||||
}else{
|
||||
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
|
||||
colDataAppendInt8(pOut->columnData, i, (int8_t*)&res);
|
||||
}
|
||||
}
|
||||
VEC_COM_INNER(pRight, 0, i)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1683,10 +1656,6 @@ void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu
|
|||
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NMATCH);
|
||||
}
|
||||
|
||||
void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
|
||||
vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_JSON_CONTAINS);
|
||||
}
|
||||
|
||||
void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
|
||||
for(int32_t i = 0; i < pLeft->numOfRows; ++i) {
|
||||
int8_t v = IS_HELPER_NULL(pLeft->columnData, i) ? 1 : 0;
|
||||
|
@ -1707,6 +1676,69 @@ void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut,
|
|||
vectorConvertImpl(pLeft, pOut);
|
||||
}
|
||||
|
||||
STagVal getJsonValue(char *json, char *key, bool *isExist) {
|
||||
STagVal val = {.pKey = key};
|
||||
bool find = tTagGet(((const STag *)json), &val); // json value is null and not exist is different
|
||||
if(isExist){
|
||||
*isExist = find;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
|
||||
SColumnInfoData *pOutputCol = pOut->columnData;
|
||||
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
|
||||
|
||||
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
|
||||
|
||||
char *pRightData = colDataGetVarData(pRight->columnData, 0);
|
||||
char *jsonKey = taosMemoryCalloc(1, varDataLen(pRightData) + 1);
|
||||
memcpy(jsonKey, varDataVal(pRightData), varDataLen(pRightData));
|
||||
for (; i >= 0 && i < pLeft->numOfRows; i += step) {
|
||||
bool isExist = false;
|
||||
|
||||
if (!colDataIsNull_var(pLeft->columnData, i)) {
|
||||
char *pLeftData = colDataGetVarData(pLeft->columnData, i);
|
||||
getJsonValue(pLeftData, jsonKey, &isExist);
|
||||
}
|
||||
|
||||
colDataAppend(pOutputCol, i, (const char*)(&isExist), false);
|
||||
|
||||
}
|
||||
taosMemoryFree(jsonKey);
|
||||
}
|
||||
|
||||
void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
|
||||
SColumnInfoData *pOutputCol = pOut->columnData;
|
||||
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
|
||||
|
||||
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
|
||||
|
||||
char *pRightData = colDataGetVarData(pRight->columnData, 0);
|
||||
char *jsonKey = taosMemoryCalloc(1, varDataLen(pRightData) + 1);
|
||||
memcpy(jsonKey, varDataVal(pRightData), varDataLen(pRightData));
|
||||
for (; i >= 0 && i < pLeft->numOfRows; i += step) {
|
||||
if (colDataIsNull_var(pLeft->columnData, i)) {
|
||||
colDataSetNull_var(pOutputCol, i);
|
||||
pOutputCol->hasNull = true;
|
||||
continue;
|
||||
}
|
||||
char *pLeftData = colDataGetVarData(pLeft->columnData, i);
|
||||
bool isExist = false;
|
||||
STagVal value = getJsonValue(pLeftData, jsonKey, &isExist);
|
||||
char *data = isExist ? tTagValToData(&value, true) : NULL;
|
||||
colDataAppend(pOutputCol, i, data, data == NULL);
|
||||
if(isExist && IS_VAR_DATA_TYPE(value.type) && data){
|
||||
taosMemoryFree(data);
|
||||
}
|
||||
}
|
||||
taosMemoryFree(jsonKey);
|
||||
}
|
||||
|
||||
_bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
|
||||
switch (binFunctionId) {
|
||||
case OP_TYPE_ADD:
|
||||
|
|
|
@ -108,7 +108,7 @@ int32_t schInitJob(SSchJob **pSchJob, SQueryPlan *pDag, void *pTrans, SArray *pN
|
|||
|
||||
pJob->refId = refId;
|
||||
|
||||
SCH_JOB_DLOG("job refId:%" PRIx64, pJob->refId);
|
||||
SCH_JOB_DLOG("job refId:0x%" PRIx64" created", pJob->refId);
|
||||
|
||||
pJob->status = JOB_TASK_STATUS_NOT_START;
|
||||
|
||||
|
@ -1476,7 +1476,7 @@ int32_t schExecJobImpl(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_
|
|||
SSchJob *pJob = NULL;
|
||||
SCH_ERR_RET(schInitJob(&pJob, pDag, pTrans, pNodeList, sql, pRes, startTs, sync));
|
||||
|
||||
qDebug("QID:0x%" PRIx64 " jobId:0x%"PRIx64 " started", pDag->queryId, pJob->refId);
|
||||
qDebug("QID:0x%" PRIx64 " job refId 0x%"PRIx64 " started", pDag->queryId, pJob->refId);
|
||||
*job = pJob->refId;
|
||||
|
||||
SCH_ERR_JRET(schLaunchJob(pJob));
|
||||
|
|
|
@ -62,10 +62,11 @@ int32_t schValidateReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgTy
|
|||
case TDMT_VND_DROP_TABLE_RSP:
|
||||
case TDMT_VND_ALTER_TABLE_RSP:
|
||||
case TDMT_VND_SUBMIT_RSP:
|
||||
case TDMT_VND_DELETE_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);
|
||||
SCH_ERR_RET(TSDB_CODE_INVALID_MSG);
|
||||
}
|
||||
|
||||
if (lastMsgType != reqMsgType) {
|
||||
|
@ -227,6 +228,25 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch
|
|||
|
||||
break;
|
||||
}
|
||||
case TDMT_VND_DELETE_RSP: {
|
||||
SCH_ERR_JRET(rspCode);
|
||||
|
||||
if (msg) {
|
||||
SDecoder coder = {0};
|
||||
SVDeleteRsp rsp = {0};
|
||||
tDecoderInit(&coder, msg, msgSize);
|
||||
tDecodeSVDeleteRsp(&coder, &rsp);
|
||||
|
||||
atomic_add_fetch_32(&pJob->resNumOfRows, rsp.affectedRows);
|
||||
SCH_TASK_DLOG("delete succeed, affectedRows:%" PRId64, rsp.affectedRows);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(msg);
|
||||
|
||||
SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask));
|
||||
|
||||
break;
|
||||
}
|
||||
case TDMT_VND_QUERY_RSP: {
|
||||
SQueryTableRsp *rsp = (SQueryTableRsp *)msg;
|
||||
|
||||
|
@ -411,6 +431,10 @@ int32_t schHandleQueryCallback(void *param, const SDataBuf *pMsg, int32_t code)
|
|||
return schHandleCallback(param, pMsg, TDMT_VND_QUERY_RSP, code);
|
||||
}
|
||||
|
||||
int32_t schHandleDeleteCallback(void *param, const SDataBuf *pMsg, int32_t code) {
|
||||
return schHandleCallback(param, pMsg, TDMT_VND_DELETE_RSP, code);
|
||||
}
|
||||
|
||||
int32_t schHandleFetchCallback(void *param, const SDataBuf *pMsg, int32_t code) {
|
||||
return schHandleCallback(param, pMsg, TDMT_VND_FETCH_RSP, code);
|
||||
}
|
||||
|
@ -501,6 +525,9 @@ int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) {
|
|||
case TDMT_VND_QUERY:
|
||||
*fp = schHandleQueryCallback;
|
||||
break;
|
||||
case TDMT_VND_DELETE:
|
||||
*fp = schHandleDeleteCallback;
|
||||
break;
|
||||
case TDMT_VND_EXPLAIN:
|
||||
*fp = schHandleExplainCallback;
|
||||
break;
|
||||
|
@ -982,6 +1009,26 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
break;
|
||||
}
|
||||
|
||||
case TDMT_VND_DELETE: {
|
||||
SVDeleteReq req = {0};
|
||||
req.header.vgId = addr->nodeId;
|
||||
req.sId = schMgmt.sId;
|
||||
req.queryId = pJob->queryId;
|
||||
req.taskId = pTask->taskId;
|
||||
req.phyLen = pTask->msgLen;
|
||||
req.sqlLen = strlen(pJob->sql);
|
||||
req.sql = (char*)pJob->sql;
|
||||
req.msg = pTask->msg;
|
||||
msgSize = tSerializeSVDeleteReq(NULL, 0, &req);
|
||||
msg = taosMemoryCalloc(1, msgSize);
|
||||
if (NULL == msg) {
|
||||
SCH_TASK_ELOG("calloc %d failed", msgSize);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
tSerializeSVDeleteReq(msg, msgSize, &req);
|
||||
break;
|
||||
}
|
||||
case TDMT_VND_QUERY: {
|
||||
SCH_ERR_RET(schMakeQueryRpcCtx(pJob, pTask, &rpcCtx));
|
||||
|
||||
|
|
|
@ -257,6 +257,8 @@ void schFreeRpcCtx(SRpcCtx *pCtx) {
|
|||
|
||||
taosHashCleanup(pCtx->args);
|
||||
|
||||
if (pCtx->freeFunc) {
|
||||
(*pCtx->freeFunc)(pCtx->brokenVal.val);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,15 +13,22 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _STREAM_INC_H_
|
||||
#define _STREAM_INC_H_
|
||||
|
||||
#include "executor.h"
|
||||
#include "tstream.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _TSTREAM_H_
|
||||
#define _TSTREAM_H_
|
||||
int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb);
|
||||
int32_t streamSink1(SStreamTask* pTask, SMsgCb* pMsgCb);
|
||||
int32_t streamDispatch(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDataBlock* data);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ifndef _TSTREAM_H_ */
|
||||
#endif /* ifndef _STREAM_INC_H_ */
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* 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 "streamInc.h"
|
||||
|
||||
int32_t streamTriggerByWrite(SStreamTask* pTask, int32_t vgId, SMsgCb* pMsgCb) {
|
||||
int8_t execStatus = atomic_load_8(&pTask->status);
|
||||
if (execStatus == TASK_STATUS__IDLE || execStatus == TASK_STATUS__CLOSING) {
|
||||
SStreamTaskRunReq* pRunReq = rpcMallocCont(sizeof(SStreamTaskRunReq));
|
||||
if (pRunReq == NULL) return -1;
|
||||
|
||||
// TODO: do we need htonl?
|
||||
pRunReq->head.vgId = vgId;
|
||||
pRunReq->streamId = pTask->streamId;
|
||||
pRunReq->taskId = pTask->taskId;
|
||||
SRpcMsg msg = {
|
||||
.msgType = TDMT_VND_TASK_RUN,
|
||||
.pCont = pRunReq,
|
||||
.contLen = sizeof(SStreamTaskRunReq),
|
||||
};
|
||||
tmsgPutToQueue(pMsgCb, FETCH_QUEUE, &msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 1
|
||||
int32_t streamTaskEnqueue(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pRsp) {
|
||||
SStreamDataBlock* pBlock = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM);
|
||||
int8_t status;
|
||||
|
||||
// enqueue
|
||||
if (pBlock != NULL) {
|
||||
pBlock->type = STREAM_DATA_TYPE_SSDATA_BLOCK;
|
||||
pBlock->sourceVg = pReq->sourceVg;
|
||||
pBlock->blocks = pReq->data;
|
||||
/*pBlock->sourceVer = pReq->sourceVer;*/
|
||||
if (streamTaskInput(pTask, (SStreamQueueItem*)pBlock) == 0) {
|
||||
status = TASK_INPUT_STATUS__NORMAL;
|
||||
} else {
|
||||
status = TASK_INPUT_STATUS__FAILED;
|
||||
}
|
||||
} else {
|
||||
streamTaskInputFail(pTask);
|
||||
status = TASK_INPUT_STATUS__FAILED;
|
||||
}
|
||||
|
||||
// rsp by input status
|
||||
void* buf = rpcMallocCont(sizeof(SMsgHead) + sizeof(SStreamDispatchRsp));
|
||||
((SMsgHead*)buf)->vgId = htonl(pReq->sourceVg);
|
||||
SStreamDispatchRsp* pCont = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
pCont->inputStatus = status;
|
||||
pCont->streamId = pReq->streamId;
|
||||
pCont->taskId = pReq->sourceTaskId;
|
||||
pRsp->pCont = buf;
|
||||
pRsp->contLen = sizeof(SMsgHead) + sizeof(SStreamDispatchRsp);
|
||||
tmsgSendRsp(pRsp);
|
||||
return status == TASK_INPUT_STATUS__NORMAL ? 0 : -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
int32_t streamProcessDispatchReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchReq* pReq, SRpcMsg* pRsp) {
|
||||
// 1. handle input
|
||||
streamTaskEnqueue(pTask, pReq, pRsp);
|
||||
|
||||
// 2. try exec
|
||||
// 2.1. idle: exec
|
||||
// 2.2. executing: return
|
||||
// 2.3. closing: keep trying
|
||||
streamExec(pTask, pMsgCb);
|
||||
|
||||
// 3. handle output
|
||||
// 3.1 check and set status
|
||||
// 3.2 dispatch / sink
|
||||
streamSink1(pTask, pMsgCb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t streamProcessDispatchRsp(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamDispatchRsp* pRsp) {
|
||||
ASSERT(pRsp->inputStatus == TASK_OUTPUT_STATUS__NORMAL || pRsp->inputStatus == TASK_OUTPUT_STATUS__BLOCKED);
|
||||
int8_t old = atomic_exchange_8(&pTask->outputStatus, pRsp->inputStatus);
|
||||
ASSERT(old == TASK_OUTPUT_STATUS__WAIT);
|
||||
if (pRsp->inputStatus == TASK_INPUT_STATUS__BLOCKED) {
|
||||
// TODO: init recover timer
|
||||
return 0;
|
||||
}
|
||||
// continue dispatch
|
||||
streamSink1(pTask, pMsgCb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t streamTaskProcessRunReq(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
||||
streamExec(pTask, pMsgCb);
|
||||
streamSink1(pTask, pMsgCb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t streamProcessRecoverReq(SStreamTask* pTask, SMsgCb* pMsgCb, SStreamTaskRecoverReq* pReq, SRpcMsg* pMsg) {
|
||||
//
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t streamProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp) {
|
||||
//
|
||||
return 0;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue