diff --git a/.travis.yml b/.travis.yml
index 06c8b863d35de3daa26ea6d3a66cbed49ed9e125..2c3fd319117be6b60e2189ed83bc6345be767e1f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -316,218 +316,19 @@ matrix:
fi
- make > /dev/null
- - os: linux
- arch: arm64
- dist: bionic
- language: c
- compiler: gcc
- env: ENV_COVER=true
-
- git:
- - depth: 1
-
- addons:
- apt:
- packages:
- - build-essential
- - cmake
- - net-tools
- - python-pip
- - python-setuptools
- - python3-pip
- - python3-setuptools
- - lcov
- - psmisc
-
- before_script:
- - cd ${TRAVIS_BUILD_DIR}
- - mkdir debug
- - cd debug
-
- script:
- - if [ "${TRAVIS_CPU_ARCH}" == "arm64" ];
- then cmake -DCOVER=true .. -DCPUTYPE=aarch64 > /dev/null;
- else cmake -DCOVER=true .. > /dev/null;
- fi
- - make > /dev/null
-
- after_success:
- - |-
- case $TRAVIS_OS_NAME in
- linux)
- cd ${TRAVIS_BUILD_DIR}/debug
- make install > /dev/null || travis_terminate $?
- pip install numpy
- pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/
- pip3 install numpy
- pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/
- cd ${TRAVIS_BUILD_DIR}/tests
- ./test-all.sh smoke COVER
- TEST_RESULT=$?
- pkill taosd
- sleep 1
- cd ${TRAVIS_BUILD_DIR}
- lcov -d . --capture --rc lcov_branch_coverage=1 -o coverage.info
- lcov --remove coverage.info '*/tests/*' '*/test/*' '*/deps/*' '*/plugins/*' -o coverage.info
- lcov -l --rc lcov_branch_coverage=1 coverage.info || travis_terminate $?
- gem install coveralls-lcov
- # Color setting
- RED='\033[0;31m'
- GREEN='\033[1;32m'
- GREEN_DARK='\033[0;32m'
- GREEN_UNDERLINE='\033[4;32m'
- NC='\033[0m'
- coveralls-lcov coverage.info
- if [ "$?" -eq "0" ]; then
- echo -e "${GREEN} ## Uploaded to Coveralls.io! ## ${NC}"
- else
- echo -e "${RED} ## Coveralls.io not collect coverage report! ## ${NC} "
- fi
- bash <(curl -s https://codecov.io/bash) -y .codecov.yml -f coverage.info
- if [ "$?" -eq "0" ]; then
- echo -e "${GREEN} ## Uploaded to Codecov! ## ${NC} "
- else
- echo -e "${RED} ## Codecov did not collect coverage report! ## ${NC} "
- fi
- if [ "$TEST_RESULT" -ne "0" ]; then
- travis_terminate $?
- fi
- ;;
- esac
-
- - os: linux
- arch: arm64
- dist: bionic
- language: c
-
- git:
- - depth: 1
-
- compiler: gcc
- env: DESC="linux/gcc build and test"
-
- addons:
- apt:
- packages:
- - build-essential
- - cmake
- - net-tools
- - python-pip
- - python-setuptools
- - python3-pip
- - python3-setuptools
- - valgrind
- - psmisc
-
- before_script:
- - cd ${TRAVIS_BUILD_DIR}
- - mkdir debug
- - cd debug
-
- script:
- - if [ "${TRAVIS_CPU_ARCH}" == "arm64" ];
- then cmake .. -DCPUTYPE=aarch64 > /dev/null;
- else cmake .. > /dev/null;
- fi
- - make > /dev/null
-
- after_success:
- - travis_wait 20
- - |-
- case $TRAVIS_OS_NAME in
- linux)
- cd ${TRAVIS_BUILD_DIR}/debug
- make install > /dev/null || travis_terminate $?
- pip install numpy
- pip install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python2/
- pip3 install numpy
- pip3 install --user ${TRAVIS_BUILD_DIR}/src/connector/python/linux/python3/
- cd ${TRAVIS_BUILD_DIR}/tests
- ./test-all.sh smoke || travis_terminate $?
- cd ${TRAVIS_BUILD_DIR}/tests/pytest
- ./valgrind-test.sh 2>&1 > mem-error-out.log
- sleep 1
- # Color setting
- RED='\033[0;31m'
- GREEN='\033[1;32m'
- GREEN_DARK='\033[0;32m'
- GREEN_UNDERLINE='\033[4;32m'
- NC='\033[0m'
- grep 'start to execute\|ERROR SUMMARY' mem-error-out.log|grep -v 'grep'|uniq|tee uniq-mem-error-out.log
- for memError in `grep 'ERROR SUMMARY' uniq-mem-error-out.log | awk '{print $4}'`
- do
- if [ -n "$memError" ]; then
- if [ "$memError" -gt 12 ]; then
- echo -e "${RED} ## Memory errors number valgrind reports is $memError.\
- More than our threshold! ## ${NC}"
- travis_terminate $memError
- fi
- fi
- done
- grep 'start to execute\|definitely lost:' mem-error-out.log|grep -v 'grep'|uniq|tee uniq-definitely-lost-out.log
- for defiMemError in `grep 'definitely lost:' uniq-definitely-lost-out.log | awk '{print $7}'`
- do
- if [ -n "$defiMemError" ]; then
- if [ "$defiMemError" -gt 13 ]; then
- echo -e "${RED} ## Memory errors number valgrind reports \
- Definitely lost is $defiMemError. More than our threshold! ## ${NC}"
- travis_terminate $defiMemError
- fi
- fi
- done
- ;;
- esac
-
- - os: linux
- arch: arm64
- dist: bionic
- language: c
- compiler: gcc
- env: COVERITY_SCAN=true
- git:
- - depth: 1
-
- script:
- - echo "this job is for coverity scan"
-
- addons:
- coverity_scan:
- # GitHub project metadata
- # ** specific to your project **
- project:
- name: TDengine
- version: 2.x
- description: TDengine
-
- # Where email notification of build analysis results will be sent
- notification_email: sdsang@taosdata.com, slguan@taosdata.com
-
- # Commands to prepare for build_command
- # ** likely specific to your build **
- build_command_prepend: cmake . > /dev/null
-
- # The command that will be added as an argument to "cov-build" to compile your project for analysis,
- # ** likely specific to your build **
- build_command: make
-
- # Pattern to match selecting branches that will run analysis. We recommend leaving this set to 'coverity_scan'.
- # Take care in resource usage, and consider the build frequency allowances per
- # https://scan.coverity.com/faq#frequency
- branch_pattern: coverity_scan
-
- # - os: osx
- # language: c
- # compiler: clang
- # env: DESC="mac/clang build"
- # git:
- # - depth: 1
- # addons:
- # homebrew:
- # - cmake
- #
- # script:
- # - cd ${TRAVIS_BUILD_DIR}
- # - mkdir debug
- # - cd debug
- # - cmake .. > /dev/null
- # - make > /dev/null
+# - os: osx
+# language: c
+# compiler: clang
+# env: DESC="mac/clang build"
+# git:
+# - depth: 1
+# addons:
+# homebrew:
+# - cmake
+#
+# script:
+# - cd ${TRAVIS_BUILD_DIR}
+# - mkdir debug
+# - cd debug
+# - cmake .. > /dev/null
+# - make > /dev/null
diff --git a/documentation/webdocs/markdowndocs/Super Table-ch.md b/documentation/webdocs/markdowndocs/Super Table-ch.md
index 626f695c27a128e48353d4c1f674c273107b1fbc..5f592ec3393e50b25316fb29edd6abb13364e06a 100644
--- a/documentation/webdocs/markdowndocs/Super Table-ch.md
+++ b/documentation/webdocs/markdowndocs/Super Table-ch.md
@@ -53,7 +53,7 @@ STable从属于库,一个STable只属于一个库,但一个库可以有一
说明:
- 1. TAGS列总长度不能超过64k bytes;
+ 1. TAGS列总长度不能超过16k bytes;
2. TAGS列的数据类型不能是timestamp;
3. TAGS列名不能与其他列名相同;
4. TAGS列名不能为预留关键字.
diff --git a/documentation/webdocs/markdowndocs/Super Table.md b/documentation/webdocs/markdowndocs/Super Table.md
index 6c80c2097c32aba7efdd5bcfad4c129a11cdb577..2c1093a3fafd143ada150dc1d743ed49cd665d8c 100644
--- a/documentation/webdocs/markdowndocs/Super Table.md
+++ b/documentation/webdocs/markdowndocs/Super Table.md
@@ -22,7 +22,7 @@ New keyword "tags" is introduced, where tag_name is the tag name, and tag_type i
Note:
-1. The bytes of all tags together shall be less than 64k
+1. The bytes of all tags together shall be less than 16k
2. Tag's data type can not be time stamp
3. Tag name shall be different from the field name
4. Tag name shall not be the same as system keywords
diff --git a/documentation/webdocs/markdowndocs/TAOS SQL-ch.md b/documentation/webdocs/markdowndocs/TAOS SQL-ch.md
index 7fe396e9e5e156c5528267e69beffd29f06a2f18..0be39ab8e46c2836bd804563f7401d8614c04c1e 100644
--- a/documentation/webdocs/markdowndocs/TAOS SQL-ch.md
+++ b/documentation/webdocs/markdowndocs/TAOS SQL-ch.md
@@ -63,7 +63,7 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
| 3 | BIGINT | 8 | 长整型,范围 [-2^63+1, 2^63-1], -2^63用于NULL |
| 4 | FLOAT | 4 | 浮点型,有效位数6-7,范围 [-3.4E38, 3.4E38] |
| 5 | DOUBLE | 8 | 双精度浮点型,有效位数15-16,范围 [-1.7E308, 1.7E308] |
-| 6 | BINARY | 自定义 | 用于记录字符串,理论上,最长可以有65526字节,但由于每行数据最多64K字节,实际上限一般小于理论值。 binary仅支持字符串输入,字符串两端使用单引号引用,否则英文全部自动转化为小写。使用时须指定大小,如binary(20)定义了最长为20个字符的字符串,每个字符占1byte的存储空间。如果用户字符串超出20字节将会报错。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示, 即 **\’**。 |
+| 6 | BINARY | 自定义 | 用于记录字符串,理论上,最长可以有16374字节,但由于每行数据最多16K字节,实际上限一般小于理论值。 binary仅支持字符串输入,字符串两端使用单引号引用,否则英文全部自动转化为小写。使用时须指定大小,如binary(20)定义了最长为20个字符的字符串,每个字符占1byte的存储空间。如果用户字符串超出20字节将会报错。对于字符串内的单引号,可以用转义字符反斜线加单引号来表示, 即 **\’**。 |
| 7 | SMALLINT | 2 | 短整型, 范围 [-32767, 32767], -32768用于NULL |
| 8 | TINYINT | 1 | 单字节整型,范围 [-127, 127], -128用于NULL |
| 9 | BOOL | 1 | 布尔型,{true, false} |
@@ -106,7 +106,7 @@ TDengine缺省的时间戳是毫秒精度,但通过修改配置参数enableMic
```mysql
CREATE TABLE [IF NOT EXISTS] tb_name (timestamp_field_name TIMESTAMP, field1_name data_type1 [, field2_name data_type2 ...])
```
- 说明:1)表的第一个字段必须是TIMESTAMP,并且系统自动将其设为主键;2)表的每行长度不能超过64K字节;3)使用数据类型binary或nchar,需指定其最长的字节数,如binary(20),表示20字节。
+ 说明:1)表的第一个字段必须是TIMESTAMP,并且系统自动将其设为主键;2)表的每行长度不能超过16K字节;3)使用数据类型binary或nchar,需指定其最长的字节数,如binary(20),表示20字节。
- **删除数据表**
diff --git a/documentation/webdocs/markdowndocs/TAOS SQL.md b/documentation/webdocs/markdowndocs/TAOS SQL.md
index 6c7f25b8f7c342d8e38ebdcd5f674534c340f6be..72e41dbec49c29b51515e5f1dd56030cf200edab 100644
--- a/documentation/webdocs/markdowndocs/TAOS SQL.md
+++ b/documentation/webdocs/markdowndocs/TAOS SQL.md
@@ -39,7 +39,7 @@ The full list of data types is listed below. For string types of data, we will
| 6 | DOUBLE | 8 | A standard nullable double float type with 15-16 significant digits and a range of [-1.7E308, 1.7E308] |
| 7 | BOOL | 1 | A nullable boolean type, [**`true`**, **`false`**] |
| 8 | TIMESTAMP | 8 | A nullable timestamp type with the same usage as the primary column timestamp |
-| 9 | BINARY(*M*) | *M* | A nullable string type whose length is *M*, error should be threw with exceeded chars, the maximum length of *M* is 65526, but as maximum row size is 64K bytes, the actual upper limit will generally less than 65526. This type of string only supports ASCii encoded chars. |
+| 9 | BINARY(*M*) | *M* | A nullable string type whose length is *M*, error should be threw with exceeded chars, the maximum length of *M* is 16374, but as maximum row size is 16K bytes, the actual upper limit will generally less than 16374. This type of string only supports ASCii encoded chars. |
| 10 | NCHAR(*M*) | 4 * *M* | A nullable string type whose length is *M*, error should be threw with exceeded chars. The **`NCHAR`** type supports Unicode encoded chars. |
All the keywords in a SQL statement are case-insensitive, but strings values are case-sensitive and must be quoted by a pair of `'` or `"`. To quote a `'` or a `"` , you can use the escape character `\`.
@@ -86,7 +86,7 @@ All the keywords in a SQL statement are case-insensitive, but strings values are
1) The first column must be a `timestamp`, and the system will set it as the primary key.
- 2) The record size is limited to 64k bytes
+ 2) The record size is limited to 16k bytes
3) For `binary` or `nchar` data types, the length must be specified. For example, binary(20) means a binary data type with 20 bytes.
diff --git a/src/client/inc/tscLocalMerge.h b/src/client/inc/tscLocalMerge.h
index 19230e34f1f8769229d0f386a8276a6c2395b279..c073f40546c6a5ceaeabeafd3d731fdf211402df 100644
--- a/src/client/inc/tscLocalMerge.h
+++ b/src/client/inc/tscLocalMerge.h
@@ -13,8 +13,8 @@
* along with this program. If not, see .
*/
-#ifndef TDENGINE_TSCSECONARYMERGE_H
-#define TDENGINE_TSCSECONARYMERGE_H
+#ifndef TDENGINE_TSCLOCALMERGE_H
+#define TDENGINE_TSCLOCALMERGE_H
#ifdef __cplusplus
extern "C" {
@@ -27,14 +27,7 @@ extern "C" {
#include "tsclient.h"
#define MAX_NUM_OF_SUBQUERY_RETRY 3
-
-/*
- * @version 0.1
- * @date 2018/01/05
- * @author liaohj
- * management of client-side reducer for metric query
- */
-
+
struct SQLFunctionCtx;
typedef struct SLocalDataSource {
@@ -60,7 +53,6 @@ typedef struct SLocalReducer {
char * prevRowOfInput;
tFilePage * pResultBuf;
int32_t nResultBufSize;
-// char * pBufForInterpo; // intermediate buffer for interpolation
tFilePage * pTempBuffer;
struct SQLFunctionCtx *pCtx;
int32_t rowSize; // size of each intermediate result.
@@ -81,13 +73,8 @@ typedef struct SLocalReducer {
} SLocalReducer;
typedef struct SSubqueryState {
- /*
- * the number of completed retrieval subquery, once this value equals to numOfVnodes,
- * all retrieval are completed.Local merge is launched.
- */
- int32_t numOfCompleted;
- int32_t numOfTotal; // number of total sub-queries
- int32_t code; // code from subqueries
+ int32_t numOfRemain; // the number of remain unfinished subquery
+ int32_t numOfTotal; // the number of total sub-queries
uint64_t numOfRetrievedRows; // total number of points in this query
} SSubqueryState;
@@ -128,4 +115,4 @@ int32_t tscDoLocalMerge(SSqlObj *pSql);
}
#endif
-#endif // TDENGINE_TSCSECONARYMERGE_H
+#endif // TDENGINE_TSCLOCALMERGE_H
diff --git a/src/client/inc/tscSubquery.h b/src/client/inc/tscSubquery.h
index 368fe2250a37e3ef226174b80a39e63e0c990fda..82d490376aa8de18814c6cf9a1f3fbfb5be6ce75 100644
--- a/src/client/inc/tscSubquery.h
+++ b/src/client/inc/tscSubquery.h
@@ -26,11 +26,9 @@ extern "C" {
void tscFetchDatablockFromSubquery(SSqlObj* pSql);
void tscSetupOutputColumnIndex(SSqlObj* pSql);
-int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql);
void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code);
SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, int32_t index);
-void tscDestroyJoinSupporter(SJoinSupporter* pSupporter);
int32_t tscHandleMasterJoinQuery(SSqlObj* pSql);
diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h
index 581ce00a62ed4e450d1c4a546e227c0e10580549..d6562f008de5ce8a42969633d53936d19fcc07ef 100644
--- a/src/client/inc/tscUtil.h
+++ b/src/client/inc/tscUtil.h
@@ -64,7 +64,8 @@ typedef struct SJoinSupporter {
SSubqueryState* pState;
SSqlObj* pObj; // parent SqlObj
int32_t subqueryIndex; // index of sub query
- int64_t interval; // interval time
+ int64_t intervalTime; // interval time
+ int64_t slidingTime; // sliding time
SLimitVal limit; // limit info
uint64_t uid; // query meter uid
SArray* colList; // previous query information, no need to use this attribute, and the corresponding attribution
diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c
index a9a34286a85e910b85ce754100adae3cd574b74e..dc44c8ea262925f00be8cedfce4c3f909d0ae906 100644
--- a/src/client/src/TSDBJNIConnector.c
+++ b/src/client/src/TSDBJNIConnector.c
@@ -192,7 +192,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setOptions(JNIEnv
const char *tz1 = (*env)->GetStringUTFChars(env, optionValue, NULL);
if (tz1 && strlen(tz1) != 0) {
res = taos_options(TSDB_OPTION_TIMEZONE, tz1);
- jniTrace("set timezone to %s, result:%d", timezone, res);
+ jniTrace("set timezone to %s, result:%d", tz1, res);
} else {
jniTrace("input timezone is empty");
}
diff --git a/src/client/src/tscSchemaUtil.c b/src/client/src/tscSchemaUtil.c
index 0dfbf8c48701becb568123040742cc9752df97ca..da06e3e5e22c7ead926339a36e79aba4317ba757 100644
--- a/src/client/src/tscSchemaUtil.c
+++ b/src/client/src/tscSchemaUtil.c
@@ -32,7 +32,6 @@ int32_t tscGetNumOfTags(const STableMeta* pTableMeta) {
}
if (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE) {
- assert(tinfo.numOfTags >= 0);
return tinfo.numOfTags;
}
diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c
index 5a2054bbcdb500787554a7e4e0eecff14a2fc08d..da807b1964a17c27119c300dc6eb34e923a9f7ec 100644
--- a/src/client/src/tscServer.c
+++ b/src/client/src/tscServer.c
@@ -646,10 +646,6 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
size_t numOfOutput = tscSqlExprNumOfExprs(pQueryInfo);
pQueryMsg->numOfOutput = htons(numOfOutput);
- if (numOfOutput < 0) {
- tscError("%p illegal value of number of output columns in query msg: %d", pSql, numOfOutput);
- return -1;
- }
// set column list ids
size_t numOfCols = taosArrayGetSize(pQueryInfo->colList);
@@ -663,7 +659,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
if (pCol->colIndex.columnIndex >= tscGetNumOfColumns(pTableMeta) || pColSchema->type < TSDB_DATA_TYPE_BOOL ||
pColSchema->type > TSDB_DATA_TYPE_NCHAR) {
tscError("%p sid:%d uid:%" PRIu64" id:%s, column index out of range, numOfColumns:%d, index:%d, column name:%s",
- pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex,
+ pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, tscGetNumOfColumns(pTableMeta), pCol->colIndex.columnIndex,
pColSchema->name);
return TSDB_CODE_TSC_INVALID_SQL;
@@ -783,7 +779,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
(pColSchema->type < TSDB_DATA_TYPE_BOOL || pColSchema->type > TSDB_DATA_TYPE_NCHAR)) {
tscError("%p sid:%d uid:%" PRIu64 " id:%s, tag index out of range, totalCols:%d, numOfTags:%d, index:%d, column name:%s",
pSql, pTableMeta->sid, pTableMeta->uid, pTableMetaInfo->name, total, numOfTagColumns,
- pCol->colIndex, pColSchema->name);
+ pCol->colIndex.columnIndex, pColSchema->name);
return TSDB_CODE_TSC_INVALID_SQL;
}
@@ -982,7 +978,7 @@ int32_t tscBuildDropDbMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCMDropDbMsg *pDropDbMsg = (SCMDropDbMsg*)pCmd->payload;
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
- strncpy(pDropDbMsg->db, pTableMetaInfo->name, tListLen(pDropDbMsg->db));
+ tstrncpy(pDropDbMsg->db, pTableMetaInfo->name, sizeof(pDropDbMsg->db));
pDropDbMsg->ignoreNotExists = pInfo->pDCLInfo->existsCheck ? 1 : 0;
pCmd->msgType = TSDB_MSG_TYPE_CM_DROP_DB;
@@ -1052,7 +1048,7 @@ int32_t tscBuildDropAcctMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
SCMDropUserMsg *pDropMsg = (SCMDropUserMsg*)pCmd->payload;
STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, pCmd->clauseIndex, 0);
- strcpy(pDropMsg->user, pTableMetaInfo->name);
+ tstrncpy(pDropMsg->user, pTableMetaInfo->name, sizeof(pDropMsg->user));
return TSDB_CODE_SUCCESS;
}
@@ -1812,6 +1808,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) {
// todo handle out of memory case
if (pTableMetaInfo->pTableMeta == NULL) {
+ free(pTableMeta);
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
@@ -2324,6 +2321,7 @@ int tscGetSTableVgroupInfo(SSqlObj *pSql, int32_t clauseIndex) {
SQueryInfo *pNewQueryInfo = NULL;
if ((code = tscGetQueryInfoDetailSafely(&pNew->cmd, 0, &pNewQueryInfo)) != TSDB_CODE_SUCCESS) {
+ tscFreeSqlObj(pNew);
return code;
}
diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c
index 126e34704c4596ad9a8fbc80efbad38c9bdaa06c..b13e7b7ccfb50a93806ab055897f7b1b49e61b17 100644
--- a/src/client/src/tscSql.c
+++ b/src/client/src/tscSql.c
@@ -584,7 +584,7 @@ char *taos_errstr(TAOS_RES *tres) {
void taos_config(int debug, char *log_path) {
uDebugFlag = debug;
- strcpy(tsLogDir, log_path);
+ tstrncpy(tsLogDir, log_path, TSDB_FILENAME_LEN);
}
char *taos_get_server_info(TAOS *taos) {
@@ -719,6 +719,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
if (sqlLen > tsMaxSQLStringLen) {
tscError("%p sql too long", pSql);
pRes->code = TSDB_CODE_TSC_INVALID_SQL;
+ tfree(pSql);
return pRes->code;
}
@@ -727,6 +728,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) {
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
tscError("%p failed to malloc sql string buffer", pSql);
tscTrace("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
+ tfree(pSql);
return pRes->code;
}
@@ -851,6 +853,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
if (tblListLen > MAX_TABLE_NAME_LENGTH) {
tscError("%p tableNameList too long, length:%d, maximum allowed:%d", pSql, tblListLen, MAX_TABLE_NAME_LENGTH);
pRes->code = TSDB_CODE_TSC_INVALID_SQL;
+ tfree(pSql);
return pRes->code;
}
@@ -858,6 +861,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
if (str == NULL) {
pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
tscError("%p failed to malloc sql string buffer", pSql);
+ tfree(pSql);
return pRes->code;
}
@@ -873,6 +877,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) {
free(str);
if (pRes->code != TSDB_CODE_SUCCESS) {
+ tscFreeSqlObj(pSql);
return pRes->code;
}
diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c
index 7ce86dc1a41a8fab22fc47883a4fd03ced1d6678..6fc934b6c00fa72a56d95aa06378925367f40bc0 100644
--- a/src/client/src/tscStream.c
+++ b/src/client/src/tscStream.c
@@ -125,7 +125,7 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
}
// launch stream computing in a new thread
- SSchedMsg schedMsg;
+ SSchedMsg schedMsg = { 0 };
schedMsg.fp = tscProcessStreamLaunchQuery;
schedMsg.ahandle = pStream;
schedMsg.thandle = (void *)1;
@@ -239,7 +239,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
/* no resuls in the query range, retry */
// todo set retry dynamic time
int32_t retry = tsProjectExecInterval;
- tscError("%p stream:%p, retrieve no data, code:%d, retry in %" PRId64 "ms", pSql, pStream, numOfRows, retry);
+ tscError("%p stream:%p, retrieve no data, code:%d, retry in %" PRId32 "ms", pSql, pStream, numOfRows, retry);
tscSetRetryTimer(pStream, pStream->pSql, retry);
return;
@@ -250,7 +250,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
}
}
- tscTrace("%p stream:%p, query on:%s, fetch result completed, fetched rows:%d", pSql, pStream, pTableMetaInfo->name,
+ tscTrace("%p stream:%p, query on:%s, fetch result completed, fetched rows:%" PRId64, pSql, pStream, pTableMetaInfo->name,
pStream->numOfRes);
// release the metric/meter meta information reference, so data in cache can be updated
diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c
index 7e3aaf7fc534e99a87a00a3009026521986fe2da..15dc58a71320b7ebf8d83bd59ee06843ee71696c 100644
--- a/src/client/src/tscSub.c
+++ b/src/client/src/tscSub.c
@@ -291,7 +291,7 @@ static int tscLoadSubscriptionProgress(SSub* pSub) {
fclose(fp);
taosArraySort(progress, tscCompareSubscriptionProgress);
- tscTrace("subscription progress loaded, %d tables: %s", taosArrayGetSize(progress), pSub->topic);
+ tscTrace("subscription progress loaded, %z tables: %s", taosArrayGetSize(progress), pSub->topic);
return 1;
}
@@ -350,7 +350,7 @@ TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char
pSub->interval = interval;
if (fp != NULL) {
- tscTrace("asynchronize subscription, create new timer", topic);
+ tscTrace("asynchronize subscription, create new timer: %s", topic);
pSub->fp = fp;
pSub->param = param;
taosTmrReset(tscProcessSubscriptionTimer, interval, pSub, tscTmr, &pSub->pTimer);
@@ -435,7 +435,9 @@ void taos_unsubscribe(TAOS_SUB *tsub, int keepProgress) {
} else {
char path[256];
sprintf(path, "%s/subscribe/%s", tsDataDir, pSub->topic);
- remove(path);
+ if (remove(path) != 0) {
+ tscError("failed to remove progress file, topic = %s, error = %s", pSub->topic, strerror(errno));
+ }
}
tscFreeSqlObj(pSub->pSql);
diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c
index 4e02325be605a954c9695bb808e063e3b2fc9f68..b0a66701c5730a8de8b66d5b1c9a259844e57f93 100644
--- a/src/client/src/tscSubquery.c
+++ b/src/client/src/tscSubquery.c
@@ -12,12 +12,12 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
+#include "os.h"
#include "tscSubquery.h"
-#include
-#include
-#include
-#include "os.h"
+#include "qast.h"
+#include "tcompare.h"
+#include "tschemautil.h"
#include "qtsbuf.h"
#include "tscLog.h"
#include "tsclient.h"
@@ -169,7 +169,8 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in
pSupporter->subqueryIndex = index;
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
- pSupporter->interval = pQueryInfo->intervalTime;
+ pSupporter->intervalTime = pQueryInfo->intervalTime;
+ pSupporter->slidingTime = pQueryInfo->slidingTime;
pSupporter->limit = pQueryInfo->limit;
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, pSql->cmd.clauseIndex, index);
@@ -186,7 +187,7 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in
return pSupporter;
}
-void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) {
+static void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) {
if (pSupporter == NULL) {
return;
}
@@ -217,7 +218,7 @@ void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) {
* primary timestamp column , the secondary query is not necessary
*
*/
-bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
+static UNUSED_FUNC bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
size_t numOfCols = taosArrayGetSize(pQueryInfo->colList);
for (int32_t i = 0; i < numOfCols; ++i) {
@@ -233,14 +234,11 @@ bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
/*
* launch secondary stage query to fetch the result that contains timestamp in set
*/
-int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
+static int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
int32_t numOfSub = 0;
SJoinSupporter* pSupporter = NULL;
- /*
- * If the columns are not involved in the final select clause,
- * the corresponding query will not be issued.
- */
+ //If the columns are not involved in the final select clause, the corresponding query will not be issued.
for (int32_t i = 0; i < pSql->numOfSubs; ++i) {
pSupporter = pSql->pSubs[i]->param;
if (taosArrayGetSize(pSupporter->exprList) > 0) {
@@ -251,13 +249,12 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
assert(numOfSub > 0);
// scan all subquery, if one sub query has only ts, ignore it
- tscTrace("%p start to launch secondary subquery, total:%d, only:%d needs to query, others are not retrieve in "
- "select clause", pSql, pSql->numOfSubs, numOfSub);
+ tscTrace("%p start to launch secondary subquery, total:%d, only:%d needs to query", pSql, pSql->numOfSubs, numOfSub);
//the subqueries that do not actually launch the secondary query to virtual node is set as completed.
SSubqueryState* pState = pSupporter->pState;
pState->numOfTotal = pSql->numOfSubs;
- pState->numOfCompleted = (pSql->numOfSubs - numOfSub);
+ pState->numOfRemain = numOfSub;
bool success = true;
@@ -301,7 +298,8 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
// set the second stage sub query for join process
TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE);
- pQueryInfo->intervalTime = pSupporter->interval;
+ pQueryInfo->intervalTime = pSupporter->intervalTime;
+ pQueryInfo->slidingTime = pSupporter->slidingTime;
pQueryInfo->groupbyExpr = pSupporter->groupbyExpr;
tscTagCondCopy(&pQueryInfo->tagCond, &pSupporter->tagCond);
@@ -356,7 +354,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
}
size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList);
- tscTrace("%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
+ tscTrace("%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%z, colList:%z, fieldsInfo:%d, name:%s",
pSql, pNew, 0, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, taosArrayGetSize(pNewQueryInfo->exprList),
numOfCols, pNewQueryInfo->fieldsInfo.numOfOutput, pTableMetaInfo->name);
}
@@ -375,6 +373,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
if (pSql->pSubs[i] == NULL) {
continue;
}
+
tscDoQuery(pSql->pSubs[i]);
}
@@ -405,11 +404,9 @@ void freeJoinSubqueryObj(SSqlObj* pSql) {
}
static void quitAllSubquery(SSqlObj* pSqlObj, SJoinSupporter* pSupporter) {
- int32_t numOfTotal = pSupporter->pState->numOfTotal;
- int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
-
- pSqlObj->res.code = pSupporter->pState->code;
- if (finished >= numOfTotal) {
+ assert(pSupporter->pState->numOfRemain > 0);
+
+ if (atomic_sub_fetch_32(&pSupporter->pState->numOfRemain, 1) <= 0) {
tscError("%p all subquery return and query failed, global code:%d", pSqlObj, pSqlObj->res.code);
freeJoinSubqueryObj(pSqlObj);
}
@@ -421,7 +418,7 @@ static void updateQueryTimeRange(SQueryInfo* pQueryInfo, STimeWindow* win) {
pQueryInfo->window = *win;
}
-static void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj* pSql) {
+static UNUSED_FUNC void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj* pSql) {
SSqlObj* pParentSql = pSupporter->pObj;
SQueryInfo* pParentQueryInfo = tscGetQueryInfoDetail(&pParentSql->cmd, pParentSql->cmd.clauseIndex);
@@ -443,22 +440,7 @@ static void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj*
// return;
// }
// }
-
- int32_t numOfTotal = pSupporter->pState->numOfTotal;
- int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
-
- if (finished >= numOfTotal) {
- assert(finished == numOfTotal);
-
- if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
- tscTrace("%p sub:%p, numOfSub:%d, quit from further procedure due to other queries failure", pParentSql, pSql,
- pSupporter->subqueryIndex);
- freeJoinSubqueryObj(pParentSql);
- return;
- }
-
- tscTrace("%p all subqueries retrieve ts complete, do ts block intersect", pParentSql);
-
+
SJoinSupporter* p1 = pParentSql->pSubs[0]->param;
SJoinSupporter* p2 = pParentSql->pSubs[1]->param;
@@ -471,7 +453,6 @@ static void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj*
updateQueryTimeRange(pParentQueryInfo, &win);
tscLaunchSecondPhaseSubqueries(pParentSql);
}
- }
}
int32_t tscCompareTidTags(const void* p1, const void* p2) {
@@ -545,11 +526,13 @@ static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj*
tscAddSpecialColumnForSelect(pQueryInfo, 0, TSDB_FUNC_TS_COMP, &index, &colSchema, TSDB_COL_NORMAL);
// set the tags value for ts_comp function
- SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 0);
- int16_t tagColId = tscGetJoinTagColIdByUid(&pSupporter->tagCond, pTableMetaInfo->pTableMeta->uid);
- pExpr->param->i64Key = tagColId;
- pExpr->numOfParams = 1;
-
+ if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
+ SSqlExpr *pExpr = tscSqlExprGet(pQueryInfo, 0);
+ int16_t tagColId = tscGetJoinTagColIdByUid(&pSupporter->tagCond, pTableMetaInfo->pTableMeta->uid);
+ pExpr->param->i64Key = tagColId;
+ pExpr->numOfParams = 1;
+ }
+
// add the filter tag column
if (pSupporter->colList != NULL) {
size_t s = taosArrayGetSize(pSupporter->colList);
@@ -568,14 +551,14 @@ static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj*
tscTrace(
"%p subquery:%p tableIndex:%d, vgroupIndex:%d, numOfVgroups:%d, type:%d, ts_comp query to retrieve timestamps, "
- "numOfExpr:%d, colList:%d, numOfOutputFields:%d, name:%s",
+ "numOfExpr:%z, colList:%z, numOfOutputFields:%d, name:%s",
pParent, pSql, 0, pTableMetaInfo->vgroupIndex, pTableMetaInfo->vgroupList->numOfVgroups, pQueryInfo->type,
tscSqlExprNumOfExprs(pQueryInfo), numOfCols, pQueryInfo->fieldsInfo.numOfOutput, pTableMetaInfo->name);
tscProcessSql(pSql);
}
-static bool checkForIdenticalTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1, void* pSql) {
+static bool checkForDuplicateTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1, SSqlObj* pPSqlObj) {
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);// todo: tags mismatch, tags not completed
@@ -587,8 +570,8 @@ static bool checkForIdenticalTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1,
STidTags* p = (STidTags*) varDataVal(p1->pIdTagList + i * p1->tagSize);
if (doCompare(prev->tag, p->tag, pColSchema->type, pColSchema->bytes) == 0) {
- tscError("%p join tags have same value for different table, free all sub SqlObj and quit", pSql);
- p1->pState->code = TSDB_CODE_QRY_DUP_JOIN_KEY;
+ tscError("%p join tags have same value for different table, free all sub SqlObj and quit", pPSqlObj);
+ pPSqlObj->res.code = TSDB_CODE_QRY_DUP_JOIN_KEY;
return false;
}
}
@@ -596,8 +579,8 @@ static bool checkForIdenticalTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1,
return true;
}
-static void getIntersectionOfTagVal(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, SArray** s1, SArray** s2) {
- tscTrace("%p all subqueries retrieve tags complete, do tags match", pParentSql);
+static void getIntersectionOfTableTuple(SQueryInfo* pQueryInfo, SSqlObj* pParentSql, SArray** s1, SArray** s2) {
+ tscTrace("%p all subqueries retrieve complete, do tags match", pParentSql);
SJoinSupporter* p1 = pParentSql->pSubs[0]->param;
SJoinSupporter* p2 = pParentSql->pSubs[1]->param;
@@ -613,7 +596,7 @@ static void getIntersectionOfTagVal(SQueryInfo* pQueryInfo, SSqlObj* pParentSql,
*s1 = taosArrayInit(p1->num, p1->tagSize);
*s2 = taosArrayInit(p2->num, p2->tagSize);
- if (!(checkForIdenticalTagVal(pQueryInfo, p1, pParentSql) && checkForIdenticalTagVal(pQueryInfo, p2, pParentSql))) {
+ if (!(checkForDuplicateTagVal(pQueryInfo, p1, pParentSql) && checkForDuplicateTagVal(pQueryInfo, p2, pParentSql))) {
freeJoinSubqueryObj(pParentSql);
pParentSql->res.code = TSDB_CODE_QRY_DUP_JOIN_KEY;
tscQueueAsyncRes(pParentSql);
@@ -642,7 +625,7 @@ static void getIntersectionOfTagVal(SQueryInfo* pQueryInfo, SSqlObj* pParentSql,
}
}
-static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
+static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRows) {
SJoinSupporter* pSupporter = (SJoinSupporter*)param;
SSqlObj* pParentSql = pSupporter->pObj;
@@ -652,239 +635,290 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
SSqlRes* pRes = &pSql->res;
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
+ assert(TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY));
- // response of tag retrieve
- if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY)) {
- // todo handle error
-
- if (numOfRows == 0 || pRes->completed) {
- if (numOfRows > 0) {
- size_t validLen = pSupporter->tagSize * pRes->numOfRows;
+ // check for the error code firstly
+ if (taos_errno(pSql) != TSDB_CODE_SUCCESS) {
+ // todo retry if other subqueries are not failed
- size_t length = pSupporter->totalLen + validLen;
- char* tmp = realloc(pSupporter->pIdTagList, length);
- assert(tmp != NULL);
- pSupporter->pIdTagList = tmp;
+ assert(numOfRows < 0 && numOfRows == taos_errno(pSql));
+ tscError("%p sub query failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex);
- memcpy(pSupporter->pIdTagList + pSupporter->totalLen,pRes->data, validLen);
- pSupporter->totalLen += validLen;
- pSupporter->num += pRes->numOfRows;
- }
+ pParentSql->res.code = numOfRows;
+ quitAllSubquery(pParentSql, pSupporter);
- // tuples have been retrieved to client, try tuples from the next vnode
- if (hasMoreVnodesToTry(pSql)) {
- STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
+ tscQueueAsyncRes(pParentSql);
+ return;
+ }
- int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups;
- pTableMetaInfo->vgroupIndex += 1;
- assert(pTableMetaInfo->vgroupIndex < totalVgroups);
+ // keep the results in memory
+ if (numOfRows > 0) {
+ size_t validLen = pSupporter->tagSize * pRes->numOfRows;
+ size_t length = pSupporter->totalLen + validLen;
- tscTrace("%p tid_tag from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d",
- pSql, pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups,
- pSupporter->num);
+ // todo handle memory error
+ char* tmp = realloc(pSupporter->pIdTagList, length);
+ if (tmp == NULL) {
+ tscError("%p failed to malloc memory", pSql);
- pCmd->command = TSDB_SQL_SELECT;
- tscResetForNextRetrieve(&pSql->res);
+ pParentSql->res.code = TAOS_SYSTEM_ERROR(errno);
+ quitAllSubquery(pParentSql, pSupporter);
- // set the callback function
- pSql->fp = tscJoinQueryCallback;
- tscProcessSql(pSql);
- return;
- }
+ tscQueueAsyncRes(pParentSql);
+ return;
+ }
- int32_t numOfTotal = pSupporter->pState->numOfTotal;
- int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
- if (finished < numOfTotal) {
- return;
- }
+ pSupporter->pIdTagList = tmp;
- // all subquery are returned, start to compare the tags
- assert(finished == numOfTotal);
+ memcpy(pSupporter->pIdTagList + pSupporter->totalLen, pRes->data, validLen);
+ pSupporter->totalLen += validLen;
+ pSupporter->num += pRes->numOfRows;
- SArray *s1 = NULL, *s2 = NULL;
- getIntersectionOfTagVal(pQueryInfo, pParentSql, &s1, &s2);
+ // query not completed, continue to retrieve tid + tag tuples
+ if (!pRes->completed) {
+ taos_fetch_rows_a(tres, tidTagRetrieveCallback, param);
+ return;
+ }
+ }
- if (taosArrayGetSize(s1) == 0 || taosArrayGetSize(s2) == 0) { // no results,return.
- tscTrace("%p free all sub SqlObj and quit", pParentSql);
- freeJoinSubqueryObj(pParentSql);
- return;
- } else {
- SSqlCmd* pSubCmd1 = &pParentSql->pSubs[0]->cmd;
- SSqlCmd* pSubCmd2 = &pParentSql->pSubs[1]->cmd;
+ // data in current vnode has all returned to client, try next vnode if exits
+ // tuples have been retrieved to client, try tuples from the next vnode
+ if (hasMoreVnodesToTry(pSql)) {
+ STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
- SQueryInfo* pQueryInfo1 = tscGetQueryInfoDetail(pSubCmd1, 0);
- STableMetaInfo* pTableMetaInfo1 = tscGetMetaInfo(pQueryInfo1, 0);
- tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo1, s1);
+ int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups;
+ pTableMetaInfo->vgroupIndex += 1;
+ assert(pTableMetaInfo->vgroupIndex < totalVgroups);
- SQueryInfo* pQueryInfo2 = tscGetQueryInfoDetail(pSubCmd2, 0);
- STableMetaInfo* pTableMetaInfo2 = tscGetMetaInfo(pQueryInfo2, 0);
- tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo2, s2);
+ tscTrace("%p tid_tag from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d",
+ pSql, pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups, pSupporter->num);
- pSupporter->pState->numOfCompleted = 0;
- pSupporter->pState->code = 0;
- pSupporter->pState->numOfTotal = 2;
+ pCmd->command = TSDB_SQL_SELECT;
+ tscResetForNextRetrieve(&pSql->res);
- for (int32_t m = 0; m < pParentSql->numOfSubs; ++m) {
- SSqlObj* psub = pParentSql->pSubs[m];
- issueTSCompQuery(psub, psub->param, pParentSql);
- }
- }
+ // set the callback function
+ pSql->fp = tscJoinQueryCallback;
+ tscProcessSql(pSql);
+ return;
+ }
- } else {
- if (numOfRows < 0) { // error
- pSupporter->pState->code = numOfRows;
- quitAllSubquery(pParentSql, pSupporter);
+ // no data exists in next vnode, mark the query completed
+ // only when there is no subquery exits any more, proceeds to get the intersect of the tuple sets.
+ if (atomic_sub_fetch_32(&pSupporter->pState->numOfRemain, 1) > 0) {
+ return;
+ }
- pParentSql->res.code = numOfRows;
- tscQueueAsyncRes(pParentSql);
- return;
- }
+ SArray *s1 = NULL, *s2 = NULL;
+ getIntersectionOfTableTuple(pQueryInfo, pParentSql, &s1, &s2);
+ if (taosArrayGetSize(s1) == 0 || taosArrayGetSize(s2) == 0) { // no results,return.
+ tscTrace("%p free all sub SqlObj and quit", pParentSql);
+ freeJoinSubqueryObj(pParentSql);
- size_t length = pSupporter->totalLen + pRes->rspLen;
- assert(length > 0);
+ } else {
+ // proceed to for ts_comp query
+ SSqlCmd* pSubCmd1 = &pParentSql->pSubs[0]->cmd;
+ SSqlCmd* pSubCmd2 = &pParentSql->pSubs[1]->cmd;
- char* tmp = realloc(pSupporter->pIdTagList, length);
- assert(tmp != NULL);
+ SQueryInfo* pQueryInfo1 = tscGetQueryInfoDetail(pSubCmd1, 0);
+ STableMetaInfo* pTableMetaInfo1 = tscGetMetaInfo(pQueryInfo1, 0);
+ tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo1, s1);
- pSupporter->pIdTagList = tmp;
+ SQueryInfo* pQueryInfo2 = tscGetQueryInfoDetail(pSubCmd2, 0);
+ STableMetaInfo* pTableMetaInfo2 = tscGetMetaInfo(pQueryInfo2, 0);
+ tscBuildVgroupTableInfo(pParentSql, pTableMetaInfo2, s2);
- memcpy(pSupporter->pIdTagList, pRes->data, pRes->rspLen);
- pSupporter->totalLen += pRes->rspLen;
- pSupporter->num += pRes->numOfRows;
+ pSupporter->pState->numOfTotal = 2;
+ pSupporter->pState->numOfRemain = pSupporter->pState->numOfTotal;
- // continue retrieve data from vnode
- taos_fetch_rows_a(tres, joinRetrieveCallback, param);
+ for (int32_t m = 0; m < pParentSql->numOfSubs; ++m) {
+ SSqlObj* sub = pParentSql->pSubs[m];
+ issueTSCompQuery(sub, sub->param, pParentSql);
}
-
- return;
}
- if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE)) {
- if (numOfRows < 0) {
- tscError("%p sub query failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex);
- pSupporter->pState->code = numOfRows;
- quitAllSubquery(pParentSql, pSupporter);
- return;
- }
+ taosArrayDestroy(s1);
+ taosArrayDestroy(s2);
+}
- if (numOfRows > 0) { // write the compressed timestamp to disk file
- fwrite(pRes->data, pRes->numOfRows, 1, pSupporter->f);
- fclose(pSupporter->f);
- pSupporter->f = NULL;
+static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRows) {
+ SJoinSupporter* pSupporter = (SJoinSupporter*)param;
- STSBuf* pBuf = tsBufCreateFromFile(pSupporter->path, true);
- if (pBuf == NULL) { // in error process, close the fd
- tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows);
+ SSqlObj* pParentSql = pSupporter->pObj;
- pSupporter->pState->code = TSDB_CODE_TSC_APP_ERROR; // todo set the informative code
- quitAllSubquery(pParentSql, pSupporter);
- return;
- }
+ SSqlObj* pSql = (SSqlObj*)tres;
+ SSqlCmd* pCmd = &pSql->cmd;
+ SSqlRes* pRes = &pSql->res;
- if (pSupporter->pTSBuf == NULL) {
- tscTrace("%p create tmp file for ts block:%s, size:%d bytes", pSql, pBuf->path, numOfRows);
- pSupporter->pTSBuf = pBuf;
- } else {
- assert(pQueryInfo->numOfTables == 1); // for subquery, only one
- STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
+ SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
+ assert(!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE));
- tsBufMerge(pSupporter->pTSBuf, pBuf, pTableMetaInfo->vgroupIndex);
- tsBufDestory(pBuf);
- }
- }
+ // check for the error code firstly
+ if (taos_errno(pSql) != TSDB_CODE_SUCCESS) {
+ // todo retry if other subqueries are not failed yet
+ assert(numOfRows < 0 && numOfRows == taos_errno(pSql));
+ tscError("%p sub query failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex);
- if (pRes->completed) {
- if (hasMoreVnodesToTry(pSql)) {
- STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
+ pParentSql->res.code = numOfRows;
+ quitAllSubquery(pParentSql, pSupporter);
- int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups;
- pTableMetaInfo->vgroupIndex += 1;
- assert(pTableMetaInfo->vgroupIndex < totalVgroups);
+ tscQueueAsyncRes(pParentSql);
+ return;
+ }
- tscTrace("%p results from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d",
- pSql, pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups,
- pRes->numOfClauseTotal);
+ if (numOfRows > 0) { // write the compressed timestamp to disk file
+ fwrite(pRes->data, pRes->numOfRows, 1, pSupporter->f);
+ fclose(pSupporter->f);
+ pSupporter->f = NULL;
- pCmd->command = TSDB_SQL_SELECT;
- tscResetForNextRetrieve(&pSql->res);
+ STSBuf* pBuf = tsBufCreateFromFile(pSupporter->path, true);
+ if (pBuf == NULL) { // in error process, close the fd
+ tscError("%p invalid ts comp file from vnode, abort subquery, file size:%d", pSql, numOfRows);
- assert(pSupporter->f == NULL);
- getTmpfilePath("ts-join", pSupporter->path);
- pSupporter->f = fopen(pSupporter->path, "w");
- pRes->row = pRes->numOfRows;
+ pParentSql->res.code = TAOS_SYSTEM_ERROR(errno);
+ tscQueueAsyncRes(pParentSql);
- // set the callback function
- pSql->fp = tscJoinQueryCallback;
- tscProcessSql(pSql);
- return;
- } else {
- tSIntersectionAndLaunchSecQuery(pSupporter, pSql);
- }
+ return;
+ }
+
+ if (pSupporter->pTSBuf == NULL) {
+ tscTrace("%p create tmp file for ts block:%s, size:%d bytes", pSql, pBuf->path, numOfRows);
+ pSupporter->pTSBuf = pBuf;
+ } else {
+ assert(pQueryInfo->numOfTables == 1); // for subquery, only one
+ STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
+
+ tsBufMerge(pSupporter->pTSBuf, pBuf, pTableMetaInfo->vgroupIndex);
+ tsBufDestory(pBuf);
+ }
- } else { // open a new file to save the incoming result
+ // continue to retrieve ts-comp data from vnode
+ if (!pRes->completed) {
getTmpfilePath("ts-join", pSupporter->path);
pSupporter->f = fopen(pSupporter->path, "w");
pRes->row = pRes->numOfRows;
- taos_fetch_rows_a(tres, joinRetrieveCallback, param);
- }
- } else { // secondary stage retrieve, driven by taos_fetch_row or other functions
- if (numOfRows < 0) {
- pSupporter->pState->code = numOfRows;
- tscError("%p retrieve failed, code:%s, index:%d", pSql, tstrerror(numOfRows), pSupporter->subqueryIndex);
+ taos_fetch_rows_a(tres, tsCompRetrieveCallback, param);
+ return;
}
+ }
- if (numOfRows >= 0) {
- pRes->numOfTotal += pRes->numOfRows;
- }
+ if (hasMoreVnodesToTry(pSql)) {
+ STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
- if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && numOfRows == 0) {
- STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
- assert(pQueryInfo->numOfTables == 1);
+ int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups;
+ pTableMetaInfo->vgroupIndex += 1;
+ assert(pTableMetaInfo->vgroupIndex < totalVgroups);
- // for projection query, need to try next vnode if current vnode is exhausted
- if ((++pTableMetaInfo->vgroupIndex) < pTableMetaInfo->vgroupList->numOfVgroups) {
- pSupporter->pState->numOfCompleted = 0;
- pSupporter->pState->numOfTotal = 1;
+ tscTrace("%p results from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d",
+ pSql, pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups,
+ pRes->numOfClauseTotal);
- pSql->cmd.command = TSDB_SQL_SELECT;
- pSql->fp = tscJoinQueryCallback;
- tscProcessSql(pSql);
+ pCmd->command = TSDB_SQL_SELECT;
+ tscResetForNextRetrieve(&pSql->res);
- return;
- }
- }
+ assert(pSupporter->f == NULL);
+ getTmpfilePath("ts-join", pSupporter->path);
+
+ // TODO check for failure
+ pSupporter->f = fopen(pSupporter->path, "w");
+ pRes->row = pRes->numOfRows;
+
+ // set the callback function
+ pSql->fp = tscJoinQueryCallback;
+ tscProcessSql(pSql);
+ return;
+ }
- int32_t numOfTotal = pSupporter->pState->numOfTotal;
- int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
+ if (atomic_sub_fetch_32(&pSupporter->pState->numOfRemain, 1) > 0) {
+ return;
+ }
- if (finished >= numOfTotal) {
- assert(finished == numOfTotal);
- tscTrace("%p all %d secondary subquery retrieves completed, global code:%d", tres, numOfTotal,
- pParentSql->res.code);
+ tscTrace("%p all subquery retrieve ts complete, do ts block intersect", pParentSql);
- if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
- pParentSql->res.code = pSupporter->pState->code;
- freeJoinSubqueryObj(pParentSql);
- pParentSql->res.completed = true;
- }
+ // proceeds to launched secondary query to retrieve final data
+ SJoinSupporter* p1 = pParentSql->pSubs[0]->param;
+ SJoinSupporter* p2 = pParentSql->pSubs[1]->param;
- // update the records for each subquery in parent sql object.
- for (int32_t i = 0; i < pParentSql->numOfSubs; ++i) {
- if (pParentSql->pSubs[i] == NULL) {
- continue;
- }
+ STimeWindow win = TSWINDOW_INITIALIZER;
+ int64_t num = doTSBlockIntersect(pParentSql, p1, p2, &win);
+ if (num <= 0) { // no result during ts intersect
+ tscTrace("%p no results generated in ts intersection, free all sub SqlObj and quit", pParentSql);
+ freeJoinSubqueryObj(pParentSql);
+
+ return;
+ }
- SSqlRes* pRes1 = &pParentSql->pSubs[i]->res;
- pRes1->numOfClauseTotal += pRes1->numOfRows;
- }
+ // launch the query the retrieve actual results from vnode along with the filtered timestamp
+ SQueryInfo* pPQueryInfo = tscGetQueryInfoDetail(&pParentSql->cmd, pParentSql->cmd.clauseIndex);
+ updateQueryTimeRange(pPQueryInfo, &win);
+ tscLaunchSecondPhaseSubqueries(pParentSql);
+}
- // data has retrieved to client, build the join results
- tscBuildResFromSubqueries(pParentSql);
- } else {
- tscTrace("%p sub:%p completed, completed:%d, total:%d", pParentSql, tres, finished, numOfTotal);
+static void joinRetrieveFinalResCallback(void* param, TAOS_RES* tres, int numOfRows) {
+ SJoinSupporter* pSupporter = (SJoinSupporter*)param;
+
+ SSqlObj* pParentSql = pSupporter->pObj;
+ SSubqueryState* pState = pSupporter->pState;
+
+ SSqlObj* pSql = (SSqlObj*)tres;
+ SSqlCmd* pCmd = &pSql->cmd;
+ SSqlRes* pRes = &pSql->res;
+
+ SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
+
+ // TODO put to async res?
+ if (taos_errno(pSql) != TSDB_CODE_SUCCESS) {
+ assert(numOfRows == taos_errno(pSql));
+
+ pParentSql->res.code = numOfRows;
+ tscError("%p retrieve failed, index:%d, code:%s", pSql, pSupporter->subqueryIndex, tstrerror(numOfRows));
+ }
+
+ if (numOfRows >= 0) {
+ pRes->numOfTotal += pRes->numOfRows;
+ }
+
+ if (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && numOfRows == 0) {
+ STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
+ assert(pQueryInfo->numOfTables == 1);
+
+ // for projection query, need to try next vnode if current vnode is exhausted
+ if ((++pTableMetaInfo->vgroupIndex) < pTableMetaInfo->vgroupList->numOfVgroups) {
+ pState->numOfRemain = 1;
+ pState->numOfTotal = 1;
+
+ pSql->cmd.command = TSDB_SQL_SELECT;
+ pSql->fp = tscJoinQueryCallback;
+ tscProcessSql(pSql);
+
+ return;
+ }
+ }
+
+ if (atomic_sub_fetch_32(&pState->numOfRemain, 1) > 0) {
+ tscTrace("%p sub:%p completed, remain:%d, total:%d", pParentSql, tres, pState->numOfRemain, pState->numOfTotal);
+ return;
+ }
+
+ tscTrace("%p all %d secondary subqueries retrieval completed, code:%d", tres, pState->numOfTotal, pParentSql->res.code);
+
+ if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
+ freeJoinSubqueryObj(pParentSql);
+ pParentSql->res.completed = true;
+ }
+
+ // update the records for each subquery in parent sql object.
+ for (int32_t i = 0; i < pParentSql->numOfSubs; ++i) {
+ if (pParentSql->pSubs[i] == NULL) {
+ continue;
}
+
+ SSqlRes* pRes1 = &pParentSql->pSubs[i]->res;
+ pRes1->numOfClauseTotal += pRes1->numOfRows;
}
+
+ // data has retrieved to client, build the join results
+ tscBuildResFromSubqueries(pParentSql);
}
static SJoinSupporter* tscUpdateSubqueryStatus(SSqlObj* pSql, int32_t numOfFetch) {
@@ -902,7 +936,7 @@ static SJoinSupporter* tscUpdateSubqueryStatus(SSqlObj* pSql, int32_t numOfFetch
}
pState->numOfTotal = pSql->numOfSubs;
- pState->numOfCompleted = pSql->numOfSubs - numOfFetch;
+ pState->numOfRemain = numOfFetch;
return pSupporter;
}
@@ -990,7 +1024,7 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
pSupporter->subqueryIndex, pTableMetaInfo->vgroupIndex);
tscResetForNextRetrieve(pRes1);
- pSql1->fp = joinRetrieveCallback;
+ pSql1->fp = joinRetrieveFinalResCallback;
if (pCmd1->command < TSDB_SQL_LOCAL) {
pCmd1->command = (pCmd1->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH;
@@ -1008,8 +1042,9 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
tscTrace("%p all subquery response, retrieve data", pSql);
+ // the column transfer support struct has been built
if (pRes->pColumnIndex != NULL) {
- return; // the column transfer support struct has been built
+ return;
}
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
@@ -1045,68 +1080,76 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
SSqlObj* pSql = (SSqlObj*)tres;
-
+
SJoinSupporter* pSupporter = (SJoinSupporter*)param;
-
+ SSqlObj* pParentSql = pSupporter->pObj;
+
// There is only one subquery and table for each subquery.
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
assert(pQueryInfo->numOfTables == 1 && pSql->cmd.numOfClause == 1);
-
- if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE)) {
- if (code != TSDB_CODE_SUCCESS) { // direct call joinRetrieveCallback and set the error code
- joinRetrieveCallback(param, pSql, code);
- } else { // first stage query, continue to retrieve compressed time stamp data
- pSql->fp = joinRetrieveCallback;
- pSql->cmd.command = TSDB_SQL_FETCH;
- tscProcessSql(pSql);
- }
- } else { // second stage join subquery
- SSqlObj* pParentSql = pSupporter->pObj;
+ // retrieve actual query results from vnode during the second stage join subquery
+ if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
+ tscError("%p abort query due to other subquery failure. code:%d, global code:%d", pSql, code, pParentSql->res.code);
+ quitAllSubquery(pParentSql, pSupporter);
+ tscQueueAsyncRes(pParentSql);
- if (pSupporter->pState->code != TSDB_CODE_SUCCESS) {
- tscError("%p abort query due to other subquery failure. code:%d, global code:%d", pSql, code,
- pSupporter->pState->code);
- quitAllSubquery(pParentSql, pSupporter);
+ return;
+ }
- return;
- }
+ // TODO here retry is required, not directly returns to client
+ if (taos_errno(pSql) != TSDB_CODE_SUCCESS) {
+ assert(taos_errno(pSql) == code);
- if (code != TSDB_CODE_SUCCESS) {
- tscError("%p sub query failed, code:%s, set global code:%s, index:%d", pSql, tstrerror(code), tstrerror(code),
- pSupporter->subqueryIndex);
-
- pSupporter->pState->code = code;
- quitAllSubquery(pParentSql, pSupporter);
+ tscError("%p abort query, code:%d, global code:%d", pSql, code, pParentSql->res.code);
+ pParentSql->res.code = code;
+
+ quitAllSubquery(pParentSql, pSupporter);
+ tscQueueAsyncRes(pParentSql);
+
+ return;
+ }
+
+ // retrieve tuples from vnode
+ if (TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY)) {
+ pSql->fp = tidTagRetrieveCallback;
+ pSql->cmd.command = TSDB_SQL_FETCH;
+ tscProcessSql(pSql);
+ return;
+ }
+
+ // retrieve ts_comp info from vnode
+ if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE)) {
+ pSql->fp = tsCompRetrieveCallback;
+ pSql->cmd.command = TSDB_SQL_FETCH;
+ tscProcessSql(pSql);
+ return;
+ }
+
+ // wait for the other subqueries response from vnode
+ if (atomic_sub_fetch_32(&pSupporter->pState->numOfRemain, 1) > 0) {
+ return;
+ }
+
+ tscSetupOutputColumnIndex(pParentSql);
+ STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
+
+ /**
+ * if the query is a continue query (vgroupIndex > 0 for projection query) for next vnode, do the retrieval of
+ * data instead of returning to its invoker
+ */
+ if (pTableMetaInfo->vgroupIndex > 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) {
+ pSupporter->pState->numOfRemain = pSupporter->pState->numOfTotal; // reset the record value
+
+ pSql->fp = joinRetrieveFinalResCallback; // continue retrieve data
+ pSql->cmd.command = TSDB_SQL_FETCH;
+ tscProcessSql(pSql);
+ } else { // first retrieve from vnode during the secondary stage sub-query
+ // set the command flag must be after the semaphore been correctly set.
+ if (pParentSql->res.code == TSDB_CODE_SUCCESS) {
+ (*pParentSql->fp)(pParentSql->param, pParentSql, 0);
} else {
- int32_t numOfTotal = pSupporter->pState->numOfTotal;
- int32_t finished = atomic_add_fetch_32(&pSupporter->pState->numOfCompleted, 1);
-
- if (finished >= numOfTotal) {
- assert(finished == numOfTotal);
-
- tscSetupOutputColumnIndex(pParentSql);
- STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
-
- /**
- * if the query is a continue query (vgroupIndex > 0 for projection query) for next vnode, do the retrieval of
- * data instead of returning to its invoker
- */
- if (pTableMetaInfo->vgroupIndex > 0 && tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0)) {
- pSupporter->pState->numOfCompleted = 0; // reset the record value
-
- pSql->fp = joinRetrieveCallback; // continue retrieve data
- pSql->cmd.command = TSDB_SQL_FETCH;
- tscProcessSql(pSql);
- } else { // first retrieve from vnode during the secondary stage sub-query
- // set the command flag must be after the semaphore been correctly set.
- if (pParentSql->res.code == TSDB_CODE_SUCCESS) {
- (*pParentSql->fp)(pParentSql->param, pParentSql, 0);
- } else {
- tscQueueAsyncRes(pParentSql);
- }
- }
- }
+ tscQueueAsyncRes(pParentSql);
}
}
}
@@ -1202,7 +1245,7 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter
tscTrace(
"%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, transfer to tid_tag query to retrieve (tableId, tags), "
- "exprInfo:%d, colList:%d, fieldsInfo:%d, tagIndex:%d, name:%s",
+ "exprInfo:%z, colList:%z, fieldsInfo:%d, tagIndex:%d, name:%s",
pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo),
numOfCols, pNewQueryInfo->fieldsInfo.numOfOutput, index.columnIndex, pNewQueryInfo->pTableMetaInfo[0]->name);
} else {
@@ -1236,8 +1279,8 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter
size_t numOfCols = taosArrayGetSize(pNewQueryInfo->colList);
tscTrace(
- "%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%d, transfer to ts_comp query to retrieve timestamps, "
- "exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s",
+ "%p subquery:%p tableIndex:%d, vgroupIndex:%d, type:%u, transfer to ts_comp query to retrieve timestamps, "
+ "exprInfo:%z, colList:%z, fieldsInfo:%d, name:%s",
pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo),
numOfCols, pNewQueryInfo->fieldsInfo.numOfOutput, pNewQueryInfo->pTableMetaInfo[0]->name);
}
@@ -1257,14 +1300,15 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) {
SSubqueryState *pState = calloc(1, sizeof(SSubqueryState));
pState->numOfTotal = pQueryInfo->numOfTables;
-
+ pState->numOfRemain = pState->numOfTotal;
+
tscTrace("%p start launch subquery, total:%d", pSql, pQueryInfo->numOfTables);
for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) {
SJoinSupporter *pSupporter = tscCreateJoinSupporter(pSql, pState, i);
if (pSupporter == NULL) { // failed to create support struct, abort current query
tscError("%p tableIndex:%d, failed to allocate join support object, abort further query", pSql, i);
- pState->numOfCompleted = pQueryInfo->numOfTables - i - 1;
+ pState->numOfRemain = i;
pSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
return pSql->res.code;
@@ -1342,6 +1386,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
tscTrace("%p retrieved query data from %d vnode(s)", pSql, pSql->numOfSubs);
SSubqueryState *pState = calloc(1, sizeof(SSubqueryState));
pState->numOfTotal = pSql->numOfSubs;
+ pState->numOfRemain = pSql->numOfSubs;
+
pRes->code = TSDB_CODE_SUCCESS;
int32_t i = 0;
@@ -1436,7 +1482,7 @@ static void tscFreeSubSqlObj(SRetrieveSupport *trsupport, SSqlObj *pSql) {
static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfRows);
static void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numOfRows);
-static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES *tres, int32_t errCode) {
+static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES *tres, int32_t code) {
// set no disk space error info
#ifdef WINDOWS
LPVOID lpMsgBuf;
@@ -1448,44 +1494,44 @@ static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES
#else
tscError("sub:%p failed to flush data to disk:reason:%s", tres, strerror(errno));
#endif
-
- trsupport->pState->code = -errCode;
+
+ SSqlObj* pParentSql = trsupport->pParentSqlObj;
+
+ pParentSql->res.code = code;
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY;
pthread_mutex_unlock(&trsupport->queryMutex);
- tscHandleSubqueryError(trsupport, tres, trsupport->pState->code);
+ tscHandleSubqueryError(trsupport, tres, pParentSql->res.code);
}
void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numOfRows) {
- SSqlObj *pPObj = trsupport->pParentSqlObj;
+ SSqlObj *pParentSql = trsupport->pParentSqlObj;
int32_t subqueryIndex = trsupport->subqueryIndex;
assert(pSql != NULL);
SSubqueryState* pState = trsupport->pState;
- assert(pState->numOfCompleted < pState->numOfTotal && pState->numOfCompleted >= 0 &&
- pPObj->numOfSubs == pState->numOfTotal);
+ assert(pState->numOfRemain <= pState->numOfTotal && pState->numOfRemain >= 0 && pParentSql->numOfSubs == pState->numOfTotal);
// retrieved in subquery failed. OR query cancelled in retrieve phase.
- if (pState->code == TSDB_CODE_SUCCESS && pPObj->res.code != TSDB_CODE_SUCCESS) {
- pState->code = pPObj->res.code;
-
+ if (taos_errno(pSql) == TSDB_CODE_SUCCESS && pParentSql->res.code != TSDB_CODE_SUCCESS) {
+
/*
* kill current sub-query connection, which may retrieve data from vnodes;
* Here we get: pPObj->res.code == TSDB_CODE_TSC_QUERY_CANCELLED
*/
pSql->res.numOfRows = 0;
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY; // disable retry efforts
- tscTrace("%p query is cancelled, sub:%p, orderOfSub:%d abort retrieve, code:%d", trsupport->pParentSqlObj, pSql,
- subqueryIndex, pState->code);
+ tscTrace("%p query is cancelled, sub:%p, orderOfSub:%d abort retrieve, code:%d", pParentSql, pSql,
+ subqueryIndex, pParentSql->res.code);
}
if (numOfRows >= 0) { // current query is successful, but other sub query failed, still abort current query.
- tscTrace("%p sub:%p retrieve numOfRows:%d,orderOfSub:%d", pPObj, pSql, numOfRows, subqueryIndex);
- tscError("%p sub:%p abort further retrieval due to other queries failure,orderOfSub:%d,code:%d", pPObj, pSql,
- subqueryIndex, pState->code);
+ tscTrace("%p sub:%p retrieve numOfRows:%d,orderOfSub:%d", pParentSql, pSql, numOfRows, subqueryIndex);
+ tscError("%p sub:%p abort further retrieval due to other queries failure,orderOfSub:%d,code:%d", pParentSql, pSql,
+ subqueryIndex, pParentSql->res.code);
} else {
- if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY && pState->code == TSDB_CODE_SUCCESS) {
+ if (trsupport->numOfRetry++ < MAX_NUM_OF_SUBQUERY_RETRY && pParentSql->res.code == TSDB_CODE_SUCCESS) {
/*
* current query failed, and the retry count is less than the available
* count, retry query clear previous retrieved data, then launch a new sub query
@@ -1503,8 +1549,8 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
if (pNew == NULL) {
tscError("%p sub:%p failed to create new subquery sqlObj due to out of memory, abort retry",
trsupport->pParentSqlObj, pSql);
-
- pState->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
+
+ pParentSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY;
return;
}
@@ -1512,24 +1558,24 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
tscProcessSql(pNew);
return;
} else { // reach the maximum retry count, abort
- atomic_val_compare_exchange_32(&pState->code, TSDB_CODE_SUCCESS, numOfRows);
- tscError("%p sub:%p retrieve failed,code:%s,orderOfSub:%d failed.no more retry,set global code:%s", pPObj, pSql,
- tstrerror(numOfRows), subqueryIndex, tstrerror(pState->code));
+ atomic_val_compare_exchange_32(&pParentSql->res.code, TSDB_CODE_SUCCESS, numOfRows);
+ tscError("%p sub:%p retrieve failed,code:%s,orderOfSub:%d failed.no more retry,set global code:%s", pParentSql, pSql,
+ tstrerror(numOfRows), subqueryIndex, tstrerror(pParentSql->res.code));
}
}
-
- int32_t numOfTotal = pState->numOfTotal;
-
- int32_t finished = atomic_add_fetch_32(&pState->numOfCompleted, 1);
- if (finished < numOfTotal) {
- tscTrace("%p sub:%p orderOfSub:%d freed, finished subqueries:%d", pPObj, pSql, trsupport->subqueryIndex, finished);
+
+ int32_t remain = -1;
+ if ((remain = atomic_sub_fetch_32(&pState->numOfRemain, 1)) > 0) {
+ tscTrace("%p sub:%p orderOfSub:%d freed, finished subqueries:%d", pParentSql, pSql, trsupport->subqueryIndex,
+ pState->numOfTotal - remain);
+
return tscFreeSubSqlObj(trsupport, pSql);
}
// all subqueries are failed
- tscError("%p retrieve from %d vnode(s) completed,code:%s.FAILED.", pPObj, pState->numOfTotal, tstrerror(pState->code));
- pPObj->res.code = pState->code;
-
+ tscError("%p retrieve from %d vnode(s) completed,code:%s.FAILED.", pParentSql, pState->numOfTotal,
+ tstrerror(pParentSql->res.code));
+
// release allocated resource
tscLocalReducerEnvDestroy(trsupport->pExtMemBuffer, trsupport->pOrderDescriptor, trsupport->pFinalColModel,
pState->numOfTotal);
@@ -1538,13 +1584,13 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
tscFreeSubSqlObj(trsupport, pSql);
// in case of second stage join subquery, invoke its callback function instead of regular QueueAsyncRes
- SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pPObj->cmd, 0);
+ SQueryInfo *pQueryInfo = tscGetQueryInfoDetail(&pParentSql->cmd, 0);
if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE)) {
- (*pPObj->fp)(pPObj->param, pPObj, pPObj->res.code);
+ (*pParentSql->fp)(pParentSql->param, pParentSql, pParentSql->res.code);
} else { // regular super table query
- if (pPObj->res.code != TSDB_CODE_SUCCESS) {
- tscQueueAsyncRes(pPObj);
+ if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
+ tscQueueAsyncRes(pParentSql);
}
}
}
@@ -1590,14 +1636,11 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
return tscAbortFurtherRetryRetrieval(trsupport, pSql, TSDB_CODE_TSC_NO_DISKSPACE);
}
- // keep this value local variable, since the pState variable may be released by other threads, if atomic_add opertion
- // increases the finished value up to pState->numOfTotal value, which means all subqueries are completed.
- // In this case, the comparsion between finished value and released pState->numOfTotal is not safe.
- int32_t numOfTotal = pState->numOfTotal;
-
- int32_t finished = atomic_add_fetch_32(&pState->numOfCompleted, 1);
- if (finished < numOfTotal) {
- tscTrace("%p sub:%p orderOfSub:%d freed, finished subqueries:%d", pPObj, pSql, trsupport->subqueryIndex, finished);
+ int32_t remain = -1;
+ if ((remain = atomic_sub_fetch_32(&pState->numOfRemain, 1)) > 0) {
+ tscTrace("%p sub:%p orderOfSub:%d freed, finished subqueries:%d", pPObj, pSql, trsupport->subqueryIndex,
+ pState->numOfTotal - remain);
+
return tscFreeSubSqlObj(trsupport, pSql);
}
@@ -1632,10 +1675,10 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfRows) {
SRetrieveSupport *trsupport = (SRetrieveSupport *)param;
- int32_t idx = trsupport->subqueryIndex;
- SSqlObj * pPObj = trsupport->pParentSqlObj;
tOrderDescriptor *pDesc = trsupport->pOrderDescriptor;
-
+ int32_t idx = trsupport->subqueryIndex;
+ SSqlObj * pPObj = trsupport->pParentSqlObj;
+
SSqlObj *pSql = (SSqlObj *)tres;
if (pSql == NULL) { // sql object has been released in error process, return immediately
tscTrace("%p subquery has been released, idx:%d, abort", pPObj, idx);
@@ -1643,13 +1686,12 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
}
SSubqueryState* pState = trsupport->pState;
- assert(pState->numOfCompleted < pState->numOfTotal && pState->numOfCompleted >= 0 &&
- pPObj->numOfSubs == pState->numOfTotal);
+ assert(pState->numOfRemain <= pState->numOfTotal && pState->numOfRemain >= 0 && pPObj->numOfSubs == pState->numOfTotal);
// query process and cancel query process may execute at the same time
pthread_mutex_lock(&trsupport->queryMutex);
- if (numOfRows < 0 || pState->code < 0 || pPObj->res.code != TSDB_CODE_SUCCESS) {
+ if (numOfRows < 0 || pPObj->res.code != TSDB_CODE_SUCCESS) {
return tscHandleSubqueryError(trsupport, pSql, numOfRows);
}
@@ -1660,11 +1702,11 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
assert(pRes->numOfRows == numOfRows);
int64_t num = atomic_add_fetch_64(&pState->numOfRetrievedRows, numOfRows);
- tscTrace("%p sub:%p retrieve numOfRows:%d totalNumOfRows:%d from ip:%s, orderOfSub:%d", pPObj, pSql,
+ tscTrace("%p sub:%p retrieve numOfRows:%" PRId64 " totalNumOfRows:%" PRIu64 " from ip:%s, orderOfSub:%d", pPObj, pSql,
pRes->numOfRows, pState->numOfRetrievedRows, pSql->ipList.fqdn[pSql->ipList.inUse], idx);
if (num > tsMaxNumOfOrderedResults && tscIsProjectionQueryOnSTable(pQueryInfo, 0)) {
- tscError("%p sub:%p num of OrderedRes is too many, max allowed:%" PRId64 " , current:%" PRId64,
+ tscError("%p sub:%p num of OrderedRes is too many, max allowed:%" PRId32 " , current:%" PRId64,
pPObj, pSql, tsMaxNumOfOrderedResults, num);
tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_SORTED_RES_TOO_MANY);
return;
@@ -1689,6 +1731,7 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
pRes->numOfRows, pQueryInfo->groupbyExpr.orderType);
if (ret < 0) { // set no disk space error info, and abort retry
tscAbortFurtherRetryRetrieval(trsupport, tres, TSDB_CODE_TSC_NO_DISKSPACE);
+ pthread_mutex_unlock(&trsupport->queryMutex);
} else if (pRes->completed) {
tscAllDataRetrievedFromDnode(trsupport, pSql);
@@ -1699,7 +1742,6 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
taos_fetch_rows_a(tres, tscRetrieveFromDnodeCallBack, param);
}
- pthread_mutex_unlock(&trsupport->queryMutex);
} else { // all data has been retrieved to client
tscAllDataRetrievedFromDnode(trsupport, pSql);
}
@@ -1738,18 +1780,16 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
SCMVgroupInfo* pVgroup = &pTableMetaInfo->vgroupList->vgroups[0];
SSubqueryState* pState = trsupport->pState;
- assert(pState->numOfCompleted < pState->numOfTotal && pState->numOfCompleted >= 0 &&
- pParentSql->numOfSubs == pState->numOfTotal);
-
- if (pParentSql->res.code != TSDB_CODE_SUCCESS || pState->code != TSDB_CODE_SUCCESS) {
+ assert(pState->numOfRemain <= pState->numOfTotal && pState->numOfRemain >= 0 && pParentSql->numOfSubs == pState->numOfTotal);
+
+ // todo set error code
+ if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
// stable query is killed, abort further retry
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY;
if (pParentSql->res.code != TSDB_CODE_SUCCESS) {
code = pParentSql->res.code;
- } else {
- code = pState->code;
}
tscTrace("%p query cancelled or failed, sub:%p, orderOfSub:%d abort, code:%s", pParentSql, pSql,
@@ -1766,7 +1806,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
if (code != TSDB_CODE_SUCCESS) {
if (trsupport->numOfRetry++ >= MAX_NUM_OF_SUBQUERY_RETRY) {
tscTrace("%p sub:%p reach the max retry times, set global code:%s", pParentSql, pSql, tstrerror(code));
- atomic_val_compare_exchange_32(&pState->code, 0, code);
+ atomic_val_compare_exchange_32(&pParentSql->res.code, TSDB_CODE_SUCCESS, code);
} else { // does not reach the maximum retry time, go on
tscTrace("%p sub:%p failed code:%s, retry:%d", pParentSql, pSql, tstrerror(code), trsupport->numOfRetry);
@@ -1775,8 +1815,8 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
if (pNew == NULL) {
tscError("%p sub:%p failed to create new subquery due to out of memory, abort retry, vgId:%d, orderOfSub:%d",
trsupport->pParentSqlObj, pSql, pVgroup->vgId, trsupport->subqueryIndex);
-
- pState->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
+
+ pParentSql->res.code = TSDB_CODE_TSC_OUT_OF_MEMORY;
trsupport->numOfRetry = MAX_NUM_OF_SUBQUERY_RETRY;
} else {
SQueryInfo *pNewQueryInfo = tscGetQueryInfoDetail(&pNew->cmd, 0);
@@ -1789,11 +1829,11 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
}
}
- if (pState->code != TSDB_CODE_SUCCESS) { // at least one peer subquery failed, abort current query
- tscTrace("%p sub:%p query failed,ip:%u,vgId:%d,orderOfSub:%d,global code:%d", pParentSql, pSql,
- pVgroup->ipAddr[0].fqdn, pVgroup->vgId, trsupport->subqueryIndex, pState->code);
+ if (pParentSql->res.code != TSDB_CODE_SUCCESS) { // at least one peer subquery failed, abort current query
+ tscTrace("%p sub:%p query failed,ip:%s,vgId:%d,orderOfSub:%d,global code:%d", pParentSql, pSql,
+ pVgroup->ipAddr[0].fqdn, pVgroup->vgId, trsupport->subqueryIndex, pParentSql->res.code);
- tscHandleSubqueryError(param, tres, pState->code);
+ tscHandleSubqueryError(param, tres, pParentSql->res.code);
} else { // success, proceed to retrieve data from dnode
tscTrace("%p sub:%p query complete, ip:%s, vgId:%d, orderOfSub:%d, retrieve data", trsupport->pParentSqlObj, pSql,
pVgroup->ipAddr[0].fqdn, pVgroup->vgId, trsupport->subqueryIndex);
@@ -1813,8 +1853,7 @@ static void multiVnodeInsertMerge(void* param, TAOS_RES* tres, int numOfRows) {
SSqlCmd* pParentCmd = &pParentObj->cmd;
SSubqueryState* pState = pSupporter->pState;
- int32_t total = pState->numOfTotal;
-
+
// increase the total inserted rows
if (numOfRows > 0) {
pParentObj->res.numOfRows += numOfRows;
@@ -1826,8 +1865,7 @@ static void multiVnodeInsertMerge(void* param, TAOS_RES* tres, int numOfRows) {
}
taos_free_result(tres);
- int32_t completed = atomic_add_fetch_32(&pState->numOfCompleted, 1);
- if (completed < total) {
+ if (atomic_sub_fetch_32(&pState->numOfRemain, 1) > 0) {
return;
}
@@ -2157,5 +2195,3 @@ static bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) {
return hasData;
}
-
-
diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c
index bcd01a322e84f7d596a3f7715b687cba812c8410..a653b8383342d688d6b9ea42919ac4afe7b69423 100644
--- a/src/client/src/tscSystem.c
+++ b/src/client/src/tscSystem.c
@@ -220,7 +220,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
if (strlen(tsLocale) == 0) { // locale does not set yet
char* defaultLocale = setlocale(LC_CTYPE, "");
- strcpy(tsLocale, defaultLocale);
+ tstrncpy(tsLocale, defaultLocale, sizeof(tsLocale));
}
// set the user specified locale
@@ -304,7 +304,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
assert(cfg != NULL);
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) {
- strcpy(tsTimezone, pStr);
+ tstrncpy(tsTimezone, pStr, sizeof(tsTimezone));
tsSetTimeZone();
cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION;
tscTrace("timezone set:%s, input:%s by taos_options", tsTimezone, pStr);
diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c
index 01f2bb7dd5d1bb82fc6368c901a27678791900f3..9a2e028dd19967520eab3978b607c80a4939a04b 100644
--- a/src/client/src/tscUtil.c
+++ b/src/client/src/tscUtil.c
@@ -1840,7 +1840,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
size_t size = taosArrayGetSize(pNewQueryInfo->colList);
tscTrace(
- "%p new subquery:%p, tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%d, colList:%d,"
+ "%p new subquery:%p, tableIndex:%d, vgroupIndex:%d, type:%d, exprInfo:%z, colList:%z,"
"fieldInfo:%d, name:%s, qrang:%" PRId64 " - %" PRId64 " order:%d, limit:%" PRId64,
pSql, pNew, tableIndex, pTableMetaInfo->vgroupIndex, pNewQueryInfo->type, tscSqlExprNumOfExprs(pNewQueryInfo),
size, pNewQueryInfo->fieldsInfo.numOfOutput, pFinalInfo->name, pNewQueryInfo->window.skey,
@@ -2002,7 +2002,7 @@ void tscTryQueryNextVnode(SSqlObj* pSql, __async_cb_func_t fp) {
int32_t totalVgroups = pTableMetaInfo->vgroupList->numOfVgroups;
while (++pTableMetaInfo->vgroupIndex < totalVgroups) {
- tscTrace("%p results from vgroup index:%d completed, try next:%d. total vgroups:%d. current numOfRes:%d", pSql,
+ tscTrace("%p results from vgroup index:%d completed, try next:%d. total vgroups:%d. current numOfRes:%" PRId64, pSql,
pTableMetaInfo->vgroupIndex - 1, pTableMetaInfo->vgroupIndex, totalVgroups, pRes->numOfClauseTotal);
/*
diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c
index 30fdd21b99b4ffaf413a27d957b391bfabecc0dd..d971e3ad6dc2a20c241c0ba1ea5aac12dfa878f8 100644
--- a/src/dnode/src/dnodeMgmt.c
+++ b/src/dnode/src/dnodeMgmt.c
@@ -407,11 +407,7 @@ static void dnodeProcessStatusRsp(SRpcMsg *pMsg) {
pMnodeInfo->nodeId = htonl(pMnodeInfo->nodeId);
}
- SDMVgroupAccess *pVgAcccess = pStatusRsp->vgAccess;
- for (int32_t i = 0; i < pCfg->numOfVnodes; ++i) {
- pVgAcccess[i].vgId = htonl(pVgAcccess[i].vgId);
- }
-
+ vnodeSetAccess(pStatusRsp->vgAccess, pCfg->numOfVnodes);
dnodeProcessModuleStatus(pCfg->moduleStatus);
dnodeUpdateDnodeCfg(pCfg);
diff --git a/src/inc/taos.h b/src/inc/taos.h
index 9ac97a24e1d4bb695b4f1a30516b9799b6ad89eb..d524d95685581560fa3e565bce4cf189145af128 100644
--- a/src/inc/taos.h
+++ b/src/inc/taos.h
@@ -55,7 +55,7 @@ typedef enum {
typedef struct taosField {
char name[65];
uint8_t type;
- uint16_t bytes;
+ int16_t bytes;
} TAOS_FIELD;
#ifdef _TD_GO_DLL_
diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h
index 8b82e1f14992d614ceebc59598732e8573ddb8df..6de7f672913f7adb94ac2fc853b2596480e2a4cb 100644
--- a/src/inc/taosdef.h
+++ b/src/inc/taosdef.h
@@ -209,8 +209,8 @@ void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
#define TSDB_MAX_SQL_SHOW_LEN 256
#define TSDB_MAX_ALLOWED_SQL_LEN (8*1024*1024U) // sql length should be less than 8mb
-#define TSDB_MAX_BYTES_PER_ROW 65535
-#define TSDB_MAX_TAGS_LEN 65535
+#define TSDB_MAX_BYTES_PER_ROW 16384
+#define TSDB_MAX_TAGS_LEN 16384
#define TSDB_MAX_TAGS 128
#define TSDB_AUTH_LEN 16
diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h
index 6af31734b5b25d5d6ea9930badccdf85a5b6a906..33e0aa24b6eab113242337b04133766f2ea9b94f 100644
--- a/src/inc/taoserror.h
+++ b/src/inc/taoserror.h
@@ -113,12 +113,12 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_QUERY_ID, 0, 0x030C, "mnode inva
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STREAM_ID, 0, 0x030D, "mnode invalid stream id")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CONN_ID, 0, 0x030E, "mnode invalid connection")
-TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE, 0, 0x0320, "[sdb] object already there")
-TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_ERROR, 0, 0x0321, "[sdb] app error")
-TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE, 0, 0x0322, "[sdb] invalid table type")
-TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_NOT_THERE, 0, 0x0323, "[sdb] object not there")
-TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_META_ROW, 0, 0x0324, "[sdb] invalid meta row")
-TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_KEY_TYPE, 0, 0x0325, "[sdb] invalid key type")
+TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_ALREADY_THERE, 0, 0x0320, "sdb object already there")
+TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_ERROR, 0, 0x0321, "sdb app error")
+TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVALID_TABLE_TYPE, 0, 0x0322, "sdb invalid table type")
+TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_OBJ_NOT_THERE, 0, 0x0323, "sdb object not there")
+TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_META_ROW, 0, 0x0324, "sdb invalid meta row")
+TAOS_DEFINE_ERROR(TSDB_CODE_MND_SDB_INVAID_KEY_TYPE, 0, 0x0325, "sdb invalid key type")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_ALREADY_EXIST, 0, 0x0330, "mnode dnode already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_EXIST, 0, 0x0331, "mnode dnode not exist")
@@ -179,6 +179,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISK_PERMISSIONS, 0, 0x0506, "vnode no d
TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR, 0, 0x0507, "vnode no such file or directory")
TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, 0, 0x0508, "vnode out of memory")
TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, 0, 0x0509, "vnode app error")
+TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_WRITE_AUTH, 0, 0x0214, "vnode no write auth")
// tsdb
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, 0, 0x0600, "tsdb invalid table id")
diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h
index fcb6d66422fddbbd3e6c623088b87607ca4bc6f2..78255a45d5432fffe3ea0d2daf87d94dff041e42 100644
--- a/src/inc/taosmsg.h
+++ b/src/inc/taosmsg.h
@@ -543,6 +543,7 @@ typedef struct {
int32_t dnodeId;
uint32_t moduleStatus;
uint32_t numOfVnodes;
+ uint32_t reserved;
} SDMDnodeCfg;
typedef struct {
diff --git a/src/inc/vnode.h b/src/inc/vnode.h
index 0da1f51e27fc8ba882a6c7d60ccfdaf0245e83dc..9f0c8cc24171184607b93ddaab30142ff29c4e7d 100644
--- a/src/inc/vnode.h
+++ b/src/inc/vnode.h
@@ -58,6 +58,7 @@ void* vnodeGetWal(void *pVnode);
int32_t vnodeProcessWrite(void *pVnode, int qtype, void *pHead, void *item);
void vnodeBuildStatusMsg(void * param);
+void vnodeSetAccess(SDMVgroupAccess *pAccess, int32_t numOfVnodes);
int32_t vnodeProcessRead(void *pVnode, SReadMsg *pReadMsg);
diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h
index 2baf28f88f9b51cae7e1159a2bd9446217adbdcd..80a638a21eff32a20abd982bdb2b545ff264d750 100644
--- a/src/mnode/inc/mnodeDef.h
+++ b/src/mnode/inc/mnodeDef.h
@@ -122,7 +122,8 @@ typedef struct SVgObj {
int32_t lbDnodeId;
int32_t lbTime;
int8_t inUse;
- int8_t reserved[13];
+ int8_t accessState;
+ int8_t reserved[12];
int8_t updateEnd[1];
int32_t refCount;
struct SVgObj *prev, *next;
diff --git a/src/mnode/inc/mnodeVgroup.h b/src/mnode/inc/mnodeVgroup.h
index d61145d9b82ffa643a52c0e4feb6c75443079153..29a0fe1799a0f31e4697ecc2bde57e8dcd230a13 100644
--- a/src/mnode/inc/mnodeVgroup.h
+++ b/src/mnode/inc/mnodeVgroup.h
@@ -34,7 +34,8 @@ void mnodeUpdateAllDbVgroups(SDbObj *pAlterDb);
void * mnodeGetNextVgroup(void *pIter, SVgObj **pVgroup);
void mnodeUpdateVgroup(SVgObj *pVgroup);
-void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *dnodeId, SVnodeLoad *pVload);
+void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVload);
+void mnodeCheckUnCreatedVgroup(SDnodeObj *pDnode, SVnodeLoad *pVloads, int32_t openVnodes);
int32_t mnodeCreateVgroup(struct SMnodeMsg *pMsg, SDbObj *pDb);
void mnodeDropVgroup(SVgObj *pVgroup, void *ahandle);
diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c
index 4c795647698edf64e28e8f5542fc4143fa8aebd9..3fcb3849aafa8221cd7c4450fd851e5dce2672f4 100644
--- a/src/mnode/src/mnodeAcct.c
+++ b/src/mnode/src/mnodeAcct.c
@@ -39,6 +39,7 @@ static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) {
static int32_t mnodeAcctActionInsert(SSdbOper *pOper) {
SAcctObj *pAcct = pOper->pObj;
memset(&pAcct->acctInfo, 0, sizeof(SAcctInfo));
+ pAcct->acctInfo.accessState = TSDB_VN_ALL_ACCCESS;
pthread_mutex_init(&pAcct->mutex, NULL);
return TSDB_CODE_SUCCESS;
}
diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c
index 35f4ea43d33c22b966eec0ec83f8cd751ed7f7af..21de887488175fcbf3fe1627283c957d3caf9c58 100644
--- a/src/mnode/src/mnodeDnode.c
+++ b/src/mnode/src/mnodeDnode.c
@@ -335,6 +335,19 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
}
int32_t openVnodes = htons(pStatus->openVnodes);
+ int32_t contLen = sizeof(SDMStatusRsp) + openVnodes * sizeof(SDMVgroupAccess);
+ SDMStatusRsp *pRsp = rpcMallocCont(contLen);
+ if (pRsp == NULL) {
+ mnodeDecDnodeRef(pDnode);
+ return TSDB_CODE_MND_OUT_OF_MEMORY;
+ }
+
+ pRsp->dnodeCfg.dnodeId = htonl(pDnode->dnodeId);
+ pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt);
+ pRsp->dnodeCfg.numOfVnodes = htonl(openVnodes);
+ mnodeGetMnodeInfos(&pRsp->mnodes);
+ SDMVgroupAccess *pAccess = (SDMVgroupAccess *)((char *)pRsp + sizeof(SDMStatusRsp));
+
for (int32_t j = 0; j < openVnodes; ++j) {
SVnodeLoad *pVload = &pStatus->load[j];
pVload->vgId = htonl(pVload->vgId);
@@ -347,6 +360,8 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
mnodeSendDropVnodeMsg(pVload->vgId, &ipSet, NULL);
} else {
mnodeUpdateVgroupStatus(pVgroup, pDnode, pVload);
+ pAccess->vgId = htonl(pVload->vgId);
+ pAccess->accessState = pVgroup->accessState;
mnodeDecVgroupRef(pVgroup);
}
}
@@ -366,26 +381,13 @@ static int32_t mnodeProcessDnodeStatusMsg(SMnodeMsg *pMsg) {
balanceNotify();
}
- mnodeDecDnodeRef(pDnode);
-
- int32_t contLen = sizeof(SDMStatusRsp) + TSDB_MAX_VNODES * sizeof(SDMVgroupAccess);
- SDMStatusRsp *pRsp = rpcMallocCont(contLen);
- if (pRsp == NULL) {
- return TSDB_CODE_MND_OUT_OF_MEMORY;
+ if (openVnodes != pDnode->openVnodes) {
+ mnodeCheckUnCreatedVgroup(pDnode, pStatus->load, openVnodes);
}
pDnode->lastAccess = tsAccessSquence;
+ mnodeDecDnodeRef(pDnode);
- mnodeGetMnodeInfos(&pRsp->mnodes);
-
- pRsp->dnodeCfg.dnodeId = htonl(pDnode->dnodeId);
- pRsp->dnodeCfg.moduleStatus = htonl((int32_t)pDnode->isMgmt);
- pRsp->dnodeCfg.numOfVnodes = 0;
-
- contLen = sizeof(SDMStatusRsp);
-
- //TODO: set vnode access
-
pMsg->rpcRsp.len = contLen;
pMsg->rpcRsp.rsp = pRsp;
diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c
index 10dfb2a28a7bbc21ffcbaa134f83bbbc9226563e..ff09af761135e6b878d40977df7c3c830627f952 100644
--- a/src/mnode/src/mnodeVgroup.c
+++ b/src/mnode/src/mnodeVgroup.c
@@ -74,6 +74,7 @@ static int32_t mnodeVgroupActionInsert(SSdbOper *pOper) {
pVgroup->pDb = pDb;
pVgroup->prev = NULL;
pVgroup->next = NULL;
+ pVgroup->accessState = TSDB_VN_ALL_ACCCESS;
int32_t size = sizeof(SChildTableObj *) * pDb->cfg.maxTables;
pVgroup->tableList = calloc(pDb->cfg.maxTables, sizeof(SChildTableObj *));
@@ -255,6 +256,8 @@ void mnodeUpdateVgroup(SVgObj *pVgroup) {
mnodeSendCreateVgroupMsg(pVgroup, NULL);
}
+void mnodeCheckUnCreatedVgroup(SDnodeObj *pDnode, SVnodeLoad *pVloads, int32_t openVnodes) {}
+
void mnodeUpdateVgroupStatus(SVgObj *pVgroup, SDnodeObj *pDnode, SVnodeLoad *pVload) {
bool dnodeExist = false;
for (int32_t i = 0; i < pVgroup->numOfVnodes; ++i) {
@@ -324,6 +327,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) {
strcpy(pVgroup->dbName, pDb->name);
pVgroup->numOfVnodes = pDb->cfg.replications;
pVgroup->createdTime = taosGetTimestampMs();
+ pVgroup->accessState = TSDB_VN_ALL_ACCCESS;
if (balanceAllocVnodes(pVgroup) != 0) {
mError("db:%s, no enough dnode to alloc %d vnodes to vgroup", pDb->name, pVgroup->numOfVnodes);
free(pVgroup);
diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c
index 0728fcaa35121a41d5c60fb0c85977f358edea69..0a25ae339779bef9c76ee3388e01024ca09c68b1 100644
--- a/src/query/src/qExecutor.c
+++ b/src/query/src/qExecutor.c
@@ -1216,7 +1216,6 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
// interval query with limit applied
int32_t numOfRes = 0;
-
if (isIntervalQuery(pQuery)) {
numOfRes = doCheckQueryCompleted(pRuntimeEnv, lastKey, pWindowResInfo);
} else {
diff --git a/src/util/inc/tstoken.h b/src/util/inc/tstoken.h
index 60a79f69afe8b7521e1869eea8ae0e96f4660487..74687e9c18ada622fadb87ab5e5f0abf22f1580f 100644
--- a/src/util/inc/tstoken.h
+++ b/src/util/inc/tstoken.h
@@ -120,6 +120,7 @@ static FORCE_INLINE int32_t isValidNumber(const SSQLToken* pToken) {
type = TK_FLOAT;
goto _end;
+ break;
}
case '0': {
diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h
index c75ba24baabb2370417ef8e3d61b2023bbd3b109..bb74bafbdde89f64e5531735fa271a6afd52146d 100644
--- a/src/util/inc/tutil.h
+++ b/src/util/inc/tutil.h
@@ -117,6 +117,8 @@ extern "C" {
#define POW2(x) ((x) * (x))
+int taosRand(void);
+
int32_t strdequote(char *src);
size_t strtrim(char *src);
diff --git a/src/util/src/tarray.c b/src/util/src/tarray.c
index b99e722262288014b4eb4cae8252235a2205c099..19225e998a1b2a5fead58b781b448ccf4b604415 100755
--- a/src/util/src/tarray.c
+++ b/src/util/src/tarray.c
@@ -95,9 +95,6 @@ void* taosArrayGetP(const SArray* pArray, size_t index) {
assert(index < pArray->size);
void* d = TARRAY_GET_ELEM(pArray, index);
- if (d == NULL) {
- return NULL;
- }
return *(void**)d;
}
diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c
index 2b6083a91ccef8ef2a08902117e8f67340ba6a37..48603a014e1479a5dfdd319f7b23f49669ee3f80 100644
--- a/src/util/src/tcache.c
+++ b/src/util/src/tcache.c
@@ -119,7 +119,7 @@ static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheDataNo
int32_t size = pNode->size;
taosHashRemove(pCacheObj->pHashTable, pNode->key, pNode->keySize);
- uTrace("key:%s is removed from cache,total:%d,size:%ldbytes", pNode->key, pCacheObj->totalSize, size);
+ uTrace("key:%s is removed from cache,total:%" PRId64 ",size:%dbytes", pNode->key, pCacheObj->totalSize, size);
if (pCacheObj->freeFp) pCacheObj->freeFp(pNode->data);
free(pNode);
}
@@ -288,7 +288,7 @@ void *taosCachePut(SCacheObj *pCacheObj, const char *key, const void *pData, siz
if (NULL != pNode) {
pCacheObj->totalSize += pNode->size;
- uTrace("key:%s %p added into cache, added:%" PRIu64 ", expire:%" PRIu64 ", total:%d, size:%" PRId64 " bytes",
+ uTrace("key:%s %p added into cache, added:%" PRIu64 ", expire:%" PRIu64 ", total:%" PRId64 ", size:%" PRId64 " bytes",
key, pNode, pNode->addedTime, pNode->expiredTime, pCacheObj->totalSize, dataSize);
} else {
uError("key:%s failed to added into cache, out of memory", key);
@@ -433,7 +433,6 @@ void taosCacheEmpty(SCacheObj *pCacheObj) {
__cache_wr_lock(pCacheObj);
while (taosHashIterNext(pIter)) {
if (pCacheObj->deleting == 1) {
- taosHashDestroyIter(pIter);
break;
}
@@ -507,7 +506,7 @@ void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) {
void taosRemoveFromTrashCan(SCacheObj *pCacheObj, STrashElem *pElem) {
if (pElem->pData->signature != (uint64_t)pElem->pData) {
- uError("key:sig:%d %p data has been released, ignore", pElem->pData->signature, pElem->pData);
+ uError("key:sig:0x%" PRIx64 " %p data has been released, ignore", pElem->pData->signature, pElem->pData);
return;
}
@@ -561,7 +560,6 @@ void taosTrashCanEmpty(SCacheObj *pCacheObj, bool force) {
}
}
- assert(pCacheObj->numOfElemsInTrash >= 0);
__cache_unlock(pCacheObj);
}
diff --git a/src/util/src/tcompression.c b/src/util/src/tcompression.c
index e3b3d65052e4d34c9c424b565d084ae123efcac0..b085e26e07177189d2b7d350a82ef779576d3cf2 100644
--- a/src/util/src/tcompression.c
+++ b/src/util/src/tcompression.c
@@ -551,7 +551,7 @@ int tsDecompressTimestampImp(const char *const input, const int nelements, char
delta_of_delta = 0;
} else {
if (is_bigendian()) {
- memcpy(&dd1 + LONG_BYTES - nbytes, input + ipos, nbytes);
+ memcpy(((char *)(&dd1)) + LONG_BYTES - nbytes, input + ipos, nbytes);
} else {
memcpy(&dd1, input + ipos, nbytes);
}
@@ -576,7 +576,7 @@ int tsDecompressTimestampImp(const char *const input, const int nelements, char
delta_of_delta = 0;
} else {
if (is_bigendian()) {
- memcpy(&dd2 + LONG_BYTES - nbytes, input + ipos, nbytes);
+ memcpy(((char *)(&dd2)) + LONG_BYTES - nbytes, input + ipos, nbytes);
} else {
memcpy(&dd2, input + ipos, nbytes);
}
diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c
index 543a84dc44cf3105aee4583bc31882df37702fad..bcea8d16543cb26e6b2c951c83382794f7cf291d 100644
--- a/src/util/src/tconfig.c
+++ b/src/util/src/tconfig.c
@@ -74,7 +74,7 @@ static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) {
*option = value;
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
} else {
- uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value,
+ uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value,
tsCfgStatusStr[cfg->cfgStatus], *option);
}
}
@@ -106,7 +106,11 @@ static void taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
} else {
if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) {
wordexp_t full_path;
- wordexp(input_value, &full_path, 0);
+ if (0 != wordexp(input_value, &full_path, 0)) {
+ printf("\nconfig dir: %s wordexp fail! reason:%s\n", input_value, strerror(errno));
+ wordfree(&full_path);
+ return;
+ }
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
strcpy(option, full_path.we_wordv[0]);
}
@@ -115,8 +119,13 @@ static void taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) {
struct stat dirstat;
if (stat(option, &dirstat) < 0) {
int code = mkdir(option, 0755);
- uPrint("config option:%s, input value:%s, directory not exist, create with return code:%d",
- cfg->option, input_value, code);
+ if (code < 0) {
+ uError("config option:%s, input value:%s, directory not exist, create fail with return code:%d",
+ cfg->option, input_value, code);
+ } else {
+ uPrint("config option:%s, input value:%s, directory not exist, create with return code:%d",
+ cfg->option, input_value, code);
+ }
}
cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE;
} else {
@@ -240,7 +249,12 @@ void taosReadGlobalLogCfg() {
sdbDebugFlag = 135;
wordexp_t full_path;
- wordexp(configDir, &full_path, 0);
+ if ( 0 != wordexp(configDir, &full_path, 0)) {
+ printf("\nconfig file: %s wordexp fail! reason:%s\n", configDir, strerror(errno));
+ wordfree(&full_path);
+ return;
+ }
+
if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) {
if (strlen(full_path.we_wordv[0]) >= TSDB_FILENAME_LEN) {
printf("\nconfig file: %s path overflow max len %d, all variables are set to default\n", full_path.we_wordv[0], TSDB_FILENAME_LEN - 1);
diff --git a/src/util/src/tdes.c b/src/util/src/tdes.c
index 3112fb411148925bf064b356df6e8dfc708ce86e..c76938d3aad47a416ee0a8e510d5ea3f7a6481c6 100644
--- a/src/util/src/tdes.c
+++ b/src/util/src/tdes.c
@@ -140,7 +140,7 @@ void print_char_as_binary(char input) {
void generate_key(unsigned char* key) {
int i;
for (i = 0; i < 8; i++) {
- key[i] = rand() % 255;
+ key[i] = taosRand() % 255;
}
}
diff --git a/src/util/src/terror.c b/src/util/src/terror.c
index c040a11362a01175a126a7d954af4a945285061d..aa6925464e12a1863b8dc510d7389ed97267d142 100644
--- a/src/util/src/terror.c
+++ b/src/util/src/terror.c
@@ -15,7 +15,6 @@
#include
#include
-#include
#include
#include
diff --git a/src/util/src/tkvstore.c b/src/util/src/tkvstore.c
index 6eca1413759b9c657432ea7a3c272b5e8f2b6e66..1c7d93b307c5621e07f9b0c6e8d93013123d50ca 100644
--- a/src/util/src/tkvstore.c
+++ b/src/util/src/tkvstore.c
@@ -566,5 +566,6 @@ static int tdRestoreKVStore(SKVStore *pStore) {
_err:
taosHashDestroyIter(pIter);
tfree(buf);
+ taosHashDestroyIter(pIter);
return -1;
}
\ No newline at end of file
diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c
index 01a0eabbca39258951f2e0d6c4e098c7bf009be8..39ec89daf4986632f50b4e11c6051b36e4366b7a 100644
--- a/src/util/src/tlog.c
+++ b/src/util/src/tlog.c
@@ -142,6 +142,10 @@ static void *taosThreadToOpenNewFile(void *param) {
umask(0);
int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO);
+ if (fd < 0) {
+ uError("open new log file fail! fd:%d reason:%s", fd, strerror(errno));
+ return NULL;
+ }
taosLockFile(fd);
lseek(fd, 0, SEEK_SET);
@@ -184,7 +188,7 @@ void taosResetLog() {
tsLogObj.lines = tsLogObj.maxLines + 10;
taosOpenNewLogFile();
- remove(lastName);
+ (void)remove(lastName);
uPrint("==================================");
uPrint(" reset log file ");
@@ -229,7 +233,9 @@ static void taosGetLogFileName(char *fn) {
}
}
- strcpy(tsLogObj.logName, fn);
+ if (strlen(fn) < LOG_FILE_NAME_LEN) {
+ strcpy(tsLogObj.logName, fn);
+ }
}
static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
@@ -249,15 +255,20 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
tsLogObj.fileNum = maxFileNum;
taosGetLogFileName(fn);
- strcpy(name, fn);
- strcat(name, ".0");
+ if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) {
+ strcpy(name, fn);
+ strcat(name, ".0");
+ }
// if none of the log files exist, open 0, if both exists, open the old one
if (stat(name, &logstat0) < 0) {
tsLogObj.flag = 0;
} else {
- strcpy(name, fn);
- strcat(name, ".1");
+ if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) {
+ strcpy(name, fn);
+ strcat(name, ".1");
+ }
+
if (stat(name, &logstat1) < 0) {
tsLogObj.flag = 1;
} else {
@@ -279,7 +290,10 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
// only an estimate for number of lines
struct stat filestat;
- fstat(tsLogObj.logHandle->fd, &filestat);
+ if (fstat(tsLogObj.logHandle->fd, &filestat) < 0) {
+ printf("\nfailed to fstat log file:%s, reason:%s\n", name, strerror(errno));
+ return -1;
+ }
size = (int32_t)filestat.st_size;
tsLogObj.lines = size / 60;
diff --git a/src/util/src/tnote.c b/src/util/src/tnote.c
index 31ed6e2f7bded579b75066e590c68b8bc8580a3e..a8d9e8d416ce9c9ee2653a665ecb080930e2c7ab 100644
--- a/src/util/src/tnote.c
+++ b/src/util/src/tnote.c
@@ -169,7 +169,9 @@ void taosGetNoteName(char *fn, taosNoteInfo * pNote)
}
}
- strcpy(pNote->taosNoteName, fn);
+ if (strlen(fn) < NOTE_FILE_NAME_LEN) {
+ strcpy(pNote->taosNoteName, fn);
+ }
}
int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInfo * pNote)
@@ -182,14 +184,18 @@ int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInf
pNote->taosNoteFileNum = maxNoteNum;
taosGetNoteName(fn, pNote);
+ if (strlen(fn) > NOTE_FILE_NAME_LEN * 2 - 2) {
+ fprintf(stderr, "the len of file name overflow:%s\n", fn);
+ return -1;
+ }
+
strcpy(name, fn);
strcat(name, ".0");
// if none of the note files exist, open 0, if both exists, open the old one
if (stat(name, ¬estat0) < 0) {
pNote->taosNoteFlag = 0;
- }
- else {
+ } else {
strcpy(name, fn);
strcat(name, ".1");
if (stat(name, ¬estat1) < 0) {
@@ -214,7 +220,10 @@ int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInf
// only an estimate for number of lines
struct stat filestat;
- fstat(pNote->taosNoteFd, &filestat);
+ if (fstat(pNote->taosNoteFd, &filestat) < 0) {
+ fprintf(stderr, "failed to fstat note file:%s reason:%s\n", name, strerror(errno));
+ return -1;
+ }
size = (int)filestat.st_size;
pNote->taosNoteLines = size / 60;
@@ -226,7 +235,7 @@ int taosOpenNoteWithMaxLines(char *fn, int maxLines, int maxNoteNum, taosNoteInf
void taosNotePrint(taosNoteInfo * pNote, const char * const format, ...)
{
va_list argpointer;
- char buffer[MAX_NOTE_LINE_SIZE];
+ char buffer[MAX_NOTE_LINE_SIZE+2];
int len;
struct tm Tm, *ptm;
struct timeval timeSecs;
diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c
index 0532b442bbd9f930c4e4765d419a341b74b98816..a65d9b0f31b515ed04179586bb8cc4997c271b7b 100644
--- a/src/util/src/tskiplist.c
+++ b/src/util/src/tskiplist.c
@@ -38,7 +38,7 @@ static FORCE_INLINE int32_t getSkipListNodeRandomHeight(SSkipList *pSkipList) {
const uint32_t factor = 4;
int32_t n = 1;
- while ((rand() % factor) == 0 && n <= pSkipList->maxLevel) {
+ while ((taosRand() % factor) == 0 && n <= pSkipList->maxLevel) {
n++;
}
diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c
index 1f4d57115b2758b9144863a44f0fc49da2c14142..98ed8d1ed761dfc7ec66f66070bf7a5f63871d18 100644
--- a/src/util/src/tsocket.c
+++ b/src/util/src/tsocket.c
@@ -278,7 +278,7 @@ int taosOpenUdpSocket(uint32_t ip, uint16_t port) {
/* bind socket to local address */
if (bind(sockFd, (struct sockaddr *)&localAddr, sizeof(localAddr)) < 0) {
uError("failed to bind udp socket: %d (%s), 0x%x:%hu", errno, strerror(errno), ip, port);
- taosCloseSocket(sockFd);
+ close(sockFd);
return -1;
}
@@ -321,7 +321,7 @@ int taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clientI
if (ret != 0) {
//uError("failed to connect socket, ip:0x%x, port:%hu(%s)", destIp, destPort, strerror(errno));
- taosCloseSocket(sockFd);
+ close(sockFd);
sockFd = -1;
}
diff --git a/src/util/src/ttime.c b/src/util/src/ttime.c
index 4dd6360752f4fa67d5269c67589b2b35cbd32b4a..02d72dd1f4539a012bf50b46f94b4a7647d73675 100644
--- a/src/util/src/ttime.c
+++ b/src/util/src/ttime.c
@@ -72,49 +72,6 @@ void deltaToUtcInitOnce() {
return;
}
-int64_t user_mktime(struct tm * tm)
-{
-#define TAOS_MINUTE 60
-#define TAOS_HOUR (60*TAOS_MINUTE)
-#define TAOS_DAY (24*TAOS_HOUR)
-#define TAOS_YEAR (365*TAOS_DAY)
-
-static int month[12] = {
- 0,
- TAOS_DAY*(31),
- TAOS_DAY*(31+29),
- TAOS_DAY*(31+29+31),
- TAOS_DAY*(31+29+31+30),
- TAOS_DAY*(31+29+31+30+31),
- TAOS_DAY*(31+29+31+30+31+30),
- TAOS_DAY*(31+29+31+30+31+30+31),
- TAOS_DAY*(31+29+31+30+31+30+31+31),
- TAOS_DAY*(31+29+31+30+31+30+31+31+30),
- TAOS_DAY*(31+29+31+30+31+30+31+31+30+31),
- TAOS_DAY*(31+29+31+30+31+30+31+31+30+31+30)
-};
-
- int64_t res;
- int year;
-
- year= tm->tm_year - 70;
- res= TAOS_YEAR*year + TAOS_DAY*((year+1)/4);
- res+= month[tm->tm_mon];
-
- if(tm->tm_mon > 1 && ((year+2)%4)) {
- res-= TAOS_DAY;
- }
-
- res+= TAOS_DAY*(tm->tm_mday-1);
- res+= TAOS_HOUR*tm->tm_hour;
- res+= TAOS_MINUTE*tm->tm_min;
- res+= tm->tm_sec;
-
- return res + m_deltaUtc;
-
-}
-
-
static int64_t parseFraction(char* str, char** end, int32_t timePrec);
static int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec);
static int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec);
diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c
index cdb2c6c0beb5ea0223fb077dde20c08a5966a294..f7acc1132de674e7a33cc4e1c3de4c786c3c1612 100644
--- a/src/util/src/ttimer.c
+++ b/src/util/src/ttimer.c
@@ -139,7 +139,7 @@ static void unlockTimerList(timer_list_t* list) {
int64_t tid = taosGetPthreadId();
if (atomic_val_compare_exchange_64(&(list->lockedBy), tid, 0) != tid) {
assert(false);
- tmrError("%d trying to unlock a timer list not locked by current thread.", tid);
+ tmrError("%" PRId64 " trying to unlock a timer list not locked by current thread.", tid);
}
}
@@ -290,6 +290,7 @@ static void addToExpired(tmr_obj_t* head) {
SSchedMsg schedMsg;
schedMsg.fp = NULL;
schedMsg.tfp = processExpiredTimer;
+ schedMsg.msg = NULL;
schedMsg.ahandle = head;
schedMsg.thandle = NULL;
taosScheduleTask(tmrQhandle, &schedMsg);
@@ -513,14 +514,17 @@ static void taosTmrModuleInit(void) {
tmrError("failed to create the mutex for wheel, reason:%s", strerror(errno));
return;
}
+ pthread_mutex_lock(&wheel->mutex);
wheel->nextScanAt = now + wheel->resolution;
wheel->index = 0;
wheel->slots = (tmr_obj_t**)calloc(wheel->size, sizeof(tmr_obj_t*));
if (wheel->slots == NULL) {
tmrError("failed to allocate wheel slots");
+ pthread_mutex_unlock(&wheel->mutex);
return;
}
timerMap.size += wheel->size;
+ pthread_mutex_unlock(&wheel->mutex);
}
timerMap.count = 0;
diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c
index 92091174153d6645474f906d3cdb09243db4455f..a2edce2387b53d6f8cd864d3495ae1cd31fd60b5 100644
--- a/src/util/src/tutil.c
+++ b/src/util/src/tutil.c
@@ -27,6 +27,33 @@
#include "tulog.h"
#include "taoserror.h"
+
+#ifdef WINDOWS
+int taosRand(void)
+{
+ return rand();
+}
+#else
+int taosRand(void)
+{
+ int fd;
+ int seed;
+
+ fd = open("/dev/urandom", 0);
+ if (fd < 0) {
+ seed = time(0);
+ } else {
+ int len = read(fd, &seed, sizeof(seed));
+ if (len < 0) {
+ seed = time(0);
+ }
+ close(fd);
+ }
+
+ return seed;
+}
+#endif
+
int32_t strdequote(char *z) {
if (z == NULL) {
return 0;
@@ -434,8 +461,10 @@ void getTmpfilePath(const char *fileNamePrefix, char *dstPath) {
strcpy(tmpPath, tmpDir);
strcat(tmpPath, tdengineTmpFileNamePrefix);
- strcat(tmpPath, fileNamePrefix);
- strcat(tmpPath, "-%d-%s");
+ if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
+ strcat(tmpPath, fileNamePrefix);
+ strcat(tmpPath, "-%d-%s");
+ }
char rand[8] = {0};
taosRandStr(rand, tListLen(rand) - 1);
@@ -447,7 +476,7 @@ void taosRandStr(char* str, int32_t size) {
int32_t len = 39;
for(int32_t i = 0; i < size; ++i) {
- str[i] = set[rand()%len];
+ str[i] = set[taosRand()%len];
}
}
@@ -557,7 +586,7 @@ bool taosGetVersionNumber(char *versionStr, int *versionNubmer) {
return false;
}
- int versionNumberPos[4] = {0};
+ int versionNumberPos[5] = {0};
int len = strlen(versionStr);
int dot = 0;
for (int pos = 0; pos < len && dot < 4; ++pos) {
@@ -709,7 +738,7 @@ void taosRemoveDir(char *rootDir) {
if (de->d_type & DT_DIR) {
taosRemoveDir(filename);
} else {
- remove(filename);
+ (void)remove(filename);
uPrint("file:%s is removed", filename);
}
}
@@ -718,4 +747,4 @@ void taosRemoveDir(char *rootDir) {
rmdir(rootDir);
uPrint("dir:%s is removed", rootDir);
-}
\ No newline at end of file
+}
diff --git a/src/vnode/inc/vnodeInt.h b/src/vnode/inc/vnodeInt.h
index ab74e329e6dd2585cdf0634e5112b087c0aa6ffc..d5a7dbfd2e970269f5bcf2ad57015c068d96a44e 100644
--- a/src/vnode/inc/vnodeInt.h
+++ b/src/vnode/inc/vnodeInt.h
@@ -37,6 +37,7 @@ typedef struct {
int32_t refCount; // reference count
int status;
int8_t role;
+ int8_t accessState;
int64_t version; // current version
int64_t fversion; // version on saved data file
void *wqueue;
diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c
index 7985b2d898c6f10517610443effbb93a5569e546..ece0c512e3bbf6f787678f54874a04b181002aa6 100644
--- a/src/vnode/src/vnodeMain.c
+++ b/src/vnode/src/vnodeMain.c
@@ -195,6 +195,7 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
pVnode->version = 0;
pVnode->tsdbCfg.tsdbId = pVnode->vgId;
pVnode->rootDir = strdup(rootDir);
+ pVnode->accessState = TSDB_VN_ALL_ACCCESS;
int32_t code = vnodeReadCfg(pVnode);
if (code != TSDB_CODE_SUCCESS) {
@@ -431,6 +432,20 @@ void vnodeBuildStatusMsg(void *param) {
taosHashDestroyIter(pIter);
}
+void vnodeSetAccess(SDMVgroupAccess *pAccess, int32_t numOfVnodes) {
+ for (int32_t i = 0; i < numOfVnodes; ++i) {
+ pAccess[i].vgId = htonl(pAccess[i].vgId);
+ SVnodeObj *pVnode = vnodeAccquireVnode(pAccess[i].vgId);
+ if (pVnode != NULL) {
+ pVnode->accessState = pAccess[i].accessState;
+ if (pVnode->accessState != TSDB_VN_ALL_ACCCESS) {
+ vTrace("vgId:%d, access state is set to %d", pAccess[i].vgId)
+ }
+ vnodeRelease(pVnode);
+ }
+ }
+}
+
static void vnodeCleanUp(SVnodeObj *pVnode) {
// remove from hash, so new messages wont be consumed
taosHashRemove(tsDnodeVnodesHash, (const char *)&pVnode->vgId, sizeof(int32_t));
diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c
index 032dbde9eac8e4edc07fbe017f6de1e7cdf4cd0b..68e98757cc0ab54662ac7af6c587d08cd44ac6ce 100644
--- a/src/vnode/src/vnodeWrite.c
+++ b/src/vnode/src/vnodeWrite.c
@@ -53,6 +53,10 @@ int32_t vnodeProcessWrite(void *param1, int qtype, void *param2, void *item) {
if (vnodeProcessWriteMsgFp[pHead->msgType] == NULL)
return TSDB_CODE_VND_MSG_NOT_PROCESSED;
+ if (!(pVnode->accessState & TSDB_VN_WRITE_ACCCESS)) {
+ return TSDB_CODE_VND_NO_WRITE_AUTH;
+ }
+
if (pHead->version == 0) { // from client or CQ
if (pVnode->status != TAOS_VN_STATUS_READY)
return TSDB_CODE_VND_INVALID_VGROUP_ID; // it may be in deleting or closing state
diff --git a/tests/script/general/parser/alter.sim b/tests/script/general/parser/alter.sim
index 018ee924d18f0c7748c9ce07cb37b27460439d3c..6b28b20fb87d3983fc93a055505415ffa56ac946 100644
--- a/tests/script/general/parser/alter.sim
+++ b/tests/script/general/parser/alter.sim
@@ -114,46 +114,46 @@ sql drop table tb
sql drop table mt
sleep 3000
-## ALTER TABLE WHILE STREAMING [TBASE271]
-sql create table tb1 (ts timestamp, c1 int, c2 nchar(5), c3 int)
-sql create table strm as select count(*), avg(c1), first(c2), sum(c3) from tb1 interval(2s)
-sql select * from strm
-if $rows != 0 then
- return -1
-endi
-#sleep 12000
-sql insert into tb1 values (now, 1, 'taos', 1)
-sleep 20000
-sql select * from strm
-print rows = $rows
-if $rows != 1 then
- return -1
-endi
-if $data04 != 1 then
- return -1
-endi
-sql alter table tb1 drop column c3
-sleep 6000
-sql insert into tb1 values (now, 2, 'taos')
-sleep 30000
-sql select * from strm
-if $rows != 2 then
- return -1
-endi
-if $data04 != 1 then
- return -1
-endi
-sql alter table tb1 add column c3 int
-sleep 6000
-sql insert into tb1 values (now, 3, 'taos', 3);
-sleep 3000
-sql select * from strm
-if $rows != 3 then
- return -1
-endi
-if $data04 != 1 then
- return -1
-endi
+### ALTER TABLE WHILE STREAMING [TBASE271]
+#sql create table tb1 (ts timestamp, c1 int, c2 nchar(5), c3 int)
+#sql create table strm as select count(*), avg(c1), first(c2), sum(c3) from tb1 interval(2s)
+#sql select * from strm
+#if $rows != 0 then
+# return -1
+#endi
+##sleep 12000
+#sql insert into tb1 values (now, 1, 'taos', 1)
+#sleep 20000
+#sql select * from strm
+#print rows = $rows
+#if $rows != 1 then
+# return -1
+#endi
+#if $data04 != 1 then
+# return -1
+#endi
+#sql alter table tb1 drop column c3
+#sleep 6000
+#sql insert into tb1 values (now, 2, 'taos')
+#sleep 30000
+#sql select * from strm
+#if $rows != 2 then
+# return -1
+#endi
+#if $data04 != 1 then
+# return -1
+#endi
+#sql alter table tb1 add column c3 int
+#sleep 6000
+#sql insert into tb1 values (now, 3, 'taos', 3);
+#sleep 3000
+#sql select * from strm
+#if $rows != 3 then
+# return -1
+#endi
+#if $data04 != 1 then
+# return -1
+#endi
## ALTER TABLE AND INSERT BY COLUMNS
sql create table mt (ts timestamp, c1 int, c2 int) tags(t1 int)
diff --git a/tests/script/general/parser/limit1_tblocks100.sim b/tests/script/general/parser/limit1_tblocks100.sim
index 2235e6b424f4f3e5fd5edbc496046bb400908b34..29b48bdd43409345caae8cf201d757c2d33d3954 100644
--- a/tests/script/general/parser/limit1_tblocks100.sim
+++ b/tests/script/general/parser/limit1_tblocks100.sim
@@ -61,6 +61,7 @@ run general/parser/limit1_stb.sim
print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
+sleep 5000
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed
diff --git a/tests/script/general/parser/null_char.sim b/tests/script/general/parser/null_char.sim
index 6da419cd4c07a298996563089d86451d732c3883..09e761c85e68b1bc7a4464901080353936a4d8e5 100644
--- a/tests/script/general/parser/null_char.sim
+++ b/tests/script/general/parser/null_char.sim
@@ -206,68 +206,70 @@ endi
################# binary
sql alter table st41 set tag tag_binary = "shanghai"
-sql describe st41
-if $data23 != shanghai then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data00 != shanghai then
return -1
endi
+
##### test 'space' case
-#$tagvalue = '
-#$tagvalue = $tagvalue '
-#sql alter table st41 set tag tag_binary = $tagvalue
+system_content echo ' ' | sed 's/ //g' | tr -d '\n' # Construct an empty result for later result checking
sql alter table st41 set tag tag_binary = ""
-#sql describe st41
-#if $data23 != $tagvalue then
-# return -1
-#endi
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data00 != $system_content then
+ print expect [ $system_content ], actual [ $data00 ]
+ return -1
+endi
+
sql alter table st41 set tag tag_binary = "NULL"
-sql describe st41
-if $data23 != NULL then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data00 != NULL then
return -1
endi
+
sql alter table st41 set tag tag_binary = NULL
-sql describe st41
-if $data23 != NULL then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data00 != NULL then
print ==8== expect: NULL, actually: $data23
return -1
endi
################### nchar
sql alter table st41 set tag tag_nchar = "��˼����"
-sql describe st41
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
#sleep 1000
-#if $data33 != ��˼���� then
-# print ==== expect ��˼����, actually $data33
+#if $data01 != ��˼���� then
+# print ==== expect ��˼����, actually $data01
# return -1
#endi
##### test 'space' case
#$tagvalue = '
#$tagvalue = $tagvalue '
sql alter table st41 set tag tag_nchar = ''
-#sql describe st41
-#if $data33 != $tagvalue then
+#sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+#if $data01 != $tagvalue then
# return -1
#endi
sql alter table st41 set tag tag_nchar = "NULL"
-sql describe st41
-if $data33 != NULL then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data01 != NULL then
return -1
endi
sql alter table st41 set tag tag_nchar = NULL
-#sql describe st41
-#if $data33 != then
-# print ==9== expect , actually $data33
+#sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+#if $data01 != then
+# print ==9== expect , actually $data01
# return -1
#endi
################### int
sql alter table st41 set tag tag_int = -2147483647
-sql describe st41
-if $data43 != -2147483647 then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data02 != -2147483647 then
return -1
endi
sql alter table st41 set tag tag_int = 2147483647
-sql describe st41
-if $data43 != 2147483647 then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data02 != 2147483647 then
return -1
endi
@@ -275,19 +277,19 @@ sql_error alter table st41 set tag tag_int = -2147483648
sql_error alter table st41 set tag tag_int = 2147483648
sql alter table st41 set tag tag_int = '-379'
-sql describe st41
-if $data43 != -379 then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data02 != -379 then
return -1
endi
sql alter table st41 set tag tag_int = -2000
-sql describe st41
-if $data43 != -2000 then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data02 != -2000 then
return -1
endi
sql alter table st41 set tag tag_int = NULL
-sql describe st41
-if $data43 != NULL then
- print ==10== expect: NULL, actually: $data43
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data02 != NULL then
+ print ==10== expect: NULL, actually: $data02
return -1
endi
sql alter table st41 set tag tag_int = 'NULL'
@@ -296,34 +298,34 @@ sql_error alter table st41 set tag tag_int = abc379
################### bool
sql alter table st41 set tag tag_bool = 'true'
-sql describe st41
-if $data53 != true then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data03 != 1 then
return -1
endi
sql alter table st41 set tag tag_bool = 'false'
-sql describe st41
-if $data53 != false then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data03 != 0 then
return -1
endi
sql alter table st41 set tag tag_bool = 0
-sql describe st41
-if $data53 != false then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data03 != 0 then
return -1
endi
sql alter table st41 set tag tag_bool = 123
-sql describe st41
-if $data53 != true then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data03 != 1 then
return -1
endi
sql alter table st41 set tag tag_bool = 'NULL'
-sql describe st41
-if $data53 != NULL then
- print ==14== expect: NULL, actually: $data53
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data03 != NULL then
+ print ==14== expect: NULL, actually: $data03
return -1
endi
sql alter table st41 set tag tag_bool = NULL
-sql describe st41
-if $data53 != NULL then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data03 != NULL then
return -1
endi
@@ -333,50 +335,51 @@ sql_error alter table st41 set tag tag_bool = abc379
################### float
sql alter table st41 set tag tag_float = -32
-sql describe st41
-if $data63 != -32.000000 then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data04 != -32.00000 then
+ print expect -32.00000 actual $data04
return -1
endi
sql alter table st41 set tag tag_float = 54.123456
-sql describe st41
-if $data63 != 54.123455 then
- print ==15== expect: 54.123455, actually: $data63
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data04 != 54.123455 then
+ print ==15== expect: 54.123455, actually: $data04
# return -1
endi
sql alter table st41 set tag tag_float = 54.12345
-sql describe st41
-if $data63 != 54.123451 then
- print ==16== expect: 54.123451, actually: $data63
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data04 != 54.12345 then
+ print ==16== expect: 54.12345, actually: $data04
return -1
endi
sql alter table st41 set tag tag_float = 54.12345678
-sql describe st41
-if $data63 != 54.123455 then
- print ==11== expect: 54.123455, actually : $data63
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data04 != 54.12346 then
+ print ==11== expect: 54.12346, actually : $data04
return -1
endi
sql alter table st41 set tag tag_float = NULL
-sql describe st41
-if $data63 != NULL then
- print ==12== expect: NULL, actually : $data63
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data04 != NULL then
+ print ==12== expect: NULL, actually : $data04
return -1
endi
sql alter table st41 set tag tag_float = 'NULL'
-sql describe st41
-if $data63 != NULL then
- print ==17== expect: NULL, actually : $data63
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data04 != NULL then
+ print ==17== expect: NULL, actually : $data04
return -1
endi
sql alter table st41 set tag tag_float = '54.123456'
-sql describe st41
-if $data63 != 54.123455 then
- print ==18== expect: 54.123455, actually : $data63
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data04 != 54.12346 then
+ print ==18== expect: 54.12346, actually : $data04
return -1
endi
sql alter table st41 set tag tag_float = '-54.123456'
-sql describe st41
-if $data63 != -54.123455 then
- print ==19== expect: -54.123455, actually : $data63
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data04 != -54.12346 then
+ print ==19== expect: -54.12346, actually : $data04
return -1
endi
sql_error alter table st41 set tag tag_float = ''
@@ -387,30 +390,32 @@ sql_error alter table st41 set tag tag_float = abc
################### double
sql alter table st41 set tag tag_double = -92
-sql describe st41
-if $data73 != -92.000000 then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data05 != -92.000000000 then
+ print expect -92.000000000 actual $data05
return -1
endi
sql alter table st41 set tag tag_double = 184
-sql describe st41
-if $data73 != 184.000000 then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data05 != 184.000000000 then
+ print expect 184.000000000 actual $data05
return -1
endi
sql alter table st41 set tag tag_double = '-2456'
-sql describe st41
-if $data73 != -2456.000000 then
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data05 != -2456.000000000 then
return -1
endi
sql alter table st41 set tag tag_double = NULL
-sql describe st41
-if $data73 != NULL then
- print ==13== expect: NULL, actually : $data73
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data05 != NULL then
+ print ==13== expect: NULL, actually : $data05
return -1
endi
sql alter table st41 set tag tag_double = 'NULL'
-sql describe st41
-if $data73 != NULL then
- print ==20== expect: NULL, actually : $data73
+sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
+if $data05 != NULL then
+ print ==20== expect: NULL, actually : $data05
return -1
endi
sql_error alter table st41 set tag tag_double = ''
@@ -427,23 +432,22 @@ sql alter table st51 set tag tag_bigint = '-379'
sql alter table st51 set tag tag_bigint = -2000
sql alter table st51 set tag tag_bigint = NULL
sql alter table st51 set tag tag_bigint = 9223372036854775807
-sql describe st51
-if $data23 != 9223372036854775807 then
+sql select tag_bigint, tag_smallint, tag_tinyint from st51
+if $data00 != 9223372036854775807 then
return -1
endi
sql alter table st51 set tag tag_bigint = 9223372036854775808
-sql describe st51
-if $data23 != 9223372036854775807 then
+sql select tag_bigint, tag_smallint, tag_tinyint from st51
+if $data00 != 9223372036854775807 then
return -1
endi
sql alter table st51 set tag tag_bigint = -9223372036854775807
-sql describe st51
-if $data23 != -9223372036854775807 then
+sql select tag_bigint, tag_smallint, tag_tinyint from st51
+if $data00 != -9223372036854775807 then
return -1
endi
sql_error alter table st51 set tag tag_bigint = -9223372036854775808
-
sql alter table st51 set tag tag_bigint = 'NULL'
sql_error alter table st51 set tag tag_bigint = ''
sql_error alter table st51 set tag tag_bigint = abc379
@@ -452,15 +456,15 @@ sql_error alter table st51 set tag tag_bigint = abc379
sql alter table st51 set tag tag_smallint = -2000
sql alter table st51 set tag tag_smallint = NULL
sql alter table st51 set tag tag_smallint = 32767
-sql describe st51
-if $data33 != 32767 then
+sql select tag_bigint, tag_smallint, tag_tinyint from st51
+if $data01 != 32767 then
return -1
endi
sql_error alter table st51 set tag tag_smallint = 32768
sql alter table st51 set tag tag_smallint = -32767
-sql describe st51
-if $data33 != -32767 then
+sql select tag_bigint, tag_smallint, tag_tinyint from st51
+if $data01 != -32767 then
return -1
endi
sql_error alter table st51 set tag tag_smallint = -32768
@@ -473,13 +477,13 @@ sql_error alter table st51 set tag tag_smallint = abc379
sql alter table st51 set tag tag_tinyint = -127
sql alter table st51 set tag tag_tinyint = NULL
sql alter table st51 set tag tag_tinyint = 127
-sql describe st51
-if $data43 != 127 then
+sql select tag_bigint, tag_smallint, tag_tinyint from st51
+if $data02 != 127 then
return -1
endi
sql alter table st51 set tag tag_tinyint = -127
-sql describe st51
-if $data43 != -127 then
+sql select tag_bigint, tag_smallint, tag_tinyint from st51
+if $data02 != -127 then
return -1
endi
sql_error alter table st51 set tag tag_tinyint = '-128'
@@ -493,4 +497,4 @@ sql_error alter table st51 set tag tag_tinyint = abc379
#sql drop database $db
-system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
+system sh/exec.sh -n dnode1 -s stop -x SIGINT
diff --git a/tests/script/general/parser/testSuite.sim b/tests/script/general/parser/testSuite.sim
index f288288fb7162760e0e3c747ab3e136ba56ea13f..31acaad1432559662584d777027ec1082a4e7373 100644
--- a/tests/script/general/parser/testSuite.sim
+++ b/tests/script/general/parser/testSuite.sim
@@ -82,26 +82,22 @@ sleep 2000
run general/parser/groupby.sim
sleep 2000
run general/parser/set_tag_vals.sim
-
sleep 2000
run general/parser/slimit_alter_tags.sim # persistent failed
-
sleep 2000
run general/parser/join.sim
sleep 2000
run general/parser/join_multivnode.sim
-
sleep 2000
-#run general/parser/repeatAlter.sim
-sleep 2000
-#run general/parser/repeatStream.sim
-
+run general/parser/repeatAlter.sim
sleep 2000
run general/parser/binary_escapeCharacter.sim
sleep 2000
run general/parser/bug.sim
-sleep 2000
-run general/parser/stream_on_sys.sim
-sleep 2000
-run general/parser/stream.sim
\ No newline at end of file
+#sleep 2000
+#run general/parser/repeatStream.sim
+#sleep 2000
+#run general/parser/stream_on_sys.sim
+#sleep 2000
+#run general/parser/stream.sim
\ No newline at end of file
diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt
index e90f22b6552b3454ab48c2012a475eca2eddff24..75be6943c946885c06ea36455d2f39ed4f322dcc 100644
--- a/tests/script/jenkins/basic.txt
+++ b/tests/script/jenkins/basic.txt
@@ -100,7 +100,7 @@ cd ../../../debug; make
./test.sh -f general/insert/query_multi_file.sim
./test.sh -f general/insert/tcp.sim
-#./test.sh -f general/parser/alter.sim
+./test.sh -f general/parser/alter.sim
./test.sh -f general/parser/alter1.sim
./test.sh -f general/parser/alter_stable.sim
./test.sh -f general/parser/auto_create_tb.sim
@@ -117,10 +117,10 @@ cd ../../../debug; make
./test.sh -f general/parser/import_commit3.sim
./test.sh -f general/parser/insert_tb.sim
./test.sh -f general/parser/first_last.sim
-#unsupport ./test.sh -f general/parser/import_file.sim
+#./test.sh -f general/parser/import_file.sim
./test.sh -f general/parser/lastrow.sim
./test.sh -f general/parser/nchar.sim
-#unsupport ./test.sh -f general/parser/null_char.sim
+#./test.sh -f general/parser/null_char.sim
./test.sh -f general/parser/single_row_in_tb.sim
./test.sh -f general/parser/select_from_cache_disk.sim
./test.sh -f general/parser/mixed_blocks.sim
@@ -147,10 +147,10 @@ cd ../../../debug; make
./test.sh -f general/parser/join_multivnode.sim
./test.sh -f general/parser/binary_escapeCharacter.sim
./test.sh -f general/parser/bug.sim
-#unsupport ./test.sh -f general/parser/stream_on_sys.sim
+#./test.sh -f general/parser/stream_on_sys.sim
./test.sh -f general/parser/stream.sim
-#unsupport ./test.sh -f general/parser/repeatAlter.sim
-#unsupport ./test.sh -f general/parser/repeatStream.sim
+./test.sh -f general/parser/repeatAlter.sim
+#./test.sh -f general/parser/repeatStream.sim
./test.sh -f general/stable/disk.sim
./test.sh -f general/stable/dnode3.sim
@@ -159,20 +159,20 @@ cd ../../../debug; make
./test.sh -f general/stable/values.sim
./test.sh -f general/stable/vnode3.sim
-#./test.sh -f general/stream/metrics_1.sim
-#./test.sh -f general/stream/metrics_del.sim
-#./test.sh -f general/stream/metrics_n.sim
-#./test.sh -f general/stream/metrics_replica1_vnoden.sim
+./test.sh general/stream/stream_1.sim
+./test.sh general/stream/stream_2.sim
+./test.sh general/stream/stream_3.sim
+./test.sh general/stream/stream_restart.sim
+./test.sh general/stream/table_1.sim
+./test.sh general/stream/metrics_1.sim
+./test.sh general/stream/table_n.sim
+./test.sh general/stream/metrics_n.sim
+./test.sh general/stream/table_del.sim
+./test.sh general/stream/metrics_del.sim
+./test.sh general/stream/table_replica1_vnoden.sim
+./test.sh general/stream/metrics_replica1_vnoden.sim
#./test.sh -f general/stream/new_stream.sim
#./test.sh -f general/stream/restart_stream.sim
-#./test.sh -f general/stream/stream_1.sim
-#./test.sh -f general/stream/stream_2.sim
-#./test.sh -f general/stream/stream_3.sim
-#./test.sh -f general/stream/stream_restart.sim
-#./test.sh -f general/stream/table_1.sim
-#./test.sh -f general/stream/table_del.sim
-#./test.sh -f general/stream/table_n.sim
-#./test.sh -f general/stream/table_replica1_vnoden.sim
./test.sh -f general/table/autocreate.sim
./test.sh -f general/table/basic1.sim
@@ -324,7 +324,7 @@ cd ../../../debug; make
./test.sh -f unique/vnode/replica3_vgroup.sim
./test.sh -f unique/arbitrator/check_cluster_cfg_para.sim
-./test.sh -f unique/arbitrator/dn2_mn1_cache_file_sync.sim
+./test.sh -f unique/arbitrator/dn2_mn1_cache_file_sync.sim
./test.sh -f unique/arbitrator/dn3_mn1_full_createTableFail.sim
./test.sh -f unique/arbitrator/dn3_mn1_full_dropDnodeFail.sim
./test.sh -f unique/arbitrator/dn3_mn1_multiCreateDropTable.sim
@@ -337,7 +337,7 @@ cd ../../../debug; make
./test.sh -f unique/arbitrator/dn3_mn1_vnode_corruptFile_offline.sim
./test.sh -f unique/arbitrator/dn3_mn1_vnode_corruptFile_online.sim
./test.sh -f unique/arbitrator/dn3_mn1_vnode_noCorruptFile_offline.sim
-#./test.sh -f unique/arbitrator/dn3_mn1_vnode_delDir.sim # unsupport
+#./test.sh -f unique/arbitrator/dn3_mn1_vnode_delDir.sim
./test.sh -f unique/arbitrator/dn3_mn1_vnode_nomaster.sim
./test.sh -f unique/arbitrator/dn3_mn2_killDnode.sim
./test.sh -f unique/arbitrator/insert_duplicationTs.sim
diff --git a/tests/script/unique/account/usage.sim b/tests/script/unique/account/usage.sim
index c1c5d7572888bae7d0360fc901a9688885e510b9..3f12c4613736fa3022a9608c4703fbd2baec9e06 100644
--- a/tests/script/unique/account/usage.sim
+++ b/tests/script/unique/account/usage.sim
@@ -1,6 +1,8 @@
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
+#system sh/exec.sh -n monitor -s 1
+system sh/exec.sh -n monitorInterval -s 1
sleep 3000
sql connect
@@ -25,13 +27,16 @@ endi
if $data05 != 0/10 then
return -1
endi
-
+if $data06 != 0.000/unlimited then
+ return -1
+endi
+
print =============== check usage account
-sql create database d1
-sql create database d2
-sql create database d3
-sql create database d4
-sql create database d5
+sql create database d1 wal 2
+sql create database d2 wal 2
+sql create database d3 wal 2
+sql create database d4 wal 2
+sql create database d5 wal 2
sql create table d1.t1 (ts timestamp, i int);
sql create user u1 pass "u1"
@@ -53,6 +58,75 @@ endi
if $data05 != 0/10 then
return -1
endi
+if $data06 != 0.000/unlimited then
+ return -1
+endi
+
+print =============== step2
+sql alter account root pass "taosdata" tseries 10 storage 1073741824 streams 10 dbs 5 users 5
+sql show accounts
+print $data00 $data01 $data02 $data03 $data04 $data05 $data06
+if $data00 != root then
+ return -1
+endi
+if $data02 != 4/5 then
+ return -1
+endi
+if $data03 != 5/5 then
+ return -1
+endi
+if $data04 != 1/10 then
+ return -1
+endi
+if $data05 != 0/10 then
+ return -1
+endi
+if $data06 != 0.000/1.000 then
+ return -1
+endi
+
+print =============== step3
+sql alter account root pass "taosdata" tseries 10 storage 16 streams 10 dbs 5 users 5
+sql show accounts
+print $data00 $data01 $data02 $data03 $data04 $data05 $data06
+if $data00 != root then
+ return -1
+endi
+if $data02 != 4/5 then
+ return -1
+endi
+if $data03 != 5/5 then
+ return -1
+endi
+if $data04 != 1/10 then
+ return -1
+endi
+if $data05 != 0/10 then
+ return -1
+endi
+if $data06 != 0.000/0.000 then
+ return -1
+endi
+
+print =============== step4
+sql insert into d1.t1 values(now + 1s, 1)
+sql insert into d1.t1 values(now + 2s, 2)
+
+# no write auth
+sleep 3000
+sql_error insert into d1.t1 values(now + 3s, 2)
+sql_error insert into d1.t1 values(now + 4s, 2)
+
+sql alter account root pass "taosdata" tseries 10 storage 36 streams 10 dbs 5 users 5
+sleep 3000
+sql insert into d1.t1 values(now + 5s, 1)
+sql insert into d1.t1 values(now + 6s, 2)
+
+# no write auth
+sleep 3000
+sql_error insert into d1.t1 values(now + 7s, 2)
+sql_error insert into d1.t1 values(now + 8s, 2)
+
print =============== check grant
sql_error create database d6