Merge branch '3.0' of https://github.com/taosdata/TDengine into enh/TD-30987-11

This commit is contained in:
Hongze Cheng 2024-07-27 16:59:13 +08:00
commit a4689e792c
43 changed files with 1997 additions and 1779 deletions

View File

@ -272,11 +272,11 @@ int32_t taosCfgDynamicOptions(SConfig *pCfg, const char *name, bool forServer);
struct SConfig *taosGetCfg();
void taosSetGlobalDebugFlag(int32_t flag);
void taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal);
void taosLocalCfgForbiddenToChange(char *name, bool *forbidden);
int8_t taosGranted(int8_t type);
int32_t taosSetSlowLogScope(char *pScope);
int32_t taosSetGlobalDebugFlag(int32_t flag);
int32_t taosSetDebugFlag(int32_t *pFlagPtr, const char *flagName, int32_t flagVal);
void taosLocalCfgForbiddenToChange(char *name, bool *forbidden);
int8_t taosGranted(int8_t type);
int32_t taosSetSlowLogScope(char *pScopeStr, int32_t *pScope);
#ifdef __cplusplus
}

View File

@ -3636,7 +3636,7 @@ static FORCE_INLINE void tqOffsetResetToLog(STqOffsetVal* pOffsetVal, int64_t ve
int32_t tEncodeSTqOffsetVal(SEncoder* pEncoder, const STqOffsetVal* pOffsetVal);
int32_t tDecodeSTqOffsetVal(SDecoder* pDecoder, STqOffsetVal* pOffsetVal);
int32_t tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
void tFormatOffset(char* buf, int32_t maxLen, const STqOffsetVal* pVal);
bool tOffsetEqual(const STqOffsetVal* pLeft, const STqOffsetVal* pRight);
int32_t tOffsetCopy(STqOffsetVal* pLeft, const STqOffsetVal* pRight);
void tOffsetDestroy(void* pVal);

View File

@ -211,7 +211,7 @@ const char* qExtractTbnameFromTask(qTaskInfo_t tinfo);
void* qExtractReaderFromStreamScanner(void* scanner);
int32_t qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner);
void qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner);
int32_t qSetStreamOperatorOptionForScanHistory(qTaskInfo_t tinfo);
int32_t qStreamSourceScanParamForHistoryScanStep1(qTaskInfo_t tinfo, SVersionRange *pVerRange, STimeWindow* pWindow);

View File

