From 9ae476c147dde4a805ce6c74cc1fc98b61ead26a Mon Sep 17 00:00:00 2001 From: wangjiaming0909 Date: Mon, 20 May 2024 10:30:51 +0800 Subject: [PATCH 1/3] fix event window operator forget filting having clause --- source/libs/executor/src/eventwindowoperator.c | 1 + tests/system-test/2-query/group_partition.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/source/libs/executor/src/eventwindowoperator.c b/source/libs/executor/src/eventwindowoperator.c index 2cba6e3241..29907e6f1f 100644 --- a/source/libs/executor/src/eventwindowoperator.c +++ b/source/libs/executor/src/eventwindowoperator.c @@ -202,6 +202,7 @@ static SSDataBlock* eventWindowAggregate(SOperatorInfo* pOperator) { } eventWindowAggImpl(pOperator, pInfo, pBlock); + doFilter(pRes, pSup->pFilterInfo, NULL); if (pRes->info.rows >= pOperator->resultInfo.threshold) { return pRes; } diff --git a/tests/system-test/2-query/group_partition.py b/tests/system-test/2-query/group_partition.py index 4b236c1bce..c63b8af9df 100644 --- a/tests/system-test/2-query/group_partition.py +++ b/tests/system-test/2-query/group_partition.py @@ -237,6 +237,9 @@ class TDTestCase: tdSql.query(f"select tbname, count(*) from {self.dbname}.{self.stable} partition by tbname event_window start with c1 >= 0 end with c2 = 9 and t2=0;") tdSql.checkRows(1) + tdSql.query(f"select tbname, count(*) from {self.dbname}.{self.stable} partition by tbname event_window start with c1 >= 0 end with c2 = 9 and t2=0 having count(*) > 10;") + tdSql.checkRows(0) + tdSql.query(f"select tbname, count(*) from {self.dbname}.{self.stable} partition by tbname event_window start with c1 >= 0 end with c2 = 9 and _rowts>0;") tdSql.checkRows(nonempty_tb_num) From a297a388181583c8604caf5d3d872930dda212a7 Mon Sep 17 00:00:00 2001 From: dmchen Date: Tue, 21 May 2024 01:57:33 +0000 Subject: [PATCH 2/3] fix/TD-29772 --- include/common/tglobal.h | 4 ++- source/client/src/clientEnv.c | 2 +- source/common/src/tglobal.c | 33 +++++++++++++++-- source/dnode/mgmt/exe/dmMain.c | 37 +++++++++---------- source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 2 +- source/dnode/mgmt/node_util/inc/dmUtil.h | 32 ++++++++++++++++- source/dnode/mgmt/node_util/src/dmFile.c | 39 +++++++++++---------- source/libs/function/src/udfd.c | 2 +- source/libs/function/test/runUdf.c | 2 +- utils/tsim/src/simSystem.c | 2 +- 10 files changed, 110 insertions(+), 45 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 17ed732af8..95b7591263 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -257,8 +257,10 @@ extern bool tsExperimental; int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc); +int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, + const char *envFile, char *apolloUrl, SArray *pArgs); int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, - bool tsc, bool isDumpCfg); + bool tsc); void taosCleanupCfg(); int32_t taosCfgDynamicOptions(SConfig *pCfg, const char *name, bool forServer); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 036cf0420a..439103e5c4 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -725,7 +725,7 @@ void taos_init_imp(void) { return; } - if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1, true) != 0) { + if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1) != 0) { tscInitRes = -1; return; } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 650a639964..e4c268302f 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -1377,6 +1377,35 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi return 0; } +int32_t taosReadDataFolder(const char *cfgDir, const char **envCmd, + const char *envFile, char *apolloUrl, SArray *pArgs) { + if (tsCfg == NULL) osDefaultInit(); + + SConfig *pCfg = cfgInit(); + if (pCfg == NULL) return -1; + + if (cfgAddDir(pCfg, "dataDir", tsDataDir, CFG_SCOPE_SERVER, CFG_DYN_NONE) != 0) return -1; + if (cfgAddInt32(pCfg, "dDebugFlag", dDebugFlag, 0, 255, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1; + + if (taosLoadCfg(pCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) { + printf("failed to load cfg since %s", terrstr()); + cfgCleanup(pCfg); + return -1; + } + + if (cfgLoadFromArray(pCfg, pArgs) != 0) { + printf("failed to load cfg from array since %s", terrstr()); + cfgCleanup(pCfg); + return -1; + } + + tstrncpy(tsDataDir, cfgGetItem(pCfg, "dataDir")->str, PATH_MAX); + dDebugFlag = cfgGetItem(pCfg, "dDebugFlag")->i32; + + cfgCleanup(pCfg); + return 0; +} + static int32_t taosCheckGlobalCfg() { uint32_t ipv4 = taosGetIpv4FromFqdn(tsLocalFqdn); if (ipv4 == 0xffffffff) { @@ -1394,7 +1423,7 @@ static int32_t taosCheckGlobalCfg() { } int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, - bool tsc, bool isDumpCfg) { + bool tsc) { if (tsCfg != NULL) return 0; tsCfg = cfgInit(); @@ -1441,7 +1470,7 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile taosSetAllDebugFlag(tsCfg, cfgGetItem(tsCfg, "debugFlag")->i32); - if(isDumpCfg) cfgDumpCfg(tsCfg, tsc, false); + cfgDumpCfg(tsCfg, tsc, false); if (taosCheckGlobalCfg() != 0) { return -1; diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index f7fcd7697f..76b0565402 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -205,11 +205,11 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { if(i < argc - 1) { int32_t len = strlen(argv[++i]); if (len < ENCRYPT_KEY_LEN_MIN) { - printf("Error: Encrypt key should be at least %d characters\n", ENCRYPT_KEY_LEN_MIN); + printf("ERROR: Encrypt key should be at least %d characters\n", ENCRYPT_KEY_LEN_MIN); return -1; } if (len > ENCRYPT_KEY_LEN) { - printf("Error: Encrypt key overflow, it should be at most %d characters\n", ENCRYPT_KEY_LEN); + printf("ERROR: Encrypt key overflow, it should be at most %d characters\n", ENCRYPT_KEY_LEN); return -1; } tstrncpy(global.encryptKey, argv[i], ENCRYPT_KEY_LEN); @@ -371,6 +371,22 @@ int mainWindows(int argc, char **argv) { printf("memory dbg enabled\n"); } #endif + if(global.generateCode) { + bool toLogFile = false; + if(taosReadDataFolder(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs) != 0){ + encryptError("failed to generate encrypt code since taosd is running, please stop it first"); + return -1; + }; + + if(dmCheckRunning(tsDataDir) == NULL) { + encryptError("failed to generate encrypt code since taosd is running, please stop it first"); + return -1; + } + int ret = dmUpdateEncryptKey(global.encryptKey, toLogFile); + taosCloseLog(); + taosCleanupArgs(); + return ret; + } if (dmInitLog() != 0) { printf("failed to start since init log error\n"); @@ -380,28 +396,13 @@ int mainWindows(int argc, char **argv) { dmPrintArgs(argc, argv); - bool isDumpCfg = true; - if(global.generateCode) { - isDumpCfg = false; - } - if (taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0, isDumpCfg) != 0) { + if (taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) { dError("failed to start since read config error"); taosCloseLog(); taosCleanupArgs(); return -1; } - if(global.generateCode) { - if(dmCheckRunning(tsDataDir) == NULL) { - dError("failed to generate encrypt code since taosd is running, please stop it first"); - return -1; - } - int ret = dmUpdateEncryptKey(global.encryptKey); - taosCloseLog(); - taosCleanupArgs(); - return ret; - } - if(dmGetEncryptKey() != 0){ dError("failed to start since failed to get encrypt key"); taosCloseLog(); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index 3ec080fb21..800f7f7864 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -220,7 +220,7 @@ int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { goto _exit; } - code = dmUpdateEncryptKey(cfgReq.value); + code = dmUpdateEncryptKey(cfgReq.value, true); if (code == 0) { tsEncryptionKeyChksum = taosCalcChecksum(0, cfgReq.value, strlen(cfgReq.value)); tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED; diff --git a/source/dnode/mgmt/node_util/inc/dmUtil.h b/source/dnode/mgmt/node_util/inc/dmUtil.h index 9fdd5e50ed..aea3286d76 100644 --- a/source/dnode/mgmt/node_util/inc/dmUtil.h +++ b/source/dnode/mgmt/node_util/inc/dmUtil.h @@ -53,6 +53,36 @@ extern "C" { #define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }} #define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }} +#define encryptDebug(...) { \ + if (toLogFile) { \ + if (dDebugFlag & DEBUG_DEBUG) {taosPrintLog("DND ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__);} \ + } else { \ + /*if (dDebugFlag & DEBUG_DEBUG) {taosPrintLog("DND ", DEBUG_SCREEN, dDebugFlag, __VA_ARGS__);}*/ \ + if (dDebugFlag & DEBUG_DEBUG) {printf(__VA_ARGS__); printf("\n");} \ + } \ +} + +#define encryptInfo(...) { \ + if (toLogFile) { \ + taosPrintLog("DND ", DEBUG_INFO, 255, __VA_ARGS__); \ + } else { \ + /*if (dDebugFlag & DEBUG_DEBUG) {taosPrintLog("DND ", DEBUG_SCREEN, dDebugFlag, __VA_ARGS__);}*/ \ + printf(__VA_ARGS__); \ + printf("\n"); \ + } \ +} + +#define encryptError(...) { \ + if (toLogFile) { \ + taosPrintLog("DND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \ + }\ + else{ \ + /*taosPrintLog("DND ", DEBUG_SCREEN, 255, __VA_ARGS__); */\ + printf("ERROR: " __VA_ARGS__); \ + printf("\n"); \ + }\ +} + #define dGFatal(param, ...) {if (dDebugFlag & DEBUG_FATAL) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); dFatal(param ", gtid:%s", __VA_ARGS__, buf);}} #define dGError(param, ...) {if (dDebugFlag & DEBUG_ERROR) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); dError(param ", gtid:%s", __VA_ARGS__, buf);}} #define dGWarn(param, ...) {if (dDebugFlag & DEBUG_WARN) { char buf[40] = {0}; TRACE_TO_STR(trace, buf); dWarn(param ", gtid:%s", __VA_ARGS__, buf);}} @@ -194,7 +224,7 @@ void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet); bool dmUpdateDnodeInfo(void *pData, int32_t *dnodeId, int64_t *clusterId, char *fqdn, uint16_t *port); void dmRemoveDnodePairs(SDnodeData *pData); void dmGetDnodeEp(void *pData, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort); -int32_t dmUpdateEncryptKey(char *key); +int32_t dmUpdateEncryptKey(char *key, bool toLogFile); int32_t dmGetEncryptKey(); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c index e2c52cfb7e..752abb83a2 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -186,7 +186,7 @@ TdFilePtr dmCheckRunning(const char *dataDir) { extern int32_t generateEncryptCode(const char *key, const char *machineId, char **encryptCode); -static int32_t dmWriteCheckCodeFile(char* file, char* realfile, char* key){ +static int32_t dmWriteCheckCodeFile(char* file, char* realfile, char* key, bool toLogFile){ TdFilePtr pFile = NULL; char *result = NULL; int32_t code = -1; @@ -211,7 +211,8 @@ static int32_t dmWriteCheckCodeFile(char* file, char* realfile, char* key){ taosCloseFile(&pFile); if (taosRenameFile(file, realfile) != 0) goto _OVER; - dInfo("succeed to write checkCode file:%s", realfile); + encryptDebug("succeed to write checkCode file:%s", realfile); + code = 0; _OVER: if(pFile != NULL) taosCloseFile(&pFile); @@ -220,7 +221,7 @@ _OVER: return code; } -static int32_t dmWriteEncryptCodeFile(char* file, char* realfile, char* encryptCode){ +static int32_t dmWriteEncryptCodeFile(char* file, char* realfile, char* encryptCode, bool toLogFile){ TdFilePtr pFile = NULL; int32_t code = -1; @@ -234,7 +235,7 @@ static int32_t dmWriteEncryptCodeFile(char* file, char* realfile, char* encryptC taosCloseFile(&pFile); if (taosRenameFile(file, realfile) != 0) goto _OVER; - dInfo("succeed to write encryptCode file:%s", realfile); + encryptDebug("succeed to write encryptCode file:%s", realfile); code = 0; _OVER: @@ -243,7 +244,7 @@ _OVER: return code; } -static int32_t dmCompareEncryptKey(char* file, char* key){ +static int32_t dmCompareEncryptKey(char* file, char* key, bool toLogFile){ char *content = NULL; int64_t size = 0; TdFilePtr pFile = NULL; @@ -253,13 +254,13 @@ static int32_t dmCompareEncryptKey(char* file, char* key){ pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to open dnode file:%s since %s", file, terrstr()); + encryptError("failed to open dnode file:%s since %s", file, terrstr()); goto _OVER; } if (taosFStatFile(pFile, &size, NULL) < 0) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to fstat dnode file:%s since %s", file, terrstr()); + encryptError("failed to fstat dnode file:%s since %s", file, terrstr()); goto _OVER; } @@ -271,11 +272,11 @@ static int32_t dmCompareEncryptKey(char* file, char* key){ if (taosReadFile(pFile, content, size) != size) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to read dnode file:%s since %s", file, terrstr()); + encryptError("failed to read dnode file:%s since %s", file, terrstr()); goto _OVER; } - dInfo("succeed to read checkCode file:%s", file); + encryptDebug("succeed to read checkCode file:%s", file); int len = ENCRYPTED_LEN(size); result = taosMemoryMalloc(len); @@ -290,11 +291,11 @@ static int32_t dmCompareEncryptKey(char* file, char* key){ if(strcmp(opts.result, DM_KEY_INDICATOR) != 0) { terrno = TSDB_CODE_DNODE_ENCRYPTKEY_CHANGED; - dError("failed to compare decrypted result"); + encryptError("failed to compare decrypted result"); goto _OVER; } - dInfo("succeed to compare checkCode file:%s", file); + encryptDebug("succeed to compare checkCode file:%s", file); code = 0; _OVER: if(result != NULL) taosMemoryFree(result); @@ -304,7 +305,7 @@ _OVER: return code; } -int32_t dmUpdateEncryptKey(char *key) { +int32_t dmUpdateEncryptKey(char *key, bool toLogFile) { #ifdef TD_ENTERPRISE int32_t code = -1; char *machineId = NULL; @@ -328,12 +329,12 @@ int32_t dmUpdateEncryptKey(char *key) { if (taosMkDir(folder) != 0) { terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to create dir:%s since %s", folder, terrstr()); + encryptError("failed to create dir:%s since %s", folder, terrstr()); goto _OVER; } if(taosCheckExistFile(realCheckFile)){ - if(dmCompareEncryptKey(realCheckFile, key) != 0){ + if(dmCompareEncryptKey(realCheckFile, key, toLogFile) != 0){ goto _OVER; } } @@ -347,21 +348,23 @@ int32_t dmUpdateEncryptKey(char *key) { goto _OVER; } - if(dmWriteEncryptCodeFile(encryptFile, realEncryptFile, encryptCode) != 0){ + if(dmWriteEncryptCodeFile(encryptFile, realEncryptFile, encryptCode, toLogFile) != 0){ goto _OVER; } - if(dmWriteCheckCodeFile(checkFile, realCheckFile, key) != 0){ + if(dmWriteCheckCodeFile(checkFile, realCheckFile, key, toLogFile) != 0){ goto _OVER; } + encryptInfo("Succeed to update encrypt key\n"); + code = 0; _OVER: taosMemoryFree(encryptCode); taosMemoryFree(machineId); if (code != 0) { if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno); - dError("failed to update encrypt key since %s", terrstr()); + encryptError("failed to update encrypt key since %s", terrstr()); } return code; #else @@ -453,7 +456,7 @@ int32_t dmGetEncryptKey(){ goto _OVER; } - if(dmCompareEncryptKey(checkFile, encryptKey) != 0){ + if(dmCompareEncryptKey(checkFile, encryptKey, true) != 0){ goto _OVER; } diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index e2ea6c1374..2a5e594ba3 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -1424,7 +1424,7 @@ int main(int argc, char *argv[]) { printf("failed to start since init log error\n"); } - if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0, true) != 0) { + if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) { fnError("failed to start since read config error"); return -2; } diff --git a/source/libs/function/test/runUdf.c b/source/libs/function/test/runUdf.c index eef6cdc3d3..aa8b88b738 100644 --- a/source/libs/function/test/runUdf.c +++ b/source/libs/function/test/runUdf.c @@ -127,7 +127,7 @@ int aggregateFuncTest() { int main(int argc, char *argv[]) { parseArgs(argc, argv); initLog(); - if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0, true) != 0) { + if (taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0) != 0) { fnError("failed to start since read config error"); return -1; } diff --git a/utils/tsim/src/simSystem.c b/utils/tsim/src/simSystem.c index 645cf0e6fe..dcf5d6ab12 100644 --- a/utils/tsim/src/simSystem.c +++ b/utils/tsim/src/simSystem.c @@ -28,7 +28,7 @@ extern bool simExecSuccess; int32_t simInitCfg() { taosCreateLog("simlog", 1, configDir, NULL, NULL, NULL, NULL, 1); - taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1, true); + taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1); SConfig *pCfg = taosGetCfg(); tstrncpy(simScriptDir, cfgGetItem(pCfg, "scriptDir")->str, PATH_MAX); From f21eeae56c3e28b221abd18a2678b79fd62de589 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Tue, 21 May 2024 16:57:00 +0800 Subject: [PATCH 3/3] fix:[TD-30180]error in judging if groupId already added to the end of table name --- include/common/tdatablock.h | 2 +- source/common/src/tdatablock.c | 19 +++++--------- source/common/test/commonTests.cpp | 34 +++++++++++++++++++++++++ source/dnode/vnode/src/tq/tqSink.c | 6 ++--- source/libs/stream/src/streamDispatch.c | 2 +- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 32cd7bb2ab..197fa125f5 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -274,7 +274,7 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** dumpBuf, c int32_t buildSubmitReqFromDataBlock(SSubmitReq2** pReq, const SSDataBlock* pDataBlocks, const STSchema* pTSchema, int64_t uid, int32_t vgId, tb_uid_t suid); -bool alreadyAddGroupId(char* ctbName); +bool alreadyAddGroupId(char* ctbName, int64_t groupId); bool isAutoTableName(char* ctbName); void buildCtbNameAddGroupId(const char* stbName, char* ctbName, uint64_t groupId); char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId); diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 1c0b696aaa..ac4811fb1b 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -2435,18 +2435,13 @@ void buildCtbNameAddGroupId(const char* stbName, char* ctbName, uint64_t groupId // the total length is fixed to be 34 bytes. bool isAutoTableName(char* ctbName) { return (strlen(ctbName) == 34 && ctbName[0] == 't' && ctbName[1] == '_'); } -bool alreadyAddGroupId(char* ctbName) { - size_t len = strlen(ctbName); - if (len == 0) return false; - size_t _location = len - 1; - while (_location > 0) { - if (ctbName[_location] < '0' || ctbName[_location] > '9') { - break; - } - _location--; - } - - return ctbName[_location] == '_' && len - 1 - _location >= 15; // 15 means the min length of groupid +bool alreadyAddGroupId(char* ctbName, int64_t groupId) { + char tmp[64] = {0}; + snprintf(tmp, sizeof(tmp), "%" PRIu64, groupId); + size_t len1 = strlen(ctbName); + size_t len2 = strlen(tmp); + if (len1 < len2) return false; + return memcmp(ctbName + len1 - len2, tmp, len2) == 0; } char* buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId) { diff --git a/source/common/test/commonTests.cpp b/source/common/test/commonTests.cpp index 8e0e50165f..d30b26e564 100644 --- a/source/common/test/commonTests.cpp +++ b/source/common/test/commonTests.cpp @@ -692,4 +692,38 @@ TEST(timeTest, epSet) { ASSERT_EQ(ep.numOfEps, 1); } } + +// Define test cases +TEST(AlreadyAddGroupIdTest, GroupIdAdded) { + // Test case 1: Group ID has been added + char ctbName[64] = "abc123"; + int64_t groupId = 123; + bool result = alreadyAddGroupId(ctbName, groupId); + EXPECT_TRUE(result); +} + +TEST(AlreadyAddGroupIdTest, GroupIdNotAdded) { + // Test case 2: Group ID has not been added + char ctbName[64] = "abc456"; + int64_t groupId = 123; + bool result = alreadyAddGroupId(ctbName, groupId); + EXPECT_FALSE(result); +} + +TEST(AlreadyAddGroupIdTest, GroupIdAddedAtTheEnd) { + // Test case 3: Group ID has been added at the end + char ctbName[64] = "xyz1"; + int64_t groupId = 1; + bool result = alreadyAddGroupId(ctbName, groupId); + EXPECT_TRUE(result); +} + +TEST(AlreadyAddGroupIdTest, GroupIdAddedWithDifferentLength) { + // Test case 4: Group ID has been added with different length + char ctbName[64] = "def"; + int64_t groupId = 123456; + bool result = alreadyAddGroupId(ctbName, groupId); + EXPECT_FALSE(result); +} + #pragma GCC diagnostic pop diff --git a/source/dnode/vnode/src/tq/tqSink.c b/source/dnode/vnode/src/tq/tqSink.c index c0f58fc3ec..5522d06263 100644 --- a/source/dnode/vnode/src/tq/tqSink.c +++ b/source/dnode/vnode/src/tq/tqSink.c @@ -71,7 +71,7 @@ int32_t tqBuildDeleteReq(STQ* pTq, const char* stbFullName, const SSDataBlock* p if (varTbName != NULL && varTbName != (void*)-1) { name = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN); memcpy(name, varDataVal(varTbName), varDataLen(varTbName)); - if (newSubTableRule && !isAutoTableName(name) && !alreadyAddGroupId(name) && groupId != 0 && stbFullName) { + if (newSubTableRule && !isAutoTableName(name) && !alreadyAddGroupId(name, groupId) && groupId != 0 && stbFullName) { buildCtbNameAddGroupId(stbFullName, name, groupId); } } else if (stbFullName) { @@ -182,7 +182,7 @@ void setCreateTableMsgTableName(SVCreateTbReq* pCreateTableReq, SSDataBlock* pDa int64_t gid, bool newSubTableRule) { if (pDataBlock->info.parTbName[0]) { if (newSubTableRule && !isAutoTableName(pDataBlock->info.parTbName) && - !alreadyAddGroupId(pDataBlock->info.parTbName) && gid != 0 && stbFullName) { + !alreadyAddGroupId(pDataBlock->info.parTbName, gid) && gid != 0 && stbFullName) { pCreateTableReq->name = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN); strcpy(pCreateTableReq->name, pDataBlock->info.parTbName); buildCtbNameAddGroupId(stbFullName, pCreateTableReq->name, gid); @@ -713,7 +713,7 @@ int32_t setDstTableDataUid(SVnode* pVnode, SStreamTask* pTask, SSDataBlock* pDat buildCtbNameByGroupIdImpl(stbFullName, groupId, dstTableName); } else { if (pTask->subtableWithoutMd5 != 1 && !isAutoTableName(dstTableName) && - !alreadyAddGroupId(dstTableName) && groupId != 0) { + !alreadyAddGroupId(dstTableName, groupId) && groupId != 0) { tqDebug("s-task:%s append groupId:%" PRId64 " for generated dstTable:%s", id, groupId, dstTableName); if(pTask->ver == SSTREAM_TASK_SUBTABLE_CHANGED_VER){ buildCtbNameAddGroupId(NULL, dstTableName, groupId); diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 58c6e19581..cc9105ffdc 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -494,7 +494,7 @@ int32_t streamSearchAndAddBlock(SStreamTask* pTask, SStreamDispatchReq* pReqs, S if (pDataBlock->info.parTbName[0]) { if(pTask->subtableWithoutMd5 != 1 && !isAutoTableName(pDataBlock->info.parTbName) && - !alreadyAddGroupId(pDataBlock->info.parTbName) && + !alreadyAddGroupId(pDataBlock->info.parTbName, groupId) && groupId != 0){ if(pTask->ver == SSTREAM_TASK_SUBTABLE_CHANGED_VER){ buildCtbNameAddGroupId(NULL, pDataBlock->info.parTbName, groupId);