TDengine/source/dnode/mnode/impl/src/mndDef.c

981 lines
32 KiB
C
Raw Normal View History

2022-03-10 09:15:45 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2022-05-07 01:36:36 +00:00
#define _DEFAULT_SOURCE
#include "mndConsumer.h"
2024-11-18 11:52:41 +00:00
#include "mndDef.h"
2024-07-20 01:25:18 +00:00
#include "taoserror.h"
2024-11-21 06:30:28 +00:00
#include "tunit.h"
feat: support customized taos/taosd (#29736) * feat: support TDAcoreOS * chore: cmake options for TD_ACORE * chore: disable lemon for TD_ACORE * chore: add lzma2 and msvcregex * chore: cmake for lzma2 * chore: adapt for TD_ACORE * chore: adapt strcasecmp for TD_ACORE * chore: adapt for geos/threadName * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE termio * chore: refact transComm.h for TD_ACORE * chore: refact transportInt.h for TD_ACORE * chore: refact trans.c for TD_ACORE * chore: refact trpc.h for TD_ACORE * chore: refact transCli.c/transComm.c/transSvr.c for TD_ACORE * chore: refact uv.h for TD_ACORE * chore: refact geosWrapper.h for TD_ACORE * chore: refact token/builtins/udf for TD_ACORE * chore: refact rocks for TD_ACORE * chore: refact tsdbCache.c for TD_ACORE, use LRU cache for last/last_row, not use rocksdb * chore: refact FAIL to _ERR to solve conflicts for TD_ACORE * chore: restore lemon.c/lempar.c * chore: support build lemon for TD_ACORE * chore: refact trpc and siginfo_t for TD_ACORE * chore: refact timezone for TD_ACORE * chore: refact lz4 for TD_ACORE * chore: refact TD_ACORE to make compile pass * chore: code optimization for TD_ASTRA * feat: support run taos with taosd integrated * feat: support invoke taos shell * feat: support invoke taos shell * feat: support invoke taos shell * chore: code optimization * chore: fix undefined reference problem os TD_ASTRA * chore: resolve compile problem for TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix getpid * chore: fix typo * chore: set stack size and ajust min pack size for TD_ASTRA * chore: fix pthread create parameters * chore: chmod adapt for TD_ASTRA * chore: fix trans compile problem * chore: adapt chmod for TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: conditional compile option * chore: adapt for TD_ASTRA * chore: adjust taosPId and msvcregex for TD_ASTRA * chore: log dir separator for wal build name * chore: fix type of pointer parameter * chore: fix compile problem of tsdbGetS3Size * enh: get last ver from wal log for TD_ASTRA * enh: refact wal meta ver * enh: refact wal meta ver * fix: typo of taosUcs4Compare * enh: process return value of CI * chore: more code for TD_ASTRA adaption * chore: return value of taosCloseFile in walMeta.c * chore: fix compile problem * chore: fix compile problem of TD_ASTRA * fix: update macro for tq and stream task * chore: code optimization for TD_ASTRA * chore: restore create log and init cfg interface * chore: restore strncasecmp and strcasecmp * fix: adjust the field position of SDataBlockInfo * fix: pragma pack min size * fix: pragma pack min size * chore: more code for TD_ASTRA adaption * fix: type of parameters * chore: adapt strncasecmp and strcasecmp for TD_ASTRA * chore: restore interface of init log * enh: pack push optimization * fix: taos init cfg * add astra support * fix: fetch the value of suid * chore: switch of build with udf * add temp code * chore: more code for TD_ASTRA adaption * chore: add macro ERRNO to replace errno * chore: bytes align for TD_ASTRA * fix: remove obsolete codes * enh: support USE_UDF macro * fix compile error * fix: resolve redefinition problem * fix: compile problem of log.cpp * fix: compile problem of osTimezone * fix: resolve compile problem of udf * fix: pragma definition on windows * fix: ucs4 and stpncpy for TD_ASTRA * fix: memory align problem for TD_ASTRA * enh: solve memory leak for TD_ASTRA_RPC * fix: compile problem of taosSetInt64Aligned * fix: restore mndSubscribe.c * fix: scalar for udf * chore: code adaption for TD_ASTRA * chore: code optimization for TD_ASTRA * fix: typo of add definition * fix: typo of macro in tudf.h * chore: remove void to make CI pass * enh: move macro from cmake.platform to cmake.options * enh: byte align for hash node and error code * chore: restore the size for lru cache * enh: restore some code about pack push * chore: restore the pack push in tmsg.h * fix: add macro of pack pop for windows --------- Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 05:32:13 +00:00
#ifdef USE_STREAM
2024-01-22 03:05:42 +00:00
static void *freeStreamTasks(SArray *pTaskLevel);
2022-05-15 00:05:26 +00:00
int32_t tEncodeSStreamObj(SEncoder *pEncoder, const SStreamObj *pObj) {
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tStartEncode(pEncoder));
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->createTime));
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->updateTime));
TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->version));
TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->totalLevel));
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->smaId));
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->uid));
TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->status));
TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->conf.igExpired));
TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->conf.trigger));
TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->conf.fillHistory));
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->conf.triggerParam));
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->conf.watermark));
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->sourceDbUid));
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->targetDbUid));
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->sourceDb));
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->targetDb));
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->targetSTbName));
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->targetStbUid));
TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->fixedSinkVgId));
2022-06-16 08:22:58 +00:00
2022-09-30 06:03:46 +00:00
if (pObj->sql != NULL) {
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->sql));
2022-09-30 06:03:46 +00:00
} else {
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
2022-09-30 06:03:46 +00:00
}
if (pObj->ast != NULL) {
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->ast));
2022-09-30 06:03:46 +00:00
} else {
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
2022-09-30 06:03:46 +00:00
}
if (pObj->physicalPlan != NULL) {
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->physicalPlan));
2022-09-30 06:03:46 +00:00
} else {
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
2022-09-30 06:03:46 +00:00
}
2022-05-15 00:05:26 +00:00
feat(stream): add new trigger continuous_window_close (#30125) * opt stream build twa result * opt force window close memory * feat(stream):optimize new interval and scan operator * adj log * opt code * opt code * fill history * fix issue for fill history * add ci * feat(stream): add new stream nonblock interval operator * adjust code * use new scan operator * use new scan operator * add log * fix issue * recover stream scan next function * fix issue * fix issue * fix issue * ignore disorder data * fix issue * fix issue for interval sliding * fix issue * fix ci issue * fix ci issue * fix ci issue * add semi && final nonblock interval operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * refactor(stream): track the msgId for each upstream tasks. * fix(stream): fix race condition. * fix(stream): update the task last msgId when putting into input queue succ. * fix issue * fix issue * put recalculate data to rocksdb * fix issue * fix issue * enh(query)[TD-33071]: add support for saving and restoring tsdbReader scan progress - Implement functionality to save scan progress during tsdbReader operations - Enable resuming scans from the last saved position * fix issue * fix issue * fix issue * fix issue * fix issue * add rec interval check * enh(stream):add recalculate tasks. * enh(stream): support the re-calculate the tasks. * fix issue && do refactor * do refactor * fix issue * fix issue * update backend opt * add new interface * add new session operator * support blob * add new session operator * fix issue * add rec state for rec task * fix invalid read * add new session window * enh(stream): update the stream tasks backend. * new session operator * add pull data * fix(stream): fix error in expand stream backend. * fix issue * fix issue * fix issue * merge code * fix issue * fix(stream): check for null ptr. * fix(stream): add more check. * fix issue * fix issue * fix issue * add debug code * fix issue * fix issue * fix issue * set rec end flag * fix(stream): opt re-calculate stream tasks. * fix issue * fix issue * add new operator * enh(stream): dispatch recalculate block to agg tasks. * fix issue * fix issue * fix(stream): adjust filter. * fix issue * refactor * refactor(stream): adjust the recalculate end block. * fix issue * fix(stream): set correct create trigger block. * fix issue * fix(stream): fix error in build recalculate end block. * fix(stream): check null ptr. * add stream client && fix issue * fix mem leak * fix(stream): free msg. * add stream client * fix(stream): fix error. * add stream client && fix issue * add stream client * refactor(stream): set the recalculate task complete. * add wend and group_id for session window dest table * feat(stream): refactor and set the recalcul agg task complete. * add cfg for adapter * fix issue * add state && event operator * feat(stream): support fill-history task. * add new fill operator * fix(stream): set correct backend when updating fill-history task to recalculate task. * add new fill operator * fix(stream): s2025-03-06 11:10:31.272 et ops always open in scan tsdb * fix(stream):set the correct taskType for sink task. * new fill operator * adj stream fill operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * adj test * fix issue * fix(stream): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix: ut com error * fix(stream): fix mem leak and adjust operator type check rule * fix(stream): fix mem leak and adjust test case * refactor code * fix(stream): free items. * fix(stream): free fix memory leak. * fix(stream): fix syntax error. * fix: ignore unexpect block * fix: adjust op type --------- Co-authored-by: Haojun Liao <hjliao@taosdata.com> Co-authored-by: Jinqing Kuang <kuangjinqingcn@gmail.com> Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 12:14:01 +00:00
int32_t sz = taosArrayGetSize(pObj->pTaskList);
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeI32(pEncoder, sz));
2022-05-15 00:05:26 +00:00
for (int32_t i = 0; i < sz; i++) {
feat(stream): add new trigger continuous_window_close (#30125) * opt stream build twa result * opt force window close memory * feat(stream):optimize new interval and scan operator * adj log * opt code * opt code * fill history * fix issue for fill history * add ci * feat(stream): add new stream nonblock interval operator * adjust code * use new scan operator * use new scan operator * add log * fix issue * recover stream scan next function * fix issue * fix issue * fix issue * ignore disorder data * fix issue * fix issue for interval sliding * fix issue * fix ci issue * fix ci issue * fix ci issue * add semi && final nonblock interval operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * refactor(stream): track the msgId for each upstream tasks. * fix(stream): fix race condition. * fix(stream): update the task last msgId when putting into input queue succ. * fix issue * fix issue * put recalculate data to rocksdb * fix issue * fix issue * enh(query)[TD-33071]: add support for saving and restoring tsdbReader scan progress - Implement functionality to save scan progress during tsdbReader operations - Enable resuming scans from the last saved position * fix issue * fix issue * fix issue * fix issue * fix issue * add rec interval check * enh(stream):add recalculate tasks. * enh(stream): support the re-calculate the tasks. * fix issue && do refactor * do refactor * fix issue * fix issue * update backend opt * add new interface * add new session operator * support blob * add new session operator * fix issue * add rec state for rec task * fix invalid read * add new session window * enh(stream): update the stream tasks backend. * new session operator * add pull data * fix(stream): fix error in expand stream backend. * fix issue * fix issue * fix issue * merge code * fix issue * fix(stream): check for null ptr. * fix(stream): add more check. * fix issue * fix issue * fix issue * add debug code * fix issue * fix issue * fix issue * set rec end flag * fix(stream): opt re-calculate stream tasks. * fix issue * fix issue * add new operator * enh(stream): dispatch recalculate block to agg tasks. * fix issue * fix issue * fix(stream): adjust filter. * fix issue * refactor * refactor(stream): adjust the recalculate end block. * fix issue * fix(stream): set correct create trigger block. * fix issue * fix(stream): fix error in build recalculate end block. * fix(stream): check null ptr. * add stream client && fix issue * fix mem leak * fix(stream): free msg. * add stream client * fix(stream): fix error. * add stream client && fix issue * add stream client * refactor(stream): set the recalculate task complete. * add wend and group_id for session window dest table * feat(stream): refactor and set the recalcul agg task complete. * add cfg for adapter * fix issue * add state && event operator * feat(stream): support fill-history task. * add new fill operator * fix(stream): set correct backend when updating fill-history task to recalculate task. * add new fill operator * fix(stream): s2025-03-06 11:10:31.272 et ops always open in scan tsdb * fix(stream):set the correct taskType for sink task. * new fill operator * adj stream fill operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * adj test * fix issue * fix(stream): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix: ut com error * fix(stream): fix mem leak and adjust operator type check rule * fix(stream): fix mem leak and adjust test case * refactor code * fix(stream): free items. * fix(stream): free fix memory leak. * fix(stream): fix syntax error. * fix: ignore unexpect block * fix: adjust op type --------- Co-authored-by: Haojun Liao <hjliao@taosdata.com> Co-authored-by: Jinqing Kuang <kuangjinqingcn@gmail.com> Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 12:14:01 +00:00
SArray *pArray = taosArrayGetP(pObj->pTaskList, i);
2022-05-15 00:05:26 +00:00
int32_t innerSz = taosArrayGetSize(pArray);
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeI32(pEncoder, innerSz));
2022-05-15 00:05:26 +00:00
for (int32_t j = 0; j < innerSz; j++) {
SStreamTask *pTask = taosArrayGetP(pArray, j);
2024-11-18 11:52:41 +00:00
if (pTask->ver < SSTREAM_TASK_SUBTABLE_CHANGED_VER) {
pTask->ver = SSTREAM_TASK_VER;
}
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeStreamTask(pEncoder, pTask));
2022-05-15 00:05:26 +00:00
}
}
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeSSchemaWrapper(pEncoder, &pObj->outputSchema));
2022-06-16 08:22:58 +00:00
2023-06-16 09:28:54 +00:00
// 3.0.20 ver =2
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->checkpointFreq));
TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->igCheckUpdate));
2023-06-16 09:28:54 +00:00
// 3.0.50 ver = 3
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->checkpointId));
TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->subTableWithoutMd5));
2023-06-16 09:28:50 +00:00
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tEncodeCStrWithLen(pEncoder, pObj->reserve, sizeof(pObj->reserve) - 1));
2023-08-31 01:28:43 +00:00
2022-10-21 01:47:04 +00:00
tEndEncode(pEncoder);
2022-05-15 00:05:26 +00:00
return pEncoder->pos;
}
2022-12-01 23:57:22 +00:00
int32_t tDecodeSStreamObj(SDecoder *pDecoder, SStreamObj *pObj, int32_t sver) {
2024-07-20 01:25:18 +00:00
int32_t code = 0;
TAOS_CHECK_RETURN(tStartDecode(pDecoder));
TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->name));
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->createTime));
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->updateTime));
TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->version));
TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->totalLevel));
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->smaId));
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->uid));
TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->status));
TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->conf.igExpired));
TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->conf.trigger));
TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->conf.fillHistory));
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->conf.triggerParam));
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->conf.watermark));
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->sourceDbUid));
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->targetDbUid));
TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->sourceDb));
TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->targetDb));
TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->targetSTbName));
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->targetStbUid));
TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->fixedSinkVgId));
TAOS_CHECK_RETURN(tDecodeCStrAlloc(pDecoder, &pObj->sql));
TAOS_CHECK_RETURN(tDecodeCStrAlloc(pDecoder, &pObj->ast));
TAOS_CHECK_RETURN(tDecodeCStrAlloc(pDecoder, &pObj->physicalPlan));
2022-06-16 08:22:58 +00:00
feat(stream): add new trigger continuous_window_close (#30125) * opt stream build twa result * opt force window close memory * feat(stream):optimize new interval and scan operator * adj log * opt code * opt code * fill history * fix issue for fill history * add ci * feat(stream): add new stream nonblock interval operator * adjust code * use new scan operator * use new scan operator * add log * fix issue * recover stream scan next function * fix issue * fix issue * fix issue * ignore disorder data * fix issue * fix issue for interval sliding * fix issue * fix ci issue * fix ci issue * fix ci issue * add semi && final nonblock interval operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * refactor(stream): track the msgId for each upstream tasks. * fix(stream): fix race condition. * fix(stream): update the task last msgId when putting into input queue succ. * fix issue * fix issue * put recalculate data to rocksdb * fix issue * fix issue * enh(query)[TD-33071]: add support for saving and restoring tsdbReader scan progress - Implement functionality to save scan progress during tsdbReader operations - Enable resuming scans from the last saved position * fix issue * fix issue * fix issue * fix issue * fix issue * add rec interval check * enh(stream):add recalculate tasks. * enh(stream): support the re-calculate the tasks. * fix issue && do refactor * do refactor * fix issue * fix issue * update backend opt * add new interface * add new session operator * support blob * add new session operator * fix issue * add rec state for rec task * fix invalid read * add new session window * enh(stream): update the stream tasks backend. * new session operator * add pull data * fix(stream): fix error in expand stream backend. * fix issue * fix issue * fix issue * merge code * fix issue * fix(stream): check for null ptr. * fix(stream): add more check. * fix issue * fix issue * fix issue * add debug code * fix issue * fix issue * fix issue * set rec end flag * fix(stream): opt re-calculate stream tasks. * fix issue * fix issue * add new operator * enh(stream): dispatch recalculate block to agg tasks. * fix issue * fix issue * fix(stream): adjust filter. * fix issue * refactor * refactor(stream): adjust the recalculate end block. * fix issue * fix(stream): set correct create trigger block. * fix issue * fix(stream): fix error in build recalculate end block. * fix(stream): check null ptr. * add stream client && fix issue * fix mem leak * fix(stream): free msg. * add stream client * fix(stream): fix error. * add stream client && fix issue * add stream client * refactor(stream): set the recalculate task complete. * add wend and group_id for session window dest table * feat(stream): refactor and set the recalcul agg task complete. * add cfg for adapter * fix issue * add state && event operator * feat(stream): support fill-history task. * add new fill operator * fix(stream): set correct backend when updating fill-history task to recalculate task. * add new fill operator * fix(stream): s2025-03-06 11:10:31.272 et ops always open in scan tsdb * fix(stream):set the correct taskType for sink task. * new fill operator * adj stream fill operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * adj test * fix issue * fix(stream): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix: ut com error * fix(stream): fix mem leak and adjust operator type check rule * fix(stream): fix mem leak and adjust test case * refactor code * fix(stream): free items. * fix(stream): free fix memory leak. * fix(stream): fix syntax error. * fix: ignore unexpect block * fix: adjust op type --------- Co-authored-by: Haojun Liao <hjliao@taosdata.com> Co-authored-by: Jinqing Kuang <kuangjinqingcn@gmail.com> Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 12:14:01 +00:00
if (pObj->pTaskList != NULL) {
pObj->pTaskList = freeStreamTasks(pObj->pTaskList);
2024-01-22 03:05:42 +00:00
}
2022-05-15 00:05:26 +00:00
int32_t sz;
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &sz));
2024-01-22 03:05:42 +00:00
2022-05-15 00:05:26 +00:00
if (sz != 0) {
feat(stream): add new trigger continuous_window_close (#30125) * opt stream build twa result * opt force window close memory * feat(stream):optimize new interval and scan operator * adj log * opt code * opt code * fill history * fix issue for fill history * add ci * feat(stream): add new stream nonblock interval operator * adjust code * use new scan operator * use new scan operator * add log * fix issue * recover stream scan next function * fix issue * fix issue * fix issue * ignore disorder data * fix issue * fix issue for interval sliding * fix issue * fix ci issue * fix ci issue * fix ci issue * add semi && final nonblock interval operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * refactor(stream): track the msgId for each upstream tasks. * fix(stream): fix race condition. * fix(stream): update the task last msgId when putting into input queue succ. * fix issue * fix issue * put recalculate data to rocksdb * fix issue * fix issue * enh(query)[TD-33071]: add support for saving and restoring tsdbReader scan progress - Implement functionality to save scan progress during tsdbReader operations - Enable resuming scans from the last saved position * fix issue * fix issue * fix issue * fix issue * fix issue * add rec interval check * enh(stream):add recalculate tasks. * enh(stream): support the re-calculate the tasks. * fix issue && do refactor * do refactor * fix issue * fix issue * update backend opt * add new interface * add new session operator * support blob * add new session operator * fix issue * add rec state for rec task * fix invalid read * add new session window * enh(stream): update the stream tasks backend. * new session operator * add pull data * fix(stream): fix error in expand stream backend. * fix issue * fix issue * fix issue * merge code * fix issue * fix(stream): check for null ptr. * fix(stream): add more check. * fix issue * fix issue * fix issue * add debug code * fix issue * fix issue * fix issue * set rec end flag * fix(stream): opt re-calculate stream tasks. * fix issue * fix issue * add new operator * enh(stream): dispatch recalculate block to agg tasks. * fix issue * fix issue * fix(stream): adjust filter. * fix issue * refactor * refactor(stream): adjust the recalculate end block. * fix issue * fix(stream): set correct create trigger block. * fix issue * fix(stream): fix error in build recalculate end block. * fix(stream): check null ptr. * add stream client && fix issue * fix mem leak * fix(stream): free msg. * add stream client * fix(stream): fix error. * add stream client && fix issue * add stream client * refactor(stream): set the recalculate task complete. * add wend and group_id for session window dest table * feat(stream): refactor and set the recalcul agg task complete. * add cfg for adapter * fix issue * add state && event operator * feat(stream): support fill-history task. * add new fill operator * fix(stream): set correct backend when updating fill-history task to recalculate task. * add new fill operator * fix(stream): s2025-03-06 11:10:31.272 et ops always open in scan tsdb * fix(stream):set the correct taskType for sink task. * new fill operator * adj stream fill operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * adj test * fix issue * fix(stream): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix: ut com error * fix(stream): fix mem leak and adjust operator type check rule * fix(stream): fix mem leak and adjust test case * refactor code * fix(stream): free items. * fix(stream): free fix memory leak. * fix(stream): fix syntax error. * fix: ignore unexpect block * fix: adjust op type --------- Co-authored-by: Haojun Liao <hjliao@taosdata.com> Co-authored-by: Jinqing Kuang <kuangjinqingcn@gmail.com> Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 12:14:01 +00:00
pObj->pTaskList = taosArrayInit(sz, sizeof(void *));
if (pObj->pTaskList == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
2024-07-20 01:25:18 +00:00
TAOS_RETURN(code);
}
2024-01-22 03:05:42 +00:00
2022-05-15 00:05:26 +00:00
for (int32_t i = 0; i < sz; i++) {
int32_t innerSz;
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &innerSz));
2022-05-15 00:05:26 +00:00
SArray *pArray = taosArrayInit(innerSz, sizeof(void *));
2024-07-20 01:25:18 +00:00
if (pArray != NULL) {
for (int32_t j = 0; j < innerSz; j++) {
SStreamTask *pTask = taosMemoryCalloc(1, sizeof(SStreamTask));
if (pTask == NULL) {
taosArrayDestroy(pArray);
code = terrno;
2024-07-20 01:25:18 +00:00
TAOS_RETURN(code);
}
if ((code = tDecodeStreamTask(pDecoder, pTask)) < 0) {
taosMemoryFree(pTask);
taosArrayDestroy(pArray);
TAOS_RETURN(code);
}
2024-07-25 09:49:58 +00:00
if (taosArrayPush(pArray, &pTask) == NULL) {
taosMemoryFree(pTask);
taosArrayDestroy(pArray);
2024-09-12 07:46:30 +00:00
code = terrno;
2024-07-25 09:49:58 +00:00
TAOS_RETURN(code);
}
}
2022-05-15 00:05:26 +00:00
}
feat(stream): add new trigger continuous_window_close (#30125) * opt stream build twa result * opt force window close memory * feat(stream):optimize new interval and scan operator * adj log * opt code * opt code * fill history * fix issue for fill history * add ci * feat(stream): add new stream nonblock interval operator * adjust code * use new scan operator * use new scan operator * add log * fix issue * recover stream scan next function * fix issue * fix issue * fix issue * ignore disorder data * fix issue * fix issue for interval sliding * fix issue * fix ci issue * fix ci issue * fix ci issue * add semi && final nonblock interval operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * refactor(stream): track the msgId for each upstream tasks. * fix(stream): fix race condition. * fix(stream): update the task last msgId when putting into input queue succ. * fix issue * fix issue * put recalculate data to rocksdb * fix issue * fix issue * enh(query)[TD-33071]: add support for saving and restoring tsdbReader scan progress - Implement functionality to save scan progress during tsdbReader operations - Enable resuming scans from the last saved position * fix issue * fix issue * fix issue * fix issue * fix issue * add rec interval check * enh(stream):add recalculate tasks. * enh(stream): support the re-calculate the tasks. * fix issue && do refactor * do refactor * fix issue * fix issue * update backend opt * add new interface * add new session operator * support blob * add new session operator * fix issue * add rec state for rec task * fix invalid read * add new session window * enh(stream): update the stream tasks backend. * new session operator * add pull data * fix(stream): fix error in expand stream backend. * fix issue * fix issue * fix issue * merge code * fix issue * fix(stream): check for null ptr. * fix(stream): add more check. * fix issue * fix issue * fix issue * add debug code * fix issue * fix issue * fix issue * set rec end flag * fix(stream): opt re-calculate stream tasks. * fix issue * fix issue * add new operator * enh(stream): dispatch recalculate block to agg tasks. * fix issue * fix issue * fix(stream): adjust filter. * fix issue * refactor * refactor(stream): adjust the recalculate end block. * fix issue * fix(stream): set correct create trigger block. * fix issue * fix(stream): fix error in build recalculate end block. * fix(stream): check null ptr. * add stream client && fix issue * fix mem leak * fix(stream): free msg. * add stream client * fix(stream): fix error. * add stream client && fix issue * add stream client * refactor(stream): set the recalculate task complete. * add wend and group_id for session window dest table * feat(stream): refactor and set the recalcul agg task complete. * add cfg for adapter * fix issue * add state && event operator * feat(stream): support fill-history task. * add new fill operator * fix(stream): set correct backend when updating fill-history task to recalculate task. * add new fill operator * fix(stream): s2025-03-06 11:10:31.272 et ops always open in scan tsdb * fix(stream):set the correct taskType for sink task. * new fill operator * adj stream fill operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * adj test * fix issue * fix(stream): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix: ut com error * fix(stream): fix mem leak and adjust operator type check rule * fix(stream): fix mem leak and adjust test case * refactor code * fix(stream): free items. * fix(stream): free fix memory leak. * fix(stream): fix syntax error. * fix: ignore unexpect block * fix: adjust op type --------- Co-authored-by: Haojun Liao <hjliao@taosdata.com> Co-authored-by: Jinqing Kuang <kuangjinqingcn@gmail.com> Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 12:14:01 +00:00
if (taosArrayPush(pObj->pTaskList, &pArray) == NULL) {
2024-07-25 09:49:58 +00:00
taosArrayDestroy(pArray);
2024-09-12 07:46:30 +00:00
code = terrno;
2024-07-25 09:49:58 +00:00
TAOS_RETURN(code);
}
2022-05-15 00:05:26 +00:00
}
}
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tDecodeSSchemaWrapper(pDecoder, &pObj->outputSchema));
2022-06-16 08:22:58 +00:00
// 3.0.20
2022-12-01 23:57:22 +00:00
if (sver >= 2) {
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->checkpointFreq));
if (!tDecodeIsEnd(pDecoder)) {
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->igCheckUpdate));
}
2022-12-01 23:57:22 +00:00
}
2023-06-16 09:28:50 +00:00
if (sver >= 3) {
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->checkpointId));
2023-06-16 09:28:50 +00:00
}
if (sver >= 5) {
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tDecodeI8(pDecoder, &pObj->subTableWithoutMd5));
}
2024-07-20 01:25:18 +00:00
TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->reserve));
2023-08-31 01:28:43 +00:00
2022-10-21 01:47:04 +00:00
tEndDecode(pDecoder);
2024-07-20 01:25:18 +00:00
TAOS_RETURN(code);
2022-05-15 00:05:26 +00:00
}
2024-01-22 03:05:42 +00:00
void *freeStreamTasks(SArray *pTaskLevel) {
if (pTaskLevel == NULL) return NULL;
int32_t numOfLevel = taosArrayGetSize(pTaskLevel);
2024-01-22 03:05:42 +00:00
for (int32_t i = 0; i < numOfLevel; i++) {
SArray *pLevel = taosArrayGetP(pTaskLevel, i);
2022-08-18 06:26:11 +00:00
int32_t taskSz = taosArrayGetSize(pLevel);
for (int32_t j = 0; j < taskSz; j++) {
SStreamTask *pTask = taosArrayGetP(pLevel, j);
2024-01-25 08:53:30 +00:00
tFreeStreamTask(pTask);
2022-08-18 06:26:11 +00:00
}
2023-04-08 17:39:09 +00:00
2022-08-18 06:26:11 +00:00
taosArrayDestroy(pLevel);
}
2023-04-08 17:39:09 +00:00
2024-07-12 07:22:39 +00:00
taosArrayDestroy(pTaskLevel);
return NULL;
}
void tFreeStreamObj(SStreamObj *pStream) {
taosMemoryFree(pStream->sql);
taosMemoryFree(pStream->ast);
taosMemoryFree(pStream->physicalPlan);
2023-06-25 02:57:10 +00:00
if (pStream->outputSchema.nCols || pStream->outputSchema.pSchema) {
taosMemoryFree(pStream->outputSchema.pSchema);
}
feat(stream): add new trigger continuous_window_close (#30125) * opt stream build twa result * opt force window close memory * feat(stream):optimize new interval and scan operator * adj log * opt code * opt code * fill history * fix issue for fill history * add ci * feat(stream): add new stream nonblock interval operator * adjust code * use new scan operator * use new scan operator * add log * fix issue * recover stream scan next function * fix issue * fix issue * fix issue * ignore disorder data * fix issue * fix issue for interval sliding * fix issue * fix ci issue * fix ci issue * fix ci issue * add semi && final nonblock interval operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * refactor(stream): track the msgId for each upstream tasks. * fix(stream): fix race condition. * fix(stream): update the task last msgId when putting into input queue succ. * fix issue * fix issue * put recalculate data to rocksdb * fix issue * fix issue * enh(query)[TD-33071]: add support for saving and restoring tsdbReader scan progress - Implement functionality to save scan progress during tsdbReader operations - Enable resuming scans from the last saved position * fix issue * fix issue * fix issue * fix issue * fix issue * add rec interval check * enh(stream):add recalculate tasks. * enh(stream): support the re-calculate the tasks. * fix issue && do refactor * do refactor * fix issue * fix issue * update backend opt * add new interface * add new session operator * support blob * add new session operator * fix issue * add rec state for rec task * fix invalid read * add new session window * enh(stream): update the stream tasks backend. * new session operator * add pull data * fix(stream): fix error in expand stream backend. * fix issue * fix issue * fix issue * merge code * fix issue * fix(stream): check for null ptr. * fix(stream): add more check. * fix issue * fix issue * fix issue * add debug code * fix issue * fix issue * fix issue * set rec end flag * fix(stream): opt re-calculate stream tasks. * fix issue * fix issue * add new operator * enh(stream): dispatch recalculate block to agg tasks. * fix issue * fix issue * fix(stream): adjust filter. * fix issue * refactor * refactor(stream): adjust the recalculate end block. * fix issue * fix(stream): set correct create trigger block. * fix issue * fix(stream): fix error in build recalculate end block. * fix(stream): check null ptr. * add stream client && fix issue * fix mem leak * fix(stream): free msg. * add stream client * fix(stream): fix error. * add stream client && fix issue * add stream client * refactor(stream): set the recalculate task complete. * add wend and group_id for session window dest table * feat(stream): refactor and set the recalcul agg task complete. * add cfg for adapter * fix issue * add state && event operator * feat(stream): support fill-history task. * add new fill operator * fix(stream): set correct backend when updating fill-history task to recalculate task. * add new fill operator * fix(stream): s2025-03-06 11:10:31.272 et ops always open in scan tsdb * fix(stream):set the correct taskType for sink task. * new fill operator * adj stream fill operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * adj test * fix issue * fix(stream): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix: ut com error * fix(stream): fix mem leak and adjust operator type check rule * fix(stream): fix mem leak and adjust test case * refactor code * fix(stream): free items. * fix(stream): free fix memory leak. * fix(stream): fix syntax error. * fix: ignore unexpect block * fix: adjust op type --------- Co-authored-by: Haojun Liao <hjliao@taosdata.com> Co-authored-by: Jinqing Kuang <kuangjinqingcn@gmail.com> Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 12:14:01 +00:00
pStream->pTaskList = freeStreamTasks(pStream->pTaskList);
pStream->pHTaskList = freeStreamTasks(pStream->pHTaskList);
2023-04-08 17:39:09 +00:00
2023-01-10 02:13:56 +00:00
// tagSchema.pSchema
if (pStream->tagSchema.nCols > 0) {
taosMemoryFree(pStream->tagSchema.pSchema);
}
qDestroyQueryPlan(pStream->pPlan);
pStream->pPlan = NULL;
tSimpleHashCleanup(pStream->pVTableMap);
pStream->pVTableMap = NULL;
2022-08-18 06:26:11 +00:00
}
feat: support customized taos/taosd (#29736) * feat: support TDAcoreOS * chore: cmake options for TD_ACORE * chore: disable lemon for TD_ACORE * chore: add lzma2 and msvcregex * chore: cmake for lzma2 * chore: adapt for TD_ACORE * chore: adapt strcasecmp for TD_ACORE * chore: adapt for geos/threadName * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE * chore: build adapt for TD_ACORE termio * chore: refact transComm.h for TD_ACORE * chore: refact transportInt.h for TD_ACORE * chore: refact trans.c for TD_ACORE * chore: refact trpc.h for TD_ACORE * chore: refact transCli.c/transComm.c/transSvr.c for TD_ACORE * chore: refact uv.h for TD_ACORE * chore: refact geosWrapper.h for TD_ACORE * chore: refact token/builtins/udf for TD_ACORE * chore: refact rocks for TD_ACORE * chore: refact tsdbCache.c for TD_ACORE, use LRU cache for last/last_row, not use rocksdb * chore: refact FAIL to _ERR to solve conflicts for TD_ACORE * chore: restore lemon.c/lempar.c * chore: support build lemon for TD_ACORE * chore: refact trpc and siginfo_t for TD_ACORE * chore: refact timezone for TD_ACORE * chore: refact lz4 for TD_ACORE * chore: refact TD_ACORE to make compile pass * chore: code optimization for TD_ASTRA * feat: support run taos with taosd integrated * feat: support invoke taos shell * feat: support invoke taos shell * feat: support invoke taos shell * chore: code optimization * chore: fix undefined reference problem os TD_ASTRA * chore: resolve compile problem for TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix undefined reference problem os TD_ASTRA * chore: fix getpid * chore: fix typo * chore: set stack size and ajust min pack size for TD_ASTRA * chore: fix pthread create parameters * chore: chmod adapt for TD_ASTRA * chore: fix trans compile problem * chore: adapt chmod for TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: more code for adaption of TD_ASTRA * chore: byte alignment for TD_ASTRA * chore: conditional compile option * chore: adapt for TD_ASTRA * chore: adjust taosPId and msvcregex for TD_ASTRA * chore: log dir separator for wal build name * chore: fix type of pointer parameter * chore: fix compile problem of tsdbGetS3Size * enh: get last ver from wal log for TD_ASTRA * enh: refact wal meta ver * enh: refact wal meta ver * fix: typo of taosUcs4Compare * enh: process return value of CI * chore: more code for TD_ASTRA adaption * chore: return value of taosCloseFile in walMeta.c * chore: fix compile problem * chore: fix compile problem of TD_ASTRA * fix: update macro for tq and stream task * chore: code optimization for TD_ASTRA * chore: restore create log and init cfg interface * chore: restore strncasecmp and strcasecmp * fix: adjust the field position of SDataBlockInfo * fix: pragma pack min size * fix: pragma pack min size * chore: more code for TD_ASTRA adaption * fix: type of parameters * chore: adapt strncasecmp and strcasecmp for TD_ASTRA * chore: restore interface of init log * enh: pack push optimization * fix: taos init cfg * add astra support * fix: fetch the value of suid * chore: switch of build with udf * add temp code * chore: more code for TD_ASTRA adaption * chore: add macro ERRNO to replace errno * chore: bytes align for TD_ASTRA * fix: remove obsolete codes * enh: support USE_UDF macro * fix compile error * fix: resolve redefinition problem * fix: compile problem of log.cpp * fix: compile problem of osTimezone * fix: resolve compile problem of udf * fix: pragma definition on windows * fix: ucs4 and stpncpy for TD_ASTRA * fix: memory align problem for TD_ASTRA * enh: solve memory leak for TD_ASTRA_RPC * fix: compile problem of taosSetInt64Aligned * fix: restore mndSubscribe.c * fix: scalar for udf * chore: code adaption for TD_ASTRA * chore: code optimization for TD_ASTRA * fix: typo of add definition * fix: typo of macro in tudf.h * chore: remove void to make CI pass * enh: move macro from cmake.platform to cmake.options * enh: byte align for hash node and error code * chore: restore the size for lru cache * enh: restore some code about pack push * chore: restore the pack push in tmsg.h * fix: add macro of pack pop for windows --------- Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 05:32:13 +00:00
#endif
2022-08-18 06:26:11 +00:00
2023-06-13 09:10:23 +00:00
SMqVgEp *tCloneSMqVgEp(const SMqVgEp *pVgEp) {
SMqVgEp *pVgEpNew = taosMemoryMalloc(sizeof(SMqVgEp));
2024-07-20 01:25:18 +00:00
if (pVgEpNew == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
2023-06-13 09:10:23 +00:00
pVgEpNew->vgId = pVgEp->vgId;
2023-06-16 09:28:50 +00:00
// pVgEpNew->qmsg = taosStrdup(pVgEp->qmsg);
2023-06-13 09:10:23 +00:00
pVgEpNew->epSet = pVgEp->epSet;
return pVgEpNew;
}
2023-06-13 09:10:23 +00:00
void tDeleteSMqVgEp(SMqVgEp *pVgEp) {
if (pVgEp) {
2023-06-16 09:28:50 +00:00
// taosMemoryFreeClear(pVgEp->qmsg);
2023-06-13 09:10:23 +00:00
taosMemoryFree(pVgEp);
}
}
2022-05-15 00:05:26 +00:00
int32_t tEncodeSMqVgEp(void **buf, const SMqVgEp *pVgEp) {
int32_t tlen = 0;
tlen += taosEncodeFixedI32(buf, pVgEp->vgId);
2023-06-16 09:28:50 +00:00
// tlen += taosEncodeString(buf, pVgEp->qmsg);
2022-05-15 00:05:26 +00:00
tlen += taosEncodeSEpSet(buf, &pVgEp->epSet);
return tlen;
}
void *tDecodeSMqVgEp(const void *buf, SMqVgEp *pVgEp, int8_t sver) {
2022-05-15 00:05:26 +00:00
buf = taosDecodeFixedI32(buf, &pVgEp->vgId);
2023-06-16 09:28:50 +00:00
if (sver == 1) {
uint64_t size = 0;
buf = taosDecodeVariantU64(buf, &size);
buf = POINTER_SHIFT(buf, size);
}
2022-05-15 00:05:26 +00:00
buf = taosDecodeSEpSet(buf, &pVgEp->epSet);
return (void *)buf;
}
2024-03-12 11:42:26 +00:00
static void *topicNameDup(void *p) { return taosStrdup((char *)p); }
2024-11-18 11:52:41 +00:00
int32_t tNewSMqConsumerObj(int64_t consumerId, char *cgroup, int8_t updateType, char *topic, SCMSubscribeReq *subscribe,
SMqConsumerObj **ppConsumer) {
int32_t code = 0;
SMqConsumerObj *pConsumer = taosMemoryCalloc(1, sizeof(SMqConsumerObj));
if (pConsumer == NULL) {
code = terrno;
goto END;
}
pConsumer->consumerId = consumerId;
(void)memcpy(pConsumer->cgroup, cgroup, TSDB_CGROUP_LEN);
pConsumer->epoch = 0;
pConsumer->status = MQ_CONSUMER_STATUS_REBALANCE;
pConsumer->hbStatus = 0;
pConsumer->pollStatus = 0;
taosInitRWLatch(&pConsumer->lock);
2024-03-12 11:42:26 +00:00
pConsumer->createTime = taosGetTimestampMs();
pConsumer->updateType = updateType;
2024-11-18 11:52:41 +00:00
if (updateType == CONSUMER_ADD_REB) {
2024-03-12 11:42:26 +00:00
pConsumer->rebNewTopics = taosArrayInit(0, sizeof(void *));
2024-11-18 11:52:41 +00:00
if (pConsumer->rebNewTopics == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
2024-03-12 11:42:26 +00:00
goto END;
}
2024-11-18 11:52:41 +00:00
char *topicTmp = taosStrdup(topic);
if (taosArrayPush(pConsumer->rebNewTopics, &topicTmp) == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
goto END;
}
2024-11-18 11:52:41 +00:00
} else if (updateType == CONSUMER_REMOVE_REB) {
2024-03-12 11:42:26 +00:00
pConsumer->rebRemovedTopics = taosArrayInit(0, sizeof(void *));
2024-11-18 11:52:41 +00:00
if (pConsumer->rebRemovedTopics == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
2024-03-12 11:42:26 +00:00
goto END;
}
2024-11-18 11:52:41 +00:00
char *topicTmp = taosStrdup(topic);
if (taosArrayPush(pConsumer->rebRemovedTopics, &topicTmp) == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
goto END;
}
2024-11-18 11:52:41 +00:00
} else if (updateType == CONSUMER_INSERT_SUB) {
2024-03-12 11:42:26 +00:00
tstrncpy(pConsumer->clientId, subscribe->clientId, tListLen(pConsumer->clientId));
pConsumer->withTbName = subscribe->withTbName;
pConsumer->autoCommit = subscribe->autoCommit;
pConsumer->autoCommitInterval = subscribe->autoCommitInterval;
pConsumer->resetOffsetCfg = subscribe->resetOffsetCfg;
pConsumer->maxPollIntervalMs = subscribe->maxPollIntervalMs;
pConsumer->sessionTimeoutMs = subscribe->sessionTimeoutMs;
tstrncpy(pConsumer->user, subscribe->user, TSDB_USER_LEN);
tstrncpy(pConsumer->fqdn, subscribe->fqdn, TSDB_FQDN_LEN);
2024-03-12 11:42:26 +00:00
pConsumer->rebNewTopics = taosArrayDup(subscribe->topicNames, topicNameDup);
2024-11-18 11:52:41 +00:00
if (pConsumer->rebNewTopics == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
2024-03-12 11:42:26 +00:00
goto END;
}
pConsumer->assignedTopics = subscribe->topicNames;
subscribe->topicNames = NULL;
2024-11-18 11:52:41 +00:00
} else if (updateType == CONSUMER_UPDATE_SUB) {
2024-03-13 11:36:00 +00:00
pConsumer->assignedTopics = subscribe->topicNames;
2024-03-12 11:42:26 +00:00
subscribe->topicNames = NULL;
}
2022-04-27 07:16:57 +00:00
*ppConsumer = pConsumer;
return 0;
2024-03-12 11:42:26 +00:00
END:
tDeleteSMqConsumerObj(pConsumer);
return code;
}
2024-03-12 11:42:26 +00:00
void tClearSMqConsumerObj(SMqConsumerObj *pConsumer) {
2023-08-04 05:52:20 +00:00
if (pConsumer == NULL) return;
2024-07-01 09:22:43 +00:00
taosArrayDestroyP(pConsumer->currentTopics, NULL);
taosArrayDestroyP(pConsumer->rebNewTopics, NULL);
taosArrayDestroyP(pConsumer->rebRemovedTopics, NULL);
taosArrayDestroyP(pConsumer->assignedTopics, NULL);
2024-03-12 11:42:26 +00:00
}
void tDeleteSMqConsumerObj(SMqConsumerObj *pConsumer) {
tClearSMqConsumerObj(pConsumer);
taosMemoryFree(pConsumer);
}
int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) {
int32_t tlen = 0;
int32_t sz;
tlen += taosEncodeFixedI64(buf, pConsumer->consumerId);
2022-07-18 03:41:56 +00:00
tlen += taosEncodeString(buf, pConsumer->clientId);
tlen += taosEncodeString(buf, pConsumer->cgroup);
tlen += taosEncodeFixedI8(buf, pConsumer->updateType);
tlen += taosEncodeFixedI32(buf, pConsumer->epoch);
tlen += taosEncodeFixedI32(buf, pConsumer->status);
2022-04-27 07:16:57 +00:00
tlen += taosEncodeFixedI32(buf, pConsumer->pid);
tlen += taosEncodeSEpSet(buf, &pConsumer->ep);
2023-06-15 07:44:52 +00:00
tlen += taosEncodeFixedI64(buf, pConsumer->createTime);
2022-04-27 07:16:57 +00:00
tlen += taosEncodeFixedI64(buf, pConsumer->subscribeTime);
tlen += taosEncodeFixedI64(buf, pConsumer->rebalanceTime);
// current topics
if (pConsumer->currentTopics) {
sz = taosArrayGetSize(pConsumer->currentTopics);
tlen += taosEncodeFixedI32(buf, sz);
for (int32_t i = 0; i < sz; i++) {
char *topic = taosArrayGetP(pConsumer->currentTopics, i);
tlen += taosEncodeString(buf, topic);
}
} else {
tlen += taosEncodeFixedI32(buf, 0);
}
// reb new topics
if (pConsumer->rebNewTopics) {
sz = taosArrayGetSize(pConsumer->rebNewTopics);
tlen += taosEncodeFixedI32(buf, sz);
for (int32_t i = 0; i < sz; i++) {
char *topic = taosArrayGetP(pConsumer->rebNewTopics, i);
tlen += taosEncodeString(buf, topic);
}
} else {
tlen += taosEncodeFixedI32(buf, 0);
}
// reb removed topics
if (pConsumer->rebRemovedTopics) {
sz = taosArrayGetSize(pConsumer->rebRemovedTopics);
tlen += taosEncodeFixedI32(buf, sz);
for (int32_t i = 0; i < sz; i++) {
char *topic = taosArrayGetP(pConsumer->rebRemovedTopics, i);
tlen += taosEncodeString(buf, topic);
}
} else {
tlen += taosEncodeFixedI32(buf, 0);
}
2022-04-27 09:15:02 +00:00
// lost topics
if (pConsumer->assignedTopics) {
sz = taosArrayGetSize(pConsumer->assignedTopics);
tlen += taosEncodeFixedI32(buf, sz);
for (int32_t i = 0; i < sz; i++) {
char *topic = taosArrayGetP(pConsumer->assignedTopics, i);
tlen += taosEncodeString(buf, topic);
}
} else {
tlen += taosEncodeFixedI32(buf, 0);
}
tlen += taosEncodeFixedI8(buf, pConsumer->withTbName);
tlen += taosEncodeFixedI8(buf, pConsumer->autoCommit);
tlen += taosEncodeFixedI32(buf, pConsumer->autoCommitInterval);
tlen += taosEncodeFixedI32(buf, pConsumer->resetOffsetCfg);
tlen += taosEncodeFixedI32(buf, pConsumer->maxPollIntervalMs);
tlen += taosEncodeFixedI32(buf, pConsumer->sessionTimeoutMs);
tlen += taosEncodeString(buf, pConsumer->user);
tlen += taosEncodeString(buf, pConsumer->fqdn);
return tlen;
}
void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer, int8_t sver) {
int32_t sz;
buf = taosDecodeFixedI64(buf, &pConsumer->consumerId);
2022-07-18 03:41:56 +00:00
buf = taosDecodeStringTo(buf, pConsumer->clientId);
buf = taosDecodeStringTo(buf, pConsumer->cgroup);
buf = taosDecodeFixedI8(buf, &pConsumer->updateType);
buf = taosDecodeFixedI32(buf, &pConsumer->epoch);
buf = taosDecodeFixedI32(buf, &pConsumer->status);
2022-04-27 07:16:57 +00:00
buf = taosDecodeFixedI32(buf, &pConsumer->pid);
buf = taosDecodeSEpSet(buf, &pConsumer->ep);
2023-06-15 07:44:52 +00:00
buf = taosDecodeFixedI64(buf, &pConsumer->createTime);
2022-04-27 07:16:57 +00:00
buf = taosDecodeFixedI64(buf, &pConsumer->subscribeTime);
buf = taosDecodeFixedI64(buf, &pConsumer->rebalanceTime);
// current topics
buf = taosDecodeFixedI32(buf, &sz);
pConsumer->currentTopics = taosArrayInit(sz, sizeof(void *));
2024-07-25 09:49:58 +00:00
if (pConsumer->currentTopics == NULL) {
return NULL;
}
for (int32_t i = 0; i < sz; i++) {
char *topic;
buf = taosDecodeString(buf, &topic);
2024-07-25 09:49:58 +00:00
if (taosArrayPush(pConsumer->currentTopics, &topic) == NULL) {
return NULL;
}
}
// reb new topics
buf = taosDecodeFixedI32(buf, &sz);
pConsumer->rebNewTopics = taosArrayInit(sz, sizeof(void *));
for (int32_t i = 0; i < sz; i++) {
char *topic;
buf = taosDecodeString(buf, &topic);
2024-07-25 09:49:58 +00:00
if (taosArrayPush(pConsumer->rebNewTopics, &topic) == NULL) {
return NULL;
}
}
// reb removed topics
buf = taosDecodeFixedI32(buf, &sz);
pConsumer->rebRemovedTopics = taosArrayInit(sz, sizeof(void *));
for (int32_t i = 0; i < sz; i++) {
char *topic;
buf = taosDecodeString(buf, &topic);
2024-07-25 09:49:58 +00:00
if (taosArrayPush(pConsumer->rebRemovedTopics, &topic) == NULL) {
return NULL;
}
}
2022-04-27 09:15:02 +00:00
// reb removed topics
buf = taosDecodeFixedI32(buf, &sz);
pConsumer->assignedTopics = taosArrayInit(sz, sizeof(void *));
for (int32_t i = 0; i < sz; i++) {
char *topic;
buf = taosDecodeString(buf, &topic);
2024-07-25 09:49:58 +00:00
if (taosArrayPush(pConsumer->assignedTopics, &topic) == NULL) {
return NULL;
}
2022-04-27 09:15:02 +00:00
}
2023-06-16 09:28:50 +00:00
if (sver > 1) {
buf = taosDecodeFixedI8(buf, &pConsumer->withTbName);
buf = taosDecodeFixedI8(buf, &pConsumer->autoCommit);
buf = taosDecodeFixedI32(buf, &pConsumer->autoCommitInterval);
buf = taosDecodeFixedI32(buf, &pConsumer->resetOffsetCfg);
}
2024-11-18 11:52:41 +00:00
if (sver > 2) {
buf = taosDecodeFixedI32(buf, &pConsumer->maxPollIntervalMs);
buf = taosDecodeFixedI32(buf, &pConsumer->sessionTimeoutMs);
buf = taosDecodeStringTo(buf, pConsumer->user);
buf = taosDecodeStringTo(buf, pConsumer->fqdn);
2024-11-18 11:52:41 +00:00
} else {
pConsumer->maxPollIntervalMs = DEFAULT_MAX_POLL_INTERVAL;
pConsumer->sessionTimeoutMs = DEFAULT_SESSION_TIMEOUT;
}
return (void *)buf;
}
2024-11-18 11:52:41 +00:00
int32_t tEncodeOffRows(void **buf, SArray *offsetRows) {
int32_t tlen = 0;
int32_t szVgs = taosArrayGetSize(offsetRows);
tlen += taosEncodeFixedI32(buf, szVgs);
2023-06-16 09:28:50 +00:00
for (int32_t j = 0; j < szVgs; ++j) {
OffsetRows *offRows = taosArrayGet(offsetRows, j);
tlen += taosEncodeFixedI32(buf, offRows->vgId);
tlen += taosEncodeFixedI64(buf, offRows->rows);
tlen += taosEncodeFixedI8(buf, offRows->offset.type);
if (offRows->offset.type == TMQ_OFFSET__SNAPSHOT_DATA || offRows->offset.type == TMQ_OFFSET__SNAPSHOT_META) {
tlen += taosEncodeFixedI64(buf, offRows->offset.uid);
tlen += taosEncodeFixedI64(buf, offRows->offset.ts);
} else if (offRows->offset.type == TMQ_OFFSET__LOG) {
tlen += taosEncodeFixedI64(buf, offRows->offset.version);
} else {
// do nothing
}
tlen += taosEncodeFixedI64(buf, offRows->ever);
2022-04-20 13:36:55 +00:00
}
return tlen;
}
int32_t tEncodeSMqConsumerEp(void **buf, const SMqConsumerEp *pConsumerEp) {
int32_t tlen = 0;
tlen += taosEncodeFixedI64(buf, pConsumerEp->consumerId);
tlen += taosEncodeArray(buf, pConsumerEp->vgs, (FEncode)tEncodeSMqVgEp);
return tlen + tEncodeOffRows(buf, pConsumerEp->offsetRows);
}
2024-11-18 11:52:41 +00:00
void *tDecodeOffRows(const void *buf, SArray **offsetRows, int8_t sver) {
int32_t szVgs = 0;
buf = taosDecodeFixedI32(buf, &szVgs);
if (szVgs > 0) {
*offsetRows = taosArrayInit(szVgs, sizeof(OffsetRows));
if (NULL == *offsetRows) return NULL;
for (int32_t j = 0; j < szVgs; ++j) {
OffsetRows *offRows = taosArrayReserve(*offsetRows, 1);
buf = taosDecodeFixedI32(buf, &offRows->vgId);
buf = taosDecodeFixedI64(buf, &offRows->rows);
buf = taosDecodeFixedI8(buf, &offRows->offset.type);
if (offRows->offset.type == TMQ_OFFSET__SNAPSHOT_DATA || offRows->offset.type == TMQ_OFFSET__SNAPSHOT_META) {
buf = taosDecodeFixedI64(buf, &offRows->offset.uid);
buf = taosDecodeFixedI64(buf, &offRows->offset.ts);
} else if (offRows->offset.type == TMQ_OFFSET__LOG) {
buf = taosDecodeFixedI64(buf, &offRows->offset.version);
} else {
// do nothing
}
2024-11-18 11:52:41 +00:00
if (sver > 2) {
buf = taosDecodeFixedI64(buf, &offRows->ever);
}
}
}
return (void *)buf;
}
void *tDecodeSMqConsumerEp(const void *buf, SMqConsumerEp *pConsumerEp, int8_t sver) {
buf = taosDecodeFixedI64(buf, &pConsumerEp->consumerId);
buf = taosDecodeArray(buf, &pConsumerEp->vgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqVgEp), sver);
2023-06-16 09:28:50 +00:00
if (sver > 1) {
buf = tDecodeOffRows(buf, &pConsumerEp->offsetRows, sver);
2022-04-20 13:36:55 +00:00
}
return (void *)buf;
}
int32_t tNewSubscribeObj(const char *key, SMqSubscribeObj **ppSub) {
2024-11-18 11:52:41 +00:00
int32_t code = 0;
SMqSubscribeObj *pSubObj = taosMemoryCalloc(1, sizeof(SMqSubscribeObj));
MND_TMQ_NULL_CHECK(pSubObj);
(void)memcpy(pSubObj->key, key, TSDB_SUBSCRIBE_KEY_LEN);
taosInitRWLatch(&pSubObj->lock);
pSubObj->vgNum = 0;
pSubObj->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
MND_TMQ_NULL_CHECK(pSubObj->consumerHash);
pSubObj->unassignedVgs = taosArrayInit(0, POINTER_BYTES);
MND_TMQ_NULL_CHECK(pSubObj->unassignedVgs);
2024-11-18 11:52:41 +00:00
if (ppSub) {
*ppSub = pSubObj;
}
return code;
END:
taosMemoryFree(pSubObj);
return code;
}
int32_t tCloneSubscribeObj(const SMqSubscribeObj *pSub, SMqSubscribeObj **ppSub) {
2024-11-18 11:52:41 +00:00
int32_t code = 0;
SMqSubscribeObj *pSubNew = taosMemoryMalloc(sizeof(SMqSubscribeObj));
if (pSubNew == NULL) {
2024-09-12 07:46:30 +00:00
code = terrno;
goto END;
}
(void)memcpy(pSubNew->key, pSub->key, TSDB_SUBSCRIBE_KEY_LEN);
taosInitRWLatch(&pSubNew->lock);
2022-04-21 08:37:55 +00:00
2022-04-29 13:01:13 +00:00
pSubNew->dbUid = pSub->dbUid;
2022-06-02 03:01:05 +00:00
pSubNew->stbUid = pSub->stbUid;
2022-04-21 08:37:55 +00:00
pSubNew->subType = pSub->subType;
2022-06-21 05:50:33 +00:00
pSubNew->withMeta = pSub->withMeta;
2022-04-21 08:37:55 +00:00
pSubNew->vgNum = pSub->vgNum;
pSubNew->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
void *pIter = NULL;
SMqConsumerEp *pConsumerEp = NULL;
while (1) {
2022-04-20 13:36:55 +00:00
pIter = taosHashIterate(pSub->consumerHash, pIter);
if (pIter == NULL) break;
pConsumerEp = (SMqConsumerEp *)pIter;
SMqConsumerEp newEp = {
.consumerId = pConsumerEp->consumerId,
2023-06-13 09:10:23 +00:00
.vgs = taosArrayDup(pConsumerEp->vgs, (__array_item_dup_fn_t)tCloneSMqVgEp),
};
2024-07-25 09:49:58 +00:00
if ((code = taosHashPut(pSubNew->consumerHash, &newEp.consumerId, sizeof(int64_t), &newEp,
sizeof(SMqConsumerEp))) != 0)
goto END;
}
2023-06-13 09:10:23 +00:00
pSubNew->unassignedVgs = taosArrayDup(pSub->unassignedVgs, (__array_item_dup_fn_t)tCloneSMqVgEp);
pSubNew->offsetRows = taosArrayDup(pSub->offsetRows, NULL);
(void)memcpy(pSubNew->dbName, pSub->dbName, TSDB_DB_FNAME_LEN);
pSubNew->qmsg = taosStrdup(pSub->qmsg);
if (ppSub) {
*ppSub = pSubNew;
}
END:
return code;
}
void tDeleteSubscribeObj(SMqSubscribeObj *pSub) {
2024-03-12 11:42:26 +00:00
if (pSub == NULL) return;
2022-09-16 06:36:01 +00:00
void *pIter = NULL;
while (1) {
pIter = taosHashIterate(pSub->consumerHash, pIter);
if (pIter == NULL) break;
SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
2023-06-13 09:10:23 +00:00
taosArrayDestroyP(pConsumerEp->vgs, (FDelete)tDeleteSMqVgEp);
taosArrayDestroy(pConsumerEp->offsetRows);
2022-09-16 06:36:01 +00:00
}
taosHashCleanup(pSub->consumerHash);
2023-06-13 09:10:23 +00:00
taosArrayDestroyP(pSub->unassignedVgs, (FDelete)tDeleteSMqVgEp);
taosMemoryFreeClear(pSub->qmsg);
taosArrayDestroy(pSub->offsetRows);
}
int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) {
int32_t tlen = 0;
tlen += taosEncodeString(buf, pSub->key);
2022-04-29 13:01:13 +00:00
tlen += taosEncodeFixedI64(buf, pSub->dbUid);
tlen += taosEncodeFixedI32(buf, pSub->vgNum);
2022-04-21 08:37:55 +00:00
tlen += taosEncodeFixedI8(buf, pSub->subType);
2022-06-21 05:50:33 +00:00
tlen += taosEncodeFixedI8(buf, pSub->withMeta);
2022-06-02 03:01:05 +00:00
tlen += taosEncodeFixedI64(buf, pSub->stbUid);
void *pIter = NULL;
int32_t sz = taosHashGetSize(pSub->consumerHash);
tlen += taosEncodeFixedI32(buf, sz);
int32_t cnt = 0;
while (1) {
pIter = taosHashIterate(pSub->consumerHash, pIter);
if (pIter == NULL) break;
SMqConsumerEp *pConsumerEp = (SMqConsumerEp *)pIter;
tlen += tEncodeSMqConsumerEp(buf, pConsumerEp);
cnt++;
}
if (cnt != sz) return -1;
tlen += taosEncodeArray(buf, pSub->unassignedVgs, (FEncode)tEncodeSMqVgEp);
2022-06-10 07:20:57 +00:00
tlen += taosEncodeString(buf, pSub->dbName);
tlen += tEncodeOffRows(buf, pSub->offsetRows);
tlen += taosEncodeString(buf, pSub->qmsg);
return tlen;
}
void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub, int8_t sver) {
//
buf = taosDecodeStringTo(buf, pSub->key);
2022-04-29 13:01:13 +00:00
buf = taosDecodeFixedI64(buf, &pSub->dbUid);
buf = taosDecodeFixedI32(buf, &pSub->vgNum);
2022-04-21 08:37:55 +00:00
buf = taosDecodeFixedI8(buf, &pSub->subType);
2022-06-21 05:50:33 +00:00
buf = taosDecodeFixedI8(buf, &pSub->withMeta);
2022-06-02 03:01:05 +00:00
buf = taosDecodeFixedI64(buf, &pSub->stbUid);
int32_t sz;
buf = taosDecodeFixedI32(buf, &sz);
pSub->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
for (int32_t i = 0; i < sz; i++) {
SMqConsumerEp consumerEp = {0};
buf = tDecodeSMqConsumerEp(buf, &consumerEp, sver);
2024-07-25 09:49:58 +00:00
if (taosHashPut(pSub->consumerHash, &consumerEp.consumerId, sizeof(int64_t), &consumerEp, sizeof(SMqConsumerEp)) !=
0)
return NULL;
}
buf = taosDecodeArray(buf, &pSub->unassignedVgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqVgEp), sver);
2022-06-10 07:20:57 +00:00
buf = taosDecodeStringTo(buf, pSub->dbName);
2023-06-16 09:28:50 +00:00
if (sver > 1) {
buf = tDecodeOffRows(buf, &pSub->offsetRows, sver);
buf = taosDecodeString(buf, &pSub->qmsg);
2023-08-04 05:52:20 +00:00
} else {
2023-06-16 11:33:03 +00:00
pSub->qmsg = taosStrdup("");
}
return (void *)buf;
}
2025-01-09 05:36:23 +00:00
int32_t mndInitConfigObj(SConfigItem *pItem, SConfigObj *pObj) {
tstrncpy(pObj->name, pItem->name, CFG_NAME_MAX_LEN);
2024-11-18 11:52:41 +00:00
pObj->dtype = pItem->dtype;
switch (pItem->dtype) {
case CFG_DTYPE_NONE:
break;
case CFG_DTYPE_BOOL:
pObj->bval = pItem->bval;
break;
case CFG_DTYPE_INT32:
pObj->i32 = pItem->i32;
break;
case CFG_DTYPE_INT64:
pObj->i64 = pItem->i64;
break;
case CFG_DTYPE_FLOAT:
case CFG_DTYPE_DOUBLE:
pObj->fval = pItem->fval;
break;
case CFG_DTYPE_STRING:
case CFG_DTYPE_DIR:
case CFG_DTYPE_LOCALE:
case CFG_DTYPE_CHARSET:
case CFG_DTYPE_TIMEZONE:
pObj->str = taosStrdup(pItem->str);
if (pObj->str == NULL) {
taosMemoryFree(pObj);
2025-01-09 05:36:23 +00:00
return TSDB_CODE_OUT_OF_MEMORY;
}
2024-11-18 11:52:41 +00:00
break;
}
2025-01-09 05:36:23 +00:00
return TSDB_CODE_SUCCESS;
2024-11-18 11:52:41 +00:00
}
2024-12-04 11:32:21 +00:00
int32_t mndUpdateObj(SConfigObj *pObjNew, const char *name, char *value) {
2024-11-21 06:30:28 +00:00
int32_t code = 0;
2024-12-04 11:32:21 +00:00
switch (pObjNew->dtype) {
2024-11-21 06:30:28 +00:00
case CFG_DTYPE_BOOL: {
bool tmp = false;
if (strcasecmp(value, "true") == 0) {
tmp = true;
}
if (taosStr2Int32(value, NULL, 10) > 0) {
2024-11-21 06:30:28 +00:00
tmp = true;
}
2024-12-04 11:32:21 +00:00
pObjNew->bval = tmp;
2024-11-21 06:30:28 +00:00
break;
}
case CFG_DTYPE_INT32: {
int32_t ival;
TAOS_CHECK_RETURN(taosStrHumanToInt32(value, &ival));
2024-12-04 11:32:21 +00:00
pObjNew->i32 = ival;
2024-11-21 06:30:28 +00:00
break;
}
case CFG_DTYPE_INT64: {
int64_t ival;
TAOS_CHECK_RETURN(taosStrHumanToInt64(value, &ival));
2024-12-04 11:32:21 +00:00
pObjNew->i64 = ival;
2024-11-21 06:30:28 +00:00
break;
}
case CFG_DTYPE_FLOAT:
case CFG_DTYPE_DOUBLE: {
float dval = 0;
TAOS_CHECK_RETURN(parseCfgReal(value, &dval));
2024-12-04 11:32:21 +00:00
pObjNew->fval = dval;
2024-11-21 06:30:28 +00:00
break;
}
case CFG_DTYPE_DIR:
case CFG_DTYPE_TIMEZONE:
case CFG_DTYPE_CHARSET:
case CFG_DTYPE_LOCALE:
case CFG_DTYPE_STRING: {
pObjNew->str = taosStrdup(value);
if (pObjNew->str == NULL) {
code = terrno;
return code;
}
2024-11-21 06:30:28 +00:00
break;
}
case CFG_DTYPE_NONE:
break;
2024-11-21 06:30:28 +00:00
default:
code = TSDB_CODE_INVALID_CFG;
break;
}
return code;
}
2025-01-09 05:36:23 +00:00
SConfigObj mndInitConfigVersion() {
SConfigObj obj;
memset(&obj, 0, sizeof(SConfigObj));
2025-01-09 02:50:23 +00:00
2025-01-09 05:36:23 +00:00
tstrncpy(obj.name, "tsmmConfigVersion", CFG_NAME_MAX_LEN);
obj.dtype = CFG_DTYPE_INT32;
obj.i32 = 0;
return obj;
2024-11-21 06:30:28 +00:00
}
int32_t tEncodeSConfigObj(SEncoder *pEncoder, const SConfigObj *pObj) {
TAOS_CHECK_RETURN(tStartEncode(pEncoder));
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->name));
TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->dtype));
switch (pObj->dtype) {
case CFG_DTYPE_BOOL:
TAOS_CHECK_RETURN(tEncodeI8(pEncoder, pObj->bval));
break;
case CFG_DTYPE_INT32:
TAOS_CHECK_RETURN(tEncodeI32(pEncoder, pObj->i32));
break;
case CFG_DTYPE_INT64:
TAOS_CHECK_RETURN(tEncodeI64(pEncoder, pObj->i64));
break;
case CFG_DTYPE_FLOAT:
case CFG_DTYPE_DOUBLE:
TAOS_CHECK_RETURN(tEncodeFloat(pEncoder, pObj->fval));
break;
case CFG_DTYPE_STRING:
case CFG_DTYPE_DIR:
case CFG_DTYPE_LOCALE:
case CFG_DTYPE_CHARSET:
case CFG_DTYPE_TIMEZONE:
if (pObj->str != NULL) {
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, pObj->str));
} else {
TAOS_CHECK_RETURN(tEncodeCStr(pEncoder, ""));
}
break;
default:
break;
}
tEndEncode(pEncoder);
return pEncoder->pos;
}
int32_t tDecodeSConfigObj(SDecoder *pDecoder, SConfigObj *pObj) {
TAOS_CHECK_RETURN(tStartDecode(pDecoder));
TAOS_CHECK_RETURN(tDecodeCStrTo(pDecoder, pObj->name));
TAOS_CHECK_RETURN(tDecodeI32(pDecoder, (int32_t *)&pObj->dtype));
switch (pObj->dtype) {
case CFG_DTYPE_NONE:
break;
case CFG_DTYPE_BOOL:
TAOS_CHECK_RETURN(tDecodeBool(pDecoder, &pObj->bval));
break;
case CFG_DTYPE_INT32:
TAOS_CHECK_RETURN(tDecodeI32(pDecoder, &pObj->i32));
break;
case CFG_DTYPE_INT64:
TAOS_CHECK_RETURN(tDecodeI64(pDecoder, &pObj->i64));
break;
case CFG_DTYPE_FLOAT:
case CFG_DTYPE_DOUBLE:
TAOS_CHECK_RETURN(tDecodeFloat(pDecoder, &pObj->fval));
break;
case CFG_DTYPE_STRING:
case CFG_DTYPE_DIR:
case CFG_DTYPE_LOCALE:
case CFG_DTYPE_CHARSET:
case CFG_DTYPE_TIMEZONE:
TAOS_CHECK_RETURN(tDecodeCStrAlloc(pDecoder, &pObj->str));
break;
}
tEndDecode(pDecoder);
TAOS_RETURN(TSDB_CODE_SUCCESS);
}
void tFreeSConfigObj(SConfigObj *obj) {
if (obj == NULL) {
return;
}
if (obj->dtype == CFG_DTYPE_STRING || obj->dtype == CFG_DTYPE_DIR || obj->dtype == CFG_DTYPE_LOCALE ||
obj->dtype == CFG_DTYPE_CHARSET || obj->dtype == CFG_DTYPE_TIMEZONE) {
2024-12-12 11:31:28 +00:00
taosMemoryFree(obj->str);
}
}
2023-06-16 09:28:50 +00:00
// SMqSubActionLogEntry *tCloneSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) {
// SMqSubActionLogEntry *pEntryNew = taosMemoryMalloc(sizeof(SMqSubActionLogEntry));
// if (pEntryNew == NULL) return NULL;
// pEntryNew->epoch = pEntry->epoch;
// pEntryNew->consumers = taosArrayDup(pEntry->consumers, (__array_item_dup_fn_t)tCloneSMqConsumerEp);
// return pEntryNew;
// }
//
2023-06-16 09:28:50 +00:00
// void tDeleteSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) {
// taosArrayDestroyEx(pEntry->consumers, (FDelete)tDeleteSMqConsumerEp);
// }
// int32_t tEncodeSMqSubActionLogEntry(void **buf, const SMqSubActionLogEntry *pEntry) {
// int32_t tlen = 0;
// tlen += taosEncodeFixedI32(buf, pEntry->epoch);
// tlen += taosEncodeArray(buf, pEntry->consumers, (FEncode)tEncodeSMqSubActionLogEntry);
// return tlen;
// }
//
2023-06-16 09:28:50 +00:00
// void *tDecodeSMqSubActionLogEntry(const void *buf, SMqSubActionLogEntry *pEntry) {
// buf = taosDecodeFixedI32(buf, &pEntry->epoch);
// buf = taosDecodeArray(buf, &pEntry->consumers, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry));
// return (void *)buf;
// }
// SMqSubActionLogObj *tCloneSMqSubActionLogObj(SMqSubActionLogObj *pLog) {
// SMqSubActionLogObj *pLogNew = taosMemoryMalloc(sizeof(SMqSubActionLogObj));
// if (pLogNew == NULL) return pLogNew;
// memcpy(pLogNew->key, pLog->key, TSDB_SUBSCRIBE_KEY_LEN);
// pLogNew->logs = taosArrayDup(pLog->logs, (__array_item_dup_fn_t)tCloneSMqConsumerEp);
// return pLogNew;
// }
//
2023-06-16 09:28:50 +00:00
// void tDeleteSMqSubActionLogObj(SMqSubActionLogObj *pLog) {
// taosArrayDestroyEx(pLog->logs, (FDelete)tDeleteSMqConsumerEp);
// }
// int32_t tEncodeSMqSubActionLogObj(void **buf, const SMqSubActionLogObj *pLog) {
// int32_t tlen = 0;
// tlen += taosEncodeString(buf, pLog->key);
// tlen += taosEncodeArray(buf, pLog->logs, (FEncode)tEncodeSMqSubActionLogEntry);
// return tlen;
// }
//
2023-06-16 09:28:50 +00:00
// void *tDecodeSMqSubActionLogObj(const void *buf, SMqSubActionLogObj *pLog) {
// buf = taosDecodeStringTo(buf, pLog->key);
// buf = taosDecodeArray(buf, &pLog->logs, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry));
// return (void *)buf;
// }
//
2023-06-16 09:28:50 +00:00
// int32_t tEncodeSMqOffsetObj(void **buf, const SMqOffsetObj *pOffset) {
// int32_t tlen = 0;
// tlen += taosEncodeString(buf, pOffset->key);
// tlen += taosEncodeFixedI64(buf, pOffset->offset);
// return tlen;
// }
//
2023-06-16 09:28:50 +00:00
// void *tDecodeSMqOffsetObj(void *buf, SMqOffsetObj *pOffset) {
// buf = taosDecodeStringTo(buf, pOffset->key);
// buf = taosDecodeFixedI64(buf, &pOffset->offset);
// return buf;
// }