From 2a5943b7fa41296005791d875fe74d25c38aaab4 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Mon, 10 Jan 2022 11:42:54 +0800 Subject: [PATCH] (query):renew table meta when cache meta version is lower than version from tasd --- src/client/src/tscServer.c | 19 +++++++++++++++++++ src/client/src/tscUtil.c | 17 +---------------- src/inc/taoserror.h | 1 + 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index af4c80eec1..8d8f3a6863 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -511,6 +511,19 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) { } bool shouldFree = tscShouldBeFreed(pSql); + if (rpcMsg->code == TSDB_CODE_TSC_INVALID_SCHEMA_VERSION) { + pSql->res.code = rpcMsg->code; + tscWarn("0x%" PRIx64 " it shall renew table meta, code:%s, retry:%d", pSql->self, tstrerror(rpcMsg->code), pSql->retry); + + ++pSql->retry; + if (pSql->retry > pSql->maxRetry) { + tscError("0x%" PRIx64 " max retry %d reached, give up", pSql->self, pSql->maxRetry); + } else { + pSql->retryReason = rpcMsg->code; + rpcMsg->code = tscRenewTableMeta(pSql); + } + } + if (rpcMsg->code != TSDB_CODE_TSC_ACTION_IN_PROGRESS) { if (rpcMsg->code != TSDB_CODE_SUCCESS) { pRes->code = rpcMsg->code; @@ -2820,6 +2833,12 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) { tlv = (STLV*) ((char*)tlv + sizeof(STLV) + ntohl(tlv->len)); } } + + STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; + if (pTableMeta->sversion < pSql->res.sVersion || pTableMeta->tversion < pSql->res.tVersion) { + return TSDB_CODE_TSC_INVALID_SCHEMA_VERSION; + } + return 0; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index ce9791523c..691eea9033 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1713,21 +1713,6 @@ 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) { @@ -1746,7 +1731,7 @@ void tscFreeSqlObj(SSqlObj* pSql) { pSql->self = 0; tscFreeSqlResult(pSql); - tscResetSqlCmd(pCmd, clearCachedMeta, pSql->self); + tscResetSqlCmd(pCmd, false, pSql->self); tfree(pCmd->payload); pCmd->allocSize = 0; diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index fb70badb86..0eb2479447 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -115,6 +115,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TSC_INVALID_PROTOCOL_TYPE TAOS_DEF_ERROR_CODE(0, 0x0225) //"Invalid line protocol type") #define TSDB_CODE_TSC_INVALID_PRECISION_TYPE TAOS_DEF_ERROR_CODE(0, 0x0226) //"Invalid timestamp precision type") #define TSDB_CODE_TSC_RES_TOO_MANY TAOS_DEF_ERROR_CODE(0, 0x0227) //"Result set too large to be output") +#define TSDB_CODE_TSC_INVALID_SCHEMA_VERSION TAOS_DEF_ERROR_CODE(0, 0x0228) //"invalid table schema version") // mnode #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed" -- GitLab