diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index a4ad35e3d63c08271bd5f431244a755b5c6f892d..85bdfa43fdf164ac2a3a51b5d8bba047821267c0 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -294,6 +294,7 @@ typedef struct { SQueryInfo *active; // current active query info int32_t batchSize; // for parameter ('?') binding and batch processing int32_t resColumnId; + SArray *hashedTableNames; } SSqlCmd; typedef struct { diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 2ddae0f903a6c42235343a6dd526d37e53147734..4ac23241fa45bdd8554c2a142f74b45f5714e086 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -336,6 +336,7 @@ void tscAsyncResultOnError(SSqlObj* pSql) { } int tscSendMsgToServer(SSqlObj *pSql); +void tscClearTableMeta(SSqlObj *pSql); void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { SSqlObj* pSql = (SSqlObj*)taosAcquireRef(tscObjRef, (int64_t)param); @@ -355,7 +356,11 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { size_t sz = strlen(tscGetErrorMsgPayload(&sub->cmd)); tscAllocPayload(&pSql->cmd, (int)sz + 1); memcpy(tscGetErrorMsgPayload(&pSql->cmd), tscGetErrorMsgPayload(&sub->cmd), sz); - } + } else if (code == TSDB_CODE_MND_INVALID_TABLE_NAME) { + if (sub->cmd.command == TSDB_SQL_MULTI_META) { + tscClearTableMeta(pSql); + } + } goto _error; } @@ -421,3 +426,13 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { tscAsyncResultOnError(pSql); taosReleaseRef(tscObjRef, pSql->self); } + +void tscClearTableMeta(SSqlObj *pSql) { + SSqlCmd* pCmd = &pSql->cmd; + + int32_t n = taosArrayGetSize(pCmd->hashedTableNames); + for (int32_t i = 0; i < n; i++) { + char *t = taosArrayGetP(pCmd->hashedTableNames, i); + taosHashRemove(UTIL_GET_TABLEMETA(pSql), t, strlen(t)); + } +} diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 2f0bf35e34626b1d3c661328ddd4f01584e7ac9a..4bac9f50b68a367507b2c7be4ef8f59c802a4a9c 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -9434,6 +9434,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); pCmd->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + pCmd->hashedTableNames = taosArrayInit(4, POINTER_BYTES); tableNameList = taosArrayInit(4, sizeof(SName)); size_t size = taosArrayGetSize(pInfo->list); @@ -9501,6 +9502,9 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { char* t = strdup(name); taosArrayPush(pVgroupList, &t); tscDebug("0x%"PRIx64" failed to retrieve stable %s vgroup id list in cache, try fetch from mnode", pSql->self, name); + + char* tb = strdup(name); + taosArrayPush(pCmd->hashedTableNames, &tb); } else { tFilePage* pdata = (tFilePage*) pv; pVgroupIdList = taosArrayInit((size_t) pdata->num, sizeof(int32_t)); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index ec4f2c1daf4cd35a984f7e2f2cf4dab8f47659f8..604af969dabcc6b7a60f079452d832a159e5d8c7 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1609,6 +1609,10 @@ void destroyTableNameList(SInsertStatementParam* pInsertParam) { tfree(pInsertParam->pTableNameList); } +static void freeElem(void* p) { + tfree(*(char**)p); +} + void tscResetSqlCmd(SSqlCmd* pCmd, bool clearCachedMeta, uint64_t id) { SSqlObj *pSql = (SSqlObj*)taosAcquireRef(tscObjRef, id); pCmd->command = 0; @@ -1624,6 +1628,10 @@ void tscResetSqlCmd(SSqlCmd* pCmd, bool clearCachedMeta, uint64_t id) { tfree(pCmd->insertParam.tagData.data); pCmd->insertParam.tagData.dataLen = 0; + if (pCmd->hashedTableNames) { + taosArrayDestroyEx(&pCmd->hashedTableNames, freeElem); + } + tscFreeQueryInfo(pCmd, clearCachedMeta, id); pCmd->pTableMetaMap = tscCleanupTableMetaMap(pCmd->pTableMetaMap); taosReleaseRef(tscObjRef, id);