diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index c5e3cb727f85dafd2b51efe741cd635394908cfd..48cc71bc9f9b9b47203f2838e9982618cc8d18ac 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 7f8e9066af2ea05dd2cc50d8a9e156a5b44cb6cc..6990d1d4a1f00f300af5dfa652e9e01e73d11f50 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 f29c3c8eb6057f9bfeec54079112957eb504dbac..2b915419e3b65b24d2f2b59b471cb4f9c76d8bfb 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 9dc76466aadbe9781dbdd727a524a32f8103650f..adba15e02a0ba479286d83a899a8ead7b8e3fcfa 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 d9c93e8cce4fd54e3417b7d335d05cfcba185c42..eeff90bd5399c1ff2e08b1254fc63c9e53d3cbc3 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 f7a895e2c08d8b9dd3e0d72c66f118b61b29bc47..8ea85041c04554eb8dc37d26ea0e16c461e209c3 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 cf4d190ff3511ed25cc49fc34296e2dcd3dfb3b4..3fca33d4d5aeed158863216c34580181b283ec88 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; }