From 3cf5fe8f7dd1e056249b2d7bc34c57b250909ef3 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Wed, 5 Jan 2022 11:41:54 +0800 Subject: [PATCH] (query,insert,other,connector,tools):use tlv for sversion/tversion for message compatibility --- src/client/src/tscServer.c | 14 ++++++++++++-- src/inc/taosmsg.h | 2 ++ src/query/src/queryMain.c | 17 ++++++++++++++--- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index c3982f04ec..30ebb63a77 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2755,8 +2755,6 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) { pRes->numOfRows = htonl(pRetrieve->numOfRows); pRes->precision = htons(pRetrieve->precision); - pRes->sVersion = htonl(pRetrieve->sVersion); - pRes->tVersion = htonl(pRetrieve->tVersion); pRes->offset = htobe64(pRetrieve->offset); pRes->useconds = htobe64(pRetrieve->useconds); pRes->completed = (pRetrieve->completed == 1); @@ -2807,6 +2805,18 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) { tscDebug("0x%"PRIx64" numOfRows:%d, offset:%" PRId64 ", complete:%d, qId:0x%"PRIx64, pSql->self, pRes->numOfRows, pRes->offset, pRes->completed, pRes->qId); + if (pRetrieve->extend == 1) { + STLV* tlv = (STLV*)(pRetrieve->data + ntohl(pRetrieve->compLen)); + while (tlv->type != TLV_TYPE_END_MARK) { + switch (tlv->type) { + case TLV_TYPE_META_VERSION: + pRes->sVersion = ntohl(*(int32_t*)tlv->value); + pRes->tVersion = ntohl(*(int32_t*)(tlv->value + sizeof(int32_t))); + break; + } + tlv = (STLV*) ((char*)tlv + sizeof(STLV) + ntohl(tlv->len)); + } + } return 0; } diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index dc65d828da..d9f6d0f2e3 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -980,7 +980,9 @@ typedef struct { } STLV; enum { + TLV_TYPE_END_MARK = -1, TLV_TYPE_DUMMY = 1, + TLV_TYPE_META_VERSION = 2, }; #pragma pack(pop) diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index 4ac4d89d74..c5365a0c68 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -391,7 +391,8 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co size += sizeof(STableIdInfo) * taosHashGetSize(pRuntimeEnv->pTableRetrieveTsMap); *contLen = (int32_t)(size + sizeof(SRetrieveTableRsp)); - + *contLen += (sizeof(STLV) + sizeof(int32_t) + sizeof(int32_t)); //tlv meta version + *contLen += sizeof(STLV); // tlv end mark // current solution only avoid crash, but cannot return error code to client *pRsp = (SRetrieveTableRsp *)rpcMallocCont(*contLen); if (*pRsp == NULL) { @@ -409,8 +410,6 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co } (*pRsp)->precision = htons(pQueryAttr->precision); - (*pRsp)->sVersion = htonl(pQueryAttr->tableGroupInfo.sVersion); - (*pRsp)->tVersion = htonl(pQueryAttr->tableGroupInfo.tVersion); (*pRsp)->compressed = (int8_t)((tsCompressColData != -1) && checkNeedToCompressQueryCol(pQInfo)); if (GET_NUM_OF_RESULTS(&(pQInfo->runtimeEnv)) > 0 && pQInfo->code == TSDB_CODE_SUCCESS) { @@ -446,6 +445,18 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co qDebug("QInfo:0x%"PRIx64" has more results to retrieve", pQInfo->qId); } + (*pRsp)->extend = 1; + STLV* tlv = (STLV*)((*pRsp)->data + compLen); + tlv->type = htons(TLV_TYPE_META_VERSION); + tlv->len = htonl(sizeof(int32_t) + sizeof(int32_t)); + int32_t sVersion = htonl(pQueryAttr->tableGroupInfo.sVersion); + int32_t tVersion = htonl(pQueryAttr->tableGroupInfo.tVersion); + memcpy(tlv->value, &sVersion, sizeof(int32_t)); + memcpy(tlv->value + sizeof(int32_t), &tVersion, sizeof(int32_t)); + + STLV* tlvEnd = (STLV*)((char*)tlv + sizeof(STLV) + ntohl(tlv->len)); + tlvEnd->type = htons(TLV_TYPE_END_MARK); + tlvEnd->len = 0; // the memory should be freed if the code of pQInfo is not TSDB_CODE_SUCCESS if (pQInfo->code != TSDB_CODE_SUCCESS) { rpcFreeCont(*pRsp); -- GitLab