Merge branch '3.0' into enh/log
This commit is contained in:
commit
f6287282a8
|
@ -234,9 +234,6 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
|
||||||
|
|
||||||
char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId);
|
char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId);
|
||||||
|
|
||||||
SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema, bool createTb, int64_t suid,
|
|
||||||
const char* stbFullName, int32_t vgId);
|
|
||||||
|
|
||||||
static FORCE_INLINE int32_t blockGetEncodeSize(const SSDataBlock* pBlock) {
|
static FORCE_INLINE int32_t blockGetEncodeSize(const SSDataBlock* pBlock) {
|
||||||
return blockDataGetSerialMetaSize(pBlock->info.numOfCols) + blockDataGetSize(pBlock);
|
return blockDataGetSerialMetaSize(pBlock->info.numOfCols) + blockDataGetSize(pBlock);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2308,6 +2308,29 @@ int32_t tDecodeSMqOffset(SDecoder* decoder, SMqOffset* pOffset);
|
||||||
int32_t tEncodeSMqCMCommitOffsetReq(SEncoder* encoder, const SMqCMCommitOffsetReq* pReq);
|
int32_t tEncodeSMqCMCommitOffsetReq(SEncoder* encoder, const SMqCMCommitOffsetReq* pReq);
|
||||||
int32_t tDecodeSMqCMCommitOffsetReq(SDecoder* decoder, SMqCMCommitOffsetReq* pReq);
|
int32_t tDecodeSMqCMCommitOffsetReq(SDecoder* decoder, SMqCMCommitOffsetReq* pReq);
|
||||||
|
|
||||||
|
// tqOffset
|
||||||
|
enum {
|
||||||
|
TMQ_OFFSET__SNAPSHOT = 1,
|
||||||
|
TMQ_OFFSET__LOG,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int8_t type;
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
int64_t uid;
|
||||||
|
int64_t ts;
|
||||||
|
};
|
||||||
|
struct {
|
||||||
|
int64_t version;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
char subKey[TSDB_SUBSCRIBE_KEY_LEN];
|
||||||
|
} STqOffset;
|
||||||
|
|
||||||
|
int32_t tEncodeSTqOffset(SEncoder* pEncoder, const STqOffset* pOffset);
|
||||||
|
int32_t tDecodeSTqOffset(SDecoder* pDecoder, STqOffset* pOffset);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char name[TSDB_TABLE_FNAME_LEN];
|
char name[TSDB_TABLE_FNAME_LEN];
|
||||||
char stb[TSDB_TABLE_FNAME_LEN];
|
char stb[TSDB_TABLE_FNAME_LEN];
|
||||||
|
|
|
@ -97,7 +97,6 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_MNODE, "create-mnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_MNODE, "create-mnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_MNODE, "alter-mnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_MNODE, "alter-mnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_MNODE, "drop-mnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_DROP_MNODE, "drop-mnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_SET_STANDBY, "set-mnode-standby", NULL, NULL)
|
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_QNODE, "create-qnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_QNODE, "create-qnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_QNODE, "alter-qnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_QNODE, "alter-qnode", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_QNODE, "drop-qnode", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_DROP_QNODE, "drop-qnode", NULL, NULL)
|
||||||
|
@ -141,7 +140,7 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_RECOVER, "consumer-recover", SMqConsumerRecoverMsg, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_RECOVER, "consumer-recover", SMqConsumerRecoverMsg, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "do-rebalance", SMqDoRebalanceMsg, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "do-rebalance", SMqDoRebalanceMsg, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DROP_CGROUP, "drop-cgroup", SMqDropCGroupReq, SMqDropCGroupRsp)
|
TD_DEF_MSG_TYPE(TDMT_MND_MQ_DROP_CGROUP, "drop-cgroup", SMqDropCGroupReq, SMqDropCGroupRsp)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp)
|
TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "mnode-commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mq-tmr", SMTimerReq, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mq-tmr", SMTimerReq, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "telem-tmr", SMTimerReq, SMTimerReq)
|
TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "telem-tmr", SMTimerReq, SMTimerReq)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "trans-tmr", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "trans-tmr", NULL, NULL)
|
||||||
|
@ -177,6 +176,7 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", SVDropStbReq, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", SVDropStbReq, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_CHANGE, "vnode-mq-vg-change", SMqRebVgReq, SMqRebVgRsp)
|
TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_CHANGE, "vnode-mq-vg-change", SMqRebVgReq, SMqRebVgRsp)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_DELETE, "vnode-mq-vg-delete", SMqVDeleteReq, SMqVDeleteRsp)
|
TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_DELETE, "vnode-mq-vg-delete", SMqVDeleteReq, SMqVDeleteRsp)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_VND_MQ_COMMIT_OFFSET, "vnode-commit-offset", STqOffset, STqOffset)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_TASK, "vnode-cancel-task", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_TASK, "vnode-cancel-task", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_DROP_TASK, "vnode-drop-task", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_DROP_TASK, "vnode-drop-task", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TOPIC, "vnode-create-topic", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TOPIC, "vnode-create-topic", NULL, NULL)
|
||||||
|
@ -238,6 +238,8 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_SEND, "sync-snapshot-send", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_SEND, "sync-snapshot-send", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_RSP, "sync-snapshot-rsp", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_RSP, "sync-snapshot-rsp", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_SYNC_LEADER_TRANSFER, "sync-leader-transfer", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_SYNC_LEADER_TRANSFER, "sync-leader-transfer", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_SYNC_SET_MNODE_STANDBY, "set-mnode-standby", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_SYNC_SET_VNODE_STANDBY, "set-vnode-standby", NULL, NULL)
|
||||||
|
|
||||||
#if defined(TD_MSG_NUMBER_)
|
#if defined(TD_MSG_NUMBER_)
|
||||||
TDMT_MAX
|
TDMT_MAX
|
||||||
|
|
|
@ -59,7 +59,13 @@ void mndClose(SMnode *pMnode);
|
||||||
* @param pMnode The mnode object.
|
* @param pMnode The mnode object.
|
||||||
*/
|
*/
|
||||||
int32_t mndStart(SMnode *pMnode);
|
int32_t mndStart(SMnode *pMnode);
|
||||||
void mndStop(SMnode *pMnode);
|
|
||||||
|
/**
|
||||||
|
* @brief Stop mnode
|
||||||
|
*
|
||||||
|
* @param pMnode The mnode object.
|
||||||
|
*/
|
||||||
|
void mndStop(SMnode *pMnode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get mnode monitor info.
|
* @brief Get mnode monitor info.
|
||||||
|
@ -71,17 +77,25 @@ void mndStop(SMnode *pMnode);
|
||||||
* @return int32_t 0 for success, -1 for failure.
|
* @return int32_t 0 for success, -1 for failure.
|
||||||
*/
|
*/
|
||||||
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pCluster, SMonVgroupInfo *pVgroup, SMonGrantInfo *pGrant);
|
int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pCluster, SMonVgroupInfo *pVgroup, SMonGrantInfo *pGrant);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get mnode loads for status msg.
|
||||||
|
*
|
||||||
|
* @param pMnode The mnode object.
|
||||||
|
* @param pLoad
|
||||||
|
* @return int32_t 0 for success, -1 for failure.
|
||||||
|
*/
|
||||||
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
|
int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Process the read, write, sync request.
|
* @brief Process the rpc, sync request.
|
||||||
*
|
*
|
||||||
* @param pMsg The request msg.
|
* @param pMsg The request msg.
|
||||||
* @return int32_t 0 for success, -1 for failure.
|
* @return int32_t 0 for success, -1 for failure.
|
||||||
*/
|
*/
|
||||||
int32_t mndProcessRpcMsg(SRpcMsg *pMsg);
|
int32_t mndProcessRpcMsg(SRpcMsg *pMsg);
|
||||||
int32_t mndProcessSyncMsg(SRpcMsg *pMsg);
|
int32_t mndProcessSyncMsg(SRpcMsg *pMsg);
|
||||||
int32_t mndPreprocessQueryMsg(SMnode * pMnode, SRpcMsg * pMsg);
|
int32_t mndPreProcessMsg(SRpcMsg *pMsg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generate machine code
|
* @brief Generate machine code
|
||||||
|
|
|
@ -142,6 +142,10 @@ typedef enum EFunctionType {
|
||||||
FUNCTION_TYPE_FIRST_MERGE,
|
FUNCTION_TYPE_FIRST_MERGE,
|
||||||
FUNCTION_TYPE_LAST_PARTIAL,
|
FUNCTION_TYPE_LAST_PARTIAL,
|
||||||
FUNCTION_TYPE_LAST_MERGE,
|
FUNCTION_TYPE_LAST_MERGE,
|
||||||
|
FUNCTION_TYPE_AVG_PARTIAL,
|
||||||
|
FUNCTION_TYPE_AVG_MERGE,
|
||||||
|
FUNCTION_TYPE_STDDEV_PARTIAL,
|
||||||
|
FUNCTION_TYPE_STDDEV_MERGE,
|
||||||
|
|
||||||
// user defined funcion
|
// user defined funcion
|
||||||
FUNCTION_TYPE_UDF = 10000
|
FUNCTION_TYPE_UDF = 10000
|
||||||
|
|
|
@ -65,6 +65,7 @@ void qDestroyQuery(SQuery* pQueryNode);
|
||||||
|
|
||||||
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema);
|
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema);
|
||||||
int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid);
|
int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid);
|
||||||
|
void qCleanupKeywordsTable();
|
||||||
|
|
||||||
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
|
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
|
||||||
int32_t qResetStmtDataBlock(void* block, bool keepBuf);
|
int32_t qResetStmtDataBlock(void* block, bool keepBuf);
|
||||||
|
|
|
@ -653,6 +653,7 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_PAR_INVALID_DELETE_WHERE TAOS_DEF_ERROR_CODE(0, 0x2655)
|
#define TSDB_CODE_PAR_INVALID_DELETE_WHERE TAOS_DEF_ERROR_CODE(0, 0x2655)
|
||||||
#define TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG TAOS_DEF_ERROR_CODE(0, 0x2656)
|
#define TSDB_CODE_PAR_INVALID_REDISTRIBUTE_VG TAOS_DEF_ERROR_CODE(0, 0x2656)
|
||||||
#define TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC TAOS_DEF_ERROR_CODE(0, 0x2657)
|
#define TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC TAOS_DEF_ERROR_CODE(0, 0x2657)
|
||||||
|
#define TSDB_CODE_PAR_INVALID_WINDOW_PC TAOS_DEF_ERROR_CODE(0, 0x2658)
|
||||||
|
|
||||||
//planner
|
//planner
|
||||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||||
|
@ -695,8 +696,8 @@ int32_t* taosGetErrno();
|
||||||
#define TSDB_CODE_RSMA_INVALID_ENV TAOS_DEF_ERROR_CODE(0, 0x3150)
|
#define TSDB_CODE_RSMA_INVALID_ENV TAOS_DEF_ERROR_CODE(0, 0x3150)
|
||||||
#define TSDB_CODE_RSMA_INVALID_STAT TAOS_DEF_ERROR_CODE(0, 0x3151)
|
#define TSDB_CODE_RSMA_INVALID_STAT TAOS_DEF_ERROR_CODE(0, 0x3151)
|
||||||
|
|
||||||
// index
|
//index
|
||||||
#define TSDB_CODE_INDEX_REBUILD TAOS_DEF_ERROR_CODE(0, 0x3251)
|
#define TSDB_CODE_INDEX_REBUILDING TAOS_DEF_ERROR_CODE(0, 0x3200)
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -206,7 +206,7 @@ int32_t execLocalCmd(SRequestObj* pRequest, SQuery* pQuery) {
|
||||||
SRetrieveTableRsp* pRsp = NULL;
|
SRetrieveTableRsp* pRsp = NULL;
|
||||||
int32_t code = qExecCommand(pQuery->pRoot, &pRsp);
|
int32_t code = qExecCommand(pQuery->pRoot, &pRsp);
|
||||||
if (TSDB_CODE_SUCCESS == code && NULL != pRsp) {
|
if (TSDB_CODE_SUCCESS == code && NULL != pRsp) {
|
||||||
code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false, false);
|
code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -1415,7 +1415,7 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32
|
||||||
int32_t bytes = *(int32_t*)p;
|
int32_t bytes = *(int32_t*)p;
|
||||||
p += sizeof(int32_t);
|
p += sizeof(int32_t);
|
||||||
|
|
||||||
// ASSERT(type == pFields[i].type && bytes == pFields[i].bytes);
|
/*ASSERT(type == pFields[i].type && bytes == pFields[i].bytes);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t* colLength = (int32_t*)p;
|
int32_t* colLength = (int32_t*)p;
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "tref.h"
|
#include "tref.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
#include "functionMgt.h"
|
||||||
|
|
||||||
#define TSC_VAR_NOT_RELEASE 1
|
#define TSC_VAR_NOT_RELEASE 1
|
||||||
#define TSC_VAR_RELEASED 0
|
#define TSC_VAR_RELEASED 0
|
||||||
|
@ -61,6 +62,9 @@ void taos_cleanup(void) {
|
||||||
|
|
||||||
cleanupTaskQueue();
|
cleanupTaskQueue();
|
||||||
|
|
||||||
|
fmFuncMgtDestroy();
|
||||||
|
qCleanupKeywordsTable();
|
||||||
|
|
||||||
id = clientConnRefPool;
|
id = clientConnRefPool;
|
||||||
clientConnRefPool = -1;
|
clientConnRefPool = -1;
|
||||||
taosCloseRef(id);
|
taosCloseRef(id);
|
||||||
|
|
|
@ -132,6 +132,7 @@ typedef struct {
|
||||||
// statistics
|
// statistics
|
||||||
int64_t pollCnt;
|
int64_t pollCnt;
|
||||||
// offset
|
// offset
|
||||||
|
int64_t committedOffset;
|
||||||
int64_t currentOffset;
|
int64_t currentOffset;
|
||||||
// connection info
|
// connection info
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
|
@ -193,6 +194,26 @@ typedef struct {
|
||||||
void* userParam;
|
void* userParam;
|
||||||
} SMqCommitCbParam;
|
} SMqCommitCbParam;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
tmq_t* tmq;
|
||||||
|
int8_t automatic;
|
||||||
|
int8_t async;
|
||||||
|
int8_t freeOffsets;
|
||||||
|
int32_t waitingRspNum;
|
||||||
|
int32_t totalRspNum;
|
||||||
|
tmq_resp_err_t rspErr;
|
||||||
|
tmq_commit_cb* userCb;
|
||||||
|
SArray* successfulOffsets;
|
||||||
|
SArray* failedOffsets;
|
||||||
|
void* userParam;
|
||||||
|
tsem_t rspSem;
|
||||||
|
} SMqCommitCbParamSet;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
SMqCommitCbParamSet* params;
|
||||||
|
STqOffset* pOffset;
|
||||||
|
} SMqCommitCbParam2;
|
||||||
|
|
||||||
tmq_conf_t* tmq_conf_new() {
|
tmq_conf_t* tmq_conf_new() {
|
||||||
tmq_conf_t* conf = taosMemoryCalloc(1, sizeof(tmq_conf_t));
|
tmq_conf_t* conf = taosMemoryCalloc(1, sizeof(tmq_conf_t));
|
||||||
conf->withTbName = false;
|
conf->withTbName = false;
|
||||||
|
@ -343,6 +364,139 @@ int32_t tmqCommitCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tmqCommitCb2(void* param, const SDataBuf* pBuf, int32_t code) {
|
||||||
|
SMqCommitCbParam2* pParam = (SMqCommitCbParam2*)param;
|
||||||
|
SMqCommitCbParamSet* pParamSet = (SMqCommitCbParamSet*)pParam->params;
|
||||||
|
// push into array
|
||||||
|
if (code == 0) {
|
||||||
|
taosArrayPush(pParamSet->failedOffsets, &pParam->pOffset);
|
||||||
|
} else {
|
||||||
|
taosArrayPush(pParamSet->successfulOffsets, &pParam->pOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
// count down waiting rsp
|
||||||
|
int32_t waitingRspNum = atomic_sub_fetch_32(&pParamSet->waitingRspNum, 1);
|
||||||
|
ASSERT(waitingRspNum >= 0);
|
||||||
|
|
||||||
|
if (waitingRspNum == 0) {
|
||||||
|
// if no more waiting rsp
|
||||||
|
if (pParamSet->async) {
|
||||||
|
// call async cb func
|
||||||
|
if (pParamSet->automatic && pParamSet->tmq->commitCb) {
|
||||||
|
pParamSet->tmq->commitCb(pParamSet->tmq, pParamSet->rspErr, NULL, pParamSet->tmq->commitCbUserParam);
|
||||||
|
} else if (!pParamSet->automatic && pParamSet->userCb) {
|
||||||
|
// sem post
|
||||||
|
pParamSet->userCb(pParamSet->tmq, pParamSet->rspErr, NULL, pParamSet->userParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayDestroyP(pParamSet->successfulOffsets, taosMemoryFree);
|
||||||
|
taosArrayDestroyP(pParamSet->failedOffsets, taosMemoryFree);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tmqCommitInner2(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8_t automatic, int8_t async,
|
||||||
|
tmq_commit_cb* userCb, void* userParam) {
|
||||||
|
int32_t code = -1;
|
||||||
|
|
||||||
|
SMqCommitCbParamSet* pParamSet = taosMemoryCalloc(1, sizeof(SMqCommitCbParamSet));
|
||||||
|
if (pParamSet == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
pParamSet->tmq = tmq;
|
||||||
|
pParamSet->automatic = automatic;
|
||||||
|
pParamSet->async = async;
|
||||||
|
pParamSet->freeOffsets = 1;
|
||||||
|
pParamSet->userCb = userCb;
|
||||||
|
pParamSet->userParam = userParam;
|
||||||
|
tsem_init(&pParamSet->rspSem, 0, 0);
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) {
|
||||||
|
SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i);
|
||||||
|
for (int32_t j = 0; j < taosArrayGetSize(pTopic->vgs); j++) {
|
||||||
|
SMqClientVg* pVg = taosArrayGet(pTopic->vgs, i);
|
||||||
|
STqOffset* pOffset = taosMemoryCalloc(1, sizeof(STqOffset));
|
||||||
|
if (pOffset == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int32_t tlen = strlen(tmq->groupId);
|
||||||
|
memcpy(pOffset->subKey, tmq->groupId, tlen);
|
||||||
|
pOffset->subKey[tlen] = TMQ_SEPARATOR;
|
||||||
|
strcpy(pOffset->subKey + tlen + 1, pTopic->topicName);
|
||||||
|
int32_t len;
|
||||||
|
int32_t code;
|
||||||
|
tEncodeSize(tEncodeSTqOffset, pOffset, len, code);
|
||||||
|
if (code < 0) {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
void* buf = taosMemoryCalloc(1, sizeof(SMsgHead) + len);
|
||||||
|
((SMsgHead*)buf)->vgId = htonl(pVg->vgId);
|
||||||
|
|
||||||
|
void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||||
|
|
||||||
|
SEncoder encoder;
|
||||||
|
tEncoderInit(&encoder, abuf, len);
|
||||||
|
tEncodeSTqOffset(&encoder, pOffset);
|
||||||
|
|
||||||
|
// build param
|
||||||
|
SMqCommitCbParam2* pParam = taosMemoryCalloc(1, sizeof(SMqCommitCbParam2));
|
||||||
|
pParam->params = pParamSet;
|
||||||
|
pParam->pOffset = pOffset;
|
||||||
|
|
||||||
|
// build send info
|
||||||
|
SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||||
|
if (pMsgSendInfo == NULL) {
|
||||||
|
// TODO
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
pMsgSendInfo->msgInfo = (SDataBuf){
|
||||||
|
.pData = buf,
|
||||||
|
.len = len,
|
||||||
|
.handle = NULL,
|
||||||
|
};
|
||||||
|
|
||||||
|
pMsgSendInfo->requestId = generateRequestId();
|
||||||
|
pMsgSendInfo->requestObjRefId = 0;
|
||||||
|
pMsgSendInfo->param = pParam;
|
||||||
|
pMsgSendInfo->fp = tmqCommitCb2;
|
||||||
|
pMsgSendInfo->msgType = TDMT_MND_MQ_COMMIT_OFFSET;
|
||||||
|
// send msg
|
||||||
|
|
||||||
|
SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp);
|
||||||
|
int64_t transporterId = 0;
|
||||||
|
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, pMsgSendInfo);
|
||||||
|
pParamSet->waitingRspNum++;
|
||||||
|
pParamSet->totalRspNum++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!async) {
|
||||||
|
tsem_wait(&pParamSet->rspSem);
|
||||||
|
code = pParamSet->rspErr;
|
||||||
|
tsem_destroy(&pParamSet->rspSem);
|
||||||
|
} else {
|
||||||
|
code = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code != 0 && async) {
|
||||||
|
if (automatic) {
|
||||||
|
tmq->commitCb(tmq, code, NULL, tmq->commitCbUserParam);
|
||||||
|
} else {
|
||||||
|
userCb(tmq, code, NULL, userParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!async) {
|
||||||
|
taosArrayDestroyP(pParamSet->successfulOffsets, taosMemoryFree);
|
||||||
|
taosArrayDestroyP(pParamSet->failedOffsets, taosMemoryFree);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tmqCommitInner(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8_t automatic, int8_t async,
|
int32_t tmqCommitInner(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, int8_t automatic, int8_t async,
|
||||||
tmq_commit_cb* userCb, void* userParam) {
|
tmq_commit_cb* userCb, void* userParam) {
|
||||||
SMqCMCommitOffsetReq req;
|
SMqCMCommitOffsetReq req;
|
||||||
|
@ -890,12 +1044,13 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
|
||||||
sprintf(vgKey, "%s:%d", topic.topicName, pVgEp->vgId);
|
sprintf(vgKey, "%s:%d", topic.topicName, pVgEp->vgId);
|
||||||
int64_t* pOffset = taosHashGet(pHash, vgKey, strlen(vgKey));
|
int64_t* pOffset = taosHashGet(pHash, vgKey, strlen(vgKey));
|
||||||
int64_t offset = pVgEp->offset;
|
int64_t offset = pVgEp->offset;
|
||||||
tscDebug("consumer %ld epoch %d vg %d offset og to %ld", tmq->consumerId, epoch, pVgEp->vgId, offset);
|
tscDebug("consumer %ld(epoch %d) original offset of vg %d is %ld", tmq->consumerId, epoch, pVgEp->vgId, offset);
|
||||||
if (pOffset != NULL) {
|
if (pOffset != NULL) {
|
||||||
offset = *pOffset;
|
offset = *pOffset;
|
||||||
tscDebug("consumer %ld epoch %d vg %d found %s", tmq->consumerId, epoch, pVgEp->vgId, vgKey);
|
tscDebug("consumer %ld(epoch %d) receive offset of vg %d, full key is %s", tmq->consumerId, epoch, pVgEp->vgId,
|
||||||
|
vgKey);
|
||||||
}
|
}
|
||||||
tscDebug("consumer %ld epoch %d vg %d offset set to %ld", tmq->consumerId, epoch, pVgEp->vgId, offset);
|
tscDebug("consumer %ld(epoch %d) offset of vg %d updated to %ld", tmq->consumerId, epoch, pVgEp->vgId, offset);
|
||||||
SMqClientVg clientVg = {
|
SMqClientVg clientVg = {
|
||||||
.pollCnt = 0,
|
.pollCnt = 0,
|
||||||
.currentOffset = offset,
|
.currentOffset = offset,
|
||||||
|
@ -1226,9 +1381,8 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
|
||||||
if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__POLL_RSP) {
|
if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__POLL_RSP) {
|
||||||
SMqPollRspWrapper* pollRspWrapper = (SMqPollRspWrapper*)rspWrapper;
|
SMqPollRspWrapper* pollRspWrapper = (SMqPollRspWrapper*)rspWrapper;
|
||||||
/*atomic_sub_fetch_32(&tmq->readyRequest, 1);*/
|
/*atomic_sub_fetch_32(&tmq->readyRequest, 1);*/
|
||||||
/*printf("handle poll rsp %d\n", rspMsg->head.mqMsgType);*/
|
int32_t consumerEpoch = atomic_load_32(&tmq->epoch);
|
||||||
if (pollRspWrapper->msg.head.epoch == atomic_load_32(&tmq->epoch)) {
|
if (pollRspWrapper->msg.head.epoch == consumerEpoch) {
|
||||||
/*printf("epoch match\n");*/
|
|
||||||
SMqClientVg* pVg = pollRspWrapper->vgHandle;
|
SMqClientVg* pVg = pollRspWrapper->vgHandle;
|
||||||
/*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/
|
/*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/
|
||||||
pVg->currentOffset = pollRspWrapper->msg.rspOffset;
|
pVg->currentOffset = pollRspWrapper->msg.rspOffset;
|
||||||
|
@ -1243,7 +1397,8 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) {
|
||||||
taosFreeQitem(pollRspWrapper);
|
taosFreeQitem(pollRspWrapper);
|
||||||
return pRsp;
|
return pRsp;
|
||||||
} else {
|
} else {
|
||||||
/*printf("epoch mismatch\n");*/
|
tscDebug("msg discard since epoch mismatch: msg epoch %d, consumer epoch %d\n", pollRspWrapper->msg.head.epoch,
|
||||||
|
consumerEpoch);
|
||||||
taosFreeQitem(pollRspWrapper);
|
taosFreeQitem(pollRspWrapper);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1263,10 +1418,14 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) {
|
||||||
SMqRspObj* rspObj;
|
SMqRspObj* rspObj;
|
||||||
int64_t startTime = taosGetTimestampMs();
|
int64_t startTime = taosGetTimestampMs();
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
tmqHandleAllDelayedTask(tmq);
|
||||||
|
tmqPollImpl(tmq, timeout);
|
||||||
rspObj = tmqHandleAllRsp(tmq, timeout, false);
|
rspObj = tmqHandleAllRsp(tmq, timeout, false);
|
||||||
if (rspObj) {
|
if (rspObj) {
|
||||||
return (TAOS_RES*)rspObj;
|
return (TAOS_RES*)rspObj;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// in no topic status also need process delayed task
|
// in no topic status also need process delayed task
|
||||||
if (atomic_load_8(&tmq->status) == TMQ_CONSUMER_STATUS__INIT) {
|
if (atomic_load_8(&tmq->status) == TMQ_CONSUMER_STATUS__INIT) {
|
||||||
|
@ -1359,8 +1518,7 @@ const char* tmq_get_table_name(TAOS_RES* res) {
|
||||||
pRspObj->resIter >= pRspObj->rsp.blockNum) {
|
pRspObj->resIter >= pRspObj->rsp.blockNum) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
const char* name = taosArrayGetP(pRspObj->rsp.blockTbName, pRspObj->resIter);
|
return (const char*)taosArrayGetP(pRspObj->rsp.blockTbName, pRspObj->resIter);
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1708,6 +1708,7 @@ char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId) {
|
||||||
pTag->keyLen = strlen(pTag->key);
|
pTag->keyLen = strlen(pTag->key);
|
||||||
pTag->type = TSDB_DATA_TYPE_UBIGINT;
|
pTag->type = TSDB_DATA_TYPE_UBIGINT;
|
||||||
pTag->u = groupId;
|
pTag->u = groupId;
|
||||||
|
pTag->length = sizeof(uint64_t);
|
||||||
taosArrayPush(tags, &pTag);
|
taosArrayPush(tags, &pTag);
|
||||||
|
|
||||||
void* cname = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1);
|
void* cname = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1);
|
||||||
|
@ -1728,173 +1729,6 @@ char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId) {
|
||||||
return rname.childTableName;
|
return rname.childTableName;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, bool createTb, int64_t suid,
|
|
||||||
const char* stbFullName, int32_t vgId) {
|
|
||||||
SSubmitReq* ret = NULL;
|
|
||||||
SArray* tagArray = taosArrayInit(1, sizeof(STagVal));
|
|
||||||
if (!tagArray) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cal size
|
|
||||||
int32_t cap = sizeof(SSubmitReq);
|
|
||||||
int32_t sz = taosArrayGetSize(pBlocks);
|
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
|
||||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
|
||||||
int32_t rows = pDataBlock->info.rows;
|
|
||||||
// TODO min
|
|
||||||
int32_t rowSize = pDataBlock->info.rowSize;
|
|
||||||
int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);
|
|
||||||
int32_t schemaLen = 0;
|
|
||||||
|
|
||||||
if (createTb) {
|
|
||||||
SVCreateTbReq createTbReq = {0};
|
|
||||||
char* cname = buildCtbNameByGroupId(stbFullName, pDataBlock->info.groupId);
|
|
||||||
createTbReq.name = cname;
|
|
||||||
createTbReq.flags = 0;
|
|
||||||
createTbReq.type = TSDB_CHILD_TABLE;
|
|
||||||
createTbReq.ctb.suid = suid;
|
|
||||||
|
|
||||||
STagVal tagVal = {.cid = 1,
|
|
||||||
.type = TSDB_DATA_TYPE_UBIGINT,
|
|
||||||
.pData = (uint8_t*)&pDataBlock->info.groupId,
|
|
||||||
.nData = sizeof(uint64_t)};
|
|
||||||
STag* pTag = NULL;
|
|
||||||
taosArrayClear(tagArray);
|
|
||||||
taosArrayPush(tagArray, &tagVal);
|
|
||||||
tTagNew(tagArray, 1, false, &pTag);
|
|
||||||
if (pTag == NULL) {
|
|
||||||
tdDestroySVCreateTbReq(&createTbReq);
|
|
||||||
taosArrayDestroy(tagArray);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
createTbReq.ctb.pTag = (uint8_t*)pTag;
|
|
||||||
|
|
||||||
int32_t code;
|
|
||||||
tEncodeSize(tEncodeSVCreateTbReq, &createTbReq, schemaLen, code);
|
|
||||||
|
|
||||||
tdDestroySVCreateTbReq(&createTbReq);
|
|
||||||
if (code < 0) {
|
|
||||||
taosArrayDestroy(tagArray);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cap += sizeof(SSubmitBlk) + schemaLen + rows * maxLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
// assign data
|
|
||||||
// TODO
|
|
||||||
ret = taosMemoryCalloc(1, cap + 46);
|
|
||||||
ret = POINTER_SHIFT(ret, 46);
|
|
||||||
ret->header.vgId = vgId;
|
|
||||||
ret->version = htonl(1);
|
|
||||||
ret->length = sizeof(SSubmitReq);
|
|
||||||
ret->numOfBlocks = htonl(sz);
|
|
||||||
|
|
||||||
void* submitBlk = POINTER_SHIFT(ret, sizeof(SSubmitReq));
|
|
||||||
for (int32_t i = 0; i < sz; i++) {
|
|
||||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
|
||||||
|
|
||||||
SSubmitBlk* blkHead = submitBlk;
|
|
||||||
blkHead->numOfRows = htons(pDataBlock->info.rows);
|
|
||||||
blkHead->sversion = htonl(pTSchema->version);
|
|
||||||
// TODO
|
|
||||||
blkHead->suid = htobe64(suid);
|
|
||||||
// uid is assigned by vnode
|
|
||||||
blkHead->uid = 0;
|
|
||||||
|
|
||||||
int32_t rows = pDataBlock->info.rows;
|
|
||||||
/*int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);*/
|
|
||||||
/*blkHead->dataLen = htonl(rows * maxLen);*/
|
|
||||||
blkHead->dataLen = 0;
|
|
||||||
|
|
||||||
void* blockData = POINTER_SHIFT(submitBlk, sizeof(SSubmitBlk));
|
|
||||||
|
|
||||||
int32_t schemaLen = 0;
|
|
||||||
if (createTb) {
|
|
||||||
SVCreateTbReq createTbReq = {0};
|
|
||||||
char* cname = buildCtbNameByGroupId(stbFullName, pDataBlock->info.groupId);
|
|
||||||
createTbReq.name = cname;
|
|
||||||
createTbReq.flags = 0;
|
|
||||||
createTbReq.type = TSDB_CHILD_TABLE;
|
|
||||||
createTbReq.ctb.suid = suid;
|
|
||||||
|
|
||||||
STagVal tagVal = {.cid = 1,
|
|
||||||
.type = TSDB_DATA_TYPE_UBIGINT,
|
|
||||||
.pData = (uint8_t*)&pDataBlock->info.groupId,
|
|
||||||
.nData = sizeof(uint64_t)};
|
|
||||||
taosArrayClear(tagArray);
|
|
||||||
taosArrayPush(tagArray, &tagVal);
|
|
||||||
STag* pTag = NULL;
|
|
||||||
tTagNew(tagArray, 1, false, &pTag);
|
|
||||||
if (pTag == NULL) {
|
|
||||||
tdDestroySVCreateTbReq(&createTbReq);
|
|
||||||
taosArrayDestroy(tagArray);
|
|
||||||
taosMemoryFreeClear(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
createTbReq.ctb.pTag = (uint8_t*)pTag;
|
|
||||||
|
|
||||||
int32_t code;
|
|
||||||
tEncodeSize(tEncodeSVCreateTbReq, &createTbReq, schemaLen, code);
|
|
||||||
if (code < 0) {
|
|
||||||
tdDestroySVCreateTbReq(&createTbReq);
|
|
||||||
taosArrayDestroy(tagArray);
|
|
||||||
taosMemoryFreeClear(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SEncoder encoder = {0};
|
|
||||||
tEncoderInit(&encoder, blockData, schemaLen);
|
|
||||||
code = tEncodeSVCreateTbReq(&encoder, &createTbReq);
|
|
||||||
tEncoderClear(&encoder);
|
|
||||||
tdDestroySVCreateTbReq(&createTbReq);
|
|
||||||
|
|
||||||
if (code < 0) {
|
|
||||||
taosArrayDestroy(tagArray);
|
|
||||||
taosMemoryFreeClear(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
blkHead->schemaLen = htonl(schemaLen);
|
|
||||||
|
|
||||||
STSRow* rowData = POINTER_SHIFT(blockData, schemaLen);
|
|
||||||
|
|
||||||
for (int32_t j = 0; j < rows; j++) {
|
|
||||||
SRowBuilder rb = {0};
|
|
||||||
tdSRowInit(&rb, pTSchema->version);
|
|
||||||
tdSRowSetTpInfo(&rb, pTSchema->numOfCols, pTSchema->flen);
|
|
||||||
tdSRowResetBuf(&rb, rowData);
|
|
||||||
|
|
||||||
for (int32_t k = 0; k < pTSchema->numOfCols; k++) {
|
|
||||||
const STColumn* pColumn = &pTSchema->columns[k];
|
|
||||||
SColumnInfoData* pColData = taosArrayGet(pDataBlock->pDataBlock, k);
|
|
||||||
if (colDataIsNull_s(pColData, j)) {
|
|
||||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NONE, NULL, false, pColumn->offset, k);
|
|
||||||
} else {
|
|
||||||
void* data = colDataGetData(pColData, j);
|
|
||||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, pColumn->offset, k);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int32_t rowLen = TD_ROW_LEN(rowData);
|
|
||||||
rowData = POINTER_SHIFT(rowData, rowLen);
|
|
||||||
blkHead->dataLen += rowLen;
|
|
||||||
}
|
|
||||||
int32_t dataLen = blkHead->dataLen;
|
|
||||||
blkHead->dataLen = htonl(dataLen);
|
|
||||||
|
|
||||||
ret->length += sizeof(SSubmitBlk) + schemaLen + dataLen;
|
|
||||||
blkHead = POINTER_SHIFT(blkHead, schemaLen + dataLen);
|
|
||||||
/*submitBlk = blkHead;*/
|
|
||||||
}
|
|
||||||
|
|
||||||
ret->length = htonl(ret->length);
|
|
||||||
taosArrayDestroy(tagArray);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols,
|
void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols,
|
||||||
int8_t needCompress) {
|
int8_t needCompress) {
|
||||||
// todo extract method
|
// todo extract method
|
||||||
|
|
|
@ -4851,3 +4851,32 @@ void tFreeSMAlterStbRsp(SMAlterStbRsp *pRsp) {
|
||||||
taosMemoryFree(pRsp->pMeta);
|
taosMemoryFree(pRsp->pMeta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tEncodeSTqOffset(SEncoder *pEncoder, const STqOffset *pOffset) {
|
||||||
|
if (tEncodeI8(pEncoder, pOffset->type) < 0) return -1;
|
||||||
|
if (pOffset->type == TMQ_OFFSET__SNAPSHOT) {
|
||||||
|
if (tEncodeI64(pEncoder, pOffset->uid) < 0) return -1;
|
||||||
|
if (tEncodeI64(pEncoder, pOffset->ts) < 0) return -1;
|
||||||
|
} else if (pOffset->type == TMQ_OFFSET__LOG) {
|
||||||
|
if (tEncodeI64(pEncoder, pOffset->version) < 0) return -1;
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
if (tEncodeCStr(pEncoder, pOffset->subKey) < 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tDecodeSTqOffset(SDecoder *pDecoder, STqOffset *pOffset) {
|
||||||
|
if (tDecodeI8(pDecoder, &pOffset->type) < 0) return -1;
|
||||||
|
if (pOffset->type == TMQ_OFFSET__SNAPSHOT) {
|
||||||
|
if (tDecodeI64(pDecoder, &pOffset->uid) < 0) return -1;
|
||||||
|
if (tDecodeI64(pDecoder, &pOffset->ts) < 0) return -1;
|
||||||
|
} else if (pOffset->type == TMQ_OFFSET__LOG) {
|
||||||
|
if (tDecodeI64(pDecoder, &pOffset->version) < 0) return -1;
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
if (tDecodeCStrTo(pDecoder, pOffset->subKey) < 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,6 @@ SArray *mmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_MNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_MNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_MNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_MNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_MNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_MNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_SET_STANDBY_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_MNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_MNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_QNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_QNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_QNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_QNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
|
@ -236,7 +235,10 @@ SArray *mmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_MND_SET_STANDBY, mmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SET_MNODE_STANDBY, mmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||||
|
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SET_MNODE_STANDBY_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SET_VNODE_STANDBY_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,8 @@ int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mmPutMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t mmPutMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
if (mndPreprocessQueryMsg(pMgmt->pMnode, pMsg) != 0) {
|
pMsg->info.node = pMgmt->pMnode;
|
||||||
|
if (mndPreProcessMsg(pMsg) != 0) {
|
||||||
dError("msg:%p, failed to pre-process in mnode since %s, type:%s", pMsg, terrstr(), TMSG_INFO(pMsg->msgType));
|
dError("msg:%p, failed to pre-process in mnode since %s, type:%s", pMsg, terrstr(), TMSG_INFO(pMsg->msgType));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -344,6 +344,7 @@ SArray *vmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT_RSMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT_RSMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_COMMIT_OFFSET, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_CONSUME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_CONSUME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_HEARTBEAT, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_HEARTBEAT, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER;
|
||||||
|
@ -373,6 +374,7 @@ SArray *vmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_REQUEST_VOTE_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_REQUEST_VOTE_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SET_VNODE_STANDBY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER;
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
|
|
|
@ -124,8 +124,6 @@ void mndReleaseRpcRef(SMnode *pMnode);
|
||||||
void mndSetRestore(SMnode *pMnode, bool restored);
|
void mndSetRestore(SMnode *pMnode, bool restored);
|
||||||
void mndSetStop(SMnode *pMnode);
|
void mndSetStop(SMnode *pMnode);
|
||||||
bool mndGetStop(SMnode *pMnode);
|
bool mndGetStop(SMnode *pMnode);
|
||||||
int32_t mndAcquireSyncRef(SMnode *pMnode);
|
|
||||||
void mndReleaseSyncRef(SMnode *pMnode);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ int32_t mndInitSma(SMnode *pMnode);
|
||||||
void mndCleanupSma(SMnode *pMnode);
|
void mndCleanupSma(SMnode *pMnode);
|
||||||
SSmaObj *mndAcquireSma(SMnode *pMnode, char *smaName);
|
SSmaObj *mndAcquireSma(SMnode *pMnode, char *smaName);
|
||||||
void mndReleaseSma(SMnode *pMnode, SSmaObj *pSma);
|
void mndReleaseSma(SMnode *pMnode, SSmaObj *pSma);
|
||||||
|
int32_t mndDropSmasByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb);
|
||||||
|
int32_t mndDropSmasByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb);
|
||||||
int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool *exist);
|
int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool *exist);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -935,6 +935,7 @@ static int32_t mndDropDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb) {
|
||||||
if (mndDropOffsetByDB(pMnode, pTrans, pDb) != 0) goto _OVER;
|
if (mndDropOffsetByDB(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||||
if (mndDropSubByDB(pMnode, pTrans, pDb) != 0) goto _OVER;
|
if (mndDropSubByDB(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||||
if (mndDropTopicByDB(pMnode, pTrans, pDb) != 0) goto _OVER;
|
if (mndDropTopicByDB(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||||
|
if (mndDropSmasByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||||
if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) goto _OVER;
|
if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||||
|
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, pDb->createUser);
|
SUserObj *pUser = mndAcquireUser(pMnode, pDb->createUser);
|
||||||
|
|
|
@ -393,11 +393,6 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
||||||
return TAOS_SYNC_OTHER_ERROR;
|
return TAOS_SYNC_OTHER_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mndAcquireSyncRef(pMnode) != 0) {
|
|
||||||
mError("failed to process sync msg:%p type:%s since %s", pMsg, TMSG_INFO(pMsg->msgType), terrstr());
|
|
||||||
return TAOS_SYNC_OTHER_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
char logBuf[512] = {0};
|
char logBuf[512] = {0};
|
||||||
char *syncNodeStr = sync2SimpleStr(pMgmt->sync);
|
char *syncNodeStr = sync2SimpleStr(pMgmt->sync);
|
||||||
snprintf(logBuf, sizeof(logBuf), "==vnodeProcessSyncReq== msgType:%d, syncNode: %s", pMsg->msgType, syncNodeStr);
|
snprintf(logBuf, sizeof(logBuf), "==vnodeProcessSyncReq== msgType:%d, syncNode: %s", pMsg->msgType, syncNodeStr);
|
||||||
|
@ -450,7 +445,7 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
||||||
SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg);
|
SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg);
|
||||||
code = syncNodeOnSnapshotRspCb(pSyncNode, pSyncMsg);
|
code = syncNodeOnSnapshotRspCb(pSyncNode, pSyncMsg);
|
||||||
syncSnapshotRspDestroy(pSyncMsg);
|
syncSnapshotRspDestroy(pSyncMsg);
|
||||||
} else if (pMsg->msgType == TDMT_MND_SET_STANDBY) {
|
} else if (pMsg->msgType == TDMT_SYNC_SET_MNODE_STANDBY) {
|
||||||
code = syncSetStandby(pMgmt->sync);
|
code = syncSetStandby(pMgmt->sync);
|
||||||
SRpcMsg rsp = {.code = code, .info = pMsg->info};
|
SRpcMsg rsp = {.code = code, .info = pMsg->info};
|
||||||
tmsgSendRsp(&rsp);
|
tmsgSendRsp(&rsp);
|
||||||
|
@ -491,7 +486,7 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
||||||
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
||||||
code = syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg);
|
code = syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg);
|
||||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
syncAppendEntriesReplyDestroy(pSyncMsg);
|
||||||
} else if (pMsg->msgType == TDMT_MND_SET_STANDBY) {
|
} else if (pMsg->msgType == TDMT_SYNC_SET_MNODE_STANDBY) {
|
||||||
code = syncSetStandby(pMgmt->sync);
|
code = syncSetStandby(pMgmt->sync);
|
||||||
SRpcMsg rsp = {.code = code, .info = pMsg->info};
|
SRpcMsg rsp = {.code = code, .info = pMsg->info};
|
||||||
tmsgSendRsp(&rsp);
|
tmsgSendRsp(&rsp);
|
||||||
|
@ -501,7 +496,6 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mndReleaseSyncRef(pMnode);
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,24 +748,3 @@ void mndSetStop(SMnode *pMnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mndGetStop(SMnode *pMnode) { return pMnode->stopped; }
|
bool mndGetStop(SMnode *pMnode) { return pMnode->stopped; }
|
||||||
|
|
||||||
int32_t mndAcquireSyncRef(SMnode *pMnode) {
|
|
||||||
int32_t code = 0;
|
|
||||||
taosThreadRwlockRdlock(&pMnode->lock);
|
|
||||||
if (pMnode->stopped) {
|
|
||||||
terrno = TSDB_CODE_APP_NOT_READY;
|
|
||||||
code = -1;
|
|
||||||
} else {
|
|
||||||
int32_t ref = atomic_add_fetch_32(&pMnode->syncRef, 1);
|
|
||||||
// mTrace("mnode sync is acquired, ref:%d", ref);
|
|
||||||
}
|
|
||||||
taosThreadRwlockUnlock(&pMnode->lock);
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
void mndReleaseSyncRef(SMnode *pMnode) {
|
|
||||||
taosThreadRwlockRdlock(&pMnode->lock);
|
|
||||||
int32_t ref = atomic_sub_fetch_32(&pMnode->syncRef, 1);
|
|
||||||
// mTrace("mnode sync is released, ref:%d", ref);
|
|
||||||
taosThreadRwlockUnlock(&pMnode->lock);
|
|
||||||
}
|
|
||||||
|
|
|
@ -55,7 +55,8 @@ int32_t mndInitMnode(SMnode *pMnode) {
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_MNODE_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_MNODE_RSP, mndTransProcessRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_MNODE, mndProcessDropMnodeReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_DROP_MNODE, mndProcessDropMnodeReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_DND_DROP_MNODE_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_DND_DROP_MNODE_RSP, mndTransProcessRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_SET_STANDBY_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_SYNC_SET_MNODE_STANDBY_RSP, mndTransProcessRsp);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_SYNC_SET_VNODE_STANDBY_RSP, mndTransProcessRsp);
|
||||||
|
|
||||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_MNODE, mndRetrieveMnodes);
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_MNODE, mndRetrieveMnodes);
|
||||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_MNODE, mndCancelGetNextMnode);
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_MNODE, mndCancelGetNextMnode);
|
||||||
|
@ -511,7 +512,7 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode
|
||||||
.epSet = dropEpSet,
|
.epSet = dropEpSet,
|
||||||
.pCont = pReq,
|
.pCont = pReq,
|
||||||
.contLen = contLen,
|
.contLen = contLen,
|
||||||
.msgType = TDMT_MND_SET_STANDBY,
|
.msgType = TDMT_SYNC_SET_MNODE_STANDBY,
|
||||||
.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED,
|
.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,10 @@
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
#include "qworker.h"
|
#include "qworker.h"
|
||||||
|
|
||||||
int32_t mndPreprocessQueryMsg(SMnode * pMnode, SRpcMsg * pMsg) {
|
int32_t mndPreProcessMsg(SRpcMsg *pMsg) {
|
||||||
if (TDMT_VND_QUERY != pMsg->msgType) {
|
if (TDMT_VND_QUERY != pMsg->msgType) return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
SMnode *pMnode = pMsg->info.node;
|
||||||
return qWorkerPreprocessQueryMsg(pMnode->pQuery, pMsg);
|
return qWorkerPreprocessQueryMsg(pMnode->pQuery, pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,10 @@ static int32_t mndSmaActionInsert(SSdb *pSdb, SSmaObj *pSma);
|
||||||
static int32_t mndSmaActionDelete(SSdb *pSdb, SSmaObj *pSpSmatb);
|
static int32_t mndSmaActionDelete(SSdb *pSdb, SSmaObj *pSpSmatb);
|
||||||
static int32_t mndSmaActionUpdate(SSdb *pSdb, SSmaObj *pOld, SSmaObj *pNew);
|
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 mndSmaGetVgEpSet(SMnode *pMnode, SDbObj *pDb, SVgEpSet **ppVgEpSet, int32_t *numOfVgroups);
|
||||||
static int32_t mndProcessMCreateSmaReq(SRpcMsg *pReq);
|
static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq);
|
||||||
static int32_t mndProcessMDropSmaReq(SRpcMsg *pReq);
|
static int32_t mndProcessDropSmaReq(SRpcMsg *pReq);
|
||||||
static int32_t mndProcessGetSmaReq(SRpcMsg *pReq);
|
static int32_t mndProcessGetSmaReq(SRpcMsg *pReq);
|
||||||
static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq);
|
static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq);
|
||||||
static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||||
static void mndCancelGetNextSma(SMnode *pMnode, void *pIter);
|
static void mndCancelGetNextSma(SMnode *pMnode, void *pIter);
|
||||||
|
|
||||||
|
@ -56,8 +56,8 @@ int32_t mndInitSma(SMnode *pMnode) {
|
||||||
.deleteFp = (SdbDeleteFp)mndSmaActionDelete,
|
.deleteFp = (SdbDeleteFp)mndSmaActionDelete,
|
||||||
};
|
};
|
||||||
|
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_SMA, mndProcessMCreateSmaReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_SMA, mndProcessCreateSmaReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_SMA, mndProcessMDropSmaReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_DROP_SMA, mndProcessDropSmaReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_CREATE_SMA_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_CREATE_SMA_RSP, mndTransProcessRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_DROP_SMA_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_DROP_SMA_RSP, mndTransProcessRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_GET_INDEX, mndProcessGetSmaReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_GET_INDEX, mndProcessGetSmaReq);
|
||||||
|
@ -79,7 +79,6 @@ static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) {
|
||||||
if (pRaw == NULL) goto _OVER;
|
if (pRaw == NULL) goto _OVER;
|
||||||
|
|
||||||
int32_t dataPos = 0;
|
int32_t dataPos = 0;
|
||||||
|
|
||||||
SDB_SET_BINARY(pRaw, dataPos, pSma->name, TSDB_TABLE_FNAME_LEN, _OVER)
|
SDB_SET_BINARY(pRaw, dataPos, pSma->name, TSDB_TABLE_FNAME_LEN, _OVER)
|
||||||
SDB_SET_BINARY(pRaw, dataPos, pSma->stb, TSDB_TABLE_FNAME_LEN, _OVER)
|
SDB_SET_BINARY(pRaw, dataPos, pSma->stb, TSDB_TABLE_FNAME_LEN, _OVER)
|
||||||
SDB_SET_BINARY(pRaw, dataPos, pSma->db, TSDB_DB_FNAME_LEN, _OVER)
|
SDB_SET_BINARY(pRaw, dataPos, pSma->db, TSDB_DB_FNAME_LEN, _OVER)
|
||||||
|
@ -100,6 +99,7 @@ static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) {
|
||||||
SDB_SET_INT32(pRaw, dataPos, pSma->tagsFilterLen, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pSma->tagsFilterLen, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pSma->sqlLen, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pSma->sqlLen, _OVER)
|
||||||
SDB_SET_INT32(pRaw, dataPos, pSma->astLen, _OVER)
|
SDB_SET_INT32(pRaw, dataPos, pSma->astLen, _OVER)
|
||||||
|
|
||||||
if (pSma->exprLen > 0) {
|
if (pSma->exprLen > 0) {
|
||||||
SDB_SET_BINARY(pRaw, dataPos, pSma->expr, pSma->exprLen, _OVER)
|
SDB_SET_BINARY(pRaw, dataPos, pSma->expr, pSma->exprLen, _OVER)
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,7 @@ static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) {
|
||||||
|
|
||||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_SMA_RESERVE_SIZE, _OVER)
|
SDB_SET_RESERVE(pRaw, dataPos, TSDB_SMA_RESERVE_SIZE, _OVER)
|
||||||
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
|
||||||
|
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
@ -193,6 +194,7 @@ static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SDB_GET_RESERVE(pRaw, dataPos, TSDB_SMA_RESERVE_SIZE, _OVER)
|
SDB_GET_RESERVE(pRaw, dataPos, TSDB_SMA_RESERVE_SIZE, _OVER)
|
||||||
|
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
@ -383,6 +385,25 @@ static int32_t mndSetCreateSmaVgroupCommitLogs(SMnode *pMnode, STrans *pTrans, S
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t mndSetUpdateSmaStbCommitLogs(SMnode *pMnode, STrans *pTrans, SStbObj *pStb) {
|
||||||
|
SStbObj stbObj = {0};
|
||||||
|
taosRLockLatch(&pStb->lock);
|
||||||
|
memcpy(&stbObj, pStb, sizeof(SStbObj));
|
||||||
|
taosRUnLockLatch(&pStb->lock);
|
||||||
|
stbObj.pColumns = NULL;
|
||||||
|
stbObj.pTags = NULL;
|
||||||
|
stbObj.updateTime = taosGetTimestampMs();
|
||||||
|
stbObj.lock = 0;
|
||||||
|
stbObj.smaVer++;
|
||||||
|
|
||||||
|
SSdbRaw *pCommitRaw = mndStbActionEncode(&stbObj);
|
||||||
|
if (pCommitRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t mndSetCreateSmaRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SSmaObj *pSma) {
|
static int32_t mndSetCreateSmaRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SSmaObj *pSma) {
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
SVgObj *pVgroup = NULL;
|
SVgObj *pVgroup = NULL;
|
||||||
|
@ -457,7 +478,6 @@ static int32_t mndSetCreateSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans,
|
||||||
pSma->schemaTag.pSchema[0].flags = 0;
|
pSma->schemaTag.pSchema[0].flags = 0;
|
||||||
snprintf(pSma->schemaTag.pSchema[0].name, TSDB_COL_NAME_LEN, "groupId");
|
snprintf(pSma->schemaTag.pSchema[0].name, TSDB_COL_NAME_LEN, "groupId");
|
||||||
|
|
||||||
|
|
||||||
int32_t smaContLen = 0;
|
int32_t smaContLen = 0;
|
||||||
void *pSmaReq = mndBuildVCreateSmaReq(pMnode, pVgroup, pSma, &smaContLen);
|
void *pSmaReq = mndBuildVCreateSmaReq(pMnode, pVgroup, pSma, &smaContLen);
|
||||||
if (pSmaReq == NULL) return -1;
|
if (pSmaReq == NULL) return -1;
|
||||||
|
@ -560,6 +580,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SRpcMsg *pReq, SMCreateSmaReq *pCrea
|
||||||
if (mndSetCreateSmaVgroupRedoLogs(pMnode, pTrans, &streamObj.fixedSinkVg) != 0) goto _OVER;
|
if (mndSetCreateSmaVgroupRedoLogs(pMnode, pTrans, &streamObj.fixedSinkVg) != 0) goto _OVER;
|
||||||
if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER;
|
if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER;
|
||||||
if (mndSetCreateSmaVgroupCommitLogs(pMnode, pTrans, &streamObj.fixedSinkVg) != 0) goto _OVER;
|
if (mndSetCreateSmaVgroupCommitLogs(pMnode, pTrans, &streamObj.fixedSinkVg) != 0) goto _OVER;
|
||||||
|
if (mndSetUpdateSmaStbCommitLogs(pMnode, pTrans, pStb) != 0) goto _OVER;
|
||||||
if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER;
|
if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER;
|
||||||
if (mndSetCreateSmaVgroupRedoActions(pMnode, pTrans, pDb, &streamObj.fixedSinkVg, &smaObj) != 0) goto _OVER;
|
if (mndSetCreateSmaVgroupRedoActions(pMnode, pTrans, pDb, &streamObj.fixedSinkVg, &smaObj) != 0) goto _OVER;
|
||||||
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, STREAM_TRIGGER_AT_ONCE, 0, pTrans) != 0) goto _OVER;
|
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, STREAM_TRIGGER_AT_ONCE, 0, pTrans) != 0) goto _OVER;
|
||||||
|
@ -600,7 +621,7 @@ static int32_t mndCheckCreateSmaReq(SMCreateSmaReq *pCreate) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessMCreateSmaReq(SRpcMsg *pReq) {
|
static int32_t mndProcessCreateSmaReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SStbObj *pStb = NULL;
|
SStbObj *pStb = NULL;
|
||||||
|
@ -782,13 +803,17 @@ static int32_t mndSetDropSmaVgroupRedoActions(SMnode *pMnode, STrans *pTrans, SD
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *pSma) {
|
static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *pSma) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SVgObj *pVgroup = NULL;
|
SVgObj *pVgroup = NULL;
|
||||||
STrans *pTrans = NULL;
|
SStbObj *pStb = NULL;
|
||||||
|
STrans *pTrans = NULL;
|
||||||
|
|
||||||
pVgroup = mndAcquireVgroup(pMnode, pSma->dstVgId);
|
pVgroup = mndAcquireVgroup(pMnode, pSma->dstVgId);
|
||||||
if (pVgroup == NULL) goto _OVER;
|
if (pVgroup == NULL) goto _OVER;
|
||||||
|
|
||||||
|
pStb = mndAcquireStb(pMnode, pSma->stb);
|
||||||
|
if (pStb == NULL) goto _OVER;
|
||||||
|
|
||||||
pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB, pReq);
|
pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_DB, pReq);
|
||||||
if (pTrans == NULL) goto _OVER;
|
if (pTrans == NULL) goto _OVER;
|
||||||
|
|
||||||
|
@ -799,6 +824,7 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p
|
||||||
if (mndSetDropSmaVgroupRedoLogs(pMnode, pTrans, pVgroup) != 0) goto _OVER;
|
if (mndSetDropSmaVgroupRedoLogs(pMnode, pTrans, pVgroup) != 0) goto _OVER;
|
||||||
if (mndSetDropSmaCommitLogs(pMnode, pTrans, pSma) != 0) goto _OVER;
|
if (mndSetDropSmaCommitLogs(pMnode, pTrans, pSma) != 0) goto _OVER;
|
||||||
if (mndSetDropSmaVgroupCommitLogs(pMnode, pTrans, pVgroup) != 0) goto _OVER;
|
if (mndSetDropSmaVgroupCommitLogs(pMnode, pTrans, pVgroup) != 0) goto _OVER;
|
||||||
|
if (mndSetUpdateSmaStbCommitLogs(pMnode, pTrans, pStb) != 0) goto _OVER;
|
||||||
if (mndSetDropSmaRedoActions(pMnode, pTrans, pDb, pSma) != 0) goto _OVER;
|
if (mndSetDropSmaRedoActions(pMnode, pTrans, pDb, pSma) != 0) goto _OVER;
|
||||||
if (mndSetDropSmaVgroupRedoActions(pMnode, pTrans, pDb, pVgroup) != 0) goto _OVER;
|
if (mndSetDropSmaVgroupRedoActions(pMnode, pTrans, pDb, pVgroup) != 0) goto _OVER;
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||||
|
@ -808,10 +834,78 @@ static int32_t mndDropSma(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SSmaObj *p
|
||||||
_OVER:
|
_OVER:
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
mndReleaseVgroup(pMnode, pVgroup);
|
mndReleaseVgroup(pMnode, pVgroup);
|
||||||
|
mndReleaseStb(pMnode, pStb);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessMDropSmaReq(SRpcMsg *pReq) {
|
int32_t mndDropSmasByStb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *pStb) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
SSmaObj *pSma = NULL;
|
||||||
|
void *pIter = NULL;
|
||||||
|
SVgObj *pVgroup = NULL;
|
||||||
|
int32_t code = -1;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
pIter = sdbFetch(pSdb, SDB_SMA, pIter, (void **)&pSma);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
if (pSma->stbUid == pStb->uid) {
|
||||||
|
pVgroup = mndAcquireVgroup(pMnode, pSma->dstVgId);
|
||||||
|
if (pVgroup == NULL) goto _OVER;
|
||||||
|
if (mndSetDropSmaVgroupCommitLogs(pMnode, pTrans, pVgroup) != 0) goto _OVER;
|
||||||
|
if (mndSetDropSmaVgroupRedoActions(pMnode, pTrans, pDb, pVgroup) != 0) goto _OVER;
|
||||||
|
if (mndSetDropSmaCommitLogs(pMnode, pTrans, pSma) != 0) goto _OVER;
|
||||||
|
if (mndSetDropSmaRedoActions(pMnode, pTrans, pDb, pSma) != 0) goto _OVER;
|
||||||
|
mndReleaseVgroup(pMnode, pVgroup);
|
||||||
|
pVgroup = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sdbRelease(pSdb, pSma);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
sdbCancelFetch(pSdb, pIter);
|
||||||
|
sdbRelease(pSdb, pSma);
|
||||||
|
mndReleaseVgroup(pMnode, pVgroup);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t mndDropSmasByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
SSmaObj *pSma = NULL;
|
||||||
|
void *pIter = NULL;
|
||||||
|
SVgObj *pVgroup = NULL;
|
||||||
|
int32_t code = -1;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
pIter = sdbFetch(pSdb, SDB_SMA, pIter, (void **)&pSma);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
if (pSma->dbUid == pDb->uid) {
|
||||||
|
pVgroup = mndAcquireVgroup(pMnode, pSma->dstVgId);
|
||||||
|
if (pVgroup == NULL) goto _OVER;
|
||||||
|
if (mndSetDropSmaVgroupCommitLogs(pMnode, pTrans, pVgroup) != 0) goto _OVER;
|
||||||
|
if (mndSetDropSmaVgroupRedoActions(pMnode, pTrans, pDb, pVgroup) != 0) goto _OVER;
|
||||||
|
if (mndSetDropSmaCommitLogs(pMnode, pTrans, pSma) != 0) goto _OVER;
|
||||||
|
mndReleaseVgroup(pMnode, pVgroup);
|
||||||
|
pVgroup = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sdbRelease(pSdb, pSma);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = 0;
|
||||||
|
|
||||||
|
_OVER:
|
||||||
|
sdbCancelFetch(pSdb, pIter);
|
||||||
|
sdbRelease(pSdb, pSma);
|
||||||
|
mndReleaseVgroup(pMnode, pVgroup);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessDropSmaReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SUserObj *pUser = NULL;
|
SUserObj *pUser = NULL;
|
||||||
|
@ -901,13 +995,13 @@ static int32_t mndGetSma(SMnode *pMnode, SUserIndexReq *indexReq, SUserIndexRsp
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool *exist) {
|
int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool *exist) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SSmaObj *pSma = NULL;
|
SSmaObj *pSma = NULL;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
STableIndexInfo info;
|
STableIndexInfo info;
|
||||||
|
|
||||||
SStbObj* pStb = mndAcquireStb(pMnode, tbFName);
|
SStbObj *pStb = mndAcquireStb(pMnode, tbFName);
|
||||||
if (NULL == pStb) {
|
if (NULL == pStb) {
|
||||||
*exist = false;
|
*exist = false;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -936,14 +1030,14 @@ int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool
|
||||||
info.dstTbUid = pSma->dstTbUid;
|
info.dstTbUid = pSma->dstTbUid;
|
||||||
info.dstVgId = pSma->dstVgId;
|
info.dstVgId = pSma->dstVgId;
|
||||||
|
|
||||||
SVgObj* pVg = mndAcquireVgroup(pMnode, pSma->dstVgId);
|
SVgObj *pVg = mndAcquireVgroup(pMnode, pSma->dstVgId);
|
||||||
if (pVg == NULL) {
|
if (pVg == NULL) {
|
||||||
code = -1;
|
code = -1;
|
||||||
sdbRelease(pSdb, pSma);
|
sdbRelease(pSdb, pSma);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
info.epSet = mndGetVgroupEpset(pMnode, pVg);
|
info.epSet = mndGetVgroupEpset(pMnode, pVg);
|
||||||
|
|
||||||
info.expr = taosMemoryMalloc(pSma->exprLen + 1);
|
info.expr = taosMemoryMalloc(pSma->exprLen + 1);
|
||||||
if (info.expr == NULL) {
|
if (info.expr == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -967,7 +1061,7 @@ int32_t mndGetTableSma(SMnode *pMnode, char *tbFName, STableIndexRsp *rsp, bool
|
||||||
|
|
||||||
sdbRelease(pSdb, pSma);
|
sdbRelease(pSdb, pSma);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1019,10 +1113,10 @@ _OVER:
|
||||||
|
|
||||||
static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) {
|
static int32_t mndProcessGetTbSmaReq(SRpcMsg *pReq) {
|
||||||
STableIndexReq indexReq = {0};
|
STableIndexReq indexReq = {0};
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
STableIndexRsp rsp = {0};
|
STableIndexRsp rsp = {0};
|
||||||
bool exist = false;
|
bool exist = false;
|
||||||
|
|
||||||
if (tDeserializeSTableIndexReq(pReq->pCont, pReq->contLen, &indexReq) != 0) {
|
if (tDeserializeSTableIndexReq(pReq->pCont, pReq->contLen, &indexReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
|
@ -1069,7 +1163,6 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
static int32_t mndRetrieveSma(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "mndPerfSchema.h"
|
#include "mndPerfSchema.h"
|
||||||
#include "mndScheduler.h"
|
#include "mndScheduler.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
|
#include "mndSma.h"
|
||||||
#include "mndTopic.h"
|
#include "mndTopic.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
#include "mndUser.h"
|
#include "mndUser.h"
|
||||||
|
@ -37,9 +38,9 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw);
|
||||||
static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb);
|
static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb);
|
||||||
static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb);
|
static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb);
|
||||||
static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew);
|
static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew);
|
||||||
static int32_t mndProcessMCreateStbReq(SRpcMsg *pReq);
|
static int32_t mndProcessCreateStbReq(SRpcMsg *pReq);
|
||||||
static int32_t mndProcessMAlterStbReq(SRpcMsg *pReq);
|
static int32_t mndProcessAlterStbReq(SRpcMsg *pReq);
|
||||||
static int32_t mndProcessMDropStbReq(SRpcMsg *pReq);
|
static int32_t mndProcessDropStbReq(SRpcMsg *pReq);
|
||||||
static int32_t mndProcessTableMetaReq(SRpcMsg *pReq);
|
static int32_t mndProcessTableMetaReq(SRpcMsg *pReq);
|
||||||
static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||||
static void mndCancelGetNextStb(SMnode *pMnode, void *pIter);
|
static void mndCancelGetNextStb(SMnode *pMnode, void *pIter);
|
||||||
|
@ -55,9 +56,9 @@ int32_t mndInitStb(SMnode *pMnode) {
|
||||||
.deleteFp = (SdbDeleteFp)mndStbActionDelete,
|
.deleteFp = (SdbDeleteFp)mndStbActionDelete,
|
||||||
};
|
};
|
||||||
|
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_STB, mndProcessMCreateStbReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_CREATE_STB, mndProcessCreateStbReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_STB, mndProcessMAlterStbReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_ALTER_STB, mndProcessAlterStbReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_DROP_STB, mndProcessMDropStbReq);
|
mndSetMsgHandle(pMnode, TDMT_MND_DROP_STB, mndProcessDropStbReq);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_CREATE_STB_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_CREATE_STB_RSP, mndTransProcessRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_ALTER_STB_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_ALTER_STB_RSP, mndTransProcessRsp);
|
||||||
mndSetMsgHandle(pMnode, TDMT_VND_DROP_STB_RSP, mndTransProcessRsp);
|
mndSetMsgHandle(pMnode, TDMT_VND_DROP_STB_RSP, mndTransProcessRsp);
|
||||||
|
@ -319,6 +320,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
|
||||||
pOld->updateTime = pNew->updateTime;
|
pOld->updateTime = pNew->updateTime;
|
||||||
pOld->tagVer = pNew->tagVer;
|
pOld->tagVer = pNew->tagVer;
|
||||||
pOld->colVer = pNew->colVer;
|
pOld->colVer = pNew->colVer;
|
||||||
|
pOld->smaVer = pNew->smaVer;
|
||||||
pOld->nextColId = pNew->nextColId;
|
pOld->nextColId = pNew->nextColId;
|
||||||
pOld->ttl = pNew->ttl;
|
pOld->ttl = pNew->ttl;
|
||||||
pOld->numOfColumns = pNew->numOfColumns;
|
pOld->numOfColumns = pNew->numOfColumns;
|
||||||
|
@ -362,7 +364,7 @@ SDbObj *mndAcquireDbByStb(SMnode *pMnode, const char *stbName) {
|
||||||
return mndAcquireDb(pMnode, db);
|
return mndAcquireDb(pMnode, db);
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int schemaExColIdCompare(const void *colId, const void *pSchema) {
|
static FORCE_INLINE int32_t schemaExColIdCompare(const void *colId, const void *pSchema) {
|
||||||
if (*(col_id_t *)colId < ((SSchema *)pSchema)->colId) {
|
if (*(col_id_t *)colId < ((SSchema *)pSchema)->colId) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (*(col_id_t *)colId > ((SSchema *)pSchema)->colId) {
|
} else if (*(col_id_t *)colId > ((SSchema *)pSchema)->colId) {
|
||||||
|
@ -396,14 +398,14 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
||||||
req.pRSmaParam.xFilesFactor = pStb->xFilesFactor;
|
req.pRSmaParam.xFilesFactor = pStb->xFilesFactor;
|
||||||
req.pRSmaParam.delay = pStb->delay;
|
req.pRSmaParam.delay = pStb->delay;
|
||||||
if (pStb->ast1Len > 0) {
|
if (pStb->ast1Len > 0) {
|
||||||
if (mndConvertRsmaTask(&req.pRSmaParam.qmsg1, &req.pRSmaParam.qmsg1Len, pStb->pAst1, pStb->uid, STREAM_TRIGGER_AT_ONCE, 0,
|
if (mndConvertRsmaTask(&req.pRSmaParam.qmsg1, &req.pRSmaParam.qmsg1Len, pStb->pAst1, pStb->uid,
|
||||||
req.pRSmaParam.xFilesFactor) != TSDB_CODE_SUCCESS) {
|
STREAM_TRIGGER_AT_ONCE, 0, req.pRSmaParam.xFilesFactor) != TSDB_CODE_SUCCESS) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pStb->ast2Len > 0) {
|
if (pStb->ast2Len > 0) {
|
||||||
if (mndConvertRsmaTask(&req.pRSmaParam.qmsg2, &req.pRSmaParam.qmsg2Len, pStb->pAst2, pStb->uid, STREAM_TRIGGER_AT_ONCE, 0,
|
if (mndConvertRsmaTask(&req.pRSmaParam.qmsg2, &req.pRSmaParam.qmsg2Len, pStb->pAst2, pStb->uid,
|
||||||
req.pRSmaParam.xFilesFactor) != TSDB_CODE_SUCCESS) {
|
STREAM_TRIGGER_AT_ONCE, 0, req.pRSmaParam.xFilesFactor) != TSDB_CODE_SUCCESS) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -762,7 +764,7 @@ int32_t mndAddStbToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SStbObj *p
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessMCreateStbReq(SRpcMsg *pReq) {
|
static int32_t mndProcessCreateStbReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SStbObj *pStb = NULL;
|
SStbObj *pStb = NULL;
|
||||||
|
@ -1301,7 +1303,7 @@ static int32_t mndBuildStbSchema(SMnode *pMnode, const char *dbFName, const char
|
||||||
|
|
||||||
static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, const SMAlterStbReq *pAlter, SStbObj *pObj, void **pCont,
|
static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, const SMAlterStbReq *pAlter, SStbObj *pObj, void **pCont,
|
||||||
int32_t *pLen) {
|
int32_t *pLen) {
|
||||||
int ret;
|
int32_t ret;
|
||||||
SEncoder ec = {0};
|
SEncoder ec = {0};
|
||||||
uint32_t contLen = 0;
|
uint32_t contLen = 0;
|
||||||
SMAlterStbRsp alterRsp = {0};
|
SMAlterStbRsp alterRsp = {0};
|
||||||
|
@ -1420,7 +1422,7 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessMAlterStbReq(SRpcMsg *pReq) {
|
static int32_t mndProcessAlterStbReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SDbObj *pDb = NULL;
|
SDbObj *pDb = NULL;
|
||||||
|
@ -1550,6 +1552,7 @@ static int32_t mndDropStb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SStbObj *p
|
||||||
if (mndSetDropStbRedoLogs(pMnode, pTrans, pStb) != 0) goto _OVER;
|
if (mndSetDropStbRedoLogs(pMnode, pTrans, pStb) != 0) goto _OVER;
|
||||||
if (mndSetDropStbCommitLogs(pMnode, pTrans, pStb) != 0) goto _OVER;
|
if (mndSetDropStbCommitLogs(pMnode, pTrans, pStb) != 0) goto _OVER;
|
||||||
if (mndSetDropStbRedoActions(pMnode, pTrans, pDb, pStb) != 0) goto _OVER;
|
if (mndSetDropStbRedoActions(pMnode, pTrans, pDb, pStb) != 0) goto _OVER;
|
||||||
|
if (mndDropSmasByStb(pMnode, pTrans, pDb, pStb) != 0) goto _OVER;
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
@ -1559,7 +1562,7 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessMDropStbReq(SRpcMsg *pReq) {
|
static int32_t mndProcessDropStbReq(SRpcMsg *pReq) {
|
||||||
SMnode *pMnode = pReq->info.node;
|
SMnode *pMnode = pReq->info.node;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SUserObj *pUser = NULL;
|
SUserObj *pUser = NULL;
|
||||||
|
|
|
@ -322,6 +322,33 @@ void *mndBuildAlterVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_
|
||||||
return pReq;
|
return pReq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *mndBuildSetVnodeStandbyReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen) {
|
||||||
|
SSetStandbyReq standbyReq = {0};
|
||||||
|
standbyReq.dnodeId = pDnode->id;
|
||||||
|
standbyReq.standby = 1;
|
||||||
|
|
||||||
|
int32_t contLen = tSerializeSSetStandbyReq(NULL, 0, &standbyReq);
|
||||||
|
if (contLen < 0) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
contLen += sizeof(SMsgHead);
|
||||||
|
void *pReq = taosMemoryMalloc(contLen);
|
||||||
|
if (pReq == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
tSerializeSSetStandbyReq((char *)pReq + sizeof(SMsgHead), contLen, &standbyReq);
|
||||||
|
SMsgHead *pHead = pReq;
|
||||||
|
pHead->contLen = htonl(contLen);
|
||||||
|
pHead->vgId = htonl(pVgroup->vgId);
|
||||||
|
|
||||||
|
*pContLen = contLen;
|
||||||
|
return pReq;
|
||||||
|
}
|
||||||
|
|
||||||
void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen) {
|
void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgObj *pVgroup, int32_t *pContLen) {
|
||||||
SDropVnodeReq dropReq = {0};
|
SDropVnodeReq dropReq = {0};
|
||||||
dropReq.dnodeId = pDnode->id;
|
dropReq.dnodeId = pDnode->id;
|
||||||
|
@ -898,6 +925,39 @@ int32_t mndAddAlterVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgO
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t mndAddSetVnodeStandByAction(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 = mndBuildSetVnodeStandbyReq(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 mndAddDropVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid,
|
int32_t mndAddDropVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid,
|
||||||
bool isRedo) {
|
bool isRedo) {
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
|
@ -952,6 +1012,7 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb,
|
||||||
SVnodeGid del = newVg.vnodeGid[vnIndex];
|
SVnodeGid del = newVg.vnodeGid[vnIndex];
|
||||||
newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica];
|
newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica];
|
||||||
memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid));
|
memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid));
|
||||||
|
if (mndAddSetVnodeStandByAction(pMnode, pTrans, pDb, pVgroup, &del, true) != 0) return -1;
|
||||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
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 (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1;
|
||||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1;
|
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1;
|
||||||
|
@ -1031,6 +1092,7 @@ static int32_t mndAddDecVgroupReplicaFromTrans(SMnode *pMnode, STrans *pTrans, S
|
||||||
memcpy(pGid, &pVgroup->vnodeGid[pVgroup->replica], sizeof(SVnodeGid));
|
memcpy(pGid, &pVgroup->vnodeGid[pVgroup->replica], sizeof(SVnodeGid));
|
||||||
memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid));
|
memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid));
|
||||||
|
|
||||||
|
if (mndAddSetVnodeStandByAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1;
|
||||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, pVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
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 (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1;
|
||||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1;
|
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1;
|
||||||
|
@ -1341,12 +1403,14 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, S
|
||||||
|
|
||||||
SVnodeGid del1 = {0};
|
SVnodeGid del1 = {0};
|
||||||
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del1) != 0) return -1;
|
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del1) != 0) return -1;
|
||||||
|
if (mndAddSetVnodeStandByAction(pMnode, pTrans, pDb, pVgroup, &del1, true) != 0) return -1;
|
||||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
||||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVgroup, &del1, true) != 0) return -1;
|
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVgroup, &del1, true) != 0) return -1;
|
||||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVgroup) != 0) return -1;
|
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVgroup) != 0) return -1;
|
||||||
|
|
||||||
SVnodeGid del2 = {0};
|
SVnodeGid del2 = {0};
|
||||||
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del2) != 0) return -1;
|
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del2) != 0) return -1;
|
||||||
|
if (mndAddSetVnodeStandByAction(pMnode, pTrans, pDb, pVgroup, &del2, true) != 0) return -1;
|
||||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVgroup, TDMT_VND_ALTER_REPLICA) != 0) return -1;
|
||||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVgroup, &del2, true) != 0) return -1;
|
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVgroup, &del2, true) != 0) return -1;
|
||||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVgroup) != 0) return -1;
|
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVgroup) != 0) return -1;
|
||||||
|
@ -1396,6 +1460,7 @@ static int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj
|
||||||
} else if (newVg1.replica == 3) {
|
} else if (newVg1.replica == 3) {
|
||||||
SVnodeGid del1 = {0};
|
SVnodeGid del1 = {0};
|
||||||
if (mndRemoveVnodeFromVgroup(pMnode, &newVg1, pArray, &del1) != 0) goto _OVER;
|
if (mndRemoveVnodeFromVgroup(pMnode, &newVg1, pArray, &del1) != 0) goto _OVER;
|
||||||
|
if (mndAddSetVnodeStandByAction(pMnode, pTrans, pDb, pVgroup, &del1, true) != 0) return -1;
|
||||||
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg1, TDMT_VND_ALTER_REPLICA) != 0) goto _OVER;
|
if (mndAddAlterVnodeAction(pMnode, pTrans, pDb, &newVg1, TDMT_VND_ALTER_REPLICA) != 0) goto _OVER;
|
||||||
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg1, &del1, true) != 0) goto _OVER;
|
if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg1, &del1, true) != 0) goto _OVER;
|
||||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg1) != 0) goto _OVER;
|
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg1) != 0) goto _OVER;
|
||||||
|
|
|
@ -41,7 +41,6 @@ extern "C" {
|
||||||
#define tqTrace(...) do { if (tqDebugFlag & DEBUG_TRACE) { taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); }} while(0)
|
#define tqTrace(...) do { if (tqDebugFlag & DEBUG_TRACE) { taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); }} while(0)
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
typedef struct STqOffsetCfg STqOffsetCfg;
|
|
||||||
typedef struct STqOffsetStore STqOffsetStore;
|
typedef struct STqOffsetStore STqOffsetStore;
|
||||||
|
|
||||||
// tqRead
|
// tqRead
|
||||||
|
@ -127,14 +126,15 @@ typedef struct {
|
||||||
} STqHandle;
|
} STqHandle;
|
||||||
|
|
||||||
struct STQ {
|
struct STQ {
|
||||||
char* path;
|
char* path;
|
||||||
SHashObj* pushMgr; // consumerId -> STqHandle*
|
SHashObj* pushMgr; // consumerId -> STqHandle*
|
||||||
SHashObj* handles; // subKey -> STqHandle
|
SHashObj* handles; // subKey -> STqHandle
|
||||||
SHashObj* pStreamTasks; // taksId -> SStreamTask
|
SHashObj* pStreamTasks; // taksId -> SStreamTask
|
||||||
SVnode* pVnode;
|
STqOffsetStore* pOffsetStore;
|
||||||
SWal* pWal;
|
SVnode* pVnode;
|
||||||
TDB* pMetaStore;
|
SWal* pWal;
|
||||||
TTB* pExecStore;
|
TDB* pMetaStore;
|
||||||
|
TTB* pExecStore;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -157,17 +157,19 @@ int32_t tqMetaClose(STQ* pTq);
|
||||||
int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle);
|
int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle);
|
||||||
int32_t tqMetaDeleteHandle(STQ* pTq, const char* key);
|
int32_t tqMetaDeleteHandle(STQ* pTq, const char* key);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t size;
|
||||||
|
} STqOffsetHead;
|
||||||
|
|
||||||
|
STqOffsetStore* tqOffsetOpen();
|
||||||
|
void tqOffsetClose(STqOffsetStore*);
|
||||||
|
STqOffset* tqOffsetRead(STqOffsetStore* pStore, const char* subscribeKey);
|
||||||
|
int32_t tqOffsetWrite(STqOffsetStore* pStore, const STqOffset* pOffset);
|
||||||
|
int32_t tqOffsetSnapshot(STqOffsetStore* pStore);
|
||||||
|
|
||||||
// tqSink
|
// tqSink
|
||||||
void tqTableSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
void tqTableSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data);
|
||||||
|
|
||||||
// tqOffset
|
|
||||||
STqOffsetStore* tqOffsetOpen(STqOffsetCfg*);
|
|
||||||
void tqOffsetClose(STqOffsetStore*);
|
|
||||||
int64_t tqOffsetFetch(STqOffsetStore* pStore, const char* subscribeKey);
|
|
||||||
int32_t tqOffsetCommit(STqOffsetStore* pStore, const char* subscribeKey, int64_t offset);
|
|
||||||
int32_t tqOffsetPersist(STqOffsetStore* pStore, const char* subscribeKey);
|
|
||||||
int32_t tqOffsetPersistAll(STqOffsetStore* pStore);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -137,6 +137,7 @@ int tqCommit(STQ*);
|
||||||
int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd);
|
int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd);
|
||||||
int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen);
|
int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen);
|
||||||
int32_t tqProcessVgDeleteReq(STQ* pTq, char* msg, int32_t msgLen);
|
int32_t tqProcessVgDeleteReq(STQ* pTq, char* msg, int32_t msgLen);
|
||||||
|
int32_t tqProcessOffsetCommitReq(STQ* pTq, char* msg, int32_t msgLen);
|
||||||
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId);
|
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId);
|
||||||
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
|
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
|
||||||
int32_t tqProcessStreamTrigger(STQ* pTq, SSubmitReq* data);
|
int32_t tqProcessStreamTrigger(STQ* pTq, SSubmitReq* data);
|
||||||
|
|
|
@ -47,7 +47,7 @@ void tqCleanUp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal) {
|
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal) {
|
||||||
STQ* pTq = taosMemoryMalloc(sizeof(STQ));
|
STQ* pTq = taosMemoryCalloc(1, sizeof(STQ));
|
||||||
if (pTq == NULL) {
|
if (pTq == NULL) {
|
||||||
terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -66,19 +66,23 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal) {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tqOffsetOpen(pTq) < 0) {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
return pTq;
|
return pTq;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tqClose(STQ* pTq) {
|
void tqClose(STQ* pTq) {
|
||||||
if (pTq) {
|
if (pTq) {
|
||||||
taosMemoryFreeClear(pTq->path);
|
tqOffsetClose(pTq->pOffsetStore);
|
||||||
taosHashCleanup(pTq->handles);
|
taosHashCleanup(pTq->handles);
|
||||||
taosHashCleanup(pTq->pStreamTasks);
|
taosHashCleanup(pTq->pStreamTasks);
|
||||||
taosHashCleanup(pTq->pushMgr);
|
taosHashCleanup(pTq->pushMgr);
|
||||||
|
taosMemoryFree(pTq->path);
|
||||||
tqMetaClose(pTq);
|
tqMetaClose(pTq);
|
||||||
taosMemoryFree(pTq);
|
taosMemoryFree(pTq);
|
||||||
}
|
}
|
||||||
// TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tqSendPollRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataBlkRsp* pRsp) {
|
int32_t tqSendPollRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, const SMqDataBlkRsp* pRsp) {
|
||||||
|
@ -109,6 +113,33 @@ int32_t tqSendPollRsp(STQ* pTq, const SRpcMsg* pMsg, const SMqPollReq* pReq, con
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tqProcessOffsetCommitReq(STQ* pTq, char* msg, int32_t msgLen) {
|
||||||
|
STqOffset offset = {0};
|
||||||
|
SDecoder decoder;
|
||||||
|
tDecoderInit(&decoder, msg, msgLen);
|
||||||
|
if (tDecodeSTqOffset(&decoder, &offset) < 0) {
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
tDecoderClear(&decoder);
|
||||||
|
|
||||||
|
if (offset.type == TMQ_OFFSET__SNAPSHOT) {
|
||||||
|
tqDebug("receive offset commit msg to %s, offset(type:snapshot) uid: %ld, ts: %ld", offset.subKey, offset.uid,
|
||||||
|
offset.ts);
|
||||||
|
} else if (offset.type == TMQ_OFFSET__LOG) {
|
||||||
|
tqDebug("receive offset commit msg to %s, offset(type:log) version: %ld", offset.subKey, offset.version);
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tqOffsetWrite(pTq->pOffsetStore, &offset) < 0) {
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
||||||
SMqPollReq* pReq = pMsg->pCont;
|
SMqPollReq* pReq = pMsg->pCont;
|
||||||
int64_t consumerId = pReq->consumerId;
|
int64_t consumerId = pReq->consumerId;
|
||||||
|
|
|
@ -16,26 +16,128 @@
|
||||||
|
|
||||||
#include "tq.h"
|
#include "tq.h"
|
||||||
|
|
||||||
enum ETqOffsetPersist {
|
|
||||||
TQ_OFFSET_PERSIST__LAZY = 1,
|
|
||||||
TQ_OFFSET_PERSIST__EAGER,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct STqOffsetCfg {
|
|
||||||
int8_t persistPolicy;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct STqOffsetStore {
|
struct STqOffsetStore {
|
||||||
STqOffsetCfg cfg;
|
char* fname;
|
||||||
SHashObj* pHash; // SHashObj<subscribeKey, offset>
|
STQ* pTq;
|
||||||
|
SHashObj* pHash; // SHashObj<subscribeKey, offset>
|
||||||
};
|
};
|
||||||
|
|
||||||
STqOffsetStore* tqOffsetOpen(STqOffsetCfg* pCfg) {
|
static char* buildFileName(const char* path) {
|
||||||
STqOffsetStore* pStore = taosMemoryMalloc(sizeof(STqOffsetStore));
|
int32_t len = strlen(path);
|
||||||
|
char* fname = taosMemoryCalloc(1, len + 20);
|
||||||
|
snprintf(fname, len + 20, "%s/offset", path);
|
||||||
|
return fname;
|
||||||
|
}
|
||||||
|
|
||||||
|
STqOffsetStore* tqOffsetOpen(STQ* pTq) {
|
||||||
|
STqOffsetStore* pStore = taosMemoryCalloc(1, sizeof(STqOffsetStore));
|
||||||
if (pStore == NULL) {
|
if (pStore == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memcpy(&pStore->cfg, pCfg, sizeof(STqOffsetCfg));
|
pStore->pTq = pTq;
|
||||||
|
pTq->pOffsetStore = pStore;
|
||||||
|
|
||||||
pStore->pHash = taosHashInit(64, MurmurHash3_32, true, HASH_NO_LOCK);
|
pStore->pHash = taosHashInit(64, MurmurHash3_32, true, HASH_NO_LOCK);
|
||||||
|
if (pStore->pHash == NULL) {
|
||||||
|
if (pStore->pHash) taosHashCleanup(pStore->pHash);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
char* fname = buildFileName(pStore->pTq->path);
|
||||||
|
TdFilePtr pFile = taosOpenFile(fname, TD_FILE_READ);
|
||||||
|
if (pFile != NULL) {
|
||||||
|
STqOffsetHead head = {0};
|
||||||
|
int64_t code;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
if ((code = taosReadFile(pFile, &head, sizeof(STqOffsetHead))) != sizeof(STqOffsetHead)) {
|
||||||
|
if (code == 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
|
// TODO handle error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int32_t size = htonl(head.size);
|
||||||
|
void* memBuf = taosMemoryCalloc(1, size);
|
||||||
|
if ((code = taosReadFile(pFile, memBuf, size)) != size) {
|
||||||
|
ASSERT(0);
|
||||||
|
// TODO handle error
|
||||||
|
}
|
||||||
|
STqOffset offset;
|
||||||
|
SDecoder decoder;
|
||||||
|
tDecoderInit(&decoder, memBuf, size);
|
||||||
|
if (tDecodeSTqOffset(&decoder, &offset) < 0) {
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
tDecoderClear(&decoder);
|
||||||
|
if (taosHashPut(pStore->pHash, offset.subKey, strlen(offset.subKey), &offset, sizeof(STqOffset)) < 0) {
|
||||||
|
ASSERT(0);
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
taosMemoryFree(fname);
|
||||||
|
}
|
||||||
return pStore;
|
return pStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tqOffsetClose(STqOffsetStore* pStore) {
|
||||||
|
tqOffsetSnapshot(pStore);
|
||||||
|
taosHashCleanup(pStore->pHash);
|
||||||
|
}
|
||||||
|
|
||||||
|
STqOffset* tqOffsetRead(STqOffsetStore* pStore, const char* subscribeKey) {
|
||||||
|
return (STqOffset*)taosHashGet(pStore->pHash, subscribeKey, strlen(subscribeKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tqOffsetWrite(STqOffsetStore* pStore, const STqOffset* pOffset) {
|
||||||
|
return taosHashPut(pStore->pHash, pOffset->subKey, strlen(pOffset->subKey), pOffset, sizeof(STqOffset));
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tqOffsetSnapshot(STqOffsetStore* pStore) {
|
||||||
|
// open file
|
||||||
|
// TODO file name should be with a version
|
||||||
|
char* fname = buildFileName(pStore->pTq->path);
|
||||||
|
TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
|
if (pFile == NULL) {
|
||||||
|
ASSERT(0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
void* pIter = NULL;
|
||||||
|
while (1) {
|
||||||
|
pIter = taosHashIterate(pStore->pHash, pIter);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
STqOffset* pOffset = (STqOffset*)pIter;
|
||||||
|
int32_t bodyLen;
|
||||||
|
int32_t code;
|
||||||
|
tEncodeSize(tEncodeSTqOffset, pOffset, bodyLen, code);
|
||||||
|
ASSERT(code == 0);
|
||||||
|
if (code < 0) {
|
||||||
|
ASSERT(0);
|
||||||
|
taosHashCancelIterate(pStore->pHash, pIter);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t totLen = sizeof(STqOffsetHead) + bodyLen;
|
||||||
|
void* buf = taosMemoryCalloc(1, totLen);
|
||||||
|
void* abuf = POINTER_SHIFT(buf, sizeof(STqOffsetHead));
|
||||||
|
|
||||||
|
((STqOffsetHead*)buf)->size = htonl(bodyLen);
|
||||||
|
SEncoder encoder;
|
||||||
|
tEncoderInit(&encoder, abuf, bodyLen);
|
||||||
|
tEncodeSTqOffset(&encoder, pOffset);
|
||||||
|
// write file
|
||||||
|
int64_t writeLen;
|
||||||
|
if ((writeLen = taosWriteFile(pFile, buf, totLen)) != bodyLen) {
|
||||||
|
ASSERT(0);
|
||||||
|
tqError("write offset incomplete, len %d, write len %ld", bodyLen, writeLen);
|
||||||
|
taosHashCancelIterate(pStore->pHash, pIter);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// close and rename file
|
||||||
|
taosCloseFile(&pFile);
|
||||||
|
taosMemoryFree(fname);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -15,6 +15,177 @@
|
||||||
|
|
||||||
#include "tq.h"
|
#include "tq.h"
|
||||||
|
|
||||||
|
static SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema, bool createTb, int64_t suid,
|
||||||
|
const char* stbFullName, int32_t vgId);
|
||||||
|
|
||||||
|
static SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, bool createTb, int64_t suid,
|
||||||
|
const char* stbFullName, int32_t vgId) {
|
||||||
|
SSubmitReq* ret = NULL;
|
||||||
|
SArray* tagArray = taosArrayInit(1, sizeof(STagVal));
|
||||||
|
if (!tagArray) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// cal size
|
||||||
|
int32_t cap = sizeof(SSubmitReq);
|
||||||
|
int32_t sz = taosArrayGetSize(pBlocks);
|
||||||
|
for (int32_t i = 0; i < sz; i++) {
|
||||||
|
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||||
|
int32_t rows = pDataBlock->info.rows;
|
||||||
|
// TODO min
|
||||||
|
int32_t rowSize = pDataBlock->info.rowSize;
|
||||||
|
int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);
|
||||||
|
int32_t schemaLen = 0;
|
||||||
|
|
||||||
|
if (createTb) {
|
||||||
|
SVCreateTbReq createTbReq = {0};
|
||||||
|
char* cname = buildCtbNameByGroupId(stbFullName, pDataBlock->info.groupId);
|
||||||
|
createTbReq.name = cname;
|
||||||
|
createTbReq.flags = 0;
|
||||||
|
createTbReq.type = TSDB_CHILD_TABLE;
|
||||||
|
createTbReq.ctb.suid = suid;
|
||||||
|
|
||||||
|
STagVal tagVal = {
|
||||||
|
.cid = pDataBlock->info.numOfCols + 1,
|
||||||
|
.type = TSDB_DATA_TYPE_UBIGINT,
|
||||||
|
.i64 = (int64_t)pDataBlock->info.groupId,
|
||||||
|
};
|
||||||
|
STag* pTag = NULL;
|
||||||
|
taosArrayClear(tagArray);
|
||||||
|
taosArrayPush(tagArray, &tagVal);
|
||||||
|
tTagNew(tagArray, 1, false, &pTag);
|
||||||
|
if (pTag == NULL) {
|
||||||
|
tdDestroySVCreateTbReq(&createTbReq);
|
||||||
|
taosArrayDestroy(tagArray);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
createTbReq.ctb.pTag = (uint8_t*)pTag;
|
||||||
|
|
||||||
|
int32_t code;
|
||||||
|
tEncodeSize(tEncodeSVCreateTbReq, &createTbReq, schemaLen, code);
|
||||||
|
|
||||||
|
tdDestroySVCreateTbReq(&createTbReq);
|
||||||
|
if (code < 0) {
|
||||||
|
taosArrayDestroy(tagArray);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cap += sizeof(SSubmitBlk) + schemaLen + rows * maxLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
// assign data
|
||||||
|
// TODO
|
||||||
|
ret = rpcMallocCont(cap);
|
||||||
|
ret->header.vgId = vgId;
|
||||||
|
ret->version = htonl(1);
|
||||||
|
ret->length = sizeof(SSubmitReq);
|
||||||
|
ret->numOfBlocks = htonl(sz);
|
||||||
|
|
||||||
|
void* submitBlk = POINTER_SHIFT(ret, sizeof(SSubmitReq));
|
||||||
|
for (int32_t i = 0; i < sz; i++) {
|
||||||
|
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||||
|
|
||||||
|
SSubmitBlk* blkHead = submitBlk;
|
||||||
|
blkHead->numOfRows = htons(pDataBlock->info.rows);
|
||||||
|
blkHead->sversion = htonl(pTSchema->version);
|
||||||
|
// TODO
|
||||||
|
blkHead->suid = htobe64(suid);
|
||||||
|
// uid is assigned by vnode
|
||||||
|
blkHead->uid = 0;
|
||||||
|
|
||||||
|
int32_t rows = pDataBlock->info.rows;
|
||||||
|
/*int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);*/
|
||||||
|
/*blkHead->dataLen = htonl(rows * maxLen);*/
|
||||||
|
blkHead->dataLen = 0;
|
||||||
|
|
||||||
|
void* blockData = POINTER_SHIFT(submitBlk, sizeof(SSubmitBlk));
|
||||||
|
|
||||||
|
int32_t schemaLen = 0;
|
||||||
|
if (createTb) {
|
||||||
|
SVCreateTbReq createTbReq = {0};
|
||||||
|
char* cname = buildCtbNameByGroupId(stbFullName, pDataBlock->info.groupId);
|
||||||
|
createTbReq.name = cname;
|
||||||
|
createTbReq.flags = 0;
|
||||||
|
createTbReq.type = TSDB_CHILD_TABLE;
|
||||||
|
createTbReq.ctb.suid = suid;
|
||||||
|
|
||||||
|
STagVal tagVal = {
|
||||||
|
.cid = pDataBlock->info.numOfCols + 1,
|
||||||
|
.type = TSDB_DATA_TYPE_UBIGINT,
|
||||||
|
.i64 = (int64_t)pDataBlock->info.groupId,
|
||||||
|
};
|
||||||
|
taosArrayClear(tagArray);
|
||||||
|
taosArrayPush(tagArray, &tagVal);
|
||||||
|
STag* pTag = NULL;
|
||||||
|
tTagNew(tagArray, 1, false, &pTag);
|
||||||
|
if (pTag == NULL) {
|
||||||
|
tdDestroySVCreateTbReq(&createTbReq);
|
||||||
|
taosArrayDestroy(tagArray);
|
||||||
|
taosMemoryFreeClear(ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
createTbReq.ctb.pTag = (uint8_t*)pTag;
|
||||||
|
|
||||||
|
int32_t code;
|
||||||
|
tEncodeSize(tEncodeSVCreateTbReq, &createTbReq, schemaLen, code);
|
||||||
|
if (code < 0) {
|
||||||
|
tdDestroySVCreateTbReq(&createTbReq);
|
||||||
|
taosArrayDestroy(tagArray);
|
||||||
|
taosMemoryFreeClear(ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SEncoder encoder = {0};
|
||||||
|
tEncoderInit(&encoder, blockData, schemaLen);
|
||||||
|
code = tEncodeSVCreateTbReq(&encoder, &createTbReq);
|
||||||
|
tEncoderClear(&encoder);
|
||||||
|
tdDestroySVCreateTbReq(&createTbReq);
|
||||||
|
|
||||||
|
if (code < 0) {
|
||||||
|
taosArrayDestroy(tagArray);
|
||||||
|
taosMemoryFreeClear(ret);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
blkHead->schemaLen = htonl(schemaLen);
|
||||||
|
|
||||||
|
STSRow* rowData = POINTER_SHIFT(blockData, schemaLen);
|
||||||
|
|
||||||
|
for (int32_t j = 0; j < rows; j++) {
|
||||||
|
SRowBuilder rb = {0};
|
||||||
|
tdSRowInit(&rb, pTSchema->version);
|
||||||
|
tdSRowSetTpInfo(&rb, pTSchema->numOfCols, pTSchema->flen);
|
||||||
|
tdSRowResetBuf(&rb, rowData);
|
||||||
|
|
||||||
|
for (int32_t k = 0; k < pTSchema->numOfCols; k++) {
|
||||||
|
const STColumn* pColumn = &pTSchema->columns[k];
|
||||||
|
SColumnInfoData* pColData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||||
|
if (colDataIsNull_s(pColData, j)) {
|
||||||
|
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NONE, NULL, false, pColumn->offset, k);
|
||||||
|
} else {
|
||||||
|
void* data = colDataGetData(pColData, j);
|
||||||
|
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, pColumn->offset, k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int32_t rowLen = TD_ROW_LEN(rowData);
|
||||||
|
rowData = POINTER_SHIFT(rowData, rowLen);
|
||||||
|
blkHead->dataLen += rowLen;
|
||||||
|
}
|
||||||
|
int32_t dataLen = blkHead->dataLen;
|
||||||
|
blkHead->dataLen = htonl(dataLen);
|
||||||
|
|
||||||
|
ret->length += sizeof(SSubmitBlk) + schemaLen + dataLen;
|
||||||
|
blkHead = POINTER_SHIFT(blkHead, schemaLen + dataLen);
|
||||||
|
/*submitBlk = blkHead;*/
|
||||||
|
}
|
||||||
|
|
||||||
|
ret->length = htonl(ret->length);
|
||||||
|
taosArrayDestroy(tagArray);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void tqTableSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
|
void tqTableSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data) {
|
||||||
const SArray* pRes = (const SArray*)data;
|
const SArray* pRes = (const SArray*)data;
|
||||||
SVnode* pVnode = (SVnode*)vnode;
|
SVnode* pVnode = (SVnode*)vnode;
|
||||||
|
|
|
@ -148,17 +148,24 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp
|
||||||
case TDMT_VND_MQ_VG_CHANGE:
|
case TDMT_VND_MQ_VG_CHANGE:
|
||||||
if (tqProcessVgChangeReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
if (tqProcessVgChangeReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
||||||
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
||||||
// TODO: handle error
|
goto _err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TDMT_VND_MQ_VG_DELETE:
|
case TDMT_VND_MQ_VG_DELETE:
|
||||||
if (tqProcessVgDeleteReq(pVnode->pTq, pMsg->pCont, pMsg->contLen) < 0) {
|
if (tqProcessVgDeleteReq(pVnode->pTq, pMsg->pCont, pMsg->contLen) < 0) {
|
||||||
// TODO: handle error
|
goto _err;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TDMT_VND_MQ_COMMIT_OFFSET:
|
||||||
|
if (tqProcessOffsetCommitReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
||||||
|
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
||||||
|
goto _err;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TDMT_STREAM_TASK_DEPLOY: {
|
case TDMT_STREAM_TASK_DEPLOY: {
|
||||||
if (tqProcessTaskDeploy(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
if (tqProcessTaskDeploy(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
|
||||||
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
pMsg->contLen - sizeof(SMsgHead)) < 0) {
|
||||||
|
goto _err;
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case TDMT_VND_ALTER_CONFIRM:
|
case TDMT_VND_ALTER_CONFIRM:
|
||||||
|
@ -368,6 +375,10 @@ int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
ret = syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg);
|
ret = syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg);
|
||||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
syncAppendEntriesReplyDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_SET_MNODE_STANDBY) {
|
||||||
|
ret = syncSetStandby(pVnode->sync);
|
||||||
|
SRpcMsg rsp = {.code = ret, .info = pMsg->info};
|
||||||
|
tmsgSendRsp(&rsp);
|
||||||
} else {
|
} else {
|
||||||
vError("==vnodeProcessSyncReq== error msg type:%d", pRpcMsg->msgType);
|
vError("==vnodeProcessSyncReq== error msg type:%d", pRpcMsg->msgType);
|
||||||
ret = TAOS_SYNC_OTHER_ERROR;
|
ret = TAOS_SYNC_OTHER_ERROR;
|
||||||
|
@ -901,8 +912,8 @@ static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void
|
||||||
static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||||
vInfo("vgId:%d, alter hashrange msg will be processed", TD_VID(pVnode));
|
vInfo("vgId:%d, alter hashrange msg will be processed", TD_VID(pVnode));
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
// 1. stop work
|
// 1. stop work
|
||||||
// 2. adjust hash range / compact / remove wals / rename vgroups
|
// 2. adjust hash range / compact / remove wals / rename vgroups
|
||||||
// 3. reload sync
|
// 3. reload sync
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -27,10 +27,7 @@ typedef struct {
|
||||||
int32_t bytes;
|
int32_t bytes;
|
||||||
} SGroupKeys, SStateKeys;
|
} SGroupKeys, SStateKeys;
|
||||||
|
|
||||||
int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** keyBuf, const SArray* pGroupColList);
|
|
||||||
uint64_t calcGroupId(char* pData, int32_t len);
|
uint64_t calcGroupId(char* pData, int32_t len);
|
||||||
void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlock* pBlock, int32_t rowIndex);
|
|
||||||
int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals);
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -336,12 +336,6 @@ typedef struct STableScanInfo {
|
||||||
int32_t dataBlockLoadFlag;
|
int32_t dataBlockLoadFlag;
|
||||||
SInterval interval; // if the upstream is an interval operator, the interval info is also kept here to get the time window to check if current data block needs to be loaded.
|
SInterval interval; // if the upstream is an interval operator, the interval info is also kept here to get the time window to check if current data block needs to be loaded.
|
||||||
|
|
||||||
SArray* pGroupCols;
|
|
||||||
SArray* pGroupColVals; // current group column values, SArray<SGroupKeys>
|
|
||||||
char* keyBuf; // group by keys for hash
|
|
||||||
int32_t groupKeyLen; // total group by column width
|
|
||||||
SHashObj* pGroupSet; // quick locate the window object for each result
|
|
||||||
|
|
||||||
SSampleExecInfo sample; // sample execution info
|
SSampleExecInfo sample; // sample execution info
|
||||||
int32_t curTWinIdx;
|
int32_t curTWinIdx;
|
||||||
} STableScanInfo;
|
} STableScanInfo;
|
||||||
|
@ -789,7 +783,7 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
|
||||||
|
|
||||||
SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode* pExNode, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode* pExNode, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, tsdbReaderT pDataReader, SReadHandle* pHandle, SArray* groupKyes, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, tsdbReaderT pDataReader, SReadHandle* pHandle, SExecTaskInfo* pTaskInfo);
|
||||||
SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pPhyNode,
|
SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* pPhyNode,
|
||||||
STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
|
STableListInfo* pTableListInfo, SExecTaskInfo* pTaskInfo);
|
||||||
SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode *pScanPhyNode, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode *pScanPhyNode, SExecTaskInfo* pTaskInfo);
|
||||||
|
@ -827,7 +821,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx
|
||||||
SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo);
|
SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo);
|
||||||
SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo);
|
SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHandle, SArray* pTableIdList,
|
SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHandle,
|
||||||
STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo, STimeWindowAggSupp* pTwSup);
|
STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo, STimeWindowAggSupp* pTwSup);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4558,7 +4558,6 @@ static tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SRead
|
||||||
|
|
||||||
static int32_t getTableList(void* metaHandle, int32_t tableType, uint64_t tableUid, STableListInfo* pListInfo,
|
static int32_t getTableList(void* metaHandle, int32_t tableType, uint64_t tableUid, STableListInfo* pListInfo,
|
||||||
SNode* pTagCond);
|
SNode* pTagCond);
|
||||||
static SArray* extractTableIdList(const STableListInfo* pTableGroupInfo);
|
|
||||||
static SArray* extractColumnInfo(SNodeList* pNodeList);
|
static SArray* extractColumnInfo(SNodeList* pNodeList);
|
||||||
|
|
||||||
static SArray* createSortInfo(SNodeList* pNodeList);
|
static SArray* createSortInfo(SNodeList* pNodeList);
|
||||||
|
@ -4592,6 +4591,85 @@ int32_t extractTableSchemaVersion(SReadHandle* pHandle, uint64_t uid, SExecTaskI
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, SArray* groupKey){
|
||||||
|
if(groupKey == NULL) {
|
||||||
|
return TDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
pTableListInfo->map = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK);
|
||||||
|
if (pTableListInfo->map == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
int32_t keyLen = 0;
|
||||||
|
void *keyBuf = NULL;
|
||||||
|
int32_t numOfGroupCols = taosArrayGetSize(groupKey);
|
||||||
|
for (int32_t j = 0; j < numOfGroupCols; ++j) {
|
||||||
|
SColumn* pCol = taosArrayGet(groupKey, j);
|
||||||
|
keyLen += pCol->bytes; // actual data + null_flag
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t nullFlagSize = sizeof(int8_t) * numOfGroupCols;
|
||||||
|
keyLen += nullFlagSize;
|
||||||
|
|
||||||
|
keyBuf = taosMemoryCalloc(1, keyLen);
|
||||||
|
if (keyBuf == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int32_t i = 0; i < taosArrayGetSize(pTableListInfo->pTableList); i++){
|
||||||
|
STableKeyInfo *info = taosArrayGet(pTableListInfo->pTableList, i);
|
||||||
|
SMetaReader mr = {0};
|
||||||
|
metaReaderInit(&mr, pHandle->meta, 0);
|
||||||
|
metaGetTableEntryByUid(&mr, info->uid);
|
||||||
|
|
||||||
|
char* isNull = (char*)keyBuf;
|
||||||
|
char* pStart = (char*)keyBuf + sizeof(int8_t) * numOfGroupCols;
|
||||||
|
for (int32_t j = 0; j < numOfGroupCols; ++j) {
|
||||||
|
SColumn* pCol = taosArrayGet(groupKey, j);
|
||||||
|
|
||||||
|
if(strcmp(pCol->name, "tbname") == 0){
|
||||||
|
isNull[i] = 0;
|
||||||
|
memcpy(pStart, mr.me.name, strlen(mr.me.name));
|
||||||
|
pStart += strlen(mr.me.name);
|
||||||
|
}else{
|
||||||
|
STagVal tagVal = {0};
|
||||||
|
tagVal.cid = pCol->colId;
|
||||||
|
const char* p = metaGetTableTagVal(&mr.me, pCol->type, &tagVal);
|
||||||
|
if(p == NULL){
|
||||||
|
isNull[j] = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
isNull[i] = 0;
|
||||||
|
if (pCol->type == TSDB_DATA_TYPE_JSON) {
|
||||||
|
// int32_t dataLen = getJsonValueLen(pkey->pData);
|
||||||
|
// memcpy(pStart, (pkey->pData), dataLen);
|
||||||
|
// pStart += dataLen;
|
||||||
|
} else if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||||
|
memcpy(pStart, tagVal.pData, tagVal.nData);
|
||||||
|
pStart += tagVal.nData;
|
||||||
|
ASSERT(tagVal.nData <= pCol->bytes);
|
||||||
|
} else {
|
||||||
|
memcpy(pStart, &(tagVal.i64), pCol->bytes);
|
||||||
|
pStart += pCol->bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t len = (int32_t) (pStart - (char*)keyBuf);
|
||||||
|
uint64_t* groupId = taosHashGet(pTableListInfo->map, keyBuf, len);
|
||||||
|
if (groupId) {
|
||||||
|
taosHashPut(pTableListInfo->map, &(info->uid), sizeof(uint64_t), groupId, sizeof(uint64_t));
|
||||||
|
} else {
|
||||||
|
uint64_t tmpId = calcGroupId(keyBuf, len);
|
||||||
|
taosHashPut(pTableListInfo->map, &(info->uid), sizeof(uint64_t), &tmpId, sizeof(uint64_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
metaReaderClear(&mr);
|
||||||
|
}
|
||||||
|
taosMemoryFree(keyBuf);
|
||||||
|
return TDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle,
|
SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle,
|
||||||
uint64_t queryId, uint64_t taskId, STableListInfo* pTableListInfo, SNode* pTagCond) {
|
uint64_t queryId, uint64_t taskId, STableListInfo* pTableListInfo, SNode* pTagCond) {
|
||||||
int32_t type = nodeType(pPhyNode);
|
int32_t type = nodeType(pPhyNode);
|
||||||
|
@ -4605,15 +4683,23 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
if (pDataReader == NULL && terrno != 0) {
|
if (pDataReader == NULL && terrno != 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
SArray* groupKyes = extractPartitionColInfo(pTableScanNode->pPartitionKeys);
|
|
||||||
int32_t code = extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo);
|
int32_t code = extractTableSchemaVersion(pHandle, pTableScanNode->scan.uid, pTaskInfo);
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbCleanupReadHandle(pDataReader);
|
tsdbCleanupReadHandle(pDataReader);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SArray* groupKeys = extractPartitionColInfo(pTableScanNode->pPartitionKeys);
|
||||||
|
code = generateGroupIdMap(pTableListInfo, pHandle, groupKeys); //todo for json
|
||||||
|
taosArrayDestroy(groupKeys);
|
||||||
|
if (code){
|
||||||
|
tsdbCleanupReadHandle(pDataReader);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SOperatorInfo* pOperator =
|
SOperatorInfo* pOperator =
|
||||||
createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, groupKyes, pTaskInfo);
|
createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, pTaskInfo);
|
||||||
|
|
||||||
STableScanInfo* pScanInfo = pOperator->info;
|
STableScanInfo* pScanInfo = pOperator->info;
|
||||||
pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder;
|
pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder;
|
||||||
|
@ -4639,12 +4725,18 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
} else {
|
} else {
|
||||||
qDebug("%s pDataReader is not NULL", GET_TASKID(pTaskInfo));
|
qDebug("%s pDataReader is not NULL", GET_TASKID(pTaskInfo));
|
||||||
}
|
}
|
||||||
SArray* tableIdList = extractTableIdList(pTableListInfo);
|
|
||||||
|
SArray* groupKeys = extractPartitionColInfo(pTableScanNode->pPartitionKeys);
|
||||||
|
int32_t code = generateGroupIdMap(pTableListInfo, pHandle, groupKeys); //todo for json
|
||||||
|
taosArrayDestroy(groupKeys);
|
||||||
|
if (code){
|
||||||
|
tsdbCleanupReadHandle(pDataReader);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SOperatorInfo* pOperator =
|
SOperatorInfo* pOperator =
|
||||||
createStreamScanOperatorInfo(pDataReader, pHandle, tableIdList, pTableScanNode, pTaskInfo, &twSup);
|
createStreamScanOperatorInfo(pDataReader, pHandle, pTableScanNode, pTaskInfo, &twSup);
|
||||||
|
|
||||||
taosArrayDestroy(tableIdList);
|
|
||||||
return pOperator;
|
return pOperator;
|
||||||
} else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == type) {
|
} else if (QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == type) {
|
||||||
SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode;
|
SSystemTableScanPhysiNode* pSysScanPhyNode = (SSystemTableScanPhysiNode*)pPhyNode;
|
||||||
|
@ -4969,6 +5061,7 @@ SArray* extractColumnInfo(SNodeList* pNodeList) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* extractPartitionColInfo(SNodeList* pNodeList) {
|
SArray* extractPartitionColInfo(SNodeList* pNodeList) {
|
||||||
|
if(!pNodeList) return NULL;
|
||||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||||
SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn));
|
SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn));
|
||||||
if (pList == NULL) {
|
if (pList == NULL) {
|
||||||
|
@ -5073,7 +5166,9 @@ int32_t getTableList(void* metaHandle, int32_t tableType, uint64_t tableUid, STa
|
||||||
|
|
||||||
SArray* res = taosArrayInit(8, sizeof(uint64_t));
|
SArray* res = taosArrayInit(8, sizeof(uint64_t));
|
||||||
code = doFilterTag(pTagCond, &metaArg, res);
|
code = doFilterTag(pTagCond, &metaArg, res);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_INDEX_REBUILDING){ // todo
|
||||||
|
// doFilter();
|
||||||
|
} else if (code != TSDB_CODE_SUCCESS) {
|
||||||
qError("failed to get tableIds, reason: %s, suid: %" PRIu64 "", tstrerror(code), tableUid);
|
qError("failed to get tableIds, reason: %s, suid: %" PRIu64 "", tstrerror(code), tableUid);
|
||||||
taosArrayDestroy(res);
|
taosArrayDestroy(res);
|
||||||
terrno = code;
|
terrno = code;
|
||||||
|
@ -5081,6 +5176,7 @@ int32_t getTableList(void* metaHandle, int32_t tableType, uint64_t tableUid, STa
|
||||||
} else {
|
} else {
|
||||||
qDebug("sucess to get tableIds, size: %d, suid: %" PRIu64 "", (int)taosArrayGetSize(res), tableUid);
|
qDebug("sucess to get tableIds, size: %d, suid: %" PRIu64 "", (int)taosArrayGetSize(res), tableUid);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < taosArrayGetSize(res); i++) {
|
for (int i = 0; i < taosArrayGetSize(res); i++) {
|
||||||
STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, .uid = *(uint64_t*)taosArrayGet(res, i)};
|
STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, .uid = *(uint64_t*)taosArrayGet(res, i)};
|
||||||
taosArrayPush(pListInfo->pTableList, &info);
|
taosArrayPush(pListInfo->pTableList, &info);
|
||||||
|
@ -5097,18 +5193,6 @@ int32_t getTableList(void* metaHandle, int32_t tableType, uint64_t tableUid, STa
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* extractTableIdList(const STableListInfo* pTableGroupInfo) {
|
|
||||||
SArray* tableIdList = taosArrayInit(4, sizeof(uint64_t));
|
|
||||||
|
|
||||||
// Transfer the Array of STableKeyInfo into uid list.
|
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(pTableGroupInfo->pTableList); ++i) {
|
|
||||||
STableKeyInfo* pkeyInfo = taosArrayGet(pTableGroupInfo->pTableList, i);
|
|
||||||
taosArrayPush(tableIdList, &pkeyInfo->uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
return tableIdList;
|
|
||||||
}
|
|
||||||
|
|
||||||
tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle,
|
tsdbReaderT doCreateDataReader(STableScanPhysiNode* pTableScanNode, SReadHandle* pHandle,
|
||||||
STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId, SNode* pTagCond) {
|
STableListInfo* pTableListInfo, uint64_t queryId, uint64_t taskId, SNode* pTagCond) {
|
||||||
int32_t code =
|
int32_t code =
|
||||||
|
|
|
@ -37,7 +37,7 @@ static void destroyGroupOperatorInfo(void* param, int32_t numOfOutput) {
|
||||||
taosArrayDestroy(pInfo->pGroupColVals);
|
taosArrayDestroy(pInfo->pGroupColVals);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** keyBuf, const SArray* pGroupColList) {
|
static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** keyBuf, const SArray* pGroupColList) {
|
||||||
*pGroupColVals = taosArrayInit(4, sizeof(SGroupKeys));
|
*pGroupColVals = taosArrayInit(4, sizeof(SGroupKeys));
|
||||||
if ((*pGroupColVals) == NULL) {
|
if ((*pGroupColVals) == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -118,7 +118,7 @@ static bool groupKeyCompare(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlo
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlock* pBlock, int32_t rowIndex) {
|
static void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlock* pBlock, int32_t rowIndex) {
|
||||||
SColumnDataAgg* pColAgg = NULL;
|
SColumnDataAgg* pColAgg = NULL;
|
||||||
|
|
||||||
size_t numOfGroupCols = taosArrayGetSize(pGroupCols);
|
size_t numOfGroupCols = taosArrayGetSize(pGroupCols);
|
||||||
|
@ -150,7 +150,7 @@ void recordNewGroupKeys(SArray* pGroupCols, SArray* pGroupColVals, SSDataBlock*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals) {
|
static int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals) {
|
||||||
ASSERT(pKey != NULL);
|
ASSERT(pKey != NULL);
|
||||||
size_t numOfGroupCols = taosArrayGetSize(pGroupColVals);
|
size_t numOfGroupCols = taosArrayGetSize(pGroupColVals);
|
||||||
|
|
||||||
|
|
|
@ -391,22 +391,16 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) {
|
||||||
longjmp(pOperator->pTaskInfo->env, code);
|
longjmp(pOperator->pTaskInfo->env, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
recordNewGroupKeys(pTableScanInfo->pGroupCols, pTableScanInfo->pGroupColVals, pBlock, 0);
|
|
||||||
int32_t len = buildGroupKeys(pTableScanInfo->keyBuf, pTableScanInfo->pGroupColVals);
|
|
||||||
|
|
||||||
uint64_t* groupId = taosHashGet(pTableScanInfo->pGroupSet, pTableScanInfo->keyBuf, len);
|
|
||||||
if (groupId) {
|
|
||||||
pBlock->info.groupId = *groupId;
|
|
||||||
} else if (len != 0) {
|
|
||||||
pBlock->info.groupId = calcGroupId(pTableScanInfo->keyBuf, len);
|
|
||||||
taosHashPut(pTableScanInfo->pGroupSet, pTableScanInfo->keyBuf, len, &pBlock->info.groupId, sizeof(uint64_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
// current block is filter out according to filter condition, continue load the next block
|
// current block is filter out according to filter condition, continue load the next block
|
||||||
if (status == FUNC_DATA_REQUIRED_FILTEROUT || pBlock->info.rows == 0) {
|
if (status == FUNC_DATA_REQUIRED_FILTEROUT || pBlock->info.rows == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t* groupId = taosHashGet(pOperator->pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t));
|
||||||
|
if (groupId) {
|
||||||
|
pBlock->info.groupId = *groupId;
|
||||||
|
}
|
||||||
|
|
||||||
pOperator->resultInfo.totalRows = pTableScanInfo->readRecorder.totalRows;
|
pOperator->resultInfo.totalRows = pTableScanInfo->readRecorder.totalRows;
|
||||||
pTableScanInfo->readRecorder.elapsedTime += (taosGetTimestampUs() - st) / 1000.0;
|
pTableScanInfo->readRecorder.elapsedTime += (taosGetTimestampUs() - st) / 1000.0;
|
||||||
|
|
||||||
|
@ -530,21 +524,13 @@ static void destroyTableScanOperatorInfo(void* param, int32_t numOfOutput) {
|
||||||
|
|
||||||
tsdbCleanupReadHandle(pTableScanInfo->dataReader);
|
tsdbCleanupReadHandle(pTableScanInfo->dataReader);
|
||||||
|
|
||||||
taosArrayDestroy(pTableScanInfo->pGroupCols);
|
|
||||||
for (int i = 0; i < taosArrayGetSize(pTableScanInfo->pGroupColVals); i++) {
|
|
||||||
SGroupKeys key = *(SGroupKeys*)taosArrayGet(pTableScanInfo->pGroupColVals, i);
|
|
||||||
taosMemoryFree(key.pData);
|
|
||||||
}
|
|
||||||
taosArrayDestroy(pTableScanInfo->pGroupColVals);
|
|
||||||
taosMemoryFree(pTableScanInfo->keyBuf);
|
|
||||||
taosHashCleanup(pTableScanInfo->pGroupSet);
|
|
||||||
if (pTableScanInfo->pColMatchInfo != NULL) {
|
if (pTableScanInfo->pColMatchInfo != NULL) {
|
||||||
taosArrayDestroy(pTableScanInfo->pColMatchInfo);
|
taosArrayDestroy(pTableScanInfo->pColMatchInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, tsdbReaderT pDataReader,
|
SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, tsdbReaderT pDataReader,
|
||||||
SReadHandle* readHandle, SArray* groupKyes, SExecTaskInfo* pTaskInfo) {
|
SReadHandle* readHandle, SExecTaskInfo* pTaskInfo) {
|
||||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
|
@ -591,18 +577,6 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
|
||||||
pOperator->numOfExprs = numOfCols;
|
pOperator->numOfExprs = numOfCols;
|
||||||
pOperator->pTaskInfo = pTaskInfo;
|
pOperator->pTaskInfo = pTaskInfo;
|
||||||
|
|
||||||
// for table group
|
|
||||||
pInfo->pGroupCols = groupKyes;
|
|
||||||
_hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY);
|
|
||||||
pInfo->pGroupSet = taosHashInit(100, hashFn, false, HASH_NO_LOCK);
|
|
||||||
if (pInfo->pGroupSet == NULL) {
|
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, groupKyes);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
goto _error;
|
|
||||||
}
|
|
||||||
|
|
||||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScan, NULL, NULL, destroyTableScanOperatorInfo,
|
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScan, NULL, NULL, destroyTableScanOperatorInfo,
|
||||||
NULL, NULL, getTableScannerExecInfo);
|
NULL, NULL, getTableScannerExecInfo);
|
||||||
|
|
||||||
|
@ -912,6 +886,11 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
|
||||||
pInfo->pRes->info.groupId = groupId;
|
pInfo->pRes->info.groupId = groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t* groupIdPre = taosHashGet(pOperator->pTaskInfo->tableqinfoList.map, &uid, sizeof(int64_t));
|
||||||
|
if (groupIdPre) {
|
||||||
|
pInfo->pRes->info.groupId = *groupIdPre;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(pInfo->pColMatchInfo); ++i) {
|
for (int32_t i = 0; i < taosArrayGetSize(pInfo->pColMatchInfo); ++i) {
|
||||||
SColMatchInfo* pColMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i);
|
SColMatchInfo* pColMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i);
|
||||||
if (!pColMatchInfo->output) {
|
if (!pColMatchInfo->output) {
|
||||||
|
@ -979,11 +958,24 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHandle, SArray* pTableIdList,
|
static SArray* extractTableIdList(const STableListInfo* pTableGroupInfo) {
|
||||||
|
SArray* tableIdList = taosArrayInit(4, sizeof(uint64_t));
|
||||||
|
|
||||||
|
// Transfer the Array of STableKeyInfo into uid list.
|
||||||
|
for (int32_t i = 0; i < taosArrayGetSize(pTableGroupInfo->pTableList); ++i) {
|
||||||
|
STableKeyInfo* pkeyInfo = taosArrayGet(pTableGroupInfo->pTableList, i);
|
||||||
|
taosArrayPush(tableIdList, &pkeyInfo->uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tableIdList;
|
||||||
|
}
|
||||||
|
|
||||||
|
SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHandle,
|
||||||
STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo,
|
STableScanPhysiNode* pTableScanNode, SExecTaskInfo* pTaskInfo,
|
||||||
STimeWindowAggSupp* pTwSup) {
|
STimeWindowAggSupp* pTwSup) {
|
||||||
SStreamBlockScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamBlockScanInfo));
|
SStreamBlockScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamBlockScanInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
|
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||||
goto _error;
|
goto _error;
|
||||||
|
@ -992,7 +984,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan
|
||||||
SScanPhysiNode* pScanPhyNode = &pTableScanNode->scan;
|
SScanPhysiNode* pScanPhyNode = &pTableScanNode->scan;
|
||||||
|
|
||||||
SDataBlockDescNode* pDescNode = pScanPhyNode->node.pOutputDataBlockDesc;
|
SDataBlockDescNode* pDescNode = pScanPhyNode->node.pOutputDataBlockDesc;
|
||||||
SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, NULL, pTaskInfo);
|
SOperatorInfo* pTableScanDummy = createTableScanOperatorInfo(pTableScanNode, pDataReader, pHandle, pTaskInfo);
|
||||||
|
|
||||||
STableScanInfo* pSTInfo = (STableScanInfo*)pTableScanDummy->info;
|
STableScanInfo* pSTInfo = (STableScanInfo*)pTableScanDummy->info;
|
||||||
|
|
||||||
|
@ -1014,10 +1006,13 @@ SOperatorInfo* createStreamScanOperatorInfo(void* pDataReader, SReadHandle* pHan
|
||||||
|
|
||||||
// set the extract column id to streamHandle
|
// set the extract column id to streamHandle
|
||||||
tqReadHandleSetColIdList((STqReadHandle*)pHandle->reader, pColIds);
|
tqReadHandleSetColIdList((STqReadHandle*)pHandle->reader, pColIds);
|
||||||
int32_t code = tqReadHandleSetTbUidList(pHandle->reader, pTableIdList);
|
SArray* tableIdList = extractTableIdList(&pTaskInfo->tableqinfoList);
|
||||||
|
int32_t code = tqReadHandleSetTbUidList(pHandle->reader, tableIdList);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
taosArrayDestroy(tableIdList);
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
taosArrayDestroy(tableIdList);
|
||||||
|
|
||||||
pInfo->pBlockLists = taosArrayInit(4, POINTER_BYTES);
|
pInfo->pBlockLists = taosArrayInit(4, POINTER_BYTES);
|
||||||
if (pInfo->pBlockLists == NULL) {
|
if (pInfo->pBlockLists == NULL) {
|
||||||
|
|
|
@ -55,16 +55,22 @@ int32_t maxCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
|
||||||
bool getAvgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
bool getAvgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
bool avgFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
bool avgFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||||
int32_t avgFunction(SqlFunctionCtx* pCtx);
|
int32_t avgFunction(SqlFunctionCtx* pCtx);
|
||||||
|
int32_t avgFunctionMerge(SqlFunctionCtx* pCtx);
|
||||||
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||||
|
int32_t avgPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||||
int32_t avgInvertFunction(SqlFunctionCtx* pCtx);
|
int32_t avgInvertFunction(SqlFunctionCtx* pCtx);
|
||||||
int32_t avgCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
|
int32_t avgCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
|
||||||
|
int32_t getAvgInfoSize();
|
||||||
|
|
||||||
bool getStddevFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
bool getStddevFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
bool stddevFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
bool stddevFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||||
int32_t stddevFunction(SqlFunctionCtx* pCtx);
|
int32_t stddevFunction(SqlFunctionCtx* pCtx);
|
||||||
|
int32_t stddevFunctionMerge(SqlFunctionCtx* pCtx);
|
||||||
int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||||
|
int32_t stddevPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||||
int32_t stddevInvertFunction(SqlFunctionCtx* pCtx);
|
int32_t stddevInvertFunction(SqlFunctionCtx* pCtx);
|
||||||
int32_t stddevCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
|
int32_t stddevCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
|
||||||
|
int32_t getStddevInfoSize();
|
||||||
|
|
||||||
bool getLeastSQRFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
bool getLeastSQRFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
bool leastSQRFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
bool leastSQRFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||||
|
|
|
@ -155,6 +155,64 @@ static int32_t translateSum(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t translateAvgPartial(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
if (1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||||
|
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||||
|
if (!IS_NUMERIC_TYPE(paraType) && !IS_NULL_TYPE(paraType)) {
|
||||||
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = getAvgInfoSize() + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY};
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateAvgMerge(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
if (1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||||
|
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||||
|
if (TSDB_DATA_TYPE_BINARY != paraType) {
|
||||||
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE};
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateStddevPartial(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
if (1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||||
|
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||||
|
if (!IS_NUMERIC_TYPE(paraType) && !IS_NULL_TYPE(paraType)) {
|
||||||
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = getStddevInfoSize() + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY};
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateStddevMerge(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
|
if (1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||||
|
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||||
|
if (TSDB_DATA_TYPE_BINARY != paraType) {
|
||||||
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE};
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t translateWduration(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
static int32_t translateWduration(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||||
// pseudo column do not need to check parameters
|
// pseudo column do not need to check parameters
|
||||||
pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT};
|
pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT};
|
||||||
|
@ -393,7 +451,8 @@ static int32_t translateTopBotImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
||||||
pValue->notReserved = true;
|
pValue->notReserved = true;
|
||||||
|
|
||||||
// set result type
|
// set result type
|
||||||
pFunc->node.resType = (SDataType){.bytes = getTopBotInfoSize(pValue->datum.i) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY};
|
pFunc->node.resType =
|
||||||
|
(SDataType){.bytes = getTopBotInfoSize(pValue->datum.i) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY};
|
||||||
} else {
|
} else {
|
||||||
if (1 != numOfParams) {
|
if (1 != numOfParams) {
|
||||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
@ -956,11 +1015,11 @@ static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
||||||
|
|
||||||
static int32_t translateFirstLastImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isPartial) {
|
static int32_t translateFirstLastImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isPartial) {
|
||||||
// first(col_list) will be rewritten as first(col)
|
// first(col_list) will be rewritten as first(col)
|
||||||
if (2 != LIST_LENGTH(pFunc->pParameterList)) { //input has two params c0,ts, is this a bug?
|
if (2 != LIST_LENGTH(pFunc->pParameterList)) { // input has two params c0,ts, is this a bug?
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
||||||
uint8_t paraType = ((SExprNode*)pPara)->resType.type;
|
uint8_t paraType = ((SExprNode*)pPara)->resType.type;
|
||||||
int32_t paraBytes = ((SExprNode*)pPara)->resType.bytes;
|
int32_t paraBytes = ((SExprNode*)pPara)->resType.bytes;
|
||||||
if (isPartial) {
|
if (isPartial) {
|
||||||
|
@ -969,8 +1028,8 @@ static int32_t translateFirstLastImpl(SFunctionNode* pFunc, char* pErrBuf, int32
|
||||||
"The parameters of first/last can only be columns");
|
"The parameters of first/last can only be columns");
|
||||||
}
|
}
|
||||||
|
|
||||||
pFunc->node.resType = (SDataType){.bytes = getFirstLastInfoSize(paraBytes) + VARSTR_HEADER_SIZE,
|
pFunc->node.resType =
|
||||||
.type = TSDB_DATA_TYPE_BINARY};
|
(SDataType){.bytes = getFirstLastInfoSize(paraBytes) + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY};
|
||||||
} else {
|
} else {
|
||||||
if (TSDB_DATA_TYPE_BINARY != paraType) {
|
if (TSDB_DATA_TYPE_BINARY != paraType) {
|
||||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||||
|
@ -1493,6 +1552,32 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.finalizeFunc = stddevFinalize,
|
.finalizeFunc = stddevFinalize,
|
||||||
.invertFunc = stddevInvertFunction,
|
.invertFunc = stddevInvertFunction,
|
||||||
.combineFunc = stddevCombine,
|
.combineFunc = stddevCombine,
|
||||||
|
.pPartialFunc = "_stddev_partial",
|
||||||
|
.pMergeFunc = "_stddev_merge"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "_stddev_partial",
|
||||||
|
.type = FUNCTION_TYPE_STDDEV_PARTIAL,
|
||||||
|
.classification = FUNC_MGT_AGG_FUNC,
|
||||||
|
.translateFunc = translateStddevPartial,
|
||||||
|
.getEnvFunc = getStddevFuncEnv,
|
||||||
|
.initFunc = stddevFunctionSetup,
|
||||||
|
.processFunc = stddevFunction,
|
||||||
|
.finalizeFunc = stddevPartialFinalize,
|
||||||
|
.invertFunc = stddevInvertFunction,
|
||||||
|
.combineFunc = stddevCombine,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "_stddev_merge",
|
||||||
|
.type = FUNCTION_TYPE_STDDEV_MERGE,
|
||||||
|
.classification = FUNC_MGT_AGG_FUNC,
|
||||||
|
.translateFunc = translateStddevMerge,
|
||||||
|
.getEnvFunc = getStddevFuncEnv,
|
||||||
|
.initFunc = stddevFunctionSetup,
|
||||||
|
.processFunc = stddevFunctionMerge,
|
||||||
|
.finalizeFunc = stddevFinalize,
|
||||||
|
.invertFunc = stddevInvertFunction,
|
||||||
|
.combineFunc = stddevCombine,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.name = "leastsquares",
|
.name = "leastsquares",
|
||||||
|
@ -1517,11 +1602,37 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.finalizeFunc = avgFinalize,
|
.finalizeFunc = avgFinalize,
|
||||||
.invertFunc = avgInvertFunction,
|
.invertFunc = avgInvertFunction,
|
||||||
.combineFunc = avgCombine,
|
.combineFunc = avgCombine,
|
||||||
|
.pPartialFunc = "_avg_partial",
|
||||||
|
.pMergeFunc = "_avg_merge"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "_avg_partial",
|
||||||
|
.type = FUNCTION_TYPE_AVG_PARTIAL,
|
||||||
|
.classification = FUNC_MGT_AGG_FUNC,
|
||||||
|
.translateFunc = translateAvgPartial,
|
||||||
|
.getEnvFunc = getAvgFuncEnv,
|
||||||
|
.initFunc = avgFunctionSetup,
|
||||||
|
.processFunc = avgFunction,
|
||||||
|
.finalizeFunc = avgPartialFinalize,
|
||||||
|
.invertFunc = avgInvertFunction,
|
||||||
|
.combineFunc = avgCombine,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.name = "_avg_merge",
|
||||||
|
.type = FUNCTION_TYPE_AVG_MERGE,
|
||||||
|
.classification = FUNC_MGT_AGG_FUNC,
|
||||||
|
.translateFunc = translateAvgMerge,
|
||||||
|
.getEnvFunc = getAvgFuncEnv,
|
||||||
|
.initFunc = avgFunctionSetup,
|
||||||
|
.processFunc = avgFunctionMerge,
|
||||||
|
.finalizeFunc = avgFinalize,
|
||||||
|
.invertFunc = avgInvertFunction,
|
||||||
|
.combineFunc = avgCombine,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.name = "percentile",
|
.name = "percentile",
|
||||||
.type = FUNCTION_TYPE_PERCENTILE,
|
.type = FUNCTION_TYPE_PERCENTILE,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_REPEAT_SCAN_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_REPEAT_SCAN_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||||
.translateFunc = translatePercentile,
|
.translateFunc = translatePercentile,
|
||||||
.getEnvFunc = getPercentileFuncEnv,
|
.getEnvFunc = getPercentileFuncEnv,
|
||||||
.initFunc = percentileFunctionSetup,
|
.initFunc = percentileFunctionSetup,
|
||||||
|
@ -1682,7 +1793,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "elapsed",
|
.name = "elapsed",
|
||||||
.type = FUNCTION_TYPE_ELAPSED,
|
.type = FUNCTION_TYPE_ELAPSED,
|
||||||
.classification = FUNC_MGT_AGG_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||||
.dataRequiredFunc = statisDataRequired,
|
.dataRequiredFunc = statisDataRequired,
|
||||||
.translateFunc = translateElapsed,
|
.translateFunc = translateElapsed,
|
||||||
.getEnvFunc = getElapsedFuncEnv,
|
.getEnvFunc = getElapsedFuncEnv,
|
||||||
|
@ -1803,7 +1914,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "twa",
|
.name = "twa",
|
||||||
.type = FUNCTION_TYPE_TWA,
|
.type = FUNCTION_TYPE_TWA,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||||
.translateFunc = translateInNumOutDou,
|
.translateFunc = translateInNumOutDou,
|
||||||
.getEnvFunc = getTwaFuncEnv,
|
.getEnvFunc = getTwaFuncEnv,
|
||||||
.initFunc = twaFunctionSetup,
|
.initFunc = twaFunctionSetup,
|
||||||
|
@ -1889,7 +2000,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "diff",
|
.name = "diff",
|
||||||
.type = FUNCTION_TYPE_DIFF,
|
.type = FUNCTION_TYPE_DIFF,
|
||||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||||
.translateFunc = translateDiff,
|
.translateFunc = translateDiff,
|
||||||
.getEnvFunc = getDiffFuncEnv,
|
.getEnvFunc = getDiffFuncEnv,
|
||||||
.initFunc = diffFunctionSetup,
|
.initFunc = diffFunctionSetup,
|
||||||
|
@ -1899,7 +2010,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "statecount",
|
.name = "statecount",
|
||||||
.type = FUNCTION_TYPE_STATE_COUNT,
|
.type = FUNCTION_TYPE_STATE_COUNT,
|
||||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC,
|
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||||
.translateFunc = translateStateCount,
|
.translateFunc = translateStateCount,
|
||||||
.getEnvFunc = getStateFuncEnv,
|
.getEnvFunc = getStateFuncEnv,
|
||||||
.initFunc = functionSetup,
|
.initFunc = functionSetup,
|
||||||
|
@ -1909,7 +2020,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "stateduration",
|
.name = "stateduration",
|
||||||
.type = FUNCTION_TYPE_STATE_DURATION,
|
.type = FUNCTION_TYPE_STATE_DURATION,
|
||||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||||
.translateFunc = translateStateDuration,
|
.translateFunc = translateStateDuration,
|
||||||
.getEnvFunc = getStateFuncEnv,
|
.getEnvFunc = getStateFuncEnv,
|
||||||
.initFunc = functionSetup,
|
.initFunc = functionSetup,
|
||||||
|
@ -1919,7 +2030,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "csum",
|
.name = "csum",
|
||||||
.type = FUNCTION_TYPE_CSUM,
|
.type = FUNCTION_TYPE_CSUM,
|
||||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||||
.translateFunc = translateCsum,
|
.translateFunc = translateCsum,
|
||||||
.getEnvFunc = getCsumFuncEnv,
|
.getEnvFunc = getCsumFuncEnv,
|
||||||
.initFunc = functionSetup,
|
.initFunc = functionSetup,
|
||||||
|
@ -1929,7 +2040,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "mavg",
|
.name = "mavg",
|
||||||
.type = FUNCTION_TYPE_MAVG,
|
.type = FUNCTION_TYPE_MAVG,
|
||||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||||
.translateFunc = translateMavg,
|
.translateFunc = translateMavg,
|
||||||
.getEnvFunc = getMavgFuncEnv,
|
.getEnvFunc = getMavgFuncEnv,
|
||||||
.initFunc = mavgFunctionSetup,
|
.initFunc = mavgFunctionSetup,
|
||||||
|
@ -1939,7 +2050,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "sample",
|
.name = "sample",
|
||||||
.type = FUNCTION_TYPE_SAMPLE,
|
.type = FUNCTION_TYPE_SAMPLE,
|
||||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC,
|
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||||
.translateFunc = translateSample,
|
.translateFunc = translateSample,
|
||||||
.getEnvFunc = getSampleFuncEnv,
|
.getEnvFunc = getSampleFuncEnv,
|
||||||
.initFunc = sampleFunctionSetup,
|
.initFunc = sampleFunctionSetup,
|
||||||
|
@ -1949,7 +2060,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "tail",
|
.name = "tail",
|
||||||
.type = FUNCTION_TYPE_TAIL,
|
.type = FUNCTION_TYPE_TAIL,
|
||||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||||
.translateFunc = translateTail,
|
.translateFunc = translateTail,
|
||||||
.getEnvFunc = getTailFuncEnv,
|
.getEnvFunc = getTailFuncEnv,
|
||||||
.initFunc = tailFunctionSetup,
|
.initFunc = tailFunctionSetup,
|
||||||
|
@ -1959,7 +2070,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
{
|
{
|
||||||
.name = "unique",
|
.name = "unique",
|
||||||
.type = FUNCTION_TYPE_UNIQUE,
|
.type = FUNCTION_TYPE_UNIQUE,
|
||||||
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC,
|
.classification = FUNC_MGT_INDEFINITE_ROWS_FUNC | FUNC_MGT_TIMELINE_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||||
.translateFunc = translateUnique,
|
.translateFunc = translateUnique,
|
||||||
.getEnvFunc = getUniqueFuncEnv,
|
.getEnvFunc = getUniqueFuncEnv,
|
||||||
.initFunc = uniqueFunctionSetup,
|
.initFunc = uniqueFunctionSetup,
|
||||||
|
|
|
@ -51,6 +51,7 @@ typedef struct SAvgRes {
|
||||||
double result;
|
double result;
|
||||||
SSumRes sum;
|
SSumRes sum;
|
||||||
int64_t count;
|
int64_t count;
|
||||||
|
int16_t type; // store the original input type, used in merge function
|
||||||
} SAvgRes;
|
} SAvgRes;
|
||||||
|
|
||||||
typedef struct STuplePos {
|
typedef struct STuplePos {
|
||||||
|
@ -88,6 +89,7 @@ typedef struct SStddevRes {
|
||||||
double dsum;
|
double dsum;
|
||||||
int64_t isum;
|
int64_t isum;
|
||||||
};
|
};
|
||||||
|
int16_t type;
|
||||||
} SStddevRes;
|
} SStddevRes;
|
||||||
|
|
||||||
typedef struct SLeastSQRInfo {
|
typedef struct SLeastSQRInfo {
|
||||||
|
@ -624,6 +626,8 @@ bool getSumFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t getAvgInfoSize() { return (int32_t)sizeof(SAvgRes); }
|
||||||
|
|
||||||
bool getAvgFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
bool getAvgFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||||
pEnv->calcMemSize = sizeof(SAvgRes);
|
pEnv->calcMemSize = sizeof(SAvgRes);
|
||||||
return true;
|
return true;
|
||||||
|
@ -642,11 +646,12 @@ bool avgFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||||
int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
||||||
int32_t numOfElem = 0;
|
int32_t numOfElem = 0;
|
||||||
|
|
||||||
// Only the pre-computing information loaded and actual data does not loaded
|
|
||||||
SInputColumnInfoData* pInput = &pCtx->input;
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
|
SColumnDataAgg* pAgg = pInput->pColumnDataAgg[0];
|
||||||
int32_t type = pInput->pData[0]->info.type;
|
int32_t type = pInput->pData[0]->info.type;
|
||||||
|
|
||||||
SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
|
pAvgRes->type = type;
|
||||||
|
|
||||||
// computing based on the true data block
|
// computing based on the true data block
|
||||||
SColumnInfoData* pCol = pInput->pData[0];
|
SColumnInfoData* pCol = pInput->pData[0];
|
||||||
|
@ -660,95 +665,107 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
|
||||||
goto _avg_over;
|
goto _avg_over;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
if (pInput->colDataAggIsSet) {
|
||||||
case TSDB_DATA_TYPE_TINYINT: {
|
numOfElem = numOfRows - pAgg->numOfNull;
|
||||||
int8_t* plist = (int8_t*)pCol->pData;
|
ASSERT(numOfElem >= 0);
|
||||||
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
|
||||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
pAvgRes->count += numOfElem;
|
||||||
continue;
|
if (IS_INTEGER_TYPE(type)) {
|
||||||
|
pAvgRes->sum.isum += pAgg->sum;
|
||||||
|
} else if (IS_FLOAT_TYPE(type)) {
|
||||||
|
pAvgRes->sum.dsum += GET_DOUBLE_VAL((const char*)&(pAgg->sum));
|
||||||
|
}
|
||||||
|
} else { // computing based on the true data block
|
||||||
|
switch (type) {
|
||||||
|
case TSDB_DATA_TYPE_TINYINT: {
|
||||||
|
int8_t* plist = (int8_t*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElem += 1;
|
||||||
|
pAvgRes->count += 1;
|
||||||
|
pAvgRes->sum.isum += plist[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
numOfElem += 1;
|
break;
|
||||||
pAvgRes->count += 1;
|
|
||||||
pAvgRes->sum.isum += plist[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
case TSDB_DATA_TYPE_SMALLINT: {
|
||||||
}
|
int16_t* plist = (int16_t*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_SMALLINT: {
|
numOfElem += 1;
|
||||||
int16_t* plist = (int16_t*)pCol->pData;
|
pAvgRes->count += 1;
|
||||||
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
pAvgRes->sum.isum += plist[i];
|
||||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
}
|
||||||
continue;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TSDB_DATA_TYPE_INT: {
|
||||||
|
int32_t* plist = (int32_t*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElem += 1;
|
||||||
|
pAvgRes->count += 1;
|
||||||
|
pAvgRes->sum.isum += plist[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
numOfElem += 1;
|
break;
|
||||||
pAvgRes->count += 1;
|
|
||||||
pAvgRes->sum.isum += plist[i];
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_INT: {
|
case TSDB_DATA_TYPE_BIGINT: {
|
||||||
int32_t* plist = (int32_t*)pCol->pData;
|
int64_t* plist = (int64_t*)pCol->pData;
|
||||||
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElem += 1;
|
||||||
|
pAvgRes->count += 1;
|
||||||
|
pAvgRes->sum.isum += plist[i];
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
numOfElem += 1;
|
|
||||||
pAvgRes->count += 1;
|
|
||||||
pAvgRes->sum.isum += plist[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
case TSDB_DATA_TYPE_FLOAT: {
|
||||||
}
|
float* plist = (float*)pCol->pData;
|
||||||
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_BIGINT: {
|
numOfElem += 1;
|
||||||
int64_t* plist = (int64_t*)pCol->pData;
|
pAvgRes->count += 1;
|
||||||
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
pAvgRes->sum.dsum += plist[i];
|
||||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
numOfElem += 1;
|
|
||||||
pAvgRes->count += 1;
|
|
||||||
pAvgRes->sum.isum += plist[i];
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_FLOAT: {
|
case TSDB_DATA_TYPE_DOUBLE: {
|
||||||
float* plist = (float*)pCol->pData;
|
double* plist = (double*)pCol->pData;
|
||||||
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
||||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
numOfElem += 1;
|
||||||
|
pAvgRes->count += 1;
|
||||||
|
pAvgRes->sum.dsum += plist[i];
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
numOfElem += 1;
|
|
||||||
pAvgRes->count += 1;
|
|
||||||
pAvgRes->sum.dsum += plist[i];
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_DOUBLE: {
|
|
||||||
double* plist = (double*)pCol->pData;
|
|
||||||
for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) {
|
|
||||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
numOfElem += 1;
|
|
||||||
pAvgRes->count += 1;
|
|
||||||
pAvgRes->sum.dsum += plist[i];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_avg_over:
|
_avg_over:
|
||||||
|
@ -757,6 +774,37 @@ _avg_over:
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void avgTransferInfo(SAvgRes* pInput, SAvgRes* pOutput) {
|
||||||
|
pOutput->type = pInput->type;
|
||||||
|
if (IS_INTEGER_TYPE(pOutput->type)) {
|
||||||
|
pOutput->sum.isum += pInput->sum.isum;
|
||||||
|
} else {
|
||||||
|
pOutput->sum.dsum += pInput->sum.dsum;
|
||||||
|
}
|
||||||
|
|
||||||
|
pOutput->count += pInput->count;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t avgFunctionMerge(SqlFunctionCtx* pCtx) {
|
||||||
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
|
SColumnInfoData* pCol = pInput->pData[0];
|
||||||
|
ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY);
|
||||||
|
|
||||||
|
SAvgRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
|
|
||||||
|
int32_t start = pInput->startRowIndex;
|
||||||
|
char* data = colDataGetData(pCol, start);
|
||||||
|
SAvgRes* pInputInfo = (SAvgRes*)varDataVal(data);
|
||||||
|
|
||||||
|
avgTransferInfo(pInputInfo, pInfo);
|
||||||
|
|
||||||
|
SET_VAL(GET_RES_INFO(pCtx), 1, 1);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
#define LIST_AVG_N(sumT, T) \
|
#define LIST_AVG_N(sumT, T) \
|
||||||
do { \
|
do { \
|
||||||
T* plist = (T*)pCol->pData; \
|
T* plist = (T*)pCol->pData; \
|
||||||
|
@ -841,8 +889,8 @@ int32_t avgCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
|
||||||
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SInputColumnInfoData* pInput = &pCtx->input;
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
|
|
||||||
int32_t type = pInput->pData[0]->info.type;
|
|
||||||
SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
SAvgRes* pAvgRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
|
int32_t type = pAvgRes->type;
|
||||||
|
|
||||||
if (IS_INTEGER_TYPE(type)) {
|
if (IS_INTEGER_TYPE(type)) {
|
||||||
pAvgRes->result = pAvgRes->sum.isum / ((double)pAvgRes->count);
|
pAvgRes->result = pAvgRes->sum.isum / ((double)pAvgRes->count);
|
||||||
|
@ -858,6 +906,24 @@ int32_t avgFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
return functionFinalize(pCtx, pBlock);
|
return functionFinalize(pCtx, pBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t avgPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
|
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||||
|
SAvgRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
|
int32_t resultBytes = getAvgInfoSize();
|
||||||
|
char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char));
|
||||||
|
|
||||||
|
memcpy(varDataVal(res), pInfo, resultBytes);
|
||||||
|
varDataSetLen(res, resultBytes);
|
||||||
|
|
||||||
|
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||||
|
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||||
|
|
||||||
|
colDataAppend(pCol, pBlock->info.rows, res, false);
|
||||||
|
|
||||||
|
taosMemoryFree(res);
|
||||||
|
return pResInfo->numOfRes;
|
||||||
|
}
|
||||||
|
|
||||||
EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
|
EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
|
||||||
return FUNC_DATA_REQUIRED_STATIS_LOAD;
|
return FUNC_DATA_REQUIRED_STATIS_LOAD;
|
||||||
}
|
}
|
||||||
|
@ -1423,6 +1489,8 @@ int32_t maxCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
|
||||||
return minMaxCombine(pDestCtx, pSourceCtx, 0);
|
return minMaxCombine(pDestCtx, pSourceCtx, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t getStddevInfoSize() { return (int32_t)sizeof(SStddevRes); }
|
||||||
|
|
||||||
bool getStddevFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
bool getStddevFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||||
pEnv->calcMemSize = sizeof(SStddevRes);
|
pEnv->calcMemSize = sizeof(SStddevRes);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1446,6 +1514,7 @@ int32_t stddevFunction(SqlFunctionCtx* pCtx) {
|
||||||
int32_t type = pInput->pData[0]->info.type;
|
int32_t type = pInput->pData[0]->info.type;
|
||||||
|
|
||||||
SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
|
pStddevRes->type = type;
|
||||||
|
|
||||||
// computing based on the true data block
|
// computing based on the true data block
|
||||||
SColumnInfoData* pCol = pInput->pData[0];
|
SColumnInfoData* pCol = pInput->pData[0];
|
||||||
|
@ -1562,6 +1631,39 @@ _stddev_over:
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void stddevTransferInfo(SStddevRes* pInput, SStddevRes* pOutput) {
|
||||||
|
pOutput->type = pInput->type;
|
||||||
|
if (IS_INTEGER_TYPE(pOutput->type)) {
|
||||||
|
pOutput->quadraticISum += pInput->quadraticISum;
|
||||||
|
pOutput->isum += pInput->isum;
|
||||||
|
} else {
|
||||||
|
pOutput->quadraticDSum += pInput->quadraticDSum;
|
||||||
|
pOutput->dsum += pInput->dsum;
|
||||||
|
}
|
||||||
|
|
||||||
|
pOutput->count += pInput->count;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t stddevFunctionMerge(SqlFunctionCtx* pCtx) {
|
||||||
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
|
SColumnInfoData* pCol = pInput->pData[0];
|
||||||
|
ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY);
|
||||||
|
|
||||||
|
SStddevRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
|
|
||||||
|
int32_t start = pInput->startRowIndex;
|
||||||
|
char* data = colDataGetData(pCol, start);
|
||||||
|
SStddevRes* pInputInfo = (SStddevRes*)varDataVal(data);
|
||||||
|
|
||||||
|
stddevTransferInfo(pInputInfo, pInfo);
|
||||||
|
|
||||||
|
SET_VAL(GET_RES_INFO(pCtx), 1, 1);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
#define LIST_STDDEV_SUB_N(sumT, T) \
|
#define LIST_STDDEV_SUB_N(sumT, T) \
|
||||||
do { \
|
do { \
|
||||||
T* plist = (T*)pCol->pData; \
|
T* plist = (T*)pCol->pData; \
|
||||||
|
@ -1627,9 +1729,10 @@ int32_t stddevInvertFunction(SqlFunctionCtx* pCtx) {
|
||||||
|
|
||||||
int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SInputColumnInfoData* pInput = &pCtx->input;
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
int32_t type = pInput->pData[0]->info.type;
|
|
||||||
SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
SStddevRes* pStddevRes = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
|
int32_t type = pStddevRes->type;
|
||||||
double avg;
|
double avg;
|
||||||
|
|
||||||
if (IS_INTEGER_TYPE(type)) {
|
if (IS_INTEGER_TYPE(type)) {
|
||||||
avg = pStddevRes->isum / ((double)pStddevRes->count);
|
avg = pStddevRes->isum / ((double)pStddevRes->count);
|
||||||
pStddevRes->result = sqrt(pStddevRes->quadraticISum / ((double)pStddevRes->count) - avg * avg);
|
pStddevRes->result = sqrt(pStddevRes->quadraticISum / ((double)pStddevRes->count) - avg * avg);
|
||||||
|
@ -1641,6 +1744,24 @@ int32_t stddevFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
return functionFinalize(pCtx, pBlock);
|
return functionFinalize(pCtx, pBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t stddevPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
|
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||||
|
SStddevRes* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
|
int32_t resultBytes = getStddevInfoSize();
|
||||||
|
char* res = taosMemoryCalloc(resultBytes + VARSTR_HEADER_SIZE, sizeof(char));
|
||||||
|
|
||||||
|
memcpy(varDataVal(res), pInfo, resultBytes);
|
||||||
|
varDataSetLen(res, resultBytes);
|
||||||
|
|
||||||
|
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||||
|
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||||
|
|
||||||
|
colDataAppend(pCol, pBlock->info.rows, res, false);
|
||||||
|
|
||||||
|
taosMemoryFree(res);
|
||||||
|
return pResInfo->numOfRes;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t stddevCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
|
int32_t stddevCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
|
||||||
SResultRowEntryInfo* pDResInfo = GET_RES_INFO(pDestCtx);
|
SResultRowEntryInfo* pDResInfo = GET_RES_INFO(pDestCtx);
|
||||||
SStddevRes* pDBuf = GET_ROWCELL_INTERBUF(pDResInfo);
|
SStddevRes* pDBuf = GET_ROWCELL_INTERBUF(pDResInfo);
|
||||||
|
@ -3226,11 +3347,10 @@ int32_t spreadFunctionMerge(SqlFunctionCtx* pCtx) {
|
||||||
ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY);
|
ASSERT(pCol->info.type == TSDB_DATA_TYPE_BINARY);
|
||||||
|
|
||||||
SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
SSpreadInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||||
SSpreadInfo* pInputInfo;
|
|
||||||
|
|
||||||
int32_t start = pInput->startRowIndex;
|
int32_t start = pInput->startRowIndex;
|
||||||
char* data = colDataGetData(pCol, start);
|
char* data = colDataGetData(pCol, start);
|
||||||
pInputInfo = (SSpreadInfo*)varDataVal(data);
|
SSpreadInfo* pInputInfo = (SSpreadInfo*)varDataVal(data);
|
||||||
|
|
||||||
spreadTransferInfo(pInputInfo, pInfo);
|
spreadTransferInfo(pInputInfo, pInfo);
|
||||||
|
|
||||||
|
|
|
@ -230,9 +230,13 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||||
SRawExprNode* pRawExpr = (SRawExprNode*)pNode;
|
SRawExprNode* pRawExpr = (SRawExprNode*)pNode;
|
||||||
SNode* pExpr = pRawExpr->pNode;
|
SNode* pExpr = pRawExpr->pNode;
|
||||||
if (nodesIsExprNode(pExpr)) {
|
if (nodesIsExprNode(pExpr)) {
|
||||||
int32_t len = TMIN(sizeof(((SExprNode*)pExpr)->aliasName) - 1, pRawExpr->n);
|
if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
|
||||||
strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, len);
|
strcpy(((SExprNode*)pExpr)->aliasName, ((SColumnNode*)pExpr)->colName);
|
||||||
((SExprNode*)pExpr)->aliasName[len] = '\0';
|
} else {
|
||||||
|
int32_t len = TMIN(sizeof(((SExprNode*)pExpr)->aliasName) - 1, pRawExpr->n);
|
||||||
|
strncpy(((SExprNode*)pExpr)->aliasName, pRawExpr->p, len);
|
||||||
|
((SExprNode*)pExpr)->aliasName[len] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
taosMemoryFreeClear(pNode);
|
taosMemoryFreeClear(pNode);
|
||||||
return pExpr;
|
return pExpr;
|
||||||
|
@ -801,7 +805,7 @@ SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOpti
|
||||||
((SDatabaseOptions*)pOptions)->pRetentions = pVal;
|
((SDatabaseOptions*)pOptions)->pRetentions = pVal;
|
||||||
break;
|
break;
|
||||||
case DB_OPTION_SCHEMALESS:
|
case DB_OPTION_SCHEMALESS:
|
||||||
// ((SDatabaseOptions*)pOptions)->schemaless = taosStr2Int8(((SToken*)pVal)->z, NULL, 10);
|
// ((SDatabaseOptions*)pOptions)->schemaless = taosStr2Int8(((SToken*)pVal)->z, NULL, 10);
|
||||||
((SDatabaseOptions*)pOptions)->schemaless = 1;
|
((SDatabaseOptions*)pOptions)->schemaless = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -537,13 +537,15 @@ static int32_t findAndSetColumn(STranslateContext* pCxt, SColumnNode** pColRef,
|
||||||
SNode* pNode;
|
SNode* pNode;
|
||||||
FOREACH(pNode, pProjectList) {
|
FOREACH(pNode, pProjectList) {
|
||||||
SExprNode* pExpr = (SExprNode*)pNode;
|
SExprNode* pExpr = (SExprNode*)pNode;
|
||||||
if (0 == strcmp(pCol->colName, pExpr->aliasName) ||
|
if (0 == strcmp(pCol->colName, pExpr->aliasName)) {
|
||||||
(isPrimaryKey((STempTableNode*)pTable, pNode) && isInternalPrimaryKey(pCol))) {
|
|
||||||
if (*pFound) {
|
if (*pFound) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_AMBIGUOUS_COLUMN, pCol->colName);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_AMBIGUOUS_COLUMN, pCol->colName);
|
||||||
}
|
}
|
||||||
setColumnInfoByExpr(pTable, pExpr, pColRef);
|
setColumnInfoByExpr(pTable, pExpr, pColRef);
|
||||||
*pFound = true;
|
*pFound = true;
|
||||||
|
} else if (isPrimaryKey((STempTableNode*)pTable, pNode) && isInternalPrimaryKey(pCol)) {
|
||||||
|
setColumnInfoByExpr(pTable, pExpr, pColRef);
|
||||||
|
*pFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -662,9 +664,24 @@ static int32_t parseTimeFromValueNode(STranslateContext* pCxt, SValueNode* pVal)
|
||||||
}
|
}
|
||||||
char* pEnd = NULL;
|
char* pEnd = NULL;
|
||||||
pVal->datum.i = taosStr2Int64(pVal->literal, &pEnd, 10);
|
pVal->datum.i = taosStr2Int64(pVal->literal, &pEnd, 10);
|
||||||
return (NULL != pEnd && '\0' == *pEnd) ? TSDB_CODE_SUCCESS : TSDB_CODE_FAILED;
|
return (NULL != pEnd && '\0' == *pEnd) ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_WRONG_VALUE_TYPE;
|
||||||
} else {
|
} else {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_PAR_WRONG_VALUE_TYPE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t parseBoolFromValueNode(STranslateContext* pCxt, SValueNode* pVal) {
|
||||||
|
if (IS_VAR_DATA_TYPE(pVal->node.resType.type) || TSDB_DATA_TYPE_BOOL == pVal->node.resType.type) {
|
||||||
|
pVal->datum.b = (0 == strcasecmp(pVal->literal, "true"));
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
} else if (IS_INTEGER_TYPE(pVal->node.resType.type)) {
|
||||||
|
pVal->datum.b = (0 != taosStr2Int64(pVal->literal, NULL, 10));
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
} else if (IS_FLOAT_TYPE(pVal->node.resType.type)) {
|
||||||
|
pVal->datum.b = (0 != taosStr2Double(pVal->literal, NULL));
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
} else {
|
||||||
|
return TSDB_CODE_PAR_WRONG_VALUE_TYPE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -685,7 +702,9 @@ static EDealRes translateValueImpl(STranslateContext* pCxt, SValueNode* pVal, SD
|
||||||
case TSDB_DATA_TYPE_NULL:
|
case TSDB_DATA_TYPE_NULL:
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_BOOL:
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
pVal->datum.b = (0 == strcasecmp(pVal->literal, "true"));
|
if (TSDB_CODE_SUCCESS != parseBoolFromValueNode(pCxt, pVal)) {
|
||||||
|
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal);
|
||||||
|
}
|
||||||
*(bool*)&pVal->typeData = pVal->datum.b;
|
*(bool*)&pVal->typeData = pVal->datum.b;
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_TINYINT: {
|
case TSDB_DATA_TYPE_TINYINT: {
|
||||||
|
@ -1068,6 +1087,16 @@ static int32_t translateForbidFillFunc(STranslateContext* pCxt, SFunctionNode* p
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t translateWindowPseudoColumnFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||||
|
if (!fmIsWindowPseudoColumnFunc(pFunc->funcId)) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
if (NULL == pCxt->pCurrSelectStmt->pWindow) {
|
||||||
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_WINDOW_PC);
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static void setFuncClassification(SSelectStmt* pSelect, SFunctionNode* pFunc) {
|
static void setFuncClassification(SSelectStmt* pSelect, SFunctionNode* pFunc) {
|
||||||
if (NULL != pSelect) {
|
if (NULL != pSelect) {
|
||||||
pSelect->hasAggFuncs = pSelect->hasAggFuncs ? true : fmIsAggFunc(pFunc->funcId);
|
pSelect->hasAggFuncs = pSelect->hasAggFuncs ? true : fmIsAggFunc(pFunc->funcId);
|
||||||
|
@ -1097,6 +1126,9 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||||
pCxt->errCode = translateForbidFillFunc(pCxt, pFunc);
|
pCxt->errCode = translateForbidFillFunc(pCxt, pFunc);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||||
|
pCxt->errCode = translateWindowPseudoColumnFunc(pCxt, pFunc);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||||
setFuncClassification(pCxt->pCurrSelectStmt, pFunc);
|
setFuncClassification(pCxt->pCurrSelectStmt, pFunc);
|
||||||
}
|
}
|
||||||
|
@ -3106,7 +3138,11 @@ static int32_t translateDropSuperTable(STranslateContext* pCxt, SDropSuperTableS
|
||||||
pStmt->ignoreNotExists);
|
pStmt->ignoreNotExists);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setAlterTableField(SAlterTableStmt* pStmt, SMAlterStbReq* pAlterReq) {
|
static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, SMAlterStbReq* pAlterReq) {
|
||||||
|
SName tableName;
|
||||||
|
tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName), pAlterReq->name);
|
||||||
|
pAlterReq->alterType = pStmt->alterType;
|
||||||
|
|
||||||
if (TSDB_ALTER_TABLE_UPDATE_OPTIONS == pStmt->alterType) {
|
if (TSDB_ALTER_TABLE_UPDATE_OPTIONS == pStmt->alterType) {
|
||||||
pAlterReq->ttl = pStmt->pOptions->ttl;
|
pAlterReq->ttl = pStmt->pOptions->ttl;
|
||||||
if ('\0' != pStmt->pOptions->comment[0]) {
|
if ('\0' != pStmt->pOptions->comment[0]) {
|
||||||
|
@ -3154,15 +3190,45 @@ static int32_t setAlterTableField(SAlterTableStmt* pStmt, SMAlterStbReq* pAlterR
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t translateAlterTable(STranslateContext* pCxt, SAlterTableStmt* pStmt) {
|
static SSchema* getColSchema(STableMeta* pTableMeta, const char* pTagName) {
|
||||||
SMAlterStbReq alterReq = {0};
|
int32_t numOfFields = getNumOfTags(pTableMeta) + getNumOfColumns(pTableMeta);
|
||||||
SName tableName;
|
for (int32_t i = 0; i < numOfFields; ++i) {
|
||||||
tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName), alterReq.name);
|
SSchema* pTagSchema = pTableMeta->schema + i;
|
||||||
alterReq.alterType = pStmt->alterType;
|
if (0 == strcmp(pTagName, pTagSchema->name)) {
|
||||||
|
return pTagSchema;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t checkAlterSuperTable(STranslateContext* pCxt, SAlterTableStmt* pStmt) {
|
||||||
if (TSDB_ALTER_TABLE_UPDATE_TAG_VAL == pStmt->alterType || TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME == pStmt->alterType) {
|
if (TSDB_ALTER_TABLE_UPDATE_TAG_VAL == pStmt->alterType || TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME == pStmt->alterType) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
||||||
}
|
}
|
||||||
int32_t code = setAlterTableField(pStmt, &alterReq);
|
if (TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES == pStmt->alterType ||
|
||||||
|
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES == pStmt->alterType) {
|
||||||
|
STableMeta* pTableMeta = NULL;
|
||||||
|
int32_t code = getTableMeta(pCxt, pStmt->dbName, pStmt->tableName, &pTableMeta);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
SSchema* pSchema = getColSchema(pTableMeta, pStmt->colName);
|
||||||
|
if (NULL == pSchema) {
|
||||||
|
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COLUMN, pStmt->colName);
|
||||||
|
} else if (!IS_VAR_DATA_TYPE(pSchema->type) || pSchema->type != pStmt->dataType.type ||
|
||||||
|
pSchema->bytes >= calcTypeBytes(pStmt->dataType)) {
|
||||||
|
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_MODIFY_COL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t translateAlterSuperTable(STranslateContext* pCxt, SAlterTableStmt* pStmt) {
|
||||||
|
SMAlterStbReq alterReq = {0};
|
||||||
|
int32_t code = checkAlterSuperTable(pCxt, pStmt);
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = buildAlterSuperTableReq(pCxt, pStmt, &alterReq);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = buildCmdMsg(pCxt, TDMT_MND_ALTER_STB, (FSerializeFunc)tSerializeSMAlterStbReq, &alterReq);
|
code = buildCmdMsg(pCxt, TDMT_MND_ALTER_STB, (FSerializeFunc)tSerializeSMAlterStbReq, &alterReq);
|
||||||
}
|
}
|
||||||
|
@ -3835,7 +3901,7 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||||
code = translateDropSuperTable(pCxt, (SDropSuperTableStmt*)pNode);
|
code = translateDropSuperTable(pCxt, (SDropSuperTableStmt*)pNode);
|
||||||
break;
|
break;
|
||||||
case QUERY_NODE_ALTER_TABLE_STMT:
|
case QUERY_NODE_ALTER_TABLE_STMT:
|
||||||
code = translateAlterTable(pCxt, (SAlterTableStmt*)pNode);
|
code = translateAlterSuperTable(pCxt, (SAlterTableStmt*)pNode);
|
||||||
break;
|
break;
|
||||||
case QUERY_NODE_CREATE_USER_STMT:
|
case QUERY_NODE_CREATE_USER_STMT:
|
||||||
code = translateCreateUser(pCxt, (SCreateUserStmt*)pNode);
|
code = translateCreateUser(pCxt, (SCreateUserStmt*)pNode);
|
||||||
|
@ -4445,10 +4511,35 @@ static int32_t translateTagVal(STranslateContext* pCxt, uint8_t precision, SSche
|
||||||
? pCxt->errCode
|
? pCxt->errCode
|
||||||
: TSDB_CODE_SUCCESS);
|
: TSDB_CODE_SUCCESS);
|
||||||
} else {
|
} else {
|
||||||
|
// return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)pNode)->aliasName);
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t buildJsonTagVal(STranslateContext* pCxt, SSchema* pTagSchema, SValueNode* pVal, SArray* pTagArray,
|
||||||
|
STag** ppTag) {
|
||||||
|
if (pVal->literal && strlen(pVal->literal) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
||||||
|
return buildSyntaxErrMsg(&pCxt->msgBuf, "json string too long than 4095", pVal->literal);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseJsontoTagData(pVal->literal, pTagArray, ppTag, &pCxt->msgBuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t buildNormalTagVal(STranslateContext* pCxt, SSchema* pTagSchema, SValueNode* pVal, SArray* pTagArray) {
|
||||||
|
if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL) {
|
||||||
|
void* nodeVal = nodesGetValueFromNode(pVal);
|
||||||
|
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
||||||
|
if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
|
||||||
|
val.pData = varDataVal(nodeVal);
|
||||||
|
val.nData = varDataLen(nodeVal);
|
||||||
|
} else {
|
||||||
|
memcpy(&val.i64, nodeVal, pTagSchema->bytes);
|
||||||
|
}
|
||||||
|
taosArrayPush(pTagArray, &val);
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
|
static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
|
||||||
STag** ppTag) {
|
STag** ppTag) {
|
||||||
int32_t numOfTags = getNumOfTags(pSuperTableMeta);
|
int32_t numOfTags = getNumOfTags(pSuperTableMeta);
|
||||||
|
@ -4458,11 +4549,10 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* pTagArray = taosArrayInit(LIST_LENGTH(pStmt->pValsOfTags), sizeof(STagVal));
|
SArray* pTagArray = taosArrayInit(LIST_LENGTH(pStmt->pValsOfTags), sizeof(STagVal));
|
||||||
if (!pTagArray) {
|
if (NULL == pTagArray) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_TSC_OUT_OF_MEMORY);
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
int16_t nTags = 0, nBufPos = 0;
|
|
||||||
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
|
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
|
||||||
SNode * pTag = NULL, *pNode = NULL;
|
SNode * pTag = NULL, *pNode = NULL;
|
||||||
bool isJson = false;
|
bool isJson = false;
|
||||||
|
@ -4490,27 +4580,12 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
||||||
} else {
|
} else {
|
||||||
REPLACE_LIST2_NODE(pVal);
|
REPLACE_LIST2_NODE(pVal);
|
||||||
}
|
}
|
||||||
if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
|
|
||||||
if (pVal->literal && strlen(pVal->literal) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
|
||||||
code = buildSyntaxErrMsg(&pCxt->msgBuf, "json string too long than 4095", pVal->literal);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (pSchema->type == TSDB_DATA_TYPE_JSON) {
|
||||||
isJson = true;
|
isJson = true;
|
||||||
code = parseJsontoTagData(pVal->literal, pTagArray, ppTag, &pCxt->msgBuf);
|
code = buildJsonTagVal(pCxt, pSchema, pVal, pTagArray, ppTag);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
} else if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL) {
|
} else if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL) {
|
||||||
void* nodeVal = nodesGetValueFromNode(pVal);
|
code = buildNormalTagVal(pCxt, pSchema, pVal, pTagArray);
|
||||||
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
|
|
||||||
if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
|
|
||||||
val.pData = varDataVal(nodeVal);
|
|
||||||
val.nData = varDataLen(nodeVal);
|
|
||||||
} else {
|
|
||||||
memcpy(&val.i64, nodeVal, pTagSchema->bytes);
|
|
||||||
}
|
|
||||||
taosArrayPush(pTagArray, &val);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4825,17 +4900,6 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
|
||||||
return rewriteToVnodeModifyOpStmt(pQuery, pBufArray);
|
return rewriteToVnodeModifyOpStmt(pQuery, pBufArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSchema* getColSchema(STableMeta* pTableMeta, const char* pTagName) {
|
|
||||||
int32_t numOfFields = getNumOfTags(pTableMeta) + getNumOfColumns(pTableMeta);
|
|
||||||
for (int32_t i = 0; i < numOfFields; ++i) {
|
|
||||||
SSchema* pTagSchema = pTableMeta->schema + i;
|
|
||||||
if (0 == strcmp(pTagName, pTagSchema->name)) {
|
|
||||||
return pTagSchema;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
||||||
SVAlterTbReq* pReq) {
|
SVAlterTbReq* pReq) {
|
||||||
SSchema* pSchema = getColSchema(pTableMeta, pStmt->colName);
|
SSchema* pSchema = getColSchema(pTableMeta, pStmt->colName);
|
||||||
|
@ -4853,6 +4917,10 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
|
||||||
return pCxt->errCode;
|
return pCxt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IS_VAR_DATA_TYPE(pSchema->type) && strlen(pStmt->pVal->literal) > pSchema->bytes) {
|
||||||
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pStmt->pVal->literal);
|
||||||
|
}
|
||||||
|
|
||||||
pReq->isNull = (TSDB_DATA_TYPE_NULL == pStmt->pVal->node.resType.type);
|
pReq->isNull = (TSDB_DATA_TYPE_NULL == pStmt->pVal->node.resType.type);
|
||||||
if (pStmt->pVal->node.resType.type == TSDB_DATA_TYPE_JSON) {
|
if (pStmt->pVal->node.resType.type == TSDB_DATA_TYPE_JSON) {
|
||||||
if (pStmt->pVal->literal &&
|
if (pStmt->pVal->literal &&
|
||||||
|
|
|
@ -186,6 +186,8 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
||||||
return "The REDISTRIBUTE VGROUP statement only support 1 to 3 dnodes";
|
return "The REDISTRIBUTE VGROUP statement only support 1 to 3 dnodes";
|
||||||
case TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC:
|
case TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC:
|
||||||
return "%s function not allowed in fill query";
|
return "%s function not allowed in fill query";
|
||||||
|
case TSDB_CODE_PAR_INVALID_WINDOW_PC:
|
||||||
|
return "_WSTARTTS, _WENDTS and _WDURATION can only be used in window queries";
|
||||||
case TSDB_CODE_OUT_OF_MEMORY:
|
case TSDB_CODE_OUT_OF_MEMORY:
|
||||||
return "Out of memory";
|
return "Out of memory";
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -207,6 +207,8 @@ int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid) {
|
||||||
return TSDB_CODE_FAILED;
|
return TSDB_CODE_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void qCleanupKeywordsTable() { taosCleanupKeywordsTable(); }
|
||||||
|
|
||||||
int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx) {
|
int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
|
|
@ -141,16 +141,18 @@ void generateTestT1(MockCatalogService* mcs) {
|
||||||
* c2 | column | VARCHAR | 20 |
|
* c2 | column | VARCHAR | 20 |
|
||||||
* tag1 | tag | INT | 4 |
|
* tag1 | tag | INT | 4 |
|
||||||
* tag2 | tag | VARCHAR | 20 |
|
* tag2 | tag | VARCHAR | 20 |
|
||||||
|
* tag3 | tag | TIMESTAMP | 8 |
|
||||||
* Child Table: st1s1, st1s2
|
* Child Table: st1s1, st1s2
|
||||||
*/
|
*/
|
||||||
void generateTestST1(MockCatalogService* mcs) {
|
void generateTestST1(MockCatalogService* mcs) {
|
||||||
ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 2)
|
ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 3)
|
||||||
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
||||||
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
.addColumn("ts", TSDB_DATA_TYPE_TIMESTAMP)
|
||||||
.addColumn("c1", TSDB_DATA_TYPE_INT)
|
.addColumn("c1", TSDB_DATA_TYPE_INT)
|
||||||
.addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
.addColumn("c2", TSDB_DATA_TYPE_BINARY, 20)
|
||||||
.addTag("tag1", TSDB_DATA_TYPE_INT)
|
.addTag("tag1", TSDB_DATA_TYPE_INT)
|
||||||
.addTag("tag2", TSDB_DATA_TYPE_BINARY, 20);
|
.addTag("tag2", TSDB_DATA_TYPE_BINARY, 20)
|
||||||
|
.addTag("tag3", TSDB_DATA_TYPE_TIMESTAMP);
|
||||||
builder.done();
|
builder.done();
|
||||||
mcs->createSubTable("test", "st1", "st1s1", 1);
|
mcs->createSubTable("test", "st1", "st1s1", 1);
|
||||||
mcs->createSubTable("test", "st1", "st1s2", 2);
|
mcs->createSubTable("test", "st1", "st1s2", 2);
|
||||||
|
@ -189,17 +191,17 @@ void generateFunctions(MockCatalogService* mcs) {
|
||||||
|
|
||||||
int32_t __catalogGetHandle(const char* clusterId, struct SCatalog** catalogHandle) { return 0; }
|
int32_t __catalogGetHandle(const char* clusterId, struct SCatalog** catalogHandle) { return 0; }
|
||||||
|
|
||||||
int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, SRequestConnInfo *pConn, const SName* pTableName,
|
int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, SRequestConnInfo* pConn, const SName* pTableName,
|
||||||
STableMeta** pTableMeta) {
|
STableMeta** pTableMeta) {
|
||||||
return g_mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta);
|
return g_mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, SRequestConnInfo *pConn,
|
int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, SRequestConnInfo* pConn, const SName* pTableName,
|
||||||
const SName* pTableName, SVgroupInfo* vgInfo) {
|
SVgroupInfo* vgInfo) {
|
||||||
return g_mockCatalogService->catalogGetTableHashVgroup(pTableName, vgInfo);
|
return g_mockCatalogService->catalogGetTableHashVgroup(pTableName, vgInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const SName* pTableName,
|
int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName,
|
||||||
SArray** pVgList) {
|
SArray** pVgList) {
|
||||||
return g_mockCatalogService->catalogGetTableDistVgInfo(pTableName, pVgList);
|
return g_mockCatalogService->catalogGetTableDistVgInfo(pTableName, pVgList);
|
||||||
}
|
}
|
||||||
|
@ -209,28 +211,26 @@ int32_t __catalogGetDBVgVersion(SCatalog* pCtg, const char* dbFName, int32_t* ve
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char* dbFName,
|
int32_t __catalogGetDBVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SArray** pVgList) {
|
||||||
SArray** pVgList) {
|
|
||||||
return g_mockCatalogService->catalogGetDBVgInfo(dbFName, pVgList);
|
return g_mockCatalogService->catalogGetDBVgInfo(dbFName, pVgList);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogGetDBCfg(SCatalog* pCtg, SRequestConnInfo *pConn, const char* dbFName, SDbCfgInfo* pDbCfg) {
|
int32_t __catalogGetDBCfg(SCatalog* pCtg, SRequestConnInfo* pConn, const char* dbFName, SDbCfgInfo* pDbCfg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogChkAuth(SCatalog* pCtg, SRequestConnInfo *pConn, const char* user, const char* dbFName,
|
int32_t __catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type,
|
||||||
AUTH_TYPE type, bool* pass) {
|
bool* pass) {
|
||||||
*pass = true;
|
*pass = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogGetUdfInfo(SCatalog* pCtg, SRequestConnInfo *pConn, const char* funcName,
|
int32_t __catalogGetUdfInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* funcName, SFuncInfo* pInfo) {
|
||||||
SFuncInfo* pInfo) {
|
|
||||||
return g_mockCatalogService->catalogGetUdfInfo(funcName, pInfo);
|
return g_mockCatalogService->catalogGetUdfInfo(funcName, pInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t __catalogRefreshGetTableMeta(SCatalog* pCatalog, SRequestConnInfo *pConn,
|
int32_t __catalogRefreshGetTableMeta(SCatalog* pCatalog, SRequestConnInfo* pConn, const SName* pTableName,
|
||||||
const SName* pTableName, STableMeta** pTableMeta, int32_t isSTable) {
|
STableMeta** pTableMeta, int32_t isSTable) {
|
||||||
return g_mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta);
|
return g_mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,9 +163,9 @@ TEST_F(ParserInitialATest, alterSTable) {
|
||||||
run("ALTER TABLE st1 DROP COLUMN c1");
|
run("ALTER TABLE st1 DROP COLUMN c1");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, 1, "c1", TSDB_DATA_TYPE_VARCHAR,
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, 1, "c2", TSDB_DATA_TYPE_VARCHAR,
|
||||||
20 + VARSTR_HEADER_SIZE);
|
30 + VARSTR_HEADER_SIZE);
|
||||||
run("ALTER TABLE st1 MODIFY COLUMN c1 VARCHAR(20)");
|
run("ALTER TABLE st1 MODIFY COLUMN c2 VARCHAR(30)");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, 2, "c1", 0, 0, "cc1");
|
// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, 2, "c1", 0, 0, "cc1");
|
||||||
|
@ -179,9 +179,9 @@ TEST_F(ParserInitialATest, alterSTable) {
|
||||||
run("ALTER TABLE st1 DROP TAG tag1");
|
run("ALTER TABLE st1 DROP TAG tag1");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, 1, "tag1", TSDB_DATA_TYPE_VARCHAR,
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, 1, "tag2", TSDB_DATA_TYPE_VARCHAR,
|
||||||
20 + VARSTR_HEADER_SIZE);
|
30 + VARSTR_HEADER_SIZE);
|
||||||
run("ALTER TABLE st1 MODIFY TAG tag1 VARCHAR(20)");
|
run("ALTER TABLE st1 MODIFY TAG tag2 VARCHAR(30)");
|
||||||
clearAlterStbReq();
|
clearAlterStbReq();
|
||||||
|
|
||||||
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_TAG_NAME, 2, "tag1", 0, 0, "tag11");
|
setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_TAG_NAME, 2, "tag1", 0, 0, "tag11");
|
||||||
|
@ -196,6 +196,10 @@ TEST_F(ParserInitialATest, alterSTableSemanticCheck) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
run("ALTER TABLE st1 RENAME COLUMN c1 cc1", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
run("ALTER TABLE st1 RENAME COLUMN c1 cc1", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
||||||
|
|
||||||
|
run("ALTER TABLE st1 MODIFY COLUMN c2 NCHAR(10)", TSDB_CODE_PAR_INVALID_MODIFY_COL);
|
||||||
|
|
||||||
|
run("ALTER TABLE st1 MODIFY TAG tag2 NCHAR(10)", TSDB_CODE_PAR_INVALID_MODIFY_COL);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserInitialATest, alterTable) {
|
TEST_F(ParserInitialATest, alterTable) {
|
||||||
|
@ -336,6 +340,8 @@ TEST_F(ParserInitialATest, alterTableSemanticCheck) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
run("ALTER TABLE st1s1 RENAME COLUMN c1 cc1", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
run("ALTER TABLE st1s1 RENAME COLUMN c1 cc1", TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
||||||
|
|
||||||
|
run("ALTER TABLE st1s1 SET TAG tag2 = '123456789012345678901'", TSDB_CODE_PAR_WRONG_VALUE_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserInitialATest, alterUser) {
|
TEST_F(ParserInitialATest, alterUser) {
|
||||||
|
|
|
@ -548,12 +548,14 @@ TEST_F(ParserInitialCTest, createTable) {
|
||||||
"a14 NCHAR(30), a15 VARCHAR(50)) "
|
"a14 NCHAR(30), a15 VARCHAR(50)) "
|
||||||
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (MIN) FILE_FACTOR 0.1");
|
"TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (MIN) FILE_FACTOR 0.1");
|
||||||
|
|
||||||
run("CREATE TABLE IF NOT EXISTS t1 USING st1 TAGS(1, 'wxy')");
|
run("CREATE TABLE IF NOT EXISTS t1 USING st1 TAGS(1, 'wxy', NOW)");
|
||||||
|
|
||||||
run("CREATE TABLE "
|
run("CREATE TABLE "
|
||||||
"IF NOT EXISTS test.t1 USING test.st1 (tag1, tag2) TAGS(1, 'abc') "
|
"IF NOT EXISTS test.t1 USING test.st1 (tag1, tag2) TAGS(1, 'abc') "
|
||||||
"IF NOT EXISTS test.t2 USING test.st1 (tag1, tag2) TAGS(2, 'abc') "
|
"IF NOT EXISTS test.t2 USING test.st1 (tag1, tag2) TAGS(2, 'abc') "
|
||||||
"IF NOT EXISTS test.t3 USING test.st1 (tag1, tag2) TAGS(3, 'abc') ");
|
"IF NOT EXISTS test.t3 USING test.st1 (tag1, tag2) TAGS(3, 'abc') ");
|
||||||
|
|
||||||
|
// run("CREATE TABLE IF NOT EXISTS t1 USING st1 TAGS(1, 'wxy', NOW + 1S)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserInitialCTest, createTopic) {
|
TEST_F(ParserInitialCTest, createTopic) {
|
||||||
|
|
|
@ -245,8 +245,8 @@ TEST_F(InsertTest, autoCreateTableTest) {
|
||||||
setDatabase("root", "test");
|
setDatabase("root", "test");
|
||||||
|
|
||||||
bind(
|
bind(
|
||||||
"insert into st1s1 using st1 tags(1, 'wxy') values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, "
|
"insert into st1s1 using st1 tags(1, 'wxy', now) "
|
||||||
"\"guangzhou\")");
|
"values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")");
|
||||||
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
||||||
dumpReslut();
|
dumpReslut();
|
||||||
checkReslut(1, 3);
|
checkReslut(1, 3);
|
||||||
|
@ -257,8 +257,8 @@ TEST_F(InsertTest, autoCreateTableTest) {
|
||||||
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
|
||||||
|
|
||||||
bind(
|
bind(
|
||||||
"insert into st1s1 using st1 tags(1, 'wxy') values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, "
|
"insert into st1s1 using st1 tags(1, 'wxy', now) "
|
||||||
"\"guangzhou\")");
|
"values (now, 1, \"beijing\")(now+1s, 2, \"shanghai\")(now+2s, 3, \"guangzhou\")");
|
||||||
ASSERT_EQ(runAsync(), TSDB_CODE_SUCCESS);
|
ASSERT_EQ(runAsync(), TSDB_CODE_SUCCESS);
|
||||||
|
|
||||||
bind(
|
bind(
|
||||||
|
|
|
@ -219,6 +219,7 @@ TEST_F(ParserSelectTest, intervalSemanticCheck) {
|
||||||
run("SELECT HISTOGRAM(c1, 'log_bin', '{\"start\": -33,\"factor\": 55,\"count\": 5,\"infinity\": false}', 1) FROM t1 "
|
run("SELECT HISTOGRAM(c1, 'log_bin', '{\"start\": -33,\"factor\": 55,\"count\": 5,\"infinity\": false}', 1) FROM t1 "
|
||||||
"WHERE ts > TIMESTAMP '2022-04-01 00:00:00' and ts < TIMESTAMP '2022-04-30 23:59:59' INTERVAL(10s) FILL(NULL)",
|
"WHERE ts > TIMESTAMP '2022-04-01 00:00:00' and ts < TIMESTAMP '2022-04-30 23:59:59' INTERVAL(10s) FILL(NULL)",
|
||||||
TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC);
|
TSDB_CODE_PAR_FILL_NOT_ALLOWED_FUNC);
|
||||||
|
run("SELECT _WSTARTTS, _WENDTS, _WDURATION, sum(c1) FROM t1", TSDB_CODE_PAR_INVALID_WINDOW_PC);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserSelectTest, subquery) {
|
TEST_F(ParserSelectTest, subquery) {
|
||||||
|
@ -231,13 +232,22 @@ TEST_F(ParserSelectTest, subquery) {
|
||||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, ts FROM st1s1 PARTITION BY TBNAME INTERVAL(1m)) INTERVAL(1n)");
|
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, ts FROM st1s1 PARTITION BY TBNAME INTERVAL(1m)) INTERVAL(1n)");
|
||||||
|
|
||||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, _wstartts FROM st1s1 PARTITION BY TBNAME INTERVAL(1m)) INTERVAL(1n)");
|
run("SELECT SUM(a) FROM (SELECT MAX(c1) a, _wstartts FROM st1s1 PARTITION BY TBNAME INTERVAL(1m)) INTERVAL(1n)");
|
||||||
|
|
||||||
|
run("SELECT _C0 FROM (SELECT _ROWTS, ts FROM st1s1)");
|
||||||
|
|
||||||
|
run("SELECT ts FROM (SELECT t1.ts FROM st1s1 t1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserSelectTest, subquerySemanticCheck) {
|
TEST_F(ParserSelectTest, subquerySemanticCheck) {
|
||||||
useDb("root", "test");
|
useDb("root", "test");
|
||||||
|
|
||||||
run("SELECT SUM(a) FROM (SELECT MAX(c1) a FROM st1s1 INTERVAL(1m)) INTERVAL(1n)", TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY,
|
run("SELECT SUM(a) FROM (SELECT MAX(c1) a FROM st1s1 INTERVAL(1m)) INTERVAL(1n)",
|
||||||
PARSER_STAGE_TRANSLATE);
|
TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY);
|
||||||
|
|
||||||
|
run("SELECT ts FROM (SELECT t1.ts AS ts, t2.ts FROM st1s1 t1, st1s2 t2 WHERE t1.ts = t2.ts)",
|
||||||
|
TSDB_CODE_PAR_AMBIGUOUS_COLUMN);
|
||||||
|
|
||||||
|
run("SELECT ts FROM (SELECT ts AS c1 FROM st1s1 t1)", TSDB_CODE_PAR_INVALID_COLUMN);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserSelectTest, semanticCheck) {
|
TEST_F(ParserSelectTest, semanticCheck) {
|
||||||
|
|
|
@ -62,7 +62,7 @@ int32_t getLogLevel() { return g_logLevel; }
|
||||||
|
|
||||||
class ParserTestBaseImpl {
|
class ParserTestBaseImpl {
|
||||||
public:
|
public:
|
||||||
ParserTestBaseImpl(ParserTestBase* pBase) : pBase_(pBase) {}
|
ParserTestBaseImpl(ParserTestBase* pBase) : pBase_(pBase), sqlNo_(0) {}
|
||||||
|
|
||||||
void login(const std::string& user) { caseEnv_.user_ = user; }
|
void login(const std::string& user) { caseEnv_.user_ = user; }
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ class ParserTestBaseImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
void run(const string& sql, int32_t expect, ParserStage checkStage) {
|
void run(const string& sql, int32_t expect, ParserStage checkStage) {
|
||||||
|
++sqlNo_;
|
||||||
if (caseEnv_.nsql_ > 0) {
|
if (caseEnv_.nsql_ > 0) {
|
||||||
--(caseEnv_.nsql_);
|
--(caseEnv_.nsql_);
|
||||||
return;
|
return;
|
||||||
|
@ -174,7 +175,7 @@ class ParserTestBaseImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump() {
|
void dump() {
|
||||||
cout << "==========================================sql : [" << stmtEnv_.sql_ << "]" << endl;
|
cout << "========================================== " << sqlNo_ << " sql : [" << stmtEnv_.sql_ << "]" << endl;
|
||||||
if (!res_.parsedAst_.empty()) {
|
if (!res_.parsedAst_.empty()) {
|
||||||
cout << "raw syntax tree : " << endl;
|
cout << "raw syntax tree : " << endl;
|
||||||
cout << res_.parsedAst_ << endl;
|
cout << res_.parsedAst_ << endl;
|
||||||
|
@ -425,6 +426,7 @@ class ParserTestBaseImpl {
|
||||||
stmtEnv stmtEnv_;
|
stmtEnv stmtEnv_;
|
||||||
stmtRes res_;
|
stmtRes res_;
|
||||||
ParserTestBase* pBase_;
|
ParserTestBase* pBase_;
|
||||||
|
int32_t sqlNo_;
|
||||||
};
|
};
|
||||||
|
|
||||||
ParserTestBase::ParserTestBase() : impl_(new ParserTestBaseImpl(this)) {}
|
ParserTestBase::ParserTestBase() : impl_(new ParserTestBaseImpl(this)) {}
|
||||||
|
|
|
@ -416,6 +416,8 @@ static int32_t stbSplCreatePartAggNode(SAggLogicNode* pMergeAgg, SLogicNode** pO
|
||||||
pMergeAgg->node.pTargets = NULL;
|
pMergeAgg->node.pTargets = NULL;
|
||||||
SNodeList* pChildren = pMergeAgg->node.pChildren;
|
SNodeList* pChildren = pMergeAgg->node.pChildren;
|
||||||
pMergeAgg->node.pChildren = NULL;
|
pMergeAgg->node.pChildren = NULL;
|
||||||
|
SNode* pConditions = pMergeAgg->node.pConditions;
|
||||||
|
pMergeAgg->node.pConditions = NULL;
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
SAggLogicNode* pPartAgg = (SAggLogicNode*)nodesCloneNode((SNode*)pMergeAgg);
|
SAggLogicNode* pPartAgg = (SAggLogicNode*)nodesCloneNode((SNode*)pMergeAgg);
|
||||||
|
@ -434,6 +436,7 @@ static int32_t stbSplCreatePartAggNode(SAggLogicNode* pMergeAgg, SLogicNode** pO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
pMergeAgg->node.pConditions = pConditions;
|
||||||
pMergeAgg->node.pTargets = pTargets;
|
pMergeAgg->node.pTargets = pTargets;
|
||||||
pPartAgg->node.pChildren = pChildren;
|
pPartAgg->node.pChildren = pChildren;
|
||||||
|
|
||||||
|
|
|
@ -82,4 +82,6 @@ TEST_F(PlanGroupByTest, stable) {
|
||||||
run("SELECT COUNT(*) FROM st1");
|
run("SELECT COUNT(*) FROM st1");
|
||||||
|
|
||||||
run("SELECT COUNT(*) FROM st1 GROUP BY c1");
|
run("SELECT COUNT(*) FROM st1 GROUP BY c1");
|
||||||
|
|
||||||
|
run("SELECT SUM(c1) FROM st1 GROUP BY c2 HAVING SUM(c1) IS NOT NULL");
|
||||||
}
|
}
|
||||||
|
|
|
@ -566,9 +566,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSMA_RM_SKEY_IN_HASH, "Rm tsma skey in cac
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_INVALID_ENV, "Invalid rsma env")
|
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_INVALID_ENV, "Invalid rsma env")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_INVALID_STAT, "Invalid rsma state")
|
TAOS_DEFINE_ERROR(TSDB_CODE_RSMA_INVALID_STAT, "Invalid rsma state")
|
||||||
|
|
||||||
//indx
|
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_INDEX_REBUILD, "Index is rebuilding")
|
|
||||||
|
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_INDEX_REBUILDING, "Index is rebuilding")
|
||||||
|
|
||||||
#ifdef TAOS_ERROR_C
|
#ifdef TAOS_ERROR_C
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,20 +2,20 @@
|
||||||
#======================b1-start===============
|
#======================b1-start===============
|
||||||
|
|
||||||
# ---- user
|
# ---- user
|
||||||
#./test.sh -f tsim/user/basic1.sim
|
./test.sh -f tsim/user/basic1.sim
|
||||||
#./test.sh -f tsim/user/pass_alter.sim
|
./test.sh -f tsim/user/pass_alter.sim
|
||||||
#./test.sh -f tsim/user/pass_len.sim
|
./test.sh -f tsim/user/pass_len.sim
|
||||||
#./test.sh -f tsim/user/user_len.sim
|
./test.sh -f tsim/user/user_len.sim
|
||||||
#./test.sh -f tsim/user/privilege1.sim
|
./test.sh -f tsim/user/privilege1.sim
|
||||||
#./test.sh -f tsim/user/privilege2.sim#
|
./test.sh -f tsim/user/privilege2.sim
|
||||||
|
|
||||||
## ---- db
|
## ---- db
|
||||||
#./test.sh -f tsim/db/create_all_options.sim
|
./test.sh -f tsim/db/create_all_options.sim
|
||||||
#./test.sh -f tsim/db/alter_option.sim
|
./test.sh -f tsim/db/alter_option.sim
|
||||||
#./test.sh -f tsim/db/basic1.sim
|
./test.sh -f tsim/db/basic1.sim
|
||||||
#./test.sh -f tsim/db/basic2.sim
|
./test.sh -f tsim/db/basic2.sim
|
||||||
#./test.sh -f tsim/db/basic3.sim
|
./test.sh -f tsim/db/basic3.sim
|
||||||
#./test.sh -f tsim/db/basic6.sim
|
./test.sh -f tsim/db/basic6.sim
|
||||||
./test.sh -f tsim/db/basic7.sim
|
./test.sh -f tsim/db/basic7.sim
|
||||||
./test.sh -f tsim/db/error1.sim
|
./test.sh -f tsim/db/error1.sim
|
||||||
./test.sh -f tsim/db/taosdlog.sim
|
./test.sh -f tsim/db/taosdlog.sim
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
# ---- mnode
|
# ---- mnode
|
||||||
./test.sh -f tsim/mnode/basic1.sim
|
./test.sh -f tsim/mnode/basic1.sim
|
||||||
./test.sh -f tsim/mnode/basic2.sim
|
./test.sh -f tsim/mnode/basic2.sim
|
||||||
./test.sh -f tsim/mnode/basic3.sim
|
#./test.sh -f tsim/mnode/basic3.sim
|
||||||
./test.sh -f tsim/mnode/basic4.sim
|
./test.sh -f tsim/mnode/basic4.sim
|
||||||
./test.sh -f tsim/mnode/basic5.sim
|
./test.sh -f tsim/mnode/basic5.sim
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@
|
||||||
# ./test.sh -f tsim/stream/state0.sim
|
# ./test.sh -f tsim/stream/state0.sim
|
||||||
# ./test.sh -f tsim/stream/triggerInterval0.sim
|
# ./test.sh -f tsim/stream/triggerInterval0.sim
|
||||||
# ./test.sh -f tsim/stream/triggerSession0.sim
|
# ./test.sh -f tsim/stream/triggerSession0.sim
|
||||||
|
# ./test.sh -f tsim/stream/partitionby.sim
|
||||||
|
|
||||||
|
|
||||||
# ---- transaction
|
# ---- transaction
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sleep 50
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
sql create database test vgroups 4;
|
||||||
|
sql use test;
|
||||||
|
sql create stable st(ts timestamp, a int, b int , c int, d double) tags(ta int,tb int,tc int);
|
||||||
|
sql create table ts1 using st tags(1,1,1);
|
||||||
|
sql create table ts2 using st tags(2,2,2);
|
||||||
|
sql create table ts3 using st tags(3,2,2);
|
||||||
|
sql create table ts4 using st tags(4,2,2);
|
||||||
|
sql create stream stream_t1 trigger at_once into streamtST1 as select _wstartts, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5 from st partition by ta,tb,tc interval(10s);
|
||||||
|
|
||||||
|
sql insert into ts1 values(1648791213001,1,12,3,1.0);
|
||||||
|
sql insert into ts2 values(1648791213001,1,12,3,1.0);
|
||||||
|
|
||||||
|
sql insert into ts3 values(1648791213001,1,12,3,1.0);
|
||||||
|
sql insert into ts4 values(1648791213001,1,12,3,1.0);
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
|
loop0:
|
||||||
|
sleep 300
|
||||||
|
sql select * from streamtST1;
|
||||||
|
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 10 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $rows != 4 then
|
||||||
|
print =====rows=$rows
|
||||||
|
goto loop0
|
||||||
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
sql create database test1 vgroups 1;
|
||||||
|
sql use test1;
|
||||||
|
sql create stable st(ts timestamp,a int,b int,c int) tags(ta int,tb int,tc int);
|
||||||
|
sql create table ts1 using st tags(1,2,3);
|
||||||
|
sql create table ts2 using st tags(1,3,4);
|
||||||
|
sql create table ts3 using st tags(1,4,5);
|
||||||
|
|
||||||
|
sql create stream streams1 trigger at_once into streamt as select _wstartts, count(*) c1, count(a) c2 from st partition by ta,tb,tc interval(10s);
|
||||||
|
|
||||||
|
|
||||||
|
sql insert into ts1 values(1648791211000,1,2,3);
|
||||||
|
|
||||||
|
sql insert into ts2 values(1648791211000,1,2,3);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
|
loop0:
|
||||||
|
sleep 300
|
||||||
|
sql select * from streamt;
|
||||||
|
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 10 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $rows != 2 then
|
||||||
|
print =====rows=$rows
|
||||||
|
goto loop0
|
||||||
|
endi
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -6,7 +6,7 @@ python3 .\test.py -f 0-others\telemetry.py
|
||||||
python3 .\test.py -f 0-others\taosdMonitor.py
|
python3 .\test.py -f 0-others\taosdMonitor.py
|
||||||
python3 .\test.py -f 0-others\udfTest.py
|
python3 .\test.py -f 0-others\udfTest.py
|
||||||
python3 .\test.py -f 0-others\udf_create.py
|
python3 .\test.py -f 0-others\udf_create.py
|
||||||
@REM python3 .\test.py -f 0-others\udf_restart_taosd.py
|
python3 .\test.py -f 0-others\udf_restart_taosd.py
|
||||||
python3 .\test.py -f 0-others\cachelast.py
|
python3 .\test.py -f 0-others\cachelast.py
|
||||||
|
|
||||||
python3 .\test.py -f 0-others\user_control.py
|
python3 .\test.py -f 0-others\user_control.py
|
||||||
|
@ -38,7 +38,7 @@ python3 .\test.py -f 2-query\concat_ws.py
|
||||||
python3 .\test.py -f 2-query\concat_ws2.py
|
python3 .\test.py -f 2-query\concat_ws2.py
|
||||||
python3 .\test.py -f 2-query\check_tsdb.py
|
python3 .\test.py -f 2-query\check_tsdb.py
|
||||||
python3 .\test.py -f 2-query\spread.py
|
python3 .\test.py -f 2-query\spread.py
|
||||||
@REM python3 .\test.py -f 2-query\hyperloglog.py
|
python3 .\test.py -f 2-query\hyperloglog.py
|
||||||
|
|
||||||
python3 .\test.py -f 2-query\timezone.py
|
python3 .\test.py -f 2-query\timezone.py
|
||||||
python3 .\test.py -f 2-query\Now.py
|
python3 .\test.py -f 2-query\Now.py
|
||||||
|
@ -82,7 +82,7 @@ python3 .\test.py -f 2-query\elapsed.py
|
||||||
python3 .\test.py -f 2-query\csum.py
|
python3 .\test.py -f 2-query\csum.py
|
||||||
python3 .\test.py -f 2-query\mavg.py
|
python3 .\test.py -f 2-query\mavg.py
|
||||||
python3 .\test.py -f 2-query\diff.py
|
python3 .\test.py -f 2-query\diff.py
|
||||||
@REM python3 .\test.py -f 2-query\sample.py
|
python3 .\test.py -f 2-query\sample.py
|
||||||
python3 .\test.py -f 2-query\function_diff.py
|
python3 .\test.py -f 2-query\function_diff.py
|
||||||
python3 .\test.py -f 2-query\unique.py
|
python3 .\test.py -f 2-query\unique.py
|
||||||
python3 .\test.py -f 2-query\stateduration.py
|
python3 .\test.py -f 2-query\stateduration.py
|
||||||
|
@ -91,7 +91,7 @@ python3 .\test.py -f 2-query\statecount.py
|
||||||
|
|
||||||
python3 .\test.py -f 7-tmq\basic5.py
|
python3 .\test.py -f 7-tmq\basic5.py
|
||||||
python3 .\test.py -f 7-tmq\subscribeDb.py
|
python3 .\test.py -f 7-tmq\subscribeDb.py
|
||||||
@REM python3 .\test.py -f 7-tmq\subscribeDb0.py
|
python3 .\test.py -f 7-tmq\subscribeDb0.py
|
||||||
python3 .\test.py -f 7-tmq\subscribeDb1.py
|
python3 .\test.py -f 7-tmq\subscribeDb1.py
|
||||||
python3 .\test.py -f 7-tmq\subscribeStb.py
|
python3 .\test.py -f 7-tmq\subscribeStb.py
|
||||||
python3 .\test.py -f 7-tmq\subscribeStb0.py
|
python3 .\test.py -f 7-tmq\subscribeStb0.py
|
||||||
|
|
Loading…
Reference in New Issue