diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 1b44b6d7ea..9b301f5d10 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -108,7 +108,7 @@ extern float tsStreamComputDelayRatio; // the delayed computing ration of the extern int64_t tsMaxRetentWindow; // build info -extern char version[]; +extern char td_version[]; extern char compatible_version[]; extern char gitinfo[]; extern char buildinfo[]; diff --git a/include/util/version.h b/include/util/version.h index bac29e5baf..ef6bfdc182 100644 --- a/include/util/version.h +++ b/include/util/version.h @@ -20,7 +20,7 @@ extern "C" { #endif -extern char version[]; +extern char td_version[]; extern char compatible_version[]; extern char gitinfo[]; extern char buildinfo[]; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 83b481658e..bdea03520a 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -397,7 +397,7 @@ const char *taos_data_type(int type) { } } -const char *taos_get_client_info() { return version; } +const char *taos_get_client_info() { return td_version; } int taos_affected_rows(TAOS_RES *res) { if (res == NULL || TD_RES_TMQ(res)) { diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index fbb4f78425..68a445db6a 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -362,7 +362,7 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) { if (cfgAddString(pCfg, "os version", info.version, 1) != 0) return -1; if (cfgAddString(pCfg, "os machine", info.machine, 1) != 0) return -1; - if (cfgAddString(pCfg, "version", version, 1) != 0) return -1; + if (cfgAddString(pCfg, "version", td_version, 1) != 0) return -1; if (cfgAddString(pCfg, "compatible_version", compatible_version, 1) != 0) return -1; if (cfgAddString(pCfg, "gitinfo", gitinfo, 1) != 0) return -1; if (cfgAddString(pCfg, "buildinfo", buildinfo, 1) != 0) return -1; diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 2b0f6a01a0..05e246ffe8 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -114,7 +114,7 @@ static void dmPrintVersion() { #else char *releaseName = "community"; #endif - printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version); + printf("%s version: %s compatible_version: %s\n", releaseName, td_version, compatible_version); printf("gitinfo: %s\n", gitinfo); printf("buildInfo: %s\n", buildinfo); } diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index ef9276caf6..4a1f0695a9 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -117,7 +117,7 @@ static void *mndThreadFp(void *param) { setThreadName("mnode-timer"); while (1) { - if (lastTime % (100) == 0) { // sleep 1 day for ttl + if (lastTime % (864000) == 0) { // sleep 1 day for ttl mndPushTtlTime(pMnode); } @@ -642,7 +642,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr } // cluster info - tstrncpy(pClusterInfo->version, version, sizeof(pClusterInfo->version)); + tstrncpy(pClusterInfo->version, td_version, sizeof(pClusterInfo->version)); pClusterInfo->monitor_interval = tsMonitorInterval; pClusterInfo->connections_total = mndGetNumOfConnections(pMnode); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 4cfcf389aa..f5a046ae52 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -232,7 +232,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { connectRsp.connType = connReq.connType; connectRsp.dnodeNum = mndGetDnodeSize(pMnode); - snprintf(connectRsp.sVersion, sizeof(connectRsp.sVersion), "ver:%s\nbuild:%s\ngitinfo:%s", version, buildinfo, + snprintf(connectRsp.sVersion, sizeof(connectRsp.sVersion), "ver:%s\nbuild:%s\ngitinfo:%s", td_version, buildinfo, gitinfo); mndGetMnodeEpSet(pMnode, &connectRsp.epSet); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 9c45fa352f..e0e3166e28 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -280,7 +280,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { } } - if (pOld->commentLen < pNew->commentLen) { + if (pOld->commentLen < pNew->commentLen && pNew->commentLen > 0) { void *comment = taosMemoryMalloc(pNew->commentLen + 1); if (comment != NULL) { taosMemoryFree(pOld->comment); @@ -291,6 +291,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { taosWUnLockLatch(&pOld->lock); } } + pOld->commentLen = pNew->commentLen; if (pOld->ast1Len < pNew->ast1Len) { void *pAst1 = taosMemoryMalloc(pNew->ast1Len); @@ -325,7 +326,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { pOld->numOfTags = pNew->numOfTags; memcpy(pOld->pColumns, pNew->pColumns, pOld->numOfColumns * sizeof(SSchema)); memcpy(pOld->pTags, pNew->pTags, pOld->numOfTags * sizeof(SSchema)); - if (pNew->commentLen != 0) { + if (pNew->commentLen > 0) { memcpy(pOld->comment, pNew->comment, pNew->commentLen + 1); } if (pNew->ast1Len != 0) { diff --git a/source/dnode/mnode/impl/src/mndTelem.c b/source/dnode/mnode/impl/src/mndTelem.c index 27814fe5be..d11e0c214f 100644 --- a/source/dnode/mnode/impl/src/mndTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -110,7 +110,7 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) { snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB); tjsonAddStringToObject(pJson, "memory", tmp); - tjsonAddStringToObject(pJson, "version", version); + tjsonAddStringToObject(pJson, "version", td_version); tjsonAddStringToObject(pJson, "buildInfo", buildinfo); tjsonAddStringToObject(pJson, "gitInfo", gitinfo); tjsonAddStringToObject(pJson, "email", pMgmt->email); diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 4d53059957..bf5d5912f9 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -400,8 +400,8 @@ static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME){ if (ttlDays <= 0) return; -// ttlKey->dtime = ctime / 1000 + ttlDays * 24 * 60 * 60; - ttlKey->dtime = ctime / 1000 + ttlDays; + ttlKey->dtime = ctime / 1000 + ttlDays * 24 * 60 * 60; +// ttlKey->dtime = ctime / 1000 + ttlDays; ttlKey->uid = pME->uid; } @@ -499,7 +499,6 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl tDecoderInit(&dc, entry.pBuf, nData); ret = metaDecodeEntry(&dc, &entry); ASSERT(ret == 0); - tDecoderClear(&dc); if (entry.type != TSDB_NORMAL_TABLE) { terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION; @@ -597,12 +596,16 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl if (pNewSchema) taosMemoryFree(pNewSchema); tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); + tDecoderClear(&dc); + return 0; _err: if (entry.pBuf) taosMemoryFree(entry.pBuf); tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); + tDecoderClear(&dc); + return -1; } @@ -800,7 +803,6 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p tDecoderInit(&dc, entry.pBuf, nData); ret = metaDecodeEntry(&dc, &entry); ASSERT(ret == 0); - tDecoderClear(&dc); entry.version = version; metaWLock(pMeta); @@ -834,6 +836,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); + tDecoderClear(&dc); if (entry.pBuf) taosMemoryFree(entry.pBuf); return 0; } diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index 02c485fa83..4d648539a9 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -785,7 +785,7 @@ static void udfdPrintVersion() { #else char *releaseName = "community"; #endif - printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version); + printf("%s version: %s compatible_version: %s\n", releaseName, td_version, compatible_version); printf("gitinfo: %s\n", gitinfo); printf("buildInfo: %s\n", buildinfo); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index f2f8b164ee..b2a36f9af5 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -895,9 +895,15 @@ SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType case TABLE_OPTION_ROLLUP: ((STableOptions*)pOptions)->pRollupFuncs = pVal; break; - case TABLE_OPTION_TTL: - ((STableOptions*)pOptions)->ttl = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); + case TABLE_OPTION_TTL:{ + int64_t ttl = taosStr2Int64(((SToken*)pVal)->z, NULL, 10); + if (ttl > INT32_MAX){ + ttl = INT32_MAX; + } + // ttl can not be smaller than 0, because there is a limitation in sql.y (TTL NK_INTEGER) + ((STableOptions*)pOptions)->ttl = ttl; break; + } case TABLE_OPTION_SMA: ((STableOptions*)pOptions)->pSma = pVal; break; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 2a559b4864..dae5d08fdd 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2810,9 +2810,6 @@ static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt if (TSDB_CODE_SUCCESS == code) { code = checkTableRollupOption(pCxt, pStmt->pOptions->pRollupFuncs); } - if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "ttl", pStmt->pOptions->ttl, TSDB_MIN_TABLE_TTL, INT32_MAX); - } if (TSDB_CODE_SUCCESS == code) { code = checkTableSmaOption(pCxt, pStmt); } @@ -4995,11 +4992,8 @@ static int32_t buildUpdateOptionsReq(STranslateContext* pCxt, SAlterTableStmt* p int32_t code = TSDB_CODE_SUCCESS; if (-1 != pStmt->pOptions->ttl) { - code = checkRangeOption(pCxt, "ttl", pStmt->pOptions->ttl, TSDB_MIN_TABLE_TTL, INT32_MAX); - if (TSDB_CODE_SUCCESS == code) { - pReq->updateTTL = true; - pReq->newTTL = pStmt->pOptions->ttl; - } + pReq->updateTTL = true; + pReq->newTTL = pStmt->pOptions->ttl; } if (TSDB_CODE_SUCCESS == code){ diff --git a/source/util/src/version.c.in b/source/util/src/version.c.in index be1a4a4048..4d00ba90c0 100644 --- a/source/util/src/version.c.in +++ b/source/util/src/version.c.in @@ -1,4 +1,4 @@ -char version[12] = "${TD_VER_NUMBER}"; +char td_version[12] = "${TD_VER_NUMBER}"; char compatible_version[12] = "${TD_VER_COMPATIBLE}"; char gitinfo[48] = "${TD_VER_GIT}"; char buildinfo[64] = "Built at ${TD_VER_DATE}"; diff --git a/tests/system-test/2-query/ttl_comment.py b/tests/system-test/2-query/ttl_comment.py new file mode 100644 index 0000000000..f303b67907 --- /dev/null +++ b/tests/system-test/2-query/ttl_comment.py @@ -0,0 +1,181 @@ +################################################################### +# 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, db_test.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 tdLog +from util.cases import tdCases +from util.sql import tdSql + +class TDTestCase: + def caseDescription(self): + ''' + ttl/comment test + ''' + return + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + + tdSql.error("create table ttl_table1(ts timestamp, i int) ttl 1.1") + tdSql.error("create table ttl_table2(ts timestamp, i int) ttl 1e1") + tdSql.error("create table ttl_table3(ts timestamp, i int) ttl -1") + + print("============== STEP 1 ===== test normal table") + + tdSql.execute("create table normal_table1(ts timestamp, i int)") + tdSql.execute("create table normal_table2(ts timestamp, i int) comment '' ttl 3") + tdSql.execute("create table normal_table3(ts timestamp, i int) ttl 2100000000020 comment 'hello'") + + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 7, 0) + tdSql.checkData(0, 8, None) + + + tdSql.query("show tables like 'normal_table2'") + tdSql.checkData(0, 0, 'normal_table2') + tdSql.checkData(0, 7, 3) + tdSql.checkData(0, 8, '') + + + tdSql.query("show tables like 'normal_table3'") + tdSql.checkData(0, 0, 'normal_table3') + tdSql.checkData(0, 7, 2147483647) + tdSql.checkData(0, 8, 'hello') + + tdSql.execute("alter table normal_table1 comment 'nihao'") + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 8, 'nihao') + + tdSql.execute("alter table normal_table1 comment ''") + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 8, '') + + tdSql.execute("alter table normal_table2 comment 'fly'") + tdSql.query("show tables like 'normal_table2'") + tdSql.checkData(0, 0, 'normal_table2') + tdSql.checkData(0, 8, 'fly') + + tdSql.execute("alter table normal_table3 comment 'fly'") + tdSql.query("show tables like 'normal_table3'") + tdSql.checkData(0, 0, 'normal_table3') + tdSql.checkData(0, 8, 'fly') + + tdSql.execute("alter table normal_table1 ttl 1") + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 7, 1) + + tdSql.execute("alter table normal_table3 ttl 0") + tdSql.query("show tables like 'normal_table3'") + tdSql.checkData(0, 0, 'normal_table3') + tdSql.checkData(0, 7, 0) + + + print("============== STEP 2 ===== test super table") + + tdSql.execute("create table super_table1(ts timestamp, i int) tags(t int)") + tdSql.execute("create table super_table2(ts timestamp, i int) tags(t int) comment ''") + tdSql.execute("create table super_table3(ts timestamp, i int) tags(t int) comment 'super'") + + tdSql.query("show stables like 'super_table1'") + tdSql.checkData(0, 0, 'super_table1') + tdSql.checkData(0, 6, None) + + + tdSql.query("show stables like 'super_table2'") + tdSql.checkData(0, 0, 'super_table2') + tdSql.checkData(0, 6, '') + + + tdSql.query("show stables like 'super_table3'") + tdSql.checkData(0, 0, 'super_table3') + tdSql.checkData(0, 6, 'super') + + + tdSql.execute("alter table super_table1 comment 'nihao'") + tdSql.query("show stables like 'super_table1'") + tdSql.checkData(0, 0, 'super_table1') + tdSql.checkData(0, 6, 'nihao') + + tdSql.execute("alter table super_table1 comment ''") + tdSql.query("show stables like 'super_table1'") + tdSql.checkData(0, 0, 'super_table1') + tdSql.checkData(0, 6, '') + + tdSql.execute("alter table super_table2 comment 'fly'") + tdSql.query("show stables like 'super_table2'") + tdSql.checkData(0, 0, 'super_table2') + tdSql.checkData(0, 6, 'fly') + + tdSql.execute("alter table super_table3 comment 'tdengine'") + tdSql.query("show stables like 'super_table3'") + tdSql.checkData(0, 0, 'super_table3') + tdSql.checkData(0, 6, 'tdengine') + + print("============== STEP 3 ===== test child table") + + tdSql.execute("create table child_table1 using super_table1 tags(1)") + tdSql.execute("create table child_table2 using super_table1 tags(1) comment ''") + tdSql.execute("create table child_table3 using super_table1 tags(1) comment 'child'") + + tdSql.query("show tables like 'child_table1'") + tdSql.checkData(0, 0, 'child_table1') + tdSql.checkData(0, 8, None) + + + tdSql.query("show tables like 'child_table2'") + tdSql.checkData(0, 0, 'child_table2') + tdSql.checkData(0, 8, '') + + + tdSql.query("show tables like 'child_table3'") + tdSql.checkData(0, 0, 'child_table3') + tdSql.checkData(0, 8, 'child') + + + tdSql.execute("alter table child_table1 comment 'nihao'") + tdSql.query("show tables like 'child_table1'") + tdSql.checkData(0, 0, 'child_table1') + tdSql.checkData(0, 8, 'nihao') + + tdSql.execute("alter table child_table1 comment ''") + tdSql.query("show tables like 'child_table1'") + tdSql.checkData(0, 0, 'child_table1') + tdSql.checkData(0, 8, '') + + tdSql.execute("alter table child_table2 comment 'fly'") + tdSql.query("show tables like 'child_table2'") + tdSql.checkData(0, 0, 'child_table2') + tdSql.checkData(0, 8, 'fly') + + tdSql.execute("alter table child_table3 comment 'tdengine'") + tdSql.query("show tables like 'child_table3'") + tdSql.checkData(0, 0, 'child_table3') + tdSql.checkData(0, 8, 'tdengine') + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) + diff --git a/tools/shell/src/shellArguments.c b/tools/shell/src/shellArguments.c index cd6613b17a..861ae99f64 100644 --- a/tools/shell/src/shellArguments.c +++ b/tools/shell/src/shellArguments.c @@ -67,7 +67,7 @@ void shellPrintHelp() { #include #include -const char *argp_program_version = version; +const char *argp_program_version = td_version; const char *argp_program_bug_address = SHELL_EMAIL; static struct argp_option shellOptions[] = { @@ -342,7 +342,7 @@ int32_t shellParseArgs(int32_t argc, char *argv[]) { shell.info.promptHeader = "taos> "; shell.info.promptContinue = " -> "; shell.info.promptSize = 6; - snprintf(shell.info.programVersion, sizeof(shell.info.programVersion), "version: %s", version); + snprintf(shell.info.programVersion, sizeof(shell.info.programVersion), "version: %s", td_version); #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) shell.info.osname = "Windows"; diff --git a/tools/shell/src/shellUtil.c b/tools/shell/src/shellUtil.c index 1529ac0e52..fecb112896 100644 --- a/tools/shell/src/shellUtil.c +++ b/tools/shell/src/shellUtil.c @@ -68,7 +68,7 @@ int32_t shellCheckIntSize() { return 0; } -void shellPrintVersion() { printf("version: %s\n", version); } +void shellPrintVersion() { printf("version: %s\n", td_version); } void shellGenerateAuth() { char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0};