From 833cda17194486122051949c2f983bdaac400f77 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Tue, 28 Dec 2021 11:26:03 +0800 Subject: [PATCH] [TD-11389](query):pass sverion/tversion from vnode to client so that client can clear meta when its meta is older --- src/client/inc/tsclient.h | 2 ++ src/client/src/tscServer.c | 2 ++ src/client/src/tscUtil.c | 17 ++++++++++++++++- src/inc/taosmsg.h | 2 ++ src/inc/tsdb.h | 2 ++ src/query/src/queryMain.c | 2 ++ src/tsdb/src/tsdbRead.c | 23 ++++++++++++++++++++++- 7 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index c5e3cb727f..48cc71bc9f 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -307,6 +307,8 @@ typedef struct { int32_t row; int16_t numOfCols; int16_t precision; + int32_t sVersion; + int32_t tVersion; bool completed; int32_t code; char * data; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 7f8e9066af..6990d1d4a1 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2756,6 +2756,8 @@ 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); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index f29c3c8eb6..2b915419e3 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1713,6 +1713,21 @@ void tscFreeSqlObj(SSqlObj* pSql) { tscFreeMetaSqlObj(&pSql->svgroupRid); SSqlCmd* pCmd = &pSql->cmd; + bool clearCachedMeta = false; + SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); + if (pQueryInfo != NULL) { + STableMeta* pTableMeta = NULL; + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + if (pTableMetaInfo != NULL) { + pTableMeta = pTableMetaInfo->pTableMeta; + } + if (pTableMeta != NULL) { + if (pTableMeta->sversion < pSql->res.sVersion || pTableMeta->tversion < pSql->res.tVersion) { + clearCachedMeta = true; + } + } + } + int32_t cmd = pCmd->command; if (cmd < TSDB_SQL_INSERT || cmd == TSDB_SQL_RETRIEVE_GLOBALMERGE || cmd == TSDB_SQL_RETRIEVE_EMPTY_RESULT || cmd == TSDB_SQL_TABLE_JOIN_RETRIEVE) { @@ -1731,7 +1746,7 @@ void tscFreeSqlObj(SSqlObj* pSql) { pSql->self = 0; tscFreeSqlResult(pSql); - tscResetSqlCmd(pCmd, false, pSql->self); + tscResetSqlCmd(pCmd, clearCachedMeta, pSql->self); tfree(pCmd->payload); pCmd->allocSize = 0; diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 9dc76466aa..adba15e02a 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -545,6 +545,8 @@ typedef struct SRetrieveTableRsp { int32_t numOfRows; int8_t completed; // all results are returned to client int16_t precision; + int32_t sVersion; + int32_t tVersion; int64_t offset; // updated offset value for multi-vnode projection query int64_t useconds; int8_t compressed; diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index d9c93e8cce..eeff90bd53 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -229,6 +229,8 @@ typedef struct { uint32_t numOfTables; SArray *pGroupList; SHashObj *map; // speedup acquire the tableQueryInfo by table uid + int32_t sVersion; + int32_t tVersion; } STableGroupInfo; #define TSDB_BLOCK_DIST_STEP_ROWS 16 diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index f7a895e2c0..8ea85041c0 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -407,6 +407,8 @@ 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) { diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index cf4d190ff3..3fca33d4d5 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -3981,7 +3981,8 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons pGroupInfo->numOfTables = (uint32_t) taosArrayGetSize(res); pGroupInfo->pGroupList = createTableGroup(res, pTagSchema, pColIndex, numOfCols, skey); - + pGroupInfo->sVersion = tsdbGetTableSchema(pTable)->version; + pGroupInfo->tVersion = pTagSchema->version; tsdbDebug("%p no table name/tag condition, all tables qualified, numOfTables:%u, group:%zu", tsdb, pGroupInfo->numOfTables, taosArrayGetSize(pGroupInfo->pGroupList)); @@ -4068,6 +4069,9 @@ int32_t tsdbGetOneTableGroup(STsdbRepo* tsdb, uint64_t uid, TSKEY startKey, STab taosArrayPush(group, &info); taosArrayPush(pGroupInfo->pGroupList, &group); + + pGroupInfo->sVersion = tsdbGetTableSchema(pTable)->version; + pGroupInfo->tVersion = tsdbGetTableTagSchema(pTable)->version; return TSDB_CODE_SUCCESS; _error: @@ -4084,6 +4088,8 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl pGroupInfo->pGroupList = taosArrayInit(1, POINTER_BYTES); SArray* group = taosArrayInit(1, sizeof(STableKeyInfo)); + int32_t sVersion = -1; + int32_t tVersion = -1; for(int32_t i = 0; i < size; ++i) { STableIdInfo *id = taosArrayGet(pTableIdList, i); @@ -4105,6 +4111,18 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl STableKeyInfo info = {.pTable = pTable, .lastKey = id->key}; taosArrayPush(group, &info); + + if (sVersion == -1) { + sVersion = tsdbGetTableSchema(pTable)->version; + } else { + assert (sVersion == tsdbGetTableSchema(pTable)->version); + } + + if (tVersion == -1) { + tVersion = tsdbGetTableTagSchema(pTable)->version; + } else { + assert (tVersion == tsdbGetTableTagSchema(pTable)->version); + } } if (tsdbUnlockRepoMeta(tsdb) < 0) { @@ -4119,6 +4137,9 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl taosArrayDestroy(&group); } + pGroupInfo->sVersion = sVersion; + pGroupInfo->tVersion = tVersion; + return TSDB_CODE_SUCCESS; } -- GitLab