diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 1f205b3f11..4abf8c27fd 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -119,9 +119,9 @@ void mndPostProcessQueryMsg(SRpcMsg *pMsg); */ void mndGenerateMachineCode(); -void mndDumpSdb(); +int32_t mndDumpSdb(); -void mndDeleteTrans(); +int32_t mndDeleteTrans(); #ifdef __cplusplus } diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 1b02203c07..5f9a4a1110 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -57,7 +57,6 @@ typedef struct SExprNode { char aliasName[TSDB_COL_NAME_LEN]; char userAlias[TSDB_COL_NAME_LEN]; SArray* pAssociation; - bool orderAlias; bool asAlias; bool asParam; bool asPosition; diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index aeaa3bef8b..4c1a484c20 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -736,6 +736,16 @@ static void monitorSendAllSlowLogFromTempDir(int64_t clusterId) { continue; } char* tmp = taosStrdup(filename); + if (tmp == NULL) { + tscError("failed to dup string:%s since %s", filename, terrstr()); + if (taosUnLockFile(pFile) != 0) { + tscError("failed to unlock file:%s, terrno:%d", filename, terrno); + } + if (taosCloseFile(&(pFile)) != 0) { + tscError("failed to close file:%s, terrno:%d", filename, terrno); + } + continue; + } monitorSendSlowLogAtBeginning(clusterId, &tmp, pFile, 0); taosMemoryFree(tmp); } diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 082daa805c..6a19f61383 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -1939,6 +1939,10 @@ int32_t smlClearForRerun(SSmlHandle *info) { return TSDB_CODE_SML_INVALID_DATA; } info->lines = (SSmlLineInfo *)taosMemoryCalloc(info->lineNum, sizeof(SSmlLineInfo)); + if (unlikely(info->lines == NULL)) { + uError("SML:0x%" PRIx64 " info->lines == NULL", info->id); + return terrno; + } } (void)memset(&info->preLine, 0, sizeof(SSmlLineInfo)); @@ -1971,10 +1975,14 @@ static bool getLine(SSmlHandle *info, char *lines[], char **rawLine, char *rawLi if (*rawLine != NULL && (uDebugFlag & DEBUG_DEBUG)) { char *print = taosMemoryCalloc(*len + 1, 1); - (void)memcpy(print, *tmp, *len); - uDebug("SML:0x%" PRIx64 " smlParseLine is raw, numLines:%d, protocol:%d, len:%d, data:%s", info->id, numLines, - info->protocol, *len, print); - taosMemoryFree(print); + if (print != NULL){ + (void)memcpy(print, *tmp, *len); + uDebug("SML:0x%" PRIx64 " smlParseLine is raw, numLines:%d, protocol:%d, len:%d, data:%s", info->id, numLines, + info->protocol, *len, print); + taosMemoryFree(print); + } else{ + uError("SML:0x%" PRIx64 " smlParseLine taosMemoryCalloc failed", info->id); + } } else { uDebug("SML:0x%" PRIx64 " smlParseLine is not numLines:%d, protocol:%d, len:%d, data:%s", info->id, numLines, info->protocol, *len, *tmp); diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index 8836fce31a..8da7367c30 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -300,6 +300,7 @@ void tmq_conf_destroy(tmq_conf_t* conf) { tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value) { int32_t code = 0; if (conf == NULL || key == NULL || value == NULL) { + tscError("tmq_conf_set null, conf:%p key:%p value:%p", conf, key, value); return TMQ_CONF_INVALID; } if (strcasecmp(key, "group.id") == 0) { @@ -320,6 +321,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value conf->autoCommit = false; return TMQ_CONF_OK; } else { + tscError("invalid value for enable.auto.commit: %s", value); return TMQ_CONF_INVALID; } } @@ -328,6 +330,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value int64_t tmp; code = taosStr2int64(value, &tmp); if (tmp < 0 || code != 0) { + tscError("invalid value for auto.commit.interval.ms: %s", value); return TMQ_CONF_INVALID; } conf->autoCommitInterval = (tmp > INT32_MAX ? INT32_MAX : tmp); @@ -338,6 +341,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value int64_t tmp; code = taosStr2int64(value, &tmp); if (tmp < 6000 || tmp > 1800000 || code != 0) { + tscError("invalid value for session.timeout.ms: %s", value); return TMQ_CONF_INVALID; } conf->sessionTimeoutMs = tmp; @@ -348,6 +352,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value int64_t tmp; code = taosStr2int64(value, &tmp); if (tmp < 1000 || tmp >= conf->sessionTimeoutMs || code != 0) { + tscError("invalid value for heartbeat.interval.ms: %s", value); return TMQ_CONF_INVALID; } conf->heartBeatIntervalMs = tmp; @@ -358,6 +363,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value int32_t tmp; code = taosStr2int32(value, &tmp); if (tmp < 1000 || code != 0) { + tscError("invalid value for max.poll.interval.ms: %s", value); return TMQ_CONF_INVALID; } conf->maxPollIntervalMs = tmp; @@ -375,6 +381,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value conf->resetOffset = TMQ_OFFSET__RESET_LATEST; return TMQ_CONF_OK; } else { + tscError("invalid value for auto.offset.reset: %s", value); return TMQ_CONF_INVALID; } } @@ -387,6 +394,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value conf->withTbName = false; return TMQ_CONF_OK; } else { + tscError("invalid value for msg.with.table.name: %s", value); return TMQ_CONF_INVALID; } } @@ -399,22 +407,38 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value conf->snapEnable = false; return TMQ_CONF_OK; } else { + tscError("invalid value for experimental.snapshot.enable: %s", value); return TMQ_CONF_INVALID; } } if (strcasecmp(key, "td.connect.ip") == 0) { - conf->ip = taosStrdup(value); + void *tmp = taosStrdup(value); + if (tmp == NULL) { + tscError("tmq_conf_set out of memory:%d", terrno); + return TMQ_CONF_INVALID; + } + conf->ip = tmp; return TMQ_CONF_OK; } if (strcasecmp(key, "td.connect.user") == 0) { - conf->user = taosStrdup(value); + void *tmp = taosStrdup(value); + if (tmp == NULL) { + tscError("tmq_conf_set out of memory:%d", terrno); + return TMQ_CONF_INVALID; + } + conf->user = tmp; return TMQ_CONF_OK; } if (strcasecmp(key, "td.connect.pass") == 0) { - conf->pass = taosStrdup(value); + void *tmp = taosStrdup(value); + if (tmp == NULL) { + tscError("tmq_conf_set out of memory:%d", terrno); + return TMQ_CONF_INVALID; + } + conf->pass = tmp; return TMQ_CONF_OK; } @@ -422,6 +446,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value int64_t tmp; code = taosStr2int64(value, &tmp); if (tmp <= 0 || tmp > 65535 || code != 0) { + tscError("invalid value for td.connect.port: %s", value); return TMQ_CONF_INVALID; } @@ -437,6 +462,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value conf->replayEnable = false; return TMQ_CONF_OK; } else { + tscError("invalid value for enable.replay: %s", value); return TMQ_CONF_INVALID; } } @@ -458,6 +484,7 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value return TMQ_CONF_OK; } + tscError("unknown key: %s", key); return TMQ_CONF_UNKNOWN; } @@ -468,7 +495,11 @@ int32_t tmq_list_append(tmq_list_t* list, const char* src) { SArray* container = &list->container; if (src == NULL || src[0] == 0) return TSDB_CODE_INVALID_PARA; char* topic = taosStrdup(src); - if (taosArrayPush(container, &topic) == NULL) return TSDB_CODE_INVALID_PARA; + if (topic == NULL) return terrno; + if (taosArrayPush(container, &topic) == NULL) { + taosMemoryFree(topic); + return terrno; + } return 0; } @@ -947,13 +978,13 @@ void tmqSendHbReq(void* param, void* tmrId) { int32_t tlen = tSerializeSMqHbReq(NULL, 0, &req); if (tlen < 0) { - tscError("tSerializeSMqHbReq failed"); + tscError("tSerializeSMqHbReq failed, size:%d", tlen); goto OVER; } void* pReq = taosMemoryCalloc(1, tlen); - if (tlen < 0) { - tscError("failed to malloc MqHbReq msg, size:%d", tlen); + if (pReq == NULL) { + tscError("failed to malloc MqHbReq msg, code:%d", terrno); goto OVER; } @@ -3514,6 +3545,10 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a } (void)taosThreadMutexInit(&pCommon->mutex, 0); pCommon->pTopicName = taosStrdup(pTopic->topicName); + if (pCommon->pTopicName == NULL) { + code = terrno; + goto end; + } pCommon->consumerId = tmq->consumerId; for (int32_t i = 0; i < (*numOfAssignment); ++i) { diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 810129e694..a3220706c7 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1092,6 +1092,9 @@ int32_t taosSetSlowLogScope(char *pScopeStr, int32_t *pScope) { while((scope = strsep(&pScopeStr, "|")) != NULL){ taosMemoryFreeClear(tmp); tmp = taosStrdup(scope); + if (tmp == NULL) { + TAOS_RETURN(terrno); + } (void)strtrim(tmp); if (0 == strcasecmp(tmp, "all")) { slowScope |= SLOW_LOG_TYPE_ALL; diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 9f5db9b0eb..1fb5271a0e 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -433,7 +433,8 @@ int mainWindows(int argc, char **argv) { } if (global.dumpSdb) { - mndDumpSdb(); + int32_t code = 0; + TAOS_CHECK_RETURN(mndDumpSdb()); taosCleanupCfg(); taosCloseLog(); taosCleanupArgs(); @@ -442,6 +443,7 @@ int mainWindows(int argc, char **argv) { } if (global.deleteTrans) { + int32_t code = 0; TdFilePtr pFile; if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) { printf("failed to generate encrypt code since taosd is running, please stop it first, reason:%s", @@ -449,7 +451,7 @@ int mainWindows(int argc, char **argv) { return code; } - mndDeleteTrans(); + TAOS_CHECK_RETURN(mndDeleteTrans()); taosCleanupCfg(); taosCloseLog(); taosCleanupArgs(); diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 986bbc4ac8..e204b5d4aa 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -24,6 +24,12 @@ static inline void dmBuildMnodeRedirectRsp(SDnode *pDnode, SRpcMsg *pMsg) { SEpSet epSet = {0}; dmGetMnodeEpSetForRedirect(&pDnode->data, pMsg, &epSet); + if (epSet.numOfEps <= 1) { + pMsg->pCont = NULL; + pMsg->code = TSDB_CODE_MNODE_NOT_FOUND; + return; + } + int32_t contLen = tSerializeSEpSet(NULL, 0, &epSet); pMsg->pCont = rpcMallocCont(contLen); if (pMsg->pCont == NULL) { @@ -109,7 +115,8 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) { int32_t svrVer = 0; (void)taosVersionStrToInt(version, &svrVer); if ((code = taosCheckVersionCompatible(pRpc->info.cliVer, svrVer, 3)) != 0) { - dError("Version not compatible, cli ver: %d, svr ver: %d, ip:0x%x", pRpc->info.cliVer, svrVer, pRpc->info.conn.clientIp); + dError("Version not compatible, cli ver: %d, svr ver: %d, ip:0x%x", pRpc->info.cliVer, svrVer, + pRpc->info.conn.clientIp); goto _OVER; } @@ -437,7 +444,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) { pTrans->statusRpc = rpcOpen(&rpcInit); if (pTrans->statusRpc == NULL) { - dError("failed to init dnode rpc status client since %s", tstrerror(terrno)); + dError("failed to init dnode rpc status client since %s", tstrerror(terrno)); return terrno; } diff --git a/source/dnode/mnode/impl/inc/mndStream.h b/source/dnode/mnode/impl/inc/mndStream.h index dceb86c963..b97eaf31d1 100644 --- a/source/dnode/mnode/impl/inc/mndStream.h +++ b/source/dnode/mnode/impl/inc/mndStream.h @@ -35,6 +35,7 @@ extern "C" { #define MND_STREAM_TASK_UPDATE_NAME "stream-task-update" #define MND_STREAM_CHKPT_UPDATE_NAME "stream-chkpt-update" #define MND_STREAM_CHKPT_CONSEN_NAME "stream-chkpt-consen" +#define MND_STREAM_RESTART_NAME "stream-restart" typedef struct SStreamTransInfo { int64_t startTime; @@ -120,6 +121,7 @@ int32_t mndStreamGetRelTrans(SMnode *pMnode, int64_t streamId); int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams); int32_t mndGetNumOfStreamTasks(const SStreamObj *pStream); int32_t mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady, SArray** pList); +void mndDestroyVgroupChangeInfo(SVgroupChangeInfo *pInfo); void mndKillTransImpl(SMnode *pMnode, int32_t transId, const char *pDbName); int32_t setTransAction(STrans *pTrans, void *pCont, int32_t contLen, int32_t msgType, const SEpSet *pEpset, int32_t retryCode, int32_t acceptCode); @@ -127,31 +129,39 @@ int32_t doCreateTrans(SMnode *pMnode, SStreamObj *pStream, SRpcMsg *pReq, ETrnC const char *pMsg, STrans **pTrans1); int32_t mndPersistTransLog(SStreamObj *pStream, STrans *pTrans, int32_t status); SSdbRaw *mndStreamActionEncode(SStreamObj *pStream); -void killAllCheckpointTrans(SMnode *pMnode, SVgroupChangeInfo *pChangeInfo); int32_t mndStreamSetUpdateEpsetAction(SMnode *pMnode, SStreamObj *pStream, SVgroupChangeInfo *pInfo, STrans *pTrans); int32_t mndGetStreamObj(SMnode *pMnode, int64_t streamId, SStreamObj** pStream); +bool mndStreamNodeIsUpdated(SMnode *pMnode); + int32_t extractNodeEpset(SMnode *pMnode, SEpSet *pEpSet, bool *hasEpset, int32_t taskId, int32_t nodeId); int32_t mndProcessStreamHb(SRpcMsg *pReq); -void saveTaskAndNodeInfoIntoBuf(SStreamObj *pStream, SStreamExecInfo *pExecNode); int32_t extractStreamNodeList(SMnode *pMnode); int32_t mndStreamSetResumeAction(STrans *pTrans, SMnode *pMnode, SStreamObj *pStream, int8_t igUntreated); int32_t mndStreamSetPauseAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream); int32_t mndStreamSetDropAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream); int32_t mndStreamSetDropActionFromList(SMnode *pMnode, STrans *pTrans, SArray *pList); int32_t mndStreamSetResetTaskAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream); -int32_t mndCreateStreamResetStatusTrans(SMnode *pMnode, SStreamObj *pStream); int32_t mndStreamSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream); +int32_t mndCreateStreamResetStatusTrans(SMnode *pMnode, SStreamObj *pStream); +int32_t mndStreamSetChkptIdAction(SMnode *pMnode, STrans *pTrans, SStreamTask* pTask, int64_t checkpointId, int64_t ts); +int32_t mndStreamSetRestartAction(SMnode* pMnode, STrans *pTrans, SStreamObj* pStream); +int32_t mndStreamSetCheckpointAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, int64_t checkpointId, + int8_t mndTrigger); int32_t mndCreateStreamChkptInfoUpdateTrans(SMnode *pMnode, SStreamObj *pStream, SArray *pChkptInfoList); int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq); int32_t mndCreateSetConsensusChkptIdTrans(SMnode *pMnode, SStreamObj *pStream, int32_t taskId, int64_t checkpointId, int64_t ts); void removeTasksInBuf(SArray *pTaskIds, SStreamExecInfo *pExecInfo); +int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList, + SVgroupChangeInfo *pInfo); +void killAllCheckpointTrans(SMnode *pMnode, SVgroupChangeInfo *pChangeInfo); int32_t createStreamTaskIter(SStreamObj *pStream, SStreamTaskIter **pIter); void destroyStreamTaskIter(SStreamTaskIter *pIter); bool streamTaskIterNextTask(SStreamTaskIter *pIter); int32_t streamTaskIterGetCurrent(SStreamTaskIter *pIter, SStreamTask **pTask); + int32_t mndInitExecInfo(); void mndInitStreamExecInfo(SMnode *pMnode, SStreamExecInfo *pExecInfo); void mndStreamResetInitTaskListLoadFlag(); diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 9704ccaa83..4365b83f86 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -463,6 +463,15 @@ static void freeItem(void *param) { } } +#define ADD_TOPIC_TO_ARRAY(element, array) \ +char *newTopicCopy = taosStrdup(element); \ +MND_TMQ_NULL_CHECK(newTopicCopy);\ +if (taosArrayPush(pConsumerNew->array, &newTopicCopy) == NULL){\ + taosMemoryFree(newTopicCopy);\ + code = terrno;\ + goto END;\ +} + static int32_t getTopicAddDelete(SMqConsumerObj *pExistedConsumer, SMqConsumerObj *pConsumerNew){ int32_t code = 0; pConsumerNew->rebNewTopics = taosArrayInit(0, sizeof(void *)); @@ -477,15 +486,13 @@ static int32_t getTopicAddDelete(SMqConsumerObj *pExistedConsumer, SMqConsumerOb if (i >= oldTopicNum) { void* tmp = taosArrayGetP(pConsumerNew->assignedTopics, j); MND_TMQ_NULL_CHECK(tmp); - char *newTopicCopy = taosStrdup(tmp); - MND_TMQ_NULL_CHECK(taosArrayPush(pConsumerNew->rebNewTopics, &newTopicCopy)); + ADD_TOPIC_TO_ARRAY(tmp, rebNewTopics); j++; continue; } else if (j >= newTopicNum) { void* tmp = taosArrayGetP(pExistedConsumer->currentTopics, i); MND_TMQ_NULL_CHECK(tmp); - char *oldTopicCopy = taosStrdup(tmp); - MND_TMQ_NULL_CHECK(taosArrayPush(pConsumerNew->rebRemovedTopics, &oldTopicCopy)); + ADD_TOPIC_TO_ARRAY(tmp, rebRemovedTopics); i++; continue; } else { @@ -499,13 +506,11 @@ static int32_t getTopicAddDelete(SMqConsumerObj *pExistedConsumer, SMqConsumerOb j++; continue; } else if (comp < 0) { - char *oldTopicCopy = taosStrdup(oldTopic); - MND_TMQ_NULL_CHECK(taosArrayPush(pConsumerNew->rebRemovedTopics, &oldTopicCopy)); + ADD_TOPIC_TO_ARRAY(oldTopic, rebRemovedTopics); i++; continue; } else { - char *newTopicCopy = taosStrdup(newTopic); - MND_TMQ_NULL_CHECK(taosArrayPush(pConsumerNew->rebNewTopics, &newTopicCopy)); + ADD_TOPIC_TO_ARRAY(newTopic, rebNewTopics); j++; continue; } @@ -789,6 +794,9 @@ static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer, return TSDB_CODE_TMQ_INVALID_MSG; } char *pNewTopic = taosStrdup(tmp); + if (pNewTopic == NULL) { + return terrno; + } removeFromTopicList(pOldConsumer->rebNewTopics, pNewTopic, pOldConsumer->consumerId, "new"); bool existing = existInCurrentTopicList(pOldConsumer, pNewTopic); if (existing) { diff --git a/source/dnode/mnode/impl/src/mndDump.c b/source/dnode/mnode/impl/src/mndDump.c index 7613282ef8..d1dd99b319 100644 --- a/source/dnode/mnode/impl/src/mndDump.c +++ b/source/dnode/mnode/impl/src/mndDump.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "mndDb.h" #include "mndInt.h" +#include "mndShow.h" #include "mndStb.h" #include "sdb.h" #include "tconfig.h" @@ -46,7 +47,9 @@ char *i642str(int64_t val) { } void dumpFunc(SSdb *pSdb, SJson *json) { - void *pIter = NULL; + int32_t code = 0; + int32_t lino = 0; + void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "funcs"); while (1) { @@ -55,26 +58,30 @@ void dumpFunc(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", pObj->name); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "funcType", i642str(pObj->funcType)); - (void)tjsonAddStringToObject(item, "scriptType", i642str(pObj->scriptType)); - (void)tjsonAddStringToObject(item, "align", i642str(pObj->align)); - (void)tjsonAddStringToObject(item, "outputType", i642str(pObj->outputType)); - (void)tjsonAddStringToObject(item, "outputLen", i642str(pObj->outputLen)); - (void)tjsonAddStringToObject(item, "bufSize", i642str(pObj->bufSize)); - (void)tjsonAddStringToObject(item, "signature", i642str(pObj->signature)); - (void)tjsonAddStringToObject(item, "commentSize", i642str(pObj->commentSize)); - (void)tjsonAddStringToObject(item, "codeSize", i642str(pObj->codeSize)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", pObj->name), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "funcType", i642str(pObj->funcType)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "scriptType", i642str(pObj->scriptType)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "align", i642str(pObj->align)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "outputType", i642str(pObj->outputType)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "outputLen", i642str(pObj->outputLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "bufSize", i642str(pObj->bufSize)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "signature", i642str(pObj->signature)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "commentSize", i642str(pObj->commentSize)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "codeSize", i642str(pObj->codeSize)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump func info at line:%d since %s", lino, tstrerror(code)); } void dumpDb(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonCreateObject(); - (void)tjsonAddItemToObject(json, "dbs", items); + TAOS_CHECK_GOTO(tjsonAddItemToObject(json, "dbs", items), &lino, _OVER); while (1) { SDbObj *pObj = NULL; @@ -82,65 +89,86 @@ void dumpDb(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToObject(items, "db", item); + RETRIEVE_CHECK_GOTO(tjsonAddItemToObject(items, "db", item), pObj, &lino, _OVER); - (void)tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)); - (void)tjsonAddStringToObject(item, "acct", pObj->acct); - (void)tjsonAddStringToObject(item, "createUser", pObj->createUser); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "uid", i642str(pObj->uid)); - (void)tjsonAddStringToObject(item, "cfgVersion", i642str(pObj->cfgVersion)); - (void)tjsonAddStringToObject(item, "vgVersion", i642str(pObj->vgVersion)); - (void)tjsonAddStringToObject(item, "numOfVgroups", i642str(pObj->cfg.numOfVgroups)); - (void)tjsonAddStringToObject(item, "numOfStables", i642str(pObj->cfg.numOfStables)); - (void)tjsonAddStringToObject(item, "buffer", i642str(pObj->cfg.buffer)); - (void)tjsonAddStringToObject(item, "pageSize", i642str(pObj->cfg.pageSize)); - (void)tjsonAddStringToObject(item, "pages", i642str(pObj->cfg.pages)); - (void)tjsonAddStringToObject(item, "cacheLastSize", i642str(pObj->cfg.cacheLastSize)); - (void)tjsonAddStringToObject(item, "daysPerFile", i642str(pObj->cfg.daysPerFile)); - (void)tjsonAddStringToObject(item, "daysToKeep0", i642str(pObj->cfg.daysToKeep0)); - (void)tjsonAddStringToObject(item, "daysToKeep1", i642str(pObj->cfg.daysToKeep1)); - (void)tjsonAddStringToObject(item, "daysToKeep2", i642str(pObj->cfg.daysToKeep2)); - (void)tjsonAddStringToObject(item, "minRows", i642str(pObj->cfg.minRows)); - (void)tjsonAddStringToObject(item, "maxRows", i642str(pObj->cfg.maxRows)); - (void)tjsonAddStringToObject(item, "precision", i642str(pObj->cfg.precision)); - (void)tjsonAddStringToObject(item, "compression", i642str(pObj->cfg.compression)); - (void)tjsonAddStringToObject(item, "encryptAlgorithm", i642str(pObj->cfg.encryptAlgorithm)); - (void)tjsonAddStringToObject(item, "replications", i642str(pObj->cfg.replications)); - (void)tjsonAddStringToObject(item, "strict", i642str(pObj->cfg.strict)); - (void)tjsonAddStringToObject(item, "cacheLast", i642str(pObj->cfg.cacheLast)); - (void)tjsonAddStringToObject(item, "hashMethod", i642str(pObj->cfg.hashMethod)); - (void)tjsonAddStringToObject(item, "hashPrefix", i642str(pObj->cfg.hashPrefix)); - (void)tjsonAddStringToObject(item, "hashSuffix", i642str(pObj->cfg.hashSuffix)); - (void)tjsonAddStringToObject(item, "sstTrigger", i642str(pObj->cfg.sstTrigger)); - (void)tjsonAddStringToObject(item, "tsdbPageSize", i642str(pObj->cfg.tsdbPageSize)); - (void)tjsonAddStringToObject(item, "schemaless", i642str(pObj->cfg.schemaless)); - (void)tjsonAddStringToObject(item, "walLevel", i642str(pObj->cfg.walLevel)); - (void)tjsonAddStringToObject(item, "walFsyncPeriod", i642str(pObj->cfg.walFsyncPeriod)); - (void)tjsonAddStringToObject(item, "walRetentionPeriod", i642str(pObj->cfg.walRetentionPeriod)); - (void)tjsonAddStringToObject(item, "walRetentionSize", i642str(pObj->cfg.walRetentionSize)); - (void)tjsonAddStringToObject(item, "walRollPeriod", i642str(pObj->cfg.walRollPeriod)); - (void)tjsonAddStringToObject(item, "walSegmentSize", i642str(pObj->cfg.walSegmentSize)); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "acct", pObj->acct), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createUser", pObj->createUser), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "uid", i642str(pObj->uid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "cfgVersion", i642str(pObj->cfgVersion)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "vgVersion", i642str(pObj->vgVersion)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfVgroups", i642str(pObj->cfg.numOfVgroups)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfStables", i642str(pObj->cfg.numOfStables)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "buffer", i642str(pObj->cfg.buffer)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "pageSize", i642str(pObj->cfg.pageSize)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "pages", i642str(pObj->cfg.pages)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "cacheLastSize", i642str(pObj->cfg.cacheLastSize)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "daysPerFile", i642str(pObj->cfg.daysPerFile)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "daysToKeep0", i642str(pObj->cfg.daysToKeep0)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "daysToKeep1", i642str(pObj->cfg.daysToKeep1)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "daysToKeep2", i642str(pObj->cfg.daysToKeep2)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "minRows", i642str(pObj->cfg.minRows)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "maxRows", i642str(pObj->cfg.maxRows)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "precision", i642str(pObj->cfg.precision)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "compression", i642str(pObj->cfg.compression)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "encryptAlgorithm", i642str(pObj->cfg.encryptAlgorithm)), pObj, + &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "replications", i642str(pObj->cfg.replications)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "strict", i642str(pObj->cfg.strict)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "cacheLast", i642str(pObj->cfg.cacheLast)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "hashMethod", i642str(pObj->cfg.hashMethod)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "hashPrefix", i642str(pObj->cfg.hashPrefix)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "hashSuffix", i642str(pObj->cfg.hashSuffix)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sstTrigger", i642str(pObj->cfg.sstTrigger)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "tsdbPageSize", i642str(pObj->cfg.tsdbPageSize)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "schemaless", i642str(pObj->cfg.schemaless)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walLevel", i642str(pObj->cfg.walLevel)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walFsyncPeriod", i642str(pObj->cfg.walFsyncPeriod)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walRetentionPeriod", i642str(pObj->cfg.walRetentionPeriod)), pObj, + &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walRetentionSize", i642str(pObj->cfg.walRetentionSize)), pObj, + &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walRollPeriod", i642str(pObj->cfg.walRollPeriod)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walSegmentSize", i642str(pObj->cfg.walSegmentSize)), pObj, &lino, + _OVER); - (void)tjsonAddStringToObject(item, "numOfRetensions", i642str(pObj->cfg.numOfRetensions)); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfRetensions", i642str(pObj->cfg.numOfRetensions)), pObj, + &lino, _OVER); for (int32_t i = 0; i < pObj->cfg.numOfRetensions; ++i) { SJson *rentensions = tjsonAddArrayToObject(item, "rentensions"); SJson *rentension = tjsonCreateObject(); - (void)tjsonAddItemToArray(rentensions, rentension); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(rentensions, rentension), pObj, &lino, _OVER); SRetention *pRetension = taosArrayGet(pObj->cfg.pRetensions, i); - (void)tjsonAddStringToObject(item, "freq", i642str(pRetension->freq)); - (void)tjsonAddStringToObject(item, "freqUnit", i642str(pRetension->freqUnit)); - (void)tjsonAddStringToObject(item, "keep", i642str(pRetension->keep)); - (void)tjsonAddStringToObject(item, "keepUnit", i642str(pRetension->keepUnit)); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "freq", i642str(pRetension->freq)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "freqUnit", i642str(pRetension->freqUnit)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "keep", i642str(pRetension->keep)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "keepUnit", i642str(pRetension->keepUnit)), pObj, &lino, _OVER); } sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump db info at line:%d since %s", lino, tstrerror(code)); } void dumpStb(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "stbs"); @@ -150,62 +178,67 @@ void dumpStb(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", mndGetStbStr(pObj->name)); - (void)tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->db)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "uid", i642str(pObj->uid)); - (void)tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)); - (void)tjsonAddStringToObject(item, "tagVer", i642str(pObj->tagVer)); - (void)tjsonAddStringToObject(item, "colVer", i642str(pObj->colVer)); - (void)tjsonAddStringToObject(item, "smaVer", i642str(pObj->smaVer)); - (void)tjsonAddStringToObject(item, "nextColId", i642str(pObj->nextColId)); - (void)tjsonAddStringToObject(item, "watermark1", i642str(pObj->watermark[0])); - (void)tjsonAddStringToObject(item, "watermark2", i642str(pObj->watermark[1])); - (void)tjsonAddStringToObject(item, "maxdelay0", i642str(pObj->maxdelay[0])); - (void)tjsonAddStringToObject(item, "maxdelay1", i642str(pObj->maxdelay[1])); - (void)tjsonAddStringToObject(item, "ttl", i642str(pObj->ttl)); - (void)tjsonAddStringToObject(item, "numOfFuncs", i642str(pObj->numOfFuncs)); - (void)tjsonAddStringToObject(item, "commentLen", i642str(pObj->commentLen)); - (void)tjsonAddStringToObject(item, "ast1Len", i642str(pObj->ast1Len)); - (void)tjsonAddStringToObject(item, "ast2Len", i642str(pObj->ast2Len)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetStbStr(pObj->name)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->db)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "uid", i642str(pObj->uid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "tagVer", i642str(pObj->tagVer)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "colVer", i642str(pObj->colVer)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "smaVer", i642str(pObj->smaVer)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "nextColId", i642str(pObj->nextColId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "watermark1", i642str(pObj->watermark[0])), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "watermark2", i642str(pObj->watermark[1])), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "maxdelay0", i642str(pObj->maxdelay[0])), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "maxdelay1", i642str(pObj->maxdelay[1])), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "ttl", i642str(pObj->ttl)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfFuncs", i642str(pObj->numOfFuncs)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "commentLen", i642str(pObj->commentLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "ast1Len", i642str(pObj->ast1Len)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "ast2Len", i642str(pObj->ast2Len)), pObj, &lino, _OVER); - (void)tjsonAddStringToObject(item, "numOfColumns", i642str(pObj->numOfColumns)); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfColumns", i642str(pObj->numOfColumns)), pObj, &lino, _OVER); SJson *columns = tjsonAddArrayToObject(item, "columns"); for (int32_t i = 0; i < pObj->numOfColumns; ++i) { SJson *column = tjsonCreateObject(); - (void)tjsonAddItemToArray(columns, column); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(columns, column), pObj, &lino, _OVER); SSchema *pColumn = &pObj->pColumns[i]; - (void)tjsonAddStringToObject(column, "type", i642str(pColumn->type)); - (void)tjsonAddStringToObject(column, "typestr", tDataTypes[pColumn->type].name); - (void)tjsonAddStringToObject(column, "flags", i642str(pColumn->flags)); - (void)tjsonAddStringToObject(column, "colId", i642str(pColumn->colId)); - (void)tjsonAddStringToObject(column, "bytes", i642str(pColumn->bytes)); - (void)tjsonAddStringToObject(column, "name", pColumn->name); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "type", i642str(pColumn->type)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "typestr", tDataTypes[pColumn->type].name), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "flags", i642str(pColumn->flags)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "colId", i642str(pColumn->colId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "bytes", i642str(pColumn->bytes)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "name", pColumn->name), pObj, &lino, _OVER); } - (void)tjsonAddStringToObject(item, "numOfTags", i642str(pObj->numOfTags)); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfTags", i642str(pObj->numOfTags)), pObj, &lino, _OVER); SJson *tags = tjsonAddArrayToObject(item, "tags"); for (int32_t i = 0; i < pObj->numOfTags; ++i) { SJson *tag = tjsonCreateObject(); - (void)tjsonAddItemToArray(tags, tag); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(tags, tag), pObj, &lino, _OVER); SSchema *pTag = &pObj->pTags[i]; - (void)tjsonAddStringToObject(tag, "type", i642str(pTag->type)); - (void)tjsonAddStringToObject(tag, "typestr", tDataTypes[pTag->type].name); - (void)tjsonAddStringToObject(tag, "flags", i642str(pTag->flags)); - (void)tjsonAddStringToObject(tag, "colId", i642str(pTag->colId)); - (void)tjsonAddStringToObject(tag, "bytes", i642str(pTag->bytes)); - (void)tjsonAddStringToObject(tag, "name", pTag->name); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "type", i642str(pTag->type)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "typestr", tDataTypes[pTag->type].name), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "flags", i642str(pTag->flags)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "colId", i642str(pTag->colId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "bytes", i642str(pTag->bytes)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "name", pTag->name), pObj, &lino, _OVER); } sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump stable info at line:%d since %s", lino, tstrerror(code)); } void dumpSma(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "smas"); @@ -215,32 +248,37 @@ void dumpSma(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", mndGetStbStr(pObj->name)); - (void)tjsonAddStringToObject(item, "stb", mndGetStbStr(pObj->stb)); - (void)tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->db)); - (void)tjsonAddStringToObject(item, "dstTbName", mndGetStbStr(pObj->dstTbName)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "uid", i642str(pObj->uid)); - (void)tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)); - (void)tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)); - (void)tjsonAddStringToObject(item, "dstTbUid", i642str(pObj->dstTbUid)); - (void)tjsonAddStringToObject(item, "intervalUnit", i642str(pObj->intervalUnit)); - (void)tjsonAddStringToObject(item, "slidingUnit", i642str(pObj->slidingUnit)); - (void)tjsonAddStringToObject(item, "timezone", i642str(pObj->timezone)); - (void)tjsonAddStringToObject(item, "dstVgId", i642str(pObj->dstVgId)); - (void)tjsonAddStringToObject(item, "interval", i642str(pObj->interval)); - (void)tjsonAddStringToObject(item, "offset", i642str(pObj->offset)); - (void)tjsonAddStringToObject(item, "sliding", i642str(pObj->sliding)); - (void)tjsonAddStringToObject(item, "exprLen", i642str(pObj->exprLen)); - (void)tjsonAddStringToObject(item, "tagsFilterLen", i642str(pObj->tagsFilterLen)); - (void)tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)); - (void)tjsonAddStringToObject(item, "astLen", i642str(pObj->astLen)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetStbStr(pObj->name)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stb", mndGetStbStr(pObj->stb)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->db)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dstTbName", mndGetStbStr(pObj->dstTbName)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "uid", i642str(pObj->uid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dstTbUid", i642str(pObj->dstTbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "intervalUnit", i642str(pObj->intervalUnit)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "slidingUnit", i642str(pObj->slidingUnit)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "timezone", i642str(pObj->timezone)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dstVgId", i642str(pObj->dstVgId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "interval", i642str(pObj->interval)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "offset", i642str(pObj->offset)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sliding", i642str(pObj->sliding)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "exprLen", i642str(pObj->exprLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "tagsFilterLen", i642str(pObj->tagsFilterLen)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "astLen", i642str(pObj->astLen)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump sma info at line:%d since %s", lino, tstrerror(code)); } void dumpVgroup(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "vgroups"); @@ -250,28 +288,33 @@ void dumpVgroup(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "vgId", i642str(pObj->vgId)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "version", i642str(pObj->version)); - (void)tjsonAddStringToObject(item, "hashBegin", i642str(pObj->hashBegin)); - (void)tjsonAddStringToObject(item, "hashEnd", i642str(pObj->hashEnd)); - (void)tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->dbName)); - (void)tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)); - (void)tjsonAddStringToObject(item, "isTsma", i642str(pObj->isTsma)); - (void)tjsonAddStringToObject(item, "replica", i642str(pObj->replica)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "vgId", i642str(pObj->vgId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "version", i642str(pObj->version)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "hashBegin", i642str(pObj->hashBegin)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "hashEnd", i642str(pObj->hashEnd)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->dbName)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "isTsma", i642str(pObj->isTsma)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "replica", i642str(pObj->replica)), pObj, &lino, _OVER); for (int32_t i = 0; i < pObj->replica; ++i) { SJson *replicas = tjsonAddArrayToObject(item, "replicas"); SJson *replica = tjsonCreateObject(); - (void)tjsonAddItemToArray(replicas, replica); - (void)tjsonAddStringToObject(replica, "dnodeId", i642str(pObj->vnodeGid[i].dnodeId)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(replicas, replica), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(replica, "dnodeId", i642str(pObj->vnodeGid[i].dnodeId)), pObj, &lino, + _OVER); } sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump vgroup info at line:%d since %s", lino, tstrerror(code)); } void dumpTopic(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "topics"); @@ -281,28 +324,32 @@ void dumpTopic(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)); - (void)tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->db)); - (void)tjsonAddStringToObject(item, "createTime", i642str(pObj->createTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "uid", i642str(pObj->uid)); - (void)tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)); - (void)tjsonAddStringToObject(item, "version", i642str(pObj->version)); - (void)tjsonAddStringToObject(item, "subType", i642str(pObj->subType)); - (void)tjsonAddStringToObject(item, "withMeta", i642str(pObj->withMeta)); - (void)tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)); - (void)tjsonAddStringToObject(item, "stbName", mndGetStableStr(pObj->stbName)); - (void)tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)); - (void)tjsonAddStringToObject(item, "astLen", i642str(pObj->astLen)); - (void)tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)); - (void)tjsonAddStringToObject(item, "ntbUid", i642str(pObj->ntbUid)); - (void)tjsonAddStringToObject(item, "ctbStbUid", i642str(pObj->ctbStbUid)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->db)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createTime", i642str(pObj->createTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "uid", i642str(pObj->uid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "version", i642str(pObj->version)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "subType", i642str(pObj->subType)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "withMeta", i642str(pObj->withMeta)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stbName", mndGetStableStr(pObj->stbName)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "astLen", i642str(pObj->astLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "ntbUid", i642str(pObj->ntbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "ctbStbUid", i642str(pObj->ctbStbUid)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump topic info at line:%d since %s", lino, tstrerror(code)); } void dumpConsumer(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "consumers"); @@ -312,14 +359,18 @@ void dumpConsumer(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "consumerId", i642str(pObj->consumerId)); - (void)tjsonAddStringToObject(item, "cgroup", pObj->cgroup); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "consumerId", i642str(pObj->consumerId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "cgroup", pObj->cgroup), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump consumer info at line:%d since %s", lino, tstrerror(code)); } void dumpSubscribe(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "subscribes"); @@ -329,16 +380,20 @@ void dumpSubscribe(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "key", pObj->key); - (void)tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)); - (void)tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "key", pObj->key), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump subscribe info at line:%d since %s", lino, tstrerror(code)); } void dumpStream(SSdb *pSdb, SJson *json) { - void *pIter = NULL; + int32_t code = 0; + int32_t lino = 0; + void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "streams"); while (1) { @@ -347,31 +402,38 @@ void dumpStream(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)); - (void)tjsonAddStringToObject(item, "createTime", i642str(pObj->createTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "version", i642str(pObj->version)); - (void)tjsonAddStringToObject(item, "totalLevel", i642str(pObj->totalLevel)); - (void)tjsonAddStringToObject(item, "smaId", i642str(pObj->smaId)); - (void)tjsonAddStringToObject(item, "uid", i642str(pObj->uid)); - (void)tjsonAddStringToObject(item, "status", i642str(pObj->status)); - (void)tjsonAddStringToObject(item, "igExpired", i642str(pObj->conf.igExpired)); - (void)tjsonAddStringToObject(item, "trigger", i642str(pObj->conf.trigger)); - (void)tjsonAddStringToObject(item, "triggerParam", i642str(pObj->conf.triggerParam)); - (void)tjsonAddStringToObject(item, "watermark", i642str(pObj->conf.watermark)); - (void)tjsonAddStringToObject(item, "sourceDbUid", i642str(pObj->sourceDbUid)); - (void)tjsonAddStringToObject(item, "targetDbUid", i642str(pObj->targetDbUid)); - (void)tjsonAddStringToObject(item, "sourceDb", mndGetDbStr(pObj->sourceDb)); - (void)tjsonAddStringToObject(item, "targetDb", mndGetDbStr(pObj->targetDb)); - (void)tjsonAddStringToObject(item, "targetSTbName", mndGetStbStr(pObj->targetSTbName)); - (void)tjsonAddStringToObject(item, "targetStbUid", i642str(pObj->targetStbUid)); - (void)tjsonAddStringToObject(item, "fixedSinkVgId", i642str(pObj->fixedSinkVgId)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createTime", i642str(pObj->createTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "version", i642str(pObj->version)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "totalLevel", i642str(pObj->totalLevel)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "smaId", i642str(pObj->smaId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "uid", i642str(pObj->uid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "status", i642str(pObj->status)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "igExpired", i642str(pObj->conf.igExpired)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "trigger", i642str(pObj->conf.trigger)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "triggerParam", i642str(pObj->conf.triggerParam)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "watermark", i642str(pObj->conf.watermark)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sourceDbUid", i642str(pObj->sourceDbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "targetDbUid", i642str(pObj->targetDbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sourceDb", mndGetDbStr(pObj->sourceDb)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "targetDb", mndGetDbStr(pObj->targetDb)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "targetSTbName", mndGetStbStr(pObj->targetSTbName)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "targetStbUid", i642str(pObj->targetStbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "fixedSinkVgId", i642str(pObj->fixedSinkVgId)), pObj, &lino, + _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump stream info at line:%d since %s", lino, tstrerror(code)); } void dumpAcct(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "accts"); @@ -381,13 +443,15 @@ void dumpAcct(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "acct", pObj->acct); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "acctId", i642str(pObj->acctId)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "acct", pObj->acct), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "acctId", i642str(pObj->acctId)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump acct info at line:%d since %s", lino, tstrerror(code)); } void dumpAuth(SSdb *pSdb, SJson *json) { @@ -395,6 +459,8 @@ void dumpAuth(SSdb *pSdb, SJson *json) { } void dumpUser(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "users"); @@ -404,21 +470,27 @@ void dumpUser(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", pObj->user); - (void)tjsonAddStringToObject(item, "acct", pObj->acct); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "superUser", i642str(pObj->superUser)); - (void)tjsonAddStringToObject(item, "authVersion", i642str(pObj->authVersion)); - (void)tjsonAddStringToObject(item, "passVersion", i642str(pObj->passVersion)); - (void)tjsonAddStringToObject(item, "numOfReadDbs", i642str(taosHashGetSize(pObj->readDbs))); - (void)tjsonAddStringToObject(item, "numOfWriteDbs", i642str(taosHashGetSize(pObj->writeDbs))); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", pObj->user), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "acct", pObj->acct), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "superUser", i642str(pObj->superUser)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "authVersion", i642str(pObj->authVersion)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "passVersion", i642str(pObj->passVersion)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfReadDbs", i642str(taosHashGetSize(pObj->readDbs))), pObj, + &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfWriteDbs", i642str(taosHashGetSize(pObj->writeDbs))), pObj, + &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump user info at line:%d since %s", lino, tstrerror(code)); } void dumpDnode(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "dnodes"); @@ -428,17 +500,21 @@ void dumpDnode(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "port", i642str(pObj->port)); - (void)tjsonAddStringToObject(item, "fqdn", pObj->fqdn); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "port", i642str(pObj->port)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "fqdn", pObj->fqdn), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump dnode info at line:%d since %s", lino, tstrerror(code)); } void dumpSnode(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "snodes"); @@ -448,15 +524,19 @@ void dumpSnode(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump snode info at line:%d since %s", lino, tstrerror(code)); } void dumpQnode(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "qnodes"); @@ -466,15 +546,19 @@ void dumpQnode(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump qnode info at line:%d since %s", lino, tstrerror(code)); } void dumpMnode(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "mnodes"); @@ -484,15 +568,20 @@ void dumpMnode(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump mnode info at line:%d since %s", lino, tstrerror(code)); } void dumpCluster(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; + void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "clusters"); @@ -502,16 +591,21 @@ void dumpCluster(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "name", pObj->name); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", pObj->name), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } + +_OVER: + if (code != 0) mError("failed to dump cluster info at line:%d since %s", lino, tstrerror(code)); } void dumpTrans(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "transactions"); @@ -521,53 +615,64 @@ void dumpTrans(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "stage", i642str(pObj->stage)); - (void)tjsonAddStringToObject(item, "policy", i642str(pObj->policy)); - (void)tjsonAddStringToObject(item, "conflict", i642str(pObj->conflict)); - (void)tjsonAddStringToObject(item, "exec", i642str(pObj->exec)); - (void)tjsonAddStringToObject(item, "oper", i642str(pObj->oper)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "dbname", pObj->dbname); - (void)tjsonAddStringToObject(item, "stbname", pObj->stbname); - (void)tjsonAddStringToObject(item, "opername", pObj->opername); - (void)tjsonAddStringToObject(item, "commitLogNum", i642str(taosArrayGetSize(pObj->commitActions))); - (void)tjsonAddStringToObject(item, "redoActionNum", i642str(taosArrayGetSize(pObj->redoActions))); - (void)tjsonAddStringToObject(item, "undoActionNum", i642str(taosArrayGetSize(pObj->undoActions))); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stage", i642str(pObj->stage)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "policy", i642str(pObj->policy)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "conflict", i642str(pObj->conflict)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "exec", i642str(pObj->exec)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "oper", i642str(pObj->oper)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbname", pObj->dbname), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stbname", pObj->stbname), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "opername", pObj->opername), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "commitLogNum", i642str(taosArrayGetSize(pObj->commitActions))), + pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "redoActionNum", i642str(taosArrayGetSize(pObj->redoActions))), + pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "undoActionNum", i642str(taosArrayGetSize(pObj->undoActions))), + pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } + +_OVER: + if (code != 0) mError("failed to dump trans info at line:%d since %s", lino, tstrerror(code)); } void dumpHeader(SSdb *pSdb, SJson *json) { - (void)tjsonAddStringToObject(json, "sver", i642str(1)); - (void)tjsonAddStringToObject(json, "applyIndex", i642str(pSdb->applyIndex)); - (void)tjsonAddStringToObject(json, "applyTerm", i642str(pSdb->applyTerm)); - (void)tjsonAddStringToObject(json, "applyConfig", i642str(pSdb->applyConfig)); + int32_t code = 0; + int32_t lino = 0; + TAOS_CHECK_GOTO(tjsonAddStringToObject(json, "sver", i642str(1)), &lino, _OVER); + TAOS_CHECK_GOTO(tjsonAddStringToObject(json, "applyIndex", i642str(pSdb->applyIndex)), &lino, _OVER); + TAOS_CHECK_GOTO(tjsonAddStringToObject(json, "applyTerm", i642str(pSdb->applyTerm)), &lino, _OVER); + TAOS_CHECK_GOTO(tjsonAddStringToObject(json, "applyConfig", i642str(pSdb->applyConfig)), &lino, _OVER); SJson *maxIdsJson = tjsonCreateObject(); - (void)tjsonAddItemToObject(json, "maxIds", maxIdsJson); + TAOS_CHECK_GOTO(tjsonAddItemToObject(json, "maxIds", maxIdsJson), &lino, _OVER); for (int32_t i = 0; i < SDB_MAX; ++i) { if(i == 5) continue; int64_t maxId = 0; if (i < SDB_MAX) { maxId = pSdb->maxId[i]; } - (void)tjsonAddStringToObject(maxIdsJson, sdbTableName(i), i642str(maxId)); + TAOS_CHECK_GOTO(tjsonAddStringToObject(maxIdsJson, sdbTableName(i), i642str(maxId)), &lino, _OVER); } SJson *tableVersJson = tjsonCreateObject(); - (void)tjsonAddItemToObject(json, "tableVers", tableVersJson); + TAOS_CHECK_GOTO(tjsonAddItemToObject(json, "tableVers", tableVersJson), &lino, _OVER); for (int32_t i = 0; i < SDB_MAX; ++i) { int64_t tableVer = 0; if (i < SDB_MAX) { tableVer = pSdb->tableVer[i]; } - (void)tjsonAddStringToObject(tableVersJson, sdbTableName(i), i642str(tableVer)); + TAOS_CHECK_GOTO(tjsonAddStringToObject(tableVersJson, sdbTableName(i), i642str(tableVer)), &lino, _OVER); } + +_OVER: + if (code != 0) mError("failed to dump sdb info at line:%d since %s", lino, tstrerror(code)); } -void mndDumpSdb() { +int32_t mndDumpSdb() { mInfo("start to dump sdb info to sdb.json"); char path[PATH_MAX * 2] = {0}; @@ -581,12 +686,12 @@ void mndDumpSdb() { msgCb.mgmt = (SMgmtWrapper *)(&msgCb); // hack tmsgSetDefault(&msgCb); - (void)walInit(NULL); - (void)syncInit(); + TAOS_CHECK_RETURN(walInit(NULL)); + TAOS_CHECK_RETURN(syncInit()); SMnodeOpt opt = {.msgCb = msgCb}; SMnode *pMnode = mndOpen(path, &opt); - if (pMnode == NULL) return; + if (pMnode == NULL) return -1; SSdb *pSdb = pMnode->pSdb; SJson *json = tjsonCreateObject(); @@ -616,21 +721,21 @@ void mndDumpSdb() { char file[] = "sdb.json"; TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - terrno = terrno; mError("failed to write %s since %s", file, terrstr()); - return; + return terrno; } - (void)taosWriteFile(pFile, pCont, contLen); - (void)taosWriteFile(pFile, "\n", 1); - UNUSED(taosFsyncFile(pFile)); - (void)taosCloseFile(&pFile); + TAOS_CHECK_RETURN(taosWriteFile(pFile, pCont, contLen)); + TAOS_CHECK_RETURN(taosWriteFile(pFile, "\n", 1)); + TAOS_CHECK_RETURN(taosFsyncFile(pFile)); + TAOS_CHECK_RETURN(taosCloseFile(&pFile)); tjsonDelete(json); taosMemoryFree(pCont); mInfo("dump sdb info success"); + return 0; } -void mndDeleteTrans() { +int32_t mndDeleteTrans() { mInfo("start to dump sdb info to sdb.json"); char path[PATH_MAX * 2] = {0}; @@ -644,16 +749,18 @@ void mndDeleteTrans() { msgCb.mgmt = (SMgmtWrapper *)(&msgCb); // hack tmsgSetDefault(&msgCb); - (void)walInit(NULL); - (void)syncInit(); + TAOS_CHECK_RETURN(walInit(NULL)); + TAOS_CHECK_RETURN(syncInit()); SMnodeOpt opt = {.msgCb = msgCb}; SMnode *pMnode = mndOpen(path, &opt); - if (pMnode == NULL) return; + if (pMnode == NULL) return terrno; - (void)sdbWriteFileForDump(pMnode->pSdb); + TAOS_CHECK_RETURN(sdbWriteFileForDump(pMnode->pSdb)); mInfo("dump sdb info success"); + + return 0; } #pragma GCC diagnostic pop diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 0af0312b62..c00c88c4f9 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -14,10 +14,10 @@ */ #define _DEFAULT_SOURCE -#include "mndMnode.h" #include "audit.h" #include "mndCluster.h" #include "mndDnode.h" +#include "mndMnode.h" #include "mndPrivilege.h" #include "mndShow.h" #include "mndSync.h" @@ -114,7 +114,7 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) { mndTransDrop(pTrans); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + TAOS_CHECK_RETURN(sdbSetRawStatus(pRaw, SDB_STATUS_READY)); if ((code = mndTransPrepare(pMnode, pTrans)) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); @@ -270,19 +270,21 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) { } } if (pObj->pDnode != NULL) { - (void)addEpIntoEpSet(pEpSet, pObj->pDnode->fqdn, pObj->pDnode->port); + if (addEpIntoEpSet(pEpSet, pObj->pDnode->fqdn, pObj->pDnode->port) != 0) { + mError("mnode:%d, failed to add ep:%s:%d into epset", pObj->id, pObj->pDnode->fqdn, pObj->pDnode->port); + } + sdbRelease(pSdb, pObj); } - sdbRelease(pSdb, pObj); - } - if (pEpSet->numOfEps == 0) { - syncGetRetryEpSet(pMnode->syncMgmt.sync, pEpSet); - } + if (pEpSet->numOfEps == 0) { + syncGetRetryEpSet(pMnode->syncMgmt.sync, pEpSet); + } - if (pEpSet->inUse >= pEpSet->numOfEps) { - pEpSet->inUse = 0; + if (pEpSet->inUse >= pEpSet->numOfEps) { + pEpSet->inUse = 0; + } + epsetSort(pEpSet); } - epsetSort(pEpSet); } static int32_t mndSetCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) { @@ -341,7 +343,11 @@ static int32_t mndBuildCreateMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *p int32_t code = 0; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pCreateReq); void *pReq = taosMemoryMalloc(contLen); - (void)tSerializeSDCreateMnodeReq(pReq, contLen, pCreateReq); + code = tSerializeSDCreateMnodeReq(pReq, contLen, pCreateReq); + if (code < 0) { + taosMemoryFree(pReq); + TAOS_RETURN(code); + } STransAction action = { .epSet = *pCreateEpSet, @@ -363,7 +369,11 @@ static int32_t mndBuildAlterMnodeTypeRedoAction(STrans *pTrans, SDAlterMnodeType int32_t code = 0; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterMnodeTypeReq); void *pReq = taosMemoryMalloc(contLen); - (void)tSerializeSDCreateMnodeReq(pReq, contLen, pAlterMnodeTypeReq); + code = tSerializeSDCreateMnodeReq(pReq, contLen, pAlterMnodeTypeReq); + if (code < 0) { + taosMemoryFree(pReq); + TAOS_RETURN(code); + } STransAction action = { .epSet = *pAlterMnodeTypeEpSet, @@ -385,8 +395,11 @@ static int32_t mndBuildAlterMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pA int32_t code = 0; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterReq); void *pReq = taosMemoryMalloc(contLen); - (void)tSerializeSDCreateMnodeReq(pReq, contLen, pAlterReq); - + code = tSerializeSDCreateMnodeReq(pReq, contLen, pAlterReq); + if (code < 0) { + taosMemoryFree(pReq); + TAOS_RETURN(code); + } STransAction action = { .epSet = *pAlterEpSet, .pCont = pReq, @@ -407,7 +420,11 @@ static int32_t mndBuildDropMnodeRedoAction(STrans *pTrans, SDDropMnodeReq *pDrop int32_t code = 0; int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, pDropReq); void *pReq = taosMemoryMalloc(contLen); - (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, pDropReq); + code = tSerializeSCreateDropMQSNodeReq(pReq, contLen, pDropReq); + if (code < 0) { + taosMemoryFree(pReq); + TAOS_RETURN(code); + } STransAction action = { .epSet = *pDroprEpSet, @@ -868,6 +885,7 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB ESdbStatus objStatus = 0; char *pWrite; int64_t curMs = taosGetTimestampMs(); + int code = 0; pSelfObj = sdbAcquire(pSdb, SDB_MNODE, &pMnode->selfDnodeId); if (pSelfObj == NULL) { @@ -881,13 +899,21 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB cols = 0; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->id, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->id, false); + if (code != 0) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } char b1[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(b1, pObj->pDnode->ep, TSDB_EP_LEN + VARSTR_HEADER_SIZE); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, b1, false); + code = colDataSetVal(pColInfo, numOfRows, b1, false); + if (code != 0) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } char role[20] = "offline"; if (pObj->id == pMnode->selfDnodeId) { @@ -904,8 +930,11 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB char b2[12 + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(b2, role, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)b2, false); - + code = colDataSetVal(pColInfo, numOfRows, (const char *)b2, false); + if (code != 0) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } const char *status = "ready"; if (objStatus == SDB_STATUS_CREATING) status = "creating"; if (objStatus == SDB_STATUS_DROPPING) status = "dropping"; @@ -913,14 +942,26 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB char b3[9 + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(b3, status, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)b3, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)b3, false); + if (code != 0) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); + if (code != 0) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } int64_t roleTimeMs = (isDnodeOnline) ? pObj->roleTimeMs : 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); + if (code != 0) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } numOfRows++; sdbRelease(pSdb, pObj); @@ -1005,6 +1046,7 @@ static void mndReloadSyncConfig(SMnode *pMnode) { void *pIter = NULL; int32_t updatingMnodes = 0; int32_t readyMnodes = 0; + int32_t code = 0; SSyncCfg cfg = { .myIndex = -1, .lastIndex = 0, @@ -1030,7 +1072,10 @@ static void mndReloadSyncConfig(SMnode *pMnode) { pNode->nodePort = pObj->pDnode->port; pNode->nodeRole = pObj->role; tstrncpy(pNode->nodeFqdn, pObj->pDnode->fqdn, TSDB_FQDN_LEN); - (void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + code = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + if (code != 0) { + mError("mnode:%d, failed to update dnode info since %s", pObj->id, terrstr()); + } mInfo("vgId:1, ep:%s:%u dnode:%d", pNode->nodeFqdn, pNode->nodePort, pNode->nodeId); if (pObj->pDnode->id == pMnode->selfDnodeId) { cfg.myIndex = cfg.totalReplicaNum; diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 511cc8f984..3ec99f6e44 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -62,9 +62,8 @@ static int32_t mndProcessStreamReqCheckpoint(SRpcMsg *pReq); static int32_t mndProcessCheckpointReport(SRpcMsg *pReq); static int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg); static void doSendQuickRsp(SRpcHandleInfo *pInfo, int32_t msgSize, int32_t vgId, int32_t code); -static int32_t mndProcessDropOrphanTaskReq(SRpcMsg* pReq); -static int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList, SVgroupChangeInfo* pInfo); -static void mndDestroyVgroupChangeInfo(SVgroupChangeInfo *pInfo); +static int32_t mndProcessDropOrphanTaskReq(SRpcMsg *pReq); +static void saveTaskAndNodeInfoIntoBuf(SStreamObj *pStream, SStreamExecInfo *pExecNode); static void addAllStreamTasksIntoBuf(SMnode *pMnode, SStreamExecInfo *pExecInfo); static void removeExpiredNodeInfo(const SArray *pNodeSnapshot); @@ -920,6 +919,85 @@ _OVER: return code; } +static int32_t mndProcessRestartStreamReq(SRpcMsg *pReq) { + SMnode *pMnode = pReq->info.node; + SStreamObj *pStream = NULL; + int32_t code = 0; + SMPauseStreamReq pauseReq = {0}; + + if (tDeserializeSMPauseStreamReq(pReq->pCont, pReq->contLen, &pauseReq) < 0) { + return TSDB_CODE_INVALID_MSG; + } + + code = mndAcquireStream(pMnode, pauseReq.name, &pStream); + if (pStream == NULL || code != 0) { + if (pauseReq.igNotExists) { + mInfo("stream:%s, not exist, not restart stream", pauseReq.name); + return 0; + } else { + mError("stream:%s not exist, failed to restart stream", pauseReq.name); + TAOS_RETURN(TSDB_CODE_MND_STREAM_NOT_EXIST); + } + } + + mInfo("stream:%s,%" PRId64 " start to restart stream", pauseReq.name, pStream->uid); + if ((code = mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pStream->targetDb)) != 0) { + sdbRelease(pMnode->pSdb, pStream); + return code; + } + + // check if it is conflict with other trans in both sourceDb and targetDb. + code = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_RESTART_NAME, true); + if (code) { + sdbRelease(pMnode->pSdb, pStream); + return code; + } + + bool updated = mndStreamNodeIsUpdated(pMnode); + if (updated) { + mError("tasks are not ready for restart, node update detected"); + sdbRelease(pMnode->pSdb, pStream); + TAOS_RETURN(TSDB_CODE_STREAM_TASK_IVLD_STATUS); + } + + STrans *pTrans = NULL; + code = doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_RESTART_NAME, "restart the stream", &pTrans); + if (pTrans == NULL || code) { + mError("stream:%s failed to pause stream since %s", pauseReq.name, tstrerror(code)); + sdbRelease(pMnode->pSdb, pStream); + return code; + } + + code = mndStreamRegisterTrans(pTrans, MND_STREAM_RESTART_NAME, pStream->uid); + if (code) { + sdbRelease(pMnode->pSdb, pStream); + mndTransDrop(pTrans); + return code; + } + + // if nodeUpdate happened, not send pause trans + code = mndStreamSetRestartAction(pMnode, pTrans, pStream); + if (code) { + mError("stream:%s, failed to restart task since %s", pauseReq.name, tstrerror(code)); + sdbRelease(pMnode->pSdb, pStream); + mndTransDrop(pTrans); + return code; + } + + code = mndTransPrepare(pMnode, pTrans); + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { + mError("trans:%d, failed to prepare restart stream trans since %s", pTrans->id, tstrerror(code)); + sdbRelease(pMnode->pSdb, pStream); + mndTransDrop(pTrans); + return code; + } + + sdbRelease(pMnode->pSdb, pStream); + mndTransDrop(pTrans); + + return TSDB_CODE_ACTION_IN_PROGRESS; +} + int64_t mndStreamGenChkptId(SMnode *pMnode, bool lock) { SStreamObj *pStream = NULL; void *pIter = NULL; @@ -973,82 +1051,6 @@ int64_t mndStreamGenChkptId(SMnode *pMnode, bool lock) { return maxChkptId + 1; } -static int32_t mndBuildStreamCheckpointSourceReq(void **pBuf, int32_t *pLen, int32_t nodeId, int64_t checkpointId, - int64_t streamId, int32_t taskId, int32_t transId, int8_t mndTrigger) { - SStreamCheckpointSourceReq req = {0}; - req.checkpointId = checkpointId; - req.nodeId = nodeId; - req.expireTime = -1; - req.streamId = streamId; // pTask->id.streamId; - req.taskId = taskId; // pTask->id.taskId; - req.transId = transId; - req.mndTrigger = mndTrigger; - - int32_t code; - int32_t blen; - - tEncodeSize(tEncodeStreamCheckpointSourceReq, &req, blen, code); - if (code < 0) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); - } - - int32_t tlen = sizeof(SMsgHead) + blen; - - void *buf = taosMemoryMalloc(tlen); - if (buf == NULL) { - return terrno; - } - - void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - SEncoder encoder; - tEncoderInit(&encoder, abuf, tlen); - int32_t pos = tEncodeStreamCheckpointSourceReq(&encoder, &req); - if (pos == -1) { - tEncoderClear(&encoder); - return TSDB_CODE_INVALID_MSG; - } - - SMsgHead *pMsgHead = (SMsgHead *)buf; - pMsgHead->contLen = htonl(tlen); - pMsgHead->vgId = htonl(nodeId); - - tEncoderClear(&encoder); - - *pBuf = buf; - *pLen = tlen; - - return 0; -} - -static int32_t doSetCheckpointAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, int64_t checkpointId, - int8_t mndTrigger) { - void *buf; - int32_t tlen; - int32_t code = 0; - SEpSet epset = {0}; - bool hasEpset = false; - - if ((code = mndBuildStreamCheckpointSourceReq(&buf, &tlen, pTask->info.nodeId, checkpointId, pTask->id.streamId, - pTask->id.taskId, pTrans->id, mndTrigger)) < 0) { - taosMemoryFree(buf); - return code; - } - - code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - taosMemoryFree(buf); - return code; - } - - code = setTransAction(pTrans, buf, tlen, TDMT_VND_STREAM_CHECK_POINT_SOURCE, &epset, TSDB_CODE_SYN_PROPOSE_NOT_READY, - TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != 0) { - taosMemoryFree(buf); - } - - return code; -} - static int32_t mndProcessStreamCheckpointTrans(SMnode *pMnode, SStreamObj *pStream, int64_t checkpointId, int8_t mndTrigger, bool lock) { int32_t code = TSDB_CODE_SUCCESS; @@ -1096,7 +1098,7 @@ static int32_t mndProcessStreamCheckpointTrans(SMnode *pMnode, SStreamObj *pStre int32_t sz = taosArrayGetSize(pLevel); for (int32_t j = 0; j < sz; j++) { SStreamTask *pTask = taosArrayGetP(pLevel, j); - code = doSetCheckpointAction(pMnode, pTrans, pTask, checkpointId, mndTrigger); + code = mndStreamSetCheckpointAction(pMnode, pTrans, pTask, checkpointId, mndTrigger); if (code != TSDB_CODE_SUCCESS) { taosWUnLockLatch(&pStream->lock); @@ -1143,70 +1145,9 @@ int32_t extractStreamNodeList(SMnode *pMnode) { return taosArrayGetSize(execInfo.pNodeList); } -static int32_t doCheckForUpdated(SMnode *pMnode, SArray **ppNodeSnapshot) { - bool allReady = false; - bool nodeUpdated = false; - SVgroupChangeInfo changeInfo = {0}; - - int32_t numOfNodes = extractStreamNodeList(pMnode); - - if (numOfNodes == 0) { - mDebug("stream task node change checking done, no vgroups exist, do nothing"); - execInfo.ts = taosGetTimestampSec(); - return false; - } - - for (int32_t i = 0; i < numOfNodes; ++i) { - SNodeEntry *pNodeEntry = taosArrayGet(execInfo.pNodeList, i); - if (pNodeEntry == NULL) { - continue; - } - - if (pNodeEntry->stageUpdated) { - mDebug("stream task not ready due to node update detected, checkpoint not issued"); - return true; - } - } - - int32_t code = mndTakeVgroupSnapshot(pMnode, &allReady, ppNodeSnapshot); - if (code) { - mError("failed to get the vgroup snapshot, ignore it and continue"); - } - - if (!allReady) { - mWarn("not all vnodes ready, quit from vnodes status check"); - return true; - } - - code = mndFindChangedNodeInfo(pMnode, execInfo.pNodeList, *ppNodeSnapshot, &changeInfo); - if (code) { - nodeUpdated = false; - } else { - nodeUpdated = (taosArrayGetSize(changeInfo.pUpdateNodeList) > 0); - if (nodeUpdated) { - mDebug("stream tasks not ready due to node update"); - } - } - - mndDestroyVgroupChangeInfo(&changeInfo); - return nodeUpdated; -} - -// check if the node update happens or not -static bool taskNodeIsUpdated(SMnode *pMnode) { - SArray *pNodeSnapshot = NULL; - - streamMutexLock(&execInfo.lock); - bool updated = doCheckForUpdated(pMnode, &pNodeSnapshot); - streamMutexUnlock(&execInfo.lock); - - taosArrayDestroy(pNodeSnapshot); - return updated; -} - static int32_t mndCheckTaskAndNodeStatus(SMnode *pMnode) { bool ready = true; - if (taskNodeIsUpdated(pMnode)) { + if (mndStreamNodeIsUpdated(pMnode)) { TAOS_RETURN(TSDB_CODE_STREAM_TASK_IVLD_STATUS); } @@ -1605,32 +1546,6 @@ int32_t mndDropStreamByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { return 0; } -int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams) { - SSdb *pSdb = pMnode->pSdb; - SDbObj *pDb = mndAcquireDb(pMnode, dbName); - if (pDb == NULL) { - TAOS_RETURN(TSDB_CODE_MND_DB_NOT_SELECTED); - } - - int32_t numOfStreams = 0; - void *pIter = NULL; - while (1) { - SStreamObj *pStream = NULL; - pIter = sdbFetch(pSdb, SDB_STREAM, pIter, (void **)&pStream); - if (pIter == NULL) break; - - if (pStream->sourceDbUid == pDb->uid) { - numOfStreams++; - } - - sdbRelease(pSdb, pStream); - } - - *pNumOfStreams = numOfStreams; - mndReleaseDb(pMnode, pDb); - return 0; -} - static int32_t mndRetrieveStream(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->info.node; SSdb *pSdb = pMnode->pSdb; @@ -1770,7 +1685,7 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) { TAOS_RETURN(code); } - bool updated = taskNodeIsUpdated(pMnode); + bool updated = mndStreamNodeIsUpdated(pMnode); if (updated) { mError("tasks are not ready for pause, node update detected"); sdbRelease(pMnode->pSdb, pStream); @@ -1965,102 +1880,6 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) { return TSDB_CODE_ACTION_IN_PROGRESS; } -static bool isNodeEpsetChanged(const SEpSet *pPrevEpset, const SEpSet *pCurrent) { - const SEp *pEp = GET_ACTIVE_EP(pPrevEpset); - const SEp *p = GET_ACTIVE_EP(pCurrent); - - if (pEp->port == p->port && strncmp(pEp->fqdn, p->fqdn, TSDB_FQDN_LEN) == 0) { - return false; - } - return true; -} - -// 1. increase the replica does not affect the stream process. -// 2. decreasing the replica may affect the stream task execution in the way that there is one or more running stream -// tasks on the will be removed replica. -// 3. vgroup redistribution is an combination operation of first increase replica and then decrease replica. So we -// will handle it as mentioned in 1 & 2 items. -static int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList, - SVgroupChangeInfo *pInfo) { - int32_t code = 0; - int32_t lino = 0; - - if (pInfo == NULL) { - return TSDB_CODE_INVALID_PARA; - } - - pInfo->pUpdateNodeList = taosArrayInit(4, sizeof(SNodeUpdateInfo)), - pInfo->pDBMap = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK); - - if (pInfo->pUpdateNodeList == NULL || pInfo->pDBMap == NULL) { - mndDestroyVgroupChangeInfo(pInfo); - TSDB_CHECK_NULL(NULL, code, lino, _err, terrno); - } - - int32_t numOfNodes = taosArrayGetSize(pPrevNodeList); - for (int32_t i = 0; i < numOfNodes; ++i) { - SNodeEntry *pPrevEntry = taosArrayGet(pPrevNodeList, i); - if (pPrevEntry == NULL) { - continue; - } - - int32_t num = taosArrayGetSize(pNodeList); - for (int32_t j = 0; j < num; ++j) { - SNodeEntry *pCurrent = taosArrayGet(pNodeList, j); - if(pCurrent == NULL) { - continue; - } - - if (pCurrent->nodeId == pPrevEntry->nodeId) { - if (pPrevEntry->stageUpdated || isNodeEpsetChanged(&pPrevEntry->epset, &pCurrent->epset)) { - const SEp *pPrevEp = GET_ACTIVE_EP(&pPrevEntry->epset); - - char buf[256] = {0}; - code = epsetToStr(&pCurrent->epset, buf, tListLen(buf)); // ignore this error - if (code) { - mError("failed to convert epset string, code:%s", tstrerror(code)); - TSDB_CHECK_CODE(code, lino, _err); - } - - mDebug("nodeId:%d restart/epset changed detected, old:%s:%d -> new:%s, stageUpdate:%d", pCurrent->nodeId, - pPrevEp->fqdn, pPrevEp->port, buf, pPrevEntry->stageUpdated); - - SNodeUpdateInfo updateInfo = {.nodeId = pPrevEntry->nodeId}; - epsetAssign(&updateInfo.prevEp, &pPrevEntry->epset); - epsetAssign(&updateInfo.newEp, &pCurrent->epset); - - void* p = taosArrayPush(pInfo->pUpdateNodeList, &updateInfo); - TSDB_CHECK_NULL(p, code, lino, _err, terrno); - } - - // todo handle the snode info - if (pCurrent->nodeId != SNODE_HANDLE) { - SVgObj *pVgroup = mndAcquireVgroup(pMnode, pCurrent->nodeId); - code = taosHashPut(pInfo->pDBMap, pVgroup->dbName, strlen(pVgroup->dbName), NULL, 0); - mndReleaseVgroup(pMnode, pVgroup); - TSDB_CHECK_CODE(code, lino, _err); - } - - break; - } - } - } - - return code; - - _err: - mError("failed to find node change info, code:%s at %s line:%d", tstrerror(code), __func__, lino); - mndDestroyVgroupChangeInfo(pInfo); - return code; -} - -static void mndDestroyVgroupChangeInfo(SVgroupChangeInfo* pInfo) { - if (pInfo != NULL) { - taosArrayDestroy(pInfo->pUpdateNodeList); - taosHashCleanup(pInfo->pDBMap); - } -} - static int32_t mndProcessVgroupChange(SMnode *pMnode, SVgroupChangeInfo *pChangeInfo, bool includeAllNodes) { SSdb *pSdb = pMnode->pSdb; SStreamObj *pStream = NULL; diff --git a/source/dnode/mnode/impl/src/mndStreamTrans.c b/source/dnode/mnode/impl/src/mndStreamTrans.c index 25a735e152..e5b4447a39 100644 --- a/source/dnode/mnode/impl/src/mndStreamTrans.c +++ b/source/dnode/mnode/impl/src/mndStreamTrans.c @@ -21,6 +21,10 @@ typedef struct SKeyInfo { int32_t keyLen; } SKeyInfo; +static bool identicalName(const char *pDb, const char *pParam, int32_t len) { + return (strlen(pDb) == len) && (strncmp(pDb, pParam, len) == 0); +} + int32_t mndStreamRegisterTrans(STrans *pTrans, const char *pTransName, int64_t streamId) { SStreamTransInfo info = { .transId = pTrans->id, .startTime = taosGetTimestampMs(), .name = pTransName, .streamId = streamId}; @@ -117,7 +121,8 @@ int32_t mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char } if (strcmp(tInfo.name, MND_STREAM_CHECKPOINT_NAME) == 0) { - if ((strcmp(pTransName, MND_STREAM_DROP_NAME) != 0) && (strcmp(pTransName, MND_STREAM_TASK_RESET_NAME) != 0)) { + if ((strcmp(pTransName, MND_STREAM_DROP_NAME) != 0) && (strcmp(pTransName, MND_STREAM_TASK_RESET_NAME) != 0) && + (strcmp(pTransName, MND_STREAM_RESTART_NAME) != 0)) { mWarn("conflict with other transId:%d streamUid:0x%" PRIx64 ", trans:%s", tInfo.transId, tInfo.streamId, tInfo.name); return TSDB_CODE_MND_TRANS_CONFLICT; @@ -126,7 +131,8 @@ int32_t mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char } } else if ((strcmp(tInfo.name, MND_STREAM_CREATE_NAME) == 0) || (strcmp(tInfo.name, MND_STREAM_DROP_NAME) == 0) || (strcmp(tInfo.name, MND_STREAM_TASK_RESET_NAME) == 0) || - strcmp(tInfo.name, MND_STREAM_TASK_UPDATE_NAME) == 0) { + (strcmp(tInfo.name, MND_STREAM_TASK_UPDATE_NAME) == 0) || + strcmp(tInfo.name, MND_STREAM_RESTART_NAME) == 0) { mWarn("conflict with other transId:%d streamUid:0x%" PRIx64 ", trans:%s", tInfo.transId, tInfo.streamId, tInfo.name); return TSDB_CODE_MND_TRANS_CONFLICT; @@ -282,10 +288,6 @@ int32_t setTransAction(STrans *pTrans, void *pCont, int32_t contLen, int32_t msg return mndTransAppendRedoAction(pTrans, &action); } -static bool identicalName(const char *pDb, const char *pParam, int32_t len) { - return (strlen(pDb) == len) && (strncmp(pDb, pParam, len) == 0); -} - int32_t doKillCheckpointTrans(SMnode *pMnode, const char *pDBName, size_t len) { void *pIter = NULL; diff --git a/source/dnode/mnode/impl/src/mndStreamTransAct.c b/source/dnode/mnode/impl/src/mndStreamTransAct.c new file mode 100644 index 0000000000..3ecd192222 --- /dev/null +++ b/source/dnode/mnode/impl/src/mndStreamTransAct.c @@ -0,0 +1,669 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "mndDb.h" +#include "mndStb.h" +#include "mndStream.h" +#include "mndTrans.h" +#include "mndVgroup.h" +#include "taoserror.h" +#include "tmisce.h" + +static int32_t doSetPauseAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { + SVPauseStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVPauseStreamTaskReq)); + if (pReq == NULL) { + mError("failed to malloc in pause stream, size:%" PRIzu ", code:%s", sizeof(SVPauseStreamTaskReq), + tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + // terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; + } + + pReq->head.vgId = htonl(pTask->info.nodeId); + pReq->taskId = pTask->id.taskId; + pReq->streamId = pTask->id.streamId; + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + terrno = code; + taosMemoryFree(pReq); + return code; + } + + char buf[256] = {0}; + code = epsetToStr(&epset, buf, tListLen(buf)); + if (code != 0) { // print error and continue + mError("failed to convert epset to str, code:%s", tstrerror(code)); + } + + mDebug("pause stream task in node:%d, epset:%s", pTask->info.nodeId, buf); + code = setTransAction(pTrans, pReq, sizeof(SVPauseStreamTaskReq), TDMT_STREAM_TASK_PAUSE, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != 0) { + taosMemoryFree(pReq); + return code; + } + return 0; +} + +static int32_t doSetDropAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { + SVDropStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVDropStreamTaskReq)); + if (pReq == NULL) { + // terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; + } + + pReq->head.vgId = htonl(pTask->info.nodeId); + pReq->taskId = pTask->id.taskId; + pReq->streamId = pTask->id.streamId; + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { // no valid epset, return directly without redoAction + return code; + } + + // The epset of nodeId of this task may have been expired now, let's use the newest epset from mnode. + code = setTransAction(pTrans, pReq, sizeof(SVDropStreamTaskReq), TDMT_STREAM_TASK_DROP, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != 0) { + taosMemoryFree(pReq); + return code; + } + + return 0; +} + +static int32_t doSetResumeAction(STrans *pTrans, SMnode *pMnode, SStreamTask *pTask, int8_t igUntreated) { + terrno = 0; + + SVResumeStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVResumeStreamTaskReq)); + if (pReq == NULL) { + mError("failed to malloc in resume stream, size:%" PRIzu ", code:%s", sizeof(SVResumeStreamTaskReq), + tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + // terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; + } + + pReq->head.vgId = htonl(pTask->info.nodeId); + pReq->taskId = pTask->id.taskId; + pReq->streamId = pTask->id.streamId; + pReq->igUntreated = igUntreated; + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || (!hasEpset)) { + terrno = code; + taosMemoryFree(pReq); + return terrno; + } + + code = setTransAction(pTrans, pReq, sizeof(SVResumeStreamTaskReq), TDMT_STREAM_TASK_RESUME, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != 0) { + taosMemoryFree(pReq); + return terrno; + } + + mDebug("set the resume action for trans:%d", pTrans->id); + return 0; +} + +static int32_t doSetDropActionFromId(SMnode *pMnode, STrans *pTrans, SOrphanTask* pTask) { + SVDropStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVDropStreamTaskReq)); + if (pReq == NULL) { + // terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; + } + + pReq->head.vgId = htonl(pTask->nodeId); + pReq->taskId = pTask->taskId; + pReq->streamId = pTask->streamId; + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->taskId, pTask->nodeId); + if (code != TSDB_CODE_SUCCESS || (!hasEpset)) { // no valid epset, return directly without redoAction + taosMemoryFree(pReq); + return code; + } + + // The epset of nodeId of this task may have been expired now, let's use the newest epset from mnode. + code = setTransAction(pTrans, pReq, sizeof(SVDropStreamTaskReq), TDMT_STREAM_TASK_DROP, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != 0) { + taosMemoryFree(pReq); + return code; + } + + return 0; +} + +static void initNodeUpdateMsg(SStreamTaskNodeUpdateMsg *pMsg, const SVgroupChangeInfo *pInfo, SStreamTaskId *pId, + int32_t transId) { + int32_t code = 0; + + pMsg->streamId = pId->streamId; + pMsg->taskId = pId->taskId; + pMsg->transId = transId; + pMsg->pNodeList = taosArrayInit(taosArrayGetSize(pInfo->pUpdateNodeList), sizeof(SNodeUpdateInfo)); + if (pMsg->pNodeList == NULL) { + mError("failed to prepare node list, code:%s", tstrerror(terrno)); + code = terrno; + } + + if (code == 0) { + void *p = taosArrayAddAll(pMsg->pNodeList, pInfo->pUpdateNodeList); + if (p == NULL) { + mError("failed to add update node list into nodeList"); + } + } +} + +static int32_t doBuildStreamTaskUpdateMsg(void **pBuf, int32_t *pLen, SVgroupChangeInfo *pInfo, int32_t nodeId, + SStreamTaskId *pId, int32_t transId) { + SStreamTaskNodeUpdateMsg req = {0}; + initNodeUpdateMsg(&req, pInfo, pId, transId); + + int32_t code = 0; + int32_t blen; + + tEncodeSize(tEncodeStreamTaskUpdateMsg, &req, blen, code); + if (code < 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosArrayDestroy(req.pNodeList); + return terrno; + } + + int32_t tlen = sizeof(SMsgHead) + blen; + + void *buf = taosMemoryMalloc(tlen); + if (buf == NULL) { + taosArrayDestroy(req.pNodeList); + return terrno; + } + + void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + SEncoder encoder; + tEncoderInit(&encoder, abuf, tlen); + code = tEncodeStreamTaskUpdateMsg(&encoder, &req); + if (code == -1) { + tEncoderClear(&encoder); + taosMemoryFree(buf); + taosArrayDestroy(req.pNodeList); + return code; + } + + SMsgHead *pMsgHead = (SMsgHead *)buf; + pMsgHead->contLen = htonl(tlen); + pMsgHead->vgId = htonl(nodeId); + + tEncoderClear(&encoder); + + *pBuf = buf; + *pLen = tlen; + + taosArrayDestroy(req.pNodeList); + return TSDB_CODE_SUCCESS; +} + +static int32_t doSetUpdateTaskAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, SVgroupChangeInfo *pInfo) { + void *pBuf = NULL; + int32_t len = 0; + SEpSet epset = {0}; + bool hasEpset = false; + + bool unusedRet = streamTaskUpdateEpsetInfo(pTask, pInfo->pUpdateNodeList); + int32_t code = doBuildStreamTaskUpdateMsg(&pBuf, &len, pInfo, pTask->info.nodeId, &pTask->id, pTrans->id); + if (code) { + mError("failed to build stream task epset update msg, code:%s", tstrerror(code)); + return code; + } + + code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + mError("failed to extract epset during create update epset, code:%s", tstrerror(code)); + return code; + } + + code = setTransAction(pTrans, pBuf, len, TDMT_VND_STREAM_TASK_UPDATE, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != TSDB_CODE_SUCCESS) { + mError("failed to create update task epset trans, code:%s", tstrerror(code)); + taosMemoryFree(pBuf); + } + + return code; +} + +static int32_t doSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { + SVUpdateCheckpointInfoReq *pReq = taosMemoryCalloc(1, sizeof(SVUpdateCheckpointInfoReq)); + if (pReq == NULL) { + mError("failed to malloc in reset stream, size:%" PRIzu ", code:%s", sizeof(SVUpdateCheckpointInfoReq), + tstrerror(terrno)); + return terrno; + } + + pReq->head.vgId = htonl(pTask->info.nodeId); + pReq->taskId = pTask->id.taskId; + pReq->streamId = pTask->id.streamId; + + SChkptReportInfo *pStreamItem = (SChkptReportInfo*)taosHashGet(execInfo.pChkptStreams, &pTask->id.streamId, sizeof(pTask->id.streamId)); + if (pStreamItem == NULL) { + return TSDB_CODE_INVALID_PARA; + } + + int32_t size = taosArrayGetSize(pStreamItem->pTaskList); + for(int32_t i = 0; i < size; ++i) { + STaskChkptInfo* pInfo = taosArrayGet(pStreamItem->pTaskList, i); + if (pInfo == NULL) { + continue; + } + + if (pInfo->taskId == pTask->id.taskId) { + pReq->checkpointId = pInfo->checkpointId; + pReq->checkpointVer = pInfo->version; + pReq->checkpointTs = pInfo->ts; + pReq->dropRelHTask = pInfo->dropHTask; + pReq->transId = pInfo->transId; + pReq->hStreamId = pTask->hTaskInfo.id.streamId; + pReq->hTaskId = pTask->hTaskInfo.id.taskId; + } + } + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + taosMemoryFree(pReq); + return code; + } + + code = setTransAction(pTrans, pReq, sizeof(SVUpdateCheckpointInfoReq), TDMT_STREAM_TASK_UPDATE_CHKPT, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != TSDB_CODE_SUCCESS) { + taosMemoryFree(pReq); + } + + return code; +} + +static int32_t doSetResetAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { + SVResetStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVResetStreamTaskReq)); + if (pReq == NULL) { + mError("failed to malloc in reset stream, size:%" PRIzu ", code:%s", sizeof(SVResetStreamTaskReq), + tstrerror(terrno)); + return terrno; + } + + pReq->head.vgId = htonl(pTask->info.nodeId); + pReq->taskId = pTask->id.taskId; + pReq->streamId = pTask->id.streamId; + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + taosMemoryFree(pReq); + return code; + } + + code = setTransAction(pTrans, pReq, sizeof(SVResetStreamTaskReq), TDMT_VND_STREAM_TASK_RESET, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != TSDB_CODE_SUCCESS) { + taosMemoryFree(pReq); + } + + return code; +} + +static int32_t mndBuildStreamCheckpointSourceReq(void **pBuf, int32_t *pLen, int32_t nodeId, int64_t checkpointId, + int64_t streamId, int32_t taskId, int32_t transId, int8_t mndTrigger) { + SStreamCheckpointSourceReq req = {0}; + req.checkpointId = checkpointId; + req.nodeId = nodeId; + req.expireTime = -1; + req.streamId = streamId; // pTask->id.streamId; + req.taskId = taskId; // pTask->id.taskId; + req.transId = transId; + req.mndTrigger = mndTrigger; + + int32_t code; + int32_t blen; + + tEncodeSize(tEncodeStreamCheckpointSourceReq, &req, blen, code); + if (code < 0) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } + + int32_t tlen = sizeof(SMsgHead) + blen; + + void *buf = taosMemoryMalloc(tlen); + if (buf == NULL) { + return terrno; + } + + void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + SEncoder encoder; + tEncoderInit(&encoder, abuf, tlen); + int32_t pos = tEncodeStreamCheckpointSourceReq(&encoder, &req); + if (pos == -1) { + tEncoderClear(&encoder); + return TSDB_CODE_INVALID_MSG; + } + + SMsgHead *pMsgHead = (SMsgHead *)buf; + pMsgHead->contLen = htonl(tlen); + pMsgHead->vgId = htonl(nodeId); + + tEncoderClear(&encoder); + + *pBuf = buf; + *pLen = tlen; + + return 0; +} +int32_t mndStreamSetPauseAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { + SStreamTaskIter *pIter = NULL; + + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while (streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code) { + destroyStreamTaskIter(pIter); + return code; + } + + code = doSetPauseAction(pMnode, pTrans, pTask); + if (code) { + destroyStreamTaskIter(pIter); + return code; + } + + if (atomic_load_8(&pTask->status.taskStatus) != TASK_STATUS__PAUSE) { + atomic_store_8(&pTask->status.statusBackup, pTask->status.taskStatus); + atomic_store_8(&pTask->status.taskStatus, TASK_STATUS__PAUSE); + } + } + + destroyStreamTaskIter(pIter); + return code; +} + +int32_t mndStreamSetDropAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { + SStreamTaskIter *pIter = NULL; + + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while(streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code) { + destroyStreamTaskIter(pIter); + return code; + } + + code = doSetDropAction(pMnode, pTrans, pTask); + if (code) { + destroyStreamTaskIter(pIter); + return code; + } + } + destroyStreamTaskIter(pIter); + return 0; +} + +int32_t mndStreamSetResumeAction(STrans *pTrans, SMnode *pMnode, SStreamObj *pStream, int8_t igUntreated) { + SStreamTaskIter *pIter = NULL; + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while (streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code || pTask == NULL) { + destroyStreamTaskIter(pIter); + return code; + } + + code = doSetResumeAction(pTrans, pMnode, pTask, igUntreated); + if (code) { + destroyStreamTaskIter(pIter); + return code; + } + + if (atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__PAUSE) { + atomic_store_8(&pTask->status.taskStatus, pTask->status.statusBackup); + } + } + destroyStreamTaskIter(pIter); + return 0; +} + +// build trans to update the epset +int32_t mndStreamSetUpdateEpsetAction(SMnode *pMnode, SStreamObj *pStream, SVgroupChangeInfo *pInfo, STrans *pTrans) { + mDebug("stream:0x%" PRIx64 " set tasks epset update action", pStream->uid); + SStreamTaskIter *pIter = NULL; + + taosWLockLatch(&pStream->lock); + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + taosWUnLockLatch(&pStream->lock); + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while (streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + + code = doSetUpdateTaskAction(pMnode, pTrans, pTask, pInfo); + if (code != TSDB_CODE_SUCCESS) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + } + + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return 0; +} + +int32_t mndStreamSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { + SStreamTaskIter *pIter = NULL; + + taosWLockLatch(&pStream->lock); + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + taosWUnLockLatch(&pStream->lock); + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while (streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + + code = doSetUpdateChkptAction(pMnode, pTrans, pTask); + if (code != TSDB_CODE_SUCCESS) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + } + + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; +} + +int32_t mndStreamSetDropActionFromList(SMnode *pMnode, STrans *pTrans, SArray* pList) { + for(int32_t i = 0; i < taosArrayGetSize(pList); ++i) { + SOrphanTask* pTask = taosArrayGet(pList, i); + if (pTask == NULL) { + return terrno; + } + + int32_t code = doSetDropActionFromId(pMnode, pTrans, pTask); + if (code != 0) { + return code; + } else { + mDebug("add drop task:0x%x action to drop orphan task", pTask->taskId); + } + } + return 0; +} + +int32_t mndStreamSetResetTaskAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { + SStreamTaskIter *pIter = NULL; + + taosWLockLatch(&pStream->lock); + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + taosWUnLockLatch(&pStream->lock); + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while (streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + + code = doSetResetAction(pMnode, pTrans, pTask); + if (code != TSDB_CODE_SUCCESS) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + } + + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return 0; +} + +int32_t mndStreamSetChkptIdAction(SMnode *pMnode, STrans *pTrans, SStreamTask* pTask, int64_t checkpointId, int64_t ts) { + SRestoreCheckpointInfo req = { + .taskId = pTask->id.taskId, + .streamId = pTask->id.streamId, + .checkpointId = checkpointId, + .startTs = ts, + .nodeId = pTask->info.nodeId, + .transId = pTrans->id, + }; + + int32_t code = 0; + int32_t blen; + tEncodeSize(tEncodeRestoreCheckpointInfo, &req, blen, code); + if (code < 0) { + return terrno; + } + + int32_t tlen = sizeof(SMsgHead) + blen; + + void *pBuf = taosMemoryMalloc(tlen); + if (pBuf == NULL) { + return terrno; + } + + void *abuf = POINTER_SHIFT(pBuf, sizeof(SMsgHead)); + SEncoder encoder; + tEncoderInit(&encoder, abuf, tlen); + code = tEncodeRestoreCheckpointInfo(&encoder, &req); + tEncoderClear(&encoder); + if (code == -1) { + taosMemoryFree(pBuf); + return code; + } + + SMsgHead *pMsgHead = (SMsgHead *)pBuf; + pMsgHead->contLen = htonl(tlen); + pMsgHead->vgId = htonl(pTask->info.nodeId); + + SEpSet epset = {0}; + bool hasEpset = false; + code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + taosMemoryFree(pBuf); + return code; + } + + code = setTransAction(pTrans, pBuf, tlen, TDMT_STREAM_CONSEN_CHKPT, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != TSDB_CODE_SUCCESS) { + taosMemoryFree(pBuf); + } + + return code; +} + + +int32_t mndStreamSetCheckpointAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, int64_t checkpointId, + int8_t mndTrigger) { + void *buf; + int32_t tlen; + int32_t code = 0; + SEpSet epset = {0}; + bool hasEpset = false; + + if ((code = mndBuildStreamCheckpointSourceReq(&buf, &tlen, pTask->info.nodeId, checkpointId, pTask->id.streamId, + pTask->id.taskId, pTrans->id, mndTrigger)) < 0) { + taosMemoryFree(buf); + return code; + } + + code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + taosMemoryFree(buf); + return code; + } + + code = setTransAction(pTrans, buf, tlen, TDMT_VND_STREAM_CHECK_POINT_SOURCE, &epset, TSDB_CODE_SYN_PROPOSE_NOT_READY, + TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != 0) { + taosMemoryFree(buf); + } + + return code; +} + +int32_t mndStreamSetRestartAction(SMnode* pMnode, STrans *pTrans, SStreamObj* pStream) { + return 0; +} + diff --git a/source/dnode/mnode/impl/src/mndStreamUtil.c b/source/dnode/mnode/impl/src/mndStreamUtil.c index 5d8ba02781..6e48c58b30 100644 --- a/source/dnode/mnode/impl/src/mndStreamUtil.c +++ b/source/dnode/mnode/impl/src/mndStreamUtil.c @@ -304,41 +304,6 @@ int32_t extractNodeEpset(SMnode *pMnode, SEpSet *pEpSet, bool *hasEpset, int32_t } } -static int32_t doSetResumeAction(STrans *pTrans, SMnode *pMnode, SStreamTask *pTask, int8_t igUntreated) { - terrno = 0; - - SVResumeStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVResumeStreamTaskReq)); - if (pReq == NULL) { - mError("failed to malloc in resume stream, size:%" PRIzu ", code:%s", sizeof(SVResumeStreamTaskReq), - tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - // terrno = TSDB_CODE_OUT_OF_MEMORY; - return terrno; - } - - pReq->head.vgId = htonl(pTask->info.nodeId); - pReq->taskId = pTask->id.taskId; - pReq->streamId = pTask->id.streamId; - pReq->igUntreated = igUntreated; - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || (!hasEpset)) { - terrno = code; - taosMemoryFree(pReq); - return terrno; - } - - code = setTransAction(pTrans, pReq, sizeof(SVResumeStreamTaskReq), TDMT_STREAM_TASK_RESUME, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != 0) { - taosMemoryFree(pReq); - return terrno; - } - - mDebug("set the resume action for trans:%d", pTrans->id); - return 0; -} - int32_t mndGetStreamTask(STaskId *pId, SStreamObj *pStream, SStreamTask **pTask) { *pTask = NULL; @@ -377,396 +342,29 @@ int32_t mndGetNumOfStreamTasks(const SStreamObj *pStream) { return num; } -int32_t mndStreamSetResumeAction(STrans *pTrans, SMnode *pMnode, SStreamObj *pStream, int8_t igUntreated) { - SStreamTaskIter *pIter = NULL; - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - mError("failed to create stream task iter:%s", pStream->name); - return code; +int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams) { + SSdb *pSdb = pMnode->pSdb; + SDbObj *pDb = mndAcquireDb(pMnode, dbName); + if (pDb == NULL) { + TAOS_RETURN(TSDB_CODE_MND_DB_NOT_SELECTED); } - while (streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code || pTask == NULL) { - destroyStreamTaskIter(pIter); - return code; + int32_t numOfStreams = 0; + void *pIter = NULL; + while (1) { + SStreamObj *pStream = NULL; + pIter = sdbFetch(pSdb, SDB_STREAM, pIter, (void **)&pStream); + if (pIter == NULL) break; + + if (pStream->sourceDbUid == pDb->uid) { + numOfStreams++; } - code = doSetResumeAction(pTrans, pMnode, pTask, igUntreated); - if (code) { - destroyStreamTaskIter(pIter); - return code; - } - - if (atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__PAUSE) { - atomic_store_8(&pTask->status.taskStatus, pTask->status.statusBackup); - } - } - destroyStreamTaskIter(pIter); - return 0; -} - -static int32_t doSetPauseAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { - SVPauseStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVPauseStreamTaskReq)); - if (pReq == NULL) { - mError("failed to malloc in pause stream, size:%" PRIzu ", code:%s", sizeof(SVPauseStreamTaskReq), - tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - // terrno = TSDB_CODE_OUT_OF_MEMORY; - return terrno; + sdbRelease(pSdb, pStream); } - pReq->head.vgId = htonl(pTask->info.nodeId); - pReq->taskId = pTask->id.taskId; - pReq->streamId = pTask->id.streamId; - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - terrno = code; - taosMemoryFree(pReq); - return code; - } - - char buf[256] = {0}; - code = epsetToStr(&epset, buf, tListLen(buf)); - if (code != 0) { // print error and continue - mError("failed to convert epset to str, code:%s", tstrerror(code)); - } - - mDebug("pause stream task in node:%d, epset:%s", pTask->info.nodeId, buf); - code = setTransAction(pTrans, pReq, sizeof(SVPauseStreamTaskReq), TDMT_STREAM_TASK_PAUSE, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != 0) { - taosMemoryFree(pReq); - return code; - } - return 0; -} - -int32_t mndStreamSetPauseAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { - SStreamTaskIter *pIter = NULL; - - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - mError("failed to create stream task iter:%s", pStream->name); - return code; - } - - while (streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code) { - destroyStreamTaskIter(pIter); - return code; - } - - code = doSetPauseAction(pMnode, pTrans, pTask); - if (code) { - destroyStreamTaskIter(pIter); - return code; - } - - if (atomic_load_8(&pTask->status.taskStatus) != TASK_STATUS__PAUSE) { - atomic_store_8(&pTask->status.statusBackup, pTask->status.taskStatus); - atomic_store_8(&pTask->status.taskStatus, TASK_STATUS__PAUSE); - } - } - - destroyStreamTaskIter(pIter); - return code; -} - -static int32_t doSetDropAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { - SVDropStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVDropStreamTaskReq)); - if (pReq == NULL) { - // terrno = TSDB_CODE_OUT_OF_MEMORY; - return terrno; - } - - pReq->head.vgId = htonl(pTask->info.nodeId); - pReq->taskId = pTask->id.taskId; - pReq->streamId = pTask->id.streamId; - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { // no valid epset, return directly without redoAction - return code; - } - - // The epset of nodeId of this task may have been expired now, let's use the newest epset from mnode. - code = setTransAction(pTrans, pReq, sizeof(SVDropStreamTaskReq), TDMT_STREAM_TASK_DROP, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != 0) { - taosMemoryFree(pReq); - return code; - } - - return 0; -} - -int32_t mndStreamSetDropAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { - SStreamTaskIter *pIter = NULL; - - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - mError("failed to create stream task iter:%s", pStream->name); - return code; - } - - while(streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code) { - destroyStreamTaskIter(pIter); - return code; - } - - code = doSetDropAction(pMnode, pTrans, pTask); - if (code) { - destroyStreamTaskIter(pIter); - return code; - } - } - destroyStreamTaskIter(pIter); - return 0; -} - -static int32_t doSetDropActionFromId(SMnode *pMnode, STrans *pTrans, SOrphanTask* pTask) { - SVDropStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVDropStreamTaskReq)); - if (pReq == NULL) { - // terrno = TSDB_CODE_OUT_OF_MEMORY; - return terrno; - } - - pReq->head.vgId = htonl(pTask->nodeId); - pReq->taskId = pTask->taskId; - pReq->streamId = pTask->streamId; - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->taskId, pTask->nodeId); - if (code != TSDB_CODE_SUCCESS || (!hasEpset)) { // no valid epset, return directly without redoAction - taosMemoryFree(pReq); - return code; - } - - // The epset of nodeId of this task may have been expired now, let's use the newest epset from mnode. - code = setTransAction(pTrans, pReq, sizeof(SVDropStreamTaskReq), TDMT_STREAM_TASK_DROP, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != 0) { - taosMemoryFree(pReq); - return code; - } - - return 0; -} - -int32_t mndStreamSetDropActionFromList(SMnode *pMnode, STrans *pTrans, SArray* pList) { - for(int32_t i = 0; i < taosArrayGetSize(pList); ++i) { - SOrphanTask* pTask = taosArrayGet(pList, i); - if (pTask == NULL) { - return terrno; - } - - int32_t code = doSetDropActionFromId(pMnode, pTrans, pTask); - if (code != 0) { - return code; - } else { - mDebug("add drop task:0x%x action to drop orphan task", pTask->taskId); - } - } - return 0; -} - -static void initNodeUpdateMsg(SStreamTaskNodeUpdateMsg *pMsg, const SVgroupChangeInfo *pInfo, SStreamTaskId *pId, - int32_t transId) { - int32_t code = 0; - - pMsg->streamId = pId->streamId; - pMsg->taskId = pId->taskId; - pMsg->transId = transId; - pMsg->pNodeList = taosArrayInit(taosArrayGetSize(pInfo->pUpdateNodeList), sizeof(SNodeUpdateInfo)); - if (pMsg->pNodeList == NULL) { - mError("failed to prepare node list, code:%s", tstrerror(terrno)); - code = terrno; - } - - if (code == 0) { - void *p = taosArrayAddAll(pMsg->pNodeList, pInfo->pUpdateNodeList); - if (p == NULL) { - mError("failed to add update node list into nodeList"); - } - } -} - -static int32_t doBuildStreamTaskUpdateMsg(void **pBuf, int32_t *pLen, SVgroupChangeInfo *pInfo, int32_t nodeId, - SStreamTaskId *pId, int32_t transId) { - SStreamTaskNodeUpdateMsg req = {0}; - initNodeUpdateMsg(&req, pInfo, pId, transId); - - int32_t code = 0; - int32_t blen; - - tEncodeSize(tEncodeStreamTaskUpdateMsg, &req, blen, code); - if (code < 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - taosArrayDestroy(req.pNodeList); - return terrno; - } - - int32_t tlen = sizeof(SMsgHead) + blen; - - void *buf = taosMemoryMalloc(tlen); - if (buf == NULL) { - taosArrayDestroy(req.pNodeList); - return terrno; - } - - void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - SEncoder encoder; - tEncoderInit(&encoder, abuf, tlen); - code = tEncodeStreamTaskUpdateMsg(&encoder, &req); - if (code == -1) { - tEncoderClear(&encoder); - taosMemoryFree(buf); - taosArrayDestroy(req.pNodeList); - return code; - } - - SMsgHead *pMsgHead = (SMsgHead *)buf; - pMsgHead->contLen = htonl(tlen); - pMsgHead->vgId = htonl(nodeId); - - tEncoderClear(&encoder); - - *pBuf = buf; - *pLen = tlen; - - taosArrayDestroy(req.pNodeList); - return TSDB_CODE_SUCCESS; -} - -static int32_t doSetUpdateTaskAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, SVgroupChangeInfo *pInfo) { - void *pBuf = NULL; - int32_t len = 0; - SEpSet epset = {0}; - bool hasEpset = false; - - bool unusedRet = streamTaskUpdateEpsetInfo(pTask, pInfo->pUpdateNodeList); - int32_t code = doBuildStreamTaskUpdateMsg(&pBuf, &len, pInfo, pTask->info.nodeId, &pTask->id, pTrans->id); - if (code) { - mError("failed to build stream task epset update msg, code:%s", tstrerror(code)); - return code; - } - - code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - mError("failed to extract epset during create update epset, code:%s", tstrerror(code)); - return code; - } - - code = setTransAction(pTrans, pBuf, len, TDMT_VND_STREAM_TASK_UPDATE, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != TSDB_CODE_SUCCESS) { - mError("failed to create update task epset trans, code:%s", tstrerror(code)); - taosMemoryFree(pBuf); - } - - return code; -} - -// build trans to update the epset -int32_t mndStreamSetUpdateEpsetAction(SMnode *pMnode, SStreamObj *pStream, SVgroupChangeInfo *pInfo, STrans *pTrans) { - mDebug("stream:0x%" PRIx64 " set tasks epset update action", pStream->uid); - SStreamTaskIter *pIter = NULL; - - taosWLockLatch(&pStream->lock); - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - taosWUnLockLatch(&pStream->lock); - mError("failed to create stream task iter:%s", pStream->name); - return code; - } - - while (streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - - code = doSetUpdateTaskAction(pMnode, pTrans, pTask, pInfo); - if (code != TSDB_CODE_SUCCESS) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - } - - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return 0; -} - -static int32_t doSetResetAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { - SVResetStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVResetStreamTaskReq)); - if (pReq == NULL) { - mError("failed to malloc in reset stream, size:%" PRIzu ", code:%s", sizeof(SVResetStreamTaskReq), - tstrerror(terrno)); - return terrno; - } - - pReq->head.vgId = htonl(pTask->info.nodeId); - pReq->taskId = pTask->id.taskId; - pReq->streamId = pTask->id.streamId; - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - taosMemoryFree(pReq); - return code; - } - - code = setTransAction(pTrans, pReq, sizeof(SVResetStreamTaskReq), TDMT_VND_STREAM_TASK_RESET, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != TSDB_CODE_SUCCESS) { - taosMemoryFree(pReq); - } - - return code; -} - -int32_t mndStreamSetResetTaskAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { - SStreamTaskIter *pIter = NULL; - - taosWLockLatch(&pStream->lock); - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - taosWUnLockLatch(&pStream->lock); - mError("failed to create stream task iter:%s", pStream->name); - return code; - } - - while (streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - - code = doSetResetAction(pMnode, pTrans, pTask); - if (code != TSDB_CODE_SUCCESS) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - } - - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); + *pNumOfStreams = numOfStreams; + mndReleaseDb(pMnode, pDb); return 0; } @@ -1000,90 +598,6 @@ int32_t removeExpiredNodeEntryAndTaskInBuf(SArray *pNodeSnapshot) { return 0; } -static int32_t doSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { - SVUpdateCheckpointInfoReq *pReq = taosMemoryCalloc(1, sizeof(SVUpdateCheckpointInfoReq)); - if (pReq == NULL) { - mError("failed to malloc in reset stream, size:%" PRIzu ", code:%s", sizeof(SVUpdateCheckpointInfoReq), - tstrerror(terrno)); - return terrno; - } - - pReq->head.vgId = htonl(pTask->info.nodeId); - pReq->taskId = pTask->id.taskId; - pReq->streamId = pTask->id.streamId; - - SChkptReportInfo *pStreamItem = (SChkptReportInfo*)taosHashGet(execInfo.pChkptStreams, &pTask->id.streamId, sizeof(pTask->id.streamId)); - if (pStreamItem == NULL) { - return TSDB_CODE_INVALID_PARA; - } - - int32_t size = taosArrayGetSize(pStreamItem->pTaskList); - for(int32_t i = 0; i < size; ++i) { - STaskChkptInfo* pInfo = taosArrayGet(pStreamItem->pTaskList, i); - if (pInfo == NULL) { - continue; - } - - if (pInfo->taskId == pTask->id.taskId) { - pReq->checkpointId = pInfo->checkpointId; - pReq->checkpointVer = pInfo->version; - pReq->checkpointTs = pInfo->ts; - pReq->dropRelHTask = pInfo->dropHTask; - pReq->transId = pInfo->transId; - pReq->hStreamId = pTask->hTaskInfo.id.streamId; - pReq->hTaskId = pTask->hTaskInfo.id.taskId; - } - } - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - taosMemoryFree(pReq); - return code; - } - - code = setTransAction(pTrans, pReq, sizeof(SVUpdateCheckpointInfoReq), TDMT_STREAM_TASK_UPDATE_CHKPT, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != TSDB_CODE_SUCCESS) { - taosMemoryFree(pReq); - } - - return code; -} - -int32_t mndStreamSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { - SStreamTaskIter *pIter = NULL; - - taosWLockLatch(&pStream->lock); - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - taosWUnLockLatch(&pStream->lock); - mError("failed to create stream task iter:%s", pStream->name); - return code; - } - - while (streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - - code = doSetUpdateChkptAction(pMnode, pTrans, pTask); - if (code != TSDB_CODE_SUCCESS) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - } - - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; -} - int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; void *pIter = NULL; @@ -1172,60 +686,6 @@ int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq) { return TSDB_CODE_SUCCESS; } -static int32_t mndStreamSetChkptIdAction(SMnode *pMnode, STrans *pTrans, SStreamTask* pTask, int64_t checkpointId, int64_t ts) { - SRestoreCheckpointInfo req = { - .taskId = pTask->id.taskId, - .streamId = pTask->id.streamId, - .checkpointId = checkpointId, - .startTs = ts, - .nodeId = pTask->info.nodeId, - .transId = pTrans->id, - }; - - int32_t code = 0; - int32_t blen; - tEncodeSize(tEncodeRestoreCheckpointInfo, &req, blen, code); - if (code < 0) { - return terrno; - } - - int32_t tlen = sizeof(SMsgHead) + blen; - - void *pBuf = taosMemoryMalloc(tlen); - if (pBuf == NULL) { - return terrno; - } - - void *abuf = POINTER_SHIFT(pBuf, sizeof(SMsgHead)); - SEncoder encoder; - tEncoderInit(&encoder, abuf, tlen); - code = tEncodeRestoreCheckpointInfo(&encoder, &req); - tEncoderClear(&encoder); - if (code == -1) { - taosMemoryFree(pBuf); - return code; - } - - SMsgHead *pMsgHead = (SMsgHead *)pBuf; - pMsgHead->contLen = htonl(tlen); - pMsgHead->vgId = htonl(pTask->info.nodeId); - - SEpSet epset = {0}; - bool hasEpset = false; - code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - taosMemoryFree(pBuf); - return code; - } - - code = setTransAction(pTrans, pBuf, tlen, TDMT_STREAM_CONSEN_CHKPT, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != TSDB_CODE_SUCCESS) { - taosMemoryFree(pBuf); - } - - return code; -} - int32_t mndCreateSetConsensusChkptIdTrans(SMnode *pMnode, SStreamObj *pStream, int32_t taskId, int64_t checkpointId, int64_t ts) { char msg[128] = {0}; @@ -1880,6 +1340,163 @@ int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlo return code; } +static bool isNodeEpsetChanged(const SEpSet *pPrevEpset, const SEpSet *pCurrent) { + const SEp *pEp = GET_ACTIVE_EP(pPrevEpset); + const SEp *p = GET_ACTIVE_EP(pCurrent); + + if (pEp->port == p->port && strncmp(pEp->fqdn, p->fqdn, TSDB_FQDN_LEN) == 0) { + return false; + } + return true; +} + +void mndDestroyVgroupChangeInfo(SVgroupChangeInfo* pInfo) { + if (pInfo != NULL) { + taosArrayDestroy(pInfo->pUpdateNodeList); + taosHashCleanup(pInfo->pDBMap); + } +} + +// 1. increase the replica does not affect the stream process. +// 2. decreasing the replica may affect the stream task execution in the way that there is one or more running stream +// tasks on the will be removed replica. +// 3. vgroup redistribution is an combination operation of first increase replica and then decrease replica. So we +// will handle it as mentioned in 1 & 2 items. +int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList, + SVgroupChangeInfo *pInfo) { + int32_t code = 0; + int32_t lino = 0; + + if (pInfo == NULL) { + return TSDB_CODE_INVALID_PARA; + } + + pInfo->pUpdateNodeList = taosArrayInit(4, sizeof(SNodeUpdateInfo)), + pInfo->pDBMap = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK); + + if (pInfo->pUpdateNodeList == NULL || pInfo->pDBMap == NULL) { + mndDestroyVgroupChangeInfo(pInfo); + TSDB_CHECK_NULL(NULL, code, lino, _err, terrno); + } + + int32_t numOfNodes = taosArrayGetSize(pPrevNodeList); + for (int32_t i = 0; i < numOfNodes; ++i) { + SNodeEntry *pPrevEntry = taosArrayGet(pPrevNodeList, i); + if (pPrevEntry == NULL) { + continue; + } + + int32_t num = taosArrayGetSize(pNodeList); + for (int32_t j = 0; j < num; ++j) { + SNodeEntry *pCurrent = taosArrayGet(pNodeList, j); + if(pCurrent == NULL) { + continue; + } + + if (pCurrent->nodeId == pPrevEntry->nodeId) { + if (pPrevEntry->stageUpdated || isNodeEpsetChanged(&pPrevEntry->epset, &pCurrent->epset)) { + const SEp *pPrevEp = GET_ACTIVE_EP(&pPrevEntry->epset); + + char buf[256] = {0}; + code = epsetToStr(&pCurrent->epset, buf, tListLen(buf)); // ignore this error + if (code) { + mError("failed to convert epset string, code:%s", tstrerror(code)); + TSDB_CHECK_CODE(code, lino, _err); + } + + mDebug("nodeId:%d restart/epset changed detected, old:%s:%d -> new:%s, stageUpdate:%d", pCurrent->nodeId, + pPrevEp->fqdn, pPrevEp->port, buf, pPrevEntry->stageUpdated); + + SNodeUpdateInfo updateInfo = {.nodeId = pPrevEntry->nodeId}; + epsetAssign(&updateInfo.prevEp, &pPrevEntry->epset); + epsetAssign(&updateInfo.newEp, &pCurrent->epset); + + void* p = taosArrayPush(pInfo->pUpdateNodeList, &updateInfo); + TSDB_CHECK_NULL(p, code, lino, _err, terrno); + } + + // todo handle the snode info + if (pCurrent->nodeId != SNODE_HANDLE) { + SVgObj *pVgroup = mndAcquireVgroup(pMnode, pCurrent->nodeId); + code = taosHashPut(pInfo->pDBMap, pVgroup->dbName, strlen(pVgroup->dbName), NULL, 0); + mndReleaseVgroup(pMnode, pVgroup); + TSDB_CHECK_CODE(code, lino, _err); + } + + break; + } + } + } + + return code; + + _err: + mError("failed to find node change info, code:%s at %s line:%d", tstrerror(code), __func__, lino); + mndDestroyVgroupChangeInfo(pInfo); + return code; + } + +static int32_t doCheckForUpdated(SMnode *pMnode, SArray **ppNodeSnapshot) { + bool allReady = false; + bool nodeUpdated = false; + SVgroupChangeInfo changeInfo = {0}; + + int32_t numOfNodes = extractStreamNodeList(pMnode); + + if (numOfNodes == 0) { + mDebug("stream task node change checking done, no vgroups exist, do nothing"); + execInfo.ts = taosGetTimestampSec(); + return false; + } + + for (int32_t i = 0; i < numOfNodes; ++i) { + SNodeEntry *pNodeEntry = taosArrayGet(execInfo.pNodeList, i); + if (pNodeEntry == NULL) { + continue; + } + + if (pNodeEntry->stageUpdated) { + mDebug("stream task not ready due to node update detected, checkpoint not issued"); + return true; + } + } + + int32_t code = mndTakeVgroupSnapshot(pMnode, &allReady, ppNodeSnapshot); + if (code) { + mError("failed to get the vgroup snapshot, ignore it and continue"); + } + + if (!allReady) { + mWarn("not all vnodes ready, quit from vnodes status check"); + return true; + } + + code = mndFindChangedNodeInfo(pMnode, execInfo.pNodeList, *ppNodeSnapshot, &changeInfo); + if (code) { + nodeUpdated = false; + } else { + nodeUpdated = (taosArrayGetSize(changeInfo.pUpdateNodeList) > 0); + if (nodeUpdated) { + mDebug("stream tasks not ready due to node update"); + } + } + + mndDestroyVgroupChangeInfo(&changeInfo); + return nodeUpdated; +} + +// check if the node update happens or not +bool mndStreamNodeIsUpdated(SMnode *pMnode) { + SArray *pNodeSnapshot = NULL; + + streamMutexLock(&execInfo.lock); + bool updated = doCheckForUpdated(pMnode, &pNodeSnapshot); + streamMutexUnlock(&execInfo.lock); + + taosArrayDestroy(pNodeSnapshot); + return updated; +} + uint32_t seed = 0; static SRpcMsg createRpcMsg(STransAction* pAction, int64_t traceId, int64_t signature) { SRpcMsg rpcMsg = {.msgType = pAction->msgType, .contLen = pAction->contLen, .info.ahandle = (void *)signature}; diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index 37a711da41..93d8b6dcde 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -113,6 +113,7 @@ static int32_t mndBuildSubChangeReq(void **pBuf, int32_t *pLen, SMqSubscribeObj MND_TMQ_RETURN_CHECK(qSubPlanToString(pPlan, &req.qmsg, &msgLen)); } else { req.qmsg = taosStrdup(""); + MND_TMQ_NULL_CHECK(req.qmsg); } req.subType = pSub->subType; req.withMeta = pSub->withMeta; diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 78aca0dbee..643bab568f 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -451,12 +451,14 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * topicObj.dbUid = pDb->uid; topicObj.version = 1; topicObj.sql = taosStrdup(pCreate->sql); + MND_TMQ_NULL_CHECK(topicObj.sql); topicObj.sqlLen = strlen(pCreate->sql) + 1; topicObj.subType = pCreate->subType; topicObj.withMeta = pCreate->withMeta; if (pCreate->subType == TOPIC_SUB_TYPE__COLUMN) { topicObj.ast = taosStrdup(pCreate->ast); + MND_TMQ_NULL_CHECK(topicObj.ast); topicObj.astLen = strlen(pCreate->ast) + 1; qDebugL("topic:%s ast %s", topicObj.name, topicObj.ast); MND_TMQ_RETURN_CHECK(nodesStringToNode(pCreate->ast, &pAst)); @@ -482,6 +484,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * if(pCreate->ast != NULL){ qDebugL("topic:%s ast %s", topicObj.name, pCreate->ast); topicObj.ast = taosStrdup(pCreate->ast); + MND_TMQ_NULL_CHECK(topicObj.ast); topicObj.astLen = strlen(pCreate->ast) + 1; } } diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 3199292a7d..2fe1ef4cfb 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -14,7 +14,6 @@ */ #define _DEFAULT_SOURCE -#include "mndVgroup.h" #include "audit.h" #include "mndArbGroup.h" #include "mndDb.h" @@ -27,6 +26,7 @@ #include "mndTopic.h" #include "mndTrans.h" #include "mndUser.h" +#include "mndVgroup.h" #include "tmisce.h" #define VGROUP_VER_NUMBER 1 @@ -320,6 +320,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg createReq.tsdbPageSize = pDb->cfg.tsdbPageSize; createReq.changeVersion = ++(pVgroup->syncConfChangeVer); createReq.encryptAlgorithm = pDb->cfg.encryptAlgorithm; + int32_t code = 0; for (int32_t v = 0; v < pVgroup->replica; ++v) { SReplica *pReplica = NULL; @@ -390,7 +391,13 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg return NULL; } - (void)tSerializeSCreateVnodeReq(pReq, contLen, &createReq); + code = tSerializeSCreateVnodeReq(pReq, contLen, &createReq); + if (code < 0) { + terrno = TSDB_CODE_APP_ERROR; + taosMemoryFree(pReq); + mError("vgId:%d, failed to serialize create vnode req,since %s", createReq.vgId, terrstr()); + return NULL; + } *pContLen = contLen; return pReq; } @@ -436,7 +443,12 @@ static void *mndBuildAlterVnodeConfigReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pV pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - (void)tSerializeSAlterVnodeConfigReq((char *)pReq + sizeof(SMsgHead), contLen, &alterReq); + if (tSerializeSAlterVnodeConfigReq((char *)pReq + sizeof(SMsgHead), contLen, &alterReq) < 0) { + taosMemoryFree(pReq); + mError("vgId:%d, failed to serialize alter vnode config req,since %s", pVgroup->vgId, terrstr()); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -514,7 +526,12 @@ static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p return NULL; } - (void)tSerializeSAlterVnodeReplicaReq(pReq, contLen, &alterReq); + if (tSerializeSAlterVnodeReplicaReq(pReq, contLen, &alterReq) < 0) { + mError("vgId:%d, failed to serialize alter vnode req,since %s", alterReq.vgId, terrstr()); + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -587,7 +604,12 @@ static void *mndBuildCheckLearnCatchupReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p return NULL; } - (void)tSerializeSAlterVnodeReplicaReq(pReq, contLen, &req); + if (tSerializeSAlterVnodeReplicaReq(pReq, contLen, &req) < 0) { + mError("vgId:%d, failed to serialize alter vnode req,since %s", req.vgId, terrstr()); + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -611,7 +633,12 @@ static void *mndBuildDisableVnodeWriteReq(SMnode *pMnode, SDbObj *pDb, int32_t v return NULL; } - (void)tSerializeSDisableVnodeWriteReq(pReq, contLen, &disableReq); + if (tSerializeSDisableVnodeWriteReq(pReq, contLen, &disableReq) < 0) { + mError("vgId:%d, failed to serialize disable vnode write req,since %s", vgId, terrstr()); + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -639,7 +666,12 @@ static void *mndBuildAlterVnodeHashRangeReq(SMnode *pMnode, int32_t srcVgId, SVg return NULL; } - (void)tSerializeSAlterVnodeHashRangeReq(pReq, contLen, &alterReq); + if (tSerializeSAlterVnodeHashRangeReq(pReq, contLen, &alterReq) < 0) { + mError("vgId:%d, failed to serialize alter vnode hashrange req,since %s", srcVgId, terrstr()); + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -664,7 +696,12 @@ void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgOb return NULL; } - (void)tSerializeSDropVnodeReq(pReq, contLen, &dropReq); + if (tSerializeSDropVnodeReq(pReq, contLen, &dropReq) < 0) { + mError("vgId:%d, failed to serialize drop vnode req,since %s", dropReq.vgId, terrstr()); + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -907,7 +944,9 @@ SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup) { epset.inUse = epset.numOfEps; } - (void)addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port); + if (addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port) != 0) { + mWarn("vgId:%d, failed to add ep:%s:%d into epset", pVgroup->vgId, pDnode->fqdn, pDnode->port); + } mndReleaseDnode(pMnode, pDnode); } epsetSort(&epset); @@ -930,7 +969,9 @@ SEpSet mndGetVgroupEpsetById(SMnode *pMnode, int32_t vgId) { epset.inUse = epset.numOfEps; } - (void)addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port); + if (addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port) != 0) { + mWarn("vgId:%d, failed to add ep:%s:%d into epset", pVgroup->vgId, pDnode->fqdn, pDnode->port); + } mndReleaseDnode(pMnode, pDnode); } @@ -945,6 +986,7 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p SVgObj *pVgroup = NULL; int32_t cols = 0; int64_t curMs = taosGetTimestampMs(); + int32_t code = 0; SDbObj *pDb = NULL; if (strlen(pShow->db) > 0) { @@ -965,26 +1007,46 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p cols = 0; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); + if (code != 0) { + mError("vgId:%d, failed to set vgId, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } SName name = {0}; char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - (void)tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB); + code = tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB); + if (code != 0) { + mError("vgId:%d, failed to set dbName, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } (void)tNameGetDbName(&name, varDataVal(db)); varDataSetLen(db, strlen(varDataVal(db))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)db, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)db, false); + if (code != 0) { + mError("vgId:%d, failed to set dbName, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfTables, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfTables, false); + if (code != 0) { + mError("vgId:%d, failed to set numOfTables, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } // default 3 replica, add 1 replica if move vnode for (int32_t i = 0; i < 4; ++i) { pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); if (i < pVgroup->replica) { int16_t dnodeId = (int16_t)pVgroup->vnodeGid[i].dnodeId; - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&dnodeId, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&dnodeId, false); + if (code != 0) { + mError("vgId:%d, failed to set dnodeId, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } bool exist = false; bool online = false; @@ -1038,7 +1100,11 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p STR_WITH_MAXSIZE_TO_VARSTR(buf1, role, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)buf1, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)buf1, false); + if (code != 0) { + mError("vgId:%d, failed to set role, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } } else { colDataSetNULL(pColInfo, numOfRows); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1048,21 +1114,25 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); int32_t cacheUsage = (int32_t)pVgroup->cacheUsage; - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&cacheUsage, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&cacheUsage, false); + if (code != 0) { + mError("vgId:%d, failed to set cacheUsage, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfCachedTables, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfCachedTables, false); + if (code != 0) { + mError("vgId:%d, failed to set numOfCachedTables, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->isTsma, false); - - // pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - // if (pDb == NULL || pDb->compactStartTime <= 0) { - // colDataSetNULL(pColInfo, numOfRows); - // } else { - // (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pDb->compactStartTime, false); - // } - + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->isTsma, false); + if (code != 0) { + mError("vgId:%d, failed to set isTsma, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } numOfRows++; sdbRelease(pSdb, pVgroup); } @@ -1147,6 +1217,7 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB SVgObj *pVgroup = NULL; int32_t cols = 0; int64_t curMs = taosGetTimestampMs(); + int32_t code = 0; while (numOfRows < rows - TSDB_MAX_REPLICA) { pShow->pIter = sdbFetch(pSdb, SDB_VGROUP, pShow->pIter, (void **)&pVgroup); @@ -1158,10 +1229,17 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB cols = 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->dnodeId, false); - + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->dnodeId, false); + if (code != 0) { + mError("vgId:%d, failed to set dnodeId, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); + if (code != 0) { + mError("vgId:%d, failed to set vgId, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } // db_name const char *dbname = mndGetDbStr(pVgroup->dbName); @@ -1172,7 +1250,11 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB STR_WITH_MAXSIZE_TO_VARSTR(b1, "NULL", TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE); } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)b1, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)b1, false); + if (code != 0) { + mError("vgId:%d, failed to set dbName, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } // dnode is online? SDnodeObj *pDnode = mndAcquireDnode(pMnode, pGid->dnodeId); @@ -1186,18 +1268,34 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB ESyncState syncState = (isDnodeOnline) ? pGid->syncState : TAOS_SYNC_STATE_OFFLINE; STR_TO_VARSTR(buf, syncStr(syncState)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)buf, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)buf, false); + if (code != 0) { + mError("vgId:%d, failed to set syncState, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } int64_t roleTimeMs = (isDnodeOnline) ? pGid->roleTimeMs : 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); + if (code != 0) { + mError("vgId:%d, failed to set roleTimeMs, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } int64_t startTimeMs = (isDnodeOnline) ? pGid->startTimeMs : 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&startTimeMs, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&startTimeMs, false); + if (code != 0) { + mError("vgId:%d, failed to set startTimeMs, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->syncRestore, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->syncRestore, false); + if (code != 0) { + mError("vgId:%d, failed to set syncRestore, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } numOfRows++; sdbRelease(pSdb, pDnode); @@ -1270,8 +1368,10 @@ static int32_t mndAddVnodeToVgroup(SMnode *pMnode, STrans *pTrans, SVgObj *pVgro sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); - + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pVgroup->vgId, tstrerror(code), __LINE__); + } TAOS_RETURN(code); } @@ -1332,7 +1432,10 @@ _OVER: sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pVgroup->vgId, tstrerror(code), __LINE__); + } TAOS_RETURN(code); } @@ -1568,6 +1671,10 @@ int32_t mndAddNewVgPrepareAction(SMnode *pMnode, STrans *pTrans, SVgObj *pVg) { TAOS_CHECK_GOTO(mndTransAppendPrepareLog(pTrans, pRaw), NULL, _err); (void)sdbSetRawStatus(pRaw, SDB_STATUS_CREATING); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pVg->vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } pRaw = NULL; TAOS_RETURN(code); @@ -1824,7 +1931,11 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, sdbFreeRaw(pRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", newVg.vgId, tstrerror(code), __LINE__); + return code; + } } TAOS_CHECK_RETURN(mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true)); @@ -1850,7 +1961,6 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, sdbFreeRaw(pRaw); return -1; } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); } if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1; @@ -1880,7 +1990,11 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, sdbFreeRaw(pRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", newVg.vgId, tstrerror(code), __LINE__); + return code; + } } for (int32_t i = 0; i < newVg.replica; ++i) { @@ -1930,7 +2044,11 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, sdbFreeRaw(pRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", newVg.vgId, tstrerror(code), __LINE__); + return code; + } } mInfo("vgId:%d, vgroup info after move, replica:%d", newVg.vgId, newVg.replica); @@ -2005,7 +2123,11 @@ static int32_t mndAddIncVgroupReplicaToTrans(SMnode *pMnode, STrans *pTrans, SDb sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pVgroup->vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } // learner for (int32_t i = 0; i < pVgroup->replica - 1; ++i) { @@ -2057,7 +2179,11 @@ static int32_t mndAddDecVgroupReplicaFromTrans(SMnode *pMnode, STrans *pTrans, S sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pVgroup->vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } TAOS_CHECK_RETURN(mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true)); for (int32_t i = 0; i < pVgroup->replica; ++i) { @@ -2171,7 +2297,11 @@ static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, sdbFreeRaw(pRaw); goto _OVER; } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", newVg.vgId, tstrerror(code), __LINE__); + goto _OVER; + } } mInfo("vgId:%d, vgroup info after redistribute, replica:%d", newVg.vgId, newVg.replica); @@ -2452,7 +2582,11 @@ static void *mndBuildSForceBecomeFollowerReq(SMnode *pMnode, SVgObj *pVgroup, in pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - (void)tSerializeSForceBecomeFollowerReq((char *)pReq + sizeof(SMsgHead), contLen, &balanceReq); + if (tSerializeSForceBecomeFollowerReq((char *)pReq + sizeof(SMsgHead), contLen, &balanceReq) < 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFree(pReq); + return NULL; + } *pContLen = contLen; return pReq; } @@ -2693,7 +2827,11 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pNewVgroup->vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } } TAOS_RETURN(code); @@ -2776,7 +2914,12 @@ int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pO sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVgroup.vgId, tstrerror(code), + __LINE__); + TAOS_RETURN(code); + } } else if (newVgroup.replica == 3 && pNewDb->cfg.replications == 1) { mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName, pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId); @@ -2801,7 +2944,12 @@ int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pO sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVgroup.vgId, tstrerror(code), + __LINE__); + TAOS_RETURN(code); + } SVnodeGid del2 = {0}; TAOS_CHECK_RETURN(mndRemoveVnodeFromVgroupWithoutSave(pMnode, pTrans, &newVgroup, pArray, &del2)); @@ -2823,7 +2971,12 @@ int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pO sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVgroup.vgId, tstrerror(code), + __LINE__); + TAOS_RETURN(code); + } } else { return -1; } @@ -2841,7 +2994,12 @@ int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pO sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVgroup.vgId, tstrerror(code), + __LINE__); + TAOS_RETURN(code); + } } TAOS_RETURN(code); @@ -2917,7 +3075,11 @@ int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVgroup.vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } TAOS_RETURN(code); } @@ -2938,7 +3100,11 @@ static int32_t mndAddVgStatusAction(STrans *pTrans, SVgObj *pVg, ESdbStatus vgSt goto _err; } if ((code = appendActionCb(pTrans, pRaw)) != 0) goto _err; - (void)sdbSetRawStatus(pRaw, vgStatus); + code = sdbSetRawStatus(pRaw, vgStatus); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", pVg->vgId, tstrerror(code), __LINE__); + goto _err; + } pRaw = NULL; TAOS_RETURN(code); _err: @@ -2956,7 +3122,11 @@ static int32_t mndAddDbStatusAction(STrans *pTrans, SDbObj *pDb, ESdbStatus dbSt goto _err; } if ((code = appendActionCb(pTrans, pRaw)) != 0) goto _err; - (void)sdbSetRawStatus(pRaw, dbStatus); + code = sdbSetRawStatus(pRaw, dbStatus); + if (code != 0) { + mError("db:%s, failed to set raw status to ready, error:%s, line:%d", pDb->name, tstrerror(code), __LINE__); + goto _err; + } pRaw = NULL; TAOS_RETURN(code); _err: @@ -3165,7 +3335,11 @@ static int32_t mndSetBalanceVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SD sdbFreeRaw(pRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVg.vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } } mInfo("vgId:%d, vgroup info after balance, replica:%d", newVg.vgId, newVg.replica); @@ -3391,7 +3565,11 @@ static void *mndBuildCompactVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgrou pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - (void)tSerializeSCompactVnodeReq((char *)pReq + sizeof(SMsgHead), contLen, &compactReq); + if (tSerializeSCompactVnodeReq((char *)pReq + sizeof(SMsgHead), contLen, &compactReq) < 0) { + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index e5aefaedd2..d0047b8e3f 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -70,6 +70,9 @@ int32_t tqOpen(const char* path, SVnode* pVnode) { } pVnode->pTq = pTq; pTq->path = taosStrdup(path); + if (pTq->path == NULL) { + return terrno; + } pTq->pVnode = pVnode; pTq->pHandle = taosHashInit(64, MurmurHash3_32, true, HASH_ENTRY_LOCK); diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c index b9cf26ee54..b7c842d05c 100644 --- a/source/dnode/vnode/src/tq/tqMeta.c +++ b/source/dnode/vnode/src/tq/tqMeta.c @@ -341,7 +341,11 @@ int32_t tqMetaCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle) { handle->execHandle.subType = req->subType; handle->fetchMeta = req->withMeta; if (req->subType == TOPIC_SUB_TYPE__COLUMN) { - handle->execHandle.execCol.qmsg = taosStrdup(req->qmsg); + void *tmp = taosStrdup(req->qmsg); + if (tmp == NULL) { + return terrno; + } + handle->execHandle.execCol.qmsg = tmp; } else if (req->subType == TOPIC_SUB_TYPE__DB) { handle->execHandle.execDb.pFilterOutTbUid = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); @@ -350,7 +354,11 @@ int32_t tqMetaCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle) { } }else if(req->subType == TOPIC_SUB_TYPE__TABLE){ handle->execHandle.execTb.suid = req->suid; - handle->execHandle.execTb.qmsg = taosStrdup(req->qmsg); + void *tmp = taosStrdup(req->qmsg); + if (tmp == NULL) { + return terrno; + } + handle->execHandle.execTb.qmsg = tmp; } handle->snapshotVer = walGetCommittedVer(pTq->pVnode->pWal); diff --git a/source/dnode/vnode/src/tq/tqScan.c b/source/dnode/vnode/src/tq/tqScan.c index 14b347ce73..f71669f158 100644 --- a/source/dnode/vnode/src/tq/tqScan.c +++ b/source/dnode/vnode/src/tq/tqScan.c @@ -69,6 +69,10 @@ static int32_t tqAddTbNameToRsp(const STQ* pTq, int64_t uid, void* pRsp, int32_t for (int32_t i = 0; i < n; i++) { char* tbName = taosStrdup(mr.me.name); + if (tbName == NULL) { + metaReaderClear(&mr); + return terrno; + } if(taosArrayPush(((SMqDataRspCommon*)pRsp)->blockTbName, &tbName) == NULL){ continue; } @@ -213,6 +217,10 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqBatc } } else { char* tbName = taosStrdup(qExtractTbnameFromTask(task)); + if (tbName == NULL) { + tqError("vgId:%d, failed to add tbname to rsp msg, null", pTq->pVnode->config.vgId); + return terrno; + } if (taosArrayPush(pRsp->common.blockTbName, &tbName) == NULL){ tqError("vgId:%d, failed to add tbname to rsp msg", pTq->pVnode->config.vgId); continue; diff --git a/source/dnode/vnode/src/tq/tqStreamTask.c b/source/dnode/vnode/src/tq/tqStreamTask.c index ae3d113c66..b0bf89029e 100644 --- a/source/dnode/vnode/src/tq/tqStreamTask.c +++ b/source/dnode/vnode/src/tq/tqStreamTask.c @@ -114,7 +114,7 @@ int32_t tqScanWalInFuture(STQ* pTq, int32_t numOfTasks, int32_t idleDuration) { } else { bool ret = taosTmrReset(doStartScanWal, idleDuration, pParam, pTimer, &pMeta->scanInfo.scanTimer); if (!ret) { - tqError("vgId:%d failed to start scan wal in:%dms", vgId, idleDuration); +// tqError("vgId:%d failed to start scan wal in:%dms", vgId, idleDuration); } } diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index bffcaa3916..d6e941c819 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -53,7 +53,7 @@ int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBu SHashObj* pBatchs = taosHashInit(taskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (NULL == pBatchs) { ctgError("taosHashInit %d batch failed", taskNum); - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } for (int32_t i = 0; i < taskNum; ++i) { @@ -462,7 +462,7 @@ int32_t ctgHandleMsgCallback(void* param, SDataBuf* pMsg, int32_t rspCode) { taosHashInit(CTG_DEFAULT_BATCH_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (NULL == pBatchs) { ctgError("taosHashInit %d batch failed", CTG_DEFAULT_BATCH_NUM); - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, -1); @@ -596,7 +596,7 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT taosArrayDestroy(newBatch.pMsgs); taosArrayDestroy(newBatch.pTaskIds); taosArrayDestroy(newBatch.pMsgIdxs); - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } newBatch.conn = *pConn; @@ -606,14 +606,14 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT req.msgLen = msgSize; req.msg = msg; if (NULL == taosArrayPush(newBatch.pMsgs, &req)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } msg = NULL; if (NULL == taosArrayPush(newBatch.pTaskIds, &pTask->taskId)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } if (NULL == taosArrayPush(newBatch.pMsgIdxs, &req.msgIdx)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } if (vgId > 0) { @@ -687,14 +687,14 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT req.msgLen = msgSize; req.msg = msg; if (NULL == taosArrayPush(pBatch->pMsgs, &req)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } msg = NULL; if (NULL == taosArrayPush(pBatch->pTaskIds, &pTask->taskId)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } if (NULL == taosArrayPush(pBatch->pMsgIdxs, &req.msgIdx)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } if (vgId > 0) { @@ -848,7 +848,7 @@ int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray if (pTask) { void* pOut = taosArrayInit(4, sizeof(SQueryNodeLoad)); if (NULL == pOut) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, pOut, NULL)); @@ -861,11 +861,11 @@ int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -913,11 +913,11 @@ int32_t ctgGetDnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -969,11 +969,11 @@ int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SBuildU #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1027,11 +1027,11 @@ int32_t ctgGetDBCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1085,11 +1085,11 @@ int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1150,11 +1150,11 @@ int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* n #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1208,11 +1208,11 @@ int32_t ctgGetUdfInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const ch #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1266,11 +1266,11 @@ int32_t ctgGetUserDbAuthFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1326,11 +1326,11 @@ int32_t ctgGetTbMetaFromMnodeImpl(SCatalog* pCtg, SRequestConnInfo* pConn, const #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1409,11 +1409,11 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa (void)tNameGetFullDbName(ctx->pName, dbFName); SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, &vConn, pTask->pJob, pTaskId, -1, NULL, dbFName, ctx->vgId, reqType, msg, msgLen)); @@ -1482,11 +1482,11 @@ int32_t ctgGetTableCfgFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const S (void)tNameGetFullDbName(ctx->pName, dbFName); SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, &vConn, pTask->pJob, pTaskId, -1, NULL, dbFName, ctx->pVgInfo->vgId, reqType, msg, @@ -1546,11 +1546,11 @@ int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const S #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1598,11 +1598,11 @@ int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, char** ou #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1660,11 +1660,11 @@ int32_t ctgGetViewInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1721,11 +1721,11 @@ int32_t ctgGetTbTSMAFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1792,11 +1792,11 @@ int32_t ctgGetStreamProgressFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, c (void)tNameGetFullDbName(pTbName, dbFName); SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET( diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 74fa645442..96cd783d2f 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -1130,7 +1130,7 @@ int32_t ctgAddMsgCtx(SArray* pCtxs, int32_t reqType, void* out, char* target) { if (NULL == taosArrayPush(pCtxs, &ctx)) { ctgFreeMsgCtx(&ctx); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; @@ -1156,7 +1156,7 @@ int32_t ctgGenerateVgList(SCatalog* pCtg, SHashObj* vgHash, SArray** pList) { vgList = taosArrayInit(vgNum, sizeof(SVgroupInfo)); if (NULL == vgList) { ctgError("taosArrayInit failed, num:%d", vgNum); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } void* pIter = taosHashIterate(vgHash, NULL); @@ -1166,7 +1166,7 @@ int32_t ctgGenerateVgList(SCatalog* pCtg, SHashObj* vgHash, SArray** pList) { if (NULL == taosArrayPush(vgList, vgInfo)) { ctgError("taosArrayPush failed, vgId:%d", vgInfo->vgId); taosHashCancelIterate(vgHash, pIter); - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } pIter = taosHashIterate(vgHash, pIter); @@ -1301,7 +1301,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR for (int32_t i = 0; i < tbNum; ++i) { vgInfo = taosMemoryMalloc(sizeof(SVgroupInfo)); if (NULL == vgInfo) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } TAOS_MEMCPY(vgInfo, &mgmtInfo, sizeof(mgmtInfo)); @@ -1326,7 +1326,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR } else { res.pRes = vgInfo; if (NULL == taosArrayPush(pCtx->pResList, &res)) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } } @@ -1344,7 +1344,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR for (int32_t i = 0; i < tbNum; ++i) { vgInfo = taosMemoryMalloc(sizeof(SVgroupInfo)); if (NULL == vgInfo) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } SVgroupInfo* pSrcVg = (SVgroupInfo*)taosArrayGet(dbInfo->vgArray, 0); @@ -1375,7 +1375,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR } else { res.pRes = vgInfo; if (NULL == taosArrayPush(pCtx->pResList, &res)) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } } @@ -1411,7 +1411,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR SVgroupInfo* pNewVg = taosMemoryMalloc(sizeof(SVgroupInfo)); if (NULL == pNewVg) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } *pNewVg = *vgInfo; @@ -1437,7 +1437,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR } else { res.pRes = pNewVg; if (NULL == taosArrayPush(pCtx->pResList, &res)) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } } @@ -1570,14 +1570,14 @@ int32_t ctgMakeVgArray(SDBVgInfo* dbInfo) { int32_t vgSize = taosHashGetSize(dbInfo->vgHash); dbInfo->vgArray = taosArrayInit(vgSize, sizeof(SVgroupInfo)); if (NULL == dbInfo->vgArray) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } void* pIter = taosHashIterate(dbInfo->vgHash, NULL); while (pIter) { if (NULL == taosArrayPush(dbInfo->vgArray, pIter)) { taosHashCancelIterate(dbInfo->vgHash, pIter); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } pIter = taosHashIterate(dbInfo->vgHash, pIter); @@ -1595,7 +1595,7 @@ int32_t ctgCloneVgInfo(SDBVgInfo* src, SDBVgInfo** dst) { *dst = taosMemoryMalloc(sizeof(SDBVgInfo)); if (NULL == *dst) { qError("malloc %d failed", (int32_t)sizeof(SDBVgInfo)); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } TAOS_MEMCPY(*dst, src, sizeof(SDBVgInfo)); @@ -1605,7 +1605,7 @@ int32_t ctgCloneVgInfo(SDBVgInfo* src, SDBVgInfo** dst) { if (NULL == (*dst)->vgHash) { qError("taosHashInit %d failed", (int32_t)hashSize); taosMemoryFreeClear(*dst); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } int32_t* vgId = NULL; @@ -1640,7 +1640,7 @@ int32_t ctgCloneMetaOutput(STableMetaOutput* output, STableMetaOutput** pOutput) *pOutput = taosMemoryMalloc(sizeof(STableMetaOutput)); if (NULL == *pOutput) { qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } TAOS_MEMCPY(*pOutput, output, sizeof(STableMetaOutput)); @@ -1657,7 +1657,7 @@ int32_t ctgCloneMetaOutput(STableMetaOutput* output, STableMetaOutput** pOutput) if (NULL == (*pOutput)->tbMeta) { qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); taosMemoryFreeClear(*pOutput); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } TAOS_MEMCPY((*pOutput)->tbMeta, output->tbMeta, metaSize); @@ -1681,7 +1681,7 @@ int32_t ctgCloneTableIndex(SArray* pIndex, SArray** pRes) { int32_t num = taosArrayGetSize(pIndex); *pRes = taosArrayInit(num, sizeof(STableIndexInfo)); if (NULL == *pRes) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } for (int32_t i = 0; i < num; ++i) { @@ -1692,7 +1692,7 @@ int32_t ctgCloneTableIndex(SArray* pIndex, SArray** pRes) { } pInfo = taosArrayPush(*pRes, pInfo); if (NULL == pInfo) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } pInfo->expr = taosStrdup(pInfo->expr); if (NULL == pInfo->expr) { @@ -1742,7 +1742,7 @@ int32_t ctgAddFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t* fet if (NULL == (*pFetchs)) { *pFetchs = taosArrayInit(CTG_DEFAULT_FETCH_NUM, sizeof(SCtgFetch)); if (NULL == *pFetchs) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } @@ -1754,7 +1754,7 @@ int32_t ctgAddFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t* fet fetch.flag = flag; if (NULL == taosArrayPush(*pFetchs, &fetch)) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; @@ -2614,7 +2614,7 @@ int32_t ctgBuildViewNullRes(SCtgTask* pTask, SCtgViewsCtx* pCtx) { for (int32_t m = 0; m < viewNum; ++m) { if (NULL == taosArrayPush(pCtx->pResList, &(SMetaData){0})) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } } @@ -2638,7 +2638,7 @@ int32_t dupViewMetaFromRsp(SViewMetaRsp* pRsp, SViewMeta* pViewMeta) { pViewMeta->numOfCols = pRsp->numOfCols; pViewMeta->pSchema = taosMemoryMalloc(pViewMeta->numOfCols * sizeof(SSchema)); if (pViewMeta->pSchema == NULL) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } TAOS_MEMCPY(pViewMeta->pSchema, pRsp->pSchema, pViewMeta->numOfCols * sizeof(SSchema)); @@ -2714,7 +2714,7 @@ int32_t ctgAddTSMAFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t* if (NULL == (*pFetchs)) { *pFetchs = taosArrayInit(CTG_DEFAULT_FETCH_NUM, sizeof(SCtgTSMAFetch)); if (NULL == *pFetchs) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } @@ -2731,7 +2731,7 @@ int32_t ctgAddTSMAFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t* } if (NULL == taosArrayPush(*pFetchs, &fetch)) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index eb74b81141..d24f830ea7 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -692,7 +692,7 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1); char* buf2 = taosMemoryMalloc(SHOW_CREATE_TB_RESULT_FIELD2_LEN); if (NULL == buf2) { - QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_RET(terrno); } int32_t len = 0; @@ -864,7 +864,7 @@ static int32_t buildLocalVariablesResultDataBlock(SSDataBlock** pOutput) { pBlock->pDataBlock = taosArrayInit(SHOW_LOCAL_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData)); if (NULL == pBlock->pDataBlock) { taosMemoryFree(pBlock); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SColumnInfoData infoData = {0}; diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 886425c69b..b82bba250f 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -135,7 +135,7 @@ int32_t qExplainInitCtx(SExplainCtx **pCtx, SHashObj *groupHash, bool verbose, d char *tbuf = taosMemoryMalloc(TSDB_EXPLAIN_RESULT_ROW_SIZE); if (NULL == tbuf) { qError("malloc size %d failed", TSDB_EXPLAIN_RESULT_ROW_SIZE); - QRY_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_JRET(terrno); } ctx->mode = mode; @@ -184,7 +184,7 @@ int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, S *pExecInfo = taosArrayInit(group->nodeNum, sizeof(SExplainExecInfo)); if (NULL == (*pExecInfo)) { qError("taosArrayInit %d explainExecInfo failed", group->nodeNum); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SExplainRsp *rsp = NULL; @@ -302,7 +302,7 @@ int32_t qExplainResAppendRow(SExplainCtx *ctx, char *tbuf, int32_t len, int32_t row.buf = taosMemoryMalloc(len); if (NULL == row.buf) { qError("taosMemoryMalloc %d failed", len); - QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_RET(terrno); } memcpy(row.buf, tbuf, len); @@ -313,7 +313,7 @@ int32_t qExplainResAppendRow(SExplainCtx *ctx, char *tbuf, int32_t len, int32_t if (NULL == taosArrayPush(ctx->rows, &row)) { qError("taosArrayPush row to explain res rows failed"); taosMemoryFree(row.buf); - QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; @@ -1971,7 +1971,7 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize); if (NULL == rsp) { qError("malloc SRetrieveTableRsp failed, size:%d", rspSize); - QRY_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_JRET(terrno); } rsp->completed = 1; @@ -2018,7 +2018,7 @@ int32_t qExplainPrepareCtx(SQueryPlan *pDag, SExplainCtx **pCtx) { taosHashInit(EXPLAIN_MAX_GROUP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (NULL == groupHash) { qError("groupHash %d failed", EXPLAIN_MAX_GROUP_NUM); - QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_RET(terrno); } QRY_ERR_JRET( @@ -2128,7 +2128,7 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t group->nodeExecInfo = taosArrayInit(group->nodeNum, sizeof(SExplainRsp)); if (NULL == group->nodeExecInfo) { qError("taosArrayInit %d explainExecInfo failed", group->nodeNum); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_CHECK_ERRNO(code); } @@ -2149,7 +2149,7 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t if(taosArrayPush(group->nodeExecInfo, pRspMsg) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_CHECK_ERRNO(code); } diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 5352ea37ae..05eaa47cae 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -208,7 +208,7 @@ static SSDataBlock* doLoadRemoteDataImpl(SOperatorInfo* pOperator) { if (p != NULL) { void* tmp = taosArrayPush(pExchangeInfo->pRecycledBlocks, &p); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); pTaskInfo->code = code; T_LONG_JMP(pTaskInfo->env, code); @@ -308,7 +308,7 @@ _end: static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo, const char* id) { pInfo->pSourceDataInfo = taosArrayInit(numOfSources, sizeof(SSourceDataInfo)); if (pInfo->pSourceDataInfo == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (pInfo->dynamicOp) { @@ -329,7 +329,7 @@ static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo, const SSourceDataInfo* pDs = taosArrayPush(pInfo->pSourceDataInfo, &dataInfo); if (pDs == NULL) { taosArrayDestroyEx(pInfo->pSourceDataInfo, freeSourceDataInfo); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -355,7 +355,7 @@ static int32_t initExchangeOperator(SExchangePhysiNode* pExNode, SExchangeInfo* pInfo->pSources = taosArrayInit(numOfSources, sizeof(SDownstreamSourceNode)); if (pInfo->pSources == NULL) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (pExNode->node.dynamicOp) { @@ -375,7 +375,7 @@ static int32_t initExchangeOperator(SExchangePhysiNode* pExNode, SExchangeInfo* void* tmp = taosArrayPush(pInfo->pSources, pNode); if (!tmp) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SExchangeSrcIndex idx = {.srcIdx = i, .inUseIdx = -1}; int32_t code = @@ -579,13 +579,13 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { int32_t buildTableScanOperatorParam(SOperatorParam** ppRes, SArray* pUidList, int32_t srcOpType, bool tableSeq) { *ppRes = taosMemoryMalloc(sizeof(SOperatorParam)); if (NULL == *ppRes) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } STableScanOperatorParam* pScan = taosMemoryMalloc(sizeof(STableScanOperatorParam)); if (NULL == pScan) { taosMemoryFreeClear(*ppRes); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pScan->pUidList = taosArrayDup(pUidList, NULL); @@ -1045,7 +1045,7 @@ int32_t addSingleExchangeSource(SOperatorInfo* pOperator, SExchangeOperatorBasic void* tmp = taosArrayPush(pExchangeInfo->pSourceDataInfo, &dataInfo); if (!tmp) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pIdx->inUseIdx = taosArrayGetSize(pExchangeInfo->pSourceDataInfo) - 1; } else { diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 01104dfe21..117a30ade2 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -622,14 +622,14 @@ int32_t getColInfoResultForGroupby(void* pVnode, SNodeList* group, STableListInf tagFilterAssist ctx = {0}; ctx.colHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_SMALLINT), false, HASH_NO_LOCK); if (ctx.colHash == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } ctx.index = 0; ctx.cInfoList = taosArrayInit(4, sizeof(SColumnInfo)); if (ctx.cInfoList == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } @@ -766,7 +766,7 @@ int32_t getColInfoResultForGroupby(void* pVnode, SNodeList* group, STableListInf pTableListInfo->remainGroups = taosHashInit(rows, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); if (pTableListInfo->remainGroups == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } @@ -1024,7 +1024,7 @@ static int32_t optimizeTbnameInCondImpl(void* pVnode, SArray* pExistedUidList, S uHash = taosHashInit(numOfExisted / 0.7, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); if (!uHash) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int i = 0; i < numOfExisted; i++) { @@ -1052,7 +1052,7 @@ static int32_t optimizeTbnameInCondImpl(void* pVnode, SArray* pExistedUidList, S STUidTagInfo s = {.uid = uid, .name = name, .pTagVal = NULL}; void* tmp = taosArrayPush(pExistedUidList, &s); if (!tmp) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } } else { @@ -1193,13 +1193,13 @@ static int32_t doSetQualifiedUid(STableListInfo* pListInfo, SArray* pUidList, co info.uid = uid; void* p = taosArrayPush(pListInfo->pTableList, &info); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (addUid) { void* tmp = taosArrayPush(pUidList, &uid); if (tmp == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } } @@ -1465,7 +1465,7 @@ _end: void* p = taosArrayPush(pListInfo->pTableList, &info); if (p == NULL) { taosArrayDestroy(pUidList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } qTrace("tagfilter get uid:%" PRIu64 ", %s", info.uid, idstr); @@ -1652,7 +1652,7 @@ int32_t extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod SArray* pList = taosArrayInit(numOfCols, sizeof(SColMatchItem)); if (pList == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; return code; } @@ -2643,7 +2643,7 @@ static int32_t sortTableGroup(STableListInfo* pTableListInfo) { pTableListInfo->groupOffset = taosMemoryMalloc(sizeof(int32_t) * pTableListInfo->numOfOuputGroups); if (pTableListInfo->groupOffset == NULL) { taosArrayDestroy(pList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pTableListInfo->groupOffset, taosArrayGet(pList, 0), sizeof(int32_t) * pTableListInfo->numOfOuputGroups); @@ -2666,7 +2666,7 @@ int32_t buildGroupIdMapForAllTables(STableListInfo* pTableListInfo, SReadHandle* pTableListInfo->remainGroups = taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); if (pTableListInfo->remainGroups == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int i = 0; i < numOfTables; i++) { diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index cd43c5c99e..c3228f59bf 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -488,7 +488,7 @@ int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableI keyBuf = taosMemoryMalloc(bufLen); if (keyBuf == NULL) { taosArrayDestroy(qa); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -877,7 +877,7 @@ int32_t qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo if (!tmp) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } diff --git a/source/libs/executor/src/executorInt.c b/source/libs/executor/src/executorInt.c index 4fef157984..b5c05c8558 100644 --- a/source/libs/executor/src/executorInt.c +++ b/source/libs/executor/src/executorInt.c @@ -1137,7 +1137,7 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t)); if (NULL == pDeleterParam->pUidList) { taosMemoryFree(pDeleterParam); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < numOfTables; ++i) { @@ -1151,7 +1151,7 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* if (!tmp) { taosArrayDestroy(pDeleterParam->pUidList); taosMemoryFree(pDeleterParam); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } diff --git a/source/libs/executor/src/filloperator.c b/source/libs/executor/src/filloperator.c index 76b41ca99a..d530382f7c 100644 --- a/source/libs/executor/src/filloperator.c +++ b/source/libs/executor/src/filloperator.c @@ -403,7 +403,7 @@ static int32_t createPrimaryTsExprIfNeeded(SFillOperatorInfo* pInfo, SFillPhysiN SExprInfo* pExpr = taosMemoryRealloc(pExprSupp->pExprInfo, (pExprSupp->numOfExprs + 1) * sizeof(SExprInfo)); if (pExpr == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = createExprFromTargetNode(&pExpr[pExprSupp->numOfExprs], (STargetNode*)pPhyFillNode->pWStartTs); diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index 17e18710f2..06706b57ee 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -45,7 +45,7 @@ static int32_t initGroupColsInfo(SGroupColsInfo* pCols, bool grpColsMayBeNull, S pCols->withNull = grpColsMayBeNull; pCols->pColsInfo = taosMemoryMalloc(pCols->colNum * sizeof(SGroupColInfo)); if (NULL == pCols->pColsInfo) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t i = 0; @@ -67,7 +67,7 @@ static int32_t initGroupColsInfo(SGroupColsInfo* pCols, bool grpColsMayBeNull, S if (pCols->colNum > 1) { pCols->pBuf = taosMemoryMalloc(pCols->bufSize); if (NULL == pCols->pBuf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -227,7 +227,7 @@ static int32_t acquireFdFromFileCtx(SGcFileCacheCtx* pFileCtx, int32_t fileId, S if (NULL == pFileCtx->pCacheFile) { pFileCtx->pCacheFile = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK); if (NULL == pFileCtx->pCacheFile) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pFileCtx->pCacheFile, freeSGroupCacheFileInfo); } @@ -461,7 +461,7 @@ static int32_t addBlkToBufCache(struct SOperatorInfo* pOperator, SSDataBlock* pB pBufInfo->pBuf = taosMemoryMalloc(bufSize); if (NULL == pBufInfo->pBuf) { qError("group cache add block to cache failed, size:%" PRId64, bufSize); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } QRY_ERR_RET(blockDataToBuf(pBufInfo->pBuf, pBlock)); @@ -508,7 +508,7 @@ void blockDataDeepClear(SSDataBlock* pDataBlock) { static int32_t buildGroupCacheBaseBlock(SSDataBlock** ppDst, SSDataBlock* pSrc) { *ppDst = taosMemoryMalloc(sizeof(*pSrc)); if (NULL == *ppDst) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*ppDst)->pBlockAgg = NULL; (*ppDst)->pDataBlock = taosArrayDup(pSrc->pDataBlock, NULL); @@ -578,7 +578,7 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa *ppBuf = taosMemoryMalloc(pBasic->bufSize); if (NULL == *ppBuf) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return; } @@ -643,7 +643,7 @@ static int32_t addNewGroupToVgHash(SOperatorInfo* pOperator, SSHashObj* pHash, S if (NULL == pVgCtx) { SArray* pList = taosArrayInit(10, sizeof(*pNew)); if (NULL == pList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (NULL == taosArrayPush(pList, pNew)) { QRY_ERR_RET(terrno); @@ -798,7 +798,7 @@ static int32_t addFileRefTableNum(SGcFileCacheCtx* pFileCtx, int32_t fileId, int if (NULL == pFileCtx->pCacheFile) { pFileCtx->pCacheFile = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK); if (NULL == pFileCtx->pCacheFile) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pFileCtx->pCacheFile, freeSGroupCacheFileInfo); } @@ -913,7 +913,7 @@ static int32_t addNewGroupData(struct SOperatorInfo* pOperator, SOperatorParam* taosWLockLatch(&pCtx->grpLock); if (NULL == taosArrayPush(pCtx->pNewGrpList, &newGroup)) { taosWUnLockLatch(&pCtx->grpLock); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosWUnLockLatch(&pCtx->grpLock); @@ -1248,12 +1248,12 @@ static int32_t initGroupCacheBlockCache(SGroupCacheOperatorInfo* pInfo) { SGcBlkCacheInfo* pCache = &pInfo->blkCache; pCache->pDirtyBlk = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); if (NULL == pCache->pDirtyBlk) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pCache->pDirtyBlk, freeGcBlkBufInfo); pCache->pReadBlk = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); if (NULL == pCache->pReadBlk) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pCache->writeDownstreamId = -1; @@ -1421,30 +1421,30 @@ static int32_t initGroupCacheDownstreamCtx(SOperatorInfo* pOperator) { pCtx->pNewGrpList = taosArrayInit(10, sizeof(SGcNewGroupInfo)); if (NULL == pCtx->pNewGrpList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (!pInfo->globalGrp) { pCtx->pGrpHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (pCtx->pGrpHash == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pCtx->pGrpHash, freeRemoveGroupCacheData); } pCtx->pSessions = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); if (pCtx->pSessions == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pCtx->pSessions, freeSGcSessionCtx); pCtx->pFreeBlock = taosArrayInit(10, POINTER_BYTES); if (NULL == pCtx->pFreeBlock) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pCtx->pWaitSessions = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); if (pCtx->pWaitSessions == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)snprintf(pCtx->fileCtx.baseFilename, sizeof(pCtx->fileCtx.baseFilename) - 1, "%s/gc_%d_%" PRIx64 "_%" PRIu64 "_%d", @@ -1539,7 +1539,7 @@ int32_t createGroupCacheOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfD if (pInfo->globalGrp) { pInfo->pGrpHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (pInfo->pGrpHash == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _error; } taosHashSetFreeFp(pInfo->pGrpHash, freeRemoveGroupCacheData); diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index e4ace6b83a..83a579615c 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -94,7 +94,7 @@ static void destroyGroupOperatorInfo(void* param) { static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** keyBuf, const SArray* pGroupColList) { *pGroupColVals = taosArrayInit(4, sizeof(SGroupKeys)); if ((*pGroupColVals) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t numOfGroupCols = taosArrayGetSize(pGroupColList); @@ -117,7 +117,7 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** void* tmp = taosArrayPush((*pGroupColVals), &key); if (!tmp) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -1555,7 +1555,7 @@ static void destroyStreamPartitionOperatorInfo(void* param) { } int32_t initParDownStream(SOperatorInfo* downstream, SPartitionBySupporter* pParSup, SExprSupp* pExpr, - SExprSupp* pTbnameExpr) { + SExprSupp* pTbnameExpr, SExprSupp* pResExprSupp, int32_t* pPkColIndex) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; SStorageAPI* pAPI = &downstream->pTaskInfo->storageAPI; @@ -1568,6 +1568,11 @@ int32_t initParDownStream(SOperatorInfo* downstream, SPartitionBySupporter* pPar pScanInfo->partitionSup = *pParSup; pScanInfo->pPartScalarSup = pExpr; pScanInfo->pPartTbnameSup = pTbnameExpr; + for (int32_t j = 0; j < pResExprSupp->numOfExprs; j++) { + if (pScanInfo->primaryKeyIndex == pResExprSupp->pExprInfo[j].base.pParam[0].pCol->slotId) { + *pPkColIndex = j; + } + } if (!pScanInfo->pUpdateInfo) { code = pAPI->stateStore.updateInfoInit(60000, TSDB_TIME_PRECISION_MILLI, 0, pScanInfo->igCheckUpdate, pScanInfo->pkColType, pScanInfo->pkColLen, &pScanInfo->pUpdateInfo); @@ -1729,7 +1734,8 @@ int32_t createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStreamPart optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL); setOperatorStreamStateFn(pOperator, streamOpReleaseState, streamOpReloadState); - code = initParDownStream(downstream, &pInfo->partitionSup, &pInfo->scalarSup, &pInfo->tbnameCalSup); + pInfo->basic.primaryPkIndex = -1; + code = initParDownStream(downstream, &pInfo->partitionSup, &pInfo->scalarSup, &pInfo->tbnameCalSup, &pOperator->exprSupp, &pInfo->basic.primaryPkIndex); QUERY_CHECK_CODE(code, lino, _error); code = appendDownstream(pOperator, &downstream, 1); @@ -1752,7 +1758,7 @@ int32_t extractColumnInfo(SNodeList* pNodeList, SArray** pArrayRes) { size_t numOfCols = LIST_LENGTH(pNodeList); SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn)); if (pList == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; (*pArrayRes) = NULL; QUERY_CHECK_CODE(code, lino, _end); } diff --git a/source/libs/executor/src/hashjoinoperator.c b/source/libs/executor/src/hashjoinoperator.c index 7f13608653..347c48b4d1 100644 --- a/source/libs/executor/src/hashjoinoperator.c +++ b/source/libs/executor/src/hashjoinoperator.c @@ -155,7 +155,7 @@ static int32_t hJoinInitKeyColsInfo(SHJoinTableCtx* pTable, SNodeList* pList) { pTable->keyCols = taosMemoryMalloc(pTable->keyNum * sizeof(SHJoinColInfo)); if (NULL == pTable->keyCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int64_t bufSize = 0; @@ -173,7 +173,7 @@ static int32_t hJoinInitKeyColsInfo(SHJoinTableCtx* pTable, SNodeList* pList) { if (pTable->keyNum > 1) { pTable->keyBuf = taosMemoryMalloc(bufSize); if (NULL == pTable->keyBuf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -212,7 +212,7 @@ static int32_t hJoinInitValColsInfo(SHJoinTableCtx* pTable, SNodeList* pList) { pTable->valCols = taosMemoryMalloc(pTable->valNum * sizeof(SHJoinColInfo)); if (NULL == pTable->valCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t i = 0; @@ -260,7 +260,7 @@ static int32_t hJoinInitValColsInfo(SHJoinTableCtx* pTable, SNodeList* pList) { static int32_t hJoinInitPrimKeyInfo(SHJoinTableCtx* pTable, int32_t slotId) { pTable->primCol = taosMemoryMalloc(sizeof(SHJoinColMap)); if (NULL == pTable->primCol) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pTable->primCol->srcSlot = slotId; @@ -413,7 +413,7 @@ static FORCE_INLINE int32_t hJoinAddPageToBufs(SArray* pRowBufs) { page.offset = 0; page.data = taosMemoryMalloc(page.pageSize); if (NULL == page.data) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (NULL == taosArrayPush(pRowBufs, &page)) { @@ -425,7 +425,7 @@ static FORCE_INLINE int32_t hJoinAddPageToBufs(SArray* pRowBufs) { static int32_t hJoinInitBufPages(SHJoinOperatorInfo* pInfo) { pInfo->pRowBufs = taosArrayInit(32, sizeof(SBufPageInfo)); if (NULL == pInfo->pRowBufs) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return hJoinAddPageToBufs(pInfo->pRowBufs); @@ -784,13 +784,13 @@ static int32_t hJoinAddRowToHashImpl(SHJoinOperatorInfo* pJoin, SGroupData* pGro if (NULL == pGroup) { group.rows = taosMemoryMalloc(sizeof(SBufRowInfo)); if (NULL == group.rows) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pRow = group.rows; } else { pRow = taosMemoryMalloc(sizeof(SBufRowInfo)); if (NULL == pRow) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } diff --git a/source/libs/executor/src/querytask.c b/source/libs/executor/src/querytask.c index cb0ebcff70..4821461ca2 100644 --- a/source/libs/executor/src/querytask.c +++ b/source/libs/executor/src/querytask.c @@ -54,7 +54,7 @@ int32_t doCreateTask(uint64_t queryId, uint64_t taskId, int32_t vgId, EOPTR_EXEC p->pResultBlockList = taosArrayInit(128, POINTER_BYTES); if (p->stopInfo.pStopInfo == NULL || p->pResultBlockList == NULL) { doDestroyTask(p); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } p->storageAPI = *pAPI; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index b6b5c5484e..76e4f8ba56 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -191,7 +191,7 @@ static int32_t insertTableToScanIgnoreList(STableScanInfo* pTableScanInfo, uint6 pTableScanInfo->pIgnoreTables = taosHashInit(tableNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); if (NULL == pTableScanInfo->pIgnoreTables) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -1169,7 +1169,7 @@ static int32_t createTableListInfoFromParam(SOperatorInfo* pOperator) { info.uid = *pUid; void* p = taosArrayPush(pListInfo->pTableList, &info); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tableIdx++; @@ -4078,6 +4078,7 @@ int32_t createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* SDataType pkType = {0}; pInfo->primaryKeyIndex = -1; + pInfo->basic.primaryPkIndex = -1; int32_t numOfOutput = taosArrayGetSize(pInfo->matchInfo.pList); pColIds = taosArrayInit(numOfOutput, sizeof(int16_t)); QUERY_CHECK_NULL(pColIds, code, lino, _error, terrno); @@ -4095,6 +4096,7 @@ int32_t createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* } if (id->isPk) { pInfo->primaryKeyIndex = id->dstSlotId; + pInfo->basic.primaryPkIndex = id->dstSlotId; pkType = id->dataType; } } diff --git a/source/libs/executor/src/streamcountwindowoperator.c b/source/libs/executor/src/streamcountwindowoperator.c index 524ef6ee2f..adf764a8c5 100644 --- a/source/libs/executor/src/streamcountwindowoperator.c +++ b/source/libs/executor/src/streamcountwindowoperator.c @@ -582,7 +582,7 @@ int32_t deleteCountWinState(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, S int32_t lino = 0; SArray* pWins = taosArrayInit(16, sizeof(SSessionKey)); if (!pWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -880,7 +880,7 @@ int32_t createStreamCountAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pInfo->dataVersion = 0; pInfo->historyWins = taosArrayInit(4, sizeof(SSessionKey)); if (!pInfo->historyWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } diff --git a/source/libs/executor/src/streameventwindowoperator.c b/source/libs/executor/src/streameventwindowoperator.c index 735b470325..a325616bd3 100644 --- a/source/libs/executor/src/streameventwindowoperator.c +++ b/source/libs/executor/src/streameventwindowoperator.c @@ -695,7 +695,7 @@ static int32_t doStreamEventAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRe if (pInfo->isHistoryOp) { SArray* pHisWins = taosArrayInit(16, sizeof(SEventWindowInfo)); if (!pHisWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } diff --git a/source/libs/executor/src/streamfilloperator.c b/source/libs/executor/src/streamfilloperator.c index 58e57eb88b..4d5f597ab6 100644 --- a/source/libs/executor/src/streamfilloperator.c +++ b/source/libs/executor/src/streamfilloperator.c @@ -858,7 +858,7 @@ static int32_t doDeleteFillResultImpl(SOperatorInfo* pOperator, TSKEY startTs, T }; void* tmp = taosArrayPush(pInfo->pFillInfo->delRanges, &tw); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -1264,13 +1264,13 @@ SStreamFillInfo* initStreamFillInfo(SStreamFillSupporter* pFillSup, SSDataBlock* if (pFillSup->type == TSDB_FILL_LINEAR) { pFillInfo->pLinearInfo->pEndPoints = taosArrayInit(pFillSup->numOfAllCols, sizeof(SPoint)); if (!pFillInfo->pLinearInfo->pEndPoints) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } pFillInfo->pLinearInfo->pNextEndPoints = taosArrayInit(pFillSup->numOfAllCols, sizeof(SPoint)); if (!pFillInfo->pLinearInfo->pNextEndPoints) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -1285,7 +1285,7 @@ SStreamFillInfo* initStreamFillInfo(SStreamFillSupporter* pFillSup, SSDataBlock* void* tmpRes = taosArrayPush(pFillInfo->pLinearInfo->pEndPoints, &value); if (!tmpRes) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -1297,7 +1297,7 @@ SStreamFillInfo* initStreamFillInfo(SStreamFillSupporter* pFillSup, SSDataBlock* tmpRes = taosArrayPush(pFillInfo->pLinearInfo->pNextEndPoints, &value); if (!tmpRes) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -1331,7 +1331,7 @@ SStreamFillInfo* initStreamFillInfo(SStreamFillSupporter* pFillSup, SSDataBlock* pFillInfo->type = pFillSup->type; pFillInfo->delRanges = taosArrayInit(16, sizeof(STimeRange)); if (!pFillInfo->delRanges) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } diff --git a/source/libs/executor/src/streamtimewindowoperator.c b/source/libs/executor/src/streamtimewindowoperator.c index b9484decdc..1879af3b50 100644 --- a/source/libs/executor/src/streamtimewindowoperator.c +++ b/source/libs/executor/src/streamtimewindowoperator.c @@ -157,7 +157,7 @@ static int32_t savePullWindow(SPullWindowInfo* pPullInfo, SArray* pPullWins) { } } if (taosArrayInsert(pPullWins, index, pPullInfo) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } @@ -298,7 +298,7 @@ static int32_t doDeleteWindows(SOperatorInfo* pOperator, SInterval* pInterval, S if (pUpWins) { void* tmp = taosArrayPush(pUpWins, &winRes); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -541,14 +541,21 @@ void reloadFromDownStream(SOperatorInfo* downstream, SStreamIntervalOperatorInfo pInfo->pUpdateInfo = pScanInfo->pUpdateInfo; } -int32_t initIntervalDownStream(SOperatorInfo* downstream, uint16_t type, SStreamIntervalOperatorInfo* pInfo) { +bool hasSrcPrimaryKeyCol(SSteamOpBasicInfo* pInfo) { return pInfo->primaryPkIndex != -1; } + +int32_t initIntervalDownStream(SOperatorInfo* downstream, uint16_t type, SStreamIntervalOperatorInfo* pInfo, struct SSteamOpBasicInfo* pBasic) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; SStateStore* pAPI = &downstream->pTaskInfo->storageAPI.stateStore; SExecTaskInfo* pTaskInfo = downstream->pTaskInfo; + if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION) { + SStreamPartitionOperatorInfo* pScanInfo = downstream->info; + pBasic->primaryPkIndex = pScanInfo->basic.primaryPkIndex; + } + if (downstream->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { - return initIntervalDownStream(downstream->pDownstream[0], type, pInfo); + return initIntervalDownStream(downstream->pDownstream[0], type, pInfo, pBasic); } SStreamScanInfo* pScanInfo = downstream->info; @@ -564,7 +571,9 @@ int32_t initIntervalDownStream(SOperatorInfo* downstream, uint16_t type, SStream pScanInfo->twAggSup = pInfo->twAggSup; pScanInfo->pState = pInfo->pState; pInfo->pUpdateInfo = pScanInfo->pUpdateInfo; - pInfo->basic.primaryPkIndex = pScanInfo->primaryKeyIndex; + if (!hasSrcPrimaryKeyCol(pBasic)) { + pBasic->primaryPkIndex = pScanInfo->basic.primaryPkIndex; + } _end: if (code != TSDB_CODE_SUCCESS) { @@ -674,7 +683,7 @@ int32_t addPullWindow(SHashObj* pMap, SWinKey* pWinRes, int32_t size) { for (int32_t i = 0; i < size; i++) { void* tmp = taosArrayPush(childIds, &i); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -810,13 +819,13 @@ static int32_t processPullOver(SSDataBlock* pBlock, SHashObj* pMap, SHashObj* pF void* tmp = taosArrayPush(pInfo->pMidPullDatas, &winRes); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } else if (savePullWindow(&pull, pPullWins) == TSDB_CODE_SUCCESS) { void* tmp = taosArrayPush(pInfo->pDelWins, &winRes); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -1013,8 +1022,6 @@ static int32_t getNextQualifiedFinalWindow(SInterval* pInterval, STimeWindow* pN return startPos; } -bool hasSrcPrimaryKeyCol(SSteamOpBasicInfo* pInfo) { return pInfo->primaryPkIndex != -1; } - static int32_t doStreamIntervalAggImpl(SOperatorInfo* pOperator, SSDataBlock* pSDataBlock, uint64_t groupId, SSHashObj* pUpdatedMap, SSHashObj* pDeletedMap) { int32_t code = TSDB_CODE_SUCCESS; @@ -1295,7 +1302,7 @@ int32_t decodeSPullWindowInfoArray(void* buf, SArray* pPullInfos, void** ppBuf) buf = decodeSPullWindowInfo(buf, &item); void* tmp = taosArrayPush(pPullInfos, &item); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -1410,7 +1417,7 @@ void doStreamIntervalDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpera SWinKey key = {0}; SArray* pArray = taosArrayInit(0, sizeof(int32_t)); if (!pArray) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -1422,7 +1429,7 @@ void doStreamIntervalDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpera buf = taosDecodeFixedI32(buf, &chId); void* tmp = taosArrayPush(pArray, &chId); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -1470,7 +1477,7 @@ static int32_t copyIntervalDeleteKey(SSHashObj* pMap, SArray* pWins) { void* pKey = tSimpleHashGetKey(pIte, NULL); void* tmp = taosArrayPush(pWins, pKey); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -1532,7 +1539,7 @@ int32_t copyUpdateResult(SSHashObj** ppWinUpdated, SArray* pUpdated, __compar_fn while ((pIte = tSimpleHashIterate(*ppWinUpdated, pIte, &iter)) != NULL) { void* tmp = taosArrayPush(pUpdated, pIte); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -2036,7 +2043,8 @@ int32_t createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiN setOperatorStreamStateFn(pOperator, streamIntervalReleaseState, streamIntervalReloadState); if (pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL || pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_MID_INTERVAL) { - code = initIntervalDownStream(downstream, pPhyNode->type, pInfo); + pInfo->basic.primaryPkIndex = -1; + code = initIntervalDownStream(downstream, pPhyNode->type, pInfo, &pInfo->basic); QUERY_CHECK_CODE(code, lino, _error); } code = appendDownstream(pOperator, &downstream, 1); @@ -2140,6 +2148,7 @@ int32_t initDownStream(SOperatorInfo* downstream, SStreamAggSupporter* pAggSup, if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION) { SStreamPartitionOperatorInfo* pScanInfo = downstream->info; pScanInfo->tsColIndex = tsColIndex; + pBasic->primaryPkIndex = pScanInfo->basic.primaryPkIndex; } if (downstream->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { @@ -2157,7 +2166,9 @@ int32_t initDownStream(SOperatorInfo* downstream, SStreamAggSupporter* pAggSup, } pScanInfo->twAggSup = *pTwSup; pAggSup->pUpdateInfo = pScanInfo->pUpdateInfo; - pBasic->primaryPkIndex = pScanInfo->primaryKeyIndex; + if (!hasSrcPrimaryKeyCol(pBasic)) { + pBasic->primaryPkIndex = pScanInfo->basic.primaryPkIndex; + } _end: if (code != TSDB_CODE_SUCCESS) { @@ -2304,7 +2315,7 @@ int32_t saveDeleteInfo(SArray* pWins, SSessionKey key) { int32_t lino = 0; void* res = taosArrayPush(pWins, &key); if (!res) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -3148,7 +3159,7 @@ int32_t getMaxTsWins(const SArray* pAllWins, SArray* pMaxWins) { SSessionKey* pSeKey = &pWinInfo->sessionWin; void* tmp = taosArrayPush(pMaxWins, pSeKey); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -3162,7 +3173,7 @@ int32_t getMaxTsWins(const SArray* pAllWins, SArray* pMaxWins) { if (preGpId != pSeKey->groupId) { void* tmp = taosArrayPush(pMaxWins, pSeKey); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } preGpId = pSeKey->groupId; @@ -3218,7 +3229,7 @@ int32_t doStreamSessionEncodeOpState(void** buf, int32_t len, SOperatorInfo* pOp size_t keyLen = 0; int32_t iter = 0; while ((pIte = tSimpleHashIterate(pInfo->streamAggSup.pResultRows, pIte, &iter)) != NULL) { - void* key = taosHashGetKey(pIte, &keyLen); + void* key = tSimpleHashGetKey(pIte, &keyLen); tlen += encodeSSessionKey(buf, key); tlen += encodeSResultWindowInfo(buf, pIte, pInfo->streamAggSup.resultRowSize); } @@ -3866,6 +3877,7 @@ int32_t createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode setOperatorStreamStateFn(pOperator, streamSessionReleaseState, streamSessionReloadState); if (downstream) { + pInfo->basic.primaryPkIndex = -1; code = initDownStream(downstream, &pInfo->streamAggSup, pOperator->operatorType, pInfo->primaryTsIndex, &pInfo->twAggSup, &pInfo->basic); QUERY_CHECK_CODE(code, lino, _error); @@ -3899,7 +3911,7 @@ int32_t deleteSessionWinState(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, int32_t lino = 0; SArray* pWins = taosArrayInit(16, sizeof(SSessionKey)); if (!pWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } code = doDeleteTimeWindows(pAggSup, pBlock, pWins); @@ -4116,7 +4128,7 @@ int32_t createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream, SPhys pAPI->stateStore.streamStateSetNumber(pChInfo->streamAggSup.pState, i, pInfo->primaryTsIndex); void* tmp = taosArrayPush(pInfo->pChildren, &pChildOp); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } } @@ -5213,7 +5225,7 @@ static int32_t doStreamIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock** p while ((pIte = tSimpleHashIterate(pInfo->pUpdatedMap, pIte, &iter)) != NULL) { void* tmp = taosArrayPush(pInfo->pUpdated, pIte); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -5377,7 +5389,8 @@ int32_t createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiNode* taosMemoryFree(buff); } - code = initIntervalDownStream(downstream, pPhyNode->type, pInfo); + pInfo->basic.primaryPkIndex = -1; + code = initIntervalDownStream(downstream, pPhyNode->type, pInfo, &pInfo->basic); QUERY_CHECK_CODE(code, lino, _error); code = appendDownstream(pOperator, &downstream, 1); @@ -5633,7 +5646,7 @@ static int32_t doStreamMidIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock* pBlock->info.type == STREAM_CLEAR) { SArray* delWins = taosArrayInit(8, sizeof(SWinKey)); if (!delWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } code = @@ -5687,7 +5700,7 @@ static int32_t doStreamMidIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock* } else if (pBlock->info.type == STREAM_MID_RETRIEVE) { SArray* delWins = taosArrayInit(8, sizeof(SWinKey)); if (!delWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } code = doDeleteWindows(pOperator, &pInfo->interval, pBlock, delWins, pInfo->pUpdatedMap, NULL); @@ -5732,7 +5745,7 @@ static int32_t doStreamMidIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock* while ((pIte = tSimpleHashIterate(pInfo->pUpdatedMap, pIte, &iter)) != NULL) { void* tmp = taosArrayPush(pInfo->pUpdated, pIte); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 18344d9e79..dcebdf59a9 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -2576,7 +2576,7 @@ int32_t optSysIntersection(SArray* in, SArray* out) { if (has == true) { void* tmp = taosArrayPush(out, &tgt); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _end; } } diff --git a/source/libs/executor/src/timesliceoperator.c b/source/libs/executor/src/timesliceoperator.c index f9211e5730..2ea300ace8 100644 --- a/source/libs/executor/src/timesliceoperator.c +++ b/source/libs/executor/src/timesliceoperator.c @@ -544,7 +544,7 @@ static int32_t initPrevRowsKeeper(STimeSliceOperatorInfo* pInfo, SSDataBlock* pB pInfo->pPrevRow = taosArrayInit(4, sizeof(SGroupKeys)); if (pInfo->pPrevRow == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); @@ -579,7 +579,7 @@ static int32_t initNextRowsKeeper(STimeSliceOperatorInfo* pInfo, SSDataBlock* pB pInfo->pNextRow = taosArrayInit(4, sizeof(SGroupKeys)); if (pInfo->pNextRow == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); @@ -615,7 +615,7 @@ static int32_t initFillLinearInfo(STimeSliceOperatorInfo* pInfo, SSDataBlock* pB pInfo->pLinearInfo = taosArrayInit(4, sizeof(SFillLinearInfo)); if (pInfo->pLinearInfo == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); diff --git a/source/libs/executor/src/tlinearhash.c b/source/libs/executor/src/tlinearhash.c index 9654f74ab1..99ef7ad9d9 100644 --- a/source/libs/executor/src/tlinearhash.c +++ b/source/libs/executor/src/tlinearhash.c @@ -229,7 +229,7 @@ static int32_t doAddNewBucket(SLHashObj* pHashObj) { char* p = taosMemoryRealloc(pHashObj->pBucket, POINTER_BYTES * newLen); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memset(p + POINTER_BYTES * pHashObj->numOfBuckets, 0, newLen - pHashObj->numOfBuckets); diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 19b825b0ca..00daafa59d 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -432,7 +432,7 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) { int32_t tsortAddSource(SSortHandle* pSortHandle, void* pSource) { void* p = taosArrayPush(pSortHandle->pOrderedSource, &pSource); - return (p != NULL)? TSDB_CODE_SUCCESS:TSDB_CODE_OUT_OF_MEMORY; + return (p != NULL)? TSDB_CODE_SUCCESS:terrno; } static int32_t doAddNewExternalMemSource(SDiskbasedBuf* pBuf, SArray* pAllSources, SSDataBlock* pBlock, @@ -449,7 +449,7 @@ static int32_t doAddNewExternalMemSource(SDiskbasedBuf* pBuf, SArray* pAllSource void* p = taosArrayPush(pAllSources, &pSource); if (p == NULL) { taosArrayDestroy(pPageIdList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*sourceId) += 1; @@ -525,7 +525,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { if (px == NULL) { taosArrayDestroy(pPageIdList); blockDataDestroy(p); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t size = blockDataGetSize(p) + sizeof(int32_t) + taosArrayGetSize(p->pDataBlock) * sizeof(int32_t); diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index d9b72b36b7..5db8863311 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -102,7 +102,6 @@ static int32_t exprNodeCopy(const SExprNode* pSrc, SExprNode* pDst) { COPY_OBJECT_FIELD(resType, sizeof(SDataType)); COPY_CHAR_ARRAY_FIELD(aliasName); COPY_CHAR_ARRAY_FIELD(userAlias); - COPY_SCALAR_FIELD(orderAlias); COPY_SCALAR_FIELD(projIdx); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 22acf4df45..06adcb4961 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -2443,8 +2443,7 @@ typedef struct SCollectFuncsCxt { static EDealRes collectFuncs(SNode* pNode, void* pContext) { SCollectFuncsCxt* pCxt = (SCollectFuncsCxt*)pContext; - if (QUERY_NODE_FUNCTION == nodeType(pNode) && pCxt->classifier(((SFunctionNode*)pNode)->funcId) && - !(((SExprNode*)pNode)->orderAlias)) { + if (QUERY_NODE_FUNCTION == nodeType(pNode) && pCxt->classifier(((SFunctionNode*)pNode)->funcId)) { SFunctionNode* pFunc = (SFunctionNode*)pNode; if (FUNCTION_TYPE_TBNAME == pFunc->funcType && pCxt->tableAlias) { SValueNode* pVal = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 0); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 7d991bce23..bc536d3b4f 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -6741,7 +6741,6 @@ static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) { pCxt->pTranslateCxt->errCode = code; return DEAL_RES_ERROR; } - ((SExprNode*)pNew)->orderAlias = true; nodesDestroyNode(*pNode); *pNode = pNew; return DEAL_RES_CONTINUE; @@ -6765,7 +6764,6 @@ static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) { pCxt->pTranslateCxt->errCode = code; return DEAL_RES_ERROR; } - ((SExprNode*)pNew)->orderAlias = true; ((SOrderByExprNode*)*pNode)->pExpr = pNew; nodesDestroyNode(pExpr); return DEAL_RES_CONTINUE; @@ -7152,7 +7150,6 @@ static int32_t addOrderByPrimaryKeyToQueryImpl(STranslateContext* pCxt, SNode* p nodesDestroyNode((SNode*)pOrderByExpr); return code; } - ((SExprNode*)pOrderByExpr->pExpr)->orderAlias = true; // NODES_DESTORY_LIST(*pOrderByList); return nodesListMakeStrictAppend(pOrderByList, (SNode*)pOrderByExpr); } diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 57f75743ac..d27aaf39e1 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -3439,7 +3439,6 @@ int32_t streamStateGetFirst_rocksdb(SStreamState* pState, SWinKey* key) { } int32_t streamStateGetGroupKVByCur_rocksdb(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen) { - stDebug("streamStateGetGroupKVByCur_rocksdb"); if (!pCur) { return -1; } @@ -3885,7 +3884,6 @@ SStreamStateCur* streamStateSessionSeekKeyPrev_rocksdb(SStreamState* pState, con } int32_t streamStateSessionGetKVByCur_rocksdb(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen) { - stDebug("streamStateSessionGetKVByCur_rocksdb"); if (!pCur) { return -1; } @@ -3985,7 +3983,6 @@ SStreamStateCur* streamStateFillGetCur_rocksdb(SStreamState* pState, const SWinK return NULL; } int32_t streamStateFillGetKVByCur_rocksdb(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen) { - stDebug("streamStateFillGetKVByCur_rocksdb"); if (!pCur) { return -1; } diff --git a/source/libs/stream/src/streamCheckpoint.c b/source/libs/stream/src/streamCheckpoint.c index 769116264d..47eec2119a 100644 --- a/source/libs/stream/src/streamCheckpoint.c +++ b/source/libs/stream/src/streamCheckpoint.c @@ -900,9 +900,6 @@ static int32_t doChkptStatusCheck(SStreamTask* pTask) { int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask); stDebug("s-task:%s vgId:%d all checkpoint-trigger recv, quit from monitor checkpoint-trigger, ref:%d", id, vgId, ref); - -// streamMutexUnlock(&pTask->lock); -// streamMetaReleaseTask(pTask->pMeta, pTask); return -1; } @@ -911,9 +908,6 @@ static int32_t doChkptStatusCheck(SStreamTask* pTask) { stWarn("s-task:%s vgId:%d checkpoint-trigger retrieve by previous checkpoint procedure, checkpointId:%" PRId64 ", quit, ref:%d", id, vgId, pTmrInfo->launchChkptId, ref); - -// streamMutexUnlock(&pActiveInfo->lock); -// streamMetaReleaseTask(pTask->pMeta, pTask); return -1; } @@ -922,9 +916,6 @@ static int32_t doChkptStatusCheck(SStreamTask* pTask) { int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask); stWarn("s-task:%s vgId:%d active checkpoint may be cleared, quit from retrieve checkpoint-trigger send tmr, ref:%d", id, vgId, ref); - -// streamMutexUnlock(&pActiveInfo->lock); -// streamMetaReleaseTask(pTask->pMeta, pTask); return -1; } @@ -1020,7 +1011,7 @@ void checkpointTriggerMonitorFn(void* param, void* tmrId) { int32_t code = doChkptStatusCheck(pTask); if (code) { - streamMutexUnlock(&pTask->lock); + streamMutexUnlock(&pActiveInfo->lock); streamMetaReleaseTask(pTask->pMeta, pTask); return; } diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 0f0015c7d9..16bc07c1d1 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -671,7 +671,10 @@ int32_t streamSearchAndAddBlock(SStreamTask* pTask, SStreamDispatchReq* pReqs, S } else { int32_t code = buildCtbNameByGroupIdImpl(pTask->outputInfo.shuffleDispatcher.stbFullName, groupId, pDataBlock->info.parTbName); - stError("s-task:%s failed to build child table name, code:%s", pTask->id.idStr, tstrerror(code)); + if (code) { + stError("s-task:%s failed to build child table name for group:%" PRId64 ", code:%s", pTask->id.idStr, + groupId, tstrerror(code)); + } } snprintf(ctbName, TSDB_TABLE_NAME_LEN, "%s.%s", pTask->outputInfo.shuffleDispatcher.dbInfo.db, diff --git a/source/libs/stream/src/streamExtraInfo.c b/source/libs/stream/src/streamExtraInfo.c new file mode 100644 index 0000000000..168571363f --- /dev/null +++ b/source/libs/stream/src/streamExtraInfo.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "os.h" + +#define UP_TASKS_NOT_SEND_CHKPT_TRIGGER 1 +#define DOWN_TASKS_NOT_READY 2 +#define DOWN_TASKS_BACKPRESSURE 3 +#define DOWN_TASKS_INPUTQ_CLOSED 4 +#define TASK_OUTPUTQ_FULL 5 +#define TASK_SINK_QUOTA_REACHED 6 + +typedef struct SStreamTaskExtraInfo { + int32_t infoId; + char* pMsg; +} SStreamTaskExtraInfo; + +SStreamTaskExtraInfo extraInfoList[8] = { + {0}, + {.infoId = UP_TASKS_NOT_SEND_CHKPT_TRIGGER, .pMsg = "%d(us) not send checkpoint-trigger"}, + {.infoId = DOWN_TASKS_NOT_READY, .pMsg = "%d(ds) tasks not ready"}, + {.infoId = DOWN_TASKS_BACKPRESSURE, .pMsg = "0x%x(ds) backpressure"}, + {.infoId = DOWN_TASKS_INPUTQ_CLOSED, .pMsg = "0x%x(ds) inputQ closed"}, + {.infoId = TASK_OUTPUTQ_FULL, .pMsg = "outputQ is full"}, + {.infoId = TASK_SINK_QUOTA_REACHED, .pMsg = "sink quota reached"}, +}; + diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index a1d2d8e38c..c2757dcabc 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -714,7 +714,6 @@ static bool tQueryAutoQWorkerTryDecActive(void *p, int32_t minActive) { if (atomicCompareExchangeActiveAndRunning(&pPool->activeRunningN, &active, active - 1, &running, running - 1)) return true; } - (void)atomicFetchSubRunning(&pPool->activeRunningN, 1); return false; } @@ -784,6 +783,7 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQ return true; } else { + (void)atomicFetchSubRunning(&pPool->activeRunningN, 1); return true; } } @@ -978,7 +978,6 @@ static int32_t tQueryAutoQWorkerAddWorker(SQueryAutoQWorkerPool *pool) { SListNode *pNode = tdListAdd(pool->workers, &worker); if (!pNode) { (void)taosThreadMutexUnlock(&pool->poolLock); - terrno = TSDB_CODE_OUT_OF_MEMORY; return terrno; } (void)taosThreadMutexUnlock(&pool->poolLock); @@ -1006,6 +1005,7 @@ static int32_t tQueryAutoQWorkerBeforeBlocking(void *p) { if (code != TSDB_CODE_SUCCESS) { return code; } + (void)atomicFetchSubRunning(&pPool->activeRunningN, 1); } return TSDB_CODE_SUCCESS; diff --git a/tests/army/query/subquery/subqueryBugs.py b/tests/army/query/subquery/subqueryBugs.py index 8442474d40..e208c40abc 100644 --- a/tests/army/query/subquery/subqueryBugs.py +++ b/tests/army/query/subquery/subqueryBugs.py @@ -78,6 +78,72 @@ class TDTestCase(TBase): rows = [row1, row2, row3, row4] tdSql.checkDataMem(sql1, rows) + def ts_5443(self): + tdLog.info("create database ts_5443") + tdSql.execute("create database ts_5443") + tdSql.execute("use ts_5443") + sqls = [ + "CREATE STABLE demo (ts TIMESTAMP, site NCHAR(8), expected BIGINT) TAGS (group_id BIGINT UNSIGNED)", + "CREATE TABLE demo_1 USING demo (group_id) TAGS (1)", + "INSERT INTO demo_1 VALUES ('2022-10-25 16:05:00.000', 'MN-01', 1)", + "CREATE TABLE demo_2 USING demo (group_id) TAGS (2)", + "INSERT INTO demo_2 VALUES ('2022-10-25 16:10:00.000', 'MN-02', 2)", + "CREATE TABLE demo_3 USING demo (group_id) TAGS (3)", + "INSERT INTO demo_3 VALUES ('2022-10-25 16:15:00.000', 'MN-03', 3)", + ] + tdSql.executes(sqls) + # test result of order by in plain query + query = ''' + SELECT _wend, site, SUM(expected) AS check + FROM ts_5443.demo + PARTITION BY site INTERVAL(5m) SLIDING (5m) + ORDER BY 1 DESC, 2, 3 + ''' + tdSql.query(query) + tdSql.checkRows(3) + rows = [ + ['2022-10-25 16:20:00.000', 'MN-03', 3], + ['2022-10-25 16:15:00.000', 'MN-02', 2], + ['2022-10-25 16:10:00.000', 'MN-01', 1], + ] + tdSql.checkDataMem(query, rows) + # test order by position alias within subquery + query = ''' + SELECT COUNT(*) FROM ( + SELECT _wend, site, SUM(expected) AS check + FROM ts_5443.demo + PARTITION BY site INTERVAL(5m) SLIDING (5m) + ORDER BY 1 DESC, 2, 3 + ) WHERE check <> 0 + ''' + tdSql.query(query) + tdSql.checkRows(1) + tdSql.checkData(0, 0, 3) + # test order by target name within subquery + query = ''' + SELECT COUNT(*) FROM ( + SELECT _wend, site, SUM(expected) AS check + FROM ts_5443.demo + PARTITION BY site INTERVAL(5m) SLIDING (5m) + ORDER BY _wend DESC, site, check + ) WHERE check <> 0 + ''' + tdSql.query(query) + tdSql.checkRows(1) + tdSql.checkData(0, 0, 3) + # test having clause within subquery + query = ''' + SELECT COUNT(*) FROM ( + SELECT _wend, site, SUM(expected) AS check + FROM ts_5443.demo + PARTITION BY site INTERVAL(5m) SLIDING (5m) + HAVING _wend > '2022-10-25 16:13:00.000' + ) WHERE check <> 0 + ''' + tdSql.query(query) + tdSql.checkRows(1) + tdSql.checkData(0, 0, 2) + # run def run(self): tdLog.debug(f"start to excute {__file__}") @@ -85,6 +151,8 @@ class TDTestCase(TBase): # TS-30189 self.ts_30189() + # TS-5443 + self.ts_5443() tdLog.success(f"{__file__} successfully executed") diff --git a/tests/script/tsim/stream/streamPrimaryKey0.sim b/tests/script/tsim/stream/streamPrimaryKey0.sim index 94f62c4719..e6cfac5906 100644 --- a/tests/script/tsim/stream/streamPrimaryKey0.sim +++ b/tests/script/tsim/stream/streamPrimaryKey0.sim @@ -242,4 +242,75 @@ if $data01 != 2 then goto loop6 endi +print step3============= + +sql create database test3 vgroups 4; +sql use test3; +sql create table st(ts timestamp, a int primary key, b int , c int, d double) tags(ta varchar(100),tb int,tc int); +sql create table t1 using st tags("aa", 1, 2); + +sql create stream streams3_1 trigger at_once ignore expired 0 ignore update 0 into streamt3_1 as select _wstart, a, max(b), count(*), ta from st partition by ta, a interval(10s); +sql create stream streams3_2 trigger at_once ignore expired 0 ignore update 0 into streamt3_2 as select _wstart, a, max(b), count(*), ta from st partition by ta, a session(ts, 10s); + +run tsim/stream/checkTaskStatus.sim + +sql insert into t1 values(1648791210001,1,2,3,4.1); +sql insert into t1 values(1648791210002,2,2,3,1.1); +sql insert into t1 values(1648791220000,3,2,3,2.1); +sql insert into t1 values(1648791220001,4,2,3,3.1); + +$loop_count = 0 + +loop7: + +print 1 select * from streamt3_1; +sql select * from streamt3_1; + +print $data00 $data01 $data02 +print $data10 $data11 $data12 +print $data20 $data21 $data22 +print $data30 $data31 $data32 +print $data40 $data41 $data42 +print $data50 $data51 $data52 +print $data60 $data61 $data62 +print $data70 $data71 $data72 + +sleep 200 + +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + +if $rows != 4 then + print =====rows=$rows + goto loop7 +endi + +loop8: + +print 1 select * from streamt3_2; +sql select * from streamt3_2; + +print $data00 $data01 $data02 +print $data10 $data11 $data12 +print $data20 $data21 $data22 +print $data30 $data31 $data32 +print $data40 $data41 $data42 +print $data50 $data51 $data52 +print $data60 $data61 $data62 +print $data70 $data71 $data72 + +sleep 200 + +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + +if $rows != 4 then + print =====rows=$rows + goto loop8 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file