diff --git a/.travis.yml b/.travis.yml index f6a3900f7a87c1af58b757590ecc07f3bfe9ce53..8c57085296041effcbbfee76e868e0eeb85c2407 100644 --- a/.travis.yml +++ b/.travis.yml @@ -146,7 +146,7 @@ matrix: branch_pattern: coverity_scan - os: linux - dist: xenial + dist: trusty language: c git: - depth: 1 @@ -156,8 +156,9 @@ matrix: packages: - build-essential - cmake + - binutils-2.26 env: - - DESC="xenial build" + - DESC="trusty/gcc-4.8/bintuils-2.26 build" before_script: - export TZ=Asia/Harbin @@ -168,7 +169,7 @@ matrix: script: - cmake .. > /dev/null - - make + - export PATH=/usr/lib/binutils-2.26/bin:$PATH && make - os: linux dist: bionic @@ -200,7 +201,7 @@ matrix: dist: bionic language: c compiler: clang - env: DESC="linux/clang build" + env: DESC="arm64 linux/clang build" git: - depth: 1 @@ -238,7 +239,7 @@ matrix: - build-essential - cmake env: - - DESC="xenial build" + - DESC="arm64 xenial build" before_script: - export TZ=Asia/Harbin diff --git a/README.md b/README.md index 36436dd549e22f58caefd82c4a9be4e8aed8d869..566b3e5c8bdf70e06bf13af644b21260b5f87164 100644 --- a/README.md +++ b/README.md @@ -33,11 +33,17 @@ To build TDengine, use [CMake](https://cmake.org/) 3.5 or higher versions in the ## Install tools -### Ubuntu & Debian: +### Ubuntu 16.04 and above & Debian: ```bash sudo apt-get install -y gcc cmake build-essential git ``` +### Ubuntu 14.04: +```bash +sudo apt-get install -y gcc cmake3 build-essential git binutils-2.26 +export PATH=/usr/lib/binutils-2.26/bin:$PATH +``` + To compile and package the JDBC driver source code, you should have a Java jdk-8 or higher and Apache Maven 2.7 or higher installed. To install openjdk-8: ```bash diff --git a/documentation20/webdocs/markdowndocs/TAOS SQL-ch.md b/documentation20/webdocs/markdowndocs/TAOS SQL-ch.md index b68f60f529d2978366f2ae7d39ff491f60b86f36..4f0e1d385313bc9d803c6ef0bd72b528669b9fd2 100644 --- a/documentation20/webdocs/markdowndocs/TAOS SQL-ch.md +++ b/documentation20/webdocs/markdowndocs/TAOS SQL-ch.md @@ -148,7 +148,7 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic SHOW TABLES [LIKE tb_name_wildcar]; ``` - 显示当前数据库下的所有数据表信息。说明:可在like中使用通配符进行名称的匹配。 通配符匹配:1)’%’ (百分号)匹配0到任意个字符;2)’_’下划线匹配一个字符。 + 显示当前数据库下的所有数据表信息。说明:可在 like 中使用通配符进行名称的匹配。 通配符匹配:1)“%”(百分号)匹配 0 到任意个字符;2)“\_”(下划线)匹配一个字符。 - **在线修改显示字符宽度** @@ -263,33 +263,33 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic - **插入一条记录,数据对应到指定的列** ```mysql - INSERT INTO tb_name (field1_name, ...) VALUES(field1_value, ...) + INSERT INTO tb_name (field1_name, ...) VALUES (field1_value, ...) ``` 向表tb_name中插入一条记录,数据对应到指定的列。SQL语句中没有出现的列,数据库将自动填充为NULL。主键(时间戳)不能为NULL。 - **插入多条记录** ```mysql - INSERT INTO tb_name VALUES (field1_value1, ...) (field1_value2, ...)...; + INSERT INTO tb_name VALUES (field1_value1, ...) (field1_value2, ...) ...; ``` 向表tb_name中插入多条记录 - **按指定的列插入多条记录** ```mysql - INSERT INTO tb_name (field1_name, ...) VALUES(field1_value1, ...) (field1_value2, ...) + INSERT INTO tb_name (field1_name, ...) VALUES (field1_value1, ...) (field1_value2, ...) ...; ``` 向表tb_name中按指定的列插入多条记录 - **向多个表插入多条记录** ```mysql - INSERT INTO tb1_name VALUES (field1_value1, ...)(field1_value2, ...)... - tb2_name VALUES (field1_value1, ...)(field1_value2, ...)...; + INSERT INTO tb1_name VALUES (field1_value1, ...) (field1_value2, ...) ... + tb2_name VALUES (field1_value1, ...) (field1_value2, ...) ...; ``` 同时向表tb1_name和tb2_name中分别插入多条记录 - **同时向多个表按列插入多条记录** ```mysql - INSERT INTO tb1_name (tb1_field1_name, ...) VALUES (field1_value1, ...) (field1_value2, ...) - tb2_name (tb2_field1_name, ...) VALUES (field1_value1, ...) (field1_value2, ...); + INSERT INTO tb1_name (tb1_field1_name, ...) VALUES (field1_value1, ...) (field1_value2, ...) ... + tb2_name (tb2_field1_name, ...) VALUES (field1_value1, ...) (field1_value2, ...) ...; ``` 同时向表tb1_name和tb2_name中按列分别插入多条记录 @@ -318,23 +318,23 @@ SELECT select_expr [, select_expr ...] ``` 说明:针对 insert 类型的 SQL 语句,我们采用的流式解析策略,在发现后面的错误之前,前面正确的部分SQL仍会执行。下面的sql中,insert语句是无效的,但是d1001仍会被创建。 ```mysql -taos> create table meters(ts timestamp, current float, voltage int, phase float) tags(location binary(30), groupId int); +taos> CREATE TABLE meters(ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS(location BINARY(30), groupId INT); Query OK, 0 row(s) affected (0.008245s) -taos> show stables; +taos> SHOW STABLES; name | created_time | columns | tags | tables | ============================================================================================ meters | 2020-08-06 17:50:27.831 | 4 | 2 | 0 | Query OK, 1 row(s) in set (0.001029s) -taos> show tables; +taos> SHOW TABLES; Query OK, 0 row(s) in set (0.000946s) -taos> insert into d1001 using meters tags('Beijing.Chaoyang', 2); +taos> INSERT INTO d1001 USING meters TAGS('Beijing.Chaoyang', 2); DB error: invalid SQL: keyword VALUES or FILE required -taos> show tables; +taos> SHOW TABLES; table_name | created_time | columns | stable_name | ====================================================================================================== d1001 | 2020-08-06 17:52:02.097 | 4 | meters | @@ -397,27 +397,41 @@ Query OK, 1 row(s) in set (0.020443s) 在使用SQL函数来进行查询过程中,部分SQL函数支持通配符操作。其中的区别在于: ```count(\*)```函数只返回一列。```first```、```last```、```last_row```函数则是返回全部列。 -``` -taos> select count(*) from d1001; +```mysql +taos> SELECT COUNT(*) FROM d1001; count(*) | ======================== 3 | Query OK, 1 row(s) in set (0.001035s) ``` -``` -taos> select first(*) from d1001; +```mysql +taos> SELECT FIRST(*) FROM d1001; first(ts) | first(current) | first(voltage) | first(phase) | ========================================================================================= 2018-10-03 14:38:05.000 | 10.30000 | 219 | 0.31000 | Query OK, 1 row(s) in set (0.000849s) ``` +##### 标签列 + +从 2.0.14 版本开始,支持在普通表的查询中指定 _标签列_,且标签列的值会与普通列的数据一起返回。 +```mysql +taos> SELECT location, groupid, current FROM d1001 LIMIT 2; + location | groupid | current | +====================================================================== + Beijing.Chaoyang | 2 | 10.30000 | + Beijing.Chaoyang | 2 | 12.60000 | +Query OK, 2 row(s) in set (0.003112s) +``` + +注意:普通表的通配符 * 中并不包含 _标签列_。 + #### 结果集列名 ```SELECT```子句中,如果不指定返回结果集合的列名,结果集列名称默认使用```SELECT```子句中的表达式名称作为列名称。此外,用户可使用```AS```来重命名返回结果集合中列的名称。例如: -``` -taos> select ts, ts as primary_key_ts from d1001; +```mysql +taos> SELECT ts, ts AS primary_key_ts FROM d1001; ts | primary_key_ts | ==================================================== 2018-10-03 14:38:05.000 | 2018-10-03 14:38:05.000 | @@ -434,53 +448,53 @@ Query OK, 3 row(s) in set (0.001191s) FROM关键字后面可以是若干个表(超级表)列表,也可以是子查询的结果。 如果没有指定用户的当前数据库,可以在表名称之前使用数据库的名称来指定表所属的数据库。例如:```power.d1001``` 方式来跨库使用表。 -``` +```mysql SELECT * FROM power.d1001; ------------------------------ -use power; +USE power; SELECT * FROM d1001; ``` #### 特殊功能 部分特殊的查询功能可以不使用FROM子句执行。获取当前所在的数据库 database() -``` -taos> SELECT database(); +```mysql +taos> SELECT DATABASE(); database() | ================================= power | Query OK, 1 row(s) in set (0.000079s) ``` 如果登录的时候没有指定默认数据库,且没有使用```use```命令切换数据,则返回NULL。 -``` -taos> SELECT database(); +```mysql +taos> SELECT DATABASE(); database() | ================================= NULL | Query OK, 1 row(s) in set (0.000184s) ``` 获取服务器和客户端版本号: -``` -taos> SELECT client_version(); +```mysql +taos> SELECT CLIENT_VERSION(); client_version() | =================== 2.0.0.0 | Query OK, 1 row(s) in set (0.000070s) -taos> SELECT server_version(); +taos> SELECT SERVER_VERSION(); server_version() | =================== 2.0.0.0 | Query OK, 1 row(s) in set (0.000077s) ``` 服务器状态检测语句。如果服务器正常,返回一个数字(例如 1)。如果服务器异常,返回error code。该SQL语法能兼容连接池对于TDengine状态的检查及第三方工具对于数据库服务器状态的检查。并可以避免出现使用了错误的心跳检测SQL语句导致的连接池连接丢失的问题。 -``` -taos> SELECT server_status(); +```mysql +taos> SELECT SERVER_STATUS(); server_status() | ================== 1 | Query OK, 1 row(s) in set (0.000074s) -taos> SELECT server_status() as status; +taos> SELECT SERVER_STATUS() AS status; status | ============== 1 | @@ -493,15 +507,15 @@ Query OK, 1 row(s) in set (0.000081s) #### 小技巧 获取一个超级表所有的子表名及相关的标签信息: -``` +```mysql SELECT TBNAME, location FROM meters; ``` 统计超级表下辖子表数量: -``` +```mysql SELECT COUNT(TBNAME) FROM meters; ``` 以上两个查询均只支持在Where条件子句中添加针对标签(TAGS)的过滤条件。例如: -``` +```mysql taos> SELECT TBNAME, location FROM meters; tbname | location | ================================================================== @@ -511,7 +525,7 @@ taos> SELECT TBNAME, location FROM meters; d1001 | Beijing.Chaoyang | Query OK, 4 row(s) in set (0.000881s) -taos> SELECT count(tbname) FROM meters WHERE groupId > 2; +taos> SELECT COUNT(tbname) FROM meters WHERE groupId > 2; count(tbname) | ======================== 2 | @@ -545,7 +559,7 @@ Query OK, 1 row(s) in set (0.001091s) - 对于下面的例子,表tb1用以下语句创建 ```mysql - CREATE TABLE tb1 (ts timestamp, col1 int, col2 float, col3 binary(50)); + CREATE TABLE tb1 (ts TIMESTAMP, col1 INT, col2 FLOAT, col3 BINARY(50)); ``` - 查询tb1刚过去的一个小时的所有记录 @@ -563,7 +577,7 @@ Query OK, 1 row(s) in set (0.001091s) - 查询col1与col2的和,并取名complex, 时间大于2018-06-01 08:00:00.000, col2大于1.2,结果输出仅仅10条记录,从第5条开始 ```mysql - SELECT (col1 + col2) AS 'complex' FROM tb1 WHERE ts > '2018-06-01 08:00:00.000' and col2 > 1.2 LIMIT 10 OFFSET 5; + SELECT (col1 + col2) AS 'complex' FROM tb1 WHERE ts > '2018-06-01 08:00:00.000' AND col2 > 1.2 LIMIT 10 OFFSET 5; ``` - 查询过去10分钟的记录,col2的值大于3.14,并且将结果输出到文件 `/home/testoutpu.csv`. @@ -590,13 +604,13 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数 示例: ```mysql - taos> SELECT COUNT(*), COUNT(VOLTAGE) FROM meters; + taos> SELECT COUNT(*), COUNT(voltage) FROM meters; count(*) | count(voltage) | ================================================ 9 | 9 | Query OK, 1 row(s) in set (0.004475s) - taos> SELECT COUNT(*), COUNT(VOLTAGE) FROM d1001; + taos> SELECT COUNT(*), COUNT(voltage) FROM d1001; count(*) | count(voltage) | ================================================ 3 | 3 | @@ -620,7 +634,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数 11.466666751 | 220.444444444 | 0.293333333 | Query OK, 1 row(s) in set (0.004135s) - taos> SELECT AVG(current), AVG(voltage), AVG(phase) from d1001; + taos> SELECT AVG(current), AVG(voltage), AVG(phase) FROM d1001; avg(current) | avg(voltage) | avg(phase) | ==================================================================================== 11.733333588 | 219.333333333 | 0.316666673 | @@ -648,13 +662,13 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数 示例: ```mysql - taos> SELECT SUM(current), SUM(voltage), SUM(phase) from meters; + taos> SELECT SUM(current), SUM(voltage), SUM(phase) FROM meters; sum(current) | sum(voltage) | sum(phase) | ================================================================================ 103.200000763 | 1984 | 2.640000001 | Query OK, 1 row(s) in set (0.001702s) - taos> SELECT SUM(current), SUM(voltage), SUM(phase) from d1001; + taos> SELECT SUM(current), SUM(voltage), SUM(phase) FROM d1001; sum(current) | sum(voltage) | sum(phase) | ================================================================================ 35.200000763 | 658 | 0.950000018 | @@ -753,7 +767,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数 功能说明:统计表/超级表中某列的值最先写入的非NULL值。 返回结果数据类型:同应用的字段。 应用字段:所有字段。 - 说明:1)如果要返回各个列的首个(时间戳最小)非NULL值,可以使用FIRST(*);2) 如果结果集中的某列全部为NULL值,则该列的返回结果也是NULL;3) 如果结果集中所有列全部为NULL值,则不返回结果。 + 说明:1)如果要返回各个列的首个(时间戳最小)非NULL值,可以使用FIRST(\*);2) 如果结果集中的某列全部为NULL值,则该列的返回结果也是NULL;3) 如果结果集中所有列全部为NULL值,则不返回结果。 示例: ```mysql @@ -777,7 +791,7 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数 功能说明:统计表/超级表中某列的值最后写入的非NULL值。 返回结果数据类型:同应用的字段。 应用字段:所有字段。 - 说明:1)如果要返回各个列的最后(时间戳最大)一个非NULL值,可以使用LAST(*);2)如果结果集中的某列全部为NULL值,则该列的返回结果也是NULL;如果结果集中所有列全部为NULL值,则不返回结果。 + 说明:1)如果要返回各个列的最后(时间戳最大)一个非NULL值,可以使用LAST(\*);2)如果结果集中的某列全部为NULL值,则该列的返回结果也是NULL;如果结果集中所有列全部为NULL值,则不返回结果。 示例: ```mysql @@ -1004,15 +1018,15 @@ SELECT function_list FROM stb_name **示例:** 智能电表的建表语句如下: ```mysql -CREATE TABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int); +CREATE TABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT); ``` 针对智能电表采集的数据,以10分钟为一个阶段,计算过去24小时的电流数据的平均值、最大值、电流的中位数、以及随着时间变化的电流走势拟合直线。如果没有计算值,用前一个非NULL值填充。 使用的查询语句如下: ```mysql -SELECT AVG(current),MAX(current),LEASTSQUARES(current, start_val, step_val), PERCENTILE(current, 50) FROM meters - WHERE TS>=NOW-1d +SELECT AVG(current), MAX(current), LEASTSQUARES(current, start_val, step_val), PERCENTILE(current, 50) FROM meters + WHERE ts>=NOW-1d INTERVAL(10m) FILL(PREV); ``` diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index fdda2139e78015910dda2009b3cefed2a13a5bb0..b4dd8d77148e4289fcd94fe195f29b858a2c8067 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -95,7 +95,7 @@ void taos_query_a(TAOS *taos, const char *sqlstr, __async_cb_func_t fp, void *pa return; } - nPrintTsc(sqlstr); + nPrintTsc("%s", sqlstr); SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { @@ -365,7 +365,7 @@ static void tscProcessAsyncError(SSchedMsg *pMsg) { void (*fp)() = pMsg->ahandle; terrno = *(int32_t*) pMsg->msg; tfree(pMsg->msg); - (*fp)(pMsg->thandle, NULL, *(int32_t*)pMsg->msg); + (*fp)(pMsg->thandle, NULL, terrno); } void tscQueueAsyncError(void(*fp), void *param, int32_t code) { diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 6dcd7beea46efccdcd7337fbe78ca96793b80990..da86b4cb1963c0cd4a535976b59f99161cff0ada 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -327,7 +327,7 @@ TAOS_RES* taos_query_c(TAOS *taos, const char *sqlstr, uint32_t sqlLen, int64_t* return NULL; } - nPrintTsc(sqlstr); + nPrintTsc("%s", sqlstr); SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); if (pSql == NULL) { diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 6b3532fef6cc290687cb8071a1a5e906eb73774b..d4f962063011910aa242c82146a5a3094da89c05 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -188,8 +188,10 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSupporter* pSupporter1, SJ tsBufFlush(output2); tsBufDestroy(pSupporter1->pTSBuf); + pSupporter1->pTSBuf = NULL; tsBufDestroy(pSupporter2->pTSBuf); - + pSupporter2->pTSBuf = NULL; + TSKEY et = taosGetTimestampUs(); tscDebug("%p input1:%" PRId64 ", input2:%" PRId64 ", final:%" PRId64 " in %d vnodes for secondary query after ts blocks " "intersecting, skey:%" PRId64 ", ekey:%" PRId64 ", numOfVnode:%d, elapsed time:%" PRId64 " us", @@ -219,12 +221,9 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, int32_t index) { assert (pSupporter->uid != 0); taosGetTmpfilePath("join-", pSupporter->path); - pSupporter->f = fopen(pSupporter->path, "w"); - // todo handle error - if (pSupporter->f == NULL) { - tscError("%p failed to create tmp file:%s, reason:%s", pSql, pSupporter->path, strerror(errno)); - } + // do NOT create file here to reduce crash generated file left issue + pSupporter->f = NULL; return pSupporter; } @@ -244,12 +243,19 @@ static void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) { tscFieldInfoClear(&pSupporter->fieldsInfo); + if (pSupporter->pTSBuf != NULL) { + tsBufDestroy(pSupporter->pTSBuf); + pSupporter->pTSBuf = NULL; + } + + unlink(pSupporter->path); + if (pSupporter->f != NULL) { fclose(pSupporter->f); - unlink(pSupporter->path); pSupporter->f = NULL; } + if (pSupporter->pVgroupTables != NULL) { taosArrayDestroy(pSupporter->pVgroupTables); pSupporter->pVgroupTables = NULL; @@ -526,6 +532,8 @@ static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSupporter* pSupporter) { tscError("%p all subquery return and query failed, global code:%s", pSqlObj, tstrerror(pSqlObj->res.code)); freeJoinSubqueryObj(pSqlObj); } + + tscDestroyJoinSupporter(pSupporter); } // update the query time range according to the join results on timestamp @@ -921,6 +929,22 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow } if (numOfRows > 0) { // write the compressed timestamp to disk file + if(pSupporter->f == NULL) { + pSupporter->f = fopen(pSupporter->path, "w"); + + if (pSupporter->f == NULL) { + tscError("%p failed to create tmp file:%s, reason:%s", pSql, pSupporter->path, strerror(errno)); + + pParentSql->res.code = TAOS_SYSTEM_ERROR(errno); + + quitAllSubquery(pParentSql, pSupporter); + + tscAsyncResultOnError(pParentSql); + + return; + } + } + fwrite(pRes->data, (size_t)pRes->numOfRows, 1, pSupporter->f); fclose(pSupporter->f); pSupporter->f = NULL; @@ -930,6 +954,9 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows); pParentSql->res.code = TAOS_SYSTEM_ERROR(errno); + + quitAllSubquery(pParentSql, pSupporter); + tscAsyncResultOnError(pParentSql); return; diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index 3e517c6fa682ce28ee2416aee3672a8628f953cf..cc8e9e86e37dea8de50d624435662c1e21ff4a94 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -181,7 +181,7 @@ void httpProcessMultiSql(HttpContext *pContext) { char *sql = httpGetCmdsString(pContext, cmd->sql); httpTraceL("context:%p, fd:%d, user:%s, process pos:%d, start query, sql:%s", pContext, pContext->fd, pContext->user, multiCmds->pos, sql); - nPrintHttp(sql); + nPrintHttp("%s", sql); taos_query_a(pContext->session->taos, sql, httpProcessMultiSqlCallBack, (void *)pContext); } @@ -329,7 +329,7 @@ void httpProcessSingleSqlCmd(HttpContext *pContext) { } httpTraceL("context:%p, fd:%d, user:%s, start query, sql:%s", pContext, pContext->fd, pContext->user, sql); - nPrintHttp(sql); + nPrintHttp("%s", sql); taos_query_a(pSession->taos, sql, httpProcessSingleSqlCallBack, (void *)pContext); } diff --git a/src/vnode/inc/vnodeRead.h b/src/vnode/inc/vnodeRead.h index f5375d6ab0c19277e2c39a987fd4428fae1885e1..0e9655f837e311fd8d7d8779ce915e5b152be288 100644 --- a/src/vnode/inc/vnodeRead.h +++ b/src/vnode/inc/vnodeRead.h @@ -27,7 +27,7 @@ void vnodeCleanupRead(void); int32_t vnodeWriteToRQueue(void *pVnode, void *pCont, int32_t contLen, int8_t qtype, void *rparam); void vnodeFreeFromRQueue(void *pVnode, SVReadMsg *pRead); int32_t vnodeProcessRead(void *pVnode, SVReadMsg *pRead); -void vnodeWaitReadCompleted(void *pVnode); +void vnodeWaitReadCompleted(SVnodeObj *pVnode); #ifdef __cplusplus } diff --git a/src/vnode/inc/vnodeWrite.h b/src/vnode/inc/vnodeWrite.h index 5238e45b81fc7955e592970fd6634199940470e0..e996bc0b06f4563b24e5ebdfc90420b9e67df003 100644 --- a/src/vnode/inc/vnodeWrite.h +++ b/src/vnode/inc/vnodeWrite.h @@ -27,7 +27,7 @@ void vnodeCleanupWrite(void); int32_t vnodeWriteToWQueue(void *pVnode, void *pHead, int32_t qtype, void *pRpcMsg); void vnodeFreeFromWQueue(void *pVnode, SVWriteMsg *pWrite); int32_t vnodeProcessWrite(void *pVnode, void *pHead, int32_t qtype, void *pRspRet); -void vnodeWaitWriteCompleted(void *pVnode); +void vnodeWaitWriteCompleted(SVnodeObj *pVnode); #ifdef __cplusplus } diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index eb43fba0798085d84c793a145b082325e6d56a15..5f6f3fe105a9f0e4933db830dc42a6b597ea2ee1 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -420,9 +420,6 @@ void vnodeCleanUp(SVnodeObj *pVnode) { vnodeSetClosingStatus(pVnode); - // release local resources only after cutting off outside connections - qQueryMgmtNotifyClosed(pVnode->qMgmt); - // stop replication module if (pVnode->sync > 0) { int64_t sync = pVnode->sync; diff --git a/src/vnode/src/vnodeRead.c b/src/vnode/src/vnodeRead.c index c864bc995bb58e81535111b1f2c7654699578930..acb1fc78f6554dc7cd4b984107a7bc1b95315b67 100644 --- a/src/vnode/src/vnodeRead.c +++ b/src/vnode/src/vnodeRead.c @@ -436,4 +436,9 @@ int32_t vnodeNotifyCurrentQhandle(void *handle, void *qhandle, int32_t vgId) { return rpcReportProgress(handle, (char *)pMsg, sizeof(SRetrieveTableMsg)); } -void vnodeWaitReadCompleted(void *pVnode) {} \ No newline at end of file +void vnodeWaitReadCompleted(SVnodeObj *pVnode) { + while (pVnode->queuedRMsg > 0) { + vTrace("vgId:%d, queued rmsg num:%d", pVnode->vgId, pVnode->queuedRMsg); + taosMsleep(10); + } +} \ No newline at end of file diff --git a/src/vnode/src/vnodeStatus.c b/src/vnode/src/vnodeStatus.c index 0bff062f09710e36c8bc94b7808d38d0e54b56c7..11f79fb372e45199626ccdb9d97c6a4065de7296 100644 --- a/src/vnode/src/vnodeStatus.c +++ b/src/vnode/src/vnodeStatus.c @@ -18,6 +18,8 @@ #include "taosmsg.h" #include "query.h" #include "vnodeStatus.h" +#include "vnodeRead.h" +#include "vnodeWrite.h" char* vnodeStatus[] = { "init", @@ -56,7 +58,7 @@ static bool vnodeSetClosingStatusImp(SVnodeObj* pVnode) { bool set = false; pthread_mutex_lock(&pVnode->statusMutex); - if (pVnode->status == TAOS_VN_STATUS_READY) { + if (pVnode->status == TAOS_VN_STATUS_READY || pVnode->status == TAOS_VN_STATUS_INIT) { pVnode->status = TAOS_VN_STATUS_CLOSING; set = true; } else { @@ -68,16 +70,18 @@ static bool vnodeSetClosingStatusImp(SVnodeObj* pVnode) { } bool vnodeSetClosingStatus(SVnodeObj* pVnode) { - if (!vnodeInInitStatus(pVnode)) { - // it may be in updating or reset state, then it shall wait - int32_t i = 0; - while (!vnodeSetClosingStatusImp(pVnode)) { - if (++i % 1000 == 0) { - sched_yield(); - } + int32_t i = 0; + while (!vnodeSetClosingStatusImp(pVnode)) { + if (++i % 1000 == 0) { + sched_yield(); } } + // release local resources only after cutting off outside connections + qQueryMgmtNotifyClosed(pVnode->qMgmt); + vnodeWaitReadCompleted(pVnode); + vnodeWaitWriteCompleted(pVnode); + return true; } @@ -96,11 +100,11 @@ bool vnodeSetUpdatingStatus(SVnodeObj* pVnode) { return set; } -bool vnodeSetResetStatus(SVnodeObj* pVnode) { +static bool vnodeSetResetStatusImp(SVnodeObj* pVnode) { bool set = false; pthread_mutex_lock(&pVnode->statusMutex); - if (pVnode->status != TAOS_VN_STATUS_CLOSING && pVnode->status != TAOS_VN_STATUS_INIT) { + if (pVnode->status == TAOS_VN_STATUS_READY || pVnode->status == TAOS_VN_STATUS_INIT) { pVnode->status = TAOS_VN_STATUS_RESET; set = true; } else { @@ -111,6 +115,22 @@ bool vnodeSetResetStatus(SVnodeObj* pVnode) { return set; } +bool vnodeSetResetStatus(SVnodeObj* pVnode) { + int32_t i = 0; + while (!vnodeSetResetStatusImp(pVnode)) { + if (++i % 1000 == 0) { + sched_yield(); + } + } + + // release local resources only after cutting off outside connections + qQueryMgmtNotifyClosed(pVnode->qMgmt); + vnodeWaitReadCompleted(pVnode); + vnodeWaitWriteCompleted(pVnode); + + return true; +} + bool vnodeInInitStatus(SVnodeObj* pVnode) { bool in = false; pthread_mutex_lock(&pVnode->statusMutex); diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index 5c2e871eb646a006484bcdc34995bda70a3ede8d..4f6ce9d2e431d4998252741bf475d1549af0eb7a 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -345,4 +345,9 @@ static int32_t vnodePerformFlowCtrl(SVWriteMsg *pWrite) { } } -void vnodeWaitWriteCompleted(void *pVnode) {} \ No newline at end of file +void vnodeWaitWriteCompleted(SVnodeObj *pVnode) { + while (pVnode->queuedWMsg > 0) { + vTrace("vgId:%d, queued wmsg num:%d", pVnode->vgId, pVnode->queuedWMsg); + taosMsleep(10); + } +} diff --git a/tests/Jenkinsfile b/tests/Jenkinsfile index 09547710c6891c4f08d594b50298b3c52e89a45b..f5b0cf1478266cc58624c5e6c89cccfb2063b4f6 100644 --- a/tests/Jenkinsfile +++ b/tests/Jenkinsfile @@ -98,7 +98,15 @@ pipeline { sh ''' cd ${WKC}/tests/examples/JDBC/JDBCDemo/ mvn clean package assembly:single -DskipTests >/dev/null - java -jar target/jdbcChecker-SNAPSHOT-jar-with-dependencies.jar -host 127.0.0.1 + java -jar target/JDBCDemo-SNAPSHOT-jar-with-dependencies.jar -host 127.0.0.1 + ''' + } + catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { + sh ''' + cd ${WKC}/src/connector/jdbc + mvn clean package -Dmaven.test.skip=true >/dev/null + cd ${WKC}/tests/examples/JDBC/JDBCDemo/ + java --class-path=../../../../src/connector/jdbc/target:$JAVA_HOME/jre/lib/ext -jar target/JDBCDemo-SNAPSHOT-jar-with-dependencies.jar -host 127.0.0.1 ''' } catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { diff --git a/tests/pytest/functions/all_null_value.py b/tests/pytest/functions/all_null_value.py index 5354b48f80dae25f7cd65fb00f90e4eeef2908cc..64791831107de4720ea43f26c250ebfb3da7195d 100644 --- a/tests/pytest/functions/all_null_value.py +++ b/tests/pytest/functions/all_null_value.py @@ -73,8 +73,8 @@ class TDTestCase: tdSql.query("select spread(c1) from st") tdSql.checkRows(0) - # tdSql.query("select stddev(c1) from st") - # tdSql.checkRows(0) + tdSql.query("select stddev(c1) from st") + tdSql.checkRows(0) tdSql.query("select sum(c1) from st") tdSql.checkRows(0) diff --git a/tests/pytest/functions/function_percentile.py b/tests/pytest/functions/function_percentile.py index e793008ce681a04111fdee29e91520fed944d05a..688e91eefa79348a88f37f3b7cb0cc1ac63152d8 100644 --- a/tests/pytest/functions/function_percentile.py +++ b/tests/pytest/functions/function_percentile.py @@ -144,8 +144,10 @@ class TDTestCase: print("apercentile result: %s" % tdSql.getData(0, 0)) # Test case for: https://jira.taosdata.com:18080/browse/TD-2609 + + # modified for : https://jira.taosdata.com:18080/browse/TD-2627 tdSql.execute("create table st(ts timestamp, k int)") - tdSql.execute("insert into st values(now, -100)") + tdSql.execute("insert into st values(now, -100)(now+1a,-99)") tdSql.query("select apercentile(k, 20) from st") tdSql.checkData(0, 0, -100.00) diff --git a/tests/pytest/query/query.py b/tests/pytest/query/query.py index 87635f86f39fb317907f689307eeefa9f3aef124..d0750ac4a5cbe631e38017e6c81746659ad16e49 100644 --- a/tests/pytest/query/query.py +++ b/tests/pytest/query/query.py @@ -44,6 +44,20 @@ class TDTestCase: tdSql.query("select * from db.st where ts='2020-05-13 10:00:00.000'") tdSql.checkRows(1) + tdSql.query("select tbname, dev from dev_001") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 'dev_001') + tdSql.checkData(0, 1, 'dev_01') + + tdSql.query("select tbname, dev, tagtype from dev_001") + tdSql.checkRows(2) + tdSql.checkData(0, 0, 'dev_001') + tdSql.checkData(0, 1, 'dev_01') + tdSql.checkData(0, 2, 1) + tdSql.checkData(1, 0, 'dev_001') + tdSql.checkData(1, 1, 'dev_01') + tdSql.checkData(1, 2, 1) + ## test case for https://jira.taosdata.com:18080/browse/TD-2488 tdSql.execute("create table m1(ts timestamp, k int) tags(a int)") tdSql.execute("create table t1 using m1 tags(1)") @@ -63,6 +77,8 @@ class TDTestCase: tdSql.checkRows(1) tdSql.checkData(0, 0, 1) + + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/query/queryInterval.py b/tests/pytest/query/queryInterval.py index 9cc468b34e6133af393d9d0d800e64d14e85c430..ce8d05ae50aa61646b20e07e9484d00559e92b49 100644 --- a/tests/pytest/query/queryInterval.py +++ b/tests/pytest/query/queryInterval.py @@ -100,7 +100,23 @@ class TDTestCase: tdSql.checkData(1, 1, None) tdSql.checkData(2, 1, None) - + # test case for https://jira.taosdata.com:18080/browse/TD-2659, https://jira.taosdata.com:18080/browse/TD-2660 + tdSql.execute("create database test3") + tdSql.execute("use test3") + tdSql.execute("create table tb(ts timestamp, c int)") + tdSql.execute("insert into tb values('2020-10-30 18:11:56.680', -111)") + tdSql.execute("insert into tb values('2020-11-19 18:11:45.773', null)") + tdSql.execute("insert into tb values('2020-12-09 18:11:17.098', null)") + tdSql.execute("insert into tb values('2020-12-29 11:00:49.412', 1)") + tdSql.execute("insert into tb values('2020-12-29 11:00:50.412', 2)") + tdSql.execute("insert into tb values('2020-12-29 11:00:52.412', 3)") + + tdSql.query("select first(ts),twa(c) from tb interval(14a)") + tdSql.checkRows(6) + + tdSql.query("select twa(c) from tb group by c") + tdSql.checkRows(4) + def stop(self): tdSql.close() diff --git a/tests/pytest/stream/history.py b/tests/pytest/stream/history.py index 890580001cf40a13ba18f6f81a3bd0faaac67991..cb8a4d598651473f907aa05a0609c9ce68c78f82 100644 --- a/tests/pytest/stream/history.py +++ b/tests/pytest/stream/history.py @@ -48,12 +48,16 @@ class TDTestCase: tdSql.execute("insert into car3 values('2019-01-01 00:00:01.389', 1)") tdSql.execute("insert into car4 values('2019-01-01 00:00:01.829', 1)") + tdSql.error("create table strm as select count(*) from cars") + tdSql.execute("create table strm as select count(*) from cars interval(4s)") tdSql.waitedQuery("select * from strm", 2, 100) tdSql.checkData(0, 1, 11) tdSql.checkData(1, 1, 2) + + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/pytest/tools/taosdemoTest.py b/tests/pytest/tools/taosdemoTest.py index 1a976aef594576ba29b928465fc38baea6dcb63e..2a4a552c8fb87f9c5a3169afcad71793462b924f 100644 --- a/tests/pytest/tools/taosdemoTest.py +++ b/tests/pytest/tools/taosdemoTest.py @@ -49,7 +49,7 @@ class TDTestCase: else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath+ "/build/bin/" - os.system("yes | %staosdemo -t %d -n %d" % (binPath,self.numberOfTables, self.numberOfRecords)) + os.system("yes | %staosdemo -t %d -n %d -x" % (binPath,self.numberOfTables, self.numberOfRecords)) tdSql.execute("use test") tdSql.query("select count(*) from meters") @@ -61,6 +61,8 @@ class TDTestCase: tdSql.query("select apercentile(f1, 1) from test.meters interval(10s)") tdSql.checkRows(11) + tdSql.error("select loc, count(loc) from test.meters") + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__)