@ -218,10 +218,10 @@ typedef struct SStoreTqReader {
int32_t (*tqGetStreamExecProgress)();
void (*tqReaderSetColIdList)();
int32_t (*tqReaderSetQueryTableList)();
void (*tqReaderSetQueryTableList)();
int32_t (*tqReaderAddTables)();
int32_t (*tqReaderRemoveTables)();
void (*tqReaderAddTables)();
void (*tqReaderRemoveTables)();
void (*tqSetTablePrimaryKey)();
bool (*tqGetTablePrimaryKey)();
@ -239,8 +239,8 @@ typedef struct SStoreSnapshotFn {
bool (*taosXGetTablePrimaryKey)(SSnapContext* ctx);
void (*taosXSetTablePrimaryKey)(SSnapContext* ctx, int64_t uid);
int32_t (*setForSnapShot)(SSnapContext* ctx, int64_t uid);
int32_t (*destroySnapshot)(SSnapContext* ctx);
SMetaTableInfo (*getMetaTableInfoFromSnapshot)(SSnapContext* ctx);
void (*destroySnapshot)(SSnapContext* ctx);
int32_t (*getMetaTableInfoFromSnapshot)(SSnapContext* ctx, SMetaTableInfo* info);
int32_t (*getTableInfoFromSnapshot)(SSnapContext* ctx, void** pBuf, int32_t* contLen, int16_t* type, int64_t* uid);
} SStoreSnapshotFn;

View File

@ -152,6 +152,9 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
#define TCONTAINER_OF(ptr, type, member) ((type *)((char *)(ptr)-offsetof(type, member)))
#define TAOS_GET_TERRNO(code) \
(terrno == 0 ? code : terrno)
#define TAOS_RETURN(CODE) \
do { \
return (terrno = (CODE)); \

View File

@ -484,7 +484,7 @@ static void buildChildElement(cJSON* json, SVCreateTbReq* pCreateReq) {
end:
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tags", tags));
(void)taosArrayDestroy(pTagVals);
taosArrayDestroy(pTagVals);
}
static void buildCreateCTableJson(SVCreateTbReq* pCreateReq, int32_t nReqs, cJSON** pJson) {
@ -588,7 +588,7 @@ end:
tDecoderClear(&decoder[i]);
taosMemoryFreeClear(pCreateReq[i].comment);
if (pCreateReq[i].type == TSDB_CHILD_TABLE) {
(void)taosArrayDestroy(pCreateReq[i].ctb.tagName);
taosArrayDestroy(pCreateReq[i].ctb.tagName);
}
}
taosMemoryFree(decoder);
@ -1097,7 +1097,7 @@ typedef struct SVgroupCreateTableBatch {
static void destroyCreateTbReqBatch(void* data) {
SVgroupCreateTableBatch* pTbBatch = (SVgroupCreateTableBatch*)data;
(void)taosArrayDestroy(pTbBatch->req.pArray);
taosArrayDestroy(pTbBatch->req.pArray);
}
static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) {
@ -1252,7 +1252,7 @@ typedef struct SVgroupDropTableBatch {
static void destroyDropTbReqBatch(void* data) {
SVgroupDropTableBatch* pTbBatch = (SVgroupDropTableBatch*)data;
(void)taosArrayDestroy(pTbBatch->req.pArray);
taosArrayDestroy(pTbBatch->req.pArray);
}
static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) {
@ -1518,7 +1518,7 @@ static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) {
}
end:
uDebug(LOG_ID_TAG " alter table return, meta:%p, len:%d, msg:%s", LOG_ID_VALUE, meta, metaLen, tstrerror(code));
(void)taosArrayDestroy(pArray);
taosArrayDestroy(pArray);
if (pVgData) taosMemoryFreeClear(pVgData->pData);
taosMemoryFreeClear(pVgData);
destroyRequest(pRequest);

View File

@ -197,8 +197,8 @@ static void smlDestroySTableMeta(void *para) {
SSmlSTableMeta *meta = *(SSmlSTableMeta **)para;
taosHashCleanup(meta->tagHash);
taosHashCleanup(meta->colHash);
(void)taosArrayDestroy(meta->tags);
(void)taosArrayDestroy(meta->cols);
taosArrayDestroy(meta->tags);
taosArrayDestroy(meta->cols);
taosMemoryFreeClear(meta->tableMeta);
taosMemoryFree(meta);
}
@ -568,7 +568,7 @@ int32_t smlSetCTableName(SSmlTableInfo *oneTable) {
if (code != TSDB_CODE_SUCCESS){
return code;
}
(void)taosArrayDestroy(dst);
taosArrayDestroy(dst);
}
return TSDB_CODE_SUCCESS;
}
@ -1198,25 +1198,25 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
SArray *pTags = taosArrayInit(taosArrayGetSize(sTableData->tags), sizeof(SField));
if (pTags == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
(void)taosArrayDestroy(pColumns);
taosArrayDestroy(pColumns);
goto end;
}
code = smlBuildFieldsList(info, NULL, NULL, sTableData->tags, pTags, 0, true);
if (code != TSDB_CODE_SUCCESS) {
uError("SML:0x%" PRIx64 " smlBuildFieldsList tag1 failed. %s", info->id, pName.tname);
(void)taosArrayDestroy(pColumns);
(void)taosArrayDestroy(pTags);
taosArrayDestroy(pColumns);
taosArrayDestroy(pTags);
goto end;
}
code = smlBuildFieldsList(info, NULL, NULL, sTableData->cols, pColumns, 0, false);
if (code != TSDB_CODE_SUCCESS) {
uError("SML:0x%" PRIx64 " smlBuildFieldsList col1 failed. %s", info->id, pName.tname);
(void)taosArrayDestroy(pColumns);
(void)taosArrayDestroy(pTags);
taosArrayDestroy(pColumns);
taosArrayDestroy(pTags);
goto end;
}
code = smlSendMetaMsg(info, &pName, pColumns, pTags, NULL, SCHEMA_ACTION_CREATE_STABLE);
(void)taosArrayDestroy(pColumns);
taosArrayDestroy(pColumns);
if (code != TSDB_CODE_SUCCESS) {
uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, pName.tname);
goto end;
@ -1271,7 +1271,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
SArray *pTags =
taosArrayInit(taosArrayGetSize(sTableData->tags) + pTableMeta->tableInfo.numOfTags, sizeof(SField));
if (pTags == NULL){
(void)taosArrayDestroy(pColumns);
taosArrayDestroy(pColumns);
code = TSDB_CODE_OUT_OF_MEMORY;
goto end;
}
@ -1282,15 +1282,15 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
tstrncpy(field.name, pTableMeta->schema[i].name, sizeof(field.name));
if (i < pTableMeta->tableInfo.numOfColumns) {
if (taosArrayPush(pColumns, &field) == NULL){
(void)taosArrayDestroy(pColumns);
(void)taosArrayDestroy(pTags);
taosArrayDestroy(pColumns);
taosArrayDestroy(pTags);
code = TSDB_CODE_OUT_OF_MEMORY;
goto end;
}
} else {
if (taosArrayPush(pTags, &field) == NULL){
(void)taosArrayDestroy(pColumns);
(void)taosArrayDestroy(pTags);
taosArrayDestroy(pColumns);
taosArrayDestroy(pTags);
code = TSDB_CODE_OUT_OF_MEMORY;
goto end;
}
@ -1300,28 +1300,28 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
pTableMeta->tableInfo.numOfColumns, true);
if (code != TSDB_CODE_SUCCESS) {
uError("SML:0x%" PRIx64 " smlBuildFieldsList tag2 failed. %s", info->id, pName.tname);
(void)taosArrayDestroy(pColumns);
(void)taosArrayDestroy(pTags);
taosArrayDestroy(pColumns);
taosArrayDestroy(pTags);
goto end;
}
if (taosArrayGetSize(pTags) + pTableMeta->tableInfo.numOfColumns > TSDB_MAX_COLUMNS) {
uError("SML:0x%" PRIx64 " too many columns than 4096", info->id);
code = TSDB_CODE_PAR_TOO_MANY_COLUMNS;
(void)taosArrayDestroy(pColumns);
(void)taosArrayDestroy(pTags);
taosArrayDestroy(pColumns);
taosArrayDestroy(pTags);
goto end;
}
if (taosArrayGetSize(pTags) > TSDB_MAX_TAGS) {
uError("SML:0x%" PRIx64 " too many tags than 128", info->id);
code = TSDB_CODE_PAR_INVALID_TAGS_NUM;
(void)taosArrayDestroy(pColumns);
(void)taosArrayDestroy(pTags);
taosArrayDestroy(pColumns);
taosArrayDestroy(pTags);
goto end;
}
code = smlSendMetaMsg(info, &pName, pColumns, pTags, pTableMeta, action);
(void)taosArrayDestroy(pColumns);
taosArrayDestroy(pColumns);
if (code != TSDB_CODE_SUCCESS) {
uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, pName.tname);
goto end;
@ -1367,7 +1367,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
SArray *pTags =
taosArrayInit(taosArrayGetSize(sTableData->tags) + pTableMeta->tableInfo.numOfTags, sizeof(SField));
if (pTags == NULL){
(void)taosArrayDestroy(pColumns);
taosArrayDestroy(pColumns);
code = TSDB_CODE_OUT_OF_MEMORY;
goto end;
}
@ -1378,15 +1378,15 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
tstrncpy(field.name, pTableMeta->schema[i].name, sizeof(field.name));
if (i < pTableMeta->tableInfo.numOfColumns) {
if (taosArrayPush(pColumns, &field) == NULL){
(void)taosArrayDestroy(pColumns);
(void)taosArrayDestroy(pTags);
taosArrayDestroy(pColumns);
taosArrayDestroy(pTags);
code = TSDB_CODE_OUT_OF_MEMORY;
goto end;
}
} else {
if (taosArrayPush(pTags, &field) == NULL){
(void)taosArrayDestroy(pColumns);
(void)taosArrayDestroy(pTags);
taosArrayDestroy(pColumns);
taosArrayDestroy(pTags);
code = TSDB_CODE_OUT_OF_MEMORY;
goto end;
}
@ -1397,21 +1397,21 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) {
pTableMeta->tableInfo.numOfColumns, false);
if (code != TSDB_CODE_SUCCESS) {
uError("SML:0x%" PRIx64 " smlBuildFieldsList col2 failed. %s", info->id, pName.tname);
(void)taosArrayDestroy(pColumns);
(void)taosArrayDestroy(pTags);
taosArrayDestroy(pColumns);
taosArrayDestroy(pTags);
goto end;
}
if (taosArrayGetSize(pColumns) + pTableMeta->tableInfo.numOfTags > TSDB_MAX_COLUMNS) {
uError("SML:0x%" PRIx64 " too many columns than 4096", info->id);
code = TSDB_CODE_PAR_TOO_MANY_COLUMNS;
(void)taosArrayDestroy(pColumns);
(void)taosArrayDestroy(pTags);
taosArrayDestroy(pColumns);
taosArrayDestroy(pTags);
goto end;
}
code = smlSendMetaMsg(info, &pName, pColumns, pTags, pTableMeta, action);
(void)taosArrayDestroy(pColumns);
taosArrayDestroy(pColumns);
if (code != TSDB_CODE_SUCCESS) {
uError("SML:0x%" PRIx64 " smlSendMetaMsg failed. can not create %s", info->id, pName.tname);
goto end;
@ -1555,7 +1555,7 @@ void smlDestroyTableInfo(void *para) {
taosHashCleanup(kvHash);
}
(void)taosArrayDestroy(tag->cols);
taosArrayDestroy(tag->cols);
taosArrayDestroyEx(tag->tags, freeSSmlKv);
taosMemoryFree(tag);
}
@ -1581,13 +1581,13 @@ void smlDestroyInfo(SSmlHandle *info) {
cJSON *tags = (cJSON *)taosArrayGetP(info->tagJsonArray, i);
cJSON_Delete(tags);
}
(void)taosArrayDestroy(info->tagJsonArray);
taosArrayDestroy(info->tagJsonArray);
for (int i = 0; i < taosArrayGetSize(info->valueJsonArray); i++) {
cJSON *value = (cJSON *)taosArrayGetP(info->valueJsonArray, i);
cJSON_Delete(value);
}
(void)taosArrayDestroy(info->valueJsonArray);
taosArrayDestroy(info->valueJsonArray);
taosArrayDestroyEx(info->preLineTagKV, freeSSmlKv);

View File

@ -583,16 +583,10 @@ static int32_t asyncCommitOffset(tmq_t* tmq, char* pTopicName, int32_t vgId, STq
goto end;
}
char offsetBuf[TSDB_OFFSET_LEN] = {0};
code = tFormatOffset(offsetBuf, tListLen(offsetBuf), offsetVal);
if (code != 0) {
goto end;
}
tFormatOffset(offsetBuf, tListLen(offsetBuf), offsetVal);
char commitBuf[TSDB_OFFSET_LEN] = {0};
code = tFormatOffset(commitBuf, tListLen(commitBuf), &pVg->offsetInfo.committedOffset);
if (code != 0) {
goto end;
}
tFormatOffset(commitBuf, tListLen(commitBuf), &pVg->offsetInfo.committedOffset);
SMqCommitCbParamSet* pParamSet = NULL;
code = prepareCommitCbParamSet(tmq, pCommitFp, userParam, 0, &pParamSet);
@ -694,10 +688,10 @@ static void asyncCommitAllOffsets(tmq_t* tmq, tmq_commit_cb* pCommitFp, void* us
if (pVg->offsetInfo.endOffset.type > 0 &&
!tOffsetEqual(&pVg->offsetInfo.endOffset, &pVg->offsetInfo.committedOffset)) {
char offsetBuf[TSDB_OFFSET_LEN] = {0};
(void)tFormatOffset(offsetBuf, tListLen(offsetBuf), &pVg->offsetInfo.endOffset);
tFormatOffset(offsetBuf, tListLen(offsetBuf), &pVg->offsetInfo.endOffset);
char commitBuf[TSDB_OFFSET_LEN] = {0};
(void)tFormatOffset(commitBuf, tListLen(commitBuf), &pVg->offsetInfo.committedOffset);
tFormatOffset(commitBuf, tListLen(commitBuf), &pVg->offsetInfo.committedOffset);
code = doSendCommitMsg(tmq, pVg->vgId, &pVg->epSet, &pVg->offsetInfo.endOffset, pTopic->topicName, pParamSet);
if (code != TSDB_CODE_SUCCESS) {
@ -865,7 +859,7 @@ void tmqSendHbReq(void* param, void* tmrId) {
offRows->offset = pVg->offsetInfo.endOffset;
offRows->ever = pVg->offsetInfo.walVerEnd == -1 ? 0 : pVg->offsetInfo.walVerEnd;
char buf[TSDB_OFFSET_LEN] = {0};
(void)tFormatOffset(buf, TSDB_OFFSET_LEN, &offRows->offset);
tFormatOffset(buf, TSDB_OFFSET_LEN, &offRows->offset);
tscDebug("consumer:0x%" PRIx64 ",report offset, group:%s vgId:%d, offset:%s/%" PRId64 ", rows:%" PRId64,
tmq->consumerId, tmq->groupId, offRows->vgId, buf, offRows->ever, offRows->rows);
}
@ -1259,7 +1253,7 @@ tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) {
}
char buf[TSDB_OFFSET_LEN] = {0};
STqOffsetVal offset = {.type = pTmq->resetOffsetCfg};
(void)tFormatOffset(buf, tListLen(buf), &offset);
tFormatOffset(buf, tListLen(buf), &offset);
tscInfo("consumer:0x%" PRIx64 " is setup, refId:%" PRId64
", groupId:%s, snapshot:%d, autoCommit:%d, commitInterval:%dms, offset:%s",
pTmq->consumerId, pTmq->refId, pTmq->groupId, pTmq->useSnapshot, pTmq->autoCommit, pTmq->autoCommitInterval,
@ -1517,7 +1511,7 @@ int32_t tmqPollCb(void* param, SDataBuf* pMsg, int32_t code) {
(void)memcpy(&pRspWrapper->dataRsp, pMsg->pData, sizeof(SMqRspHead));
char buf[TSDB_OFFSET_LEN] = {0};
(void)tFormatOffset(buf, TSDB_OFFSET_LEN, &pRspWrapper->dataRsp.common.rspOffset);
tFormatOffset(buf, TSDB_OFFSET_LEN, &pRspWrapper->dataRsp.common.rspOffset);
tscDebug("consumer:0x%" PRIx64 " recv poll rsp, vgId:%d, req ver:%" PRId64 ", rsp:%s type %d, reqId:0x%" PRIx64,
tmq->consumerId, vgId, pRspWrapper->dataRsp.common.reqOffset.version, buf, rspType, requestId);
} else if (rspType == TMQ_MSG_TYPE__POLL_META_RSP) {
@ -1695,7 +1689,7 @@ static bool doUpdateLocalEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp)
(void)sprintf(vgKey, "%s:%d", pTopicCur->topicName, pVgCur->vgId);
char buf[TSDB_OFFSET_LEN] = {0};
(void)tFormatOffset(buf, TSDB_OFFSET_LEN, &pVgCur->offsetInfo.endOffset);
tFormatOffset(buf, TSDB_OFFSET_LEN, &pVgCur->offsetInfo.endOffset);
tscInfo("consumer:0x%" PRIx64 ", epoch:%d vgId:%d vgKey:%s, offset:%s", tmq->consumerId, epoch, pVgCur->vgId,
vgKey, buf);
@ -1959,7 +1953,7 @@ static int32_t doTmqPollImpl(tmq_t* pTmq, SMqClientTopic* pTopic, SMqClientVg* p
int64_t transporterId = 0;
char offsetFormatBuf[TSDB_OFFSET_LEN] = {0};
(void)tFormatOffset(offsetFormatBuf, tListLen(offsetFormatBuf), &pVg->offsetInfo.endOffset);
tFormatOffset(offsetFormatBuf, tListLen(offsetFormatBuf), &pVg->offsetInfo.endOffset);
code = asyncSendMsgToServer(pTmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, sendInfo);
tscDebug("consumer:0x%" PRIx64 " send poll to %s vgId:%d, code:%d, epoch %d, req:%s, reqId:0x%" PRIx64,
pTmq->consumerId, pTopic->topicName, pVg->vgId, code, pTmq->epoch, offsetFormatBuf, req.reqId);
@ -2130,7 +2124,7 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout) {
tmq->consumerId, pDataRsp->blockNum != 0);
char buf[TSDB_OFFSET_LEN] = {0};
(void)tFormatOffset(buf, TSDB_OFFSET_LEN, &pDataRsp->rspOffset);
tFormatOffset(buf, TSDB_OFFSET_LEN, &pDataRsp->rspOffset);
if (pDataRsp->blockNum == 0) {
tscDebug("consumer:0x%" PRIx64 " empty block received, vgId:%d, offset:%s, vg total:%" PRId64
", total:%" PRId64 ", reqId:0x%" PRIx64,
@ -2287,7 +2281,7 @@ static void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout) {
tmq->totalRows += numOfRows;
char buf[TSDB_OFFSET_LEN] = {0};
(void)tFormatOffset(buf, TSDB_OFFSET_LEN, &pVg->offsetInfo.endOffset);
tFormatOffset(buf, TSDB_OFFSET_LEN, &pVg->offsetInfo.endOffset);
tscDebug("consumer:0x%" PRIx64 " process taosx poll rsp, vgId:%d, offset:%s, blocks:%d, rows:%" PRId64
", vg total:%" PRId64 ", total:%" PRId64 ", reqId:0x%" PRIx64,
tmq->consumerId, pVg->vgId, buf, pDataRsp->blockNum, numOfRows, pVg->numOfRows, tmq->totalRows,
@ -3401,7 +3395,7 @@ int32_t tmq_get_topic_assignment(tmq_t* tmq, const char* pTopicName, tmq_topic_a
int64_t transporterId = 0;
char offsetFormatBuf[TSDB_OFFSET_LEN] = {0};
(void)tFormatOffset(offsetFormatBuf, tListLen(offsetFormatBuf), &pClientVg->offsetInfo.beginOffset);
tFormatOffset(offsetFormatBuf, tListLen(offsetFormatBuf), &pClientVg->offsetInfo.beginOffset);
tscInfo("consumer:0x%" PRIx64 " %s retrieve wal info vgId:%d, epoch %d, req:%s, reqId:0x%" PRIx64,
tmq->consumerId, pTopic->topicName, pClientVg->vgId, tmq->epoch, offsetFormatBuf, req.reqId);

View File

@ -65,7 +65,7 @@ TEST(testCase, smlParseInfluxString_Test) {
ASSERT_EQ(elements.timestamp, sql + elements.measureTagsLen + 1 + elements.colsLen + 1);
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
(void)taosArrayDestroy(elements.colArray);
taosArrayDestroy(elements.colArray);
elements.colArray = nullptr;
// case 2 false
@ -74,7 +74,7 @@ TEST(testCase, smlParseInfluxString_Test) {
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
ASSERT_NE(ret, 0);
(void)taosArrayDestroy(elements.colArray);
taosArrayDestroy(elements.colArray);
elements.colArray = nullptr;
// case 4 tag is null
@ -95,7 +95,7 @@ TEST(testCase, smlParseInfluxString_Test) {
ASSERT_EQ(elements.timestamp, sql + elements.measureTagsLen + 1 + elements.colsLen + 1);
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
(void)taosArrayDestroy(elements.colArray);
taosArrayDestroy(elements.colArray);
elements.colArray = nullptr;
// case 5 tag is null
@ -115,7 +115,7 @@ TEST(testCase, smlParseInfluxString_Test) {
ASSERT_EQ(elements.timestamp, sql + 1 + elements.measureTagsLen + 3 + elements.colsLen + 2);
ASSERT_EQ(elements.timestampLen, strlen("1626006833639000000"));
(void)taosArrayDestroy(elements.colArray);
taosArrayDestroy(elements.colArray);
elements.colArray = nullptr;
// case 6
@ -124,7 +124,7 @@ TEST(testCase, smlParseInfluxString_Test) {
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
ASSERT_EQ(ret, 0);
(void)taosArrayDestroy(elements.colArray);
taosArrayDestroy(elements.colArray);
elements.colArray = nullptr;
ASSERT_EQ(smlClearForRerun(info), 0);
@ -134,7 +134,7 @@ TEST(testCase, smlParseInfluxString_Test) {
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
ASSERT_NE(ret, 0);
(void)taosArrayDestroy(elements.colArray);
taosArrayDestroy(elements.colArray);
elements.colArray = nullptr;
// case 8 false
@ -143,7 +143,7 @@ TEST(testCase, smlParseInfluxString_Test) {
(void)memset(&elements, 0, sizeof(SSmlLineInfo));
ret = smlParseInfluxString(info, sql, sql + strlen(sql), &elements);
ASSERT_NE(ret, 0);
(void)taosArrayDestroy(elements.colArray);
taosArrayDestroy(elements.colArray);
elements.colArray = nullptr;
taosMemoryFree(sql);
@ -250,7 +250,7 @@ TEST(testCase, smlParseCols_Error_Test) {
// printf("i:%d\n", i);
ASSERT_NE(ret, TSDB_CODE_SUCCESS);
taosMemoryFree(sql);
(void)taosArrayDestroy(elements.colArray);
taosArrayDestroy(elements.colArray);
}
smlDestroyInfo(info);
}
@ -458,7 +458,7 @@ TEST(testCase, smlParseCols_Test) {
ASSERT_EQ(kv->length, 4);
ASSERT_EQ(strncasecmp(kv->value, "iuwq", 4), 0);
(void)taosArrayDestroy(elements.colArray);
taosArrayDestroy(elements.colArray);
taosMemoryFree(sql);
smlDestroyInfo(info);
}

View File

@ -1510,6 +1510,9 @@ int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows) {
}
void blockDataFreeRes(SSDataBlock* pBlock) {
if (pBlock == NULL){
return;
}
int32_t numOfOutput = taosArrayGetSize(pBlock->pDataBlock);
for (int32_t i = 0; i < numOfOutput; ++i) {
SColumnInfoData* pColInfoData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i);

File diff suppressed because it is too large Load Diff

View File

@ -9180,7 +9180,7 @@ int32_t tDecodeSTqOffsetVal(SDecoder *pDecoder, STqOffsetVal *pOffsetVal) {
return 0;
}
int32_t tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) {
void tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) {
if (pVal->type == TMQ_OFFSET__RESET_NONE) {
(void)snprintf(buf, maxLen, "none");
} else if (pVal->type == TMQ_OFFSET__RESET_EARLIEST) {
@ -9201,11 +9201,7 @@ int32_t tFormatOffset(char *buf, int32_t maxLen, const STqOffsetVal *pVal) {
(void)snprintf(buf, maxLen, "tsdb:%" PRId64 "|%" PRId64 ",pk type:%d,val:%" PRId64, pVal->uid, pVal->ts,
pVal->primaryKey.type, pVal->primaryKey.val);
}
} else {
return TSDB_CODE_INVALID_PARA;
}
return 0;
}
bool tOffsetEqual(const STqOffsetVal *pLeft, const STqOffsetVal *pRight) {

View File

@ -1252,13 +1252,13 @@ static bool isSeperatorChar(char c) {
return (c > 0x20 && c < 0x7F && !(c >= 'A' && c <= 'Z') && !(c >= 'a' && c <= 'z') && !(c >= '0' && c <= '9'));
}
static void parseTsFormat(const char* formatStr, SArray* formats) {
static int32_t parseTsFormat(const char* formatStr, SArray* formats) {
TSFormatNode* lastOtherFormat = NULL;
while (*formatStr) {
const TSFormatKeyWord* key = keywordSearch(formatStr);
if (key) {
TSFormatNode format = {.key = key, .type = TS_FORMAT_NODE_TYPE_KEYWORD};
taosArrayPush(formats, &format);
if (NULL == taosArrayPush(formats, &format)) TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
formatStr += key->len;
lastOtherFormat = NULL;
} else {
@ -1286,7 +1286,7 @@ static void parseTsFormat(const char* formatStr, SArray* formats) {
TSFormatNode format = {.type = TS_FORMAT_NODE_TYPE_CHAR, .key = NULL};
format.c = formatStr;
format.len = 1;
taosArrayPush(formats, &format);
if (NULL == taosArrayPush(formats, &format)) TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
formatStr++;
last = taosArrayGetLast(formats);
}
@ -1314,13 +1314,14 @@ static void parseTsFormat(const char* formatStr, SArray* formats) {
.key = NULL};
format.c = formatStr;
format.len = 1;
taosArrayPush(formats, &format);
if (NULL == taosArrayPush(formats, &format)) TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
formatStr++;
if (format.type == TS_FORMAT_NODE_TYPE_CHAR) lastOtherFormat = taosArrayGetLast(formats);
}
}
}
}
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int32_t outLen) {
@ -1488,7 +1489,7 @@ static int32_t tm2char(const SArray* formats, const struct STm* tm, char* s, int
s += 6;
break;
case TSFKW_NS:
sprintf(s, "%09" PRId64, tm->fsec);
(void)sprintf(s, "%09" PRId64, tm->fsec);
s += 9;
break;
case TSFKW_TZH:
@ -1925,7 +1926,7 @@ int32_t taosTs2Char(const char* format, SArray** formats, int64_t ts, int32_t pr
if (!*formats){
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
parseTsFormat(format, *formats);
TAOS_CHECK_RETURN(parseTsFormat(format, *formats));
}
struct STm tm;
TAOS_CHECK_RETURN(taosTs2Tm(ts, precision, &tm));
@ -1941,7 +1942,7 @@ int32_t taosChar2Ts(const char* format, SArray** formats, const char* tsStr, int
if (!*formats) {
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
parseTsFormat(format, *formats);
TAOS_CHECK_RETURN(parseTsFormat(format, *formats));
}
int32_t code = char2ts(tsStr, *formats, ts, precision, &sErrPos, &fErrIdx);
if (code == -1) {
@ -1966,7 +1967,7 @@ int32_t TEST_ts2char(const char* format, int64_t ts, int32_t precision, char* ou
if (!formats) {
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
parseTsFormat(format, formats);
TAOS_CHECK_RETURN(parseTsFormat(format, formats));
struct STm tm;
TAOS_CHECK_GOTO(taosTs2Tm(ts, precision, &tm), NULL, _exit);
TAOS_CHECK_GOTO(tm2char(formats, &tm, out, outLen), NULL, _exit);
@ -1980,11 +1981,11 @@ int32_t TEST_char2ts(const char* format, int64_t* ts, int32_t precision, const c
const char* sErrPos;
int32_t fErrIdx;
SArray* formats = taosArrayInit(4, sizeof(TSFormatNode));
parseTsFormat(format, formats);
TAOS_CHECK_RETURN(parseTsFormat(format, formats));
int32_t code = char2ts(tsStr, formats, ts, precision, &sErrPos, &fErrIdx);
if (code == -1) {
printf("failed position: %s\n", sErrPos);
printf("failed format: %s\n", ((TSFormatNode*)taosArrayGet(formats, fErrIdx))->key->name);
(void)printf("failed position: %s\n", sErrPos);
(void)printf("failed format: %s\n", ((TSFormatNode*)taosArrayGet(formats, fErrIdx))->key->name);
}
taosArrayDestroy(formats);
return code;

View File

@ -175,7 +175,7 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) {
break;
default: {
if (len > 0) {
memcpy(val, src, len);
(void)memcpy(val, src, len);
}
break;

View File

@ -426,7 +426,7 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin
size_t lenInwchar = len / TSDB_NCHAR_SIZE;
pVar->ucs4 = taosMemoryCalloc(1, (lenInwchar + 1) * TSDB_NCHAR_SIZE);
memcpy(pVar->ucs4, pz, lenInwchar * TSDB_NCHAR_SIZE);
(void)memcpy(pVar->ucs4, pz, lenInwchar * TSDB_NCHAR_SIZE);
pVar->nLen = (int32_t)len;
break;
@ -435,7 +435,7 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_GEOMETRY: { // todo refactor, extract a method
pVar->pz = taosMemoryCalloc(len + 1, sizeof(char));
memcpy(pVar->pz, pz, len);
(void)memcpy(pVar->pz, pz, len);
pVar->nLen = (int32_t)len;
break;
}
@ -470,10 +470,10 @@ void taosVariantAssign(SVariant *pDst, const SVariant *pSrc) {
char *p = taosMemoryRealloc(pDst->pz, len);
ASSERT(p);
memset(p, 0, len);
(void)memset(p, 0, len);
pDst->pz = p;
memcpy(pDst->pz, pSrc->pz, pSrc->nLen);
(void)memcpy(pDst->pz, pSrc->pz, pSrc->nLen);
pDst->nLen = pSrc->nLen;
return;
}

View File

@ -733,16 +733,17 @@ TEST(AlreadyAddGroupIdTest, GroupIdAddedWithDifferentLength) {
#define SLOW_LOG_TYPE_OTHERS 0x4
#define SLOW_LOG_TYPE_ALL 0x7
static int32_t taosSetSlowLogScope(char *pScope) {
if (NULL == pScope || 0 == strlen(pScope)) {
return SLOW_LOG_TYPE_QUERY;
static int32_t taosSetSlowLogScope(char* pScopeStr, int32_t* pScope) {
if (NULL == pScopeStr || 0 == strlen(pScopeStr)) {
*pScope = SLOW_LOG_TYPE_QUERY;
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
int32_t slowScope = 0;
char* scope = NULL;
char *tmp = NULL;
while((scope = strsep(&pScope, "|")) != NULL){
while((scope = strsep(&pScopeStr, "|")) != NULL){
taosMemoryFreeClear(tmp);
tmp = taosStrdup(scope);
strtrim(tmp);
@ -772,73 +773,94 @@ static int32_t taosSetSlowLogScope(char *pScope) {
}
taosMemoryFreeClear(tmp);
uError("Invalid slowLog scope value:%s", pScope);
terrno = TSDB_CODE_INVALID_CFG_VALUE;
return -1;
uError("Invalid slowLog scope value:%s", pScopeStr);
TAOS_RETURN(TSDB_CODE_INVALID_CFG_VALUE);
}
*pScope = slowScope;
taosMemoryFreeClear(tmp);
return slowScope;
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
TEST(TaosSetSlowLogScopeTest, NullPointerInput) {
char *pScope = NULL;
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY);
char* pScopeStr = NULL;
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
}
TEST(TaosSetSlowLogScopeTest, EmptyStringInput) {
char pScope[1] = "";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY);
char pScopeStr[1] = "";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
}
TEST(TaosSetSlowLogScopeTest, AllScopeInput) {
char pScope[] = "all";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_ALL);
char pScopeStr[] = "all";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_ALL);
}
TEST(TaosSetSlowLogScopeTest, QueryScopeInput) {
char pScope[] = " query";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_QUERY);
char pScopeStr[] = " query";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_QUERY);
}
TEST(TaosSetSlowLogScopeTest, InsertScopeInput) {
char pScope[] = "insert";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_INSERT);
char pScopeStr[] = "insert";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_INSERT);
}
TEST(TaosSetSlowLogScopeTest, OthersScopeInput) {
char pScope[] = "others";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_OTHERS);
char pScopeStr[] = "others";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_OTHERS);
}
TEST(TaosSetSlowLogScopeTest, NoneScopeInput) {
char pScope[] = "none";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, SLOW_LOG_TYPE_NULL);
char pScopeStr[] = "none";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, SLOW_LOG_TYPE_NULL);
}
TEST(TaosSetSlowLogScopeTest, InvalidScopeInput) {
char pScope[] = "invalid";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, -1);
char pScopeStr[] = "invalid";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, -1);
}
TEST(TaosSetSlowLogScopeTest, MixedScopesInput) {
char pScope[] = "query|insert|others|none";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
char pScopeStr[] = "query|insert|others|none";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
}
TEST(TaosSetSlowLogScopeTest, MixedScopesInputWithSpaces) {
char pScope[] = "query | insert | others ";
int32_t result = taosSetSlowLogScope(pScope);
EXPECT_EQ(result, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
char pScopeStr[] = "query | insert | others ";
int32_t scope = 0;
int32_t result = taosSetSlowLogScope(pScopeStr, &scope);
EXPECT_EQ(result, TSDB_CODE_SUCCESS);
EXPECT_EQ(scope, (SLOW_LOG_TYPE_QUERY | SLOW_LOG_TYPE_INSERT | SLOW_LOG_TYPE_OTHERS));
}
#pragma GCC diagnostic pop

View File

@ -74,7 +74,7 @@ static struct {
char encryptKey[ENCRYPT_KEY_LEN + 1];
} global = {0};
static void dmSetDebugFlag(int32_t signum, void *sigInfo, void *context) { taosSetGlobalDebugFlag(143); }
static void dmSetDebugFlag(int32_t signum, void *sigInfo, void *context) { (void)taosSetGlobalDebugFlag(143); }
static void dmSetAssert(int32_t signum, void *sigInfo, void *context) { tsAssert = 1; }
static void dmStopDnode(int signum, void *sigInfo, void *context) {

View File

@ -104,7 +104,7 @@ void mndReleaseArbGroup(SMnode *pMnode, SArbGroup *pGroup) {
void mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup) {
ASSERT(pVgObj->replica == 2);
memset(outGroup, 0, sizeof(SArbGroup));
(void)memset(outGroup, 0, sizeof(SArbGroup));
outGroup->dbUid = pVgObj->dbUid;
outGroup->vgId = pVgObj->vgId;
for (int i = 0; i < TSDB_ARB_GROUP_MEMBER_NUM; i++) {
@ -223,7 +223,7 @@ static int32_t mndArbGroupActionInsert(SSdb *pSdb, SArbGroup *pGroup) {
static int32_t mndArbGroupActionDelete(SSdb *pSdb, SArbGroup *pGroup) {
mTrace("arbgroup:%d, perform delete action, row:%p", pGroup->vgId, pGroup);
if (pGroup->mutexInited) {
taosThreadMutexDestroy(&pGroup->mutex);
(void)taosThreadMutexDestroy(&pGroup->mutex);
pGroup->mutexInited = false;
}
return 0;
@ -231,7 +231,7 @@ static int32_t mndArbGroupActionDelete(SSdb *pSdb, SArbGroup *pGroup) {
static int32_t mndArbGroupActionUpdate(SSdb *pSdb, SArbGroup *pOld, SArbGroup *pNew) {
mTrace("arbgroup:%d, perform update action, old row:%p new row:%p", pOld->vgId, pOld, pNew);
taosThreadMutexLock(&pOld->mutex);
(void)taosThreadMutexLock(&pOld->mutex);
if (pOld->version != pNew->version) {
mInfo("arbgroup:%d, skip to perform update action, old row:%p new row:%p, old version:%" PRId64
@ -241,18 +241,18 @@ static int32_t mndArbGroupActionUpdate(SSdb *pSdb, SArbGroup *pOld, SArbGroup *p
}
for (int i = 0; i < TSDB_ARB_GROUP_MEMBER_NUM; i++) {
memcpy(pOld->members[i].state.token, pNew->members[i].state.token, TSDB_ARB_TOKEN_SIZE);
(void)memcpy(pOld->members[i].state.token, pNew->members[i].state.token, TSDB_ARB_TOKEN_SIZE);
}
pOld->isSync = pNew->isSync;
pOld->assignedLeader.dnodeId = pNew->assignedLeader.dnodeId;
memcpy(pOld->assignedLeader.token, pNew->assignedLeader.token, TSDB_ARB_TOKEN_SIZE);
(void)memcpy(pOld->assignedLeader.token, pNew->assignedLeader.token, TSDB_ARB_TOKEN_SIZE);
pOld->assignedLeader.acked = pNew->assignedLeader.acked;
pOld->version++;
_OVER:
taosThreadMutexUnlock(&pOld->mutex);
(void)taosThreadMutexUnlock(&pOld->mutex);
taosHashRemove(arbUpdateHash, &pOld->vgId, sizeof(int32_t));
(void)taosHashRemove(arbUpdateHash, &pOld->vgId, sizeof(int32_t));
return 0;
}
@ -389,7 +389,7 @@ static int32_t mndProcessArbHbTimer(SRpcMsg *pReq) {
pIter = sdbFetch(pSdb, SDB_ARBGROUP, pIter, (void **)&pArbGroup);
if (pIter == NULL) break;
taosThreadMutexLock(&pArbGroup->mutex);
(void)taosThreadMutexLock(&pArbGroup->mutex);
for (int i = 0; i < TSDB_ARB_GROUP_MEMBER_NUM; i++) {
SArbGroupMember *pMember = &pArbGroup->members[i];
@ -400,13 +400,13 @@ static int32_t mndProcessArbHbTimer(SRpcMsg *pReq) {
hbMembers = *(SArray **)pObj;
} else {
hbMembers = taosArrayInit(16, sizeof(SVArbHbReqMember));
taosHashPut(pDnodeHash, &dnodeId, sizeof(int32_t), &hbMembers, POINTER_BYTES);
(void)taosHashPut(pDnodeHash, &dnodeId, sizeof(int32_t), &hbMembers, POINTER_BYTES);
}
SVArbHbReqMember reqMember = {.vgId = pArbGroup->vgId, .hbSeq = pMember->state.nextHbSeq++};
taosArrayPush(hbMembers, &reqMember);
(void)taosArrayPush(hbMembers, &reqMember);
}
taosThreadMutexUnlock(&pArbGroup->mutex);
(void)taosThreadMutexUnlock(&pArbGroup->mutex);
sdbRelease(pSdb, pArbGroup);
}
@ -602,9 +602,9 @@ static int32_t mndProcessArbCheckSyncTimer(SRpcMsg *pReq) {
pIter = sdbFetch(pSdb, SDB_ARBGROUP, pIter, (void **)&pArbGroup);
if (pIter == NULL) break;
taosThreadMutexLock(&pArbGroup->mutex);
(void)taosThreadMutexLock(&pArbGroup->mutex);
mndArbGroupDupObj(pArbGroup, &arbGroupDup);
taosThreadMutexUnlock(&pArbGroup->mutex);
(void)taosThreadMutexUnlock(&pArbGroup->mutex);
int32_t vgId = arbGroupDup.vgId;
@ -668,7 +668,10 @@ static int32_t mndProcessArbCheckSyncTimer(SRpcMsg *pReq) {
SArbGroup newGroup = {0};
mndArbGroupDupObj(&arbGroupDup, &newGroup);
mndArbGroupSetAssignedLeader(&newGroup, candidateIndex);
taosArrayPush(pUpdateArray, &newGroup);
if (taosArrayPush(pUpdateArray, &newGroup) == NULL) {
taosArrayDestroy(pUpdateArray);
return TSDB_CODE_OUT_OF_MEMORY;
}
sdbRelease(pSdb, pArbGroup);
}
@ -722,7 +725,7 @@ static int32_t mndPullupArbUpdateGroup(SMnode *pMnode, SArbGroup *pNewGroup) {
mndInitArbUpdateGroup(pNewGroup, &newGroup);
SArray *pArray = taosArrayInit(1, sizeof(SMArbUpdateGroup));
taosArrayPush(pArray, &newGroup);
if (taosArrayPush(pArray, &newGroup) == NULL) goto _OVER;
int32_t contLen = 0;
void *pHead = mndBuildArbUpdateGroupBatchReq(&contLen, pArray);
@ -736,7 +739,7 @@ static int32_t mndPullupArbUpdateGroup(SMnode *pMnode, SArbGroup *pNewGroup) {
ret = tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
if (ret != 0) goto _OVER;
taosHashPut(arbUpdateHash, &pNewGroup->vgId, sizeof(pNewGroup->vgId), NULL, 0);
if ((ret = taosHashPut(arbUpdateHash, &pNewGroup->vgId, sizeof(pNewGroup->vgId), NULL, 0)) != 0) goto _OVER;
_OVER:
taosArrayDestroy(pArray);
@ -758,8 +761,8 @@ static int32_t mndPullupArbUpdateGroupBatch(SMnode *pMnode, SArray *newGroupArra
SMArbUpdateGroup newGroup = {0};
mndInitArbUpdateGroup(pNewGroup, &newGroup);
taosArrayPush(pArray, &newGroup);
taosHashPut(arbUpdateHash, &pNewGroup->vgId, sizeof(pNewGroup->vgId), NULL, 0);
if (taosArrayPush(pArray, &newGroup) == NULL) goto _OVER;
if (taosHashPut(arbUpdateHash, &pNewGroup->vgId, sizeof(pNewGroup->vgId), NULL, 0) != 0) goto _OVER;
}
if (taosArrayGetSize(pArray) == 0) {
@ -784,7 +787,7 @@ _OVER:
if (ret != 0) {
for (size_t i = 0; i < sz; i++) {
SArbGroup *pNewGroup = taosArrayGet(newGroupArray, i);
taosHashRemove(arbUpdateHash, &pNewGroup->vgId, sizeof(pNewGroup->vgId));
(void)taosHashRemove(arbUpdateHash, &pNewGroup->vgId, sizeof(pNewGroup->vgId));
}
}
@ -816,19 +819,19 @@ static int32_t mndProcessArbUpdateGroupBatchReq(SRpcMsg *pReq) {
newGroup.dbUid = pUpdateGroup->dbUid;
for (int i = 0; i < TSDB_ARB_GROUP_MEMBER_NUM; i++) {
newGroup.members[i].info.dnodeId = pUpdateGroup->members[i].dnodeId;
memcpy(newGroup.members[i].state.token, pUpdateGroup->members[i].token, TSDB_ARB_TOKEN_SIZE);
(void)memcpy(newGroup.members[i].state.token, pUpdateGroup->members[i].token, TSDB_ARB_TOKEN_SIZE);
}
newGroup.isSync = pUpdateGroup->isSync;
newGroup.assignedLeader.dnodeId = pUpdateGroup->assignedLeader.dnodeId;
memcpy(newGroup.assignedLeader.token, pUpdateGroup->assignedLeader.token, TSDB_ARB_TOKEN_SIZE);
(void)memcpy(newGroup.assignedLeader.token, pUpdateGroup->assignedLeader.token, TSDB_ARB_TOKEN_SIZE);
newGroup.assignedLeader.acked = pUpdateGroup->assignedLeader.acked;
newGroup.version = pUpdateGroup->version;
SArbGroup *pOldGroup = sdbAcquire(pMnode->pSdb, SDB_ARBGROUP, &newGroup.vgId);
if (!pOldGroup) {
mInfo("vgId:%d, arb skip to update arbgroup, since no obj found", newGroup.vgId);
taosHashRemove(arbUpdateHash, &newGroup.vgId, sizeof(int32_t));
(void)taosHashRemove(arbUpdateHash, &newGroup.vgId, sizeof(int32_t));
continue;
}
@ -858,7 +861,7 @@ _OVER:
// failed to update arbgroup
for (size_t i = 0; i < sz; i++) {
SMArbUpdateGroup *pUpdateGroup = taosArrayGet(req.updateArray, i);
taosHashRemove(arbUpdateHash, &pUpdateGroup->vgId, sizeof(int32_t));
(void)taosHashRemove(arbUpdateHash, &pUpdateGroup->vgId, sizeof(int32_t));
}
}
@ -868,20 +871,20 @@ _OVER:
}
static void mndArbGroupDupObj(SArbGroup *pGroup, SArbGroup *pNew) {
memcpy(pNew, pGroup, offsetof(SArbGroup, mutexInited));
(void)memcpy(pNew, pGroup, offsetof(SArbGroup, mutexInited));
}
static void mndArbGroupSetAssignedLeader(SArbGroup *pGroup, int32_t index) {
SArbGroupMember *pMember = &pGroup->members[index];
pGroup->assignedLeader.dnodeId = pMember->info.dnodeId;
strncpy(pGroup->assignedLeader.token, pMember->state.token, TSDB_ARB_TOKEN_SIZE);
(void)strncpy(pGroup->assignedLeader.token, pMember->state.token, TSDB_ARB_TOKEN_SIZE);
pGroup->assignedLeader.acked = false;
}
static void mndArbGroupResetAssignedLeader(SArbGroup *pGroup) {
pGroup->assignedLeader.dnodeId = 0;
memset(pGroup->assignedLeader.token, 0, TSDB_ARB_TOKEN_SIZE);
(void)memset(pGroup->assignedLeader.token, 0, TSDB_ARB_TOKEN_SIZE);
pGroup->assignedLeader.acked = false;
}
@ -923,7 +926,7 @@ bool mndUpdateArbGroupByHeartBeat(SArbGroup *pGroup, SVArbHbRspMember *pRspMembe
bool updateToken = false;
SArbGroupMember *pMember = NULL;
taosThreadMutexLock(&pGroup->mutex);
(void)taosThreadMutexLock(&pGroup->mutex);
int index = 0;
for (; index < TSDB_ARB_GROUP_MEMBER_NUM; index++) {
@ -957,7 +960,7 @@ bool mndUpdateArbGroupByHeartBeat(SArbGroup *pGroup, SVArbHbRspMember *pRspMembe
// update token
mndArbGroupDupObj(pGroup, pNewGroup);
memcpy(pNewGroup->members[index].state.token, pRspMember->memberToken, TSDB_ARB_TOKEN_SIZE);
(void)memcpy(pNewGroup->members[index].state.token, pRspMember->memberToken, TSDB_ARB_TOKEN_SIZE);
pNewGroup->isSync = false;
bool resetAssigned = false;
@ -970,7 +973,7 @@ bool mndUpdateArbGroupByHeartBeat(SArbGroup *pGroup, SVArbHbRspMember *pRspMembe
mInfo("dnodeId:%d vgId:%d, arb token updating, resetAssigned:%d", dnodeId, pRspMember->vgId, resetAssigned);
_OVER:
taosThreadMutexUnlock(&pGroup->mutex);
(void)taosThreadMutexUnlock(&pGroup->mutex);
return updateToken;
}
@ -991,7 +994,7 @@ static int32_t mndUpdateArbHeartBeat(SMnode *pMnode, int32_t dnodeId, SArray *me
bool updateToken = mndUpdateArbGroupByHeartBeat(pGroup, pRspMember, nowMs, dnodeId, &newGroup);
if (updateToken) {
taosArrayPush(pUpdateArray, &newGroup);
(void)taosArrayPush(pUpdateArray, &newGroup);
}
sdbRelease(pMnode->pSdb, pGroup);
@ -1007,7 +1010,7 @@ bool mndUpdateArbGroupByCheckSync(SArbGroup *pGroup, int32_t vgId, char *member0
bool newIsSync, SArbGroup *pNewGroup) {
bool updateIsSync = false;
taosThreadMutexLock(&pGroup->mutex);
(void)taosThreadMutexLock(&pGroup->mutex);
if (pGroup->assignedLeader.dnodeId != 0) {
terrno = TSDB_CODE_SUCCESS;
@ -1033,7 +1036,7 @@ bool mndUpdateArbGroupByCheckSync(SArbGroup *pGroup, int32_t vgId, char *member0
}
_OVER:
taosThreadMutexUnlock(&pGroup->mutex);
(void)taosThreadMutexUnlock(&pGroup->mutex);
return updateIsSync;
}
@ -1148,7 +1151,7 @@ bool mndUpdateArbGroupBySetAssignedLeader(SArbGroup *pGroup, int32_t vgId, char
SArbGroup *pNewGroup) {
bool updateAssigned = false;
taosThreadMutexLock(&pGroup->mutex);
(void)taosThreadMutexLock(&pGroup->mutex);
if (mndArbCheckToken(pGroup->assignedLeader.token, memberToken) != 0) {
mInfo("skip update arb assigned for vgId:%d, member token mismatch, local:[%s] msg:[%s]", vgId,
pGroup->assignedLeader.token, memberToken);
@ -1171,7 +1174,7 @@ bool mndUpdateArbGroupBySetAssignedLeader(SArbGroup *pGroup, int32_t vgId, char
}
_OVER:
taosThreadMutexUnlock(&pGroup->mutex);
(void)taosThreadMutexUnlock(&pGroup->mutex);
return updateAssigned;
}
@ -1241,43 +1244,43 @@ static int32_t mndRetrieveArbGroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
pShow->pIter = sdbFetch(pSdb, SDB_ARBGROUP, pShow->pIter, (void **)&pGroup);
if (pShow->pIter == NULL) break;
taosThreadMutexLock(&pGroup->mutex);
(void)taosThreadMutexLock(&pGroup->mutex);
cols = 0;
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
SVgObj *pVgObj = sdbAcquire(pSdb, SDB_VGROUP, &pGroup->vgId);
if (!pVgObj) {
taosThreadMutexUnlock(&pGroup->mutex);
(void)taosThreadMutexUnlock(&pGroup->mutex);
sdbRelease(pSdb, pGroup);
continue;
}
char dbname[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(dbname, mndGetDbStr(pVgObj->dbName), TSDB_ARB_TOKEN_SIZE + VARSTR_HEADER_SIZE);
colDataSetVal(pColInfo, numOfRows, (const char *)dbname, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)dbname, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pGroup->vgId, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pGroup->vgId, false);
for (int i = 0; i < TSDB_ARB_GROUP_MEMBER_NUM; i++) {
SArbGroupMember *pMember = &pGroup->members[i];
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pMember->info.dnodeId, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pMember->info.dnodeId, false);
}
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pGroup->isSync, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pGroup->isSync, false);
if (pGroup->assignedLeader.dnodeId != 0) {
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pGroup->assignedLeader.dnodeId, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pGroup->assignedLeader.dnodeId, false);
char token[TSDB_ARB_TOKEN_SIZE + VARSTR_HEADER_SIZE] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(token, pGroup->assignedLeader.token, TSDB_ARB_TOKEN_SIZE + VARSTR_HEADER_SIZE);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)token, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)token, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pGroup->assignedLeader.acked, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pGroup->assignedLeader.acked, false);
} else {
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetNULL(pColInfo, numOfRows);
@ -1289,7 +1292,7 @@ static int32_t mndRetrieveArbGroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
colDataSetNULL(pColInfo, numOfRows);
}
taosThreadMutexUnlock(&pGroup->mutex);
(void)taosThreadMutexUnlock(&pGroup->mutex);
numOfRows++;
sdbRelease(pSdb, pVgObj);

View File

@ -243,7 +243,7 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
int32_t code = taosGetSystemUUID(clusterObj.name, TSDB_CLUSTER_ID_LEN);
if (code != 0) {
strcpy(clusterObj.name, "tdengine3.0");
(void)strcpy(clusterObj.name, "tdengine3.0");
mError("failed to get name from system, set to default val %s", clusterObj.name);
}
@ -355,7 +355,7 @@ static int32_t mndProcessUptimeTimer(SRpcMsg *pReq) {
void *pIter = NULL;
SClusterObj *pCluster = mndAcquireCluster(pMnode, &pIter);
if (pCluster != NULL) {
memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
(void)memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
clusterObj.upTime += tsUptimeInterval;
mndReleaseCluster(pMnode, pCluster, pIter);
}
@ -420,7 +420,7 @@ int32_t mndProcessConfigClusterReq(SRpcMsg *pReq) {
if (pCluster) mndReleaseCluster(pMnode, pCluster, pIter);
goto _exit;
}
memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
(void)memcpy(&clusterObj, pCluster, sizeof(SClusterObj));
mndReleaseCluster(pMnode, pCluster, pIter);
if (strncmp(cfgReq.config, GRANT_ACTIVE_CODE, TSDB_DNODE_CONFIG_LEN) == 0) {

View File

@ -231,7 +231,7 @@ int32_t mndAddCompactToTran(SMnode *pMnode, STrans *pTrans, SCompactObj *pCompac
int32_t code = 0;
pCompact->compactId = tGenIdPI32();
strcpy(pCompact->dbname, pDb->name);
(void)strcpy(pCompact->dbname, pDb->name);
pCompact->startTime = taosGetTimestampMs();
@ -283,21 +283,21 @@ int32_t mndRetrieveCompact(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock,
char tmpBuf[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0};
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pCompact->compactId, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompact->compactId, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
if (pDb != NULL || !IS_SYS_DBNAME(pCompact->dbname)) {
SName name = {0};
tNameFromString(&name, pCompact->dbname, T_NAME_ACCT | T_NAME_DB);
tNameGetDbName(&name, varDataVal(tmpBuf));
(void)tNameFromString(&name, pCompact->dbname, T_NAME_ACCT | T_NAME_DB);
(void)tNameGetDbName(&name, varDataVal(tmpBuf));
} else {
strncpy(varDataVal(tmpBuf), pCompact->dbname, TSDB_SHOW_SQL_LEN);
(void)strncpy(varDataVal(tmpBuf), pCompact->dbname, TSDB_SHOW_SQL_LEN);
}
varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pCompact->startTime, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompact->startTime, false);
numOfRows++;
sdbRelease(pSdb, pCompact);
@ -334,7 +334,7 @@ static void *mndBuildKillCompactReq(SMnode *pMnode, SVgObj *pVgroup, int32_t *pC
pHead->contLen = htonl(contLen);
pHead->vgId = htonl(pVgroup->vgId);
tSerializeSVKillCompactReq((char *)pReq + sizeof(SMsgHead), contLen, &req);
(void)tSerializeSVKillCompactReq((char *)pReq + sizeof(SMsgHead), contLen, &req);
*pContLen = contLen;
return pReq;
}
@ -478,7 +478,7 @@ int32_t mndProcessKillCompactReq(SRpcMsg *pReq) {
code = TSDB_CODE_ACTION_IN_PROGRESS;
char obj[TSDB_INT32_ID_LEN] = {0};
sprintf(obj, "%d", pCompact->compactId);
(void)sprintf(obj, "%d", pCompact->compactId);
auditRecord(pReq, pMnode->clusterId, "killCompact", pCompact->dbname, obj, killCompactReq.sql, killCompactReq.sqlLen);
@ -587,7 +587,7 @@ void mndCompactSendProgressReq(SMnode *pMnode, SCompactObj *pCompact) {
pHead->contLen = htonl(contLen);
pHead->vgId = htonl(pDetail->vgId);
tSerializeSQueryCompactProgressReq((char *)pHead + sizeof(SMsgHead), contLen - sizeof(SMsgHead), &req);
(void)tSerializeSQueryCompactProgressReq((char *)pHead + sizeof(SMsgHead), contLen - sizeof(SMsgHead), &req);
SRpcMsg rpcMsg = {.msgType = TDMT_VND_QUERY_COMPACT_PROGRESS, .contLen = contLen};
@ -602,7 +602,10 @@ void mndCompactSendProgressReq(SMnode *pMnode, SCompactObj *pCompact) {
mDebug("compact:%d, send update progress msg to %s", pDetail->compactId, detail);
tmsgSendReq(&epSet, &rpcMsg);
if (tmsgSendReq(&epSet, &rpcMsg) < 0) {
sdbRelease(pMnode->pSdb, pDetail);
continue;
}
}
sdbRelease(pMnode->pSdb, pDetail);
@ -806,7 +809,7 @@ void mndCompactPullup(SMnode *pMnode) {
SCompactObj *pCompact = NULL;
pIter = sdbFetch(pMnode->pSdb, SDB_COMPACT, pIter, (void **)&pCompact);
if (pIter == NULL) break;
taosArrayPush(pArray, &pCompact->compactId);
(void)taosArrayPush(pArray, &pCompact->compactId);
sdbRelease(pSdb, pCompact);
}

View File

@ -68,22 +68,22 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
char tmpBuf[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0};
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->compactId, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->compactId, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->vgId, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->vgId, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->dnodeId, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->dnodeId, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->numberFileset, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->numberFileset, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->finished, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->finished, false);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->startTime, false);
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->startTime, false);
numOfRows++;
sdbRelease(pSdb, pCompactDetail);

View File

@ -946,7 +946,7 @@ static int32_t mndRetrieveConsumer(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *
char buf[TSDB_OFFSET_LEN] = {0};
STqOffsetVal pVal = {.type = pConsumer->resetOffsetCfg};
MND_TMQ_RETURN_CHECK(tFormatOffset(buf, TSDB_OFFSET_LEN, &pVal));
tFormatOffset(buf, TSDB_OFFSET_LEN, &pVal);
char parasStr[64 + TSDB_OFFSET_LEN + VARSTR_HEADER_SIZE] = {0};
(void)sprintf(varDataVal(parasStr), "tbname:%d,commit:%d,interval:%dms,reset:%s", pConsumer->withTbName,

View File

@ -1375,7 +1375,7 @@ static int32_t buildResult(SSDataBlock *pBlock, int32_t *numOfRows, int64_t cons
if (data) {
// vg id
char buf[TSDB_OFFSET_LEN * 2 + VARSTR_HEADER_SIZE] = {0};
MND_TMQ_RETURN_CHECK(tFormatOffset(varDataVal(buf), TSDB_OFFSET_LEN, &data->offset));
tFormatOffset(varDataVal(buf), TSDB_OFFSET_LEN, &data->offset);
(void)sprintf(varDataVal(buf) + strlen(varDataVal(buf)), "/%" PRId64, data->ever);
varDataSetLen(buf, strlen(varDataVal(buf)));
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);

View File

@ -223,9 +223,9 @@ bool tqGetTablePrimaryKey(STqReader *pReader);
void tqSetTablePrimaryKey(STqReader *pReader, int64_t uid);
void tqReaderSetColIdList(STqReader *pReader, SArray *pColIdList);
int32_t tqReaderSetTbUidList(STqReader *pReader, const SArray *tbUidList, const char *id);
int32_t tqReaderAddTbUidList(STqReader *pReader, const SArray *pTableUidList);
int32_t tqReaderRemoveTbUidList(STqReader *pReader, const SArray *tbUidList);
void tqReaderSetTbUidList(STqReader *pReader, const SArray *tbUidList, const char *id);
void tqReaderAddTbUidList(STqReader *pReader, const SArray *pTableUidList);
void tqReaderRemoveTbUidList(STqReader *pReader, const SArray *tbUidList);
bool tqReaderIsQueriedTable(STqReader *pReader, uint64_t uid);
bool tqCurrentBlockConsumed(const STqReader *pReader);
@ -261,9 +261,9 @@ void taosXSetTablePrimaryKey(SSnapContext *ctx, int64_t uid);
int32_t buildSnapContext(SVnode *pVnode, int64_t snapVersion, int64_t suid, int8_t subType, int8_t withMeta,
SSnapContext **ctxRet);
int32_t getTableInfoFromSnapshot(SSnapContext *ctx, void **pBuf, int32_t *contLen, int16_t *type, int64_t *uid);
SMetaTableInfo getMetaTableInfoFromSnapshot(SSnapContext *ctx);
int32_t getMetaTableInfoFromSnapshot(SSnapContext *ctx, SMetaTableInfo* info);
int32_t setForSnapShot(SSnapContext *ctx, int64_t uid);
int32_t destroySnapContext(SSnapContext *ctx);
void destroySnapContext(SSnapContext *ctx);
// structs
struct STsdbCfg {

View File

@ -85,18 +85,18 @@ typedef struct {
TXN* pTxn;
} STtlDelTtlCtx;
int ttlMgrOpen(STtlManger** ppTtlMgr, TDB* pEnv, int8_t rollback, const char* logPrefix, int32_t flushThreshold);
void ttlMgrClose(STtlManger* pTtlMgr);
int32_t ttlMgrOpen(STtlManger** ppTtlMgr, TDB* pEnv, int8_t rollback, const char* logPrefix, int32_t flushThreshold);
void ttlMgrClose(STtlManger* pTtlMgr);
bool ttlMgrNeedUpgrade(TDB* pEnv);
int ttlMgrUpgrade(STtlManger* pTtlMgr, void* pMeta);
bool ttlMgrNeedUpgrade(TDB* pEnv);
int32_t ttlMgrUpgrade(STtlManger* pTtlMgr, void* pMeta);
int ttlMgrInsertTtl(STtlManger* pTtlMgr, const STtlUpdTtlCtx* pUpdCtx);
int ttlMgrDeleteTtl(STtlManger* pTtlMgr, const STtlDelTtlCtx* pDelCtx);
int ttlMgrUpdateChangeTime(STtlManger* pTtlMgr, const STtlUpdCtimeCtx* pUpdCtimeCtx);
int32_t ttlMgrInsertTtl(STtlManger* pTtlMgr, const STtlUpdTtlCtx* pUpdCtx);
int32_t ttlMgrDeleteTtl(STtlManger* pTtlMgr, const STtlDelTtlCtx* pDelCtx);
int32_t ttlMgrUpdateChangeTime(STtlManger* pTtlMgr, const STtlUpdCtimeCtx* pUpdCtimeCtx);
int ttlMgrFlush(STtlManger* pTtlMgr, TXN* pTxn);
int ttlMgrFindExpired(STtlManger* pTtlMgr, int64_t timePointMs, SArray* pTbUids, int32_t ttlDropMaxCount);
int32_t ttlMgrFlush(STtlManger* pTtlMgr, TXN* pTxn);
int32_t ttlMgrFindExpired(STtlManger* pTtlMgr, int64_t timePointMs, SArray* pTbUids, int32_t ttlDropMaxCount);
#ifdef __cplusplus
}

View File

@ -121,11 +121,11 @@ int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxR
int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, void* pRsp, int32_t numOfCols, int8_t precision);
int32_t tqSendDataRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq, const void* pRsp,
int32_t type, int32_t vgId);
int32_t tqPushEmptyDataRsp(STqHandle* pHandle, int32_t vgId);
void tqPushEmptyDataRsp(STqHandle* pHandle, int32_t vgId);
// tqMeta
int32_t tqMetaOpen(STQ* pTq);
int32_t tqMetaClose(STQ* pTq);
void tqMetaClose(STQ* pTq);
int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle);
int32_t tqMetaSaveInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen, const void* value, int32_t vLen);
int32_t tqMetaDeleteInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen);
@ -133,7 +133,7 @@ int32_t tqMetaCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle);
int32_t tqMetaDecodeCheckInfo(STqCheckInfo *info, void *pVal, int32_t vLen);
int32_t tqMetaDecodeOffsetInfo(STqOffset *info, void *pVal, int32_t vLen);
int32_t tqMetaGetHandle(STQ* pTq, const char* key, STqHandle** pHandle);
void* tqMetaGetOffset(STQ* pTq, const char* subkey);
int32_t tqMetaGetOffset(STQ* pTq, const char* subkey, STqOffset** pOffset);
int32_t tqMetaTransform(STQ* pTq);
// tqSink
int32_t tqBuildDeleteReq(STQ* pTq, const char* stbFullName, const SSDataBlock* pDataBlock, SBatchDeleteReq* deleteReq,
@ -166,12 +166,12 @@ int32_t buildAutoCreateTableReq(const char* stbFullName, int64_t suid, int32_t n
} \
} while (0)
#define TQ_ERR_RETURN(c) \
do { \
code = c; \
if (code != TSDB_CODE_SUCCESS) { \
return code; \
} \
#define TQ_NULL_GO_TO_END(c) \
do { \
if (c == NULL) { \
code = (terrno == 0 ? TSDB_CODE_OUT_OF_MEMORY : terrno); \
goto END; \
} \
} while (0)
#define TQ_SUBSCRIBE_NAME "subscribe"

View File

@ -239,12 +239,12 @@ int32_t tsdbSetKeepCfg(STsdb* pTsdb, STsdbCfg* pCfg);
int64_t tsdbGetEarliestTs(STsdb* pTsdb);
// tq
STQ* tqOpen(const char* path, SVnode* pVnode);
int32_t tqOpen(const char* path, SVnode* pVnode);
void tqNotifyClose(STQ*);
void tqClose(STQ*);
int tqPushMsg(STQ*, tmsg_t msgType);
int tqRegisterPushHandle(STQ* pTq, void* handle, SRpcMsg* pMsg);
int tqUnregisterPushHandle(STQ* pTq, void* pHandle);
void tqUnregisterPushHandle(STQ* pTq, void* pHandle);
int tqScanWalAsync(STQ* pTq, bool ckPause);
int32_t tqStopStreamTasksAsync(STQ* pTq);
int32_t tqProcessTaskCheckPointSourceReq(STQ* pTq, SRpcMsg* pMsg, SRpcMsg* pRsp);
@ -345,7 +345,7 @@ int32_t tsdbSnapRAWWriterPrepareClose(STsdbSnapRAWWriter* pWriter);
int32_t tsdbSnapRAWWriterClose(STsdbSnapRAWWriter** ppWriter, int8_t rollback);
// STqSnapshotReader ==
int32_t tqSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, int8_t type, STqSnapReader** ppReader);
int32_t tqSnapReaderClose(STqSnapReader** ppReader);
void tqSnapReaderClose(STqSnapReader** ppReader);
int32_t tqSnapRead(STqSnapReader* pReader, uint8_t** ppData);
// STqSnapshotWriter ======================================
int32_t tqSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapWriter** ppWriter);

View File

@ -219,50 +219,91 @@ static void destroySTableInfoForChildTable(void* data) {
tDeleteSchemaWrapper(pData->tagRow);
}
static void MoveToSnapShotVersion(SSnapContext* ctx) {
tdbTbcClose((TBC*)ctx->pCur);
tdbTbcOpen(ctx->pMeta->pTbDb, (TBC**)&ctx->pCur, NULL);
static int32_t MoveToSnapShotVersion(SSnapContext* ctx) {
int32_t code = 0;
(void)tdbTbcClose((TBC*)ctx->pCur);
code = tdbTbcOpen(ctx->pMeta->pTbDb, (TBC**)&ctx->pCur, NULL);
if (code != 0){
return TAOS_GET_TERRNO(code);
}
STbDbKey key = {.version = ctx->snapVersion, .uid = INT64_MAX};
int c = 0;
tdbTbcMoveTo((TBC*)ctx->pCur, &key, sizeof(key), &c);
code = tdbTbcMoveTo((TBC*)ctx->pCur, &key, sizeof(key), &c);
if (code != 0){
return TAOS_GET_TERRNO(code);
}
if (c < 0) {
tdbTbcMoveToPrev((TBC*)ctx->pCur);
}
return 0;
}
static int32_t MoveToPosition(SSnapContext* ctx, int64_t ver, int64_t uid) {
tdbTbcClose((TBC*)ctx->pCur);
tdbTbcOpen(ctx->pMeta->pTbDb, (TBC**)&ctx->pCur, NULL);
(void)tdbTbcClose((TBC*)ctx->pCur);
int32_t code = tdbTbcOpen(ctx->pMeta->pTbDb, (TBC**)&ctx->pCur, NULL);
if (code != 0){
return TAOS_GET_TERRNO(code);
}
STbDbKey key = {.version = ver, .uid = uid};
int c = 0;
tdbTbcMoveTo((TBC*)ctx->pCur, &key, sizeof(key), &c);
code = tdbTbcMoveTo((TBC*)ctx->pCur, &key, sizeof(key), &c);
if (code != 0){
return TAOS_GET_TERRNO(code);
}
return c;
}
static void MoveToFirst(SSnapContext* ctx) {
tdbTbcClose((TBC*)ctx->pCur);
tdbTbcOpen(ctx->pMeta->pTbDb, (TBC**)&ctx->pCur, NULL);
tdbTbcMoveToFirst((TBC*)ctx->pCur);
static int32_t MoveToFirst(SSnapContext* ctx) {
(void)tdbTbcClose((TBC*)ctx->pCur);
int32_t code = tdbTbcOpen(ctx->pMeta->pTbDb, (TBC**)&ctx->pCur, NULL);
if (code != 0){
return TAOS_GET_TERRNO(code);
}
code = tdbTbcMoveToFirst((TBC*)ctx->pCur);
if (code != 0){
return TAOS_GET_TERRNO(code);
}
return 0;
}
static void saveSuperTableInfoForChildTable(SMetaEntry* me, SHashObj* suidInfo) {
static int32_t saveSuperTableInfoForChildTable(SMetaEntry* me, SHashObj* suidInfo) {
STableInfoForChildTable* data = (STableInfoForChildTable*)taosHashGet(suidInfo, &me->uid, sizeof(tb_uid_t));
if (data) {
return;
return 0;
}
int32_t code = 0;
STableInfoForChildTable dataTmp = {0};
dataTmp.tableName = taosStrdup(me->name);
if (dataTmp.tableName == NULL){
code = TSDB_CODE_OUT_OF_MEMORY;
goto END;
}
dataTmp.schemaRow = tCloneSSchemaWrapper(&me->stbEntry.schemaRow);
if (dataTmp.schemaRow == NULL){
code = TSDB_CODE_OUT_OF_MEMORY;
goto END;
}
dataTmp.tagRow = tCloneSSchemaWrapper(&me->stbEntry.schemaTag);
taosHashPut(suidInfo, &me->uid, sizeof(tb_uid_t), &dataTmp, sizeof(STableInfoForChildTable));
if (dataTmp.tagRow == NULL){
code = TSDB_CODE_OUT_OF_MEMORY;
goto END;
}
code = taosHashPut(suidInfo, &me->uid, sizeof(tb_uid_t), &dataTmp, sizeof(STableInfoForChildTable));
if (code != 0){
goto END;
}
return 0;
END:
destroySTableInfoForChildTable(&dataTmp);
return TAOS_GET_TERRNO(code);;
}
int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8_t subType, int8_t withMeta,
SSnapContext** ctxRet) {
SSnapContext* ctx = taosMemoryCalloc(1, sizeof(SSnapContext));
if (ctx == NULL) {
return terrno;
if (ctx == NULL){
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
*ctxRet = ctx;
ctx->pMeta = pVnode->pMeta;
@ -273,23 +314,29 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8
ctx->withMeta = withMeta;
ctx->idVersion = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
if (ctx->idVersion == NULL) {
return terrno;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
ctx->suidInfo = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
if (ctx->suidInfo == NULL) {
return terrno;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);;
}
taosHashSetFreeFp(ctx->suidInfo, destroySTableInfoForChildTable);
ctx->index = 0;
ctx->idList = taosArrayInit(100, sizeof(int64_t));
if (ctx->idList == NULL){
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);;
}
void* pKey = NULL;
void* pVal = NULL;
int vLen = 0, kLen = 0;
metaDebug("tmqsnap init snapVersion:%" PRIi64, ctx->snapVersion);
MoveToFirst(ctx);
int32_t code = MoveToFirst(ctx);
if (code != 0){
return code;
}
while (1) {
int32_t ret = tdbTbcNext((TBC*)ctx->pCur, &pKey, &kLen, &pVal, &vLen);
if (ret < 0) break;
@ -301,15 +348,18 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8
continue;
}
if (tdbTbGet(ctx->pMeta->pUidIdx, &tmp->uid, sizeof(tb_uid_t), NULL, NULL) <
0) { // check if table exist for now, need optimize later
if (tdbTbGet(ctx->pMeta->pUidIdx, &tmp->uid, sizeof(tb_uid_t), NULL, NULL) < 0) { // check if table exist for now, need optimize later
continue;
}
SDecoder dc = {0};
SMetaEntry me = {0};
tDecoderInit(&dc, pVal, vLen);
metaDecodeEntry(&dc, &me);
ret = metaDecodeEntry(&dc, &me);
if (ret < 0){
tDecoderClear(&dc);
return TAOS_GET_TERRNO(ret);
}
if (ctx->subType == TOPIC_SUB_TYPE__TABLE) {
if ((me.uid != ctx->suid && me.type == TSDB_SUPER_TABLE) ||
(me.ctbEntry.suid != ctx->suid && me.type == TSDB_CHILD_TABLE)) {
@ -318,16 +368,24 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8
}
}
taosArrayPush(ctx->idList, &tmp->uid);
if (taosArrayPush(ctx->idList, &tmp->uid) == NULL){
tDecoderClear(&dc);
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
metaDebug("tmqsnap init idlist name:%s, uid:%" PRIi64, me.name, tmp->uid);
SIdInfo info = {0};
taosHashPut(ctx->idVersion, &tmp->uid, sizeof(tb_uid_t), &info, sizeof(SIdInfo));
tDecoderClear(&dc);
SIdInfo info = {0};
if (taosHashPut(ctx->idVersion, &tmp->uid, sizeof(tb_uid_t), &info, sizeof(SIdInfo)) != 0) {
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
}
taosHashClear(ctx->idVersion);
MoveToSnapShotVersion(ctx);
code = MoveToSnapShotVersion(ctx);
if (code != 0){
return code;
}
while (1) {
int32_t ret = tdbTbcPrev((TBC*)ctx->pCur, &pKey, &kLen, &pVal, &vLen);
if (ret < 0) break;
@ -338,12 +396,20 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8
continue;
}
SIdInfo info = {.version = tmp->version, .index = 0};
taosHashPut(ctx->idVersion, &tmp->uid, sizeof(tb_uid_t), &info, sizeof(SIdInfo));
ret = taosHashPut(ctx->idVersion, &tmp->uid, sizeof(tb_uid_t), &info, sizeof(SIdInfo));
if (ret != 0) {
return TAOS_GET_TERRNO(ret);
}
SDecoder dc = {0};
SMetaEntry me = {0};
tDecoderInit(&dc, pVal, vLen);
metaDecodeEntry(&dc, &me);
ret = metaDecodeEntry(&dc, &me);
if (ret < 0){
tDecoderClear(&dc);
return TAOS_GET_TERRNO(ret);
}
if (ctx->subType == TOPIC_SUB_TYPE__TABLE) {
if ((me.uid != ctx->suid && me.type == TSDB_SUPER_TABLE) ||
(me.ctbEntry.suid != ctx->suid && me.type == TSDB_CHILD_TABLE)) {
@ -354,17 +420,24 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8
if ((ctx->subType == TOPIC_SUB_TYPE__DB && me.type == TSDB_SUPER_TABLE) ||
(ctx->subType == TOPIC_SUB_TYPE__TABLE && me.uid == ctx->suid)) {
saveSuperTableInfoForChildTable(&me, ctx->suidInfo);
ret = saveSuperTableInfoForChildTable(&me, ctx->suidInfo);
if (ret != 0){
tDecoderClear(&dc);
return ret;
}
}
tDecoderClear(&dc);
}
for (int i = 0; i < taosArrayGetSize(ctx->idList); i++) {
int64_t* uid = taosArrayGet(ctx->idList, i);
if (uid == NULL){
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
SIdInfo* idData = (SIdInfo*)taosHashGet(ctx->idVersion, uid, sizeof(int64_t));
if (!idData) {
metaError("meta/snap: null idData");
return TSDB_CODE_FAILED;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
idData->index = i;
@ -377,13 +450,12 @@ int32_t buildSnapContext(SVnode* pVnode, int64_t snapVersion, int64_t suid, int8
return TDB_CODE_SUCCESS;
}
int32_t destroySnapContext(SSnapContext* ctx) {
tdbTbcClose((TBC*)ctx->pCur);
void destroySnapContext(SSnapContext* ctx) {
(void)tdbTbcClose((TBC*)ctx->pCur);
taosArrayDestroy(ctx->idList);
taosHashCleanup(ctx->idVersion);
taosHashCleanup(ctx->suidInfo);
taosMemoryFree(ctx);
return 0;
}
static int32_t buildNormalChildTableInfo(SVCreateTbReq* req, void** pBuf, int32_t* contLen) {
@ -392,32 +464,36 @@ static int32_t buildNormalChildTableInfo(SVCreateTbReq* req, void** pBuf, int32_
reqs.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq));
if (NULL == reqs.pArray) {
ret = -1;
ret = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
goto end;
}
if (taosArrayPush(reqs.pArray, req) == NULL){
ret = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
goto end;
}
taosArrayPush(reqs.pArray, req);
reqs.nReqs = 1;
tEncodeSize(tEncodeSVCreateTbBatchReq, &reqs, *contLen, ret);
if (ret < 0) {
ret = -1;
ret = TAOS_GET_TERRNO(ret);
goto end;
}
*contLen += sizeof(SMsgHead);
*pBuf = taosMemoryMalloc(*contLen);
if (NULL == *pBuf) {
ret = -1;
ret = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
goto end;
}
SEncoder coder = {0};
tEncoderInit(&coder, POINTER_SHIFT(*pBuf, sizeof(SMsgHead)), *contLen);
if (tEncodeSVCreateTbBatchReq(&coder, &reqs) < 0) {
ret = tEncodeSVCreateTbBatchReq(&coder, &reqs);
tEncoderClear(&coder);
if (ret < 0) {
taosMemoryFreeClear(*pBuf);
tEncoderClear(&coder);
ret = -1;
ret = TAOS_GET_TERRNO(ret);
goto end;
}
tEncoderClear(&coder);
end:
taosArrayDestroy(reqs.pArray);
@ -428,48 +504,46 @@ static int32_t buildSuperTableInfo(SVCreateStbReq* req, void** pBuf, int32_t* co
int32_t ret = 0;
tEncodeSize(tEncodeSVCreateStbReq, req, *contLen, ret);
if (ret < 0) {
return ret;
return TAOS_GET_TERRNO(ret);
}
*contLen += sizeof(SMsgHead);
*pBuf = taosMemoryMalloc(*contLen);
if (NULL == *pBuf) {
return terrno;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
SEncoder encoder = {0};
tEncoderInit(&encoder, POINTER_SHIFT(*pBuf, sizeof(SMsgHead)), *contLen);
if ((ret = tEncodeSVCreateStbReq(&encoder, req)) < 0) {
taosMemoryFreeClear(*pBuf);
tEncoderClear(&encoder);
return ret;
}
ret = tEncodeSVCreateStbReq(&encoder, req);
tEncoderClear(&encoder);
if (ret < 0) {
taosMemoryFreeClear(*pBuf);
return TAOS_GET_TERRNO(ret);
}
return 0;
}
int32_t setForSnapShot(SSnapContext* ctx, int64_t uid) {
int c = 0;
if (uid == 0) {
ctx->index = 0;
return c;
return 0;
}
SIdInfo* idInfo = (SIdInfo*)taosHashGet(ctx->idVersion, &uid, sizeof(tb_uid_t));
if (!idInfo) {
return -1;
if (idInfo == NULL) {
return terrno;
}
ctx->index = idInfo->index;
return c;
return 0;
}
void taosXSetTablePrimaryKey(SSnapContext* ctx, int64_t uid) {
bool ret = false;
SSchemaWrapper* schema = metaGetTableSchema(ctx->pMeta, uid, -1, 1);
if (schema->nCols >= 2 && schema->pSchema[1].flags & COL_IS_KEY) {
void taosXSetTablePrimaryKey(SSnapContext* ctx, int64_t uid){
bool ret = false;
SSchemaWrapper *schema = metaGetTableSchema(ctx->pMeta, uid, -1, 1);
if (schema && schema->nCols >= 2 && schema->pSchema[1].flags & COL_IS_KEY){
ret = true;
}
tDeleteSchemaWrapper(schema);
@ -493,11 +567,15 @@ int32_t getTableInfoFromSnapshot(SSnapContext* ctx, void** pBuf, int32_t* contLe
}
int64_t* uidTmp = taosArrayGet(ctx->idList, ctx->index);
if (uidTmp == NULL) {
metaError("tmqsnap get meta null uid");
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
ctx->index++;
SIdInfo* idInfo = (SIdInfo*)taosHashGet(ctx->idVersion, uidTmp, sizeof(tb_uid_t));
if (!idInfo) {
metaError("meta/snap: null idInfo");
return TSDB_CODE_FAILED;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
*uid = *uidTmp;
@ -508,11 +586,18 @@ int32_t getTableInfoFromSnapshot(SSnapContext* ctx, void** pBuf, int32_t* contLe
metaDebug("tmqsnap get meta not exist uid:%" PRIi64 " version:%" PRIi64, *uid, idInfo->version);
}
tdbTbcGet((TBC*)ctx->pCur, (const void**)&pKey, &kLen, (const void**)&pVal, &vLen);
ret = tdbTbcGet((TBC*)ctx->pCur, (const void**)&pKey, &kLen, (const void**)&pVal, &vLen);
if (ret < 0) {
return TAOS_GET_TERRNO(ret);
}
SDecoder dc = {0};
SMetaEntry me = {0};
tDecoderInit(&dc, pVal, vLen);
metaDecodeEntry(&dc, &me);
ret = metaDecodeEntry(&dc, &me);
if (ret < 0) {
ret = TAOS_GET_TERRNO(ret);
goto END;
}
metaDebug("tmqsnap get meta uid:%" PRIi64 " name:%s index:%d", *uid, me.name, ctx->index - 1);
if ((ctx->subType == TOPIC_SUB_TYPE__DB && me.type == TSDB_SUPER_TABLE) ||
@ -528,14 +613,14 @@ int32_t getTableInfoFromSnapshot(SSnapContext* ctx, void** pBuf, int32_t* contLe
ret = buildSuperTableInfo(&req, pBuf, contLen);
*type = TDMT_VND_CREATE_STB;
} else if ((ctx->subType == TOPIC_SUB_TYPE__DB && me.type == TSDB_CHILD_TABLE) ||
(ctx->subType == TOPIC_SUB_TYPE__TABLE && me.type == TSDB_CHILD_TABLE && me.ctbEntry.suid == ctx->suid)) {
STableInfoForChildTable* data =
(STableInfoForChildTable*)taosHashGet(ctx->suidInfo, &me.ctbEntry.suid, sizeof(tb_uid_t));
if (!data) {
metaError("meta/snap: null data");
return TSDB_CODE_FAILED;
ret = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
goto END;
}
SVCreateTbReq req = {0};
@ -549,46 +634,48 @@ int32_t getTableInfoFromSnapshot(SSnapContext* ctx, void** pBuf, int32_t* contLe
req.ctb.stbName = data->tableName;
SArray* tagName = taosArrayInit(req.ctb.tagNum, TSDB_COL_NAME_LEN);
if (tagName == NULL) {
metaError("meta/snap: init tag name failed.");
ret = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
goto END;
}
STag* p = (STag*)me.ctbEntry.pTags;
if (tTagIsJson(p)) {
if (p->nTag != 0) {
SSchema* schema = &data->tagRow->pSchema[0];
taosArrayPush(tagName, schema->name);
if (taosArrayPush(tagName, schema->name) == NULL) {
ret = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
taosArrayDestroy(tagName);
goto END;
}
}
} else {
SArray* pTagVals = NULL;
if (tTagToValArray((const STag*)p, &pTagVals) != 0) {
ret = tTagToValArray((const STag*)p, &pTagVals);
if (ret != 0) {
metaError("meta/snap: tag to val array failed.");
return TSDB_CODE_FAILED;
taosArrayDestroy(pTagVals);
taosArrayDestroy(tagName);
goto END;
}
int16_t nCols = taosArrayGetSize(pTagVals);
for (int j = 0; j < nCols; ++j) {
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
for (int i = 0; i < data->tagRow->nCols; i++) {
for (int i = 0; pTagVal && i < data->tagRow->nCols; i++) {
SSchema* schema = &data->tagRow->pSchema[i];
if (schema->colId == pTagVal->cid) {
taosArrayPush(tagName, schema->name);
if (taosArrayPush(tagName, schema->name) == NULL) {
ret = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
taosArrayDestroy(pTagVals);
taosArrayDestroy(tagName);
goto END;
}
}
}
}
taosArrayDestroy(pTagVals);
}
// SIdInfo* sidInfo = (SIdInfo*)taosHashGet(ctx->idVersion, &me.ctbEntry.suid, sizeof(tb_uid_t));
// if(sidInfo->version >= idInfo->version){
// // need parse tag
// STag* p = (STag*)me.ctbEntry.pTags;
// SArray* pTagVals = NULL;
// if (tTagToValArray((const STag*)p, &pTagVals) != 0) {
// }
//
// int16_t nCols = taosArrayGetSize(pTagVals);
// for (int j = 0; j < nCols; ++j) {
// STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
// }
// }else{
req.ctb.pTag = me.ctbEntry.pTags;
// }
req.ctb.tagName = tagName;
ret = buildNormalChildTableInfo(&req, pBuf, contLen);
*type = TDMT_VND_CREATE_TABLE;
@ -605,15 +692,15 @@ int32_t getTableInfoFromSnapshot(SSnapContext* ctx, void** pBuf, int32_t* contLe
*type = TDMT_VND_CREATE_TABLE;
} else {
metaError("meta/snap: invalid topic sub type: %" PRId8 " get meta from snap failed.", ctx->subType);
ret = -1;
ret = TSDB_CODE_SDB_INVALID_TABLE_TYPE;
}
tDecoderClear(&dc);
END:
tDecoderClear(&dc);
return ret;
}
SMetaTableInfo getMetaTableInfoFromSnapshot(SSnapContext* ctx) {
SMetaTableInfo result = {0};
int32_t getMetaTableInfoFromSnapshot(SSnapContext* ctx, SMetaTableInfo* result) {
void* pKey = NULL;
void* pVal = NULL;
int vLen, kLen;
@ -621,14 +708,17 @@ SMetaTableInfo getMetaTableInfoFromSnapshot(SSnapContext* ctx) {
while (1) {
if (ctx->index >= taosArrayGetSize(ctx->idList)) {
metaDebug("tmqsnap get uid info end");
return result;
return 0;
}
int64_t* uidTmp = taosArrayGet(ctx->idList, ctx->index);
if (uidTmp == NULL){
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
ctx->index++;
SIdInfo* idInfo = (SIdInfo*)taosHashGet(ctx->idVersion, uidTmp, sizeof(tb_uid_t));
if (!idInfo) {
metaError("meta/snap: null idInfo");
return result;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
int32_t ret = MoveToPosition(ctx, idInfo->version, *uidTmp);
@ -637,44 +727,46 @@ SMetaTableInfo getMetaTableInfoFromSnapshot(SSnapContext* ctx) {
idInfo->version);
continue;
}
tdbTbcGet((TBC*)ctx->pCur, (const void**)&pKey, &kLen, (const void**)&pVal, &vLen);
ret = tdbTbcGet((TBC*)ctx->pCur, (const void**)&pKey, &kLen, (const void**)&pVal, &vLen);
if (ret != 0){
return TAOS_GET_TERRNO(ret);
}
SDecoder dc = {0};
SMetaEntry me = {0};
tDecoderInit(&dc, pVal, vLen);
metaDecodeEntry(&dc, &me);
ret = metaDecodeEntry(&dc, &me);
if (ret != 0){
tDecoderClear(&dc);
return TAOS_GET_TERRNO(ret);
}
metaDebug("tmqsnap get uid info uid:%" PRIi64 " name:%s index:%d", me.uid, me.name, ctx->index - 1);
if (ctx->subType == TOPIC_SUB_TYPE__DB && me.type == TSDB_CHILD_TABLE) {
if ((ctx->subType == TOPIC_SUB_TYPE__DB && me.type == TSDB_CHILD_TABLE) ||
(ctx->subType == TOPIC_SUB_TYPE__TABLE && me.type == TSDB_CHILD_TABLE && me.ctbEntry.suid == ctx->suid)){
STableInfoForChildTable* data =
(STableInfoForChildTable*)taosHashGet(ctx->suidInfo, &me.ctbEntry.suid, sizeof(tb_uid_t));
result.uid = me.uid;
result.suid = me.ctbEntry.suid;
result.schema = tCloneSSchemaWrapper(data->schemaRow);
strcpy(result.tbName, me.name);
tDecoderClear(&dc);
break;
if (data == NULL) {
tDecoderClear(&dc);
metaError("meta/snap: null data");
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
result->suid = me.ctbEntry.suid;
result->schema = tCloneSSchemaWrapper(data->schemaRow);
} else if (ctx->subType == TOPIC_SUB_TYPE__DB && me.type == TSDB_NORMAL_TABLE) {
result.uid = me.uid;
result.suid = 0;
strcpy(result.tbName, me.name);
result.schema = tCloneSSchemaWrapper(&me.ntbEntry.schemaRow);
tDecoderClear(&dc);
break;
} else if (ctx->subType == TOPIC_SUB_TYPE__TABLE && me.type == TSDB_CHILD_TABLE && me.ctbEntry.suid == ctx->suid) {
STableInfoForChildTable* data =
(STableInfoForChildTable*)taosHashGet(ctx->suidInfo, &me.ctbEntry.suid, sizeof(tb_uid_t));
result.uid = me.uid;
result.suid = me.ctbEntry.suid;
strcpy(result.tbName, me.name);
result.schema = tCloneSSchemaWrapper(data->schemaRow);
tDecoderClear(&dc);
break;
result->suid = 0;
result->schema = tCloneSSchemaWrapper(&me.ntbEntry.schemaRow);
} else {
metaDebug("tmqsnap get uid continue");
tDecoderClear(&dc);
continue;
}
result->uid = me.uid;
tstrncpy(result->tbName, me.name, TSDB_TABLE_NAME_LEN);
tDecoderClear(&dc);
if(result->schema == NULL){
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
break;
}
return result;
return 0;
}

View File

@ -46,39 +46,38 @@ static bool ttlMgrNeedFlush(STtlManger *pTtlMgr);
const char *ttlTbname = "ttl.idx";
const char *ttlV1Tbname = "ttlv1.idx";
int ttlMgrOpen(STtlManger **ppTtlMgr, TDB *pEnv, int8_t rollback, const char *logPrefix, int32_t flushThreshold) {
int ret = TSDB_CODE_SUCCESS;
int32_t ttlMgrOpen(STtlManger **ppTtlMgr, TDB *pEnv, int8_t rollback, const char *logPrefix, int32_t flushThreshold) {
int32_t code = TSDB_CODE_SUCCESS;
int64_t startNs = taosGetTimestampNs();
*ppTtlMgr = NULL;
STtlManger *pTtlMgr = (STtlManger *)tdbOsCalloc(1, sizeof(*pTtlMgr));
if (pTtlMgr == NULL) return TSDB_CODE_OUT_OF_MEMORY;
if (pTtlMgr == NULL) TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
char *logBuffer = (char *)tdbOsCalloc(1, strlen(logPrefix) + 1);
if (logBuffer == NULL) {
tdbOsFree(pTtlMgr);
return TSDB_CODE_OUT_OF_MEMORY;
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
strcpy(logBuffer, logPrefix);
(void)strcpy(logBuffer, logPrefix);
pTtlMgr->logPrefix = logBuffer;
pTtlMgr->flushThreshold = flushThreshold;
ret = tdbTbOpen(ttlV1Tbname, TDB_VARIANT_LEN, TDB_VARIANT_LEN, ttlIdxKeyV1Cmpr, pEnv, &pTtlMgr->pTtlIdx, rollback);
if (ret < 0) {
metaError("%s, failed to open %s since %s", pTtlMgr->logPrefix, ttlV1Tbname, tstrerror(terrno));
code = tdbTbOpen(ttlV1Tbname, TDB_VARIANT_LEN, TDB_VARIANT_LEN, ttlIdxKeyV1Cmpr, pEnv, &pTtlMgr->pTtlIdx, rollback);
if (TSDB_CODE_SUCCESS != code) {
metaError("%s, failed to open %s since %s", pTtlMgr->logPrefix, ttlV1Tbname, tstrerror(code));
tdbOsFree(pTtlMgr);
return ret;
TAOS_RETURN(code);
}
pTtlMgr->pTtlCache = taosHashInit(8192, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
pTtlMgr->pDirtyUids = taosHashInit(8192, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
ret = ttlMgrFillCache(pTtlMgr);
if (ret < 0) {
if ((code = ttlMgrFillCache(pTtlMgr)) != TSDB_CODE_SUCCESS) {
metaError("%s, failed to fill hash since %s", pTtlMgr->logPrefix, tstrerror(terrno));
ttlMgrCleanup(pTtlMgr);
return ret;
TAOS_RETURN(code);
}
int64_t endNs = taosGetTimestampNs();
@ -86,7 +85,7 @@ int ttlMgrOpen(STtlManger **ppTtlMgr, TDB *pEnv, int8_t rollback, const char *lo
taosHashGetSize(pTtlMgr->pTtlCache), endNs - startNs);
*ppTtlMgr = pTtlMgr;
return TSDB_CODE_SUCCESS;
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
void ttlMgrClose(STtlManger *pTtlMgr) { ttlMgrCleanup(pTtlMgr); }
@ -99,37 +98,34 @@ bool ttlMgrNeedUpgrade(TDB *pEnv) {
return needUpgrade;
}
int ttlMgrUpgrade(STtlManger *pTtlMgr, void *pMeta) {
SMeta *meta = (SMeta *)pMeta;
int ret = TSDB_CODE_SUCCESS;
int32_t ttlMgrUpgrade(STtlManger *pTtlMgr, void *pMeta) {
SMeta *meta = (SMeta *)pMeta;
int32_t code = TSDB_CODE_SUCCESS;
if (!tdbTbExist(ttlTbname, meta->pEnv)) return TSDB_CODE_SUCCESS;
if (!tdbTbExist(ttlTbname, meta->pEnv)) TAOS_RETURN(TSDB_CODE_SUCCESS);
metaInfo("%s, ttl mgr start upgrade", pTtlMgr->logPrefix);
int64_t startNs = taosGetTimestampNs();
ret = tdbTbOpen(ttlTbname, sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, meta->pEnv, &pTtlMgr->pOldTtlIdx, 0);
if (ret < 0) {
metaError("%s, failed to open %s index since %s", pTtlMgr->logPrefix, ttlTbname, tstrerror(terrno));
code = tdbTbOpen(ttlTbname, sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, meta->pEnv, &pTtlMgr->pOldTtlIdx, 0);
if (TSDB_CODE_SUCCESS != code) {
metaError("%s, failed to open %s index since %s", pTtlMgr->logPrefix, ttlTbname, tstrerror(code));
goto _out;
}
ret = ttlMgrConvert(pTtlMgr->pOldTtlIdx, pTtlMgr->pTtlIdx, pMeta);
if (ret < 0) {
metaError("%s, failed to convert ttl index since %s", pTtlMgr->logPrefix, tstrerror(terrno));
if ((code = ttlMgrConvert(pTtlMgr->pOldTtlIdx, pTtlMgr->pTtlIdx, pMeta)) != TSDB_CODE_SUCCESS) {
metaError("%s, failed to convert ttl index since %s", pTtlMgr->logPrefix, tstrerror(code));
goto _out;
}
ret = tdbTbDropByName(ttlTbname, meta->pEnv, meta->txn);
if (ret < 0) {
metaError("%s, failed to drop old ttl index since %s", pTtlMgr->logPrefix, tstrerror(terrno));
if ((code = tdbTbDropByName(ttlTbname, meta->pEnv, meta->txn)) != TSDB_CODE_SUCCESS) {
metaError("%s, failed to drop old ttl index since %s", pTtlMgr->logPrefix, tstrerror(code));
goto _out;
}
ret = ttlMgrFillCache(pTtlMgr);
if (ret < 0) {
metaError("%s, failed to fill hash since %s", pTtlMgr->logPrefix, tstrerror(terrno));
if ((code = ttlMgrFillCache(pTtlMgr)) != TSDB_CODE_SUCCESS) {
metaError("%s, failed to fill hash since %s", pTtlMgr->logPrefix, tstrerror(code));
goto _out;
}
@ -141,14 +137,14 @@ _out:
tdbTbClose(pTtlMgr->pOldTtlIdx);
pTtlMgr->pOldTtlIdx = NULL;
return ret;
TAOS_RETURN(code);
}
static void ttlMgrCleanup(STtlManger *pTtlMgr) {
taosMemoryFree(pTtlMgr->logPrefix);
taosHashCleanup(pTtlMgr->pTtlCache);
taosHashCleanup(pTtlMgr->pDirtyUids);
tdbTbClose(pTtlMgr->pTtlIdx);
(void)tdbTbClose(pTtlMgr->pTtlIdx);
taosMemoryFree(pTtlMgr);
}
@ -215,30 +211,30 @@ static int32_t ttlMgrFillCacheOneEntry(const void *pKey, int keyLen, const void
return taosHashPut(pCache, &uid, sizeof(uid), &data, sizeof(data));
}
static int ttlMgrConvertOneEntry(const void *pKey, int keyLen, const void *pVal, int valLen, void *pConvertData) {
static int32_t ttlMgrConvertOneEntry(const void *pKey, int keyLen, const void *pVal, int valLen, void *pConvertData) {
SConvertData *pData = (SConvertData *)pConvertData;
STtlIdxKey *ttlKey = (STtlIdxKey *)pKey;
tb_uid_t uid = ttlKey->uid;
int64_t ttlDays = 0;
int ret = metaGetTableTtlByUid(pData->pMeta, uid, &ttlDays);
if (ret < 0) {
metaError("ttlMgr convert failed to get ttl since %s", tstrerror(terrno));
int32_t code = TSDB_CODE_SUCCESS;
if ((code = metaGetTableTtlByUid(pData->pMeta, uid, &ttlDays)) != TSDB_CODE_SUCCESS) {
metaError("ttlMgr convert failed to get ttl since %s", tstrerror(code));
goto _out;
}
STtlIdxKeyV1 ttlKeyV1 = {.deleteTimeMs = ttlKey->deleteTimeSec * 1000, .uid = uid};
ret = tdbTbUpsert(pData->pNewTtlIdx, &ttlKeyV1, sizeof(ttlKeyV1), &ttlDays, sizeof(ttlDays), pData->pMeta->txn);
if (ret < 0) {
metaError("ttlMgr convert failed to upsert since %s", tstrerror(terrno));
code = tdbTbUpsert(pData->pNewTtlIdx, &ttlKeyV1, sizeof(ttlKeyV1), &ttlDays, sizeof(ttlDays), pData->pMeta->txn);
if (code != TSDB_CODE_SUCCESS) {
metaError("ttlMgr convert failed to upsert since %s", tstrerror(code));
goto _out;
}
ret = 0;
code = TSDB_CODE_SUCCESS;
_out:
return ret;
TAOS_RETURN(code);
}
static int32_t ttlMgrFindExpiredOneEntry(const void *pKey, int keyLen, const void *pVal, int valLen,
@ -248,7 +244,10 @@ static int32_t ttlMgrFindExpiredOneEntry(const void *pKey, int keyLen, const voi
int c = ttlIdxKeyV1Cmpr(&pCtx->expiredKey, sizeof(pCtx->expiredKey), pKey, keyLen);
if (c > 0) {
taosArrayPush(pCtx->pTbUids, &((STtlIdxKeyV1 *)pKey)->uid);
if (NULL == taosArrayPush(pCtx->pTbUids, &((STtlIdxKeyV1 *)pKey)->uid)) {
metaError("ttlMgr find expired failed since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY));
return -1;
}
pCtx->count++;
}
@ -262,16 +261,16 @@ static int ttlMgrConvert(TTB *pOldTtlIdx, TTB *pNewTtlIdx, void *pMeta) {
SConvertData cvData = {.pNewTtlIdx = pNewTtlIdx, .pMeta = meta};
int ret = tdbTbTraversal(pOldTtlIdx, &cvData, ttlMgrConvertOneEntry);
if (ret < 0) {
metaError("failed to convert since %s", tstrerror(terrno));
int code = TSDB_CODE_SUCCESS;
if ((code = tdbTbTraversal(pOldTtlIdx, &cvData, ttlMgrConvertOneEntry)) != TSDB_CODE_SUCCESS) {
metaError("failed to convert since %s", tstrerror(code));
}
metaInfo("ttlMgr convert end.");
return ret;
TAOS_RETURN(code);
}
int ttlMgrInsertTtl(STtlManger *pTtlMgr, const STtlUpdTtlCtx *updCtx) {
int32_t ttlMgrInsertTtl(STtlManger *pTtlMgr, const STtlUpdTtlCtx *updCtx) {
if (updCtx->ttlDays == 0) return 0;
STtlCacheEntry cacheEntry = {.ttlDays = updCtx->ttlDays,
@ -280,56 +279,55 @@ int ttlMgrInsertTtl(STtlManger *pTtlMgr, const STtlUpdTtlCtx *updCtx) {
.changeTimeMsDirty = updCtx->changeTimeMs};
STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_UPSERT};
int ret = taosHashPut(pTtlMgr->pTtlCache, &updCtx->uid, sizeof(updCtx->uid), &cacheEntry, sizeof(cacheEntry));
if (ret < 0) {
metaError("%s, ttlMgr insert failed to update cache since %s", pTtlMgr->logPrefix, tstrerror(terrno));
int32_t code = taosHashPut(pTtlMgr->pTtlCache, &updCtx->uid, sizeof(updCtx->uid), &cacheEntry, sizeof(cacheEntry));
if (TSDB_CODE_SUCCESS != code) {
metaError("%s, ttlMgr insert failed to update cache since %s", pTtlMgr->logPrefix, tstrerror(code));
goto _out;
}
ret = taosHashPut(pTtlMgr->pDirtyUids, &updCtx->uid, sizeof(updCtx->uid), &dirtryEntry, sizeof(dirtryEntry));
if (ret < 0) {
metaError("%s, ttlMgr insert failed to update dirty uids since %s", pTtlMgr->logPrefix, tstrerror(terrno));
code = taosHashPut(pTtlMgr->pDirtyUids, &updCtx->uid, sizeof(updCtx->uid), &dirtryEntry, sizeof(dirtryEntry));
if (TSDB_CODE_SUCCESS != code) {
metaError("%s, ttlMgr insert failed to update dirty uids since %s", pTtlMgr->logPrefix, tstrerror(code));
goto _out;
}
if (ttlMgrNeedFlush(pTtlMgr)) {
ttlMgrFlush(pTtlMgr, updCtx->pTxn);
(void)ttlMgrFlush(pTtlMgr, updCtx->pTxn);
}
ret = 0;
code = TSDB_CODE_SUCCESS;
_out:
metaTrace("%s, ttl mgr insert ttl, uid: %" PRId64 ", ctime: %" PRId64 ", ttlDays: %" PRId64, pTtlMgr->logPrefix,
updCtx->uid, updCtx->changeTimeMs, updCtx->ttlDays);
return ret;
TAOS_RETURN(code);
}
int ttlMgrDeleteTtl(STtlManger *pTtlMgr, const STtlDelTtlCtx *delCtx) {
int32_t ttlMgrDeleteTtl(STtlManger *pTtlMgr, const STtlDelTtlCtx *delCtx) {
if (delCtx->ttlDays == 0) return 0;
STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_DELETE};
int ret = taosHashPut(pTtlMgr->pDirtyUids, &delCtx->uid, sizeof(delCtx->uid), &dirtryEntry, sizeof(dirtryEntry));
if (ret < 0) {
metaError("%s, ttlMgr del failed to update dirty uids since %s", pTtlMgr->logPrefix, tstrerror(terrno));
int32_t code = taosHashPut(pTtlMgr->pDirtyUids, &delCtx->uid, sizeof(delCtx->uid), &dirtryEntry, sizeof(dirtryEntry));
if (TSDB_CODE_SUCCESS != code) {
metaError("%s, ttlMgr del failed to update dirty uids since %s", pTtlMgr->logPrefix, tstrerror(code));
goto _out;
}
if (ttlMgrNeedFlush(pTtlMgr)) {
ttlMgrFlush(pTtlMgr, delCtx->pTxn);
(void)ttlMgrFlush(pTtlMgr, delCtx->pTxn);
}
ret = 0;
code = TSDB_CODE_SUCCESS;
_out:
metaTrace("%s, ttl mgr delete ttl, uid: %" PRId64, pTtlMgr->logPrefix, delCtx->uid);
return ret;
TAOS_RETURN(code);
}
int ttlMgrUpdateChangeTime(STtlManger *pTtlMgr, const STtlUpdCtimeCtx *pUpdCtimeCtx) {
int ret = 0;
int32_t ttlMgrUpdateChangeTime(STtlManger *pTtlMgr, const STtlUpdCtimeCtx *pUpdCtimeCtx) {
int32_t code = TSDB_CODE_SUCCESS;
STtlCacheEntry *oldData = taosHashGet(pTtlMgr->pTtlCache, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid));
if (oldData == NULL) {
@ -342,43 +340,39 @@ int ttlMgrUpdateChangeTime(STtlManger *pTtlMgr, const STtlUpdCtimeCtx *pUpdCtime
.changeTimeMsDirty = pUpdCtimeCtx->changeTimeMs};
STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_UPSERT};
ret = taosHashPut(pTtlMgr->pTtlCache, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid), &cacheEntry, sizeof(cacheEntry));
if (ret < 0) {
metaError("%s, ttlMgr update ctime failed to update cache since %s", pTtlMgr->logPrefix, tstrerror(terrno));
code = taosHashPut(pTtlMgr->pTtlCache, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid), &cacheEntry, sizeof(cacheEntry));
if (TSDB_CODE_SUCCESS != code) {
metaError("%s, ttlMgr update ctime failed to update cache since %s", pTtlMgr->logPrefix, tstrerror(code));
goto _out;
}
ret = taosHashPut(pTtlMgr->pDirtyUids, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid), &dirtryEntry,
sizeof(dirtryEntry));
if (ret < 0) {
code = taosHashPut(pTtlMgr->pDirtyUids, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid), &dirtryEntry,
sizeof(dirtryEntry));
if (TSDB_CODE_SUCCESS != code) {
metaError("%s, ttlMgr update ctime failed to update dirty uids since %s", pTtlMgr->logPrefix,
tstrerror(terrno));
tstrerror(code));
goto _out;
}
if (ttlMgrNeedFlush(pTtlMgr)) {
ttlMgrFlush(pTtlMgr, pUpdCtimeCtx->pTxn);
(void)ttlMgrFlush(pTtlMgr, pUpdCtimeCtx->pTxn);
}
ret = 0;
code = TSDB_CODE_SUCCESS;
_out:
metaTrace("%s, ttl mgr update ctime, uid: %" PRId64 ", ctime: %" PRId64, pTtlMgr->logPrefix, pUpdCtimeCtx->uid,
pUpdCtimeCtx->changeTimeMs);
return ret;
TAOS_RETURN(code);
}
int ttlMgrFindExpired(STtlManger *pTtlMgr, int64_t timePointMs, SArray *pTbUids, int32_t ttlDropMaxCount) {
int ret = -1;
int32_t ttlMgrFindExpired(STtlManger *pTtlMgr, int64_t timePointMs, SArray *pTbUids, int32_t ttlDropMaxCount) {
int32_t code = TSDB_CODE_SUCCESS;
STtlIdxKeyV1 ttlKey = {.deleteTimeMs = timePointMs, .uid = INT64_MAX};
STtlExpiredCtx expiredCtx = {
.ttlDropMaxCount = ttlDropMaxCount, .count = 0, .expiredKey = ttlKey, .pTbUids = pTbUids};
ret = tdbTbTraversal(pTtlMgr->pTtlIdx, &expiredCtx, ttlMgrFindExpiredOneEntry);
if (ret) {
goto _out;
}
TAOS_CHECK_GOTO(tdbTbTraversal(pTtlMgr->pTtlIdx, &expiredCtx, ttlMgrFindExpiredOneEntry), NULL, _out);
size_t vIdx = 0;
for (size_t i = 0; i < pTbUids->size; i++) {
@ -393,20 +387,20 @@ int ttlMgrFindExpired(STtlManger *pTtlMgr, int64_t timePointMs, SArray *pTbUids,
taosArrayPopTailBatch(pTbUids, pTbUids->size - vIdx);
_out:
return ret;
TAOS_RETURN(code);
}
static bool ttlMgrNeedFlush(STtlManger *pTtlMgr) {
return pTtlMgr->flushThreshold > 0 && taosHashGetSize(pTtlMgr->pDirtyUids) > pTtlMgr->flushThreshold;
}
int ttlMgrFlush(STtlManger *pTtlMgr, TXN *pTxn) {
int32_t ttlMgrFlush(STtlManger *pTtlMgr, TXN *pTxn) {
int64_t startNs = taosGetTimestampNs();
int64_t endNs = startNs;
metaTrace("%s, ttl mgr flush start. dirty uids:%d", pTtlMgr->logPrefix, taosHashGetSize(pTtlMgr->pDirtyUids));
int ret = -1;
int32_t code = TSDB_CODE_SUCCESS;
void *pIter = taosHashIterate(pTtlMgr->pDirtyUids, NULL);
while (pIter != NULL) {
@ -415,8 +409,8 @@ int ttlMgrFlush(STtlManger *pTtlMgr, TXN *pTxn) {
STtlCacheEntry *cacheEntry = taosHashGet(pTtlMgr->pTtlCache, pUid, sizeof(*pUid));
if (cacheEntry == NULL) {
metaError("%s, ttlMgr flush failed to get ttl cache since %s, uid: %" PRId64 ", type: %d", pTtlMgr->logPrefix,
tstrerror(terrno), *pUid, pEntry->type);
metaError("%s, ttlMgr flush failed to get ttl cache, uid: %" PRId64 ", type: %d", pTtlMgr->logPrefix, *pUid,
pEntry->type);
continue;
}
@ -428,26 +422,26 @@ int ttlMgrFlush(STtlManger *pTtlMgr, TXN *pTxn) {
if (pEntry->type == ENTRY_TYPE_UPSERT) {
// delete old key & upsert new key
tdbTbDelete(pTtlMgr->pTtlIdx, &ttlKey, sizeof(ttlKey), pTxn); // maybe first insert, ignore error
ret = tdbTbUpsert(pTtlMgr->pTtlIdx, &ttlKeyDirty, sizeof(ttlKeyDirty), &cacheEntry->ttlDaysDirty,
(void)tdbTbDelete(pTtlMgr->pTtlIdx, &ttlKey, sizeof(ttlKey), pTxn); // maybe first insert, ignore error
code = tdbTbUpsert(pTtlMgr->pTtlIdx, &ttlKeyDirty, sizeof(ttlKeyDirty), &cacheEntry->ttlDaysDirty,
sizeof(cacheEntry->ttlDaysDirty), pTxn);
if (ret < 0) {
metaError("%s, ttlMgr flush failed to upsert since %s", pTtlMgr->logPrefix, tstrerror(terrno));
if (TSDB_CODE_SUCCESS != code) {
metaError("%s, ttlMgr flush failed to upsert since %s", pTtlMgr->logPrefix, tstrerror(code));
goto _out;
}
cacheEntry->ttlDays = cacheEntry->ttlDaysDirty;
cacheEntry->changeTimeMs = cacheEntry->changeTimeMsDirty;
} else if (pEntry->type == ENTRY_TYPE_DELETE) {
ret = tdbTbDelete(pTtlMgr->pTtlIdx, &ttlKey, sizeof(ttlKey), pTxn);
if (ret < 0) {
metaError("%s, ttlMgr flush failed to delete since %s", pTtlMgr->logPrefix, tstrerror(terrno));
code = tdbTbDelete(pTtlMgr->pTtlIdx, &ttlKey, sizeof(ttlKey), pTxn);
if (TSDB_CODE_SUCCESS != code) {
metaError("%s, ttlMgr flush failed to delete since %s", pTtlMgr->logPrefix, tstrerror(code));
goto _out;
}
ret = taosHashRemove(pTtlMgr->pTtlCache, pUid, sizeof(*pUid));
if (ret < 0) {
metaError("%s, ttlMgr flush failed to remove cache since %s", pTtlMgr->logPrefix, tstrerror(terrno));
code = taosHashRemove(pTtlMgr->pTtlCache, pUid, sizeof(*pUid));
if (TSDB_CODE_SUCCESS != code) {
metaError("%s, ttlMgr flush failed to remove cache since %s", pTtlMgr->logPrefix, tstrerror(code));
goto _out;
}
} else {
@ -457,16 +451,16 @@ int ttlMgrFlush(STtlManger *pTtlMgr, TXN *pTxn) {
void *pIterTmp = pIter;
pIter = taosHashIterate(pTtlMgr->pDirtyUids, pIterTmp);
taosHashRemove(pTtlMgr->pDirtyUids, pUid, sizeof(tb_uid_t));
(void)taosHashRemove(pTtlMgr->pDirtyUids, pUid, sizeof(tb_uid_t));
}
taosHashClear(pTtlMgr->pDirtyUids);
ret = 0;
code = TSDB_CODE_SUCCESS;
_out:
endNs = taosGetTimestampNs();
metaTrace("%s, ttl mgr flush end, time consumed: %" PRId64 " ns", pTtlMgr->logPrefix, endNs - startNs);
return ret;
TAOS_RETURN(code);
}

View File

@ -60,35 +60,41 @@ static bool tqOffsetEqual(const STqOffset* pLeft, const STqOffset* pRight) {
pLeft->val.version == pRight->val.version;
}
STQ* tqOpen(const char* path, SVnode* pVnode) {
int32_t tqOpen(const char* path, SVnode* pVnode) {
STQ* pTq = taosMemoryCalloc(1, sizeof(STQ));
if (pTq == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
return TSDB_CODE_OUT_OF_MEMORY;
}
pVnode->pTq = pTq;
pTq->path = taosStrdup(path);
pTq->pVnode = pVnode;
pTq->pHandle = taosHashInit(64, MurmurHash3_32, true, HASH_ENTRY_LOCK);
if (pTq->pHandle == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
taosHashSetFreeFp(pTq->pHandle, tqDestroyTqHandle);
taosInitRWLatch(&pTq->lock);
pTq->pPushMgr = taosHashInit(64, MurmurHash3_32, false, HASH_NO_LOCK);
if (pTq->pPushMgr == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
pTq->pCheckInfo = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
if (pTq->pCheckInfo == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
taosHashSetFreeFp(pTq->pCheckInfo, (FDelete)tDeleteSTqCheckInfo);
pTq->pOffset = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_ENTRY_LOCK);
if (pTq->pOffset == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
taosHashSetFreeFp(pTq->pOffset, (FDelete)tDeleteSTqOffset);
int32_t code = tqInitialize(pTq);
if (code != TSDB_CODE_SUCCESS) {
tqClose(pTq);
return NULL;
} else {
return pTq;
}
return tqInitialize(pTq);
}
int32_t tqInitialize(STQ* pTq) {
@ -102,11 +108,7 @@ int32_t tqInitialize(STQ* pTq) {
streamMetaLoadAllTasks(pTq->pStreamMeta);
if (tqMetaOpen(pTq) < 0) {
return -1;
}
return 0;
return tqMetaOpen(pTq);
}
void tqClose(STQ* pTq) {
@ -150,25 +152,32 @@ void tqNotifyClose(STQ* pTq) {
streamMetaNotifyClose(pTq->pStreamMeta);
}
int32_t tqPushEmptyDataRsp(STqHandle* pHandle, int32_t vgId) {
void tqPushEmptyDataRsp(STqHandle* pHandle, int32_t vgId) {
int32_t code = 0;
SMqPollReq req = {0};
if (tDeserializeSMqPollReq(pHandle->msg->pCont, pHandle->msg->contLen, &req) < 0) {
tqError("tDeserializeSMqPollReq %d failed", pHandle->msg->contLen);
terrno = TSDB_CODE_INVALID_MSG;
return -1;
code = tDeserializeSMqPollReq(pHandle->msg->pCont, pHandle->msg->contLen, &req);
if (code < 0) {
tqError("tDeserializeSMqPollReq %d failed, code:%d", pHandle->msg->contLen, code);
return;
}
SMqDataRsp dataRsp = {0};
tqInitDataRsp(&dataRsp.common, req.reqOffset);
code = tqInitDataRsp(&dataRsp.common, req.reqOffset);
if (code != 0) {
tqError("tqInitDataRsp failed, code:%d", code);
return;
}
dataRsp.common.blockNum = 0;
char buf[TSDB_OFFSET_LEN] = {0};
tFormatOffset(buf, TSDB_OFFSET_LEN, &dataRsp.common.reqOffset);
tqInfo("tqPushEmptyDataRsp to consumer:0x%" PRIx64 " vgId:%d, offset:%s, reqId:0x%" PRIx64, req.consumerId, vgId, buf,
req.reqId);
tqSendDataRsp(pHandle, pHandle->msg, &req, &dataRsp, TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
code = tqSendDataRsp(pHandle, pHandle->msg, &req, &dataRsp, TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
if (code != 0) {
tqError("tqSendDataRsp failed, code:%d", code);
}
tDeleteMqDataRsp(&dataRsp);
return 0;
}
int32_t tqSendDataRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq* pReq, const void* pRsp,
@ -176,8 +185,6 @@ int32_t tqSendDataRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq*
int64_t sver = 0, ever = 0;
walReaderValidVersionRange(pHandle->execHandle.pTqReader->pWalReader, &sver, &ever);
tqDoSendDataRsp(&pMsg->info, pRsp, pReq->epoch, pReq->consumerId, type, sver, ever);
char buf1[TSDB_OFFSET_LEN] = {0};
char buf2[TSDB_OFFSET_LEN] = {0};
tFormatOffset(buf1, TSDB_OFFSET_LEN, &((SMqDataRspCommon*)pRsp)->reqOffset);
@ -186,7 +193,7 @@ int32_t tqSendDataRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPollReq*
tqDebug("tmq poll vgId:%d consumer:0x%" PRIx64 " (epoch %d) send rsp, block num:%d, req:%s, rsp:%s, reqId:0x%" PRIx64,
vgId, pReq->consumerId, pReq->epoch, ((SMqDataRspCommon*)pRsp)->blockNum, buf1, buf2, pReq->reqId);
return 0;
return tqDoSendDataRsp(&pMsg->info, pRsp, pReq->epoch, pReq->consumerId, type, sver, ever);
}
int32_t tqProcessOffsetCommitReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
@ -217,8 +224,9 @@ int32_t tqProcessOffsetCommitReq(STQ* pTq, int64_t sversion, char* msg, int32_t
goto end;
}
STqOffset* pSavedOffset = (STqOffset*)tqMetaGetOffset(pTq, pOffset->subKey);
if (pSavedOffset != NULL && tqOffsetEqual(pOffset, pSavedOffset)) {
STqOffset* pSavedOffset = NULL;
code = tqMetaGetOffset(pTq, pOffset->subKey, &pSavedOffset);
if (code == 0 && tqOffsetEqual(pOffset, pSavedOffset)) {
tqInfo("not update the offset, vgId:%d sub:%s since committed:%" PRId64 " less than/equal to existed:%" PRId64,
vgId, pOffset->subKey, pOffset->val.version, pSavedOffset->val.version);
goto end; // no need to update the offset value
@ -328,7 +336,7 @@ int32_t tqProcessPollPush(STQ* pTq, SRpcMsg* pMsg) {
.pCont = pHandle->msg->pCont,
.contLen = pHandle->msg->contLen,
.info = pHandle->msg->info};
tmsgPutToQueue(&pTq->pVnode->msgCb, QUERY_QUEUE, &msg);
(void)tmsgPutToQueue(&pTq->pVnode->msgCb, QUERY_QUEUE, &msg);
taosMemoryFree(pHandle->msg);
pHandle->msg = NULL;
}
@ -434,18 +442,16 @@ int32_t tqProcessVgCommittedInfoReq(STQ* pTq, SRpcMsg* pMsg) {
tDecoderClear(&decoder);
STqOffset* pSavedOffset = (STqOffset*)tqMetaGetOffset(pTq, vgOffset.offset.subKey);
if (pSavedOffset == NULL) {
terrno = TSDB_CODE_TMQ_NO_COMMITTED;
return terrno;
STqOffset* pSavedOffset = NULL;
int32_t code = tqMetaGetOffset(pTq, vgOffset.offset.subKey, &pSavedOffset);
if (code != 0) {
return TSDB_CODE_TMQ_NO_COMMITTED;
}
vgOffset.offset = *pSavedOffset;
int32_t code = 0;
tEncodeSize(tEncodeMqVgOffset, &vgOffset, len, code);
if (code < 0) {
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
return TAOS_GET_TERRNO(TSDB_CODE_INVALID_PARA);
}
void* buf = rpcMallocCont(len);
@ -455,8 +461,12 @@ int32_t tqProcessVgCommittedInfoReq(STQ* pTq, SRpcMsg* pMsg) {
}
SEncoder encoder;
tEncoderInit(&encoder, buf, len);
tEncodeMqVgOffset(&encoder, &vgOffset);
code = tEncodeMqVgOffset(&encoder, &vgOffset);
tEncoderClear(&encoder);
if (code < 0) {
rpcFreeCont(buf);
return TAOS_GET_TERRNO(TSDB_CODE_INVALID_PARA);
}
SRpcMsg rsp = {.info = pMsg->info, .pCont = buf, .contLen = len, .code = 0};
@ -465,11 +475,11 @@ int32_t tqProcessVgCommittedInfoReq(STQ* pTq, SRpcMsg* pMsg) {
}
int32_t tqProcessVgWalInfoReq(STQ* pTq, SRpcMsg* pMsg) {
int32_t code = 0;
SMqPollReq req = {0};
if (tDeserializeSMqPollReq(pMsg->pCont, pMsg->contLen, &req) < 0) {
tqError("tDeserializeSMqPollReq %d failed", pMsg->contLen);
terrno = TSDB_CODE_INVALID_MSG;
return -1;
return TSDB_CODE_INVALID_MSG;
}
int64_t consumerId = req.consumerId;
@ -481,18 +491,17 @@ int32_t tqProcessVgWalInfoReq(STQ* pTq, SRpcMsg* pMsg) {
STqHandle* pHandle = taosHashGet(pTq->pHandle, req.subKey, strlen(req.subKey));
if (pHandle == NULL) {
tqError("consumer:0x%" PRIx64 " vgId:%d subkey:%s not found", consumerId, vgId, req.subKey);
terrno = TSDB_CODE_INVALID_MSG;
taosRUnLockLatch(&pTq->lock);
return -1;
return TSDB_CODE_INVALID_MSG;
}
// 2. check rebalance status
if (pHandle->consumerId != consumerId) {
tqDebug("ERROR consumer:0x%" PRIx64 " vgId:%d, subkey %s, mismatch for saved handle consumer:0x%" PRIx64,
consumerId, vgId, req.subKey, pHandle->consumerId);
terrno = TSDB_CODE_TMQ_CONSUMER_MISMATCH;
taosRUnLockLatch(&pTq->lock);
return -1;
return TSDB_CODE_TMQ_CONSUMER_MISMATCH;
}
int64_t sver = 0, ever = 0;
@ -500,13 +509,15 @@ int32_t tqProcessVgWalInfoReq(STQ* pTq, SRpcMsg* pMsg) {
taosRUnLockLatch(&pTq->lock);
SMqDataRsp dataRsp = {0};
tqInitDataRsp(&dataRsp.common, req.reqOffset);
code = tqInitDataRsp(&dataRsp.common, req.reqOffset);
if (code != 0) {
return code;
}
if (req.useSnapshot == true) {
tqError("consumer:0x%" PRIx64 " vgId:%d subkey:%s snapshot not support wal info", consumerId, vgId, req.subKey);
terrno = TSDB_CODE_INVALID_PARA;
tDeleteMqDataRsp(&dataRsp);
return -1;
code = TSDB_CODE_INVALID_PARA;
goto END;
}
dataRsp.common.rspOffset.type = TMQ_OFFSET__LOG;
@ -514,13 +525,13 @@ int32_t tqProcessVgWalInfoReq(STQ* pTq, SRpcMsg* pMsg) {
if (reqOffset.type == TMQ_OFFSET__LOG) {
dataRsp.common.rspOffset.version = reqOffset.version;
} else if (reqOffset.type < 0) {
STqOffset* pOffset = (STqOffset*)(STqOffset*)tqMetaGetOffset(pTq, req.subKey);
if (pOffset != NULL) {
STqOffset* pOffset = NULL;
code = tqMetaGetOffset(pTq, req.subKey, &pOffset);
if (code == 0) {
if (pOffset->val.type != TMQ_OFFSET__LOG) {
tqError("consumer:0x%" PRIx64 " vgId:%d subkey:%s, no valid wal info", consumerId, vgId, req.subKey);
terrno = TSDB_CODE_INVALID_PARA;
tDeleteMqDataRsp(&dataRsp);
return -1;
code = TSDB_CODE_INVALID_PARA;
goto END;
}
dataRsp.common.rspOffset.version = pOffset->val.version;
@ -538,14 +549,15 @@ int32_t tqProcessVgWalInfoReq(STQ* pTq, SRpcMsg* pMsg) {
} else {
tqError("consumer:0x%" PRIx64 " vgId:%d subkey:%s invalid offset type:%d", consumerId, vgId, req.subKey,
reqOffset.type);
terrno = TSDB_CODE_INVALID_PARA;
tDeleteMqDataRsp(&dataRsp);
return -1;
code = TSDB_CODE_INVALID_PARA;
goto END;
}
tqDoSendDataRsp(&pMsg->info, &dataRsp, req.epoch, req.consumerId, TMQ_MSG_TYPE__WALINFO_RSP, sver, ever);
code = tqDoSendDataRsp(&pMsg->info, &dataRsp, req.epoch, req.consumerId, TMQ_MSG_TYPE__WALINFO_RSP, sver, ever);
END:
tDeleteMqDataRsp(&dataRsp);
return 0;
return code;
}
int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
@ -568,9 +580,7 @@ int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
taosMsleep(10);
continue;
}
tqUnregisterPushHandle(pTq, pHandle);
code = taosHashRemove(pTq->pHandle, pReq->subKey, strlen(pReq->subKey));
if (code != 0) {
tqError("cannot process tq delete req %s, since no such handle", pReq->subKey);
@ -598,33 +608,25 @@ int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
int32_t tqProcessAddCheckInfoReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
STqCheckInfo info = {0};
if(tqMetaDecodeCheckInfo(&info, msg, msgLen) != 0){
return -1;
int32_t code = tqMetaDecodeCheckInfo(&info, msg, msgLen);
if(code != 0){
return code;
}
if (taosHashPut(pTq->pCheckInfo, info.topic, strlen(info.topic), &info, sizeof(STqCheckInfo)) < 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
code = taosHashPut(pTq->pCheckInfo, info.topic, strlen(info.topic), &info, sizeof(STqCheckInfo));
if (code != 0) {
tDeleteSTqCheckInfo(&info);
return -1;
return code;
}
if (tqMetaSaveInfo(pTq, pTq->pCheckStore, info.topic, strlen(info.topic), msg, msgLen) < 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
return 0;
return tqMetaSaveInfo(pTq, pTq->pCheckStore, info.topic, strlen(info.topic), msg, msgLen);
}
int32_t tqProcessDelCheckInfoReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
if (taosHashRemove(pTq->pCheckInfo, msg, strlen(msg)) < 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
return TSDB_CODE_TSC_INTERNAL_ERROR;
}
if (tqMetaDeleteInfo(pTq, pTq->pCheckStore, msg, strlen(msg)) < 0) {
tqError("cannot process tq delete check info req %s, since no such check info", msg);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
return 0;
return tqMetaDeleteInfo(pTq, pTq->pCheckStore, msg, strlen(msg));
}
int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
@ -633,12 +635,10 @@ int32_t tqProcessSubscribeReq(STQ* pTq, int64_t sversion, char* msg, int32_t msg
SDecoder dc = {0};
tDecoderInit(&dc, (uint8_t*)msg, msgLen);
ret = tDecodeSMqRebVgReq(&dc, &req);
// decode req
if (tDecodeSMqRebVgReq(&dc, &req) < 0) {
terrno = TSDB_CODE_INVALID_MSG;
tDecoderClear(&dc);
return -1;
if (ret < 0) {
goto end;
}
tqInfo("vgId:%d, tq process sub req:%s, Id:0x%" PRIx64 " -> Id:0x%" PRIx64, pTq->pVnode->config.vgId, req.subKey,
@ -777,18 +777,14 @@ int32_t tqBuildStreamTask(void* pTqObj, SStreamTask* pTask, int64_t nextProcessV
return 0;
}
int32_t tqProcessTaskCheckReq(STQ* pTq, SRpcMsg* pMsg) { return tqStreamTaskProcessCheckReq(pTq->pStreamMeta, pMsg); }
int32_t tqProcessTaskCheckReq(STQ* pTq, SRpcMsg* pMsg) {
return tqStreamTaskProcessCheckReq(pTq->pStreamMeta, pMsg); }
int32_t tqProcessTaskCheckRsp(STQ* pTq, SRpcMsg* pMsg) {
return tqStreamTaskProcessCheckRsp(pTq->pStreamMeta, pMsg, vnodeIsRoleLeader(pTq->pVnode));
}
int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t sversion, char* msg, int32_t msgLen) {
// if (!pTq->pVnode->restored) {
// tqDebug("vgId:%d not restored, ignore the stream task deploy msg", TD_VID(pTq->pVnode));
// return TSDB_CODE_SUCCESS;
// }
return tqStreamTaskProcessDeployReq(pTq->pStreamMeta, &pTq->pVnode->msgCb, sversion, msg, msgLen,
vnodeIsRoleLeader(pTq->pVnode), pTq->pVnode->restored);
}

View File

@ -58,12 +58,13 @@ int32_t tDecodeSTqHandle(SDecoder* pDecoder, STqHandle* pHandle) {
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
pHandle->execHandle.execDb.pFilterOutTbUid =
taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
if (pHandle->execHandle.execDb.pFilterOutTbUid == NULL) return -1;
int32_t size = 0;
if (tDecodeI32(pDecoder, &size) < 0) return -1;
for (int32_t i = 0; i < size; i++) {
int64_t tbUid = 0;
if (tDecodeI64(pDecoder, &tbUid) < 0) return -1;
taosHashPut(pHandle->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0);
if (taosHashPut(pHandle->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0) != 0) return -1;
}
} else if (pHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
if (tDecodeI64(pDecoder, &pHandle->execHandle.execTb.suid) < 0) return -1;
@ -79,11 +80,12 @@ int32_t tqMetaDecodeCheckInfo(STqCheckInfo* info, void* pVal, int32_t vLen) {
SDecoder decoder = {0};
tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
int32_t code = tDecodeSTqCheckInfo(&decoder, info);
tDecoderClear(&decoder);
if (code != 0) {
tDeleteSTqCheckInfo(info);
return TSDB_CODE_OUT_OF_MEMORY;
}
tDecoderClear(&decoder);
return code;
}
@ -91,11 +93,12 @@ int32_t tqMetaDecodeOffsetInfo(STqOffset* info, void* pVal, int32_t vLen) {
SDecoder decoder = {0};
tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
int32_t code = tDecodeSTqOffset(&decoder, info);
tDecoderClear(&decoder);
if (code != 0) {
tDeleteSTqOffset(info);
return TSDB_CODE_OUT_OF_MEMORY;
}
tDecoderClear(&decoder);
return code;
}
@ -131,32 +134,36 @@ END:
return code;
}
void* tqMetaGetOffset(STQ* pTq, const char* subkey) {
int32_t tqMetaGetOffset(STQ* pTq, const char* subkey, STqOffset** pOffset){
void* data = taosHashGet(pTq->pOffset, subkey, strlen(subkey));
if (data == NULL) {
int vLen = 0;
if (tdbTbGet(pTq->pOffsetStore, subkey, strlen(subkey), &data, &vLen) < 0) {
tdbFree(data);
return NULL;
return TSDB_CODE_OUT_OF_MEMORY;
}
STqOffset offset = {0};
if (tqMetaDecodeOffsetInfo(&offset, data, vLen) != TDB_CODE_SUCCESS) {
tdbFree(data);
return NULL;
return TSDB_CODE_OUT_OF_MEMORY;
}
if (taosHashPut(pTq->pOffset, subkey, strlen(subkey), &offset, sizeof(STqOffset)) != 0) {
tDeleteSTqOffset(&offset);
tdbFree(data);
return NULL;
return TSDB_CODE_OUT_OF_MEMORY;
}
tdbFree(data);
return taosHashGet(pTq->pOffset, subkey, strlen(subkey));
*pOffset = taosHashGet(pTq->pOffset, subkey, strlen(subkey));
if(*pOffset == NULL){
return TSDB_CODE_OUT_OF_MEMORY;
}
} else {
return data;
*pOffset = data;
}
return 0;
}
int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle) {
@ -199,10 +206,9 @@ static int tqMetaInitHandle(STQ* pTq, STqHandle* handle) {
int32_t vgId = TD_VID(pVnode);
handle->pRef = walOpenRef(pVnode->pWal);
if (handle->pRef == NULL) {
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
TQ_ERR_RETURN(walSetRefVer(handle->pRef, handle->snapshotVer));
TQ_NULL_GO_TO_END(handle->pRef);
TQ_ERR_GO_TO_END(walSetRefVer(handle->pRef, handle->snapshotVer));
SReadHandle reader = {
.vnode = pVnode,
@ -214,43 +220,36 @@ static int tqMetaInitHandle(STQ* pTq, STqHandle* handle) {
initStorageAPI(&reader.api);
if (handle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) {
handle->execHandle.task = qCreateQueueExecTaskInfo(handle->execHandle.execCol.qmsg, &reader, vgId,
&handle->execHandle.numOfCols, handle->consumerId);
if (handle->execHandle.task == NULL) {
tqError("cannot create exec task for %s", handle->subKey);
return TSDB_CODE_OUT_OF_MEMORY;
}
handle->execHandle.task =
qCreateQueueExecTaskInfo(handle->execHandle.execCol.qmsg, &reader, vgId, &handle->execHandle.numOfCols, handle->consumerId);
TQ_NULL_GO_TO_END(handle->execHandle.task);
void* scanner = NULL;
(void)qExtractStreamScanner(handle->execHandle.task, &scanner);
if (scanner == NULL) {
tqError("cannot extract stream scanner for %s", handle->subKey);
return TSDB_CODE_SCH_INTERNAL_ERROR;
}
qExtractStreamScanner(handle->execHandle.task, &scanner);
TQ_NULL_GO_TO_END(scanner);
handle->execHandle.pTqReader = qExtractReaderFromStreamScanner(scanner);
if (handle->execHandle.pTqReader == NULL) {
tqError("cannot extract exec reader for %s", handle->subKey);
return TSDB_CODE_SCH_INTERNAL_ERROR;
}
TQ_NULL_GO_TO_END(handle->execHandle.pTqReader);
} else if (handle->execHandle.subType == TOPIC_SUB_TYPE__DB) {
handle->pWalReader = walOpenReader(pVnode->pWal, NULL, 0);
TQ_NULL_GO_TO_END(handle->pWalReader);
handle->execHandle.pTqReader = tqReaderOpen(pVnode);
buildSnapContext(reader.vnode, reader.version, 0, handle->execHandle.subType, handle->fetchMeta,
(SSnapContext**)(&reader.sContext));
TQ_NULL_GO_TO_END(handle->execHandle.pTqReader);
TQ_ERR_GO_TO_END(buildSnapContext(reader.vnode, reader.version, 0, handle->execHandle.subType, handle->fetchMeta,
(SSnapContext**)(&reader.sContext)));
handle->execHandle.task = qCreateQueueExecTaskInfo(NULL, &reader, vgId, NULL, handle->consumerId);
TQ_NULL_GO_TO_END(handle->execHandle.task);
} else if (handle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {
handle->pWalReader = walOpenReader(pVnode->pWal, NULL, 0);
if (handle->execHandle.execTb.qmsg != NULL && strcmp(handle->execHandle.execTb.qmsg, "") != 0) {
TQ_NULL_GO_TO_END(handle->pWalReader);
if(handle->execHandle.execTb.qmsg != NULL && strcmp(handle->execHandle.execTb.qmsg, "") != 0) {
if (nodesStringToNode(handle->execHandle.execTb.qmsg, &handle->execHandle.execTb.node) != 0) {
tqError("nodesStringToNode error in sub stable, since %s", terrstr());
return TSDB_CODE_SCH_INTERNAL_ERROR;
}
}
buildSnapContext(reader.vnode, reader.version, handle->execHandle.execTb.suid, handle->execHandle.subType,
handle->fetchMeta, (SSnapContext**)(&reader.sContext));
TQ_ERR_GO_TO_END(buildSnapContext(reader.vnode, reader.version, handle->execHandle.execTb.suid, handle->execHandle.subType,
handle->fetchMeta, (SSnapContext**)(&reader.sContext)));
handle->execHandle.task = qCreateQueueExecTaskInfo(NULL, &reader, vgId, NULL, handle->consumerId);
TQ_NULL_GO_TO_END(handle->execHandle.task);
SArray* tbUidList = NULL;
int ret = qGetTableList(handle->execHandle.execTb.suid, pVnode, handle->execHandle.execTb.node, &tbUidList,
handle->execHandle.task);
@ -262,10 +261,13 @@ static int tqMetaInitHandle(STQ* pTq, STqHandle* handle) {
tqInfo("vgId:%d, tq try to get ctb for stb subscribe, suid:%" PRId64, pVnode->config.vgId,
handle->execHandle.execTb.suid);
handle->execHandle.pTqReader = tqReaderOpen(pVnode);
TQ_NULL_GO_TO_END(handle->execHandle.pTqReader);
tqReaderSetTbUidList(handle->execHandle.pTqReader, tbUidList, NULL);
taosArrayDestroy(tbUidList);
}
return 0;
END:
return code;
}
static int32_t tqMetaRestoreHandle(STQ* pTq, void* pVal, int vLen, STqHandle* handle) {
@ -287,7 +289,7 @@ END:
int32_t tqMetaCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle) {
int32_t vgId = TD_VID(pTq->pVnode);
memcpy(handle->subKey, req->subKey, TSDB_SUBSCRIBE_KEY_LEN);
(void)memcpy(handle->subKey, req->subKey, TSDB_SUBSCRIBE_KEY_LEN);
handle->consumerId = req->newConsumerId;
handle->execHandle.subType = req->subType;
@ -297,15 +299,19 @@ int32_t tqMetaCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle) {
} else if (req->subType == TOPIC_SUB_TYPE__DB) {
handle->execHandle.execDb.pFilterOutTbUid =
taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
} else if (req->subType == TOPIC_SUB_TYPE__TABLE) {
if(handle->execHandle.execDb.pFilterOutTbUid == NULL){
return TSDB_CODE_OUT_OF_MEMORY;
}
}else if(req->subType == TOPIC_SUB_TYPE__TABLE){
handle->execHandle.execTb.suid = req->suid;
handle->execHandle.execTb.qmsg = taosStrdup(req->qmsg);
}
handle->snapshotVer = walGetCommittedVer(pTq->pVnode->pWal);
if (tqMetaInitHandle(pTq, handle) < 0) {
return -1;
int32_t code = tqMetaInitHandle(pTq, handle);
if (code != 0){
return code;
}
tqInfo("tqMetaCreateHandle %s consumer 0x%" PRIx64 " vgId:%d, snapshotVer:%" PRId64, handle->subKey,
handle->consumerId, vgId, handle->snapshotVer);
@ -377,10 +383,12 @@ END:
return code;
}
static int32_t replaceTqPath(char** path) {
char* tpath = NULL;
int32_t code = TDB_CODE_SUCCESS;
TQ_ERR_RETURN(tqBuildFName(&tpath, *path, TQ_SUBSCRIBE_NAME));
static int32_t replaceTqPath(char** path){
char* tpath = NULL;
int32_t code = tqBuildFName(&tpath, *path, TQ_SUBSCRIBE_NAME);
if (code != 0){
return code;
}
taosMemoryFree(*path);
*path = tpath;
return TDB_CODE_SUCCESS;
@ -407,7 +415,7 @@ static int32_t tqMetaRestoreCheckInfo(STQ* pTq) {
END:
tdbFree(pKey);
tdbFree(pVal);
tdbTbcClose(pCur);
(void)tdbTbcClose(pCur);
tDeleteSTqCheckInfo(&info);
return code;
}
@ -480,7 +488,7 @@ END:
return code;
}
int32_t tqMetaClose(STQ* pTq) {
void tqMetaClose(STQ* pTq) {
if (pTq->pExecStore) {
(void)tdbTbClose(pTq->pExecStore);
}
@ -491,5 +499,4 @@ int32_t tqMetaClose(STQ* pTq) {
(void)tdbTbClose(pTq->pOffsetStore);
}
(void)tdbClose(pTq->pMetaDB);
return 0;
}

View File

@ -22,17 +22,28 @@ int32_t tqProcessSubmitReqForSubscribe(STQ* pTq) {
}
SRpcMsg msg = {.msgType = TDMT_VND_TMQ_CONSUME_PUSH};
msg.pCont = rpcMallocCont(sizeof(SMsgHead));
if (msg.pCont == NULL) {
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
msg.contLen = sizeof(SMsgHead);
SMsgHead *pHead = msg.pCont;
pHead->vgId = TD_VID(pTq->pVnode);
pHead->contLen = msg.contLen;
tmsgPutToQueue(&pTq->pVnode->msgCb, QUERY_QUEUE, &msg);
return 0;
int32_t code = tmsgPutToQueue(&pTq->pVnode->msgCb, QUERY_QUEUE, &msg);
if (code != 0){
tqError("vgId:%d failed to push msg to queue, code:%d", TD_VID(pTq->pVnode), code);
rpcFreeCont(msg.pCont);
}
return code;
}
int32_t tqPushMsg(STQ* pTq, tmsg_t msgType) {
int32_t code = 0;
if (msgType == TDMT_VND_SUBMIT) {
tqProcessSubmitReqForSubscribe(pTq);
code = tqProcessSubmitReqForSubscribe(pTq);
if (code != 0){
tqError("vgId:%d failed to process submit request for subscribe, code:%d", TD_VID(pTq->pVnode), code);
}
}
streamMetaRLock(pTq->pStreamMeta);
@ -46,10 +57,10 @@ int32_t tqPushMsg(STQ* pTq, tmsg_t msgType) {
// 2. the vnode should be the leader.
// 3. the stream is not suspended yet.
if ((!tsDisableStream) && (numOfTasks > 0)) {
tqScanWalAsync(pTq, true);
code = tqScanWalAsync(pTq, true);
}
return 0;
return code;
}
int32_t tqRegisterPushHandle(STQ* pTq, void* handle, SRpcMsg* pMsg) {
@ -58,43 +69,52 @@ int32_t tqRegisterPushHandle(STQ* pTq, void* handle, SRpcMsg* pMsg) {
if (pHandle->msg == NULL) {
pHandle->msg = taosMemoryCalloc(1, sizeof(SRpcMsg));
memcpy(pHandle->msg, pMsg, sizeof(SRpcMsg));
if (pHandle->msg == NULL) {
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
(void)memcpy(pHandle->msg, pMsg, sizeof(SRpcMsg));
pHandle->msg->pCont = rpcMallocCont(pMsg->contLen);
if (pHandle->msg->pCont == NULL) {
taosMemoryFree(pHandle->msg);
pHandle->msg = NULL;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
} else {
// tqPushDataRsp(pHandle, vgId);
tqPushEmptyDataRsp(pHandle, vgId);
void* tmp = pHandle->msg->pCont;
memcpy(pHandle->msg, pMsg, sizeof(SRpcMsg));
(void)memcpy(pHandle->msg, pMsg, sizeof(SRpcMsg));
pHandle->msg->pCont = tmp;
}
memcpy(pHandle->msg->pCont, pMsg->pCont, pMsg->contLen);
(void)memcpy(pHandle->msg->pCont, pMsg->pCont, pMsg->contLen);
pHandle->msg->contLen = pMsg->contLen;
int32_t ret = taosHashPut(pTq->pPushMgr, pHandle->subKey, strlen(pHandle->subKey), &pHandle, POINTER_BYTES);
tqDebug("vgId:%d data is over, ret:%d, consumerId:0x%" PRIx64 ", register to pHandle:%p, pCont:%p, len:%d", vgId, ret,
pHandle->consumerId, pHandle, pHandle->msg->pCont, pHandle->msg->contLen);
return 0;
if (ret != 0) {
rpcFreeCont(pHandle->msg->pCont);
taosMemoryFree(pHandle->msg);
pHandle->msg = NULL;
}
return ret;
}
int tqUnregisterPushHandle(STQ* pTq, void *handle) {
void tqUnregisterPushHandle(STQ* pTq, void *handle) {
STqHandle *pHandle = (STqHandle*)handle;
int32_t vgId = TD_VID(pTq->pVnode);
if(taosHashGetSize(pTq->pPushMgr) <= 0) {
return 0;
return;
}
int32_t ret = taosHashRemove(pTq->pPushMgr, pHandle->subKey, strlen(pHandle->subKey));
tqInfo("vgId:%d remove pHandle:%p,ret:%d consumer Id:0x%" PRIx64, vgId, pHandle, ret, pHandle->consumerId);
if(ret == 0 && pHandle->msg != NULL) {
// tqPushDataRsp(pHandle, vgId);
tqPushEmptyDataRsp(pHandle, vgId);
rpcFreeCont(pHandle->msg->pCont);
taosMemoryFree(pHandle->msg);
pHandle->msg = NULL;
}
return 0;
}

View File

@ -27,26 +27,26 @@ bool isValValidForTable(STqHandle* pHandle, SWalCont* pHead) {
int64_t tbSuid = pHandle->execHandle.execTb.suid;
int64_t realTbSuid = 0;
SDecoder coder;
SDecoder dcoder = {0};
void* data = POINTER_SHIFT(body, sizeof(SMsgHead));
int32_t len = bodyLen - sizeof(SMsgHead);
tDecoderInit(&coder, data, len);
tDecoderInit(&dcoder, data, len);
if (msgType == TDMT_VND_CREATE_STB || msgType == TDMT_VND_ALTER_STB) {
SVCreateStbReq req = {0};
if (tDecodeSVCreateStbReq(&coder, &req) < 0) {
if (tDecodeSVCreateStbReq(&dcoder, &req) < 0) {
goto end;
}
realTbSuid = req.suid;
} else if (msgType == TDMT_VND_DROP_STB) {
SVDropStbReq req = {0};
if (tDecodeSVDropStbReq(&coder, &req) < 0) {
if (tDecodeSVDropStbReq(&dcoder, &req) < 0) {
goto end;
}
realTbSuid = req.suid;
} else if (msgType == TDMT_VND_CREATE_TABLE) {
SVCreateTbBatchReq req = {0};
if (tDecodeSVCreateTbBatchReq(&coder, &req) < 0) {
if (tDecodeSVCreateTbBatchReq(&dcoder, &req) < 0) {
goto end;
}
@ -66,34 +66,42 @@ bool isValValidForTable(STqHandle* pHandle, SWalCont* pHead) {
realTbSuid = tbSuid;
SVCreateTbBatchReq reqNew = {0};
reqNew.pArray = taosArrayInit(req.nReqs, sizeof(struct SVCreateTbReq));
if (reqNew.pArray == NULL) {
tDeleteSVCreateTbBatchReq(&req);
goto end;
}
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
pCreateReq = req.pReqs + iReq;
if (pCreateReq->type == TSDB_CHILD_TABLE && pCreateReq->ctb.suid == tbSuid) {
reqNew.nReqs++;
taosArrayPush(reqNew.pArray, pCreateReq);
if (taosArrayPush(reqNew.pArray, pCreateReq) == NULL){
taosArrayDestroy(reqNew.pArray);
tDeleteSVCreateTbBatchReq(&req);
goto end;
}
}
}
int tlen;
int tlen = 0;
int32_t ret = 0;
tEncodeSize(tEncodeSVCreateTbBatchReq, &reqNew, tlen, ret);
void* buf = taosMemoryMalloc(tlen);
if (NULL == buf) {
taosArrayDestroy(reqNew.pArray);
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
pCreateReq = req.pReqs + iReq;
taosMemoryFreeClear(pCreateReq->comment);
if (pCreateReq->type == TSDB_CHILD_TABLE) {
taosArrayDestroy(pCreateReq->ctb.tagName);
}
}
tDeleteSVCreateTbBatchReq(&req);
goto end;
}
SEncoder coderNew = {0};
tEncoderInit(&coderNew, buf, tlen - sizeof(SMsgHead));
tEncodeSVCreateTbBatchReq(&coderNew, &reqNew);
ret = tEncodeSVCreateTbBatchReq(&coderNew, &reqNew);
tEncoderClear(&coderNew);
memcpy(pHead->body + sizeof(SMsgHead), buf, tlen);
if (ret < 0) {
taosMemoryFree(buf);
taosArrayDestroy(reqNew.pArray);
tDeleteSVCreateTbBatchReq(&req);
goto end;
}
(void)memcpy(pHead->body + sizeof(SMsgHead), buf, tlen);
pHead->bodyLen = tlen + sizeof(SMsgHead);
taosMemoryFree(buf);
taosArrayDestroy(reqNew.pArray);
@ -103,7 +111,7 @@ bool isValValidForTable(STqHandle* pHandle, SWalCont* pHead) {
} else if (msgType == TDMT_VND_ALTER_TABLE) {
SVAlterTbReq req = {0};
if (tDecodeSVAlterTbReq(&coder, &req) < 0) {
if (tDecodeSVAlterTbReq(&dcoder, &req) < 0) {
goto end;
}
@ -119,7 +127,7 @@ bool isValValidForTable(STqHandle* pHandle, SWalCont* pHead) {
} else if (msgType == TDMT_VND_DROP_TABLE) {
SVDropTbBatchReq req = {0};
if (tDecodeSVDropTbBatchReq(&coder, &req) < 0) {
if (tDecodeSVDropTbBatchReq(&dcoder, &req) < 0) {
goto end;
}
@ -140,15 +148,21 @@ bool isValValidForTable(STqHandle* pHandle, SWalCont* pHead) {
realTbSuid = tbSuid;
SVDropTbBatchReq reqNew = {0};
reqNew.pArray = taosArrayInit(req.nReqs, sizeof(SVDropTbReq));
if (reqNew.pArray == NULL) {
goto end;
}
for (int32_t iReq = 0; iReq < req.nReqs; iReq++) {
pDropReq = req.pReqs + iReq;
if (pDropReq->suid == tbSuid) {
reqNew.nReqs++;
taosArrayPush(reqNew.pArray, pDropReq);
if (taosArrayPush(reqNew.pArray, pDropReq) == NULL){
taosArrayDestroy(reqNew.pArray);
goto end;
}
}
}
int tlen;
int tlen = 0;
int32_t ret = 0;
tEncodeSize(tEncodeSVDropTbBatchReq, &reqNew, tlen, ret);
void* buf = taosMemoryMalloc(tlen);
@ -158,23 +172,28 @@ bool isValValidForTable(STqHandle* pHandle, SWalCont* pHead) {
}
SEncoder coderNew = {0};
tEncoderInit(&coderNew, buf, tlen - sizeof(SMsgHead));
tEncodeSVDropTbBatchReq(&coderNew, &reqNew);
ret = tEncodeSVDropTbBatchReq(&coderNew, &reqNew);
tEncoderClear(&coderNew);
memcpy(pHead->body + sizeof(SMsgHead), buf, tlen);
if (ret != 0) {
taosMemoryFree(buf);
taosArrayDestroy(reqNew.pArray);
goto end;
}
(void)memcpy(pHead->body + sizeof(SMsgHead), buf, tlen);
pHead->bodyLen = tlen + sizeof(SMsgHead);
taosMemoryFree(buf);
taosArrayDestroy(reqNew.pArray);
}
} else if (msgType == TDMT_VND_DELETE) {
SDeleteRes req = {0};
if (tDecodeDeleteRes(&coder, &req) < 0) {
if (tDecodeDeleteRes(&dcoder, &req) < 0) {
goto end;
}
realTbSuid = req.suid;
}
end:
tDecoderClear(&coder);
tDecoderClear(&dcoder);
return tbSuid == realTbSuid;
}
@ -242,10 +261,10 @@ END:
bool tqGetTablePrimaryKey(STqReader* pReader) { return pReader->hasPrimaryKey; }
void tqSetTablePrimaryKey(STqReader* pReader, int64_t uid) {
bool ret = false;
SSchemaWrapper* schema = metaGetTableSchema(pReader->pVnodeMeta, uid, -1, 1);
if (schema->nCols >= 2 && schema->pSchema[1].flags & COL_IS_KEY) {
void tqSetTablePrimaryKey(STqReader* pReader, int64_t uid){
bool ret = false;
SSchemaWrapper *schema = metaGetTableSchema(pReader->pVnodeMeta, uid, -1, 1);
if (schema && schema->nCols >= 2 && schema->pSchema[1].flags & COL_IS_KEY){
ret = true;
}
tDeleteSchemaWrapper(schema);
@ -333,7 +352,7 @@ int32_t extractMsgFromWal(SWalReader* pReader, void** pItem, int64_t maxVer, con
return code;
}
memcpy(data, pBody, len);
(void)memcpy(data, pBody, len);
SPackedData data1 = (SPackedData){.ver = ver, .msgLen = len, .msgStr = data};
code = streamDataSubmitNew(&data1, STREAM_INPUT__DATA_SUBMIT, (SStreamDataSubmit**)pItem);
@ -379,6 +398,11 @@ bool tqNextBlockInWal(STqReader* pReader, const char* id, int sourceExcluded) {
pReader->msg.ver);
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
if (pSubmitTbData == NULL) {
tqError("tq reader next data block %d/%d, len:%d %" PRId64, pReader->nextBlk, numOfBlocks, pReader->msg.msgLen,
pReader->msg.ver);
return false;
}
if ((pSubmitTbData->flags & sourceExcluded) != 0) {
pReader->nextBlk += 1;
continue;
@ -412,7 +436,9 @@ bool tqNextBlockInWal(STqReader* pReader, const char* id, int sourceExcluded) {
void* pBody = POINTER_SHIFT(pWalReader->pHead->head.body, sizeof(SSubmitReq2Msg));
int32_t bodyLen = pWalReader->pHead->head.bodyLen - sizeof(SSubmitReq2Msg);
int64_t ver = pWalReader->pHead->head.version;
tqReaderSetSubmitMsg(pReader, pBody, bodyLen, ver);
if (tqReaderSetSubmitMsg(pReader, pBody, bodyLen, ver) != 0) {
return false;
}
pReader->nextBlk = 0;
}
}
@ -423,13 +449,14 @@ int32_t tqReaderSetSubmitMsg(STqReader* pReader, void* msgStr, int32_t msgLen, i
pReader->msg.ver = ver;
tqDebug("tq reader set msg %p %d", msgStr, msgLen);
SDecoder decoder;
SDecoder decoder = {0};
tDecoderInit(&decoder, pReader->msg.msgStr, pReader->msg.msgLen);
if (tDecodeSubmitReq(&decoder, &pReader->submit) < 0) {
int32_t code = tDecodeSubmitReq(&decoder, &pReader->submit);
if (code != 0) {
tDecoderClear(&decoder);
tqError("DecodeSSubmitReq2 error, msgLen:%d, ver:%" PRId64, msgLen, ver);
return -1;
return code;
}
tDecoderClear(&decoder);
@ -453,6 +480,9 @@ bool tqNextBlockImpl(STqReader* pReader, const char* idstr) {
(pReader->nextBlk + 1), numOfBlocks, idstr);
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
if (pSubmitTbData == NULL){
return false;
}
if (pReader->tbIdHash == NULL) {
return true;
}
@ -482,6 +512,7 @@ bool tqNextDataBlockFilterOut(STqReader* pReader, SHashObj* filterOutUids) {
int32_t blockSz = taosArrayGetSize(pReader->submit.aSubmitTbData);
while (pReader->nextBlk < blockSz) {
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
if (pSubmitTbData == NULL) return false;
if (filterOutUids == NULL) return true;
void* ret = taosHashGet(filterOutUids, &pSubmitTbData->uid, sizeof(int64_t));
@ -499,7 +530,7 @@ bool tqNextDataBlockFilterOut(STqReader* pReader, SHashObj* filterOutUids) {
}
int32_t tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrapper* pSrc, char* mask) {
int32_t code;
int32_t code = 0;
int32_t cnt = 0;
for (int32_t i = 0; i < pSrc->nCols; i++) {
@ -509,7 +540,7 @@ int32_t tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrap
pDst->nCols = cnt;
pDst->pSchema = taosMemoryCalloc(cnt, sizeof(SSchema));
if (pDst->pSchema == NULL) {
return -1;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
int32_t j = 0;
@ -520,7 +551,7 @@ int32_t tqMaskBlock(SSchemaWrapper* pDst, SSDataBlock* pBlock, const SSchemaWrap
createColumnInfoData(pSrc->pSchema[i].type, pSrc->pSchema[i].bytes, pSrc->pSchema[i].colId);
code = blockDataAppendColInfo(pBlock, &colInfo);
if (code != 0) {
return -1;
return code;
}
}
}
@ -556,10 +587,13 @@ static int32_t buildResSDataBlock(SSDataBlock* pBlock, SSchemaWrapper* pSchema,
SSchema* pColSchema = &pSchema->pSchema[i];
col_id_t colIdSchema = pColSchema->colId;
col_id_t colIdNeed = *(col_id_t*)taosArrayGet(pColIdList, j);
if (colIdSchema < colIdNeed) {
col_id_t* pColIdNeed = (col_id_t*)taosArrayGet(pColIdList, j);
if (pColIdNeed == NULL) {
break;
}
if (colIdSchema < *pColIdNeed) {
i++;
} else if (colIdSchema > colIdNeed) {
} else if (colIdSchema > *pColIdNeed) {
j++;
} else {
SColumnInfoData colInfo = createColumnInfoData(pColSchema->type, pColSchema->bytes, pColSchema->colId);
@ -583,7 +617,7 @@ static int32_t doSetVal(SColumnInfoData* pColumnInfoData, int32_t rowIndex, SCol
char val[65535 + 2] = {0};
if (COL_VAL_IS_VALUE(pColVal)) {
if (pColVal->value.pData != NULL) {
memcpy(varDataVal(val), pColVal->value.pData, pColVal->value.nData);
(void)memcpy(varDataVal(val), pColVal->value.pData, pColVal->value.nData);
}
varDataSetLen(val, pColVal->value.nData);
code = colDataSetVal(pColumnInfoData, rowIndex, val, false);
@ -599,8 +633,11 @@ static int32_t doSetVal(SColumnInfoData* pColumnInfoData, int32_t rowIndex, SCol
int32_t tqRetrieveDataBlock(STqReader* pReader, SSDataBlock** pRes, const char* id) {
tqTrace("tq reader retrieve data block %p, index:%d", pReader->msg.msgStr, pReader->nextBlk);
int32_t code = 0;
int32_t line = 0;
STSchema* pTSchema = NULL;
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk++);
TSDB_CHECK_NULL(pSubmitTbData, code, line, END, terrno);
SSDataBlock* pBlock = pReader->pResBlock;
*pRes = pBlock;
@ -625,8 +662,7 @@ int32_t tqRetrieveDataBlock(STqReader* pReader, SSDataBlock** pRes, const char*
"version %d, possibly dropped table",
vgId, suid, uid, pReader->cachedSchemaVer);
pReader->cachedSchemaSuid = 0;
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
return -1;
return TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
}
pReader->cachedSchemaUid = uid;
@ -635,29 +671,23 @@ int32_t tqRetrieveDataBlock(STqReader* pReader, SSDataBlock** pRes, const char*
ASSERT(pReader->cachedSchemaVer == pReader->pSchemaWrapper->version);
if (blockDataGetNumOfCols(pBlock) == 0) {
int32_t code = buildResSDataBlock(pReader->pResBlock, pReader->pSchemaWrapper, pReader->pColIdList);
if (code != TSDB_CODE_SUCCESS) {
tqError("vgId:%d failed to build data block, code:%s", vgId, tstrerror(code));
return code;
}
code = buildResSDataBlock(pReader->pResBlock, pReader->pSchemaWrapper, pReader->pColIdList);
TSDB_CHECK_CODE(code, line, END);
}
}
int32_t numOfRows = 0;
if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
SColData* pCol = taosArrayGet(pSubmitTbData->aCol, 0);
TSDB_CHECK_NULL(pCol, code, line, END, terrno);
numOfRows = pCol->nVal;
} else {
numOfRows = taosArrayGetSize(pSubmitTbData->aRowP);
}
if (blockDataEnsureCapacity(pBlock, numOfRows) < 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
}
code = blockDataEnsureCapacity(pBlock, numOfRows);
TSDB_CHECK_CODE(code, line, END);
pBlock->info.rows = numOfRows;
int32_t colActual = blockDataGetNumOfCols(pBlock);
// convert and scan one block
@ -668,7 +698,7 @@ int32_t tqRetrieveDataBlock(STqReader* pReader, SSDataBlock** pRes, const char*
int32_t sourceIdx = 0;
while (targetIdx < colActual) {
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
TSDB_CHECK_NULL(pColData, code, line, END, terrno);
if (sourceIdx >= numOfCols) {
tqError("lostdata tqRetrieveDataBlock sourceIdx:%d >= numOfCols:%d", sourceIdx, numOfCols);
colDataSetNNULL(pColData, 0, numOfRows);
@ -676,20 +706,17 @@ int32_t tqRetrieveDataBlock(STqReader* pReader, SSDataBlock** pRes, const char*
continue;
}
SColData* pCol = taosArrayGet(pCols, sourceIdx);
SColVal colVal;
tqTrace("lostdata colActual:%d, sourceIdx:%d, targetIdx:%d, numOfCols:%d, source cid:%d, dst cid:%d", colActual,
sourceIdx, targetIdx, numOfCols, pCol->cid, pColData->info.colId);
SColData* pCol = taosArrayGet(pCols, sourceIdx);
TSDB_CHECK_NULL(pCol, code, line, END, terrno);
SColVal colVal = {0};
tqTrace("lostdata colActual:%d, sourceIdx:%d, targetIdx:%d, numOfCols:%d, source cid:%d, dst cid:%d", colActual, sourceIdx, targetIdx, numOfCols, pCol->cid, pColData->info.colId);
if (pCol->cid < pColData->info.colId) {
sourceIdx++;
} else if (pCol->cid == pColData->info.colId) {
for (int32_t i = 0; i < pCol->nVal; i++) {
tColDataGetValue(pCol, i, &colVal);
int32_t code = doSetVal(pColData, i, &colVal);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
code = doSetVal(pColData, i, &colVal);
TSDB_CHECK_CODE(code, line, END);
}
sourceIdx++;
targetIdx++;
@ -701,26 +728,28 @@ int32_t tqRetrieveDataBlock(STqReader* pReader, SSDataBlock** pRes, const char*
} else {
SArray* pRows = pSubmitTbData->aRowP;
SSchemaWrapper* pWrapper = pReader->pSchemaWrapper;
STSchema* pTSchema = tBuildTSchema(pWrapper->pSchema, pWrapper->nCols, pWrapper->version);
pTSchema = tBuildTSchema(pWrapper->pSchema, pWrapper->nCols, pWrapper->version);
TSDB_CHECK_NULL(pTSchema, code, line, END, terrno);
for (int32_t i = 0; i < numOfRows; i++) {
SRow* pRow = taosArrayGetP(pRows, i);
TSDB_CHECK_NULL(pRow, code, line, END, terrno);
int32_t sourceIdx = 0;
for (int32_t j = 0; j < colActual; j++) {
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, j);
TSDB_CHECK_NULL(pColData, code, line, END, terrno);
while (1) {
SColVal colVal;
tRowGet(pRow, pTSchema, sourceIdx, &colVal);
SColVal colVal = {0};
code = tRowGet(pRow, pTSchema, sourceIdx, &colVal);
TSDB_CHECK_CODE(code, line, END);
if (colVal.cid < pColData->info.colId) {
sourceIdx++;
continue;
} else if (colVal.cid == pColData->info.colId) {
int32_t code = doSetVal(pColData, i, &colVal);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
code = doSetVal(pColData, i, &colVal);
TSDB_CHECK_CODE(code, line, END);
sourceIdx++;
break;
} else {
@ -731,17 +760,196 @@ int32_t tqRetrieveDataBlock(STqReader* pReader, SSDataBlock** pRes, const char*
}
}
taosMemoryFreeClear(pTSchema);
}
return 0;
END:
if (code != 0){
tqError("tqRetrieveDataBlock failed, line:%d, code:%d", line, code);
}
taosMemoryFreeClear(pTSchema);
return code;
}
#define PROCESS_VAL \
if (curRow == 0) {\
assigned[j] = !COL_VAL_IS_NONE(&colVal);\
buildNew = true;\
} else {\
bool currentRowAssigned = !COL_VAL_IS_NONE(&colVal);\
if (currentRowAssigned != assigned[j]) {\
assigned[j] = currentRowAssigned;\
buildNew = true;\
}\
}
#define SET_DATA \
if (colVal.cid < pColData->info.colId) {\
sourceIdx++;\
} else if (colVal.cid == pColData->info.colId) {\
TQ_ERR_GO_TO_END(doSetVal(pColData, curRow - lastRow, &colVal));\
sourceIdx++;\
targetIdx++;\
}
static int32_t processBuildNew(STqReader* pReader, SSubmitTbData* pSubmitTbData, SArray* blocks,
SArray* schemas, SSchemaWrapper* pSchemaWrapper, char* assigned,
int32_t numOfRows, int32_t curRow, int32_t* lastRow){
int32_t code = 0;
SSchemaWrapper* pSW = NULL;
SSDataBlock* block = NULL;
if (taosArrayGetSize(blocks) > 0) {
SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
TQ_NULL_GO_TO_END(pLastBlock);
pLastBlock->info.rows = curRow - *lastRow;
*lastRow = curRow;
}
block = taosMemoryCalloc(1, sizeof(SSDataBlock));
TQ_NULL_GO_TO_END(block);
pSW = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
TQ_NULL_GO_TO_END(pSW);
TQ_ERR_GO_TO_END(tqMaskBlock(pSW, block, pSchemaWrapper, assigned));
tqTrace("vgId:%d, build new block, col %d", pReader->pWalReader->pWal->cfg.vgId,
(int32_t)taosArrayGetSize(block->pDataBlock));
block->info.id.uid = pSubmitTbData->uid;
block->info.version = pReader->msg.ver;
TQ_ERR_GO_TO_END(blockDataEnsureCapacity(block, numOfRows - curRow));
TQ_NULL_GO_TO_END(taosArrayPush(blocks, block));
TQ_NULL_GO_TO_END(taosArrayPush(schemas, &pSW));
pSW = NULL;
taosMemoryFreeClear(block);
END:
tDeleteSchemaWrapper(pSW);
blockDataFreeRes(block);
taosMemoryFree(block);
return code;
}
static int32_t tqProcessColData(STqReader* pReader, SSubmitTbData* pSubmitTbData, SArray* blocks, SArray* schemas){
int32_t code = 0;
int32_t curRow = 0;
int32_t lastRow = 0;
SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
char* assigned = taosMemoryCalloc(1, pSchemaWrapper->nCols);
TQ_NULL_GO_TO_END(assigned);
SArray* pCols = pSubmitTbData->aCol;
SColData* pCol = taosArrayGet(pCols, 0);
TQ_NULL_GO_TO_END(pCol);
int32_t numOfRows = pCol->nVal;
int32_t numOfCols = taosArrayGetSize(pCols);
for (int32_t i = 0; i < numOfRows; i++) {
bool buildNew = false;
for (int32_t j = 0; j < numOfCols; j++) {
pCol = taosArrayGet(pCols, j);
TQ_NULL_GO_TO_END(pCol);
SColVal colVal = {0};
tColDataGetValue(pCol, i, &colVal);
PROCESS_VAL
}
if (buildNew) {
TQ_ERR_GO_TO_END(processBuildNew(pReader, pSubmitTbData, blocks, schemas, pSchemaWrapper, assigned, numOfRows, curRow, &lastRow));
}
SSDataBlock* pBlock = taosArrayGetLast(blocks);
TQ_NULL_GO_TO_END(pBlock);
tqTrace("vgId:%d, taosx scan, block num: %d", pReader->pWalReader->pWal->cfg.vgId,
(int32_t)taosArrayGetSize(blocks));
int32_t targetIdx = 0;
int32_t sourceIdx = 0;
int32_t colActual = blockDataGetNumOfCols(pBlock);
while (targetIdx < colActual) {
pCol = taosArrayGet(pCols, sourceIdx);
TQ_NULL_GO_TO_END(pCol);
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
TQ_NULL_GO_TO_END(pColData);
SColVal colVal = {0};
tColDataGetValue(pCol, i, &colVal);
SET_DATA
}
curRow++;
}
SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
pLastBlock->info.rows = curRow - lastRow;
END:
taosMemoryFree(assigned);
return code;
}
int32_t tqProcessRowData(STqReader* pReader, SSubmitTbData* pSubmitTbData, SArray* blocks, SArray* schemas){
int32_t code = 0;
STSchema* pTSchema = NULL;
SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
char* assigned = taosMemoryCalloc(1, pSchemaWrapper->nCols);
TQ_NULL_GO_TO_END(assigned);
int32_t curRow = 0;
int32_t lastRow = 0;
SArray* pRows = pSubmitTbData->aRowP;
int32_t numOfRows = taosArrayGetSize(pRows);
pTSchema = tBuildTSchema(pSchemaWrapper->pSchema, pSchemaWrapper->nCols, pSchemaWrapper->version);
for (int32_t i = 0; i < numOfRows; i++) {
bool buildNew = false;
SRow* pRow = taosArrayGetP(pRows, i);
TQ_NULL_GO_TO_END(pRow);
for (int32_t j = 0; j < pTSchema->numOfCols; j++) {
SColVal colVal = {0};
TQ_ERR_GO_TO_END(tRowGet(pRow, pTSchema, j, &colVal));
PROCESS_VAL
}
if (buildNew) {
TQ_ERR_GO_TO_END(processBuildNew(pReader, pSubmitTbData, blocks, schemas, pSchemaWrapper, assigned, numOfRows, curRow, &lastRow));
}
SSDataBlock* pBlock = taosArrayGetLast(blocks);
TQ_NULL_GO_TO_END(pBlock);
tqTrace("vgId:%d, taosx scan, block num: %d", pReader->pWalReader->pWal->cfg.vgId,
(int32_t)taosArrayGetSize(blocks));
int32_t targetIdx = 0;
int32_t sourceIdx = 0;
int32_t colActual = blockDataGetNumOfCols(pBlock);
while (targetIdx < colActual) {
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
SColVal colVal = {0};
TQ_ERR_GO_TO_END(tRowGet(pRow, pTSchema, sourceIdx, &colVal));
SET_DATA
}
curRow++;
}
SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
pLastBlock->info.rows = curRow - lastRow;
END:
taosMemoryFreeClear(pTSchema);
taosMemoryFree(assigned);
return code;
}
// todo refactor:
int32_t tqRetrieveTaosxBlock(STqReader* pReader, SArray* blocks, SArray* schemas, SSubmitTbData** pSubmitTbDataRet) {
tqDebug("tq reader retrieve data block %p, %d", pReader->msg.msgStr, pReader->nextBlk);
SSDataBlock* block = NULL;
SSubmitTbData* pSubmitTbData = taosArrayGet(pReader->submit.aSubmitTbData, pReader->nextBlk);
if(pSubmitTbData == NULL){
return terrno;
}
pReader->nextBlk++;
if (pSubmitTbDataRet) {
@ -758,248 +966,57 @@ int32_t tqRetrieveTaosxBlock(STqReader* pReader, SArray* blocks, SArray* schemas
tqWarn("vgId:%d, cannot found schema wrapper for table: suid:%" PRId64 ", version %d, possibly dropped table",
pReader->pWalReader->pWal->cfg.vgId, uid, pReader->cachedSchemaVer);
pReader->cachedSchemaSuid = 0;
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
return -1;
return TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
}
SSchemaWrapper* pSchemaWrapper = pReader->pSchemaWrapper;
int32_t numOfRows = 0;
if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
SArray* pCols = pSubmitTbData->aCol;
SColData* pCol = taosArrayGet(pCols, 0);
numOfRows = pCol->nVal;
return tqProcessColData(pReader, pSubmitTbData, blocks, schemas);
} else {
SArray* pRows = pSubmitTbData->aRowP;
numOfRows = taosArrayGetSize(pRows);
return tqProcessRowData(pReader, pSubmitTbData, blocks, schemas);
}
int32_t curRow = 0;
int32_t lastRow = 0;
char* assigned = taosMemoryCalloc(1, pSchemaWrapper->nCols);
if (assigned == NULL) return -1;
// convert and scan one block
if (pSubmitTbData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) {
SArray* pCols = pSubmitTbData->aCol;
int32_t numOfCols = taosArrayGetSize(pCols);
for (int32_t i = 0; i < numOfRows; i++) {
bool buildNew = false;
for (int32_t j = 0; j < numOfCols; j++) {
SColData* pCol = taosArrayGet(pCols, j);
SColVal colVal;
tColDataGetValue(pCol, i, &colVal);
if (curRow == 0) {
assigned[j] = !COL_VAL_IS_NONE(&colVal);
buildNew = true;
} else {
bool currentRowAssigned = !COL_VAL_IS_NONE(&colVal);
if (currentRowAssigned != assigned[j]) {
assigned[j] = currentRowAssigned;
buildNew = true;
}
}
}
if (buildNew) {
if (taosArrayGetSize(blocks) > 0) {
SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
pLastBlock->info.rows = curRow - lastRow;
lastRow = curRow;
}
SSDataBlock block = {0};
SSchemaWrapper* pSW = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
if (pSW == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto FAIL;
}
if (tqMaskBlock(pSW, &block, pSchemaWrapper, assigned) < 0) {
blockDataFreeRes(&block);
tDeleteSchemaWrapper(pSW);
goto FAIL;
}
tqTrace("vgId:%d, build new block, col %d", pReader->pWalReader->pWal->cfg.vgId,
(int32_t)taosArrayGetSize(block.pDataBlock));
block.info.id.uid = uid;
block.info.version = pReader->msg.ver;
if (blockDataEnsureCapacity(&block, numOfRows - curRow) < 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
blockDataFreeRes(&block);
tDeleteSchemaWrapper(pSW);
goto FAIL;
}
taosArrayPush(blocks, &block);
taosArrayPush(schemas, &pSW);
}
SSDataBlock* pBlock = taosArrayGetLast(blocks);
tqTrace("vgId:%d, taosx scan, block num: %d", pReader->pWalReader->pWal->cfg.vgId,
(int32_t)taosArrayGetSize(blocks));
int32_t targetIdx = 0;
int32_t sourceIdx = 0;
int32_t colActual = blockDataGetNumOfCols(pBlock);
while (targetIdx < colActual) {
SColData* pCol = taosArrayGet(pCols, sourceIdx);
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
SColVal colVal;
if (pCol->cid < pColData->info.colId) {
sourceIdx++;
} else if (pCol->cid == pColData->info.colId) {
tColDataGetValue(pCol, i, &colVal);
if (doSetVal(pColData, curRow - lastRow, &colVal) != TDB_CODE_SUCCESS) {
goto FAIL;
}
sourceIdx++;
targetIdx++;
}
}
curRow++;
}
} else {
SSchemaWrapper* pWrapper = pReader->pSchemaWrapper;
STSchema* pTSchema = tBuildTSchema(pWrapper->pSchema, pWrapper->nCols, pWrapper->version);
SArray* pRows = pSubmitTbData->aRowP;
for (int32_t i = 0; i < numOfRows; i++) {
SRow* pRow = taosArrayGetP(pRows, i);
bool buildNew = false;
for (int32_t j = 0; j < pTSchema->numOfCols; j++) {
SColVal colVal;
tRowGet(pRow, pTSchema, j, &colVal);
if (curRow == 0) {
assigned[j] = !COL_VAL_IS_NONE(&colVal);
buildNew = true;
} else {
bool currentRowAssigned = !COL_VAL_IS_NONE(&colVal);
if (currentRowAssigned != assigned[j]) {
assigned[j] = currentRowAssigned;
buildNew = true;
}
}
}
if (buildNew) {
if (taosArrayGetSize(blocks) > 0) {
SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
pLastBlock->info.rows = curRow - lastRow;
lastRow = curRow;
}
SSDataBlock block = {0};
SSchemaWrapper* pSW = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
if (pSW == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto FAIL;
}
if (tqMaskBlock(pSW, &block, pSchemaWrapper, assigned) < 0) {
blockDataFreeRes(&block);
tDeleteSchemaWrapper(pSW);
goto FAIL;
}
tqTrace("vgId:%d, build new block, col %d", pReader->pWalReader->pWal->cfg.vgId,
(int32_t)taosArrayGetSize(block.pDataBlock));
block.info.id.uid = uid;
block.info.version = pReader->msg.ver;
if (blockDataEnsureCapacity(&block, numOfRows - curRow) < 0) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
blockDataFreeRes(&block);
tDeleteSchemaWrapper(pSW);
goto FAIL;
}
taosArrayPush(blocks, &block);
taosArrayPush(schemas, &pSW);
}
SSDataBlock* pBlock = taosArrayGetLast(blocks);
tqTrace("vgId:%d, taosx scan, block num: %d", pReader->pWalReader->pWal->cfg.vgId,
(int32_t)taosArrayGetSize(blocks));
int32_t targetIdx = 0;
int32_t sourceIdx = 0;
int32_t colActual = blockDataGetNumOfCols(pBlock);
while (targetIdx < colActual) {
SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, targetIdx);
SColVal colVal;
tRowGet(pRow, pTSchema, sourceIdx, &colVal);
if (colVal.cid < pColData->info.colId) {
sourceIdx++;
} else if (colVal.cid == pColData->info.colId) {
if (doSetVal(pColData, curRow - lastRow, &colVal) != TDB_CODE_SUCCESS) {
goto FAIL;
}
sourceIdx++;
targetIdx++;
}
}
curRow++;
}
taosMemoryFreeClear(pTSchema);
}
SSDataBlock* pLastBlock = taosArrayGetLast(blocks);
pLastBlock->info.rows = curRow - lastRow;
taosMemoryFree(assigned);
return 0;
FAIL:
taosMemoryFree(assigned);
return -1;
}
void tqReaderSetColIdList(STqReader* pReader, SArray* pColIdList) { pReader->pColIdList = pColIdList; }
int tqReaderSetTbUidList(STqReader* pReader, const SArray* tbUidList, const char* id) {
void tqReaderSetTbUidList(STqReader* pReader, const SArray* tbUidList, const char* id) {
if (pReader->tbIdHash) {
taosHashClear(pReader->tbIdHash);
} else {
pReader->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
}
if (pReader->tbIdHash == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
if (pReader->tbIdHash == NULL) {
tqError("s-task:%s failed to init hash table", id);
return;
}
}
for (int i = 0; i < taosArrayGetSize(tbUidList); i++) {
int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i);
taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0);
if (pKey && taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0) != 0) {
tqError("s-task:%s failed to add table uid:%" PRId64 " to hash", id, *pKey);
continue;
}
}
tqDebug("s-task:%s %d tables are set to be queried target table", id, (int32_t)taosArrayGetSize(tbUidList));
return 0;
}
int tqReaderAddTbUidList(STqReader* pReader, const SArray* pTableUidList) {
void tqReaderAddTbUidList(STqReader* pReader, const SArray* pTableUidList) {
if (pReader->tbIdHash == NULL) {
pReader->tbIdHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
if (pReader->tbIdHash == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1;
tqError("failed to init hash table");
return;
}
}
int32_t numOfTables = taosArrayGetSize(pTableUidList);
for (int i = 0; i < numOfTables; i++) {
int64_t* pKey = (int64_t*)taosArrayGet(pTableUidList, i);
taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0);
if (taosHashPut(pReader->tbIdHash, pKey, sizeof(int64_t), NULL, 0) != 0) {
tqError("failed to add table uid:%" PRId64 " to hash", *pKey);
continue;
}
}
return 0;
}
bool tqReaderIsQueriedTable(STqReader* pReader, uint64_t uid) {
@ -1008,16 +1025,15 @@ bool tqReaderIsQueriedTable(STqReader* pReader, uint64_t uid) {
bool tqCurrentBlockConsumed(const STqReader* pReader) { return pReader->msg.msgStr == NULL; }
int tqReaderRemoveTbUidList(STqReader* pReader, const SArray* tbUidList) {
void tqReaderRemoveTbUidList(STqReader* pReader, const SArray* tbUidList) {
for (int32_t i = 0; i < taosArrayGetSize(tbUidList); i++) {
int64_t* pKey = (int64_t*)taosArrayGet(tbUidList, i);
taosHashRemove(pReader->tbIdHash, pKey, sizeof(int64_t));
if (pKey && taosHashRemove(pReader->tbIdHash, pKey, sizeof(int64_t)) != 0){
tqError("failed to remove table uid:%" PRId64 " from hash", *pKey);
}
}
return 0;
}
// todo update the table list in wal reader
int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
void* pIter = NULL;
int32_t vgId = TD_VID(pTq->pVnode);
@ -1041,8 +1057,11 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) {
if (!isAdd) {
int32_t sz = taosArrayGetSize(tbUidList);
for (int32_t i = 0; i < sz; i++) {
int64_t tbUid = *(int64_t*)taosArrayGet(tbUidList, i);
taosHashPut(pTqHandle->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0);
int64_t* tbUid = (int64_t*)taosArrayGet(tbUidList, i);
if (tbUid && taosHashPut(pTqHandle->execHandle.execDb.pFilterOutTbUid, tbUid, sizeof(int64_t), NULL, 0) != 0){
tqError("failed to add table uid:%" PRId64 " to hash", *tbUid);
continue;
}
}
}
} else if (pTqHandle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) {

View File

@ -30,8 +30,14 @@ int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, void* pRsp, int32_t numOf
int32_t actualLen = blockEncode(pBlock, pRetrieve->data, numOfCols);
actualLen += sizeof(SRetrieveTableRspForTmq);
taosArrayPush(((SMqDataRspCommon*)pRsp)->blockDataLen, &actualLen);
taosArrayPush(((SMqDataRspCommon*)pRsp)->blockData, &buf);
if (taosArrayPush(((SMqDataRspCommon*)pRsp)->blockDataLen, &actualLen) == NULL){
taosMemoryFree(buf);
return TSDB_CODE_OUT_OF_MEMORY;
}
if (taosArrayPush(((SMqDataRspCommon*)pRsp)->blockData, &buf) == NULL) {
taosMemoryFree(buf);
return TSDB_CODE_OUT_OF_MEMORY;
}
return TSDB_CODE_SUCCESS;
}
@ -39,9 +45,11 @@ int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, void* pRsp, int32_t numOf
static int32_t tqAddBlockSchemaToRsp(const STqExecHandle* pExec, void* pRsp) {
SSchemaWrapper* pSW = tCloneSSchemaWrapper(pExec->pTqReader->pSchemaWrapper);
if (pSW == NULL) {
return -1;
return TSDB_CODE_OUT_OF_MEMORY;
}
if (taosArrayPush(((SMqDataRspCommon*)pRsp)->blockSchema, &pSW) == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
taosArrayPush(((SMqDataRspCommon*)pRsp)->blockSchema, &pSW);
return 0;
}
@ -49,15 +57,17 @@ static int32_t tqAddTbNameToRsp(const STQ* pTq, int64_t uid, void* pRsp, int32_t
SMetaReader mr = {0};
metaReaderDoInit(&mr, pTq->pVnode->pMeta, META_READER_LOCK);
// TODO add reference to gurantee success
if (metaReaderGetTableEntryByUidCache(&mr, uid) < 0) {
int32_t code = metaReaderGetTableEntryByUidCache(&mr, uid);
if (code < 0) {
metaReaderClear(&mr);
return -1;
return code;
}
for (int32_t i = 0; i < n; i++) {
char* tbName = taosStrdup(mr.me.name);
taosArrayPush(((SMqDataRspCommon*)pRsp)->blockTbName, &tbName);
if(taosArrayPush(((SMqDataRspCommon*)pRsp)->blockTbName, &tbName) == NULL){
continue;
}
}
metaReaderClear(&mr);
return 0;
@ -71,8 +81,7 @@ int32_t getDataBlock(qTaskInfo_t task, const STqHandle* pHandle, int32_t vgId, S
int32_t code = qExecTask(task, res, &ts);
if (code != TSDB_CODE_SUCCESS) {
tqError("consumer:0x%" PRIx64 " vgId:%d, task exec error since %s", pHandle->consumerId, vgId, tstrerror(code));
terrno = code;
return -1;
return code;
}
tqDebug("consumer:0x%" PRIx64 " vgId:%d tmq one task end executed, pDataBlock:%p", pHandle->consumerId, vgId, *res);
@ -82,22 +91,20 @@ int32_t getDataBlock(qTaskInfo_t task, const STqHandle* pHandle, int32_t vgId, S
int32_t tqScanData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal* pOffset, const SMqPollReq* pRequest) {
int32_t vgId = TD_VID(pTq->pVnode);
int32_t code = 0;
int32_t line = 0;
int32_t totalRows = 0;
const STqExecHandle* pExec = &pHandle->execHandle;
qTaskInfo_t task = pExec->task;
if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
return -1;
}
code = qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
TSDB_CHECK_CODE(code, line, END);
qStreamSetSourceExcluded(task, pRequest->sourceExcluded);
while (1) {
SSDataBlock* pDataBlock = NULL;
code = getDataBlock(task, pHandle, vgId, &pDataBlock);
if (code != 0) {
return code;
}
TSDB_CHECK_CODE(code, line, END);
if (pRequest->enableReplay) {
if (IS_OFFSET_RESET_TYPE(pRequest->reqOffset.type) && pHandle->block != NULL) {
@ -111,27 +118,23 @@ int32_t tqScanData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal*
STqOffsetVal offset = {0};
qStreamExtractOffset(task, &offset);
pHandle->block = createOneDataBlock(pDataBlock, true);
TSDB_CHECK_NULL(pDataBlock, code, line, END, terrno);
pHandle->blockTime = offset.ts;
tOffsetDestroy(&offset);
code = getDataBlock(task, pHandle, vgId, &pDataBlock);
if (code != 0) {
return code;
}
TSDB_CHECK_CODE(code, line, END);
}
code = tqAddBlockDataToRsp(pHandle->block, pRsp, pExec->numOfCols, pTq->pVnode->config.tsdbCfg.precision);
if (code != TSDB_CODE_SUCCESS) {
tqError("vgId:%d, failed to add block to rsp msg", vgId);
return code;
}
TSDB_CHECK_CODE(code, line, END);
pRsp->common.blockNum++;
if (pDataBlock == NULL) {
blockDataDestroy(pHandle->block);
pHandle->block = NULL;
} else {
copyDataBlock(pHandle->block, pDataBlock);
code = copyDataBlock(pHandle->block, pDataBlock);
TSDB_CHECK_CODE(code, line, END);
STqOffsetVal offset = {0};
qStreamExtractOffset(task, &offset);
pRsp->sleepTime = offset.ts - pHandle->blockTime;
@ -144,10 +147,7 @@ int32_t tqScanData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal*
break;
}
code = tqAddBlockDataToRsp(pDataBlock, pRsp, pExec->numOfCols, pTq->pVnode->config.tsdbCfg.precision);
if (code != TSDB_CODE_SUCCESS) {
tqError("vgId:%d, failed to add block to rsp msg", vgId);
return code;
}
TSDB_CHECK_CODE(code, line, END);
pRsp->common.blockNum++;
totalRows += pDataBlock->info.rows;
@ -160,15 +160,19 @@ int32_t tqScanData(STQ* pTq, STqHandle* pHandle, SMqDataRsp* pRsp, STqOffsetVal*
tqDebug("consumer:0x%" PRIx64 " vgId:%d tmq task executed finished, total blocks:%d, totalRows:%d",
pHandle->consumerId, vgId, pRsp->common.blockNum, totalRows);
qStreamExtractOffset(task, &pRsp->common.rspOffset);
return 0;
END:
if ( code!= 0){
tqError("consumer:0x%" PRIx64 " vgId:%d tmq task executed error, line:%d code:%d", pHandle->consumerId, vgId, line, code);
}
return code;
}
int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqBatchMetaRsp* pBatchMetaRsp, STqOffsetVal* pOffset) {
const STqExecHandle* pExec = &pHandle->execHandle;
qTaskInfo_t task = pExec->task;
if (qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType) < 0) {
return -1;
int code = qStreamPrepareScan(task, pOffset, pHandle->execHandle.subType);
if (code != 0) {
return code;
}
int32_t rowCnt = 0;
@ -176,11 +180,10 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqBatc
SSDataBlock* pDataBlock = NULL;
uint64_t ts = 0;
tqDebug("tmqsnap task start to execute");
int code = qExecTask(task, &pDataBlock, &ts);
code = qExecTask(task, &pDataBlock, &ts);
if (code != 0) {
tqError("vgId:%d, task exec error since %s", pTq->pVnode->config.vgId, tstrerror(code));
terrno = code;
return -1;
return code;
}
tqDebug("tmqsnap task execute end, get %p", pDataBlock);
@ -190,24 +193,37 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqBatc
if (pOffset->type == TMQ_OFFSET__LOG) {
int64_t uid = pExec->pTqReader->lastBlkUid;
if (tqAddTbNameToRsp(pTq, uid, pRsp, 1) < 0) {
tqError("vgId:%d, failed to add tbname to rsp msg", pTq->pVnode->config.vgId);
continue;
}
} else {
char* tbName = taosStrdup(qExtractTbnameFromTask(task));
taosArrayPush(pRsp->common.blockTbName, &tbName);
if (taosArrayPush(pRsp->common.blockTbName, &tbName) == NULL){
tqError("vgId:%d, failed to add tbname to rsp msg", pTq->pVnode->config.vgId);
continue;
}
}
}
if (pRsp->common.withSchema) {
if (pOffset->type == TMQ_OFFSET__LOG) {
tqAddBlockSchemaToRsp(pExec, pRsp);
if (tqAddBlockSchemaToRsp(pExec, pRsp) != 0){
tqError("vgId:%d, failed to add schema to rsp msg", pTq->pVnode->config.vgId);
continue;
}
} else {
SSchemaWrapper* pSW = tCloneSSchemaWrapper(qExtractSchemaFromTask(task));
taosArrayPush(pRsp->common.blockSchema, &pSW);
if(taosArrayPush(pRsp->common.blockSchema, &pSW) == NULL){
tqError("vgId:%d, failed to add schema to rsp msg", pTq->pVnode->config.vgId);
continue;
}
}
}
tqAddBlockDataToRsp(pDataBlock, (SMqDataRsp*)pRsp, taosArrayGetSize(pDataBlock->pDataBlock),
pTq->pVnode->config.tsdbCfg.precision);
if (tqAddBlockDataToRsp(pDataBlock, (SMqDataRsp*)pRsp, taosArrayGetSize(pDataBlock->pDataBlock),
pTq->pVnode->config.tsdbCfg.precision) != 0) {
tqError("vgId:%d, failed to add block to rsp msg", pTq->pVnode->config.vgId);
continue;
}
pRsp->common.blockNum++;
if (pOffset->type == TMQ_OFFSET__LOG) {
continue;
@ -222,7 +238,6 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqBatc
if (taosArrayGetSize(tmp->batchMetaReq) > 0) {
qStreamExtractOffset(task, &tmp->rspOffset);
*pBatchMetaRsp = *tmp;
tqDebug("tmqsnap task get meta");
break;
}
@ -248,150 +263,135 @@ int32_t tqScanTaosx(STQ* pTq, const STqHandle* pHandle, STaosxRsp* pRsp, SMqBatc
return 0;
}
static void tqProcessSubData(STQ* pTq, STqHandle* pHandle, STaosxRsp* pRsp, int32_t* totalRows, int8_t sourceExcluded){
int32_t code = 0;
STqExecHandle* pExec = &pHandle->execHandle;
STqReader* pReader = pExec->pTqReader;
SArray* pBlocks = NULL;
SArray* pSchemas = NULL;
pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
if (pBlocks == NULL) {
code = terrno;
goto END;
}
pSchemas = taosArrayInit(0, sizeof(void*));
if(pSchemas == NULL){
code = terrno;
goto END;
}
SSubmitTbData* pSubmitTbDataRet = NULL;
code = tqRetrieveTaosxBlock(pReader, pBlocks, pSchemas, &pSubmitTbDataRet);
if (code != 0) {
tqError("vgId:%d, failed to retrieve block", pTq->pVnode->config.vgId);
goto END;
}
if ((pSubmitTbDataRet->flags & sourceExcluded) != 0) {
goto END;
}
if (pRsp->common.withTbName) {
int64_t uid = pExec->pTqReader->lastBlkUid;
code = tqAddTbNameToRsp(pTq, uid, pRsp, taosArrayGetSize(pBlocks));
if (code != 0) {
tqError("vgId:%d, failed to add tbname to rsp msg", pTq->pVnode->config.vgId);
goto END;
}
}
if (pHandle->fetchMeta != WITH_DATA && pSubmitTbDataRet->pCreateTbReq != NULL) {
if (pRsp->createTableNum == 0) {
pRsp->createTableLen = taosArrayInit(0, sizeof(int32_t));
if (pRsp->createTableLen == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto END;
}
pRsp->createTableReq = taosArrayInit(0, sizeof(void*));
if (pRsp->createTableReq == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto END;
}
}
uint32_t len = 0;
tEncodeSize(tEncodeSVCreateTbReq, pSubmitTbDataRet->pCreateTbReq, len, code);
if (TSDB_CODE_SUCCESS != code) {
goto END;
}
void* createReq = taosMemoryCalloc(1, len);
if (createReq == NULL){
code = TSDB_CODE_OUT_OF_MEMORY;
goto END;
}
SEncoder encoder = {0};
tEncoderInit(&encoder, createReq, len);
code = tEncodeSVCreateTbReq(&encoder, pSubmitTbDataRet->pCreateTbReq);
tEncoderClear(&encoder);
if (code < 0) {
taosMemoryFree(createReq);
goto END;
}
if (taosArrayPush(pRsp->createTableLen, &len) == NULL){
taosMemoryFree(createReq);
goto END;
}
if (taosArrayPush(pRsp->createTableReq, &createReq) == NULL){
taosMemoryFree(createReq);
goto END;
}
pRsp->createTableNum++;
}
if (pHandle->fetchMeta == ONLY_META && pSubmitTbDataRet->pCreateTbReq == NULL) {
goto END;
}
for (int32_t i = 0; i < taosArrayGetSize(pBlocks); i++) {
SSDataBlock* pBlock = taosArrayGet(pBlocks, i);
if (pBlock == NULL) {
continue;
}
if (tqAddBlockDataToRsp(pBlock, (SMqDataRsp*)pRsp, taosArrayGetSize(pBlock->pDataBlock),
pTq->pVnode->config.tsdbCfg.precision) != 0){
tqError("vgId:%d, failed to add block to rsp msg", pTq->pVnode->config.vgId);
continue;
}
*totalRows += pBlock->info.rows;
blockDataFreeRes(pBlock);
SSchemaWrapper* pSW = taosArrayGetP(pSchemas, i);
if (taosArrayPush(pRsp->common.blockSchema, &pSW) == NULL){
tqError("vgId:%d, failed to add schema to rsp msg", pTq->pVnode->config.vgId);
continue;
}
pRsp->common.blockNum++;
}
taosArrayDestroy(pBlocks);
taosArrayDestroy(pSchemas);
return;
END:
taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
}
int32_t tqTaosxScanLog(STQ* pTq, STqHandle* pHandle, SPackedData submit, STaosxRsp* pRsp, int32_t* totalRows,
int8_t sourceExcluded) {
STqExecHandle* pExec = &pHandle->execHandle;
SArray* pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
SArray* pSchemas = taosArrayInit(0, sizeof(void*));
int32_t code = 0;
STqReader* pReader = pExec->pTqReader;
code = tqReaderSetSubmitMsg(pReader, submit.msgStr, submit.msgLen, submit.ver);
if (code != 0) {
return code;
}
if (pExec->subType == TOPIC_SUB_TYPE__TABLE) {
STqReader* pReader = pExec->pTqReader;
tqReaderSetSubmitMsg(pReader, submit.msgStr, submit.msgLen, submit.ver);
while (tqNextBlockImpl(pReader, NULL)) {
taosArrayClear(pBlocks);
taosArrayClear(pSchemas);
SSubmitTbData* pSubmitTbDataRet = NULL;
if (tqRetrieveTaosxBlock(pReader, pBlocks, pSchemas, &pSubmitTbDataRet) < 0) {
if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) goto loop_table;
}
if ((pSubmitTbDataRet->flags & sourceExcluded) != 0) {
goto loop_table;
}
if (pRsp->common.withTbName) {
int64_t uid = pExec->pTqReader->lastBlkUid;
if (tqAddTbNameToRsp(pTq, uid, pRsp, taosArrayGetSize(pBlocks)) < 0) {
goto loop_table;
}
}
if (pHandle->fetchMeta != WITH_DATA && pSubmitTbDataRet->pCreateTbReq != NULL) {
if (pRsp->createTableNum == 0) {
pRsp->createTableLen = taosArrayInit(0, sizeof(int32_t));
pRsp->createTableReq = taosArrayInit(0, sizeof(void*));
}
int32_t code = TSDB_CODE_SUCCESS;
uint32_t len = 0;
tEncodeSize(tEncodeSVCreateTbReq, pSubmitTbDataRet->pCreateTbReq, len, code);
if (TSDB_CODE_SUCCESS != code) {
goto loop_table;
}
void* createReq = taosMemoryCalloc(1, len);
SEncoder encoder = {0};
tEncoderInit(&encoder, createReq, len);
code = tEncodeSVCreateTbReq(&encoder, pSubmitTbDataRet->pCreateTbReq);
if (code < 0) {
tEncoderClear(&encoder);
taosMemoryFree(createReq);
goto loop_table;
}
taosArrayPush(pRsp->createTableLen, &len);
taosArrayPush(pRsp->createTableReq, &createReq);
pRsp->createTableNum++;
tEncoderClear(&encoder);
}
if (pHandle->fetchMeta == ONLY_META && pSubmitTbDataRet->pCreateTbReq == NULL) {
goto loop_table;
}
for (int32_t i = 0; i < taosArrayGetSize(pBlocks); i++) {
SSDataBlock* pBlock = taosArrayGet(pBlocks, i);
tqAddBlockDataToRsp(pBlock, (SMqDataRsp*)pRsp, taosArrayGetSize(pBlock->pDataBlock),
pTq->pVnode->config.tsdbCfg.precision);
*totalRows += pBlock->info.rows;
blockDataFreeRes(pBlock);
SSchemaWrapper* pSW = taosArrayGetP(pSchemas, i);
taosArrayPush(pRsp->common.blockSchema, &pSW);
pRsp->common.blockNum++;
}
continue;
loop_table:
taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
pSchemas = taosArrayInit(0, sizeof(void*));
tqProcessSubData(pTq, pHandle, pRsp, totalRows, sourceExcluded);
}
} else if (pExec->subType == TOPIC_SUB_TYPE__DB) {
STqReader* pReader = pExec->pTqReader;
tqReaderSetSubmitMsg(pReader, submit.msgStr, submit.msgLen, submit.ver);
while (tqNextDataBlockFilterOut(pReader, pExec->execDb.pFilterOutTbUid)) {
taosArrayClear(pBlocks);
taosArrayClear(pSchemas);
SSubmitTbData* pSubmitTbDataRet = NULL;
if (tqRetrieveTaosxBlock(pReader, pBlocks, pSchemas, &pSubmitTbDataRet) < 0) {
if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) goto loop_db;
}
if ((pSubmitTbDataRet->flags & sourceExcluded) != 0) {
goto loop_db;
}
if (pRsp->common.withTbName) {
int64_t uid = pExec->pTqReader->lastBlkUid;
if (tqAddTbNameToRsp(pTq, uid, pRsp, taosArrayGetSize(pBlocks)) < 0) {
goto loop_db;
}
}
if (pHandle->fetchMeta != WITH_DATA && pSubmitTbDataRet->pCreateTbReq != NULL) {
if (pRsp->createTableNum == 0) {
pRsp->createTableLen = taosArrayInit(0, sizeof(int32_t));
pRsp->createTableReq = taosArrayInit(0, sizeof(void*));
}
int32_t code = TSDB_CODE_SUCCESS;
uint32_t len = 0;
tEncodeSize(tEncodeSVCreateTbReq, pSubmitTbDataRet->pCreateTbReq, len, code);
if (TSDB_CODE_SUCCESS != code) {
goto loop_db;
}
void* createReq = taosMemoryCalloc(1, len);
SEncoder encoder = {0};
tEncoderInit(&encoder, createReq, len);
code = tEncodeSVCreateTbReq(&encoder, pSubmitTbDataRet->pCreateTbReq);
if (code < 0) {
tEncoderClear(&encoder);
taosMemoryFree(createReq);
goto loop_db;
}
taosArrayPush(pRsp->createTableLen, &len);
taosArrayPush(pRsp->createTableReq, &createReq);
pRsp->createTableNum++;
tEncoderClear(&encoder);
}
if (pHandle->fetchMeta == ONLY_META && pSubmitTbDataRet->pCreateTbReq == NULL) {
goto loop_db;
}
for (int32_t i = 0; i < taosArrayGetSize(pBlocks); i++) {
SSDataBlock* pBlock = taosArrayGet(pBlocks, i);
tqAddBlockDataToRsp(pBlock, (SMqDataRsp*)pRsp, taosArrayGetSize(pBlock->pDataBlock),
pTq->pVnode->config.tsdbCfg.precision);
*totalRows += pBlock->info.rows;
blockDataFreeRes(pBlock);
SSchemaWrapper* pSW = taosArrayGetP(pSchemas, i);
taosArrayPush(pRsp->common.blockSchema, &pSW);
pRsp->common.blockNum++;
}
continue;
loop_db:
taosArrayDestroyEx(pBlocks, (FDelete)blockDataFreeRes);
taosArrayDestroyP(pSchemas, (FDelete)tDeleteSchemaWrapper);
pBlocks = taosArrayInit(0, sizeof(SSDataBlock));
pSchemas = taosArrayInit(0, sizeof(void*));
tqProcessSubData(pTq, pHandle, pRsp, totalRows, sourceExcluded);
}
}
taosArrayDestroy(pBlocks);
taosArrayDestroy(pSchemas);
return 0;
return code;
}

View File

@ -76,14 +76,10 @@ _err:
return code;
}
int32_t tqSnapReaderClose(STqSnapReader** ppReader) {
int32_t code = 0;
tdbTbcClose((*ppReader)->pCur);
void tqSnapReaderClose(STqSnapReader** ppReader) {
(void)tdbTbcClose((*ppReader)->pCur);
taosMemoryFree(*ppReader);
*ppReader = NULL;
return code;
}
int32_t tqSnapRead(STqSnapReader* pReader, uint8_t** ppData) {
@ -99,14 +95,14 @@ int32_t tqSnapRead(STqSnapReader* pReader, uint8_t** ppData) {
*ppData = taosMemoryMalloc(sizeof(SSnapDataHdr) + vLen);
if (*ppData == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
goto _err;
}
SSnapDataHdr* pHdr = (SSnapDataHdr*)(*ppData);
pHdr->type = pReader->type;
pHdr->size = vLen;
memcpy(pHdr->data, pVal, vLen);
(void)memcpy(pHdr->data, pVal, vLen);
_exit:
tdbFree(pKey);
@ -131,20 +127,20 @@ struct STqSnapWriter {
int32_t tqSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapWriter** ppWriter) {
int32_t code = 0;
STqSnapWriter* pWriter;
STqSnapWriter* pWriter = NULL;
// alloc
pWriter = (STqSnapWriter*)taosMemoryCalloc(1, sizeof(*pWriter));
if (pWriter == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);;
goto _err;
}
pWriter->pTq = pTq;
pWriter->sver = sver;
pWriter->ever = ever;
if (tdbBegin(pTq->pMetaDB, &pWriter->txn, tdbDefaultMalloc, tdbDefaultFree, NULL, 0) < 0) {
code = -1;
code = tdbBegin(pTq->pMetaDB, &pWriter->txn, tdbDefaultMalloc, tdbDefaultFree, NULL, 0);
if (code < 0) {
taosMemoryFree(pWriter);
goto _err;
}
@ -164,7 +160,7 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) {
STQ* pTq = pWriter->pTq;
if (rollback) {
tdbAbort(pWriter->pTq->pMetaDB, pWriter->txn);
(void)tdbAbort(pWriter->pTq->pMetaDB, pWriter->txn);
} else {
code = tdbCommit(pWriter->pTq->pMetaDB, pWriter->txn);
if (code) goto _err;
@ -207,7 +203,8 @@ int32_t tqSnapCheckInfoWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nD
int32_t code = 0;
STQ* pTq = pWriter->pTq;
STqCheckInfo info = {0};
if(tqMetaDecodeCheckInfo(&info, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr)) != 0){
code = tqMetaDecodeCheckInfo(&info, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
if(code != 0){
goto _err;
}
@ -217,7 +214,7 @@ int32_t tqSnapCheckInfoWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nD
return code;
_err:
_err:
tqError("vgId:%d, vnode check info tq write failed since %s", TD_VID(pTq->pVnode), tstrerror(code));
return code;
}
@ -227,7 +224,8 @@ int32_t tqSnapOffsetWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData
STQ* pTq = pWriter->pTq;
STqOffset info = {0};
if(tqMetaDecodeOffsetInfo(&info, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr)) != 0){
code = tqMetaDecodeOffsetInfo(&info, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
if(code != 0){
goto _err;
}

View File

@ -21,16 +21,15 @@ static int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, c
const SMqBatchMetaRsp* pRsp, int32_t vgId);
int32_t tqInitDataRsp(SMqDataRspCommon* pRsp, STqOffsetVal pOffset) {
tOffsetCopy(&pRsp->reqOffset, &pOffset);
tOffsetCopy(&pRsp->rspOffset, &pOffset);
pRsp->blockData = taosArrayInit(0, sizeof(void*));
pRsp->blockDataLen = taosArrayInit(0, sizeof(int32_t));
if (pRsp->blockData == NULL || pRsp->blockDataLen == NULL) {
return -1;
return TSDB_CODE_OUT_OF_MEMORY;
}
tOffsetCopy(&pRsp->reqOffset, &pOffset);
tOffsetCopy(&pRsp->rspOffset, &pOffset);
pRsp->withTbName = 0;
pRsp->withSchema = false;
return 0;
@ -72,7 +71,7 @@ static int32_t tqInitTaosxRsp(SMqDataRspCommon* pRsp, STqOffsetVal pOffset) {
taosArrayDestroy(pRsp->blockSchema);
pRsp->blockSchema = NULL;
}
return -1;
return TSDB_CODE_OUT_OF_MEMORY;
}
return 0;
@ -81,12 +80,13 @@ static int32_t tqInitTaosxRsp(SMqDataRspCommon* pRsp, STqOffsetVal pOffset) {
static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
SRpcMsg* pMsg, bool* pBlockReturned) {
uint64_t consumerId = pRequest->consumerId;
STqOffset* pOffset = (STqOffset*)tqMetaGetOffset(pTq, pRequest->subKey);
STqOffset* pOffset = NULL;
int32_t code = tqMetaGetOffset(pTq, pRequest->subKey, &pOffset);
int32_t vgId = TD_VID(pTq->pVnode);
*pBlockReturned = false;
// In this vnode, data has been polled by consumer for this topic, so let's continue from the last offset value.
if (pOffset != NULL) {
if (code == 0) {
tOffsetCopy(pOffsetVal, &pOffset->val);
char formatBuf[TSDB_OFFSET_LEN] = {0};
@ -116,10 +116,13 @@ static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHand
SMqDataRsp dataRsp = {0};
tqOffsetResetToLog(pOffsetVal, pHandle->pRef->refVer + 1);
tqInitDataRsp(&dataRsp.common, *pOffsetVal);
code = tqInitDataRsp(&dataRsp.common, *pOffsetVal);
if (code != 0){
return code;
}
tqDebug("tmq poll: consumer:0x%" PRIx64 ", subkey %s, vgId:%d, (latest) offset reset to %" PRId64, consumerId,
pHandle->subKey, vgId, dataRsp.common.rspOffset.version);
int32_t code = tqSendDataRsp(pHandle, pMsg, pRequest, &dataRsp, TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
code = tqSendDataRsp(pHandle, pMsg, pRequest, &dataRsp, TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
tDeleteMqDataRsp(&dataRsp);
*pBlockReturned = true;
@ -128,8 +131,7 @@ static int32_t extractResetOffsetVal(STqOffsetVal* pOffsetVal, STQ* pTq, STqHand
tqError("tmq poll: subkey:%s, no offset committed for consumer:0x%" PRIx64
" in vg %d, subkey %s, reset none failed",
pHandle->subKey, consumerId, vgId, pRequest->subKey);
terrno = TSDB_CODE_TQ_NO_COMMITTED_OFFSET;
return -1;
return TSDB_CODE_TQ_NO_COMMITTED_OFFSET;
}
}
@ -143,10 +145,13 @@ static int32_t extractDataAndRspForNormalSubscribe(STQ* pTq, STqHandle* pHandle,
terrno = 0;
SMqDataRsp dataRsp = {0};
tqInitDataRsp(&dataRsp.common, *pOffset);
int code = tqInitDataRsp(&dataRsp.common, *pOffset);
if (code != 0) {
goto end;
}
qSetTaskId(pHandle->execHandle.task, consumerId, pRequest->reqId);
int code = tqScanData(pTq, pHandle, &dataRsp, pOffset, pRequest);
code = tqScanData(pTq, pHandle, &dataRsp, pOffset, pRequest);
if (code != 0 && terrno != TSDB_CODE_WAL_LOG_NOT_EXIST) {
goto end;
}
@ -201,17 +206,14 @@ static void tDeleteCommon(void* parm) {}
static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle, const SMqPollReq* pRequest,
SRpcMsg* pMsg, STqOffsetVal* offset) {
int code = 0;
int32_t vgId = TD_VID(pTq->pVnode);
STaosxRsp taosxRsp = {0};
SMqBatchMetaRsp btMetaRsp = {0};
tqInitTaosxRsp(&taosxRsp.common, *offset);
int32_t vgId = TD_VID(pTq->pVnode);
STaosxRsp taosxRsp = {0};
SMqBatchMetaRsp btMetaRsp = {0};
int32_t code = 0;
TQ_ERR_GO_TO_END(tqInitTaosxRsp(&taosxRsp.common, *offset));
if (offset->type != TMQ_OFFSET__LOG) {
if (tqScanTaosx(pTq, pHandle, &taosxRsp, &btMetaRsp, offset) < 0) {
code = -1;
goto end;
}
TQ_ERR_GO_TO_END(tqScanTaosx(pTq, pHandle, &taosxRsp, &btMetaRsp, offset));
if (taosArrayGetSize(btMetaRsp.batchMetaReq) > 0) {
code = tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
@ -219,8 +221,7 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
",ts:%" PRId64,
pRequest->consumerId, pHandle->subKey, vgId, btMetaRsp.rspOffset.type, btMetaRsp.rspOffset.uid,
btMetaRsp.rspOffset.ts);
tDeleteMqBatchMetaRsp(&btMetaRsp);
goto end;
goto END;
}
tqDebug("taosx poll: consumer:0x%" PRIx64 " subkey:%s vgId:%d, send data blockNum:%d, offset type:%d,uid:%" PRId64
@ -229,7 +230,7 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
taosxRsp.common.rspOffset.uid, taosxRsp.common.rspOffset.ts);
if (taosxRsp.common.blockNum > 0) {
code = tqSendDataRsp(pHandle, pMsg, pRequest, &taosxRsp, TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
goto end;
goto END;
} else {
tOffsetCopy(offset, &taosxRsp.common.rspOffset);
}
@ -249,15 +250,15 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
if (tqFetchLog(pTq, pHandle, &fetchVer, pRequest->reqId) < 0) {
if (totalMetaRows > 0) {
tqOffsetResetToLog(&btMetaRsp.rspOffset, fetchVer);
tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
code = tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
ASSERT(totalRows == 0);
goto end;
goto END;
}
tqOffsetResetToLog(&taosxRsp.common.rspOffset, fetchVer);
code = tqSendDataRsp(
pHandle, pMsg, pRequest, &taosxRsp,
taosxRsp.createTableNum > 0 ? TMQ_MSG_TYPE__POLL_DATA_META_RSP : TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
goto end;
goto END;
}
SWalCont* pHead = &pHandle->pWalReader->pHead->head;
@ -271,7 +272,7 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
code = tqSendDataRsp(
pHandle, pMsg, pRequest, &taosxRsp,
taosxRsp.createTableNum > 0 ? TMQ_MSG_TYPE__POLL_DATA_META_RSP : TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
goto end;
goto END;
}
if ((pRequest->sourceExcluded & TD_REQ_FROM_TAOX) != 0) {
@ -295,12 +296,20 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
metaRsp.metaRspLen = pHead->bodyLen;
metaRsp.metaRsp = pHead->body;
code = tqSendMetaPollRsp(pHandle, pMsg, pRequest, &metaRsp, vgId);
goto end;
goto END;
}
if (!btMetaRsp.batchMetaReq) {
btMetaRsp.batchMetaReq = taosArrayInit(4, POINTER_BYTES);
if (btMetaRsp.batchMetaReq == NULL) {
code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
goto END;
}
btMetaRsp.batchMetaLen = taosArrayInit(4, sizeof(int32_t));
if (btMetaRsp.batchMetaLen == NULL) {
code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
goto END;
}
}
fetchVer++;
@ -316,30 +325,40 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
}
int32_t tLen = sizeof(SMqRspHead) + len;
void* tBuf = taosMemoryCalloc(1, tLen);
if (tBuf == NULL){
code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
goto END;
}
void* metaBuff = POINTER_SHIFT(tBuf, sizeof(SMqRspHead));
SEncoder encoder = {0};
tEncoderInit(&encoder, metaBuff, len);
code = tEncodeMqMetaRsp(&encoder, &tmpMetaRsp);
tEncoderClear(&encoder);
if (code < 0) {
tEncoderClear(&encoder);
tqError("tmq extract meta from log, tEncodeMqMetaRsp error");
continue;
}
taosArrayPush(btMetaRsp.batchMetaReq, &tBuf);
taosArrayPush(btMetaRsp.batchMetaLen, &tLen);
totalMetaRows++;
if (taosArrayPush(btMetaRsp.batchMetaReq, &tBuf) == NULL){
code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
goto END;
}
if (taosArrayPush(btMetaRsp.batchMetaLen, &tLen) == NULL){
code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
goto END;
}
if ((taosArrayGetSize(btMetaRsp.batchMetaReq) >= tmqRowSize) || (taosGetTimestampMs() - st > 1000)) {
tqOffsetResetToLog(&btMetaRsp.rspOffset, fetchVer);
tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
goto end;
code = tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
goto END;
}
continue;
}
if (totalMetaRows > 0) {
tqOffsetResetToLog(&btMetaRsp.rspOffset, fetchVer);
tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
goto end;
code = tqSendBatchMetaPollRsp(pHandle, pMsg, pRequest, &btMetaRsp, vgId);
goto END;
}
// process data
@ -353,7 +372,7 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
if (code < 0) {
tqError("tmq poll: tqTaosxScanLog error %" PRId64 ", in vgId:%d, subkey %s", pRequest->consumerId, vgId,
pRequest->subKey);
goto end;
goto END;
}
if (totalRows >= tmqRowSize || (taosGetTimestampMs() - st > 1000)) {
@ -361,14 +380,14 @@ static int32_t extractDataAndRspForDbStbSubscribe(STQ* pTq, STqHandle* pHandle,
code = tqSendDataRsp(
pHandle, pMsg, pRequest, &taosxRsp,
taosxRsp.createTableNum > 0 ? TMQ_MSG_TYPE__POLL_DATA_META_RSP : TMQ_MSG_TYPE__POLL_DATA_RSP, vgId);
goto end;
goto END;
} else {
fetchVer++;
}
}
}
end:
END:
tDeleteMqBatchMetaRsp(&btMetaRsp);
tDeleteSTaosxRsp(&taosxRsp);
return code;
@ -423,12 +442,12 @@ int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SM
int32_t code = 0;
tEncodeSize(tEncodeMqBatchMetaRsp, pRsp, len, code);
if (code < 0) {
return -1;
return TAOS_GET_TERRNO(code);
}
int32_t tlen = sizeof(SMqRspHead) + len;
void* buf = rpcMallocCont(tlen);
if (buf == NULL) {
return -1;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
int64_t sver = 0, ever = 0;
@ -439,9 +458,12 @@ int32_t tqSendBatchMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SM
SEncoder encoder = {0};
tEncoderInit(&encoder, abuf, len);
tEncodeMqBatchMetaRsp(&encoder, pRsp);
code = tEncodeMqBatchMetaRsp(&encoder, pRsp);
tEncoderClear(&encoder);
if (code < 0) {
rpcFreeCont(buf);
return TAOS_GET_TERRNO(code);
}
SRpcMsg resp = {.info = pMsg->info, .pCont = buf, .contLen = tlen, .code = 0};
tmsgSendRsp(&resp);
@ -457,12 +479,12 @@ int32_t tqSendMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPoll
int32_t code = 0;
tEncodeSize(tEncodeMqMetaRsp, pRsp, len, code);
if (code < 0) {
return -1;
return TAOS_GET_TERRNO(code);
}
int32_t tlen = sizeof(SMqRspHead) + len;
void* buf = rpcMallocCont(tlen);
if (buf == NULL) {
return -1;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
int64_t sver = 0, ever = 0;
@ -473,8 +495,12 @@ int32_t tqSendMetaPollRsp(STqHandle* pHandle, const SRpcMsg* pMsg, const SMqPoll
SEncoder encoder = {0};
tEncoderInit(&encoder, abuf, len);
tEncodeMqMetaRsp(&encoder, pRsp);
code = tEncodeMqMetaRsp(&encoder, pRsp);
tEncoderClear(&encoder);
if (code < 0) {
rpcFreeCont(buf);
return TAOS_GET_TERRNO(code);
}
SRpcMsg resp = {.info = pMsg->info, .pCont = buf, .contLen = tlen, .code = 0};
@ -497,13 +523,13 @@ int32_t tqDoSendDataRsp(const SRpcHandleInfo* pRpcHandleInfo, const void* pRsp,
}
if (code < 0) {
return -1;
return TAOS_GET_TERRNO(code);
}
int32_t tlen = sizeof(SMqRspHead) + len;
void* buf = rpcMallocCont(tlen);
if (buf == NULL) {
return -1;
return TSDB_CODE_OUT_OF_MEMORY;
}
SMqRspHead* pHead = (SMqRspHead*)buf;
@ -515,12 +541,15 @@ int32_t tqDoSendDataRsp(const SRpcHandleInfo* pRpcHandleInfo, const void* pRsp,
tEncoderInit(&encoder, abuf, len);
if (type == TMQ_MSG_TYPE__POLL_DATA_RSP || type == TMQ_MSG_TYPE__WALINFO_RSP) {
tEncodeMqDataRsp(&encoder, pRsp);
code = tEncodeMqDataRsp(&encoder, pRsp);
} else if (type == TMQ_MSG_TYPE__POLL_DATA_META_RSP) {
tEncodeSTaosxRsp(&encoder, pRsp);
code = tEncodeSTaosxRsp(&encoder, pRsp);
}
tEncoderClear(&encoder);
if (code < 0) {
rpcFreeCont(buf);
return TAOS_GET_TERRNO(code);
}
SRpcMsg rsp = {.info = *pRpcHandleInfo, .pCont = buf, .contLen = tlen, .code = 0};
tmsgSendRsp(&rsp);
@ -528,49 +557,61 @@ int32_t tqDoSendDataRsp(const SRpcHandleInfo* pRpcHandleInfo, const void* pRsp,
}
int32_t tqExtractDelDataBlock(const void* pData, int32_t len, int64_t ver, void** pRefBlock, int32_t type) {
int32_t code;
int32_t code = 0;
int32_t line = 0;
SDecoder* pCoder = &(SDecoder){0};
SDeleteRes* pRes = &(SDeleteRes){0};
*pRefBlock = NULL;
pRes->uidList = taosArrayInit(0, sizeof(tb_uid_t));
if (pRes->uidList == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
TSDB_CHECK_NULL(pRes->uidList, code, line, END, terrno)
tDecoderInit(pCoder, (uint8_t*)pData, len);
tDecodeDeleteRes(pCoder, pRes);
tDecoderClear(pCoder);
code = tDecodeDeleteRes(pCoder, pRes);
TSDB_CHECK_CODE(code, line, END);
int32_t numOfTables = taosArrayGetSize(pRes->uidList);
if (numOfTables == 0 || pRes->affectedRows == 0) {
taosArrayDestroy(pRes->uidList);
return TSDB_CODE_SUCCESS;
goto END;
}
SSDataBlock* pDelBlock = createSpecialDataBlock(STREAM_DELETE_DATA);
blockDataEnsureCapacity(pDelBlock, numOfTables);
TSDB_CHECK_NULL(pDelBlock, code, line, END, terrno)
code = blockDataEnsureCapacity(pDelBlock, numOfTables);
TSDB_CHECK_CODE(code, line, END);
pDelBlock->info.rows = numOfTables;
pDelBlock->info.version = ver;
for (int32_t i = 0; i < numOfTables; i++) {
// start key column
SColumnInfoData* pStartCol = taosArrayGet(pDelBlock->pDataBlock, START_TS_COLUMN_INDEX);
colDataSetVal(pStartCol, i, (const char*)&pRes->skey, false); // end key column
TSDB_CHECK_NULL(pStartCol, code, line, END, terrno)
code = colDataSetVal(pStartCol, i, (const char*)&pRes->skey, false); // end key column
TSDB_CHECK_CODE(code, line, END);
SColumnInfoData* pEndCol = taosArrayGet(pDelBlock->pDataBlock, END_TS_COLUMN_INDEX);
colDataSetVal(pEndCol, i, (const char*)&pRes->ekey, false);
TSDB_CHECK_NULL(pEndCol, code, line, END, terrno)
code = colDataSetVal(pEndCol, i, (const char*)&pRes->ekey, false);
TSDB_CHECK_CODE(code, line, END);
// uid column
SColumnInfoData* pUidCol = taosArrayGet(pDelBlock->pDataBlock, UID_COLUMN_INDEX);
int64_t* pUid = taosArrayGet(pRes->uidList, i);
colDataSetVal(pUidCol, i, (const char*)pUid, false);
TSDB_CHECK_NULL(pUidCol, code, line, END, terrno)
colDataSetNULL(taosArrayGet(pDelBlock->pDataBlock, GROUPID_COLUMN_INDEX), i);
colDataSetNULL(taosArrayGet(pDelBlock->pDataBlock, CALCULATE_START_TS_COLUMN_INDEX), i);
colDataSetNULL(taosArrayGet(pDelBlock->pDataBlock, CALCULATE_END_TS_COLUMN_INDEX), i);
int64_t* pUid = taosArrayGet(pRes->uidList, i);
code = colDataSetVal(pUidCol, i, (const char*)pUid, false);
TSDB_CHECK_CODE(code, line, END);
void* tmp = taosArrayGet(pDelBlock->pDataBlock, GROUPID_COLUMN_INDEX);
TSDB_CHECK_NULL(tmp, code, line, END, terrno)
colDataSetNULL(tmp, i);
tmp = taosArrayGet(pDelBlock->pDataBlock, CALCULATE_START_TS_COLUMN_INDEX);
TSDB_CHECK_NULL(tmp, code, line, END, terrno)
colDataSetNULL(tmp, i);
tmp = taosArrayGet(pDelBlock->pDataBlock, CALCULATE_END_TS_COLUMN_INDEX);
TSDB_CHECK_NULL(tmp, code, line, END, terrno)
colDataSetNULL(tmp, i);
}
taosArrayDestroy(pRes->uidList);
if (type == 0) {
code = taosAllocateQitem(sizeof(SStreamRefDataBlock), DEF_QITEM, 0, pRefBlock);
if (code) {
@ -587,7 +628,13 @@ int32_t tqExtractDelDataBlock(const void* pData, int32_t len, int64_t ver, void*
ASSERTS(0, "unknown type:%d", type);
}
return TSDB_CODE_SUCCESS;
END:
if (code != 0){
tqError("failed to extract delete data block, line:%d code:%d", line, code);
}
tDecoderClear(pCoder);
taosArrayDestroy(pRes->uidList);
return code;
}
int32_t tqGetStreamExecInfo(SVnode* pVnode, int64_t streamId, int64_t* pDelay, bool* fhFinished) {
@ -612,6 +659,9 @@ int32_t tqGetStreamExecInfo(SVnode* pVnode, int64_t streamId, int64_t* pDelay, b
for (int32_t i = 0; i < numOfTasks; ++i) {
SStreamTaskId* pId = taosArrayGet(pMeta->pTaskList, i);
if (pId == NULL){
continue;
}
if (pId->streamId != streamId) {
continue;
}

View File

@ -459,8 +459,7 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC
}
// sma required the tq is initialized before the vnode open
pVnode->pTq = tqOpen(tdir, pVnode);
if (pVnode->pTq == NULL) {
if (tqOpen(tdir, pVnode)) {
vError("vgId:%d, failed to open vnode tq since %s", TD_VID(pVnode), tstrerror(terrno));
goto _err;
}

View File

@ -370,8 +370,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
goto _exit;
} else {
pReader->tqHandleDone = 1;
code = tqSnapReaderClose(&pReader->pTqSnapReader);
TSDB_CHECK_CODE(code, lino, _exit);
tqSnapReaderClose(&pReader->pTqSnapReader);
}
}
if (!pReader->tqCheckInfoDone) {
@ -387,8 +386,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
goto _exit;
} else {
pReader->tqCheckInfoDone = 1;
code = tqSnapReaderClose(&pReader->pTqCheckInfoReader);
TSDB_CHECK_CODE(code, lino, _exit);
tqSnapReaderClose(&pReader->pTqCheckInfoReader);
}
}
if (!pReader->tqOffsetDone) {
@ -404,8 +402,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
goto _exit;
} else {
pReader->tqOffsetDone = 1;
code = tqSnapReaderClose(&pReader->pTqOffsetReader);
TSDB_CHECK_CODE(code, lino, _exit);
tqSnapReaderClose(&pReader->pTqOffsetReader);
}
}

View File

@ -827,9 +827,7 @@ static int32_t execAlterLocal(SAlterLocalStmt* pStmt) {
return terrno;
}
if (taosCfgDynamicOptions(tsCfg, pStmt->config, false)) {
return terrno;
}
TAOS_CHECK_RETURN(taosCfgDynamicOptions(tsCfg, pStmt->config, false));
_return:

View File

@ -470,11 +470,7 @@ int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableI
}
int32_t numOfQualifiedTables = taosArrayGetSize(qa);
qDebug("%d qualified child tables added into stream scanner, %s", numOfQualifiedTables, id);
code = pTaskInfo->storageAPI.tqReaderFn.tqReaderAddTables(pScanInfo->tqReader, qa);
if (code != TSDB_CODE_SUCCESS) {
taosArrayDestroy(qa);
return code;
}
pTaskInfo->storageAPI.tqReaderFn.tqReaderAddTables(pScanInfo->tqReader, qa);
bool assignUid = false;
size_t bufLen = (pScanInfo->pGroupTags != NULL) ? getTableTagsBufLen(pScanInfo->pGroupTags) : 0;
@ -528,7 +524,7 @@ int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableI
} else { // remove the table id in current list
qDebug("%d remove child tables from the stream scanner, %s", (int32_t)taosArrayGetSize(tableIdList), id);
taosWLockLatch(&pTaskInfo->lock);
code = pTaskInfo->storageAPI.tqReaderFn.tqReaderRemoveTables(pScanInfo->tqReader, tableIdList);
pTaskInfo->storageAPI.tqReaderFn.tqReaderRemoveTables(pScanInfo->tqReader, tableIdList);
taosWUnLockLatch(&pTaskInfo->lock);
}
@ -958,7 +954,7 @@ int32_t qGetExplainExecInfo(qTaskInfo_t tinfo, SArray* pExecInfoList) {
return getOperatorExplainExecInfo(pTaskInfo->pRoot, pExecInfoList);
}
int32_t qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner) {
void qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner) {
SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
SOperatorInfo* pOperator = pTaskInfo->pRoot;
@ -966,7 +962,7 @@ int32_t qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner) {
uint16_t type = pOperator->operatorType;
if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
*scanner = pOperator->info;
return 0;
break;
} else {
ASSERT(pOperator->numOfDownstream == 1);
pOperator = pOperator->pDownstream[0];
@ -1215,7 +1211,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
if (subType == TOPIC_SUB_TYPE__COLUMN && pOffset->type == TMQ_OFFSET__LOG) {
pOperator = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id);
if (pOperator == NULL) {
return -1;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
SStreamScanInfo* pInfo = pOperator->info;
SStoreTqReader* pReaderAPI = &pTaskInfo->storageAPI.tqReaderFn;
@ -1230,7 +1226,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
if (subType == TOPIC_SUB_TYPE__COLUMN) {
pOperator = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id);
if (pOperator == NULL) {
return -1;
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
}
SStreamScanInfo* pInfo = pOperator->info;
@ -1245,9 +1241,10 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
SStoreTqReader* pReaderAPI = &pTaskInfo->storageAPI.tqReaderFn;
SWalReader* pWalReader = pReaderAPI->tqReaderGetWalReader(pInfo->tqReader);
walReaderVerifyOffset(pWalReader, pOffset);
if (pReaderAPI->tqReaderSeek(pInfo->tqReader, pOffset->version, id) < 0) {
code = pReaderAPI->tqReaderSeek(pInfo->tqReader, pOffset->version, id);
if (code < 0) {
qError("tqReaderSeek failed ver:%" PRId64 ", %s", pOffset->version, id);
return -1;
return code;
}
} else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
// iterate all tables from tableInfoList, and retrieve rows from each table one-by-one
@ -1262,15 +1259,14 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
if (uid == 0) {
if (numOfTables != 0) {
STableKeyInfo* pTableInfo = tableListGetInfo(pTableListInfo, 0);
uid = pTableInfo->uid;
STableKeyInfo* tmp = tableListGetInfo(pTableListInfo, 0);
if (tmp) uid = tmp->uid;
ts = INT64_MIN;
pScanInfo->currentTable = 0;
} else {
taosRUnLockLatch(&pTaskInfo->lock);
qError("no table in table list, %s", id);
terrno = TSDB_CODE_TMQ_NO_TABLE_QUALIFIED;
return -1;
return TSDB_CODE_TMQ_NO_TABLE_QUALIFIED;
}
}
pTaskInfo->storageAPI.tqReaderFn.tqSetTablePrimaryKey(pInfo->tqReader, uid);
@ -1290,8 +1286,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
} else {
qError("vgId:%d uid:%" PRIu64 " not found in table list, total:%d, index:%d %s", pTaskInfo->id.vgId, uid,
numOfTables, pScanInfo->currentTable, id);
terrno = TSDB_CODE_TMQ_NO_TABLE_QUALIFIED;
return -1;
return TSDB_CODE_TMQ_NO_TABLE_QUALIFIED;
}
STableKeyInfo keyInfo = {.uid = uid};
@ -1311,8 +1306,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
(void**)&pScanBaseInfo->dataReader, id, NULL);
if (code != TSDB_CODE_SUCCESS) {
qError("prepare read tsdb snapshot failed, uid:%" PRId64 ", code:%s %s", pOffset->uid, tstrerror(code), id);
terrno = code;
return -1;
return code;
}
qDebug("tsdb reader created with offset(snapshot) uid:%" PRId64 " ts:%" PRId64 " table index:%d, total:%d, %s",
@ -1337,8 +1331,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
pScanBaseInfo->cond.twindows.skey = oldSkey;
} else {
qError("invalid pOffset->type:%d, %s", pOffset->type, id);
terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
return -1;
return TSDB_CODE_PAR_INTERNAL_ERROR;
}
} else { // subType == TOPIC_SUB_TYPE__TABLE/TOPIC_SUB_TYPE__DB
@ -1351,11 +1344,14 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
if (pAPI->snapshotFn.setForSnapShot(sContext, pOffset->uid) != 0) {
qError("setDataForSnapShot error. uid:%" PRId64 " , %s", pOffset->uid, id);
terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
return -1;
return TSDB_CODE_PAR_INTERNAL_ERROR;
}
SMetaTableInfo mtInfo = pTaskInfo->storageAPI.snapshotFn.getMetaTableInfoFromSnapshot(sContext);
SMetaTableInfo mtInfo = {0};
code = pTaskInfo->storageAPI.snapshotFn.getMetaTableInfoFromSnapshot(sContext, &mtInfo);
if (code != 0){
return code;
}
pTaskInfo->storageAPI.tsdReader.tsdReaderClose(pInfo->dataReader);
pInfo->dataReader = NULL;
@ -1363,6 +1359,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
tableListClear(pTableListInfo);
if (mtInfo.uid == 0) {
tDeleteSchemaWrapper(mtInfo.schema);
goto end; // no data
}
@ -1370,6 +1367,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
code = initQueryTableDataCondForTmq(&pTaskInfo->streamInfo.tableCond, sContext, &mtInfo);
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
tDeleteSchemaWrapper(mtInfo.schema);
return code;
}
if (pAPI->snapshotFn.taosXGetTablePrimaryKey(sContext)) {
@ -1380,6 +1378,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
code = tableListAddTableInfo(pTableListInfo, mtInfo.uid, 0);
if (code != TSDB_CODE_SUCCESS) {
tDeleteSchemaWrapper(mtInfo.schema);
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
return code;
}
@ -1391,11 +1390,12 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
NULL, (void**)&pInfo->dataReader, NULL, NULL);
if (code != TSDB_CODE_SUCCESS) {
qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
tDeleteSchemaWrapper(mtInfo.schema);
return code;
}
cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
strcpy(pTaskInfo->streamInfo.tbName, mtInfo.tbName);
tstrncpy(pTaskInfo->streamInfo.tbName, mtInfo.tbName, TSDB_TABLE_NAME_LEN);
tDeleteSchemaWrapper(pTaskInfo->streamInfo.schema);
pTaskInfo->streamInfo.schema = mtInfo.schema;
@ -1403,10 +1403,10 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT
} else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_META) {
SStreamRawScanInfo* pInfo = pOperator->info;
SSnapContext* sContext = pInfo->sContext;
if (pTaskInfo->storageAPI.snapshotFn.setForSnapShot(sContext, pOffset->uid) != 0) {
code = pTaskInfo->storageAPI.snapshotFn.setForSnapShot(sContext, pOffset->uid);
if (code != 0) {
qError("setForSnapShot error. uid:%" PRIu64 " ,version:%" PRId64, pOffset->uid, pOffset->version);
terrno = TSDB_CODE_PAR_INTERNAL_ERROR;
return -1;
return code;
}
qDebug("tmqsnap qStreamPrepareScan snapshot meta uid:%" PRId64 " ts %" PRId64 " %s", pOffset->uid, pOffset->ts,
id);

View File

@ -3457,7 +3457,13 @@ static int32_t doRawScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
}
}
SMetaTableInfo mtInfo = pAPI->snapshotFn.getMetaTableInfoFromSnapshot(pInfo->sContext);
SMetaTableInfo mtInfo = {0};
code = pAPI->snapshotFn.getMetaTableInfoFromSnapshot(pInfo->sContext, &mtInfo);
QUERY_CHECK_CODE(code, lino, _end);
if (code != 0) {
tDeleteSchemaWrapper(mtInfo.schema);
goto _end;
}
STqOffsetVal offset = {0};
if (mtInfo.uid == 0 || pInfo->sContext->withMeta == ONLY_META) { // read snapshot done, change to get data from wal
qDebug("tmqsnap read snapshot done, change to get data from wal");
@ -3467,9 +3473,9 @@ static int32_t doRawScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) {
tqOffsetResetToData(&offset, mtInfo.uid, INT64_MIN, val);
qDebug("tmqsnap change get data uid:%" PRId64 "", mtInfo.uid);
}
tDeleteSchemaWrapper(mtInfo.schema);
code = qStreamPrepareScan(pTaskInfo, &offset, pInfo->sContext->subType);
QUERY_CHECK_CODE(code, lino, _end);
tDeleteSchemaWrapper(mtInfo.schema);
(*ppRes) = NULL;
return code;
} else if (pTaskInfo->streamInfo.currentOffset.type == TMQ_OFFSET__SNAPSHOT_META) {
@ -3560,7 +3566,7 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) {
static void destroyRawScanOperatorInfo(void* param) {
SStreamRawScanInfo* pRawScan = (SStreamRawScanInfo*)param;
pRawScan->pAPI->tsdReader.tsdReaderClose(pRawScan->dataReader);
(void)pRawScan->pAPI->snapshotFn.destroySnapshot(pRawScan->sContext);
pRawScan->pAPI->snapshotFn.destroySnapshot(pRawScan->sContext);
tableListDestroy(pRawScan->pTableListInfo);
taosMemoryFree(pRawScan);
}
@ -3890,13 +3896,7 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
SArray* tableIdList = NULL;
code = extractTableIdList(((STableScanInfo*)(pInfo->pTableScanOp->info))->base.pTableListInfo, &tableIdList);
QUERY_CHECK_CODE(code, lino, _error);
code = pAPI->tqReaderFn.tqReaderSetQueryTableList(pInfo->tqReader, tableIdList, idstr);
if (code != 0) {
taosArrayDestroy(tableIdList);
goto _error;
}
pAPI->tqReaderFn.tqReaderSetQueryTableList(pInfo->tqReader, tableIdList, idstr);
taosArrayDestroy(tableIdList);
memcpy(&pTaskInfo->streamInfo.tableCond, &pTSInfo->base.cond, sizeof(SQueryTableDataCond));
} else {

View File

@ -29,7 +29,7 @@ void geosFreeBuffer(void *buffer) {
void geosErrMsgeHandler(const char *errMsg, void *userData) {
char *targetErrMsg = userData;
snprintf(targetErrMsg, 512, "%s", errMsg);
(void)snprintf(targetErrMsg, 512, "%s", errMsg);
}
int32_t initCtxMakePoint() {
@ -94,7 +94,7 @@ static int32_t initWktRegex(pcre2_code **ppRegex, pcre2_match_data **ppMatchData
return TSDB_CODE_OUT_OF_MEMORY;
}
sprintf(
(void)sprintf(
wktPatternWithSpace,
"^( *)point( *)z?m?( *)((empty)|(\\(( *)(([-+]?[0-9]+\\.?[0-9]*)|([-+]?[0-9]*\\.?[0-9]+))(e[-+]?[0-9]+)?(( "
"*)(([-+]?[0-9]+\\.?[0-9]*)|([-+]?[0-9]*\\.?[0-9]+))(e[-+]?[0-9]+)?){1,3}( *)\\)))|linestring( *)z?m?( "
@ -264,7 +264,7 @@ int32_t doAsText(const unsigned char *inputGeom, size_t size, char **outputWKT)
SGeosContext *geosCtx = getThreadLocalGeosCtx();
GEOSGeometry *geom = NULL;
unsigned char *wkt = NULL;
char *wkt = NULL;
geom = GEOSWKBReader_read_r(geosCtx->handle, geosCtx->WKBReader, inputGeom, size);
if (geom == NULL) {

View File

@ -42,7 +42,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url);
extern char **environ;
int32_t cfgInit(SConfig ** ppCfg) {
int32_t cfgInit(SConfig **ppCfg) {
SConfig *pCfg = taosMemoryCalloc(1, sizeof(SConfig));
if (pCfg == NULL) {
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
@ -54,7 +54,7 @@ int32_t cfgInit(SConfig ** ppCfg) {
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
taosThreadMutexInit(&pCfg->lock, NULL);
TAOS_CHECK_RETURN(taosThreadMutexInit(&pCfg->lock, NULL));
*ppCfg = pCfg;
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
@ -113,7 +113,7 @@ void cfgCleanup(SConfig *pCfg) {
}
taosArrayDestroy(pCfg->array);
taosThreadMutexDestroy(&pCfg->lock);
(void)taosThreadMutexDestroy(&pCfg->lock);
taosMemoryFree(pCfg);
}
@ -244,17 +244,17 @@ static int32_t doSetConf(SConfigItem *pItem, const char *value, ECfgSrcType styp
static int32_t cfgSetTimezone(SConfigItem *pItem, const char *value, ECfgSrcType stype) {
TAOS_CHECK_RETURN(doSetConf(pItem, value, stype));
osSetTimezone(value);
TAOS_CHECK_RETURN(osSetTimezone(value));
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value, const char *level, const char *primary,
const char *disable, ECfgSrcType stype) {
taosThreadMutexLock(&pCfg->lock);
(void)taosThreadMutexLock(&pCfg->lock);
SConfigItem *pItem = cfgGetItem(pCfg, name);
if (pItem == NULL) {
taosThreadMutexUnlock(&pCfg->lock);
(void)taosThreadMutexUnlock(&pCfg->lock);
TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND);
}
@ -262,7 +262,7 @@ static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value,
if (pItem->array == NULL) {
pItem->array = taosArrayInit(16, sizeof(SDiskCfg));
if (pItem->array == NULL) {
taosThreadMutexUnlock(&pCfg->lock);
(void)taosThreadMutexUnlock(&pCfg->lock);
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
@ -275,13 +275,13 @@ static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value,
cfg.disable = disable ? atoi(disable) : 0;
void *ret = taosArrayPush(pItem->array, &cfg);
if (ret == NULL) {
taosThreadMutexUnlock(&pCfg->lock);
(void)taosThreadMutexUnlock(&pCfg->lock);
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
pItem->stype = stype;
taosThreadMutexUnlock(&pCfg->lock);
(void)taosThreadMutexUnlock(&pCfg->lock);
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
@ -307,7 +307,7 @@ static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool rese
if (pDebugFlagItem == NULL) return -1;
if (pDebugFlagItem->array != NULL) {
SLogVar logVar = {0};
strncpy(logVar.name, name, TSDB_LOG_VAR_LEN - 1);
(void)strncpy(logVar.name, name, TSDB_LOG_VAR_LEN - 1);
if (NULL == taosArrayPush(pDebugFlagItem->array, &logVar)) {
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
@ -317,15 +317,15 @@ static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool rese
int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcType stype, bool lock) {
// GRANT_CFG_SET;
int32_t code = 0;
int32_t code = TSDB_CODE_SUCCESS;
if (lock) {
taosThreadMutexLock(&pCfg->lock);
(void)taosThreadMutexLock(&pCfg->lock);
}
SConfigItem *pItem = cfgGetItem(pCfg, name);
if (pItem == NULL) {
taosThreadMutexUnlock(&pCfg->lock);
(void)taosThreadMutexUnlock(&pCfg->lock);
TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND);
}
@ -374,7 +374,7 @@ int32_t cfgSetItem(SConfig *pCfg, const char *name, const char *value, ECfgSrcTy
}
if (lock) {
taosThreadMutexUnlock(&pCfg->lock);
(void)taosThreadMutexUnlock(&pCfg->lock);
}
TAOS_RETURN(code);
@ -398,12 +398,10 @@ void cfgLock(SConfig *pCfg) {
return;
}
taosThreadMutexLock(&pCfg->lock);
(void)taosThreadMutexLock(&pCfg->lock);
}
void cfgUnLock(SConfig *pCfg) {
taosThreadMutexUnlock(&pCfg->lock);
}
void cfgUnLock(SConfig *pCfg) { (void)taosThreadMutexUnlock(&pCfg->lock); }
int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *pVal, bool isServer) {
ECfgDynType dynType = isServer ? CFG_DYN_SERVER : CFG_DYN_CLIENT;
@ -420,11 +418,13 @@ int32_t cfgCheckRangeForDynUpdate(SConfig *pCfg, const char *name, const char *p
switch (pItem->dtype) {
case CFG_DTYPE_STRING: {
if (strcasecmp(name, "slowLogScope") == 0) {
char *tmp = taosStrdup(pVal);
if (taosSetSlowLogScope(tmp) < 0) {
char *tmp = taosStrdup(pVal);
int32_t scope = 0;
int32_t code = taosSetSlowLogScope(tmp, &scope);
if (TSDB_CODE_SUCCESS != code) {
cfgUnLock(pCfg);
taosMemoryFree(tmp);
TAOS_RETURN(TSDB_CODE_INVALID_CFG);
TAOS_RETURN(code);
}
taosMemoryFree(tmp);
}
@ -506,7 +506,7 @@ static int32_t cfgAddItem(SConfig *pCfg, SConfigItem *pItem, const char *name) {
int32_t len = strlen(name);
char lowcaseName[CFG_NAME_MAX_LEN + 1] = {0};
strntolower(lowcaseName, name, TMIN(CFG_NAME_MAX_LEN, len));
(void)strntolower(lowcaseName, name, TMIN(CFG_NAME_MAX_LEN, len));
if (taosArrayPush(pCfg->array, pItem) == NULL) {
if (pItem->dtype == CFG_DTYPE_STRING) {
@ -721,10 +721,10 @@ int32_t cfgDumpItemScope(SConfigItem *pItem, char *buf, int32_t bufSize, int32_t
void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump) {
if (dump) {
printf(" s3 config");
printf("\n");
printf("=================================================================");
printf("\n");
(void)printf(" s3 config");
(void)printf("\n");
(void)printf("=================================================================");
(void)printf("\n");
} else {
uInfo(" s3 config");
uInfo("=================================================================");
@ -752,7 +752,7 @@ void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump) {
switch (pItem->dtype) {
case CFG_DTYPE_BOOL:
if (dump) {
printf("%s %s %u\n", src, name, pItem->bval);
(void)printf("%s %s %u\n", src, name, pItem->bval);
} else {
uInfo("%s %s %u", src, name, pItem->bval);
}
@ -760,14 +760,14 @@ void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump) {
break;
case CFG_DTYPE_INT32:
if (dump) {
printf("%s %s %d\n", src, name, pItem->i32);
(void)printf("%s %s %d\n", src, name, pItem->i32);
} else {
uInfo("%s %s %d", src, name, pItem->i32);
}
break;
case CFG_DTYPE_INT64:
if (dump) {
printf("%s %s %" PRId64 "\n", src, name, pItem->i64);
(void)printf("%s %s %" PRId64 "\n", src, name, pItem->i64);
} else {
uInfo("%s %s %" PRId64, src, name, pItem->i64);
}
@ -775,7 +775,7 @@ void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump) {
case CFG_DTYPE_DOUBLE:
case CFG_DTYPE_FLOAT:
if (dump) {
printf("%s %s %.2f\n", src, name, pItem->fval);
(void)printf("%s %s %.2f\n", src, name, pItem->fval);
} else {
uInfo("%s %s %.2f", src, name, pItem->fval);
}
@ -787,7 +787,7 @@ void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump) {
case CFG_DTYPE_TIMEZONE:
case CFG_DTYPE_NONE:
if (dump) {
printf("%s %s %s\n", src, name, pItem->str);
(void)printf("%s %s %s\n", src, name, pItem->str);
} else {
uInfo("%s %s %s", src, name, pItem->str);
}
@ -796,7 +796,7 @@ void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump) {
}
if (dump) {
printf("=================================================================\n");
(void)printf("=================================================================\n");
} else {
uInfo("=================================================================");
}
@ -804,10 +804,10 @@ void cfgDumpCfgS3(SConfig *pCfg, bool tsc, bool dump) {
void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
if (dump) {
printf(" global config");
printf("\n");
printf("=================================================================");
printf("\n");
(void)printf(" global config");
(void)printf("\n");
(void)printf("=================================================================");
(void)printf("\n");
} else {
uInfo(" global config");
uInfo("=================================================================");
@ -834,7 +834,7 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
switch (pItem->dtype) {
case CFG_DTYPE_BOOL:
if (dump) {
printf("%s %s %u\n", src, name, pItem->bval);
(void)printf("%s %s %u\n", src, name, pItem->bval);
} else {
uInfo("%s %s %u", src, name, pItem->bval);
}
@ -842,14 +842,14 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
break;
case CFG_DTYPE_INT32:
if (dump) {
printf("%s %s %d\n", src, name, pItem->i32);
(void)printf("%s %s %d\n", src, name, pItem->i32);
} else {
uInfo("%s %s %d", src, name, pItem->i32);
}
break;
case CFG_DTYPE_INT64:
if (dump) {
printf("%s %s %" PRId64 "\n", src, name, pItem->i64);
(void)printf("%s %s %" PRId64 "\n", src, name, pItem->i64);
} else {
uInfo("%s %s %" PRId64, src, name, pItem->i64);
}
@ -857,7 +857,7 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
case CFG_DTYPE_DOUBLE:
case CFG_DTYPE_FLOAT:
if (dump) {
printf("%s %s %.2f\n", src, name, pItem->fval);
(void)printf("%s %s %.2f\n", src, name, pItem->fval);
} else {
uInfo("%s %s %.2f", src, name, pItem->fval);
}
@ -869,7 +869,7 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
case CFG_DTYPE_TIMEZONE:
case CFG_DTYPE_NONE:
if (dump) {
printf("%s %s %s\n", src, name, pItem->str);
(void)printf("%s %s %s\n", src, name, pItem->str);
} else {
uInfo("%s %s %s", src, name, pItem->str);
}
@ -878,7 +878,7 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) {
}
if (dump) {
printf("=================================================================\n");
(void)printf("=================================================================\n");
} else {
uInfo("=================================================================");
}
@ -900,21 +900,21 @@ int32_t cfgLoadFromEnvVar(SConfig *pConfig) {
pEnv++;
(void)taosEnvToCfg(line, line);
paGetToken(line, &name, &olen);
(void)paGetToken(line, &name, &olen);
if (olen == 0) continue;
name[olen] = 0;
paGetToken(name + olen + 1, &value, &vlen);
(void)paGetToken(name + olen + 1, &value, &vlen);
if (vlen == 0) continue;
value[vlen] = 0;
paGetToken(value + vlen + 1, &value2, &vlen2);
(void)paGetToken(value + vlen + 1, &value2, &vlen2);
if (vlen2 != 0) {
value2[vlen2] = 0;
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
(void)paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
if (vlen3 != 0) {
value3[vlen3] = 0;
paGetToken(value3 + vlen3 + 1, &value4, &vlen4);
(void)paGetToken(value3 + vlen3 + 1, &value4, &vlen4);
if (vlen4 != 0) value4[vlen4] = 0;
}
}
@ -947,21 +947,21 @@ int32_t cfgLoadFromEnvCmd(SConfig *pConfig, const char **envCmd) {
name = value = value2 = value3 = value4 = NULL;
olen = vlen = vlen2 = vlen3 = vlen4 = 0;
paGetToken(buf, &name, &olen);
(void)paGetToken(buf, &name, &olen);
if (olen == 0) continue;
name[olen] = 0;
paGetToken(name + olen + 1, &value, &vlen);
(void)paGetToken(name + olen + 1, &value, &vlen);
if (vlen == 0) continue;
value[vlen] = 0;
paGetToken(value + vlen + 1, &value2, &vlen2);
(void)paGetToken(value + vlen + 1, &value2, &vlen2);
if (vlen2 != 0) {
value2[vlen2] = 0;
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
(void)paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
if (vlen3 != 0) {
value3[vlen3] = 0;
paGetToken(value3 + vlen3 + 1, &value4, &vlen4);
(void)paGetToken(value3 + vlen3 + 1, &value4, &vlen4);
if (vlen4 != 0) value4[vlen4] = 0;
}
}
@ -1015,21 +1015,21 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
if (line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
(void)taosEnvToCfg(line, line);
paGetToken(line, &name, &olen);
(void)paGetToken(line, &name, &olen);
if (olen == 0) continue;
name[olen] = 0;
paGetToken(name + olen + 1, &value, &vlen);
(void)paGetToken(name + olen + 1, &value, &vlen);
if (vlen == 0) continue;
value[vlen] = 0;
paGetToken(value + vlen + 1, &value2, &vlen2);
(void)paGetToken(value + vlen + 1, &value2, &vlen2);
if (vlen2 != 0) {
value2[vlen2] = 0;
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
(void)paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
if (vlen3 != 0) {
value3[vlen3] = 0;
paGetToken(value3 + vlen3 + 1, &value4, &vlen4);
(void)paGetToken(value3 + vlen3 + 1, &value4, &vlen4);
if (vlen4 != 0) value4[vlen4] = 0;
}
}
@ -1043,7 +1043,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
}
}
taosCloseFile(&pFile);
(void)taosCloseFile(&pFile);
uInfo("load from env cfg file %s success", filepath);
TAOS_RETURN(TSDB_CODE_SUCCESS);
@ -1079,11 +1079,11 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
if (line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
paGetToken(line, &name, &olen);
(void)paGetToken(line, &name, &olen);
if (olen == 0) continue;
name[olen] = 0;
paGetToken(name + olen + 1, &value, &vlen);
(void)paGetToken(name + olen + 1, &value, &vlen);
if (vlen == 0) continue;
value[vlen] = 0;
@ -1096,7 +1096,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
int32_t count = 1;
while (vlen < 1024) {
paGetToken(value + vlen + 1 * count, &tmp, &len);
(void)paGetToken(value + vlen + 1 * count, &tmp, &len);
if (len == 0) break;
tmp[len] = 0;
strcpy(newValue + vlen, tmp);
@ -1107,13 +1107,13 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
code = cfgSetItem(pConfig, name, newValue, CFG_STYPE_CFG_FILE, true);
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_CFG_NOT_FOUND != code) break;
} else {
paGetToken(value + vlen + 1, &value2, &vlen2);
(void)paGetToken(value + vlen + 1, &value2, &vlen2);
if (vlen2 != 0) {
value2[vlen2] = 0;
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
(void)paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
if (vlen3 != 0) {
value3[vlen3] = 0;
paGetToken(value3 + vlen3 + 1, &value4, &vlen4);
(void)paGetToken(value3 + vlen3 + 1, &value4, &vlen4);
if (vlen4 != 0) value4[vlen4] = 0;
}
}
@ -1136,7 +1136,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
}
}
taosCloseFile(&pFile);
(void)taosCloseFile(&pFile);
if (TSDB_CODE_SUCCESS == code || TSDB_CODE_CFG_NOT_FOUND == code) {
uInfo("load from cfg file %s success", filepath);
@ -1177,18 +1177,18 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
// if(line[_bytes - 1] == '\n') line[_bytes - 1] = 0;
// paGetToken(line, &name, &olen);
// (void)paGetToken(line, &name, &olen);
// if (olen == 0) continue;
// name[olen] = 0;
// paGetToken(name + olen + 1, &value, &vlen);
// (void)paGetToken(name + olen + 1, &value, &vlen);
// if (vlen == 0) continue;
// value[vlen] = 0;
// paGetToken(value + vlen + 1, &value2, &vlen2);
// (void)paGetToken(value + vlen + 1, &value2, &vlen2);
// if (vlen2 != 0) {
// value2[vlen2] = 0;
// paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
// (void)paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
// if (vlen3 != 0) value3[vlen3] = 0;
// }
@ -1200,7 +1200,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
// }
// }
// taosCloseFile(&pFile);
// (void)taosCloseFile(&pFile);
// if (line != NULL) taosMemoryFreeClear(line);
// if (code == 0 || (code != 0 && terrno == TSDB_CODE_CFG_NOT_FOUND)) {
@ -1243,20 +1243,20 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END);
char *buf = taosMemoryMalloc(fileSize + 1);
if (!buf) {
taosCloseFile(&pFile);
(void)taosCloseFile(&pFile);
uError("load json file error: %s, failed to alloc memory", filepath);
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
buf[fileSize] = 0;
taosLSeekFile(pFile, 0, SEEK_SET);
(void)taosLSeekFile(pFile, 0, SEEK_SET);
if (taosReadFile(pFile, buf, fileSize) <= 0) {
taosCloseFile(&pFile);
(void)taosCloseFile(&pFile);
uError("load json file error: %s", filepath);
taosMemoryFreeClear(buf);
TAOS_RETURN(TSDB_CODE_INVALID_DATA_FMT);
}
taosCloseFile(&pFile);
(void)taosCloseFile(&pFile);
pJson = tjsonParse(buf);
if (NULL == pJson) {
const char *jsonParseError = tjsonGetError();
@ -1284,25 +1284,24 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
goto _err_json;
}
memcpy(cfgLineBuf, itemName, itemNameLen);
(void)memcpy(cfgLineBuf, itemName, itemNameLen);
cfgLineBuf[itemNameLen] = ' ';
memcpy(&cfgLineBuf[itemNameLen + 1], itemValueString, itemValueStringLen);
paGetToken(cfgLineBuf, &name, &olen);
(void)memcpy(&cfgLineBuf[itemNameLen + 1], itemValueString, itemValueStringLen);
(void)paGetToken(cfgLineBuf, &name, &olen);
if (olen == 0) continue;
name[olen] = 0;
paGetToken(name + olen + 1, &value, &vlen);
(void)paGetToken(name + olen + 1, &value, &vlen);
if (vlen == 0) continue;
value[vlen] = 0;
paGetToken(value + vlen + 1, &value2, &vlen2);
(void)paGetToken(value + vlen + 1, &value2, &vlen2);
if (vlen2 != 0) {
value2[vlen2] = 0;
paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
(void)paGetToken(value2 + vlen2 + 1, &value3, &vlen3);
if (vlen3 != 0) {
value3[vlen3] = 0;
paGetToken(value3 + vlen3 + 1, &value4, &vlen4);
(void)paGetToken(value3 + vlen3 + 1, &value4, &vlen4);
if (vlen4 != 0) value4[vlen4] = 0;
}
}
@ -1346,7 +1345,7 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl
p++;
p[strlen(p) - 1] = '\0';
}
memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
(void)memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
uInfo("get apollo url from env cmd success");
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
@ -1368,7 +1367,7 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl
p++;
p[strlen(p) - 1] = '\0';
}
memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
(void)memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
uInfo("get apollo url from env variables success, apolloUrl=%s", apolloUrl);
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
@ -1405,14 +1404,14 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl
p++;
p[strlen(p) - 1] = '\0';
}
memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
taosCloseFile(&pFile);
(void)memcpy(apolloUrl, p, TMIN(strlen(p) + 1, PATH_MAX));
(void)taosCloseFile(&pFile);
uInfo("get apollo url from env file success");
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
}
}
taosCloseFile(&pFile);
(void)taosCloseFile(&pFile);
}
uInfo("fail get apollo url from cmd env file");
@ -1436,7 +1435,7 @@ int32_t cfgCreateIter(SConfig *pConf, SConfigIter **ppIter) {
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
SConfigItem *cfgNextIter(SConfigIter* pIter) {
SConfigItem *cfgNextIter(SConfigIter *pIter) {
if (pIter->index < cfgGetSize(pIter->pConf)) {
return taosArrayGet(pIter->pConf->array, pIter->index++);
}