diff --git a/include/libs/command/command.h b/include/libs/command/command.h index b788b03386..47c106dc51 100644 --- a/include/libs/command/command.h +++ b/include/libs/command/command.h @@ -20,6 +20,14 @@ #include "plannodes.h" #include "tmsg.h" +#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t)) << 1) + +#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \ + do { \ + ((int32_t*)(_p))[0] = (_compLen); \ + ((int32_t*)(_p))[1] = (_fullLen); \ + } while (0); + typedef struct SExplainCtx SExplainCtx; int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode *pStmt, SRetrieveTableRsp **pRsp, int8_t biMode); diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 3e178c876f..f04e5e53c6 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -25,6 +25,7 @@ #include "tglobal.h" #include "tname.h" #include "tversion.h" +#include "command.h" extern SClientHbMgr clientHbMgr; @@ -499,7 +500,7 @@ static int32_t buildShowVariablesRsp(SArray* pVars, SRetrieveTableRsp** pRsp) { return code; } - size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock); + size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock) + PAYLOAD_PREFIX_LEN; *pRsp = taosMemoryCalloc(1, rspSize); if (NULL == *pRsp) { blockDataDestroy(pBlock); @@ -510,15 +511,20 @@ static int32_t buildShowVariablesRsp(SArray* pVars, SRetrieveTableRsp** pRsp) { (*pRsp)->completed = 1; (*pRsp)->precision = 0; (*pRsp)->compressed = 0; - (*pRsp)->compLen = 0; - (*pRsp)->payloadLen = 0; + (*pRsp)->numOfRows = htobe64((int64_t)pBlock->info.rows); (*pRsp)->numOfCols = htonl(SHOW_VARIABLES_RESULT_COLS); - int32_t len = blockEncode(pBlock, (*pRsp)->data, SHOW_VARIABLES_RESULT_COLS); + int32_t len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, SHOW_VARIABLES_RESULT_COLS); blockDataDestroy(pBlock); - if (len != rspSize - sizeof(SRetrieveTableRsp)) { + SET_PAYLOAD_LEN((*pRsp)->data, len, len); + + int32_t payloadLen = len + PAYLOAD_PREFIX_LEN; + (*pRsp)->payloadLen = htonl(payloadLen); + (*pRsp)->compLen = htonl(payloadLen); + + if (payloadLen != rspSize - sizeof(SRetrieveTableRsp)) { uError("buildShowVariablesRsp error, len:%d != rspSize - sizeof(SRetrieveTableRsp):%" PRIu64, len, (uint64_t)(rspSize - sizeof(SRetrieveTableRsp))); return TSDB_CODE_TSC_INVALID_INPUT; @@ -612,7 +618,7 @@ static int32_t buildRetriveTableRspForCompactDb(SCompactDbRsp* pCompactDb, SRetr return code; } - size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock); + size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock) + PAYLOAD_PREFIX_LEN; *pRsp = taosMemoryCalloc(1, rspSize); if (NULL == *pRsp) { blockDataDestroy(pBlock); @@ -628,10 +634,16 @@ static int32_t buildRetriveTableRspForCompactDb(SCompactDbRsp* pCompactDb, SRetr (*pRsp)->numOfRows = htobe64((int64_t)pBlock->info.rows); (*pRsp)->numOfCols = htonl(COMPACT_DB_RESULT_COLS); - int32_t len = blockEncode(pBlock, (*pRsp)->data, COMPACT_DB_RESULT_COLS); + int32_t len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, COMPACT_DB_RESULT_COLS); blockDataDestroy(pBlock); - if (len != rspSize - sizeof(SRetrieveTableRsp)) { + SET_PAYLOAD_LEN((*pRsp)->data, len, len); + + int32_t payloadLen = len + PAYLOAD_PREFIX_LEN; + (*pRsp)->payloadLen = htonl(payloadLen); + (*pRsp)->compLen = htonl(payloadLen); + + if (payloadLen != rspSize - sizeof(SRetrieveTableRsp)) { uError("buildRetriveTableRspForCompactDb error, len:%d != rspSize - sizeof(SRetrieveTableRsp):%" PRIu64, len, (uint64_t)(rspSize - sizeof(SRetrieveTableRsp))); return TSDB_CODE_TSC_INVALID_INPUT; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 57ddbb9beb..4de0086f96 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -1148,7 +1148,6 @@ _OVER: } tFreeSShowVariablesRsp(&rsp); - return code; } diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 75ce4c9819..3557dd86ae 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -25,14 +25,6 @@ extern SConfig* tsCfg; -#define PAYLOAD_PREFIX_LEN ((sizeof(int32_t))<<1) - -#define SET_PAYLOAD_LEN(_p, _compLen, _fullLen) \ - do { \ - ((int32_t*)(_p))[0] = (_compLen); \ - ((int32_t*)(_p))[1] = (_fullLen); \ - } while (0); - static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRetrieveTableRsp** pRsp) { size_t rspSize = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pBlock) + PAYLOAD_PREFIX_LEN; *pRsp = taosMemoryCalloc(1, rspSize);