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 57362499a4fcaaa1500b199de8f63c07a03af898..c3982f04ec2b5cb335d82604075522bfd0daece5 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2755,6 +2755,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 322413a3cd7e637c477903b09522f60c11056885..a3bc278fe49c0f0fd65b3e2527513cd3bcf99d38 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1701,6 +1701,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) { @@ -1719,7 +1734,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 a44e958be4345d4aa131cab8f616e0460624e8c1..6dbfe89a50542ad892745a63e5acde3dd7596af3 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -228,6 +228,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 be734ce0cccad6827cba4e2c27d0be478af92af3..b6b8d94faec4943360f0ff95b610c5db1cb06a12 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -3715,7 +3715,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)); @@ -3802,6 +3803,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: @@ -3818,6 +3822,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); @@ -3839,6 +3845,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) { @@ -3853,6 +3871,9 @@ int32_t tsdbGetTableGroupFromIdList(STsdbRepo* tsdb, SArray* pTableIdList, STabl taosArrayDestroy(&group); } + pGroupInfo->sVersion = sVersion; + pGroupInfo->tVersion = tVersion; + return TSDB_CODE_SUCCESS; }