From 76e36a8d4e2a1d8c4a594c04ba64a31d9add6786 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 21 Jul 2020 03:05:47 +0000 Subject: [PATCH 01/15] fix defect found in coverity scan --- src/mnode/src/mnodeDb.c | 18 +++++++++++++----- src/mnode/src/mnodeSdb.c | 2 +- src/mnode/src/mnodeVgroup.c | 17 ++++++++++++----- src/plugins/http/src/gcJson.c | 4 ++++ src/plugins/http/src/httpContext.c | 2 +- src/plugins/http/src/restJson.c | 4 ++++ src/plugins/mqtt/src/mqttSystem.c | 2 +- 7 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index fb97d6f380..a159e98ed5 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -67,8 +67,11 @@ static int32_t mnodeDbActionInsert(SSdbOper *pOper) { SAcctObj *pAcct = mnodeGetAcct(pDb->acct); pthread_mutex_init(&pDb->mutex, NULL); + pthread_mutex_lock(&pDb->mutex); pDb->vgListSize = VG_LIST_SIZE; pDb->vgList = calloc(pDb->vgListSize, sizeof(SVgObj *)); + pthread_mutex_unlock(&pDb->mutex); + pDb->numOfVgroups = 0; pDb->numOfTables = 0; pDb->numOfSuperTables = 0; @@ -395,8 +398,8 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, void *pMs code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS) { - mnodeDestroyDb(pDb); mLInfo("db:%s, failed to create, reason:%s", pDb->name, tstrerror(code)); + mnodeDestroyDb(pDb); return code; } else { return TSDB_CODE_MND_ACTION_IN_PROGRESS; @@ -605,7 +608,9 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn static char *mnodeGetDbStr(char *src) { char *pos = strstr(src, TS_PATH_DELIMITER); - return ++pos; + if (pos != NULL) ++pos; + + return pos; } static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void *pConn) { @@ -622,10 +627,13 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void cols = 0; - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; char* name = mnodeGetDbStr(pDb->name); - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, pShow->bytes[cols]); + if (name != NULL) { + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, name, pShow->bytes[cols]); + } else { + STR_TO_VARSTR(pWrite, "NULL"); + } cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 42ded7ed06..dee82f53be 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -453,7 +453,7 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) { keySize = strlen((char *)key); } - taosHashPut(pTable->iHandle, key, keySize, &pOper->pObj, sizeof(void **)); + taosHashPut(pTable->iHandle, key, keySize, &pOper->pObj, sizeof(int64_t)); sdbIncRef(pTable, pOper->pObj); atomic_add_fetch_32(&pTable->numOfRows, 1); diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 1de591df7c..46255a6c8f 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -434,15 +434,22 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi } if (pDb->numOfVgroups < maxVgroupsPerDb) { - mDebug("app:%p:%p, db:%s, try to create a new vgroup, numOfVgroups:%d maxVgroupsPerDb:%d", pMsg->rpcMsg.ahandle, pMsg, - pDb->name, pDb->numOfVgroups, maxVgroupsPerDb); + mDebug("app:%p:%p, db:%s, try to create a new vgroup, numOfVgroups:%d maxVgroupsPerDb:%d", pMsg->rpcMsg.ahandle, + pMsg, pDb->name, pDb->numOfVgroups, maxVgroupsPerDb); pthread_mutex_unlock(&pDb->mutex); int32_t code = mnodeCreateVgroup(pMsg); - if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) return code; + if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { + return code; + } else { + pthread_mutex_lock(&pDb->mutex); + } } SVgObj *pVgroup = pDb->vgList[0]; - if (pVgroup == NULL) return TSDB_CODE_MND_NO_ENOUGH_DNODES; + if (pVgroup == NULL) { + pthread_mutex_unlock(&pDb->mutex); + return TSDB_CODE_MND_NO_ENOUGH_DNODES; + } int32_t code = mnodeAllocVgroupIdPool(pVgroup); if (code != TSDB_CODE_SUCCESS) { @@ -483,7 +490,7 @@ static int32_t mnodeCreateVgroupCb(SMnodeMsg *pMsg, int32_t code) { } else { pVgroup->status = TAOS_VG_STATUS_READY; SSdbOper desc = {.type = SDB_OPER_GLOBAL, .pObj = pVgroup, .table = tsVgroupSdb}; - sdbUpdateRow(&desc); + (void)sdbUpdateRow(&desc); } mInfo("app:%p:%p, vgId:%d, is created in mnode, db:%s replica:%d", pMsg->rpcMsg.ahandle, pMsg, pVgroup->vgId, diff --git a/src/plugins/http/src/gcJson.c b/src/plugins/http/src/gcJson.c index 544a11b5fc..94d53db6ef 100644 --- a/src/plugins/http/src/gcJson.c +++ b/src/plugins/http/src/gcJson.c @@ -121,6 +121,10 @@ bool gcBuildQueryJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, for (int k = 0; k < numOfRows; ++k) { TAOS_ROW row = taos_fetch_row(result); + if (row == NULL) { + cmd->numOfRows--; + continue; + } int32_t* length = taos_fetch_lengths(result); // for group by diff --git a/src/plugins/http/src/httpContext.c b/src/plugins/http/src/httpContext.c index cefcca7821..225977abae 100644 --- a/src/plugins/http/src/httpContext.c +++ b/src/plugins/http/src/httpContext.c @@ -108,7 +108,7 @@ HttpContext *httpCreateContext(int32_t fd) { pContext->lastAccessTime = taosGetTimestampSec(); pContext->state = HTTP_CONTEXT_STATE_READY; - HttpContext **ppContext = taosCachePut(tsHttpServer.contextCache, &pContext, sizeof(void *), &pContext, sizeof(void *), 3); + HttpContext **ppContext = taosCachePut(tsHttpServer.contextCache, &pContext, sizeof(int64_t), &pContext, sizeof(int64_t), 3); pContext->ppContext = ppContext; httpDebug("context:%p, fd:%d, is created, data:%p", pContext, fd, ppContext); diff --git a/src/plugins/http/src/restJson.c b/src/plugins/http/src/restJson.c index 53b0248149..7a73f6559f 100644 --- a/src/plugins/http/src/restJson.c +++ b/src/plugins/http/src/restJson.c @@ -94,6 +94,10 @@ bool restBuildSqlJson(HttpContext *pContext, HttpSqlCmd *cmd, TAOS_RES *result, for (int k = 0; k < numOfRows; ++k) { TAOS_ROW row = taos_fetch_row(result); + if (row == NULL) { + cmd->numOfRows--; + continue; + } int32_t* length = taos_fetch_lengths(result); // data row array begin diff --git a/src/plugins/mqtt/src/mqttSystem.c b/src/plugins/mqtt/src/mqttSystem.c index 2687106124..0259ea23eb 100644 --- a/src/plugins/mqtt/src/mqttSystem.c +++ b/src/plugins/mqtt/src/mqttSystem.c @@ -64,7 +64,7 @@ int32_t mqttInitSystem() { } char* _begin_hostname = strstr(url, recntStatus.hostname); - if (strstr(_begin_hostname, ":") != NULL) { + if (_begin_hostname != NULL && strstr(_begin_hostname, ":") != NULL) { recntStatus.port = strbetween(_begin_hostname, ":", "/"); } else { recntStatus.port = strbetween("'1883'", "'", "'"); From 08fe5fbfa66c3869223c3adab63ae0d1de92492f Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Tue, 21 Jul 2020 13:55:31 +0800 Subject: [PATCH 02/15] increase crash_gen step to 1000. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4d7a809e29..f2cd83343e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,7 +63,7 @@ matrix: pkill -TERM -x taosd fuser -k -n tcp 6030 sleep 1 - ./crash_gen.sh -a -p -t 4 -s 25|| travis_terminate $? + ./crash_gen.sh -a -p -t 4 -s 1000|| travis_terminate $? sleep 1 cd ${TRAVIS_BUILD_DIR}/tests/pytest From bfe15fe0927b975f1cdf0726ec7649336f73e9bf Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Tue, 21 Jul 2020 14:18:06 +0800 Subject: [PATCH 03/15] increase crash_gen step to 2000. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f2cd83343e..6a4acce451 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,7 +63,7 @@ matrix: pkill -TERM -x taosd fuser -k -n tcp 6030 sleep 1 - ./crash_gen.sh -a -p -t 4 -s 1000|| travis_terminate $? + ./crash_gen.sh -a -p -t 4 -s 2000|| travis_terminate $? sleep 1 cd ${TRAVIS_BUILD_DIR}/tests/pytest From 43b2f41fbbcbf7ee8c1620354dd7ff3441ac3caa Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Tue, 21 Jul 2020 16:24:59 +0800 Subject: [PATCH 04/15] TD-819: increase test coverage --- tests/pytest/fulltest.sh | 20 +++ tests/pytest/functions/function_avg.py | 73 +++++++++ tests/pytest/functions/function_bottom.py | 98 ++++++++++++ tests/pytest/functions/function_count.py | 84 +++++++++++ tests/pytest/functions/function_diff.py | 103 +++++++++++++ tests/pytest/functions/function_first.py | 124 ++++++++++++++++ tests/pytest/functions/function_last.py | 124 ++++++++++++++++ tests/pytest/functions/function_last_row.py | 133 +++++++++++++++++ .../pytest/functions/function_leastsquares.py | 82 ++++++++++ tests/pytest/functions/function_max.py | 78 ++++++++++ tests/pytest/functions/function_min.py | 78 ++++++++++ tests/pytest/functions/function_operations.py | 86 +++++++++++ tests/pytest/functions/function_percentile.py | 140 ++++++++++++++++++ tests/pytest/functions/function_spread.py | 111 ++++++++++++++ tests/pytest/functions/function_stddev.py | 80 ++++++++++ tests/pytest/functions/function_sum.py | 70 +++++++++ tests/pytest/functions/function_top.py | 98 ++++++++++++ tests/pytest/functions/function_twa.py | 135 +++++++++++++++++ tests/pytest/query/filterOtherTypes.py | 24 ++- tests/pytest/regressiontest.sh | 21 +++ tests/pytest/util/sql.py | 20 ++- 21 files changed, 1768 insertions(+), 14 deletions(-) create mode 100644 tests/pytest/functions/function_avg.py create mode 100644 tests/pytest/functions/function_bottom.py create mode 100644 tests/pytest/functions/function_count.py create mode 100644 tests/pytest/functions/function_diff.py create mode 100644 tests/pytest/functions/function_first.py create mode 100644 tests/pytest/functions/function_last.py create mode 100644 tests/pytest/functions/function_last_row.py create mode 100644 tests/pytest/functions/function_leastsquares.py create mode 100644 tests/pytest/functions/function_max.py create mode 100644 tests/pytest/functions/function_min.py create mode 100644 tests/pytest/functions/function_operations.py create mode 100644 tests/pytest/functions/function_percentile.py create mode 100644 tests/pytest/functions/function_spread.py create mode 100644 tests/pytest/functions/function_stddev.py create mode 100644 tests/pytest/functions/function_sum.py create mode 100644 tests/pytest/functions/function_top.py create mode 100644 tests/pytest/functions/function_twa.py diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 9d1aef0dc5..904e712fa4 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -144,6 +144,7 @@ python3 ./test.py -f query/querySort.py python3 ./test.py -f query/queryJoin.py python3 ./test.py -f query/select_last_crash.py python3 ./test.py -f query/queryNullValueTest.py +python3 ./test.py -f query/queryInsertValue.py #stream python3 ./test.py -f stream/metric_1.py @@ -161,3 +162,22 @@ python3 ./test.py -f client/client.py # Misc python3 testCompress.py python3 testNoCompress.py + +# functions +python3 ./test.py -f functions/function_avg.py +python3 ./test.py -f functions/function_bottom.py +python3 ./test.py -f functions/function_count.py +python3 ./test.py -f functions/function_diff.py +python3 ./test.py -f functions/function_first.py +python3 ./test.py -f functions/function_last.py +python3 ./test.py -f functions/function_last_row.py +python3 ./test.py -f functions/function_leastsquares.py +python3 ./test.py -f functions/function_max.py +python3 ./test.py -f functions/function_min.py +python3 ./test.py -f functions/function_operations.py +python3 ./test.py -f functions/function_percentile.py +python3 ./test.py -f functions/function_spread.py +python3 ./test.py -f functions/function_stddev.py +python3 ./test.py -f functions/function_sum.py +python3 ./test.py -f functions/function_top.py +python3 ./test.py -f functions/function_twa.py \ No newline at end of file diff --git a/tests/pytest/functions/function_avg.py b/tests/pytest/functions/function_avg.py new file mode 100644 index 0000000000..9481550ba3 --- /dev/null +++ b/tests/pytest/functions/function_avg.py @@ -0,0 +1,73 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # average verifacation + tdSql.error("select avg(ts) from test") + tdSql.error("select avg(ts) from test1") + tdSql.error("select avg(col7) from test") + tdSql.error("select avg(col7) from test1") + tdSql.error("select avg(col8) from test") + tdSql.error("select avg(col8) from test1") + tdSql.error("select avg(col9) from test") + tdSql.error("select avg(col9) from test1") + + tdSql.query("select avg(col1) from test") + tdSql.checkData(0, 0, np.average(intData)) + tdSql.query("select avg(col2) from test") + tdSql.checkData(0, 0, np.average(intData)) + tdSql.query("select avg(col3) from test") + tdSql.checkData(0, 0, np.average(intData)) + tdSql.query("select avg(col4) from test") + tdSql.checkData(0, 0, np.average(intData)) + tdSql.query("select avg(col5) from test") + tdSql.checkData(0, 0, np.average(floatData)) + tdSql.query("select avg(col6) from test") + tdSql.checkData(0, 0, np.average(floatData)) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_bottom.py b/tests/pytest/functions/function_bottom.py new file mode 100644 index 0000000000..cb008d522a --- /dev/null +++ b/tests/pytest/functions/function_bottom.py @@ -0,0 +1,98 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # bottom verifacation + tdSql.error("select bottom(ts, 10) from test") + tdSql.error("select bottom(col1, 0) from test") + tdSql.error("select bottom(col1, 101) from test") + tdSql.error("select bottom(col2, 0) from test") + tdSql.error("select bottom(col2, 101) from test") + tdSql.error("select bottom(col3, 0) from test") + tdSql.error("select bottom(col3, 101) from test") + tdSql.error("select bottom(col4, 0) from test") + tdSql.error("select bottom(col4, 101) from test") + tdSql.error("select bottom(col5, 0) from test") + tdSql.error("select bottom(col5, 101) from test") + tdSql.error("select bottom(col6, 0) from test") + tdSql.error("select bottom(col6, 101) from test") + tdSql.error("select bottom(col7, 10) from test") + tdSql.error("select bottom(col8, 10) from test") + tdSql.error("select bottom(col9, 10) from test") + + tdSql.query("select bottom(col1, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 1) + tdSql.checkData(1, 1, 2) + + tdSql.query("select bottom(col2, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 1) + tdSql.checkData(1, 1, 2) + + tdSql.query("select bottom(col3, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 1) + tdSql.checkData(1, 1, 2) + + tdSql.query("select bottom(col4, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 1) + tdSql.checkData(1, 1, 2) + + tdSql.query("select bottom(col5, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 0.1) + tdSql.checkData(1, 1, 1.1) + + tdSql.query("select bottom(col6, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 0.1) + tdSql.checkData(1, 1, 1.1) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_count.py b/tests/pytest/functions/function_count.py new file mode 100644 index 0000000000..e5ef71bf5a --- /dev/null +++ b/tests/pytest/functions/function_count.py @@ -0,0 +1,84 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # Count verifacation + tdSql.query("select count(*) from test") + tdSql.checkData(0, 0, 10) + + tdSql.query("select count(ts) from test") + tdSql.checkData(0, 0, 10) + tdSql.query("select count(col1) from test") + tdSql.checkData(0, 0, 10) + tdSql.query("select count(col2) from test") + tdSql.checkData(0, 0, 10) + tdSql.query("select count(col3) from test") + tdSql.checkData(0, 0, 10) + tdSql.query("select count(col4) from test") + tdSql.checkData(0, 0, 10) + tdSql.query("select count(col5) from test") + tdSql.checkData(0, 0, 10) + tdSql.query("select count(col6) from test") + tdSql.checkData(0, 0, 10) + tdSql.query("select count(col7) from test") + tdSql.checkData(0, 0, 10) + tdSql.query("select count(col8) from test") + tdSql.checkData(0, 0, 10) + tdSql.query("select count(col9) from test") + tdSql.checkData(0, 0, 10) + + tdSql.execute("alter table test add column col10 int") + tdSql.query("select count(col10) from test") + tdSql.checkRows(0) + + tdSql.execute("insert into test1 values(now, 1, 2, 3, 4, 1.1, 2.2, false, 'test', 'test' 1)") + tdSql.query("select count(col10) from test") + tdSql.checkData(0, 0, 1) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_diff.py b/tests/pytest/functions/function_diff.py new file mode 100644 index 0000000000..62daa5fa82 --- /dev/null +++ b/tests/pytest/functions/function_diff.py @@ -0,0 +1,103 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + tdSql.execute("insert into test1 values(%d, 0, 0, 0, 0, 0.0, 0.0, False, ' ', ' ')" % (self.ts - 1)) + tdSql.query("select diff(col1) from test1") + tdSql.checkRows(0) + + tdSql.query("select diff(col2) from test1") + tdSql.checkRows(0) + + tdSql.query("select diff(col3) from test1") + tdSql.checkRows(0) + + tdSql.query("select diff(col4) from test1") + tdSql.checkRows(0) + + tdSql.query("select diff(col5) from test1") + tdSql.checkRows(0) + + tdSql.query("select diff(col6) from test1") + tdSql.checkRows(0) + + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # diff verifacation + tdSql.error("select diff(ts) from test") + tdSql.error("select diff(ts) from test1") + tdSql.error("select diff(col1) from test") + tdSql.error("select diff(col2) from test") + tdSql.error("select diff(col3) from test") + tdSql.error("select diff(col4) from test") + tdSql.error("select diff(col5) from test") + tdSql.error("select diff(col6) from test") + tdSql.error("select diff(col7) from test") + tdSql.error("select diff(col7) from test1") + tdSql.error("select diff(col8) from test") + tdSql.error("select diff(col8) from test1") + tdSql.error("select diff(col9) from test") + tdSql.error("select diff(col9) from test1") + + tdSql.query("select diff(col1) from test1") + tdSql.checkRows(10) + + tdSql.query("select diff(col2) from test1") + tdSql.checkRows(10) + + tdSql.query("select diff(col3) from test1") + tdSql.checkRows(10) + + tdSql.query("select diff(col4) from test1") + tdSql.checkRows(10) + + tdSql.query("select diff(col5) from test1") + tdSql.checkRows(10) + + tdSql.query("select diff(col6) from test1") + tdSql.checkRows(10) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_first.py b/tests/pytest/functions/function_first.py new file mode 100644 index 0000000000..27ce09b309 --- /dev/null +++ b/tests/pytest/functions/function_first.py @@ -0,0 +1,124 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + tdSql.execute("insert into test1(ts) values(%d)" % (self.ts - 1)) + + # first verifacation + tdSql.query("select first(*) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 1, None) + + tdSql.query("select first(col1) from test1") + tdSql.checkRows(0) + + tdSql.query("select first(col2) from test1") + tdSql.checkRows(0) + + tdSql.query("select first(col3) from test1") + tdSql.checkRows(0) + + tdSql.query("select first(col4) from test1") + tdSql.checkRows(0) + + tdSql.query("select first(col5) from test1") + tdSql.checkRows(0) + + tdSql.query("select first(col6) from test1") + tdSql.checkRows(0) + + tdSql.query("select first(col7) from test1") + tdSql.checkRows(0) + + tdSql.query("select first(col8) from test1") + tdSql.checkRows(0) + + tdSql.query("select first(col9) from test1") + tdSql.checkRows(0) + + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + tdSql.query("select first(*) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 1) + + tdSql.query("select first(col1) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query("select first(col2) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query("select first(col3) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query("select first(col4) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query("select first(col5) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0.1) + + tdSql.query("select first(col6) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0.1) + + tdSql.query("select first(col7) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, False) + + tdSql.query("select first(col8) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 'taosdata1') + + tdSql.query("select first(col9) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '涛思数据1') + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_last.py b/tests/pytest/functions/function_last.py new file mode 100644 index 0000000000..6412b7ce6a --- /dev/null +++ b/tests/pytest/functions/function_last.py @@ -0,0 +1,124 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + tdSql.execute("insert into test1(ts) values(%d)" % (self.ts - 1)) + + # first verifacation + tdSql.query("select last(*) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 1, None) + + tdSql.query("select last(col1) from test1") + tdSql.checkRows(0) + + tdSql.query("select last(col2) from test1") + tdSql.checkRows(0) + + tdSql.query("select last(col3) from test1") + tdSql.checkRows(0) + + tdSql.query("select last(col4) from test1") + tdSql.checkRows(0) + + tdSql.query("select last(col5) from test1") + tdSql.checkRows(0) + + tdSql.query("select last(col6) from test1") + tdSql.checkRows(0) + + tdSql.query("select last(col7) from test1") + tdSql.checkRows(0) + + tdSql.query("select last(col8) from test1") + tdSql.checkRows(0) + + tdSql.query("select last(col9) from test1") + tdSql.checkRows(0) + + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + tdSql.query("select last(*) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 10) + + tdSql.query("select last(col1) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select last(col2) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select last(col3) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select last(col4) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select last(col5) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 9.1) + + tdSql.query("select last(col6) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 9.1) + + tdSql.query("select last(col7) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, True) + + tdSql.query("select last(col8) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 'taosdata10') + + tdSql.query("select last(col9) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '涛思数据10') + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_last_row.py b/tests/pytest/functions/function_last_row.py new file mode 100644 index 0000000000..19db865a3d --- /dev/null +++ b/tests/pytest/functions/function_last_row.py @@ -0,0 +1,133 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + tdSql.execute("insert into test1(ts) values(%d)" % (self.ts - 1)) + + # first verifacation + tdSql.query("select last_row(*) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 1, None) + + tdSql.query("select last_row(col1) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query("select last_row(col2) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query("select last_row(col3) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query("select last_row(col4) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query("select last_row(col5) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query("select last_row(col6) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query("select last_row(col7) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query("select last_row(col8) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query("select last_row(col9) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + tdSql.query("select last_row(*) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 10) + + tdSql.query("select last_row(col1) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select last_row(col2) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select last_row(col3) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select last_row(col4) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select last_row(col5) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 9.1) + + tdSql.query("select last_row(col6) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 9.1) + + tdSql.query("select last_row(col7) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, True) + + tdSql.query("select last_row(col8) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 'taosdata10') + + tdSql.query("select last_row(col9) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, '涛思数据10') + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_leastsquares.py b/tests/pytest/functions/function_leastsquares.py new file mode 100644 index 0000000000..66187926f5 --- /dev/null +++ b/tests/pytest/functions/function_leastsquares.py @@ -0,0 +1,82 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # leastsquares verifacation + tdSql.error("select leastsquares(ts, 1, 1) from test1") + tdSql.error("select leastsquares(col1, 1, 1) from test") + tdSql.error("select leastsquares(col2, 1, 1) from test") + tdSql.error("select leastsquares(col3, 1, 1) from test") + tdSql.error("select leastsquares(col4, 1, 1) from test") + tdSql.error("select leastsquares(col5, 1, 1) from test") + tdSql.error("select leastsquares(col6, 1, 1) from test") + tdSql.error("select leastsquares(col7, 1, 1) from test1") + tdSql.error("select leastsquares(col8, 1, 1) from test1") + tdSql.error("select leastsquares(col9, 1, 1) from test1") + + tdSql.query("select leastsquares(col1, 1, 1) from test1") + tdSql.checkData(0, 0, '{slop:1.000000, intercept:0.000000}') + + tdSql.query("select leastsquares(col2, 1, 1) from test1") + tdSql.checkData(0, 0, '{slop:1.000000, intercept:0.000000}') + + tdSql.query("select leastsquares(col3, 1, 1) from test1") + tdSql.checkData(0, 0, '{slop:1.000000, intercept:0.000000}') + + tdSql.query("select leastsquares(col4, 1, 1) from test1") + tdSql.checkData(0, 0, '{slop:1.000000, intercept:0.000000}') + + tdSql.query("select leastsquares(col5, 1, 1) from test1") + tdSql.checkData(0, 0, '{slop:1.000000, intercept:-0.900000}') + + tdSql.query("select leastsquares(col6, 1, 1) from test1") + tdSql.checkData(0, 0, '{slop:1.000000, intercept:-0.900000}') + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_max.py b/tests/pytest/functions/function_max.py new file mode 100644 index 0000000000..02364e0fde --- /dev/null +++ b/tests/pytest/functions/function_max.py @@ -0,0 +1,78 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # min verifacation + tdSql.error("select max(ts) from test") + tdSql.error("select max(ts) from test1") + tdSql.error("select max(col7) from test") + tdSql.error("select max(col7) from test1") + tdSql.error("select max(col8) from test") + tdSql.error("select max(col8) from test1") + tdSql.error("select max(col9) from test") + tdSql.error("select max(col9) from test1") + + tdSql.query("select max(col1) from test1") + tdSql.checkData(0, 0, np.max(intData)) + + tdSql.query("select max(col2) from test1") + tdSql.checkData(0, 0, np.max(intData)) + + tdSql.query("select max(col3) from test1") + tdSql.checkData(0, 0, np.max(intData)) + + tdSql.query("select max(col4) from test1") + tdSql.checkData(0, 0, np.max(intData)) + + tdSql.query("select max(col5) from test1") + tdSql.checkData(0, 0, np.max(floatData)) + + tdSql.query("select max(col6) from test1") + tdSql.checkData(0, 0, np.max(floatData)) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_min.py b/tests/pytest/functions/function_min.py new file mode 100644 index 0000000000..bc180bc224 --- /dev/null +++ b/tests/pytest/functions/function_min.py @@ -0,0 +1,78 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # min verifacation + tdSql.error("select min(ts) from test") + tdSql.error("select min(ts) from test1") + tdSql.error("select min(col7) from test") + tdSql.error("select min(col7) from test1") + tdSql.error("select min(col8) from test") + tdSql.error("select min(col8) from test1") + tdSql.error("select min(col9) from test") + tdSql.error("select min(col9) from test1") + + tdSql.query("select min(col1) from test1") + tdSql.checkData(0, 0, np.min(intData)) + + tdSql.query("select min(col2) from test1") + tdSql.checkData(0, 0, np.min(intData)) + + tdSql.query("select min(col3) from test1") + tdSql.checkData(0, 0, np.min(intData)) + + tdSql.query("select min(col4) from test1") + tdSql.checkData(0, 0, np.min(intData)) + + tdSql.query("select min(col5) from test1") + tdSql.checkData(0, 0, np.min(floatData)) + + tdSql.query("select min(col6) from test1") + tdSql.checkData(0, 0, np.min(floatData)) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_operations.py b/tests/pytest/functions/function_operations.py new file mode 100644 index 0000000000..ec8da92c95 --- /dev/null +++ b/tests/pytest/functions/function_operations.py @@ -0,0 +1,86 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # min verifacation + tdSql.error("select ts + col1 from test") + tdSql.error("select ts + col1 from test1") + tdSql.error("select col1 + col7 from test") + tdSql.error("select col1 + col7 from test1") + tdSql.error("select col1 + col8 from test") + tdSql.error("select col1 + col8 from test1") + tdSql.error("select col1 + col9 from test") + tdSql.error("select col1 + col9 from test1") + + tdSql.query("select col1 + col2 from test1") + tdSql.checkRows(10) + tdSql.checkData(0, 0, 2.0) + + tdSql.query("select col1 + col2 * col3 from test1") + tdSql.checkRows(10) + tdSql.checkData(1, 0, 6.0) + + tdSql.query("select col1 + col2 * col3 + col3 / col4 + col5 + col6 from test1") + tdSql.checkRows(10) + tdSql.checkData(0, 0, 3.2) + + tdSql.execute("insert into test1(ts, col1) values(%d, 11)" % (self.ts + 11)) + tdSql.query("select col1 + col2 from test1") + tdSql.checkRows(11) + tdSql.checkData(10, 0, None) + + tdSql.query("select col1 + col2 * col3 from test1") + tdSql.checkRows(11) + tdSql.checkData(10, 0, None) + + tdSql.query("select col1 + col2 * col3 + col3 / col4 + col5 + col6 from test1") + tdSql.checkRows(11) + tdSql.checkData(10, 0, None) + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_percentile.py b/tests/pytest/functions/function_percentile.py new file mode 100644 index 0000000000..aaeb94372e --- /dev/null +++ b/tests/pytest/functions/function_percentile.py @@ -0,0 +1,140 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20))''') + for i in range(self.rowNum): + tdSql.execute("insert into test values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # percentile verifacation + tdSql.error("select percentile(ts 20) from test") + tdSql.error("select apercentile(ts 20) from test") + tdSql.error("select percentile(col7 20) from test") + tdSql.error("select apercentile(col7 20) from test") + tdSql.error("select percentile(col8 20) from test") + tdSql.error("select apercentile(col8 20) from test") + tdSql.error("select percentile(col9 20) from test") + tdSql.error("select apercentile(col9 20) from test") + + tdSql.query("select percentile(col1, 0) from test") + tdSql.checkData(0, 0, np.percentile(intData, 0)) + tdSql.query("select apercentile(col1, 0) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col1, 50) from test") + tdSql.checkData(0, 0, np.percentile(intData, 50)) + tdSql.query("select apercentile(col1, 50) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col1, 100) from test") + tdSql.checkData(0, 0, np.percentile(intData, 100)) + tdSql.query("select apercentile(col1, 100) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + + tdSql.query("select percentile(col2, 0) from test") + tdSql.checkData(0, 0, np.percentile(intData, 0)) + tdSql.query("select apercentile(col2, 0) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col2, 50) from test") + tdSql.checkData(0, 0, np.percentile(intData, 50)) + tdSql.query("select apercentile(col2, 50) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col2, 100) from test") + tdSql.checkData(0, 0, np.percentile(intData, 100)) + tdSql.query("select apercentile(col2, 100) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + + tdSql.query("select percentile(col3, 0) from test") + tdSql.checkData(0, 0, np.percentile(intData, 0)) + tdSql.query("select apercentile(col3, 0) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col3, 50) from test") + tdSql.checkData(0, 0, np.percentile(intData, 50)) + tdSql.query("select apercentile(col3, 50) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col3, 100) from test") + tdSql.checkData(0, 0, np.percentile(intData, 100)) + tdSql.query("select apercentile(col3, 100) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + + tdSql.query("select percentile(col4, 0) from test") + tdSql.checkData(0, 0, np.percentile(intData, 0)) + tdSql.query("select apercentile(col4, 0) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col4, 50) from test") + tdSql.checkData(0, 0, np.percentile(intData, 50)) + tdSql.query("select apercentile(col4, 50) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col4, 100) from test") + tdSql.checkData(0, 0, np.percentile(intData, 100)) + tdSql.query("select apercentile(col4, 100) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + + tdSql.query("select percentile(col5, 0) from test") + print("query result: %s" % tdSql.getData(0, 0)) + print("array result: %s" % np.percentile(floatData, 0)) + tdSql.query("select apercentile(col5, 0) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col5, 50) from test") + print("query result: %s" % tdSql.getData(0, 0)) + print("array result: %s" % np.percentile(floatData, 50)) + tdSql.query("select apercentile(col5, 50) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col5, 100) from test") + print("query result: %s" % tdSql.getData(0, 0)) + print("array result: %s" % np.percentile(floatData, 100)) + tdSql.query("select apercentile(col5, 100) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + + tdSql.query("select percentile(col6, 0) from test") + tdSql.checkData(0, 0, np.percentile(floatData, 0)) + tdSql.query("select apercentile(col6, 0) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col6, 50) from test") + tdSql.checkData(0, 0, np.percentile(floatData, 50)) + tdSql.query("select apercentile(col6, 50) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + tdSql.query("select percentile(col6, 100) from test") + tdSql.checkData(0, 0, np.percentile(floatData, 100)) + tdSql.query("select apercentile(col6, 100) from test") + print("apercentile result: %s" % tdSql.getData(0, 0)) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_spread.py b/tests/pytest/functions/function_spread.py new file mode 100644 index 0000000000..62b604a279 --- /dev/null +++ b/tests/pytest/functions/function_spread.py @@ -0,0 +1,111 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + tdSql.execute("insert into test1 values(%d, 0, 0, 0, 0, 0.0, 0.0, False, ' ', ' ')" % (self.ts - 1)) + + # spread verifacation + tdSql.query("select spread(ts) from test1") + tdSql.checkRows(1) + + tdSql.query("select spread(col1) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query("select spread(col2) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query("select spread(col3) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query("select spread(col4) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query("select spread(col5) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query("select spread(col6) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + tdSql.error("select spread(col7) from test") + tdSql.error("select spread(col7) from test1") + tdSql.error("select spread(col8) from test") + tdSql.error("select spread(col8) from test1") + tdSql.error("select spread(col9) from test") + tdSql.error("select spread(col9) from test1") + + tdSql.query("select spread(col1) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select spread(col2) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select spread(col3) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select spread(col4) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 10) + + tdSql.query("select spread(col5) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 9.1) + + tdSql.query("select spread(col6) from test1") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 9.1) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_stddev.py b/tests/pytest/functions/function_stddev.py new file mode 100644 index 0000000000..23df415aa3 --- /dev/null +++ b/tests/pytest/functions/function_stddev.py @@ -0,0 +1,80 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # stddev verifacation + tdSql.error("select stddev(ts) from test1") + tdSql.error("select stddev(col1) from test") + tdSql.error("select stddev(col2) from test") + tdSql.error("select stddev(col3) from test") + tdSql.error("select stddev(col4) from test") + tdSql.error("select stddev(col5) from test") + tdSql.error("select stddev(col6) from test") + tdSql.error("select stddev(col7) from test1") + tdSql.error("select stddev(col8) from test1") + tdSql.error("select stddev(col9) from test1") + + tdSql.query("select stddev(col1) from test1") + tdSql.checkData(0, 0, np.std(intData)) + + tdSql.query("select stddev(col2) from test1") + tdSql.checkData(0, 0, np.std(intData)) + + tdSql.query("select stddev(col3) from test1") + tdSql.checkData(0, 0, np.std(intData)) + + tdSql.query("select stddev(col4) from test1") + tdSql.checkData(0, 0, np.std(intData)) + + tdSql.query("select stddev(col5) from test1") + tdSql.checkData(0, 0, np.std(floatData)) + + tdSql.query("select stddev(col6) from test1") + tdSql.checkData(0, 0, np.std(floatData)) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_sum.py b/tests/pytest/functions/function_sum.py new file mode 100644 index 0000000000..8e4e289c7e --- /dev/null +++ b/tests/pytest/functions/function_sum.py @@ -0,0 +1,70 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # sum verifacation + tdSql.error("select sum(ts) from test") + tdSql.error("select sum(col7) from test") + tdSql.error("select sum(col8) from test") + tdSql.error("select sum(col9) from test") + + tdSql.query("select sum(col1) from test") + tdSql.checkData(0, 0, np.sum(intData)) + tdSql.query("select sum(col2) from test") + tdSql.checkData(0, 0, np.sum(intData)) + tdSql.query("select sum(col3) from test") + tdSql.checkData(0, 0, np.sum(intData)) + tdSql.query("select sum(col4) from test") + tdSql.checkData(0, 0, np.sum(intData)) + tdSql.query("select sum(col5) from test") + print("query result for folat sum function: %f" % tdSql.getData(0, 0)) + print("calculation result for numpy sum function: %f" % np.sum(floatData)) + tdSql.query("select sum(col6) from test") + tdSql.checkData(0, 0, np.sum(floatData)) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_top.py b/tests/pytest/functions/function_top.py new file mode 100644 index 0000000000..e24ff1cc53 --- /dev/null +++ b/tests/pytest/functions/function_top.py @@ -0,0 +1,98 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # top verifacation + tdSql.error("select top(ts, 10) from test") + tdSql.error("select top(col1, 0) from test") + tdSql.error("select top(col1, 101) from test") + tdSql.error("select top(col2, 0) from test") + tdSql.error("select top(col2, 101) from test") + tdSql.error("select top(col3, 0) from test") + tdSql.error("select top(col3, 101) from test") + tdSql.error("select top(col4, 0) from test") + tdSql.error("select top(col4, 101) from test") + tdSql.error("select top(col5, 0) from test") + tdSql.error("select top(col5, 101) from test") + tdSql.error("select top(col6, 0) from test") + tdSql.error("select top(col6, 101) from test") + tdSql.error("select top(col7, 10) from test") + tdSql.error("select top(col8, 10) from test") + tdSql.error("select top(col9, 10) from test") + + tdSql.query("select top(col1, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 9) + tdSql.checkData(1, 1, 10) + + tdSql.query("select top(col2, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 9) + tdSql.checkData(1, 1, 10) + + tdSql.query("select top(col3, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 9) + tdSql.checkData(1, 1, 10) + + tdSql.query("select top(col4, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 9) + tdSql.checkData(1, 1, 10) + + tdSql.query("select top(col5, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 8.1) + tdSql.checkData(1, 1, 9.1) + + tdSql.query("select top(col6, 2) from test") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 8.1) + tdSql.checkData(1, 1, 9.1) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/functions/function_twa.py b/tests/pytest/functions/function_twa.py new file mode 100644 index 0000000000..1ce4c99b60 --- /dev/null +++ b/tests/pytest/functions/function_twa.py @@ -0,0 +1,135 @@ +################################################################### +# 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 * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + + intData = [] + floatData = [] + + tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double, + col7 bool, col8 binary(20), col9 nchar(20)) tags(loc nchar(20))''') + tdSql.execute("create table test1 using test tags('beijing')") + for i in range(self.rowNum): + tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')" + % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) + intData.append(i + 1) + floatData.append(i + 0.1) + + # twa verifacation + tdSql.error("select twa(ts) from test") + tdSql.error("select twa(ts) from test1") + + tdSql.error("select twa(col1) from test") + tdSql.error("select twa(col1) from test1") + + tdSql.error("select twa(col2) from test") + tdSql.error("select twa(col2) from test1") + + tdSql.error("select twa(col3) from test") + tdSql.error("select twa(col3) from test1") + + tdSql.error("select twa(col4) from test") + tdSql.error("select twa(col4) from test1") + + tdSql.error("select twa(col5) from test") + tdSql.error("select twa(col5) from test1") + + tdSql.error("select twa(col6) from test") + tdSql.error("select twa(col6) from test1") + + tdSql.error("select twa(col7) from test") + tdSql.error("select twa(col7) from test1") + + tdSql.error("select twa(col8) from test") + tdSql.error("select twa(col8) from test1") + + tdSql.error("select twa(col9) from test") + tdSql.error("select twa(col9) from test1") + + tdSql.error("select twa(col1) from test where ts > %d" % self.ts) + tdSql.error("select twa(col1) from test1 where ts > %d" % self.ts) + + tdSql.error("select twa(col2) from test where ts > %d" % self.ts) + tdSql.error("select twa(col2) from test1 where ts > %d" % self.ts) + + tdSql.error("select twa(col3) from test where ts > %d" % self.ts) + tdSql.error("select twa(col3) from test1 where ts > %d" % self.ts) + + tdSql.error("select twa(col4) from test where ts > %d" % self.ts) + tdSql.error("select twa(col4) from test1 where ts > %d" % self.ts) + + tdSql.error("select twa(col5) from test where ts > %d" % self.ts) + tdSql.error("select twa(col5) from test1 where ts > %d" % self.ts) + + tdSql.error("select twa(col6) from test where ts > %d" % self.ts) + tdSql.error("select twa(col6) from test1 where ts > %d" % self.ts) + + tdSql.error("select twa(col1) from test where ts < %d" % (self.ts + self.rowNum)) + tdSql.error("select twa(col1) from test1 where ts < %d" % (self.ts + self.rowNum)) + + tdSql.error("select twa(col2) from test where ts < %d" % (self.ts + self.rowNum)) + tdSql.error("select twa(col2) from test1 where ts < %d" % (self.ts + self.rowNum)) + + tdSql.error("select twa(col3) from test where ts < %d" % (self.ts + self.rowNum)) + tdSql.error("select twa(col3) from test1 where ts < %d" % (self.ts + self.rowNum)) + + tdSql.error("select twa(col4) from test where ts < %d" % (self.ts + self.rowNum)) + tdSql.error("select twa(col4) from test1 where ts < %d" % (self.ts + self.rowNum)) + + tdSql.error("select twa(col5) from test where ts < %d" % (self.ts + self.rowNum)) + tdSql.error("select twa(col5) from test1 where ts < %d" % (self.ts + self.rowNum)) + + tdSql.error("select twa(col6) from test where ts < %d" % (self.ts + self.rowNum)) + tdSql.error("select twa(col6) from test1 where ts < %d" % (self.ts + self.rowNum)) + + tdSql.query("select twa(col1) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + tdSql.query("select twa(col1) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + + tdSql.query("select twa(col2) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + tdSql.query("select twa(col2) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + + tdSql.query("select twa(col3) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + tdSql.query("select twa(col3) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + + tdSql.query("select twa(col4) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + tdSql.query("select twa(col4) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + + tdSql.query("select twa(col5) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + tdSql.query("select twa(col5) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + + tdSql.query("select twa(col6) from test where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + tdSql.query("select twa(col6) from test1 where ts > %d and ts < %d" % (self.ts, self.ts + self.rowNum)) + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/query/filterOtherTypes.py b/tests/pytest/query/filterOtherTypes.py index 1db5497604..5033ffdb48 100644 --- a/tests/pytest/query/filterOtherTypes.py +++ b/tests/pytest/query/filterOtherTypes.py @@ -231,10 +231,12 @@ class TDTestCase: tdSql.error("select * from st where tagcol1 like '____'") # > for nchar type on tag - tdSql.error("select * from st where tagcol2 > 'table'") + tdSql.query("select * from st where tagcol2 > 'table1'") + tdSql.checkRows(5) # >= for nchar type on tag - tdSql.error("select * from st where tagcol2 >= 'table'") + tdSql.query("select * from st where tagcol2 >= 'table1'") + tdSql.checkRows(10) # = for nchar type on tag tdSql.query("select * from st where tagcol2 = 'table1'") @@ -249,10 +251,12 @@ class TDTestCase: tdSql.checkRows(10) # > for nchar type on tag - tdSql.error("select * from st where tagcol2 < 'table'") + tdSql.query("select * from st where tagcol2 < 'table'") + tdSql.checkRows(0) # >= for nchar type on tag - tdSql.error("select * from st where tagcol2 <= 'table'") + tdSql.query("select * from st where tagcol2 <= 'table'") + tdSql.checkRows(0) # % for nchar type on tag case 1 tdSql.query("select * from st where tagcol2 like '%'") @@ -291,10 +295,12 @@ class TDTestCase: tdSql.checkRows(10) # > for binary type on tag - tdSql.error("select * from st where tagcol3 > '表'") + tdSql.query("select * from st where tagcol3 > '表'") + tdSql.checkRows(10) # >= for binary type on tag - tdSql.error("select * from st where tagcol3 >= '表'") + tdSql.query("select * from st where tagcol3 >= '表'") + tdSql.checkRows(10) # = for binary type on tag tdSql.query("select * from st where tagcol3 = '水表'") @@ -309,10 +315,12 @@ class TDTestCase: tdSql.checkRows(5) # > for binary type on tag - tdSql.error("select * from st where tagcol3 < '水表'") + tdSql.query("select * from st where tagcol3 < '水表'") + tdSql.checkRows(0) # >= for binary type on tag - tdSql.error("select * from st where tagcol3 <= '水表'") + tdSql.query("select * from st where tagcol3 <= '水表'") + tdSql.checkRows(5) # % for binary type on tag case 1 tdSql.query("select * from st where tagcol3 like '%'") diff --git a/tests/pytest/regressiontest.sh b/tests/pytest/regressiontest.sh index 24cd93f0fc..61ec491f5d 100755 --- a/tests/pytest/regressiontest.sh +++ b/tests/pytest/regressiontest.sh @@ -141,6 +141,7 @@ python3 ./test.py -f query/filterCombo.py python3 ./test.py -f query/queryNormal.py python3 ./test.py -f query/select_last_crash.py python3 ./test.py -f query/queryNullValueTest.py +python3 ./test.py -f query/queryInsertValue.py #stream python3 ./test.py -f stream/stream1.py @@ -155,3 +156,23 @@ python3 ./test.py -f client/client.py # Misc python3 testCompress.py python3 testNoCompress.py + + +# functions +python3 ./test.py -f functions/function_avg.py +python3 ./test.py -f functions/function_bottom.py +python3 ./test.py -f functions/function_count.py +python3 ./test.py -f functions/function_diff.py +python3 ./test.py -f functions/function_first.py +python3 ./test.py -f functions/function_last.py +python3 ./test.py -f functions/function_last_row.py +python3 ./test.py -f functions/function_leastsquares.py +python3 ./test.py -f functions/function_max.py +python3 ./test.py -f functions/function_min.py +python3 ./test.py -f functions/function_operations.py +python3 ./test.py -f functions/function_percentile.py +python3 ./test.py -f functions/function_spread.py +python3 ./test.py -f functions/function_stddev.py +python3 ./test.py -f functions/function_sum.py +python3 ./test.py -f functions/function_top.py +python3 ./test.py -f functions/function_twa.py diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index ec39ab61b9..1e1d02959f 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -122,11 +122,16 @@ class TDSql: return self.cursor.istype(col, dataType) def checkData(self, row, col, data): - self.checkRowCol(row, col) - if self.queryResult[row][col] != data: - caller = inspect.getframeinfo(inspect.stack()[1][0]) - args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data) - tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args) + self.checkRowCol(row, col) + if self.queryResult[row][col] != data: + if isinstance(data, float) and abs(self.queryResult[row][col] - data) <= 0.000001: + tdLog.info("sql:%s, row:%d col:%d data:%f == expect:%f" % + (self.sql, row, col, self.queryResult[row][col], data)) + return + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data) + tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args) if data is None: tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % @@ -135,9 +140,12 @@ class TDSql: tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % (self.sql, row, col, self.queryResult[row][col], data)) elif isinstance(data, datetime.date): + tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % + (self.sql, row, col, self.queryResult[row][col], data)) + elif isinstance(data, float): tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % (self.sql, row, col, self.queryResult[row][col], data)) - else: + else: tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%d" % (self.sql, row, col, self.queryResult[row][col], data)) From 2867f3082942b3b27fa5e573e530ad66a8e1c2d8 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Tue, 21 Jul 2020 17:29:31 +0800 Subject: [PATCH 05/15] fix sh/exec signal for coverage test. [TD-976] --- tests/script/fullGeneralSuite.sim | 4 ---- tests/script/sh/exec-no-random-fail.sh | 12 +++++++----- tests/script/sh/exec-random-fail.sh | 15 +++++++++------ tests/script/sh/exec.sh | 8 ++++---- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/tests/script/fullGeneralSuite.sim b/tests/script/fullGeneralSuite.sim index 2f45ab077c..15cc2954e8 100644 --- a/tests/script/fullGeneralSuite.sim +++ b/tests/script/fullGeneralSuite.sim @@ -135,7 +135,6 @@ run general/parser/set_tag_vals.sim #unsupport run general/parser/repeatAlter.sim #unsupport run general/parser/slimit_alter_tags.sim #unsupport run general/parser/stream_on_sys.sim -run general/parser/stream.sim #unsupport run general/parser/repeatStream.sim run general/stable/disk.sim run general/stable/dnode3.sim @@ -212,12 +211,9 @@ run general/vector/table_mix.sim run general/vector/table_query.sim run general/vector/table_time.sim run general/stream/restart_stream.sim -run general/stream/stream_1.sim -run general/stream/stream_2.sim run general/stream/stream_3.sim run general/stream/stream_restart.sim run general/stream/table_1.sim -run general/stream/metrics_1.sim run general/stream/table_n.sim run general/stream/metrics_n.sim run general/stream/table_del.sim diff --git a/tests/script/sh/exec-no-random-fail.sh b/tests/script/sh/exec-no-random-fail.sh index 04a663bc5a..2bd0a64923 100755 --- a/tests/script/sh/exec-no-random-fail.sh +++ b/tests/script/sh/exec-no-random-fail.sh @@ -88,7 +88,9 @@ if [ "$EXEC_OPTON" = "start" ]; then echo "ExcuteCmd:" $EXE_DIR/taosd -c $CFG_DIR if [ "$SHELL_OPTION" = "true" ]; then - nohup valgrind --log-file=${LOG_DIR}/valgrind.log --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 & + TT=`date +%s` + mkdir ${LOG_DIR}/${TT} + nohup valgrind --log-file=${LOG_DIR}/${TT}/valgrind.log --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 & else nohup $EXE_DIR/taosd -c $CFG_DIR --random-file-fail-factor 0 > /dev/null 2>&1 & fi @@ -99,12 +101,12 @@ else PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'` while [ -n "$PID" ] do - if [ "$SIGNAL" = "SIGINT" ]; then - echo try to kill by signal SIGINT - kill -SIGINT $PID - else + if [ "$SIGNAL" = "SIGKILL" ]; then echo try to kill by signal SIGKILL kill -9 $PID + else + echo try to kill by signal SIGINT + kill -SIGINT $PID fi sleep 1 PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'` diff --git a/tests/script/sh/exec-random-fail.sh b/tests/script/sh/exec-random-fail.sh index a354021684..3761498859 100755 --- a/tests/script/sh/exec-random-fail.sh +++ b/tests/script/sh/exec-random-fail.sh @@ -88,9 +88,12 @@ if [ "$EXEC_OPTON" = "start" ]; then echo "ExcuteCmd:" $EXE_DIR/taosd -c $CFG_DIR if [ "$SHELL_OPTION" = "true" ]; then - nohup valgrind --log-file=${LOG_DIR}/valgrind.log --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 & + TT=`date +%s` + mkdir ${LOG_DIR}/${TT} + nohup valgrind --log-file=${LOG_DIR}/${TT}/valgrind.log --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes $EXE_DIR/taosd -c $CFG_DIR > /dev/null 2>&1 & else - nohup $EXE_DIR/taosd -c $CFG_DIR --alloc-random-fail --random-file-fail-factor 5 > /dev/null 2>&1 & + nohup $EXE_DIR/taosd -c $CFG_DIR --alloc-random-fail \ + --random-file-fail-factor 5 > /dev/null 2>&1 & fi else @@ -99,12 +102,12 @@ else PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'` while [ -n "$PID" ] do - if [ "$SIGNAL" = "SIGINT" ]; then - echo try to kill by signal SIGINT - kill -SIGINT $PID - else + if [ "$SIGNAL" = "SIGKILL" ]; then echo try to kill by signal SIGKILL kill -9 $PID + else + echo try to kill by signal SIGINT + kill -SIGINT $PID fi sleep 1 PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'` diff --git a/tests/script/sh/exec.sh b/tests/script/sh/exec.sh index 2f294075a1..1c84a6b10e 100755 --- a/tests/script/sh/exec.sh +++ b/tests/script/sh/exec.sh @@ -101,12 +101,12 @@ else PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'` while [ -n "$PID" ] do - if [ "$SIGNAL" = "SIGINT" ]; then - echo try to kill by signal SIGINT - kill -SIGINT $PID - else + if [ "$SIGNAL" = "SIGKILL" ]; then echo try to kill by signal SIGKILL kill -9 $PID + else + echo try to kill by signal SIGINT + kill -SIGINT $PID fi sleep 1 PID=`ps -ef|grep taosd | grep $RCFG_DIR | grep -v grep | awk '{print $2}'` From 52fb827f0a5f42f33f952c313b8bcd02009ec928 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 21 Jul 2020 20:40:19 +0800 Subject: [PATCH 06/15] [TD-972] --- src/mnode/inc/mnodeDef.h | 32 +++++++++++++++----------------- src/mnode/src/mnodeSdb.c | 14 ++++++++++---- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index 3154a441ca..a454f413f0 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -50,8 +50,8 @@ typedef struct SDnodeObj { int8_t alternativeRole; // from dnode status msg, 0-any, 1-mgmt, 2-dnode int8_t status; // set in balance function int8_t isMgmt; - int8_t reserve1[14]; - int8_t updateEnd[1]; + int8_t reserve1[11]; + int8_t updateEnd[4]; int32_t refCount; uint32_t moduleStatus; uint32_t lastReboot; // time stamp for last reboot @@ -68,8 +68,8 @@ typedef struct SMnodeObj { int32_t mnodeId; int8_t reserved0[4]; int64_t createdTime; - int8_t reserved1[7]; - int8_t updateEnd[1]; + int8_t reserved1[4]; + int8_t updateEnd[4]; int32_t refCount; int8_t role; int8_t reserved2[3]; @@ -90,8 +90,7 @@ typedef struct SSuperTableObj { int32_t tversion; int32_t numOfColumns; int32_t numOfTags; - int8_t reserved1[3]; - int8_t updateEnd[1]; + int8_t updateEnd[4]; int32_t refCount; int32_t numOfTables; SSchema * schema; @@ -111,8 +110,7 @@ typedef struct { int32_t sid; int32_t vgId; int32_t sqlLen; - int8_t updateEnd[1]; - int8_t reserved1[1]; + int8_t updateEnd[4]; int32_t refCount; char* sql; //used by normal table SSchema* schema; //used by normal table @@ -138,8 +136,8 @@ typedef struct SVgObj { int8_t status; int8_t reserved0[4]; SVnodeGid vnodeGid[TSDB_MAX_REPLICA]; - int8_t reserved1[7]; - int8_t updateEnd[1]; + int8_t reserved1[4]; + int8_t updateEnd[4]; int32_t refCount; int32_t numOfTables; int64_t totalStorage; @@ -176,8 +174,8 @@ typedef struct SDbObj { int32_t cfgVersion; SDbCfg cfg; int8_t status; - int8_t reserved1[14]; - int8_t updateEnd[1]; + int8_t reserved1[11]; + int8_t updateEnd[4]; int32_t refCount; int32_t numOfVgroups; int32_t numOfTables; @@ -196,8 +194,8 @@ typedef struct SUserObj { int64_t createdTime; int8_t superAuth; int8_t writeAuth; - int8_t reserved[13]; - int8_t updateEnd[1]; + int8_t reserved[10]; + int8_t updateEnd[4]; int32_t refCount; struct SAcctObj * pAcct; } SUserObj; @@ -228,11 +226,11 @@ typedef struct SAcctObj { int64_t createdTime; int32_t acctId; int8_t status; - int8_t reserved0[10]; - int8_t updateEnd[1]; - SAcctInfo acctInfo; + int8_t reserved0[7]; + int8_t updateEnd[4]; int32_t refCount; int8_t reserved1[4]; + SAcctInfo acctInfo; pthread_mutex_t mutex; } SAcctObj; diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index dee82f53be..26b0f60fcd 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -406,7 +406,7 @@ void sdbDecRef(void *handle, void *pObj) { int32_t refCount = atomic_sub_fetch_32(pRefCount, 1); sdbTrace("def ref of table:%s record:%p:%s:%d", pTable->tableName, pObj, sdbGetKeyStrFromObj(pTable, pObj), *pRefCount); - int8_t *updateEnd = pObj + pTable->refCountPos - 1; + int32_t *updateEnd = pObj + pTable->refCountPos - 4; if (refCount <= 0 && *updateEnd) { sdbTrace("table:%s, record:%p:%s:%d is destroyed", pTable->tableName, pObj, sdbGetKeyStrFromObj(pTable, pObj), *pRefCount); SSdbOper oper = {.pObj = pObj}; @@ -472,6 +472,14 @@ static int32_t sdbInsertHash(SSdbTable *pTable, SSdbOper *pOper) { } static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) { + int32_t *updateEnd = pOper->pObj + pTable->refCountPos - 4; + bool set = atomic_val_compare_exchange_32(updateEnd, 0, 1) == 0; + if (!set) { + sdbError("table:%s, failed to delete record:%s from hash, for it already removed", pTable->tableName, + sdbGetKeyStrFromObj(pTable, pOper->pObj)); + return TSDB_CODE_MND_SDB_OBJ_NOT_THERE; + } + (*pTable->deleteFp)(pOper); void * key = sdbGetObjKey(pTable, pOper->pObj); @@ -486,8 +494,6 @@ static int32_t sdbDeleteHash(SSdbTable *pTable, SSdbOper *pOper) { sdbDebug("table:%s, delete record:%s from hash, numOfRows:%" PRId64 ", msg:%p", pTable->tableName, sdbGetKeyStrFromObj(pTable, pOper->pObj), pTable->numOfRows, pOper->pMsg); - int8_t *updateEnd = pOper->pObj + pTable->refCountPos - 1; - *updateEnd = 1; sdbDecRef(pTable, pOper->pObj); return TSDB_CODE_SUCCESS; @@ -654,7 +660,7 @@ bool sdbCheckRowDeleted(void *pTableInput, void *pRow) { SSdbTable *pTable = pTableInput; if (pTable == NULL) return false; - int8_t *updateEnd = pRow + pTable->refCountPos - 1; + int32_t *updateEnd = pRow + pTable->refCountPos - 4; return (*updateEnd == 1); } From 2104d465863922c9352bb9778f88cc3f66cb1fdb Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Wed, 22 Jul 2020 10:26:25 +0800 Subject: [PATCH 07/15] change kill to term signal for coverage flush. --- tests/pytest/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytest/test.py b/tests/pytest/test.py index a9da8e5671..678bd87336 100644 --- a/tests/pytest/test.py +++ b/tests/pytest/test.py @@ -96,7 +96,7 @@ if __name__ == "__main__": processID = subprocess.check_output(usePortPID, shell=True) if processID: - killCmd = "kill -9 %s" % processID + killCmd = "kill -TERM %s" % processID os.system(killCmd) fuserCmd = "fuser -k -n tcp %d" % port os.system(fuserCmd) From 9463982cecc1c00c2c47b3dc3448d8d148114c62 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 22 Jul 2020 11:27:02 +0800 Subject: [PATCH 08/15] [TD-972] drop table before rsp --- src/mnode/src/mnodeSdb.c | 3 +- src/mnode/src/mnodeTable.c | 68 +++++++++++++++++++++++--------------- 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 26b0f60fcd..4b2945152b 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -661,7 +661,8 @@ bool sdbCheckRowDeleted(void *pTableInput, void *pRow) { if (pTable == NULL) return false; int32_t *updateEnd = pRow + pTable->refCountPos - 4; - return (*updateEnd == 1); + return atomic_val_compare_exchange_32(updateEnd, 1, 1) == 1; + // return (*updateEnd == 1); } int32_t sdbDeleteRow(SSdbOper *pOper) { diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 7478d7cd78..12ab58d949 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -72,7 +72,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg); static int32_t mnodeProcessDropTableMsg(SMnodeMsg *mnodeMsg); static int32_t mnodeProcessDropSuperTableMsg(SMnodeMsg *pMsg); static void mnodeProcessDropSuperTableRsp(SRpcMsg *rpcMsg); -static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn); +static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg); static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg); static int32_t mnodeProcessSuperTableVgroupMsg(SMnodeMsg *mnodeMsg); @@ -759,7 +759,7 @@ static int32_t mnodeProcessDropTableMsg(SMnodeMsg *pMsg) { SChildTableObj *pCTable = (SChildTableObj *)pMsg->pTable; mInfo("app:%p:%p, table:%s, start to drop ctable, vgId:%d sid:%d uid:%" PRIu64, pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId, pCTable->vgId, pCTable->sid, pCTable->uid); - return mnodeProcessDropChildTableMsg(pMsg, true); + return mnodeProcessDropChildTableMsg(pMsg); } } @@ -882,7 +882,7 @@ static int32_t mnodeProcessCreateSuperTableMsg(SMnodeMsg *pMsg) { static int32_t mnodeDropSuperTableCb(SMnodeMsg *pMsg, int32_t code) { SSuperTableObj *pTable = (SSuperTableObj *)pMsg->pTable; if (code != TSDB_CODE_SUCCESS) { - mError("app:%p:%p, table:%s, failed to drop, sdb error", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); + mError("app:%p:%p, stable:%s, failed to drop, sdb error", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); } else { mLInfo("app:%p:%p, stable:%s, is dropped from sdb", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); } @@ -1765,18 +1765,13 @@ static int32_t mnodeProcessCreateChildTableMsg(SMnodeMsg *pMsg) { } } -static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) { +static int32_t mnodeSendDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) { SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable; - if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId); - if (pMsg->pVgroup == NULL) { - mError("app:%p:%p, table:%s, failed to drop ctable, vgroup not exist", pMsg->rpcMsg.ahandle, pMsg, - pTable->info.tableId); - return TSDB_CODE_MND_APP_ERROR; - } + mLInfo("app:%p:%p, ctable:%s, is dropped from sdb", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); SMDDropTableMsg *pDrop = rpcMallocCont(sizeof(SMDDropTableMsg)); if (pDrop == NULL) { - mError("app:%p:%p, table:%s, failed to drop ctable, no enough memory", pMsg->rpcMsg.ahandle, pMsg, + mError("app:%p:%p, ctable:%s, failed to drop ctable, no enough memory", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); return TSDB_CODE_MND_OUT_OF_MEMORY; } @@ -1789,7 +1784,7 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) { SRpcEpSet epSet = mnodeGetEpSetFromVgroup(pMsg->pVgroup); - mInfo("app:%p:%p, table:%s, send drop ctable msg, vgId:%d sid:%d uid:%" PRIu64, pMsg->rpcMsg.ahandle, pMsg, + mInfo("app:%p:%p, ctable:%s, send drop ctable msg, vgId:%d sid:%d uid:%" PRIu64, pMsg->rpcMsg.ahandle, pMsg, pDrop->tableId, pTable->vgId, pTable->sid, pTable->uid); SRpcMsg rpcMsg = { @@ -1807,6 +1802,40 @@ static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg, bool needReturn) { return TSDB_CODE_MND_ACTION_IN_PROGRESS; } +static int32_t mnodeDropChildTableCb(SMnodeMsg *pMsg, int32_t code) { + if (code != TSDB_CODE_SUCCESS) { + SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable; + mError("app:%p:%p, ctable:%s, failed to drop, sdb error", pMsg->rpcMsg.ahandle, pMsg, pTable->info.tableId); + return code; + } + + return mnodeSendDropChildTableMsg(pMsg, true); +} + +static int32_t mnodeProcessDropChildTableMsg(SMnodeMsg *pMsg) { + SChildTableObj *pTable = (SChildTableObj *)pMsg->pTable; + if (pMsg->pVgroup == NULL) pMsg->pVgroup = mnodeGetVgroup(pTable->vgId); + if (pMsg->pVgroup == NULL) { + mError("app:%p:%p, table:%s, failed to drop ctable, vgroup not exist", pMsg->rpcMsg.ahandle, pMsg, + pTable->info.tableId); + return TSDB_CODE_MND_APP_ERROR; + } + + SSdbOper oper = { + .type = SDB_OPER_GLOBAL, + .table = tsChildTableSdb, + .pObj = pTable, + .pMsg = pMsg, + .cb = mnodeDropChildTableCb + }; + + int32_t code = sdbDeleteRow(&oper); + if (code == TSDB_CODE_SUCCESS) { + return TSDB_CODE_MND_ACTION_IN_PROGRESS; + } + return code; +} + static int32_t mnodeFindNormalTableColumnIndex(SChildTableObj *pTable, char *colName) { SSchema *schema = (SSchema *) pTable->schema; for (int32_t col = 0; col < pTable->numOfColumns; col++) { @@ -2220,19 +2249,6 @@ static void mnodeProcessDropChildTableRsp(SRpcMsg *rpcMsg) { return; } - SSdbOper oper = { - .type = SDB_OPER_GLOBAL, - .table = tsChildTableSdb, - .pObj = pTable - }; - - int32_t code = sdbDeleteRow(&oper); - if (code != TSDB_CODE_SUCCESS) { - mError("app:%p:%p, table:%s, update ctables sdb error", mnodeMsg->rpcMsg.ahandle, mnodeMsg, pTable->info.tableId); - dnodeSendRpcMnodeWriteRsp(mnodeMsg, TSDB_CODE_MND_SDB_ERROR); - return; - } - if (mnodeMsg->pVgroup->numOfTables <= 0) { mInfo("app:%p:%p, vgId:%d, all tables is dropped, drop vgroup", mnodeMsg->rpcMsg.ahandle, mnodeMsg, mnodeMsg->pVgroup->vgId); @@ -2259,7 +2275,7 @@ static void mnodeProcessCreateChildTableRsp(SRpcMsg *rpcMsg) { if (sdbCheckRowDeleted(tsChildTableSdb, pTable)) { mDebug("app:%p:%p, table:%s, create table rsp received, but a deleting opertion incoming, vgId:%d sid:%d uid:%" PRIu64, mnodeMsg->rpcMsg.ahandle, mnodeMsg, pTable->info.tableId, pTable->vgId, pTable->sid, pTable->uid); - mnodeProcessDropChildTableMsg(mnodeMsg, false); + mnodeSendDropChildTableMsg(mnodeMsg, false); rpcMsg->code = TSDB_CODE_SUCCESS; } From 9397bbe48a4bd18c5dceff6c0bc244dae011981b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 22 Jul 2020 11:47:02 +0800 Subject: [PATCH 09/15] [TD-972] jump or move depends on uninitialised value --- src/mnode/src/mnodeShow.c | 4 ++-- src/mnode/src/mnodeUser.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index e3d5b41be3..1d85a8cacd 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -236,7 +236,7 @@ static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) { } SCMHeartBeatMsg *pHBMsg = pMsg->rpcMsg.pCont; - SRpcConnInfo connInfo; + SRpcConnInfo connInfo = {0}; rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo); int32_t connId = htonl(pHBMsg->connId); @@ -284,7 +284,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { SCMConnectRsp *pConnectRsp = NULL; int32_t code = TSDB_CODE_SUCCESS; - SRpcConnInfo connInfo; + SRpcConnInfo connInfo = {0}; if (rpcGetConnInfo(pMsg->rpcMsg.handle, &connInfo) != 0) { mError("thandle:%p is already released while process connect msg", pMsg->rpcMsg.handle); code = TSDB_CODE_MND_INVALID_CONNECTION; diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index 84f5d6aa58..8c783eebaf 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -358,7 +358,7 @@ static int32_t mnodeRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, voi } SUserObj *mnodeGetUserFromConn(void *pConn) { - SRpcConnInfo connInfo; + SRpcConnInfo connInfo = {0}; if (rpcGetConnInfo(pConn, &connInfo) == 0) { return mnodeGetUser(connInfo.user); } else { From b6fb79dc0dd43518442ef0a02ca71e5e905b495a Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 22 Jul 2020 14:32:36 +0800 Subject: [PATCH 10/15] fix td-900: support both config dir & file --- src/util/src/tconfig.c | 53 ++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index 74acb7ce35..d561e8ba5f 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -308,38 +308,47 @@ bool taosReadGlobalCfg() { sprintf(fileName, "%s/taos.cfg", configDir); FILE* fp = fopen(fileName, "r"); + if (fp == NULL) { + struct stat s; + if (stat(configDir, &s) != 0 || (!S_ISREG(s.st_mode) && !S_ISLNK(s.st_mode))) { + //return true to follow behavior before file support + return true; + } + fp = fopen(configDir, "r"); + if (fp == NULL) { + return false; + } + } size_t len = 1024; line = calloc(1, len); - if (fp != NULL) { - while (!feof(fp)) { - memset(line, 0, len); + while (!feof(fp)) { + memset(line, 0, len); - option = value = NULL; - olen = vlen = 0; + option = value = NULL; + olen = vlen = 0; - getline(&line, &len, fp); - line[len - 1] = 0; - - paGetToken(line, &option, &olen); - if (olen == 0) continue; - option[olen] = 0; + getline(&line, &len, fp); + line[len - 1] = 0; + + paGetToken(line, &option, &olen); + if (olen == 0) continue; + option[olen] = 0; - paGetToken(option + olen + 1, &value, &vlen); - if (vlen == 0) continue; - value[vlen] = 0; + paGetToken(option + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; - // For dataDir, the format is: - // dataDir /mnt/disk1 0 - paGetToken(value + vlen + 1, &value1, &vlen1); - - taosReadConfigOption(option, value); - } - - fclose(fp); + // For dataDir, the format is: + // dataDir /mnt/disk1 0 + paGetToken(value + vlen + 1, &value1, &vlen1); + + taosReadConfigOption(option, value); } + fclose(fp); + tfree(line); return true; From ec47ae9ccab2d0a0695a66dd9b6cd8b7ad67cb5d Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Wed, 22 Jul 2020 14:38:06 +0800 Subject: [PATCH 11/15] TD-978: adjust kill command --- .../java/com/taosdata/jdbc/utils/TDNode.java | 51 ++++++++++++++++--- .../java/com/taosdata/jdbc/utils/TDNodes.java | 32 ++---------- .../test/java/com/taosdata/jdbc/BaseTest.java | 28 +++++----- 3 files changed, 62 insertions(+), 49 deletions(-) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java index df25076a95..800265868d 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNode.java @@ -1,6 +1,8 @@ package com.taosdata.jdbc.utils; +import java.io.BufferedReader; import java.io.File; +import java.io.InputStreamReader; import java.util.*; import java.util.concurrent.TimeUnit; @@ -31,6 +33,10 @@ public class TDNode { this.testCluster = testCluster; } + public void setRunning(int running) { + this.running = running; + } + public void searchTaosd(File dir, ArrayList taosdPath) { File[] fileList = dir.listFiles(); @@ -102,15 +108,46 @@ public class TDNode { this.running = 1; } - public void stop() { - String toBeKilled = "taosd"; + public Integer getTaosdPid() { + String cmd = "ps -ef|grep -w taosd| grep -v grep | awk '{print $2}'"; + String[] cmds = {"sh", "-c", cmd}; + try { + Process process = Runtime.getRuntime().exec(cmds); + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line = null; + Integer res = null; + while((line = reader.readLine()) != null) { + if(!line.isEmpty()) { + res = Integer.valueOf(line); + break; + } + } + + return res; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + public void stop() { if (this.running != 0) { - String killCmd = "pkill -kill -x " + toBeKilled; - String[] killCmds = {"sh", "-c", killCmd}; - try { - Runtime.getRuntime().exec(killCmds).waitFor(); + Integer pid = null; + while((pid = getTaosdPid()) != null) { + + String killCmd = "kill -term " + pid; + String[] killCmds = {"sh", "-c", killCmd}; + try { + Runtime.getRuntime().exec(killCmds).waitFor(); + TimeUnit.SECONDS.sleep(2); + } catch (Exception e) { + e.printStackTrace(); + } + } + + try { for(int port = 6030; port < 6041; port ++) { String fuserCmd = "fuser -k -n tcp " + port; Runtime.getRuntime().exec(fuserCmd).waitFor(); @@ -120,7 +157,7 @@ public class TDNode { } this.running = 0; - System.out.println("dnode:" + this.index + " is stopped by pkill"); + System.out.println("dnode:" + this.index + " is stopped by kill -term"); } } diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNodes.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNodes.java index ea15ae9863..efc4c53e28 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNodes.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/TDNodes.java @@ -14,33 +14,6 @@ public class TDNodes { } } - public void setPath(String path) { - try { - String killCmd = "pkill -kill -x taosd"; - String[] killCmds = {"sh", "-c", killCmd}; - Runtime.getRuntime().exec(killCmds).waitFor(); - - String binPath = System.getProperty("user.dir"); - binPath += "/../../../debug"; - System.out.println("binPath: " + binPath); - - File file = new File(path); - binPath = file.getCanonicalPath(); - System.out.println("binPath real path: " + binPath); - - if(path.isEmpty()){ - file = new File(path + "/../../"); - path = file.getCanonicalPath(); - } - - for(int i = 0; i < tdNodes.size(); i++) { - tdNodes.get(i).setPath(path); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - public void setTestCluster(boolean testCluster) { this.testCluster = testCluster; } @@ -70,6 +43,11 @@ public class TDNodes { check(index); tdNodes.get(index - 1).setCfgConfig(option, value); } + + public TDNode getTDNode(int index) { + check(index); + return tdNodes.get(index - 1); + } public void start(int index) { check(index); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java index 5f105fb782..6c3437186f 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/BaseTest.java @@ -1,6 +1,5 @@ package com.taosdata.jdbc; -import java.io.File; import com.taosdata.jdbc.utils.TDNodes; import org.junit.AfterClass; @@ -8,31 +7,30 @@ import org.junit.BeforeClass; public class BaseTest { - private static boolean testCluster = false; - private static String deployPath = System.getProperty("user.dir"); - private static TDNodes tdNodes = new TDNodes(); + private static boolean testCluster = false; + private static TDNodes nodes = new TDNodes(); @BeforeClass public static void setupEnv() { - try{ - File file = new File(deployPath + "/../../../"); - String rootPath = file.getCanonicalPath(); - - tdNodes.setPath(rootPath); - tdNodes.setTestCluster(testCluster); + try{ + if (nodes.getTDNode(1).getTaosdPid() != null) { + System.out.println("Kill taosd before running JDBC test"); + nodes.getTDNode(1).setRunning(1); + nodes.stop(1); + } - tdNodes.deploy(1); - tdNodes.start(1); + nodes.setTestCluster(testCluster); + nodes.deploy(1); + nodes.start(1); } catch (Exception e) { - e.printStackTrace(); - System.out.println("Base Test Exception"); + e.printStackTrace(); } } @AfterClass public static void cleanUpEnv() { - tdNodes.stop(1); + nodes.stop(1); } } \ No newline at end of file From 01e348cc0182111863b2d819700719255c721726 Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 22 Jul 2020 16:23:52 +0800 Subject: [PATCH 12/15] fix td-980 --- src/query/src/qExecutor.c | 6 ++++- src/tsdb/src/tsdbMeta.c | 5 +++- src/tsdb/src/tsdbRead.c | 53 ++++++++++++++++++++++++++------------- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 906d0cfe67..1220c5ca31 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -6419,8 +6419,12 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co size += sizeof(STableIdInfo) * taosArrayGetSize(pQInfo->arrTableIdInfo); *contLen = size + sizeof(SRetrieveTableRsp); - // todo handle failed to allocate memory + // todo proper handle failed to allocate memory, + // current solution only avoid crash, but cannot return error code to client *pRsp = (SRetrieveTableRsp *)rpcMallocCont(*contLen); + if (*pRsp == NULL) { + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } (*pRsp)->numOfRows = htonl(pQuery->rec.rows); int32_t code = pQInfo->code; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index c1923f5235..b25e734694 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -123,7 +123,10 @@ int tsdbCreateTable(TSDB_REPO_T *repo, STableCfg *pCfg) { int tlen2 = tsdbGetTableEncodeSize(TSDB_UPDATE_META, table); int tlen = tlen1 + tlen2; void *buf = tsdbAllocBytes(pRepo, tlen); - ASSERT(buf != NULL); + if (buf == NULL) { + goto _err; + } + if (newSuper) { void *pBuf = tsdbInsertTableAct(pRepo, TSDB_UPDATE_META, buf, super); ASSERT(POINTER_DISTANCE(pBuf, buf) == tlen1); diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index b2204948d0..fc67c64e2e 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -201,18 +201,34 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab int32_t numOfCols = pCond->numOfCols; pQueryHandle->statis = calloc(numOfCols, sizeof(SDataStatis)); + if (pQueryHandle->statis == NULL) { + tsdbCleanupQueryHandle(pQueryHandle); + return NULL; + } pQueryHandle->pColumns = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); // todo: use list instead of array? + if (pQueryHandle->pColumns == NULL) { + tsdbCleanupQueryHandle(pQueryHandle); + return NULL; + } for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData colInfo = {{0}, 0}; colInfo.info = pCond->colList[i]; colInfo.pData = calloc(1, EXTRA_BYTES + pQueryHandle->outputCapacity * pCond->colList[i].bytes); + if (colInfo.pData == NULL) { + tsdbCleanupQueryHandle(pQueryHandle); + return NULL; + } taosArrayPush(pQueryHandle->pColumns, &colInfo); pQueryHandle->statis[i].colId = colInfo.info.colId; } pQueryHandle->pTableCheckInfo = taosArrayInit(groupList->numOfTables, sizeof(STableCheckInfo)); + if (pQueryHandle->pTableCheckInfo == NULL) { + tsdbCleanupQueryHandle(pQueryHandle); + return NULL; + } STsdbMeta* pMeta = tsdbGetMeta(tsdb); assert(pMeta != NULL); @@ -2372,28 +2388,31 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) { return; } - size_t size = taosArrayGetSize(pQueryHandle->pTableCheckInfo); - for (int32_t i = 0; i < size; ++i) { - STableCheckInfo* pTableCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i); - destroyTableMemIterator(pTableCheckInfo); + if (pQueryHandle->pTableCheckInfo != NULL) { + size_t size = taosArrayGetSize(pQueryHandle->pTableCheckInfo); + for (int32_t i = 0; i < size; ++i) { + STableCheckInfo* pTableCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i); + destroyTableMemIterator(pTableCheckInfo); - if (pTableCheckInfo->pDataCols != NULL) { - tfree(pTableCheckInfo->pDataCols->buf); + if (pTableCheckInfo->pDataCols != NULL) { + tfree(pTableCheckInfo->pDataCols->buf); + } + + tfree(pTableCheckInfo->pDataCols); + tfree(pTableCheckInfo->pCompInfo); } - - tfree(pTableCheckInfo->pDataCols); - tfree(pTableCheckInfo->pCompInfo); + taosArrayDestroy(pQueryHandle->pTableCheckInfo); } - taosArrayDestroy(pQueryHandle->pTableCheckInfo); + if (pQueryHandle->pColumns != NULL) { + size_t cols = taosArrayGetSize(pQueryHandle->pColumns); + for (int32_t i = 0; i < cols; ++i) { + SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, i); + tfree(pColInfo->pData); + } + taosArrayDestroy(pQueryHandle->pColumns); + } - size_t cols = taosArrayGetSize(pQueryHandle->pColumns); - for (int32_t i = 0; i < cols; ++i) { - SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, i); - tfree(pColInfo->pData); - } - - taosArrayDestroy(pQueryHandle->pColumns); taosArrayDestroy(pQueryHandle->defaultLoadColumn); tfree(pQueryHandle->pDataBlockInfo); tfree(pQueryHandle->statis); From 41c76edcc3c7e356e181dac66e64c40a8428746e Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 22 Jul 2020 17:06:53 +0800 Subject: [PATCH 13/15] fix crash in executing compress2.sim --- src/tsdb/src/tsdbRead.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index fc67c64e2e..c82d1f905a 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -188,8 +188,7 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab pQueryHandle->allocSize = 0; if (tsdbInitReadHelper(&pQueryHandle->rhelper, (STsdbRepo*) tsdb) != 0) { - free(pQueryHandle); - return NULL; + goto out_of_memory; } tsdbTakeMemSnapshot(pQueryHandle->pTsdb, &pQueryHandle->mem, &pQueryHandle->imem); @@ -202,13 +201,11 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab pQueryHandle->statis = calloc(numOfCols, sizeof(SDataStatis)); if (pQueryHandle->statis == NULL) { - tsdbCleanupQueryHandle(pQueryHandle); - return NULL; + goto out_of_memory; } pQueryHandle->pColumns = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); // todo: use list instead of array? if (pQueryHandle->pColumns == NULL) { - tsdbCleanupQueryHandle(pQueryHandle); - return NULL; + goto out_of_memory; } for (int32_t i = 0; i < numOfCols; ++i) { @@ -217,8 +214,7 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab colInfo.info = pCond->colList[i]; colInfo.pData = calloc(1, EXTRA_BYTES + pQueryHandle->outputCapacity * pCond->colList[i].bytes); if (colInfo.pData == NULL) { - tsdbCleanupQueryHandle(pQueryHandle); - return NULL; + goto out_of_memory; } taosArrayPush(pQueryHandle->pColumns, &colInfo); pQueryHandle->statis[i].colId = colInfo.info.colId; @@ -226,8 +222,7 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab pQueryHandle->pTableCheckInfo = taosArrayInit(groupList->numOfTables, sizeof(STableCheckInfo)); if (pQueryHandle->pTableCheckInfo == NULL) { - tsdbCleanupQueryHandle(pQueryHandle); - return NULL; + goto out_of_memory; } STsdbMeta* pMeta = tsdbGetMeta(tsdb); assert(pMeta != NULL); @@ -263,6 +258,11 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab tsdbInitCompBlockLoadInfo(&pQueryHandle->compBlockLoadInfo); return (TsdbQueryHandleT) pQueryHandle; + +out_of_memory: + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + tsdbCleanupQueryHandle(pQueryHandle); + return NULL; } TsdbQueryHandleT tsdbQueryLastRow(TSDB_REPO_T *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, void* qinfo) { From 8428a1afbc85afc734dd4b18fb155f942bb9fe49 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 22 Jul 2020 09:56:08 +0000 Subject: [PATCH 14/15] [TD-926] refactor alter dnode func --- src/client/src/tscSQLParser.c | 44 ++++++++++++++------- src/common/inc/tglobal.h | 1 + src/common/src/tglobal.c | 41 +++++++++++++++++++- src/inc/taoserror.h | 1 + src/inc/tbalance.h | 1 + src/mnode/src/mnodeBalance.c | 1 + src/mnode/src/mnodeDnode.c | 56 +++++++++++++-------------- src/plugins/monitor/src/monitorMain.c | 43 ++++++-------------- 8 files changed, 113 insertions(+), 75 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 09db65a105..32d44dfb81 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -358,7 +358,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) { } case TSDB_SQL_CFG_DNODE: { - const char* msg2 = "invalid configure options or values"; + const char* msg2 = "invalid configure options or values, such as resetlog / debugFlag 135 / balance 'vnode:1-dnode:2' / monitor 1 "; const char* msg3 = "invalid dnode ep"; /* validate the ip address */ @@ -4674,26 +4674,42 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { return TSDB_CODE_TSC_INVALID_SQL; } - const int DNODE_DYNAMIC_CFG_OPTIONS_SIZE = 19; - const SDNodeDynConfOption DNODE_DYNAMIC_CFG_OPTIONS[] = { - {"resetLog", 8}, {"resetQueryCache", 15}, {"debugFlag", 9}, {"mDebugFlag", 10}, - {"dDebugFlag", 10}, {"sdbDebugFlag", 12}, {"vDebugFlag", 10}, {"cDebugFlag", 10}, - {"httpDebugFlag", 13}, {"monitorDebugFlag", 16}, {"rpcDebugFlag", 12}, {"uDebugFlag", 10}, - {"tmrDebugFlag", 12}, {"qDebugflag", 10}, {"sDebugflag", 10}, {"tsdbDebugFlag", 13}, - {"mqttDebugFlag", 13}, {"wDebugFlag", 10}, {"monitor", 7}}; + const int tokenLogEnd = 2; + const int tokenBalance = 2; + const int tokenMonitor = 3; + const int tokenDebugFlag = 4; + const int tokenDebugFlagEnd = 20; + const SDNodeDynConfOption cfgOptions[] = { + {"resetLog", 8}, {"resetQueryCache", 15}, {"balance", 7}, {"monitor", 7}, + {"debugFlag", 9}, {"monitorDebugFlag", 16}, {"vDebugFlag", 10}, {"mDebugFlag", 10}, + {"cDebugFlag", 10}, {"httpDebugFlag", 13}, {"qDebugflag", 10}, {"sdbDebugFlag", 12}, + {"uDebugFlag", 10}, {"tsdbDebugFlag", 13}, {"sDebugflag", 10}, {"rpcDebugFlag", 12}, + {"dDebugFlag", 10}, {"mqttDebugFlag", 13}, {"wDebugFlag", 10}, {"tmrDebugFlag", 12}, + }; SSQLToken* pOptionToken = &pOptions->a[1]; if (pOptions->nTokens == 2) { // reset log and reset query cache does not need value - for (int32_t i = 0; i < 2; ++i) { - const SDNodeDynConfOption* pOption = &DNODE_DYNAMIC_CFG_OPTIONS[i]; + for (int32_t i = 0; i < tokenLogEnd; ++i) { + const SDNodeDynConfOption* pOption = &cfgOptions[i]; if ((strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0) && (pOption->len == pOptionToken->n)) { return TSDB_CODE_SUCCESS; } } - } else if ((strncasecmp(DNODE_DYNAMIC_CFG_OPTIONS[DNODE_DYNAMIC_CFG_OPTIONS_SIZE - 1].name, pOptionToken->z, pOptionToken->n) == 0) && - (DNODE_DYNAMIC_CFG_OPTIONS[DNODE_DYNAMIC_CFG_OPTIONS_SIZE - 1].len == pOptionToken->n)) { + } else if ((strncasecmp(cfgOptions[tokenBalance].name, pOptionToken->z, pOptionToken->n) == 0) && + (cfgOptions[tokenBalance].len == pOptionToken->n)) { + SSQLToken* pValToken = &pOptions->a[2]; + int32_t vnodeIndex = 0; + int32_t dnodeIndex = 0; + strdequote(pValToken->z); + bool parseOk = taosCheckBalanceCfgOptions(pValToken->z, &vnodeIndex, &dnodeIndex); + if (!parseOk) { + return TSDB_CODE_TSC_INVALID_SQL; // options value is invalid + } + return TSDB_CODE_SUCCESS; + } else if ((strncasecmp(cfgOptions[tokenMonitor].name, pOptionToken->z, pOptionToken->n) == 0) && + (cfgOptions[tokenMonitor].len == pOptionToken->n)) { SSQLToken* pValToken = &pOptions->a[2]; int32_t val = strtol(pValToken->z, NULL, 10); if (val != 0 && val != 1) { @@ -4709,8 +4725,8 @@ int32_t validateDNodeConfig(tDCLSQL* pOptions) { return TSDB_CODE_TSC_INVALID_SQL; } - for (int32_t i = 2; i < DNODE_DYNAMIC_CFG_OPTIONS_SIZE - 1; ++i) { - const SDNodeDynConfOption* pOption = &DNODE_DYNAMIC_CFG_OPTIONS[i]; + for (int32_t i = tokenDebugFlag; i < tokenDebugFlagEnd; ++i) { + const SDNodeDynConfOption* pOption = &cfgOptions[i]; if ((strncasecmp(pOption->name, pOptionToken->z, pOptionToken->n) == 0) && (pOption->len == pOptionToken->n)) { /* options is valid */ diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 6506707457..7ba96ceb60 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -174,6 +174,7 @@ bool taosCheckGlobalCfg(); void taosSetAllDebugFlag(); bool taosCfgDynamicOptions(char *msg); int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port); +bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeIndex, int32_t *dnodeIndex); #ifdef __cplusplus } diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 56c63ee49d..c79b016b93 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -198,6 +198,7 @@ int32_t tsdbDebugFlag = 131; int32_t (*monitorStartSystemFp)() = NULL; void (*monitorStopSystemFp)() = NULL; +void (*monitorExecuteSQLFp)(char *sql) = NULL; static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT; @@ -252,11 +253,15 @@ bool taosCfgDynamicOptions(char *msg) { if (monitorStartSystemFp) { (*monitorStartSystemFp)(); uInfo("monitor is enabled"); + } else { + uError("monitor can't be updated, for monitor not initialized"); } } else { if (monitorStopSystemFp) { (*monitorStopSystemFp)(); uInfo("monitor is disabled"); + } else { + uError("monitor can't be updated, for monitor not initialized"); } } return true; @@ -276,7 +281,12 @@ bool taosCfgDynamicOptions(char *msg) { } if (strncasecmp(option, "resetQueryCache", 15) == 0) { - uError("reset query cache can't be executed, for monitor not initialized"); + if (monitorExecuteSQLFp) { + (*monitorExecuteSQLFp)("resetQueryCache"); + uInfo("resetquerycache is executed"); + } else { + uError("resetquerycache can't be executed, for monitor not started"); + } } return false; @@ -1300,3 +1310,32 @@ int taosGetFqdnPortFromEp(const char *ep, char *fqdn, uint16_t *port) { return 0; } + +/* + * alter dnode 1 balance "vnode:1-dnode:2" + */ + +bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeIndex, int32_t *dnodeIndex) { + int len = strlen(option); + if (strncasecmp(option, "vnode:", 6) != 0) { + return false; + } + + int pos = 0; + for (; pos < len; ++pos) { + if (option[pos] == '-') break; + } + + if (++pos >= len) return false; + if (strncasecmp(option + pos, "dnode:", 6) != 0) { + return false; + } + + *vnodeIndex = strtol(option + 6, NULL, 10); + *dnodeIndex = strtol(option + pos + 6, NULL, 10); + if (*vnodeIndex <= 1 || *dnodeIndex <= 0) { + return false; + } + + return true; +} \ No newline at end of file diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index 3503e39d31..59b2c0220b 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -227,6 +227,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_CPU_LIMITED, 0, 0x080B, "grant cpu // sync TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INVALID_CONFIG, 0, 0x0900, "sync invalid configuration") +TAOS_DEFINE_ERROR(TSDB_CODE_SYN_NOT_ENABLED, 0, 0x0901, "sync module not enabled") // wal TAOS_DEFINE_ERROR(TSDB_CODE_WAL_APP_ERROR, 0, 0x1000, "wal app error") diff --git a/src/inc/tbalance.h b/src/inc/tbalance.h index c52f5afaaa..9ee8d73189 100644 --- a/src/inc/tbalance.h +++ b/src/inc/tbalance.h @@ -29,6 +29,7 @@ void balanceAsyncNotify(); void balanceSyncNotify(); void balanceReset(); int32_t balanceAllocVnodes(struct SVgObj *pVgroup); +int32_t balanceCfgDnode(struct SDnodeObj *pDnode, const char *option); int32_t balanceDropDnode(struct SDnodeObj *pDnode); #ifdef __cplusplus diff --git a/src/mnode/src/mnodeBalance.c b/src/mnode/src/mnodeBalance.c index 23fc10d0bd..d2ec6dd36e 100644 --- a/src/mnode/src/mnodeBalance.c +++ b/src/mnode/src/mnodeBalance.c @@ -28,6 +28,7 @@ void balanceCleanUp() {} void balanceAsyncNotify() {} void balanceSyncNotify() {} void balanceReset() {} +int32_t balanceCfgDnode(struct SDnodeObj *pDnode, const char *option) { return TSDB_CODE_SYN_NOT_ENABLED; } int32_t balanceAllocVnodes(SVgObj *pVgroup) { void * pIter = NULL; diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 7edba8662e..26c4b7a3ea 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -277,45 +277,45 @@ static int32_t mnodeProcessCfgDnodeMsg(SMnodeMsg *pMsg) { SCMCfgDnodeMsg *pCmCfgDnode = pMsg->rpcMsg.pCont; if (pCmCfgDnode->ep[0] == 0) { tstrncpy(pCmCfgDnode->ep, tsLocalEp, TSDB_EP_LEN); - } - - int32_t dnodeId = 0; - char* pos = strchr(pCmCfgDnode->ep, ':'); - if (NULL == pos) { - dnodeId = strtol(pCmCfgDnode->ep, NULL, 10); - if (dnodeId <= 0 || dnodeId > 65536) { - mError("failed to cfg dnode, invalid dnodeId:%s", pCmCfgDnode->ep); - return TSDB_CODE_MND_DNODE_NOT_EXIST; - } } - SRpcEpSet epSet = mnodeGetEpSetFromIp(pCmCfgDnode->ep); - if (dnodeId != 0) { - SDnodeObj *pDnode = mnodeGetDnode(dnodeId); + SDnodeObj *pDnode = mnodeGetDnodeByEp(pCmCfgDnode->ep); + if (pDnode == NULL) { + int32_t dnodeId = strtol(pCmCfgDnode->ep, NULL, 10); + if (dnodeId <= 0 || dnodeId > 65536) { + mError("failed to cfg dnode, invalid dnodeEp:%s", pCmCfgDnode->ep); + return TSDB_CODE_MND_DNODE_NOT_EXIST; + } + + pDnode = mnodeGetDnode(dnodeId); if (pDnode == NULL) { mError("failed to cfg dnode, invalid dnodeId:%d", dnodeId); return TSDB_CODE_MND_DNODE_NOT_EXIST; } - epSet = mnodeGetEpSetFromIp(pDnode->dnodeEp); - mnodeDecDnodeRef(pDnode); } - SMDCfgDnodeMsg *pMdCfgDnode = rpcMallocCont(sizeof(SMDCfgDnodeMsg)); - strcpy(pMdCfgDnode->ep, pCmCfgDnode->ep); - strcpy(pMdCfgDnode->config, pCmCfgDnode->config); + SRpcEpSet epSet = mnodeGetEpSetFromIp(pDnode->dnodeEp); + mnodeDecDnodeRef(pDnode); - SRpcMsg rpcMdCfgDnodeMsg = { - .ahandle = 0, - .code = 0, - .msgType = TSDB_MSG_TYPE_MD_CONFIG_DNODE, - .pCont = pMdCfgDnode, - .contLen = sizeof(SMDCfgDnodeMsg) - }; + if (strncasecmp(pCmCfgDnode->config, "balance", 7) == 0) { + return balanceCfgDnode(pDnode, pCmCfgDnode->config + 8); + } else { + SMDCfgDnodeMsg *pMdCfgDnode = rpcMallocCont(sizeof(SMDCfgDnodeMsg)); + strcpy(pMdCfgDnode->ep, pCmCfgDnode->ep); + strcpy(pMdCfgDnode->config, pCmCfgDnode->config); - mInfo("dnode:%s, is configured by %s", pCmCfgDnode->ep, pMsg->pUser->user); - dnodeSendMsgToDnode(&epSet, &rpcMdCfgDnodeMsg); + SRpcMsg rpcMdCfgDnodeMsg = { + .ahandle = 0, + .code = 0, + .msgType = TSDB_MSG_TYPE_MD_CONFIG_DNODE, + .pCont = pMdCfgDnode, + .contLen = sizeof(SMDCfgDnodeMsg) + }; - return TSDB_CODE_SUCCESS; + mInfo("dnode:%s, is configured by %s", pCmCfgDnode->ep, pMsg->pUser->user); + dnodeSendMsgToDnode(&epSet, &rpcMdCfgDnodeMsg); + return TSDB_CODE_SUCCESS; + } } static void mnodeProcessCfgDnodeMsgRsp(SRpcMsg *rpcMsg) { diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index e6e8cf982b..0cc28bb82c 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -27,7 +27,6 @@ #include "dnode.h" #include "monitor.h" - #define monitorFatal(...) { if (monitorDebugFlag & DEBUG_FATAL) { taosPrintLog("MON FATAL ", 255, __VA_ARGS__); }} #define monitorError(...) { if (monitorDebugFlag & DEBUG_ERROR) { taosPrintLog("MON ERROR ", 255, __VA_ARGS__); }} #define monitorWarn(...) { if (monitorDebugFlag & DEBUG_WARN) { taosPrintLog("MON WARN ", 255, __VA_ARGS__); }} @@ -78,6 +77,7 @@ static void monitorStartTimer(); static void monitorSaveSystemInfo(); extern int32_t (*monitorStartSystemFp)(); extern void (*monitorStopSystemFp)(); +extern void (*monitorExecuteSQLFp)(char *sql); static void monitorCheckDiskUsage(void *para, void *unused) { taosGetDisk(); @@ -207,6 +207,7 @@ static void monitorInitDatabase() { taos_query_a(tsMonitorConn.conn, tsMonitorConn.sql, monitorInitDatabaseCb, NULL); } else { tsMonitorConn.state = MONITOR_STATE_INITIALIZED; + monitorExecuteSQLFp = monitorExecuteSQL; monitorInfo("monitor service init success"); monitorStartTimer(); @@ -230,6 +231,7 @@ static void monitorInitDatabaseCb(void *param, TAOS_RES *result, int32_t code) { void monitorStopSystem() { monitorInfo("monitor module is stopped"); + monitorExecuteSQLFp = NULL; tsMonitorConn.state = MONITOR_STATE_STOPPED; if (tsMonitorConn.initTimer != NULL) { taosTmrStopA(&(tsMonitorConn.initTimer)); @@ -248,33 +250,13 @@ static void monitorStartTimer() { taosTmrReset(monitorSaveSystemInfo, tsMonitorInterval * 1000, NULL, tscTmr, &tsMonitorConn.timer); } -static void dnodeMontiorInsertAcctCallback(void *param, TAOS_RES *result, int32_t code) { +static void dnodeMontiorLogCallback(void *param, TAOS_RES *result, int32_t code) { if (code < 0) { - monitorError("monitor:%p, save account info failed, code:%s", tsMonitorConn.conn, tstrerror(code)); + monitorError("monitor:%p, save %s failed, reason:%s", tsMonitorConn.conn, (char *)param, tstrerror(code)); } else if (code == 0) { - monitorError("monitor:%p, save account info failed, affect rows:%d", tsMonitorConn.conn, code); + monitorError("monitor:%p, save %s failed, affect rows:%d", tsMonitorConn.conn, (char *)param, code); } else { - monitorDebug("monitor:%p, save account info success, code:%s", tsMonitorConn.conn, tstrerror(code)); - } -} - -static void dnodeMontiorInsertSysCallback(void *param, TAOS_RES *result, int32_t code) { - if (code < 0) { - monitorError("monitor:%p, save system info failed, code:%s %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql); - } else if (code == 0) { - monitorError("monitor:%p, save system info failed, affect rows:%d %s", tsMonitorConn.conn, code, tsMonitorConn.sql); - } else { - monitorDebug("monitor:%p, save system info success, code:%s %s", tsMonitorConn.conn, tstrerror(code), tsMonitorConn.sql); - } -} - -static void dnodeMontiorInsertLogCallback(void *param, TAOS_RES *result, int32_t code) { - if (code < 0) { - monitorError("monitor:%p, save log failed, code:%s", tsMonitorConn.conn, tstrerror(code)); - } else if (code == 0) { - monitorError("monitor:%p, save log failed, affect rows:%d", tsMonitorConn.conn, code); - } else { - monitorDebug("monitor:%p, save log info success, code:%s", tsMonitorConn.conn, tstrerror(code)); + monitorDebug("monitor:%p, save %s info success, reason:%s", tsMonitorConn.conn, (char *)param, tstrerror(code)); } } @@ -359,7 +341,7 @@ static void monitorSaveSystemInfo() { pos += monitorBuildReqSql(sql + pos); monitorDebug("monitor:%p, save system info, sql:%s", tsMonitorConn.conn, sql); - taos_query_a(tsMonitorConn.conn, sql, dnodeMontiorInsertSysCallback, "log"); + taos_query_a(tsMonitorConn.conn, sql, dnodeMontiorLogCallback, "sys"); if (tsMonitorConn.timer != NULL && tsMonitorConn.state != MONITOR_STATE_STOPPED) { monitorStartTimer(); @@ -397,7 +379,7 @@ void monitorSaveAcctLog(SAcctMonitorObj *pMon) { pMon->accessState); monitorDebug("monitor:%p, save account info, sql %s", tsMonitorConn.conn, sql); - taos_query_a(tsMonitorConn.conn, sql, dnodeMontiorInsertAcctCallback, "account"); + taos_query_a(tsMonitorConn.conn, sql, dnodeMontiorLogCallback, "account"); } void monitorSaveLog(int32_t level, const char *const format, ...) { @@ -421,14 +403,11 @@ void monitorSaveLog(int32_t level, const char *const format, ...) { sql[len++] = 0; monitorDebug("monitor:%p, save log, sql: %s", tsMonitorConn.conn, sql); - taos_query_a(tsMonitorConn.conn, sql, dnodeMontiorInsertLogCallback, "log"); + taos_query_a(tsMonitorConn.conn, sql, dnodeMontiorLogCallback, "log"); } void monitorExecuteSQL(char *sql) { if (tsMonitorConn.state != MONITOR_STATE_INITIALIZED) return; - monitorDebug("monitor:%p, execute sql: %s", tsMonitorConn.conn, sql); - - // bug while insert binary - // taos_query_a(tsMonitorConn.conn, sql, NULL, NULL); + taos_query_a(tsMonitorConn.conn, sql, dnodeMontiorLogCallback, "sql"); } From 8b1451b3eabd0c9ba2022e1811460fc652007f8e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 22 Jul 2020 10:01:54 +0000 Subject: [PATCH 15/15] scripts --- tests/script/general/alter/dnode.sim | 71 ++++++++++++++++++++++++++++ tests/script/jenkins/basic.txt | 1 + 2 files changed, 72 insertions(+) create mode 100644 tests/script/general/alter/dnode.sim diff --git a/tests/script/general/alter/dnode.sim b/tests/script/general/alter/dnode.sim new file mode 100644 index 0000000000..20ce879979 --- /dev/null +++ b/tests/script/general/alter/dnode.sim @@ -0,0 +1,71 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 2 +system sh/exec.sh -n dnode1 -s start + +sleep 3000 +sql connect + +print ======== step1 +sql alter dnode 1 resetlog +sql alter dnode 1 monitor 1 + +sleep 5000 +sql select * from log.dn +if $rows <= 0 then + return -1 +endi + +print ======== step2 + +sql alter dnode 1 resetquerycache +sql alter dnode 1 debugFlag 135 +sql alter dnode 1 debugFlag 131 +sql alter dnode 1 monitor 0 +sql alter dnode 1 debugFlag 135 +sql alter dnode 1 monitorDebugFlag 135 +sql alter dnode 1 vDebugFlag 135 +sql alter dnode 1 mDebugFlag 135 +sql alter dnode 1 cDebugFlag 135 +sql alter dnode 1 httpDebugFlag 135 +sql alter dnode 1 qDebugflag 135 +sql alter dnode 1 sdbDebugFlag 135 +sql alter dnode 1 uDebugFlag 135 +sql alter dnode 1 tsdbDebugFlag 135 +sql alter dnode 1 sDebugflag 135 +sql alter dnode 1 rpcDebugFlag 135 +sql alter dnode 1 dDebugFlag 135 +sql alter dnode 1 mqttDebugFlag 135 +sql alter dnode 1 wDebugFlag 135 +sql alter dnode 1 tmrDebugFlag 135 +sql_error alter dnode 2 wDebugFlag 135 +sql_error alter dnode 2 tmrDebugFlag 135 + +print ======== step3 +sql_error alter $hostname1 debugFlag 135 +sql_error alter $hostname1 monitorDebugFlag 135 +sql_error alter $hostname1 vDebugFlag 135 +sql_error alter $hostname1 mDebugFlag 135 +sql_error alter dnode $hostname2 debugFlag 135 +sql_error alter dnode $hostname2 monitorDebugFlag 135 +sql_error alter dnode $hostname2 vDebugFlag 135 +sql_error alter dnode $hostname2 mDebugFlag 135 +sql alter dnode $hostname1 debugFlag 135 +sql alter dnode $hostname1 monitorDebugFlag 135 +sql alter dnode $hostname1 vDebugFlag 135 +sql alter dnode $hostname1 tmrDebugFlag 131 + +print ======== step4 +sql_error sql alter dnode 1 balance 0 +sql_error sql alter dnode 1 balance vnode:1-dnode:1 +sql_error sql alter dnode 1 balance "vnode:1" +sql_error sql alter dnode 1 balance "vnode:1-dnode:1" +sql_error sql alter dnode 1 balance "dnode:1-vnode:1" +sql_error sql alter dnode 1 balance "dnode:1-" +sql_error sql alter dnode 1 balance "vnode:2-dnod" +sql alter dnode 1 balance "vnode:2-dnode:1" -x step4 +step4: + +print ======= over +system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 3b9806558e..2fd5db0165 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -3,6 +3,7 @@ cd ../../../debug; make ./test.sh -f general/alter/cached_schema_after_alter.sim ./test.sh -f general/alter/count.sim +./test.sh -f general/alter/dnode.sim ./test.sh -f general/alter/import.sim ./test.sh -f general/alter/insert1.sim ./test.sh -f general/alter/insert2.sim