diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index c353c4af5d25388266e7afd702ff0a3f6658707b..2ada7b32e8ad74de1a3436139cc59481d674667c 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 036a95fe15b0062fe5daff336cb4e6bda85b34b6..df1b98478c2244b15b0170e310565d8a6cddc314 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -341,6 +341,11 @@ void tscAsyncResultOnError(SSqlObj* pSql) { } int tscSendMsgToServer(SSqlObj *pSql); +void tscClearTableMeta(SSqlObj *pSql); + +static void freeElem(void* p) { + tfree(*(char**)p); +} void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { SSqlObj* pSql = (SSqlObj*)taosAcquireRef(tscObjRef, (int64_t)param); @@ -360,10 +365,23 @@ 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 && pSql->cmd.hashedTableNames) { + tscClearTableMeta(pSql); + taosArrayDestroyEx(&pSql->cmd.hashedTableNames, freeElem); + pSql->cmd.hashedTableNames = NULL; + } + } goto _error; } + if (sub->cmd.command == TSDB_SQL_MULTI_META) { + if (pSql->cmd.hashedTableNames) { + taosArrayDestroyEx(&pSql->cmd.hashedTableNames, freeElem); + pSql->cmd.hashedTableNames = NULL; + } + } + tscDebug("0x%"PRIx64" get %s successfully", pSql->self, msg); if (pSql->pStream == NULL) { SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); @@ -426,3 +444,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 7ba67ca878b479cb0573ae1a82398339e57f32be..3d806bdac5758016aef05786510a443de56c6120 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -10083,6 +10083,15 @@ 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); + + if (pCmd->hashedTableNames == NULL) { + pCmd->hashedTableNames = taosArrayInit(4, POINTER_BYTES); + } + + if (pCmd->hashedTableNames) { + 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/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 3edfe997495c3ecda8933bca7133fd5ae3532caa..a5b683d4c884d80b54642332ca211fe419f2f67e 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -740,6 +740,7 @@ 4,,system-test,python3 ./test.py -f 2-query/TD-11561.py 4,,system-test,python3 test.py -f 1-insert/stmt_error.py 4,,pytest,python3 test.py -f user/pass_len.py +4,,pytest,python3 test.py -f client/dropTable.py 4,,pytest,python3 test.py -f TimeZone/TestCaseTimeZone.py 4,,pytest,python3 test.py -f tag_lite/unsignedBigint.py 4,,pytest,python3 test.py -f tag_lite/tinyint.py diff --git a/tests/pytest/client/dropTable.py b/tests/pytest/client/dropTable.py new file mode 100644 index 0000000000000000000000000000000000000000..af7a3a4c69f503dba2684cc4c02bace9af9ed4ac --- /dev/null +++ b/tests/pytest/client/dropTable.py @@ -0,0 +1,46 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * +import multiprocessing as mp + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + self.ts = 1609430400000 + + def run(self): + tdSql.prepare() + os.system("taos -s 'create table db.st(ts timestamp, c1 int, c2 float) tags(t1 int)' ") + os.system("taos -s 'create table db.t1 using db.st tags(1)' ") + os.system("taos -s 'insert into t1 values(%d, 1, 1.11)'" % self.ts) + os.system("taos -s 'desc db.st'") + tdSql.query("desc db.st") + tdSql.checkRows(4) + + os.system("taos -s 'drop table db.st'") + tdSql.error("select * from db.st") + tdSql.error("desc db.st") + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file