fix:[TD-30180]error in judging if groupId already added to the end of table name
This commit is contained in:
parent
1eb6975db7
commit
f21eeae56c
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue