fix double compress when retry

This commit is contained in:
yihaoDeng 2024-11-21 14:59:51 +08:00
parent 62e609c558
commit 2a26f48a1b
5 changed files with 472 additions and 5 deletions

View File

@ -452,6 +452,7 @@ void transPrintEpSet(SEpSet* pEpSet);
void transFreeMsg(void* msg);
int32_t transCompressMsg(char* msg, int32_t len);
int32_t transDecompressMsg(char** msg, int32_t* len);
int32_t transDecompressMsgExt(char const* msg, int32_t len, char** out, int32_t* outLen);
int32_t transOpenRefMgt(int size, void (*func)(void*));
void transCloseRefMgt(int32_t refMgt);

View File

@ -1334,13 +1334,31 @@ static void cliBatchSendCb(uv_write_t* req, int status) {
}
}
bool cliConnMayAddUserInfo(SCliConn* pConn, STransMsgHead** ppHead, int32_t* msgLen) {
int32_t code = 0;
SCliThrd* pThrd = pConn->hostThrd;
STrans* pInst = pThrd->pInst;
if (pConn->userInited == 1) {
return false;
}
STransMsgHead* pHead = *ppHead;
STransMsgHead* tHead = taosMemoryCalloc(1, *msgLen + sizeof(pInst->user));
int32_t len = *msgLen;
char* oriMsg = NULL;
int32_t oriLen = 0;
if (pHead->comp == 1) {
int32_t msgLen = htonl(pHead->msgLen);
code = transDecompressMsgExt((char*)(pHead), msgLen, &oriMsg, &oriLen);
if (code < 0) {
tError("failed to decompress since %s", tstrerror(code));
return false;
} else {
tDebug("decompress msg and resent, compress size %d, raw size %d", pHead, oriMsg, msgLen, oriLen);
}
pHead = (STransMsgHead*)oriMsg;
len = oriLen;
}
STransMsgHead* tHead = taosMemoryCalloc(1, len + sizeof(pInst->user));
if (tHead == NULL) {
return false;
}
@ -1348,14 +1366,17 @@ bool cliConnMayAddUserInfo(SCliConn* pConn, STransMsgHead** ppHead, int32_t* msg
memcpy((char*)tHead + TRANS_MSG_OVERHEAD, pInst->user, sizeof(pInst->user));
memcpy((char*)tHead + TRANS_MSG_OVERHEAD + sizeof(pInst->user), (char*)pHead + TRANS_MSG_OVERHEAD,
*msgLen - TRANS_MSG_OVERHEAD);
len - TRANS_MSG_OVERHEAD);
tHead->withUserInfo = 1;
*ppHead = tHead;
*msgLen += sizeof(pInst->user);
*msgLen = len + sizeof(pInst->user);
pConn->pInitUserReq = tHead;
pConn->userInited = 1;
if (oriMsg != NULL) {
taosMemoryFree(oriMsg);
}
return true;
}
int32_t cliBatchSend(SCliConn* pConn, int8_t direct) {
@ -1421,9 +1442,8 @@ int32_t cliBatchSend(SCliConn* pConn, int8_t direct) {
pReq->contLen = 0;
}
int32_t msgLen = transMsgLenFromCont(pReq->contLen);
STransMsgHead* pHead = transHeadFromCont(pReq->pCont);
int32_t msgLen = transMsgLenFromCont(pReq->contLen);
char* content = pReq->pCont;
int32_t contLen = pReq->contLen;

View File

@ -77,6 +77,11 @@ int32_t transDecompressMsg(char** msg, int32_t* len) {
STransMsgHead* pNewHead = (STransMsgHead*)buf;
int32_t decompLen = LZ4_decompress_safe(pCont + sizeof(STransCompMsg), (char*)pNewHead->content,
tlen - sizeof(STransMsgHead) - sizeof(STransCompMsg), oriLen);
if (decompLen != oriLen) {
taosMemoryFree(buf);
return TSDB_CODE_INVALID_MSG;
}
memcpy((char*)pNewHead, (char*)pHead, sizeof(STransMsgHead));
*len = oriLen + sizeof(STransMsgHead);
@ -84,9 +89,36 @@ int32_t transDecompressMsg(char** msg, int32_t* len) {
taosMemoryFree(pHead);
*msg = buf;
return 0;
}
int32_t transDecompressMsgExt(char const* msg, int32_t len, char** out, int32_t* outLen) {
STransMsgHead* pHead = (STransMsgHead*)msg;
char* pCont = transContFromHead(pHead);
STransCompMsg* pComp = (STransCompMsg*)pCont;
int32_t oriLen = htonl(pComp->contLen);
int32_t tlen = len;
char* buf = taosMemoryCalloc(1, oriLen + sizeof(STransMsgHead));
if (buf == NULL) {
return terrno;
}
STransMsgHead* pNewHead = (STransMsgHead*)buf;
int32_t decompLen = LZ4_decompress_safe(pCont + sizeof(STransCompMsg), (char*)pNewHead->content,
tlen - sizeof(STransMsgHead) - sizeof(STransCompMsg), oriLen);
if (decompLen != oriLen) {
tError("msgLen:%d, originLen:%d, decompLen:%d", len, oriLen, decompLen);
taosMemoryFree(buf);
return TSDB_CODE_INVALID_MSG;
}
memcpy((char*)pNewHead, (char*)pHead, sizeof(STransMsgHead));
*out = buf;
*outLen = oriLen + sizeof(STransMsgHead);
pNewHead->msgLen = *outLen;
pNewHead->comp = 0;
return 0;
}

View File

@ -1300,6 +1300,7 @@
#,,y,script,./test.sh -f tsim/mnode/basic3.sim
,,y,script,./test.sh -f tsim/mnode/basic4.sim
,,y,script,./test.sh -f tsim/mnode/basic5.sim
,,y,script,./test.sh -f tsim/mnode/basic6.sim
,,y,script,./test.sh -f tsim/show/basic.sim
,,y,script,./test.sh -f tsim/table/autocreate.sim
,,y,script,./test.sh -f tsim/table/basic1.sim

View File

@ -0,0 +1,413 @@
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/deploy.sh -n dnode2 -i 2
system sh/deploy.sh -n dnode3 -i 3
system sh/deploy.sh -n dnode4 -i 4
system sh/cfg.sh -n dnode1 -c compressMsgSize -v 0
system sh/cfg.sh -n dnode2 -c compressMsgSize -v 0
system sh/cfg.sh -n dnode3 -c compressMsgSize -v 0
system sh/cfg.sh -n dnode4 -c compressMsgSize -v 0
system sh/exec.sh -n dnode1 -s start
sql connect
print =============== step1: create dnodes
sql create dnode $hostname port 7200
sql create dnode $hostname port 7300
sql create dnode $hostname port 7400
$x = 0
step1:
$x = $x + 1
sleep 1000
if $x == 5 then
return -1
endi
sql select * from information_schema.ins_dnodes
if $data(1)[4] != ready then
goto step1
endi
print =============== step2: create dnodes - with error
sql_error create mnode on dnode 1;
sql_error create mnode on dnode 2;
sql_error create mnode on dnode 3;
sql_error create mnode on dnode 4;
sql_error create mnode on dnode 5;
sql_error create mnode on dnode 6;
print =============== step3: create mnode 2 and 3
system sh/exec.sh -n dnode2 -s start
system sh/exec.sh -n dnode3 -s start
system sh/exec.sh -n dnode4 -s start
$x = 0
step3:
$x = $x + 1
sleep 1000
if $x == 5 then
return -1
endi
sql select * from information_schema.ins_dnodes
if $data(2)[4] != ready then
goto step3
endi
if $data(3)[4] != ready then
goto step3
endi
if $data(4)[4] != ready then
goto step3
endi
sql create mnode on dnode 2
sql create mnode on dnode 3
$x = 0
step31:
$x = $x + 1
sleep 1000
if $x == 50 then
return -1
endi
sql select * from information_schema.ins_mnodes
$leaderNum = 0
if $data(1)[2] == leader then
$leaderNum = 1
endi
if $data(2)[2] == leader then
$leaderNum = 1
endi
if $data(3)[2] == leader then
$leaderNum = 1
endi
if $leaderNum == 0 then
goto step31
endi
print =============== step4: create dnodes - with error
sql_error create mnode on dnode 1
sql_error create mnode on dnode 2;
sql_error create mnode on dnode 3;
sql_error create mnode on dnode 4;
sql_error create mnode on dnode 5;
sql_error create mnode on dnode 6;
print =============== step5: drop mnodes - with error
sql_error drop mnode on dnode 1
sql_error drop mnode on dnode 4
sql_error drop mnode on dnode 5
sql_error drop mnode on dnode 6
system sh/exec.sh -n dnode2 -s stop
$x = 0
step5:
$x = $x + 1
sleep 1000
if $x == 10 then
return -1
endi
sql select * from information_schema.ins_dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
if $data(1)[4] != ready then
goto step5
endi
if $data(2)[4] != offline then
goto step5
endi
if $data(3)[4] != ready then
goto step5
endi
if $data(4)[4] != ready then
goto step5
endi
sql_error drop mnode on dnode 2
system sh/exec.sh -n dnode2 -s start
$x = 0
step51:
$x = $x + 1
sleep 1000
if $x == 10 then
return -1
endi
sql select * from information_schema.ins_dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
if $data(1)[4] != ready then
goto step51
endi
if $data(2)[4] != ready then
goto step51
endi
if $data(3)[4] != ready then
goto step51
endi
if $data(4)[4] != ready then
goto step51
endi
print =============== step6: stop mnode1
system sh/exec.sh -n dnode1 -s stop
# sql_error drop mnode on dnode 1
$x = 0
step61:
$x = $x + 1
sleep 1000
if $x == 10 then
return -1
endi
sql select * from information_schema.ins_mnodes -x step61
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
$leaderNum = 0
if $data(2)[2] == leader then
$leaderNum = 1
endi
if $data(3)[2] == leader then
$leaderNum = 1
endi
if $leaderNum != 1 then
goto step61
endi
print =============== step7: start mnode1 and wait it online
system sh/exec.sh -n dnode1 -s start
$x = 0
step71:
$x = $x + 1
sleep 1000
if $x == 50 then
return -1
endi
sql select * from information_schema.ins_dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
if $data(1)[4] != ready then
goto step71
endi
if $data(2)[4] != ready then
goto step71
endi
if $data(3)[4] != ready then
goto step71
endi
if $data(4)[4] != ready then
goto step71
endi
print =============== step8: stop mnode1 and drop it
system sh/exec.sh -n dnode1 -s stop
$x = 0
step81:
$x = $x + 1
sleep 1000
if $x == 10 then
return -1
endi
sql select * from information_schema.ins_mnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
$leaderNum = 0
if $data(1)[2] == leader then
$leaderNum = 1
endi
if $data(2)[2] == leader then
$leaderNum = 1
endi
if $data(3)[2] == leader then
$leaderNum = 1
endi
if $leaderNum != 1 then
goto step81
endi
print =============== step9: start mnode1 and wait it dropped
print check mnode has leader step9a
$x = 0
step9a:
$x = $x + 1
sleep 1000
if $x == 10 then
return -1
endi
print check mnode leader
sql select * from information_schema.ins_mnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
$leaderNum = 0
if $data(1)[2] == leader then
$leaderNum = 1
endi
if $data(2)[2] == leader then
$leaderNum = 1
endi
if $data(3)[2] == leader then
$leaderNum = 1
endi
if $leaderNum != 1 then
goto step9a
endi
print start dnode1 step9b
system sh/exec.sh -n dnode1 -s start
$x = 0
step9b:
$x = $x + 1
sleep 1000
if $x == 10 then
return -1
endi
print check dnode1 ready
sql select * from information_schema.ins_dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
if $data(1)[4] != ready then
goto step9b
endi
if $data(2)[4] != ready then
goto step9b
endi
if $data(3)[4] != ready then
goto step9b
endi
if $data(4)[4] != ready then
goto step9b
endi
sleep 4000
print check mnode has leader step9c
$x = 0
step9c:
$x = $x + 1
sleep 1000
if $x == 10 then
return -1
endi
print check mnode leader
sql select * from information_schema.ins_mnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
$leaderNum = 0
if $data(1)[2] == leader then
$leaderNum = 1
endi
if $data(2)[2] == leader then
$leaderNum = 1
endi
if $data(3)[2] == leader then
$leaderNum = 1
endi
if $leaderNum != 1 then
goto step9c
endi
print drop mnode step9d
sql drop mnode on dnode 1
$x = 0
step9d:
$x = $x + 1
sleep 1000
if $x == 20 then
return -1
endi
print check mnode leader
sql select * from information_schema.ins_mnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
$leaderNum = 0
if $data(1)[2] == leader then
$leaderNum = 1
endi
if $data(2)[2] == leader then
$leaderNum = 1
endi
if $data(3)[2] == leader then
$leaderNum = 1
endi
if $leaderNum != 1 then
goto step9d
endi
if $rows != 2 then
goto step9d
endi
print =============== stepa: create mnode1 again
sql create mnode on dnode 1
$x = 0
stepa:
$x = $x + 1
sleep 1000
if $x == 10 then
return -1
endi
sql select * from information_schema.ins_mnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
$leaderNum = 0
if $data(1)[2] == leader then
$leaderNum = 1
endi
if $data(2)[2] == leader then
$leaderNum = 1
endi
if $data(3)[2] == leader then
$leaderNum = 1
endi
if $leaderNum == 0 then
goto stepa
endi
if $leaderNum != 1 then
return -1
endi
$x = 0
stepb:
$x = $x + 1
sleep 1000
if $x == 10 then
print ====> dnode not ready!
return -1
endi
sql select * from information_schema.ins_dnodes
print ===> $data00 $data01 $data02 $data03 $data04 $data05
print ===> $data10 $data11 $data12 $data13 $data14 $data15
print ===> $data20 $data21 $data22 $data23 $data24 $data25
print ===> $data30 $data31 $data32 $data33 $data34 $data35
if $rows != 4 then
return -1
endi
if $data(1)[4] != ready then
goto stepb
endi
if $data(2)[4] != ready then
goto stepb
endi
if $data(3)[4] != ready then
goto stepb
endi
if $data(4)[4] != ready then
goto stepb
endi
system sh/exec.sh -n dnode1 -s stop
system sh/exec.sh -n dnode2 -s stop
system sh/exec.sh -n dnode3 -s stop
system sh/exec.sh -n dnode4 -s stop