From 8bf4ef21fac840d56ef0e51f383ab3ae7bb556ca Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Sat, 23 May 2020 15:00:22 +0800 Subject: [PATCH] fix td-317: max table name length now is 392 --- src/common/src/tname.c | 1 + src/mnode/src/mgmtTable.c | 4 ++-- tests/pytest/table/boundary.py | 37 ++++++++++++++++++++++++++++------ tests/pytest/util/sql.py | 3 +++ 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/common/src/tname.c b/src/common/src/tname.c index 29236ed0ff..3566f26abd 100644 --- a/src/common/src/tname.c +++ b/src/common/src/tname.c @@ -29,6 +29,7 @@ void extractTableName(const char* tableId, char* name) { size_t s2 = strcspn(&tableId[s1 + 1], &TS_PATH_DELIMITER[0]); strncpy(name, &tableId[s1 + s2 + 2], TSDB_TABLE_NAME_LEN); + name[TSDB_TABLE_NAME_LEN] = 0; } char* extractDBName(const char* tableId, char* name) { diff --git a/src/mnode/src/mgmtTable.c b/src/mnode/src/mgmtTable.c index f0c55449a3..87243d25c0 100644 --- a/src/mnode/src/mgmtTable.c +++ b/src/mnode/src/mgmtTable.c @@ -1139,7 +1139,7 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v prefixLen = strlen(prefix); SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER; - char stableName[TSDB_TABLE_NAME_LEN] = {0}; + char stableName[TSDB_TABLE_NAME_LEN + 1] = {0}; while (numOfRows < rows) { pShow->pIter = mgmtGetNextSuperTable(pShow->pIter, &pTable); @@ -2148,7 +2148,7 @@ static int32_t mgmtRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows, continue; } - char tableName[TSDB_TABLE_NAME_LEN] = {0}; + char tableName[TSDB_TABLE_NAME_LEN + 1] = {0}; // pattern compare for table name mgmtExtractTableName(pTable->info.tableId, tableName); diff --git a/tests/pytest/table/boundary.py b/tests/pytest/table/boundary.py index b68671c61a..29fdd5c475 100644 --- a/tests/pytest/table/boundary.py +++ b/tests/pytest/table/boundary.py @@ -10,7 +10,7 @@ from util.sql import * class TDTestCase: - def init(self, conn): + def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) @@ -95,18 +95,43 @@ class TDTestCase: maxTableNameLen = self.getLimitFromSourceCode('TSDB_TABLE_NAME_LEN') tdLog.notice("table name max length is %d" % maxTableNameLen) - name = self.generateString(maxTableNameLen - 1) - tdLog.info("table name is '%s'" % name) + # create a super table with name exceed max length + sname = self.generateString(maxTableNameLen + 1) + tdLog.info("create a super table with length %d" % len(sname)) + tdSql.error("create table %s (ts timestamp, value int) tags(id int)" % sname) - tdSql.execute("create table %s (ts timestamp, value int)" % name) - tdSql.execute("insert into %s values(now, 0)" % name) + # create a super table with name of max length + sname = self.generateString(maxTableNameLen) + tdLog.info("create a super table with length %d" % len(sname)) + tdSql.execute("create table %s (ts timestamp, value int) tags(id int)" % sname) + tdLog.info("check table count, should be one") + tdSql.query('show stables') + tdSql.checkRows(1) + + # create a child table with name exceed max length + name = self.generateString(maxTableNameLen + 1) + tdLog.info("create a child table with length %d" % len(name)) + tdSql.error("create table %s using %s tags(0)" % (name, sname)) + # create a child table with name of max length + name = self.generateString(maxTableNameLen) + tdLog.info("create a child table with length %d" % len(name)) + tdSql.execute("create table %s using %s tags(0)" % (name, sname)) tdSql.query('show tables') tdSql.checkRows(1) - tdSql.query('select * from %s' % name) + # insert one row + tdLog.info("insert one row of data") + tdSql.execute("insert into %s values(now, 0)" % name) + tdSql.query("select * from " + name) + tdSql.checkRows(1) + tdSql.query("select * from " + sname) tdSql.checkRows(1) + name = name[:len(name) - 1] + tdSql.error("select * from " + name) + tdSql.checkRows(0) + def checkRowBoundaries(self): tdLog.debug("checking row boundaries") tdSql.prepare() diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 245e4b0945..ec7ac117c0 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -58,6 +58,9 @@ class TDSql: "%s failed: sql:%s, expect error not occured" % (callerFilename, sql)) else: + self.queryRows = 0 + self.queryCols = 0 + self.queryResult = None tdLog.info("sql:%s, expect error occured" % (sql)) def query(self, sql): -- GitLab