From 1eba18490741c02360e4b3420334fad392bb76aa Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Jul 2022 15:58:21 +0800 Subject: [PATCH 1/4] fix: fix stmt rerun issue --- source/client/src/clientStmt.c | 18 ++++++++++++++++++ source/libs/planner/src/planPhysiCreater.c | 1 + 2 files changed, 19 insertions(+) diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 1e0f30695d..77e16a5318 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -351,6 +351,7 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { pStmt->bInfo.inExecCache = true; if (pStmt->sql.autoCreateTbl) { + tscDebug("reuse stmt block for tb %s in execBlock", pStmt->bInfo.tbFName); return TSDB_CODE_SUCCESS; } } @@ -359,9 +360,11 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { if (pStmt->bInfo.inExecCache) { ASSERT(taosHashGetSize(pStmt->exec.pBlockHash) == 1); pStmt->bInfo.needParse = false; + tscDebug("reuse stmt block for tb %s in execBlock", pStmt->bInfo.tbFName); return TSDB_CODE_SUCCESS; } + tscDebug("no stmt block cache for tb %s", pStmt->bInfo.tbFName); return TSDB_CODE_SUCCESS; } @@ -385,6 +388,8 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } + tscDebug("reuse stmt block for tb %s in sqlBlock, suid:0x%" PRIx64 , pStmt->bInfo.tbFName, pStmt->bInfo.tbSuid); + return TSDB_CODE_SUCCESS; } @@ -400,6 +405,8 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) { STMT_ERR_RET(stmtCleanBindInfo(pStmt)); + tscDebug("tb %s not exist", pStmt->bInfo.tbFName); + return TSDB_CODE_SUCCESS; } @@ -414,6 +421,8 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { if (uid == pStmt->bInfo.tbUid) { pStmt->bInfo.needParse = false; + tscDebug("tb %s is current table", pStmt->bInfo.tbFName); + return TSDB_CODE_SUCCESS; } @@ -434,6 +443,8 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { pStmt->bInfo.boundTags = pCache->boundTags; pStmt->bInfo.tagsCached = true; + tscDebug("tb %s in execBlock list, set to current", pStmt->bInfo.tbFName); + return TSDB_CODE_SUCCESS; } @@ -455,6 +466,8 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } + tscDebug("tb %s in sqlBlock list, set to current", pStmt->bInfo.tbFName); + return TSDB_CODE_SUCCESS; } @@ -523,6 +536,8 @@ int stmtPrepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { int stmtSetTbName(TAOS_STMT* stmt, const char* tbName) { STscStmt* pStmt = (STscStmt*)stmt; + tscDebug("start to set stmt tbName: %s", tbName); + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTBNAME)); int32_t insert = 0; @@ -568,6 +583,7 @@ int stmtSetTbTags(TAOS_STMT* stmt, TAOS_MULTI_BIND* tags) { STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } + tscDebug("start to bind stmt tag values"); STMT_ERR_RET(qBindStmtTagsValue(*pDataBlock, pStmt->bInfo.boundTags, pStmt->bInfo.tbSuid, pStmt->bInfo.sname.tname, tags, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen)); @@ -713,6 +729,8 @@ int stmtAddBatch(TAOS_STMT* stmt) { } int stmtUpdateTableUid(STscStmt* pStmt, SSubmitRsp* pRsp) { + tscDebug("start to update stmt tbUid"); + if (pRsp->nBlocks <= 0) { tscError("invalid submit resp block number %d", pRsp->nBlocks); STMT_ERR_RET(TSDB_CODE_TSC_APP_ERROR); diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 18d69d21d8..0876a3e3bb 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -1522,6 +1522,7 @@ static SSubplan* makeSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubpl static int32_t buildInsertValuesSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, SSubplan* pSubplan) { pSubplan->msgType = pModify->msgType; + pSubplan->execNode.nodeId = pModify->pVgDataBlocks->vg.vgId; pSubplan->execNode.epSet = pModify->pVgDataBlocks->vg.epSet; return createDataInserter(pCxt, pModify->pVgDataBlocks, &pSubplan->pDataSink); } From c8e1e2a09ee9d32aad17173237a6205bdde93c7e Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Jul 2022 16:28:55 +0800 Subject: [PATCH 2/4] fix: fix stmt rerun --- source/client/src/clientStmt.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 77e16a5318..3df6169591 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -517,6 +517,8 @@ TAOS_STMT* stmtInit(STscObj* taos) { int stmtPrepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { STscStmt* pStmt = (STscStmt*)stmt; + tscDebug("stmt start to prepare"); + if (pStmt->sql.status >= STMT_PREPARE) { STMT_ERR_RET(stmtResetStmt(pStmt)); } @@ -536,7 +538,7 @@ int stmtPrepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { int stmtSetTbName(TAOS_STMT* stmt, const char* tbName) { STscStmt* pStmt = (STscStmt*)stmt; - tscDebug("start to set stmt tbName: %s", tbName); + tscDebug("stmt start to set tbName: %s", tbName); STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTBNAME)); @@ -570,6 +572,8 @@ int stmtSetTbName(TAOS_STMT* stmt, const char* tbName) { int stmtSetTbTags(TAOS_STMT* stmt, TAOS_MULTI_BIND* tags) { STscStmt* pStmt = (STscStmt*)stmt; + tscDebug("stmt start to set tbTags"); + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS)); if (pStmt->bInfo.inExecCache) { @@ -629,6 +633,8 @@ int stmtFetchColFields(STscStmt* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { STscStmt* pStmt = (STscStmt*)stmt; + tscDebug("start to bind stmt data, colIdx: %d", colIdx); + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND)); if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && @@ -721,6 +727,8 @@ int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { int stmtAddBatch(TAOS_STMT* stmt) { STscStmt* pStmt = (STscStmt*)stmt; + tscDebug("stmt start to add batch"); + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_ADD_BATCH)); STMT_ERR_RET(stmtCacheBlock(pStmt)); @@ -729,7 +737,7 @@ int stmtAddBatch(TAOS_STMT* stmt) { } int stmtUpdateTableUid(STscStmt* pStmt, SSubmitRsp* pRsp) { - tscDebug("start to update stmt tbUid"); + tscDebug("stmt start to update tbUid, blockNum: %d", pRsp->nBlocks); if (pRsp->nBlocks <= 0) { tscError("invalid submit resp block number %d", pRsp->nBlocks); @@ -791,6 +799,8 @@ int stmtExec(TAOS_STMT* stmt) { SSubmitRsp* pRsp = NULL; bool autoCreateTbl = pStmt->exec.autoCreateTbl; + tscDebug("stmt start to exec"); + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE)); if (STMT_TYPE_QUERY == pStmt->sql.type) { From e69f59ba7769f5a7cd4db490cbcaa76fb47c0c9e Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Jul 2022 17:38:09 +0800 Subject: [PATCH 3/4] fix: fix stmt rerun issue --- source/libs/parser/inc/parInsertData.h | 1 + source/libs/parser/src/parInsertData.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/source/libs/parser/inc/parInsertData.h b/source/libs/parser/inc/parInsertData.h index 167970838b..ea78735d5e 100644 --- a/source/libs/parser/inc/parInsertData.h +++ b/source/libs/parser/inc/parInsertData.h @@ -20,6 +20,7 @@ #include "os.h" #include "tname.h" #include "ttypes.h" +#include "query.h" #define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED) diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index 84bcef7185..290c65de12 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -630,6 +630,17 @@ int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) { memcpy(*pDst, pSrc, sizeof(STableDataBlocks)); ((STableDataBlocks*)(*pDst))->cloned = true; + STableDataBlocks* pBlock = (STableDataBlocks*)(*pDst); + if (pBlock->pTableMeta) { + void *pNewMeta = taosMemoryMalloc(TABLE_META_SIZE(pBlock->pTableMeta)); + if (NULL == pNewMeta) { + taosMemoryFreeClear(*pDst); + return TSDB_CODE_OUT_OF_MEMORY; + } + memcpy(pNewMeta, pBlock->pTableMeta, TABLE_META_SIZE(pBlock->pTableMeta)); + pBlock->pTableMeta = pNewMeta; + } + return qResetStmtDataBlock(*pDst, false); } From f3d298c81f6e72bb9df15493d82c977e740a395c Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 11 Jul 2022 17:51:03 +0800 Subject: [PATCH 4/4] fix: fix stmt rerun issue --- source/client/src/clientStmt.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 3df6169591..75567404df 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -751,11 +751,6 @@ int stmtUpdateTableUid(STscStmt* pStmt, SSubmitRsp* pRsp) { char* key = taosHashGetKey(pIter, &keyLen); STableMeta* pMeta = qGetTableMetaInDataBlock(pBlock); - if (pMeta->uid != pStmt->bInfo.tbUid) { - tscError("table uid %" PRIx64 " mis-match with current table uid %" PRIx64, pMeta->uid, pStmt->bInfo.tbUid); - STMT_ERR_RET(TSDB_CODE_TSC_APP_ERROR); - } - if (pMeta->uid) { pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); continue;